//enter
script "guildquest1_enter" {
	// entering available
	nRet = target.canEnterGuildQuest;
	if ( nRet == 1 ) { 
		self.say( "You are on your way to entering Sharenian. The door to Sharenian will open 3 minutes after entering." );
		takeawayitem;
		
		//----------- if party members have the party items before starting the pq
		party_hack = party_check_item;
		if (party_hack == 1) {
			self.say( "A member in your party has an inappropriate item. Please try again." );
			end;
		}
		//------------
			
		set = FieldSet( "Guild1" );
		result = set.enter( target.nCharacterID, 0 );
		if ( result != 0 ) self.say( "The Guild Quest is currently not ready, and therefore closed. Please try again later." );
		end;
	}
	else if ( nRet == 2 ) {
	
		set = FieldSet( "Guild1" );
		if ( set.getUserCount >= 30 ) {
			self.say( "Unable to join the Guild Quest due to all 30 slots for the Guild Quest being filled with participants." );
			end;
		} else {
		  self.say( "You are on your way to entering Sharenian. The door to Sharenian will open 3 minutes after entering." );
		  takeawayitem;
		
		  //----------- if party members have the party items before starting the pq
		  party_hack = party_check_item;
		  if (party_hack == 1) {
			self.say( "A member in your party has an inappropriate item. Please try again." );
			end;
		  }
		  //------------
		
		registerTransferField( 990000000, "" );
		end;
		}
	}

	guildcount = self.dealWithGuildQuest( 0 ); 
	while ( 1 ) {
		v0 = self.askMenu( "Hello, there. I'm Shuang, one of the relic excavators stationed here. I'm in charge of the registration for exploring <Sharenian> and the Guild Quest. To find out the requirements to join this quest, please check out the notice at the left bulletin board. \r\n#b#L0# Register for the Guild Quest#l \r\n#b#L1# The Waitlist for the Guild Quest#l\r\n#b#L2# Cancel registration#l " );

		if ( v0 == 0 ) {
			// target is not a guild master or vice master. not a proper guild
			if ( target.isGuildMaster != 1 and target.isGuildSubMaster != 1 ) {
				self.say( "Only the Master and the Jr. Master of the Guild may register for the Guild." );
				end;
			}

				//ask to register
			if ( guildcount < 0 ) { // already registered -guildcount is a channel number
				if ( guildcount == -2 ) self.say( "Your Guild is already registered at Channel 2." );
				else self.say( "Your Guild is already registered at Channel " + (-guildcount) + ".");
			} else {
				say = "";
				if ( guildcount == 0 ) say = "You'll be entering Sharenian really soon. Once it reaches your turn, you'll have 3 minutes to gather up at least 6 members of your Guild here and enter the place through me. Would you like to register and wait?";
				else if ( guildcount == 1 ) say = "There's currently 1 Guild participating in the quest, and, no other guild is waiting in line. Would you like to register and wait?";
				else say = "There's currently 1 Guild participating in the quest, and, " + string( guildcount - 1 ) + " other Guild(s) are waiting in line. Would you like to register and wait?";
				nRet = self.askYesNo( say );
				if ( nRet == 0 ) self.say( "I'm ridiculously busy here, so please make a decision immediately and then talk to me." );
				else {
					nRet = self.dealWithGuildQuest( 1 );
					if ( nRet == 1 ) self.say( "Your Guild has been registered, so please wait. Talk to me when your turn comes." );
					else if ( nRet < 0 ) {
						if ( guildcount == -2 ) say = "Your Guild is already registered at Channel 2.";
						else say = "You're already registered at Channel " + (-guildcount) + ".";
						self.say( say );
					}
					else self.say( "Something's not right here. The registration's not working..." );
				}
			}
			end;
		} else if ( v0 == 1 ) {
			//register view
			waitNum = self.dealWithGuildQuest( 3 );
			if ( waitNum == -1 ) {
				if ( guildcount > 0 )  {
				
					if ( guildcount == 1 )  self.say( "No other guild is waiting in line.\r I'm afraid " + target.sCharacterName + " is not in the list of guildmembers waiting in line.");
					else
					self.say( "There are currently " + string( guildcount -1 ) + " Guild(s) waiting in line.\r I'm afraid " + target.sCharacterName + " is not in the list of guildmembers waiting in line.");
				}
				else if ( guildcount == 0 )  self.say( "No other guild is waiting in line.\r I'm afraid " + target.sCharacterName + " is not in the list of guildmembers waiting in line.");
				
				else self.say( "There are currently " + string( guildcount ) + " Guild(s) waiting in line.\r I'm afraid " + target.sCharacterName + " is not in the list of guildmembers waiting in line.");
			} else if ( waitNum == 0 ) {
				self.say( "You must be a member of the Guild that's currently participating in the Guild Quest." );
			} else {
				if ( guildcount == -2 ) self.say( target.sCharacterName + "'s Guild is number " + ( waitNum -1) + " on the waiting list at Channel 2." );
				else self.say( target.sCharacterName + "'s Guild is number " + (waitNum -1) + " on the waiting list at Channel " + string( -guildcount ));
			}
			end;
		} else if ( v0 == 2 ) {
			// target is not a guild master or vice master. not a proper guild
			if ( target.isGuildMaster != 1 and target.isGuildSubMaster != 1 ) {
				self.say( "Only the Master and the Jr. Master of the Guild may cancel the registration." );
				end;
			}
			//register cancel
			if ( guildcount < 0 ) { // already registered -guildcount is a channel number
				say = "";
				if ( guildcount == -2 ) say = "You're currently registered at Channel 2. If you cancel the registration now, you'll have to register all over again the next time up. Will you still cancel it?";
				else say = "You're currently registered at Channel" +(-guildcount) + ". If you cancel the registration now, you'll have to register all over again the next time up. Will you still cancel it?";
				nRet = self.askYesNo( say );
				if ( nRet == 0 ) self.say( "Please wait." );
				else {
					nRet = self.dealWithGuildQuest( 2 );
					if ( nRet == 1 ) self.say( "The registration has been cancelled." );
					else self.say( "You may not cancel the Guild Quest once it's your turn. Please check again." );
				}
			} else self.say( "Your Guild is not registered.");
			end;
		}
	}
}

function(integer) party_check_item {

	inven = target.inventory;
	hacking = 0;

	nItem00 = inven.hasThisItemInHisParty( 4001024  ); 
	nItem01 = inven.hasThisItemInHisParty( 4001025  ); 
	nItem02 = inven.hasThisItemInHisParty( 4001026  ); 
	nItem03 = inven.hasThisItemInHisParty( 4001027  ); 
	nItem04 = inven.hasThisItemInHisParty( 4001028  ); 
	nItem05 = inven.hasThisItemInHisParty( 4001029  ); 
	nItem06 = inven.hasThisItemInHisParty( 4001030  ); 
	nItem07 = inven.hasThisItemInHisParty( 4001031  ); 
	nItem08 = inven.hasThisItemInHisParty( 4001032  ); 
	nItem09 = inven.hasThisItemInHisParty( 4001033  ); 
	nItem10 = inven.hasThisItemInHisParty( 4001034  ); 
	nItem11 = inven.hasThisItemInHisParty( 4001035  ); 
	nItem12 = inven.hasThisItemInHisParty( 4001036  ); 
	nItem13 = inven.hasThisItemInHisParty( 4001037  ); 
	nItem14 = inven.hasThisItemInHisParty( 1032033  ); 
	
	if ( nItem00 > 0 or nItem01 > 0 or nItem02 > 0 or nItem03 > 0 or nItem04 > 0 or nItem05 > 0 or nItem06 > 0 or nItem07 > 0 or nItem08 > 0 or nItem09 > 0 or nItem10 > 0 or nItem11 > 0 or nItem12 > 0 or nItem13 > 0 or nItem14 > 0 )
	
	hacking = 1;
	
	return hacking ;
	
}

//delete quest items
function takeawayitem {
	//delte quest items
	inven = target.inventory;

	nItem = inven.itemCount( 4001024  ); //风 厚救
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001024, -nItem );
	}

	nItem = inven.itemCount( 4001025  ); //氛扁穿胶狼 芒
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001025, -nItem );
	}

	nItem = inven.itemCount( 4001026  ); //凯艰
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001026, -nItem );
	}

	nItem = inven.itemCount( 4001027  ); //侩扁狼 绕厘
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001027, -nItem );
	}

	nItem = inven.itemCount( 4001028  ); //瘤驱狼 滴风付府
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001028, -nItem );
	}

	nItem = inven.itemCount( 4001029  ); //坷贰等 澜侥
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001029, -nItem );
	}

	nItem = inven.itemCount( 4001030  ); //700斥魂 林聪绢 匙虐 贱
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001030, -nItem );
	}

	nItem = inven.itemCount( 4001031 ); //箕坊3技狼 官瘤
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001031, -nItem );
	}

	nItem = inven.itemCount( 4001032 ); //箕坊3技狼 脚惯
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001032, -nItem );
	}

	nItem = inven.itemCount( 4001033 ); //箕坊3技狼 惑狼
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001033, -nItem );
	}

	nItem = inven.itemCount( 4001034 ); //箕坊3技狼 空包
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001034, -nItem );
	}

	nItem = inven.itemCount( 4001035 ); //厩付狼 钎侥
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001035, -nItem );
	}

	nItem = inven.itemCount( 4001036 ); //捧疙酒捞袍
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001036, -nItem );
	}

	nItem = inven.itemCount( 4001037  ); //踌郊凯艰
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 4001037, -nItem );
	}

	nItem = inven.itemCount( 1032033  ); //荐龋籍
	if ( nItem > 0 ) {
		ret = inven.exchange( 0, 1032033, -nItem );
	}

	nItem =  inven.removeEquippedItem( 1032033 ); //厘厚茄 荐龋籍 力芭
	if (nItem == 0) {
		target.message( "The equipped Protector Rock has been removed." );
	} 
	return;
}