summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/struct/shr_armor.erl.m496
-rw-r--r--src/shared/struct/shr_omnimods.erl149
-rw-r--r--src/shared/struct/shr_weapon.erl.m4122
3 files changed, 161 insertions, 206 deletions
diff --git a/src/shared/struct/shr_armor.erl.m4 b/src/shared/struct/shr_armor.erl.m4
index 5db4b36..01d810a 100644
--- a/src/shared/struct/shr_armor.erl.m4
+++ b/src/shared/struct/shr_armor.erl.m4
@@ -5,23 +5,19 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-type id() :: non_neg_integer().
--type category() :: 'kinetic' | 'leather' | 'chain' | 'plate'.
-
-record
(
armor,
{
id :: id(),
name :: binary(),
- category :: category(),
- coef :: float()
+ omnimods :: shr_omnimods:type()
}
).
-opaque type() :: #armor{}.
-export_type([type/0, id/0]).
--export_type ([category/0]).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -32,8 +28,7 @@
[
get_id/1,
get_name/1,
- get_coefficient/1,
- get_category/1
+ get_omnimods/1
]
).
@@ -41,9 +36,7 @@
(
[
random_id/0,
- from_id/1,
- apply_to_attributes/2,
- get_resistance_to/2
+ from_id/1
]
).
@@ -62,11 +55,8 @@ get_id (Ar) -> Ar#armor.id.
-spec get_name (type()) -> binary().
get_name (Ar) -> Ar#armor.name.
--spec get_coefficient (type()) -> float().
-get_coefficient (Ar) -> Ar#armor.coef.
-
--spec get_category (type()) -> category().
-get_category (Ar) -> Ar#armor.category.
+-spec get_omnimods (type()) -> shr_omnimods:type().
+get_omnimods (Ar) -> Ar#armor.omnimods.
-spec from_id (id()) -> type().
m4_include(__MAKEFILE_DATA_DIR/armor/global.m4.conf)m4_dnl
@@ -76,79 +66,3 @@ from_id(_) ->
-spec random_id () -> id().
random_id () -> shr_roll:between(0, 4).
-
--spec apply_to_attributes
- (
- type(),
- shr_attributes:type()
- )
- -> shr_attributes:type().
-apply_to_attributes (Ar, Att) ->
- Constitution = shr_attributes:get_constitution(Att),
- Dexterity = shr_attributes:get_dexterity(Att),
- Speed = shr_attributes:get_speed(Att),
- Strength = shr_attributes:get_strength(Att),
- Mind = shr_attributes:get_mind(Att),
- Impact = shr_math_util:ceil(20.0 * Ar#armor.coef),
- HalfImpact = shr_math_util:ceil(10.0 * Ar#armor.coef),
- Category = Ar#armor.category,
-
- case Category of
- kinetic -> shr_attributes:set_unsafe_mind((Mind - Impact), Att);
- leather ->
- shr_attributes:set_unsafe_constitution
- (
- (Constitution - HalfImpact),
- shr_attributes:set_unsafe_dexterity((Dexterity - HalfImpact), Att)
- );
-
- chain ->
- shr_attributes:set_unsafe_constitution
- (
- (Constitution - HalfImpact),
- shr_attributes:set_unsafe_dexterity
- (
- (Dexterity - HalfImpact),
- shr_attributes:set_unsafe_speed((Speed - Impact), Att)
- )
- );
-
- plate ->
- shr_attributes:set_unsafe_constitution
- (
- (Constitution - HalfImpact),
- shr_attributes:set_unsafe_dexterity
- (
- (Dexterity - HalfImpact),
- shr_attributes:set_unsafe_speed
- (
- (Speed - Impact),
- shr_attributes:set_unsafe_strength((Strength - Impact), Att)
- )
- )
- )
- end.
-
--spec get_resistance_to (shr_weapon:damage_type(), type()) -> non_neg_integer().
-get_resistance_to (DamageType, Armor) ->
- ArmorCategory = Armor#armor.category,
- BaseResistance =
- case {DamageType, ArmorCategory} of
- {slash, kinetic} -> 0.0;
- {slash, leather} -> 20.0;
- {slash, chain} -> 30.0;
- {slash, plate} -> 30.0;
- {blunt, kinetic} -> 20.0;
- {blunt, leather} -> 20.0;
- {blunt, chain} -> 20.0;
- {blunt, plate} -> 20.0;
- {pierce, kinetic} -> 20.0;
- {pierce, leather} -> 20.0;
- {pierce, chain} -> 20.0;
- {pierce, plate} -> 30.0
- end,
-
- ArmorCoefficient = Armor#armor.coef,
- ActualResistance = (ArmorCoefficient * BaseResistance),
-
- shr_math_util:ceil(ActualResistance).
diff --git a/src/shared/struct/shr_omnimods.erl b/src/shared/struct/shr_omnimods.erl
index b87f2cd..2d06493 100644
--- a/src/shared/struct/shr_omnimods.erl
+++ b/src/shared/struct/shr_omnimods.erl
@@ -4,15 +4,16 @@
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-type entry() :: {atom(), integer()}.
+-type mods() :: dict:dict(atom(), integer()).
-record
(
omnimods,
{
- attmods = list(entry()),
- stamods = list(entry()),
- atkmods = list(entry()),
- defmods = list(entry())
+ attmods :: mods(),
+ stamods :: mods(),
+ atkmods :: mods(),
+ defmods :: mods()
}
).
@@ -26,7 +27,8 @@
-export
(
[
- new/4
+ new/4,
+ new_dirty/4
]
).
@@ -34,14 +36,149 @@
-export
(
[
+ merge/2,
+ apply_coefficient/2
+ ]
+).
+
+-export
+(
+ [
+ apply_to_attributes/3,
+ apply_to_statistics/3,
+ get_attack_damage/3
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec cleanup_entry_list (list(entry())) -> list(entry()).
+cleanup_entry_list (ModList) ->
+ [First|Rem] = ModList,
+ case First of
+ {none, _} -> Rem;
+ _ -> ModList
+ end.
+
+-spec apply_coefficient_to_mods (float(), mods()) -> mods().
+apply_coefficient_to_mods (Coef, Mods) ->
+ dict:map(fun ({_Name, Val}) -> shr_util:ceil(Coef * Val) end, Mods).
+
+-spec merge_mods (mods(), mods()) -> mods().
+merge_mods (ModsA, ModsB) ->
+ dict:merge(fun (_Name, ValA, ValB) -> (ValA + ValB) end, ModsA, ModsB).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%
+%%% Creation
+-spec new
+(
+ list(entry()),
+ list(entry()),
+ list(entry()),
+ list(entry())
+ )
+ -> type().
+new (AttributeMods, StatisticMods, AttackMods, DefenseMods) ->
+ #omnimods
+ {
+ attmods = dict:from_list(AttributeMods),
+ stamods = dict:from_list(StatisticMods),
+ atkmods = dict:from_list(AttackMods),
+ defmods = dict:from_list(DefenseMods)
+ }.
+
+-spec new_dirty
+(
+ list(entry()),
+ list(entry()),
+ list(entry()),
+ list(entry())
+ )
+ -> type().
+new_dirty(AttributeMods, StatisticMods, AttackMods, DefenseMods) ->
+ new
+ (
+ cleanup_entry_list(AttributeMods),
+ cleanup_entry_list(StatisticMods),
+ cleanup_entry_list(AttackMods),
+ cleanup_entry_list(DefenseMods)
+ ).
+
+%%% Modification
+-spec merge (type(), type()) -> type().
+merge (OmniA, OmniB) ->
+ OmniA#omnimods
+ {
+ attmods = merge_mods(OmniA#omnimods.attmods, OmniB#omnimods.attmods),
+ stamods = merge_mods(OmniA#omnimods.stamods, OmniB#omnimods.stamods),
+ atkmods = merge_mods(OmniA#omnimods.atkmods, OmniB#omnimods.atkmods),
+ defmods = merge_mods(OmniA#omnimods.defmods, OmniB#omnimods.defmods)
+ }.
+
+-spec apply_coefficient (float(), type()) -> type().
+apply_coefficient (Coef, Omnimods) ->
+ Omnimods#omnimods
+ {
+ attmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.attmods),
+ stamods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.stamods),
+ atkmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.atkmods),
+ defmods = apply_coefficient_to_mods(Coef, Omnimods#omnimods.defmods)
+ }.
+
+%%% Application
+-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) ->
+ dict:fold
+ (
+ UpdateFun,
+ 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) ->
+ dict:fold
+ (
+ UpdateFun,
+ Statistics,
+ Omnimods#omnimods.attmods
+ ).
+
+-spec get_attack_damage (float(), type(), type()) -> non_neg_integer().
+get_attack_damage (AttackModifier, AttackerOmnimods, DefenderOmnimods) ->
+ AttackerOmnimodsAttmods = AttackerOmnimods#omnimods.atkmods,
+ DefenderOmnimodsDefmods = DefenderOmnimods#omnimods.defmods,
+
+ S0Calc =
+ apply_coefficient_to_mods(-1*AttackModifier, AttackerOmnimodsAttmods),
+ S1Calc = merge_mods(DefenderOmnimodsDefmods, S0Calc),
+
+ Result =
+ dict:fold
+ (
+ fun (_Name, Val, CurrResult) ->
+ case (Val > 0) of
+ true -> (CurrResult + Val);
+ _ -> CurrResult
+ end
+ end,
+ 0,
+ S1Calc
+ ),
+
+ Result.
diff --git a/src/shared/struct/shr_weapon.erl.m4 b/src/shared/struct/shr_weapon.erl.m4
index 862edb6..55c2815 100644
--- a/src/shared/struct/shr_weapon.erl.m4
+++ b/src/shared/struct/shr_weapon.erl.m4
@@ -5,37 +5,21 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-type id() :: non_neg_integer().
--type range_type() :: 'ranged' | 'melee'.
--type range_modifier() :: 'long' | 'short'.
--type damage_type() :: 'slash' | 'pierce' | 'blunt'.
--type damage_modifier() :: 'heavy' | 'light'.
-
-record
(
weapon,
{
id :: id(),
name :: binary(),
- range_type :: range_type(),
- range_mod :: range_modifier(),
- damage_type :: damage_type(),
- damage_mod :: damage_modifier(),
- coef :: float()
+ range_min:: non_neg_integer(),
+ range_max :: non_neg_integer(),
+ omnimods :: shr_omnimods:type()
}
).
-opaque type() :: #weapon{}.
-export_type([type/0, id/0]).
--export_type
-(
- [
- range_type/0,
- range_modifier/0,
- damage_type/0,
- damage_modifier/0
- ]
-).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -46,13 +30,9 @@
[
get_id/1,
get_name/1,
- get_range_type/1,
- get_range_modifier/1,
- get_damage_type/1,
- get_damage_modifier/1,
- get_coefficient/1,
- get_ranges/1,
- get_damages/1
+ get_minimum_range/1,
+ get_maximum_range/1,
+ get_omnimods/1
]
).
@@ -60,36 +40,13 @@
(
[
random_id/0,
- from_id/1,
- can_parry/1,
- apply_to_attributes/2
+ from_id/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec ranges_of_type
- (
- range_type(),
- range_modifier()
- )
- -> {non_neg_integer(), non_neg_integer()}.
-ranges_of_type (ranged, long) -> {2, 6};
-ranges_of_type (ranged, short) -> {1, 4};
-ranges_of_type (melee, long) -> {0, 2};
-ranges_of_type (melee, short) -> {0, 1}.
-
--spec damages_of_type
- (
- range_type(),
- damage_modifier()
- )
- -> {non_neg_integer(), non_neg_integer()}.
-damages_of_type (ranged, heavy) -> {15, 30};
-damages_of_type (ranged, light) -> {10, 25};
-damages_of_type (melee, heavy) -> {20, 35};
-damages_of_type (melee, light) -> {15, 30}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -101,33 +58,14 @@ get_id (Wp) -> Wp#weapon.id.
-spec get_name (type()) -> binary().
get_name (Wp) -> Wp#weapon.name.
--spec get_range_type (type()) -> range_type().
-get_range_type (Wp) -> Wp#weapon.range_type.
-
--spec get_range_modifier (type()) -> range_modifier().
-get_range_modifier (Wp) -> Wp#weapon.range_mod.
-
--spec get_damage_type (type()) -> damage_type().
-get_damage_type (Wp) -> Wp#weapon.damage_type.
-
--spec get_damage_modifier (type()) -> damage_modifier().
-get_damage_modifier (Wp) -> Wp#weapon.damage_mod.
+-spec get_minimum_range (type()) -> non_neg_integer().
+get_minimum_range (Wp) -> Wp#weapon.range_min.
--spec get_coefficient (type()) -> float().
-get_coefficient (Wp) -> Wp#weapon.coef.
+-spec get_maximum_range (type()) -> non_neg_integer().
+get_maximum_range (Wp) -> Wp#weapon.range_max.
--spec get_ranges (type()) -> {non_neg_integer(), non_neg_integer()}.
-get_ranges (Wp) ->
- ranges_of_type(Wp#weapon.range_type, Wp#weapon.range_mod).
-
--spec get_damages (type()) -> {non_neg_integer(), non_neg_integer()}.
-get_damages (Wp) ->
- Coef = Wp#weapon.coef,
- {Min, Max} = damages_of_type(Wp#weapon.range_type, Wp#weapon.damage_mod),
- {shr_math_util:ceil(Min * Coef), shr_math_util:ceil(Max * Coef)}.
-
--spec can_parry (type()) -> boolean().
-can_parry (Wp) -> (Wp#weapon.range_type == melee).
+-spec get_omnimods (type()) -> shr_omnimods:type().
+get_omnimods (Wp) -> Wp#weapon.omnimods.
-spec from_id (id()) -> type().
m4_include(__MAKEFILE_DATA_DIR/weapon/global.m4.conf)m4_dnl
@@ -135,39 +73,5 @@ m4_include(__MAKEFILE_DATA_DIR/weapon/basic.m4d)m4_dnl
from_id (_) ->
from_id(0).
-
-spec random_id () -> id().
random_id () -> shr_roll:between(0, 24).
-
--spec apply_to_attributes
- (
- type(),
- shr_attributes:type()
- )
- -> shr_attributes:type().
-apply_to_attributes (Weapon, Attributes) ->
- Dexterity = shr_attributes:get_dexterity(Attributes),
- Speed = shr_attributes:get_speed(Attributes),
- RangeModifier = Weapon#weapon.range_mod,
- DamageModifier = Weapon#weapon.damage_mod,
-
- Impact = (20.0 * Weapon#weapon.coef),
- FullImpact = shr_math_util:ceil(Impact),
- QuarterImpact = shr_math_util:ceil(Impact / 4.0),
-
- ResultingDexterity =
- case RangeModifier of
- long -> (Dexterity - FullImpact);
- short -> (Dexterity - QuarterImpact)
- end,
- ResultingSpeed =
- case DamageModifier of
- heavy -> (Speed - FullImpact);
- light -> (Speed - QuarterImpact)
- end,
-
- S0Attributes = shr_attributes:set_unsafe_speed(ResultingSpeed, Attributes),
- S1Attributes =
- shr_attributes:set_unsafe_dexterity(ResultingDexterity, S0Attributes),
-
- S1Attributes.