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)
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_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_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)
def test_cyclone_bonus(self): error = "Cyclone didn't deal increasing damage with a consecutive hit" elemental = CombatElementalBuilder().build() cyclone_action = ElementalAction(actor=elemental, ability=Cyclone(), combat=self.get_mocked_combat()) elemental.add_action(cyclone_action) bonus = Cyclone().get_bonus_multiplier(Mock(), elemental) self.assertGreater(bonus, 1, error)
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)
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)
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)
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)
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)
def test_blood_fangs_base_healing(self): error = "Blood Fangs didn't recover 10% health baseline" elemental = CombatElementalBuilder().build() action = ElementalAction(actor=elemental, ability=BloodFangs(), combat=self.get_mocked_combat()) action._refresh_target() action.execute() self.assertEqual(0.1, action.total_healing / elemental.max_hp, error)
def test_blood_fangs_scaled_healing(self): error = "Blood Fangs didn't scale with missing health" elemental = CombatElementalBuilder().build() elemental.receive_damage(20, Mock()) action = ElementalAction(actor=elemental, ability=BloodFangs(), combat=self.get_mocked_combat()) action._refresh_target() action.execute() self.assertGreater(action.total_healing / elemental.max_hp, 0.1, error)
def test_mana_consumption(self): error = "Mana-consuming ability didn't consume mana" elemental = CombatElementalBuilder().build() previous_mana = elemental.current_mana action = ElementalAction(actor=elemental, ability=RazorFangs(), combat=self.get_mocked_combat()) action._refresh_target() action.execute() self.assertLess(elemental.current_mana, previous_mana, error)
def test_defend_charge(self): error = "Defend didn't use a defend charge" elemental = CombatElementalBuilder().build() previous_charges = elemental.defend_charges action = ElementalAction(actor=elemental, ability=Defend(), combat=self.get_mocked_combat()) action._refresh_target() action.execute() self.assertEqual(elemental.defend_charges, (previous_charges - 1), error)
def test_blood_fangs_healing(self): error = "Blood Fangs didn't heal the actor" elemental = CombatElementalBuilder().build() elemental.receive_damage(10, Mock()) hp_before = elemental.current_hp action = ElementalAction(actor=elemental, ability=BloodFangs(), combat=self.get_mocked_combat()) action._refresh_target() action.execute() hp_after = elemental.current_hp self.assertGreater(hp_after, hp_before, 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)
def make_move(self, ability) -> None: action = ElementalAction(actor=self.active_elemental, ability=ability, combat=self.combat) self.combat.request_action(action)