def reputation_2(motivated: NPC) -> list: """ Kill enemies of motivated :param motivated: given from higher level nodes :return: """ results = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if results: enemy = results.get() else: # No NPC left in the world except the motivated enemies_clan = Clan.select().where(Clan.id != motivated.clan).order_by( fn.Random()).get() enemy = NPC.create(place=Place.select().order_by(fn.Random()).get(), clan=enemies_clan, name=NPCName.fetch_new()) player = Player.current() killing_report_intel = Intel.construct(other='arbitrary_killing_report_' + str(randint(100, 999))) PlayerKnowledgeBook.create(player=player, intel=killing_report_intel) # steps: # goto enemies place # kill enemies # goto motivated place # T.report intel(?) to motivated steps = [[enemy.place, enemy], [enemy], [motivated.place, motivated], [killing_report_intel, motivated]] Message.instruction("%s: Kill my enemy '%s', and report it" % (motivated, enemy)) return steps
def comfort_2(motivated: NPC) -> list: """ Kill pests :param motivated: :return: """ # find enemy of motivated, or create one results = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if results: enemy = results.get() else: # No NPC left in the world except the motivated enemies_clan = Clan.select().where(Clan.id != motivated.clan).order_by( fn.Random()).get() enemy = NPC.create(place=Place.select().order_by(fn.Random()).get(), clan=enemies_clan, name=NPCName.fetch_new()) player = Player.current() damage_report_intel = Intel.construct( other='arbitrary_pest_damage_report_' + str(randint(100, 999))) PlayerKnowledgeBook.create(player=player, intel=damage_report_intel) # steps: # goto enemies place # kill enemies # goto motivated place # T.report intel(?) to motivated steps = [[enemy.place, enemy], [enemy], [motivated.place, motivated], [damage_report_intel, motivated]] Message.instruction("%s: Take care of that pest '%s' for me" % (motivated, enemy)) return steps
def conquest_1(motivated: NPC) -> list: """ Attack enemy :param motivated: :return: """ # find enemy of motivated, or create one results = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if results: enemy = results.get() else: # No NPC left in the world except the motivated enemies_clan = Clan.select().where(Clan.id != motivated.clan).order_by( fn.Random()).get() enemy = NPC.create(place=Place.select().order_by(fn.Random()).get(), clan=enemies_clan, name=NPCName.fetch_new()) # steps: # goto enemies place # damage enemies steps = [[enemy.place, enemy], [enemy]] Message.instruction("%s: Damage my enemy '%s' for me" % (motivated, enemy)) return steps
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 protection_1(motivated: NPC) -> list: """ Attack threatening entities :param motivated: :return: """ # find enemy of motivated, or create one results = NPC.select().where(NPC.clan != motivated.clan).order_by( fn.Random()).limit(1) if results: enemy = results.get() else: # No NPC left in the world except the motivated enemies_clan = Clan.select().where(Clan.id != motivated.clan).order_by( fn.Random()).get() enemy = NPC.create(place=Place.select().order_by(fn.Random()).get(), clan=enemies_clan, name=NPCName.fetch_new()) player = Player.current() threat_report_intel = Intel.construct( other='arbitrary_threat_damage_report_' + str(randint(100, 999))) PlayerKnowledgeBook.create(player=player, intel=threat_report_intel) # steps: # goto enemies place # kill enemies # goto motivated place # T.report intel(?) to motivated steps = [[enemy.place, enemy], [enemy], [motivated.place, motivated], [threat_report_intel, motivated]] Message.instruction("%s: Relieve me of '%s' threats, then report it" % (motivated, enemy)) return steps
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 knowledge_2(NPC_knowledge_motivated: NPC): player = Player.current() # find someone enemy to the given NPC who has a worthy intel that the given NPC doesn't have. # or player already know them already_known_intel_list = Intel.select(Intel.id)\ .join(NPCKnowledgeBook)\ .where(NPCKnowledgeBook.npc == NPC_knowledge_motivated) already_known_intel_list += Intel.select(Intel.id)\ .join(PlayerKnowledgeBook)\ .where(PlayerKnowledgeBook.player == player) results = NPC.select(NPC, Intel.id.alias('intel_id'))\ .join(NPCKnowledgeBook)\ .join(Intel)\ .where(NPC.clan != NPC_knowledge_motivated.clan, Intel.id.not_in(already_known_intel_list))\ .order_by(Intel.worth.desc()).group_by(NPC).objects() if results: locations_scores = [player.distance(res.place) for res in results] results = sort_by_list(results, locations_scores) spy_target = results[0] spy_intel = Intel.get_by_id(spy_target.intel_id) del spy_target.intel_id else: # enemies results = NPC.select().where(NPC.clan != NPC_knowledge_motivated.clan) if not results: # no enemy found, pick any NPC Message.debug("knowledge_2: no enemy found, pick any NPC") results = NPC.select() locations_scores = [player.distance(res.place) for res in results] results = sort_by_list(results, locations_scores) spy_target = results[0] new_intel_list = Intel.select().where( Intel.id.not_in(already_known_intel_list)).order_by( Intel.worth.desc()) if new_intel_list: # add the most valuable intel to the NPC knowledge book Message.debug( "knowledge_2: add the most valuable intel to the NPC knowledge book" ) spy_intel = new_intel_list[0] else: # no new intel found, create a new intel spy_intel = Intel.construct(spell=Spell.create( name=SpellName.fetch_new(), text='magical arbitrary spell')) NPCKnowledgeBook.create(npc=spy_target, intel=spy_intel) # steps: # spy: on target, to get intel, then report it to knowledge_motivated NPC steps = [[spy_target, spy_intel, NPC_knowledge_motivated]] Message.instruction("%s: Spy on '%s' to get the intel '%s' for me" % (NPC_knowledge_motivated, spy_target, spy_intel)) return steps
def goto_1(destination: Place, npc: NPC = None, item: Item = None): """ You are already there. :return: """ player = Player.current() if npc or item: event_dest_str = str(npc if npc else item) + ' (' + str( destination) + ')' else: event_dest_str = str(destination) if npc: # move the npc npc.place = player.place npc.save() intel = Intel.construct(npc_place=npc) PlayerKnowledgeBook.get_or_create(player=player, intel=intel) Message.debug("NPC (%s) moved to the player location (%s)" % (npc, player.place)) Message.event("%s moved to your location" % npc) elif item: # move item or the holder if item.belongs_to: holder = item.belongs_to # type: NPC holder.place = player.place holder.save() intel = Intel.construct(npc_place=holder) PlayerKnowledgeBook.get_or_create(player=player, intel=intel) Message.debug( "Item (%s) holder (%s) moved to the player location (%s)" % (item, item.belongs_to, player.place)) Message.event("Item '%s's holder moved to your location" % item) elif item.belongs_to_player: Message.debug("Player already has the item %s" % item) Message.event("You already have the item '%s'" % item) else: item.place = player.place item.save() intel = Intel.construct(item_place=item) PlayerKnowledgeBook.get_or_create(player=player, intel=intel) Message.debug("Item (%s) moved to the player location (%s)" % (item, player.place)) Message.event("Item '%s' has been moved to your location" % item) else: # update player's location player.place = destination player.save() Message.debug("Player moved to %s location" % event_dest_str) Message.event("Player has been moved to %s location" % destination) return [[]]
def do_npc(self, args): """Print NPC's info (type npc <category). NPC Goblin intel""" args = parse(args) if not args: # less than 1 arg self.check_length(args, 1) return else: npc_name = args[0] if len(args) == 1: cat = None elif len(args) == 2: cat = args[1] else: # more than 2 args self.check_length(args, 2) return npc = NPC.get_or_none(NPC.name == npc_name) if not npc: print("Error: npc", npc_name, "not found") return if cat == "intel": print_npc_intel(npc, debug=True) elif cat == "items" or cat == "item" or cat == "belongings" or cat == "belonging": print_npc_belongings(npc, debug=True) elif cat == "places" or cat == "place_location" or cat == "locations" or cat == "location": print_npc_place(npc, debug=True) else: print_npc_intel(npc, debug=True) print_npc_belongings(npc, debug=True) print_npc_place(npc, debug=True)
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 do_take(self, args): """Take something from an NPC. TAKE bandage Goblin""" args = parse(args) if not self.check_length(args, 2): return item = Item.get_or_none(Item.name == args[0]) npc = NPC.get_or_none(NPC.name == args[1]) dead = NPCDead.get_or_none(NPCDead.name == args[1]) if not npc and dead: # npc is dead, loot him if not self.set_inputs(action=T.take, args=[item]): return found = terminals.take_loot(item_to_take=item, loot_npc=dead) else: # npc is alive, or not found among dead, can't loot if not self.set_inputs(action=T.take, args=[item, npc]): return found = terminals.take(item_to_take=item, item_holder=npc) if not found: print("failed!") return print("player's belongings updated.") print_player_belongings() print("NPC belongings updated.") print_npc_belongings(npc) self.last_action_doable = True
def do_exchange(self, args): """Exchange an Item with another with an NPC. EXCHANGE goblin potion bandage <means give potion to goblin and take bandage from him>""" args = parse(args) if not self.check_length(args, 3): return item_holder = NPC.get_or_none(NPC.name == args[0]) item_to_give = Item.get_or_none(Item.name == args[1]) item_to_take = Item.get_or_none(Item.name == args[2]) if not self.set_inputs(action=T.exchange, args=[item_holder, item_to_give, item_to_take]): return found = terminals.exchange(item_holder=item_holder, item_to_give=item_to_give, item_to_take=item_to_take) if not found: print("failed!") return print("player's belongings updated.") print_player_belongings() print("NPC belongings updated.") print_npc_belongings(item_holder) self.last_action_doable = True
def quest_neutral(motivation: NT) -> List[List[BaseElement]]: # select an ally NPC with a certain motivation results = Motivation.select()\ .where(Motivation.action == motivation.value, Motivation.motive > 0.5)\ .order_by(Motivation.motive.desc()).limit(1) if results: motivated = results.get().npc else: # No motivated NPC found, create one place = Place.select().order_by(fn.Random()).get() clan = Clan.select().order_by(fn.Random()).get() motivated = NPC.create(place=place, clan=clan, name=NPCName.fetch_new()) Motivation.create(npc=motivated, action=motivation.value, motive=0.65) # steps: # give useful info to this NPC steps = [[motivated]] Message.instruction("NPC '%s' has '%s' motivation" % (motivated.name, motivation.name)) return steps
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
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 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 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 finish_quest(self): print("Congratulations!! Quest completed!!!!") self.progress.current_node = self.progress.quest self.quest_in_progress = False self.quest_done = True Intel.delete_all_arbitrary() query = Item.delete().where(Item.name.contains('arbitrary')) query.execute() query = Place.delete().where(Place.name.contains('arbitrary')) query.execute() query = NPC.delete().where(NPC.name.contains('arbitrary')) query.execute()
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
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 get_2(item_to_fetch: Item): """ Steal it from somebody. :return: """ if not item_to_fetch.belongs_to: holder = NPC.select().get() item_to_fetch.belongs_to = holder item_to_fetch.save() # steps: # steal: steal item[1] from NPC[1] steps = [[item_to_fetch, item_to_fetch.belongs_to]] Message.instruction("Steal '%s' from '%s'" % (item_to_fetch, item_to_fetch.belongs_to)) return steps
def do_stealth(self, args): """Stealth on an NPC. STEALTH Goblin""" args = parse(args) if not self.check_length(args, 1): return target = NPC.get_or_none(NPC.name == args[0]) if not self.set_inputs(action=T.stealth, args=[target]): return found = terminals.stealth(target=target) if not found: print("failed!") return self.last_action_doable = True
def do_damage(self, args): """Damage an NPC. Damage Goblin""" args = parse(args) if not self.check_length(args, 1): return npc = NPC.get_or_none(NPC.name == args[0]) if not self.set_inputs(action=T.damage, args=[npc]): return found = terminals.damage(target=npc) if not found: print("failed!") return self.last_action_doable = True
def do_use(self, args): """Use an item (tool) on an NPC. USE potion Lempeck""" args = parse(args) if not self.check_length(args, 2): return item = Item.get_or_none(Item.name == args[0]) npc = NPC.get_or_none(NPC.name == args[1]) if not self.set_inputs(action=T.use, args=[item, npc]): return found = terminals.use(item_to_use=item, target=npc) if not found: print("failed!") return print("NPC health meter:", npc.health_meter) self.last_action_doable = True
def do_spy(self, args): """Spy on an NPC to gather some information (intel: type intel_value). SPY Goblin place_location tomas_place""" args = parse(args) if not self.check_length(args, 3): return target = NPC.get_or_none(NPC.name == args[0]) intel = Intel.find_by_name(args[1], [args[2]]) if not self.set_inputs(action=T.spy, args=[target, intel]): return found = terminals.spy(spy_on=target, intel_target=intel) if not found: print("failed!") return print("Player intel updated.") print_player_intel() self.last_action_doable = True
def do_listen(self, args): """Listen a piece of intel from an NPC (intel: type intel_value). LISTEN spell needs_path Goblin""" args = parse(args) if not self.check_length(args, 3): return intel = Intel.find_by_name(args[0], [args[1]]) npc = NPC.get_or_none(NPC.name == args[2]) if not self.set_inputs(action=T.listen, args=[intel, npc]): return found = terminals.listen(intel=intel, informer=npc) if not found: print("failed!") return print("Player intel updated.") print_player_intel() self.last_action_doable = True
def do_report(self, args): """Report a piece of intel to an NPC (intel: type intel_value). REPORT spell needs_path Steve""" args = parse(args) if not self.check_length(args, 3): return intel = Intel.find_by_name(args[0], [args[1]]) npc = NPC.get_or_none(NPC.name == args[2]) if not self.set_inputs(action=T.report, args=[intel, npc]): return found = terminals.report(intel=intel, target=npc) if not found: print("failed!") return print("NPC intel updated.") print_npc_intel(npc) self.last_action_doable = True
def do_give(self, args): """Give an NPC something. GIVE bandage Goblin""" args = parse(args) if not self.check_length(args, 2): return item = Item.get_or_none(Item.name == args[0]) npc = NPC.get_or_none(NPC.name == args[1]) if not self.set_inputs(action=T.give, args=[item, npc]): return found = terminals.give(item=item, receiver=npc) if not found: print("failed!") return print("player's belongings updated.") print_player_belongings() print("NPC belongings updated.") print_npc_belongings(npc) self.last_action_doable = True
def do_talk(self, args): """Talk to an NPC. TALK goblin (starts a quest if possible)""" args = parse(args) if not self.check_length(args, 1): return npc = NPC.get_or_none(NPC.name == args[0]) found = terminals.talk(npc=npc) if not found: print("failed!") return if self.quest_in_progress: print("talk and talk and talk ..!") else: motive, nt = npc.top_motive() if nt == T.null: print("not motivated, let's talk and talk ..!") return # find quest rule number based on motive type quest_rule_number = None for rule_number, set_of_actions in rules[NT.quest].items(): if len(set_of_actions) and set_of_actions[0] == nt: quest_rule_number = rule_number break quest = ga_quest_generator(quest_rule_number) if quest: if query_yes_no("Do you want to play quest '%s'" % quest.genre()): motive.delete_instance() self.start_quest(quest) else: print("Quest", quest.genre(), "refused to be played! Maybe later, huh?") else: print('quest not found!') print('failed!')
def do_explore(self, args): """Explore current location to find an NPC or Item. EXPLORE item potion | EXPLORE npc goblin""" args = parse(args) if not self.check_length(args, 2): return dest = Player.current().place if args[0] == 'item': item = Item.get_or_none(Item.name == args[1]) if not self.set_inputs(action=T.explore, args=[dest, '', item]): return found = terminals.explore(area_location=dest, item=item) else: npc = NPC.get_or_none(NPC.name == args[1]) if not self.set_inputs(action=T.explore, args=[dest, npc, '']): return found = terminals.explore(area_location=dest, npc=npc) if not found: print("failed!") return self.last_action_doable = True