コード例 #1
0
ファイル: test_events.py プロジェクト: clckwrkbdgr/dotfiles
 def should_post_event_to_queue(self):
     channel_name = self._channel_name()
     Events(channel_name).trigger('test')
     self.assertEqual(Events(channel_name).pending(), 1)
     event = Events(channel_name).listen()
     self.assertEqual(event, 'test')
     self.assertEqual(Events(channel_name).pending(), 0)
コード例 #2
0
    def get_new_messages(self):
        process_game_events(self.data, self.data.history)
        del self.data.history[:]

        events = Events()
        while events.listen():
            trace.debug("Message posted: {0}: {1}".format(
                repr(events.current), str(events.current)))
            yield events.current
コード例 #3
0
 def descend(self):
     """ Go down. """
     dungeon = self.data
     stairs_here = next(
         filter(
             lambda obj: isinstance(obj, LevelPassage) and obj.can_go_down,
             dungeon.current_level.objects_at(dungeon.rogue.pos)), None)
     if stairs_here:
         dungeon.use_stairs(stairs_here)
         Events().trigger(GoingDown())
         return to_main_screen(self)
     else:
         Events().trigger(CannotDig())
コード例 #4
0
 def on_item(self, item):
     new_state = not getattr(self.data.god, item.data)
     setattr(self.data.god, item.data, new_state)
     Events().trigger(
         GodModeSwitched(name=item.text,
                         state='ON' if new_state else 'off'))
     return to_main_screen(self)
コード例 #5
0
 def take_off(self):
     """ Take item off. """
     dungeon = self.data
     if not dungeon.rogue.wearing:
         Events().trigger(NothingToTakeOff())
     else:
         self.data.history += dungeon.rogue.wear(None)
コード例 #6
0
 def wear(self):
     """ Wear item. """
     dungeon = self.data
     if not dungeon.rogue.inventory:
         Events().trigger(InventoryEmpty())
     else:
         return QuickWearItem(to_main_screen(self), self.data)
コード例 #7
0
 def unwield(self):
     """ Unwield item. """
     dungeon = self.data
     if not dungeon.rogue.wielding:
         Events().trigger(NothingToUnwield())
     else:
         self.data.history += dungeon.rogue.wield(None)
コード例 #8
0
 def eat(self):
     """ Consume item. """
     dungeon = self.data
     if not dungeon.rogue.inventory:
         Events().trigger(InventoryEmpty())
     else:
         return QuickConsumeItem(to_main_screen(self), self.data)
コード例 #9
0
 def drop(self):
     """ Drop item. """
     dungeon = self.data
     if not dungeon.rogue.inventory:
         Events().trigger(InventoryEmpty())
     else:
         return QuickDropItem(to_main_screen(self), self.data)
コード例 #10
0
 def ascend(self):
     """ Go up. """
     dungeon = self.data
     stairs_here = next(
         filter(lambda obj: isinstance(obj, LevelPassage) and obj.can_go_up,
                dungeon.current_level.objects_at(dungeon.rogue.pos)), None)
     if stairs_here:
         try:
             dungeon.use_stairs(stairs_here)
             Events().trigger(GoingUp())
             return to_main_screen(self)
         except Furniture.Locked:
             Events().trigger(NeedMcGuffin())
         except GameCompleted:
             return Greetings
     else:
         Events().trigger(CannotReachCeiling())
コード例 #11
0
 def grab(self):
     """ Grab item. """
     dungeon = self.data
     item_here = next((index for index, (
         pos, item) in enumerate(reversed(dungeon.current_level.items))
                       if pos == dungeon.rogue.pos), None)
     trace.debug("Items: {0}".format(dungeon.current_level.items))
     trace.debug("Rogue: {0}".format(dungeon.rogue.pos))
     trace.debug("Items here: {0}".format([
         (index, pos, item) for index, (
             pos, item) in enumerate(reversed(dungeon.current_level.items))
         if pos == dungeon.rogue.pos
     ]))
     trace.debug("Item here: {0}".format(item_here))
     if item_here is not None:
         item_here = len(dungeon.current_level.items
                         ) - 1 - item_here  # Index is from reversed list.
         trace.debug("Unreversed item here: {0}".format(item_here))
         _, item = dungeon.current_level.items[item_here]
         self.data.history += dungeon.current_level.grab_item(
             dungeon.rogue, item)
         self.step_is_over = True
     else:
         Events().trigger(NothingToPickUp())
コード例 #12
0
ファイル: test_events.py プロジェクト: clckwrkbdgr/dotfiles
 def should_detect_empty_queue(self):
     channel_name = self._channel_name()
     self.assertEqual(Events(channel_name).pending(), 0)
     event = Events(channel_name).listen()
     self.assertIsNone(event)
コード例 #13
0
def process_game_events(dungeon, events):
    for event in events:
        if isinstance(event, Event.BumpIntoTerrain):
            if event.who != dungeon.rogue:
                Events().trigger(BumpsIntoWall(Who=event.who.name.title()))
        elif isinstance(event, Event.BumpIntoMonster):
            Events().trigger(
                BumpsIntoOther(Who=event.who.name.title(),
                               whom=event.whom.name))
        elif isinstance(event, Event.AttackMonster):
            Events().trigger(
                Attacking(Who=event.who.name.title(),
                          whom=event.whom.name,
                          damage=event.damage))
        elif isinstance(event, Event.MonsterDied):
            Events().trigger(IsDead(Who=event.who.name.title()))
        elif isinstance(event, Event.MonsterDroppedItem):
            Events().trigger(
                DropsItem(Who=event.who.name.title(), item=event.item.name))
        elif isinstance(event, Event.MonsterConsumedItem):
            Events().trigger(ItemConsumed(item=event.item.name))
        elif isinstance(event, Event.Unwielding):
            Events().trigger(Unwielding(item=event.item.name))
        elif isinstance(event, Event.TakingOff):
            Events().trigger(TakingOff(item=event.item.name))
        elif isinstance(event, Event.Wielding):
            Events().trigger(Wielding(item=event.item.name))
        elif isinstance(event, Event.Wearing):
            Events().trigger(Wearing(item=event.item.name))
        elif isinstance(event, Event.NotWearable):
            Events().trigger(CannotWear(item=event.item.name))
        elif isinstance(event, Event.NotConsumable):
            Events().trigger(CannotConsume(item=event.item.name))
        elif isinstance(event, Event.WelcomeBack):
            trace.debug(event)
            Events().trigger(WelcomeBack(who=event.who.name))
        elif isinstance(event, Event.InventoryFull):
            Events().trigger(InventoryFull(item=event.item.name))
        elif isinstance(event, Event.GrabbedItem):
            Events().trigger(
                GrabbedItem(who=event.who.name, item=event.item.name))
コード例 #14
0
 def consume_by(self, who):
     who.heal(10)
     Events().trigger(DrinksHealingPotion(Who=who.name.title()))
     return True