예제 #1
0
def explore(area_location: Place, npc: NPC = None, item: Item = None):

    player = Player.current()

    if player.place != area_location:
        Message.error("You are not at the area '%s'" % area_location)
        return False

    if (npc and npc.place != area_location) or (item and
                                                item.place != area_location):
        Message.error("What you're looking for, is not here")
        return False

    # check if player knows the location
    results = PlayerKnowledgeBook.select().join(Intel)\
        .where(PlayerKnowledgeBook.player == player, Intel.place_location == area_location).limit(1)
    if not results:
        Message.debug(
            "Location %s unknown (Intel not found in player's knowledge book)"
            % area_location)
        Message.error("Location %s is unknown" % area_location)
        return False

    # update Player's location
    player.place = area_location
    player.save()

    if npc:
        target = npc
    elif item:
        target = item
    else:
        target = ''

    Message.achievement("You have found '%s' by exploring '%s'" %
                        (target, area_location))

    if npc:
        # find npc for player (give npc place intel to player)
        intel = Intel.construct(npc_place=npc)
    elif item:
        intel = Intel.construct(item_place=item)
    else:
        intel = None
    if intel:
        PlayerKnowledgeBook.get_or_create(player=player, intel=intel)
        Message.achievement("Intel '%s' learned" % intel.detail())

    return True
예제 #2
0
 def save(self, force_insert=False, only=None):
     if self.id is not None:
         for dirty in self.dirty_fields:
             if isinstance(dirty, ForeignKeyField) \
                     and dirty.rel_model == Place:
                 try:
                     old_place = NPC.get_by_id(self.id).place
                 except:
                     old_place = None
                 if old_place != self.place:
                     # remove npc_place knowledge from every player's knowledge book
                     from World.Types.Intel import Intel
                     from World.Types.BridgeModels import PlayerKnowledgeBook
                     results = PlayerKnowledgeBook.select().join(Intel).where(Intel.npc_place == self.id)
                     for res in results:
                         res.delete_instance()
     super(NPC, self).save()
예제 #3
0
def goto(destination: Place):

    player = Player.current()

    # check if player knows the location
    results = PlayerKnowledgeBook.select().join(Intel)\
        .where(PlayerKnowledgeBook.player == player, Intel.place_location == destination).limit(1)
    if not results:
        Message.error("Location '%s' is unknown" % destination)
        return False

    # update Player's location
    player.place = destination
    player.save()

    Message.achievement("Player went to '%s'" % destination)
    return True