summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2019-10-23 17:46:45 +0200
committernsensfel <SpamShield0@noot-noot.org>2019-10-23 17:46:45 +0200
commit65a2b95f7355b6b495516b95dafa63f8ccaa2bb0 (patch)
tree05011efdd963f8aa017d508bab1386eb90379df2 /src
parent240b60a2a747d073eb001dd92450fd19b91902e9 (diff)
...
Diffstat (limited to 'src')
-rw-r--r--src/battle/mechanic/action/btl_action_attack.erl2
-rw-r--r--src/battle/struct/btl_attack.erl69
-rw-r--r--src/battle/struct/btl_character.erl28
-rw-r--r--src/battle/struct/btl_condition.erl7
-rw-r--r--src/battle/struct/btl_turn_result.erl91
-rw-r--r--src/bounty/bnt_join_battle.erl10
-rw-r--r--src/shared/struct/shr_condition.erl9
7 files changed, 105 insertions, 111 deletions
diff --git a/src/battle/mechanic/action/btl_action_attack.erl b/src/battle/mechanic/action/btl_action_attack.erl
index 26e1190..ea7857a 100644
--- a/src/battle/mechanic/action/btl_action_attack.erl
+++ b/src/battle/mechanic/action/btl_action_attack.erl
@@ -259,7 +259,7 @@ handle_start_of_attack (S0AttackSequence, Action, S0Update) ->
S1Update =
btl_character_turn_update:add_to_timeline
(
- btl_turn_result:new_targeting
+ btl_turn_result:new_character_targetted
(
btl_action:get_actor_index(Action),
btl_action:get_target_index(Action)
diff --git a/src/battle/struct/btl_attack.erl b/src/battle/struct/btl_attack.erl
index 27436f2..7e0a834 100644
--- a/src/battle/struct/btl_attack.erl
+++ b/src/battle/struct/btl_attack.erl
@@ -6,41 +6,26 @@
-type category() :: ('first' | 'second' | 'counter').
-type precision() :: ('misses' | 'grazes' | 'hits').
--record
-(
- attack,
- {
- category :: category(),
- precision :: precision(),
- is_critical :: boolean(),
- is_parry :: boolean(),
- damage :: non_neg_integer()
- }
-).
-
--opaque type() :: #attack{}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--export_type([type/0, category/0, precision/0]).
-
--export
-(
- [
- new/5
- ]
-).
+-export_type([category/0, precision/0]).
-export
(
[
- encode/1
+ encode_category/1,
+ encode_precision/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec encode_category (category()) -> binary().
encode_category (first) -> <<"f">>;
encode_category (counter) -> <<"c">>;
@@ -50,43 +35,3 @@ encode_category (second) -> <<"s">>.
encode_precision (hits) -> <<"h">>;
encode_precision (grazes) -> <<"g">>;
encode_precision (misses) -> <<"m">>.
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
--spec new
- (
- category(),
- precision(),
- boolean(),
- boolean(),
- non_neg_integer()
- )
- -> type().
-new (Category, Precision, IsCritical, IsParry, Damage) ->
- #attack
- {
- category = Category,
- precision = Precision,
- is_critical = IsCritical,
- is_parry = IsParry,
- damage = Damage
- }.
-
--spec encode (type()) -> {list(any())}.
-encode (Attack) ->
- Category = Attack#attack.category,
- Precision = Attack#attack.precision,
- IsCritical = Attack#attack.is_critical,
- IsParry = Attack#attack.is_parry,
- Damage = Attack#attack.damage,
-
- {
- [
- {<<"ord">>, encode_category(Category)},
- {<<"pre">>, encode_precision(Precision)},
- {<<"cri">>, IsCritical},
- {<<"par">>, IsParry},
- {<<"dmg">>, Damage}
- ]
- }.
diff --git a/src/battle/struct/btl_character.erl b/src/battle/struct/btl_character.erl
index 51d6191..6a4fe2f 100644
--- a/src/battle/struct/btl_character.erl
+++ b/src/battle/struct/btl_character.erl
@@ -102,7 +102,6 @@
resolve/2,
is_unresolved/1,
to_unresolved/1,
- decode/1,
encode/1
]
).
@@ -490,7 +489,7 @@ ataxia_set_conditions (Conditions, Char) ->
rank(),
shr_location:type(),
shr_character:type(),
- list(btl_condition:type())
+ btl_condition:collection()
)
-> type().
new
@@ -563,25 +562,6 @@ get_base_character_field () -> #btl_char_ref.base.
-spec get_conditions_field() -> non_neg_integer().
get_conditions_field () -> #btl_char_ref.conditions.
--spec decode (map()) -> unresolved().
-decode (Map) ->
- #btl_char_ref
- {
- player_ix = maps:get(?PLAYER_IX_FIELD, Map),
- rank = maps:get(?RANK_FIELD, Map),
- location = shr_location:decode(maps:get(?LOCATION_FIELD, Map)),
- current_health = maps:get(?CURRENT_HEALTH_FIELD, Map),
- is_active = maps:get(?IS_ACTIVE_FIELD, Map),
- is_defeated = maps:get(?IS_DEFEATED_FIELD, Map),
- base = shr_character:decode(maps:get(?BASE_CHAR_FIELD, Map)),
- conditions =
- lists:map
- (
- fun btl_condition:decode/1,
- maps:get(?CONDITIONS_FIELD, Map)
- )
- }.
-
-spec encode (unresolved()) -> {list({binary(), any()})}.
encode (CharRef) ->
{
@@ -595,11 +575,7 @@ encode (CharRef) ->
{?BASE_CHAR_FIELD, shr_character:encode(CharRef#btl_char_ref.base)},
{
?CONDITIONS_FIELD,
- lists:map
- (
- fun btl_condition:encode/1,
- CharRef#btl_char_ref.conditions
- )
+ btl_condition:encode_collection(CharRef#btl_char_ref.conditions)
}
]
}.
diff --git a/src/battle/struct/btl_condition.erl b/src/battle/struct/btl_condition.erl
index 546c38b..695830b 100644
--- a/src/battle/struct/btl_condition.erl
+++ b/src/battle/struct/btl_condition.erl
@@ -74,7 +74,8 @@
-export
(
[
- encode/1
+ encode/1,
+ encode_collection/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -436,6 +437,8 @@ new (CondID, Triggers, Params) ->
-spec new_collection () -> collection().
new_collection () -> orddict:new().
-
-spec encode (type()) -> {list({binary(), any()})}.
encode (Condition) -> {[]}. % TODO
+
+-spec encode_collection (collection()) -> {list({binary(), any()})}.
+encode_collection (Conditions) -> {[]}. % TODO
diff --git a/src/battle/struct/btl_turn_result.erl b/src/battle/struct/btl_turn_result.erl
index eaf974b..3e1be50 100644
--- a/src/battle/struct/btl_turn_result.erl
+++ b/src/battle/struct/btl_turn_result.erl
@@ -24,11 +24,15 @@
-record
(
- attacked,
+ hit,
{
attacker_ix :: non_neg_integer(),
defender_ix :: non_neg_integer(),
- sequence :: list(btl_attack:type()),
+ category :: btl_attack:category(),
+ precision :: btl_attack:precision(),
+ is_critical :: boolean(),
+ is_parry :: boolean(),
+ damage :: non_neg_integer(),
attacker_luck :: integer(),
defender_luck :: integer()
}
@@ -36,6 +40,16 @@
-record
(
+ targetted,
+ {
+ attacker_ix :: non_neg_integer(),
+ defender_ix :: non_neg_integer()
+ }
+).
+
+
+-record
+(
player_won,
{
player_ix :: non_neg_integer()
@@ -61,7 +75,8 @@
-opaque type() :: (
#switched_weapon{}
| #moved{}
- | #attacked{}
+ | #hit{}
+ | #targetted{}
| #player_won{}
| #player_lost{}
| #player_turn_started{}
@@ -80,7 +95,8 @@
new_player_turn_started/1,
new_character_switched_weapons/1,
new_character_moved/3,
- new_character_attacked/5
+ new_character_hit/9,
+ new_character_targetted/2
]
).
@@ -129,28 +145,48 @@ new_character_moved (CharacterIX, Path, NewLocation) ->
new_location = NewLocation
}.
--spec new_character_attacked
+-spec new_character_targetted (non_neg_integer(), non_neg_integer()) -> type().
+new_character_targetted (AttackerIX, DefenderIX) ->
+ #targetted
+ {
+ attacker_ix = AttackerIX,
+ defender_ix = DefenderIX
+ }.
+
+-spec new_character_hit
(
non_neg_integer(),
non_neg_integer(),
- list(btl_attack:type()),
+ btl_attack:category(),
+ btl_attack:precision(),
+ boolean(),
+ boolean(),
+ non_neg_integer(),
integer(),
integer()
)
-> type().
-new_character_attacked
+new_character_hit
(
AttackerIX,
DefenderIX,
- AttackSequence,
+ Category,
+ Precision,
+ IsCritical,
+ IsParry,
+ Damage,
AttackerLuck,
DefenderLuck
) ->
- #attacked
+ #hit
{
attacker_ix = AttackerIX,
defender_ix = DefenderIX,
- sequence = AttackSequence,
+ category = Category,
+ precision = Precision,
+ is_critical = IsCritical,
+ is_parry = IsParry,
+ damage = Damage,
attacker_luck = AttackerLuck,
defender_luck = DefenderLuck
}.
@@ -181,25 +217,42 @@ encode (TurnResult) when is_record(TurnResult, moved) ->
{<<"nlc">>, EncodedNewLocation}
]
};
-encode (TurnResult) when is_record(TurnResult, attacked) ->
- AttackerIX = TurnResult#attacked.attacker_ix,
- DefenderIX = TurnResult#attacked.defender_ix,
- Sequence = TurnResult#attacked.sequence,
- AttackerLuck = TurnResult#attacked.attacker_luck,
- DefenderLuck = TurnResult#attacked.defender_luck,
-
- EncodedSequence = lists:map(fun btl_attack:encode/1, Sequence),
+encode (TurnResult) when is_record(TurnResult, hit) ->
+ AttackerIX = TurnResult#hit.attacker_ix,
+ DefenderIX = TurnResult#hit.defender_ix,
+ Category = TurnResult#hit.category,
+ Precision = TurnResult#hit.precision,
+ IsCritical = TurnResult#hit.is_critical,
+ IsParry = TurnResult#hit.is_parry,
+ Damage = TurnResult#hit.damage,
+ AttackerLuck = TurnResult#hit.attacker_luck,
+ DefenderLuck = TurnResult#hit.defender_luck,
{
[
{<<"t">>, <<"atk">>},
{<<"aix">>, AttackerIX},
{<<"dix">>, DefenderIX},
- {<<"seq">>, EncodedSequence},
+ {<<"ord">>, btl_attack:encode_category(Category)},
+ {<<"pre">>, btl_attack:encode_precision(Precision)},
+ {<<"cri">>, IsCritical},
+ {<<"par">>, IsParry},
+ {<<"dmg">>, Damage},
{<<"alk">>, AttackerLuck},
{<<"dlk">>, DefenderLuck}
]
};
+encode (TurnResult) when is_record(TurnResult, targetted) ->
+ AttackerIX = TurnResult#targetted.attacker_ix,
+ DefenderIX = TurnResult#targetted.defender_ix,
+
+ {
+ [
+ {<<"t">>, <<"tar">>},
+ {<<"aix">>, AttackerIX},
+ {<<"dix">>, DefenderIX}
+ ]
+ };
encode (TurnResult) when is_record(TurnResult, player_won) ->
PlayerIX = TurnResult#player_won.player_ix,
diff --git a/src/bounty/bnt_join_battle.erl b/src/bounty/bnt_join_battle.erl
index 68a3358..4e6f7fe 100644
--- a/src/bounty/bnt_join_battle.erl
+++ b/src/bounty/bnt_join_battle.erl
@@ -82,8 +82,16 @@ create_character (PlayerIX, RosterChar, Map, ForbiddenLocations) ->
ResolvedBaseChar = shr_character:resolve(TileOmnimods, RosterChar),
% TODO: link rank to roster.
+ % TODO: link conditions to roster.
Result =
- btl_character:new(PlayerIX, optional, Location, ResolvedBaseChar, []),
+ btl_character:new
+ (
+ PlayerIX,
+ optional,
+ Location,
+ ResolvedBaseChar,
+ btl_condition:new_collection()
+ ),
btl_character:to_unresolved(Result).
diff --git a/src/shared/struct/shr_condition.erl b/src/shared/struct/shr_condition.erl
index 13c3426..25504fa 100644
--- a/src/shared/struct/shr_condition.erl
+++ b/src/shared/struct/shr_condition.erl
@@ -13,6 +13,7 @@
{
id :: id(),
name :: binary(),
+ module :: atom(),
description :: binary(),
% can it be removed or stolen? Not ranks, for example.
is_transferable :: boolean()
@@ -29,6 +30,8 @@
-export
(
[
+ from_id/1,
+ get_module/1
]
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -38,3 +41,9 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec get_module (type()) -> atom().
+get_module (#condition{ module = Module }) -> Module.
+
+-spec from_id (id()) -> type().
+from_id (ID) ->
+ error({condition, unknown, ID}).