Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. import storage, auxiliary, mudsys, hooks
  2. import prompt
  3. import math
  4.  
  5. class Stats:
  6. def __init__(self, sset=None):
  7. for k in ('str', 'dex', 'agi', 'int', 'wis', 'con'):
  8. setattr(self, k, 5)
  9. for k in ('hp', 'max_hp', 'speed', 'heal_rate'):
  10. setattr(self, k, 0)
  11. self.chargenned = False
  12.  
  13. if (sset is not None):
  14. for k in ('str', 'dex', 'agi', 'int', 'wis', 'con', 'hp', 'max_hp', 'speed', 'heal_rate'):
  15. if (sset.contains(k)):
  16. setattr(self, k, sset.readInt(k))
  17. else:
  18. setattr(self, k, 5)
  19. self.chargenned = sset.readBool("chargenned")or False
  20.  
  21. def store(self):
  22. sset = storage.StorageSet()
  23. for k in ('str', 'dex', 'agi', 'int', 'wis', 'con', 'hp', 'max_hp', 'heal_rate', 'speed'):
  24. sset.storeInt(k, getattr(self, k))
  25. sset.storeBool("chargenned", self.chargenned)
  26. return sset
  27.  
  28. def copy(self):
  29. return self.copyTo(Stats())
  30.  
  31. def copyTo(self, src):
  32. src.str = self.str
  33. src.dex = self.dex
  34. src.agi = self.agi
  35. src.int = self.int
  36. src.wis = self.wis
  37. src.con = self.con
  38. src.hp = self.hp
  39. src.max_hp = self.max_hp
  40. src.chargenned = self.chargenned
  41. return src
  42.  
  43. #attribute methods
  44. def calculateMaxHp(self):
  45. self.max_hp = (100+(self.con*4)+(self.str*2))
  46. def calculateHealRate(self):
  47. self.heal_rate = (self.max_hp*.025)
  48. def calculateSpeed(self):
  49. self.speed = (self.agi*4)+(self.dex*2)
  50. def calculateAttributes(self):
  51. self.calculateSpeed()
  52. self.calculateHealRate()
  53. self.calculateMaxHp()
  54.  
  55. def hook_calculateAttributes(info):
  56. ch, = hooks.parse_info(info)
  57. ch.stats.calculateAttributes()
  58. def prompt_hp(ch):
  59. return str(ch.stats.hp)
  60. def prompt_maxHp(ch):
  61. return str(ch.stats.max_hp)
  62.  
  63. def heartbeat_heal(info):
  64. ch, = hooks.parse_info(info)
  65. ch.stats.hp = int(min(ch.stats.max_hp, math.floor(ch.stats.hp+ch.stats.heal_rate)))
  66.  
  67. auxiliary.install("aux_stats", Stats, "char")
  68. mudsys.add_char_method("stats", property(lambda me: me.aux("aux_stats")))
  69. hooks.add("char_to_game", hook_calculateAttributes)
  70. prompt.addPrompt("h", prompt_hp)
  71. prompt.addPrompt("H", prompt_maxHp)
  72. hooks.add("heartbeat", heartbeat_heal)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement