def test_chassis_can_store_after_making_space(): chassis = Chassis({SlotTypes.STORAGE: 1}) mod = build_mod() chassis.attempt_store(mod) second_mod = build_mod() assert not chassis.can_store(second_mod) chassis.remove_mod(mod) assert chassis.can_store(second_mod) chassis.remove_mod(second_mod)
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
def test_character_state_change(self): char = self._character() assert not char.status.has_state(State.ON_FIRE) char.chassis.attempt_store( build_mod(states_granted=State.ON_FIRE, valid_slots=_ACTIVE_SLOT)) assert char.status.has_state(State.ON_FIRE)
def test_chassis_stores_in_active_slot_first(): chassis = Chassis({SlotTypes.ARMS: 1, SlotTypes.STORAGE: 1}) fire_mod = build_mod(states_granted=State.ON_FIRE, valid_slots=SlotTypes.ARMS) chassis.attempt_store(fire_mod) assert chassis.grants_state(State.ON_FIRE) assert fire_mod in chassis.all_active_mods()
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)
def test_mods_affect_max_attribute(self): char = self._character() max_health = char.status.get_attribute(Attributes.MAX_HEALTH) bonus = 5 char.chassis.attempt_store( build_mod(attribute_modifiers={Attributes.MAX_HEALTH: bonus}, valid_slots=_ACTIVE_SLOT)) assert char.status.get_attribute( Attributes.MAX_HEALTH) == max_health + bonus
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')
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()
def _typical_mods(locations: Iterable[SlotTypes]) -> List[Mod]: # Loot on the ground out = [] counts = defaultdict(lambda: 0) for loc in locations: counts[loc] += 1 description = '{} mod {}'.format(loc.value, counts[loc]) out.append(build_mod(valid_slots=loc, description=description)) return out
def build_character(chassis: Chassis = None, ai_type: AIType = AIType.No_AI, mods: Iterable[Mod] = (), name: str = 'unnamed Character', image_path: str = 'src/data/images/drone.png', data: CharacterData = None) -> _CharacterImpl: """Factory function for Characters. Args: chassis: Character chassis. Default is the Drone chassis defined by ChassisTypes.DRONE. ai_type: AI assigned to the character. Default is NO_AI (human). mods: Mods that the character initially picks up. These are picked up in order. If a mod cannot be picked up an error is raised. name: Character name. image_path: Path to character image. Default is drone image. data: (Optional) A CharacterData object containing all desired properties. If this is passed, other arguments are ignored. Returns: A Character with the specified properties. """ if data is not None: chassis = Chassis.from_data(data.chassis_data) mods = (build_mod(data=m_data) for m_data in data.mods) return build_character(chassis, data.ai_type, mods, data.name, data.image_path) ai = build_ai(ai_type) if chassis is None: chassis = Chassis.from_data(ChassisTypes.DRONE.data) char = _CharacterImpl(chassis, ai, image_path, name=name) ai.set_user(char) for mod in mods: assert char.chassis.can_store(mod), 'Mod cannot be picked up.' char.chassis.attempt_store(mod) # Initialize starting health and CPU health = char.status.get_attribute(Attributes.MAX_HEALTH) char.status.increment_attribute(Attributes.HEALTH, health) cpu = char.status.get_attribute(Attributes.MAX_CPU) char.status.increment_attribute(Attributes.CPU_AVAILABLE, cpu) return char
def _one_health_enemy(): chassis = Chassis( {}, build_mod(attribute_modifiers={Attributes.MAX_HEALTH: 1})) return build_character(chassis)
def loot() -> List[Mod]: return [build_mod(data=ModTypes.REPAIR_NANITES.data)]
def _mini_laser() -> Tuple[Mod]: return build_mod(subroutines_granted=direct_damage(1, 0, 1, 'Mini laser'), valid_slots=SlotTypes.HEAD, description='Mini laser'),
def from_data(cls, data: 'ChassisData') -> 'Chassis': base_mod = build_mod(data.states_granted, data.attribute_modifiers, data.subroutines_granted, description='base mod') return Chassis(data.slot_capacities, base_mod)
def test_chassis_cannot_store_same_mod_twice(): chassis = Chassis({SlotTypes.STORAGE: 2}) mod = build_mod() chassis.attempt_store(mod) assert not chassis.can_store(mod)
def test_chassis_can_store_in_storage_by_default(): storage_only_chassis = Chassis({SlotTypes.STORAGE: 1}) mod = build_mod(valid_slots=SlotTypes.HEAD) assert storage_only_chassis.can_store(mod)
def test_chassis_base_mod_is_active(): mod = build_mod() chassis = Chassis({}, base_mod=mod) assert mod in chassis.all_active_mods()
def test_chassis_mods_in_storage_not_active(): chassis = Chassis({SlotTypes.ARMS: 1, SlotTypes.STORAGE: 1}) mod = build_mod(valid_slots=SlotTypes.CHEST) chassis.attempt_store(mod) assert mod not in chassis.all_active_mods() assert mod in chassis.all_mods()