예제 #1
0
def test_chassis_base_mod_included():
    base_mod = build_mod(states_granted=State.ON_FIRE,
                         attribute_modifiers={Attributes.CREDITS: 3},
                         subroutines_granted=direct_damage(3))
    chassis = Chassis({}, base_mod=base_mod)

    assert len(list(chassis.all_mods())) == 1
예제 #2
0
def test_direct_move_removes_and_returns_cpu(player, enemy):
    cpu_used = 2
    time = 3
    damage = 1
    move = Move(
        direct_damage(damage, cpu_slots=cpu_used, time_to_resolve=time),
        player, enemy)

    logic = CombatLogic([player, enemy])

    def get_cpu():
        return player.status.get_attribute(Attributes.CPU_AVAILABLE)

    def get_health():
        return enemy.status.get_attribute(Attributes.HEALTH)

    starting_cpu = get_cpu()
    starting_health = get_health()
    # Add move to stack and wait until it resolves.
    logic.start_round([move])
    for _ in range(time):
        assert get_health() == starting_health
        logic.end_round()
        assert get_cpu() == starting_cpu - cpu_used
        logic.start_round([])
        assert get_cpu() == starting_cpu - cpu_used

    # When it resolves cpu should return and HP should go down.
    logic.end_round()
    assert get_cpu() == starting_cpu
    assert get_health() == starting_health - damage
예제 #3
0
def create_combat_group(group_size: int, health: int = 10, damage: int = 2,
                        base_name: str = 'combatant',
                        subroutine: Subroutine = None) -> List[Character]:
    if subroutine is None:
        subroutine = direct_damage(damage)
    return [_get_combatant(health=health, subroutine=subroutine,
                           name=base_name + str(i))
            for i in range(group_size)]
예제 #4
0
def test_combat_scene_to_decision_scene():
    game = Game()  # noqa: F841
    view_manager = ViewManager()  # noqa: F841

    # dummy decision scene to which will will transision
    def dummy_scene():
        return DecisionScene('dummy scene for testing purposes', {})

    # combat scene with two 1 health enemies
    enemies = [_one_health_enemy() for _ in range(2)]
    scene = combat_scene.CombatScene(
        enemies, win_resolution=BasicResolution(dummy_scene))
    event_utils.post_scene_change(scene)

    assert isinstance(_get_active_controller(), CombatSceneController)

    # Start with player holding nothing
    player = get_player()
    [player.chassis.remove_mod(mod) for mod in player.chassis.all_mods()]
    assert len(list(player.chassis.all_mods())) == 1  # Base mod only

    # give player ability to fire laser

    shoot_laser = direct_damage(1,
                                label='laser',
                                time_to_resolve=0,
                                cpu_slots=0)
    laser_mod = build_mod(subroutines_granted=shoot_laser,
                          valid_slots=tuple(s for s in SlotTypes
                                            if s != SlotTypes.STORAGE))
    assert player.chassis.can_store(laser_mod)
    player.chassis.attempt_store(laser_mod)
    assert laser_mod in player.chassis.all_active_mods()

    # Kill each enemy
    for enemy in enemies:
        # click enemy
        click_on_char(enemy, scene.layout)

        assert enemy is selected_char(scene.layout)

        # select the fire laser ability
        laser_ind = [
            ind for ind, move in enumerate(scene.available_moves())
            if move.subroutine is shoot_laser
        ][0]
        event_utils.simulate_key_press(str(laser_ind + 1))
        assert is_dead(enemy)

    # check that scene has ended
    assert scene.is_resolved()

    # update the scene by waiting a tick, confirm that we've switched to a
    # Decision scene
    EventManager.post(BasicEvents.TICK)
    assert isinstance(_get_active_controller(), DecisionSceneController)
예제 #5
0
    def test_mods_add_subroutines(self):
        char = self._character()

        subroutine = direct_damage(12)
        assert subroutine not in char.chassis.all_subroutines()

        char.chassis.attempt_store(
            build_mod(subroutines_granted=subroutine,
                      valid_slots=_ACTIVE_SLOT))
        assert subroutine in char.chassis.all_subroutines()
예제 #6
0
def test_fire_laser(character):
    damage = 3
    fire_laser = direct_damage(damage)
    other_char = build_character(data=CharacterData(ChassisTypes.NO_LEGS.data))
    other_char.status.set_state(State.IS_PLAYER, True)

    assert not fire_laser.can_use(character, character)
    assert fire_laser.can_use(character, other_char)
    fire_laser.use(character, other_char)
    value = other_char.status.get_attribute
    assert value(Attributes.HEALTH) == value(Attributes.MAX_HEALTH) - damage
예제 #7
0
    BASIC_HULL_PLATING = 'hull plating'
    FIRE_HELM = 'helm of being on fire'
    CAMOUFLAGE_PAINT = 'camo paint'
    SMALL_LASER = 'small laser'
    BIG_LASER = 'big laser'
    LASER_REPEATER = 'laser repeater'
    REPAIR_NANITES = 'self-repair nanites'
    SHIELD_GENERATOR = 'shield generator'
    CPU_SCRAMBLER = 'CPU scrambler'

    @property
    def data(self) -> ModData:
        return _mod_types_to_data[self]._replace(description=self.value)


_shoot_small = direct_damage(2, label='small laser')
_shoot_big = direct_damage(5, label='big laser')
_shoot_many = damage_over_time(1,
                               num_rounds=3,
                               time_to_resolve=1,
                               label='laser barrage')
_shield_3_rounds = shield_buff(amount=1, num_rounds=3, cpu_slots=1)
_lower_cpu = adjust_attribute(Attributes.MAX_CPU,
                              amount=-2,
                              duration=2,
                              cpu_slots=2,
                              time_to_resolve=1,
                              is_buff=False)

_mod_types_to_data = {
    ModTypes.BASIC_HULL_PLATING:
예제 #8
0
def _mini_laser() -> Tuple[Mod]:
    return build_mod(subroutines_granted=direct_damage(1, 0, 1, 'Mini laser'),
                     valid_slots=SlotTypes.HEAD,
                     description='Mini laser'),
예제 #9
0
from models.characters.subroutines_base import build_subroutine

_NO_LEGS = ChassisData(slot_capacities={
    SlotTypes.HEAD: 1,
    SlotTypes.CHEST: 3,
    SlotTypes.ARMS: 2,
    SlotTypes.STORAGE: 10
},
                       attribute_modifiers={
                           Attributes.MAX_HEALTH: 10,
                           Skills.STEALTH: 1,
                           Skills.MECHANICS: 1,
                           Attributes.MAX_CPU: 4
                       })

_shoot_laser = direct_damage(2, label='small laser')

_SINGLE_LASER = ChassisData(slot_capacities={
    SlotTypes.HEAD: 1,
    SlotTypes.STORAGE: 1
},
                            states_granted=(State.ON_FIRE, ),
                            attribute_modifiers={
                                Attributes.MAX_HEALTH: 5,
                                Attributes.MAX_CPU: 2
                            },
                            subroutines_granted=(_shoot_laser, ))

_do_nothing_1 = build_subroutine(can_use=True,
                                 description='Do nothing',
                                 time_to_resolve=1,