def voice_command(self, user_input, input_kwargs): if rooms[self.location].entity_type['group'] != "ship_personal": WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "You are not in a ship.") else: # establish variables input_kwargs['ship_id'] = rooms[self.location].ship_id input_kwargs['room_of_ship'] = rooms[items[input_kwargs['ship_id']].location] input_kwargs['room_ship_list'] = [] # check if player owns the ship for auth to perform commands if rooms[self.location].owner != self.name: Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = f'|comp| "Unauthorized." |compx|', target_person = "", third_person = f'|comp| "Unauthorized." |compx|') # if checks pass, go on to find the command and run the associated function else: # print(user_input) rooms[self.location].ship_id.voice_command(self, user, user_input, input_kwargs)
def say(self, user_input, input_kwargs): print("SAY | User Input:", user_input) if len(user_input) < 2: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "|alert| Syntax: |alertx| '(sentence) or SAY (sentence).") else: if self.entity_type['base'] == 'npc': Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = '|npc| You say|npcx|, "{}"'.format(" ".join(user_input[1:])), target_person = "", third_person = '|npc| {} says|npcx|, "{}"'.format(self.name.capitalize(), " ".join(user_input[1:]))) else: if user_input[1] == "computer,": send_kwargs = {'type': 'text', 'spacing': 1} else: send_kwargs = {'type': 'text', 'spacing': 1} Lex.pub_print( self=self, target=None, send_kwargs=send_kwargs, first_person = '|self_speech| You say|self_speechx|, "{}"'.format(" ".join(user_input[1:])), target_person = "", third_person = '|player_speech| {} says|player_speechx|, "{}"'.format(self.name.capitalize(), " ".join(user_input[1:]))) if user_input[1] == "computer,": self.voice_command(user_input, input_kwargs)
def display_inventory(self): inv = [] for i in self.inventory: if self.inventory[i]['contents'] == None: pass else: inv.append("{} {} {} {}".format( self.inventory[i]['contents'].name, self.inventory[i]['worn'], "your", self.inventory[i]['name'])) if inv == []: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You have nothing.") else: WsWrap.ws_send( self.client, { 'type': 'text', 'spacing': 1 }, "You have {}.".format(", ".join(Lex.converted_contents(inv))))
def start_simulation(self, user_input, input_kwargs): holo = Holodeck.create_simulation(self, user_input, input_kwargs) self.location = None WsWrap.ws_send(self.client, speech, "Your surroundings shift and you see {}.".format())
def update_player_health(self): send_kwargs = {'type': 'vitals', 'spacing': False} if self.vitals['hp_current'] < 0: self.vitals['hp_current'] = 0 # update health WsWrap.ws_send(self.client, send_kwargs, {'hp_current': self.vitals['hp_current'], "hp_max": self.vitals['hp_max']})
def update_init_round_time(self): send_kwargs = {'type': 'init_round_time', 'spacing': False} init_round_time = self.conditions['init_round_time'] # update init rt try: WsWrap.ws_send(self.client, send_kwargs, init_round_time) except: print("ERROR | UPDATE INIT RT | Cannot update client for", self.name + ". User not in-game.")
def update_char_info(self): send_kwargs = {'type': 'char_info', 'spacing': False} char_info = {} char_info['char_name'] = self.name.capitalize() char_info['char_gender'] = self.gender.capitalize() char_info['char_xp'] = self.core_attributes['xp']['current'] # update health WsWrap.ws_send(self.client, send_kwargs, char_info)
def update_round_time(self): send_kwargs = {'type': 'round_time', 'spacing': 1} round_time = self.conditions['round_time'] # update rt try: print(self.client) WsWrap.ws_send(self.client, send_kwargs, round_time) except: print("ERROR | UPDATE RT | Cannot update client for", self.name + ". User not in-game.")
def update_user_settings(self): send_kwargs = {'type': 'user_settings', 'spacing': False} user_settings = {} user_settings['player_name'] = self.name user_settings['location'] = self.location user_settings['player_state'] = self.player_state # update health WsWrap.ws_send(self.client, send_kwargs, user_settings)
def enter_door(self, user_input, input_kwargs): print(input_kwargs) if input_kwargs['target'] == None: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "Usage: go <door>. For navigation, just use n, s, o, up, down, etc.") else: if not "is_door" in input_kwargs['target'].attributes: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You walk towards {}.".format(Lex.a_an(input_kwargs['target'].name)), target_person = "", third_person = "{} walks towards {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) elif input_kwargs['target'].is_open == False: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "That is closed.") else: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You enter {}.".format(Lex.a_an(input_kwargs['target'].name)), target_person = "", third_person = "{} enters {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) print(input_kwargs['target']) if rooms[input_kwargs['target'].room_target['target']].entity_type['group'] == "holodeck": Holodeck.enter_holo(self, user_input, input_kwargs) else: rooms[self.location].player_inv.remove(self) print(self.location) self.location = input_kwargs['target'].room_target['target'] print(self.location) rooms[self.location].player_inv.append(self) rooms[self.location].display_room(self) Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "", target_person = "", third_person = "{} just arrived.".format(self.name.capitalize())) rooms[self.location].render_map(self)
def help(self, user_input, input_kwargs): if len(user_input) < 2: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "|alert| Syntax: |alertx| HELP ON or HELP OFF.") else: if user_input[1] == "on": WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, 'Help is |success| ON.|successx|') self.conditions['help'] = "enabled" elif user_input[1] == "off": WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, 'Help is |alert| OFF|alertx|. ') self.conditions['help'] = "disabled" else: WsWrap.ws_send( self.client, { 'type': 'text', 'spacing': 1 }, "|alert| Syntax: |alertx| HELP ON or HELP OFF.")
def update_central_db(self): send_kwargs = {'type': 'wiki', 'spacing': False} # update player object in memory # central_db = {} # for i in global_command_list: # central_db[i] = {'cmd_title': global_command_list[i]['cmd_title'], # 'cmd_usage': global_command_list[i]['cmd_usage'], # 'desc': global_command_list[i]['desc']} final_list = sorted(global_command_list, key=lambda d: d['cmd_title']) WsWrap.ws_send(self.client, send_kwargs, final_list)
def echo(self): if self.conditions['echo'] == True: self.conditions['echo'] = False WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Echo is now |alert| disabled. |alertx|") else: self.conditions['echo'] = True WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Echo is now |success| enabled. |successx|")
def spawn(self, user_input, input_kwargs): if self.entity_type["group"] != "admin": WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You must be an admin to do that.") else: creature = user_input[1] # try: npc_obj = Npc( **{ "uuid_id": uuid.uuid4(), # uuid "entity_type": npc_table[creature] ['entity_type'], # entity_type "join_table": creature, # join_table reference name "vitals": npc_table[creature]['vitals'], # vitals "core_attributes": npc_table[creature] ['core_attributes'], # core_attributes "conditions": npc_table[creature] ['conditions'], # conditions "credit": npc_table[creature]['credit'], # credit "inventory": copy.deepcopy(inv), # inventory "location": self.location, # location "description": npc_table[creature] ['description'], # npc_desc "npc_state": npc_table[creature]['npc_state'], # npc_state "supply": npc_table[creature]['supply'], # supply "demand": npc_table[creature]['demand'], # demand "home_loc": npc_table[creature]['home_loc'], # hom_loc "demeanor": npc_table[creature]['demeanor'] # demeanor }) print(vars(npc_obj)) npcs[npc_obj.uuid_id] = npc_obj Sched_Child.create_new_sched(npc_obj) WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, f"|alert|A {creature} runs in!|alertx|") rooms[self.location].npc_inv.append(npc_obj) npc_obj.conditions['awake'] = True
def update_player_inventory(self): send_kwargs = {'type': 'inventory', 'spacing': False} # update health jinventory = {} for item in self.inventory: if self.inventory[item]['contents'] is not None: parsed_item = self.inventory[item]['contents'].name jinventory[self.inventory[item]['name']] = parsed_item else: pass WsWrap.ws_send(self.client, send_kwargs, jinventory)
def close_door(self, user_input, input_kwargs): room_obj_outside_of_ship = rooms[items[ input_kwargs['ship_id']].location] if items[input_kwargs['ship_id']].is_open == False: Lex.pub_print( self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person='comp| "The door is already closed." |/comp|', target_person="", third_person='|comp| "The door is already closed." |/comp|') # all_schedules[self.uuid_id]['sched'].eventabs(time.time() + 1, 1, "ship_ai", "print", Lex.pub_print, kwargs={'self': self, # 'target': None, # 'send_kwargs': {'type': 'text', 'spacing': 1}, # 'first_person': '|comp|"The door is already closed."|/comp|', # 'target_person': '', # 'third_person': '|comp|"The door is already closed."|/comp|'}) if items[input_kwargs['ship_id']].is_open == True: items[input_kwargs['ship_id']].is_open = False Lex.pub_print(self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person='The ship door closes with a *whoosh*.', target_person="", third_person='The ship door closes with a *whoosh*.') for i in room_obj_outside_of_ship.player_inv: WsWrap.ws_send(i.client, { 'type': 'text', 'spacing': 1 }, "A ship door closes with a *whoosh*.") items[input_kwargs['ship_id']].is_open = False rooms[self.location].exits = {}
def change_stance(self, user_input, input_kwargs): # function if self.conditions['stance'] == user_input[0]: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "You are already doing that.") else: if user_input[0] == "stand": self.conditions['stance'] = "stand" Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = 'You stand back up.', target_person = "", third_person = '{} stands up.'.format(self.name.capitalize())) elif user_input[0] == "sit": self.conditions['stance'] = "sit" Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = 'You sit down.', target_person = "", third_person = '{} sits down.'.format(self.name.capitalize())) elif user_input[0] == "lie": self.conditions['stance'] = "lie" Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = 'You lie down.', target_person = "", third_person = '{} lies down.'.format(self.name.capitalize()))
def open_door(self, user_input, input_kwargs): room_obj_outside_of_ship = rooms[items[ input_kwargs['ship_id']].location] if items[input_kwargs['ship_id']].is_open == True: Lex.pub_print( self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person='comp| "The door is already open." |/comp|', target_person="", third_person='|comp| "The door is already open." |/comp|') if items[input_kwargs['ship_id']].is_open == False: items[input_kwargs['ship_id']].is_open = True Lex.pub_print(self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person='The ship door opens with a *whoosh*.', target_person="", third_person='The ship door opens with a *whoosh*.') for i in room_obj_outside_of_ship.player_inv: WsWrap.ws_send(i.client, { 'type': 'text', 'spacing': 1 }, "A ship door closes with a *whoosh*.") items[input_kwargs['ship_id']].is_open = True rooms[self.location].exits = { "out": input_kwargs['room_of_ship'].uuid_id }
def update_suit_shield(self): send_kwargs = {'type': 'suit_shield', 'spacing': False} # try: if self.inventory['suit']['contents'] == None: WsWrap.ws_send(self.client, send_kwargs, {"shield_current": 0, "shield_max": 0}) if self.inventory['suit']['contents']: shield_current = items[self.inventory['suit']['contents'].uuid_id].vitals['shield_current'] shield_max = items[self.inventory['suit']['contents'].uuid_id].vitals['shield_max_current'] print("Updating:", self.name, "Suit Shield:", {"shield_current": shield_current, "shield_max": shield_max}) WsWrap.ws_send(self.client, send_kwargs, {"shield_current": shield_current, "shield_max": shield_max}) # except: # print("ERROR Updating Suit Shield for:", self.name) # print("")
def drop_item(self, user_input, input_kwargs): if self.inventory['r_hand']['contents'] == input_kwargs['target']: self.inventory['r_hand']['contents'] = None input_kwargs['target'].location = self.location input_kwargs['target'].location_body['location'] = None rooms[self.location].item_inv.append(input_kwargs['target']) print("[LOG]: Dropped item:", self.inventory['r_hand']['contents']) Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You drop {}.".format(Lex.a_an(input_kwargs['target'].name)), target_person = "", third_person = "{} drops {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) Update_Client.update_player_inventory(self) elif self.inventory['l_hand']['contents'] == input_kwargs['target']: self.inventory['l_hand']['contents'] = None input_kwargs['target'].location = self.location input_kwargs['target'].location_body['location'] = None rooms[self.location].item_inv.append(input_kwargs['target']) print("[LOG]: Dropped item:", self.inventory['l_hand']['contents']) Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You drop {}.".format(Lex.a_an(input_kwargs['target'].name)), target_person = "", third_person = "{} drops {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) Update_Client.update_player_inventory(self) else: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "You don't have that.")
def message_received(client, server, message): send_kwargs = {'type': 'text', 'spacing': True} # WsWrap.ws_send(client, send_kwargs, "") # if client['token'] == None: # client['guest_progress'] = 'name_input' # user_id = message.replace('"', "") # print(username) # client['token'] = username if client['type'] == 'guest': # server.send_message(client, send_kwargs, "> {}".format(message)) check_user(client, server, message) elif client['type'] == 'member_authenticated' or client['type'] == 'tourist': if client['obj'].conditions['echo'] == True: WsWrap.ws_send(client, {'type': 'text', 'spacing': 0}, "|repeat|> {}|repeatx|".format(message)) logging.debug('%s %s %s', ":", client['obj'].name, client['obj'].uuid_id) logging.debug('%s %s', ":", message) input_kwargs = {} all_ok = True cmd_found = False cmd_help = None user_input = message.split() print("SERVER PY | Splitting Input:", user_input) if not user_input: WsWrap.ws_send(client, send_kwargs, "|alert|No input.|alertx|") else: speaking = Input_Parser.speech(client['obj'], user_input, input_kwargs) if speaking == False: cmd_input, params = Input_Parser.parse_input(user_input) print("SERVER PY | cmd_input:", cmd_input) print("SERVER PY | params:", params) print("SERVER PY | user_input:", user_input) print("PARSE | inp matching command:", user_input) # input_kwargs['target'] = Input_Handler.full_handler(client['obj'], user_input, params) # try: T3_CMD = Lex.first_three(cmd_input) for i in all_commands: for hotkey in all_commands[i]['hotkey']: if user_input[0] == hotkey: cmd_found = True if all_commands[i]['requirements']: for func in all_commands[i]['requirements']: input_kwargs['cmd_name'] = i input_kwargs['cmd_req'] = all_commands[i]['requirements'][func]['req'] if 'help' in all_commands[i]: cmd_help = all_commands[i]['help'] status, response = all_commands[i]['requirements'][func]['func'](client['obj'], user_input, input_kwargs) input_kwargs['status'] = status input_kwargs['response'] = response if input_kwargs['status'] == False: if response != None: WsWrap.ws_send(client, {'type': 'text', 'spacing': 1}, "{}".format(response)) all_ok = False break # cmd_help if client['obj'].conditions['help'] == "enabled": if cmd_help != None: WsWrap.ws_send(client, {'type': 'text', 'spacing': 1}, "{}".format(cmd_help)) if all_ok == True: if all_commands[i]["need_com_name"] == "yes": all_commands[i]["func"](client['obj'], user_input, all_commands[i]["name"]) break elif all_commands[i]["need_com_input"] == "yes": all_commands[i]["func"](client['obj'], user_input, input_kwargs) break else: all_commands[i]["func"](client['obj']) break if cmd_found == False: WsWrap.ws_send(client, {'type': 'text', 'spacing': 1}, "Hmm?") logging.info("----------")
def display_room(self, user): room_num = user.location name_list = Gen.players_in_room(user) item_list = Gen.items_in_room(user) npc_list = Gen.npcs_in_room(user) # check if there are items if item_list == []: pass else: room_item_list = [] for i in item_list: room_item_list.append(i.name) room_item_list = Lex.converted_contents(room_item_list) if rooms[user.location].entity_type['group'] == "ship_personal": ship_num = rooms[user.location].ship_id room_of_ship = rooms[items[ship_num].location] WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "|room|{} | Outside you see {}|roomx|".format( rooms[room_num].name, Lex.a_an(room_of_ship.name))) else: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "|room|{} | {}|roomx| | [{},{}]".format( rooms[room_num].region, rooms[room_num].name, rooms[room_num].coordinates['x'], rooms[room_num].coordinates['y'])) # check if there are items if item_list == []: if rooms[user.location].entity_type['group'] == "ship_personal": room_ship_list = [] ship_list = Gen.ships_in_room(user) for i in ship_list: room_ship_list.append(i.name) if room_ship_list == []: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "{} Outside, {}".format( rooms[room_num].description, rooms[items[rooms[user.location].ship_id]. location].description.lower())) else: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "{} Outside, {} You also see the {}.".format( rooms[room_num].description, rooms[items[rooms[user.location].ship_id]. location].description.lower(), ", ".join(room_ship_list))) else: WsWrap.ws_send(user.client, { 'type': 'text', 'spacing': 0 }, "{}".format(rooms[room_num].description)) else: room_item_list = [] for i in item_list: if i.static_stats['visible'] == True: room_item_list.append(i.name) room_item_list = Lex.converted_contents(room_item_list) if "ship_personal" == rooms[user.location].entity_type['group']: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "{} Outside, {} You also see {}.".format( rooms[room_num].description, rooms[items[rooms[user.location].ship_id].location]. description.lower(), ", ".join(room_item_list))) else: if room_item_list == []: WsWrap.ws_send(user.client, { 'type': 'text', 'spacing': 0 }, "{}".format(rooms[room_num].description)) else: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "{} You also see {}.".format( rooms[room_num].description, ", ".join(room_item_list))) # check for npcs if npc_list == []: pass else: room_npc_names = [] for i in npc_list: if i.vitals['alive'] == False: room_npc_names.append("dead " + i.name) else: room_npc_names.append(i.name) WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "You also see |npc| {} |npcx|.".format(", ".join( Lex.converted_contents(room_npc_names)))) # check for other players if name_list == []: pass else: room_player_names = [] for i in name_list: if i.client['type'] == "tourist": i.name = "{} {}".format("Tourist", i.name) room_player_names.append('{} {}'.format( i.core_attributes['title'], i.name.capitalize())) WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 0 }, "|room| Also here: |roomx| {}".format( ", ".join(room_player_names))) # check for obvious exits if rooms[room_num].exits == {}: WsWrap.ws_send(user.client, { 'type': 'text', 'spacing': 1 }, "|exits| Exits: |/exits| None") else: WsWrap.ws_send( user.client, { 'type': 'text', 'spacing': 1 }, "|exits| Exits: |/exits| {}".format(", ".join( rooms[room_num].exits))) self.render_map(user)
def navigate(self, user_input, name): name = name travel_verb_first = "travel" travel_verb_third = "travels" if name in rooms[self.location].exits: exit_room = rooms[self.location].exits[name] if self.entity_type['base'] == "npc": rooms[self.location].npc_inv.remove(self) self.location = exit_room rooms[self.location].npc_inv.append(self) print("AI |", self.name, "moving rooms.") if self.entity_type['group'] != "human": Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "", target_person = "", third_person = "|alert|{} just arrived.|alertx|".format(Lex.a_an(self.name).capitalize())) else: Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "", target_person = "", third_person = "|alert|{} just arrived.|alertx|".format(self.name.capitalize())) else: rooms[self.location].player_inv.remove(self) Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You {} {}.".format(travel_verb_first, name), target_person = "", third_person = "{} {} {} {}.".format(self.core_attributes['title'], self.name.capitalize(), travel_verb_third, name)) self.location = exit_room rooms[self.location].player_inv.append(self) rooms[self.location].display_room(self) Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "", target_person = "", third_person = "{} {} just arrived.".format(self.core_attributes['title'], self.name.capitalize())) else: WsWrap.ws_send(self.client, {'type': 'text', 'spacing': 1}, "You can't go there.") rooms[self.location].render_map(self)
def look(self, user_input, input_kwargs): # This is the general look function. It allows a player to look at the room, # look at items, in items, etc. Basically anyhthing that invloves the 'look' # verb. print("LOOK | UI:", user_input) if len(user_input) == 1: rooms[self.location].display_room(self) else: if user_input[1] == "at": # input_kwargs['target'] = Input_Handler.full_handler(self, user_input[2], input_kwargs) WsWrap.ws_send( self.client, { 'type': 'text', 'spacing': 1 }, "|alert| Syntax: |alertx| L | L (item) | L in (item).") elif user_input[1] == "in": input_kwargs['target'] = Input_Handler.full_handler( self, user_input[2], input_kwargs) print("LOOK | ", input_kwargs) if not input_kwargs['target']: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Look in what?") else: if not hasattr(input_kwargs['target'], "is_open"): WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You can't really look in that.") else: if input_kwargs['target'].is_open == False: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "That is closed.") else: if input_kwargs['target'].entity_type[ 'base'] == "item": Item.items_in_item(self, user_input, input_kwargs) else: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You can't seem to do that.") else: input_kwargs['target'] = Input_Handler.full_handler( self, user_input[1], input_kwargs) print("LOOK | ", input_kwargs) if not input_kwargs['target']: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "That's not a valid target.") else: input_kwargs['target'].entity_description( self, user_input, input_kwargs)
def check_user(client, server, message): # print(message) send_kwargs = {'type': 'text', 'spacing': 1} if "username" in message: user_info = json.loads(message.lower()) client['uuid_id'] = user_info['username'] # print("LOG | CHECK USER MSG |", user_info) login = check_login(client['uuid_id']) if login == False: if client['type'] == "guest": print(client['guest_progress']) if client['guest_progress'] == 'name_input': WsWrap.ws_send( client, send_kwargs, "|comp|Welcome! Three questions and you're in the game.|/comp|" ) WsWrap.ws_send(client, send_kwargs, "|w|1. What is your first name?|/w|") client['guest_progress'] = 'name_confirm' elif client['guest_progress'] == 'name_confirm': client['name'] = re.sub("[^a-zA-Z]+", "", message) for i in players: if message.capitalize() == i.capitalize(): WsWrap.ws_send( client, send_kwargs, '|w| {} is taken. Please choose another. |/w|'. format(client['name'].capitalize())) break else: WsWrap.ws_send( client, send_kwargs, '|w|2. {}, is this correct? (y/n)|/w|'.format( client['name'].capitalize())) client['guest_progress'] = 'name_confirm2' elif client['guest_progress'] == 'name_confirm2': if message == "no" or message == "n": WsWrap.ws_send( client, send_kwargs, "|w|Alright, let's try this again. What is your first name?|/w|" ) client['guest_progress'] = 'name_confirm' elif message == "yes" or message == "y": WsWrap.ws_send( client, send_kwargs, '|w|3. Great. Are you (m)ale or (f)emale?|/w|') client['guest_progress'] = 'gender_input' elif client['guest_progress'] == 'gender_input': if message == "male" or message == "m": gender = "male" elif message == "female" or message == "f": gender = "female" if message != "female" and message != "f" and message != "male" and message != "m": WsWrap.ws_send(client, send_kwargs, '|w|Please choose (m)ale or (f)emale.|/w|') else: WsWrap.ws_send( client, send_kwargs, '|comp|Please stand by. Creating your character...|/comp|' ) client['type'] = 'member_authenticated' client['reg'] == "online" inventory = copy.deepcopy(inv) print("Guest:", client) hero = Player( **{ "uuid_id": client['uuid_id'], "entity_type": { "base": "player", "group": "registered", "model": None, "sub_model": None }, "name": client['name'], "race": "human", "gender": gender, "vitals": { "hp_max": 100, "hp_current": 100, "hp_mod": 0, "hp_regen": 1, "hp_regen_mod": 0, "alive": True }, "core_attributes": { "title": "Ensign", "str": { "base": 8, "mod": 0 }, "dex": { "base": 10, "mod": 0 }, "con": { "base": 8, "mod": 0 }, "ins": { "base": 12, "mod": 0 }, "edu": { "base": 10, "mod": 0 }, "soc": { "base": 10, "mod": 0 }, "xp": { "current": 0, "buffer": 0, "absorp_rate_percent": 1 } }, "conditions": { "stance": "stand", "action": "None", "state": "awake", "round_time": 0, "help": "enabled", "echo": False }, "credit": { "credit": 100 }, "location": "65d56cbe-f276-4055-899c-3244c0c92003", "player_state": "logged_in", "stow_loc": None, "client": client, "unique_id": None }) update_user_player(hero) add_new_player_to_db(hero) client['obj'] = hero # for i in all_schedules: # print(i) Sched_Child.create_new_sched(client['obj']) # update the client client['type'] == 'member_authenticated' # update the player object in the player list players[hero.uuid_id] = hero players[client['obj'].uuid_id].player_state = "online" WsWrap.ws_send_to_all( send_kwargs, "** A new player, {}, just joined the server.".format( hero.name)) WsWrap.ws_send( hero.client, send_kwargs, "|comp| Welcome, {}. We've been awaiting your arrival. |compx|" .format(hero.name.capitalize())) WsWrap.ws_send( hero.client, { 'type': 'text', 'spacing': 0 }, '|success| For your convenience, help cues are currently {}. Help cues will provide additional context or syntax when you type a command. Some commands may not have help associated with them yet. We are working on this. |successx|' .format(client['obj'].conditions['help'].upper())) WsWrap.ws_send( hero.client, { 'type': 'text', 'spacing': 1 }, '|success| Type HELP ON or HELP OFF to toggle this feature. |successx|' ) rooms[hero.location].player_inv.append(client['obj']) rooms[hero.location].display_room(hero) # update player settings to the client Update_Client.update_char_info(client['obj']) Update_Client.update_user_settings(client['obj']) Update_Client.update_player_health(client['obj']) Update_Client.update_player_attributes(client['obj']) Update_Client.update_player_list(client['obj']) Update_Client.update_player_inventory(client['obj']) Update_Client.update_central_db(client['obj']) else: # login = check_login(client['uuid_id']) inventory = copy.deepcopy(inv) hero = players[login] hero.inventory = inventory client['obj'] = hero client['type'] = "member_authenticated" players[client['obj'].uuid_id].player_state = "online" rooms[hero.location].player_inv.append(client['obj']) print("New Client Connected:", client, client['obj']) print("") client['id'] = client['obj'].unique_id print("Updated Client:", client, client['obj']) print("") if hero.uuid_id in all_schedules: pass else: Sched_Child.create_new_sched(client['obj']) for u in items: if items[u].location == client['obj'].uuid_id: if "location" in items[u].location_body: # print("LOG: Re-adding item", items[u].name, "to", items[u].location_body['location']) hero.inventory[items[u].location_body['location']][ 'contents'] = items[u] # # check round_time # if hero.conditions['round_time'] > 0: # if 'round_time' in all_schedules[hero.uuid_id]['sched'].event_names: # hero.round_time_dec() # update the player object in the player list client['obj'].client = client Lex.pub_print( self=client['obj'], target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person= "|comp| Welcome back, {}. We've been awaiting your arrival. |compx|" .format(hero.name.capitalize()), target_person="", third_person="{} just arrived.".format( client['obj'].name.capitalize())) WsWrap.ws_send( hero.client, { 'type': 'text', 'spacing': 0 }, '|success| For your convenience, help cues are currently |successx| |y| {}|yx|. |success| Help cues will provide additional context or syntax when you type a command. Some commands may not have help associated with them yet. We are working on this. |successx|' .format(client['obj'].conditions['help'].upper())) WsWrap.ws_send( hero.client, { 'type': 'text', 'spacing': 1 }, '|success| Type HELP ON or HELP OFF to toggle this feature. |successx|' ) WsWrap.ws_send( hero.client, { 'type': 'text', 'spacing': 1 }, '|success| You may also toggle the input echo on/off by typing "echo". Default is off. |successx|' ) rooms[client['obj'].location].display_room(client['obj']) # update player settings to the client Update_Client.update_char_info(client['obj']) Update_Client.update_user_settings(client['obj']) Update_Client.update_player_health(client['obj']) Update_Client.update_suit_shield(client['obj']) Update_Client.update_player_attributes(client['obj']) Update_Client.update_player_list(client['obj']) Update_Client.update_player_inventory(client['obj']) Update_Client.update_central_db(client['obj'])
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 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 update_map(self, map_render): send_kwargs = {'type': 'map_render', 'spacing': False} WsWrap.ws_send(self.client, send_kwargs, map_render)
def update_player_attributes(self): send_kwargs = {'type': 'attr', 'spacing': False} # update core attributes WsWrap.ws_send(self.client, send_kwargs, self.core_attributes)
def stow_set(self, user_input, input_kwargs): stow_item = False if len(user_input) == 1 or len(user_input) > 3: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Syntax: STOW SET (container) or STOW (ITEM)") elif user_input[1] == "set": input_kwargs['target'] = Input_Handler.target_self_inventory( self, user_input[2], input_kwargs) self.stow_loc = input_kwargs['target'] if self.stow_loc == None: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Make sure you are wearing the container.") else: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Ok.") elif user_input[1] != "set": if self.stow_loc == None: WsWrap.ws_send( self.client, { 'type': 'text', 'spacing': 1 }, "You must first STOW SET (CONTAINER) for a container you are wearing." ) elif self.stow_loc.location_body['state'] != "worn": WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You must be wearing that container.") elif self.inventory['r_hand']['contents'] != None: if user_input[1] in self.inventory['r_hand']['contents'].name: stow_item = True input_kwargs['target'] = self.inventory['r_hand'][ 'contents'] input_kwargs['target_parent'] = self.stow_loc elif self.inventory['l_hand']['contents'] != None: if user_input[1] in self.inventory['l_hand']['contents'].name: stow_item = True input_kwargs['target'] = self.inventory['l_hand'][ 'contents'] input_kwargs['target_parent'] = self.stow_loc else: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You can't stow that.") if stow_item == True: status, response = Status_Check.item_open_closed( self, user_input, input_kwargs) if status == True: if self.stow_loc == input_kwargs['target']: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "You can't stow something in itself.") else: Character.put_item(self, user_input, input_kwargs) else: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "That is not open.") else: WsWrap.ws_send(self.client, { 'type': 'text', 'spacing': 1 }, "Error with STOW target.")