Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import storage, auxiliary, mudsys, hooks
- import prompt
- import math
- class Stats:
- def __init__(self, sset=None):
- for k in ('str', 'dex', 'agi', 'int', 'wis', 'con'):
- setattr(self, k, 5)
- for k in ('hp', 'max_hp', 'speed', 'heal_rate'):
- setattr(self, k, 0)
- self.chargenned = False
- if (sset is not None):
- for k in ('str', 'dex', 'agi', 'int', 'wis', 'con', 'hp', 'max_hp', 'speed', 'heal_rate'):
- if (sset.contains(k)):
- setattr(self, k, sset.readInt(k))
- else:
- setattr(self, k, 5)
- self.chargenned = sset.readBool("chargenned")or False
- def store(self):
- sset = storage.StorageSet()
- for k in ('str', 'dex', 'agi', 'int', 'wis', 'con', 'hp', 'max_hp', 'heal_rate', 'speed'):
- sset.storeInt(k, getattr(self, k))
- sset.storeBool("chargenned", self.chargenned)
- return sset
- def copy(self):
- return self.copyTo(Stats())
- def copyTo(self, src):
- src.str = self.str
- src.dex = self.dex
- src.agi = self.agi
- src.int = self.int
- src.wis = self.wis
- src.con = self.con
- src.hp = self.hp
- src.max_hp = self.max_hp
- src.chargenned = self.chargenned
- return src
- #attribute methods
- def calculateMaxHp(self):
- self.max_hp = (100+(self.con*4)+(self.str*2))
- def calculateHealRate(self):
- self.heal_rate = (self.max_hp*.025)
- def calculateSpeed(self):
- self.speed = (self.agi*4)+(self.dex*2)
- def calculateAttributes(self):
- self.calculateSpeed()
- self.calculateHealRate()
- self.calculateMaxHp()
- def hook_calculateAttributes(info):
- ch, = hooks.parse_info(info)
- ch.stats.calculateAttributes()
- def prompt_hp(ch):
- return str(ch.stats.hp)
- def prompt_maxHp(ch):
- return str(ch.stats.max_hp)
- def heartbeat_heal(info):
- ch, = hooks.parse_info(info)
- ch.stats.hp = int(min(ch.stats.max_hp, math.floor(ch.stats.hp+ch.stats.heal_rate)))
- auxiliary.install("aux_stats", Stats, "char")
- mudsys.add_char_method("stats", property(lambda me: me.aux("aux_stats")))
- hooks.add("char_to_game", hook_calculateAttributes)
- prompt.addPrompt("h", prompt_hp)
- prompt.addPrompt("H", prompt_maxHp)
- hooks.add("heartbeat", heartbeat_heal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement