summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/battle/struct/btl_turn_result.erl')
-rw-r--r--src/battle/struct/btl_turn_result.erl34
1 files changed, 33 insertions, 1 deletions
diff --git a/src/battle/struct/btl_turn_result.erl b/src/battle/struct/btl_turn_result.erl
index 3e1be50..d8e20c0 100644
--- a/src/battle/struct/btl_turn_result.erl
+++ b/src/battle/struct/btl_turn_result.erl
@@ -3,7 +3,15 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%%%
+-record
+(
+ condition,
+ {
+ module :: atom(),
+ params :: any()
+ }
+).
+
-record
(
switched_weapon,
@@ -80,6 +88,7 @@
| #player_won{}
| #player_lost{}
| #player_turn_started{}
+ | #condition{}
).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -90,6 +99,7 @@
-export
(
[
+ new_condition/2,
new_player_won/1,
new_player_lost/1,
new_player_turn_started/1,
@@ -114,6 +124,10 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec new_condition (atom(), any()) -> type().
+new_condition (Module, Params) ->
+ #condition{ module = Module, params = Params }.
+
-spec new_player_won (non_neg_integer()) -> type().
new_player_won (PlayerIX) ->
#player_won { player_ix = PlayerIX }.
@@ -280,5 +294,23 @@ encode (TurnResult) when is_record(TurnResult, player_turn_started) ->
{<<"ix">>, PlayerIX}
]
};
+encode (TurnResult) when is_record(TurnResult, condition) ->
+ {ModuleID, EncodedParams} =
+ erlang:apply
+ (
+ TurnResult#condition.module,
+ encode_turn_result,
+ [
+ TurnResult#condition.params
+ ]
+ ),
+
+ {
+ [
+ {<<"t">>, <<"con">>},
+ {<<"m">>, ModuleID},
+ {<<"p">>, EncodedParams}
+ ]
+ };
encode (Other) ->
error(io_lib:format("~n invalid encode param\"~p\"~n", [Other])).