summaryrefslogtreecommitdiff |
diff options
author | nsensfel <SpamShield0@noot-noot.org> | 2018-08-29 16:24:10 +0200 |
---|---|---|
committer | nsensfel <SpamShield0@noot-noot.org> | 2018-08-29 16:24:10 +0200 |
commit | 9ffa08c3aad8e4f40b7f7d1e7845e5153f9c34ab (patch) | |
tree | 363619618b680e59ab76efa8e7db92bc57ca784a /src/battle/struct | |
parent | 79b2d1dd4f114bc31105df0e554f9c1f18c87e5d (diff) |
Still working on it...
Diffstat (limited to 'src/battle/struct')
-rw-r--r-- | src/battle/struct/btl_attack.erl | 101 | ||||
-rw-r--r-- | src/battle/struct/btl_character_current_data.erl | 113 | ||||
-rw-r--r-- | src/battle/struct/btl_character_turn_data.erl | 24 |
3 files changed, 184 insertions, 54 deletions
diff --git a/src/battle/struct/btl_attack.erl b/src/battle/struct/btl_attack.erl index 04302b3..2411529 100644 --- a/src/battle/struct/btl_attack.erl +++ b/src/battle/struct/btl_attack.erl @@ -30,7 +30,7 @@ ( [ get_sequence/3, - get_description_of/5, + get_description_of/3, apply_to_healths/3 ] ). @@ -71,34 +71,15 @@ roll_parry (DefenderStatistics) -> DefenderParryChance = shr_statistics:get_parries(DefenderStatistics), (shr_roll:percentage() =< DefenderParryChance). --spec effect_of_attack +-spec get_damage ( - order(), - shr_statistics:type(), + precision(), + boolean(), shr_omnimods:type(), - shr_statistics:type(), - shr_omnimods:type(), - boolean() + shr_omnimods:type() ) - -> type(). -effect_of_attack (Order, AtkStats, AtkOmni, DefStats, DefOmni, CanParry) -> - ParryIsSuccessful = (CanParry and roll_parry(DefStats)), - - {ActualAtkStats, ActualDefStats} = - case ParryIsSuccessful of - true -> {DefStats, AtkStats}; - false -> {AtkStats, DefStats} - end, - - {ActualAtkOmni, ActualDefOmni} = - case ParryIsSuccessful of - true -> {DefOmni, AtkOmni}; - false -> {AtkOmni, DefOmni} - end, - - Precision = roll_precision(ActualAtkStats, ActualDefStats), - IsCritical = roll_critical_hit(ActualAtkStats), - + -> non_neg_integer(). +get_damage (Precision, IsCritical, ActualAtkOmni, ActualDefOmni) -> S0DamageMultiplier = case Precision of misses -> 0; @@ -109,7 +90,7 @@ effect_of_attack (Order, AtkStats, AtkOmni, DefStats, DefOmni, CanParry) -> S1DamageMultiplier = case IsCritical of true -> (S0DamageMultiplier * 2); - false -> S0DamageMultiplier + _ -> S0DamageMultiplier end, ActualDamage = @@ -120,13 +101,43 @@ effect_of_attack (Order, AtkStats, AtkOmni, DefStats, DefOmni, CanParry) -> ActualDefOmni ), + ActualDamage. + +-spec effect_of_attack + ( + order(), + btl_character_current_data:type(), + btl_character_current_data:type(), + boolean() + ) + -> type(). +effect_of_attack (Order, AtkCurrData, DefCurrData, CanParry) -> + DefStats = btl_character_current_data:get_statistics(DefCurrData), + + ParryIsSuccessful = (CanParry and roll_parry(DefStats)), + + {ActualAtkData, ActualDefData} = + case ParryIsSuccessful of + true -> {DefCurrData, AtkCurrData}; + false -> {AtkCurrData, DefCurrData} + end, + + ActualAtkStats = btl_character_current_data:get_statistics(ActualAtkData), + ActualAtkOmni = btl_character_current_data:get_omnimods(ActualAtkData), + ActualDefStats = btl_character_current_data:get_statistics(ActualDefData), + ActualDefOmni = btl_character_current_data:get_omnimods(ActualDefData), + + Precision = roll_precision(ActualAtkStats, ActualDefStats), + IsCritical = roll_critical_hit(ActualAtkStats), + Damage = get_damage(Precision, IsCritical, ActualAtkOmni, ActualDefOmni), + #attack { order = Order, precision = Precision, is_critical = IsCritical, is_parry = ParryIsSuccessful, - damage = ActualDamage + damage = Damage }. -spec encode_order (order()) -> binary(). @@ -146,42 +157,26 @@ encode_precision (misses) -> <<"m">>. -spec get_description_of ( step(), - shr_statistics:type(), - shr_omnimods:type(), - shr_statistics:type(), - shr_omnimods:type() + btl_character_current_data:type(), + btl_character_current_data:type() ) -> maybe_type(). -get_description_of ({first, CanParry}, AtkStats, AtkOmni, DefStats, DefOmni) -> - effect_of_attack(first, AtkStats, AtkOmni, DefStats, DefOmni, CanParry); -get_description_of ({second, CanParry}, AtkStats, AtkOmni, DefStats, DefOmni) -> +get_description_of ({first, CanParry}, AtkCurrData, DefCurrData) -> + effect_of_attack(first, AtkCurrData, DefCurrData, CanParry); +get_description_of ({second, CanParry}, AtkCurrData, DefCurrData) -> + AtkStats = btl_character_current_data:get_statistics(AtkCurrData), AttackerDoubleAttackChange = shr_statistics:get_double_hits(AtkStats), case shr_roll:percentage() of X when (X =< AttackerDoubleAttackChange) -> - effect_of_attack - ( - second, - AtkStats, - AtkOmni, - DefStats, - DefOmni, - CanParry - ); + effect_of_attack(second, AtkCurrData, DefCurrData, CanParry); _ -> nothing end; -get_description_of -( - {counter, CanParry}, - AtkStats, - AtkOmni, - DefStats, - DefOmni -) -> - effect_of_attack(counter, DefStats, DefOmni, AtkStats, AtkOmni, CanParry). +get_description_of ({counter, CanParry}, AtkCurrData, DefCurrData) -> + effect_of_attack(counter, DefCurrData, AtkCurrData, CanParry). -spec apply_to_healths ( diff --git a/src/battle/struct/btl_character_current_data.erl b/src/battle/struct/btl_character_current_data.erl new file mode 100644 index 0000000..60bfdbc --- /dev/null +++ b/src/battle/struct/btl_character_current_data.erl @@ -0,0 +1,113 @@ +-module(btl_character_current_data). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-record +( + character_current_data, + { + attributes :: shr_attributes:type(), + statistics :: shr_statistics:type(), + omnimods :: shr_omnimods:type() + } +). + +-opaque type() :: #character_current_data{}. + +-export_type([type/0]). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-export +( + [ + get_attributes/1, + get_statistics/1, + get_omnimods/1 + ] +). + +-export +( + [ + new/2 + ] +). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec location_to_omnimods + ( + {non_neg_integer(), non_neg_integer()}, + btl_map:type() + ) + -> shr_omnimods:type(). +location_to_omnimods (Location, Map) -> + TileInstance = btl_map:get_tile_instance(Location, Map), + TileClassID = shr_tile:extract_main_class_id(TileInstance), + Tile = shr_tile:from_class_id(TileClassID), + + shr_tile:get_omnimods(Tile). + +-spec weapon_id_to_omnimods (shr_weapon:id()) -> shr_omnimods:type(). +weapon_id_to_omnimods (WeaponID) -> + Weapon = shr_weapon:from_id(WeaponID), + + shr_weapon:get_omnimods(Weapon). + +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +%%%% Accessors +-spec get_omnimods (type()) -> shr_omnimods:type(). +get_omnimods (Char) -> Char#character_current_data.omnimods. + +-spec get_attributes (type()) -> shr_attributes:type(). +get_attributes (Char) -> Char#character_current_data.attributes. + +-spec get_statistics (type()) -> shr_statistics:type(). +get_statistics (Char) -> Char#character_current_data.statistics. + +%%%% Utils +-spec new (btl_character:type(), btl_map:type()) -> type(). +new (Character, Map) -> + PermanentOmnimods = btl_character:get_permanent_omnimods(Character), + + {WeaponID, _} = btl_character:get_weapon_ids(Character), + WeaponOmnimods = weapon_id_to_omnimods(WeaponID), + + Location = btl_character:get_location(Character), + TileOmnimods = location_to_omnimods(Location, Map), + + CurrentOmnimods = + shr_omnimods:merge + ( + shr_omnimods:merge(WeaponOmnimods, TileOmnimods), + PermanentOmnimods + ), + + CurrentAttributes = + shr_omnimods:apply_to_attributes + ( + CurrentOmnimods, + shr_attributes:default() + ), + + CurrentStatistics = + shr_omnimods:apply_to_statistics + ( + CurrentOmnimods, + shr_statistics:new_raw(CurrentAttributes) + ), + + #character_current_data + { + attributes = CurrentAttributes, + statistics = CurrentStatistics, + omnimods = CurrentOmnimods + }. + diff --git a/src/battle/struct/btl_character_turn_data.erl b/src/battle/struct/btl_character_turn_data.erl index 64df29f..6742d1c 100644 --- a/src/battle/struct/btl_character_turn_data.erl +++ b/src/battle/struct/btl_character_turn_data.erl @@ -10,6 +10,7 @@ dirty :: boolean(), battle :: btl_battle:type(), character :: btl_character:type(), + character_current_data :: btl_character_current_data:type(), character_ix :: non_neg_integer() } ). @@ -29,10 +30,12 @@ get_battle_is_dirty/1, get_battle/1, get_character/1, + get_character_current_data/1, get_character_ix/1, set_battle/2, - set_character/2 + set_character/2, + refresh_character_current_data/1 ] ). @@ -54,12 +57,15 @@ -spec new (btl_battle:type(), non_neg_integer()) -> type(). new (Battle, CharacterIX) -> Character = btl_battle:get_character(CharacterIX, Battle), + Map = btl_battle:get_map(Battle), + CharacterCurrentData = btl_character_current_data:new(Character, Map), #type { dirty = false, battle = Battle, character = Character, + character_current_data = CharacterCurrentData, character_ix = CharacterIX }. @@ -72,6 +78,9 @@ get_battle (Data) -> Data#type.battle. -spec get_character (type()) -> btl_character:type(). get_character (Data) -> Data#type.character. +-spec get_character_current_data (type()) -> btl_character_current_data:type(). +get_character_current_data (Data) -> Data#type.character_current_data. + -spec get_character_ix (type()) -> non_neg_integer(). get_character_ix (Data) -> Data#type.character_ix. @@ -87,6 +96,19 @@ set_character (Character, Data) -> character = Character }. +-spec refresh_character_current_data (type()) -> type(). +refresh_character_current_data (Data) -> + Battle = Data#type.battle, + Character = Data#type.character, + Map = btl_battle:get_map(Battle), + CharacterCurrentData = btl_character_current_data:new(Character, Map), + + Data#type + { + character_current_data = CharacterCurrentData + }. + + -spec clean_battle (type()) -> type(). clean_battle (Data) -> Data#type |