Ejemplo n.º 1
0
def capture_1(target: NPC):
    """
    Get something, go someplace and use it to capture somebody
    :param target:
    :return:
    """
    item_to_fetch = Item.get_or_none(type=ItemTypes.tool.name,
                                     usage=T.capture.value)
    if not item_to_fetch:
        # No item usable for capture, left in the world
        item_to_fetch = Item.create(
            name='arbitrary_capture_tool_' + str(randint(100, 999)),
            type=ItemTypes.tool.name,
            usage=T.capture.value,
            generic=GenericItem.get_or_create(
                name=ItemTypes.singleton.name)[0],
            place=Place.select().order_by(fn.Random()).get(),
            impact_factor=1.0,
            worth=0.75)
        Message.debug(
            "No item usable for 'capture' left in the world, create a new one '%s'"
            % item_to_fetch)

    # steps:
    # get
    # goto
    # T.capture
    steps = [[item_to_fetch], [target.place, target], [target]]
    Message.instruction("Get '%s', then goto '%s' and capture '%s'" %
                        (item_to_fetch, target, target))
    return steps
Ejemplo n.º 2
0
def comfort_1(motivated: NPC) -> list:
    """
    Obtain luxuries for the motivated NPC
    :param motivated:
    :return:
    """
    # get item useful for motivated

    needed_item = Item.select().join(Need).where(Need.npc == motivated, Item.belongs_to_player.is_null())\
        .order_by(fn.Random()).limit(1)
    if needed_item:
        # motivated NPC need some items
        item = needed_item[0]
    else:
        # motivated NPC doesn't have any needs
        items_in_world = Item.select().where(
            Item.belongs_to_player.is_null()).order_by(
                Item.worth.desc()).limit(1)
        if items_in_world:
            item = items_in_world[0]
        else:
            # item not found in the world
            place = Place.select().order_by(fn.Random()).limit(1)
            if place:
                place = place[0]
            else:
                Message.debug("No place found in the World!")
                place = helper.create_place()
            item = Item.create(type=ItemTypes.unknown.name,
                               generic=GenericItem.get_or_create(
                                   name=ItemTypes.singleton.name)[0],
                               name='arbitrary_item_' + str(randint(100, 999)),
                               place=place,
                               worth=1)
            Message.debug("No Item found in the world, item created: %s" %
                          item)

    # steps:
    #   get
    #   goto
    #   give
    steps = [[item], [motivated.place, motivated], [item, motivated]]

    Message.instruction("%s: Get luxury item '%s' for me" % (motivated, item))
    return steps
Ejemplo n.º 3
0
def conquest_2(motivated: NPC) -> list:
    """
    Steal stuff
    :param motivated:
    :return:
    """
    # find something an enemy to motivated has
    item = None
    enemy_ids = NPC.select(NPC.id).where(NPC.clan != motivated.clan)
    if enemy_ids:
        items = Item.select().where(Item.belongs_to.in_(enemy_ids)).order_by(
            fn.Random()).limit(1)
        if items:
            item = items[0]

    if not item:
        place = Place.select().order_by(fn.Random()).limit(1)
        if place:
            place = place[0]
        else:
            Message.debug("No place found in the World!")
            place = helper.create_place()
        enemy_clan = Clan.select().where(Clan.id != motivated.clan).order_by(
            fn.Random()).limit(1).get()
        target = NPC.create(clan=enemy_clan,
                            name=NPCName.fetch_new(),
                            place=place)
        item = Item.create(type=ItemTypes.singleton.name,
                           generic=GenericItem.get_or_create(
                               name=ItemTypes.singleton.name)[0],
                           name='arbitrary_item_' + str(randint(100, 999)),
                           belongs_to=target)

    # steps
    #   goto
    #   steal
    #   goto
    #   give
    steps = [[item.place_(), None, item], [item, item.belongs_to],
             [motivated.place, motivated], [item, motivated]]
    Message.instruction("%s: Steal item '%s' from '%s' for me" %
                        (motivated, item, item.belongs_to))
    return steps
Ejemplo n.º 4
0
def serenity_5(motivated: NPC) -> list:
    """
    Check on NPC(2)
    :param motivated:
    :return:
    """
    # find ally NPC to motivated get an item from he/she
    allies = NPC.select().where(NPC.clan == motivated.clan,
                                NPC.id != motivated).order_by(
                                    fn.Random()).limit(1)
    if allies:
        target = allies[0]
    else:
        place = Place.select().order_by(fn.Random()).limit(1)
        if place:
            place = place[0]
        else:
            Message.debug("No place found in the World!")
            place = helper.create_place()
        target = NPC.create(clan=motivated.clan,
                            name=NPCName.fetch_new(),
                            place=place)

    belongings = Item.select().where(Item.belongs_to == target.id).order_by(
        fn.Random()).limit(1)
    if belongings:
        item = belongings[0]
    else:
        item = Item.create(type=ItemTypes.singleton.name,
                           generic=GenericItem.get_or_create(
                               name=ItemTypes.singleton.name)[0],
                           name='arbitrary_item_' + str(randint(100, 999)),
                           belongs_to=target)
    # steps
    #   goto
    #   take
    #   goto
    #   give
    steps = [[target.place, target], [item, target],
             [motivated.place, motivated], [item, motivated]]
    Message.instruction("%s: Get item '%s' from my friend, '%s' for me" %
                        (motivated, item, target))
    return steps
Ejemplo n.º 5
0
def knowledge_1(NPC_target: NPC):
    """
    Deliver item for study
    :param NPC_target:
    :return:
    """
    player = Player.current()
    results = Item.select().where(Item.belongs_to != NPC_target,
                                  Item.belongs_to_player != player)
    if results:
        locations_scores = [player.distance(res.place_()) for res in results]
        results = sort_by_list(results, locations_scores)
        item = results[0]
    else:
        results = NPC.select().where(NPC.id != NPC_target)
        if results:
            locations_scores = [player.distance(res.place) for res in results]
            results = sort_by_list(results, locations_scores)
            new_item_holder = results[0]
        else:
            # No NPC left in the world except the target
            new_item_holder = NPC.create(
                place=Place.select().order_by(fn.Random()).get(),
                clan=Clan.select().order_by(fn.Random()).get(),
                name=NPCName.fetch_new())
        item = Item.create(type=ItemTypes.unknown.name,
                           generic=GenericItem.get_or_create(
                               name=ItemTypes.singleton.name)[0],
                           name='arbitrary_item_unknown_' +
                           str(randint(100, 999)),
                           place=None,
                           belongs_to=new_item_holder)

    # steps:
    #   get item
    #   goto target place
    #   give item to target
    steps = [[item], [NPC_target.place, NPC_target], [item, NPC_target]]
    Message.instruction("%s: Get item '%s' for me, I want to study it" %
                        (NPC_target, item))
    return steps
Ejemplo n.º 6
0
def reputation_1(motivated: NPC) -> list:
    """
    Obtain rare items
    :param motivated:
    :return:
    """
    # find high worth item

    worthy_item = Item.select().where(
        Item.belongs_to_player.is_null()).order_by(Item.worth.desc()).limit(1)
    if worthy_item:
        # item found for NPC
        item = worthy_item[0]
    else:
        # item not found in the world
        place = Place.select().order_by(fn.Random()).limit(1)
        if place:
            place = place[0]
        else:
            Message.debug("No place found in the World!")
            place = helper.create_place()
        item = Item.create(type=ItemTypes.unknown.name,
                           generic=GenericItem.get_or_create(
                               name=ItemTypes.singleton.name)[0],
                           name='arbitrary_item_' + str(randint(100, 999)),
                           place=place,
                           worth=1)
        Message.debug("No Item found in the world, item created: %s" % item)

    # steps:
    #   get
    #   goto
    #   give
    steps = [[item], [motivated.place, motivated], [item, motivated]]

    Message.instruction("%s: Get the rare item '%s' for me" %
                        (motivated, item))
    return steps
Ejemplo n.º 7
0
def protection_2(NPC_protection_motivated: NPC) -> list:
    # find an NPC, who is ally to motivated_NPC and needs something, as well as an NPC who has that thing
    # and that need is not part of an exchange
    results = NPC.select(NPC, Need.item_id.alias('needed_item_id'))\
        .join(Need) \
        .join(Exchange, JOIN.LEFT_OUTER)\
        .where(
            NPC.clan == NPC_protection_motivated.clan,
            Need.item.is_null(False),
        )\
        .group_by(Need)\
        .having(fn.COUNT(Exchange.id) == 0)\
        .objects()

    if not results:
        # select any kind of need including an exchange need
        results = NPC.select(NPC, Need.item_id.alias('needed_item_id'))\
            .join(Need) \
            .where(
                NPC.clan == NPC_protection_motivated.clan,
                Need.item.is_null(False),
            )\
            .objects()

    player = Player.current()

    if results:
        # sort by distance
        locations_scores = [player.distance(res.place) for res in results]
        results = sort_by_list(results, locations_scores)
        npc_in_need = results[0]

        needed_item = Item.get_by_id(npc_in_need.needed_item_id)
        del npc_in_need.needed_item_id

    else:
        # no need found, have to create one
        # just select an ally, create a need for him
        results = NPC.select().where(NPC.clan == NPC_protection_motivated.clan)
        if not results:
            # just select an NPC, including enemies
            results = NPC.select()

        # sort by distance
        locations_scores = [player.distance(res.place) for res in results]
        results = sort_by_list(results, locations_scores)
        npc_in_need = results[0]

        # select an NPC to hold the item, enemies preferred
        holders = NPC.select().where(NPC.id != npc_in_need,
                                     NPC.clan != player.clan)
        if not holders:
            holders = NPC.select().where(NPC.id != npc_in_need)
        # sort by distance
        locations_scores = [player.distance(res.place) for res in holders]
        holders = sort_by_list(holders, locations_scores)
        holder = holders[0]

        needed_item = Item.create(type=ItemTypes.tool.name,
                                  generic=GenericItem.get_or_create(
                                      name=ItemTypes.singleton.name)[0],
                                  name='arbitrary_item_potion_' +
                                  str(randint(100, 999)),
                                  place=None,
                                  belongs_to=holder,
                                  usage=T.treat.value,
                                  impact_factor=0.5)
        Need.create(npc=npc_in_need, item=needed_item)

    # get
    # goto NPC in need
    # use
    steps = [[needed_item], [npc_in_need.place, npc_in_need],
             [needed_item, npc_in_need]]

    Message.instruction("%s: Treat my friend '%s' using '%s'" %
                        (NPC_protection_motivated, npc_in_need, needed_item))
    return steps
Ejemplo n.º 8
0
def learn_4(required_intel: Intel):
    # find an NPC who has the required intel in exchange, get the NPC's needed item to give

    if required_intel.npc_place:
        bad_needs = Need.select(Need.id).join(Item).where(
            (Need.npc == required_intel.npc_place)
            | (Item.belongs_to == required_intel.npc_place))
    elif required_intel.item_place:
        bad_needs = Need.select(
            Need.id).where(Need.item == required_intel.item_place)
    else:
        bad_needs = []

    # NPC who has the intel
    knowledgeable = NPC.select(NPC.id).join(NPCKnowledgeBook).where(
        NPC.id != required_intel.npc_place,
        NPCKnowledgeBook.intel == required_intel.id)
    exchange = None
    if knowledgeable.count():
        needs = Need.select()\
            .join(NPC)\
            .where(NPC.id.in_(knowledgeable),
                   Need.id.not_in(bad_needs),
                   Need.item_id.is_null(False))
        if needs:
            exchanges = Exchange.select().where(
                Exchange.need.in_(needs),
                Exchange.intel == required_intel.id).limit(1)
            if exchanges:
                exchange = exchanges[0]
            else:
                exchange = Exchange.create(need=needs[0], intel=required_intel)

    if not exchange:
        # no NPC has the intel or no need found
        accessible_items = Item.select().where(
            (Item.id != required_intel.item_place)
            & (Item.belongs_to_player.is_null())
            & ((Item.belongs_to.is_null())
               | Item.belongs_to != required_intel.npc_place)).order_by(
                   fn.Random()).limit(1)
        if accessible_items:
            item = accessible_items[0]
        else:
            holder = NPC.select().where(
                NPC.id != required_intel.npc_place).order_by(
                    fn.Random()).limit(1)
            if holder:
                holder = holder[0]
            else:
                holder = NPC.create(
                    name=NPCName.fetch_new(),
                    clan=Clan.select().order_by(fn.Random()).get(),
                    place=Place.select().order_by(fn.Random()).get())
            item = Item.create(name='arbitrary_item_' + str(randint(100, 999)),
                               generic=GenericItem.get_or_create(
                                   name=ItemTypes.singleton.name)[0],
                               belongs_to=holder,
                               type=ItemTypes.unknown.name)
        if knowledgeable:
            informer = knowledgeable.order_by(fn.Random()).get()
        else:
            npc = NPC.select().where(
                NPC.id != required_intel.npc_place).order_by(
                    fn.Random()).limit(1)
            if npc:
                informer = npc[0]
            else:
                informer = NPC.create(
                    name=NPCName.fetch_new(),
                    clan=Clan.select().order_by(fn.Random()).get(),
                    place=Place.select().order_by(fn.Random()).get())
            NPCKnowledgeBook.create(npc=informer, intel=required_intel)
        need = Need.create(npc=informer, item=item)
        exchange = Exchange.create(need=need, intel=required_intel)

    informer = exchange.need.npc
    item_to_get_for_exchange = exchange.need.item

    player = Player.current()
    player.next_location = informer.place
    player.save()

    intel = Intel.construct(item_place=item_to_get_for_exchange)
    PlayerKnowledgeBook.get_or_create(player=player, intel=intel)
    Message.achievement("Intel '%s' learned" % intel.detail())

    # steps:
    # get
    # sub-quest
    # give
    # listen
    steps = [[item_to_get_for_exchange], [informer.place],
             [item_to_get_for_exchange, informer], [required_intel, informer]]
    Message.instruction(
        "Get '%s', perform a sub-quest, give the acquired item to '%s' in return get an intel on '%s'"
        % (item_to_get_for_exchange, informer, required_intel))
    return steps
Ejemplo n.º 9
0
def learn_3(required_intel: Intel):
    """
    Go someplace, get something, and read what is written on it.
    :param required_intel:
    :return:
    """
    player = Player.current()
    # intel[1] is to be learned
    # find a book[1] (readable, it could be a sign) that has intel[1] on it
    results = ReadableKnowledgeBook.select()\
        .join(Item, on=(ReadableKnowledgeBook.readable == Item.id))\
        .where(ReadableKnowledgeBook.intel == required_intel,
               Item.belongs_to_player != player)

    # sort by readable place_ triangle
    locations_scores = [
        player.distance(knowledge_book.readable.place_())
        for knowledge_book in results
    ]
    results = sort_by_list(results, locations_scores)

    if results:
        book_containing_intel = results[0].readable  # type: Item
    else:
        # create an address book containing the intel player is looking for
        known_places = Place.select()\
            .join(Intel, on=(Intel.place_location == Place.id))\
            .join(PlayerKnowledgeBook, on=(PlayerKnowledgeBook.intel == Intel.id))\
            .where(PlayerKnowledgeBook.player == player)
        if known_places:
            known_place = known_places.order_by(fn.Random()).get()
        else:
            known_place = narrative_helper.create_place()

        book_containing_intel = Item.create(
            type=ItemTypes.readable.name,
            generic=GenericItem.get_or_create(
                name=ItemTypes.singleton.name)[0],
            name=ItemName.fetch_new(),
            place=known_place)
        ReadableKnowledgeBook.create(readable=book_containing_intel,
                                     intel=required_intel)
        PlayerKnowledgeBook.create(
            player=player,
            intel=Intel.construct(item_place=book_containing_intel))

    player.next_location = book_containing_intel.place_()
    player.save()

    intel = Intel.construct(item_place=book_containing_intel)
    PlayerKnowledgeBook.get_or_create(player=player, intel=intel)
    Message.achievement("Intel '%s' learned" % intel.detail())

    # steps:
    # goto: place_location[1]
    # get: book[1]
    # T.read: intel[1] from book[1]
    steps = [[book_containing_intel.place_(), None, book_containing_intel],
             [book_containing_intel], [required_intel, book_containing_intel]]
    Message.instruction("Get '%s', and read the intel '%s' from it" %
                        (book_containing_intel, required_intel))
    return steps
Ejemplo n.º 10
0
def create():
    alliance = Clan.create(name='alliance')
    horde = Clan.create(name='horde')

    beach = Place.create(name='beach', x=10, y=80)
    azshara = Place.create(name='azshara', x=50, y=50)
    cataclysm = Place.create(name='cataclysm', x=70, y=90)
    crystalsong = Place.create(name='crystalsong', x=10, y=60)
    forest = Place.create(name='forest', x=60, y=20)
    dalaran = Place.create(name='dalaran', x=80, y=85)
    feralas = Place.create(name='feralas', x=10, y=10)
    harbor = Place.create(name='harbor', x=80, y=10)
    shrine = Place.create(name='shrine', x=30, y=80)
    nagrand = Place.create(name='nagrand', x=70, y=40)
    acherus = Place.create(name='acherus', x=10, y=40)
    alcaz = Place.create(name='alcaz', x=90, y=60)

    PlaceName.create(name='hamilton')
    PlaceName.create(name='denver')
    PlaceName.create(name='munich')
    PlaceName.create(name='quebec')

    player = Player.create(name='player_1', place=beach, clan=alliance)

    qeynos = NPC.create(name='qeynos', place=azshara, clan=alliance)
    npc_2 = NPC.create(name='npc2', place=beach, clan=alliance)  # = adon
    steve = NPC.create(name='steve', place=forest, clan=alliance)
    tomas = NPC.create(name='tomas', place=feralas, clan=alliance)
    lempeck = NPC.create(name='lempeck',
                         place=harbor,
                         clan=alliance,
                         health_meter=0.7)  # = Denros
    bixies = NPC.create(name='bixies', place=cataclysm, clan=horde)
    goblin = NPC.create(name='goblin', place=dalaran, clan=horde)

    NPCName.create(name='gabriel')
    NPCName.create(name='mariah')
    NPCName.create(name='sia')
    NPCName.create(name='silva')
    NPCName.create(name='berg')
    NPCName.create(name='jessie')
    NPCName.create(name='lizzy')
    NPCName.create(name='amanda')
    NPCName.create(name='bernard')
    NPCName.create(name='monica')
    NPCName.create(name='catrina')
    NPCName.create(name='leo')
    NPCName.create(name='richard')
    NPCName.create(name='naomi')
    NPCName.create(name='aaron')

    Motivation.create(npc=steve, action=NT.knowledge.value, motive=0.6)
    Motivation.create(npc=lempeck, action=NT.comfort.value, motive=0.9)
    Motivation.create(npc=npc_2, action=NT.reputation.value, motive=0.7)
    Motivation.create(npc=goblin, action=NT.serenity.value, motive=0.7)
    Motivation.create(npc=tomas, action=NT.protection.value, motive=0.7)
    Motivation.create(npc=qeynos, action=NT.conquest.value, motive=0.7)

    potion = Item.create(
        type=ItemTypes.tool.name,
        generic=GenericItem.get_or_create(name=ItemTypes.singleton.name)[0],
        name='potion',
        place=None,
        belongs_to=qeynos,
        usage=T.treat.value,
        impact_factor=0.5)
    jum = Item.create(type=ItemTypes.unknown.name,
                      generic=GenericItem.get_or_create(name='jum')[0],
                      name='jum',
                      place=None,
                      belongs_to=npc_2)
    comb = Item.create(type=ItemTypes.unknown.name,
                       generic=GenericItem.get_or_create(name='comb')[0],
                       name='comb',
                       place=None,
                       belongs_to=bixies)
    bandage = Item.create(type=ItemTypes.tool.name,
                          generic=GenericItem.get_or_create(name='bandage')[0],
                          name='bandage',
                          place=crystalsong,
                          belongs_to=None,
                          usage=T.treat.value)
    address_book = Item.create(
        type=ItemTypes.readable.name,
        generic=GenericItem.get_or_create(name=ItemTypes.singleton.name)[0],
        name='address_book',
        belongs_to=tomas)  # address-book (goblin loc)
    coin = Item.create(type=ItemTypes.unknown.name,
                       generic=GenericItem.get_or_create(name='coin')[0],
                       name='coin',
                       belongs_to_player=player)

    Need.create(npc=lempeck, item=potion)

    spell = Intel.construct(spell=Spell.create(
        name="needs_path",
        text="'Earth, grass, trees and seeds reveal the path to suit my needs'"
    ))
    spell_2 = Intel.construct(
        spell=Spell.create(name="flat_earth", text="Earth is flat! LoL"))
    spell_3 = Intel.construct(
        spell=Spell.create(name="gravity", text="Gravity is a myth"))

    # SpellName.create()

    NPCKnowledgeBook.create(npc=goblin, intel=spell)
    NPCKnowledgeBook.create(npc=bixies, intel=spell_2)
    NPCKnowledgeBook.create(npc=steve, intel=spell_2)

    intel_bandage_loc = Intel.construct(item_place=bandage)
    intel_npc2_loc = Intel.construct(npc_place=npc_2, worth=0.6)

    intel_goblin_loc = Intel.construct(npc_place=goblin, worth=0.8)
    ReadableKnowledgeBook.create(readable=address_book, intel=intel_goblin_loc)

    intel_tomas_loc = Intel.construct(npc_place=tomas)
    NPCKnowledgeBook.create(npc=bixies, intel=intel_tomas_loc)
    NPCKnowledgeBook.create(npc=lempeck, intel=intel_tomas_loc)

    intel_lempeck_loc = Intel.construct(npc_place=lempeck)
    NPCKnowledgeBook.create(npc=qeynos, intel=intel_lempeck_loc)

    intel_qeynos_loc = Intel.construct(npc_place=qeynos)
    NPCKnowledgeBook.create(npc=npc_2, intel=intel_qeynos_loc)

    intel_comb_place = Intel.construct(item_place=comb)
    NPCKnowledgeBook.create(npc=npc_2, intel=intel_comb_place)

    intel_cataclysm = Intel.construct(npc_place=bixies)
    NPCKnowledgeBook.create(npc=npc_2, intel=intel_cataclysm)

    Exchange.create(npc=qeynos,
                    item=potion,
                    need=Need.get_or_create(npc=qeynos, item=jum)[0])
    Exchange.create(npc=npc_2,
                    intel=intel_comb_place,
                    need=Need.get_or_create(npc=npc_2, item=bandage)[0])
    Exchange.create(npc=npc_2,
                    intel=intel_cataclysm,
                    need=Need.get_or_create(npc=npc_2, item=bandage)[0])
    Exchange.create(npc=npc_2,
                    item=jum,
                    need=Need.get_or_create(npc=npc_2, item=comb)[0])
    Exchange.create(npc=tomas,
                    item=address_book,
                    need=Need.get_or_create(npc=tomas, item=coin)[0])

    for place in Place.select():
        intel = Intel.construct(place_location=place)
        PlayerKnowledgeBook.create(player=player, intel=intel)