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 print_player_intel(player: Player = None, print_locations: bool = False): if not player: player = Player.current() results = Intel.select().join(PlayerKnowledgeBook).where( PlayerKnowledgeBook.player == player) if not print_locations: results = results.where(Intel.type != IntelTypes.location) detailed = [] for intel in results: detailed.append(intel.detail()) print("intel:") print_indented(detailed)
def knowledge_3(NPC_knowledge_motivated: NPC): """ Interview an NPC :return: """ player = Player.current() # NPC[0] is from knowledge itself (parent node) # NPC_knowledge_motivated = None # select an NPC[1] that: # has an intel that NPC[0] doesn't have # not an enemy to Player (or NPC[0]) # willing to tell, either intel is not expensive, or you already done a favour for the NPC[1] # location is not too far from NPC[0] not_interesting_intel = Intel.select(Intel.id).join(NPCKnowledgeBook).join(NPC)\ .where(NPC.id == NPC_knowledge_motivated) not_interesting_intel += Intel.select(Intel.id).join(PlayerKnowledgeBook)\ .where(PlayerKnowledgeBook.player == player) results = NPC.select(NPC, Intel.id.alias('intel_id'))\ .join(NPCKnowledgeBook)\ .join(Intel)\ .order_by(Intel.worth.desc())\ .where(Intel.id.not_in(not_interesting_intel), NPC.clan == player.clan).objects() if results: locations_scores = [player.distance(res.place) for res in results] results = sort_by_list(results, locations_scores) NPC_knowledgeable = results[0] intended_intel = Intel.get_by_id(NPC_knowledgeable.intel_id) del NPC_knowledgeable.intel_id else: new_intel_list = Intel.select().where( Intel.id.not_in(not_interesting_intel)).order_by( Intel.worth.desc()) if new_intel_list: intended_intel = new_intel_list[0] else: # no new intel found, create a new intel intended_intel = Intel.construct(spell=Spell.create( name=SpellName.fetch_new(), text='magical arbitrary spell')) results = NPC.select().where(NPC.clan == player.clan) if not results: results = NPC.select() locations_scores = [player.distance(res.place) for res in results] results = sort_by_list(results, locations_scores) NPC_knowledgeable = results[0] NPCKnowledgeBook.create(npc=NPC_knowledgeable, intel=intended_intel) # intel[1] is the intel NPC[1] has that NPC[0] doesn't # place_location[0] is where the NPC[0] is living # place_location[1] is where the NPC[1] is living # steps: # goto[1]: from place_location[0] | destination place_location[1] # listen: get intel[1] from NPC[1] # goto[2]: from place_location[1] | destination place_location[0] # report: give intel[1] to NPC[0] steps = [[NPC_knowledgeable.place], [intended_intel, NPC_knowledgeable], [NPC_knowledge_motivated.place], [intended_intel, NPC_knowledge_motivated]] Message.instruction( "%s: Ask '%s' about '%s'" % (NPC_knowledge_motivated, NPC_knowledgeable, intended_intel)) return steps
def print_npc_intel(npc: NPC, debug=False): if debug or Params.debug_mode: results = Intel.select().join(NPCKnowledgeBook).where( NPCKnowledgeBook.npc == npc) print("intel:") print_indented(results)