-
Notifications
You must be signed in to change notification settings - Fork 0
/
Commands.js
54 lines (44 loc) · 1.15 KB
/
Commands.js
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
function Command(type, payload) {
this.type = type;
this.payload = payload;
this.authKey = authKey;
}
sendCommandtoParty = (command, sendToSelf = false) => {
for (var key in PARTY_MEMBERS) {
let name = PARTY_MEMBERS[key];
if (name == character.name && !sendToSelf) {
continue;
}
send_cm(name, command);
}
}
function on_cm(from, data) {
if (!data) {
game_log(`Recieved empty command from ${from}`);
return;
}
if (!(data.authKey && data.authKey === authKey)) {
game_log(`Recieved unauthorized command from ${from}`);
return;
}
game_log(`Recieved command: ${JSON.stringify(data.type)} - ${JSON.stringify(data.payload)} from ${from}`);
switch (data.type) {
case COMMAND_TYPES.SAY:
safeSay(data.payload);
break;
case COMMAND_TYPES.HEAL_REQUEST:
safeSay(`Im healing ${from}`);
heal(get_player(from));
break;
case COMMAND_TYPES.SET_TARGET:
setCombatTarget(data.payload);
break;
case COMMAND_TYPES.UPDATE_ENEMY_TO_KILL:
setEnemyToKill(data.payload);
setState(STATES.MOVING_TO_ENEMIES);
break;
default:
game_log("Unhandled command type");
break;
}
}