Пример #1
0
    def test_resolve_event_with_location_prerequisite_without_match(self):
        prerequisite_kind = EventMatchPrerequisiteKind.LOCATION
        prerequisite_location = self.lighthouse_location
        prerequisite = LocationEventMatchPrerequisite(prerequisite_kind, False,
                                                      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.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))
Пример #2
0
    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))
Пример #3
0
    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))
Пример #4
0
    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)
Пример #5
0
    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)
Пример #6
0
    def parse_event_outcome_actions(self, event_outcome_action_inputs,
                                    items_by_id, locations_by_id):
        if not event_outcome_action_inputs:
            return []

        actions = []

        for event_outcome_action_input in event_outcome_action_inputs:
            kind_key = event_outcome_action_input["kind"].upper()
            kind = EventOutcomeActionKind[kind_key]

            if kind == EventOutcomeActionKind.PLAYER:
                attribute = int(event_outcome_action_input["attribute"], 16)
                on = event_outcome_action_input["on"]

                action = PlayerEventOutcomeAction(kind=kind,
                                                  attribute=attribute,
                                                  on=on)
                actions.append(action)

            elif kind == EventOutcomeActionKind.ITEM:
                item_id = event_outcome_action_input["item_id"]
                item = items_by_id[item_id]
                destination = self.parse_item_event_outcome_action_destination(
                    event_outcome_action_input["destination"], items_by_id,
                    locations_by_id)

                action = ItemEventOutcomeAction(kind=kind,
                                                item=item,
                                                destination=destination)
                actions.append(action)

            elif kind == EventOutcomeActionKind.LOCATION:
                location_id = event_outcome_action_input["location_id"]
                location = locations_by_id[location_id]
                attribute = int(event_outcome_action_input["attribute"], 16)
                on = event_outcome_action_input["on"]

                action = LocationEventOutcomeAction(kind=kind,
                                                    location=location,
                                                    attribute=attribute,
                                                    on=on)
                actions.append(action)

            elif kind == EventOutcomeActionKind.LINK:
                source_id = event_outcome_action_input["source_id"]
                source = locations_by_id[source_id]

                direction_key = event_outcome_action_input["direction"].upper()
                direction = Direction[direction_key]

                destination = None
                destination_id = event_outcome_action_input.get(
                    "destination_id")
                if destination_id:
                    destination = locations_by_id[destination_id]

                action = LinkEventOutcomeAction(kind=kind,
                                                source=source,
                                                direction=direction,
                                                destination=destination)
                actions.append(action)

            elif kind == EventOutcomeActionKind.DESCRIPTION:
                data_id = event_outcome_action_input["data_id"]
                named_data_element = locations_by_id.get(data_id)
                if not named_data_element:
                    named_data_element = items_by_id.get(data_id)

                extended_description_index = event_outcome_action_input[
                    "extended_description_index"]

                action = DescriptionEventOutcomeAction(
                    kind=kind,
                    named_data_element=named_data_element,
                    extended_description_index=extended_description_index)
                actions.append(action)

        return actions