| summaryrefslogtreecommitdiff | 
diff options
| author | nsensfel <SpamShield0@noot-noot.org> | 2019-01-29 17:24:26 +0100 | 
|---|---|---|
| committer | nsensfel <SpamShield0@noot-noot.org> | 2019-01-29 17:24:26 +0100 | 
| commit | e7f43fd8b82ec6fdd118557e5c87ab0697e179a1 (patch) | |
| tree | 38316e96a9f4c26dfbdddfd03b204b9320d609f4 /src | |
| parent | c116cb57903333bec870d50df180fbcb624f21ff (diff) | |
Changes the luck mechanism.
It's fairer than the previous version, but there's no way to recover if
all characters' actions are set to 0% chance due to their luck. Maybe
use (ActorLuck - TargetLuck) instead?
Diffstat (limited to 'src')
| -rw-r--r-- | src/battle/mechanic/turn_action/btl_turn_actions_attack.erl | 1 | ||||
| -rw-r--r-- | src/battle/struct/btl_attack.erl | 63 | ||||
| -rw-r--r-- | src/shared/shr_roll.erl | 98 | 
3 files changed, 64 insertions, 98 deletions
| diff --git a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl index 150d7b5..d4dc818 100644 --- a/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl +++ b/src/battle/mechanic/turn_action/btl_turn_actions_attack.erl @@ -180,7 +180,6 @@ handle (BattleAction, Update) ->           []        ), -   % TODO: update lucks...     NextAttackingPlayer = btl_player:set_luck(NewAttackerLuck, AttackingPlayer),     NextDefendingPlayer = btl_player:set_luck(NewDefenderLuck, DefendingPlayer), diff --git a/src/battle/struct/btl_attack.erl b/src/battle/struct/btl_attack.erl index 769f3e3..72e7b98 100644 --- a/src/battle/struct/btl_attack.erl +++ b/src/battle/struct/btl_attack.erl @@ -49,7 +49,6 @@     (        shr_statistics:type(),        shr_statistics:type(), -      integer(),        integer()     )     -> {precision(), integer(), integer()}. @@ -57,20 +56,14 @@ roll_precision  (     AttackerStatistics,     DefenderStatistics, -   AttackerLuck,     DefenderLuck  ) ->     DefenderDodges = shr_statistics:get_dodges(DefenderStatistics),     AttackerAccuracy = shr_statistics:get_accuracy(AttackerStatistics),     MissChance = max(0, (DefenderDodges - AttackerAccuracy)), -   {Roll, _IsSuccess, NewDefenderLuck, NewAttackerLuck} = -      shr_roll:conflict_with_luck -      ( -         MissChance, -         DefenderLuck, -         AttackerLuck -      ), +   {Roll, _IsSuccess, PositiveModifier, NegativeModifier} = +      shr_roll:percentage_with_luck(MissChance, DefenderLuck),     {        case Roll of @@ -78,8 +71,8 @@ roll_precision           X when (X =< (MissChance * 2)) -> grazes;           _ -> hits        end, -      NewAttackerLuck, -      NewDefenderLuck +      PositiveModifier, +      NegativeModifier     }.  -spec roll_critical_hit @@ -87,26 +80,26 @@ roll_precision        shr_statistics:type(),        integer()     ) -   -> {boolean(), integer()}. +   -> {boolean(), integer(), integer()}.  roll_critical_hit (AttackerStatistics, AttackerLuck) ->     CriticalHitChance = shr_statistics:get_critical_hits(AttackerStatistics), -   {_Roll, IsSuccess, NewLuck} = +   {_Roll, IsSuccess, PositiveModifier, NegativeModifier} =        shr_roll:percentage_with_luck(CriticalHitChance, AttackerLuck), -   {IsSuccess, NewLuck}. +   {IsSuccess, PositiveModifier, NegativeModifier}.  -spec roll_parry     (        shr_statistics:type(),        integer()     ) -   -> {boolean(), integer()}. +   -> {boolean(), integer(), integer()}.  roll_parry (DefenderStatistics, DefenderLuck) ->     DefenderParryChance = shr_statistics:get_parries(DefenderStatistics), -   {_Roll, IsSuccess, NewLuck} = +   {_Roll, IsSuccess, PositiveModifier, NegativeModifier} =        shr_roll:percentage_with_luck(DefenderParryChance, DefenderLuck), -   {IsSuccess, NewLuck}. +   {IsSuccess, PositiveModifier, NegativeModifier}.  -spec get_damage     ( @@ -164,12 +157,15 @@ effect_of_attack  ) ->     DefStats = btl_character_current_data:get_statistics(DefCurrData), -   {ParryIsSuccessful, S0DefLuck} = +   {ParryIsSuccessful, PositiveModifier, NegativeModifier} =        case CanParry of           true -> roll_parry(DefStats, DefenderLuck); -         false -> {false, DefenderLuck} +         false -> {false, 0}        end, +   S0DefenderLuck = (DefenderLuck + PositiveModifier), +   S0AttackerLuck = (AttackerLuck + NegativeModifier), +     {        ActualAtkData,        ActualDefData, @@ -177,8 +173,8 @@ effect_of_attack        ActualDefLuck     } =        case ParryIsSuccessful of -         true -> {DefCurrData, AtkCurrData, S0DefLuck, AttackerLuck}; -         false -> {AtkCurrData, DefCurrData, AttackerLuck, S0DefLuck} +         true -> {DefCurrData, AtkCurrData, S0DefenderLuck, S0AttackerLuck}; +         false -> {AtkCurrData, DefCurrData, S0AttackerLuck, S0DefenderLuck}        end,     ActualAtkStats = btl_character_current_data:get_statistics(ActualAtkData), @@ -186,18 +182,24 @@ effect_of_attack     ActualDefStats = btl_character_current_data:get_statistics(ActualDefData),     ActualDefOmni = btl_character_current_data:get_omnimods(ActualDefData), -   {Precision, S0ActualAtkLuck, S0ActualDefLuck} = +   {Precision, S0PositiveModifier, S0NegativeModifier} =        roll_precision        (           ActualAtkStats,           ActualDefStats, -         ActualAtkLuck,           ActualDefLuck        ), -   {IsCritical, S1ActualAtkLuck} = +   % Precision roll is actually the defender attempting to evade. +   S0ActualDefLuck = (ActualDefLuck + S0PositiveModifier), +   S0ActualAtkLuck = (ActualAtkLuck + S0NegativeModifier), + +   {IsCritical, S1PositiveModifier, S1NegativeModifier} =        roll_critical_hit(ActualAtkStats, S0ActualAtkLuck), +   S1ActualAtkLuck = (S0ActualAtkLuck + S1PositiveModifier), +   S1ActualDefLuck = (S0ActualDefLuck + S1NegativeModifier), +     AtkDamageModifier = shr_statistics:get_damage_modifier(ActualAtkStats),     Damage =        get_damage @@ -211,8 +213,8 @@ effect_of_attack     {FinalAttackerLuck, FinalDefenderLuck} =        case ParryIsSuccessful of -         true -> {S0ActualDefLuck, S1ActualAtkLuck}; -         false -> {S1ActualAtkLuck, S0ActualDefLuck} +         true -> {S1ActualDefLuck, S1ActualAtkLuck}; +         false -> {S1ActualAtkLuck, S1ActualDefLuck}        end,     { @@ -279,9 +281,12 @@ get_description_of     AtkStats = btl_character_current_data:get_statistics(AtkCurrData),     AttackerDoubleAttackChance =        shr_statistics:get_double_hits(AtkStats), -   {_Roll, IsSuccessful, NewAtkLuck} = +   {_Roll, IsSuccessful, PositiveModifier, NegativeModifier} =        shr_roll:percentage_with_luck(AttackerDoubleAttackChance, AtkLuck), +   NewAtkLuck = (AtkLuck + PositiveModifier), +   NewDefLuck = (DefLuck + NegativeModifier), +     case IsSuccessful of        true ->           effect_of_attack @@ -291,10 +296,10 @@ get_description_of              DefCurrData,              CanParry,              NewAtkLuck, -            DefLuck +            NewDefLuck           ); -      _ -> {nothing, NewAtkLuck, DefLuck} +      _ -> {nothing, NewAtkLuck, NewDefLuck}     end;  get_description_of  ( diff --git a/src/shared/shr_roll.erl b/src/shared/shr_roll.erl index 7c9e1c5..e03d548 100644 --- a/src/shared/shr_roll.erl +++ b/src/shared/shr_roll.erl @@ -12,8 +12,7 @@     [        percentage/0,        between/2, -      percentage_with_luck/2, -      conflict_with_luck/3 +      percentage_with_luck/2     ]  ). @@ -21,6 +20,23 @@  %% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +-spec calculate_costs (boolean(), 0..100, 0..100) -> integer(). +calculate_costs (true, Roll, Chance) when (Chance > 50) -> +   % Succeeded, was likely to succeed. +   % Only pay what was used. +   max(0, (Roll - Chance)); +calculate_costs (true, _Roll, Chance) when (Chance =< 50) -> +   % Succeeded, was unlikely to succeed. +   % Pay a lot! +   (Chance - 55); +calculate_costs (false, _Roll, Chance) when (Chance > 50) -> +   % Failure due to bad roll. +   % Was likely to succeed, you get a lot! +   (Chance - 45); +calculate_costs (_, _, _) -> +   % Failure on unlikely roll. Not costs. +   0. +  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -38,70 +54,16 @@ percentage () ->        non_neg_integer(),        integer()     ) -   -> {0..100, boolean(), integer()}. -percentage_with_luck (Target, Luck) -> -   BaseRoll = percentage(), -   ModedRoll = max(0, min((BaseRoll - Luck), 100)), -   IsSuccess = (ModedRoll =< Target), - -   NewLuck = -      case {IsSuccess, (Target > 50)} of -         {true, true} -> -            % Succeeded, was likely to succeed. -            % Only pay what was used. -            MissingPoints = max(0, (BaseRoll - Target)), -            (Luck - MissingPoints); - -         {true, false} -> -            % Succeeded, was unlikely to succeed. -            % Pay a lot! -            MissingPoints = (55 - Target), -            (Luck - MissingPoints); - -         {false, true} -> -            % Failure due to bad roll. -            % Was likely to succeed, you get a lot! -            OwedPoints = (Target - 45), -            (Luck + OwedPoints); - -         _ -> Luck -      end, - -   {ModedRoll, IsSuccess, NewLuck}. - --spec conflict_with_luck -   ( -      non_neg_integer(), -      integer(), -      integer() -   )     -> {0..100, boolean(), integer(), integer()}. -conflict_with_luck (Target, LuckA, LuckB) -> -   BaseRoll = percentage(), -   ModedRoll = max(0, min((BaseRoll - (LuckA - LuckB)), 100)), -   IsSuccess = (ModedRoll =< Target), - -   {NewLuckA, NewLuckB} = -      case {IsSuccess, (Target > 50)} of -         {true, true} -> -            % Succeeded, was likely to succeed. -            % Only pay what was used. -            MissingPoints = max(0, (BaseRoll - Target)), -            {(LuckA - MissingPoints), LuckB}; - -         {true, false} -> -            % Succeeded, was unlikely to succeed. -            % Pay a lot! -            MissingPoints = (55 - Target), -            {(LuckA - MissingPoints), (LuckB + MissingPoints)}; - -         {false, true} -> -            % Failure due to bad roll. -            % Was likely to succeed, you get a lot! -            OwedPoints = (Target - 45), -            {(LuckA + OwedPoints), (LuckB - OwedPoints)}; - -         _ -> {LuckA, LuckB} -      end, - -   {ModedRoll, IsSuccess, NewLuckA, NewLuckB}. +percentage_with_luck (Chance, Luck) -> +   Roll = percentage(), +   ModedChance = max(0, min((Chance + Luck), 100)), +   ModedRoll = max(0, min((Roll - Luck), 100)), +   IsSuccess = (Roll =< ModedChance), + +   { +      ModedRoll, +      IsSuccess, +      calculate_costs(IsSuccess, Roll, Chance), +      (-1 * calculate_costs(IsSuccess, Roll, ModedChance)) +   }. | 


