aboutsummaryrefslogtreecommitdiff
path: root/src/action.moon
blob: e9b11508788c09a62b616cd8f5ac57edfd44a21a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
-- 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