OSDN Git Service

First version
[st-ro/stro.git] / npc / custom / woe_controller.txt
1 //===== rAthena Script =======================================
2 //= Euphy's WOE Controller
3 //===== By: ==================================================
4 //= Euphy
5 //===== Current Version: =====================================
6 //= 1.5
7 //===== Compatible With: =====================================
8 //= rAthena Project
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 //============================================================
19
20 // Information NPC
21 //============================================================
22 prontera,149,193,4      script  WOE Information 835,{
23         doevent "WOE_CONTROL::OnMenu";
24         end;
25 OnAgitStart:
26         while(agitcheck()) {
27                 specialeffect EF_BEGINSPELL6;
28                 sleep 425;
29         }
30         end;
31 }
32
33 // Script Core
34 //============================================================
35 -       script  WOE_CONTROL     -1,{
36 function Disp_Owner; function Add_Zero;
37
38 OnInit:
39
40 // -----------------------------------------------------------
41 //  Configuration settings.
42 // -----------------------------------------------------------
43
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.
49
50 // -----------------------------------------------------------
51 //  Reward options.
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 // -----------------------------------------------------------
65
66         // Combine values as needed (e.g. 1|8 = 1+8 = 9).
67         set .Options, 1|8;
68
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;
73
74 // -----------------------------------------------------------
75 //  Constants (leave this section alone).
76 // -----------------------------------------------------------
77
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;
91
92 // -----------------------------------------------------------
93
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;
99                 }
100         if (!agitcheck() && !agitcheck2()) sleep 4000;
101         set .Init,1;
102
103 OnMinute00:
104         freeloop(1);
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]) {
108                         OnWOEEnd:
109                                 announce "The War Of Emperium is over!",bc_all|bc_woe;
110                                 AgitEnd; AgitEnd2;
111                                 sleep 1000;
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;
115                                 }
116                                 if ((.Options&1) && .Active[0] && .ForceEnd != 2) callsub OnReward, .Active[0];
117                                 deletearray .Active[0],2;
118                                 if (.ForceEnd) { set .ForceEnd,0; end; }
119                                 break;
120                         }
121         }
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;
130                                 sleep 1000;
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));
136                                         } else {
137                                                 if (.@j<20) {
138                                                         donpcevent "Agit#"+.Castles$[.@j]+"::OnAgitEnd";
139                                                         killmonster .Castles$[.@j], "Agit#"+.Castles$[.@j]+"::OnAgitBreak";
140                                                 } else {
141                                                         donpcevent "Manager#"+.Castles$[.@j]+"::OnAgitEnd2";
142                                                         killmonster .Castles$[.@j], "Steward#"+.EndLabel$[.@j-20]+"::OnStartArena";
143                                                 }
144                                         }
145                                 }
146                                 break;
147                         }
148         }
149         set .Init,0;
150         end;
151
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;
156         return;
157 }
158 function Add_Zero {
159         return ((getarg(0)<10)?"0":"")+getarg(0)+(getarg(1,0)?".":":")+"00";
160 }
161
162 OnReward:
163         set .@sql$, ((.Options&4)?"position = 0":"online = 1");
164         if (.Options&2) set .@str$,gettimestr("%B %d, %Y",21);
165         freeloop(1);
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;
176                                 }
177                                 if (.Options&2) {
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.";
185                                         }
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])+".";
190                                 }
191                         }
192                 }
193         if (.Options&2) query_sql("UPDATE `mail` SET message = REPLACE(message,'%',CHAR(13)) WHERE send_name = 'no-reply'");
194         return;
195
196 OnPCLoadMapEvent:
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;
200                 sleep2 1000;
201                 message strcharinfo(0), getcastlename(strcharinfo(3))+" is currently inactive.";
202                 sleep2 5000;
203                 if (compare(strcharinfo(3),"g_cas")) warp "SavePoint",0,0;
204         }
205         end;
206
207 OnMenu:
208 while(1) {
209         mes "[WOE Information]";
210         if (agitcheck() || agitcheck2()) {
211                 if (.Active[0]) {
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];
215                                         break;
216                                 }
217                         mes "The War of Emperium is ^0055FFactive^000000 until ^FF0000"+Add_Zero(.@i)+"^000000 in the following regions:";
218                         mes " ";
219                         for(set .@i,0; .@i<6; set .@i,.@i+1)
220                                 if (.Active[1]&(1<<(.@i+1))) mes " > ^777777"+.Regions$[.@i]+"^000000";
221                 } else
222                         mes "The War of Emperium is ^0055FFactive^000000.";
223         } else {
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];
227                                 break;
228                         }
229                 if (!getarraysize(.@time))
230                         setarray .@time[0],$WOE_CONTROL[0],$WOE_CONTROL[1];
231                 mes "The War of Emperium is ^777777inactive^000000.";
232                 if (.Size) {
233                         mes " ";
234                         mes "The next session will begin";
235                         mes "on ^0055FF"+.Days$[.@time[0]]+"^000000 at "+Add_Zero(.@time[1])+"^000000.";
236                 }
237         }
238         next;
239         switch(select(""+((.CastleWarp || .Active[1])?" ~ Warp to castles...":"")+": ~ Check schedule...: ~ View castle owners...:"+((getgmlevel()<.GMAccess || !getgmlevel())?"":" ~ Manage sessions...")+": ~ ^777777Cancel^000000")) {
240         case 1:
241                 if (.CastleWarp) set .@clr$,"^0055FF";
242                 set .@menu$,"";
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$+":";
247                 }
248                 set .@i, select(.@menu$)-1;
249                 set .@menu$,"";
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$+":";
254                 }
255                 set .@j, select(.@menu$)-1;
256                 warp .Map$[.@i],.MapX[(.@i*5)+.@j],.MapY[(.@i*5)+.@j];
257                 close;
258         case 2:
259                 mes "[Schedule]";
260                 if (.Size) {
261                         freeloop(1);
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 " ";
267                         }
268                         freeloop(0);
269                 } else
270                         mes "No times are configured.";
271                 next;
272                 break;
273         case 3:
274                 mes "[Castle Ownership]";
275                 for(set .@i,0; .@i<6; set .@i,.@i+1) {
276                         set .@k, .@i*5;
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";
281                         }
282                         if (.@i < 5) mes " ";
283                 }
284                 next;
285                 break;
286         case 4:
287         while(1) {
288                 mes "[Session Manager]";
289                 mes "There are ^0055FF"+(.Size/4)+" session(s)^000000 configured.";
290                 mes "What would you like to do?";
291                 next;
292                 switch(select(" ~ Add a session...: ~ Delete a session...: ~ Reload settings...:"+((agitcheck() || agitcheck2())?" ~ End WOE session...":"")+": ~ ^777777Go back^000000")) {
293                 case 1:
294                         mes "[New Session]";
295                         if (.Size > 127) {
296                                 mes "You have already reached the maximum of 32 sessions.";
297                                 next;
298                                 break;
299                         }
300                         mes "Select a day.";
301                         next;
302                         set .@Day, select(" ~ "+implode(.Days$,": ~ "))-1;
303                         mes "[New Session]";
304                         mes "Select a start time for ^0055FF"+.Days$[.@Day]+"^000000.";
305                         next;
306                         set .@menu$,"";
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;
310                         mes "[New Session]";
311                         mes "Select an end time for ^0055FF"+.Days$[.@Day]+"^000000.";
312                         next;
313                         set .@menu$,"";
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]))) {
322                                         mes "[New Session]";
323                                         mes "The chosen times overlap with an existing session.";
324                                         next;
325                                         set .@d,1;
326                                         break;
327                                 }
328                         if (.@d) { set .@d,0; break; }
329                         set .@Castle,0;
330                         while(1) {
331                                 mes "[New Session]";
332                                 mes "^0055FF"+.Days$[.@Day]+" ("+Add_Zero(.@Start)+"-"+Add_Zero(.@End)+")^000000";
333                                 mes " > Castles:";
334                                 if (!.@Castle)
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]+")";
338                                 next;
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;
343                                 if (.@i)
344                                         set .@Castle, .@Castle^(1<<(.@i-1));
345                                 else {
346                                         mes "[New Session]";
347                                         mes "Are you sure?";
348                                         next;
349                                         switch(select(" ~ ^0055FFAdd session...^000000: ~ Continue selecting castles...: ~ ^777777Cancel^000000")) {
350                                         case 1:
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]) {
353                                                                 set .@d,1;
354                                                                 break;
355                                                         }
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);
360                                         case 3:
361                                                 mes "[New Session]";
362                                                 mes ((.@d)?"Session added.":"Cancelled.");
363                                                 next;
364                                                 set .@d,1;
365                                         case 2:
366                                                 break;
367                                         }
368                                         if (.@d) { set .@d,0; break; }
369                                 }
370                         }
371                         break;
372                 case 2:
373                         mes "[Remove Session]";
374                         if (!.Size) {
375                                 mes "There are no sessions configured.";
376                                 next;
377                                 break;
378                         }
379                         mes "Select a session to remove.";
380                         next;
381                         set .@menu$,"";
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.";
390                         next;
391                         set .@j, select(" ~ ^FF0000Delete session...^000000: ~ ^777777Cancel^000000");
392                         mes "[Remove Session]";
393                         if (.@j == 2)
394                                 mes "Cancelled.";
395                         else {
396                                 deletearray $WOE_CONTROL[.@i*4],4;
397                                 set .Size, getarraysize($WOE_CONTROL);
398                                 mes "Session deleted.";
399                         }
400                         next;
401                         break;
402                 case 3:
403                         mes "[Reload Settings]";
404                         mes "This will trigger all events related to new session configurations, if any.";
405                         if (agitcheck() || agitcheck2()) {
406                                 mes " ";
407                                 mes "Be aware that this will disrupt the current WOE session.";
408                         }
409                         next;
410                         set .@i, select(" ~ ^0055FFReload settings...^000000: ~ ^777777Cancel^000000");
411                         mes "[Reload Settings]";
412                         if (.@i == 2) mes "Cancelled.";
413                         else {
414                                 set .Init,1;
415                                 donpcevent "WOE_CONTROL::OnMinute00";
416                                 mes "Variables have been re-initialized.";
417                         }
418                         next;
419                         break;
420                 case 4:
421                         mes "[Force Agit End]";
422                         if (!agitcheck() && !agitcheck2())  {
423                                 mes "WOE has already ended.";
424                                 next;
425                                 break;
426                         }
427                         mes "This command will safely execute all AgitEnd events.";
428                         mes " ";
429                         mes "Kill the current WOE session?";
430                         next;
431                         set .@i, select(" ~ ^FF0000End session...^000000:"+((.Options&1)?" ~ ^FF0000End session without rewards...^000000":"")+": ~ ^777777Cancel^000000");
432                         mes "[Force Agit End]";
433                         if (.@i == 3)
434                                 mes "Cancelled.";
435                         else {
436                                 set .ForceEnd, .@i;
437                                 donpcevent "WOE_CONTROL::OnWOEEnd";
438                                 mes "WOE session terminated.";
439                         }
440                         next;
441                         break;
442                 case 5:
443                         set .@d,1; break;
444                 }
445                 if (.@d) { set .@d,0; break; }
446                 } break;
447         case 5:
448                 close;
449         } }
450 }