Exemple #1
0
 def test_cast_execution_recap(self):
     error = "Recap for execution of a cast was incorrect"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = Combat([team_a], [team_b], Mock())
     team_a.handle_cast_time(Castable(ShiningLaser()))
     team_b.make_move(Claw())
     team_b.make_move(Claw())
     turn_logs = combat.turn_logger.logs[-2]
     self.assertIn("used Shining Laser!", turn_logs[0].recap, error)
     self.assertIn("used Shining Laser!", turn_logs[1].recap, error)
Exemple #2
0
 def test_channel_recap(self):
     error = "Recap for the execution of a channeled ability was incorrect"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = Combat([team_a], [team_b], Mock())
     team_a.make_move(Rampage())
     team_b.make_move(Claw())
     team_b.make_move(Claw())
     elemental = team_a.active_elemental
     turn_logs = combat.turn_logger.logs[-2]
     self.assertEqual(f"{elemental.nickname}'s Rampage continues!", turn_logs[0].recap, error)
     self.assertEqual(f"{elemental.nickname}'s Rampage continues!", turn_logs[1].recap, error)
Exemple #3
0
 def test_set_excessive_abilities(self):
     error = "Replacing an elemental's abilities with an excessive set wasn't handled correctly"
     species = self.get_species()
     elemental = ElementalBuilder().with_level(5).with_species(
         species).build()
     abilities = [Slam(), RollingThunder(), Rend(), Fireball(), Claw()]
     elemental.set_abilities(abilities)
     ability_names = [
         ability.name for ability in elemental.active_abilities
     ]
     self.assertNotIn(Claw().name, ability_names, error)
     self.assertEqual(4, len(elemental.active_abilities))
Exemple #4
0
 def test_physical_defence(self):
     error = "Physical defence didn't reduce any damage"
     low_def = CombatElementalBuilder().with_elemental(
         ElementalBuilder().with_physical_def(1).build()).build()
     high_def = CombatElementalBuilder().with_elemental(
         ElementalBuilder().with_physical_def(30).build()).build()
     actor = CombatElementalBuilder().build()
     low_def_calculator = DamageCalculator(low_def, actor, Claw())
     low_def_calculator.calculate()
     high_def_calculator = DamageCalculator(high_def, actor, Claw())
     high_def_calculator.calculate()
     self.assertGreater(low_def_calculator.final_damage,
                        high_def_calculator.final_damage, error)
Exemple #5
0
 def test_elemental_exp_gain(self):
     error = "Knocking out an elemental didn't grant exp to player's elementals"
     elemental = ElementalBuilder().with_level(5).build()
     team_a = CombatTeam([elemental], PlayerBuilder().build())
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     # Nearly fatal damage
     damage = team_b.active_elemental.max_hp - 1
     team_b.active_elemental.receive_damage(damage, team_a.active_elemental)
     exp_before = elemental.current_exp
     team_a.make_move(Claw())
     team_b.make_move(Claw())
     exp_after = elemental.current_exp
     self.assertGreater(exp_after, exp_before, error)
Exemple #6
0
 def test_player_exp_gain(self):
     error = "Knocking out an elemental didn't grant exp to player"
     player = PlayerBuilder().build()
     team_a = CombatTeam([ElementalBuilder().build()], player)
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     # Nearly fatal damage
     damage = team_b.active_elemental.max_hp - 1
     team_b.active_elemental.receive_damage(damage, team_a.elementals[0])
     exp_before = player.current_exp
     team_a.make_move(Claw())
     team_b.make_move(Claw())
     exp_after = player.current_exp
     self.assertGreater(exp_after, exp_before, error)
Exemple #7
0
 def test_knockout_log(self):
     error = "Event logger didn't receive a log for knockout"
     combat = self.get_mocked_combat()
     team_a = self.get_combat_team()
     team_b = self.get_combat_team()
     combat.join_battle(team_a)
     combat.join_battle(team_b)
     team_a.active_elemental.receive_damage(
         team_a.active_elemental.max_hp - 1, team_b.active_elemental)
     combat.request_action(
         ElementalAction(team_a.active_elemental, Claw(), combat))
     combat.request_action(
         ElementalAction(team_b.active_elemental, Claw(), combat))
     self.assertIn("was knocked out!",
                   combat.turn_logger.most_recent_log.recap, error)
 def test_enrage(self):
     error = "Enrage didn't increase damage output"
     elemental = CombatElementalBuilder().build()
     combat = get_mocked_combat()
     combat.get_target = MagicMock(
         return_value=CombatElementalBuilder().build())
     before_buff = ElementalAction(elemental, Claw(), combat)
     before_buff._refresh_target()
     before_buff.execute()
     elemental.add_status_effect(EnrageEffect())
     elemental.end_turn()
     after_buff = ElementalAction(elemental, Claw(), combat)
     after_buff._refresh_target()
     after_buff.execute()
     self.assertGreater(after_buff.final_damage, before_buff.final_damage,
                        error)
Exemple #9
0
 def get_learnable_ability(self, level: int) -> LearnableAbility:
     """
     Returns a test LearnableAbility for checking requirements.
     """
     learnable = LearnableAbility(Claw())
     learnable.level_required = level
     return learnable
Exemple #10
0
 def test_knockout_grace_turn(self):
     error = "An attack could incorrectly be queued while waiting for a knockout replacement"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     team_a.active_elemental.receive_damage(10000, team_b.active_elemental)
     team_b.make_move(Claw())
     self.assertEqual(len(combat.action_requests), 0, error)
Exemple #11
0
 def test_action_speed_priority(self):
     error = "Faster elemental didn't attack first"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     slower = CombatElemental(ElementalBuilder().with_level(1).build(),
                              team_a)
     team_a.change_active_elemental(slower)
     faster = CombatElemental(
         ElementalBuilder().with_level(10).with_nickname('loksy').build(),
         team_b)
     team_b.change_active_elemental(faster)
     combat.request_action(ElementalAction(slower, Claw(), combat))
     faster_action = ElementalAction(faster, Claw(), combat)
     combat.request_action(faster_action)
     expected = combat.previous_round_actions[0].actor.nickname
     self.assertEqual(expected, faster.nickname, error)
 def test_frost_barrier_chill(self):
     error = "Attackers were not chilled by Frost Barrier"
     elemental = CombatElementalBuilder().build()
     frost_barrier = FrostBarrierEffect()
     frost_barrier.applier = elemental
     elemental.add_status_effect(frost_barrier)
     attacker = CombatElementalBuilder().build()
     elemental.on_receive_ability(Claw(), attacker)
     self.assertIsInstance(attacker.status_effects[0], Chill, error)
Exemple #13
0
 def test_elemental_action(self):
     error = "ElementalAction could incorrectly trigger when the elemental is KOed."
     elemental = ElementalBuilder().build()
     team = CombatTeam([elemental], PlayerBuilder().build())
     elemental.receive_damage(10000)
     action = ElementalAction(actor=team.elementals[0],
                              ability=Claw(),
                              combat=Mock())
     self.assertFalse(action.can_execute, error)
Exemple #14
0
 def test_cast_time_wait(self):
     error = "A spell that requires one turn charge time resolved immediately"
     team_a = make_combat_team()
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     elemental_b = team_b.elementals[0]
     health_before = elemental_b.current_hp
     team_a.handle_cast_time(Castable(ShiningLaser()))
     team_b.make_move(Claw())
     self.assertEqual(elemental_b.current_hp, health_before, error)
Exemple #15
0
 def test_active_elemental_action(self):
     error = "ElementalAction could incorrectly trigger when the elemental forcibly switched."
     team = make_combat_team()
     old_active = team.elementals[0]
     team.change_active_elemental(old_active)
     team.change_active_elemental(CombatElementalBuilder().build())
     action = ElementalAction(actor=old_active,
                              ability=Claw(),
                              combat=Mock())
     self.assertFalse(action.can_execute, error)
Exemple #16
0
 def test_cast_recap(self):
     error = "Recap message was incorrect for a cast time spell"
     team_a = make_combat_team()
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     elemental_a = team_a.elementals[0]
     team_a.handle_cast_time(Castable(ShiningLaser()))
     team_b.make_move(Claw())
     self.assertIn(f'{team_a.active_elemental.name} is shining mightily!!',
                   elemental_a.last_action.recap, error)
Exemple #17
0
 def test_attack_knocked_out(self):
     error = "Attack attempted to resolve even though the opponent was KOed"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     team_b.active_elemental.receive_damage(10000, team_a.active_elemental)
     action = ElementalAction(actor=team_a.active_elemental,
                              ability=Claw(),
                              combat=combat)
     self.assertFalse(action.can_execute, error)
Exemple #18
0
 def test_get_turn_log_knockout(self):
     error = "Turn logs skipped the most recent log on combat end"
     combat = self.get_mocked_combat()
     team_a = self.get_combat_team()
     team_b = self.get_combat_team()
     combat.join_battle(team_a)
     combat.join_battle(team_b)
     team_a.active_elemental.receive_damage(
         team_a.active_elemental.max_hp - 1, team_b.active_elemental)
     combat.request_action(
         ElementalAction(team_a.active_elemental, Claw(), combat))
     combat.request_action(
         ElementalAction(team_b.active_elemental, Claw(), combat))
     log_groups = combat.turn_logger.get_turn_logs(0)
     ko_log_exists = False
     for log in log_groups[-1]:
         if "was knocked out!" in log.recap:
             ko_log_exists = True
             break
     self.assertTrue(ko_log_exists, error)
Exemple #19
0
 def test_cast_time_resolution(self):
     error = "Casted spell didn't resolve when ready"
     team_a = make_combat_team()
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     elemental_b = team_b.elementals[0]
     health_before = elemental_b.current_hp
     team_b.make_move(Defend())
     team_a.handle_cast_time(Castable(ShiningLaser()))
     team_b.make_move(Claw())
     self.assertLess(elemental_b.current_hp, health_before, error)
Exemple #20
0
 def test_action_switch_priority(self):
     error = "Switch wasn't faster than a regular ability"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     combat_elemental = CombatElemental(ElementalBuilder().build(), team_b)
     combat.request_action(ElementalAction(combat_elemental, Claw(),
                                           combat))
     combat.request_action(
         Switch(team_a, combat_elemental, combat_elemental))
     self.assertIsInstance(combat.previous_round_actions[0], Switch, error)
Exemple #21
0
 def test_cast_resources(self):
     error = "A casted ability incorrectly consumed mana multiple times"
     team_a = make_combat_team()
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     team_b.make_move(Defend())
     team_a.handle_cast_time(Castable(ShiningLaser()))
     mana_before = team_a.active_elemental.current_mana
     team_b.make_move(Claw())
     mana_after = team_a.active_elemental.current_mana
     # Assert greater for turn start mana regen.
     self.assertGreater(mana_after, mana_before, error)
Exemple #22
0
 def test_channeling_resources(self):
     error = "A channeled ability incorrectly consumed mana across its duration"
     team_a = make_combat_team()
     team_b = make_combat_team()
     get_mocked_combat(team_a, team_b)
     team_b.make_move(Defend())
     team_a.make_move(Rampage())
     mana_before = team_a.active_elemental.current_mana
     team_b.make_move(Claw())
     mana_after = team_a.active_elemental.current_mana
     # Assert greater for turn start mana regen.
     self.assertGreater(mana_after, mana_before, error)
Exemple #23
0
 def test_switch_target(self):
     error = "Attacks didn't retarget after a switch"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     old_target = team_b.active_elemental
     target = CombatElementalBuilder().build()
     combat.request_action(
         ElementalAction(team_a.active_elemental, Claw(), combat))
     hp_before = target.current_hp
     combat.request_action(Switch(team_b, old_target, target))
     hp_after = target.current_hp
     self.assertLess(hp_after, hp_before, error)
Exemple #24
0
 def test_defend_priority(self):
     error = "Defend wasn't faster than other abilities"
     team_a = make_combat_team()
     team_b = make_combat_team()
     combat = get_mocked_combat(team_a, team_b)
     faster = CombatElemental(ElementalBuilder().with_speed(10).build(),
                              team_b)
     team_b.change_active_elemental(faster)
     slower = CombatElemental(ElementalBuilder().with_speed(1).build(),
                              team_a)
     team_a.change_active_elemental(slower)
     combat.request_action(ElementalAction(faster, Claw(), combat))
     combat.request_action(ElementalAction(slower, Defend(), combat))
     self.assertIsInstance(combat.previous_round_actions[0].ability, Defend,
                           error)
Exemple #25
0
 def claw(level=0) -> LearnableAbility:
     return LearnableAbility(Claw(), level)