class 1 siege_swoop_cannon : default_npc
{
parameter:
	int	DDMagic1 = 1308161;
	int	DDMagic2 = 1308417;

handler:
	EventHandler CREATED()
	{
		myself::AddPetDefaultDesire_Follow(20.000000);
		myself::Summon_SetOption(1,900);
		myself::AddTimerEx(100020,1000);
		myself::AddTimerEx(100021,( 1000 * 60 ));
	}

	EventHandler NO_DESIRE()
	{
		myself::AddPetDefaultDesire_Follow(20.000000);
	}

	EventHandler MENU_SELECTED(talker,ask,reply,action_id,i0,i1)
	{
		if( action_id == 1039 )
		{
			i0 = myself.master.target_id;
			i1 = myself.master.target_index;
			if( myself::IsStaticObjectID(i0) )
			{
				myself::Say(myself::MakeFString(1110073,"","","","",""));
				return;
			}
			c0 = myself::GetCreatureFromIndex(i1);
			if( c0.npc_class_id == 1035062 )
			{
				myself::Say(myself::MakeFString(1110073,"","","","",""));
				return;
			}
			if( myself.sm.action == 1 )
			{
				myself::Say(myself::MakeFString(1110071,"","","","",""));
			}
			else if( myself.sm.action == 2 )
			{
				myself::Say(myself::MakeFString(1110072,"","","","",""));
			}
			else if( c0 )
			{
				if( myself::DistFromMe(c0) > 1600 )
				{
					myself::Say(myself::MakeFString(1110074,"","","","",""));
				}
				else if( myself::Skill_InReuseDelay(DDMagic1) )
				{
					myself::Say(myself::MakeFString(1010551,"","","","",""));
				}
				if( myself::Skill_GetConsumeMP(DDMagic1) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic1) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic1) == 0 )
				{
					if( myself::OwnItemCount(myself.master,8872) >= 4 )
					{
						myself::AddUseSkillDesireEx(myself.master.target_id,DDMagic1,0,reply,ask,1000000,0);
						myself::DeleteItem1(myself.master,8872,4);
					}
				}
			}
		}
		else if( action_id == 1040 )
		{
			i0 = myself.master.target_id;
			i1 = myself.master.target_index;
			if( myself::IsStaticObjectID(i0) )
			{
				myself::Say(myself::MakeFString(1110073,"","","","",""));
				return;
			}
			c0 = myself::GetCreatureFromIndex(i1);
			if( c0.npc_class_id == 1035062 )
			{
				myself::Say(myself::MakeFString(1110073,"","","","",""));
				return;
			}
			if( myself.sm.action == 1 )
			{
				myself::Say(myself::MakeFString(1110071,"","","","",""));
			}
			else if( myself.sm.action == 2 )
			{
				myself::Say(myself::MakeFString(1110072,"","","","",""));
			}
			else if( c0 )
			{
				if( myself::DistFromMe(c0) > 2000 )
				{
					myself::Say(myself::MakeFString(1110074,"","","","",""));
				}
				else if( myself::Skill_InReuseDelay(DDMagic2) )
				{
					myself::Say(myself::MakeFString(1010551,"","","","",""));
				}
				if( myself::Skill_GetConsumeMP(DDMagic2) < myself.sm.mp && myself::Skill_GetConsumeHP(DDMagic2) < myself.sm.hp && myself::Skill_InReuseDelay(DDMagic2) == 0 )
				{
					if( myself::OwnItemCount(myself.master,8872) >= 5 )
					{
						myself::DeleteItem1(myself.master,8872,5);
						myself::AddUseSkillDesireEx(myself.master.target_id,DDMagic2,0,reply,ask,1000000,0);
					}
				}
			}
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id)
	{
		if( timer_id == 100020 )
		{
			if( myself.master.alive == 0 )
			{
				myself::Despawn();
			}
			myself::AddTimerEx(100020,1000);
		}
		if( timer_id == 100021 )
		{
			if( myself::OwnItemCount(myself.master,2132) < 42 && myself::OwnItemCount(myself.master,2132) >= 21 )
			{
				myself::Say(myself::MakeFString(1000169,"","","","",""));
			}
			if( myself::OwnItemCount(myself.master,2132) >= 21 )
			{
				myself::DeleteItem1(myself.master,2132,21);
			}
			else
			{
				myself::Despawn();
			}
			myself::AddTimerEx(100021,( 1000 * 60 ));
		}
	}

}
