summaryrefslogtreecommitdiff
path: root/npc/items/legacy_heal.txt
blob: 2beb820d3b2bbc1db0ecb22bc38b9fec0b120f07 (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
// TMW-2 Script.
// Evol scripts.
// Author:
//    Reid
//    Jesusalva
// Description:
//    Legacy Healing System
//
// Variables:
//    @delay    Second of healing
//    @min      Min amount of healing
//    @max      Max amount of healing
//
// *getequipoption(EQI_HEAD_TOP,1,168); → Heal Bonus (should be first bonus on Chef Hat)


// ItHeal(delay, min, {max=min})
function	script	ItHeal	{
    .@delay=getarg(0, @delay);
    .@min=getarg(1, @min);
    .@max=getarg(2, (@max ? @max : .@min));

    if (.@delay <= 0) {
        Exception("Invalid legacy healing item, deleting without healing effect.");
        end;
    }

    // Decide the healing bonus type. We have four types: S, L, G and M
    // By default, we use 'S'
    .@skill = SC_S_LIFEPOTION;

    // Vitality can improve the healing amount
    .@min = min(.@max, .@min + (.@min * readparam2(bVit) / 100));
    .@max = .@max + (.@max * readparam2(bVit) / 240);

    // Obtain the real healing
    @val1 = rand2(.@min, .@max) / .@delay;
    //debugmes "Heal %d-%d/%d = %d", .@min, .@max, .@delay, @val1;

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

    // We now have @val1 (new effect), @delay (new delay)
    // But do we have .@v and .@d (old effect and delay)?
    .@v=getstatus(.@skill, 1);
    .@d=getstatus(.@skill, 4) * 1000;

    // If there WAS an effect previously, get ponderate average
    // Note: never use double-precision ponderate averages
    if (.@v > 0) {
        @val1=ponderate_avg(@val1, .@delay, .@v, .@d);
        // Overflow and Underflow protection
        if (.@delay+.@d < .@delay*5 && .@d > 0)
            .@delay=.@delay+.@d;
        //.@delay=ponderate_avg(.@delay, @val1, .@d, .@v);
    }

    // Apply the effect and finish
    sc_end .@skill;
    sc_start2 .@skill, .@delay, @val1, 1;

    // @val1 must be preserved for cross-reading
    @delay=0;
    @min=0;
    @max=0;
    // @val1=0;
    return;
}

-	script	legacy_heal	-1,{

OnUse:
    if (@delay <= 0) {
        Exception("Invalid legacy healing item, deleting without healing effect.");
        end;
    }

    ItHeal(@delay, @min, @max);
    end;
}