def test_resolve_event_with_multiple_events(self): prerequisite_kind_0 = EventMatchPrerequisiteKind.LOCATION prerequisite_location_0 = self.lighthouse_location prerequisite_0 = LocationEventMatchPrerequisite( prerequisite_kind_0, False, prerequisite_location_0) pour_potion_bean_event_0_match = EventMatch( command=self.pour_command, arguments=[self.potion, self.bean], prerequisites=[prerequisite_0]) destroy_bean_destination_0 = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.DESTROY, named_data_element=None) destroy_bean_action_0 = ItemEventOutcomeAction( kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=destroy_bean_destination_0) pour_potion_bean_event_outcome_0 = EventOutcome( text_key="event_response_key", actions=[destroy_bean_action_0]) pour_potion_bean_event_0 = Event( event_id=3003, attributes=0x0, match=pour_potion_bean_event_0_match, outcome=pour_potion_bean_event_outcome_0) pour_potion_bean_event_1_match = EventMatch( command=self.pour_command, arguments=[self.potion, self.bean], prerequisites=[]) pour_potion_bean_event_outcome_1 = EventOutcome( text_key="event_response_key", actions=[]) pour_potion_bean_event_1 = Event( event_id=3003, attributes=0x0, match=pour_potion_bean_event_1_match, outcome=pour_potion_bean_event_outcome_1) self.data.get_events.side_effect = lambda x: { (self.pour_command, self.potion, self.bean): [pour_potion_bean_event_0, pour_potion_bean_event_1], }.get(x) self.lighthouse_location.add(self.bean) response = self.resolver.resolve_event(self.pour_command, self.player, self.potion, self.bean) self.assertEqual( (True, ["event_response_key"], [self.potion, self.bean ], [self.potion, self.bean]), response) self.assertTrue(self.lighthouse_location.contains(self.bean))
def test_resolve_event_with_description_outcome_action(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) action = DescriptionEventOutcomeAction( kind=EventOutcomeActionKind.DESCRIPTION, named_data_element=self.lighthouse_location, extended_description_index=1) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[action]) wave_wand_event = Event(event_id=3004, attributes=0x4, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.assertEqual(1, self.lighthouse_location.extended_description_index)
def test_resolve_event_with_link_outcome_action_remove_link_does_not_already_exist( self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) action = LinkEventOutcomeAction(kind=EventOutcomeActionKind.LINK, source=self.lighthouse_location, direction=Direction.EAST, destination=None) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[action]) wave_wand_event = Event(event_id=3004, attributes=0x4, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.assertFalse(Direction.EAST in self.lighthouse_location.directions)
def test_resolve_event_with_location_outcome_action_unset_attribute(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) action = LocationEventOutcomeAction( kind=EventOutcomeActionKind.LOCATION, location=self.lighthouse_location, attribute=0x1, on=False) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[action]) wave_wand_event = Event(event_id=3004, attributes=0x4, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.assertFalse(self.lighthouse_location.gives_light())
def test_resolve_event_with_item_outcome_action_replace(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) wand_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.REPLACE, named_data_element=self.lamp) wand_action = ItemEventOutcomeAction(kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=wand_destination) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[wand_action]) wave_wand_event = Event(event_id=3005, attributes=0x0, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) self.lighthouse_location.add(self.bean) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.assertFalse(self.lighthouse_location.contains(self.bean)) self.assertTrue(self.lighthouse_location.contains(self.lamp))
def test_resolve_event_with_item_outcome_action_absolute_container_copyable( self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) wand_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.ABSOLUTE_CONTAINER, named_data_element=self.bottle) wand_action = ItemEventOutcomeAction(kind=EventOutcomeActionKind.ITEM, item=self.potion, destination=wand_destination) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[wand_action]) wave_wand_event = Event(event_id=3006, attributes=0x0, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event] }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.assertFalse(self.bottle.contains(self.potion)) potion_copy = self.bottle.get_allow_copy(self.potion) self.assertTrue(potion_copy.is_allow_copy(self.potion))
def test_resolve_event_with_item_outcome_action_current_inventory(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) wand_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.CURRENT_INVENTORY, named_data_element=None) wand_action = ItemEventOutcomeAction(kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=wand_destination) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[wand_action]) wave_wand_event = Event(event_id=3005, attributes=0x0, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.player.take_item.assert_called_once_with(self.bean)
def test_resolve_event_with_match_to_two_args(self): pour_potion_bean_event_match = EventMatch( command=self.pour_command, arguments=[self.potion, self.bean], prerequisites=[]) destroy_bean_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.DESTROY, named_data_element=None) destroy_bean_action = ItemEventOutcomeAction( kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=destroy_bean_destination) pour_potion_bean_event_outcome = EventOutcome( text_key="event_response_key", actions=[destroy_bean_action]) pour_potion_bean_event = Event(event_id=3003, attributes=0x0, match=pour_potion_bean_event_match, outcome=pour_potion_bean_event_outcome) self.data.get_events.side_effect = lambda x: { (self.pour_command, self.potion, self.bean): [pour_potion_bean_event], }.get(x) response = self.resolver.resolve_event(self.pour_command, self.player, self.potion, self.bean) self.assertEqual( (True, ["event_response_key"], [self.potion, self.bean ], [self.potion, self.bean]), response)
def parse_event_match(self, event_match_input, commands_by_id, items_by_id, locations_by_id): command = self.get_event_match_command(event_match_input["command_id"], commands_by_id) arguments = self.parse_event_match_arguments( event_match_input["arguments"], items_by_id) prerequisites = self.parse_event_match_prerequisites( event_match_input.get("prerequisites"), items_by_id, locations_by_id) return EventMatch(command, arguments, prerequisites)
def test_resolve_event_with_item_current_location_prerequisite_with_match( self): prerequisite_kind = EventMatchPrerequisiteKind.ITEM prerequisite_item = self.bean prerequisite_container_kind = ItemEventMatchPrerequisiteContainerKind.CURRENT_LOCATION prerequisite_container = ItemEventMatchPrerequisiteContainer( prerequisite_container_kind, None) prerequisite = ItemEventMatchPrerequisite(prerequisite_kind, False, prerequisite_item, prerequisite_container) pour_potion_bean_event_match = EventMatch( command=self.pour_command, arguments=[self.potion, self.bean], prerequisites=[prerequisite]) destroy_bean_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.DESTROY, named_data_element=None) destroy_bean_action = ItemEventOutcomeAction( kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=destroy_bean_destination) pour_potion_bean_event_outcome = EventOutcome( text_key="event_response_key", actions=[destroy_bean_action]) pour_potion_bean_event = Event(event_id=3003, attributes=0x0, match=pour_potion_bean_event_match, outcome=pour_potion_bean_event_outcome) self.data.get_events.side_effect = lambda x: { (self.pour_command, self.potion, self.bean): [pour_potion_bean_event], }.get(x) self.player.get_location.return_value = self.lighthouse_location self.lighthouse_location.add(self.bean) response = self.resolver.resolve_event(self.pour_command, self.player, self.potion, self.bean) self.assertEqual( (True, ["event_response_key"], [self.potion, self.bean ], [self.potion, self.bean]), response) self.assertFalse(self.lighthouse_location.contains(self.bean))
def test_resolve_event_with_match_to_non_copyable_item(self): rub_lamp_event_match = EventMatch(command=self.rub_command, arguments=[self.lamp], prerequisites=[]) rub_lamp_event_outcome = EventOutcome(text_key="event_response_key", actions=[]) rub_lamp_event = Event(event_id=3001, attributes=0x0, match=rub_lamp_event_match, outcome=rub_lamp_event_outcome) self.data.get_events.side_effect = lambda x: { (self.rub_command, self.lamp): [rub_lamp_event], }.get(x) response = self.resolver.resolve_event(self.rub_command, self.player, self.lamp) self.assertEqual( (True, ["event_response_key"], [self.lamp], [self.lamp]), response)
def test_resolve_event_puzzle(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[]) wave_wand_event = Event(event_id=3004, attributes=0x4, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.player.solve_puzzle.assert_called_once_with(3004)
def test_resolve_event_end_game(self): rub_lamp_event_match = EventMatch(command=self.rub_command, arguments=[self.lamp], prerequisites=[]) rub_lamp_event_outcome = EventOutcome(text_key="event_response_key", actions=[]) rub_lamp_event = Event(event_id=3001, attributes=0x1, match=rub_lamp_event_match, outcome=rub_lamp_event_outcome) self.data.get_events.side_effect = lambda x: { (self.rub_command, self.lamp): [rub_lamp_event], }.get(x) response = self.resolver.resolve_event(self.rub_command, self.player, self.lamp) self.assertEqual( (True, ["event_response_key"], [self.lamp], [self.lamp]), response) self.player.set_playing.assert_called_once_with(False)
def test_resolve_event_with_match_to_copyable_item(self): drink_potion_event_match = EventMatch(command=self.drink_command, arguments=[self.potion], prerequisites=[]) drink_potion_event_outcome = EventOutcome( text_key="event_response_key", actions=[]) drink_potion_event = Event(event_id=3002, attributes=0x0, match=drink_potion_event_match, outcome=drink_potion_event_outcome) self.data.get_events.side_effect = lambda x: { (self.drink_command, self.potion): [drink_potion_event], }.get(x) potion_copy = copy(self.potion) response = self.resolver.resolve_event(self.drink_command, self.player, potion_copy) self.assertEqual( (True, ["event_response_key"], [potion_copy], [potion_copy]), response)
def test_resolve_event_with_player_outcome_action_unset_attribute(self): wave_wand_event_match = EventMatch(command=self.wave_command, arguments=[self.wand], prerequisites=[]) action = PlayerEventOutcomeAction(kind=EventOutcomeActionKind.PLAYER, attribute=0x8, on=False) wave_wand_event_outcome = EventOutcome(text_key="event_response_key", actions=[action]) wave_wand_event = Event(event_id=3004, attributes=0x4, match=wave_wand_event_match, outcome=wave_wand_event_outcome) self.data.get_events.side_effect = lambda x: { (self.wave_command, self.wand): [wave_wand_event], }.get(x) response = self.resolver.resolve_event(self.wave_command, self.player, self.wand) self.assertEqual( (True, ["event_response_key"], [self.wand], [self.wand]), response) self.player.unset_attribute.assert_called_once_with(0x8)
def test_resolve_event_with_event_prerequisite_with_match_invert(self): prerequisite_kind = EventMatchPrerequisiteKind.EVENT prerequisite_location = 3002 prerequisite = EventEventMatchPrerequisite(prerequisite_kind, True, prerequisite_location) pour_potion_bean_event_match = EventMatch( command=self.pour_command, arguments=[self.potion, self.bean], prerequisites=[prerequisite]) destroy_bean_destination = ItemEventOutcomeActionDestination( kind=ItemEventOutcomeActionDestinationKind.DESTROY, named_data_element=None) destroy_bean_action = ItemEventOutcomeAction( kind=EventOutcomeActionKind.ITEM, item=self.bean, destination=destroy_bean_destination) pour_potion_bean_event_outcome = EventOutcome( text_key="event_response_key", actions=[destroy_bean_action]) pour_potion_bean_event = Event(event_id=3003, attributes=0x0, match=pour_potion_bean_event_match, outcome=pour_potion_bean_event_outcome) self.data.get_events.side_effect = lambda x: { (self.pour_command, self.potion, self.bean): [pour_potion_bean_event], }.get(x) self.player.has_completed_event.return_value = True self.lighthouse_location.add(self.bean) response = self.resolver.resolve_event(self.pour_command, self.player, self.potion, self.bean) self.assertEqual((True, [], [self.potion, self.bean], []), response) self.assertTrue(self.lighthouse_location.contains(self.bean))