| 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/shared | |
| 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/shared')
| -rw-r--r-- | src/shared/shr_roll.erl | 98 | 
1 files changed, 30 insertions, 68 deletions
| 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)) +   }. | 


