Ejemplo n.º 1
0
def _build_player_char() -> Character:
    char = build_character(data=CharacterTypes.HUMAN_PLAYER.data)

    # This identifies the character as the player character, which is used in
    # determining teams.
    char.status.set_state(State.IS_PLAYER, True)
    return char
Ejemplo n.º 2
0
    def __init__(self,
                 enemies: Sequence[Character] = None,
                 win_resolution: Resolution = None,
                 loss_resolution: Resolution = None,
                 background_image: str = None) -> None:
        if enemies is None:
            enemies = (build_character(data=CharacterTypes.DRONE.data), )
        self._enemies: Tuple[Character, ...] = tuple(enemies)
        super().__init__()
        self._player = get_player()

        self._combat_logic = CombatLogic((self._player, ) + self._enemies)

        self._win_resolution = win_resolution
        self._loss_resolution = loss_resolution

        self._selected_char: Optional[Character] = None

        self._update_layout()

        # Rect positions
        if background_image is None:
            self._background_image = BackgroundImages.CITY.path
        else:
            self._background_image = background_image

        # Animation data
        self._animation_progress: Optional[float] = None
        self._first_turn = True
Ejemplo n.º 3
0
    def test_no_valid_moves_gives_default_move(self, ai_type):
        unusable = build_subroutine(can_use=False)
        data = CharacterData(ChassisData(subroutines_granted=(unusable,)))
        user = build_character(data=data)
        ai = build_ai(ai_type)
        ai.set_user(user)
        target = build_character(data=data)

        move_comps = set()
        for _ in range(100):
            move = ai.select_move([target])
            sub = move.subroutine
            components = (
                sub.cpu_slots(), sub.time_to_resolve(), sub.description())
            move_comps.add(components)

        assert len(move_comps) == 1
Ejemplo n.º 4
0
def _get_combatant(health: int, subroutine: Subroutine, name: str,
                   ai_type: AIType = AIType.No_AI) -> Character:
    mod_data = ModData(attribute_modifiers={Attributes.MAX_HEALTH: health},
                       subroutines_granted=(subroutine,),
                       valid_slots=(SlotTypes.ARMS,))
    chassis_data = ChassisData({SlotTypes.ARMS: 10})
    char_data = CharacterData(chassis_data, name, (mod_data,), '', ai_type)

    return build_character(data=char_data)
Ejemplo n.º 5
0
def _medical_bot(number: int) -> Character:
    """Construct a medical robot character"""

    base_mod = build_mod(subroutines_granted=[_heal_over_time(), _bone_drill()],
                         attribute_modifiers={Attributes.MAX_HEALTH: 4,
                                              Attributes.MAX_CPU: 2})
    chassis = Chassis({}, base_mod=base_mod)
    name = 'med_bot {}'.format(number)
    return build_character(chassis, AIType.Random, name=name,
                           image_path='src/data/images/medbot.png')
Ejemplo n.º 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
Ejemplo n.º 7
0
 def _character(self):
     chassis = ChassisData({SlotTypes.STORAGE: 10, _ACTIVE_SLOT: 10},
                           attribute_modifiers={Attributes.MAX_HEALTH: 10})
     return build_character(data=CharacterData(chassis))
Ejemplo n.º 8
0
def enemy():
    return build_character(data=CharacterTypes.DRONE.data)
Ejemplo n.º 9
0
def player():
    # Player character with zero initial mods.
    chassis = Chassis.from_data(ChassisTypes.NO_LEGS.data)
    player = build_character(chassis, name='player')
    player.status.set_state(State.IS_PLAYER, True)
    return player
Ejemplo n.º 10
0
def test_increment_attribute():
    char = build_character(data=CharacterTypes.DRONE.data)
    health = char.status.get_attribute(Attributes.HEALTH)
    delta = -3
    increment_attribute(Attributes.HEALTH, delta, char)
    assert char.status.get_attribute(Attributes.HEALTH) == health + delta
Ejemplo n.º 11
0
def _one_health_enemy():
    chassis = Chassis(
        {}, build_mod(attribute_modifiers={Attributes.MAX_HEALTH: 1}))
    return build_character(chassis)
def _create_enemy(health: int = 10) -> Character:
    char_data = CharacterData(
        ChassisData(attribute_modifiers={Attributes.MAX_HEALTH: health}))
    return build_character(data=char_data)
Ejemplo n.º 13
0
def character():
    return build_character(data=CharacterData(ChassisTypes.NO_LEGS.data))