Esempio n. 1
0
    def test_stronger_against_specific_entity_kind(self):
        power = 5
        strong_against = [Keyword.LARGE]
        weapon = random_weapon(atk=power, strong_against=strong_against)

        normal_foe = random_foe_entity(keywords=[])
        self.assertEqual(power, weapon.hit(random_player_entity(), normal_foe))

        vulnerable_foe = random_foe_entity(keywords=[Keyword.LARGE])
        self.assertEqual(power * 2, weapon.hit(random_player_entity(), vulnerable_foe))
Esempio n. 2
0
    def test_stronger_against_multiple_entity_kinds(self):
        power = 4
        strong_against = [Keyword.LARGE, Keyword.CAVALRY]
        weapon = random_weapon(atk=power, strong_against=strong_against)

        non_vulnerable_foe = random_foe_entity(keywords=[Keyword.SMALL])
        self.assertEqual(power, weapon.hit(random_player_entity(), non_vulnerable_foe))

        vulnerable_foe = random_foe_entity(keywords=[Keyword.LARGE])
        self.assertEqual(power * 2, weapon.hit(random_player_entity(), vulnerable_foe))

        super_vulnerable_foe = random_foe_entity(keywords=[Keyword.CAVALRY, Keyword.LARGE])
        self.assertEqual(power * 3, weapon.hit(random_player_entity(), super_vulnerable_foe))
    def test_update_state_position_objective(self):
        nature = rd.choice([MissionType.POSITION, MissionType.TOUCH_POSITION])
        position = [random_position()]
        players = [random_player_entity(), random_player_entity()]
        mission = Mission(True, nature, position, 'Test mission', 2)

        self.assertTrue(mission.update_state(players[0]))
        self.assertFalse(mission.ended)
        self.assertEqual(players[0], mission.succeeded_chars[0])

        self.assertTrue(mission.update_state(players[1]))
        self.assertTrue(mission.ended)
        self.assertEqual(players, mission.succeeded_chars)
Esempio n. 4
0
 def test_save_and_load_player_turn_finished(self):
     player = random_player_entity(name="raimund",
                                   classes=['warrior'],
                                   race='human')
     player.end_turn()
     player_saved = player.save('player')
     loaded_player = load_player(player_saved, True)
     self.assertTrue(loaded_player.turn_is_finished())
Esempio n. 5
0
    def test_no_charge_bonus_for_weapon_with_no_charge(self):
        power = 4
        weapon = random_weapon(atk=power, attack_kind='PHYSICAL', charge=False)
        player = random_player_entity()
        player.strength = 5
        attacked_ent = random_foe_entity(min_hp=1000, max_hp=1000, max_defense=0, keywords=[])
        player.equip(weapon)

        # No charge bonus even if there is a " charge "
        player.pos = (player.old_pos[0] + 5 * TILE_SIZE, player.old_pos[1])
        self.assertEqual(player.strength + weapon.atk, player.attack(attacked_ent))
Esempio n. 6
0
 def test_save_and_load_player_with_equipment(self):
     helmet = parse_item_file('helmet')
     equipment = [helmet]
     player = random_player_entity(name="raimund",
                                   classes=['warrior'],
                                   race='human',
                                   equipments=equipment)
     player_saved = player.save('player')
     loaded_player = load_player(player_saved, True)
     self.assertFalse(loaded_player.turn_is_finished())
     self.assertTrue(helmet in loaded_player.equipments)
Esempio n. 7
0
 def test_save_and_load_player_with_items(self):
     first_item = parse_item_file('short_sword')
     second_item = parse_item_file('life_potion')
     inventory = [first_item, second_item]
     player = random_player_entity(name="raimund",
                                   classes=['warrior'],
                                   race='human',
                                   items=inventory)
     player_saved = player.save('player')
     loaded_player = load_player(player_saved, True)
     self.assertFalse(loaded_player.turn_is_finished())
     self.assertTrue(first_item in loaded_player.items)
     self.assertTrue(second_item in loaded_player.items)
Esempio n. 8
0
    def test_charge_bonus(self):
        power = 4
        spear = random_weapon(atk=power, attack_kind='PHYSICAL', charge=True)
        player = random_player_entity()
        player.strength = 5
        attacked_ent = random_foe_entity(min_hp=1000, max_hp=1000, max_defense=0, keywords=[])
        player.equip(spear)
        # No charge
        self.assertEqual(player.strength + spear.atk, player.attack(attacked_ent))

        # Charge
        player.pos = (player.old_pos[0] + 5 * TILE_SIZE, player.old_pos[1])
        self.assertEqual(player.strength + int(spear.atk * 1.5), player.attack(attacked_ent))

        # Stronger charge
        player.pos = (player.old_pos[0] + 8 * TILE_SIZE, player.old_pos[1])
        self.assertEqual(player.strength + int(spear.atk * 2), player.attack(attacked_ent))
 def test_hit_power(self):
     power = 3
     strong_against = []
     weapon = random_weapon(atk=power, strong_against=strong_against)
     self.assertEqual(
         power, weapon.hit(random_player_entity(), random_foe_entity()))