Exemplo n.º 1
0
 def test_fs_defence_no_armor(self):
     attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Fighter())
     target = Player('Other Bob', [10, 10, 17, 17, 17, 17], Human(), Fighter())
     target.add_fighting_style(Trait.FIGHTING_STYLE_DEFENCE)
     set_values([8])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.DAGGER], None), HitType.HIT)
Exemplo n.º 2
0
 def test_fs_archery(self):
     attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Fighter())
     attacker.add_fighting_style(Trait.FIGHTING_STYLE_ARCHERY)
     target = Goblin()
     set_values([11])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.SHORTBOW], None), HitType.HIT)
Exemplo n.º 3
0
 def test_critical_miss(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     target = Goblin()
     attack = weapons[WeaponId.DAGGER]
     set_values([1])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.CRITICAL_MISS)
Exemplo n.º 4
0
 def test_ranged(self):
     attacker = Player('Bob', [10, 16, 10, 10, 10, 10], Human(), Fighter())
     attack = weapons[WeaponId.LIGHT_CROSSBOW]
     set_values([3])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             roll_damage(attacker, None, attack, HitType.HIT, None), 6)
Exemplo n.º 5
0
 def test_miss(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     attack = weapons[WeaponId.DAGGER]
     set_values([3])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             roll_damage(attacker, None, attack, HitType.MISS, None), 0)
Exemplo n.º 6
0
 def test_lucky(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], StoutHalfling(), Fighter())
     target = Goblin()
     attack = weapons[WeaponId.DAGGER]
     set_values([1, 17])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
Exemplo n.º 7
0
 def test_side_effects(self):
     set_values([20, 15, 10, 3])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(dice.d20(), 20)
         self.assertEqual(dice.d20(), 15)
         self.assertEqual(dice.d20(), 10)
         self.assertEqual(dice.d20(), 3)
Exemplo n.º 8
0
 def test_negative_damage(self):
     attacker = Player('Bob', [3, 3, 10, 10, 10, 10], Human(), Fighter())
     set_values([1])
     attack = weapons[WeaponId.DAGGER]
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             roll_damage(attacker, None, attack, HitType.HIT, None), 0)
Exemplo n.º 9
0
 def test_unproficient_armor(self):
     attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Rogue())
     target = Goblin()
     attacker.set_armor(armors[ArmorId.PLATE])
     set_values([20, 3])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.DAGGER], None), HitType.MISS)
Exemplo n.º 10
0
 def test_goblin_attack_player(self):
     attacker = Goblin()
     target = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     target.set_armor(armors[ArmorId.CHAIN_SHIRT])
     target.set_left_hand(armors[ArmorId.SHIELD])
     set_values([11])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attacker.get_actions()[0], None), HitType.HIT)
Exemplo n.º 11
0
 def test_critical_hit_maul(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     attack = weapons[WeaponId.MAUL]
     set_values([4, 3, 6, 5])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             roll_damage(attacker, None, attack, HitType.CRITICAL_HIT,
                         None), 18)
Exemplo n.º 12
0
 def test_monster(self):
     attacker = Goblin()
     set_values([1])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             3,
             roll_damage(attacker, None,
                         attacker.get_actions()[0], HitType.HIT, None))
Exemplo n.º 13
0
 def test_critical_hit(self):
     s = Scimitar()
     o = Orc()
     # dice rolls for a critical hit and then max damage of 18
     set_values([20, 8, 8])
     with patch('game_engine.dice._random_int', side_effect=value):
         hit = s.roll_to_hit(o)
         s.roll_damage(o, hit)
         self.assertEqual(o.cur_hp, o.get_hp() - 18)
Exemplo n.º 14
0
 def test_goblin_vs_orc(self):
     # this means hp rolls, initiative rolls, to hit roll and damage rolls until one dead
     set_values([3, 3, 4, 4, 20, 10, 10, 3, 10, 8])
     with patch('game_engine.dice._random_int', side_effect=value):
         f1 = Faction('Goblins', [Goblin()])
         f2 = Faction('Orcs', [Orc()])
         game = Game([f1, f2])
         winner = game.play()
         self.assertEqual(winner.get_name(), 'Orcs')
Exemplo n.º 15
0
 def test_proficieny_matters_not_rogue(self):
     # makes sure to use the higher mod to be able to hit
     # goblin AC is 15
     # rolls a 13
     attacker = Player('Bob', [10, 10, 17, 17, 17, 17], Human(), Rogue())
     target = Goblin()
     attack = weapons[WeaponId.MAUL]
     set_values([13])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.MISS)
Exemplo n.º 16
0
 def test_fighter_hp(self):
     #              9        12       17       8        9        11
     set_values([
         3, 3, 1, 3, 2, 4, 6, 1, 6, 6, 5, 2, 2, 3, 1, 3, 5, 1, 1, 3, 2, 6,
         3, 3
     ])
     with patch('game_engine.dice._random_int', side_effect=value):
         stats, _ = CharacterBuilder.roll_stats()
         player = Player('Radrick', stats, Human(), Fighter())
         self.assertEqual(14, player.get_cur_hp())
Exemplo n.º 17
0
 def test_fs_dueling_two_handed(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     attacker.set_two_hands(weapons[WeaponId.SPEAR])
     attacker.add_fighting_style(Trait.FIGHTING_STYLE_DUELING)
     set_values([6])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             6,
             roll_damage(attacker, None, attacker.get_two_hands(),
                         HitType.HIT, None))
Exemplo n.º 18
0
 def test_fs_greatweapon(self):
     attacker = Player('Bob', [10, 10, 10, 10, 10, 10], Human(), Fighter())
     attacker.set_two_hands(weapons[WeaponId.LONGSWORD])
     attacker.add_fighting_style(Trait.FIGHTING_STYLE_GREAT_WEAPON_FIGHTING)
     set_values([1, 10])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(
             10,
             roll_damage(attacker, None, attacker.get_two_hands(),
                         HitType.HIT, None))
Exemplo n.º 19
0
 def test_halfling_racial_dex_roll_mod(self):
     # roll a dex of 10, (+0) add 2 for halfling results in a mod of +1
     #              9        10       17       8        9        11
     set_values([
         3, 3, 1, 3, 2, 2, 6, 1, 6, 6, 5, 2, 2, 3, 1, 3, 5, 1, 1, 3, 2, 6,
         3, 3
     ])
     with patch('game_engine.dice._random_int', side_effect=value):
         stats, _ = CharacterBuilder.roll_stats()
         player = Player('Radrick', stats, Halfling(), Fighter())
         self.assertEqual(1, player.get_dex_mod())
Exemplo n.º 20
0
 def test_proficieny_matters(self):
     # makes sure to use the higher mod to be able to hit
     # goblin AC is 15
     # proficiency is +2
     # rolls a 13
     attacker = Player('Bob', [10, 10, 17, 17, 17, 17], StoutHalfling(), Fighter())
     target = Goblin()
     attack = weapons[WeaponId.DAGGER]
     set_values([13])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
Exemplo n.º 21
0
 def test_ranged(self):
     # will hit if using the dex bonus not the str bonus (or no bonus for that matter)
     # goblin AC is 15
     # proficiency is +2
     # rolls a 10
     # needs a dex mod of +3 to hit
     attacker = Player('Bob', [10, 17, 10, 10, 10, 10], StoutHalfling(), Fighter())
     target = Goblin()
     attack = weapons[WeaponId.LIGHT_CROSSBOW]
     set_values([10])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attack, None), HitType.HIT)
Exemplo n.º 22
0
 def test_roll_all_stats(self):
     set_values([3,3,1,3, 2,4,3,4, 6,6,5,2, 2,3,1,3, 5,1,1,3, 2,6,3,3])
     with patch('game_engine.dice._random_int', side_effect=value):
         rolls, perfect = CharacterBuilder.roll_stats()
         self.assertEqual(rolls[0], 9)
         self.assertEqual(rolls[1], 11)
         self.assertEqual(rolls[2], 17)
         self.assertEqual(rolls[3], 8)
         self.assertEqual(rolls[4], 9)
         self.assertEqual(rolls[5], 12)
         expected_perfect = (9 + 11 + 17 + 8 + 9 + 12 - 3 * 6) / (15 * 6)
         self.assertEqual(perfect, expected_perfect)
Exemplo n.º 23
0
 def test_disadvantage(self):
     set_values([10, 15])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(dice.d20(RollType.DISADVANTAGE), 10)
Exemplo n.º 24
0
 def test_critical_hit(self):
     set_values([8, 8])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(dice.roll_damage('1d8 + 2', HitType.CRITICAL_HIT),
                          18)
Exemplo n.º 25
0
 def test_single_stats_roll(self):
     set_values([3,3,1,3])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(CharacterBuilder._roll_stat(), 9)
Exemplo n.º 26
0
 def test_goblin_attack_orc(self):
     attacker = Goblin()
     target = Orc()
     set_values([13])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, attacker.get_actions()[0], None), HitType.HIT)
Exemplo n.º 27
0
 def test_natural_1(self):
     attacker = Player('Bob', [18, 18, 17, 17, 17, 17], Human(), Fighter())
     target = Goblin()
     set_values([1])
     with patch('game_engine.dice._random_int', side_effect=value):
         self.assertEqual(roll_to_hit(attacker, target, weapons[WeaponId.DAGGER], None), HitType.CRITICAL_MISS)