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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
|
function script fightclub_sendrequest {
goto L_try;
L_try:
@loop = 0;
goto L_Loop;
L_Loop:
if(@Duel_Queue$[@loop] == @caster_name$) goto L_Exists;
if((@Duel_Queue$[@loop] == "") && (@Duel_Queue$[(@loop + 1)] == "")) goto L_Proceed;
if((@Duel_Queue$[@loop] == "") && (@Duel_Queue$[(@loop + 1)] != "")) goto L_ShiftQueue;
@loop = (@loop + 1);
if(@loop >= getarraysize(@Duel_Queue)) goto L_Full; // this shouldn't happen since we check in magic but we still handle it
goto L_Loop;
L_ShiftQueue:
@Duel_Queue$[@loop] = @Duel_Queue$[(@loop + 1)];
@Duel_Queue[@loop] = @Duel_Queue[(@loop + 1)];
@Duel_Queue$[(@loop + 1)] = "";
@Duel_Queue[(@loop + 1)] = 0;
@loop = (@loop + 1);
if(@loop >= getarraysize(@Duel_Queue)) goto L_try;
goto L_ShiftQueue;
L_Full:
message @caster_name$, "There is already "+ $@Duel_PlayerQueueLimit +" duel request(s) in the queue of this player, which is the maximum.";
return;
L_Exists:
message @caster_name$, "You already requested a duel with this player.";
return;
L_Proceed:
misceffect FX_MAGIC_DARKRED, @caster_name$;
message @caster_name$, "Your request has been sent.";
@Duel_Queue$[@loop] = @caster_name$;
@Duel_Queue[@loop] = gettimetick(2);
if(@Duel_Fighter == 0) message strcharinfo(0), "You have received a new duel request. Talk to Rouge to accept or decline.";
if(@Duel_Fighter == 0) misceffect FX_MAGIC_DARKRED, strcharinfo(0);
if(@Duel_Fighter == 1) set @Duel_HasPendingRequest, 1;
return;
}
function script fightclub_getrules {
$@fightclub_myself = getcharid(3);
if(@target < 1) goto L_Proceed; // get our own rules
if(attachrid(@target) == 1) goto L_Proceed;
goto L_Missing;
L_Proceed:
$@Temp_NoMagic = (DUELS & $@NoMagicBit);
if($@fightclub_myself == getcharid(3)) goto L_Proceed2; // the target is ourselves
if(attachrid($@fightclub_myself) == 1) goto L_Proceed2;
goto L_Missing;
L_Missing:
return;
L_Proceed2:
$@fightclub_myself = 0;
@target = 0;
if($@Temp_NoMagic == 0)
mes "(no rules)";
if($@Temp_NoMagic != 0) mes "- No Magic";
set $@Temp_NoMagic, 0; // now we clean these vars ASAP because they're globals
return;
}
function script fightclub_AddToQueue {
@ATQ_Loop = 0;
goto L_Loop;
L_Loop:
if(($@Duel_Queue_Blue$[@ATQ_Loop] == @caster_name$) && ($@Duel_Queue_Red$[@ATQ_Loop] == @target_name$)) goto L_Exists;
if(($@Duel_Queue_Red$[@ATQ_Loop] == @caster_name$) && ($@Duel_Queue_Blue$[@ATQ_Loop] == @target_name$)) goto L_Exists;
@ATQ_Loop = (@ATQ_Loop + 1);
if(@ATQ_Loop >= getarraysize($@Duel_Queue_ID)) goto L_Proceed2;
goto L_Loop;
L_Exists:
mes "This battle is already in the queue.";
return;
L_Full:
mes "There is already " + $@Duel_QueueLimit + " battles in the queue, which is the maximum. Please try again later.";
return;
L_Proceed2:
if(getarraysize($@Duel_Queue_ID) >= ($@Duel_QueueLimit + 1)) goto L_Full;
@index = getarraysize($@Duel_Queue_ID);
if(@index >= 1) goto L_Proceed22;
@index = 1;
goto L_Proceed22;
L_Proceed22:
if($@Duel_Queue_Red$[@index] != "") goto L_NotClean;
$@Duel_Queue_Red$[@index] = @caster_name$;
if($@Duel_Queue_Blue$[@index] != "") goto L_NotClean;
$@Duel_Queue_Blue$[@index] = @target_name$;
if($@Duel_Queue_ID[@index] != 0) goto L_NotClean;
$@Duel_Queue_ID[@index] = ($@Duel_Queue_ID[(@index - 1)] + 1);
if($@Duel_Queue_ID[@index] <= $Duel_LastDuel) goto L_FixId;
return;
L_NotClean:
message @caster_name$, "An error occured: array element not empty. Try again in 5 seconds.";
return;
L_FixId:
$@Duel_Queue_ID[@index] = ($Duel_LastDuel + 1);
return;
}
function script fightclub_NextBattle {
set $@Duel_Queue_Blue$[0], ""; // clean the 0 index
$@Duel_Queue_Red$[0] = "";
$@Duel_Queue_ID[0] = 0;
set $@Duel_Loop, 1; // start the loop at 1
goto L_Loop;
L_Loop: // here we shift the array to the left
if($@Duel_Queue_ID[$@Duel_Loop] < 1) goto L_Empty;
$@Duel_Queue_Red$[($@Duel_Loop - 1)] = $@Duel_Queue_Red$[$@Duel_Loop];
set $@Duel_Queue_Red$[$@Duel_Loop], ""; // it is always important to clean
$@Duel_Queue_Blue$[($@Duel_Loop - 1)] = $@Duel_Queue_Blue$[$@Duel_Loop];
$@Duel_Queue_Blue$[$@Duel_Loop] = "";
$@Duel_Queue_ID[($@Duel_Loop - 1)] = $@Duel_Queue_ID[$@Duel_Loop];
$@Duel_Queue_ID[$@Duel_Loop] = 0;
$@Duel_Loop = ($@Duel_Loop + 1);
if($@Duel_Loop >= getarraysize($@Duel_Queue_ID)) goto L_Proceed;
goto L_Loop;
L_Empty:
// the queue is now empty
return;
L_Proceed:
callfunc "fightclub_CleanStage";
set $@Duel_CurrentDuel, $@Duel_Queue_ID[0]; // since the array is shifted, the index is always 0
set $Duel_LastDuel, $@Duel_Queue_ID[0]; // this is used to keep the same index across reboots
$@Duel_BluePlayer = getcharid(3,$@Duel_Queue_Blue$[0]);
$@Duel_RedPlayer = getcharid(3,$@Duel_Queue_Red$[0]);
if(attachrid($@Duel_BluePlayer) != 1) goto L_Missing;
if(attachrid($@Duel_RedPlayer) == 1) goto L_Proceed2;
goto L_Missing;
L_Missing:
callfunc "fightclub_CleanStage";
callfunc "fightclub_NextBattle";
return;
L_Proceed2:
addtimer ($@Duel_TimeBeforeNext * 1000), "#FightClubUtils::OnDelayedNextBattle";
return;
}
function script fightclub_NextBattleProceed {
$@Duel_NoMagic = 0;
if((DUELS & $@NoMagicBit) != 0) set $@Duel_NoMagic, 1; // get the rules of the caster
donpcevent "Rouge#Duels::OnAnnounceNext";
$@Duel_Started = 0;
addtimer ($@Duel_TimeBeforeWarp * 1000), "#FightClubUtils::OnDelayedStart";
return;
}
function script fightclub_StartBattle {
$@Duel_Started = 1;
npcwarp 40, 45, "Rouge#Duels";
donpcevent "#FightClubTimeLimit::OnStartTimer";
if(attachrid($@Duel_RedPlayer) != 1) goto L_Missing;
callfunc "fightclub_enter";
if(attachrid($@Duel_BluePlayer) != 1) goto L_Missing;
callfunc "fightclub_enter";
return;
L_Missing:
callfunc "fightclub_CleanStage";
callfunc "fightclub_NextBattle";
return;
}
function script fightclub_TimeOut {
donpcevent "Rouge#Duels::OnAnnounceTimeOut";
if(attachrid($@Duel_RedPlayer) != 1) goto L_Missing;
callfunc "fightclub_exit";
if(attachrid($@Duel_BluePlayer) != 1) goto L_Missing;
callfunc "fightclub_exit";
callfunc "fightclub_CleanStage";
callfunc "fightclub_NextBattle";
return;
L_Missing:
callfunc "fightclub_CleanStage";
callfunc "fightclub_NextBattle";
return;
}
function script fightclub_Intrusion {
// nothing to do here (yet)
return;
}
function script fightclub_EmergencyWipe {
callfunc "fightclub_CleanStage";
callfunc "fightclub_StartUp";
// TODO: check if everything is clean (function) and mapexit otherwise
return;
}
function script fightclub_Victory {
// TODO: give some sort of reward
// TODO: increase score
// TODO: update leaderboard
return;
}
function script fightclub_DestroyMe {
@Duel_Fighter = 0;
setpvpchannel @previous_channel;
sc_end 132; sc_end 14; sc_end 37; sc_end 185; sc_end 194; sc_end 195; sc_end 196; sc_end 197; sc_end 198; sc_end 199; // remove effects
heal MaxHp, MaxSp; // refill hp/mana
if(getmapname() == "009-7") warp "009-7", rand($@fightclub_x1, $@fightclub_x2), rand(($@fightclub_y1 - 2), ($@fightclub_y1 - 3));
return;
}
function script fightclub_Missing {
// $@Duel_Missing 1 = red, 2 = blue
if (attachrid($@Duel_BluePlayer) == 1) goto L_Proceed; // we need to attach to at least one player
if (attachrid($@Duel_RedPlayer) == 1) goto L_Proceed;
goto L_Resume; // can't attach either of them (this is not a problem since it means they are offline so their vars are clean anyway)
L_Proceed:
if($@Duel_Missing == 1) goto L_BlueWins;
goto L_RedWins;
L_BlueWins:
donpcevent "Rouge#Duels::OnAnnounceBlueForfeit";
$@duel_winner = $@Duel_BluePlayer;
callfunc "fightclub_Victory";
goto L_Clean;
L_RedWins:
donpcevent "Rouge#Duels::OnAnnounceRedForfeit";
$@duel_winner = $@Duel_RedPlayer;
callfunc "fightclub_Victory";
goto L_Clean;
L_KillBlue:
callfunc "fightclub_exit";
if(attachrid($@Duel_RedPlayer) == 1) goto L_KillRed;
goto L_Resume;
L_KillRed:
callfunc "fightclub_exit";
goto L_Resume;
L_Clean:
if(attachrid($@Duel_BluePlayer) == 1) goto L_KillBlue;
if(attachrid($@Duel_RedPlayer) == 1) goto L_KillRed;
goto L_Resume; // couldn't kill them
L_Resume:
callfunc "fightclub_CleanStage";
callfunc "fightclub_NextBattle";
return;
}
function script fightclub_StartUp {
if($@Duel_TimeBeforeNext < 1) set $@Duel_TimeBeforeNext, 5; // init the (temporary) TimeBeforeNext global
if($@Duel_TimeBeforeWarp < 1) set $@Duel_TimeBeforeWarp, 5; // init the (temporary) TimeBeforeWarp global
if($@Duel_TimeBeforeStart < 1) set $@Duel_TimeBeforeStart, 3; // init the (temporary) TimeBeforeStart global
if($@Duel_TimeLimit < 1) set $@Duel_TimeLimit, 120; // init the (temporary) TimeLimit global
if($@Duel_QueueLimit < 1) set $@Duel_QueueLimit, 5; // init the (temporary) QueueLimit global
if($@Duel_PlayerQueueLimit < 1) set $@Duel_PlayerQueueLimit, 2; // init the (temporary) PlayerQueueLimit global
if($@Duel_PlayerQueueTimeOut < 1) set $@Duel_PlayerQueueTimeOut, 300; // init the (temporary) PlayerQueueTimeOut global
setarray $@Duel_Queue_ID, 0;
cleararray $@Duel_Queue_ID, 0, ($@Duel_QueueLimit + 1);
setarray $@Duel_Queue_Blue$, "";
cleararray $@Duel_Queue_Blue$, "", ($@Duel_QueueLimit + 1);
setarray $@Duel_Queue_Red$, "";
cleararray $@Duel_Queue_Red$, "", ($@Duel_QueueLimit + 1);
$@Duel_TotalTime = 0;
$@Duel_Channel = 20;
if($fightclub_enabled) set $fightclub_enabled, 0; // this var moved to $SANGUINE
// DUELS flags below
$@DuelPvpBit = (1 << 1);
$@NoMagicBit = (1 << 2);
// $SANGUINE flags below
$@SV_FCDBit = (1 << 1);
$@SV_BMDBit = (1 << 2);
return;
}
function script fightclub_CleanStage {
if($@Duel_NoWarp != 1) areawarp "009-7", $@fightclub_x1, $@fightclub_y1, $@fightclub_x2, $@fightclub_y2, "009-7", 31, 40; // kick all players from stage
$@Duel_NoWarp = 0;
set $@Duel_NoMagic, 0; // clean the Duel parameters
set $@Duel_CurrentDuel, 0; // no duel atm
set $@Duel_Started, 0; // no duel atm
$@Duel_RedPlayer = 0;
$@Duel_BluePlayer = 0;
$@Duel_Missing = 0;
$@Duel_TotalTime = 0;
npcwarp 32, 45, "Rouge#Duels";
donpcevent "#FightClubTimeLimit::OnStopTimer";
killmonster "009-7", "All";
return;
}
function script fightclub_setrules {
goto L_Main;
L_Main:
mes "Your rules are the following: "; mes "";
callfunc "fightclub_getrules";
mes ""; mes "What do you want to do?";
menu
"Change my rules.", L_Start,
"Nevermind.", L_Return;
L_Start:
DUELS = DUELS | $@NoMagicBit;
goto L_NoMagic;
L_NoMagic:
mes "Do you want to allow magic?";
mes "If disabled, the fighters will not be able to use any kind of spell.";
menu
"Yes.", L_NoMagicYes,
"No.", L_Done;
L_NoMagicYes:
DUELS = DUELS &~ $@NoMagicBit;
goto L_Done;
L_Done:
next;
mes "You have succesfully changed your options.";
goto L_Main;
L_Return:
return;
}
function script fightclub_death {
if(@Duel_Fighter != 1) goto L_NoDuel;
if(($@Duel_CurrentDuel < 1) || ($@Duel_Started != 1)) goto L_Reset;
if(@killerrid != 0) goto L_Murdered;
goto L_Killed;
L_Killed:
if(getcharid(3) == $@Duel_RedPlayer) goto L_BlueWins;
goto L_RedWins;
L_RedWins:
donpcevent "Rouge#Duels::OnAnnounceRedWins";
$@duel_winner = $@Duel_RedPlayer;
callfunc "fightclub_Victory";
callfunc "fightclub_exit";
if(attachrid($@Duel_RedPlayer) == 1) goto L_RedWins2;
goto L_Missing;
L_RedWins2:
callfunc "fightclub_exit";
goto L_Proceed;
L_BlueWins:
donpcevent "Rouge#Duels::OnAnnounceBlueWins";
$@duel_winner = $@Duel_BluePlayer;
callfunc "fightclub_Victory";
callfunc "fightclub_exit";
if(attachrid($@Duel_BluePlayer) == 1) goto L_BlueWins2;
goto L_Missing;
L_Missing:
goto L_Proceed;
L_BlueWins2:
callfunc "fightclub_exit";
goto L_Proceed;
L_Proceed:
callfunc "fightclub_CleanStage";
return;
L_Murdered:
if(($@Duel_RedPlayer != @killerrid) && ($@Duel_BluePlayer != @killerrid)) goto L_Stranger;
goto L_Killed; // now we proceed the same way as L_Killed
L_Stranger:
// the victim was not murdered by its adversary (wtf)
if(debug) donpcevent "Debug#Duels::OnKillerNotInDuel";
callfunc "fightclub_EmergencyWipe";
return;
L_NoDuel:
if(debug) donpcevent "Debug#Duels::OnVictimNotInDuel";
return;
L_Reset: // the player has duel_fighter but no duel is ongoing (happens if the player quit before fightclub_exit can be called)
if(debug) donpcevent "Debug#Duels::OnVictimInDuelNoDuel";
callfunc "fightclub_DestroyMe"; // here we attempt to resume the interrupted procedure
return;
}
function script fightclub_enter {
@Duel_Fighter = 1;
warp "009-7", rand($@fightclub_x1,$@fightclub_x2), rand($@fightclub_y1,$@fightclub_y2);
heal MaxHp, MaxSp; // ensure that you can't duel wih a corpse
sc_end 132; sc_end 14; sc_end 37; sc_end 185; sc_end 194; sc_end 195; sc_end 196; sc_end 197; sc_end 198; sc_end 199; // remove effects
message strcharinfo(0), "Get Ready.";
addtimer ($@Duel_TimeBeforeStart * 1000), "#FightClubUtils::OnBecomeKiller"; // call fightclub_enter_killer in 3 seconds
return;
}
function script fightclub_enter_killer {
if(getpvpflag(0) != $@Duel_Channel) set @previous_channel, getpvpflag(0);
setpvpchannel $@Duel_Channel;
message strcharinfo(0), "GO !";
return;
}
function script fightclub_exit {
callfunc "fightclub_DestroyMe"; // kill and reset state
message strcharinfo(0), "Thank you for participating in the fight club!";
if(@Duel_HasPendingRequest) message strcharinfo(0), "You have received a new duel request.";
return;
}
function script fightclub_event_killed {
@duel_killer = 0;
if(@Duel_Fighter != 1) goto L_End;
if(getmapname() != "009-7") goto L_End;
set $@duel_loser, getcharid(3); // grab the rid of the victim
set $@duel_winner, @killerrid; // grab the rid of the killer
set @killerrid, 0; // reset killerid
callfunc "fightclub_death";
goto L_End;
L_End:
if(getpvpflag(0) == $@Duel_Channel) setpvpflag @previous_channel;
return;
}
function script fightclub_event_die {
@duel_killer = 0;
if(@Duel_Fighter != 1) goto L_End;
if(getmapname() != "009-7") goto L_End;
set @killerrid, 0; // since the player was not murdered, the killerrid is 0
set $@duel_loser, getcharid(3); // grab the rid of the victim
callfunc "fightclub_death";
goto L_End;
L_End:
if(getpvpflag(0) == $@Duel_Channel) setpvpflag @previous_channel;
return;
}
|