summaryrefslogtreecommitdiff
blob: e60d1ace3a98b7741fd7e873318452c633cae11b (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
-module(btl_cond_heal).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-include("tacticians/conditions.hrl").

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-export
(
   [
      encode/1,
      get_turn_result_encoding/1,
      apply/3
   ]
).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% LOCAL FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec heal_character
   (
      non_neg_integer(),
      btl_character:type(),
      non_neg_integer()
   )
   ->
   (
      {
         non_neg_integer(),
         btl_character:type(),
         btl_turn_result:type(),
         ataxic:basic()
      }
      | none
   ).
heal_character (ActorIX, S0Actor, S0HealingAmount) ->
   case btl_character:get_is_alive(S0Actor) of
      false -> none;
      true ->
         CurrentHealth = btl_character:get_current_health(S0Actor),
         BaseActor = btl_character:get_base_character(S0Actor),
         ActorAttributes = shr_character:get_attributes(BaseActor),
         MaxHealth = shr_attributes:get_maximum_health(ActorAttributes),
         MaxHealing = (MaxHealth - CurrentHealth),
         S1HealingAmount = min(MaxHealing, S0HealingAmount),
         {S1Actor, ActorAtaxicUpdate} =
            btl_character:ataxia_set_current_health
            (
               S0Actor,
               (CurrentHealth + S1HealingAmount)
            ),

         {
            S1HealingAmount,
            S1Actor,
            btl_turn_result:new_condition
            (
               btl_cond_heal,
               {ActorIX, S1HealingAmount}
            ),
            ActorAtaxicUpdate
         }
   end.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EXPORTED FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-spec apply
   (
      btl_conditions:ref(),
      btl_character_turn_update:type(),
      shr_condition:context(any(), VolatileDataType),
   )
   -> {VolatileDataType, btl_character_turn_update:type()}.
apply (SelfRef, S0Update, S0Context) ->
   {_Trigger, _ReadOnlyData, VolatileData} = S0Context,

   {VolatileData, S0Update}.