summaryrefslogtreecommitdiff
blob: 0fbaf82cfb2eee966501746d03625af25db6166d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
-module(bm_add_char).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export([generate/3]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec rank_to_string (bm_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(),
      bm_character:type(),
      bm_player:id()
   )
   -> {list(any())}.
generate (IX, Character, PlayerID) ->
   Attributes = bm_character:get_attributes(Character),
   {ActiveWeapon, SecondaryWeapon} = bm_character:get_weapon_ids(Character),
   OwnerID = bm_character:get_owner_id(Character),
   Location = bm_character:get_location(Character),

   {
      [
         {<<"msg">>, <<"add_char">>},
         {<<"ix">>, IX},
         {<<"nam">>, bm_character:get_name(Character)},
         {<<"rnk">>, rank_to_string(bm_character:get_rank(Character))},
         {<<"ico">>, bm_character:get_icon(Character)},
         {<<"prt">>, bm_character:get_portrait(Character)},
         {
            <<"hea">>,
            bm_character:get_current_health(Character)
         },
         {<<"lc">>, bm_location:encode(Location)},
         {<<"pla">>, OwnerID},
         {
            <<"ena">>,
            (
               bm_character:get_is_active(Character)
               and
               (OwnerID == PlayerID)
            )
         },
         {<<"att">>, attributes_as_json(Attributes)},
         {<<"awp">>, ActiveWeapon},
         {<<"swp">>, SecondaryWeapon},
         {<<"ar">>, bm_character:get_armor_id(Character)}
      ]
   }.