127 lines
4.7 KiB
Python
127 lines
4.7 KiB
Python
def unknown(mud, command, id):
|
|
mud.send_message(id, "Unknown command '{}'"
|
|
.format(command))
|
|
|
|
|
|
def help(mud, id):
|
|
mud.send_message(id, '''This are the currently available commands:
|
|
* say <message>: Says something to everyone in the room.
|
|
* go <exit>: Enters an exit.
|
|
* look: Gives a description of the room. Use it in a players to see info
|
|
about them. Use 'me' to see info about you.
|
|
* open <exit> <room>: (Only available for the builders of the room) creates
|
|
an exit to another room.
|
|
* build <room> <return> <description>: Creates a room. The return param is
|
|
the name of an exit to come back to the current room.
|
|
* me <action>: Emotes action. Example, 'me chuckles'. Visible to everyone
|
|
in the room.
|
|
''')
|
|
|
|
|
|
def say(mud, id, players, params):
|
|
for pid, pl in players.items():
|
|
if players[pid]["room"] == players[id]["room"]:
|
|
mud.send_message(pid, "{} says: {}"
|
|
.format(players[id]["name"], params))
|
|
|
|
|
|
def go(mud, id, players, rooms, params):
|
|
old_room = players[id]["room"]
|
|
params_list = params.split()
|
|
if len(params_list) != 1:
|
|
mud.send_message(id, "Invalid params.")
|
|
return
|
|
exit = params_list[0]
|
|
room = rooms[players[id]["room"]]
|
|
if exit in room["exits"]:
|
|
if room["exits"][exit] not in rooms:
|
|
mud.send_message(id, "Room '{}' not found."
|
|
.format(room["exits"][exit]))
|
|
return
|
|
for pid, pl in players.items():
|
|
if pl["room"] == players[id]["room"] and pid != id:
|
|
mud.send_message(pid, "{} left via exit '{}'."
|
|
.format(players[id]["name"], exit))
|
|
players[id]["room"] = room["exits"][exit]
|
|
mud.send_message(id, "You arrive at '{}'.".format(players[id]["room"]))
|
|
|
|
for pid, pl in players.items():
|
|
if pl["room"] == players[id]["room"] and pid != id:
|
|
mud.send_message(pid, "{} arrived from '{}' via exit '{}'."
|
|
.format(players[id]["name"], old_room, exit))
|
|
else:
|
|
mud.send_message(id, "Unknown exit '{}'".format(exit))
|
|
|
|
|
|
def look(mud, id, players, rooms, params):
|
|
params_list = params.split()
|
|
if len(params_list) > 1:
|
|
mud.send_message(id, "Invalid params.")
|
|
return
|
|
if len(params_list) == 1:
|
|
for pid, pl in players.items():
|
|
if params_list[0] == "me":
|
|
mud.send_message(id, players[id]["description"])
|
|
mud.send_message(id, "species: {}"
|
|
.format(players[id]["species"]))
|
|
break
|
|
elif params_list[0] == pl["name"]:
|
|
mud.send_message(id, pl["description"])
|
|
mud.send_message(id, "species: {}"
|
|
.format(players[pid]["species"]))
|
|
return
|
|
room = rooms[players[id]["room"]]
|
|
mud.send_message(id, room["description"])
|
|
|
|
room_players = []
|
|
|
|
for pid, pl in players.items():
|
|
if pl["room"] != players[id]["room"]:
|
|
continue
|
|
room_players.append(pl["name"])
|
|
|
|
mud.send_message(id, "Players here: {}.".format(", ".join(room_players)))
|
|
mud.send_message(id, "Exits are: {}.".format(", ".join(room["exits"])))
|
|
|
|
|
|
def open(mud, id, players, rooms, params):
|
|
params_list = params.split()
|
|
if len(params_list) != 2:
|
|
mud.send_message(id, "Invalid params.")
|
|
return
|
|
if not players[id]["name"] in rooms[players[id]["room"]]["builders"]:
|
|
mud.send_message(id, "You don't have the rights of building here.")
|
|
return
|
|
rooms[players[id]["room"]]["exits"][params_list[0]] = params_list[1]
|
|
mud.send_message(id, "You open the exit '{}' to '{}'."
|
|
.format(params_list[0], params_list[1]))
|
|
|
|
|
|
def build(mud, id, players, rooms, params):
|
|
params_list = params.split()
|
|
if len(params_list) < 3:
|
|
mud.send_message(id, "Invalid params.")
|
|
return
|
|
params_list = [params_list[0], params_list[1], " ".join(params_list[2:])]
|
|
room = params_list[0]
|
|
if room in rooms:
|
|
mud.send_message("Room '{}' already exits."
|
|
.format(room))
|
|
return
|
|
rooms[room] = {
|
|
"description": params_list[2],
|
|
"exits": {params_list[1]: players[id]["room"]},
|
|
"owner": players[id]["name"],
|
|
"builders": [players[id]["name"]]
|
|
}
|
|
|
|
|
|
def me(mud, id, players, rooms, params):
|
|
if not params:
|
|
mud.send_message(id, "Invalid params.")
|
|
return
|
|
for pid, pl in players.items():
|
|
if pl["room"] == players[id]["room"]:
|
|
mud.send_message(pid, "{} {}"
|
|
.format(players[id]["name"], params))
|