Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. # 1. Each skill has a "cooldowns" defaultdict which stores the cooldowns
  2. # These cooldowns are then used directly in the skill methods
  3. # Upsides: easy to read, easy to use
  4. # Downsides: clutters the method and makes it harder to find out the skill's "actual" code
  5.  
  6. fail_message = SayText2('Remaining: {remaining}')
  7.  
  8. @callback('player_attack')
  9. def _burn_victim(self, attacker, victim, **eargs):
  10.     cooldown = self.cooldowns[self._burn_victim]  # replace with any key, as long as it's unique
  11.     if cooldown.remaining > 0:
  12.         fail_message.send(attacker.index, remaining=cooldown.remaining)
  13.     else:
  14.         victim.burn(duration=self.level)
  15.         cooldown.remaining = 10 - self.level
  16.  
  17. # 2. A cooldown decorator which takes two arguments, a cooldown callback and a fail_callback
  18. # Upsides: versatile and keeps the function's body very clean. The callbacks can be separate methods instead of ugly lambdas
  19. # Downsides: Let's be honest, most of the time: ugly lambdas. Even if not, extra methods in the class
  20.  
  21. fail_message = SayText2('Remaining: {f.remaining_cooldown}')
  22.  
  23. @callback('player_attack')
  24. @cooldown(lambda self, **eargs: 10 - self.level,
  25.     fail_callback=lambda self, attacker, **eargs: fail_message.send(attacker.index, f=self._burn_victim))
  26. def _burn_victim(self, victim, **eargs):
  27.     victim.burn(duration=self.level)
  28.  
  29. # 3. A simplified cooldown decorator which takes a fail_message instead of fail_callback
  30. # Upsides: keeps the function's body very clean. Also keeps the decorator much cleaner from lambdas
  31. # Downsides: not as versatile as the other two, as a message is always forced. Needs exact formatting in the message
  32.  
  33. fail_message = SayText2('Remaining: {skill._burn_victim.remaining_cooldown')
  34.  
  35. @callback('player_attack')
  36. @cooldown(lambda self, **eargs: 10 - self.level, fail_message=fail_message)
  37. def _burn_victim(self, victim, **eargs):
  38.     victim.burn(duration=self.level)