def combat_flow(self, user_input, input_kwargs, combat_kwargs): # Debug --- print( f"COMBAT | FLOW | Entity: {self.name}, input_kwargs: {input_kwargs}, combat_kwargs: {combat_kwargs}" ) # Determine dmg output --- Combat.calc_dmg(self, user_input, input_kwargs, combat_kwargs) # Establish RT --- if self.entity_type['base'] == "player": self.round_time_set(combat_kwargs['round_time']) Update_Client.update_round_time(self) Lex.pub_print( self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person= f"Round time, {combat_kwargs['round_time']} seconds...", target_person="", third_person="", ) # Check death --- self.check_death(user_input, input_kwargs)
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 check_death(self, user_input, input_kwargs): if input_kwargs['target'].vitals['hp_current'] <= 0: if input_kwargs['target'].entity_type['base'] == "npc": Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "|npc|{} crumples into a heap and dies.|npcx|".format(Lex.a_an(input_kwargs['target'].name).capitalize()), target_person = "", third_person = "|npc|{} crumples into a heap and dies.|npcx|".format(Lex.a_an(input_kwargs['target'].name).capitalize())) input_kwargs['target'].conditions['stance'] = "lying" input_kwargs['target'].conditions['state'] = "sleep" input_kwargs['target'].vitals['alive'] = False # clear the event schedule ent_sched = all_schedules[input_kwargs['target'].uuid_id]['sched'] list(map(ent_sched.cancel, ent_sched.queue)) elif input_kwargs['target'].entity_type['base'] == "player": input_kwargs['target'].conditions['stance'] = "lying" 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 = "|alert|You crumple into a heap and die.|alertx|", third_person = "{} crumples into a heap and dies.".format(input_kwargs['target'].name).capitalize())
def client_left(client, server): # client['obj'].conditions['schedule'] = { # 'event_names': all_schedules[client['obj'].uuid_id]['sched'].event_names, # 'event_types': all_schedules[client['obj'].uuid_id]['sched'].event_types # } # update_db_player(players[client['obj'].uuid_id]) send_kwargs = {'type': 'text', 'spacing': 1} Lex.pub_print( self=client['obj'], target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "", target_person = "", third_person = "{} just left.".format(client['obj'].name.capitalize())) logging.debug('%s %s', "LOG | Removing client:", client['obj']) logging.info("----------") print("LOG | Removing client:", client['obj'], "from room:", rooms[client['obj'].location].player_inv) players[client['obj'].uuid_id].player_state = "logged_out" rooms[client['obj'].location].player_inv.remove(client['obj']) # Update_Client.update_player_object(client['obj']) Update_Client.update_player_list(client['obj'])
def comms(self, user_input, input_kwargs): Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = '|self_comm|You say|/self_speech|, "{}"'.format(" ".join(user_input)), target_person = "", third_person = '|player_comm|{} says|/player_speech|, "{}"'.format(self.name.capitalize(), " ".join(user_input)))
def swap_hands(self, user_input, input_kwargs): right_hand = self.inventory['r_hand']['contents'] left_hand = self.inventory['l_hand']['contents'] self.inventory['r_hand']['contents'] = left_hand self.inventory['l_hand']['contents'] = right_hand Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You swap the items in your hands.", target_person = "", third_person = "{} swaps the items in {} hands.".format(self.name.capitalize(), Lex.gender(self, "own"))) Update_Client.update_player_inventory(self)
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 enter_holo(self, user_input, input_kwargs): holo_template = "6942edc5-1f21-4164-86e7-b10f7a3d0b6a" new_holo = Room( **{ "uuid_id": uuid.uuid4(), # uuid "entity_type": rooms[holo_template].entity_type, # base_type "ship_id": rooms[holo_template].ship_id, # ship_id "coordinates": rooms[holo_template].coordinates, # coordinates "name": rooms[holo_template].name, # name "description": rooms[holo_template].description, # description "exits": { "out": self.location }, # exits "region": rooms[holo_template].region, # region "zone": rooms[holo_template].zone, # zone "elevation": rooms[holo_template].elevation, # elevation "effects": rooms[holo_template].effects, # effects "player_inv": rooms[holo_template].player_inv, # player_inv "item_inv": rooms[holo_template].item_inv, # item_inv "npc_inv": rooms[holo_template].npc_inv, # npc_inv "mob_inv": rooms[holo_template].mob_inv, # mob_inv "owner": rooms[holo_template].owner }) # owner rooms[new_holo.uuid_id] = new_holo rooms[self.location].player_inv.remove(self) print("before holo:", self.location) self.location = new_holo.uuid_id print("after holo:", self.location) rooms[self.location].player_inv.append(self) Room.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))
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 put_item(self, user_input, input_kwargs): if self.inventory['r_hand']['contents'] == input_kwargs['target']: hand = self.inventory['r_hand'] elif self.inventory['l_hand']['contents'] == input_kwargs['target']: hand = self.inventory['l_hand'] input_kwargs['target_parent'].item_inv.append(hand['contents']) hand['contents'] = None Update_Client.update_player_inventory(self) Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "You put {} in {}.".format(Lex.a_an(input_kwargs['target'].name), Lex.a_an(input_kwargs['target_parent'].name)), target_person = "", third_person = "{} puts {} in {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name), Lex.a_an(input_kwargs['target_parent'].name)))
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 entity_description(self, user, user_input, input_kwargs): if self.vitals['alive'] == True: first_person_value = "{}".format(self.description['desc']) target_person_value = "" third_person_value = "{} observes {}.".format(self.description['name'], Lex.a_an(self.description['name'])) else: first_person_value = "{} is dead. {}".format(Lex.gender(self.description['name'], "pro").capitalize(), self.description['desc']), target_person_value = "{} observes your dead body.".format(self.description['name']) third_person_value = "{} observes {}.".format(self.description['name'], Lex.a_an(self.description['name'])) Lex.pub_print( self=user, target=input_kwargs['target'], send_kwargs={'type': 'text', 'spacing': 1}, first_person = first_person_value, target_person = target_person_value, third_person = third_person_value, )
def voice_command(self, user, user_input, input_kwargs): for cmd_entry in ship_ai_cmds: if user_input[2] == cmd_entry: cmd = ship_ai_cmds[cmd_entry] ship_ai_cmds[cmd_entry]['cmd_run'](self, user_input, input_kwargs) break else: Lex.pub_print(self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person="That didn't work.", target_person="", third_person="")
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 search_target(self, user_input, input_kwargs): inv_dropped = [] for i in input_kwargs['target'].inventory: inv_item = input_kwargs['target'].inventory[i]['contents'] if input_kwargs['target'].inventory[i]['contents'] == None: pass else: inv_dropped.append(input_kwargs['target'].inventory[i]['contents'].name) inv_item.location = self.location input_kwargs['target'].inventory[i]['contents'] = None rooms[self.location].item_inv.append(inv_item) if inv_dropped == []: Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 0}, first_person = "You pat down {} but it had nothing of value.".format(Lex.a_an(input_kwargs['target'].name), ", ".join(inv_dropped)), target_person = "", third_person = "{} searches {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) else: Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 0}, first_person = "You pat down {} and find {}.".format(Lex.a_an(input_kwargs['target'].name), ", ".join(inv_dropped)), target_person = "", third_person = "{} searches {}.".format(self.name.capitalize(), Lex.a_an(input_kwargs['target'].name))) Lex.pub_print( self=self, target=None, send_kwargs={'type': 'text', 'spacing': 1}, first_person = "The {} decays away.".format(input_kwargs['target'].name), target_person = "", third_person = "The {} decays away.".format(input_kwargs['target'].name)) del all_schedules[input_kwargs['target'].uuid_id] rooms[self.location].npc_inv.remove(input_kwargs['target'])
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 create_first_room(self): # create the first room room_obj = self.create_room() self.current_size += 1 # pick a random spot in the max_size grid room_obj.coordinates['x'] = 0 room_obj.coordinates['y'] = 0 # add to global room list rooms[room_obj.uuid_id] = room_obj # add to local instance room list self.instance.append(room_obj) # create portal to first room from current room portal_in = Item( uuid_id=uuid.uuid4(), join_table={ "module": "Item", "class": "Item", "table": "item_table", "keyword": "door_ship_visible" }, description={ "name": "portal", "desc": "Looks like a black void with purple clouds encircling it." }, keyword="portal", attributes={"is_door"}, dynamic_stats={}, room_target={'target': room_obj.uuid_id}, location=self.user.location, location_body=None, owner=None, is_open=True, vitals={}) portal_out = Item( uuid_id=uuid.uuid4(), join_table={ "module": "Item", "class": "Item", "table": "item_table", "keyword": "door_ship_visible" }, description={ "name": "portal", "desc": "Looks like a black void with purple clouds encircling it." }, keyword="portal", attributes={"is_door"}, dynamic_stats={}, room_target={'target': rooms[self.user.location].uuid_id}, location=room_obj.uuid_id, location_body=None, owner=None, is_open=True, vitals={}) # pprint.pprint(vars(portal_in)) # pprint.pprint(vars(portal_out)) # add portal into instance in current room items[portal_in.uuid_id] = portal_in rooms[portal_in.location].item_inv.append(portal_in) # add exit portal from instance back to original room items[portal_out.uuid_id] = portal_out rooms[portal_out.location].item_inv.append(portal_out) Lex.pub_print(self=self.user, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person='A portal suddenly appears.', target_person="", third_person='A portal suddenly appears.') print("PROCGEN | Created First Room:", room_obj.name, "|", room_obj.coordinates, "|", room_obj.exits) return room_obj
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 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)))
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 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 calc_dmg(self, user_input, input_kwargs, combat_kwargs): # Establish attack die and attack modifier from ammo, these are defaults # or overridden if items are present weapon_base_dmg = 1 weapon_base_dmg_mod = 0 if self.inventory["r_hand"]["contents"]: weapon_base = combat_kwargs['attribute'] + "_base" weapon_mod_base = combat_kwargs['attribute'] + "_mod" # Override R hand weapon_base_dmg if weapon_base in self.inventory["r_hand"][ "contents"].static_stats: if self.inventory["r_hand"]["contents"].static_stats[ weapon_base]: weapon_base_dmg = self.inventory["r_hand"][ "contents"].static_stats[weapon_base] # Override R hand weapon_base_mod if weapon_mod_base in self.inventory["r_hand"][ "contents"].static_stats: if self.inventory["r_hand"]["contents"].item_inv != []: if self.inventory["r_hand"]["contents"].entity_type[ 'group'] == "gun": weapon_base_dmg_mod = items[ self.inventory["r_hand"]["contents"]. dynamic_stats['ammo_id']].static_stats[weapon_base] # Pull in attacker's appropriate attibute and create a base roll attrib_base = self.core_attributes[combat_kwargs['attribute']]['base'] base_roll = random.randint(1, 12) # Base Attack is simply the attack die multiplied by the base roll base_att = attrib_base + weapon_base_dmg + weapon_base_dmg_mod + base_roll final_dmg = base_att # apply damage if input_kwargs['target'].inventory['suit']['contents'] == None: # client printing options if self.entity_type['base'] == "player": send_kwargs = {'type': 'text', 'spacing': 0} # if AI is performing elif self.entity_type['base'] == "npc": send_kwargs = {'type': 'text', 'spacing': 1} input_kwargs['target'].vitals['hp_current'] = input_kwargs[ 'target'].vitals['hp_current'] - final_dmg if input_kwargs['target'].entity_type['base'] == 'player': Update_Client.update_player_health(input_kwargs['target']) Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={ 'type': 'text', 'spacing': 0 }, first_person="AB: {} + WBD: {} + WBDM: {} + BR: {} = {}". format(attrib_base, weapon_base_dmg, weapon_base_dmg_mod, base_roll, base_att), target_person="AB: {} + WBD: {} + WBDM: {} + BR: {} = {}". format(attrib_base, weapon_base_dmg, weapon_base_dmg_mod, base_roll, base_att), third_person="", ) Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs=send_kwargs, first_person="You hit for {} damage!".format(final_dmg), target_person="|alert| You take {} damage! |alertx|".format( final_dmg), third_person="{} takes the force of the blow.".format( input_kwargs['target'].name), ) else: if input_kwargs['target'].entity_type['base'] == 'player': if input_kwargs['target'].inventory['suit']['contents'].vitals[ 'shield_current'] > 0: if input_kwargs['target'].inventory['suit'][ 'contents'].vitals['shield_current'] < final_dmg: input_kwargs['target'].inventory['suit'][ 'contents'].vitals['shield_current'] = 0 else: input_kwargs['target'].inventory['suit'][ 'contents'].vitals['shield_current'] = input_kwargs[ 'target'].inventory['suit']['contents'].vitals[ 'shield_current'] - final_dmg Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person= "You see its shield glimmer as you hit for {} damage!". format(final_dmg), target_person= '|self_suit| "Shields absorb {} damage, {}% integrity." |self_suitx|' .format( final_dmg, input_kwargs['target'].inventory['suit'] ['contents'].vitals['shield_current']), third_person= "{}'s suit glimmers as it absorbs the damage.".format( input_kwargs['target'].name), ) else: input_kwargs['target'].vitals['hp_current'] = input_kwargs[ 'target'].vitals['hp_current'] - final_dmg Update_Client.update_player_health(input_kwargs['target']) Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person="Shields are down! You hit for {} damage!" .format(final_dmg), target_person= '|alert| "Your suit\'s shield is broken and your body takes {} damage!" |alertx|' .format(final_dmg), third_person="", ) return attrib_base, base_roll, final_dmg
def attack(self, user_input, input_kwargs): # Combat flow parameters --- combat_kwargs = { "round_time": 5, "combat_action": "attack", "attribute": "str" } # input_kwargs['round_time'] = round_time # input_kwargs["combat_action"] = "attack" # if player is performing if self.entity_type['base'] == "player": ent_label = "player" ent_name = self.name.capitalize() send_kwargs = {'type': 'text', 'spacing': 0} # if AI is performing elif self.entity_type['base'] == "npc": send_kwargs = {'type': 'text', 'spacing': 0} ent_label = "npc" ent_name = Lex.a_an(self.name).capitalize() # catch other errors else: ent_label = "" ent_name = "|error: no ent name|" # --- # LOG for reviewing attacks if self.entity_type['base'] == "npc": print("COMBAT | AI | CMD: ATTACK |", self.name, "attacking", input_kwargs['target'].name) else: print("COMBAT | PLAYER | CMD: ATTACK |", self.name, "attacking", input_kwargs['target'].name) # Determine if unarmed or armed attack and set nouns for rest of function if self.inventory["r_hand"]["contents"]: weapon = self.inventory["r_hand"]["contents"].name else: weapon = "fist" if self.inventory["r_hand"]['contents'] == None: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs=send_kwargs, first_person="|self_text| You swing a fist at {}! |self_textx|" .format(Lex.a_an(input_kwargs['target'].name)), target_person="{} swings a fist at you!".format( Lex.a_an(self.name).capitalize()), third_person="{} swings a fist at {}!".format( ent_name, Lex.a_an(input_kwargs['target'].name))) else: Lex.pub_print( self=self, target=input_kwargs['target'], send_kwargs=send_kwargs, first_person="|self_text| You swing {} at {}! |self_textx|". format(Lex.a_an(weapon), Lex.a_an(input_kwargs['target'].name)), target_person="{} swings {} at you!".format( ent_name, Lex.a_an(weapon)), third_person="{} swings {} at {}!".format( ent_name, Lex.a_an(weapon), Lex.a_an(input_kwargs['target'].name))) # Run post-attack combat flow Combat.combat_flow(self, user_input, input_kwargs, combat_kwargs)
def fire_gun(self, user_input, input_kwargs): # Combat flow parameters --- combat_kwargs = { "round_time": 5, "combat_action": "fire_gun", "attribute": "dex" } # --- mag = items[self.inventory["r_hand"] ["contents"].dynamic_stats['ammo_id']] mag.dynamic_stats['current_capacity'] -= 1 Lex.pub_print( self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 0 }, first_person="|self_speech| You fire your {} at {}! |self_speechx|" .format(self.inventory["r_hand"]["contents"].name, Lex.a_an(input_kwargs['target'].name)), target_person="", third_person="{} fires {} {} at {}!".format( self.name, Lex.gender(self, "own"), self.inventory["r_hand"]["contents"].name, Lex.a_an(input_kwargs['target'].name))) # Run post-attack combat flow Combat.combat_flow(self, user_input, input_kwargs, combat_kwargs) if mag.dynamic_stats['current_capacity'] < 1: self.inventory["r_hand"]["contents"].dynamic_stats[ 'loaded'] = False self.inventory["r_hand"]["contents"].dynamic_stats[ 'ammo_id'] = None self.inventory["r_hand"]["contents"].item_inv.remove( items[mag.uuid_id]) del items[mag.uuid_id] Lex.pub_print( self=self, target=None, send_kwargs={ 'type': 'text', 'spacing': 1 }, first_person= "|alert|You're dry!|alertx| You release the empty {} and it casually falls to the ground out of sight." .format(mag.name), target_person="", third_person= "{} releases a spent magazine from {} {} and it falls aside.". format(self.name, Lex.gender(self, "own"), self.inventory["r_hand"]["contents"].name)) else: pass