// @unloadnpc dreward
// @loadnpc npc/thor/dailyreward.txt

-	script	dreward	-1,{
OnWhisperGlobal:
OnLoginCmnd:
	if (getgroupid() == 4) end;
	attachnpctimer ""+strcharinfo(0)+"";
	initnpctimer;
	if (!#DRewardCon){ 
		set .@xg,1;
	} else {
		set .@xg,#DRewardCon;
	}
	cutin "dr00",4;
	
	if (#LastDailyReward && !#RewardWait) {
		set .@ilog, (gettime(GETTIME_YEAR) * 365 * 24 * 60) + (gettime(GETTIME_DAYOFYEAR) * 24 * 60) + (gettime(GETTIME_HOUR) * 60) + gettime(GETTIME_MINUTE);
		set .@days,(#LastDailyReward + .MinWait - .@ilog)/60/24;
		set .@hours,((#LastDailyReward + .MinWait - .@ilog)/60)%24;
		set .@mins,(#LastDailyReward + .MinWait - .@ilog)%60;
		if (#DRewardCon == 28)
			dispbottom "[Daily Reward] You are currently on your Day#"+(#DRewardCon)+". Your Day#1 reward will start counting after "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +" ";
		else
			dispbottom "[Daily Reward] You are currently on your Day#"+(#DRewardCon)+". Your Day#"+(#DRewardCon+1)+" reward will start counting after "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +" ";

	}
	if (#RewardWait) {
		set .@days,0;
		set .@hours,(.Rest-#minute)*60/3600;
		set .@mins,((.Rest-#minute)*60 % 3600)/60;
		dispbottom "[Daily Reward] You have to stay online for "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +"to get your Day#"+(#DRewardCon+1)+" rewards. Use @reward to check.";
	}
	end;

OnPCLoginEvent:
	if (getgroupid() == 4) end;
	attachnpctimer ""+strcharinfo(PC_NAME)+"";
	initnpctimer;

	set .@reward, (gettime(GETTIME_YEAR) * 365 * 24 * 60) + (gettime(GETTIME_DAYOFYEAR) * 24 * 60) + (gettime(GETTIME_HOUR) * 60) + gettime(GETTIME_MINUTE);
	if(!#RewardWait && .@reward >= (#LastDailyReward + .MinWait) || !#LastDailyReward ){
		set #RewardWait, 1;
	}

	if (#LastDailyReward && !#RewardWait) {
		set .@ilog, (gettime(GETTIME_YEAR) * 365 * 24 * 60) + (gettime(GETTIME_DAYOFYEAR) * 24 * 60) + (gettime(GETTIME_HOUR) * 60) + gettime(GETTIME_MINUTE);
		set .@days,(#LastDailyReward + .MinWait - .@ilog)/60/24;
		set .@hours,((#LastDailyReward + .MinWait - .@ilog)/60)%24;
		set .@mins,(#LastDailyReward + .MinWait - .@ilog)%60;
		if (#DRewardCon == 28)
			dispbottom "[Daily Reward] You are currently on your Day#"+(#DRewardCon)+". Your Day#1 reward will start counting after "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +" ";
		else
			dispbottom "[Daily Reward] You are currently on your Day#"+(#DRewardCon)+". Your Day#"+(#DRewardCon+1)+" reward will start counting after "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +" ";

	}
	if (#RewardWait) {
		set .@days,0;
		set .@hours,(.Rest-#minute)*60/3600;
		set .@mins,((.Rest-#minute)*60 % 3600)/60;
		dispbottom "[Daily Reward] You have to stay online for "+ ((.@days) ? .@days +":Days " : "") +""+ ((.@hours) ? .@hours +":Hours " : "") +""+ ((.@mins) ? .@mins +":Minutes " : "") +"to get your Day#"+(#DRewardCon+1)+" rewards. Use @reward to check.";
	}
	end;


OnTimer30000:
	
	//Check if Vending (normal or @at)
	if(checkvending() >= 1 && #RewardWait) {
		dispbottom "[Daily Reward] Your daily reward counter has stopped because you were vending. Please relog if you wish to try again.";
		stopnpctimer;
		end;
	}



OnTimer60000:
	set .@reward, (gettime(GETTIME_YEAR) * 365 * 24 * 60) + (gettime(GETTIME_DAYOFYEAR) * 24 * 60) + (gettime(GETTIME_HOUR) * 60) + gettime(GETTIME_MINUTE);
	if(!#RewardWait && .@reward >= (#LastDailyReward + .MinWait) || !#LastDailyReward ){
		set #RewardWait, 1;
	}
	if(#RewardWait){ 
		set #minute, #minute + 1;
	}
	if(#minute >= .Rest) {
		set .@i, (gettime(GETTIME_YEAR) * 365 * 24 * 60) + (gettime(GETTIME_DAYOFYEAR) * 24 * 60) + (gettime(GETTIME_HOUR) * 60) + gettime(GETTIME_MINUTE);
		if(#RewardWait == 1 && .@i >= (#LastDailyReward + .MinWait)){
			set .@g, (#DRewardCon > getarraysize(.Rewards$)) ? (getarraysize(.Rewards$)-1) : #DRewardCon;
			explode(.@XT$,.Rewards$[.@g],"|");
			for(set .@x,0; .@x < getarraysize(.@XT$); set .@x,.@x + 1){
				set .@TT[.@x], atoi(.@XT$[.@x]);
			}
			if(.Mode & 1 && .@TT[4]){
				for(set .@x,4; .@x < getarraysize(.@TT); set .@x,.@x + 2){
					getitembound  .@TT[.@x], .@TT[.@x+1],1;	
					message strcharinfo(PC_NAME),"Received "+  .@TT[.@x+1] +" "+ getitemname(.@TT[.@x]);
				}
			}
			dispbottom "[Daily Reward] You have collected your day#"+(#DRewardCon+1)+" reward. You can collect again after 24 hours.";
			cutin "dr00",4;	
			#DRewardCon++;
			if(#DRewardCon == 30) { 
				set #DRewardCon,0;
			}
			set #LastDailyReward, .@i;
			set #RewardWait, 0;
			set #minute, 0;
			
		}

	}
	stopnpctimer;
	initnpctimer;	
	end;


OnInit:
	
	//Basic Settings
	//   1: Item | 2: Points | 4: Exp  
	//   8: Gain Buffs Every X Consecutive Days logged in
	// (a bit value, e.g. 3 = Items & Points from Multi)
	set .Mode,1;

	//To Enable @ Command '@loginreward' unslash next lines
	// * Needs extra commands for typos
	bindatcmd("reward"	,"dreward::OnLoginCmnd",0,99);

	//Minimum Minuets Between Collecting Daily Reward
	//   Day: 22*60 - 24*60
	//   Week: 10080
	set .MinWait,1260;
	

	//Minuets Before Lose Consecutive Daily Reward
	//   Day: 48*60 - 50*60
	//   Week: 20160
	set .MaxWait,518400;
	
	//Number of mins after logging before collecting prize
	set .Rest,180;

	//Point Type
	//   [0] Points earned
	//   [1] Point name in mes
	setarray .points$,"#KAFRAPOINTS","K-Points";

	// Consecutive Days Buff
	// Each buff contains 4 variables (32 Total Max)
	// <Type>,<Days>,<Duration>,<Rate>, // Buff 1
	// <Type>,<Days>,<Duration>,<Rate>, // Buff 2
	//   ...;
	//
	//  Example: 188,7,45,3
	//    -Every 7th consecutive day logged in Player gains +3 Str for 45 mins
	//
	//  Type is 188, which references which SC_ to use, SC_INCSTR in this example
	//     -For a full list of SC_ visit the db/const.txt
	//  Days is days buff is applied, in this example 7, so every 7th day, 14,21,28....
	//  Duration is buff duration is Minuits, in this example 45 mins
	//  Rate is buff strength, in this example player gains 3 Str
	setarray .BuffInfo	,260,2,360,1	// Life Insurance for 360 Mins Every 2nd Day
				,198,3,120,10	// +10% Hp for 120 Mins Every 3th Day
				,196,5,120,25	// +25 Flee for 120 Mins Every 5th Day
				,257,7,240,50;	// +50% Exp for 240 Mins Every 7th Day

	// Daily Prize items (max 128 days):
	//   "<Zeny>|<Points>|<BaseExp>|<JobExp>|<itemID-1>|<amount-1>|<itemID-2>|<amount-2>...etc", // Day 1
	//   "<Zeny>|<Points>|<BaseExp>|<JobExp>|<itemID-1>|<amount-1>|<itemID-2>|<amount-2>...etc"  // Day 2
	//   ...;
	// Total length of any days string must be 255 or shorter
	// * If players login longer than the last set
	//   day, they will keep getting the last prize.
	setarray .Rewards$,
		"0|0|0|0|608|15",		// Day 1 15x yggdrasil seed			
		"0|0|0|0|14527|5",		// Day 2 5x Dungeon Teleport Scroll	
		"0|0|0|0|603|5",		// Day 3 5x OBB	
		"0|0|0|0|12253|5",		// Day 4 5x Hwergelmir's Tonic
		"0|0|0|0|985|7",		// Day 5 7x Elunium	
		"0|0|0|0|984|7",		// Day 6 7x Oridecon
		"0|0|0|0|30293|1",		// Day 7 1x Spin2Win

		"0|0|0|0|12252|5",		// Day 8 5x Dragon breath cocktail
		"0|0|0|0|616|2",		// Day 9 2x Old Card Album
		"0|0|0|0|30090|1",		// Day 10 Dungeon Teleport Scroll / 1x VIP Gold
		"0|0|0|0|608|15",		// Day 11 15x yggdrasil seed
		"0|0|0|0|14527|5",		// Day 12 5x Dungeon Teleport Scroll
		"0|0|0|0|603|5",		// Day 13 5x OBB
		"0|0|0|0|30293|1",		// Day 14 1x Spin2Win
		"0|0|0|0|985|7",		// Day 15 7x Elunium
		"0|0|0|0|984|7",		// Day 16 7x Oridecon
		"0|0|0|0|12253|5",		// Day 17 5x Hwergelmir Tonic
		"0|0|0|0|12252|5",		// Day 18 5x Dragon breath cocktail

		"0|0|0|0|616|2",		// Day 19 2x Old Card Album	
		"0|0|0|0|30294|1",		// Day 20 1x Costume Evil Mask
		"0|0|0|0|30293|1",		// Day 21 1x Spin2Win

		"0|0|0|0|14527|5",		// Day 22 5x Dungeon Teleport Scroll	
		"0|0|0|0|603|5",		// Day 23 5x OBB
		"0|0|0|0|12253|5",		// Day 24 5x Hwergelmir's Tonic

		"0|0|0|0|985|7",		// Day 25 7x Elunium			
		"0|0|0|0|984|7",		// Day 26 7x Oridecon	
		"0|0|0|0|12252|5",		// Day 27 5x Dragon breath cocktail
		"0|0|0|0|30293|1",		// Day 28 1x Spin2Win

		"0|0|0|0|616|2",		// Day 29 2x Old Card Album
		"0|0|0|0|5512|1";		// Day 30 1x Aquarius Diadem


	
	setarray .Pic$,
	"dr01", //pic with day1 highlighted
	"dr02", //pic with day2 highlighted
	"dr03", //pic with day3 highlighted
	"dr04", //pic with day3 highlighted
	"dr05", //pic with day3 highlighted
	"dr06", //pic with day3 highlighted
	"dr07", //pic with day3 highlighted
	"dr08", //pic with day3 highlighted
	"dr09", //pic with day3 highlighted
	"dr10", //pic with day3 highlighted
	"dr11", //pic with day3 highlighted
	"dr12", //pic with day3 highlighted
	"dr13", //pic with day3 highlighted
	"dr14", //pic with day3 highlighted
	"dr15", //pic with day3 highlighted
	"dr16", //pic with day3 highlighted
	"dr17", //pic with day3 highlighted
	"dr18", //pic with day3 highlighted
	"dr19", //pic with day3 highlighted
	"dr20", //pic with day3 highlighted
	"dr21", //pic with day3 highlighted
	"dr22", //pic with day3 highlighted
	"dr23", //pic with day3 highlighted
	"dr24", //pic with day3 highlighted
	"dr25", //pic with day3 highlighted
	"dr26", //pic with day3 highlighted
	"dr27", //pic with day3 highlighted
	"dr28", //pic with day3 highlighted
	"dr29", //pic with day3 highlighted
	"dr30"; //pic with day3 highlighted

end;
}