def print_player_belongings(player: Player = None): if not player: player = Player.current() results = Item.select().where(Item.belongs_to_player == player) print("items:") print_indented(results)
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
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
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
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
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
def print_npc_belongings(npc: NPC, debug=False): if debug or Params.debug_mode: results = Item.select().where(Item.belongs_to == npc) print("items:") print_indented(results)
def get_4(item_to_fetch: Item): """ an NPC have the item, but you need to give the NPC something in an exchange :param item_to_fetch: :return: """ player = Player.current() # find an NPC who has the needed item, and has it in exchange list exchanges = Exchange.select().join(Item) if item_to_fetch.is_singleton(): exchanges = exchanges.where(Exchange.item == item_to_fetch) else: exchanges = exchanges.where( Exchange.item.generic == item_to_fetch.generic) if exchanges: locations_scores = [ player.distance(exc.need.npc.place) for exc in exchanges ] exchanges = sort_by_list(exchanges, locations_scores) exchange = exchanges[0] item_to_give = exchange.need.item item_holder = exchange.need.npc else: # no one wants to offer the "item_to_fetch" in exchange for something else # you can even trade with your enemies so alliance doesn't really matters here # first try find someone who needs this item Message.debug( "No one wants to offer the '%s' in exchange for something else" % item_to_fetch) needs = Need.select().where(Need.item == item_to_fetch).group_by( Need.npc) if needs.count(): need = needs.order_by(fn.Random()).get() item_holder = need.npc Message.debug( "NPC '%s' needs something, ideal to create an exchange motive with the item '%s' for him" % (item_holder, item_to_fetch)) else: # no one need anything create a need for coin for an NPC results = NPC.select() locations_scores = [player.distance(npc.place) for npc in results] results = sort_by_list(results, locations_scores) item_holder = results[0] Message.debug( "No one need anything create a need for 'coin' for a close-by NPC '%s'" % item_holder) need = Need.create( npc=item_holder, item=Item.get(generic=GenericItem.get(name='coin'))) Exchange.create(need=need, item=item_to_fetch) if item_to_fetch.belongs_to != item_holder: # ensure NPC has the item item_to_fetch.belongs_to = item_holder item_to_fetch.save() item_to_give = need.item player.next_location = item_holder.place player.save() intel = Intel.construct(item_place=item_to_fetch) PlayerKnowledgeBook.get_or_create(player=player, intel=intel) Message.achievement("Intel '%s' learned" % intel.detail()) # check for player belonging for the exchange item if item_to_give.is_singleton(): player_owns = (item_to_give.belongs_to_player == player) else: player_owns = Item.select().where(Item.generic == item_to_give.generic, Item.belongs_to_player == player) is True if player_owns: # player has the item # goto # exchange steps = [[], [], [], [item_holder.place, item_holder], [item_holder, item_to_give, item_to_fetch]] Message.instruction( "Do a sub-quest, meet '%s' and exchange '%s' with '%s'" % (item_holder, item_to_give, item_to_fetch)) return steps # steps: # goto # get # sub-quest # goto # exchange steps = [[item_to_give.place_(), None, item_to_give], [item_to_give], [], [item_holder.place, item_holder], [item_holder, item_to_give, item_to_fetch]] Message.instruction( "Get '%s', do a sub-quest, meet '%s' and exchange '%s' with '%s'" % (item_to_give, item_holder, item_to_give, item_to_fetch)) return steps
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