summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornsensfel <SpamShield0@noot-noot.org>2018-07-11 17:54:14 +0200
committernsensfel <SpamShield0@noot-noot.org>2018-07-11 17:54:14 +0200
commitfde827cba1ff3d889135c74ee1978098465fd200 (patch)
treed6022f800aa8226bf79a26a19189965c8cbfb2fe /src/battle/reply/btl_add_char.erl
parentdf59024199c387903e3d4a901171939a358489d3 (diff)
"Battlemap" -> "Battle".
Diffstat (limited to 'src/battle/reply/btl_add_char.erl')
-rw-r--r--src/battle/reply/btl_add_char.erl83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/battle/reply/btl_add_char.erl b/src/battle/reply/btl_add_char.erl
new file mode 100644
index 0000000..75b6fcd
--- /dev/null
+++ b/src/battle/reply/btl_add_char.erl
@@ -0,0 +1,83 @@
+-module(btl_add_char).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-export([generate/3]).
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec rank_to_string (btl_character:rank()) -> binary().
+rank_to_string (Rank) ->
+ case Rank of
+ optional -> <<"o">>;
+ target -> <<"t">>;
+ commander -> <<"c">>
+ end.
+
+-spec attributes_as_json
+ (
+ sh_attributes:type()
+ ) ->
+ {list({binary(), non_neg_integer()})}.
+attributes_as_json (Attributes) ->
+ {
+ [
+ {<<"con">>, sh_attributes:get_constitution(Attributes)},
+ {<<"dex">>, sh_attributes:get_dexterity(Attributes)},
+ {<<"int">>, sh_attributes:get_intelligence(Attributes)},
+ {<<"min">>, sh_attributes:get_mind(Attributes)},
+ {<<"spe">>, sh_attributes:get_speed(Attributes)},
+ {<<"str">>, sh_attributes:get_strength(Attributes)}
+ ]
+ }.
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+-spec generate
+ (
+ non_neg_integer(),
+ btl_character:type(),
+ non_neg_integer()
+ )
+ -> {list(any())}.
+generate (IX, Character, PlayerIX) ->
+ Attributes = btl_character:get_attributes(Character),
+ {ActiveWeapon, SecondaryWeapon} = btl_character:get_weapon_ids(Character),
+ CharacterPlayerIX = btl_character:get_player_index(Character),
+ Location = btl_character:get_location(Character),
+
+ {
+ [
+ {<<"msg">>, <<"add_char">>},
+ {<<"ix">>, IX},
+ {<<"nam">>, btl_character:get_name(Character)},
+ {<<"rnk">>, rank_to_string(btl_character:get_rank(Character))},
+ {<<"ico">>, btl_character:get_icon(Character)},
+ {<<"prt">>, btl_character:get_portrait(Character)},
+ {
+ <<"hea">>,
+ btl_character:get_current_health(Character)
+ },
+ {<<"lc">>, btl_location:encode(Location)},
+ {<<"pla">>, CharacterPlayerIX},
+ {
+ <<"ena">>,
+ (
+ btl_character:get_is_active(Character)
+ and (CharacterPlayerIX == PlayerIX)
+ )
+ },
+ {<<"dea">>, btl_character:get_is_defeated(Character)},
+ {<<"att">>, attributes_as_json(Attributes)},
+ {<<"awp">>, ActiveWeapon},
+ {<<"swp">>, SecondaryWeapon},
+ {<<"ar">>, btl_character:get_armor_id(Character)}
+ ]
+ }.