class 1 wild_beast_messenger : citizen
{
parameter:
	string	fnHi = "wild_beast_messenger001.htm";
	string	fnNoFeudInfo = "wild_beast_messenger002.htm";
	string	fnBRList = "wild_beast_messenger003.htm";

handler:
	EventHandler TALKED(talker,fhtml0)
	{
		if( myself.sm.residence_id > 0 )
		{
			if( myself::Castle_GetPledgeId() )
			{
				myself::FHTML_SetFileName(fhtml0,fnHi);
				myself::FHTML_SetStr(fhtml0,"my_pledge_name",myself::Castle_GetPledgeName());
				myself::FHTML_SetStr(fhtml0,"my_owner_name",myself::Castle_GetOwnerName());
			}
			else
			{
				myself::FHTML_SetFileName(fhtml0,fnNoFeudInfo);
			}
		}
		myself::ShowFHTML(talker,fhtml0);
	}

	EventHandler TALK_SELECTED(fhtml0,i0,pledge0,talker)
	{
		if( _from_choice == 0 )
		{
			if( myself::HaveMemo(talker,655) == 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 0;
				myself::AddChoice(0,"A Grand Plan for Taming Wild Beasts");
			}
			if( myself::HaveMemo(talker,655) == 1 && ( ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) > 3600 || ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 0 ) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 1;
				myself::AddChoice(1,"A Grand Plan for Taming Wild Beasts(Continue)");
			}
			if( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,4333) > 0 && myself::OwnItemCount(talker,8084) < 10 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 86400 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 2;
				myself::AddChoice(2,"A Grand Plan for Taming Wild Beasts(Continue)");
			}
			if( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,5009) > 0 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 3600 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 3;
				myself::AddChoice(3,"A Grand Plan for Taming Wild Beasts(Continue)");
			}
			if( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,4333) > 0 && myself::OwnItemCount(talker,8084) >= 10 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 86400 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 4;
				myself::AddChoice(4,"A Grand Plan for Taming Wild Beasts(Continue)");
			}
			if( _choiceN > 1 )
			{
				myself::ShowChoicePage(talker,1);
				return;
			}
		}
		if( _from_choice || _choiceN == 1 )
		{
			switch(_code)
			{
				case 0:
				{
					if( _from_choice == 0 || myself::HaveMemo(talker,655) == 0 )
					{
						myself::SetCurrentQuestID(655);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						if( myself::GetMemoCount(talker) < 25 )
						{
							if( talker.is_pledge_master == 1 )
							{
								pledge0 = myself::GetPledge(talker);
								if( pledge0.skill_level >= 4 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) < 3600 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 && pledge0.agit_id == 0 )
								{
									myself::FHTML_SetFileName(fhtml0,"wild_beast_messenger_q0655_01.htm");
									myself::FHTML_SetInt(fhtml0,"quest_id",655);
									myself::ShowFHTML(talker,fhtml0);
								}
								else if( ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 3600 || ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) < 0 )
								{
									if( myself::Castle_GetSiegeTime() != "" )
									{
										myself::FHTML_SetFileName(fhtml0,"wild_beast_messenger_q0655_03.htm");
										myself::FHTML_SetStr(fhtml0,"next_siege",myself::Castle_GetSiegeTime());
										myself::ShowFHTML(talker,fhtml0);
									}
								}
								else if( pledge0.skill_level < 4 )
								{
									myself::ShowPage(talker,"wild_beast_messenger_q0655_04.htm");
								}
								else
								{
									myself::ShowPage(talker,"wild_beast_messenger_q0655_10.htm");
								}
							}
							else
							{
								pledge0 = myself::GetPledge(talker);
								if( pledge0 )
								{
									if( pledge0.agit_id == 63 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) < 3600 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 )
									{
										myself::ShowPage(talker,"agit_wild_beast_messenger_1.htm");
									}
									else if( pledge0.agit_id != 63 )
									{
										myself::ShowPage(talker,"wild_beast_messenger_q0655_05.htm");
									}
									else
									{
										myself::ShowPage(talker,"wild_beast_messenger_q0655_03.htm");
									}
								}
								else
								{
									myself::ShowPage(talker,"wild_beast_messenger_q0655_05.htm");
								}
							}
						}
						else
						{
							myself::ShowPage(talker,"fullquest.htm");
						}
					}
					break;
				}
				case 1:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,655) == 1 && ( ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) > 3600 || ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 0 ) ) )
					{
						myself::SetCurrentQuestID(655);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						if( myself::OwnItemCount(talker,8084) > 0 )
						{
							myself::DeleteItem1(talker,8084,myself::OwnItemCount(talker,8084));
						}
						if( myself::OwnItemCount(talker,4333) > 0 )
						{
							myself::DeleteItem1(talker,4333,1);
						}
						if( myself::OwnItemCount(talker,8293) > 0 )
						{
							myself::DeleteItem1(talker,8293,myself::OwnItemCount(talker,8293));
						}
						myself::ShowPage(talker,"wild_beast_messenger_q0655_06.htm");
						myself::RemoveMemo(talker,655);
						myself::AddLog(3,talker,655);
						myself::SoundEffect(talker,"ItemSound.quest_finsih");
					}
					break;
				}
				case 2:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,4333) > 0 && myself::OwnItemCount(talker,8084) < 10 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 86400 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 ) )
					{
						myself::SetCurrentQuestID(655);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						myself::ShowPage(talker,"wild_beast_messenger_q0655_07.htm");
					}
					break;
				}
				case 3:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,8293) > 0 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 3600 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 ) )
					{
						myself::SetCurrentQuestID(655);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						myself::ShowPage(talker,"wild_beast_messenger_q0655_07a.htm");
					}
					break;
				}
				case 4:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,655) == 1 && myself::OwnItemCount(talker,4333) > 0 && myself::OwnItemCount(talker,8084) >= 10 && ( myself::Castle_GetRawSiegeTime() - myself::GetMemoState(talker,655) ) < 86400 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 ) )
					{
						myself::SetCurrentQuestID(655);
						if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
						{
							myself::ShowSystemMessage(talker,1118);
							return;
						}
						if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
						{
							talker.quest_last_reward_time = myself::GetCurrentTick();
							i0 = myself::GetMemoStateEx(talker,655,1);
							myself::SetMemoStateEx(talker,655,1,( i0 + 1 ));
							myself::DeleteItem1(talker,8084,myself::OwnItemCount(talker,8084));
							myself::DeleteItem1(talker,4333,myself::OwnItemCount(talker,4333));
							myself::GiveItem1(talker,8293,1);
							myself::ShowPage(talker,"wild_beast_messenger_q0655_08.htm");
							myself::AddLog(3,talker,655);
							myself::SoundEffect(talker,"ItemSound.quest_finsih");
						}
					}
					break;
				}
			}
			return;
		}
		super;
	}

	EventHandler QUEST_ACCEPTED(quest_id,talker)
	{
		if( quest_id == 655 )
		{
			myself::SetCurrentQuestID(655);
			if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
			{
				myself::ShowSystemMessage(talker,1118);
				return;
			}
			if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
			{
				if( myself::OwnItemCount(talker,8084) > 0 )
				{
					myself::DeleteItem1(talker,8084,myself::OwnItemCount(talker,8084));
				}
				if( myself::OwnItemCount(talker,4333) > 0 )
				{
					myself::DeleteItem1(talker,4333,myself::OwnItemCount(talker,4333));
				}
				if( myself::OwnItemCount(talker,8293) > 0 )
				{
					myself::DeleteItem1(talker,8293,myself::OwnItemCount(talker,8293));
				}
				talker.quest_last_reward_time = myself::GetCurrentTick();
				myself::GiveItem1(talker,4333,1);
				myself::SetFlagJournal(talker,655,1);
				myself::SetMemoState(talker,655,myself::Castle_GetRawSystemTime());
				myself::AddLog(1,talker,655);
				myself::SoundEffect(talker,"ItemSound.quest_accept");
				myself::ShowPage(talker,"wild_beast_messenger_q0655_02.htm");
			}
			return;
		}
		super;
	}

	EventHandler MENU_SELECTED(talker,ask,reply,fhtml0,pledge0)
	{
		if( ask == 1 )
		{
			if( myself::Castle_GetRawSiegeTime() < 0 || ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 3600 )
			{
				myself::FHTML_SetFileName(fhtml0,"wild_beast_messenger_q0655_03.htm");
				myself::FHTML_SetStr(fhtml0,"next_siege",myself::Castle_GetSiegeTime());
				myself::ShowFHTML(talker,fhtml0);
				return;
			}
			if( reply == 1 )
			{
				myself::TB_GetPledgeRegisterStatus(talker,1);
			}
			else if( reply == 2 )
			{
				if( talker.is_pledge_master != 1 )
				{
					myself::TB_RegisterMember(talker);
				}
				else
				{
					myself::ShowPage(talker,"agit_wild_beast_messenger_5.htm");
				}
			}
			else if( reply == 101 )
			{
				pledge0 = myself::GetPledge(talker);
				if( pledge0.agit_id == 0 )
				{
					if( talker.is_pledge_master == 1 )
					{
						if( myself::GetPledgeSkillLevel(talker) >= 4 )
						{
							myself::TB_GetPledgeRegisterStatus(talker,0);
						}
						else
						{
							myself::ShowPage(talker,"wild_beast_messenger_q0655_04.htm");
						}
					}
					else
					{
						myself::ShowPage(talker,"wild_beast_messenger_q0655_05.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"wild_beast_messenger_q0655_10.htm");
				}
			}
			else if( reply == 3 )
			{
				myself::TB_GetNpcType(talker);
			}
			else if( reply == 4 )
			{
				myself::TB_SetNpcType(talker,2);
			}
			else if( reply == 5 )
			{
				myself::TB_SetNpcType(talker,1);
			}
			else if( reply == 6 )
			{
				myself::TB_SetNpcType(talker,3);
			}
			else if( reply == 7 )
			{
				myself::TB_SetNpcType(talker,4);
			}
			else if( reply == 8 )
			{
				myself::TB_SetNpcType(talker,5);
			}
			else if( reply == 9 )
			{
				myself::TB_GetNpcType(talker);
			}
		}
		if( ask == 101 )
		{
			myself::TB_GetBattleRoyalPledgeList(talker);
		}
		if( ask == 504 )
		{
			myself::SetCurrentQuestID(655);
			if( myself::GetInventoryInfo(talker,0) >= ( myself::GetInventoryInfo(talker,1) * 0.800000 ) || myself::GetInventoryInfo(talker,2) >= ( myself::GetInventoryInfo(talker,3) * 0.800000 ) )
			{
				myself::ShowSystemMessage(talker,1118);
				return;
			}
			if( reply == 1 )
			{
				if( ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) < 3600 && ( myself::Castle_GetRawSiegeTime() - myself::Castle_GetRawSystemTime() ) > 0 )
				{
					myself::ShowPage(talker,"agit_wild_beast_messenger_1.htm ");
				}
				else if( myself::Castle_GetSiegeTime() != "" )
				{
					myself::FHTML_SetFileName(fhtml0,"wild_beast_messenger_q0655_09.htm");
					myself::FHTML_SetStr(fhtml0,"next_siege",myself::Castle_GetSiegeTime());
					myself::ShowFHTML(talker,fhtml0);
				}
			}
		}
	}

	EventHandler TB_REGISTER_PLEDGE_RETURNED(talker,reply)
	{
		if( reply < 0 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_3.htm");
		}
		else if( reply == 0 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4a.htm");
		}
		else if( reply == 1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4b.htm");
		}
		else if( reply == 2 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4c.htm");
		}
		else if( reply == 3 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4d.htm");
		}
		else if( reply == 4 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4e.htm");
		}
	}

	EventHandler TB_GET_PLEDGE_REGISTER_STATUS_INFORMED(talker,reply,pledge0)
	{
		if( reply == -2 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_21.htm");
		}
		else if( reply == -1 )
		{
			if( myself::IsMyLord(talker) )
			{
				myself::ShowPage(talker,"agit_wild_beast_messenger_22.htm");
			}
			else if( myself::OwnItemCount(talker,8293) > 0 )
			{
				myself::DeleteItem1(talker,8293,1);
				myself::RemoveMemo(talker,655);
				myself::TB_RegisterPledge(talker);
			}
			else
			{
				myself::ShowPage(talker,"agit_wild_beast_messenger_24.htm");
			}
		}
		else if( reply == -3 )
		{
			if( myself::IsMyLord(talker) )
			{
				myself::ShowPage(talker,"agit_wild_beast_messenger_22.htm");
			}
			else
			{
				pledge0 = myself::GetPledge(talker);
				if( pledge0.agit_id == 0 )
				{
					if( talker.is_pledge_master == 1 )
					{
						if( myself::GetPledgeSkillLevel(talker) >= 4 )
						{
							if( myself::OwnItemCount(talker,57) >= 200000 )
							{
								myself::DeleteItem1(talker,57,200000);
								myself::TB_RegisterPledge(talker);
							}
							else
							{
								myself::ShowPage(talker,"agit_wild_beast_messenger_26.htm");
							}
						}
						else
						{
							myself::ShowPage(talker,"wild_beast_messenger_q0655_04.htm");
						}
					}
					else
					{
						myself::ShowPage(talker,"wild_beast_messenger_q0655_05.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"wild_beast_messenger_q0655_10.htm");
				}
			}
		}
		else if( reply == 0 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4a.htm");
		}
		else if( reply == 1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4b.htm");
		}
		else if( reply == 2 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4c.htm");
		}
		else if( reply == 3 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4d.htm");
		}
		else if( reply == 4 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_4e.htm");
		}
	}

	EventHandler TB_REGISTER_MEMBER_RETURNED(talker,reply)
	{
		if( reply == 0 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_7.htm");
		}
		else if( reply == 1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_8.htm");
		}
		else if( reply == 2 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_9.htm");
		}
	}

	EventHandler TB_SET_NPC_TYPE_RETURNED(talker,reply)
	{
		if( reply == -1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_7.htm");
		}
		else if( reply >= 1 && reply <= 5 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_9.htm");
		}
	}

	EventHandler TB_GET_NPC_TYPE_INFORMED(talker,reply)
	{
		if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_25.htm");
			return;
		}
		if( reply == -1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_7.htm");
		}
		else if( reply == 0 )
		{
			if( talker.is_pledge_master == 1 )
			{
				myself::ShowPage(talker,"agit_wild_beast_messenger_6.htm");
			}
			else
			{
				myself::ShowPage(talker,"agit_wild_beast_messenger_10.htm");
			}
		}
		else if( reply == 1 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_18.htm");
		}
		else if( reply == 2 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_17.htm");
		}
		else if( reply == 3 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_19.htm");
		}
		else if( reply == 4 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_20.htm");
		}
		else if( reply == 5 )
		{
			myself::ShowPage(talker,"agit_wild_beast_messenger_23.htm");
		}
	}

	EventHandler TB_GET_BATTLE_ROYAL_PLEDGE_LIST_INFORMED(talker,fhtml0,i0,i1,i2,i3,i4,pledge0)
	{
		myself::FHTML_SetFileName(fhtml0,fnBRList);
		if( i0 >= 0 )
		{
			pledge0 = myself::GetPledgeByIndex(i0);
			myself::FHTML_SetStr(fhtml0,"pledge0",pledge0.name);
		}
		else
		{
			myself::FHTML_SetStr(fhtml0,"pledge0",myself::MakeFString(1000495,"","","","",""));
		}
		if( i1 >= 0 )
		{
			pledge0 = myself::GetPledgeByIndex(i1);
			myself::FHTML_SetStr(fhtml0,"pledge1",pledge0.name);
		}
		else
		{
			myself::FHTML_SetStr(fhtml0,"pledge1",myself::MakeFString(1000495,"","","","",""));
		}
		if( i2 >= 0 )
		{
			pledge0 = myself::GetPledgeByIndex(i2);
			myself::FHTML_SetStr(fhtml0,"pledge2",pledge0.name);
		}
		else
		{
			myself::FHTML_SetStr(fhtml0,"pledge2",myself::MakeFString(1000495,"","","","",""));
		}
		if( i3 >= 0 )
		{
			pledge0 = myself::GetPledgeByIndex(i3);
			myself::FHTML_SetStr(fhtml0,"pledge3",pledge0.name);
		}
		else
		{
			myself::FHTML_SetStr(fhtml0,"pledge3",myself::MakeFString(1000495,"","","","",""));
		}
		if( i4 >= 0 )
		{
			pledge0 = myself::GetPledgeByIndex(i4);
			myself::FHTML_SetStr(fhtml0,"pledge4",pledge0.name);
		}
		else
		{
			myself::FHTML_SetStr(fhtml0,"pledge4",myself::MakeFString(1000495,"","","","",""));
		}
		myself::ShowFHTML(talker,fhtml0);
	}

}
