From 921db62f5055b8b77ae1d8c677e43f11371d90c4 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Mon, 19 Aug 2019 23:19:44 +0200 Subject: ... --- src/balancer/blc_damage_type.erl | 25 +++++-- src/balancer/blc_distribution.erl | 10 ++- src/balancer/struct/blc_armor.erl | 97 ++++++++++++++++++++++++++-- src/shared/struct/inventory/shr_armor.erl.m4 | 2 +- src/shared/struct/shr_omnimods.erl | 29 ++++++++- 5 files changed, 148 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/balancer/blc_damage_type.erl b/src/balancer/blc_damage_type.erl index 340b4ff..feac276 100644 --- a/src/balancer/blc_damage_type.erl +++ b/src/balancer/blc_damage_type.erl @@ -99,7 +99,11 @@ generate_entries_from_score (TargetScore, SortedRatios) -> SortedRatios ), - Base = (TargetScore / (Distribution / 100)), + Base = + case Distribution of + 0 -> 0; + _ -> (TargetScore / (Distribution / 100)) + end, UnderperformingEntries = lists:map @@ -110,8 +114,19 @@ generate_entries_from_score (TargetScore, SortedRatios) -> MissingScore = (TargetScore - compute_score(UnderperformingEntries)), - case (MissingScore >= 0) of - true -> apply_score_modifier(MissingScore, 1, UnderperformingEntries); - false -> - apply_score_modifier((-1 * MissingScore), -1, UnderperformingEntries) + case Base of + 0 -> []; + _ -> + case (MissingScore >= 0) of + true -> + apply_score_modifier(MissingScore, 1, UnderperformingEntries); + + false -> + apply_score_modifier + ( + (-1 * MissingScore), + -1, + UnderperformingEntries + ) + end end. diff --git a/src/balancer/blc_distribution.erl b/src/balancer/blc_distribution.erl index 2e8a141..a305dd4 100644 --- a/src/balancer/blc_distribution.erl +++ b/src/balancer/blc_distribution.erl @@ -10,7 +10,8 @@ -export ( [ - generate/2 + generate/2, + generate/3 ] ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -50,7 +51,12 @@ generate_internals (N, CurrentResult, Sequence) -> -spec generate (non_neg_integer(), 0..100) -> list(list(0..100)). generate (0, _Step) -> []; generate (Elements, Step) -> - Sequence = lists:seq(0, 100, Step), + generate(Elements, 0, Step). + +-spec generate (non_neg_integer(), 0..100, 0..100) -> list(list(0..100)). +generate (0, _Min, _Step) -> []; +generate (Elements, Min, Step) -> + Sequence = lists:seq(Min, 100, Step), generate_internals ( (Elements - 1), diff --git a/src/balancer/struct/blc_armor.erl b/src/balancer/struct/blc_armor.erl index 0c642e1..4d94a88 100644 --- a/src/balancer/struct/blc_armor.erl +++ b/src/balancer/struct/blc_armor.erl @@ -77,7 +77,9 @@ [ new/1, get_remaining_points/1, - generate/1 + generate/3, + finalize/1, + export/1 ] ). @@ -327,15 +329,15 @@ increase_defense_score_for (GivenPoints, Armor) -> -spec get_remaining_points (type()) -> non_neg_integer(). get_remaining_points (Armor) -> Armor#proto_armor.remaining_points. --spec generate (non_neg_integer()) -> list(type()). -generate (Step) -> +-spec generate (0..100, 0..100, 0..100) -> list(type()). +generate (AttributeMin, AttributeStep, ElementStep) -> MaxDamageModifier = get_max_attribute_ratio(?ATTRIBUTE_DAMAGE_MODIFIER), MaxDodgeChance = get_max_attribute_ratio(?ATTRIBUTE_DODGE_CHANCE), MaxMovementPoints = get_max_attribute_ratio(?ATTRIBUTE_MOVEMENT_POINTS), MaxHealth = get_max_attribute_ratio(?ATTRIBUTE_HEALTH), MaxDefenseScore = get_max_attribute_ratio(?ATTRIBUTE_DEFENSE_SCORE), - Distributions = blc_distribution:generate(5, Step), + Distributions = blc_distribution:generate(5, AttributeMin, AttributeStep), ValidDistributions = lists:filtermap ( @@ -439,9 +441,92 @@ generate (Step) -> PointsUsed ), - FinalArmor + lists:foldl + ( + fun ({Attribute, _}, Armor) -> + NewArmor = + case Attribute of + ?ATTRIBUTE_DEFENSE_SCORE -> + increase_defense_score_for + ( + Armor#proto_armor.remaining_points, + Armor + ); + + _ -> increase_attribute_by(Attribute, 1, Armor) + end, + + case NewArmor of + {ok, NextArmor} -> NextArmor; + _ -> Armor + end + end, + FinalArmor, + lists:sort + ( + fun ({_AttributeA, ScoreA}, {_AttributeB, ScoreB}) -> + (ScoreA > ScoreB) + end, + lists:map + ( + fun (Attribute) -> + case Attribute of + ?ATTRIBUTE_DEFENSE_SCORE -> + { + ?ATTRIBUTE_DEFENSE_SCORE, + FinalArmor#proto_armor.defense_score + }; + + _ -> + { + Attribute, + shr_omnimods:get_attribute_modifier + ( + Attribute, + FinalArmor#proto_armor.omnimods + ) + } + end + end, + [ + ?ATTRIBUTE_DEFENSE_SCORE, + ?ATTRIBUTE_DODGE_CHANCE, + ?ATTRIBUTE_HEALTH, + ?ATTRIBUTE_DAMAGE_MODIFIER, + ?ATTRIBUTE_MOVEMENT_POINTS + ] + ) + ) + ) end, ValidDistributions ), - BaseArmors. + shr_lists_util:product + ( + fun (Armor, ElementDistribution) -> + set_defense_coefficients(ElementDistribution, Armor) + end, + BaseArmors, + lists:map + ( + fun ([A, B, C]) -> + [ + {?DAMAGE_TYPE_SLASH, A}, + {?DAMAGE_TYPE_PIERCE, B}, + {?DAMAGE_TYPE_BLUNT, C} + ] + end, + blc_distribution:generate(3, ElementStep) + ) + ). + +-spec export (type()) -> list(). +export (Armor) -> shr_omnimods:export(Armor#proto_armor.omnimods). + +-spec finalize (type()) -> {shr_omnimods:type(), non_neg_integer()}. +finalize (Armor) -> + { + Armor#proto_armor.omnimods, + Armor#proto_armor.remaining_points + }. diff --git a/src/shared/struct/inventory/shr_armor.erl.m4 b/src/shared/struct/inventory/shr_armor.erl.m4 index 0594577..bdcd249 100644 --- a/src/shared/struct/inventory/shr_armor.erl.m4 +++ b/src/shared/struct/inventory/shr_armor.erl.m4 @@ -61,7 +61,7 @@ get_omnimods (Ar) -> Ar#armor.omnimods. -spec from_id (id()) -> type(). m4_include(__MAKEFILE_DATA_DIR/armor/global.m4.conf)m4_dnl -m4_include(__MAKEFILE_DATA_DIR/armor/basic.m4d)m4_dnl +m4_include(__MAKEFILE_DATA_DIR/armor/20_20_20.m4d)m4_dnl from_id(_) -> default(). diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl index ae8ba44..f452e34 100644 --- a/src/shared/struct/shr_omnimods.erl +++ b/src/shared/struct/shr_omnimods.erl @@ -80,7 +80,8 @@ -export ( [ - encode/1 + encode/1, + export/1 ] ). @@ -114,6 +115,22 @@ encode_mods (Mods) -> dict:to_list(Mods) ). +-spec mod_list_to_string_list (mods()) -> list(). +mod_list_to_string_list (Mods) -> + ( + "__MOD_LIST(" + ++ + lists:map + ( + fun ({Name, Value}) -> + io_lib:format("__MOD_~p(~p),", [Name, Value]) + end, + Mods + ) + ++ + ")" + ). + %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -351,3 +368,13 @@ encode (Omnimods) -> {<<"defm">>, encode_mods(Omnimods#omnimods.defmods)} ] }. + +-spec export (type()) -> list(). +export (Omnimods) -> + ( + mod_list_to_string_list(dict:to_list(Omnimods#omnimods.attmods)) + ++ "\n" + ++ mod_list_to_string_list(dict:to_list(Omnimods#omnimods.atkmods)) + ++ "\n" + ++ mod_list_to_string_list(dict:to_list(Omnimods#omnimods.defmods)) + ). -- cgit v1.2.3-70-g09d2