summaryrefslogblamecommitdiff
path: root/npc/re/woe-fe/invest_main.txt
blob: 6a65a9c78a7852e86e00cd435604cf21dac7c35c (plain) (tree)


























                                                                           
                                
                                                                           



                                            







































                                                                                         
 
                                                            
                                                              
                                          
                                                             
                                                                    
                                      



                                                                             
                                                                 
                                      



                                                                                     
                                                               


                                                             
                                                




                                                   


                                           





                                
                                                                                        


                                                   
                                                             


                                                

                                                                                                       










                                                                                                                         
                                                                                               





                                                                                                
                                                                                                                                    
                       
                                    

                              
                                     

                              
                                     























                                                                                 
                                         







                                                                                                                                                                        
                               
                                                          
                                                     





                                                                   
                                                                                                                     
                       
                                      

                              
                                      























                                                                                                     
                                                                



                                                                                                         
                                         


                                                                                                                                                                                                                               
                                                     
                                                          
                                                     







                                
                                                            
                                                   

            
                                                      
                                   
                                      








                                                                                           
                         

                                                    
                                    
                                                  
                                                                                                                                                                                                                                   



                                                                
                                         



                                                                       
                                         




                                                                

                                                            
                                      

                    


                                                           
                                                                               

                                    
                                           

                                             


                                                                           

                                                                     







                                                
                                                          
                                                                 
                                              



                                                      

                                              
                                                        
                                                                   

                                    










                                                                                                   





                                                                       
                                      




                                                                                                                                                                                                     



















                         









                                                                                                                                                                                     























                                     



                                                       
                              



                                                      
                                                           
                            

                                            
                                               

                                                                                          
                                                               











                                                                           
 




                                                                

                                        



                                                    
                                    








                                                                                          

                                


                     

                                







                                               
                                                                  


                                                                                                                       
                                                                            













                                                                                                                                                                                                              
                                                                             




                                                        
                                                      








                                                                                           










                                                                            

                             


                                                              
                                      

                                        


                                                                      

                                                                     


                                    
                                                  


                                                          

                                 


















                                                           
                                        
                            
                                                              




                                                                                                                                                                    
                                                              












                                                                    
                                                                             
                                     






                                                                 

                                                  








                                                                                                        
                                                                      










                                                                          
                                                              
                                                 
                                               
                                                     
                                                   
                                                     
                                                        
                                                     
                                                        
         
                                                
















































                                                                                                                                                                   
                                                              
                                                 
                                                  
                                                     
                                                      
                                                     
                                                           
                                                     
                                                           

                                                                                                                                                         




                                 





                                                        
                                                       




                                             
                                      


                                                   
                                      


                                                          
                                      









                                                         
                                                             
                                                  
 
                                                  



                                                                 
                                                        



                                                      
                                                        



                                                                 
                                                        



                                                                    
         
                               





                                                                               
                                                                                                                                     




                                                                                                                                 
                                                                                                               






























                                                                                                                                                  
                                                                                                                       











































































































                                                                                                                                                                                      
                                                                             





                                                             
                                                              











                                                                                                      
                                                   



                                                                                 
                                                         

                                                                                                         
                              
                                                                                                                      





                                                                                                                               
                                                       



























                                                                                                                     
                                                  
 
                                                  



                                         
                                                        



                                             
                                                        



                                                 
                                                        



                                               
         
                               





                                                                      
                                                     








                                                                                                                         
                                                                                                            













                                                                                       
                              

                                                                                  
                                                                
                                                                     
                                                                    
                                                                     
                                                                    
                                                                      
                                                                    















                                                                                                                           
                                                  
                                                      
                                   
                                                          

                                           
                                                                

                                               
                                                                

                                                    
                                                                

                                                    
                 
                                               



                                                                                
                                       
                                       
                                       
                                       
                                       
                    
                                               
                                                      


                                                                      

                                                                                                                   
                                                             











                                                                                                                          
                                            


















                                                                                                 
                                                            
                                                  
 

                                                                                                  

                                   
                                                                

                                       
                                                                

                                            
                                                                

                                            

         
                                                     
                                                








                                                                                                          
                                                                                                                     
               
                                                                             




                                                                                                                           
                                                              











                                                                                                      
                                                        









                                                                                               
                                                  



                                                                                                         
                                                                  






                                                                        
                                                                        






                                                                        
                                                                        






                                                                        
                                                                        









                                                                        
                                                  


                                                                                                                          
                                                                  






                                                                     
                                                                        






                                                                     
                                                                        






                                                                     
                                                                        
















                                                                     
                                                      
                                   
                                                                






















                                                                                                
                                                            
                                                                          


                                                              
                                                                         























                                                                                                                                                                                                                          
                                                            
                          
                                                

                                              




















                                                                                                             










                                                                                                                           
                                                                   
                                                                     












                                                     
                                                                                                                   































                                                                                                                                                                                 
                                                                            














                                                                                                                                                        
                                                          
                               









































                                                                                                                                                                                                                                                           








                                                            
                               

                                                     
                                                 
                    
                                               















                                                                                            
                                                   






                                                      
                                     










                                                                                             
                                                            
                                                                            
                                                                     












                                                                                  
                                                                                                                   




                                                                                  
                                                                                                                                                                                                                                                                                                                                                                                                                                                                 





























                                                                                                   




                                                                                                                                          
                                                          


                                                                                                   























































































































                                                                                         



                                                                                                                                             
                                                           


                                                                                                   







































































































































                                                                                          





                                                                               
                                                          


                                                                                           
                                               













                                                                                                                      
//================= Hercules Script =======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License ===============================================
//= This file is part of Hercules.
//= http://herc.ws - http://github.com/HerculesWS/Hercules
//=
//= Copyright (C) 2013-2015  Hercules Dev Team
//= Copyright (C)  Euphy
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http://www.gnu.org/licenses/>.
//=========================================================================
//= Hall of Abyss - Core Scripts
//================= Description ===========================================
//= Expansion for War of Emperium FE.
//= Invest in each realm to unlock new maps:
//= - Guild Dungeon F2, total 20,000,000z.
//= - Hall of Abyss, total 70,000,000z.
//================= Current Version =======================================
//= 1.1
//================= Variables Used ========================================
//= Note: an asterisk (*) represents any realm (prt, pay, gef, alde).
//= $2011_agit_invest
//= - 0: Inactive.
//= - 1: Investment in progress.
//= - 2: Investment results calculating.
//= - 4: Investment calculations complete (only when at least one $*_invest_result is 3).
//= - 11-21: Tie, revote required.
//=
//= $agit_result_notice
//= - 0: Inactive.
//= - 1-12: Interim statements (displaying $@vfund_*x) available.
//=
//= $agit_result_timer
//= - 0: Inactive.
//= - 0-59: Time elapsed during investment (in hours).
//=
//= $agit_revoting_timer
//= - 0: Inactive.
//= - 0-29: Time elapsed during revote (in minutes).
//= - 30: Revote closed.
//= - 31: Revote results calculating.
//=
//= $*_invest_result
//= - 0: No data.
//= - 1: Realm not connected.
//= - 2: Guild Dungeon F2 open.
//= - 3: Abyss Gate (Hall of Abyss and Gulid Dungeon F2) open.
//=
//= $fund_*[01-05]
//= - Investment units per guild castle.
//= $fund_*_extra
//= - Investment units per realm.
//=
//= $@vfund_*[01-05]
//= $@vfund_*_extra
//= -- Investment units, used in interim statements only.
//=========================================================================

//== Investment Functions & Controller =====================
// Note: The times in this section are almost entirely custom.
-	script	#invest_timer	FAKE_NPC,{
OnClock0000:	// Open investments on Wed (1 hour after WoE)
	if (gettime(GETTIME_WEEKDAY) == WEDNESDAY && !agitcheck()) {
		$2011_agit_invest = 1;
		donpcevent "#fund_master::OnInvest_start";
	}
	end;
OnClock1200:	// Close investments on Fri (60 hours after investments open)
	if (gettime(GETTIME_WEEKDAY) == FRIDAY && !agitcheck()) {
		$2011_agit_invest = 2;
		donpcevent "#fund_master::OnInvest_stop";
	}
	end;
OnClock1235:	// Open dungeons on Fri (at least 31 minutes after investments close)
	if (gettime(GETTIME_WEEKDAY) == FRIDAY && !agitcheck())
		donpcevent "#fund_master::OnResult";
	end;
OnClock2000:	// Close dungeons on Tues (1 hour before WoE)
	if (gettime(GETTIME_WEEKDAY) == TUESDAY)
		donpcevent "#fund_master::OnReset";
	end;
}

function	script	F_Invest_Status	{
	.@day = gettime(GETTIME_WEEKDAY);
	.@hour = gettime(GETTIME_HOUR);
	.@minute = gettime(GETTIME_MINUTE);

	// Inactive.
	if (agitcheck())
		return 0;

	// Open for investments.
	if (.@day >= WEDNESDAY && (.@day < FRIDAY || (.@day == FRIDAY && .@hour <= 12)))
		return 1;

	// Investments closed, calculating results.
	if (.@day == FRIDAY && .@hour == 12 && .@minute < 35)
		return 2;

	// Calculations complete, dungeons open.
	if ((.@day == FRIDAY && (.@hour > 12 || (.@hour == 12 && .@minute >= 35))) || .@day > FRIDAY ||
	    .@day < TUESDAY || (.@day == TUESDAY && .@hour < 20))
		return 3;

	// Dungeons closed.
	return 0;
}

//callfunc "F_Invest_Abyss","<variable>","<NPC name>"{,"<addon message>"};
function	script	F_Invest_Abyss	{
	mes "There are 2 ways to invest, by Zeny or the Investment Certificate given out by the Cat Paw Merchant Guild.";
	mes "Which way would you like to make your investment?";
	next;
	switch(select("Invest with Zeny.", "Invest with Investment Certificates.", "Cancel")) {
	case 1:
		mes getarg(1);
		mes "So you've decided to invest in Zeny.";
		mes "Minimum investment unit is ^4d4dff10,000 Zeny^000000.";
		mes "You can invest a maximum of 50 units which is ^4d4dff500,000 Zeny^000000.";
		next;
		switch(select("1 unit 10,000 Zeny", "10 units 100,000 Zeny", "50 units 500,000 Zeny", "Another amount", "Cancel")) {
		case 1:
			.@units = 1;
			break;
		case 2:
			.@units = 10;
			break;
		case 3:
			.@units = 50;
			break;
		case 4:
			mes getarg(1);
			mes "Please enter the amount you want to invest.";
			mes "Please choose between 1 to 200.";
			mes "Please enter 0 to cancel.";
			next;
			input .@units;
			if (.@units < 0 || .@units > 200) {
				mes getarg(1);
				mes "You've exceeded the amount per investment.";
				mes "Please try again.";
				close;
			} else if (.@units == 0) {
				mes getarg(1);
				mes "Canceled.";
				close;
			} else
				break;
		case 5:
			mes getarg(1);
			mes "Canceled.";
			close;
		}
		.@zeny = .@units * 10000;
		if (Zeny < .@zeny) {
			mes getarg(1);
			mes "You do not have enough money.";
			close;
		}
		mes getarg(1);
		mes "You've invested "+.@units+" unit"+((.@units == 1)?"":"s")+" "+((.@units < 100)?.@units:insertchar(""+.@units,",",1))+"0,000 Zeny"+getarg(2,"")+".";
		mes "Not much but this is a small gift. You can exchange it with items in Malangdo.";
		Zeny -= .@zeny;
		setd getarg(0), getd(getarg(0)) + .@units;
		getitem Thanks_Invest_Ticket,.@units;
		close;
	case 2:
		mes getarg(1);
		mes "Wow, you've brought Investment Certificates.";
		mes "How many certificates will you submit?";
		next;
		switch(select("1 Investment Certificate", "5 Investment Certificates", "Another amount", "Cancel")) {
		case 1:
			.@tickets = 1;
			break;
		case 2:
			.@tickets = 5;
			break;
		case 3:
			mes getarg(1);
			mes "Please enter the number of Investment Certificates you want to submit.";
			mes "Please choose between 1 to 20.";
			mes "Please enter 0 to cancel.";
			next;
			input .@tickets;
			if (.@tickets < 0 || .@tickets > 20) {
				mes getarg(1);
				mes "You've exceeded the amount per investment.";
				mes "Please try again.";
				close;
			} else if (.@tickets == 0) {
				mes getarg(1);
				mes "Canceled.";
				close;
			} else
				break;
		case 4:
			mes getarg(1);
			mes "Canceled.";
			close;
		}
		if (countitem(Cats_Invest_Certif) < .@tickets) {
			mes getarg(1);
			mes "Looks like you have fewer Investment Certificates than you want to submit.";
			close;
		}
		.@units = .@tickets * 10;
		mes getarg(1);
		mes .@tickets+" Investment Certificate"+((.@tickets == 1)?" is":"s are")+" the same as an investment of "+.@units+" units ("+((.@units < 100)?.@units:insertchar(""+.@units,",",1))+"0,000z)"+getarg(2,"")+".";
		mes "Not much but this is a small gift. You can exchange it with items in Malangdo.";
		delitem Cats_Invest_Certif,.@tickets;
		setd getarg(0), getd(getarg(0)) + .@units;
		getitem Thanks_Invest_Ticket,.@units;
		close;
	case 3:
		mes getarg(1);
		mes "Canceled.";
		close;
	}
}

//== Script Core ===========================================
prt_gld,1,1,0	script	#fund_master	CLEAR_NPC,{
	end;
OnInit:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 1) {
		$2011_agit_invest = 1;
		end;
	}
	if ((.@invest_status == 2 && $2011_agit_invest == 1) ||
	    (.@invest_status == 3 && ($2011_agit_invest == 1 || $2011_agit_invest == 2))) {
		donpcevent "#fund_master::OnCalculate";
		end;
	}
	end;
OnCalculate_Election:
	.@force_vote = 1;
OnCalculate:
	setarray .@cas$[0],"prt","pay","gef","alde";
	for(.@i = 0; .@i<4; ++.@i) {
		// All funds per realm are summed.
		.@funds[.@i] = getd("$fund_"+.@cas$[.@i]+"01")+getd("$fund_"+.@cas$[.@i]+"02")+getd("$fund_"+.@cas$[.@i]+"03")+getd("$fund_"+.@cas$[.@i]+"04")+getd("$fund_"+.@cas$[.@i]+"05")+getd("$fund_"+.@cas$[.@i]+"_extra");

		// 70,000,000z opens Hall of Abyss and F2.
		if (.@funds[.@i] >= 7000) {
			setd "$"+.@cas$[.@i]+"_invest_result",3;
			.@total_7000 = 1;
		}
		// 20,000,000z opens F2 and a chance for Hall of Abyss.
		else if (.@funds[.@i] >= 2000) {
			setd "$"+.@cas$[.@i]+"_invest_result",2;
			.@total_2000 = 1;
		}
		// Anything below that opens nothing.
		else
			setd "$"+.@cas$[.@i]+"_invest_result",1;
	}
	// No further actions if any realm hits 70,000,000z.
	if (.@total_7000) {
		$2011_agit_invest = 4;
		end;
	}
	// No further actions if 20,000,000z isn't reached.
	if (!.@total_2000)
		end;
	// Otherwise, highest investment above 20,000,000z opens Hall of Abyss.
	.@max = .@funds[0];
	for(.@i = 1; .@i<4; ++.@i) {
		if (.@funds[.@i] > .@max) {
			.@max = .@funds[.@i];
			.@ele = .@i;
			deletearray .@rand$[0], getarraysize(.@rand$);
		} else if (.@funds[.@i] == .@max && .@funds[.@i] >= 2000) {
			if (!getarraysize(.@rand$))
				.@rand$[0] = .@cas$[.@ele];
			.@rand$[getarraysize(.@rand$)] = .@cas$[.@i];
		}
	}
	if (.@max < 2000)
		end;
	if (getarraysize(.@rand$)) {

		// Tie: declare a random winner.
		if (!.@force_vote) {
			.@i = rand(getarraysize(.@rand$));
			setd "$"+.@rand$[.@i]+"_invest_result",3;
			$2011_agit_invest = 4;
			end;
		}

		// Tie: initiate a 30-minute election.
		.@str$ = implode(.@rand$,"|");
		for(.@i = 0; .@i<4; ++.@i) {
			if (compare(.@str$,.@cas$[.@i]))
				.@election = .@election | (1<<.@i);
		}
		switch(.@election) {
			case 3:  $2011_agit_invest = 11; break; //Prontera|Payon
			case 9:  $2011_agit_invest = 12; break; //Prontera|Al De Baran
			case 5:  $2011_agit_invest = 13; break; //Prontera|Geffen
			case 10: $2011_agit_invest = 14; break; //Al De Baran|Payon
			case 6:  $2011_agit_invest = 15; break; //Geffen|Payon
			case 12: $2011_agit_invest = 16; break; //Al De Baran|Geffen
			case 11: $2011_agit_invest = 17; break; //Prontera|Payon|Al De Baran
			case 7:  $2011_agit_invest = 18; break; //Prontera|Payon|Geffen
			case 13: $2011_agit_invest = 19; break; //Prontera|Al De Baran|Geffen
			case 14: $2011_agit_invest = 20; break; //Al De Baran|Payon|Geffen
			case 15: $2011_agit_invest = 21; break; //Prontera|Payon|Al De Baran|Geffen
		}
		if ($2011_agit_invest >= 11)
			donpcevent "Revoting Manager#Invest1::OnStart";
		end;
	} else {
		setd "$"+.@cas$[.@ele]+"_invest_result",3;
		$2011_agit_invest = 4;
		end;
	}
	end;
OnInvest_start:
	announce "From now on, we are going to start the investments to connect the 'Abyss Gate' in the WOE areas: Valkyrie Realm, Greenwood Lake, Luina, Britoniah.",bc_all,0xFF0000; //FW_NORMAL 10
	$fund_prt01 = 0;
	$fund_prt02 = 0;
	$fund_prt03 = 0;
	$fund_prt04 = 0;
	$fund_prt05 = 0;
	$fund_pay01 = 0;
	$fund_pay02 = 0;
	$fund_pay03 = 0;
	$fund_pay04 = 0;
	$fund_pay05 = 0;
	$fund_gef01 = 0;
	$fund_gef02 = 0;
	$fund_gef03 = 0;
	$fund_gef04 = 0;
	$fund_gef05 = 0;
	$fund_alde01 = 0;
	$fund_alde02 = 0;
	$fund_alde03 = 0;
	$fund_alde04 = 0;
	$fund_alde05 = 0;
	donpcevent "Investment_total#fund00::OnEnable";
	end;
OnInvest_stop:
	announce "We've finished the investments to connect the 'Abyss Gate'.",bc_all,0xFF0000; //FW_NORMAL 10
	donpcevent "Investment_total#fund00::OnReset";
	donpcevent "#fund_master::OnCalculate_Election";
	end;
OnResult:
	announce "We've got the results of the investments for the 'Abyss Gate'. You can check through the Investment Status Board in each WOE area.",bc_all,0xFF0000; //FW_NORMAL 10
	if ($2011_agit_invest == 4) {
		$fund_prt01 = 0;
		$fund_prt02 = 0;
		$fund_prt03 = 0;
		$fund_prt04 = 0;
		$fund_prt05 = 0;
		$fund_prt_extra = 0;
		$fund_pay01 = 0;
		$fund_pay02 = 0;
		$fund_pay03 = 0;
		$fund_pay04 = 0;
		$fund_pay05 = 0;
		$fund_pay_extra = 0;
		$fund_gef01 = 0;
		$fund_gef02 = 0;
		$fund_gef03 = 0;
		$fund_gef04 = 0;
		$fund_gef05 = 0;
		$fund_gef_extra = 0;
		$fund_alde01 = 0;
		$fund_alde02 = 0;
		$fund_alde03 = 0;
		$fund_alde04 = 0;
		$fund_alde05 = 0;
		$fund_alde_extra = 0;
	} else if ($2011_agit_invest == 2)
		donpcevent "#fund_master::OnCalculate";
	end;
OnReset:
	$2011_agit_invest = 0;
	donpcevent "Investment_total#fund00::OnReset";
	end;
}

prt_gld,2,2,0	script	Investment_total#fund00	CLEAR_NPC,{
	callfunc "F_GM_NPC";
	mes "Is this not working properly?";
	next;
	if (callfunc("F_GM_NPC",1854,0) == 1) {
		mes "If you think the investment timer is dead, please adjust the timer.";
		next;
		switch(select("Turn on the timer", "Cancel")) {
		case 1:
			donpcevent "Investment_total#fund00::OnTimerReset";
			mes "You've turned on the timer.";
			close;
		case 2:
			mes "Canceled.";
			close;
		}
	} else {
		mes "I don't need to adjust anything now.";
		close;
	}

OnInit:
	if (callfunc("F_Invest_Status") == 1) {
		initnpctimer;
		donpcevent "Investment_total#fund00::OnVarInit";
	} else {
		$agit_result_timer = 0;
		$agit_result_notice = 0;
	}
	end;
OnVarInit:
	setarray .@cas$[0],"prt","pay","gef","alde";
	for(.@i = 0; .@i<4; ++.@i) {
		setd "$@vfund_"+.@cas$[.@i]+"01", getd("$fund_"+.@cas$[.@i]+"01");
		setd "$@vfund_"+.@cas$[.@i]+"02", getd("$fund_"+.@cas$[.@i]+"02");
		setd "$@vfund_"+.@cas$[.@i]+"03", getd("$fund_"+.@cas$[.@i]+"03");
		setd "$@vfund_"+.@cas$[.@i]+"04", getd("$fund_"+.@cas$[.@i]+"04");
		setd "$@vfund_"+.@cas$[.@i]+"05", getd("$fund_"+.@cas$[.@i]+"05");
		setd "$@vfund_"+.@cas$[.@i]+"_extra", getd("$fund_"+.@cas$[.@i]+"_extra");
	}
	end;
OnEnable:
	$agit_result_timer = 0;
	$agit_result_notice = 0;
	initnpctimer;
	end;
OnReset:
	$agit_result_timer = 0;
	$agit_result_notice = 0;
	stopnpctimer;
	end;
OnTimerReset:
	initnpctimer;
	end;
OnTimer3600000:
	if (callfunc("F_Invest_Status") == 1) {
		if ($agit_result_timer < 59) {
			$agit_result_timer = $agit_result_timer+1;

			// Trigger on multiples of 5 up to 55, and 58.
			if ($agit_result_timer % 10 == 5 || $agit_result_timer % 10 == 0 || $agit_result_timer == 58) {
				$agit_result_notice = $agit_result_notice+1;
				donpcevent "Investment_total#fund00::OnVarInit";
				announce "No. "+$agit_result_notice+" Interim statement is now available. You can check through the Investment Status Board in each WOE area.",bc_all,0xFF0000; //FW_NORMAL 10
			}

			donpcevent "Investment_total#fund00::OnTimerReset";
		} else
			stopnpctimer;
		end;
	} else {
		donpcevent "Investment_total#fund00::OnReset";
		end;
	}
}

prt_gld,164,98,3	script	Revoting Manager#Invest1	4_M_BOSSCAT,{
	mes "[Revoting Manager]";
	mes "We are not accepting additional votes.";
	mes "Please wait for our results announcement.";
	close;
OnInit:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 2 && $2011_agit_invest >= 11 && $agit_revoting_timer < 30) {
		donpcevent "Revoting Manager#Invest2::OnEnable";
		initnpctimer;
	} else if (.@invest_status == 3 && $2011_agit_invest >= 11)
		donpcevent "Revoting Manager#Invest1::OnCalculate";
	donpcevent "Revoting Manager#Invest1::OnDisable";
	end;
OnCalculate:
	switch($2011_agit_invest) {
		case 11: setarray .@cas$[0],"prt","pay"; break;
		case 12: setarray .@cas$[0],"prt","alde"; break;
		case 13: setarray .@cas$[0],"prt","gef"; break;
		case 14: setarray .@cas$[0],"alde","pay"; break;
		case 15: setarray .@cas$[0],"gef","pay"; break;
		case 16: setarray .@cas$[0],"alde","gef"; break;
		case 17: setarray .@cas$[0],"prt","pay","alde"; break;
		case 18: setarray .@cas$[0],"prt","pay","gef"; break;
		case 19: setarray .@cas$[0],"prt","alde","gef"; break;
		case 20: setarray .@cas$[0],"alde","pay","gef"; break;
		case 21: setarray .@cas$[0],"prt","pay","alde","gef"; break;
		default: end;
	}
	.@max = getd("$fund_"+.@cas$[0]+"_extra");
	for(.@i = 1; .@i<getarraysize(.@cas$); ++.@i) {
		.@funds = getd("$fund_"+.@cas$[.@i]+"_extra");
		if (.@funds > .@max) {
			.@max = .@funds;
			.@ele = .@i;
			deletearray .@rand$[0], getarraysize(.@rand$);
		} else if (.@funds == .@max) {
			if (!getarraysize(.@rand$))
				.@rand$[0] = .@cas$[.@ele];
			.@rand$[getarraysize(.@rand$)] = .@cas$[.@i];
		}
	}
	if (getarraysize(.@rand$)) {
		.@i = rand(getarraysize(.@rand$));
		setd "$"+.@rand$[.@i]+"_invest_result",3;
	} else
		setd "$"+.@cas$[.@ele]+"_invest_result",3;
	$2011_agit_invest = 4;
	$agit_revoting_timer = 0;
	end;
OnEnable:
	enablenpc "Revoting Manager#Invest1";
	end;
OnDisable:
	disablenpc "Revoting Manager#Invest1";
	end;
OnStart:
	initnpctimer;
	donpcevent "Revoting Manager#Invest2::OnNotice_on";
	end;
OnEnd:
	stopnpctimer;
	disablenpc "Revoting Manager#Invest1";
	end;
OnTimerReset:
	initnpctimer;
	end;
OnTimer60000:
	.@revote = $agit_revoting_timer;
	if (.@revote < 30) {
		$agit_revoting_timer = $agit_revoting_timer+1;
		donpcevent "Revoting Manager#Invest1::OnTimerReset";
	} else if (.@revote == 30) {
		announce "Cat Paw Merchant Guild: Now we are going to close the additional vote. We will announce the results soon.",bc_all,0xFF0000; //FW_NORMAL 10
		donpcevent "Revoting Manager#Invest2::OnDisable";
		donpcevent "Revoting Manager#Invest1::OnEnable";
		$agit_revoting_timer = $agit_revoting_timer+1;
		donpcevent "Revoting Manager#Invest1::OnTimerReset";
	} else if (.@revote == 31) {
		donpcevent "Revoting Manager#Invest1::OnCalculate";
		donpcevent "Revoting Manager#Invest1::OnDisable";
		stopnpctimer;
		end;
	} else {
		donpcevent "Revoting Manager#Invest1::OnDisable";
		stopnpctimer;
	}
	end;
}

prt_gld,164,98,3	script	Revoting Manager#Invest2	4_M_BOSSCAT,{
	.@invest = $2011_agit_invest;
	if (.@invest < 11) {
		mes "[Revoting Manager]";
		mes "No! This is not the time to take a revote.";
		close2;
		disablenpc "Revoting Manager#Invest2";
		end;
	}
	.@playtime = questprogress(7349,PLAYTIME);
	if (.@playtime == 1) {
		mes "[Revoting Manager]";
		mes "You've already participated in the vote.";
		mes "Please relax and wait for the results.";
		close;
	} else if (.@playtime == 2)
		erasequest 7349;
	mes "[Revoting Manager]";
	mes "Would you like to participate in the vote for choosing where to connect the 'Abyss Gate'?";
	next;
	if(select("Participate in the vote.", "Skip for now.") == 2) {
		mes "[Revoting Manager]";
		mes "You've canceled the vote.";
		close;
	}
	mes "[Revoting Manager]";
	mes "You can vote once and won't need to invest for your choice.";
	mes "Plesae choose one WOE area.";
	next;

	// Create menu.
	explode(.@candidates$, callsub(OnGetCandidates, .@invest),"|");
	for(.@i = 0; .@i<getarraysize(.@candidates$); ++.@i) {
		if (.@candidates$[.@i] == "alde")
			.@menu$[.@i] = "Luina";
		else if (.@candidates$[.@i] == "gef")
			.@menu$[.@i] = "Britoniah";
		else if (.@candidates$[.@i] == "pay")
			.@menu$[.@i] = "Greenwood Lake";
		else if (.@candidates$[.@i] == "prt")
			.@menu$[.@i] = "Valkyrie Realm";
	}
	.@vote = select(implode(.@menu$,":"))-1;

	mes "[Revoting Manager]";
	mes "You've voted for "+.@menu$[.@vote]+".";
	mes "Thanks for voting.";
	setquest 7349;
	setd "$fund_"+.@candidates$[.@vote]+"_extra", getd("$fund_"+.@candidates$[.@vote]+"_extra") + 1;
	close;
OnGetCandidates:
	switch(getarg(0)) {
		case 11: return "prt|pay";
		case 12: return "prt|alde";
		case 13: return "prt|gef";
		case 14: return "alde|pay";
		case 15: return "gef|pay";
		case 16: return "alde|gef";
		case 17: return "prt|pay|alde";
		case 18: return "prt|pay|gef";
		case 19: return "prt|alde|gef";
		case 20: return "alde|pay|gef";
		case 21: return "prt|pay|alde|gef";
	}
	return "";
OnInit:
	disablenpc "Revoting Manager#Invest2";
	end;
OnEnable:
	enablenpc "Revoting Manager#Invest2";
	end;
OnDisable:
	disablenpc "Revoting Manager#Invest2";
	stopnpctimer;
	end;
OnNotice_on:
	initnpctimer;
	end;
OnTimer5000:
	announce "Cat Paw Merchant Guild: As no WOE area has reached the maximum investment level to connect the 'Abyss Gate'...",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer8000:
	announce "Cat Paw Merchant Guild: We were about to connect the 'Abyss Gate' to the WOE area which invested most.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer11000:
	announce "Cat Paw Merchant Guild: However, there were areas which invested the same amount. So we will put them to a vote.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer14000:
	announce "Cat Paw Merchant Guild: Additional votes will be available for 30 minutes. You can vote in Valkyrie Realm.",bc_all,0xFF0000; //FW_NORMAL 10
	end;
OnTimer20000:
	explode(.@candidates$, callsub(OnGetCandidates, $2011_agit_invest),"|");
	for(.@i = 0; .@i<getarraysize(.@candidates$); ++.@i) {
		if (.@candidates$[.@i] == "alde")
			.@choices$[.@i] = "Luina";
		else if (.@candidates$[.@i] == "gef")
			.@choices$[.@i] = "Britoniah";
		else if (.@candidates$[.@i] == "pay")
			.@choices$[.@i] = "Greenwood Lake";
		else if (.@candidates$[.@i] == "prt")
			.@choices$[.@i] = "Valkyrie Realm";
	}
	announce "Cat Paw Merchant Guild: The candidates for the additional vote are... "+implode(.@choices$," vs. ")+".",bc_all,0xFF0000; //FW_NORMAL 10
	$fund_prt_extra = 0;
	$fund_pay_extra = 0;
	$fund_gef_extra = 0;
	$fund_alde_extra = 0;
	$agit_revoting_timer = 0;
	donpcevent "Revoting Manager#Invest2::OnEnable";
	stopnpctimer;
	end;
}

/*
prtg_cas01,2,2,0	script	Abrai	1_M_JOBTESTER,{
	mes "I should quit my steward job.";
	close;
OnAgitInvest:
	switch(callfunc("F_Invest_Status")) {
	case 0:
		$2011_agit_invest = 0;
		donpcevent "#fund_master::OnReset";
		break;
	case 1:
		$2011_agit_invest = 1;
		donpcevent "#fund_master::OnInvest_start";
		break;
	case 2:
		$2011_agit_invest = 2;
		donpcevent "#fund_master::OnInvest_stop";
		break;
	case 3:
		donpcevent "#fund_master::OnResult";
		break;
	}
	end;
}
*/

//== Realms - Merchant Guilds, Gate Managers, Status Boards =
-	script	Cat Paw Merchant Guild	FAKE_NPC,{

	if (compare(strnpcinfo(NPC_MAP),"alde")) {
		.@npc$ = "alde";
		.@name$ = "Megrez";
		.@realm$ = "Luina";
		.@intro$ = "Luina Branch Manager in Al De Baran";
	} else if (compare(strnpcinfo(NPC_MAP),"gef")) {
		.@npc$ = "gef";
		.@name$ = "Meraq";
		.@realm$ = "Britoniah";
		.@intro$ = "Britoniah Branch Manager";
	} else if (compare(strnpcinfo(NPC_MAP),"pay")) {
		.@npc$ = "pay";
		.@name$ = "Phecda";
		.@realm$ = "Greenwood Lake";
		.@intro$ = "Payon Greenwood Lake Branch Manager";
	} else if (compare(strnpcinfo(NPC_MAP),"prt")) {
		.@npc$ = "prt";
		.@name$ = "Dubae";
		.@realm$ = "Valkyrie Realm";
		.@intro$ = "Prontera Valkyrie Realm Branch Manager";
	}
	.@n$ = "["+.@name$+"]";

	mes .@n$;
	mes "I'm "+.@name$+", the "+.@intro$+" of the Cat Paw Merchant Guild.";
	mes "I consult about investments for the Abyss Gate development.";
	mes "How may I help you?";
	next;
	switch(select("What is the Abyss Gate?", "Investing in the gate development?", "I want to invest in this area.", "Cancel")) {
	case 1:
		mes .@n$;
		mes "It is only called the Abyss Gate for convenience but it's simply a ^4d4dffgap to another dimension^000000.";
		next;
		mes .@n$;
		mes "More of these gaps are found here and there after Morroc created the Crack of Dimension.";
		mes "I personally think that the Abyss Gate found recently is part of the past or even from the future.";
		next;
		mes .@n$;
		mes "It is said that the Abyss Gate forcefully connects to another dimension beyond our world.";
		mes "Probably because there are those that follow the Emperium's power.";
		next;
		mes .@n$;
		mes "There are a total of 4 Abyss Gates found so far. They all connect to the Agit region overflowing with the Emperium's force.";
		next;
		mes .@n$;
		mes "We named each by dimension beyond the gap.";
		mes "^4d4dffWay of the Warrior, Hill of the Dead, Winds of the Ancient, and the Hero's Tears.^000000";
		mes "And all these four gaps are called the ^4d4dffAbyss Gate^000000.";
		next;
		mes .@n$;
		mes "The gap may lead to the past, future or even an unknown world.";
		mes "The power the Abyss Gate holds is both fearful but sweet";
		next;
		mes .@n$;
		mes "Are you also interested in exploring the Abyss Gate?";
		mes "Ha ha. You'll need to go through several steps before exploring.";
		next;
		mes .@n$;
		mes "If you are interested,";
		mes "will you take the time to sit down and talk about investing in maintaining the Abyss Gate?";
		close;
	case 2:
		mes .@n$;
		mes "Are you curious about investing in the Gate development?";
		mes "What do you want to know about?";
		next;
		switch(select("About the Gate?", "About investments?", "How to invest?", "Benefits from investing?")) {
		case 1:
			mes .@n$;
			mes "The Gate is what it is named after, a door.";
			mes "A dimensional passageway that connects here to there.";
			next;
			mes .@n$;
			mes "The Abyss Gate was created as a very unstable path from beyond the dimensional gap,";
			mes "therefore traveling through the Gate will need an artificial dimension connection.";
			next;
			mes .@n$;
			mes "Humans are far from having the advanced technology that's needed";
			mes "but our Cat Paw Merchant Guild holds the high technology to use the Crack of Dimension.";
			next;
			mes .@n$;
			mes "So we made a proposal.";
			mes "With the promise of support the Cat Paw Merchant Guild and paying for the immense expense for maintaining the connection with the Gate,";
			mes "we will make the connection to the Crack of Dimension.";
			next;
			mes .@n$;
			mes "Of course working on the Crack of Dimension is no easy job and it does come with risks.";
			mes "There are cases where people go missing from traveling between.";
			next;
			mes .@n$;
			mes "The best maintaining duration is about 4 days";
			mes "You invest in us and we create the door that connects to the dimensional gap.";
			next;
			mes .@n$;
			mes "Doesn't this sound like the perfect win-win proposal?";
			close;
		case 2:
			mes .@n$;
			mes "Forcing through the unstable dimensional gap and creating a passageway is very dangerous.";
			mes "Not to mention the huge resources needed.";
			next;
			mes .@n$;
			mes "If you take care of the charges and also the danger pay by investing in the Cat Paw Merchant Guild,";
			mes "we'll create and maintain the gate regardless of the risks.";
			next;
			mes .@n$;
			mes "But then of course the money involved for the gate costs will be extreme.";
			mes "It will be easy if you can find investors to share the amount.";
			next;
			mes .@n$;
			mes "There is a basic charge to start connecting the gate.";
			mes "Results depend on the how much investment money is collected.";
			next;
			mes .@n$;
			mes "The Abyss Gate exists in each Agit region.";
			mes "Can you imagine how much money and sacrifice our guild will have to go through to develop in all areas?";
			next;
			mes .@n$;
			mes "This explains the regional competition in investments.";
			mes "If not enough gate maintenance costs are collected then it is obvious the region with the most investments will receive the benefits";
			next;
			mes .@n$;
			mes "If ^4d4dffthe Abyss Gate is successfully connected then the dungeon of the hideout area";
			mes "will be open to others instead of being guild exclusive^000000 which will be very attractive for investment.";
			next;
			mes .@n$;
			mes "But then again, this is only for when the gate is connected.";
			close;
		case 3:
			mes .@n$;
			mes "It's simple.";
			mes "Visit the branch manager of the ^4d4dffregion you want to invest in during the investment duration^000000 and make your investment.";
			next;
			mes .@n$;
			mes "We usually receive ^4d4dffthe common currency here, Zeny^000000.";
			mes "But since we're talking about supporting our Cat Paw Merchant Guild, you can also invest with items in demand in Malangdo.";
			next;
			mes .@n$;
			mes "Provide the items in need to Namis in Malangdo who is in charge of general affairs in our guild.";
			mes "Bring back your Investment Certificate to add it to the investment tribute.";
			next;
			mes .@n$;
			mes "You must visit and invest at the region you want in order for your investment to be counted as a tribute.";
			close;
		case 4:
			mes .@n$;
			mes "The Abyss Gate is basically contracting and connecting with the castle that owns the Agit;";
			mes "therefore, we will provide all we have once the costs for connecting and maintaining the gate are sufficient.";
			next;
			mes .@n$;
			mes "In terms of the minimum and maximum costs for the whole work,";
			mes "if the collected investment ^4d4dffexceeds the minimum costs^000000, we can connect you to the ^4d4dffdeepest layer of an unknown guild dungeon^000000.";
			next;
			mes .@n$;
			mes "If investments exceed the maximum costs, that region will be connected to the";
			mes "^4d4dffAbyss Gate^000000 regardless of the investment rank which includes the deepest layer of the guild dungeon.";
			next;
			mes .@n$;
			mes "^ff0000If there is no Agit region that reached the maximum investment, then the region with the";
			mes "highest investment participation will get the Abyss Gate connected with the investment collected from all regions.^000000";
			next;
			mes .@n$;
			mes "Once the Abyss Gate is connected, the deepest layer (2F) of the guild dungeon";
			mes "will be open to all adventurers that participated in the regional investment.";
			next;
			mes .@n$;
			mes "Visits to the dungeon will be counted for the next investment for the Agit region";
			mes "so being in good terms with the guild that claims the Agit castle will be a bonus.";
			next;
			mes .@n$;
			mes "By the way, it isn't easy to maintain the connection with the Abyss Gate and investments and reconnection is needed weekly";
			mes "so please continue your support and investment if you want the power of the unknown.";
			close;
		}
	case 3:
		if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 2000) {
			mes "- Currently you're carrying -";
			mes "- too many items with you. -";
			mes "- Please try again after you -";
			mes "- lose some weight. -";
			close;
		}
		if (countitem(Thanks_Invest_Ticket) >= 4800) {
			mes .@n$;
			mes "You have too many Thank You Tickets to receive any more.";
			mes "Cannot give you any more tickets. Please use your ticket and come back.";
			mes "The ticket can be exchanged with various items in Malangdo.";
			close;
		}
		if (callfunc("F_Invest_Status") != 1) {
			mes .@n$;
			mes "We do not receive investments now.";
			mes "Please come back during the investment duration.";
			close;
		}
		.@guild = getcharid(CHAR_ID_GUILD);
		for(.@i = 1; .@i<=5; ++.@i) {
			.@castle_name$[.@i] = getcastlename(.@npc$+"g_cas0"+.@i);
			.@owner_id[.@i] = getcastledata(.@npc$+"g_cas0"+.@i,1);
			.@owner_name$[.@i] = getguildname(.@owner_id[.@i]);
			if (.@guild == .@owner_id[.@i]) {
				.@menu$ = .@menu$+.@castle_name$[.@i]+" ["+.@owner_name$[.@i]+"] Guild:";
				.@castles_owned = .@castles_owned | (1<<.@i);
			} else
				.@menu$ = .@menu$+"^aaaaaaNot the guild that claimed "+.@castle_name$[.@i]+"^000000:";
		}
		mes .@n$;
		mes "Would you like to invest in the ^4d4dff"+.@realm$+"^000000 region?";
		mes "If there is a castle occupied already, you will invest in the castle and the guild that is occupying it.";
		next;
		if (.@castles_owned) {
			.@i = select(.@menu$+"Cancel");
			if (.@i == 6) {
				mes .@n$;
				mes "Canceled.";
				close;
			}
			if (.@guild != .@owner_id[.@i]) {
				mes .@n$;
				mes "The guild that is occupying "+.@castle_name$[.@i]+" is "+.@owner_name$[.@i]+".";
				mes "Doesn't look like your guild.";
				close;
			}
			mes .@n$;
			mes "Invest under "+.@castle_name$[.@i]+"'s"+.@owner_name$[.@i]+" guild name.";
			callfunc "F_Invest_Abyss","$fund_"+.@npc$+"0"+.@i,.@n$;
			end;
		} else {
			mes .@n$;
			callfunc "F_Invest_Abyss","$fund_"+.@npc$+"_extra",.@n$," for "+.@realm$;
			end;
		}
	case 4:
		mes .@n$;
		mes "Is that so?";
		mes "Please come back whenever you are interested in investing in the Abyss Gate development.";
		close;
	}
}

-	script	Gate Manager#realm	FAKE_NPC,{

	if (compare(strnpcinfo(NPC_MAP),"alde")) {
		.@npc$ = "alde";
		.@name$ = "Alkor";
		.@gate$ = "Hero's Tears";
		.@realm$ = "Luina";
	} else if (compare(strnpcinfo(NPC_MAP),"gef")) {
		.@npc$ = "gef";
		.@name$ = "Mizar";
		.@gate$ = "Hill of the Dead";
		.@realm$ = "Britoniah";
	} else if (compare(strnpcinfo(NPC_MAP),"pay")) {
		.@npc$ = "pay";
		.@name$ = "Alkaid";
		.@gate$ = "Winds of the Ancient";
		.@realm$ = "Greenwood Lake";
	} else if (compare(strnpcinfo(NPC_MAP),"prt")) {
		.@npc$ = "prt";
		.@name$ = "Arios";
		.@gate$ = "Way of the Warrior";
		.@realm$ = "Valkyrie Realm";
	}
	.@n$ = "["+.@name$+"]";

	if (callfunc("F_Invest_Status") != 3) {
		mes .@n$;
		mes "There are currently no connected dungeon gates.";
		close;
	}
	.@status = getd("$"+.@npc$+"_invest_result");
	if (.@status == 3) {
		mes .@n$;
		mes "We've successfully connected the Abyss Gate ["+.@gate$+"] with the help from your investment.";
		mes "The Agit dungeon will be open to everyone with a small entrance fee in "+.@realm$+".";
		next;
		mes .@n$;
		mes "Please visit as often as possible since the entrance fee is saved as an investment for the region.";
		mes "Do you want to enter the Agit dungeon?";
		next;
		.@i = select(.@realm$+" Dungeon 1F - 10000z", ""+.@realm$+" Dungeon 2F - 10000z", "Cancel");
		if (.@i == 3) {
			mes .@n$;
			mes "Canceled.";
			close;
		}
		if (Zeny < 10000) {
			mes .@n$;
			mes "I'm collecting a small entrance fee.";
			mes "Your contribution will be saved for the next investment.";
			mes "Entrance fee is 10000z.";
			close;
		}
		mes .@n$;
		mes "I'm sending you to the "+.@realm$+" Agit Dungeon "+.@i+"F.";
		Zeny -= 10000;
		setd "$fund_"+.@npc$+"_extra", getd("$fund_"+.@npc$+"_extra") + 1;
		close2;
		if (compare(strnpcinfo(NPC_NAME_HIDDEN),"alde"))
			warp "gld_dun02"+((.@i == 2)?"_2":""),32,122;
		else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"gef"))
			warp "gld_dun04"+((.@i == 2)?"_2":""),39,258;
		else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"pay"))
			warp "gld_dun01"+((.@i == 2)?"_2":""),186,165;
		else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"prt"))
			warp "gld_dun03"+((.@i == 2)?"_2":""),164,268;
		end;
	} else if (.@status == 2) {
		mes .@n$;
		mes "The "+.@realm$+" Agit Dungeon 2F is now available but since it is not connected with the Abyss Gate,";
		mes "the Agit dungeon is only accessible to the Agit guild.";
		close;
	} else {
		mes .@n$;
		mes .@realm$+" was not chosen to be connected with a gate this time.";
		mes "Please wait for the next investment duration.";
		close;
	}
	end;
}

-	script	Investment Status Board	FAKE_NPC,{
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 1) {
		if (compare(strnpcinfo(NPC_MAP),"alde")) {
			.@npc$ = "alde";
			.@realm$ = "Luina";
		} else if (compare(strnpcinfo(NPC_MAP),"gef")) {
			.@npc$ = "gef";
			.@realm$ = "Britoniah";
		} else if (compare(strnpcinfo(NPC_MAP),"pay")) {
			.@npc$ = "pay";
			.@realm$ = "Greenwood Lake";
		} else if (compare(strnpcinfo(NPC_MAP),"prt")) {
			.@npc$ = "prt";
			.@realm$ = "Valkyrie Realm";
		}
		.@notice = $agit_result_notice;
		if (.@notice < 1 || .@notice > 12) {
			mes "There are currently no investment sums available.";
			close;
		} else if (.@notice == 1)
			.@str$ = "1st";
		else if (.@notice == 2)
			.@str$ = "2nd";
		else if (.@notice == 3)
			.@str$ = "3rd";
		else
			.@str$ = .@notice+"th";
		mes .@str$+" total (unit in 10,000z)";
		for(.@i = 1; .@i<=5; ++.@i) {
			.@map$ = .@npc$+"g_cas0"+.@i;
			.@fund[.@i] = getd("$@vfund_"+.@npc$+"0"+.@i);
			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,1))+" Guild: "+.@fund[.@i];
		}
		.@fund[0] = getd("$@vfund_"+.@npc$+"_extra");
		mes .@realm$+" normal: "+.@fund[0];
		mes .@realm$+" Investment Grand Total: "+(.@fund[0]+.@fund[1]+.@fund[2]+.@fund[3]+.@fund[4]+.@fund[5]);
		close;
	} else if (.@invest_status == 2) {
		mes "!- Notice -!";
		mes "No sums are available because the total investment amount is currently being calculated.";
		mes "Please wait for the announcement of the results.";
		close;
	} else if (.@invest_status == 3) {
		setarray .@invest_result[0], $prt_invest_result,$pay_invest_result,$gef_invest_result,$alde_invest_result;
		setarray .@invest_region$[0],  "Valkyrie Realm",  "Greenwood Lake",       "Britoniah",            "Luina";
		mes "!- Investment Results of All Agit Regions -!";
		for(.@i = 0; .@i<4; ++.@i) {
			if (.@invest_result[.@i] == 1)
				mes "^aaaaaa["+.@invest_region$[.@i]+"] below minimum^000000";
			else if (.@invest_result[.@i] == 2) {
				mes "["+.@invest_region$[.@i]+"] minimum achieved";
				mes "-> Guild Dungeon Deepest Layer (2F) available";
			} else if (.@invest_result[.@i] == 3) {
				mes "^4d4dff["+.@invest_region$[.@i]+"] maximum achieved^000000";
				mes "-> Abyss Gate available";
			} else
				mes "No data for ["+.@invest_region$[.@i]+"].";
		}
		close;
	} else {
		mes "!- Notice -!";
		mes "No investment information will be announced now.";
		close;
	}
}

//== Inside Castles - Gate Managers ========================
-	script	Gate Manager#castle	FAKE_NPC,{

	.@id = atoi(charat(strnpcinfo(NPC_NAME_HIDDEN),getstrlen(strnpcinfo(NPC_NAME_HIDDEN))-1));
	if (compare(strnpcinfo(NPC_NAME_HIDDEN),"alde")) {
		.@npc$ = "alde";
		.@realm$ = "Luina";
	} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"gef")) {
		.@npc$ = "gef";
		.@realm$ = "Britoniah";
	} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"pay")) {
		.@npc$ = "pay";
		.@realm$ = "Greenwood Lake";
	} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"prt")) {
		.@npc$ = "prt";
		.@realm$ = "Valkyrie Realm";
	}

	.@GID = getcastledata(strnpcinfo(NPC_MAP),1);
	if (getcharid(CHAR_ID_GUILD) != .@GID) {
		mes "[Gate Manager]";
		mes "You don't seem to be the member of guild owning this castle.";
		mes "If you need any help, please visit any of our guild members at "+.@realm$+" Square.";
		close;
	}
	mes "[Gate Manager]";
	mes "Hello, I am the Gate Manager from Cat Paw Merchant Guild warp department.";
	mes "How may I help you today?";
	next;
	switch(select("Invest for gate connection", "Deepest Layer Dungeon Access", "Abyss Gate Access", "Cancel")) {
	case 1:
		if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 2000) {
			mes "[Gate Manager]";
			mes "You have too many items to receive the Thank You Ticket as a small gift for your investment.";
			mes "Please come back after making room in your inventory.";
			close;
		}
		if (countitem(Thanks_Invest_Ticket) >= 4800) {
			mes "[Gate Manager]";
			mes "You have too many Thank You Tickets to receive any more.";
			mes "Cannot give you any more tickets. Please use your ticket and come back.";
			mes "The ticket can be exchanged with various items in Malangdo.";
			close;
		}
		if (callfunc("F_Invest_Status") != 1) {
			mes "[Gate Manager]";
			mes "We do not receive investments now.";
			mes "Please come back during the investment duration.";
			close;
		}
		if (getcharid(CHAR_ID_GUILD) != .@GID) {
			mes "[Gate Manager]";
			mes "You don't seem to be the member of the guild owning this castle.";
			mes "Please use the normal investment from "+.@realm$+" Square.";
			close;
		}
		mes "[Gate Manager]";
		mes "Proceed investing under your guild name.";
		callfunc "F_Invest_Abyss","$fund_"+.@npc$+"0"+.@id,"[Gate Manager]";
		end;
	case 2:
		callsub L_Enter,1,.@realm$,.@npc$;
		mes "[Gate Manager]";
		mes "You are interested in exploring the "+.@realm$+" Guild Dungeon Deepest Layer (2F).";
		mes "Let me guide you. Good luck.";
		close2;
		if (compare(strnpcinfo(NPC_NAME_HIDDEN),"alde")) {
			switch(.@id) {
				case 1: warp "gld_dun02_2",32,122; end;
				case 2: warp "gld_dun02_2",79,30; end;
				case 3: warp "gld_dun02_2",165,38; end;
				case 4: warp "gld_dun02_2",160,148; end;
				case 5: warp "gld_dun02_2",103,169; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"gef")) {
			switch(.@id) {
				case 1: warp "gld_dun04_2",39,258; end;
				case 2: warp "gld_dun04_2",125,270; end;
				case 3: warp "gld_dun04_2",268,251; end;
				case 4: warp "gld_dun04_2",268,108; end;
				case 5: warp "gld_dun04_2",230,35; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"pay")) {
			switch(.@id) {
				case 1: warp "gld_dun01_2",186,165; end;
				case 2: warp "gld_dun01_2",54,165; end;
				case 3: warp "gld_dun01_2",54,39; end;
				case 4: warp "gld_dun01_2",186,39; end;
				case 5: warp "gld_dun01_2",223,202; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"prt")) {
			switch(.@id) {
				case 1: warp "gld_dun03_2",28,251; end;
				case 2: warp "gld_dun03_2",164,268; end;
				case 3: warp "gld_dun03_2",164,179; end;
				case 4: warp "gld_dun03_2",268,203; end;
				case 5: warp "gld_dun03_2",199,28; end;
			}
		}
		end;
	case 3:
		callsub L_Enter,2,.@realm$,.@npc$;
		mes "[Gate Manager]";
		mes "Let me guide you to the Abyss Gap connected with "+.@realm$+", the Abyss Gate 'Way of the Warrior'.";
		close2;
		if (compare(strnpcinfo(NPC_NAME_HIDDEN),"alde")) {
			switch(.@id) {
				case 1: warp "gld2_ald",175,41; end;
				case 2: warp "gld2_ald",77,64; end;
				case 3: warp "gld2_ald",46,127; end;
				case 4: warp "gld2_ald",104,246; end;
				case 5: warp "gld2_ald",241,156; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"gef")) {
			switch(.@id) {
				case 1: warp "gld2_gef",28,199; end;
				case 2: warp "gld2_gef",217,46; end;
				case 3: warp "gld2_gef",171,195; end;
				case 4: warp "gld2_gef",30,67; end;
				case 5: warp "gld2_gef",115,40; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"pay")) {
			switch(.@id) {
				case 1: warp "gld2_pay",33,112; end;
				case 2: warp "gld2_pay",119,27; end;
				case 3: warp "gld2_pay",205,111; end;
				case 4: warp "gld2_pay",175,221; end;
				case 5: warp "gld2_pay",61,221; end;
			}
		} else if (compare(strnpcinfo(NPC_NAME_HIDDEN),"prt")) {
			switch(.@id) {
				case 1: warp "gld2_prt",10,27; end;
				case 2: warp "gld2_prt",14,247; end;
				case 3: warp "gld2_prt",259,236; end;
				case 4: warp "gld2_prt",226,25; end;
				case 5: warp "gld2_prt",97,11; end;
			}
		}
		end;
	case 4:
		mes "[Gate Manager]";
		mes "Canceled.";
		close;
	}
	end;

L_Enter:
	.@invest_status = callfunc("F_Invest_Status");
	if (.@invest_status == 3) {
		.@status = getd("$"+getarg(2)+"_invest_result");
		if ((getarg(0) == 1 && .@status == 2) || .@status == 3)
			return;
		else {
			mes "[Gate Manager]";
			mes getarg(1)+" was not chosen to be connected with a gate this time.";
			mes "Please wait for the next investment duration.";
			close;
		}
	} else if (.@invest_status < 3) {
		mes "[Gate Manager]";
		mes "There are currently no connected dungeon gates.";
		mes "A gate will be connected as soon as the investment results are available.";
		mes "Please wait.";
		close;
	} else {
		mes "[Gate Manager]";
		mes "The gate will disappear soon.";
		mes "The dungeon is no longer accessible.";
		mes "Please try again next time.";
		close;
	}
}

//== Item Investments ======================================
malangdo,218,126,4	script	Cat Paw Merchants Notice	4_BOARD3,{
	mes "<< Cat Paw Merchants Notice >>";
	mes "'^C379CEInvest Unused Items for Prizes!^000000'";
	next;
	switch(select("Read Notice", "Check Event 1", "Check Event 2")) {
	case 1:
		mes "- Notice -";
		mes "Hello all Cat Paw Merchants customers! With your love, we Cat Paw Merchants are growing every day. All executives and staff members promise to do our best to further our frontier and development.";
		next;
		mes "- Event Notice! -";
		mes " An Event called '^C379CEInvest Unused Items for Prizes!^000000' is under way, where you could exchange unused items in your storage for Investment Certificate of the Cat Paw Merchants.";
		next;
		mes "Exchangeable items will be announced on a separate sheet. Thank you for your time.";
		mes "- From all the employees of Cat Paw Merchants -";
		next;
		mes "There is a small warning at the bottom.";
		mes " ";
		mes "^FF0000This event could be changed or repealed due to the Merchants' situation.^000000";
		close;
	case 2:
		mes "'^C379CEInvest Unused Items for Prizes!^000000'";
		mes "There are details of Event 1.";
		next;
		setarray .@event1$[0],
			"Wings of the Insect Queen","Crown of the Fly King","I hear Dragon Scales are tough 01","The Meaning of the Mother's Nightmare",
			"To refine ore","Hekekek Orcs, Orcs!!","Study of Yin-Yang","Secrets of the Pyramid King","Tick-tock the time goes",
			"Planting trees on Mellow Island","Ancient language research","Weapons made of sharp teeth","Toy boss doll 01",
			"A tiger is just a cat after all","The shattered spear and shield?","Toy boss doll 02","Best in summer! Cold scales",
			"Piece of Thanatos' armor","I hear Dragon Scales are tough 02","The identity of the creepy eye","If only I could see!";
		.@menu$ = "Quit:"+implode(.@event1$[0],":");
		while(1) {
			.@i = select(.@menu$)-1;
			switch(.@i) {
				case 0: close;
				case 1: .@str$ = "2 Pieces of Queen's Wing"; break;
				case 2: .@str$ = "2 Broken Crowns"; break;
				case 3: .@str$ = "2 Fire Dragon Scales"; break;
				case 4: .@str$ = "3 Mother's Nightmares"; break;
				case 5: .@str$ = "5 Gemstones"; break;
				case 6: .@str$ = "5 Heroic Emblems"; break;
				case 7: .@str$ = "3 Taeguk Plates"; break;
				case 8: .@str$ = "3 Broken Pharaoh Symbols and 3 Tutankhamen's Masks"; break;
				case 9: .@str$ = "2 Pocket Watches"; break;
				case 10: .@str$ = "3 Young Twigs"; break;
				case 11: .@str$ = "5 Rossata Pieces"; break;
				case 12: .@str$ = "5 Fangs of Garm"; break;
				case 13: .@str$ = "3 Baphomet Dolls"; break;
				case 14: .@str$ = "1 Tiger's Footskin and 5 Tiger Skins"; break;
				case 15: .@str$ = "3 Broken Shield Pieces and 3 Shining Spear Blades"; break;
				case 16: .@str$ = "3 Osiris Dolls"; break;
				case 17: .@str$ = "1 Ice Scale"; break;
				case 18: .@str$ = "1 Skeletal Armor Piece"; break;
				case 19: .@str$ = "1 Darkred Scale Piece"; break;
				case 20: .@str$ = "2 Wills of Red Darkness"; break;
				case 21: .@str$ = "2 Foolishness of the Blind"; break;
			}
			mes "["+.@event1$[.@i-1]+"]";
			mes .@str$+" for one Cat Paw Merchants Investment Certificate.";
			next;
		}
	case 3:
		mes "Look out for the next '^C379CEInvest Unused Items for Prizes!^000000' Event 2!! Coming up real soon!";
		close;
	}
}

malangdo,218,123,1	script	Namis#invest	4_CAT_SAILOR2,4,4,{
	if (checkweight(Knife,1) == 0 || MaxWeight - Weight < 1000) {
		mes "- Currently you're carrying -";
		mes "- too many items with you. -";
		mes "- Please try again after you -";
		mes "- lose some weight. -";
		close;
	}
	emotion e_omg;
	emotion e_an;
	emotion e_ag;
	mes "[Namis]";
	mes "Purr-Purr-Purrr-Purrrr-Pur~ Meow!!";
	mes "Wh-- What? How rude. You scared me.";
	next;
	switch(select("What do you need? I'll invest!", "What's the purpose of this event?", "Were you asleep?")) {
	case 1:
		break;
	case 2:
		mes "[Namis]";
		mes "So, another pushover in contract with the Cat Paw Merchants?";
		next;
		select("Huh? What! You calling me a pushover?");
		mes "[Namis]";
		mes "I'll say this just once, so you listen good!";
		mes "We, the Cat Paw Merchants have planned an event for loyal workers like yourself.";
		next;
		mes "[Namis]";
		mes "Run along to your storage and bring back rotting antiques to us and we'll exchange them for the oh-so valuable 'Cat Paw Merchants Investment Certificate'.";
		next;
		mes "[Namis]";
		mes "It will be wise for you to do so because the Cat Paw Merchants are doing this at a loss!";
		next;
		mes "[Namis]";
		mes "Details are on the notice.";
		close;
	case 3:
		mes "[Namis]";
		mes "Hick- Slurp-";
		mes "Remember, human! There's no other cat who works as hard as I do.";
		close;
	}
	mes "[Namis]";
	mes "You must be here to participate in the '^C379CEInvest Unused Items for Prizes!^000000' event of the Cat Paw Merchants.";
	next;
	mes "[Namis]";
	mes "So, which event do you wish to participate in?";
	next;
	switch(select("Not interested", "Event 1 Items", "Event 2 Items")) {
	case 1:
		mes "[Namis]";
		mes "Don't you mess with a busy cat!";
		close;
	case 2:
		mes "[Namis]";
		mes "So you're in for Event 1.";
		mes "Choose from the shown list.";
		next;
		setarray .@event1$[0],
			"Wings of the Insect Queen","Crown of the Fly King","I hear Dragon Scales are tough 01","The Meaning of the Mother's Nightmare",
			"To refine ore","Hekekek Orcs, Orcs!!","Study of Yin-Yang","Secrets of the Pyramid King","Tick-tock the time goes",
			"Planting trees on Mellow Island","Ancient language research","Weapons made of sharp teeth","Toy boss doll 01",
			"A tiger is just a cat after all","The shattered spear and shield?","Toy boss doll 02","Best in summer! Cold scales",
			"Piece of Thanatos' armor","I hear Dragon Scales are tough 02","The identity of the creepy eye","If only I could see!";
		.@i = select(implode(.@event1$[0],":"))-1;
		switch(.@i+1) {
		case 1:
			callsub(L_Check, "2 Pieces of Queen's Wing", Queen_Wing_Piece, 2, "Wings of the Insect Queen? What a pitiful name. I would've given some cool names!", .@event1$[.@i]);
		case 2:
			callsub(L_Check, "2 Broken Crowns", Broken_Crown, 2, "For crying out loud! Those cats working on these events must be playing around. Can't they think of a better name?", .@event1$[.@i]);
		case 3:
			callsub(L_Check, "2 Fire Dragon Scales", Scale_Of_Red_Dragon, 2, "Dragon scales? Well... I guess they are tough. But what are they going to use them for?", .@event1$[.@i]);
		case 4:
			callsub(L_Check, "3 Mother's Nightmares", Mothers_Nightmare, 3, "Even though I don't have the authority to find out, I wonder what they're doing with the collected items?", .@event1$[.@i]);
		case 5:
			callsub(L_Check, "5 Gemstones", Gemstone, 5, "Something useful for a change. The ore will end up as nice pieces of jewelry.", .@event1$[.@i]);
		case 6:
			callsub(L_Check, "5 Heroic Emblems", Voucher_Of_Orcish_Hero, 5, "Good, good. This is the kind of name I wanted!", .@event1$[.@i]);
		case 7:
			callsub(L_Check, "3 Taeguk Plates", Taegeuk_Plate, 3, "Taking in something like this, maybe they're up to something dangerous.", .@event1$[.@i]);
		case 8:
			callsub(L_Check, "3 Broken Pharaoh Symbols and 3 Tutankhamen's Masks", Broken_Pharaoh_Symbol, 3, "I hear the pyramids are in Morroc, but I've never been there. Some humans call it Morco.", .@event1$[.@i], Tutankhamens_Mask, 3);
		case 9:
			callsub(L_Check, "2 Pocket Watches", Pocket_Watch, 2, "Those lazy merchants, why do they need pocket watches they don't even use?", .@event1$[.@i]);
		case 10:
			callsub(L_Check, "3 Young Twigs", Young_Twig, 3, "Mellow Island has a climate like with where we cats used to live. But the trees die out sometimes due to it being an island.", .@event1$[.@i]);
		case 11:
			callsub(L_Check, "5 Rossata Pieces", Rojerta_Piece, 5, "I guess they collect these because humans have them, but what's the use of researching ancient languages?", .@event1$[.@i]);
		case 12:
			callsub(L_Check, "5 Fangs of Garm", Fang_Of_Garm, 5, "Weak humans need sharp weapons, but cats already have nice and sharp claws, so why are we collecting these!!", .@event1$[.@i]);
		case 13:
			callsub(L_Check, "3 Baphomet Dolls", Baphomet_Doll, 3, "Baphomet dolls are great for playing around with.", .@event1$[.@i]);
		case 14:
			callsub(L_Check, "1 Tiger's Footskin and 5 Tiger Skins", Tiger_Footskin, 1, "Did you know that tigers are cats too? Therefore, cats are better than tigers.", .@event1$[.@i], Tigers_Skin, 5);
		case 15:
			callsub(L_Check, "3 Broken Shield Pieces and 3 Shining Spear Blades", Boroken_Shiled_Piece, 3, "I don't know what they want with these.", .@event1$[.@i], Shine_Spear_Blade, 3);
		case 16:
			callsub(L_Check, "3 Osiris Dolls", Osiris_Doll, 3, "Shame~ I never got to play with an Osiris doll.", .@event1$[.@i]);
		case 17:
			callsub(L_Check, "1 Ice Scale", Ice_Scale, 1, "Mellow Island is a fabulous place to live. But the ships are too hot.", .@event1$[.@i]);
		case 18:
			callsub(L_Check, "1 Skeletal Armor Piece", Piece_Of_Bone_Armor, 1, "Ewww... Why would they collect something so creepy?", .@event1$[.@i]);
		case 19:
			callsub(L_Check, "1 Darkred Scale Piece", Dark_Red_Scale, 1, "Dragon scales? Well... I guess they are tough. But what are they going to use them for?", .@event1$[.@i]);
		case 20:
			callsub(L_Check, "2 Wills of Red Darkness", Will_Of_Darkness_, 2, "Interesting! Does it scream or something when I poke it in the eye?", .@event1$[.@i]);
		case 21:
			callsub(L_Check, "2 Foolishness of the Blind", Foolishness_Of_Blind, 2, "This blind man is foolish in not knowing that gathering 300 cats cures blindness...", .@event1$[.@i]);
		}
	case 3:
		mes "[Namis]";
		mes "Participate in Event 2?";
		mes "It is not yet in motion. Wait for it!";
		close;
	}
	end;
L_Check:
	.@args = getargcount();
	if (.@args > 5) {
		if (countitem(getarg(5)) < getarg(6))
			.@items = 1; //incomplete
		else
			.@items = 2; //complete
	}
	if (countitem(getarg(1)) < getarg(2) || .@items == 1) {
		mes "[Namis]";
		mes "You don't have the items?";
		mes getarg(0)+" exchange for one Cat Paw Merchants Investment Certificate.";
		next;
		mes "[Namis]";
		mes "Don't bother me and look up the details on the board over there!";
		close;
	}
	mes "[Namis]";
	mes "'^8E5601"+getarg(4)+" Event^000000'";
	mes "Seems to be the right items.";
	mes getarg(3);
	mes "Oh! Almost forgot. Will you invest?";
	next;
	if(select("Invest", "Don't Invest") == 2) {
		mes "[Namis]";
		mes "Don't you mess with a busy cat!";
		close;
	}
	delitem getarg(1),getarg(2);
	if (.@items == 2)
		delitem getarg(5),getarg(6);
	getitem Cats_Invest_Certif,1;
	mes "[Namis]";
	mes "Here's your Certificate. Always be grateful to the Merchants for these events!";
	close;
OnTouch:
	if (rand(2))
		emotion e_yawn;
	else
		specialeffect EF_SLEEPATTACK;
	end;
}

//== Investment Rewards ====================================
malangdo,215,119,4	script	Thanks Ticket Machine	2_VENDING_MACHINE1,{
	if (MaxWeight - Weight < 4500 || checkweight(Knife,1) == 0) {
		mes "- Currently you're carrying -";
		mes "- too many items with you. -";
		mes "- Please try again after you -";
		mes "- lose some weight. -";
		close;
	}
	mes "[Vending Machine Notice]";
	mes "^6815EA1. Don't kick the machine please. @_@";
	mes "2. You can only insert Invest Thanks Ticket.";
	mes "3. About the Jelly Box, if you open it, it gives you a random item.";
	mes "4. Hope you enjoy~^000000";
	mes "- Mr. Cat, the Machine Owner -";
	next;
	switch(select("Finish", "Purchase", "Red Paw Jelly Bag (5 Tickets)", "Black Paw Jelly Bag (50 Tickets)")) {
	case 1:
		close;
	case 2:
		mes "The Vending Machine is selling items in the following list.";
		next;
		switch(select("Finish", "1 Siege Arrow Quiver A (2 Tickets)", "1 Siege Arrow Quiver S (2 Tickets)", "30 White Potion (12 Tickets)", "30 White Slim Potion (14 Tickets)", "10 Dark Water (20 Tickets)", "20 Siege_Violet_Potion (30 Tickets)", "10 Coldproof Potion (30 Tickets)", "10 Thunderproof Potion (30 Tickets)", "10 Earthproof Potion (30 Tickets)", "10 Fireproof Potion (30 Tickets)", "10 Elemental Converter[Fire] (30 Tickets)")) {
		case 1:
			close;
		case 2:
			callsub(L_Purchase, 2, Siege_Arrow_Quiver_A, 1);
		case 3:
			callsub(L_Purchase, 2, Siege_Arrow_Quiver_S, 1);
		case 4:
			callsub(L_Purchase, 12, White_Potion, 30);
		case 5:
			callsub(L_Purchase, 14, White_Slim_Potion, 30);
		case 6:
			callsub(L_Purchase, 20, Water_Of_Darkness, 10);
		case 7:
			callsub(L_Purchase, 30, Woe_Violet_Potion, 20);
		case 8:
			callsub(L_Purchase, 30, Resist_Water, 10);
		case 9:
			callsub(L_Purchase, 30, Resist_Wind, 10);
		case 10:
			callsub(L_Purchase, 30, Resist_Earth, 10);
		case 11:
			callsub(L_Purchase, 30, Resist_Fire, 10);
		case 12:
			callsub(L_Purchase, 30, Elemental_Fire, 10, "Elemental Converter[Fire]");
		case 13:
			callsub(L_Purchase, 30, Elemental_Water, 10, "Elemental Converter[Water]");
		case 14:
			callsub(L_Purchase, 30, Elemental_Wind, 10, "Elemental Converter[Wind]");
		case 15:
			callsub(L_Purchase, 30, Elemental_Earth, 10, "Elemental Converter[Earth]");
		}
		end;
	case 3:
		mes "Red Paw Jelly Bag Button chosen. Need to insert 5 ^FF0000Invest Thanks Ticket^000000 and a random item will appear.";
		next;
		if (countitem(Thanks_Invest_Ticket) < 5) {
			mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
			close;
		}
		delitem(Thanks_Invest_Ticket, 5);
		.@i = rand(1, 10000);
		if (.@i <= 100)
			callsub(L_Bag, White_Potion_Box, 1);
		else if (.@i <= 200)
			callsub(L_Bag, White_Slim_Pot_Box2, 1);
		else if (.@i <= 250)
			callsub(L_Bag, Woe_Blue_Potion, 10);
		else if (.@i <= 660)
			callsub(L_Bag, Old_Violet_Box, 1);
		else if (.@i <= 710)
			callsub(L_Bag, Royal_Jelly_Box2, 1);
		else if (.@i <= 760)
			callsub(L_Bag, Blue_Herb_Box2, 1);
		else if (.@i <= 810)
			callsub(L_Bag, Blue_Potion, 5);
		else if (.@i <= 1110)
			callsub(L_Bag, Gift_Box, 1);
		else if (.@i <= 1120)
			callsub(L_Bag, Yggdrasilberry, 1);
		else if (.@i <= 1130)
			callsub(L_Bag, Seed_Of_Yggdrasil, 2);
		else if (.@i <= 1140)
			callsub(L_Bag, Unripe_Fruit, 5);
		else if (.@i <= 1150)
			callsub(L_Bag, Dried_Yggdrasilberry, 5);
		else if (.@i <= 1250)
			callsub(L_Bag, Sg_White_Potion_Box, 1);
		else if (.@i <= 1471)
			callsub(L_Bag, Old_Blue_Box, 1);
		else if (.@i <= 1571)
			callsub(L_Bag, Poison_Bottle_Box2, 1, "Poison Bottle Box(30);");
		else if (.@i <= 1671)
			callsub(L_Bag, Water_Of_Darkness, 10);
		else if (.@i <= 1871)
			callsub(L_Bag, Box_Of_Grudge, 5);
		else if (.@i <= 2071)
			callsub(L_Bag, Sleepy_Box, 5);
		else if (.@i <= 2371)
			callsub(L_Bag, Box_Of_Sunlight, 2);
		else if (.@i <= 2571)
			callsub(L_Bag, Elemental_Fire, 5, "Elemental Converter[Fire]");
		else if (.@i <= 2771)
			callsub(L_Bag, Elemental_Water, 5, "Elemental Converter[Water]");
		else if (.@i <= 2971)
			callsub(L_Bag, Elemental_Earth, 5, "Elemental Converter[Wind]");
		else if (.@i <= 3171)
			callsub(L_Bag, Elemental_Wind, 5, "Elemental Converter[Earth]");
		else if (.@i <= 3271)
			callsub(L_Bag, Sg_Blue_Potion_Box, 1);
		else if (.@i <= 3471)
			callsub(L_Bag, Resist_Fire, 5);
		else if (.@i <= 3671)
			callsub(L_Bag, Resist_Water, 5);
		else if (.@i <= 3871)
			callsub(L_Bag, Resist_Wind, 5);
		else if (.@i <= 4071)
			callsub(L_Bag, Resist_Earth, 5);
		else if (.@i <= 4271)
			callsub(L_Bag, Immortal_Heart, 20);
		else if (.@i <= 4471)
			callsub(L_Bag, Transparent_Cloth, 20);
		else if (.@i <= 4671)
			callsub(L_Bag, Stem, 20);
		else if (.@i <= 4871)
			callsub(L_Bag, Aloebera, 10);
		else if (.@i <= 5071)
			callsub(L_Bag, Amulet, 10);
		else if (.@i <= 5271)
			callsub(L_Bag, Illusion_Flower, 2);
		else if (.@i <= 5471)
			callsub(L_Bag, Prickly_Fruit, 20);
		else if (.@i <= 5671)
			callsub(L_Bag, Bitter_Herb, 10);
		else if (.@i <= 5871)
			callsub(L_Bag, Izidor, 10);
		else if (.@i <= 6071)
			callsub(L_Bag, Anodyne, 10);
		else if (.@i <= 6171)
			callsub(L_Bag, Woe_White_Potion, 10);
		else if (.@i <= 6371)
			callsub(L_Bag, Four_Leaf_Clover, 10);
		else if (.@i <= 6571)
			callsub(L_Bag, Leaflet_Of_Aloe, 10);
		else if (.@i <= 6771)
			callsub(L_Bag, Singing_Plant, 10);
		else if (.@i <= 6971)
			callsub(L_Bag, Leaf_Of_Yggdrasil, 10);
		else if (.@i <= 7021)
			callsub(L_Bag, Sg_Violet_Potion_Box, 1);
		else if (.@i <= 7171)
			callsub(L_Bag, Savage_Meat, 10);
		else if (.@i <= 7321)
			callsub(L_Bag, Wolf_Blood, 10);
		else if (.@i <= 7471)
			callsub(L_Bag, Beef_Head_Meat, 10);
		else if (.@i <= 7621)
			callsub(L_Bag, Cold_Ice, 10);
		else if (.@i <= 7771)
			callsub(L_Bag, Ice_Fragment, 10);
		else if (.@i <= 7921)
			callsub(L_Bag, Ice_Crystal, 10);
		else if (.@i <= 8071)
			callsub(L_Bag, Petti_Tail, 10);
		else if (.@i <= 8309)
			callsub(L_Bag, Poison_Herb_Nerium, 20);
		else if (.@i <= 8547)
			callsub(L_Bag, Poison_Herb_Rantana, 20);
		else if (.@i <= 8785)
			callsub(L_Bag, Poison_Herb_Makulata, 20);
		else if (.@i <= 9023)
			callsub(L_Bag, Poison_Herb_Seratum, 20);
		else if (.@i <= 9261)
			callsub(L_Bag, Poison_Herb_Scopolia, 20);
		else if (.@i <= 9499)
			callsub(L_Bag, Poison_Herb_Amoena, 20);
		else if (.@i <= 9699)
			callsub(L_Bag, Mandragora_Flowerpot, 20);
		else
			callsub(L_Bag, Speed_Up_Potion, 10);
		end;
	case 4:
		mes "Black Paw Jelly Bag Button chosen. Need to insert 50 ^FF0000Invest Thanks Ticket^000000 and a random item will appear.";
		next;
		if (countitem(Thanks_Invest_Ticket) < 50) {
			mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
			close;
		}
		delitem(Thanks_Invest_Ticket, 50);
		.@i = rand(1, 10000);
		if (.@i <= 100)
			callsub(L_Bag, White_Potion_Box, 1);
		else if (.@i <= 200)
			callsub(L_Bag, White_Slim_Pot_Box2, 1);
		else if (.@i <= 250)
			callsub(L_Bag, Woe_Blue_Potion, 20);
		else if (.@i <= 450)
			callsub(L_Bag, Old_Violet_Box, 1);
		else if (.@i <= 500)
			callsub(L_Bag, Royal_Jelly_Box2, 1);
		else if (.@i <= 550)
			callsub(L_Bag, Blue_Herb_Box2, 1);
		else if (.@i <= 600)
			callsub(L_Bag, Blue_Potion, 10);
		else if (.@i <= 800)
			callsub(L_Bag, Gift_Box, 1);
		else if (.@i <= 810)
			callsub(L_Bag, Yggdrasilberry, 2);
		else if (.@i <= 820)
			callsub(L_Bag, Seed_Of_Yggdrasil, 3);
		else if (.@i <= 830)
			callsub(L_Bag, Unripe_Fruit, 10);
		else if (.@i <= 840)
			callsub(L_Bag, Dried_Yggdrasilberry, 10);
		else if (.@i <= 940)
			callsub(L_Bag, Sg_White_Potion_Box, 1);
		else if (.@i <= 1140)
			callsub(L_Bag, Old_Blue_Box, 1);
		else if (.@i <= 1240)
			callsub(L_Bag, Poison_Bottle_Box2, 1, "Poison Bottle Box(30)");
		else if (.@i <= 1340)
			callsub(L_Bag, Water_Of_Darkness, 20);
		else if (.@i <= 1440)
			callsub(L_Bag, Box_Of_Grudge, 10);
		else if (.@i <= 1540)
			callsub(L_Bag, Sleepy_Box, 10);
		else if (.@i <= 1690)
			callsub(L_Bag, Box_Of_Sunlight, 4);
		else if (.@i <= 1790)
			callsub(L_Bag, Elemental_Fire, 10, "Elemental Converter[Fire]");
		else if (.@i <= 1890)
			callsub(L_Bag, Elemental_Water, 10, "Elemental Converter[Water]");
		else if (.@i <= 1990)
			callsub(L_Bag, Elemental_Wind, 10, "Elemental Converter[Wind]");
		else if (.@i <= 2090)
			callsub(L_Bag, Elemental_Earth, 10, "Elemental Converter[Earth]");
		else if (.@i <= 2190)
			callsub(L_Bag, Sg_Blue_Potion_Box, 1);
		else if (.@i <= 2290)
			callsub(L_Bag, Resist_Fire, 10);
		else if (.@i <= 2390)
			callsub(L_Bag, Resist_Water, 10);
		else if (.@i <= 2490)
			callsub(L_Bag, Resist_Wind, 10);
		else if (.@i <= 2590)
			callsub(L_Bag, Resist_Earth, 10);
		else if (.@i <= 2690)
			callsub(L_Bag, Immortal_Heart, 40);
		else if (.@i <= 2790)
			callsub(L_Bag, Transparent_Cloth, 40);
		else if (.@i <= 2890)
			callsub(L_Bag, Stem, 40);
		else if (.@i <= 2990)
			callsub(L_Bag, Aloebera, 20);
		else if (.@i <= 3090)
			callsub(L_Bag, Amulet, 20);
		else if (.@i <= 3190)
			callsub(L_Bag, Illusion_Flower, 4);
		else if (.@i <= 3290)
			callsub(L_Bag, Prickly_Fruit, 40);
		else if (.@i <= 3390)
			callsub(L_Bag, Bitter_Herb, 20);
		else if (.@i <= 3490)
			callsub(L_Bag, Izidor, 20);
		else if (.@i <= 3590)
			callsub(L_Bag, Anodyne, 20);
		else if (.@i <= 3690)
			callsub(L_Bag, Woe_White_Potion, 20);
		else if (.@i <= 3790)
			callsub(L_Bag, Four_Leaf_Clover, 20);
		else if (.@i <= 3890)
			callsub(L_Bag, Leaflet_Of_Aloe, 20);
		else if (.@i <= 3990)
			callsub(L_Bag, Singing_Plant, 20);
		else if (.@i <= 4090)
			callsub(L_Bag, Leaf_Of_Yggdrasil, 20);
		else if (.@i <= 4140)
			callsub(L_Bag, Sg_Violet_Potion_Box, 1);
		else if (.@i <= 4240)
			callsub(L_Bag, Savage_Meat, 20);
		else if (.@i <= 4340)
			callsub(L_Bag, Wolf_Blood, 20);
		else if (.@i <= 4440)
			callsub(L_Bag, Beef_Head_Meat, 20);
		else if (.@i <= 4540)
			callsub(L_Bag, Cold_Ice, 20);
		else if (.@i <= 4640)
			callsub(L_Bag, Ice_Fragment, 20);
		else if (.@i <= 4740)
			callsub(L_Bag, Ice_Crystal, 20);
		else if (.@i <= 4840)
			callsub(L_Bag, Petti_Tail, 20);
		else if (.@i <= 4940)
			callsub(L_Bag, Poison_Herb_Nerium, 40);
		else if (.@i <= 5040)
			callsub(L_Bag, Poison_Herb_Rantana, 40);
		else if (.@i <= 5140)
			callsub(L_Bag, Poison_Herb_Makulata, 40);
		else if (.@i <= 5240)
			callsub(L_Bag, Poison_Herb_Seratum, 40);
		else if (.@i <= 5340)
			callsub(L_Bag, Poison_Herb_Scopolia, 40);
		else if (.@i <= 5440)
			callsub(L_Bag, Poison_Herb_Amoena, 40);
		else if (.@i <= 5540)
			callsub(L_Bag, Mandragora_Flowerpot, 40);
		else if (.@i <= 6000)
			callsub(L_Bag, Speed_Up_Potion, 20);
		else if (.@i <= 6500)
			callsub(L_Bag, Siege_Greave, 1);
		else if (.@i <= 7000)
			callsub(L_Bag, Siege_Boots, 1);
		else if (.@i <= 7500)
			callsub(L_Bag, Siege_Shoes, 1);
		else if (.@i <= 8000)
			callsub(L_Bag, Siege_Manteau, 1);
		else if (.@i <= 8500)
			callsub(L_Bag, Siege_Muffler, 1);
		else if (.@i <= 9000)
			callsub(L_Bag, Siege_Plate, 1);
		else if (.@i <= 9500)
			callsub(L_Bag, Siege_Suits, 1);
		else
			callsub(L_Bag, Siege_Robe, 1);
		end;
	}
	end;

//callsub L_Purchase,<ticket cost>,<reward ID>,<reward amount>{,<reward name>};
L_Purchase:
	if (countitem(Thanks_Invest_Ticket) < getarg(0)) {
		mes "You don't have enough ^FF0000Invest Thanks Ticket^000000 to proceed.";
		close;
	}
	delitem Thanks_Invest_Ticket,getarg(0);
	getitem getarg(1),getarg(2);
	mes "- Done! -";
	next;
	mes "The item ^0000FF"+((getargcount() > 3)?getarg(3,""):getitemname(getarg(1)))+"^000000 has been obtained.";
	close;

//callsub L_Bag,<reward ID>,<reward amount>{,<reward name>};
L_Bag:
	getitem getarg(0),getarg(1);
	mes "- Done! -";
	next;
	mes "The item ^0000FF"+((getargcount() > 2)?getarg(2,""):getitemname(getarg(0)))+"^000000 has been obtained.";
	close;
}