Exemplo n.º 1
0
def familiar_scout(mud, players, id, nid, npcs, npcs_db, rooms, direction):
    """familiar begins scouting the surrounding rooms
    """
    start_room_id = npcs[nid]['room']
    room_exits = rooms[start_room_id]['exits']

    new_path = []

    if direction == 'any' or direction == 'all' or len(direction) == 0:
        new_path = \
            _familiar_scout_any_direction(npcs[nid]['siz'], start_room_id,
                                          room_exits, rooms)
    else:
        new_path = \
            _familiar_scout_in_direction(mud, players, id, start_room_id,
                                         room_exits, direction, rooms)

    if len(new_path) > 0:
        npcs[nid]['familiarMode'] = "scout"
        npcs[nid]['moveType'] = "patrol"
        npcs[nid]['path'] = deepcopy(new_path)
        npcs_db[nid]['familiarMode'] = "scout"
        npcs_db[nid]['moveType'] = "patrol"
        npcs_db[nid]['path'] = deepcopy(new_path)
    else:
        familiar_default_mode(nid, npcs, npcs_db)
Exemplo n.º 2
0
def run_messages(mud, channels, players):
    # go through channels messages queue and send messages to subscribed
    # players
    previous_timing = time.time()

    chans = deepcopy(channels)

    previous_timing = \
        show_timing(previous_timing, "copy channels")

    for plyr in players:
        if players[plyr]['channels'] is not None:
            for cha in players[plyr]['channels']:
                # print(c)
                for msg in chans:
                    if chans[msg]['channel'] == cha:
                        mud.send_message(
                            plyr, "[<f191>" + chans[msg]['channel'] +
                            "<r>] <f32>" + chans[msg]['sender'] +
                            "<r>: " + chans[msg]['message'] + "\n")
                        # del channels[m]
            previous_timing = \
                show_timing(previous_timing, "send message " +
                            str(len(players[plyr]['channels'])) + ' x ' +
                            str(len(chans)))
Exemplo n.º 3
0
def remove_corpses(corpses: {}):
    # Iterate through corpses and remove ones older than their TTL
    corpses_copy = deepcopy(corpses)
    curr_time = int(time.time())
    for cor, _ in corpses_copy.items():
        if curr_time >= corpses_copy[cor]['died'] + corpses_copy[cor]['TTL']:
            del corpses[cor]
Exemplo n.º 4
0
def disconnect_idle_players(mud, players: {}, allowed_player_idle: int,
                            players_db: {}) -> bool:
    # Evaluate player idle time and disconnect if required
    authenticated_players_disconnected = False
    now = int(time.time())
    players_copy = deepcopy(players)
    for plyr in players_copy:
        if now - players_copy[plyr]['idleStart'] > allowed_player_idle:
            if players[plyr]['authenticated'] is not None:
                mud.send_message_wrap(
                    plyr, "<f232><b11>",
                    "<f232><b11>Your body starts tingling. " +
                    "You instinctively hold your hand up to " +
                    "your face and notice you slowly begin to " +
                    "vanish. You are being disconnected due " +
                    "to inactivity...****DISCONNECT****\n")
                save_state(players[plyr], players_db, False)
                authenticated_players_disconnected = True
            else:
                mud.send_message(
                    plyr, "<f232><b11>You are being disconnected " +
                    "due to inactivity. Bye!****DISCONNECT****\n")
            name_str = str(players[plyr]['name'])
            if str(plyr).isdigit():
                name_str += ' ID ' + str(plyr)
            log(
                "Character " + name_str +
                " is being disconnected due to inactivity.", "warning")
            p_str = str(plyr)
            log("Disconnecting client " + p_str, "warning")
            del players[plyr]
            mud.handle_disconnect(plyr)
    return authenticated_players_disconnected
Exemplo n.º 5
0
def _run_player_disconnections(mud, players, players_db, fights, Config,
                               terminalMode: {}):
    # go through any recently disconnected players
    for id in mud.get_disconnected_players():

        # if for any reason the player isn't in the player map, skip them and
        # move on to the next one
        if id not in players:
            continue

        id_str = str(id)
        terminalMode[id_str] = False
        name_str = str(players[id]['name'])
        log("Player ID " + id_str + " has disconnected [" + name_str + "]",
            "info")

        # go through all the players in the game
        for pid, _ in list(players.items()):
            # send each player a message to tell them about the diconnected
            # player if they are in the same room
            if players[pid]['authenticated'] is not None:
                if players[pid]['authenticated'] is not None \
                   and players[pid]['room'] == players[id]['room'] \
                   and players[pid]['name'] != players[id]['name']:
                    mud.send_message(
                        pid, "<f32><u>{}<r>".format(players[id]['name']) +
                        "'s body has vanished.\n\n")

        # Code here to save player to the database after he's disconnected and
        # before removing him from players dictionary
        if players[id]['authenticated'] is not None:
            log("Player disconnected, saving state", "info")
            save_state(players[id], players_db, False)
            players_db = load_players_db()

        # Create a deep copy of fights, iterate through it and remove fights
        # disconnected player was taking part in
        fights_copy = deepcopy(fights)
        for fight, _ in fights_copy.items():
            if fights_copy[fight]['s1'] == players[id]['name'] or \
               fights_copy[fight]['s2'] == players[id]['name']:
                del fights[fight]

        # remove the player's entry in the player dictionary
        del players[id]
Exemplo n.º 6
0
def familiar_recall(mud, players, id, npcs, npcs_db):
    """Move any familiar to the player's location
    """
    # remove any existing familiars
    removals = []
    for nid, item in list(npcs.items()):
        if item['familiarOf'] == players[id]['name']:
            removals.append(nid)

    for index in removals:
        del npcs[index]

    # By default player has no familiar
    players[id]['familiar'] = -1

    # Find familiar and set its room to that of the player
    for nid, item in list(npcs_db.items()):
        if item['familiarOf'] == players[id]['name']:
            players[id]['familiar'] = int(nid)
            if not npcs.get(nid):
                npcs[nid] = deepcopy(npcs_db[nid])
            npcs[nid]['room'] = players[id]['room']
            mud.send_message(id, "Your familiar is recalled.\n\n")
            break
Exemplo n.º 7
0
add_to_scheduler(1, -1, event_schedule, scripted_events_db)
add_to_scheduler(2, -1, event_schedule, scripted_events_db)
add_to_scheduler(3, -1, event_schedule, scripted_events_db)

# Declare number of seconds to elapse between State Saves
# A State Save takes values held in memory and updates the database
# at set intervals to achieve player state persistence
state_save_interval = int(Config.get('World', 'StateSaveInterval'))
state_save_inter_str = str(state_save_interval)
log("State Save interval: " + state_save_inter_str + " seconds", "info")

# Set last state save to 'now' on server boot
last_state_save = int(time.time())

# Deepcopy npcs fetched from a database into a master template
npcs_template = deepcopy(npcs)

# List items in world for debugging purposes
# for x in items_in_world:
# print (x)
# for y in items_in_world[x]:
# print(y,':',items_in_world[x][y])

# stores the players in the game
players = {}

# list of players
player_list = []

# start the server
mud = MudServer(websocket_tls, websocket_cert, websocket_key, websocket_ver)
Exemplo n.º 8
0
def run_deaths(mud, players: {}, npcs: {}, corpses, fights: {}, event_schedule,
               scripted_events_db):
    # Handle Player Deaths
    for pid, _ in list(players.items()):
        if players[pid]['authenticated']:
            if players[pid]['hp'] <= 0:
                corpse_name = str(players[pid]['name'] + "'s corpse")
                if not corpse_exists(corpses, players[pid]['room'],
                                     corpse_name):
                    # Create player's corpse in the room
                    corpses[len(corpses)] = {
                        'room': players[pid]['room'],
                        'name': corpse_name,
                        'inv': deepcopy(players[pid]['inv']),
                        'died': int(time.time()),
                        'TTL': players[pid]['corpseTTL'],
                        'owner': 1
                    }
                # Clear player's inventory, it stays on the corpse
                players[pid]['clo_lhand'] = 0
                players[pid]['clo_rhand'] = 0
                players[pid]['inv'] = []
                players[pid]['isInCombat'] = 0
                players[pid]['prone'] = 1
                players[pid]['shove'] = 0
                players[pid]['dodge'] = 0
                players[pid]['lastRoom'] = players[pid]['room']
                players[pid]['room'] = '$rid=1262$'
                fights_copy = deepcopy(fights)
                for fight, _ in fights_copy.items():
                    if ((fights_copy[fight]['s1type'] == 'pc'
                         and fights_copy[fight]['s1id'] == pid)
                            or (fights_copy[fight]['s2type'] == 'pc'
                                and fights_copy[fight]['s2id'] == pid)):
                        # clear the combat flag
                        if fights_copy[fight]['s1type'] == 'pc':
                            fid = fights_copy[fight]['s1id']
                            players[fid]['isInCombat'] = 0
                        elif fights_copy[fight]['s1type'] == 'npc':
                            fid = fights_copy[fight]['s1id']
                            npcs[fid]['isInCombat'] = 0
                        if fights_copy[fight]['s2type'] == 'pc':
                            fid = fights_copy[fight]['s2id']
                            players[fid]['isInCombat'] = 0
                        elif fights_copy[fight]['s2type'] == 'npc':
                            fid = fights_copy[fight]['s2id']
                            npcs[fid]['isInCombat'] = 0
                        players[pid]['isInCombat'] = 0
                        del fights[fight]
                for pid2, _ in list(players.items()):
                    if players[pid2]['authenticated'] is not None \
                       and players[pid2]['room'] == players[pid]['lastRoom'] \
                       and players[pid2]['name'] != players[pid]['name']:
                        mud.send_message(
                            pid2, '<u><f32>{}'.format(players[pid]['name']) +
                            '<r> <f124>has been killed.\n')
                        players[pid]['lastRoom'] = None
                        mud.send_message(
                            pid, '<b88><f158>Oh dear! You have died!\n')

                # Add Player Death event (ID:666) to event_schedule
                add_to_scheduler(666, pid, event_schedule, scripted_events_db)

                players[pid]['hp'] = 4