def test_kill_group_resolved_after_death(self) -> None: kill_group = resolutions.KillGroup('Mortys') player = testing_utilities.make_player() sprite_labels = {'Mortys': {player}} kill_group.load_sprite_data(sprite_labels) self.assertFalse(kill_group.is_resolved) player.kill() self.assertTrue(kill_group.is_resolved)
def test_set_player_adds_gained_item(self) -> None: description = 'description' decision = MakeDecision('decision') rock: ItemObject = constructors.build_map_object('rock') player = make_player() self.assertNotIn(rock.mod.loc, player.inventory.active_mods) ctrl = TransitionController(description, decision, rock) self.assertNotIn(rock.mod.loc, player.inventory.active_mods) ctrl.set_player_data(player.data) self.assertIn(rock.mod.loc, player.inventory.active_mods)
def test_condition_satisfied_too_many_labels_error(self) -> None: condition_data = {'damaged': None} res_data = { 'condition': { 'condition data': condition_data, 'tested label': 'Morty' } } player = testing_utilities.make_player() labels = {'Morty': [player, player]} resolution = resolutions.resolution_from_data(res_data) with self.assertRaises(ValueError): resolution.load_sprite_data(labels)
def test_turret_behavior(self) -> None: player = make_player() enemy_data_dict = load_npc_data_kwargs('turret') enemy_data = EnemyData(**enemy_data_dict) turret = Enemy(player.pos + Vector2(100, 0), player, enemy_data) self.assertEqual(turret.status.state, 'passive') self.assertEqual(turret.motion.rot, 0) self.assertEqual(len(self.groups.enemy_projectiles), 0) turret.update() self.assertEqual(turret.status.state, 'active') self.assertAlmostEqual(turret.motion.rot % 360, 180)
def test_condition_satisfied_is_resolved(self) -> None: condition_data = {'damaged': None} res_data = { 'condition': { 'condition data': condition_data, 'tested label': 'Morty' } } player = testing_utilities.make_player() labels = {'Morty': {player}} resolution = resolutions.resolution_from_data(res_data) resolution.load_sprite_data(labels) self.assertFalse(resolution.is_resolved) player.status.increment_health(-3) self.assertTrue(resolution.is_resolved)
def test_enter_zone_resolved_after_collision(self) -> None: data = { 'enter zone': { 'zone label': 'collidee', 'entering label': 'collider' } } resolution = resolutions.resolution_from_data(data) player = testing_utilities.make_player() zombie = testing_utilities.make_zombie(player) labels = {'collidee': {zombie}, 'collider': {player}} resolution.load_sprite_data(labels) self.assertFalse(resolution.is_resolved) player.pos = zombie.pos self.assertTrue(resolution.is_resolved)
def test_behavior_load_from_data_correct_state_conditions(self) -> None: player = make_player() cond_val = 1 behavior_dict = { 'passive': { 'conditions': ['default'], 'effects': {} }, 'active': { 'conditions': [{ 'target close': { 'threshold': 400, 'value': cond_val } }], 'effects': {} }, 'dead': { 'conditions': [{ 'dead': { 'value': 100 } }], 'effects': {} } } behavior = Behavior(behavior_dict, player) state_condition_values = behavior._state_conditions_values states = set(state_condition_values.keys()) expected = {'active', 'dead'} self.assertEqual(states, expected) expected_state = 'passive' self.assertEqual(behavior.default_state, expected_state) active_conditions = state_condition_values['active'] key = next(iter(active_conditions.keys())) self.assertIsInstance(key, TargetClose) self.assertEqual(active_conditions[key], cond_val)
def test_set_player_gained_item_removed_from_groups_even_if_not_picked_up( self) -> None: transition = TransitionScene('description', 'shotgun') player = make_player() while not player.inventory.backpack.is_full: pistol = constructors.build_map_object('pistol') player.inventory.attempt_pickup(pistol) num_items = len(self.groups.items) ctrl, _ = transition.make_controller_and_resolutions() self.assertEqual(len(self.groups.items), num_items + 1) ctrl.set_player_data(player.data) self.assertEqual(len(self.groups.items), num_items) shotgun = constructors.build_map_object('shotgun') self.assertNotIn(shotgun.mod, player.inventory.backpack) active_mod = player.inventory.active_mods[shotgun.mod.loc] self.assertNotEqual(shotgun.mod, active_mod)
def test_behavior_load_from_data_correct_effects(self) -> None: player = make_player() behavior_dict = { 'passive': { 'conditions': ['default'], 'effects': { 'stop motion': None } }, 'active': { 'conditions': [{ 'target close': { 'threshold': 400, 'value': 1 } }], 'effects': { 'face and pursue target': { 'conditions': [{ 'dead': { 'logical_not': None } }, { 'damaged': { 'logical_not': None } }] } } }, 'dead': { 'conditions': [{ 'dead': { 'value': 100 } }], 'effects': { 'kill': None } } } enemy_data = EnemyData(**load_npc_data_kwargs('zombie')).replace( behavior_dict=behavior_dict) enemy = Enemy(player.pos + Vector2(100, 0), player, enemy_data) self.assertEqual(enemy.status.state, 'passive') self.assertEqual(enemy.motion.vel, Vector2(0, 0)) self.assertEqual(enemy.motion.rot, 0) enemy.update() self.assertEqual(enemy.status.state, 'active') self.assertLess(enemy.motion.vel.x, 0) self.assertAlmostEqual(enemy.motion.rot % 360, 180) enemy.status.increment_health(-enemy.status.max_health) self.assertEqual(len(self.groups.enemies), 1) enemy.update() self.assertEqual(enemy.status.state, 'dead') self.assertEqual(len(self.groups.enemies), 0)
def test_enemy_construction_with_behavior(self) -> None: player = make_player() enemy_data_dict = load_npc_data_kwargs('zombie') enemy_data = EnemyData(**enemy_data_dict) Enemy(player.pos, player, enemy_data)