summaryrefslogtreecommitdiff
path: root/world/map/npc/magic/level1-detect-magic.txt
blob: 7936fa9980ef923e255147cc9df780a676aaee75 (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
-|script|detect-magic|32767
{
    if(call("magic_checks")) end;
    if (Sp < 3) end;
    if (getskilllv(SKILL_MAGIC) < .level) end;
    set @_M_BLOCK, 1; // block casting, until the timer clears it
    addtimer 6000, "Magic Timer::OnClear"; // set the new debuff
    sc_start SC_COOLDOWN, 6000, 0, BL_ID;
    callfunc "adjust_spellpower";
    set Sp, Sp - 3;
    set CASTS, CASTS + 1;
    if (CASTS < 0) set CASTS, 1; // overflow
    misceffect FX_MAGIC_DETECT_CAST, strcharinfo(0);
    set .@range, (@spellpower/50)+1;
    set .caster, getcharid(3);
    foreach 0, getmap(), POS_X - .@range, POS_Y - .@range, POS_X + .@range, POS_Y + .@range,
            strnpcinfo(0) + "::OnNearbyPlayer";
    foreach 1, getmap(), POS_X - .@range, POS_Y - .@range, POS_X + .@range, POS_Y + .@range,
            strnpcinfo(0) + "::OnNearbyNpc";
    if (getmap() == "099-4")
        addtimer 10, "#TMWFinalExam::OnMiteyo";
    if (getmap() == "099-5")
        addtimer 10, "#TMWFinalExam::OnMiteyo";
    callfunc "magic_exp";
    end;

OnNearbyPlayer:
    if (@target_id == BL_ID) end;           // Dont do lookups on caster.
    if (sc_check(SC_HIDE, @target_id)) end; // Also skip hidden (anwiltyp) players.
    if (attachrid(@target_id) < 1) end;     // Switch context -> found player (to look up focused skills)
    if (call("is_magician")) misceffect FX_MAGIC_DETECT_HIT, BL_ID; // BL_ID because now attached to target
    if (attachrid(.caster) < 1) end;        // Try to reattach back -> caster (is it needed?)
    end;

OnNearbyNpc:
    set .@e$, strnpcinfo(2,@target_id);
    if(.@e$ == "#_M" || .@e$ == "#MAGIC" || get(.IS_MAGIC, @target_id))
        misceffect FX_MAGIC_DETECT_HIT, @target_id;
    end;

OnInit:
    set .school, SKILL_MAGIC;
    set .invocation$, chr(MAGIC_SYMBOL) + "miteyo"; // used in npcs that refer to this spell
    void call("magic_register");
    set .level, 1;
    set .exp_gain, 0;
    end;
}

// This function tests if current RID is a magician (Astral soul skill Lv 9).
function|script|is_magician
{
    getactivatedpoolskilllist;
    if (@skilllist_count != 0) goto L_iterate_focused; // Had some focused skills -> look further
    goto L_focus_notfound; // No focused skills at all -> bail out.

L_iterate_focused:
    set @skilllist_count, @skilllist_count-1;
    if ((@skilllist_id[@skilllist_count] == SKILL_ASTRAL_SOUL) && (getskilllv(SKILL_ASTRAL_SOUL) >= 2)) goto L_focus_found;
    if (@skilllist_count == 0) goto L_focus_notfound;
    goto L_iterate_focused; // iterate via array of focused skills.

L_focus_found:
    return 1;

L_focus_notfound:
    return 0;
}