summaryrefslogtreecommitdiff
path: root/npc/items/rand_sc_heal.txt
blob: 046b38e1cec1f0df36038eea17185674a71410e3 (plain) (blame)
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
// TMW-2 Script.
// Evol scripts.
// Author:
//    Reid
//    Jesusalva
// Description:
//    Random heal every x seconds.
//
// Variables:
//    @delay    Second of healing
//    @min      Min amount of healing
//    @max      Max amount of healing
//    @type     1 Heal
//              2 Other
//              3 Special 1
//              4 Special 2

-	script	rand_sc_heal	-1,{

    // Add remaning bonus if the last one hasn't finished
    function remaining_bonus
    {
        if (getstatus(getarg(0)))
        {
            .@old_val1 = getstatus(getarg(0), 1);
            .@old_delay = getstatus(getarg(0), 4) * 1000;

            // change the delay to prevent fast healing
            if (.@old_delay > @delay)
            {
                @delay = .@old_delay;
                @val1 += .@old_val1;
            }
            else
            {
                @val1 += (.@old_val1 * .@old_delay) / @delay;
            }
        }
        else
        {
            @val3 = @val1;
        }
        return;
    }

OnUse:
    if (@delay <= 0) close;

    // minimum between @min and bVit / 2 * BaseLevel / 10
    .@vitality_bonus = min(@min, readparam(bVit) * BaseLevel / 20);
    .@rand_heal_val = rand(@min, @max);

    // val3 is the heal value without the vitality bonus
    @val3 = .@rand_heal_val / @delay;
    @val1 = (.@rand_heal_val + .@vitality_bonus) / @delay;

    if (@val3 <= 0) close;

    @delay *= 1000; // Put the delay in ms

    switch (@type)
    {
        case 1:
            .@skill = SC_S_LIFEPOTION;
            break;
        case 2:
            .@skill = SC_L_LIFEPOTION;
            break;
        case 3:
            .@skill = SC_G_LIFEPOTION;
            break;
        case 4:
            .@skill = SC_M_LIFEPOTION;
            break;
        default :
            .@skill = 0;
            break;
    }
    if (.@skill != 0)
    {
        remaining_bonus(.@skill);
        sc_end .@skill;
        sc_start2 .@skill, @delay, @val1, 1;
    }

    close;
}