summaryrefslogtreecommitdiff
path: root/world/map/npc/magic/_procedures.txt
blob: bdeb6140bf86472b7b55be3e274e3d447ab61f59 (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
function|script|magic_register
{
    //debugmes ">> Register " + .invocation$ + " @ " + strnpcinfo(0);
    set .@ext$, if_then_else(getarg(0,"") != "", "::"+getarg(0), "");
    registercmd .invocation$, strnpcinfo(0) + .@ext$; // register the spell
    set .index, $@magic_index;
    set $@magic_index, $@magic_index + 1;
    return;
}

// this can only be done with a npc so...
-|script|Magic Timer|32767
{
    end;

OnLogin:
    set @_M_BLOCK, 1;
    addtimer 10000, "Magic Timer::OnClear";
    end;

OnClear:
    set @_M_BLOCK, 0;
    end;
}

// this function is call()-only
function|script|magic_checks
{
    set .@r, 0;
    if(HIDDEN) set .@r, 1; // can not cast with @hide
    if(@_M_BLOCK) set .@r, 2; // check if last debuff ended
    if(Hp < 1) set .@r, 3; // can not cast when dead
    if (MATK1 < 1) set .@r, 4; // can not cast with a grey mana bar
    if (.@r)
        smsg SMSG_FAILURE, "Magic: Impossible to cast right now.";
    return .@r;
}

function|script|elt_damage
{
    // args are damage, dmgplus(mutation), bonus_elt, malus_elt, effect
    set .@dmg, getarg(0) + rand(getarg(1));
    if(get(ELTTYPE, @target_id) == getarg(3)) // malus
        set .@dmg, .@dmg / 3;
    if(get(ELTTYPE, @target_id) == getarg(2)) // bonus
        set .@dmg, ((get(ELTLVL, @target_id) + 4) * .@dmg) / 4;
    set .@source, .caster;
    if (!.@source) set .@source, getcharid(3);

    injure .@source, @target_id, (.@dmg * (100 - get(MDEF1, @target_id))) / 100;
    misceffect getarg(4), @target_id;
    return;
}

function|script|melee_damage
{
    // args are spell power, target id, dmg
    if ((getarg(0) - rand(100)) < (get(BaseLevel, getarg(1)) + get(MDEF1, getarg(1))))
        injure BL_ID, getarg(1), 0;
    else injure BL_ID, getarg(1), (getarg(2) * (100 - get(MDEF1, @target_id))) / 100;
    return;
}

function|script|magic_create_item
{
    // FIXME / XXX: IMO, using Luk for this is very bad and unfair
    set .@exp, (MAGIC_EXPERIENCE & (BYTE_0_MASK | BYTE_1_MASK)) >> BYTE_0_SHIFT;
    set .@score, (.@exp + rand(min(@spellpower, ((.@exp / 3) + 1))));
    set @create_params[2], 1; // success flag
    if (.@score >= @create_params[1]) goto L_Perfect;
    set @create_params[2], 0; // success flag
    set .@score, .@score + rand(Luk) + rand(Luk);
    if (.@score < (@create_params[1] / 3)) goto L_Backfire;
    if (.@score < ((@create_params[1] * 2) / 3)) goto L_Iten;
    message strcharinfo(0), "Magic : ##3##BYour spell takes on a mind of its own!";
    if (rand(3) == 1) getitem @create_items$[1], 1; // bad item
    return;

L_Iten:
    if (rand(5) != 2) goto L_Escape;
    message strcharinfo(0), "Magic : ##3##BYour spell solidifies into the shape of a mysterious object!";
    getitem "Iten", 1;
    return;

L_Escape:
    message strcharinfo(0), "Magic : ##3##BYour spell escapes!";
    return;

L_Backfire:
    message strcharinfo(0), "Magic : ##3##BYour spell backfires!";
    if (rand(110) < Luk) heal 0 - ((BaseLevel+1)*(BaseLevel+2)*(rand(28)+3)), 0;
    else                 heal 0 - (BaseLevel + 1), 0;
    return;

L_Perfect:
    getitem @create_items$[0], @create_params[0]; // good item
    return;
}

function|script|magic_exp
{
    set @last_index, (MAGIC_EXPERIENCE & BYTE_2_MASK) >> BYTE_2_SHIFT;
    set @last_exp, (MAGIC_EXPERIENCE & (BYTE_0_MASK | BYTE_1_MASK)) >> BYTE_0_SHIFT;

    //debugmes "old spell index: " + @last_index;
    //debugmes "new spell index: " + .index;

    if(getskilllv(SKILL_MAGIC) < (.level + 3) && .index != @last_index)
        goto L_Gain;
    //debugmes "same as last spell => don't proceed";
    goto L_Return;

L_Gain:
    if(.exp_gain < 1) goto L_Return; // only the spells that have exp register here. If you
    //                                 remove this line then players can cast a spell with
    //                                 no cost, then a spell with a reagents, then another
    //                                 spell with no costs and still get the exp
    set @new_exp, @last_exp + .exp_gain;
    if(@new_exp > (BYTE_0_MASK | BYTE_1_MASK)) set @new_exp, (BYTE_0_MASK | BYTE_1_MASK);
    //debugmes "old magic exp: "+ @last_exp;
    //debugmes "new magic exp: "+ @new_exp;
    set MAGIC_EXPERIENCE, (MAGIC_EXPERIENCE &~ (BYTE_0_MASK | BYTE_1_MASK)) | (@new_exp << BYTE_0_SHIFT);
    set MAGIC_EXPERIENCE, (MAGIC_EXPERIENCE &~ BYTE_2_MASK) | (.index << BYTE_2_SHIFT);
    goto L_Return;

L_Return:
    return;
}

function|script|adjust_spellpower
{
    set @spellpower, MATK1 + getskilllv(SKILL_MAGIC) + getskilllv(.school) + 10;
    if((.school != SKILL_MAGIC_NATURE) && (.school != SKILL_MAGIC_LIFE)) goto L_Return;
    if(@args$ == "" || !@args$ || getpartnerid2() == 0) goto L_Return;
    if(getcharid(3, @args$) < 1 || getpartnerid2() != getcharid(3, @args$) || !(isloggedin(getcharid(3, @args$))))
        goto L_Return;
    //debugmes "You targeted your spouse!";
    // XXX: the spell power increases when the target is the spouse so one could
    //      just do #modrilax (spouse) right?
    //
    // ... let's just forget about spouse for now
    goto L_Return;

L_Return:
    return;
}

function|script|gain_heal_xp
{
    set @last_heal_xp, ((SCRIPT_XP & SCRIPT_HEALSPELL_MASK) >>  SCRIPT_HEALSPELL_SHIFT);
    if ((@target_id != BL_ID) && ((.@heal_value / .heal_xp_value_divisor) > (((10 + @last_heal_xp) + rand(@last_heal_xp + 1)) + rand(@last_heal_xp + 1))))
        goto L_Block;
    goto L_Return;

L_Block:
    set @heal_xp, (@last_heal_xp + @mexp);
    if (@heal_xp > SCRIPT_HEALSPELL_MASK)
        set @heal_xp, SCRIPT_HEALSPELL_MASK;
    set SCRIPT_XP, (SCRIPT_XP & ~(SCRIPT_HEALSPELL_MASK) | (@heal_xp << SCRIPT_HEALSPELL_SHIFT));
    goto L_Gain_Xp;

L_Gain_Xp:
    set @heal_exp, .@heal_value;
    if (.@heal_value > get(HEALXP, @target_id))
        set @heal_exp, get(HEALXP, @target_id);
    getexp (.base_exp_factor * @heal_exp), 0;
    goto L_Return;

L_Return:
    return;
}