Exemple #1
0
    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)
Exemple #2
0
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'])
Exemple #3
0
    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())
Exemple #4
0
    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)
Exemple #5
0
    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)
Exemple #6
0
	def animation_load(self, user, user_input, input_kwargs):

		first_person = "You easily slide the magazine into your {}.".format(self.name)
		target_person = "{} slides a magazine into {} {}.".format(user.name, Lex.gender(user, "own"), self.name)
		third_person = "{} slides a magazine into {} {}.".format(user.name, Lex.gender(user, "own"), self.name)

		return first_person, target_person, third_person
Exemple #7
0
    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)))
Exemple #8
0
    def animation_load(self, user, user_input, input_kwargs):
        print(user.inventory)

        first_person = "You side-load {} into your {} and it immediately spins up, humming with energy.".format(
            Lex.a_an(user.inventory['l_hand']['contents'].name),
            user.inventory['r_hand']['contents'].name)
        target_person = ""
        third_person = "{} side-loads {} into {} {}.".format(
            user.name, Lex.a_an(user.inventory['l_hand']['contents'].name),
            Lex.gender(user, "own"),
            Lex.a_an(user.inventory['r_hand']['contents'].name))

        return first_person, target_person, third_person
Exemple #9
0
    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)
Exemple #10
0
    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))))
Exemple #11
0
    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)
Exemple #12
0
    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 = {}
Exemple #13
0
    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'])
Exemple #14
0
    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))
Exemple #15
0
    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
        }
Exemple #16
0
    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)))
Exemple #17
0
    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
Exemple #18
0
    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
Exemple #19
0
    def target_items_in_self_l_hand(self, user_input, input_kwargs):

        # check left hand next
        target = None
        print("hand user_input:", user_input)

        if self.inventory['l_hand']['contents']:
            if Lex.first_three(self.inventory['l_hand']
                               ['contents'].keyword) in user_input:
                target = item
                print("HANDLER | Target Found: self l_hand, ", target)

        return target
Exemple #20
0
    def target_self_inventory(self, user_input, input_kwargs):

        # check if the target is in your inventory
        target = None

        for inv in self.inventory:
            if self.inventory[inv]['contents']:
                item = self.inventory[inv]['contents']

                if Lex.first_three(item.keyword) in user_input:
                    target = item

        return target
Exemple #21
0
    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,
            )
Exemple #22
0
    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="")
Exemple #23
0
    def docking(self, user_input, input_kwargs, destination):

        ship_id = rooms[self.location].ship_id

        print("Ship_ID:", ship_id)
        print("Ship was in room:", items[ship_id].location)

        items[ship_id].location = destination
        rooms[destination].item_inv.append(items[ship_id])

        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':
                'The ship safely completes its docking. Outside, you see {}. {}'
                .format(
                    Lex.a_an(rooms[items[ship_id].location].name).lower(),
                    rooms[items[ship_id].location].description),
                'target_person':
                '',
                'third_person':
                'The ship safely completes its docking. Outside, you see {}. {}'
                .format(
                    Lex.a_an(rooms[items[ship_id].location].name).lower(),
                    rooms[items[ship_id].location].description)
            })

        print("Ship now in room:", destination)
        print("Inv of this room:", rooms[destination].item_inv)
Exemple #24
0
    def display_npc_inventory(target):

        npc_inv = []

        for i in target.inventory:
            if target.inventory[i]['contents'] == None:
                pass
            else:
                npc_inv.append("{} {} {} {}".format(
                    target.inventory[i]['contents'].name,
                    target.inventory[i]['worn'], Lex.gender(target, "own"),
                    target.inventory[i]['name']))
        if npc_inv == []:
            npc_inv = "nothing"

        print(npc_inv)
        return npc_inv
Exemple #25
0
    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.")
Exemple #26
0
    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()))
Exemple #27
0
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("----------")
Exemple #28
0
    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
Exemple #29
0
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'])
Exemple #30
0
    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)