{$CLEO .cs}

nop
:LOAD_SETTINGS
wait 0
int H_heal_time = -1
int H_StartWait = IniFile.ReadInt("cleo/healing.ini", "Health", "StartWait")
int H_RepeatInterval = IniFile.ReadInt("cleo/healing.ini", "Health", "RepeatInterval")
float H_MaxPercent = IniFile.ReadFloat("cleo/healing.ini", "Health", "MaxPercent")
float H_MinPercent = IniFile.ReadFloat("cleo/healing.ini", "Health", "MinPercent")
float H_OncePercent = IniFile.ReadFloat("cleo/healing.ini", "Health", "OncePercent")
int H_OncePoint
int H_MaxPoint
int H_MinPoint
int A_heal_time = -1
int A_StartWait = IniFile.ReadInt("cleo/healing.ini", "Armor", "StartWait")
int A_RepeatInterval = IniFile.ReadInt("cleo/healing.ini", "Armor", "RepeatInterval")
float A_MaxPercent = IniFile.ReadFloat("cleo/healing.ini", "Armor", "MaxPercent")
float A_MinPercent = IniFile.ReadFloat("cleo/healing.ini", "Armor", "MinPercent")
float A_OncePercent = IniFile.ReadFloat("cleo/healing.ini", "Armor", "OncePercent")
int A_OncePoint
int A_MaxPoint
int A_MinPoint
if
    H_StartWait < 0
then
    H_StartWait = 0
end
if
    H_RepeatInterval < 0
then
    H_RepeatInterval = 0
end
if
    H_OncePercent > 1.0
then
    H_OncePercent = 1.0
end
if
    H_MaxPercent > 1.0
then
    H_MaxPercent = 1.0
end
if
    A_StartWait < 0
then
    A_StartWait = 0
end
if
    A_RepeatInterval < 0
then
    A_RepeatInterval = 0
end
if
    A_OncePercent > 1.0
then
    A_OncePercent = 1.0
end
if
    A_MaxPercent > 1.0
then
    A_MaxPercent = 1.0
end
jump @CHECK

:CHECK
wait 0
if
    Char.IsDead($scplayer)
then
    H_heal_time = -1
    A_heal_time = -1
jump @CHECK
end
int hurt = 0
int i
for i = 0 to 57 step 1
    if
        Char.HasBeenDamagedByWeapon($scplayer, i)
    then
        Char.ClearLastWeaponDamage($scplayer)
        hurt = 1
        break
    end
end
int health = Char.GetHealth($scplayer)
int H_imax = Memory.Read(0xB7CEE7, 1, 0)
float H_tmax
H_tmax =# H_imax
float H_fmax = H_tmax
H_fmax *= H_MaxPercent
H_MaxPoint =# H_fmax
if
    H_MaxPoint < 1
then
    H_MaxPoint = 1
end
float H_fmin = H_tmax
H_fmin *= H_MinPercent
H_MinPoint =# H_fmin
if                 
    H_MinPoint < 0
then
    H_MinPoint = 0
end
float H_fonce = H_tmax
H_fonce *= H_OncePercent
H_OncePoint =# H_fonce
if                 
    H_OncePoint < 1
then
    H_OncePoint = 1
end
if and
    H_MinPoint < H_MaxPoint
    health >= H_MinPoint
    health < H_MaxPoint
then
    if or
        hurt == 1
        H_heal_time < 0
    then
        TIMERA = 0
        H_heal_time = H_StartWait
    else
        if
            TIMERA >= H_heal_time
        then
            health += H_OncePoint
            if
                health >= H_MaxPoint
            then
                H_heal_time = -1
                health = H_MaxPoint
            else
                TIMERA = 0
                H_heal_time = H_RepeatInterval
            end
            Char.SetHealth($scplayer, health)
        end
    end
else
    H_heal_time = -1
end
int armor = Char.GetArmor($scplayer)
int A_imax = Player.GetMaxArmor($player1)
float A_fmax
A_fmax =# A_imax
A_fmax *= A_MaxPercent
A_MaxPoint =# A_fmax
if
    A_MaxPoint < 1
then
    A_MaxPoint = 1
end
float A_fmin
A_fmin =# A_imax
A_fmin *= A_MinPercent
A_MinPoint =# A_fmin
if
    A_MinPoint < 0
then
    A_MinPoint = 0
end
float A_fonce
A_fonce =# A_imax
A_fonce *= A_OncePercent
A_OncePoint =# A_fonce
if
    A_OncePoint < 1
then
    A_OncePoint = 1
end
if and
    A_MinPoint < A_MaxPoint
    armor >= A_MinPoint
    armor < A_MaxPoint
then
    if or
        hurt == 1
        A_heal_time < 0
    then
        TIMERB = 0
        A_heal_time = A_StartWait
    else
        if
            TIMERB >= A_heal_time
        then
            int tmp = armor
            tmp += A_OncePoint
            if
                tmp >= A_MaxPoint
            then
                A_heal_time = -1
                tmp = A_MaxPoint
            else
                TIMERB = 0
                A_heal_time = A_RepeatInterval
            end
            tmp -= armor
            Char.AddArmor($scplayer, tmp)
        end
    end
else
    A_heal_time = -1
end
jump @CHECK