예제 #1
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
예제 #2
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
예제 #3
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