| summaryrefslogtreecommitdiff | 
diff options
| -rw-r--r-- | src/battle/struct/btl_character.erl | 99 | ||||
| -rw-r--r-- | src/roster/struct/rst_character.erl | 32 | ||||
| -rw-r--r-- | src/special/spe_battle.erl | 96 | 
3 files changed, 135 insertions, 92 deletions
| diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index a95a10c..1b90141 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -3,14 +3,12 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --type id() :: non_neg_integer().  -type rank() :: ('optional' | 'target' | 'commander').  -record  (     character,     { -      id :: id(),        player_ix :: non_neg_integer(),        name :: binary(),        rank :: rank(), @@ -36,11 +34,9 @@  -export  (     [ -      get_id/1,        get_player_index/1,        get_name/1,        get_rank/1, -      get_icon/1,        get_portrait/1,        get_weapon_ids/1,        get_armor_id/1, @@ -71,58 +67,18 @@  -export  (     [ -      random/5 +      new/10     ]  ).  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec find_random_location -   ( -      btl_map:type(), -      list({non_neg_integer(), non_neg_integer()}) -   ) -   -> {{non_neg_integer(), non_neg_integer()}, shr_tile:type()}. -find_random_location (Map, ForbiddenLocations) -> -   MapWidth = btl_map:get_width(Map), -   MapHeight = btl_map:get_height(Map), - -   Candidate = -      { -         shr_roll:between(0, (MapWidth - 1)), -         shr_roll:between(0, (MapHeight - 1)) -      }, - -   IsForbidden = lists:member(Candidate, ForbiddenLocations), - -   case IsForbidden of -      true -> find_random_location(Map, ForbiddenLocations); - -      _ -> -         Tile = -            shr_tile:from_class_id -            ( -               shr_tile:extract_main_class_id -               ( -                  btl_map:get_tile_instance(Candidate, Map) -               ) -            ), - -         case (shr_tile:get_cost(Tile) > 200) of -            true -> find_random_location(Map, ForbiddenLocations); - -            false -> {Candidate, Tile} -         end -   end.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%% Accessors --spec get_id (type()) -> id(). -get_id (Char) -> Char#character.id. -  -spec get_player_index (type()) -> non_neg_integer().  get_player_index (Char) -> Char#character.player_ix. @@ -226,36 +182,46 @@ set_weapon_ids (WeaponIDs, Char) ->     }.  %%%% Utils --spec random +-spec new     (        non_neg_integer(), -      non_neg_integer(), +      binary(), +      rank(),        shr_omnimods:type(), -      btl_map:type(), -      list({non_neg_integer(), non_neg_integer()}) +      shr_portrait:id(), +      {shr_weapon:id(), shr_weapon:id()}, +      shr_armor:id(), +      btl_location:type(), +      shr_omnimods:type()     )     -> type(). -random (ID, PlayerIX, GlyphOmnimods, Map, ForbiddenLocations) -> -   {Location, CurrentTile} = find_random_location(Map, ForbiddenLocations), -   ActiveWeaponID = shr_weapon:random_id(), -   WeaponIDs = {ActiveWeaponID, shr_weapon:random_id()}, -   ArmorID = shr_armor:random_id(), -   IDAsListString = integer_to_list(ID), -   IDAsBinaryString = list_to_binary(IDAsListString), +new +( +   PlayerIX, +   Name, +   Rank, +   GlyphsOmnimods, +   PortraitID, +   WeaponIDs, +   ArmorID, +   Location, +   LocationOmnimods +) -> +   {MainWeaponID, _} = WeaponIDs,     Armor = shr_armor:from_id(ArmorID), -   ActiveWeapon = shr_weapon:from_id(ActiveWeaponID), +   MainWeapon = shr_weapon:from_id(MainWeaponID),     PermanentOmnimods = -      shr_omnimods:merge(shr_armor:get_omnimods(Armor), GlyphOmnimods), +      shr_omnimods:merge(shr_armor:get_omnimods(Armor), GlyphsOmnimods),     CurrentOmnimods =        shr_omnimods:merge        (           shr_omnimods:merge           ( -            shr_weapon:get_omnimods(ActiveWeapon), -            shr_tile:get_omnimods(CurrentTile) +            shr_weapon:get_omnimods(MainWeapon), +            LocationOmnimods           ),           PermanentOmnimods        ), @@ -276,17 +242,10 @@ random (ID, PlayerIX, GlyphOmnimods, Map, ForbiddenLocations) ->     #character     { -      id = ID,        player_ix = PlayerIX, -      name = list_to_binary("Char" ++ IDAsListString), -      rank = -         if -            ((ID rem 8) == 0) -> commander; -            ((ID rem 3) == 0) -> target; -            true -> optional -         end, -      icon = IDAsBinaryString, -      portrait = IDAsBinaryString, +      name = Name, +      rank = Rank, +      portrait = PortraitID,        weapon_ids = WeaponIDs,        armor_id = ArmorID,        location = Location, diff --git a/src/roster/struct/rst_character.erl b/src/roster/struct/rst_character.erl index e3663cc..afe370d 100644 --- a/src/roster/struct/rst_character.erl +++ b/src/roster/struct/rst_character.erl @@ -8,7 +8,7 @@     character,     {        name :: binary(), -      portrait :: binary(), +      portrait_id :: shr_portrait:id(),        weapon_ids :: {shr_weapon:id(), shr_weapon:id()},        armor_id :: shr_armor:id(),        glyph_ids :: array:array(shr_glyph:id()), @@ -27,21 +27,21 @@  (     [        get_name/1, -      get_portrait/1, +      get_portrait_id/1,        get_weapon_ids/1,        get_armor_id/1,        get_glyph_ids/1,        get_glyph_board_id/1,        set_name/2, -      set_portrait/2, +      set_portrait_id/2,        set_weapon_ids/2,        set_armor_id/2,        set_glyph_ids/2,        set_glyph_board_id/2,        get_name_field/0, -      get_portrait_field/0, +      get_portrait_id_field/0,        get_weapon_ids_field/0,        get_armor_id_field/0,        get_glyph_ids_field/0, @@ -72,8 +72,8 @@ validate_name (_Name) ->     % TODO [SECURITY][LOW]: unimplemented     ok. --spec validate_portrait (shr_inventory:type(), binary()) -> ok. -validate_portrait (_Inventory, _Portrait) -> +-spec validate_portrait_id (shr_inventory:type(), shr_portrait:id()) -> ok. +validate_portrait_id (_Inventory, _Portrait) ->     % TODO [SECURITY][LOW]: unimplemented     ok. @@ -119,8 +119,8 @@ validate_glyphs_on_board (_Glyphs, _GlyphBoard) ->  -spec get_name (type()) -> binary().  get_name (Char) -> Char#character.name. --spec get_portrait (type()) -> binary(). -get_portrait (Char) -> Char#character.portrait. +-spec get_portrait_id (type()) -> shr_portrait:id(). +get_portrait_id (Char) -> Char#character.portrait_id.  -spec get_weapon_ids (type()) -> {shr_weapon:id(), shr_weapon:id()}.  get_weapon_ids (Char) -> Char#character.weapon_ids. @@ -142,11 +142,11 @@ set_name (Name, Char) ->        name = Name     }. --spec set_portrait (binary(), type()) -> type(). -set_portrait (PortraitID, Char) -> +-spec set_portrait_id (shr_portrait:id(), type()) -> type(). +set_portrait_id (PortraitID, Char) ->     Char#character     { -      portrait = PortraitID +      portrait_id = PortraitID     }.  -spec set_armor_id (shr_armor:id(), type()) -> type(). @@ -182,7 +182,7 @@ random () ->     #character     {        name = <<"">>, -      portrait = <<"0">>, +      portrait_id = <<"0">>,        weapon_ids = {0, 0},        armor_id = 0,        glyph_ids = array:new(), @@ -191,8 +191,8 @@ random () ->  -spec get_name_field () -> non_neg_integer().  get_name_field () -> #character.name. --spec get_portrait_field () -> non_neg_integer(). -get_portrait_field () -> #character.portrait. +-spec get_portrait_id_field () -> non_neg_integer(). +get_portrait_id_field () -> #character.portrait_id.  -spec get_armor_id_field () -> non_neg_integer().  get_armor_id_field () -> #character.armor_id.  -spec get_weapon_ids_field () -> non_neg_integer(). @@ -215,7 +215,7 @@ decode (JSONReqMap) ->     #character     {        name = Name, -      portrait = Portrait, +      portrait_id = Portrait,        weapon_ids = {ActiveWeapon, SecondaryWeapon},        armor_id = Armor,        glyph_ids = array:from_list(GlyphsList), @@ -228,7 +228,7 @@ validate (Inventory, Character) ->     GlyphBoard = Character#character.glyph_board_id,     validate_name(Character#character.name), -   validate_portrait(Inventory, Character#character.portrait), +   validate_portrait_id(Inventory, Character#character.portrait_id),     validate_weapons(Inventory, Character#character.weapon_ids),     validate_armor(Inventory, Character#character.armor_id),     validate_glyphs(Inventory, Glyphs), diff --git a/src/special/spe_battle.erl b/src/special/spe_battle.erl index 1b3453c..31f844a 100644 --- a/src/special/spe_battle.erl +++ b/src/special/spe_battle.erl @@ -12,9 +12,19 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +%%%% DB ACCESS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -spec reserve_id () -> binary(). -reserve_id () -> <<"0">>. +reserve_id () -> +   %% TODO Unimplemented. +   <<"0">>. + +-spec commit (btl_battle:type()) -> ok. +commit (_Battle) -> +   %% TODO Unimplemented. +   ok. +%%%% USED IDS COLLECTION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -spec get_equipment_ids     (        list(btl_character:type()) @@ -56,6 +66,84 @@ get_tile_ids (TileInstances) ->     UsedTileIDs. +%%%% ROSTERS HANDLING %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec find_random_location +   ( +      btl_map:type(), +      list({non_neg_integer(), non_neg_integer()}) +   ) +   -> {{non_neg_integer(), non_neg_integer()}, shr_tile:type()}. +find_random_location (Map, ForbiddenLocations) -> +   MapWidth = btl_map:get_width(Map), +   MapHeight = btl_map:get_height(Map), + +   Candidate = +      { +         shr_roll:between(0, (MapWidth - 1)), +         shr_roll:between(0, (MapHeight - 1)) +      }, + +   IsForbidden = lists:member(Candidate, ForbiddenLocations), + +   case IsForbidden of +      true -> find_random_location(Map, ForbiddenLocations); + +      _ -> +         Tile = +            shr_tile:from_class_id +            ( +               shr_tile:extract_main_class_id +               ( +                  btl_map:get_tile_instance(Candidate, Map) +               ) +            ), + +         case (shr_tile:get_cost(Tile) > 200) of +            true -> find_random_location(Map, ForbiddenLocations); + +            false -> {Candidate, Tile} +         end +   end. + +-spec get_glyphs_omnimods (rst_character:type()) -> shr_omnimods:type(). +get_glyphs_omnimods (RosterChar) -> +   GlyphBoardID = rst_character:get_glyph_board_id(RosterChar), +   GlyphIDs = rst_character:get_glyph_ids(RosterChar), +   GlyphBoard = shr_glyph_board:from_id(GlyphBoardID), +   Glyphs = array:map(fun rst_glyph:from_id/1, GlyphIDs), +   Result = shr_glyph_board:get_omnimods(Glyphs, GlyphBoard), + +   Result. + +-spec create_character +   ( +      non_neg_integer(), +      rst_character:type(), +      btl_map:type(), +      list(btl_location:type()) +   ) +   -> btl_character:type(). +create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) -> +   {Location, Tile} = find_random_location(Map, ForbiddenLocations), +   TileOmnimods = shr_tile:get_omnimods(Tile), +   GlyphsOmnimods = get_glyphs_omnimods(RosterChar), + +   Result = +      btl_character:new +      ( +         PlayerIX, +         rst_character:get_name(RosterChar), +         optional, % TODO: link this to roster. +         GlyphsOmnimods, +         rst_character:get_portrait_id(RosterChar), +         rst_character:get_weapon_ids(RosterChar), +         rst_character:get_armor_id(RosterChar), +         Location, +         TileOmnimods +      ), + +   Result. +  -spec handle_rosters     (        list(rst_roster:type()) @@ -65,6 +153,7 @@ handle_rosters (_Rosters) ->     %% TODO Unimplemented.     {[], []}. +%%%% BATTLE CREATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -spec generate_battle     (        binary(), @@ -99,11 +188,6 @@ generate_battle (ID, Map, Rosters) ->     Battle. --spec commit (btl_battle:type()) -> ok. -commit (_Battle) -> -   %% TODO Unimplemented. -   ok. -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | 


