1 //===== rAthena Script =======================================
2 //= Euphy's WOE Controller
3 //===== By: ==================================================
5 //===== Current Version: =====================================
7 //===== Compatible With: =====================================
9 //===== Description: =========================================
10 //= A controller for War of Emperium designed for
11 //= simplicity and ease of use.
12 //= Many concepts taken from ToastOfDoom's script,
13 //= and "rewards" function originally by Goddameit.
14 //===== Additional Comments: =================================
15 //= Be sure to disable the default agit controllers!
16 //== npc\guild\agit_controller.txt
17 //== npc\guild2\agit_start_se.txt
18 //============================================================
21 //============================================================
22 prontera,149,193,4 script WOE Information 835,{
23 doevent "WOE_CONTROL::OnMenu";
27 specialeffect EF_BEGINSPELL6;
34 //============================================================
35 - script WOE_CONTROL -1,{
36 function Disp_Owner; function Add_Zero;
40 // -----------------------------------------------------------
41 // Configuration settings.
42 // -----------------------------------------------------------
44 set .CastleWarp,0; // 1: Always enable all castle warps. | 0: Warp only to active castles.
45 set .AutoKick,1; // Automatically kick players from inactive castles during WOE? (1:yes / 0:no)
46 set .NoOwner,0; // Automatically kick players from unconquered castles outside of WOE? (1:yes / 0:no)
47 set .ExitWarp,0; // Warp all players from castles when WOE ends? (1:yes / 0:no)
48 set .GMAccess,99; // GM level required to access Session Manager.
50 // -----------------------------------------------------------
52 // -----------------------------------------------------------
53 // [1] Enable rewards.
54 // [2] Mail all rewards.
55 // - If not set, players receive items in their inventory.
56 // - Only ONE item can be sent via mail, plus Zeny.
57 // - Note that offline players do NOT receive rewards.
58 // [4] Only reward Guild Masters.
59 // - If not set, all guild members are rewarded.
60 // - If mailing is enabled (option 2), offline Guild Masters WILL receive rewards.
61 // [8] Duplicate IP check.
62 // - Members in a guild with the same IP address are not rewarded.
63 // - If Guild Masters is enabled (option 4), this feature is not used.
64 // -----------------------------------------------------------
66 // Combine values as needed (e.g. 1|8 = 1+8 = 9).
69 // Rewards per castle.
70 // -- when given directly: <itemID>,<amount>{,<itemID>,<amount>,...}
71 // -- via mail (option 2): <itemID>,<amount>,<Zeny>
72 setarray .Reward[0],14001,1;
74 // -----------------------------------------------------------
75 // Constants (leave this section alone).
76 // -----------------------------------------------------------
78 setarray .Castles$[0],
79 "prtg_cas01","prtg_cas02","prtg_cas03","prtg_cas04","prtg_cas05",
80 "payg_cas01","payg_cas02","payg_cas03","payg_cas04","payg_cas05",
81 "gefg_cas01","gefg_cas02","gefg_cas03","gefg_cas04","gefg_cas05",
82 "aldeg_cas01","aldeg_cas02","aldeg_cas03","aldeg_cas04","aldeg_cas05",
83 "arug_cas01","arug_cas02","arug_cas03","arug_cas04","arug_cas05",
84 "schg_cas01","schg_cas02","schg_cas03","schg_cas04","schg_cas05";
85 setarray .EndLabel$[0],"ar01","ar02","ar03","ar04","ar05","sc01","sc02","sc03","sc04","sc05";
86 setarray .Days$[0],"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday";
87 setarray .Regions$[0],"Prontera","Payon","Geffen","Aldebaran","Arunafeltz","Schwaltzvalt";
88 setarray .Map$[0],"prt_gld","pay_gld","gef_fild13","alde_gld","aru_gld","sch_gld";
89 setarray .MapX[0],134,240,153,111,208,121,295,317,140,204,214,308,143,193,305,48, 95,142,239,264,158,83, 68,299,292,293,288, 97,137, 71;
90 setarray .MapY[0], 65,128,137,240,240,233,116,293,160,266, 75,240,240,278, 87,83,249, 85,242, 90,272,47,155,345,107,100,252,196, 90,315;
92 // -----------------------------------------------------------
94 set .Size, getarraysize($WOE_CONTROL);
95 if (.AutoKick || .NoOwner)
96 for(set .@i,0; .@i<30; set .@i,.@i+1) {
97 setmapflag .Castles$[.@i], mf_loadevent;
98 setd "."+.Castles$[.@i], .@i;
100 if (!agitcheck() && !agitcheck2()) sleep 4000;
105 if (agitcheck() || agitcheck2()) {
106 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
107 if (gettime(DT_DAYOFWEEK) == $WOE_CONTROL[.@i] && gettime(DT_HOUR) == $WOE_CONTROL[.@i+2]) {
109 announce "The War Of Emperium is over!",bc_all|bc_woe;
112 for(set .@j,0; .@j<30; set .@j,.@j+1) {
113 if (.Active[0]&(1<<.@j)) Disp_Owner(.Castles$[.@j],1);
114 if (.ExitWarp) maprespawnguildid .Castles$[.@j],0,3;
116 if ((.Options&1) && .Active[0] && .ForceEnd != 2) callsub OnReward, .Active[0];
117 deletearray .Active[0],2;
118 if (.ForceEnd) { set .ForceEnd,0; end; }
122 if ((!agitcheck() && !agitcheck2()) || .Init) {
123 if (!agitcheck() && !agitcheck2()) set .Init,0;
124 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
125 if (gettime(DT_DAYOFWEEK) == $WOE_CONTROL[.@i] && gettime(DT_HOUR) >= $WOE_CONTROL[.@i+1] && gettime(DT_HOUR) < $WOE_CONTROL[.@i+2]) {
126 deletearray .Active[0],2;
127 set .Active[0], $WOE_CONTROL[.@i+3];
128 if (.Init) { AgitEnd; AgitEnd2; }
129 else announce "The War Of Emperium has begun!",bc_all|bc_woe;
131 AgitStart; AgitStart2;
132 for(set .@j,0; .@j<30; set .@j,.@j+1) {
133 if (.Active[0]&(1<<.@j)) {
134 if (!.Init) Disp_Owner(.Castles$[.@j],0);
135 set .Active[1], .Active[1] | (1<<((.@j/5)+1));
138 donpcevent "Agit#"+.Castles$[.@j]+"::OnAgitEnd";
139 killmonster .Castles$[.@j], "Agit#"+.Castles$[.@j]+"::OnAgitBreak";
141 donpcevent "Manager#"+.Castles$[.@j]+"::OnAgitEnd2";
142 killmonster .Castles$[.@j], "Steward#"+.EndLabel$[.@j-20]+"::OnStartArena";
152 function Disp_Owner {
153 set .@o, getcastledata(getarg(0),1);
154 if (.@o) announce "The ["+getcastlename(getarg(0))+"] castle "+((getarg(1))?"has been conquered":"is currently held")+" by the ["+getguildname(.@o)+"] guild.",bc_all|bc_woe;
155 else announce "The ["+getcastlename(getarg(0))+"] castle is currently unoccupied.",bc_all|bc_woe;
159 return ((getarg(0)<10)?"0":"")+getarg(0)+(getarg(1,0)?".":":")+"00";
163 set .@sql$, ((.Options&4)?"position = 0":"online = 1");
164 if (.Options&2) set .@str$,gettimestr("%B %d, %Y",21);
166 for(set .@i,0; .@i<30; set .@i,.@i+1)
167 if (getarg(0)&(1<<.@i)) {
168 set .@gid, getcastledata(.Castles$[.@i],1);
169 if (!.@gid) continue;
170 set .@size, query_sql("SELECT account_id,char_id FROM `guild_member` WHERE guild_id = '"+.@gid+"' AND "+.@sql$,.@aid,.@cid);
171 for(set .@j,0; .@j<.@size; set .@j,.@j+1) {
172 if ((.Options&8) && !(.Options&4)) {
173 set .@ip$, replacestr(getcharip(.@aid[.@j]),".","a");
174 if (getd(".@ip_"+.@i+"_"+.@ip$)) continue;
175 setd ".@ip_"+.@i+"_"+.@ip$,1;
178 query_sql("INSERT INTO `mail` (send_name,dest_id,title,message,nameid,amount,identify,zeny,time) VALUES ("+
179 "'no-reply',"+.@cid[.@j]+",'** Siege Reward: "+getcastlename(.Castles$[.@i])+" **',"+
180 "'Brave one,% % Congratulations!% Your guild has successfully occupied% territory in the War of Emperium on% "+.@str$+".% % % % % [ Your reward is attached. ]',"+
181 .Reward[0]+","+.Reward[1]+",0,"+.Reward[2]+",UNIX_TIMESTAMP(NOW()))");
182 if (!getd(".@str_"+.@cid[.@j]) && isloggedin(.@aid[.@j],.@cid[.@j])) {
183 setd ".@str_"+.@cid[.@j],1;
184 message rid2name(.@aid[.@j]),"You've got mail! Please re-login to update your mailing list.";
186 } else if (isloggedin(.@aid[.@j])) {
187 for(set .@k,0; .@k<getarraysize(.Reward); set .@k,.@k+2)
188 getitem .Reward[.@k], .Reward[.@k+1], .@aid[.@j];
189 message rid2name(.@aid[.@j]),"You have been rewarded for conquering "+getcastlename(.Castles$[.@i])+".";
193 if (.Options&2) query_sql("UPDATE `mail` SET message = REPLACE(message,'%',CHAR(13)) WHERE send_name = 'no-reply'");
197 if (!compare(strcharinfo(3),"g_cas")) end;
198 if (((.AutoKick && .Active[0]) || (.NoOwner && !getcastledata(strcharinfo(3),1))) && !(.Active[0]&(1<<getd("."+strcharinfo(3))))) {
199 if (getcharid(2) && getcastledata(strcharinfo(3),1) == getcharid(2)) end;
201 message strcharinfo(0), getcastlename(strcharinfo(3))+" is currently inactive.";
203 if (compare(strcharinfo(3),"g_cas")) warp "SavePoint",0,0;
209 mes "[WOE Information]";
210 if (agitcheck() || agitcheck2()) {
212 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
213 if (gettime(DT_DAYOFWEEK) == $WOE_CONTROL[.@i] && gettime(DT_HOUR) >= $WOE_CONTROL[.@i+1] && gettime(DT_HOUR) < $WOE_CONTROL[.@i+2]) {
214 set .@i, $WOE_CONTROL[.@i+2];
217 mes "The War of Emperium is ^0055FFactive^000000 until ^FF0000"+Add_Zero(.@i)+"^000000 in the following regions:";
219 for(set .@i,0; .@i<6; set .@i,.@i+1)
220 if (.Active[1]&(1<<(.@i+1))) mes " > ^777777"+.Regions$[.@i]+"^000000";
222 mes "The War of Emperium is ^0055FFactive^000000.";
224 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
225 if ((gettime(DT_DAYOFWEEK) == $WOE_CONTROL[.@i] && gettime(DT_HOUR) <= $WOE_CONTROL[.@i+1]) || gettime(DT_DAYOFWEEK) < $WOE_CONTROL[.@i]) {
226 setarray .@time[0],$WOE_CONTROL[.@i],$WOE_CONTROL[.@i+1];
229 if (!getarraysize(.@time))
230 setarray .@time[0],$WOE_CONTROL[0],$WOE_CONTROL[1];
231 mes "The War of Emperium is ^777777inactive^000000.";
234 mes "The next session will begin";
235 mes "on ^0055FF"+.Days$[.@time[0]]+"^000000 at "+Add_Zero(.@time[1])+"^000000.";
239 switch(select(""+((.CastleWarp || .Active[1])?" ~ Warp to castles...":"")+": ~ Check schedule...: ~ View castle owners...:"+((getgmlevel()<.GMAccess || !getgmlevel())?"":" ~ Manage sessions...")+": ~ ^777777Cancel^000000")) {
241 if (.CastleWarp) set .@clr$,"^0055FF";
243 for(set .@i,0; .@i<6; set .@i,.@i+1) {
244 if (.CastleWarp || .Active[1]&(1<<(.@i+1)))
245 set .@menu$, .@menu$+" ~ "+((.Active[1]&(1<<(.@i+1)))?.@clr$:"^777777")+.Regions$[.@i]+" Castles^000000";
246 set .@menu$, .@menu$+":";
248 set .@i, select(.@menu$)-1;
250 for(set .@j,.@i*5; .@j<(.@i*5)+5; set .@j,.@j+1) {
251 if (.CastleWarp || .Active[0]&(1<<.@j))
252 set .@menu$, .@menu$+" ~ "+((.Active[0]&(1<<.@j))?.@clr$:"^777777")+getcastlename(.Castles$[.@j])+"^000000";
253 set .@menu$, .@menu$+":";
255 set .@j, select(.@menu$)-1;
256 warp .Map$[.@i],.MapX[(.@i*5)+.@j],.MapY[(.@i*5)+.@j];
262 for(set .@i,0; .@i<.Size; set .@i,.@i+4) {
263 mes "> ^FF0000"+.Days$[$WOE_CONTROL[.@i]]+" ("+Add_Zero($WOE_CONTROL[.@i+1])+"-"+Add_Zero($WOE_CONTROL[.@i+2])+")^000000";
264 for(set .@j,0; .@j<30; set .@j,.@j+1)
265 if ($WOE_CONTROL[.@i+3]&(1<<.@j)) mes " ~ "+getcastlename(.Castles$[.@j])+" ^777777("+.Castles$[.@j]+")^000000";
266 if (.@i+4 < .Size) mes " ";
270 mes "No times are configured.";
274 mes "[Castle Ownership]";
275 for(set .@i,0; .@i<6; set .@i,.@i+1) {
277 mes "> ^FF0000"+.Regions$[.@i]+"^000000";
278 for(set .@j,.@k; .@j<(.@k+5); set .@j,.@j+1) {
279 set .@t, getcastledata(.Castles$[.@j],1);
280 mes " ~ "+getcastlename(.Castles$[.@j])+": "+((.@t)?"^0055FF"+getguildname(.@t):"^777777unoccupied")+"^000000";
282 if (.@i < 5) mes " ";
288 mes "[Session Manager]";
289 mes "There are ^0055FF"+(.Size/4)+" session(s)^000000 configured.";
290 mes "What would you like to do?";
292 switch(select(" ~ Add a session...: ~ Delete a session...: ~ Reload settings...:"+((agitcheck() || agitcheck2())?" ~ End WOE session...":"")+": ~ ^777777Go back^000000")) {
296 mes "You have already reached the maximum of 32 sessions.";
302 set .@Day, select(" ~ "+implode(.Days$,": ~ "))-1;
304 mes "Select a start time for ^0055FF"+.Days$[.@Day]+"^000000.";
307 for(set .@i,0; .@i<23; set .@i,.@i+1)
308 set .@menu$, .@menu$+" ~ "+Add_Zero(.@i,1)+":";
309 set .@Start, select(.@menu$)-1;
311 mes "Select an end time for ^0055FF"+.Days$[.@Day]+"^000000.";
314 for(set .@i,.@Start+1; .@i<24; set.@i,.@i+1)
315 set .@menu$, .@menu$+" ~ "+Add_Zero(.@i,1)+":";
316 set .@End, select(.@menu$)+.@Start;
317 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
318 if (.@Day == $WOE_CONTROL[.@i] &&
319 ((.@Start >= $WOE_CONTROL[.@i+1] && .@Start < $WOE_CONTROL[.@i+2]) ||
320 (.@End > $WOE_CONTROL[.@i+1] && .@End <= $WOE_CONTROL[.@i+2]) ||
321 (.@Start <= $WOE_CONTROL[.@i+1] && .@End >= $WOE_CONTROL[.@i+2]))) {
323 mes "The chosen times overlap with an existing session.";
328 if (.@d) { set .@d,0; break; }
332 mes "^0055FF"+.Days$[.@Day]+" ("+Add_Zero(.@Start)+"-"+Add_Zero(.@End)+")^000000";
335 mes " ~ ^777777(none selected)^000000";
336 else for(set .@i,0; .@i<30; set .@i,.@i+1)
337 if (.@Castle&(1<<.@i)) mes " ~ "+getcastlename(.Castles$[.@i])+" ("+.Castles$[.@i]+")";
339 set .@menu$,((.@Castle)?" ~ ^FF0000Finished...^000000":"")+":";
340 for(set .@i,0; .@i<30; set .@i,.@i+1)
341 set .@menu$, .@menu$+" ~ "+((.@Castle&(1<<.@i))?"^0055FF":"")+getcastlename(.Castles$[.@i])+" ("+.Castles$[.@i]+")^000000:";
342 set .@i, select(.@menu$)-1;
344 set .@Castle, .@Castle^(1<<(.@i-1));
349 switch(select(" ~ ^0055FFAdd session...^000000: ~ Continue selecting castles...: ~ ^777777Cancel^000000")) {
351 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
352 if ((.@Day == $WOE_CONTROL[.@i] && .@End <= $WOE_CONTROL[.@i+1]) || .@Day < $WOE_CONTROL[.@i]) {
356 if (!.@d) { set .@d,1; set .@i,.Size; }
357 copyarray $WOE_CONTROL[.@i+4], $WOE_CONTROL[.@i], .Size-.@i;
358 setarray $WOE_CONTROL[.@i], .@Day, .@Start, .@End, .@Castle;
359 set .Size, getarraysize($WOE_CONTROL);
362 mes ((.@d)?"Session added.":"Cancelled.");
368 if (.@d) { set .@d,0; break; }
373 mes "[Remove Session]";
375 mes "There are no sessions configured.";
379 mes "Select a session to remove.";
382 for(set .@i,0; .@i<.Size; set .@i,.@i+4)
383 set .@menu$, .@menu$+" ~ "+.Days$[$WOE_CONTROL[.@i]]+" ("+Add_Zero($WOE_CONTROL[.@i+1],1)+"-"+Add_Zero($WOE_CONTROL[.@i+2],1)+"):";
384 set .@menu$, .@menu$+" ~ ^777777Cancel^000000";
385 set .@i, select(.@menu$)-1;
386 if (.@i == (.Size/4)) break;
387 mes "[Remove Session]";
388 mes "Delete ^0055FF"+.Days$[$WOE_CONTROL[.@i*4]]+"'s^000000 session?";
389 mes "This action cannot be undone.";
391 set .@j, select(" ~ ^FF0000Delete session...^000000: ~ ^777777Cancel^000000");
392 mes "[Remove Session]";
396 deletearray $WOE_CONTROL[.@i*4],4;
397 set .Size, getarraysize($WOE_CONTROL);
398 mes "Session deleted.";
403 mes "[Reload Settings]";
404 mes "This will trigger all events related to new session configurations, if any.";
405 if (agitcheck() || agitcheck2()) {
407 mes "Be aware that this will disrupt the current WOE session.";
410 set .@i, select(" ~ ^0055FFReload settings...^000000: ~ ^777777Cancel^000000");
411 mes "[Reload Settings]";
412 if (.@i == 2) mes "Cancelled.";
415 donpcevent "WOE_CONTROL::OnMinute00";
416 mes "Variables have been re-initialized.";
421 mes "[Force Agit End]";
422 if (!agitcheck() && !agitcheck2()) {
423 mes "WOE has already ended.";
427 mes "This command will safely execute all AgitEnd events.";
429 mes "Kill the current WOE session?";
431 set .@i, select(" ~ ^FF0000End session...^000000:"+((.Options&1)?" ~ ^FF0000End session without rewards...^000000":"")+": ~ ^777777Cancel^000000");
432 mes "[Force Agit End]";
437 donpcevent "WOE_CONTROL::OnWOEEnd";
438 mes "WOE session terminated.";
445 if (.@d) { set .@d,0; break; }