class 1 event_cursed_pig : (null)
{
parameter:
	int	ImPig = 1013031;
	int	PigHeal1 = 213647361;
	int	PigHeal2 = 213778433;
	int	PigCurse1 = 1332737;
	int	PigCurse2 = 1332993;
	int	PigCurse3 = 1336065;
	int	PigCurse4 = 1336321;
	int	EventItemCoin = 9142;
	int	EventItemCoinAmount = 50;
	int	Shout1 = 1303101;
	int	Shout2 = 1303102;
	int	Shout3 = 1303103;
	int	Shout4 = 1303104;

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

	EventHandler NO_DESIRE()
	{
		if( myself.p_state != 3 && myself.p_state != 5 && myself.p_state != 10 )
		{
			myself::AddMoveAroundDesire(5,5);
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id)
	{
		if( timer_id == 1001 )
		{
			if( myself.sm.alive == 0 )
			{
				return;
			}
			if( myself.i_ai2 == 0 && ( myself.p_state == 0 || myself.p_state == 1 || myself.p_state == 2 ) )
			{
				if( myself.i_ai0 > 0 )
				{
					myself.i_ai0 = ( myself.i_ai0 - 1 );
					if( myself.i_ai0 == 0 )
					{
						myself::Say("Hru... Uu-ui-ii-iu-u...");
					}
					else
					{
						myself::AddTimerEx(1001,10000);
					}
				}
			}
		}
		if( timer_id == 1002 )
		{
			if( myself.sm.alive != 0 )
			{
				myself.i_ai1 = 0;
				myself.i_ai2 = 0;
			}
		}
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2,i0,i1)
	{
		if( ImPig >= 1013034 )
		{
			return;
		}
		if( script_event_arg1 == 10020 && myself.i_ai2 == 0 )
		{
			myself::BroadcastScriptEvent(10021,0,200);
		}
		if( script_event_arg1 == 10021 && myself.i_ai2 == 1 )
		{
			myself.i_ai1 = ( myself.i_ai1 + 1 );
			if( gg::Rand(100) < 15 && myself.i_ai1 >= 3 )
			{
				myself::Say(myself::MakeFString(Shout3,"","","","",""));
				i1 = myself::GetDirection(myself.sm);
				i0 = gg::Rand(100);
				if( i0 > 20 )
				{
					myself::CreateOnePrivateEx(1013034,"super_huge_cursed_pig",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),i1,0,0,0);
				}
				else if( i0 <= 20 )
				{
					myself::CreateOnePrivateEx(1013035,"golden_cursed_pig",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),i1,0,0,0);
				}
				myself::BroadcastScriptEvent(10022,0,200);
				myself::Despawn();
				return;
			}
		}
		if( script_event_arg1 == 10022 && myself.i_ai2 == 0 )
		{
			myself.i_ai0 = 0;
			myself.i_ai1 = 0;
			myself.i_ai2 = 0;
			myself::Despawn();
			return;
		}
	}

	EventHandler ATTACKED(attacker,damage,skill_name_id,i0,i1,c0)
	{
		if( myself.top_desire_target == attacker )
		{
		}
		else
		{
			myself.c_quest0 = attacker;
		}
		i0 = gg::Rand(100);
		if( i0 < 80 && myself::DistFromMe(attacker) <= 1500 )
		{
			i1 = 2;
			if( ImPig > 1013033 )
			{
				i1 = 4;
			}
			i0 = gg::Rand(i1);
			switch(i0)
			{
				case 0:
				{
					myself::AddUseSkillDesire(attacker,PigCurse1,0,1,1000000);
					break;
				}
				case 1:
				{
					myself::AddUseSkillDesire(attacker,PigCurse2,0,1,1000000);
					break;
				}
				case 2:
				{
					myself::AddUseSkillDesire(attacker,PigCurse3,0,1,1000000);
					break;
				}
				case 3:
				{
					myself::AddUseSkillDesire(attacker,PigCurse4,0,1,1000000);
					break;
				}
			}
		}
		if( skill_name_id == PigHeal1 )
		{
			if( gg::Rand(100) <= 40 )
			{
				myself::Say(myself::MakeFString(Shout2,"","","","",""));
				if( myself.i_ai0 == 0 )
				{
					myself::AddTimerEx(1001,10000);
				}
				myself.i_ai0 = ( myself.i_ai0 + 1 );
				myself::AddHateInfo(attacker,3000,0,1,1);
			}
			else if( gg::Rand(100) < 20 )
			{
				myself::Say(myself::MakeFString(Shout1,"","","","",""));
			}
		}
		if( skill_name_id == PigHeal2 )
		{
			if( gg::Rand(100) <= 40 )
			{
				myself::Say(myself::MakeFString(Shout2,"","","","",""));
				if( myself.i_ai0 == 0 )
				{
					myself::AddTimerEx(1001,10000);
				}
				myself.i_ai0 = ( myself.i_ai0 + 1 );
				myself::AddHateInfo(attacker,3000,0,1,1);
			}
			else if( gg::Rand(100) < 20 )
			{
				myself::Say(myself::MakeFString(Shout1,"","","","",""));
			}
			if( ImPig < 1013034 && myself.i_ai2 == 0 )
			{
				myself::BroadcastScriptEvent(10020,skill_name_id,200);
				myself.i_ai2 = 1;
				myself::AddTimerEx(1002,2000);
			}
		}
		myself::AddFleeDesire(attacker,5000);
	}

	EventHandler MY_DYING(last_attacker,weapon_class_id,c0)
	{
		c0 = last_attacker;
		if( gg::IsNull(c0) != 0 || myself::DistFromMe(c0) >= 1500 )
		{
			return;
		}
		if( c0.equiped_weapon_class_id == 9141 && myself.i_ai0 >= 3 )
		{
			myself::Say(myself::MakeFString(Shout4,"","","","",""));
			if( ImPig < 1013034 )
			{
				myself::DropItem2(myself.sm,EventItemCoin,( gg::Rand(2) + 1 ),last_attacker.id);
			}
			else if( ImPig == 1013034 )
			{
				myself::DropItem2(myself.sm,EventItemCoin,( gg::Rand(10) + 1 ),last_attacker.id);
			}
			if( ImPig == 1013035 )
			{
				myself::DropItem2(myself.sm,9144,1,last_attacker.id);
				myself::DropItem2(myself.sm,EventItemCoin,( gg::Rand(2) + 1 ),last_attacker.id);
			}
			if( myself::OwnItemCount(c0,EventItemCoin) == EventItemCoinAmount )
			{
				myself::SoundEffect(c0,"ItemSound.quest_middle");
			}
			else
			{
				myself::SoundEffect(c0,"ItemSound.quest_itemget");
			}
		}
	}

}
