| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2017-11-20 17:25:37 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2017-11-20 17:25:37 +0100 | 
| commit | b984be19b36226b02cb2d58d8597d2cff4be1eaf (patch) | |
| tree | 96493a00a29ec934297acf073ee431bf6174f1e8 /www/handler/battlemap/character_turn.yaws | |
| parent | c3c8f24ebde2370d8314b1f0e571a26fbcff9450 (diff) | |
Trying to get character turns to register.
Diffstat (limited to 'www/handler/battlemap/character_turn.yaws')
| -rw-r--r-- | www/handler/battlemap/character_turn.yaws | 93 | 
1 files changed, 64 insertions, 29 deletions
diff --git a/www/handler/battlemap/character_turn.yaws b/www/handler/battlemap/character_turn.yaws index ffcf0f9..40540f6 100644 --- a/www/handler/battlemap/character_turn.yaws +++ b/www/handler/battlemap/character_turn.yaws @@ -1,34 +1,69 @@  <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) -> -   io:format("~nReceived~p...", [Req]), -   JSON_Req_Map = jiffy:decode(Req, [return_maps]), -   UserToken = maps:get(<<"user_token">>, JSON_Req_Map), -   io:format("~nCharacter Turn for ~p...", [UserToken]), -%%   ok = users_manager:ping(UserToken), -   jiffy:encode -   ( -      { -         [ -            {<<"types">>, [<<"STATUS">>]}, -            { -               <<"data">>, -               [ -                  jiffy:encode -                  ( -                     { -                        [ -                           { -                              <<"status">>, -                              <<"OK">> -                           } -                        ] -                     } -                  ) -               ] -            } -         ] -      } -   ). +   %%%% 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) ->     {  | 


