Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import time
- #i'm lazy
- def alert(line):
- world.Note(line)
- #constants
- TREE_BAL = 10
- HERB = 1
- SMOKE = 2
- SALVE = 3
- #masks
- TREEABLE = 1<<0
- PURGEABLE = 1<<1
- FOCUSABLE = 1<<2
- #manages limb damage etc
- class Limb:
- def __init__(self, name):
- self.name = name
- self.damage = 0
- self.is_parried = False
- def get_damage(self):
- return self.damage
- def damaged(self, dam):
- self.damage += dam
- def heal(self, dam):
- self.damage -= dam
- if self.damage < 0:
- self.damage = 0
- def healed(self):
- self.damage = 0
- def parried(self):
- self.is_parried = True
- def has_parry(self):
- return self.is_parried
- #affliction structure
- class Affliction:
- def __init__(self, name, type, cure, priority, cures=0):
- self.name = name
- self.cure = cure
- self.type = type
- self.default_priority = priority
- self.priority = priority
- self.on = False
- self.cures = cures
- self.gained_at = 0
- #is being a python keyword ruins everything
- def aff_is(self, what):
- return (self.cures & what)
- def has(self):
- return (self.on == True)
- #this is for handling your own affs, not a targets
- def gained(self):
- if self.on == True:
- return
- self.on = True
- alert("<Aff> " + self.name)
- self.gained_at = time.time()
- #this is for handling your own affs, not a targets
- def cured(self, silent=False):
- if self.on == False:
- return
- self.on = False
- if silent:
- return
- time_taken = time.time() - self.gained_at
- alert("<Cured> %s (%.2fs)" % (self.name, time_taken))
- def get_priority(self):
- return self.priority
- def set_priority(self, priority):
- self.priority = priority
- def get_default_priority(self):
- return self.default_priority
- def reset_priority(self):
- self.priority = self.default_priority
- def get_type(self):
- return self.type
- #for targets affs mostly
- def set(self, state):
- self.on = state
- #defence structure
- class Defence:
- def __init__(self, name, default_state=False):
- self.name = name
- self.on = default_state
- self.waiting = 0
- self.delay_start = 0
- def has(self):
- return (self.on == 1)
- def delay(self, now):
- self.delay_start = now
- def is_delayed(self):
- return (self.delay_start > 0)
- def pending(self):
- self.on = 0.5
- def is_pending(self):
- return (self.on == 0.5)
- def gained(self):
- if self.on == 1:
- return
- self.on = 1
- self.delay_start = 0
- def lost(self):
- if self.on < 1:
- return
- self.on = 0
- #structure to hold data about a single individual
- class TrackData:
- def __init__(self, who):
- self.name = who.title()
- self.affs = new_aff_dict()
- self.defs = new_defence_dict()
- self.health_percent = 100
- self.mana_percent = 100
- self.last_eat = 0
- self.last_tree = 0
- self.last_purge = 0
- self.last_elixir = 0
- self.last_apply = 0
- self.salve_timer = 0
- self.potential_affs = []
- self.potential_cures = []
- self.prof = None
- self.limbs = {
- "head" : Limb("head"),
- "torso" : Limb("torso"),
- "left_arm" : Limb("left arm"),
- "right_arm" : Limb("right arm"),
- "left_leg" : Limb("left leg"),
- "right_leg" : Limb("right leg"),
- }
- self.shadowplant = None
- self.nairat = None
- self.loshre = None
- #type is like HERB/SMOKE/etc, cure is like maidenhair/kelp/laurel
- def sorted_affs_to_cure(self, type, cure):
- affs = []
- for aff in self.affs.values():
- if aff.has():
- if (not type or aff.type == type) and (not cure or aff.cure == cure):
- affs.append(aff)
- return sorted(affs, key=lambda aff: aff.priority)
- #this is where you'd check for shadowplant hits, nairat, etc
- def verify_cures(self):
- for cure in self.potential_cures:
- self.set_aff(cure, False)
- self.print_status()
- #helper function
- def cure_blocker(self):
- if self.nairat or self.shadowplant or self.loshre or self.prof == "assassin" or self.prof == "renegade":
- return True
- #you'd call this on the prompt, do your shrug/rebounding/whatever verification here
- def verify_affs(self):
- for aff in self.potential_affs:
- self.set_aff(aff, True)
- def aff_count(self):
- return len([aff for aff in self.affs if self.affs[aff].has()])
- def applied(self, bal):
- self.salve_timer = bal
- self.last_apply = time.time()
- def cant_tree(self):
- if self.affs["paresis"].has() or self.affs["paralysis"].has() or (time.time() - self.last_tree < TREE_BAL):
- return True
- return False
- def cant_purge(self):
- if self.affs["hemotoxin"].has() or self.affs["disrupted"].has() or time.time() - self.last_purge < 15:
- return True
- return False
- def off_herb_bal_for(self, amt):
- if self.last_eat == 0:
- return 0
- period = time.time() - self.last_eat
- if period > 2.0:
- return 0
- period = 2 - period
- if period >= amt:
- return True
- return False
- def off_salve_bal(self):
- if self.salve_timer == 0:
- return False
- now = time.time()
- if now - self.last_apply > self.salve_timer:
- return False
- return True
- def print_status(self):
- target = world.GetVariable("target")
- if target is None:
- return
- target = target.title()
- if self.name != target:
- return
- afflictions = []
- for aff in self.affs:
- if self.affs[aff].has():
- afflictions.append(aff)
- defences = []
- for defence in self.defs:
- if self.defs[defence].has():
- defences.append(defence)
- alert(self.name + ":")
- alert("<Affs>: " + ", ".join(afflictions))
- alert("<Defs>: " + ", ".join(defences))
- #afflictions to seal a truelock
- def affs_to_seal_lock(self, ignore_confuse, ignore_disrupt):
- lock = []
- if not self.affs["asthma"].has():
- lock.append("asthma")
- if not self.affs["impatience"].has():
- lock.append("impatience")
- if not self.affs["anorexia"].has():
- lock.append("anorexia")
- if not self.affs["slickness"].has():
- lock.append("slickness")
- if not self.affs["numbness"].has() and not self.affs["paralysis"].has():
- lock.append("numbness")
- if not ignore_confuse and not self.affs["confusion"].has():
- lock.append("confusion")
- if not ignore_disrupt and not self.affs["disrupted"].has():
- lock.append("disrupted")
- return lock
- #are they locked?
- def truelocked(self, confused, disrupted):
- locked = (self.affs["asthma"].has() and self.affs["slickness"].has() and self.affs["impatience"].has() and self.affs["anorexia"].has() and (self.affs["numbness"].has() or self.affs["paralysis"].has()))
- if not locked:
- return False
- if locked and (not disrupted or self.affs["disrupted"].has()) and (not confused or self.affs["confusion"].has()):
- return True
- return False
- def has_aff(self, aff):
- aff = normalise_aff(aff)
- if not self.affs.has_key(aff):
- alert("Unknown aff in has_aff: " + aff)
- return
- return self.affs[aff].has()
- def has_def(self, defence):
- defence = normalise_aff(defence)
- if not self.defs.has_key(defence):
- alert("Unknown defence " + defence + " in has_def")
- return
- return self.defs[defence].has()
- def reset_affs(self):
- self.affs = new_aff_dict()
- alert("Reset afflictions for " + self.name)
- def set_aff(self, aff, state=True):
- aff = normalise_aff(aff)
- if not self.affs.has_key(aff):
- alert(self.name + " received unknown aff " + aff + ". Needs adding to new_aff_dict()")
- return
- if aff == "sensitivity" and self.defs["deafness"].has():
- self.set_def("deafness", False)
- return
- old_val = self.affs[aff].on
- self.affs[aff].set(state)
- if old_val == state:
- return
- self.print_status()
- def set_def(self, defence, state=True):
- defence = normalise_aff(defence)
- if not self.defs.has_key(defence):
- alert(self.name + " tried to handle defence " + defence + ". Needs adding to new_defence_dict()")
- return
- if self.defs[defence] != state:
- self.defs[defence] = state
- self.print_status()
- def reset_defs(self):
- self.defs = new_defence_dict()
- alert("Reset defences for " + self.name + ".")
- def limb_damage(self, limb, damage):
- if not self.limbs.has_key(limb):
- alert("Tried to damage the " + limb + " of " + self.name + ", but he doesn't appear to have one!")
- return
- self.limbs[limb].damage(damage)
- def limb_cure(self, limb, amount):
- if not self.limbs.has_key(limb):
- alert("Tried to cure the %s of %s, but he doesn't have one. Poor guy." % (limb, self.name))
- return
- self.limbs[limb].heal(amt)
- def print_limbs(self, raw=False):
- alert("Limbs of " + self.name + ":")
- for limb in self.limbs:
- alert("%s: %s" % (limb, self.limbs[limb].get_damage()))
- def reset(self):
- self.affs = new_aff_dict()
- self.defs = new_defence_dict()
- self.health_percent = 100
- self.mana_percent = 100
- self.last_tree = 0
- self.last_eat = 0
- self.last_elixir = 0
- self.last_apply = 0
- self.last_purge = 0
- alert("Reset tracking for " + self.name + ".")
- for l in self.limbs:
- self.limbs[l].healed()
- def new_defence_dict():
- return {
- "fitness" : Defence("fitness", True),
- "deafness" : Defence("deafness", True),
- "fangbarrier" : Defence("fangbarrier", True),
- "rebounding" : Defence("rebounding", True),
- "shielded" : Defence("shielded"),
- "speed" : Defence("speed", True),
- "insulation" : Defence("caloric", True),
- "insomnia" : Defence("insomnia", True),
- }
- # priority is how important the aff is.
- # lower priorities are cured first
- #i.e. in the example below, someone eats maidenhair, numbness will be cleared from the tracker before paralysis
- def new_aff_dict():
- return {
- "paralysis" : Affliction("paralysis", HERB, "maidenhair", 6, PURGEABLE),
- "numbness" : Affliction("numbness", HERB, "maidenhair", 5, PURGEABLE),
- "stupidity" : Affliction("stupidity", HERB, "orphine", 0, TREEABLE | FOCUSABLE | PURGEABLE),
- "anorexia" : Affliction("anorexia", SALVE, "epidermal to body", 0, FOCUSABLE | PURGEABLE),
- "penance" : Affliction("penance", SMOKE, "laurel", 0, TREEABLE),
- }
- #where all tracking data is stored
- tracker = {}
- #keep affs in a consistent format
- def normalise_aff(aff):
- return aff.replace(" ", "_")
- #give a person an aff
- def person_aff(who, aff, state=True):
- who = who.lower().strip()
- new_tracker_entry(who)
- tracker[who].set_aff(who, state)
- def new_tracker_entry(who):
- who = who.lower().strip()
- if tracker.has_key(who):
- return
- tracker[who] = TrackData(who)
- alert("<Tracker>: Created new entry for " + who.title())
- # there's some redundant code here since we check they have the affs already in the sorting process
- # But I'm pretty sure I had it here for a reason.
- def person_ate(target, herb):
- target = target.lower().strip()
- new_tracker_entry(target)
- tracker[target].last_eat = time.time()
- order = tracker[target].sorted_affs_to_cure(HERB, herb)
- for aff in order:
- tracker[target].set_aff(aff.name, False)
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement