summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-24 16:23:01 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-24 16:23:01 +0100
commit114dc835cb90a82bde298367df7848499a73dc1c (patch)
treee2c1a88c499aaf00d5d11dceaa0af3e2ae8dcc8c /src/query/character_turn/handle_character_instance_attacking_2.erl
parent96c35eb8c79826fa07d2b00bbac039d9ec95eb3c (diff)
Fixes parries, starts work on load_state.
Diffstat (limited to 'src/query/character_turn/handle_character_instance_attacking_2.erl')
-rw-r--r--src/query/character_turn/handle_character_instance_attacking_2.erl204
1 files changed, 83 insertions, 121 deletions
diff --git a/src/query/character_turn/handle_character_instance_attacking_2.erl b/src/query/character_turn/handle_character_instance_attacking_2.erl
index ecb2a95..52c3f3d 100644
--- a/src/query/character_turn/handle_character_instance_attacking_2.erl
+++ b/src/query/character_turn/handle_character_instance_attacking_2.erl
@@ -1,14 +1,7 @@
roll_hits (AttackerStatistics, DefenderStatistics) ->
- MissChance =
- max
- (
- 0,
- (
- statistics:get_dodges(DefenderStatistics)
- -
- statistics:get_accuracy(AttackerStatistics)
- )
- ),
+ DefenderDodges = statistics:get_dodges(DefenderStatistics),
+ AttackerAccuracy = statistics:get_accuracy(AttackerStatistics),
+ MissChance = max(0, (DefenderDodges - AttackerAccuracy)),
case roll:percentage() of
X when (X =< MissChance) -> misses;
X when (X =< (MissChance * 2)) -> grazes;
@@ -21,119 +14,122 @@ roll_damage (AttackerStatistics, _DefenderStatistics) ->
BaseDamage = MinimumDamage + (rand:uniform(MaximumRoll) - 1),
CriticalHitChance = statistics:get_critical_hits(AttackerStatistics),
case roll:percentage() of
- X when (X =< CriticalHitChance) ->
- {critical, (BaseDamage * 2)};
- _ ->
- {basic, BaseDamage}
+ X when (X =< CriticalHitChance) -> {critical, (BaseDamage * 2)};
+ _ -> {basic, BaseDamage}
end.
handle_attack (AttackerStatistics, DefenderStatistics) ->
Hits = roll_hits(AttackerStatistics, DefenderStatistics),
{Critical, Damage} = roll_damage(AttackerStatistics, DefenderStatistics),
case Hits of
- misses ->
- {Hits, Critical, 0};
-
- grazes ->
- {
- Hits,
- Critical,
- trunc(Damage / 2)
- };
-
- _ ->
- {
- Hits,
- Critical,
- Damage
- }
+ misses -> {Hits, Critical, 0};
+ grazes -> {Hits, Critical, trunc(Damage / 2)};
+ hits -> {Hits, Critical, Damage}
end.
-handle_parry (AttackerStatistics, DefenderStatistics) ->
- ParryChance = statistics:get_parries(DefenderStatistics),
- case roll:percentage() of
- X when (X =< ParryChance) ->
- [{parry, handle_attack(DefenderStatistics, AttackerStatistics)}];
- _ ->
- []
- end.
%% FIXME: parry not working as intended
handle_attacks ([], _AttackerStatistics, _DefenderStatistics, Results) ->
Results;
handle_attacks
(
- [nothing|Next],
+ [first|Next],
AttackerStatistics,
DefenderStatistics,
Results
) ->
+ AttackResult = handle_attack(AttackerStatistics, DefenderStatistics),
handle_attacks
(
Next,
AttackerStatistics,
DefenderStatistics,
- Results
+ [{first, AttackResult} | Results]
);
handle_attacks
(
- [first|Next],
+ [second|Next],
AttackerStatistics,
DefenderStatistics,
Results
) ->
- handle_attacks
- (
- Next,
- AttackerStatistics,
- DefenderStatistics,
- [
- {
- first,
- handle_attack(AttackerStatistics, DefenderStatistics)
- }
- |
- Results
- ]
- );
+ SecondHitChance = statistics:get_second_hits(AttackerStatistics),
+ UpdatedResults =
+ case roll:percentage() of
+ X when (X =< SecondHitChance) ->
+ [
+ {second, handle_attack(AttackerStatistics, DefenderStatistics)}
+ |
+ Results
+ ];
+
+ _ ->
+ Results
+ end,
+ handle_attacks(Next, AttackerStatistics, DefenderStatistics, UpdatedResults);
handle_attacks
(
- [second|Next],
+ [{first, parry}|Next],
AttackerStatistics,
DefenderStatistics,
Results
) ->
+ ParryChance = statistics:get_parries(DefenderStatistics),
+ AttackResult =
+ case roll:percentage() of
+ X when (X =< ParryChance) ->
+ {
+ {first, parry},
+ handle_attack(DefenderStatistics, AttackerStatistics)
+ };
+
+ _ ->
+ {first, handle_attack(AttackerStatistics, DefenderStatistics)}
+ end,
handle_attacks
(
Next,
AttackerStatistics,
DefenderStatistics,
- [
- {
- second,
- handle_attack(AttackerStatistics, DefenderStatistics)
- }
- |
- Results
- ]
+ [AttackResult|Results]
);
handle_attacks
(
- [parry|Next],
+ [{second, parry}|Next],
AttackerStatistics,
DefenderStatistics,
Results
) ->
+ SecondHitChance = statistics:get_second_hits(AttackerStatistics),
+ ParryChance = statistics:get_parries(DefenderStatistics),
+ AttackResult =
+ case roll:percentage() of
+ X when (X =< SecondHitChance) ->
+ case roll:percentage() of
+ Y when (Y =< ParryChance) ->
+ {
+ {second, parry},
+ handle_attack(DefenderStatistics, AttackerStatistics)
+ };
+
+ _ ->
+ {
+ second,
+ handle_attack(AttackerStatistics, DefenderStatistics)
+ }
+ end;
+
+ _ -> nothing
+ end,
handle_attacks
(
Next,
AttackerStatistics,
DefenderStatistics,
- (
- handle_parry(AttackerStatistics, DefenderStatistics)
- ++
- Results
- )
+ case AttackResult of
+ nothing -> Results;
+ _ -> [AttackResult|Results]
+ end
);
handle_attacks
(
@@ -148,10 +144,7 @@ handle_attacks
AttackerStatistics,
DefenderStatistics,
[
- {
- counter,
- handle_attack(DefenderStatistics, AttackerStatistics)
- }
+ {counter, handle_attack(DefenderStatistics, AttackerStatistics)}
|
Results
]
@@ -161,31 +154,12 @@ apply_attacks_to_healths ([], AttackerHealth, DefenderHealth, ValidEffects) ->
{ValidEffects, AttackerHealth, DefenderHealth};
apply_attacks_to_healths
(
- [{first, Effect}|Next],
- AttackerHealth,
- DefenderHealth,
- ValidEffects
-) ->
- {_Hit, _Critical, Damage} = Effect,
- case (AttackerHealth > 0) of
- true ->
- apply_attacks_to_healths
- (
- Next,
- AttackerHealth,
- max(0, (DefenderHealth - Damage)),
- [{first, Effect}|ValidEffects]
- );
- false ->
- ValidEffects
- end;
-apply_attacks_to_healths
-(
- [{second, Effect}|Next],
+ [{Action, Effect}|Next],
AttackerHealth,
DefenderHealth,
ValidEffects
-) ->
+)
+when ((Action == first) or (Action == second)) ->
{_Hit, _Critical, Damage} = Effect,
case (AttackerHealth > 0) of
true ->
@@ -194,37 +168,24 @@ apply_attacks_to_healths
Next,
AttackerHealth,
max(0, (DefenderHealth - Damage)),
- [{second, Effect}|ValidEffects]
+ [{Action, Effect}|ValidEffects]
);
+
false ->
ValidEffects
end;
apply_attacks_to_healths
(
- [{counter, Effect}|Next],
+ [{Action, Effect}|Next],
AttackerHealth,
DefenderHealth,
ValidEffects
-) ->
- {_Hit, _Critical, Damage} = Effect,
- case (DefenderHealth > 0) of
- true ->
- apply_attacks_to_healths
- (
- Next,
- max(0, (AttackerHealth - Damage)),
- DefenderHealth,
- [{counter, Effect}|ValidEffects]
- );
- false ->
- ValidEffects
- end;
-apply_attacks_to_healths
+)
+when
(
- [{parry, Effect}|Next],
- AttackerHealth,
- DefenderHealth,
- ValidEffects
+ (Action == counter)
+ or (Action == {first, parry})
+ or (Action == {second, parry})
) ->
{_Hit, _Critical, Damage} = Effect,
case (DefenderHealth > 0) of
@@ -234,8 +195,9 @@ apply_attacks_to_healths
Next,
max(0, (AttackerHealth - Damage)),
DefenderHealth,
- [{parry, Effect}|ValidEffects]
+ [{Action, Effect}|ValidEffects]
);
+
false ->
ValidEffects
end.
@@ -324,11 +286,11 @@ handle_character_instance_attacking (QueryState, Input) ->
Actions =
case {CanDefend, CanParry} of
{true, true} ->
- [{second, parry}, counter, {first, parry}];
+ [{attack, parry}, counter, {attack, parry}];
{true, false} ->
- [{second, no_parry}, counter, {fist, no_parry}];
+ [second, counter, no_parry];
{false, _} ->
- [{second, no_parry}, {first, no_parry}]
+ [second, first]
end,
Effects =
handle_attacks