summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/balancer/struct/blc_armor.erl')
-rw-r--r--src/balancer/struct/blc_armor.erl320
1 files changed, 149 insertions, 171 deletions
diff --git a/src/balancer/struct/blc_armor.erl b/src/balancer/struct/blc_armor.erl
index 9677f88..cc23415 100644
--- a/src/balancer/struct/blc_armor.erl
+++ b/src/balancer/struct/blc_armor.erl
@@ -40,22 +40,19 @@
(
proto_armor,
{
- health :: non_neg_integer(),
- damage_modifier :: non_neg_integer(),
- dodge :: non_neg_integer(),
- mvt_points :: non_neg_integer(),
- defense :: list(blc_damage_type:entry()),
+ omnimods :: shr_omnimods:type(),
defense_coef :: list(blc_damage_type:coefficient()),
- defense_score :: non_neg_integer()
+ defense_score :: non_neg_integer(),
+ remaining_points :: non_neg_integer()
}
).
--opaque proto_armor() :: #proto_armor{}.
+-opaque type() :: #proto_armor{}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export_type([proto_armor/0]).
+-export_type([type/0]).
-export
(
@@ -78,13 +75,54 @@
(
[
new/1,
- get_spendable_points/0
+ get_remaining_points/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec increase_attribute_by
+ (
+ shr_attributes:enum(),
+ non_neg_integer(),
+ type()
+ )
+ -> ({ok, type()} | blc_error:type()).
+increase_attribute_by (Attribute, S0Amount, Armor) ->
+ CurrentOmnimods = Armor#proto_armor.omnimods,
+ CurrentValue =
+ shr_omnimods:get_attribute_modifier(Attribute, CurrentOmnimods),
+
+ {_AttMin, _AttDef, AttMax, AttCost} = blc_attribute:get_info(Attribute),
+
+ S1Amount =
+ case ((CurrentValue + S0Amount) > AttMax) of
+ true -> (AttMax - CurrentValue);
+ false -> S0Amount
+ end,
+
+ Cost = (S1Amount * AttCost),
+ RemainingPoints = Armor#proto_armor.remaining_points,
+
+ case (Cost > RemainingPoints) of
+ true -> {error, balance, RemainingPoints, Cost};
+ false ->
+ {
+ ok,
+ Armor#proto_armor
+ {
+ remaining_points = (RemainingPoints - Cost),
+ omnimods =
+ shr_omnimods:mod_attribute_modifier
+ (
+ Attribute,
+ S1Amount,
+ Armor#proto_armor.omnimods
+ )
+ }
+ }
+ end.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -92,246 +130,186 @@
-spec increase_health_by
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_health_by (Amount, Armor) ->
- NewHealth = (Armor#proto_armor.health + Amount),
- case (NewHealth > ?ATTRIBUTE_HEALTH_MAX) of
- true ->
- {
- Armor#proto_armor{ health = ?ATTRIBUTE_HEALTH_MAX },
- (
- (?ATTRIBUTE_HEALTH_MAX - Armor#proto_armor.health)
- * ?ATTRIBUTE_HEALTH_COST
- )
- };
-
- false ->
- {
- Armor#proto_armor{ health = NewHealth },
- (Amount * ?ATTRIBUTE_HEALTH_COST)
- }
- end.
+ increase_attribute_by(?ATTRIBUTE_HEALTH, Amount, Armor).
-spec increase_damage_modifier_by
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_damage_modifier_by (Amount, Armor) ->
- NewDamageModifier = (Armor#proto_armor.damage_modifier + Amount),
- case (NewDamageModifier > ?ATTRIBUTE_DAMAGE_MODIFIER_MAX) of
- true ->
- {
- Armor#proto_armor
- {
- damage_modifier = ?ATTRIBUTE_DAMAGE_MODIFIER_MAX
- },
- (
- (
- ?ATTRIBUTE_DAMAGE_MODIFIER_MAX
- - Armor#proto_armor.damage_modifier
- )
- * ?ATTRIBUTE_DAMAGE_MODIFIER_COST
- )
- };
-
- false ->
- {
- Armor#proto_armor{ damage_modifier = NewDamageModifier },
- (Amount * ?ATTRIBUTE_DAMAGE_MODIFIER_COST)
- }
- end.
+ increase_attribute_by(?ATTRIBUTE_DAMAGE_MODIFIER, Amount, Armor).
-spec increase_dodge_chance_by
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_dodge_chance_by (Amount, Armor) ->
- NewDodgeChance = (Armor#proto_armor.dodge + Amount),
- case (NewDodgeChance > ?ATTRIBUTE_DODGE_CHANCE_MAX) of
- true ->
- {
- Armor#proto_armor{ dodge = ?ATTRIBUTE_DODGE_CHANCE_MAX },
- (
- (?ATTRIBUTE_DODGE_CHANCE_MAX - Armor#proto_armor.dodge)
- * ?ATTRIBUTE_DODGE_CHANCE_COST
- )
- };
-
- false ->
- {
- Armor#proto_armor{ dodge = NewDodgeChance },
- (Amount * ?ATTRIBUTE_DODGE_CHANCE_COST)
- }
- end.
+ increase_attribute_by(?ATTRIBUTE_DODGE_CHANCE, Amount, Armor).
-spec increase_movement_points_by
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_movement_points_by (Amount, Armor) ->
- NewMvtPoints = (Armor#proto_armor.mvt_points + Amount),
- case (NewMvtPoints > ?ATTRIBUTE_MOVEMENT_POINTS_MAX) of
- true ->
- {
- Armor#proto_armor{ mvt_points = ?ATTRIBUTE_MOVEMENT_POINTS_MAX },
- (
- (?ATTRIBUTE_MOVEMENT_POINTS_MAX - Armor#proto_armor.mvt_points)
- * ?ATTRIBUTE_MOVEMENT_POINTS_COST
- )
- };
-
- false ->
- {
- Armor#proto_armor{ mvt_points = NewMvtPoints },
- (Amount * ?ATTRIBUTE_MOVEMENT_POINTS_COST)
- }
- end.
+ increase_attribute_by(?ATTRIBUTE_MOVEMENT_POINTS, Amount, Armor).
-spec increase_defense_score_by
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
-increase_defense_score_by (Amount, Armor) ->
- NewDefenseScore = (Armor#proto_armor.defense_score + Amount),
- case (NewDefenseScore > ?ATTRIBUTE_DEFENSE_SCORE_MAX) of
- true ->
- {
- Armor#proto_armor
+ -> ({ok, type()} | blc_error:type()).
+increase_defense_score_by (S0Amount, Armor) ->
+ CurrentValue = Armor#proto_armor.defense_score,
+ S0NewValue = CurrentValue + S0Amount,
+ {S1Amount, S1NewValue} =
+ case (S0NewValue > ?ATTRIBUTE_DEFENSE_SCORE_MAX) of
+ false -> {S0Amount, S0NewValue};
+ true ->
{
- defense_score = ?ATTRIBUTE_DEFENSE_SCORE_MAX,
- defense =
- blc_damage_type:generate_entries_from_score
- (
- NewDefenseScore,
- Armor#proto_armor.defense_coef
- )
- },
- (
- (?ATTRIBUTE_DEFENSE_SCORE_MAX - Armor#proto_armor.defense_score)
- * Amount
- )
- };
+ (?ATTRIBUTE_DEFENSE_SCORE_MAX - CurrentValue),
+ ?ATTRIBUTE_DEFENSE_SCORE_MAX
+ }
+ end,
+
+ Cost = (S1Amount * ?ATTRIBUTE_DEFENSE_SCORE_COST),
+ RemainingPoints = Armor#proto_armor.remaining_points,
+ case (Cost > RemainingPoints) of
+ true -> {error, balance, RemainingPoints, Cost};
false ->
{
+ ok,
Armor#proto_armor
{
- defense_score = NewDefenseScore,
- defense =
- blc_damage_type:generate_entries_from_score
+ remaining_points = (RemainingPoints - Cost),
+ defense_score = S1NewValue,
+ omnimods =
+ shr_omnimods:set_defense_modifiers
(
- NewDefenseScore,
- Armor#proto_armor.defense_coef
+ blc_damage_type:generate_entries_from_score
+ (
+ S1NewValue,
+ Armor#proto_armor.defense_coef
+ ),
+ Armor#proto_armor.omnimods
)
- },
- (Amount * ?ATTRIBUTE_DEFENSE_SCORE_COST)
+ }
}
end.
-spec set_defense_coefficients
(
list(blc_damage_type:coefficient()),
- proto_armor()
+ type()
)
- -> proto_armor().
+ -> type().
set_defense_coefficients (Coefficients, Armor) ->
- {Result, 0} =
- increase_defense_score_by
- (
- 0,
- Armor#proto_armor
- {
- defense_coef = blc_damage_type:sort_entries(Coefficients)
- }
- ),
+ NewCoefs = blc_damage_type:sort_entries(Coefficients),
+
+ Armor#proto_armor
+ {
+ defense_coef = NewCoefs,
+ omnimods =
+ shr_omnimods:set_defense_modifiers
+ (
+ blc_damage_type:generate_entries_from_score
+ (
+ Armor#proto_armor.defense_score,
+ NewCoefs
+ ),
+ Armor#proto_armor.omnimods
+ )
+ }.
- Result.
--spec new (list(blc_damage_type:coefficient())) -> proto_armor().
+-spec new (list(blc_damage_type:coefficient())) -> type().
new (Coefficients) ->
- {Result, _DefenseScoreIncreaseCost} =
- increase_defense_score_by
- (
- ?ATTRIBUTE_DEFENSE_SCORE_MIN,
- #proto_armor
- {
- health = ?ATTRIBUTE_HEALTH_MIN,
- damage_modifier = ?ATTRIBUTE_DAMAGE_MODIFIER_MIN,
- dodge = ?ATTRIBUTE_DODGE_CHANCE_MIN,
- mvt_points = ?ATTRIBUTE_MOVEMENT_POINTS_MIN,
- defense = [],
- defense_coef = blc_damage_type:sort_entries(Coefficients),
- defense_score = 0
- }
- ),
+ SortedCoefficients = blc_damage_type:sort_entries(Coefficients),
+
+ #proto_armor
+ {
+ omnimods =
+ shr_omnimods:new
+ (
+ [
+ {?ATTRIBUTE_HEALTH, ?ATTRIBUTE_HEALTH_MIN},
+ {?ATTRIBUTE_DAMAGE_MODIFIER, ?ATTRIBUTE_DAMAGE_MODIFIER_MIN},
+ {?ATTRIBUTE_DODGE_CHANCE, ?ATTRIBUTE_DODGE_CHANCE_MIN},
+ {?ATTRIBUTE_MOVEMENT_POINTS, ?ATTRIBUTE_MOVEMENT_POINTS_MIN}
+ ],
+ [],
+ blc_damage_type:generate_entries_from_score
+ (
+ ?ATTRIBUTE_DEFENSE_SCORE_MIN,
+ SortedCoefficients
+ )
+ ),
- Result.
+ defense_coef = SortedCoefficients,
+ defense_score = ?ATTRIBUTE_DEFENSE_SCORE_MIN,
+ remaining_points = ?SPENDABLE_ARMOR_POINTS
+ }.
-spec increase_health_for
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_health_for (GivenPoints, Armor) ->
AmountOfIncrease = trunc(GivenPoints / ?ATTRIBUTE_HEALTH_COST),
- {Result, SpentPoints} = increase_health_by(AmountOfIncrease, Armor),
- {Result, (GivenPoints - SpentPoints)}.
+ increase_health_by(AmountOfIncrease, Armor).
-spec increase_damage_modifier_for
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_damage_modifier_for (GivenPoints, Armor) ->
AmountOfIncrease = trunc(GivenPoints / ?ATTRIBUTE_DAMAGE_MODIFIER_COST),
- {Result, SpentPoints} = increase_damage_modifier_by(AmountOfIncrease, Armor),
- {Result, (GivenPoints - SpentPoints)}.
+ increase_damage_modifier_by(AmountOfIncrease, Armor).
-spec increase_dodge_chance_for
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_dodge_chance_for (GivenPoints, Armor) ->
AmountOfIncrease = trunc(GivenPoints / ?ATTRIBUTE_DODGE_CHANCE_COST),
- {Result, SpentPoints} = increase_dodge_chance_by(AmountOfIncrease, Armor),
- {Result, (GivenPoints - SpentPoints)}.
+ increase_dodge_chance_by(AmountOfIncrease, Armor).
-spec increase_movement_points_for
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_movement_points_for (GivenPoints, Armor) ->
AmountOfIncrease = trunc(GivenPoints / ?ATTRIBUTE_MOVEMENT_POINTS_COST),
- {Result, SpentPoints} = increase_movement_points_by(AmountOfIncrease, Armor),
- {Result, (GivenPoints - SpentPoints)}.
+ increase_movement_points_by(AmountOfIncrease, Armor).
-spec increase_defense_score_for
(
non_neg_integer(),
- proto_armor()
+ type()
)
- -> {proto_armor(), non_neg_integer()}.
+ -> ({ok, type()} | blc_error:type()).
increase_defense_score_for (GivenPoints, Armor) ->
AmountOfIncrease = trunc(GivenPoints / ?ATTRIBUTE_DEFENSE_SCORE_COST),
- {Result, SpentPoints} = increase_defense_score_by(AmountOfIncrease, Armor),
- {Result, (GivenPoints - SpentPoints)}.
-
+ increase_defense_score_by(AmountOfIncrease, Armor).
--spec get_spendable_points () -> non_neg_integer().
-get_spendable_points () -> ?SPENDABLE_ARMOR_POINTS.
+-spec get_remaining_points (type()) -> non_neg_integer().
+get_remaining_points (Armor) -> Armor#proto_armor.remaining_points.