Exemplo n.º 1
0
def report(intel: Intel, target: NPC):

    player = Player.current()

    # check if player has the intel
    if not PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
        Message.error("You don't have the intel '%s'" % intel)
        return False

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

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

    # update Player's favours book if target hasn't have it already
    if not NPCKnowledgeBook.get_or_none(npc=target, intel=intel):
        FavoursBook.construct(target, intel.worth_())
        # update target's intel list
        NPCKnowledgeBook.create(npc=target, intel=intel)

    Message.achievement("Intel '%s' reported to the NPC '%s'" %
                        (intel.detail(), target))
    return True
Exemplo n.º 2
0
def spy(spy_on: NPC, intel_target: Intel):

    player = Player.current()

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

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

    # check if the target has the piece of intel
    if not NPCKnowledgeBook.get_or_none(npc=spy_on, intel=intel_target):
        Message.debug(
            "Target (%s) does not have the intel (%s) player wanted" %
            (spy_on, intel_target))
        Message.error(
            "Target (%s) does not have the intel (%s) player wanted" %
            (spy_on, intel_target))
        return False

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

    Message.achievement("Intel '%s' gathered by spying on '%s'" %
                        (intel_target.detail(), spy_on))
    return True
Exemplo n.º 3
0
def listen(intel: Intel, informer: NPC):

    # check if informer has the intel
    if not NPCKnowledgeBook.get_or_none(intel=intel, npc=informer):
        Message.error("Informer doesn't have the intel (%s) player wants" %
                      intel)
        return False

    player = Player.current()

    # check if player is in the informer place_location
    if informer.place != player.place:
        Message.error("You are not at the informer's (%s) location" % informer)
        return False

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

    # update Player's intel
    NarrativeHelper.add_intel(intel)
    FavoursBook.construct(informer, -intel.worth_(), player)

    Message.achievement("Intel '%s' acquired by listening to '%s'" %
                        (intel.detail(), informer))
    return True
Exemplo n.º 4
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
Exemplo n.º 5
0
def use(item_to_use: Item, target: NPC):

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

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

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

    item_to_use.use(npc=target)

    # depending on positive or negative impact_factor of the item usage, target record in player's favour gets updated
    FavoursBook.construct(target, float(item_to_use.impact_factor or 0.0))

    Message.achievement("Item '%s' used on the '%s'" % (item_to_use, target))
    return True
Exemplo n.º 6
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
Exemplo n.º 7
0
def damage(target: NPC):

    player = Player.current()

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

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

    target.health_meter -= 0.3
    if target.health_meter <= 0:
        return kill(target)
    else:
        Message.debug("NPC '%s' has been damaged, current health meter: %s" %
                      (target, target.health_meter))
        Message.achievement("NPC '%s' has been damaged" % target)
        target.save()

    return True
def goto_2(destination: Place, npc: NPC = None, item: Item = None):
    """
    Explore destination to find npc or item
    :return:
    """
    # place_location[1] is destination
    # area around location[1] is given to player to explore and find location[1]
    player = Player.current()

    # ensure player doesn't already know where the NPC or item is
    if npc:
        intel = Intel.construct(npc_place=npc)
        if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
            # player knows where the NPC is, move the NPC then
            npc.place = Place.select().where(Place.id != destination).order_by(
                fn.Random()).get()
            npc.save()
            destination = npc.place
            Message.event(
                "You just missed '%s' he has moved to somewhere else" % npc)
    elif item:
        intel = Intel.construct(item_place=item)
        if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
            # player knows where the Item is, move the item or item's holder
            if item.belongs_to:
                holder = item.belongs_to
                holder.place = Place.select().where(
                    Place.id != destination).order_by(fn.Random()).get()
                holder.save()
                destination = holder.place
                Message.event(
                    "Item '%s's holder just has been moved to somewhere else" %
                    item)
            else:
                item.place = Place.select().where(
                    Place.id != destination).order_by(fn.Random()).get()
                item.save()
                destination = item.place
                Message.event(
                    "Item '%s' just has been moved to somewhere else" % item)

    # steps:
    # T.explore
    steps = [[destination, npc, item]]
    Message.instruction("Explore around '%s'" % destination)
    return steps
Exemplo n.º 9
0
def talk(npc: NPC):
    player = Player.current()
    if player.place != npc.place:
        Message.error("You are not at the NPC '%s's place, can't talk to him" %
                      npc)
        return False

    if not PlayerKnowledgeBook.get_or_none(
            player=player, intel=Intel.construct(npc_place=npc)):
        Message.error("NPC '%s's current location is unknown" % npc)
        return False

    Message.achievement("Talking to '%s'" % npc)
    return True
Exemplo n.º 10
0
def explore(area_location: Place, npc: NPC, item: Item):
    player = Player.current()

    if npc:
        intel = Intel.construct(npc_place=npc)
    elif item:
        intel = Intel.construct(item_place=item)
    else:
        intel = None

    if intel and not PlayerKnowledgeBook.get_or_none(player=player,
                                                     intel=intel):
        return False

    return player.place == area_location
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
0
def stealth(target: NPC):

    player = Player.current()

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

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

    Message.achievement("Successfully snuck on '%s'" % target)
    return True
Exemplo n.º 14
0
def kill(target: NPC):

    player = Player.current()

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

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

    NPCDead.create(name=target.name, place=target.place, clan=target.clan)

    Message.achievement("NPC '%s' has been killed" % target)
    target.delete_instance(recursive=True)
    return True
Exemplo n.º 15
0
def goto_3(destination: Place, npc: NPC = None, item: Item = None):
    """
    Find out where to go and go there.
    :return:
    """
    # place_location[1] is destination
    # location[1] is place_location[1] exact location
    player = Player.current()

    # find correct type of Intel from npc_place, item_place and place_location
    if npc:
        intel = Intel.get_or_none(type=IntelTypes.npc_place.name,
                                  npc_place=npc)
        if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
            # player already knows, move the npc
            destination = Place.select().where(Place.id != npc.place).order_by(
                fn.Random())
            if destination:
                destination = destination.get()
            else:
                destination = narrative_helper.create_place()
            npc.place = destination
            npc.save()
            # by moving NPC place, npc_place intel removes from player knowledge book automatically
            Message.event("NPC %s has moved to somewhere else" % npc)
    elif item:
        if item.belongs_to:
            intel = Intel.get_or_none(type=IntelTypes.npc_place.name,
                                      npc_place=item.belongs_to)
            if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
                # player already knows where the item holder is, move the npc
                holder = item.belongs_to
                destination = Place.select().where(
                    Place.id != holder.place).order_by(fn.Random())
                if destination:
                    destination = destination.get()
                else:
                    destination = narrative_helper.create_place()
                holder.place = destination
                holder.save()
                Message.debug(
                    "Item holder (%s) is moved somewhere else (item: %s)" %
                    (item.belongs_to, item))
                Message.event(
                    "Item '%s's holder has been just moved to somewhere else" %
                    item)
        else:
            intel = Intel.get_or_none(type=IntelTypes.item_place.name,
                                      item_place=item)
            if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
                # player already knows where the item is located at, move the item
                destination = Place.select().where(
                    Place.id != item.place).order_by(fn.Random())
                if destination:
                    destination = destination.get()
                else:
                    destination = narrative_helper.create_place()
                item.place = destination
                item.save()
                Message.event("Item '%s' has been misplaced" % item)
    else:
        intel = Intel.get_or_none(type=IntelTypes.location.name,
                                  place_location=destination)
        if PlayerKnowledgeBook.get_or_none(player=player, intel=intel):
            # player already knows where the place is exactly,
            # so create a new place at the same location with a different name, now player doesn't know!
            destination = Place.create(name=PlaceName.fetch_new(),
                                       x=destination.x,
                                       y=destination.y)
            intel = Intel.construct(place_location=destination)
            Message.event("Change of plans, destination is now '%s'" %
                          destination)

    if not intel:
        # create the correct type of intel based on what is being asked
        if npc:
            intel = Intel.construct(npc_place=npc)
        elif item and item.belongs_to:
            intel = Intel.construct(npc_place=item.belongs_to)
        elif item:
            intel = Intel.construct(item_place=item)
        else:
            intel = Intel.construct(place_location=destination)

    # update player's next location
    player.next_location = destination
    player.save()

    # steps:
    #   learn: location[1]
    #   T.goto: location[1]
    steps = [[intel], [destination]]

    if PlayParams.debug_mode and (npc or item):
        destination_str = str(npc if npc else item) + ' (' + str(
            destination) + ')'
    else:
        if npc:
            destination_str = npc
        elif item:
            destination_str = item
        else:
            destination_str = destination

    Message.instruction("Find out how to get to '%s' location, then go to it" %
                        destination_str)

    return steps
Exemplo n.º 16
0
def listen(intel: Intel, informer: NPC):
    player = Player.current()

    return PlayerKnowledgeBook.get_or_none(player=player,
                                           intel=intel) is not None
Exemplo n.º 17
0
def read(intel: Intel, readable: Item):
    player = Player.current()

    return PlayerKnowledgeBook.get_or_none(player=player,
                                           intel=intel) is not None
Exemplo n.º 18
0
def spy(spy_on: NPC, intel_target: Intel):
    player = Player.current()

    return PlayerKnowledgeBook.get_or_none(player=player,
                                           intel=intel_target) is not None