+def cmd_TASKS(game, connection_id):
+ tasks = []
+ game.io.send('TASKS ' + ','.join(game.tasks.keys()), connection_id)
+cmd_TASKS.argtypes = ''
+
def cmd_ALL(game, msg, connection_id):
if not connection_id in game.sessions:
raise GameError('need to be logged in for this')
from plomrogue.io_tcp import PlomTCPServer
from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_QUERY, cmd_PING,
cmd_MAP, cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION,
- cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE)
+ cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE,
+ cmd_TASKS)
from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE,
Task_FLATTEN_SURROUNDINGS)
import sys
game.register_command(cmd_ANNOTATE)
game.register_command(cmd_PORTAL)
game.register_command(cmd_GET_GAMESTATE)
+game.register_command(cmd_TASKS)
game.register_task(Task_WAIT)
game.register_task(Task_MOVE)
game.register_task(Task_WRITE)
game.tui.do_refresh = True
cmd_ANNOTATION.argtypes = 'yx_tuple:nonneg string'
+def cmd_TASKS(game, tasks_comma_separated):
+ game.tasks = tasks_comma_separated.split(',')
+cmd_TASKS.argtypes = 'string'
+
def cmd_PONG(game):
pass
cmd_PONG.argtypes = ''
class Game(GameBase):
thing_type = ThingBase
turn_complete = False
+ tasks = {}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.register_command(cmd_ARGUMENT_ERROR)
self.register_command(cmd_GAME_ERROR)
self.register_command(cmd_PLAY_ERROR)
+ self.register_command(cmd_TASKS)
self.map_content = ''
self.player_id = -1
self.info_db = {}
self.log_msg(" /%s or /play - switch to play mode" % self.keys['switch_to_play']);
self.log_msg(" /%s or /study - switch to study mode" % self.keys['switch_to_study']);
self.log_msg("commands common to study and play mode:");
- self.log_msg(" %s - move" % ','.join(self.movement_keys));
+ if 'MOVE' in self.game.tasks:
+ self.log_msg(" %s - move" % ','.join(self.movement_keys));
self.log_msg(" %s - switch to chat mode" % self.keys['switch_to_chat']);
self.log_msg("commands specific to play mode:");
- self.log_msg(" %s - write following ASCII character" % self.keys['switch_to_edit']);
- self.log_msg(" %s - flatten surroundings" % self.keys['flatten']);
+ if 'WRITE' in self.game.tasks:
+ self.log_msg(" %s - write following ASCII character" % self.keys['switch_to_edit']);
+ if 'FLATTEN_SURROUNDINGS' in self.game.tasks:
+ self.log_msg(" %s - flatten surroundings" % self.keys['flatten']);
self.log_msg(" %s - switch to study mode" % self.keys['switch_to_study']);
self.log_msg("commands specific to study mode:");
+ if 'MOVE' not in self.game.tasks:
+ self.log_msg(" %s - move" % ','.join(self.movement_keys));
self.log_msg(" %s - annotate terrain" % self.keys['switch_to_annotate']);
self.log_msg(" %s - switch to play mode" % self.keys['switch_to_play']);
self.socket = socket_client_class(handle_recv, self.host)
self.socket_thread = threading.Thread(target=self.socket.run)
self.socket_thread.start()
+ self.socket.send('TASKS')
self.switch_mode('login')
return
except ConnectionRefusedError:
self.switch_mode('chat')
elif key == self.keys['switch_to_study']:
self.switch_mode('study')
- if key == self.keys['switch_to_edit']:
+ if key == self.keys['switch_to_edit'] and\
+ 'WRITE' in self.game.tasks:
self.switch_mode('edit')
- elif key == self.keys['flatten']:
+ elif key == self.keys['flatten'] and\
+ 'FLATTEN_SURROUNDINGS' in self.game.tasks:
self.send('TASK:FLATTEN_SURROUNDINGS')
- elif key in self.movement_keys:
+ elif key in self.movement_keys and 'MOVE' in self.game.tasks:
self.send('TASK:MOVE ' + self.movement_keys[key])
elif self.mode == self.mode_edit:
self.send('TASK:WRITE ' + key)
this.websocket = new WebSocket(this.url);
this.websocket.onopen = function(event) {
window.setInterval(function() { server.send(['PING']) }, 30000);
+ this.send('TASKS');
tui.log_msg("@ server connected! :)");
tui.switch_mode(mode_login);
};
game.get_thing(tokens[1], true).position = parser.parse_yx(tokens[2]);
} else if (tokens[0] === 'THING_NAME') {
game.get_thing(tokens[1], true).name_ = tokens[2];
+ } else if (tokens[0] === 'TASKS') {
+ game.tasks = tokens[1].split(',')
} else if (tokens[0] === 'MAP') {
game.map_geometry = tokens[1];
tui.init_keys();
this.log_msg(" /" + this.keys.switch_to_play + " or /play - switch to play mode");
this.log_msg(" /" + this.keys.switch_to_study + " or /study - switch to study mode");
this.log_msg("commands common to study and play mode:");
- this.log_msg(" " + movement_keys_desc + " - move");
+ if (game.tasks.includes('MOVE')) {
+ this.log_msg(" " + movement_keys_desc + " - move");
+ }
this.log_msg(" " + this.keys.switch_to_chat + " - switch to chat mode");
this.log_msg("commands specific to play mode:");
- this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character");
- this.log_msg(" " + this.keys.flatten + " - flatten surroundings");
+ if (game.tasks.includes('WRITE')) {
+ this.log_msg(" " + this.keys.switch_to_edit + " - write following ASCII character");
+ }
+ if (game.tasks.includes('FLATTEN_SURROUNDINGS')) {
+ this.log_msg(" " + this.keys.flatten + " - flatten surroundings");
+ }
this.log_msg(" " + this.keys.switch_to_study + " - switch to study mode");
this.log_msg("commands specific to study mode:");
+ if (!game.tasks.includes('MOVE')) {
+ this.log_msg(" " + movement_keys_desc + " - move");
+ }
this.log_msg(" " + this.keys.switch_to_annotate + " - annotate terrain");
this.log_msg(" " + this.keys.switch_to_play + " - switch to play mode");
},
this.map_size = [0,0];
this.player_id = -1;
this.portals = {};
+ this.tasks = {};
},
get_thing: function(id_, create_if_not_found=false) {
if (id_ in game.things) {
if (event.key === tui.keys.switch_to_chat) {
event.preventDefault();
tui.switch_mode(mode_chat);
- } else if (event.key === tui.keys.switch_to_edit) {
+ } else if (event.key === tui.keys.switch_to_edit
+ && game.tasks.includes('WRITE')) {
event.preventDefault();
tui.switch_mode(mode_edit);
} else if (event.key === tui.keys.switch_to_study) {
tui.switch_mode(mode_study);
- } else if (event.key === tui.keys.flatten) {
+ } else if (event.key === tui.keys.flatten
+ && game.tasks.includes('FLATTEN_SURROUNDINGS')) {
server.send(["TASK:FLATTEN_SURROUNDINGS"]);
- } else if (event.key in tui.movement_keys) {
+ } else if (event.key in tui.movement_keys
+ && game.tasks.includes('MOVE')) {
server.send(['TASK:MOVE', tui.movement_keys[event.key]]);
};
} else if (tui.mode == mode_study) {