Best thing to do is to use scripting either through the main script file or in a plugin. Here's an example script in Python, with comments:
from time import clock
class Balance(object):
""" This is the main balance class. All types of balances
(herb, salve, tree, focus, etc.) can be derived from it. """
def __init__(self, timer):
""" This is called when a new balance is created. We set the
initial state for the given balance to True, and supply the timer
period for the balance - the time it takes to recover this balance.
herbBalance = Balance(2.0)"""
self.state = True
self.timer = timer
self.offTime = clock()
def __setattr__(self,name, value):
""" This is for internal use only, it is called when the value of self.state
is changed """
if name == "state":
if value:
object.__setattr__(self, name, value)
if globals().has_key("CureAfflictions"):
CureAfflictions()
else:
if self.state:
self.offTime = clock()
object.__setattr__(self, name, value)
def CheckTime(self):
""" Checks how much time has passed since the balance's been set False,
if it's been longer than self.timer then we set it back to True. This method
if for internal use only, you'll never have to use it """
if (clock() - self.offTime) >= self.timer:
return True
else:
return False
def TimerExpired(self):
""" Called to figure out whether the balance timer has expired """
if not self.state:
self.state = self.CheckTime()
#Create a herb balance
herbBalance = Balance(2.0)
#Create a list to hold afflictions you have
afflictions = []
def SaveAffliction(name, value):
""" This can be called by triggers to set/reset afflictions. To set an affliction use:
SaveAffliction("curare", 1)
To reset it:
SaveAffliction("curare", 0) """
global afflictions
if value:
if name not in afflictions:
afflictions.append(name)
else:
if name in afflictions:
afflictions.remove(name)
def CureAfflictions():
""" Call this to cure afflictions according to priority or just how they appear in the
list. """
global afflictions, herbBalance
#If we have herb balance then cure prioritized
if herbBalance.state:
if "curare" in afflictions:
world.Send("outr bloodroot")
world.Send("eat bloodroot")
#set herb balance false
herbBalance.state = False
elif "aconite" in afflictions:
world.Send("outr goldenseal")
world.Send("eat goldenseal")
#set herb balance false
herbBalance.state = False
Then from your affliction triggers you could send to Script, and send SaveAffliction("aconite", 1)
to note that you now have stupidity, and SaveAffliction("aconite", 0)
to note that you are no longer stupid. The only other thing you'll need is either a prompt trigger or a plugin with OnPluginPartialLine event defined, either of these should call the TimerExpired method for each balance object, i.e. like this:
herbBalance.TimerExpired()
As long as the CureAfflictions function can recognize all the afflictions by name, and you have triggers for all afflictions, the script will take care of all the gruesome details automatically by curing whatever you have when you have a corresponding balance.
|