class 1 magic_trader_cema : merchant_for_chaotic
{
property:
	BuySellList SellList0 = {{"apprentice_s_staff";20};{"relic_of_saints";20};{"mage_staff";20};{"crucifix_of_blessing";20};{"voodoo_doll";20};{"bone_staff";20};{"scroll_of_wisdom";20};{"branch_of_life";20};{"proof_of_revenge";20};{"mace_of_prayer";20};{"doom_hammer";20};{"mystic_staff";20};{"staff_of_mana";20};{"divine_tome";20};{"sword_of_magic";20};{"sword_of_mystic";20};{"sword_of_occult";20};{"dagger_of_mana";20};{"mystic_knife";20};{"conjure_knife";20};{"knife_o__silenus";20};{"staff_of_magicpower";20};{"blood_of_saints";20};{"tome_of_blood";20};{"goathead_staff";20};{"crucifix_of_blood";20};{"demon_fangs";20};{"hose_of_devotion";20};{"tunic_of_devotion";20};{"hose_of_magicpower";20};{"tunic_of_magicpower";20};{"cursed_hose";20};{"cursed_tunic";20};{"dark_hose";20};{"white_tunic";20};{"mage_s_hose";20};{"mage_s_tunic";20};{"hose_of_knowledge";20};{"tunic_of_knowledge";20};{"mithril_hose";20};{"mithril_tunic";20};{"round_shield";20};{"bone_shield";20};{"bronze_shield";20};{"aspis";20};{"hoplon";20};{"kite_shield";20};{"leather_gloves";20};{"bracer";20};{"excellence_leather_gloves";20};{"leather_gauntlet";20};{"gauntlet";20};{"gauntlet_of_repose_of_the_soul";20};{"low_boots";20};{"boots";20};{"leather_boots";20};{"blue_buckskin_boots";20};{"iron_boots";20};{"boots_of_power";20};{"leather_helmet";20};{"hard_leather_helmet";20};{"bone_helmet";20};{"bronze_helmet";20};{"helmet";20};{"cotton_shirt";20};{"linen_shirt";20};{"striped_cotton_shirt";20};{"striped_linen_shirt";20};{"wooden_arrow";20};{"bone_arrow";20};{"fine_steel_arrow";20}};
	BuySellList SellList1 = {{"soulshot_none";20};{"spiritshot_none";20};{"blessed_spiritshot_none";20};{"comp_bspiritshot_none";20};{"comp_spiritshot_none";20};{"comp_soulshot_none";20};{"adv_comp_bspiritshot_none";20};{"adv_comp_spiritshot_none";20};{"adv_comp_soulshot_none";20};{"wooden_arrow";20};{"bone_arrow";20};{"fine_steel_arrow";20};{"lesser_healing_potion";20};{"healing_potion";20};{"antidote";20};{"advanced_antidote";20};{"bandage";20};{"emergency_dressing";20};{"quick_step_potion";20};{"swift_attack_potion";20};{"potion_of_acumen2";20};{"scroll_of_awake";20};{"scroll_of_escape";20};{"scroll_of_resurrection";20};{"scroll_of_escape_to_agit";20};{"scroll_of_escape_to_castle";20};{"energy_stone";20};{"key_of_thief";20};{"dice_heart";20};{"dice_spade";20};{"dice_clover";20};{"dice_diamond";20};{"cursed_bone";20}};

handler:
	EventHandler TALK_SELECTED(fhtml0,talker)
	{
		if( _from_choice == 0 )
		{
			if( myself::HaveMemo(talker,343) == 0 )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 0;
				myself::AddChoice(0,"Under the Shadow of the Ivory Tower");
			}
			if( myself::HaveMemo(talker,343) == 1 && myself::OwnItemCount(talker,4364) < 1 && myself::IsInCategory(2,talker.occupation) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 1;
				myself::AddChoice(1,"Under the Shadow of the Ivory Tower");
			}
			if( myself::HaveMemo(talker,343) == 1 && myself::OwnItemCount(talker,4364) >= 1 && myself::IsInCategory(2,talker.occupation) )
			{
				_choiceN = ( _choiceN + 1 );
				_code = 2;
				myself::AddChoice(2,"Under the Shadow of the Ivory Tower");
			}
			if( _choiceN > 1 )
			{
				myself::ShowChoicePage(talker,1);
				return;
			}
		}
		if( _from_choice || _choiceN == 1 )
		{
			switch(_code)
			{
				case 0:
				{
					if( _from_choice == 0 || myself::HaveMemo(talker,343) == 0 )
					{
						myself::SetCurrentQuestID(343);
						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) < 26 )
						{
							if( myself::IsInCategory(2,talker.occupation) == 0 )
							{
								myself::ShowPage(talker,"magic_trader_cema_q0343_01.htm");
							}
							else if( myself::IsInCategory(2,talker.occupation) && talker.level < 40 )
							{
								myself::ShowPage(talker,"magic_trader_cema_q0343_02.htm");
							}
							else if( myself::IsInCategory(2,talker.occupation) && talker.level >= 40 )
							{
								myself::ShowPage(talker,"magic_trader_cema_q0343_03.htm");
							}
						}
						else
						{
							myself::ShowPage(talker,"fullquest.htm");
						}
					}
					break;
				}
				case 1:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,343) == 1 && myself::OwnItemCount(talker,4364) < 1 && myself::IsInCategory(2,talker.occupation) ) )
					{
						myself::SetCurrentQuestID(343);
						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,"magic_trader_cema_q0343_06.htm");
					}
					break;
				}
				case 2:
				{
					if( _from_choice == 0 || ( myself::HaveMemo(talker,343) == 1 && myself::OwnItemCount(talker,4364) >= 1 && myself::IsInCategory(2,talker.occupation) ) )
					{
						myself::SetCurrentQuestID(343);
						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,"magic_trader_cema_q0343_07.htm");
					}
					break;
				}
			}
			return;
		}
		super;
	}

	EventHandler QUEST_ACCEPTED(quest_id,talker)
	{
		if( quest_id == 343 )
		{
			myself::SetCurrentQuestID(343);
			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::SetMemo(talker,quest_id);
				myself::SetMemoState(talker,343,1);
				myself::SetMemoStateEx(talker,343,1,0);
				myself::AddLog(1,talker,343);
				myself::SetFlagJournal(talker,343,1);
				myself::SoundEffect(talker,"ItemSound.quest_accept");
				myself::ShowPage(talker,"magic_trader_cema_q0343_05.htm");
			}
			return;
		}
		super;
	}

	EventHandler MENU_SELECTED(ask,fhtml0,reply,talker)
	{
		if( ask == 343 )
		{
			myself::SetCurrentQuestID(343);
			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 == 343 && myself::IsInCategory(2,talker.occupation) )
		{
			if( reply == 1 )
			{
				myself::FHTML_SetFileName(fhtml0,"magic_trader_cema_q0343_04.htm");
				myself::FHTML_SetInt(fhtml0,"quest_id",343);
				myself::ShowFHTML(talker,fhtml0);
			}
			if( reply == 2 )
			{
				if( myself::OwnItemCount(talker,4364) >= 1 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,57,( myself::OwnItemCount(talker,4364) * 120 ));
						myself::DeleteItem1(talker,4364,myself::OwnItemCount(talker,4364));
						myself::ShowPage(talker,"magic_trader_cema_q0343_08.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_08a.htm");
				}
			}
			if( reply == 3 )
			{
				myself::ShowPage(talker,"magic_trader_cema_q0343_09.htm");
			}
			if( reply == 4 )
			{
				myself::ShowPage(talker,"magic_trader_cema_q0343_10.htm");
			}
			if( reply == 5 )
			{
				myself::ShowPage(talker,"magic_trader_cema_q0343_11.htm");
				myself::RemoveMemo(talker,343);
				myself::AddLog(2,talker,343);
				myself::SoundEffect(talker,"ItemSound.quest_finish");
			}
			if( reply == 6 )
			{
				if( myself::OwnItemCount(talker,4364) >= 10 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,734,1);
						myself::DeleteItem1(talker,4364,10);
						myself::ShowPage(talker,"magic_trader_cema_q0343_12.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 7 )
			{
				if( myself::OwnItemCount(talker,4364) >= 15 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,737,1);
						myself::DeleteItem1(talker,4364,15);
						myself::ShowPage(talker,"magic_trader_cema_q0343_13.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 8 )
			{
				if( myself::OwnItemCount(talker,4364) >= 20 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,735,1);
						myself::DeleteItem1(talker,4364,20);
						myself::ShowPage(talker,"magic_trader_cema_q0343_14.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 9 )
			{
				if( myself::OwnItemCount(talker,4364) >= 20 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,2508,10);
						myself::DeleteItem1(talker,4364,20);
						myself::ShowPage(talker,"magic_trader_cema_q0343_15.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 10 )
			{
				if( myself::OwnItemCount(talker,4364) >= 100 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,956,1);
						myself::DeleteItem1(talker,4364,100);
						myself::ShowPage(talker,"magic_trader_cema_q0343_16.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 11 )
			{
				if( myself::OwnItemCount(talker,4364) >= 400 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,952,1);
						myself::DeleteItem1(talker,4364,400);
						myself::ShowPage(talker,"magic_trader_cema_q0343_17.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
			if( reply == 12 )
			{
				if( myself::OwnItemCount(talker,4364) >= 200 )
				{
					if( ( myself::GetCurrentTick() - talker.quest_last_reward_time ) > 1 )
					{
						talker.quest_last_reward_time = myself::GetCurrentTick();
						myself::GiveItem1(talker,4365,1);
						myself::DeleteItem1(talker,4364,200);
						myself::ShowPage(talker,"magic_trader_cema_q0343_18.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"magic_trader_cema_q0343_19.htm");
				}
			}
		}
		super;
	}

}
