summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-02-28 13:59:39 +0100
committernsensfel <SpamShield0@noot-noot.org>2018-02-28 13:59:39 +0100
commit5235345620c0d4a6669ccc6badc387902ea8c92a (patch)
tree0a8989ffd29b0a9d8ab997d763f15268d18de06a /src/query/character_turn
parent8ed3e625a5576b6f43b966ee77e0f6de282a074e (diff)
Adds more types specifications.
Diffstat (limited to 'src/query/character_turn')
-rw-r--r--src/query/character_turn/handle_character_instance_attacking_2.erl64
1 files changed, 62 insertions, 2 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 5f34d05..6995c4c 100644
--- a/src/query/character_turn/handle_character_instance_attacking_2.erl
+++ b/src/query/character_turn/handle_character_instance_attacking_2.erl
@@ -1,4 +1,23 @@
-%% FIXME: parry not working as intended
+% TODO: put all of that into separate modules. It's kind of a mess here.
+-type hits() :: ('misses' | 'grazes' | 'hits').
+-type critical() :: ('critical' | 'basic').
+-type attack_category() ::
+ (
+ 'first'
+ | 'second'
+ | 'counter'
+ | {'first', 'parry'}
+ | {'second', 'parry'}
+ ).
+-type attack_effect() :: {hits(), critical(), non_neg_integer()}.
+-type attack_desc() :: {attack_category(), attack_effect()}.
+
+-spec roll_hits
+ (
+ statistics:struct(),
+ statistics:struct()
+ )
+ -> hits().
roll_hits (AttackerStatistics, DefenderStatistics) ->
DefenderDodges = statistics:get_dodges(DefenderStatistics),
AttackerAccuracy = statistics:get_accuracy(AttackerStatistics),
@@ -9,6 +28,12 @@ roll_hits (AttackerStatistics, DefenderStatistics) ->
_ -> hits
end.
+-spec roll_damage
+ (
+ statistics:struct(),
+ statistics:struct()
+ )
+ -> {critical(), non_neg_integer()}.
roll_damage (AttackerStatistics, _DefenderStatistics) ->
{MinimumDamage, MaximumDamage} = statistics:get_damages(AttackerStatistics),
MaximumRoll = max(1, MaximumDamage - MinimumDamage),
@@ -19,6 +44,12 @@ roll_damage (AttackerStatistics, _DefenderStatistics) ->
_ -> {basic, BaseDamage}
end.
+-spec handle_attack
+ (
+ statistics:struct(),
+ statistics:struct()
+ )
+ -> {hits(), critical(), non_neg_integer()}.
handle_attack (AttackerStatistics, DefenderStatistics) ->
Hits = roll_hits(AttackerStatistics, DefenderStatistics),
{Critical, Damage} = roll_damage(AttackerStatistics, DefenderStatistics),
@@ -28,7 +59,14 @@ handle_attack (AttackerStatistics, DefenderStatistics) ->
hits -> {Hits, Critical, Damage}
end.
-
+-spec handle_attacks
+ (
+ list(attack_category()),
+ statistics:struct(),
+ statistics:struct(),
+ list(attack_desc())
+ )
+ -> list(attack_desc()).
handle_attacks ([], _AttackerStatistics, _DefenderStatistics, Results) ->
Results;
handle_attacks
@@ -150,6 +188,14 @@ handle_attacks
]
).
+-spec apply_attacks_to_healths
+ (
+ list(attack_desc()),
+ non_neg_integer(),
+ non_neg_integer(),
+ list(attack_desc())
+ )
+ -> {list(attack_desc()), non_neg_integer(), non_neg_integer()}.
apply_attacks_to_healths ([], AttackerHealth, DefenderHealth, ValidEffects) ->
{ValidEffects, AttackerHealth, DefenderHealth};
apply_attacks_to_healths
@@ -202,6 +248,14 @@ when
{ValidEffects, AttackerHealth, DefenderHealth}
end.
+-spec set_new_healths_in_query_state
+ (
+ non_neg_integer(),
+ non_neg_integer(),
+ query_state(),
+ input()
+ )
+ -> query_state().
set_new_healths_in_query_state
(
RemainingAttackerHealth,
@@ -246,6 +300,12 @@ set_new_healths_in_query_state
)
}.
+-spec handle_character_instance_attacking
+ (
+ query_state(),
+ input()
+ )
+ -> {list(attack_desc()), query_state()}.
handle_character_instance_attacking (QueryState, Input) ->
BattlemapInstance = QueryState#query_state.battlemap_instance,
ControlledCharacterInstance = QueryState#query_state.character_instance,