class 1 master_toma : citizen
{
handler:
	EventHandler CREATED()
	{
		myself::SetTimerPeriod(1800);
	}

	EventHandler TIMER_FIRED(i6)
	{
		i6 = gg::Rand(90);
		if( i6 > 60 )
		{
			myself::InstantTeleport(myself.sm,178849,-184342,-342);
		}
		else if( i6 > 30 )
		{
			myself::InstantTeleport(myself.sm,154132,-220070,-3404);
		}
		else
		{
			myself::InstantTeleport(myself.sm,151572,-174829,-1781);
		}
	}

	EventHandler TALK_SELECTED(fhtml0,talker)
	{
		if( _from_choice == 0 )
		{
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1646) == 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 0;
				myself::AddChoice(0,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1653) == 1 && myself::OwnItemCount(talker,1655) < 5 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 1;
				myself::AddChoice(1,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1653) == 1 && myself::OwnItemCount(talker,1655) >= 5 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 2;
				myself::AddChoice(2,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1654) == 1 && myself::OwnItemCount(talker,1656) < 20 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 3;
				myself::AddChoice(3,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1654) == 1 && myself::OwnItemCount(talker,1656) >= 20 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 4;
				myself::AddChoice(4,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1657) > 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 5;
				myself::AddChoice(5,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,417) == 1 && ( myself::OwnItemCount(talker,1644) > 0 || myself::OwnItemCount(talker,1645) > 0 ) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 6;
				myself::AddChoice(6,"Path to a Scavenger (Continue)");
			}
			if( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2871) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 7;
				myself::AddChoice(7,"Test of the Maestro (Continue)");
			}
			if( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2916) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 8;
				myself::AddChoice(8,"Test of the Maestro (Continue)");
			}
			if( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2872) == 5 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 9;
				myself::AddChoice(9,"Test of the Maestro (Continue)");
			}
			if( myself::HaveMemo(talker,221) == 1 && myself::OwnItemCount(talker,3262) == 0 && myself::OwnItemCount(talker,3256) == 0 && myself::OwnItemCount(talker,3251) == 0 && myself::OwnItemCount(talker,3239) >= 1 && myself::OwnItemCount(talker,3246) >= 1 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 10;
				myself::AddChoice(10,"Testimony of Prosperity (Continue)");
			}
			if( myself::HaveMemo(talker,221) == 1 && myself::OwnItemCount(talker,3239) >= 1 && myself::OwnItemCount(talker,3246) >= 1 && myself::OwnItemCount(talker,3256) >= 1 && myself::OwnItemCount(talker,3262) == 0 && myself::OwnItemCount(talker,3251) == 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 11;
				myself::AddChoice(11,"Testimony of Prosperity (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,417) == 1 && myself::OwnItemCount(talker,1646) == 1 ) )
					{
						myself::SetCurrentQuestID(417);
						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();
							myself::ShowPage(talker,"master_toma_q0417_01.htm");
							myself::DeleteItem1(talker,1646,1);
							myself::GiveItem1(talker,1653,1);
							myself::SetFlagJournal(talker,417,5);
							talker.flag = 0;
						}
					}
					break;
				}
				case 1:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1653) == 1 && myself::OwnItemCount(talker,1655) < 5 ) )
					{
						myself::SetCurrentQuestID(417);
						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,"master_toma_q0417_02.htm");
					}
					break;
				}
				case 2:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1653) == 1 && myself::OwnItemCount(talker,1655) >= 5 ) )
					{
						myself::SetCurrentQuestID(417);
						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();
							myself::ShowPage(talker,"master_toma_q0417_03.htm");
							myself::DeleteItem1(talker,1655,myself::OwnItemCount(talker,1655));
							myself::DeleteItem1(talker,1653,1);
							myself::GiveItem1(talker,1654,1);
							myself::SetFlagJournal(talker,417,7);
						}
					}
					break;
				}
				case 3:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1654) == 1 && myself::OwnItemCount(talker,1656) < 20 ) )
					{
						myself::SetCurrentQuestID(417);
						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,"master_toma_q0417_04.htm");
					}
					break;
				}
				case 4:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1654) == 1 && myself::OwnItemCount(talker,1656) >= 20 ) )
					{
						myself::SetCurrentQuestID(417);
						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();
							myself::ShowPage(talker,"master_toma_q0417_05.htm");
							myself::DeleteItem1(talker,1656,myself::OwnItemCount(talker,1656));
							myself::DeleteItem1(talker,1654,1);
							myself::GiveItem1(talker,1657,1);
							myself::SetFlagJournal(talker,417,9);
						}
					}
					break;
				}
				case 5:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && myself::OwnItemCount(talker,1657) > 0 ) )
					{
						myself::SetCurrentQuestID(417);
						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,"master_toma_q0417_06.htm");
					}
					break;
				}
				case 6:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,417) == 1 && ( myself::OwnItemCount(talker,1644) > 0 || myself::OwnItemCount(talker,1645) > 0 ) ) )
					{
						myself::SetCurrentQuestID(417);
						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,"master_toma_q0417_07.htm");
					}
					break;
				}
				case 7:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2871) ) )
					{
						myself::SetCurrentQuestID(231);
						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,"master_toma_q0231_01.htm");
					}
					break;
				}
				case 8:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2916) ) )
					{
						myself::SetCurrentQuestID(231);
						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();
							myself::ShowPage(talker,"master_toma_q0231_06.htm");
							myself::GiveItem1(talker,2872,5);
							myself::DeleteItem1(talker,2916,1);
						}
					}
					break;
				}
				case 9:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,231) == 1 && myself::GetMemoState(talker,231) == 3 && myself::OwnItemCount(talker,2872) == 5 ) )
					{
						myself::SetCurrentQuestID(231);
						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,"master_toma_q0231_07.htm");
					}
					break;
				}
				case 10:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,221) == 1 && myself::OwnItemCount(talker,3262) == 0 && myself::OwnItemCount(talker,3256) == 0 && myself::OwnItemCount(talker,3251) == 0 && myself::OwnItemCount(talker,3239) >= 1 && myself::OwnItemCount(talker,3246) >= 1 ) )
					{
						myself::SetCurrentQuestID(221);
						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();
							myself::ShowPage(talker,"master_toma_q0221_01.htm");
							myself::GiveItem1(talker,3256,1);
						}
					}
					break;
				}
				case 11:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,221) == 1 && myself::OwnItemCount(talker,3239) >= 1 && myself::OwnItemCount(talker,3246) >= 1 && myself::OwnItemCount(talker,3256) >= 1 && myself::OwnItemCount(talker,3262) == 0 && myself::OwnItemCount(talker,3251) == 0 ) )
					{
						myself::SetCurrentQuestID(221);
						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,"master_toma_q0221_02.htm");
					}
					break;
				}
			}
			return;
		}
		super;
	}

	EventHandler MENU_SELECTED(ask,reply,talker)
	{
		if( ask == 231 )
		{
			myself::SetCurrentQuestID(231);
			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( ask == 231 )
		{
			if( reply == 1 )
			{
				myself::ShowPage(talker,"master_toma_q0231_02.htm");
			}
			else if( reply == 2 )
			{
				myself::ShowPage(talker,"master_toma_q0231_03.htm");
			}
			else if( reply == 3 && myself::OwnItemCount(talker,2871) > 0 )
			{
				if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
				{
					talker.quest_last_reward_time = myself::GetCurrentTick();
					myself::ShowPage(talker,"master_toma_q0231_05.htm");
					myself::GiveItem1(talker,2916,1);
					myself::DeleteItem1(talker,2871,1);
					myself::InstantTeleport(talker,140352,-194133,-3146);
					myself::CreateOnePrivateEx(1020150,"king_bugbear",0,5,140333,-194153,-3138,0,myself::GetIndexFromCreature(talker),0,0);
					myself::CreateOnePrivateEx(1020150,"king_bugbear",0,5,140395,-194147,-3146,0,myself::GetIndexFromCreature(talker),0,0);
					myself::CreateOnePrivateEx(1020150,"king_bugbear",0,5,140304,-194082,-3157,0,myself::GetIndexFromCreature(talker),0,0);
				}
			}
			else if( reply == 4 )
			{
				myself::ShowPage(talker,"master_toma_q0231_04.htm");
			}
		}
		super;
	}

}
