-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a chat module which can be used to communicate with all other p…
…layers in the game, or with an individual player privately.
- Loading branch information
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
import spacegame.core | ||
import spacegame.modules | ||
|
||
def init(): | ||
spacegame.core.init() | ||
spacegame.modules.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from spacegame.modules import chat | ||
|
||
|
||
def init(): | ||
chat.init() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from pantsmud.driver import parser | ||
|
||
from spacegame.core import command_manager | ||
|
||
|
||
def chat_global_command(mobile, _, args): | ||
params = parser.parse([("message", parser.STRING)], args) | ||
universe = mobile.universe | ||
for m in (universe.mobiles[u] for u in universe.mobiles): | ||
m.message("chat.global", {"mobile_from": mobile.name, "message": params["message"]}) | ||
|
||
|
||
def chat_private_command(mobile, _, args): | ||
params = parser.parse([("mobile_name", parser.WORD), ("message", parser.STRING)], args) | ||
target = mobile.universe.get_mobile(params["mobile_name"]) | ||
if not target: | ||
mobile.message("chat.private.fail") # TODO Add error message. | ||
return | ||
if target is mobile: | ||
mobile.message("chat.private.fail") # TODO Add error message. | ||
return | ||
data = { | ||
"mobile_from": mobile.name, | ||
"mobile_to": target.name, | ||
"message": params["message"] | ||
} | ||
target.message("chat.private", data) | ||
mobile.message("chat.private", data) | ||
|
||
|
||
def init(): | ||
command_manager.add_command("chat.global", chat_global_command) | ||
command_manager.add_command("chat.private", chat_private_command) |