class 1 court_magician : merchant
{
parameter:
	int	Multisell = 1;

handler:
	EventHandler CREATED()
	{
		myself.c_ai0 = 0;
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
	}

	EventHandler MENU_SELECTED(talker,ask,reply,c0)
	{
		if( ask == 1100 )
		{
			if( reply == 1 )
			{
				myself.c_ai0 = myself::Pledge_GetLeader(talker);
				if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
				{
					if( myself.c_ai0 != talker )
					{
						if( myself::IsNullCreature(myself.c_ai0) == 0 )
						{
							if( myself.c_ai0.alive == 1 )
							{
								if( myself::GetAbnormalLevel(myself.c_ai0,myself::Skill_GetAbnormalType(929793)) == 10 )
								{
									myself::AddTimerEx(( myself::GetIndexFromCreature(talker) + 1000000 ),( 1000 * 4 ));
									myself::AddUseSkillDesire(talker,1307905,1,0,1000000);
									myself.i_ai0 = myself::FloatToInt(myself.c_ai0.x);
									myself.i_ai1 = myself::FloatToInt(myself.c_ai0.y);
									myself.i_ai2 = myself::FloatToInt(myself.c_ai0.z);
								}
								else
								{
									myself::ShowPage(talker,"court_magician_clan_gate_closed.htm");
								}
							}
							else
							{
								myself::ShowPage(talker,"court_magician_clan_master_not_alive.htm");
							}
						}
						else
						{
							myself::ShowPage(talker,"court_magician_clan_clan_master_offline.htm");
						}
					}
					else
					{
						myself::ShowPage(talker,"court_magician_my_lord.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"court_magician_not_my_clan.htm");
				}
			}
		}
		if( ask == 35648 )
		{
			switch(reply)
			{
				case 1:
				{
					if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
					{
						myself::ShowMultisell(Multisell,talker);
					}
					else
					{
						myself::ShowPage(talker,"court_magician_not_my_clan.htm");
					}
					break;
				}
				case 2:
				{
					if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
					{
						myself::ShowMultisell(356482,talker);
					}
					else
					{
						myself::ShowPage(talker,"court_magician_not_my_clan.htm");
					}
					break;
				}
				case 3:
				{
					if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
					{
						myself::ShowMultisell(356483,talker);
					}
					else
					{
						myself::ShowPage(talker,"court_magician_not_my_clan.htm");
					}
					break;
				}
				case 4:
				{
					if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
					{
						myself::ShowMultisell(356484,talker);
					}
					else
					{
						myself::ShowPage(talker,"court_magician_not_my_clan.htm");
					}
					break;
				}
			}
		}
		if( ask == -302 )
		{
			if( myself::IsMyLord(talker) || ( myself::HavePledgePower(talker,8) && myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 ) )
			{
				if( myself::OwnItemCount(talker,9912) >= 10 )
				{
					myself::DeleteItem1(talker,9912,10);
					switch(gg::Rand(77))
					{
						case 0:
						{
							myself::GiveItem1(talker,9914,1);
							break;
						}
						case 1:
						{
							myself::GiveItem1(talker,9915,1);
							break;
						}
						case 2:
						{
							myself::GiveItem1(talker,9916,1);
							break;
						}
						case 3:
						{
							myself::GiveItem1(talker,9917,1);
							break;
						}
						case 4:
						{
							myself::GiveItem1(talker,9918,1);
							break;
						}
						case 5:
						{
							myself::GiveItem1(talker,9919,1);
							break;
						}
						case 6:
						{
							myself::GiveItem1(talker,9920,1);
							break;
						}
						case 7:
						{
							myself::GiveItem1(talker,9921,1);
							break;
						}
						case 8:
						{
							myself::GiveItem1(talker,9922,1);
							break;
						}
						case 9:
						{
							myself::GiveItem1(talker,9923,1);
							break;
						}
						case 10:
						{
							myself::GiveItem1(talker,9924,1);
							break;
						}
						case 11:
						{
							myself::GiveItem1(talker,9925,1);
							break;
						}
						case 12:
						{
							myself::GiveItem1(talker,9926,1);
							break;
						}
						case 13:
						{
							myself::GiveItem1(talker,9927,1);
							break;
						}
						case 14:
						{
							myself::GiveItem1(talker,9928,1);
							break;
						}
						case 15:
						{
							myself::GiveItem1(talker,9929,1);
							break;
						}
						case 16:
						{
							myself::GiveItem1(talker,9930,1);
							break;
						}
						case 17:
						{
							myself::GiveItem1(talker,9931,1);
							break;
						}
						case 18:
						{
							myself::GiveItem1(talker,9932,1);
							break;
						}
						case 19:
						{
							myself::GiveItem1(talker,9933,1);
							break;
						}
						case 20:
						{
							myself::GiveItem1(talker,9934,1);
							break;
						}
						case 21:
						{
							myself::GiveItem1(talker,9935,1);
							break;
						}
						case 22:
						{
							myself::GiveItem1(talker,9936,1);
							break;
						}
						case 23:
						{
							myself::GiveItem1(talker,9937,1);
							break;
						}
						case 24:
						{
							myself::GiveItem1(talker,9938,1);
							break;
						}
						case 25:
						{
							myself::GiveItem1(talker,9939,1);
							break;
						}
						case 26:
						{
							myself::GiveItem1(talker,9940,1);
							break;
						}
						case 27:
						{
							myself::GiveItem1(talker,9941,1);
							break;
						}
						case 28:
						{
							myself::GiveItem1(talker,9942,1);
							break;
						}
						case 29:
						{
							myself::GiveItem1(talker,9943,1);
							break;
						}
						case 30:
						{
							myself::GiveItem1(talker,9944,1);
							break;
						}
						case 31:
						{
							myself::GiveItem1(talker,9945,1);
							break;
						}
						case 32:
						{
							myself::GiveItem1(talker,9946,1);
							break;
						}
						case 33:
						{
							myself::GiveItem1(talker,9947,1);
							break;
						}
						case 34:
						{
							myself::GiveItem1(talker,9948,1);
							break;
						}
						case 35:
						{
							myself::GiveItem1(talker,9949,1);
							break;
						}
						case 36:
						{
							myself::GiveItem1(talker,9950,1);
							break;
						}
						case 37:
						{
							myself::GiveItem1(talker,9951,1);
							break;
						}
						case 38:
						{
							myself::GiveItem1(talker,9952,1);
							break;
						}
						case 39:
						{
							myself::GiveItem1(talker,9953,1);
							break;
						}
						case 40:
						{
							myself::GiveItem1(talker,9954,1);
							break;
						}
						case 41:
						{
							myself::GiveItem1(talker,9955,1);
							break;
						}
						case 42:
						{
							myself::GiveItem1(talker,9956,1);
							break;
						}
						case 43:
						{
							myself::GiveItem1(talker,9957,1);
							break;
						}
						case 44:
						{
							myself::GiveItem1(talker,9958,1);
							break;
						}
						case 45:
						{
							myself::GiveItem1(talker,9959,1);
							break;
						}
						case 46:
						{
							myself::GiveItem1(talker,9960,1);
							break;
						}
						case 47:
						{
							myself::GiveItem1(talker,9961,1);
							break;
						}
						case 48:
						{
							myself::GiveItem1(talker,9962,1);
							break;
						}
						case 49:
						{
							myself::GiveItem1(talker,9963,1);
							break;
						}
						case 50:
						{
							myself::GiveItem1(talker,9964,1);
							break;
						}
						case 51:
						{
							myself::GiveItem1(talker,9965,1);
							break;
						}
						case 52:
						{
							myself::GiveItem1(talker,9966,1);
							break;
						}
						case 53:
						{
							myself::GiveItem1(talker,10141,1);
							break;
						}
						case 54:
						{
							myself::GiveItem1(talker,10142,1);
							break;
						}
						case 55:
						{
							myself::GiveItem1(talker,10158,1);
							break;
						}
						case 56:
						{
							myself::GiveItem1(talker,10416,1);
							break;
						}
						case 57:
						{
							myself::GiveItem1(talker,10417,1);
							break;
						}
						case 58:
						{
							myself::GiveItem1(talker,10418,1);
							break;
						}
						case 59:
						{
							myself::GiveItem1(talker,10419,1);
							break;
						}
						case 60:
						{
							myself::GiveItem1(talker,10420,1);
							break;
						}
						case 61:
						{
							myself::GiveItem1(talker,10421,1);
							break;
						}
						case 62:
						{
							myself::GiveItem1(talker,10422,1);
							break;
						}
						case 63:
						{
							myself::GiveItem1(talker,10423,1);
							break;
						}
						case 64:
						{
							myself::GiveItem1(talker,10424,1);
							break;
						}
						case 65:
						{
							myself::GiveItem1(talker,10518,1);
							break;
						}
						case 66:
						{
							myself::GiveItem1(talker,10519,1);
							break;
						}
						case 67:
						{
							myself::GiveItem1(talker,10533,1);
							break;
						}
						case 68:
						{
							myself::GiveItem1(talker,10534,1);
							break;
						}
						case 69:
						{
							myself::GiveItem1(talker,10535,1);
							break;
						}
						case 70:
						{
							myself::GiveItem1(talker,10536,1);
							break;
						}
						case 71:
						{
							myself::GiveItem1(talker,10537,1);
							break;
						}
						case 72:
						{
							myself::GiveItem1(talker,10538,1);
							break;
						}
						case 73:
						{
							myself::GiveItem1(talker,10539,1);
							break;
						}
						case 74:
						{
							myself::GiveItem1(talker,10540,1);
							break;
						}
						case 75:
						{
							myself::GiveItem1(talker,10541,1);
							break;
						}
						case 76:
						{
							myself::GiveItem1(talker,10542,1);
							break;
						}
						case 77:
						{
							myself::GiveItem1(talker,10543,1);
							break;
						}
					}
				}
				else
				{
					myself::Say("10 Knights Epaulette is necessary");
				}
			}
			else
			{
				myself::ShowPage(talker,"fortress_wizard004.htm");
			}
		}
		super;
	}

	EventHandler TIMER_FIRED_EX(timer_id,talker)
	{
		if( timer_id <= 1000000 )
		{
			return;
		}
		talker = myself::GetCreatureFromIndex(( timer_id - 1000000 ));
		if( myself::IsNullCreature(talker) || talker.alive == 0 || talker.is_pc == 0 )
		{
			return;
		}
		if( myself::Castle_GetPledgeId() == talker.pledge_id && talker.pledge_id != 0 )
		{
			if( myself.c_ai0 != talker )
			{
				if( myself::IsNullCreature(myself.c_ai0) == 0 )
				{
					if( myself.c_ai0.alive == 1 )
					{
						if( myself::GetAbnormalLevel(myself.c_ai0,myself::Skill_GetAbnormalType(929793)) == 10 )
						{
							myself::InstantTeleport(talker,( myself.i_ai0 + gg::Rand(80) ),( myself.i_ai1 + gg::Rand(80) ),myself.i_ai2);
						}
						else
						{
							myself::ShowPage(talker,"court_magician_clan_gate_closed.htm");
						}
					}
					else
					{
						myself::ShowPage(talker,"court_magician_clan_master_not_alive.htm");
					}
				}
				else
				{
					myself::ShowPage(talker,"court_magician_clan_clan_master_offline.htm");
				}
			}
			else
			{
				myself::ShowPage(talker,"court_magician_my_lord.htm");
			}
		}
		else
		{
			myself::ShowPage(talker,"court_magician_not_my_clan.htm");
		}
	}

}
