summaryrefslogtreecommitdiff
blob: c5304244e085872e309df16d0b92944339b1946c (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
-module(character_instance).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-record
(
   character_instance,
   {
      character,
      location,
      current_health,
      active
   }
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
   [
      new/2
   ]
).

%%%% Accessors
-export
(
   [
      get_character/1,
      get_location/1,
      get_current_health/1,
      get_is_active/1,

      set_character/2,
      set_location/2,
      set_current_health/2,
      set_is_active/2
   ]
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% Accessors
get_character (CharInst) -> CharInst#character_instance.character.
get_location (CharInst) -> CharInst#character_instance.location.
get_current_health (CharInst) -> CharInst#character_instance.current_health.
get_is_active (CharInst) ->
   (
      CharInst#character_instance.active
      and
      (CharInst#character_instance.current_health > 0)
   ).

set_character (Char, CharInst) ->
   CharInst#character_instance
   {
      character = Char
   }.

set_location (Location, CharInst) ->
   CharInst#character_instance
   {
      location = Location
   }.

set_current_health (Health, CharInst) ->
   CharInst#character_instance
   {
      current_health = Health
   }.

set_is_active (Active, CharInst) ->
   CharInst#character_instance
   {
      active = Active
   }.

%%%% Utils
new (Char, Location) ->
   Stats = character:get_statistics(Char),
   #character_instance
   {
      character = Char,
      location = Location,
      current_health = statistics:get_health(Stats),
      active = false
   }.