def serenity_1(motivated: NPC): """ Revenge, Justice :param motivated: :return: """ enemies = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if enemies: target = enemies[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() 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) # steps # goto # damage steps = [[target.place, target], [target]] Message.instruction("%s: Get my revenge from '%s'" % (motivated, target)) return steps
def sub_quest_2(suggested_destination: Place = None) -> list: player = Player.current() if suggested_destination: return_point = suggested_destination else: return_point = player.place results = Place.select()\ .join(Intel)\ .join(PlayerKnowledgeBook, JOIN.LEFT_OUTER)\ .group_by(Intel).having(fn.COUNT(PlayerKnowledgeBook.id) == 0) locations_scores = [player.distance(place) for place in results] results = sort_by_list(results, locations_scores) if results: place_to_go = results[0] else: # not enough places to go, then create a new place unknown to player place_to_go = narrative_helper.create_place() player.next_location = place_to_go player.save() # steps: # goto # Quest # goto steps = [[place_to_go], [], [return_point]] Message.instruction("Goto '%s' do another Quest, then go to '%s'" % (place_to_go, return_point)) return steps
def reputation_3(motivated: NPC) -> list: """ Visit a dangerous place :param motivated: :return: """ # goto an enemies place enemies = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if enemies: place = enemies[0].place 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() player = Player.current() danger_report_intel = Intel.construct(other='arbitrary_danger_report_' + str(randint(100, 999))) PlayerKnowledgeBook.create(player=player, intel=danger_report_intel) # steps # goto # goto # report steps = [[place], [motivated.place, motivated], [danger_report_intel, motivated]] Message.instruction( "%s: Goto the dangerous '%s' and report what you've seen there" % (motivated, place)) return steps
def sub_quest_1(suggested_destination: Place = None): # just go somewhere - pick a place_location unknown to player to go to # the reason for unknown place_location is, if "learn" comes up in next level, we'll be lucky, # if it doesn't, intel can be added to Players knowledge right away. player = Player.current() if suggested_destination: place_to_go = suggested_destination else: results = Place.select()\ .join(Intel)\ .join(PlayerKnowledgeBook, JOIN.LEFT_OUTER)\ .group_by(Intel).having(fn.COUNT(PlayerKnowledgeBook.id) == 0) locations_scores = [player.distance(place) for place in results] results = sort_by_list(results, locations_scores) if results: place_to_go = results[0] else: # not enough places to go, then create a new place unknown to player place_to_go = narrative_helper.create_place() player.next_location = place_to_go player.save() # steps: # goto steps = [[place_to_go]] Message.instruction("Goto '%s'" % place_to_go) return steps
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 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 serenity_4(motivated: NPC) -> list: """ Check on NPC(1) :param motivated: :return: """ # find ally NPC to motivated get generated intel about health and well being 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) well_being_intel = Intel.construct(other='arbitrary_well_being_report_' + str(randint(100, 999))) NPCKnowledgeBook.create(npc=target, intel=well_being_intel) # steps # goto # listen # goto # report steps = [[target.place, target], [well_being_intel, target], [motivated.place, motivated], [well_being_intel, motivated]] Message.instruction( "%s: Check on my friend, '%s' ask how he's doing for me" % (motivated, target)) return steps
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
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