summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-28 23:29:55 +0200
committerNathanael Sensfelder <SpamShield0@MultiAgentSystems.org>2018-08-28 23:29:55 +0200
commit9b424b11dbea33a41b2129daf232557515de9db1 (patch)
tree97cbe449c02e4273c79448859ceac722a06524b1 /src
parent68d3f1d7fd3703a8aef68bd6e9f89a84eab5e539 (diff)
Still propagating the changes...
It'll require the attributes and statistics being recalculated every time a character is used, which isn't great. Can't exactly avoid it though: moving and changing weapon are both likely to alter them, and people rarely attack without doing one or the other.
Diffstat (limited to 'src')
-rw-r--r--src/battle/reply/btl_add_armor.erl8
-rw-r--r--src/battle/reply/btl_add_char.erl25
-rw-r--r--src/battle/reply/btl_add_tile.erl3
-rw-r--r--src/battle/reply/btl_add_weapon.erl30
-rw-r--r--src/battle/struct/btl_character.erl130
-rw-r--r--src/shared/struct/shr_attributes.erl52
-rw-r--r--src/shared/struct/shr_omnimods.erl55
-rw-r--r--src/shared/struct/shr_statistics.erl155
-rw-r--r--src/shared/struct/shr_tile.erl.m42
9 files changed, 269 insertions, 191 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().
diff --git a/src/shared/struct/shr_attributes.erl b/src/shared/struct/shr_attributes.erl
index 23824e4..c402e74 100644
--- a/src/shared/struct/shr_attributes.erl
+++ b/src/shared/struct/shr_attributes.erl
@@ -46,7 +46,9 @@
set_unsafe_intelligence/2,
set_unsafe_mind/2,
set_unsafe_speed/2,
- set_unsafe_strength/2
+ set_unsafe_strength/2,
+
+ apply_mod/3
]
).
@@ -54,7 +56,7 @@
-export
(
[
- random/0
+ default/0
]
).
@@ -64,6 +66,28 @@
-spec make_safe (integer()) -> non_neg_integer().
make_safe (Val) -> max(0, min(100, Val)).
+-spec mod_unsafe_constitution (integer(), type()) -> type().
+mod_unsafe_constitution (Val, Att) ->
+ set_constitution(make_safe(get_constitution(Att) + Val), Att).
+
+-spec mod_unsafe_dexterity (integer(), type()) -> type().
+mod_unsafe_dexterity (Val, Att) ->
+ set_dexterity(make_safe(get_dexterity(Att) + Val), Att).
+
+-spec mod_unsafe_intelligence (integer(), type()) -> type().
+mod_unsafe_intelligence (Val, Att) ->
+ set_intelligence(make_safe(get_intelligence(Att) + Val), Att).
+
+-spec mod_unsafe_mind (integer(), type()) -> type().
+mod_unsafe_mind (Val, Att) -> set_mind(make_safe(get_mind(Att) + Val), Att).
+
+-spec mod_unsafe_speed (integer(), type()) -> type().
+mod_unsafe_speed (Val, Att) -> set_speed(make_safe(get_speed(Att) + Val), Att).
+
+-spec mod_unsafe_strength (integer(), type()) -> type().
+mod_unsafe_strength (Val, Att) ->
+ set_strength(make_safe(get_strength(Att) + Val), Att).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -122,14 +146,22 @@ set_unsafe_speed (Val, Att) -> set_speed(make_safe(Val), Att).
-spec set_unsafe_strength (integer(), type()) -> type().
set_unsafe_strength (Val, Att) -> set_strength(make_safe(Val), Att).
--spec random () -> type().
-random () ->
+-spec default () -> type().
+default () ->
#attributes
{
- constitution = shr_roll:percentage(),
- dexterity = shr_roll:percentage(),
- intelligence = shr_roll:percentage(),
- mind = shr_roll:percentage(),
- speed = shr_roll:percentage(),
- strength = shr_roll:percentage()
+ constitution = 50,
+ dexterity = 50,
+ intelligence = 50,
+ mind = 50,
+ speed = 50,
+ strength = 50
}.
+
+-spec apply_mod (atom(), integer(), type()) -> type().
+apply_mod (con, Value, Att) -> mod_unsafe_constitution(Value, Att);
+apply_mod (dex, Value, Att) -> mod_unsafe_dexterity(Value, Att);
+apply_mod (int, Value, Att) -> mod_unsafe_intelligence(Value, Att);
+apply_mod (min, Value, Att) -> mod_unsafe_mind(Value, Att);
+apply_mod (spe, Value, Att) -> mod_unsafe_speed(Value, Att);
+apply_mod (str, Value, Att) -> mod_unsafe_strength(Value, Att).
diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl
index 03ec5af..31d61f2 100644
--- a/src/shared/struct/shr_omnimods.erl
+++ b/src/shared/struct/shr_omnimods.erl
@@ -24,6 +24,7 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%% Accessors
-export
(
[
@@ -32,7 +33,7 @@
]
).
-%%%% Accessors
+%%%% Modification
-export
(
[
@@ -41,15 +42,24 @@
]
).
+%%%% Access
-export
(
[
- apply_to_attributes/3,
- apply_to_statistics/3,
+ apply_to_attributes/2,
+ apply_to_statistics/2,
get_attack_damage/3
]
).
+%%%% Export
+-export
+(
+ [
+ encode/1
+ ]
+).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -69,6 +79,21 @@ apply_coefficient_to_mods (Coef, Mods) ->
merge_mods (ModsA, ModsB) ->
dict:merge(fun (_Name, ValA, ValB) -> (ValA + ValB) end, ModsA, ModsB).
+-spec encode_mods (mods()) -> list(any()).
+encode_mods (Mods) ->
+ lists:map
+ (
+ fun ({Name, Value}) ->
+ {
+ [
+ {<<"t">>, Name},
+ {<<"v">>, Value}
+ ]
+ }
+ end,
+ dict:to_list(Mods)
+ ).
+
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -128,33 +153,31 @@ apply_coefficient (Coef, Omnimods) ->
defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods)
}.
-%%% Application
+%%% Access
-spec apply_to_attributes
(
- fun((atom(), integer(), shr_attributes:type()) -> shr_attributes:type()),
type(),
shr_attributes:type()
)
-> shr_attributes:type().
-apply_to_attributes (UpdateFun, Omnimods, Attributes) ->
+apply_to_attributes (Omnimods, Attributes) ->
dict:fold
(
- UpdateFun,
+ fun shr_attributes:apply_mod/3,
Attributes,
Omnimods#omnimods.attmods
).
-spec apply_to_statistics
(
- fun((atom(), integer(), shr_statistics:type()) -> shr_statistics:type()),
type(),
shr_statistics:type()
)
-> shr_statistics:type().
-apply_to_statistics (UpdateFun, Omnimods, Statistics) ->
+apply_to_statistics (Omnimods, Statistics) ->
dict:fold
(
- UpdateFun,
+ fun shr_statistics:apply_mod/3,
Statistics,
Omnimods#omnimods.attmods
).
@@ -187,3 +210,15 @@ get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) ->
),
Result.
+
+%%% Export
+-spec encode (type()) -> {list(any())}.
+encode (Omnimods) ->
+ {
+ [
+ {<<"attm">>, encode_mods(Omnimods#omnimods.attmods)},
+ {<<"stam">>, encode_mods(Omnimods#omnimods.stamods)},
+ {<<"atkm">>, encode_mods(Omnimods#omnimods.atkmods)},
+ {<<"defm">>, encode_mods(Omnimods#omnimods.defmods)}
+ ]
+ }.
diff --git a/src/shared/struct/shr_statistics.erl b/src/shared/struct/shr_statistics.erl
index cf48d96..4249d52 100644
--- a/src/shared/struct/shr_statistics.erl
+++ b/src/shared/struct/shr_statistics.erl
@@ -11,11 +11,10 @@
health :: non_neg_integer(),
dodges :: non_neg_integer(),
parries :: non_neg_integer(),
- damage_min :: non_neg_integer(),
- damage_max :: non_neg_integer(),
accuracy :: non_neg_integer(),
double_hits :: non_neg_integer(),
- critical_hits :: non_neg_integer()
+ critical_hits :: non_neg_integer(),
+ damage_modifier :: float()
}
).
@@ -34,20 +33,19 @@
get_health/1,
get_dodges/1,
get_parries/1,
- get_damage_min/1,
- get_damage_max/1,
get_accuracy/1,
get_double_hits/1,
get_critical_hits/1,
+ get_damage_modifier/1,
- get_damages/1
+ apply_mod/3
]
).
-export
(
[
- new/3
+ new_raw/1
]
).
@@ -94,14 +92,76 @@ sudden_exp_growth (V) -> float_to_int(math:pow(4.0, V / 25.0)).
-spec damage_base_modifier (non_neg_integer()) -> float().
damage_base_modifier (Strength) -> ((math:pow(Strength, 1.8) / 2000.0) - 0.75).
--spec apply_damage_base_modifier
- (
- float(),
- non_neg_integer()
- )
- -> non_neg_integer().
-apply_damage_base_modifier (Modifier, BaseValue) ->
- max(0, float_to_int(BaseValue + (BaseValue * Modifier))).
+-spec make_movement_points_safe (non_neg_integer()) -> non_neg_integer().
+make_movement_points_safe (Val) -> min_max(0, 200, Val).
+
+-spec make_health_safe (non_neg_integer()) -> non_neg_integer().
+make_health_safe (Val) -> max(1, Val).
+
+-spec make_dodges_safe (non_neg_integer()) -> non_neg_integer().
+make_dodges_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_parries_safe (non_neg_integer()) -> non_neg_integer().
+make_parries_safe (Val) -> min_max(0, 75, Val).
+
+-spec make_accuracy_safe (non_neg_integer()) -> non_neg_integer().
+make_accuracy_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_double_hits_safe (non_neg_integer()) -> non_neg_integer().
+make_double_hits_safe (Val) -> min_max(0, 100, Val).
+
+-spec make_critical_hits_safe (non_neg_integer()) -> non_neg_integer().
+make_critical_hits_safe (Val) -> min_max(0, 100, Val).
+
+-spec mod_movement_points (integer(), type()) -> type().
+mod_movement_points (Mod, Stats) ->
+ Stats#statistics
+ {
+ movement_points =
+ make_movement_points_safe(get_movement_points(Stats) + Mod)
+ }.
+
+-spec mod_health (integer(), type()) -> type().
+mod_health (Mod, Stats) ->
+ Stats#statistics
+ {
+ health = make_health_safe(get_health(Stats) + Mod)
+ }.
+
+-spec mod_dodges (integer(), type()) -> type().
+mod_dodges (Mod, Stats) ->
+ Stats#statistics
+ {
+ dodges = make_dodges_safe(get_dodges(Stats) + Mod)
+ }.
+
+-spec mod_parries (integer(), type()) -> type().
+mod_parries (Mod, Stats) ->
+ Stats#statistics
+ {
+ parries = make_parries_safe(get_parries(Stats) + Mod)
+ }.
+
+-spec mod_accuracy (integer(), type()) -> type().
+mod_accuracy (Mod, Stats) ->
+ Stats#statistics
+ {
+ accuracy = make_accuracy_safe(get_accuracy(Stats) + Mod)
+ }.
+
+-spec mod_double_hits (integer(), type()) -> type().
+mod_double_hits (Mod, Stats) ->
+ Stats#statistics
+ {
+ double_hits = make_double_hits_safe(get_double_hits(Stats) + Mod)
+ }.
+
+-spec mod_critical_hits (integer(), type()) -> type().
+mod_critical_hits (Mod, Stats) ->
+ Stats#statistics
+ {
+ critical_hits = make_critical_hits_safe(get_critical_hits(Stats) + Mod)
+ }.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -119,12 +179,6 @@ get_dodges (Stats) -> Stats#statistics.dodges.
-spec get_parries (type()) -> non_neg_integer().
get_parries (Stats) -> Stats#statistics.parries.
--spec get_damage_min (type()) -> non_neg_integer().
-get_damage_min (Stats) -> Stats#statistics.damage_min.
-
--spec get_damage_max (type()) -> non_neg_integer().
-get_damage_max (Stats) -> Stats#statistics.damage_max.
-
-spec get_accuracy (type()) -> non_neg_integer().
get_accuracy (Stats) -> Stats#statistics.accuracy.
@@ -134,38 +188,17 @@ get_double_hits (Stats) -> Stats#statistics.double_hits.
-spec get_critical_hits (type()) -> non_neg_integer().
get_critical_hits (Stats) -> Stats#statistics.critical_hits.
--spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}.
-get_damages (Stats) ->
- {
- Stats#statistics.damage_min,
- Stats#statistics.damage_max
- }.
+-spec get_damage_modifier (type()) -> float().
+get_damage_modifier (Stats) -> Stats#statistics.damage_modifier.
--spec new
- (
- shr_attributes:type(),
- {shr_weapon:id(), shr_weapon:id()},
- shr_armor:id()
- )
- -> type().
-new (BaseAttributes, WeaponIDs, ArmorID) ->
- {ActiveWeaponID, _} = WeaponIDs,
- ActiveWeapon = shr_weapon:from_id(ActiveWeaponID),
- {MinDamage, MaxDamage} = shr_weapon:get_damages(ActiveWeapon),
- Armor = shr_armor:from_id(ArmorID),
- Attributes =
- shr_armor:apply_to_attributes
- (
- Armor,
- shr_weapon:apply_to_attributes(ActiveWeapon, BaseAttributes)
- ),
+-spec new_raw (shr_attributes:type()) -> type().
+new_raw (Attributes) ->
Constitution = shr_attributes:get_constitution(Attributes),
Dexterity = shr_attributes:get_dexterity(Attributes),
Intelligence = shr_attributes:get_intelligence(Attributes),
Mind = shr_attributes:get_mind(Attributes),
Speed = shr_attributes:get_speed(Attributes),
Strength = shr_attributes:get_strength(Attributes),
- DamageBaseModifier = damage_base_modifier(Strength),
#statistics
{
@@ -180,21 +213,23 @@ new (BaseAttributes, WeaponIDs, ArmorID) ->
average([Constitution, Constitution, Constitution, Mind])
),
dodges =
- min_max(0, 100, sudden_exp_growth(average([Dexterity, Mind, Speed]))),
+ sudden_exp_growth(average([Dexterity, Mind, Speed])),
parries =
- min_max
+ sudden_exp_growth
(
- 0,
- 75,
- sudden_exp_growth
- (
- average([Dexterity, Intelligence, Speed, Strength])
- )
+ average([Dexterity, Intelligence, Speed, Strength])
),
- damage_min = apply_damage_base_modifier(DamageBaseModifier, MinDamage),
- damage_max = apply_damage_base_modifier(DamageBaseModifier, MaxDamage),
- accuracy = min_max(0, 100, sudden_squared_growth(Dexterity)),
- double_hits =
- min_max(0, 100, sudden_squared_growth(average([Mind, Speed]))),
- critical_hits = min_max(0, 100, sudden_squared_growth(Intelligence))
+ accuracy = sudden_squared_growth(Dexterity),
+ double_hits = sudden_squared_growth(average([Mind, Speed])),
+ critical_hits = sudden_squared_growth(Intelligence),
+ damage_modifier = damage_base_modifier(Strength)
}.
+
+-spec apply_mod (atom(), integer(), type()) -> type().
+apply_mod(mheal, Value, Stats) -> mod_health(Value, Stats);
+apply_mod(mpts, Value, Stats) -> mod_movement_points(Value, Stats);
+apply_mod(dodg, Value, Stats) -> mod_dodges(Value, Stats);
+apply_mod(pary, Value, Stats) -> mod_parries(Value, Stats);
+apply_mod(accu, Value, Stats) -> mod_accuracy(Value, Stats);
+apply_mod(dhit, Value, Stats) -> mod_double_hits(Value, Stats);
+apply_mod(crit, Value, Stats) -> mod_critical_hits(Value, Stats).
diff --git a/src/shared/struct/shr_tile.erl.m4 b/src/shared/struct/shr_tile.erl.m4
index 535bcde..750e59a 100644
--- a/src/shared/struct/shr_tile.erl.m4
+++ b/src/shared/struct/shr_tile.erl.m4
@@ -16,7 +16,7 @@
}
).
--opaque class_id() :: non_neg_integer().
+-type class_id() :: non_neg_integer().
-opaque instance() :: list(non_neg_integer()).
-opaque border() :: list(non_neg_integer()).