Esempio n. 1
0
def take_loot(item_to_take: Item, loot_npc: NPCDead = None):

    player = Player.current()

    # check if the item belongs to dead
    if not loot_npc:
        # NPC confirmed dead already, object among dead is given
        try:
            holder = item_to_take.belongs_to
        except:
            # holder not found = dead
            Message.debug("Item '%s' holder is dead")
            holder = None

        if holder:
            # holder is alive
            return take(item_to_take, item_holder=holder)

    # remove item from holder's belongings and add to player's
    item_to_take.belongs_to = None
    item_to_take.belongs_to_player = player
    item_to_take.save()

    # FavoursBook.construct(item_holder, -item_to_take.worth_(), player)

    Message.achievement("Item '%s' has taken by looting" % item_to_take)
    return True
Esempio n. 2
0
def give(item: Item, receiver: NPC):

    # check if player has the item
    player = Player.current()
    if item.belongs_to_player != player:
        Message.error("You don't have the item (%s) to give" % item)
        return False

    # check if player is at receiver's location
    if player.place != receiver.place:
        Message.debug("Player is not at the receiver NPC (%s) location (%s)" %
                      (receiver, receiver.place))
        Message.error("You are not at the receiver's (%s) location" % receiver)
        return False

    # check if player know where the receiver is
    if not PlayerKnowledgeBook.get_or_none(
            player=player, intel=Intel.construct(npc_place=receiver)):
        Message.debug("Player does not know where the NPC (%s) is located" %
                      receiver)
        Message.error("Player does not know where the NPC is located")
        return False

    item.belongs_to_player = None
    item.belongs_to = receiver
    item.save()

    # update favours book
    FavoursBook.construct(npc=receiver,
                          owe_factor=item.worth_(),
                          player=player)

    Message.achievement("Item '%s' has been given to the NPC '%s'" %
                        (item, receiver))
    return True
Esempio n. 3
0
def gather(item_to_gather: Item):

    player = Player.current()

    # check if player is at item location
    if item_to_gather.place != player.place:
        Message.debug(
            "Player is not at the item '%s's location (%s) to gather it" %
            (item_to_gather, item_to_gather.place))
        Message.error("You are not at the item '%s's location to gather it" %
                      item_to_gather)
        return False

    # check if player know where the item is
    if not PlayerKnowledgeBook.get_or_none(
            player=player, intel=Intel.construct(item_place=item_to_gather)):
        Message.debug("Player does not know where the item (%s) is located" %
                      item_to_gather)
        Message.error("Player does not know where the item is located")
        return False

    # update Player's belongings
    item_to_gather.belongs_to_player = player
    item_to_gather.save()

    Message.achievement("Item '%s' gathered" % item_to_gather)
    return True
Esempio n. 4
0
def exchange(item_holder: NPC, item_to_give: Item, item_to_take: Item):

    player = Player.current()

    # check if player has the item_to_give and holder has the item_to_take
    if item_to_give.belongs_to_player != player:
        Message.debug("item_to_give: '%s', belongs_to_player: '%s'" %
                      (item_to_give, item_to_give.belongs_to_player))
        return False
    if item_to_take.belongs_to != item_holder:
        Message.debug(
            "item_to_take: '%s', belongs_to: '%s', item_holder: '%s'" %
            (item_to_take, item_to_give.belongs_to, item_holder))
        return False

    # check if player is at item_holder's place_location
    if item_holder.place != player.place:
        Message.debug(
            "Player is not at the item_holder (%s) place_location (%s)" %
            (item_holder, item_holder.place))
        Message.error("You are not at the item holder (%s) location" %
                      item_holder)
        return False

    # check if player know where the receiver is
    if not PlayerKnowledgeBook.get_or_none(
            player=player, intel=Intel.construct(npc_place=item_holder)):
        Message.debug("Player does not know where the NPC (%s) is located" %
                      item_holder)
        Message.error("Player does not know where the NPC is located")
        return False

    # update Player's belongings
    item_to_take.belongs_to = None
    item_to_take.belongs_to_player = player
    item_to_take.save()

    item_to_give.belongs_to_player = None
    item_to_give.belongs_to = item_holder
    item_to_give.save()

    npc_owing = item_to_give.worth_() - item_to_take.worth_()
    FavoursBook.construct(item_holder, npc_owing, player)

    Message.achievement("Item '%s' exchanged for '%s', with NPC '%s'" %
                        (item_to_give, item_to_take, item_holder))
    return True
def get_1(item_to_fetch: Item):

    # if not, add it to player's belongings
    item_to_fetch.belongs_to_player = Player.current()
    item_to_fetch.save()

    Message.event("Item '%s' acquired" % item_to_fetch)
    return []
Esempio n. 6
0
def take(item_to_take: Item, item_holder: NPC = None):

    if item_holder is None:
        return take_loot(item_to_take)

    player = Player.current()

    # check if NPC has the item
    if item_to_take.belongs_to != item_holder:
        Message.debug(
            "NPC '%s' doesn't have the item '%s' to give. It belongs to '%s'" %
            (item_holder, item_to_take, item_to_take.belongs_to))
        Message.error("NPC '%s' doesn't have the item '%s' to give" %
                      (item_holder, item_to_take))
        return False

    # check if player is at item_holder's place_location
    if item_holder.place != player.place:
        Message.debug(
            "Player is not at the item_holder (%s) place_location (%s)" %
            (item_holder, item_holder.place))
        Message.error("You are not at the NPC '%s's location" % item_holder)
        return False

    # check if player know where the receiver is
    if not PlayerKnowledgeBook.get_or_none(
            player=player, intel=Intel.construct(npc_place=item_holder)):
        Message.debug("Player does not know where the NPC (%s) is located" %
                      item_holder)
        Message.error("Player does not know where the NPC is located")
        return False

    # remove item from holder's belongings and add to player's
    item_to_take.belongs_to = None
    item_to_take.belongs_to_player = player
    item_to_take.save()

    FavoursBook.construct(item_holder, -item_to_take.worth_(), player)

    Message.achievement("Item '%s' taken" % item_to_take)
    return True
Esempio n. 7
0
def read(intel: Intel, readable: Item):

    # check if the readable has the intel
    if not ReadableKnowledgeBook.get_or_none(
            ReadableKnowledgeBook.intel == intel,
            ReadableKnowledgeBook.readable == readable):
        Message.debug(
            "Readable '%s' does not contain the intel '%s', ReadableKnowledgeBook not found"
            % (readable, intel))
        Message.error(
            "Readable '%s' does not contain the intel player looking for" %
            readable)
        return False

    player = Player.current()
    # check if player owns the readable
    if readable.belongs_to_player != player:
        Message.debug("Player doesn't have the readable '%s'" % readable)
        if readable.place_() == player.place:
            readable.belongs_to = None
            readable.belongs_to_player = player
            readable.save()
            Message.debug(
                "Player didn't own the readable (%s) but at its place so he take it"
                % readable)
        else:
            Message.debug(
                "Player neither own the readable (%s), nor at the item's place_location (%s)"
                % (readable, readable.place_()))
            Message.error(
                "You neither own the readable (%s), nor are at the item's location"
                % readable)
            return False

    # update Player's intel
    NarrativeHelper.add_intel(intel)

    Message.achievement("By reading '%s', intel '%s' has been learned" %
                        (readable, intel.detail()))
    return True