summaryrefslogtreecommitdiff
blob: edb01fd3a9449e058e03d29f27805a5b036ddfef (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
-module(btl_cond_heal).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec apply_to_character
   (
      btl_condition:type(),
      btl_character:type()
   )
   ->
   {
      btl_condition:type(),
      btl_condition:update_order(),
      [{btl_character:type(), ataxic:basic()}]
   }.
apply_to_character (Condition, S0Character) ->
   {_, Amount} = btl_condition:get_parameters(Condition),

   case btl_character:get_is_alive(S0Character) of
      false -> {Condition, btl_condition:do_nothing(), []};
      true ->
         RemainingUses = btl_condition:get_remaining_uses(Condition),
         CurrentHealth = btl_character:get_current_health(S0Character),
         MaxHealth =
            shr_attributes:get_health
            (
               shr_character:get_attributes
               j(
                  btl_character:get_base_character(S0Character)
               )
            ),

         UpdatedHealth = min(MaxHealth, (CurrentHealth + Amount)),
         UpdatedRemainingUses =

         {S1Character, CharacterUpdate} =
            btl_character:ataxia_set_current_health(UpdatedHealth, S0Character),

         if
            (RemainingUses == -1) ->
               {
                  Condition,
                  btl_condition:do_nothing(),
                  [{S1Character, CharacterUpdate}]
               };

            (RemainingUses == 1) ->
               {
                  btl_condition:set_remaining_uses
                  (
                     UpdatedRemainingUses,
                     Condition
                  ),
                  btl_condition:remove(),
                  [{S1Character, CharacterUpdate}]
               };

            (RemainingUses == 0) ->
               {
                  Condition,
                  btl_condition:remove(),
                  [{S1Character, CharacterUpdate}]
               };

            true ->
               {UpdatedCondition, ConditionUpdate} =
                  btl_condition:ataxia_set_remaining_uses
                  (
                     UpdatedRemainingUses,
                     Condition
                  ),
               {
                  UpdatedCondition,
                  btl_condition:update(ConditionUpdate),
                  [{S1Character, CharacterUpdate}]
               }
         end
   end.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec apply
   (
      btl_condition:trigger(),
      tuple(),
      btl_condition:type(),
      btl_character_turn_update:type()
   ) ->
   {
      [{btl_condition:type(), ataxic:basic()}],
      tuple(),
      btl_character_turn_update:type()
   }.
apply(?CONDITION_TRIGGER_START_OF_PLAYER_TURN, {PlayerIX}, Condition, Update) ->
apply(?CONDITION_TRIGGER_END_OF_PLAYER_TURN, {PlayerIX}, Condition, Update) ->
apply
(
   ?CONDITION_TRIGGER_START_OF_CHARACTER_TURN,
   {CharacterIX},
   Condition,
   Update
) ->
apply
(
   ?CONDITION_TRIGGER_END_OF_CHARACTER_TURN,
   {CharacterIX},
   Condition,
   Update
) ->
apply
(
   ?CONDITION_TRIGGER_END_OF_CHARACTER_TURN,
   {CharacterIX},
   Condition,
   Update
) ->

   Trigger,
   Parameters,
   Condition,
   Update) ->
   {TargetIX, Amount} =
      case btl_condition:get_parameters(Condition) of
         {StoredTargetIX, StoredAmount} -> {StoredTargetIX, StoredAmount};
         Other -> error({condition, parameter, Other})
      end,

   % TODO
   {[{Condition, []}], Update}.