コード例 #1
0
def learn_1(required_intel: Intel):
    """
    You already know it.
    :param required_intel:
    :return:
    """
    player = Player.current()
    # update player intel
    PlayerKnowledgeBook.get_or_create(player=player, intel=required_intel)

    if (required_intel.npc_place or
            required_intel.item_place) and not required_intel.place_location:
        # if player knows an NPC's place but doesn't know the location of that place, add the location too
        if required_intel.npc_place:
            place = required_intel.npc_place.place
        else:
            place = required_intel.item_place.place
        if not place:
            Message.debug("Error! npc_place or item_place are empty")

        PlayerKnowledgeBook.get_or_create(
            player=player, intel=Intel.construct(place_location=place))

    Message.event("Intel '%s' discovered" % required_intel.detail())
    return [[]]
コード例 #2
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
コード例 #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
コード例 #4
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
コード例 #5
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