summaryrefslogtreecommitdiff
path: root/npc/functions/soul-menhir.txt
blob: 3d4344c964f4043d7f5285f8803d843788c8988e (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
// Evol scripts.
// Author:
//    gumi
//    Jesusalva
// Description:
//    place of power, mana refills faster when sitting nearby

-	script	Soul Menhir	NPC_HIDDEN,{
    if (!@menhir_meditation_message)
    {
        dispbottom(l("You feel a strong magic aura. You want to sit near it and meditate."));
        @menhir_meditation_message=1;
    }
    end;

OnRefill:
    @menhir_lock = false;
    getmapxy(.@map$, .@x, .@y, UNITTYPE_PC);

    if (.@map$ != .map$ || distance(.x, .y, .@x, .@y) > .refill_distance ||
        !(issit()))
        end;

    heal(0, .refill_rate);
    end;


OnTimer500:
    .@count = getunits(BL_PC, .@units[0], false, .map$, (.x - .refill_distance),
        (.y - .refill_distance), (.x + .refill_distance), (.y + .refill_distance));

    for (.@i = 0; .@i < .@count; ++.@i)
    {
        if (.@units[.@i] < 0) continue; // pre-check, just in case
        deltimer(.name$ + "::OnRefill", .@units[.@i]);
        if (gettimer(TIMER_COUNT, .@units[.@i], .name$ + "::OnRefill") > 0 ||
            getvariableofpc(@menhir_lock, .@units[.@i])) {
            continue;
        }
        set(getvariableofpc(@menhir_lock, .@units[.@i]), true);
        addtimer(rand(.refill_timer), .name$ + "::OnRefill", .@units[.@i]);
    }

    initnpctimer();
    end;

OnInit:
    // Placeholder menhir doesn't have to run
    if (.name$ == "Soul Menhir")
        end;

    // "Next-Generation" parsing system
    // Syntax: RATE_DISTANCE_TIMER
    // Soul Menhir#town_rate_dist_timer
    // example
    // Soul Menhir#hurns_1_7_200
    .@n$=strnpcinfo(0, "_0_0_0");
    explode(.@ni$, .@n$, "_");
    .refill_rate=atoi(.@ni$[1]);
    .refill_distance=atoi(.@ni$[2]);
    .refill_timer=atoi(.@ni$[3]);

    // number of SP to give every refill
    if (!.refill_rate)
        .refill_rate = 1;
    // max distance
    if (.refill_distance < 0)
        .refill_distance = 7;
    // wait rand(X) ms before refill
    if (.refill_timer < 1)
        .refill_timer = 200;

    initnpctimer();
    end;
}