| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2018-02-23 11:35:45 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2018-02-23 11:35:45 +0100 | 
| commit | acf9e9f1eb880ffb8ab918c40724eda566aefcc7 (patch) | |
| tree | efa3dd6c88d7970632fbe44f322d03b983b02768 | |
| parent | 43e38e5fc54fd58e8230b2b5198b6d8cb625803c (diff) | |
Starting a big refactoring...
| -rw-r--r-- | src/query/character_turn.erl | 4 | ||||
| -rw-r--r-- | src/shim/attributes_shim.erl (renamed from src/type/attributes_shim.erl) | 0 | ||||
| -rw-r--r-- | src/shim/battlemap_instance_shim.erl (renamed from src/type/battlemap_instance_shim.erl) | 0 | ||||
| -rw-r--r-- | src/shim/battlemap_shim.erl (renamed from src/type/battlemap_shim.erl) | 0 | ||||
| -rw-r--r-- | src/shim/character_shim.erl (renamed from src/type/character_shim.erl) | 0 | ||||
| -rw-r--r-- | src/shim/weapon_shim.erl (renamed from src/type/weapon_shim.erl) | 0 | ||||
| -rw-r--r-- | src/struct/armor.erl (renamed from src/type/armor.erl) | 0 | ||||
| -rw-r--r-- | src/struct/attributes.erl (renamed from src/type/attributes.erl) | 0 | ||||
| -rw-r--r-- | src/struct/battlemap.erl (renamed from src/type/battlemap.erl) | 0 | ||||
| -rw-r--r-- | src/struct/battlemap_instance.erl | 94 | ||||
| -rw-r--r-- | src/struct/character.erl (renamed from src/type/character.erl) | 0 | ||||
| -rw-r--r-- | src/struct/character_instance.erl (renamed from src/type/character_instance.erl) | 0 | ||||
| -rw-r--r-- | src/struct/glyph.erl (renamed from src/type/glyph.erl) | 0 | ||||
| -rw-r--r-- | src/struct/player_turn.erl | 51 | ||||
| -rw-r--r-- | src/struct/statistics.erl (renamed from src/type/statistics.erl) | 0 | ||||
| -rw-r--r-- | src/struct/weapon.erl (renamed from src/type/weapon.erl) | 0 | ||||
| -rw-r--r-- | src/type/battlemap/cross_5.erl | 63 | ||||
| -rw-r--r-- | src/type/battlemap_instance.erl | 133 | 
18 files changed, 147 insertions, 198 deletions
| diff --git a/src/query/character_turn.erl b/src/query/character_turn.erl index da5e5e1..501c82b 100644 --- a/src/query/character_turn.erl +++ b/src/query/character_turn.erl @@ -45,8 +45,7 @@  parse_input (Req) ->     JSONReqMap = jiffy:decode(Req, [return_maps]),     PlayerID = maps:get(<<"player_id">>, JSONReqMap), -   SessionToken =  maps:get(<<"session_token">>, JSONReqMap), -   database_shim:assert_session_is_valid(PlayerID, SessionToken), +   SessionToken = maps:get(<<"session_token">>, JSONReqMap),     Target =        case maps:get(<<"targets_id">>, JSONReqMap) of           [] -> <<"">>; @@ -254,6 +253,7 @@ generate_reply (QueryState) ->  handle (Req) ->     %%%% Parse     Input = parse_input(Req), +   assert_player_identity(Req),     %%%% Fetch     QueryState = fetch_data(Input),     %%%% Calc diff --git a/src/type/attributes_shim.erl b/src/shim/attributes_shim.erl index b80ee6d..b80ee6d 100644 --- a/src/type/attributes_shim.erl +++ b/src/shim/attributes_shim.erl diff --git a/src/type/battlemap_instance_shim.erl b/src/shim/battlemap_instance_shim.erl index 94ae7ce..94ae7ce 100644 --- a/src/type/battlemap_instance_shim.erl +++ b/src/shim/battlemap_instance_shim.erl diff --git a/src/type/battlemap_shim.erl b/src/shim/battlemap_shim.erl index b19a653..b19a653 100644 --- a/src/type/battlemap_shim.erl +++ b/src/shim/battlemap_shim.erl diff --git a/src/type/character_shim.erl b/src/shim/character_shim.erl index 35a0753..35a0753 100644 --- a/src/type/character_shim.erl +++ b/src/shim/character_shim.erl diff --git a/src/type/weapon_shim.erl b/src/shim/weapon_shim.erl index e0364f0..e0364f0 100644 --- a/src/type/weapon_shim.erl +++ b/src/shim/weapon_shim.erl diff --git a/src/type/armor.erl b/src/struct/armor.erl index 89df653..89df653 100644 --- a/src/type/armor.erl +++ b/src/struct/armor.erl diff --git a/src/type/attributes.erl b/src/struct/attributes.erl index b4395cb..b4395cb 100644 --- a/src/type/attributes.erl +++ b/src/struct/attributes.erl diff --git a/src/type/battlemap.erl b/src/struct/battlemap.erl index f55aadb..f55aadb 100644 --- a/src/type/battlemap.erl +++ b/src/struct/battlemap.erl diff --git a/src/struct/battlemap_instance.erl b/src/struct/battlemap_instance.erl new file mode 100644 index 0000000..c219a07 --- /dev/null +++ b/src/struct/battlemap_instance.erl @@ -0,0 +1,94 @@ +-module(battlemap_instance). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( +   battlemap_instance, +   { +      id, +      battlemap, +      character_instances, +      players, +      current_player_turn, +      last_player_turn +   } +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( +   [ +      get_id/1, +      get_battlemap/1, +      get_character_instances/1, +      get_players/1, +      get_current_player_turn/1, +      get_last_player_turn/1, + +      set_battlemap/2, +      set_character_instances/2, +      set_players/2, +      set_current_player_turn/2, +      set_last_player_turn/2 +   ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +get_id (BattlemapInstance) -> BattlemapInstance#battlemap_instance.id. + +get_battlemap (BattlemapInstance) -> +   BattlemapInstance#battlemap_instance.battlemap. + +get_character_instances (BattlemapInstance) -> +   BattlemapInstance#battlemap_instance.character_instances. + +get_players (BattlemapInstance) -> +   BattlemapInstance#battlemap_instance.players. + +get_current_player_turn (BattlemapInstance) -> +   BattlemapInstance#battlemap_instance.current_player_turn. + +get_last_player_turn (BattlemapInstance) -> +   BattlemapInstance#battlemap_instance.last_player_turn. + +set_battlemap (Battlemap, BattlemapInstance) -> +   BattlemapInstance#battlemap_instance +   { +      battlemap = Battlemap +   }. + +set_character_instances (CharacterInstances, BattlemapInstance) -> +   BattlemapInstance#battlemap_instance +   { +      character_instances = CharacterInstances +   }. + +set_players (Players, BattlemapInstance) -> +   BattlemapInstance#battlemap_instance +   { +      players = Players +   }. + +set_current_player_turn (PlayerTurn, BattlemapInstance) -> +   BattlemapInstance#battlemap_instance +   { +      current_player_turn = PlayerTurn +   }. + +set_last_player_turn (PlayerTurn, BattlemapInstance) -> +   BattlemapInstance#battlemap_instance +   { +      last_player_turn = PlayerTurn +   }. diff --git a/src/type/character.erl b/src/struct/character.erl index 03906e3..03906e3 100644 --- a/src/type/character.erl +++ b/src/struct/character.erl diff --git a/src/type/character_instance.erl b/src/struct/character_instance.erl index 63045a7..63045a7 100644 --- a/src/type/character_instance.erl +++ b/src/struct/character_instance.erl diff --git a/src/type/glyph.erl b/src/struct/glyph.erl index 18d8455..18d8455 100644 --- a/src/type/glyph.erl +++ b/src/struct/glyph.erl diff --git a/src/struct/player_turn.erl b/src/struct/player_turn.erl new file mode 100644 index 0000000..b973135 --- /dev/null +++ b/src/struct/player_turn.erl @@ -0,0 +1,51 @@ +-module(player_turn). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( +   player_turn, +   { +      number, +      player_id +   } +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-export +( +   [ +      new/2 +   ] +). + +%%%% Accessors +-export +( +   [ +      get_number/1, +      get_player_id/1 +   ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +new (Number, PlayerID) -> +   #player_turn +   { +      number = Number, +      player_id = PlayerID +   }. + +get_number (PlayerTurn) -> PlayerTurn#player_turn.number. + +get_player_id (PlayerTurn) -> PlayerTurn#player_turn.player_id. diff --git a/src/type/statistics.erl b/src/struct/statistics.erl index 0668fea..0668fea 100644 --- a/src/type/statistics.erl +++ b/src/struct/statistics.erl diff --git a/src/type/weapon.erl b/src/struct/weapon.erl index add445a..add445a 100644 --- a/src/type/weapon.erl +++ b/src/struct/weapon.erl diff --git a/src/type/battlemap/cross_5.erl b/src/type/battlemap/cross_5.erl deleted file mode 100644 index dccc4b9..0000000 --- a/src/type/battlemap/cross_5.erl +++ /dev/null @@ -1,63 +0,0 @@ -%% -%% battlemap:cross/5 -%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -next_loc (X, Y, <<"L">>) -> {(X - 1), Y}; -next_loc (X, Y, <<"R">>) -> {(X + 1), Y}; -next_loc (X, Y, <<"U">>) -> {X, (Y - 1)}; -next_loc (X, Y, <<"D">>) -> {X, (Y + 1)}. - -loc_to_index(X, Y, Map) -> -   if -      (X < 0) -> error; -      (Y < 0) -> error; -      (X >= Map#battlemap.width) -> error; -      true -> ((Y * Map#battlemap.width) + X) -   end. - -calc_new_loc (X, Y, [], Points, _Map, _CharInstsLocs) -> -   io:format("~nPoints remaining: ~p ~n", [Points]), -   true = (Points >= 0), -   {X, Y}; -calc_new_loc (X, Y, [Step|Path], Points, Map, CharInstsLocs) -> -   io:format("~nStep - Points remaining: ~p ~n", [Points]), -   {NX, NY} = next_loc(X, Y, Step), -   TileCost = -      tile:get_cost -      ( -         array:get -         ( -            loc_to_index(NX, NY, Map), -            Map#battlemap.content -         ) -      ), -   io:format("~nStep cost: ~p ~n", [TileCost]), -   NPoints = -      ( -         Points -         - -         TileCost -      ), -   false = lists:member({NX, NY}, CharInstsLocs), -   calc_new_loc(NX, NY, Path, NPoints, Map, CharInstsLocs). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -cross (Battlemap, {X, Y}, Points, Path, CharInsts) -> -   calc_new_loc -   ( -      X, -      Y, -      Path, -      Points, -      Battlemap, -      lists:map -      ( -         fun character_instance:get_location/1, -         CharInsts -      ) -   ). diff --git a/src/type/battlemap_instance.erl b/src/type/battlemap_instance.erl deleted file mode 100644 index 6a6fe3b..0000000 --- a/src/type/battlemap_instance.erl +++ /dev/null @@ -1,133 +0,0 @@ --module(battlemap_instance). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --record -( -   battlemap_instance, -   { -      id, -      chars, -      curr_player, -      players, -      rem_chars, -      last_turn -   } -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors --export -( -   [ -      get_id/1, -      list_characters/1, -      get_char_instances/1, -      get_char_instance/2, -      set_char_instance/3 -   ] -). - -%%%% Utils --export -( -   [ -      can_play_char_instance/3, -      post_play_char_instance/2 -   ] -). - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%%%% Accessors -get_id (BattlemapInstance) -> BattlemapInstance#battlemap_instance.id. - -list_characters (BattlemapInstance) -> -   dict:to_list(BattlemapInstance#battlemap_instance.chars). - -get_char_instances (BattlemapInstance) -> -   lists:map -   ( -      fun ({_K, V}) -> V end, -      dict:to_list(BattlemapInstance#battlemap_instance.chars) -   ). - -can_play_char_instance -( -   BattlemapInstance, -   PlayerID, -   CharInstID -) -> -   ( -      ( -         array:get -         ( -            BattlemapInstance#battlemap_instance.curr_player, -            BattlemapInstance#battlemap_instance.players -         ) -         =:= -         PlayerID -      ) -      and -      lists:member(CharInstID, BattlemapInstance#battlemap_instance.rem_chars) -   ). - -post_play_char_instance (BattlemapInstance, CharInstID) -> -   case BattlemapInstance#battlemap_instance.rem_chars of -      [CharInstID|[]] -> -         NextPlayer = -            ( -               (BattlemapInstance#battlemap_instance.curr_player + 1) -               rem -               array:size(BattlemapInstance#battlemap_instance.players) -            ), -         BattlemapInstance#battlemap_instance -         { -            curr_player = NextPlayer, -            rem_chars = -               lists:filtermap -               ( -                  fun ({K, V}) -> -                     case character_instance:get_owner(V) of -                        NextPlayer -> {true, K}; -                        _ -> false -                     end -                  end, -                  dict:to_list(BattlemapInstance#battlemap_instance.chars) -               ) -         }; - -      _ -> -         BattlemapInstance#battlemap_instance -         { -            rem_chars = -               lists:delete -               ( -                  CharInstID, -                  BattlemapInstance#battlemap_instance.rem_chars -               ) -         } -   end. - -get_char_instance (BattlemapInstance, CharInstID) -> -   dict:fetch(CharInstID, BattlemapInstance#battlemap_instance.chars). - -set_char_instance (BattlemapInstance, CharInstID, CharInst) -> -   BattlemapInstance#battlemap_instance -   { -      chars = -         dict:store -         ( -            CharInstID, -            CharInst, -            BattlemapInstance#battlemap_instance.chars -         ) -   }. | 


