94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
# push_one_period.py
|
|
#
|
|
# Copyright 2007 by David Delbecq
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
#
|
|
#
|
|
#
|
|
# This script make the object is is attached to swap at
|
|
# given periods of day with a specifc object in the event's inventory
|
|
# To use it, give this event's parameter the name of
|
|
# period where the swap is active. Put in the inventiry the swapped object
|
|
# The swap can occur for objects in map and for object in other object
|
|
#
|
|
# exemple
|
|
#
|
|
# arch event_time
|
|
# title Python
|
|
# slaying /python/tod/replace_one_period.py
|
|
# name Morning,Noon
|
|
# arch beholder
|
|
# end
|
|
# end
|
|
#
|
|
# parameters are separated by comas. Those
|
|
# are the periods of day where the swap is active
|
|
|
|
|
|
import Crossfire
|
|
import string
|
|
event = Crossfire.WhatIsEvent()
|
|
alreadymatched = (event.Value!=0)
|
|
|
|
parameters = string.split(Crossfire.ScriptParameters(),",")
|
|
now = Crossfire.GetTime()
|
|
current = [Crossfire.GetMonthName(now[1]),Crossfire.GetWeekdayName(now[5]),Crossfire.GetSeasonName(now[7]),Crossfire.GetPeriodofdayName(now[8])]
|
|
if (set(parameters) - set(current)):
|
|
match = False
|
|
else:
|
|
match = True
|
|
if ( (match and (not alreadymatched)) or (alreadymatched and (not match))):
|
|
Crossfire.Log(Crossfire.LogDebug, "replace_one_period")
|
|
event = Crossfire.WhatIsEvent()
|
|
current = Crossfire.WhoAmI()
|
|
future = event.Inventory
|
|
# we do not want to repace a monster/anything useable in game by a subevent on the event.
|
|
# seems for technical reasons, EVENT object have a destroy subevent. So let's just
|
|
# ignore subevents
|
|
while ( (future != None) & (future.Type == Crossfire.Type.EVENT_CONNECTOR)):
|
|
future=future.Below
|
|
if (future):
|
|
if (future.Below):
|
|
Crossfire.Log(Crossfire.LogDebug, "future.Below is %s" %future.Below.Name)
|
|
Crossfire.Log(Crossfire.LogDebug, "current is %s, future is %s, event is %s" %(current.Name, future.Name, event.Name))
|
|
if (current.Env):
|
|
Crossfire.Log(Crossfire.LogDebug, "env mode")
|
|
env = current.Env
|
|
future.InsertInto(env)
|
|
event.InsertInto(future)
|
|
current.InsertInto(event)
|
|
if (alreadymatched):
|
|
event.Value=0
|
|
else:
|
|
event.Value=1
|
|
elif (current.Map):
|
|
Crossfire.Log(Crossfire.LogDebug, "Map mode")
|
|
mymap = current.Map
|
|
x = current.X
|
|
y = current.Y
|
|
Crossfire.Log(Crossfire.LogDebug, "inserting future %s in map" %future.Name)
|
|
mymap.Insert(future,x,y)
|
|
Crossfire.Log(Crossfire.LogDebug, "inserting event %s in future" %event.Name)
|
|
event.InsertInto(future)
|
|
Crossfire.Log(Crossfire.LogDebug, "inserting current %s in event" %current.Name)
|
|
current.InsertInto(event)
|
|
if (alreadymatched):
|
|
event.Value=0
|
|
else:
|
|
event.Value=1
|
|
else:
|
|
Crossfire.Log(Crossfire.LogDebug, "neither env object nor map found")
|