//===== eAthena Script =======================================
//= War of Emperium - WoE Auto-Start
//===== By: ==================================================
//= kalen (1.0)
//= 1.1 by Akaru and ho|yAnge|
//===== Current Version: =====================================
//= 1.8b
//===== Compatible With: =====================================
//= eAthena 0.1+; RO Episode 4+
//===== Description: =========================================
//= Auto Start for War of Emperium
//=============================================
//= gettime(3): Gets hour (24 hour time)
//= gettime(4): Gets day of week 1=Monday, 2=Tuesday,
//= 3=Wednesday, 4=Thursday, etc.
//===== Additional Comments: =================================
//= v1.1a changed OnInit to OnAgitInit.[kobra_k88]
//= v1.2 added gettime checks. removed $AgitStarted var.[kobra_k88]
//= v1.3 Moved treasure spawn time here.[kobra_k88]
//= v1.3a Implemented Shadowlady's idea to allow for different
//= start/stop times on different days.[kobra_k88]
//= 1.4 Fixed treasure chests spawn! We had to unroll some loops
//= Now they appear in castles from 00:01 to 00:24. [Lupus]
//= 1.5 Fixed WOE end messages on non-WOE days, by Avaj
//= 1.5a missing tabs [KarLaeda]
//= 1.6 Corrected multiple "WoE has begun" announces [ultramage]
//= 1.7 Commented out the WoE start and end announces. [L0ne_W0lf]
//= 1.8 Castle owners displayed when WoE starts and finished. [L0ne_W0lf]
//= 1.8a Will now report unoccupied castles at start/end. [L0ne_W0lf]
//= 1.8b Whoops. Fixed a mistake :D [L0ne_W0lf]
//============================================================
//| To know how to set up WoE times, go to doc\woe_time_explanation.txt
// WoE Start/Stop times
//======================================
-	script	Agit_Event	-1,{
	end;

OnClock2100:	//start time for Tues(2), Thurs(4)
OnClock2300:	//end time for Tues(2), Thurs(4)
OnClock1600:	//start time for Sat(6)
OnClock1800:	//end time for Sat(6)

OnAgitInit:
	// starting time checks
	if((gettime(4)==2) && (gettime(3)>=21 && gettime(3)<23)) goto L_Start;
	if((gettime(4)==4) && (gettime(3)>=21 && gettime(3)<23)) goto L_Start;
	if((gettime(4)==6) && (gettime(3)>=16 && gettime(3)<18)) goto L_Start;

	// end time checks
	if((gettime(4)==2) && (gettime(3)==23)) goto L_End;
	if((gettime(4)==4) && (gettime(3)==23)) goto L_End;
	if((gettime(4)==6) && (gettime(3)==18)) goto L_End;
	end;

L_End:
	if (agitcheck()) {
		//Announce "The War Of Emperium is over!",8;
		AgitEnd;
		goto L_DisplayOwners;
	}
	end;

L_Start:
	if (!agitcheck()) {
		//Announce "The War Of Emperium has begun!",8;
		AgitStart;
		goto L_DisplayOwners;
	}
	end;

L_DisplayOwners:
	setarray .@maps$[0],"aldeg_cas01","aldeg_cas02","aldeg_cas03","aldeg_cas04","aldeg_cas05";
	setarray .@maps$[5],"gefg_cas01","gefg_cas02","gefg_cas03","gefg_cas04","gefg_cas05";
	setarray .@maps$[10],"payg_cas01","payg_cas02","payg_cas03","payg_cas04","payg_cas05";
	setarray .@maps$[15],"prtg_cas01","prtg_cas02","prtg_cas03","prtg_cas04","prtg_cas05";
	for( set .@i, 0; .@i <= 19; set .@i, .@i+1 ) {
		if (GetCastleData(.@maps$[.@i],1)) {
			Announce "The [" + GetCastleName(.@maps$[.@i]) + "] castle has been conquered by the [" + GetGuildName(GetCastleData(.@maps$[.@i],1)) + "] guild.",bc_all;
		}
		else {
			Announce "The [" + GetCastleName(.@maps$[.@i]) + "] castle is currently unoccupied.",bc_all;
		}		
	}
	end;
}

// Treasure Spawn Time
//========================================
-	script	TreasSpawn	-1,{
	end;

// Please explain the relevence of this to me?
// Why are we spawning chests per zone on 1 minute intervals?
// They should al spawn at the same time in the same castle.
// Is there a reason for this? Am I reading something wrong?

OnClock0001:
	callfunc "F_GldTreas","aldeg_cas01","A01",$boxNumA01,$@bxA01,$@boxIdA01,1324,114,218,123,227,0;
	callfunc "F_GldTreas","aldeg_cas02","A02",$boxNumA02,$@bxA02,$@boxIdA02,1326,130,226,138,235,0;
	callfunc "F_GldTreas","aldeg_cas03","A03",$boxNumA03,$@bxA03,$@boxIdA03,1328,220,264,229,273,0;
	callfunc "F_GldTreas","aldeg_cas04","A04",$boxNumA04,$@bxA04,$@boxIdA04,1330,80,8,89,17,0;
	callfunc "F_GldTreas","aldeg_cas05","A05",$boxNumA05,$@bxA05,$@boxIdA05,1332,58,8,65,15,0;
	end;
OnClock0002:
	callfunc "F_GldTreas","gefg_cas01","G01",$boxNumG01,$@bxG01,$@boxIdG01,1334,150,108,158,114,0;
	callfunc "F_GldTreas","gefg_cas02","G02",$boxNumG02,$@bxG02,$@boxIdG02,1336,136,112,145,118,0;
	callfunc "F_GldTreas","gefg_cas03","G03",$boxNumG03,$@bxG03,$@boxIdG03,1338,266,286,275,293,0;
	callfunc "F_GldTreas","gefg_cas04","G04",$boxNumG04,$@bxG04,$@boxIdG04,1340,112,114,119,123,0;
	callfunc "F_GldTreas","gefg_cas05","G05",$boxNumG05,$@bxG05,$@boxIdG05,1342,140,106,147,113,0;
	end;
OnClock0003:
	callfunc "F_GldTreas","payg_cas01","Py01",$boxNumPy01,$@bxPy01,$@boxIdPy01,1344,286,4,295,13,0;
	callfunc "F_GldTreas","payg_cas02","Py02",$boxNumPy02,$@bxPy02,$@boxIdPy02,1346,140,140,148,149,0;
	callfunc "F_GldTreas","payg_cas03","Py03",$boxNumPy03,$@bxPy03,$@boxIdPy03,1348,154,164,162,173,0;
	callfunc "F_GldTreas","payg_cas04","Py04",$boxNumPy04,$@bxPy04,$@boxIdPy04,1350,142,44,151,51,0;
	callfunc "F_GldTreas","payg_cas05","Py05",$boxNumPy05,$@bxPy05,$@boxIdPy05,1352,152,128,160,135,0;
	end;
OnClock0004:
	callfunc "F_GldTreas","prtg_cas01","Pt01",$boxNumPt01,$@bxPt01,$@boxIdPt01,1354,6,204,15,213,0;
	callfunc "F_GldTreas","prtg_cas02","Pt02",$boxNumPt02,$@bxPt02,$@boxIdPt02,1356,198,224,207,233,0;
	callfunc "F_GldTreas","prtg_cas03","Pt03",$boxNumPt03,$@bxPt03,$@boxIdPt03,1358,184,128,193,135,0;
	callfunc "F_GldTreas","prtg_cas04","Pt04",$boxNumPt04,$@bxPt04,$@boxIdPt04,1360,266,158,275,167,0;
	callfunc "F_GldTreas","prtg_cas05","Pt05",$boxNumPt05,$@bxPt05,$@boxIdPt05,1362,272,174,279,181,0;
	end;
OnClock0005:
	callfunc "F_GldTreas","nguild_alde","N01",$boxNumN01,$@bxN01,$@boxIdN01,1324,114,218,123,227,0;
	callfunc "F_GldTreas","nguild_gef","N02",$boxNumN02,$@bxN02,$@boxIdN02,1334,150,108,158,114,0;
	callfunc "F_GldTreas","nguild_pay","N03",$boxNumN03,$@bxN03,$@boxIdN03,1344,286,4,295,13,0;
	callfunc "F_GldTreas","nguild_prt","N04",$boxNumN04,$@bxN04,$@boxIdN04,1354,6,204,15,213,0;
	end;
}
