def test_command_register(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands import CommandRegister cmds = CommandRegister() self.assertEqual(cmds['supercalifragilisticexpieladocious'], None, "Command Register is returning things it doesn't have!") cmds.register((lambda : 3), ['bob', 'sam']) self.assertEqual(cmds['bob'](), 3, "Registered command 'bob' returned wrong value.") self.assertEqual(cmds['sam'](), 3, "Registered command 'sam' returned wrong value.") self.assertEqual(cmds['bob'], cmds['sam'], "Registered aliases 'bob' and 'sam' did not return same function.")
def test_command_register(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands import CommandRegister cmds = CommandRegister() self.assertEqual( cmds['supercalifragilisticexpieladocious'], None, "Command Register is returning things it doesn't have!") cmds.register((lambda: 3), ['bob', 'sam']) self.assertEqual(cmds['bob'](), 3, "Registered command 'bob' returned wrong value.") self.assertEqual(cmds['sam'](), 3, "Registered command 'sam' returned wrong value.") self.assertEqual( cmds['bob'], cmds['sam'], "Registered aliases 'bob' and 'sam' did not return same function.")
def critical(self): """Critical attacks do up to twice as much damage. """ base_damage = self.attacker.damage.calculate() if not base_damage: base_damage = {'impact': 3} damage = dict([(key, randint(int(1.5 * val + 0.5), 2 * val)) for key, val in base_damage.items()]) total = self.target.takes_damage( damage, "Critical Hit! %s" % self.attacker.fancy_name()) self.attacker.update_output( "Critical Hit! You strike %s for %s damage!" % (self.target.fancy_name(), str(total))) Action_list.register(Attack, ['attack']) class Run(BattleAction): cost = FAST_ACTION_COST def roll_to_hit(self): if randint(0, 3): loc = self.attacker.location world = World.get_world() self.attacker.go(world.get_location(self.target[0], self.target[1])) self.battle.tell_all(self.attacker.fancy_name() + " ran away!", [self.attacker.name]) self.attacker.mode.active = False self.battle.remove_character(self.attacker)
def miss(self): self.attacker.update_output("You attack %s but miss!" % self.target.fancy_name()) self.target.update_output("%s tried to attack you, but missed" % (self.attacker.fancy_name())) def critical(self): """Critical attacks do up to twice as much damage. """ base_damage = self.attacker.damage.calculate() if not base_damage: base_damage = {'impact': 3} damage = dict([(key, randint(int(1.5 * val + 0.5), 2* val)) for key, val in base_damage.items()]) total = self.target.takes_damage(damage, "Critical Hit! %s" % self.attacker.fancy_name()) self.attacker.update_output("Critical Hit! You strike %s for %s damage!" % (self.target.fancy_name(), str(total))) Action_list.register(Attack, ['attack']) class Run(BattleAction): cost = FAST_ACTION_COST def roll_to_hit(self): if randint(0,3): loc = self.attacker.location world = World.get_world() self.attacker.go(world.get_location(self.target[0], self.target[1])) self.battle.tell_all(self.attacker.fancy_name() + " ran away!", [self.attacker.name]) self.attacker.mode.active = False self.battle.remove_character(self.attacker) self.attacker.battle = None else: self.attacker.update_output("You try to run, but can't get away!")