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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
|
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, 2;
//if (MAGIC_EXPERIENCE < 0)
// set MAGIC_EXPERIENCE, 0; // bug fix
// ^ XXX: check if negative MAGIC_EXPERIENCE is desirable
addtimer 10000, "Magic Timer::OnClear";
end;
OnClear:
set @_M_BLOCK, 0;
end;
}
// this function is call()-only
function|script|magic_checks
{
set .@flags, getarg(0);
set .@nonmagic, .@flags & (1<<0);
if (GM >= 50) goto L_Return; // event managers have no restrictions
if(HIDDEN) goto L_Hidden; // can not cast with @hide
if(@_M_BLOCK == 2) goto L_Login; // login warmup
if(@_M_BLOCK) goto L_Blocked; // check if last debuff ended
if(Hp < 1) goto L_Dead; // can not cast when dead
if (MATK1 < 1 && .@nonmagic < 1) goto L_Greybar; // can not cast with a grey mana bar
if ($@xmas_time && $@xmas_time != $@xmas_reward_time) goto L_Christmas2020;
return 0;
L_Hidden:
smsg SMSG_FAILURE, "Magic: Impossible to cast while hidden!";
return 1;
L_Blocked:
smsg SMSG_FAILURE, "Magic: Impossible to cast while a cooldown is in effect. Please wait.";
return 2;
L_Dead:
smsg SMSG_FAILURE, "Magic: Impossible to cast while dead!";
return 3;
L_Greybar:
smsg SMSG_FAILURE, "Magic: Impossible to cast with 0 m.atk. This might happen if your mana bar is grey. Some equipment can reduce your m.atk.";
return 4;
L_Login:
smsg SMSG_FAILURE, "Magic: Impossible to cast for 10s after logging in.";
return 5;
L_Xmas2020:
smsg SMSG_FAILURE, "Magic: Jack Frost's magical powers prevented your summoning!";
return 6;
L_Christmas2020:
if (gettime(7) != 2020)
goto L_Return;
// If it is not Astral nor Dark I don't really care
if (.school != SKILL_MAGIC_ASTRAL && .school != SKILL_MAGIC_DARK)
goto L_Return;
// TODO: Not all astral nor all dark magic are summons
// But I don't have that sort of fine grained control in TMWA
// So I must whitelist a few invocations and hope they cover everything
if (.invocation$ == "#asorm" || .invocation$ == "#anwiltyp" || .invocation$ == "#phlex")
goto L_Return;
// Not in burst time, so not really important?
// Actually, nevermind, that would not use snowball >__>
// Unallowed in the map
if (getmap() == "034-1" || getmap() == "033-1" || getmap() == "046-1" || getmap() == "047-1")
goto L_Xmas2020;
// Other map? Don't care
goto L_Return;
L_Return:
return 0;
}
// Custom version of checks for Dungeon Masters boss "powerups".
// Both GMs and player eventers MAY eventually call "boss powerups".
// By default, only GMs >= 40 can use BossPowers, but:
// - If someone abuses BossPowers, setting #BP_DISABLED = 1 on them locks them out.
// - Some (trusted) player can be allowed to invoke this by setting BP_EVENTER = 42 on them.
// On TMWA these changes need GM Lv 80 to issue @setvar, so access can only be changed by Lv 80.
// Advantage of this permissions system is: no need to shuffle GM levels, nor there's need to restart server.
function|script|boss_powerup_checks
{
if (HIDDEN) goto L_Hidden; // can not cast with @hide
if (Hp < 1) goto L_Dead; // can not cast when dead
if (@_M_BLOCK) goto L_Blocked; // check if last debuff ended
if ($BP_DISABLE) goto L_Killswitch1; // If things go wrong, boss powers can be completely disabled.
if (#BP_DISABLE) goto L_Killswitch2; // If someone abuses BossPowers there's _per-account_ DENY flag.
if (GM >= 40) goto L_Allowed; // GM >= 40 can use boss actions.
if (IS_EVENTER == 42) goto L_Allowed; // Trusted player(s) could be allowed to access Eventer "magic":
// Use @setvar BP_EVENTER 0 42 Nick (GM Lv 80 command).
smsg SMSG_FAILURE, "BossPowers: Only few of mere mortals may try to enter the twilight zone";
return 1; // Not allowed by default.
L_Allowed:
return 0; // Whoever gets here allowed to invoke BossPowers spells
L_Dead:
smsg SMSG_FAILURE, "BossPowers: you're dead!";
return 2;
L_Hidden:
smsg SMSG_FAILURE, "BossPowers: can't be used when hidden!";
return 3;
L_Killswitch1:
smsg SMSG_FAILURE, "BossPowers: unavailable at the moment (KillSwitch 1)";
return 4;
L_Killswitch2:
smsg SMSG_FAILURE, "BossPowers: unavailable at the moment (KillSwitch 2)";
return 5;
L_Blocked:
smsg SMSG_FAILURE, "BossPowers: cooldown is in effect. Please wait.";
return 6;
}
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;
if (getarg(4) != FX_NONE) 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+Luk2)) + rand((Luk+Luk2));
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+Luk2)) 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|bit
{
//0 name
//1 mask
//2 shift
//3 value
return ((getarg(0) & ~(getarg(1) << getarg(2))) | ((getarg(3) & getarg(1)) << getarg(2)));
}
function|script|magic_exp
{
set @last_index, (MAGIC_EXPERIENCE >> 16) & 0xFF;
set @last_exp, MAGIC_EXPERIENCE & 0xFFFF;
//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, min(0xFFFF, @last_exp + .exp_gain);
//debugmes "old magic exp: "+ @last_exp;
//debugmes "new magic exp: "+ @new_exp;
set MAGIC_EXPERIENCE, call("bit", MAGIC_EXPERIENCE, 0xFFFF, 0, @new_exp);
set MAGIC_EXPERIENCE, call("bit", MAGIC_EXPERIENCE, 0xFF, 16, .index);
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 .@value, getarg(0);
set .@gain, getarg(1);
set .@value_divisor, getarg(2);
set .@base_xp_factor, getarg(3);
set .@last_heal_xp, ((MAGIC_EXPERIENCE >> 24) & 0xFF);
if ((.@value / .@value_divisor) <= (10 + .@last_heal_xp + rand(.@last_heal_xp + 1) + rand(.@last_heal_xp + 1)))
goto L_Return;
set .@heal_xp, min(0xFF, .@last_heal_xp + .@gain); // XXX: maybe switch to 7F
getexp (.@base_xp_factor * .@heal_xp), 0;
// FIXME: extract_heal_xp
//debugmes "old heal exp: "+ .@last_heal_xp;
set MAGIC_EXPERIENCE, call("bit", MAGIC_EXPERIENCE, 0xFF, 24, .@heal_xp);
//debugmes "new heal exp: "+ ((MAGIC_EXPERIENCE >> 24) & 0xFF);
return 1;
L_Return:
return 0;
}
// magic_activity should be called with player RID attached.
// This function used to keep track of magic activity.
function|script|magic_activity
{
set CASTS, CASTS + 1;
if (CASTS < 0) set CASTS, 1; // overflow
return;
}
// consume_sp must be called with player RID attached.
// Params: arg(0): amount of XP to consume.
// Return: 0 on success. On failure: nonzero + message to caster.
function|script|consume_sp
{
if (getarg(0) <= 0) goto L_SpArgFail; // Usage bug? Function fails.
if (Sp < getarg(0)) goto L_NoSp; // Caster lacks enough Sp, fail.
set Sp, (Sp - getarg(0)); // Consume Sp and return success.
callfunc "magic_activity"; // Call activity here to unclutter spells.
return 0;
L_NoSp:
message strcharinfo(0), "Magic : ##3##BNot enough Mana!";
return 1;
L_SpArgFail:
debugmes "bug: consume_sp needs arg(0) > 0";
return 2;
}
// spell_lv_checks helper must be called by spell NPC, with player RID attached.
// It expects "typical" spell NPC structure with .level ans .school
// Params: no args. Data taken from spell NPC.
// Return: 0 on success. On failure: nonzero + message to caster.
function|script|lvl_and_school_check
{
if ((.level <= 0) || (.school <= 0)) goto L_LvCkFail; // Weird/missing school/level on NPC?
if (getskilllv(SKILL_MAGIC) < .level) goto L_LvCkReqs; // General magic < required level?
if (getskilllv(.school) < .level) goto L_LvCkReqs; // Magic school < required level?
return 0; // All checks passed -> success.
L_LvCkReqs:
message strcharinfo(0), "Magic : ##3##BThis spell too hard for you yet.";
return 1; // User below spell requirements set on spell's NPC
L_LvCkFail:
debugmes "bug: lvl_and_school_check needs .school and .level > 0 on spell NPC";
return 2; // NPC bug or not called by spell NPC -> fail
}
// magic_cooldown helper should be called with player RID attached.
// This function used to lock out spell.
// Input: arg0 - length of cooldown.
// Input: arg1 - optional: custom SC_COOLDOWN ID to use.
function|script|magic_block
{
if (getarg(0) <= 0) goto L_Block_Fail;
set @_M_BLOCK, 1; // block casting, until the timer clears it
addtimer getarg(0), "Magic Timer::OnClear"; // Disable spell casting
if (getarg(1) > 0) goto L_CustomCool; // Custom cooldown ID given?
sc_start SC_COOLDOWN, getarg(0), 0, BL_ID; // If not -> default SC_COOLDOWN
return;
L_CustomCool:
sc_start getarg(1), getarg(0), 0, BL_ID; // Apply custom cooldown.
return;
L_Block_Fail:
debugmes "bug: magic_block needs arg(0) > 0";
return; // Called wrong way -> spell bug.
}
|