def target_items_in_container(self, user_input, input_kwargs): target = None for y in Gen.items_in_container(input_kwargs['target_parent']): if Lex.first_three(y.keyword) in user_input: target = y print("HANDLER | Target Found: item in container, ", target) # print("Items in room:", item_list) return target
def target_items_in_room(self, user_input, input_kwargs): # check if the target is an item in the room target = None for y in Gen.items_in_room(self): if Lex.first_three(y.keyword) in user_input: target = y print("HANDLER | Target Found: item in room, ", target) return target
def target_players_in_room(self, user_input, input_kwargs): # check if the target is a player in the room for player in Gen.players_in_room(self): if user_input in player.name: target = player print("HANDLER | Target Found: player, ", target) break else: target = None return target
def comms(self, first_person, target_person, third_person, target, send_kwargs): if first_person == "": pass else: WsWrap.ws_send(self.client, send_kwargs, first_person) # WsWrap.ws_send(self.client, send_kwargs, "") if Gen.players_in_room(self): for i in Gen.players_in_room(self): if target == None: WsWrap.ws_send(i.client, send_kwargs, third_person) WsWrap.ws_send(i.client, send_kwargs, "") else: if target.name == i.name: WsWrap.ws_send(target.client, send_kwargs, target_person) WsWrap.ws_send(target.client, send_kwargs, "") else: WsWrap.ws_send(i.client, send_kwargs, third_person) WsWrap.ws_send(i.client, send_kwargs, "")
def target_npcs_in_room(self, user_input, input_kwargs): # check if the target is an NPC in the room for npc in Gen.npcs_in_room(self): if user_input in npc.name.lower(): target = npc print("HANDLER | Target Found: NPC, ", target) break else: target = None return target
def takeoff(self, user_input, input_kwargs): ship_id = rooms[self.location].ship_id room_of_ship = rooms[items[ship_id].location] print("Ship_ID:", ship_id) print("Ship was in room:", items[ship_id].location) items[ship_id].location = items[ "r23b4335-5o7k-4f52-92b8-56ad69f63bea"].location rooms[items["r23b4335-5o7k-4f52-92b8-56ad69f63bea"]. location].item_inv.append(items[ship_id]) room_ship_list = [] ship_list = Gen.ships_in_room(self) for i in ship_list: room_ship_list.append(i.name) all_schedules[self.uuid_id]['sched'].eventabs( time.time() + 1, 1, "ship_ai", "print", Lex.pub_print, kwargs={ 'self': self, 'target': input_kwargs['target'], 'first_person': 'You reach open space. Outside, {} You also see {}.'.format( rooms[items[ship_id].location].description, ", ".join(room_ship_list)), 'target_person': '', 'third_person': 'You reach open space. Outside, {} You also see {}.'.format( rooms[items[ship_id].location].description, ", ".join(room_ship_list)) }) print("Ship now in room:", items[ship_id].location) print("Inv of this room:", rooms[items[ship_id].location].item_inv)
def npc_assess(self, **npc_kwargs): # alert types: # sleep = not performing any tasks # awake = moving rooms, searching for targets # engaged = engaging a target in combat if self.conditions['state'] == "sleep": pass elif self.conditions['state'] != "sleep": players_in_room = Gen.players_in_room(self) if players_in_room == []: exit = Gen.random_movement(self) if exit == None: pass else: rand_die = random.randint(1, 1) Character.navigate(self, None, exit) all_schedules[self.uuid_id]['sched'].eventabs( time.time() + rand_die, 1, "npc_assess", "npc", Npc.npc_assess, kwargs={"self": self}) elif players_in_room != []: input_kwargs = {} input_kwargs['target'] = random.choice(players_in_room) if input_kwargs['target'].vitals['alive'] == False: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person="", target_person= f"{Lex.a_an(self.name).capitalize()} smirks at your dead body.", third_person= f"{Lex.a_an(self.name).capitalize()} smirks at {input_kwargs['target'].name}'s dead body." ) self.conditions['state'] = "awake" print( f"NPC ASSESS | Entity: {self.name} changing state to: {self.conditions['state']}." ) else: self.conditions['state'] = "engaged" print( f"NPC ASSESS | Entity: {self.name} changing state to: {self.conditions['state']}." ) print("") roll = Gen.random_number(2, 1, 6) combat_choice = Gen.random_number(1, 1, 6) Combat.attack(self, None, input_kwargs)
def pub_print(self, first_person, target_person, third_person, target, send_kwargs): # parse words for color changes first_edit = first_person.split() target_edit = target_person.split() third_edit = third_person.split() try: for location, word in enumerate(first_edit): if self.entity_type['base'] == 'player': if word == self.name: first_edit[location] = "|player|{}|playerx|".format( word.capitalize()) if target: if target.entity_type['base'] != "npc": pass else: if word == target.name: first_edit[location] = "|npc|{}|npcx|".format( word) for location, word in enumerate(target_edit): if word == target.name: target_edit[location] = "|player|{}|playerx|".format( word.capitalize()) if target: if word == self.name: target_edit[location] = "|npc|{}|npcx|".format(word) for location, word in enumerate(third_edit): if self.entity_type['base'] == 'player': if word == self.name: third_edit[location] = "|player|{}|playerx|".format( word.capitalize()) if target: if word == target.name: third_edit[location] = "|npc|{}|npcx|".format(word) except AttributeError as error: print("LOG | ERROR | PubPrint. Please contact your Admin.", error) # apply first letter capitalization to first/target/third person output # print("LEX:", first_edit) if first_edit: if "|" in first_edit[:1]: first_edit[1] = first_edit[1].capitalize() else: first_edit[0] = first_edit[0].capitalize() first_person = first_edit # print("LEX:", target_edit) if target_edit: if "|" in target_edit[:1]: target_edit[1] = target_edit[1].capitalize() else: target_edit[0] = target_edit[0].capitalize() target_person = target_edit # print("LEX:", third_edit) if third_edit: if "|" in third_edit[:1]: third_edit[1] = third_edit[1].capitalize() else: third_edit[0] = third_edit[0].capitalize() third_person = third_edit # print words to client if self.entity_type['base'] == "npc": if target is not None and target is not self: WsWrap.ws_send(target.client, send_kwargs, "{}".format(" ".join(target_person))) elif self.entity_type['base'] == "player": if first_person == "" or first_person == []: pass else: WsWrap.ws_send(self.client, send_kwargs, "{}".format(" ".join(first_person))) if Gen.players_in_room(self): for i in Gen.players_in_room(self): if i == target: pass else: if third_person == "" or third_person == []: pass else: WsWrap.ws_send(i.client, send_kwargs, "{}".format(" ".join(third_person)))
def get_item(self, user_input, input_kwargs): all_ok = False obj_generator = False if input_kwargs['target'] in Gen.items_in_room(self): print(input_kwargs['target'], input_kwargs['target'].attributes) if "obj_generator" in input_kwargs['target'].attributes: print("obj_gen") else: rooms[input_kwargs['target'].location].item_inv.remove(input_kwargs['target']) all_ok = True elif input_kwargs['target_parent'] is not None: container = items[input_kwargs['target_parent'].uuid_id] items[input_kwargs['target_parent'].uuid_id].item_inv.remove(input_kwargs['target']) all_ok = True elif input_kwargs['target'] == self.inventory['r_hand']['contents'] or input_kwargs['target'] == self.inventory['l_hand']['contents']: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "You already have that.") if all_ok == True: if self.inventory['r_hand']['contents'] == None: hand = self.inventory['r_hand'] input_kwargs['target'].location = self.uuid_id input_kwargs['target'].location_body['location'] = "r_hand" self.inventory['r_hand']['contents'] = input_kwargs['target'] Update_Client.update_player_inventory(self) elif self.inventory['l_hand']['contents'] == None: hand = self.inventory['l_hand'] input_kwargs['target'].location = self.uuid_id input_kwargs['target'].location_body['location'] = "l_hand" self.inventory['l_hand']['contents'] = input_kwargs['target'] Update_Client.update_player_inventory(self) if input_kwargs['target_parent'] is not None: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You pull {} out from inside of {}.".format(Lex.a_an(input_kwargs['target'].name), Lex.a_an(container.name)), target_person = "", third_person = "{} pulls {} from inside of {}.".format(self.name, Lex.a_an(input_kwargs['target'].name), Lex.a_an(container.name))) else: Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You pickup {} in your {}.".format(Lex.a_an(input_kwargs['target'].name), hand['name']), target_person = "", third_person = "{} picks up {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name)))