class 1 tree_q0421_3 : quest_party_leader
{
handler:
	EventHandler MY_DYING(always_list,c0,c1,code_info,i9,last_attacker,lparty,member,random1_list,target)
	{
		always_list = gg::AllocCodeInfoList();
		random1_list = gg::AllocCodeInfoList();
		target = last_attacker;
		always_list::SetInfo(0,target);
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			if( code_info.code == 0 )
			{
				myself::SetCurrentQuestID(421);
				target = code_info::RandomSelectOne();
				if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
				{
					c1 = myself::GetLastAttacker();
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),-1);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
					myself::CreateOnePrivateEx(1027189,"guardian_of_tree",0,0,myself::FloatToInt(myself.sm.x),myself::FloatToInt(myself.sm.y),myself::FloatToInt(myself.sm.z),0,0,myself::GetIndexFromCreature(c1),0);
				}
			}
		}
		code_info = random1_list::RandomSelectOne();
		if( gg::IsNull(code_info) == 0 )
		{
		}
		super;
	}

	EventHandler ATTACKED(attacker,c1,damage,i0)
	{
		myself::SetCurrentQuestID(421);
		myself.c_quest0 = attacker;
		if( myself.c_quest0.master )
		{
			c1 = myself.c_quest0.master;
			if( myself::HaveMemo(c1,421) && myself::GetMemoState(c1,421) <= 16 )
			{
				if( ( myself::GetMemoState(c1,421) % 8 ) < 4 )
				{
					if( attacker.pet_dbid == myself::GetMemoStateEx(c1,421,1) )
					{
						c1.flag = ( c1.flag + 1 );
						if( c1.flag < 150 )
						{
						}
						else if( gg::Rand(100) <= 1 )
						{
							if( myself::OwnItemCount(c1,4325) >= 1 )
							{
								myself::Say(myself::MakeFString(42111,"","","","",""));
								myself::DeleteItem1(c1,4325,1);
								myself::SetMemoState(c1,421,( myself::GetMemoState(c1,421) + 4 ));
								c1.flag = 0;
								myself::SoundEffect(c1,"ItemSound.quest_middle");
								if( myself::GetMemoStateEx(c1,421,1) >= 15 && myself::OwnItemCount(c1,4325) <= 1 )
								{
									myself::SetFlagJournal(c1,421,3);
								}
							}
						}
					}
				}
				else
				{
					i0 = gg::Rand(3);
					if( i0 == 0 )
					{
						myself::Say(myself::MakeFString(42112,"","","","",""));
					}
					else if( i0 == 1 )
					{
						myself::Say(myself::MakeFString(42116,"","","","",""));
					}
					else
					{
						myself::Say(myself::MakeFString(42114,"","","","",""));
					}
				}
			}
		}
		else if( myself::HaveMemo(myself.c_quest0,421) && myself::GetMemoState(myself.c_quest0,421) <= 16 )
		{
			if( gg::Rand(100) <= 29 )
			{
				myself::AddUseSkillDesire(myself.c_quest0,1086209,0,0,1000000);
			}
		}
		else if( myself.sm.hp < ( myself.sm.max_hp * 0.670000 ) && gg::Rand(100) <= 29 )
		{
			myself::AddUseSkillDesire(myself.c_quest0,1086209,0,0,1000000);
		}
		super;
	}

}
