-- Actions to send to the server, and to receive char = require "char" mod = ... mod.msg = { "request_class_change" ,--client to server request "confirm_class_change" ,-- server to client answer "deny_class_change" ,-- server to client answer "info_class_change" ,-- server to client info "player_joined" ,--client to server hello "info_player_joined" ,-- server to client info "info_player_dropped" ,-- server to client info "request_campaign_start" , --client to server, start game "info_campaign_start" , --server to client, game is starting "request_player_list" ,-- client to server request "respond_player_list" ,--server to client respond with player list "info_room" ,-- server to client notify about room info "info_turnup", -- sever to client, when is the turn up? "info_enemy_party", --server to client notify about enemy party "set_action" ,-- client to server, notify action for next turn "info_timeref" , --server to client, when the next turn is up "info_actions" ,-- server to client set animations to play "info_deaths", -- server to client, deaths that are about to happen "info_loot" ,--server to client loot for clearing a room "request_camp_action" ,--client to server what action to take at camp "info_camp" ,--server to client actions taken at camp "info_defeat", --server to client, you're done! } mod.msg_rev = {} for k,v in pairs(mod.msg) do mod.msg_rev[v] = k mod.action_reg = {} mod.class_counter = 1 mod.request_class_change = (what) -> assert(what, "class may not be nil") assert(char.class_order_rev[what], "class must be one of " .. tostring(char.class_order)) msg_json = am.to_json({msg:"request_class_change", time:am.current_time(), class:what}) am.eval_js(string.format("CLIENT.send(%q);",msg_json)) mod.start_game = () -> msg_json = am.to_json({msg:"request_campaign_start", time:am.current_time()}) am.eval_js(string.format("CLIENT.send(%q);",msg_json)) mod.sync_players = () -> msg_json = am.to_json({msg:"request_player_list", time:am.current_time()}) am.eval_js(string.format("CLIENT.send(%q);",msg_json)) mod.set_action = (name) -> msg_json = am.to_json({ msg: "set_action" time: am.current_time! action: name }) am.eval_js(string.format("CLIENT.send(%q);",msg_json)) mod