示例#1
0
文件: complexmud.py 项目: hsum/mud-pi
        mud.send_message(player_id, "You arrive at '{}'".format(
                                                  players[player_id]["room"]))

    # the specified exit wasn't found in the current room
    else:
        # send back an 'unknown exit' message
        mud.send_message(player_id, "Unknown exit '{}'".format(ex))
#print(list(
#    (k.replace('command_', ''), v) for k, v in locals().items() if callable(v) and k.startswith('command_')
#))
commands = {
    k.replace('command_', ''): v for k, v in locals().items() if callable(v) and k.startswith('command_')
}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    while mud.events_new_player:
        player_id = mud.events_new_player.popleft()
示例#2
0
npcsTemplate = deepcopy(npcs)

# List items in world for debugging purposes
# for x in itemsInWorld:
	# print (x)
	# for y in itemsInWorld[x]:
		# print(y,':',itemsInWorld[x][y])
		
# stores the players in the game
players = {}

#list of players for Grapevine
playerList = []

# start the server
mud = MudServer()



# main game loop. We loop forever (i.e. until the program is terminated)
while True:
	# print(int(time.time()))
	if useGrapevine == True or grapevineReconnecting == True:
		if gsocket.state["connected"] == True:
			gsocket.import_players(playerList)
			gsocket.handle_read()
			gsocket.handle_write()
	
			rcvd_msg = None
			ret_value = None
			
示例#3
0
    * Saving players accounts between sessions
    * A password login
    * A shop from which to buy items

author: Mark Frimston - [email protected]
"""

import time

from game_data import rooms
from mudserver import MudServer
from lib.constants import DEFAULT_START_LOCATION
from lib.command import Commands
from lib.models.game_state import GameState

game = GameState(MudServer())
commands = Commands(game)

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    game.update()

    # go through any newly connected players
    new_players = game.handle_player_join()
示例#4
0
#!/usr/bin/env python

import time
import json
from mudserver import MudServer

# imported from rooms.json, defines rooms
with open('rooms.json', 'r') as f:
    rooms = json.load(f)
# stores the players in the game
players = {}
# start the server
mud = MudServer()

# main game infinite loop
while True:

    # calling update for uptodate information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():

        # adding  the new player to the dictionary with their name and room empty
        players[id] = {
            "name": None,
            "room": None,
        }

        # ask the new player for their name
        mud.send_message(id, "What is your name?")
示例#5
0
    return rooms[getPlayerRoomID(id)]


def setPlayerRoom(id: int, roomID: str) -> dict:
    players[id]["room"] = roomID
    return rooms[roomID]


# structure defining the rooms in the game. Try adding more rooms to the game!
rooms = hjson.loads(Path("data/rooms.hjson").read_text())

# stores the players in the game
players = {}

# start the server
mud = MudServer()


def processNewPlayers():
    for id in mud.get_new_players():
        # add the new player to the dictionary, noting that they've not been
        # named yet.
        # The dictionary key is the player's id number. We set their room to
        # None initially until they have entered a name
        # Try adding more player stats - level, gold, inventory, etc
        players[id] = {
            "name": None,
            "room": None,
        }

        # send the new player a prompt for their name
示例#6
0
        "hazards": [],
        "items": []
    }

needed_repairs = len(location_list)

#Generate Hub Exits:
for k in rooms.keys():
    if k != 'hub':
        rooms['hub']['exits'][k] = k

# stores the players in the game
players = {}

# start the server
mud = MudServer()


#Utility functions
def message_room(msg):
    # go through every player in the game
    for pid, pl in players.items():
        # if they're in the same room as the player
        if players[pid]["room"] == players[id]["room"]:
            # send them a message telling them what the player said
            mud.send_message(pid, msg)


def message_all(msg):
    # go all the players in the game
    for pid, pl in players.items():
示例#7
0
import time
import os
import sys

# add the mud_py data directory to the python path variable
mud_dir = os.path.join(os.getcwd() + '/data')
sys.path.append(mud_dir)

# local imports
from mudserver import MudServer
from gamefunctions import new_players_check
from gamefunctions import disconnected_players_check
from gamefunctions import process_commands

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()
    new_players_check(mud)
    disconnected_players_check(mud)
    process_commands(mud)
示例#8
0
author: Mark Frimston - [email protected]
"""

import time
import re
from rooms import rooms
import items

# import the MUD server class
from mudserver import MudServer

# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:
    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():

        # add the new player to the dictionary, noting that they've not been
示例#9
0
rooms = {
    "Tavern": {
        "description": "You're in a cozy tavern warmed by an open fire.",
        "exits": {"outside": "Outside"},
    },
    "Outside": {
        "description": "You're standing outside a tavern. It's raining.",
        "exits": {"inside": "Tavern"},
    }
}

# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():
示例#10
0
import json

# import the MUD server class
from mudserver import MudServer

# structure defining the rooms in the game. Try adding more rooms to the game!
with open('world.json') as json_data:
    rooms = json.load(json_data)
# structure where players are saved
with open('players.json') as json_data:
    players = json.load(json_data)

active_players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():
示例#11
0
文件: main.py 项目: triplrrr/RPG-MUD
    "electrum": {"electrum": 1, "platinum": 10, "gold": 100, "silver": 1000,
    "copper": 10000},
    "platinum": {"electrum": 0.1, "platinum": 1, "gold": 10, "silver": 100,
    "copper": 1000},
    "gold": {"electrum": 0.01, "platinum": 0.1, "gold": 1, "silver": 10,
    "copper": 100},
    "silver": {"electrum": 0.001, "platinum": 0.01, "gold": 0.1, "silver": 1,
    "copper": 10},
    "copper": {"electrum": 0.0001, "platinum": 0.001, "gold": 0.01,
    "silver": 0.1, "copper": 1}
}"""
# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:
    # pause for 1/5 of a second on each loop, so that we don't constantly use
    # 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give us
    # up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():
        # add the new player to the dictionary, noting that they've not been
        # named yet. The dictionary key is the player's id number. We set their
示例#12
0
    },
    "Outside": {
        "description": "You're standing outside a tavern. It's raining.",
        "exits": {
            "inside": "Tavern"
        },
    }
}

texte = []

# liste des joueurs connectés
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # test d'event par interval
    #if random.randint(0, 10) > 8:
    #   for pid, pl in players.items():
示例#13
0
rooms = {
    "Tavern": {
        "description": "You're in a cozy tavern warmed by an open fire.",
        "exits": { "outside": "Outside" },
    },
    "Outside": {
        "description": "You're standing outside a tavern. It's raining.",
        "exits": { "inside": "Tavern" },
    }
}

# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

	# pause for 1/5 of a second on each loop, so that we don't constantly 
	# use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()
    
    
    # go through any newly connected players
    for id in mud.get_new_players():
示例#14
0
from mudserver import MudServer

# import rooms from rooms.py
from rooms import rooms

# import items from items.py
from items import items

# import npcs from npcs.py
from npcs import npcs

# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():
示例#15
0
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)

# weather
curr_hour = datetime.datetime.today().hour
curr_min = datetime.datetime.today().minute
days_since_epoch = (datetime.datetime.today() -
                    datetime.datetime(1970, 1, 1)).days
day_mins = (curr_hour * 60) + curr_min
random.seed((days_since_epoch * 1440) + day_mins)
last_weather_update = int(time.time())
weather_update_interval = 120
fishing_update_interval = 120
last_fishing_update = int(time.time())
clouds = {}
cloud_grid = {}
tile_size = 2
示例#16
0
    def run(self):
        logging.info("Starting server.")
        self.mud = MudServer()
        library.store_server(self.mud)
        logging.info("Server started successfully.")
        # main game loop. We loop forever (i.e. until the program is terminated)
        while self.keep_running:
            try:
                server_command = self.q.get(block=False)
                if server_command is not None:
                    if server_command.command_type == ServerCommandEnum.BROADCAST_MESSAGE:
                        self.mud.send_message_to_all(server_command.params)
                    elif server_command.command_type == ServerCommandEnum.GET_PLAYERS:
                        logging.info("Players: ")
                        for player in control.Player.player_ids.values():
                            logging.info(str(player))

            except Exception:
                pass

            # 'update' must be called in the loop to keep the game running and give
            # us up-to-date information
            self.mud.update()

            # handle events on the server_queue
            while (len(self.mud.server_queue) > 0):
                event = self.mud.server_queue.popleft()
                logging.info(event)
                id = event.id
                if event.type is EventType.PLAYER_JOIN:
                    logging.info("Player %s joined." % event.id)
                    # notifying the player of their class, creating the character
                    self.mud.send_message(id, "Welcome to MuddySwamp!")
                    PlayerClass = library.random_class.get()
                    self.mud.send_message(id, "You are a(n) %s" % PlayerClass)
                    self.mud.send_message(id, "What is your name?")
                    # creating a controler (a 'Player'), then giving that Player control of a new character
                    # of whatever class the player is
                    new_player = control.Player(event.id)
                    new_character = PlayerClass()
                    new_player.assume_control(new_character)

                elif event.type is EventType.MESSAGE_RECEIVED:
                    # log the message
                    logging.debug("Event message: " + event.message)
                    control.Player.send_command(id, event.message)

                elif event.type is EventType.PLAYER_DISCONNECT:
                    # logging data of the player
                    player = control.Player.player_ids[id]
                    logging.info("%s left" % player)
                    if player.receiver is not None:
                        pass
                        #self.mud.send_message_to_all("%s quit the game" % player.receiver)
                    control.Player.remove_player(id)

            # temporary: move this to a better place later
            for id, msg in control.Player.receive_messages():
                self.mud.send_message(id, msg)

        # Shut down the mud instance after the while loop finishes
        self.mud.shutdown()
示例#17
0
            "outside": "Outside"
        },
    },
    "Outside": {
        "description": "You're standing outside a tavern. It's raining.",
        "exits": {
            "inside": "Tavern"
        },
    }
}

# stores the players in the game
players = {}

# start the server
mud = MudServer()

# main game loop. We loop forever (i.e. until the program is terminated)
while True:

    # pause for 1/5 of a second on each loop, so that we don't constantly
    # use 100% CPU time
    time.sleep(0.2)

    # 'update' must be called in the loop to keep the game running and give
    # us up-to-date information
    mud.update()

    # go through any newly connected players
    for id in mud.get_new_players():
示例#18
0
lastStateSave = int(time.time())

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

# List items in world for debugging purposes
# for x in itemsInWorld:
	# print (x)
	# for y in itemsInWorld[x]:
		# print(y,':',itemsInWorld[x][y])
		
# stores the players in the game
players = {}

# start the server
mud = MudServer()



# main game loop. We loop forever (i.e. until the program is terminated)
while True:
	# print(type(gsocket.outbound_frame_buffer))
	# Gossip test
	#inbound = gsocket.handle_read()
	#if inbound != None:
		#print(type(inbound))
		#print(inbound)
	#gsocket.handle_write()

	#print(type(readtest))
	#print(readtest)