class 1 kasha_bear : warrior_aggressive
{
handler:
	EventHandler MY_DYING(always_list,c1,code_info,i0,i1,i2,i9,last_attacker,lparty,member,random1_list,target)
	{
		always_list = gg::AllocCodeInfoList();
		random1_list = gg::AllocCodeInfoList();
		target = last_attacker;
		always_list::SetInfo(0,target);
		target = last_attacker;
		always_list::SetInfo(1,target);
		target = last_attacker;
		always_list::SetInfo(2,target);
		while( gg::IsNull(code_info = always_list::Next()) == 0 )
		{
			switch(code_info.code)
			{
				case 0:
				{
					myself::SetCurrentQuestID(415);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( myself::HaveMemo(myself.c_quest0,415) == 1 && myself::OwnItemCount(myself.c_quest0,1594) == 1 && myself.i_quest0 == 1 )
						{
							if( myself::OwnItemCount(myself.c_quest0,1600) == 4 )
							{
								myself::DeleteItem1(myself.c_quest0,1600,myself::OwnItemCount(myself.c_quest0,1600));
								myself::DeleteItem1(myself.c_quest0,1594,myself::OwnItemCount(myself.c_quest0,1594));
								myself::GiveItem1(myself.c_quest0,1597,1);
								myself::SetFlagJournal(myself.c_quest0,415,3);
								myself::SoundEffect(myself.c_quest0,"ItemSound.quest_middle");
							}
							else
							{
								myself::GiveItem1(myself.c_quest0,1600,1);
								myself::SoundEffect(myself.c_quest0,"ItemSound.quest_itemget");
							}
						}
					}
					break;
				}
				case 1:
				{
					myself::SetCurrentQuestID(416);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( myself::HaveMemo(myself.c_quest0,416) == 1 && myself::OwnItemCount(myself.c_quest0,1616) == 1 && myself::OwnItemCount(myself.c_quest0,1617) < 1 && myself.i_quest0 == 1 )
						{
							if( myself::OwnItemCount(myself.c_quest0,1617) < 1 && myself::OwnItemCount(myself.c_quest0,1618) >= 1 && myself::OwnItemCount(myself.c_quest0,1619) >= 1 )
							{
								myself::GiveItem1(myself.c_quest0,1617,1);
								myself::SetFlagJournal(myself.c_quest0,416,2);
								myself::SoundEffect(myself.c_quest0,"ItemSound.quest_middle");
							}
							else
							{
								myself::GiveItem1(myself.c_quest0,1617,1);
								myself::SoundEffect(myself.c_quest0,"ItemSound.quest_itemget");
							}
						}
					}
					break;
				}
				case 2:
				{
					myself::SetCurrentQuestID(276);
					target = code_info::RandomSelectOne();
					if( gg::IsNull(target) == 0 && myself::DistFromMe(target) <= 1500 )
					{
						c1 = myself::GetLastAttacker();
						if( c1.master )
						{
							c1 = c1.master;
						}
						if( myself::HaveMemo(c1,276) && myself::OwnItemCount(c1,1481) < 1 )
						{
							i0 = myself::OwnItemCount(c1,1480);
							i1 = gg::Rand(100);
							i2 = 1;
							if( i0 >= 79 )
							{
								myself::CreateOnePrivate(1027044,"kasha_bear_totem",0,1);
								myself::DeleteItem1(c1,1480,myself::OwnItemCount(c1,1480));
								i2 = 0;
							}
							else if( i0 >= 69 )
							{
								if( i1 <= 20 )
								{
									myself::CreateOnePrivate(1027044,"kasha_bear_totem",0,1);
									myself::DeleteItem1(c1,1480,myself::OwnItemCount(c1,1480));
									i2 = 0;
								}
							}
							else if( i0 >= 59 )
							{
								if( i1 <= 15 )
								{
									myself::CreateOnePrivate(1027044,"kasha_bear_totem",0,1);
									myself::DeleteItem1(c1,1480,myself::OwnItemCount(c1,1480));
									i2 = 0;
								}
							}
							else if( i0 >= 49 )
							{
								if( i1 <= 10 )
								{
									myself::CreateOnePrivate(1027044,"kasha_bear_totem",0,1);
									myself::DeleteItem1(c1,1480,myself::OwnItemCount(c1,1480));
									i2 = 0;
								}
							}
							else if( i0 >= 39 )
							{
								if( i1 <= 2 )
								{
									myself::CreateOnePrivate(1027044,"kasha_bear_totem",0,1);
									myself::DeleteItem1(c1,1480,myself::OwnItemCount(c1,1480));
									i2 = 0;
								}
							}
							if( i2 )
							{
								myself::GiveItem1(c1,1480,1);
								myself::SoundEffect(c1,"ItemSound.quest_itemget");
							}
						}
					}
					break;
				}
			}
		}
		code_info = random1_list::RandomSelectOne();
		if( gg::IsNull(code_info) == 0 )
		{
		}
		super;
	}

	EventHandler ATTACKED(attacker,damage)
	{
		myself::SetCurrentQuestID(415);
		if( myself::HaveMemo(attacker,415) )
		{
			switch(myself.i_quest0)
			{
				case 0:
				{
					if( attacker.attack_type != 5 && attacker.attack_type != 9 )
					{
						myself.i_quest0 = 2;
					}
					else
					{
						myself.i_quest0 = 1;
					}
					myself.c_quest0 = attacker;
					break;
				}
				case 1:
				{
					if( myself.c_quest0 != attacker || ( attacker.attack_type != 5 && attacker.attack_type != 9 ) )
					{
						myself.i_quest0 = 2;
					}
					break;
				}
				case 2:
				{
					break;
				}
			}
		}
		myself::SetCurrentQuestID(416);
		if( myself::HaveMemo(attacker,416) )
		{
			switch(myself.i_quest0)
			{
				case 0:
				{
					myself.i_quest0 = 1;
					if( attacker.master )
					{
						myself.c_quest0 = attacker.master;
					}
					else
					{
						myself.c_quest0 = attacker;
					}
					break;
				}
				case 1:
				{
					if( attacker.master )
					{
						if( myself.c_quest0 != attacker.master )
						{
							myself.i_quest0 = 2;
						}
					}
					else if( myself.c_quest0 != attacker )
					{
						myself.i_quest0 = 2;
					}
					break;
				}
				case 2:
				{
					break;
				}
			}
		}
		super;
	}

}
