示例#1
0
def test_roll_hit_die(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)
    result = a.roll_hit_die()
    # Just testing that the random number is between 1 and the sides (usually 20)
    assert result >= 1
    assert result <= a.die
示例#2
0
def test_calc_target_number__negative_target_number(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)

    target = factory.make("storm drone")
    assert target.fighter.ac == -20

    result = a.calc_target_number(target)
    assert result >= 1
示例#3
0
def test_calc_target_number__positive_ac(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)

    target = factory.make("henchman")
    assert target.fighter.ac == 6

    result = a.calc_target_number(target)
    expected = 10 + target.fighter.ac + player.level.current_level
    assert result == expected
示例#4
0
def test_execute_damage__no_weapon(test_map):
    player = test_map.player
    assert not player.equipment.slots['WEAPON']

    a = AttackAction(entity=player, dx=-1, dy=-1)
    target = factory.make("henchman")
    atk = player.offense.attacks[0]
    result = a.execute_damage(target, atk)
    assert result >= atk.min_dmg()
    assert result <= atk.max_dmg()
示例#5
0
def test_execute_damage__with_weapon(test_map):
    player = test_map.player
    dagger = player.inventory.item_dict.get('a')
    assert player.equipment.toggle_equip(dagger)

    a = AttackAction(entity=player, dx=-1, dy=-1)
    target = factory.make("henchman")
    atk = player.equipment.slots['WEAPON'].equippable.offense.attacks[0]
    result = a.execute_damage(target, atk)
    assert result >= atk.min_dmg()
    assert result <= atk.max_dmg()
示例#6
0
def test_calc_target_number__negative_ac(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)

    target = factory.make("giant leech")
    assert target.fighter.ac == -2

    result = a.calc_target_number(target)
    max_expected = 10 - 1 + player.level.current_level
    min_expected = 10 + target.fighter.ac + player.level.current_level

    assert result >= min_expected
    assert result <= max_expected
示例#7
0
def test_reduce_dmg__ac_reduces_dmg_below_0__returns_1():
    stormdrone = factory.make("storm drone")
    assert stormdrone.fighter.ac == -20

    # Note: We'll only pass in 1 damage to test that damage can never be reduced below 1.
    # With any -AC, the defender will always try to reduce it to 0.
    result = AttackAction.reduce_dmg(stormdrone, 1)
    assert result == 1
示例#8
0
def test_miss__enemy_misses_enemy(test_map):
    henchman = factory.make("henchman")
    a = AttackAction(entity=henchman, dx=0, dy=1)
    a.miss(henchman)
    assert a.msg == f"The henchman misses the henchman. "
示例#9
0
def test_reduce_dmg__negative_ac():
    giant_leech = factory.make("giant leech")
    assert giant_leech.fighter.ac == -2
    result = AttackAction.reduce_dmg(giant_leech, 5)
    assert result == 3 or result == 4
示例#10
0
def test_blocked_msg__player_blocks(test_map):
    target = test_map.player
    henchman = factory.make("henchman")
    a = AttackAction(entity=henchman, dx=-1, dy=-1)
    a.blocked_msg(target)
    assert a.msg == f"You block the henchman's attack! "
示例#11
0
def test_init(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=1, dy=-1)
    assert a.dx == 1
    assert a.dy == -1
    assert a.entity == player
示例#12
0
def test_perform__no_target__raises_Impossible(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)
    with pytest.raises(exceptions.Impossible):
        a.perform()
示例#13
0
def test_hit_msg__not_implemented(test_map):
    a = AttackAction(entity=test_map.player, dx=0, dy=1)
    henchman = factory.make("henchman")
    with pytest.raises(NotImplementedError):
        a.hit_msg(henchman, "hit", 15)
示例#14
0
def test_init__is_ActionWithDirection(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=1, dy=-1)
    assert isinstance(a, ActionWithDirection)
示例#15
0
def test_reduce_dmg__positive_ac_equals_no_reduction():
    henchman = factory.make("henchman")
    assert henchman.fighter.ac == 6
    result = AttackAction.reduce_dmg(henchman, 5)
    assert result == 5
示例#16
0
def test_miss__enemy_misses_you(test_map):
    target = test_map.player
    henchman = factory.make("henchman")
    a = AttackAction(entity=henchman, dx=0, dy=1)
    a.miss(target)
    assert a.msg == f"The henchman misses you. "
示例#17
0
def test_miss__player_misses(test_map):
    player = test_map.player
    a = AttackAction(entity=player, dx=-1, dy=-1)
    target = factory.make("henchman")
    a.miss(target)
    assert a.msg == f"You miss the henchman. "
示例#18
0
def test_blocked_msg__enemy_blocks_enemy():
    henchman = factory.make("henchman")
    a = AttackAction(entity=henchman, dx=0, dy=1)
    a.blocked_msg(henchman)
    assert a.msg == f"The henchman blocks the henchman's attack! "
示例#19
0
def test_blocked_msg__enemy_blocks_you(test_map):
    player = test_map.player
    target = factory.make("henchman")
    a = AttackAction(entity=player, dx=0, dy=1)
    a.blocked_msg(target)
    assert a.msg == f"The henchman blocks your attack! "