| summaryrefslogtreecommitdiff | 
diff options
Diffstat (limited to 'src/battle')
| -rw-r--r-- | src/battle/reply/btl_add_armor.erl | 8 | ||||
| -rw-r--r-- | src/battle/reply/btl_add_char.erl | 25 | ||||
| -rw-r--r-- | src/battle/reply/btl_add_tile.erl | 3 | ||||
| -rw-r--r-- | src/battle/reply/btl_add_weapon.erl | 30 | ||||
| -rw-r--r-- | src/battle/struct/btl_character.erl | 130 | 
5 files changed, 86 insertions, 110 deletions
| diff --git a/src/battle/reply/btl_add_armor.erl b/src/battle/reply/btl_add_armor.erl index 01c99ad..d78edc5 100644 --- a/src/battle/reply/btl_add_armor.erl +++ b/src/battle/reply/btl_add_armor.erl @@ -12,11 +12,6 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec encode_category (shr_armor:category()) -> binary(). -encode_category (kinetic) -> <<"k">>; -encode_category (leather) -> <<"l">>; -encode_category (chain) -> <<"c">>; -encode_category (plate) -> <<"p">>.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -28,7 +23,6 @@ generate (Armor) ->           {<<"msg">>, <<"add_armor">>},           {<<"id">>, shr_armor:get_id(Armor)},           {<<"nam">>, shr_armor:get_name(Armor)}, -         {<<"ct">>, encode_category(shr_armor:get_category(Armor))}, -         {<<"cf">>, shr_armor:get_coefficient(Armor)} +         {<<"omni">>, shr_omnimods:encode(shr_armor:get_omnimods(Armor))}        ]     }. diff --git a/src/battle/reply/btl_add_char.erl b/src/battle/reply/btl_add_char.erl index f0b70e9..a6fb60c 100644 --- a/src/battle/reply/btl_add_char.erl +++ b/src/battle/reply/btl_add_char.erl @@ -20,23 +20,6 @@ rank_to_string (Rank) ->        commander -> <<"c">>     end. --spec attributes_as_json -   ( -      shr_attributes:type() -   ) -> -   {list({binary(), non_neg_integer()})}. -attributes_as_json (Attributes) -> -   { -      [ -         {<<"con">>, shr_attributes:get_constitution(Attributes)}, -         {<<"dex">>, shr_attributes:get_dexterity(Attributes)}, -         {<<"int">>, shr_attributes:get_intelligence(Attributes)}, -         {<<"min">>, shr_attributes:get_mind(Attributes)}, -         {<<"spe">>, shr_attributes:get_speed(Attributes)}, -         {<<"str">>, shr_attributes:get_strength(Attributes)} -      ] -   }. -  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -48,7 +31,6 @@ attributes_as_json (Attributes) ->     )     -> {list(any())}.  generate (IX, Character, PlayerIX) -> -   Attributes = btl_character:get_attributes(Character),     {ActiveWeapon, SecondaryWeapon} = btl_character:get_weapon_ids(Character),     CharacterPlayerIX = btl_character:get_player_index(Character),     Location = btl_character:get_location(Character), @@ -75,9 +57,12 @@ generate (IX, Character, PlayerIX) ->              )           },           {<<"dea">>, btl_character:get_is_defeated(Character)}, -         {<<"att">>, attributes_as_json(Attributes)},           {<<"awp">>, ActiveWeapon},           {<<"swp">>, SecondaryWeapon}, -         {<<"ar">>, btl_character:get_armor_id(Character)} +         {<<"ar">>, btl_character:get_armor_id(Character)}, +         { +            <<"pomni">>, +            shr_omnimods:encode(btl_character:get_permanent_omnimods(Character)) +         }        ]     }. diff --git a/src/battle/reply/btl_add_tile.erl b/src/battle/reply/btl_add_tile.erl index c9cd18e..bf76547 100644 --- a/src/battle/reply/btl_add_tile.erl +++ b/src/battle/reply/btl_add_tile.erl @@ -23,6 +23,7 @@ generate (Tile) ->           {<<"msg">>, <<"add_tile">>},           {<<"id">>, shr_tile:get_class_id(Tile)},           {<<"nam">>, shr_tile:get_name(Tile)}, -         {<<"ct">>, shr_tile:get_cost(Tile)} +         {<<"ct">>, shr_tile:get_cost(Tile)}, +         {<<"omni">>, shr_omnimods:encode(shr_tile:get_omnimods(Tile))}        ]     }. diff --git a/src/battle/reply/btl_add_weapon.erl b/src/battle/reply/btl_add_weapon.erl index 5484a76..e5f7522 100644 --- a/src/battle/reply/btl_add_weapon.erl +++ b/src/battle/reply/btl_add_weapon.erl @@ -12,22 +12,6 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% --spec encode_range_type (shr_weapon:range_type()) -> binary(). -encode_range_type (melee) -> <<"m">>; -encode_range_type (ranged) -> <<"r">>. - --spec encode_range_modifier (shr_weapon:range_modifier()) -> binary(). -encode_range_modifier (long) -> <<"l">>; -encode_range_modifier (short) -> <<"s">>. - --spec encode_damage_type (shr_weapon:damage_type()) -> binary(). -encode_damage_type (slash) -> <<"s">>; -encode_damage_type (pierce) -> <<"p">>; -encode_damage_type (blunt) -> <<"b">>. - --spec encode_damage_modifier (shr_weapon:damage_modifier()) -> binary(). -encode_damage_modifier (heavy) -> <<"h">>; -encode_damage_modifier (light) -> <<"l">>.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -39,16 +23,8 @@ generate (Weapon) ->           {<<"msg">>, <<"add_weapon">>},           {<<"id">>, shr_weapon:get_id(Weapon)},           {<<"nam">>, shr_weapon:get_name(Weapon)}, -         {<<"rt">>, encode_range_type(shr_weapon:get_range_type(Weapon))}, -         { -            <<"rm">>, -            encode_range_modifier(shr_weapon:get_range_modifier(Weapon)) -         }, -         {<<"dt">>, encode_damage_type(shr_weapon:get_damage_type(Weapon))}, -         { -            <<"dm">>, -            encode_damage_modifier(shr_weapon:get_damage_modifier(Weapon)) -         }, -         {<<"cf">>, shr_weapon:get_coefficient(Weapon)} +         {<<"rmi">>, shr_weapon:get_range_minimum(Weapon)}, +         {<<"rma">>, shr_weapon:get_range_maximum(Weapon)}, +         {<<"omni">>, shr_omnimods:encode(shr_armor:get_omnimods(Weapon))}        ]     }. diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl index 3f5c360..a95a10c 100644 --- a/src/battle/struct/btl_character.erl +++ b/src/battle/struct/btl_character.erl @@ -16,14 +16,13 @@        rank :: rank(),        icon :: binary(),        portrait :: binary(), -      attributes :: shr_attributes:type(), -      statistics :: shr_statistics:type(),        weapon_ids :: {shr_weapon:id(), shr_weapon:id()},        armor_id :: shr_armor:id(),        location :: {non_neg_integer(), non_neg_integer()},        current_health :: integer(), %% Negative integers let us reverse attacks.        is_active :: boolean(), -      is_defeated :: boolean() +      is_defeated :: boolean(), +      permanent_omnimods :: shr_omnimods:type()     }  ). @@ -43,8 +42,6 @@        get_rank/1,        get_icon/1,        get_portrait/1, -      get_attributes/1, -      get_statistics/1,        get_weapon_ids/1,        get_armor_id/1,        get_location/1, @@ -52,18 +49,17 @@        get_is_alive/1,        get_is_active/1,        get_is_defeated/1, +      get_permanent_omnimods/1,        set_rank/2,        set_weapon_ids/2,        set_armor_id/2, -      set_statistics/2,        set_location/2,        set_current_health/2,        set_is_active/2,        set_is_defeated/2,        get_rank_field/0, -      get_statistics_field/0,        get_weapons_field/0,        get_location_field/0,        get_current_health_field/0, @@ -84,27 +80,40 @@  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  -spec find_random_location     ( -      non_neg_integer(), -      non_neg_integer(), +      btl_map:type(),        list({non_neg_integer(), non_neg_integer()})     ) -   -> {non_neg_integer(), non_neg_integer()}. -find_random_location (MapWidth, MapHeight, ForbiddenLocations) -> -   X = shr_roll:between(0, (MapWidth - 1)), -   Y = shr_roll:between(0, (MapHeight - 1)), +   -> {{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), -   IsForbidden = lists:member({X, Y}, ForbiddenLocations), +   Candidate = +      { +         shr_roll:between(0, (MapWidth - 1)), +         shr_roll:between(0, (MapHeight - 1)) +      }, -   case IsForbidden of -      true -> -         find_random_location -         ( -            MapWidth, -            MapHeight, -            ForbiddenLocations -         ); +   IsForbidden = lists:member(Candidate, ForbiddenLocations), -      _ -> {X, Y} +   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.  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -129,24 +138,21 @@ get_icon (Char) -> Char#character.icon.  -spec get_portrait (type()) -> binary().  get_portrait (Char) -> Char#character.portrait. --spec get_attributes (type()) -> shr_attributes:type(). -get_attributes (Char) -> Char#character.attributes. -  -spec get_armor_id (type()) -> shr_armor:id().  get_armor_id (Char) -> Char#character.armor_id.  -spec get_weapon_ids (type()) -> {shr_weapon:id(), shr_weapon:id()}.  get_weapon_ids (Char) -> Char#character.weapon_ids. --spec get_statistics (type()) -> shr_statistics:type(). -get_statistics (Char) -> Char#character.statistics. -  -spec get_location (type()) -> {non_neg_integer(), non_neg_integer()}.  get_location (Char) -> Char#character.location.  -spec get_current_health (type()) -> integer().  get_current_health (Char) -> Char#character.current_health. +-spec get_permanent_omnimods (type()) -> shr_omnimods:type(). +get_permanent_omnimods (Char) -> Char#character.permanent_omnimods. +  -spec get_is_alive (type()) -> boolean().  get_is_alive (Char) ->     ( @@ -219,38 +225,55 @@ set_weapon_ids (WeaponIDs, Char) ->        weapon_ids = WeaponIDs     }. --spec set_statistics -   ( -      shr_statistics:type(), -      type() -   ) -   -> type(). -set_statistics (Stats, Char) -> -   Char#character -   { -      statistics = Stats -   }. -  %%%% Utils  -spec random     (        non_neg_integer(),        non_neg_integer(), -      non_neg_integer(), -      non_neg_integer(), +      shr_omnimods:type(), +      btl_map:type(),        list({non_neg_integer(), non_neg_integer()})     )     -> type(). -random (ID, PlayerIX, MapWidth, MapHeight, ForbiddenLocations) -> -   Location = -      find_random_location(MapWidth, MapHeight, ForbiddenLocations), -   WeaponIDs = {shr_weapon:random_id(), shr_weapon:random_id()}, +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(), -   Attributes = shr_attributes:random(), -   Statistics = shr_statistics:new(Attributes, WeaponIDs, ArmorID),     IDAsListString = integer_to_list(ID),     IDAsBinaryString = list_to_binary(IDAsListString), +   Armor = shr_armor:from_id(ArmorID), +   ActiveWeapon = shr_weapon:from_id(ActiveWeaponID), + +   PermanentOmnimods = +      shr_omnimods:merge(shr_armor:get_omnimods(Armor), GlyphOmnimods), + +   CurrentOmnimods = +      shr_omnimods:merge +      ( +         shr_omnimods:merge +         ( +            shr_weapon:get_omnimods(ActiveWeapon), +            shr_tile:get_omnimods(CurrentTile) +         ), +         PermanentOmnimods +      ), + +   CurrentAttributes = +      shr_omnimods:apply_to_attributes +      ( +         CurrentOmnimods, +         shr_attributes:default() +      ), + +   CurrentStatistics = +      shr_omnimods:apply_to_statistics +      ( +         CurrentOmnimods, +         shr_statistics:new_raw(CurrentAttributes) +      ), +     #character     {        id = ID, @@ -264,20 +287,17 @@ random (ID, PlayerIX, MapWidth, MapHeight, ForbiddenLocations) ->           end,        icon = IDAsBinaryString,        portrait = IDAsBinaryString, -      attributes = Attributes,        weapon_ids = WeaponIDs,        armor_id = ArmorID, -      statistics = Statistics,        location = Location, -      current_health = shr_statistics:get_health(Statistics), +      current_health = shr_statistics:get_health(CurrentStatistics),        is_active = false, -      is_defeated = false +      is_defeated = false, +      permanent_omnimods = PermanentOmnimods     }.  -spec get_rank_field() -> non_neg_integer().  get_rank_field () -> #character.rank. --spec get_statistics_field() -> non_neg_integer(). -get_statistics_field () -> #character.statistics.  -spec get_weapons_field() -> non_neg_integer().  get_weapons_field () -> #character.weapon_ids.  -spec get_location_field() -> non_neg_integer(). | 


