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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<erl>
-record
(
input,
{
session_token,
player_id,
battlemap_id,
instance_id,
char_id,
path,
target_id
}
).
-include("/tmp/timed_cache_data.hrl").
parse_input (Req) ->
JSONReqMap = jiffy:decode(Req, [return_maps]),
#input
{
session_token = maps:get(<<"session_token">>, JSONReqMap),
player_id = maps:get(<<"player_id">>, JSONReqMap),
battlemap_id = maps:get(<<"battlemap_id">>, JSONReqMap),
instance_id = maps:get(<<"instance_id">>, JSONReqMap),
path = maps:get(<<"path">>, JSONReqMap),
target_id = maps:get(<<"target_id">>, JSONReqMap)
}.
handle (Req) ->
%%%% Parse
Input = parse_input(Req),
%%%% Fetch
Battlemap = timed_cache:fetch(battlemap_db, Input#input.battlemap_id),
BattlemapInstance =
timed_cache:fetch
(
battlemap_instance_db,
<<"0">>
),
{ok, CharInst} =
battlemap_instance:get_char_instance
(
BattlemapInstance,
Input#input.char_id
),
%%%% Calc
{ok, {X, Y}} =
battlemap:cross
(
Battlemap,
CharInst,
Input#input.path,
battlemap_instance:get_char_instances(BattlemapInstance)
),
NewBattlemapInstance =
battlemap_instance:set_char_instance
(
BattlemapInstance,
Input#input.char_id,
character_instance:set_location(CharInst, X, Y)
),
%%%% Commit
database_shim:commit(battlemap_instance_db, <<"0">>, NewBattlemapInstance),
%%%% Reply
jiffy:encode([[<<"okay">>]]).
out(A) ->
{
content,
"application/json; charset=UTF-8",
handle(A#arg.clidata)
}.
</erl>
|