summaryrefslogtreecommitdiff
blob: 0be920b27bd602b6660cb89361a2d61791094c47 (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
-module(btl_character_current_data).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
   character_current_data,
   {
      attributes :: shr_attributes:type(),
      statistics :: shr_statistics:type(),
      omnimods :: shr_omnimods:type()
   }
).

-opaque type() :: #character_current_data{}.

-export_type([type/0]).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-export
(
   [
      get_attributes/1,
      get_statistics/1,
      get_omnimods/1
   ]
).

-export
(
   [
      new/2
   ]
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec location_to_omnimods
   (
      {non_neg_integer(), non_neg_integer()},
      shr_map:type()
   )
   -> shr_omnimods:type().
location_to_omnimods (Location, Map) ->
   TileInstance = shr_map:get_tile_instance(Location, Map),
   TileClassID = shr_tile:extract_main_class_id(TileInstance),
   Tile = shr_tile:from_class_id(TileClassID),

   shr_tile:get_omnimods(Tile).

-spec weapon_id_to_omnimods (shr_weapon:id()) -> shr_omnimods:type().
weapon_id_to_omnimods (WeaponID) ->
   Weapon = shr_weapon:from_id(WeaponID),

   shr_weapon:get_omnimods(Weapon).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
-spec get_omnimods (type()) -> shr_omnimods:type().
get_omnimods (Char) -> Char#character_current_data.omnimods.

-spec get_attributes (type()) -> shr_attributes:type().
get_attributes (Char) -> Char#character_current_data.attributes.

-spec get_statistics (type()) -> shr_statistics:type().
get_statistics (Char) -> Char#character_current_data.statistics.

%%%% Utils
-spec new (btl_character:type(), shr_map:type()) -> type().
new (Character, Map) ->
   PermanentOmnimods = btl_character:get_permanent_omnimods(Character),

   {WeaponID, _} = btl_character:get_weapon_ids(Character),
   WeaponOmnimods = weapon_id_to_omnimods(WeaponID),

   Location = btl_character:get_location(Character),
   TileOmnimods = location_to_omnimods(Location, Map),

   CurrentOmnimods =
      shr_omnimods:merge
      (
         shr_omnimods:merge(WeaponOmnimods, TileOmnimods),
         PermanentOmnimods
      ),

   CurrentAttributes =
      shr_omnimods:apply_to_attributes
      (
         CurrentOmnimods,
         shr_attributes:default()
      ),

   CurrentStatistics =
      shr_omnimods:apply_to_statistics
      (
         CurrentOmnimods,
         shr_statistics:new_raw(CurrentAttributes)
      ),

   #character_current_data
   {
      attributes = CurrentAttributes,
      statistics = CurrentStatistics,
      omnimods = CurrentOmnimods
   }.