class 1 frintezza : (null)
{
parameter:
	int	GM_ID_1 = 8;
	int	GM_ID_2 = 7;
	int	GM_ID_3 = 10;
	int	GM_ID_4 = 20;
	int	GM_ID_5 = 21;
	int	GM_ID_6 = 22;
	int	GM_ID_7 = 23;
	int	Timer = 35;
	string	AreaName1 = "psycho";
	string	AreaName2 = "coral";
	string	AreaName3 = "dash";
	string	LevelName = "Frintezza";

handler:
	EventHandler CREATED(reply,i0,gg)
	{
		myself.i_ai0 = -1;
		myself.i_ai1 = 1;
		myself.i_ai3 = 0;
		myself::Area_SetOnOff(AreaName1,0);
		myself::Area_SetOnOff(AreaName2,0);
		myself::Area_SetOnOff(AreaName3,0);
		myself::Castle_GateOpenClose2("Godad_fritezzaroomDoor",0);
		if( reply == 0 )
		{
			myself::SetDBValue(myself.sm,0);
			myself::EarthQuakeByNPC(myself.sm,20,10,1,0,0,0);
		}
		if( GM_ID_1 != 0 )
		{
			i0 = myself::GetGlobalMap(GM_ID_1);
			if( i0 == -1 )
			{
				myself::RegisterGlobalMap(GM_ID_1,myself::GetIndexFromCreature(myself.sm));
			}
		}
		if( myself.sm.db_value == 1 )
		{
			gg::InstantTeleportEx(myself.sm,174240,-89810,-5000,16384);
			myself::AddTimerEx(10003,( ( Timer * 60 ) * 1000 ));
		}
		else if( myself.sm.db_value == 2 )
		{
			gg::InstantTeleportEx(myself.sm,174240,-89810,-5000,16384);
			myself::AddUseSkillDesire(myself.sm,1281537,1,1,1000);
			myself::AddTimerEx(2000,40000);
			myself::Castle_GateOpenClose2("Godad_fritezzaroomDoor",1);
			myself::AddTimerEx(1002,600000);
			myself::AddTimerEx(1003,10000);
		}
	}

	EventHandler SCRIPT_EVENT(gg)
	{
		if( myself.sm.db_value == 0 )
		{
			gg::InstantTeleportEx(myself.sm,174240,-89810,-5000,16384);
			myself::SetDBValue(myself.sm,1);
			myself::AddTimerEx(10003,( ( Timer * 60 ) * 1000 ));
		}
	}

	EventHandler ATTACKED()
	{
		if( myself.sm.db_value == 1 )
		{
			myself::SetDBValue(myself.sm,2);
			myself::AddTimerEx(10000,1000);
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id,i0,i1,i2,i3,c0,c1,c2,c3,room0,rlist0,gg)
	{
		if( timer_id == 10000 )
		{
			myself::Castle_GateOpenClose2("Godad_fritezzaroomDoor",1);
			myself::SpecialCamera(myself.sm,0,90,0,0,10000,10000,0,0,0,0);
			myself::AddUseSkillDesire(myself.sm,1281537,1,1,1000);
			myself::AddTimerEx(2000,40000);
			myself::AddTimerEx(10001,10000);
		}
		if( timer_id == 10001 )
		{
			i0 = myself::GetGlobalMap(GM_ID_2);
			if( i0 != -1 )
			{
				c0 = myself::GetCreatureFromIndex(i0);
				gg::SendScriptEvent(c0,0,0);
			}
			myself::AddTimerEx(1002,600000);
			myself::AddTimerEx(1003,60000);
		}
		if( timer_id == 10003 )
		{
			if( myself.sm.db_value == 1 )
			{
				myself::SetDBValue(myself.sm,0);
				myself::InstantTeleport(myself.sm,-105233,-251261,-15530);
				myself::AddTimerEx(10004,1000);
			}
		}
		if( timer_id == 10004 )
		{
			rlist0 = gg::GetRoomInfoList(LevelName);
			if( gg::IsNull(rlist0) )
			{
				myself::Say("!!! Error Room Created !!!");
			}
			else
			{
				room0 = rlist0::GetRoomInfo(0);
				room0.status::Exchange(0);
				room0::Clear();
			}
		}
		if( timer_id == 1002 )
		{
			i0 = myself::GetGlobalMap(GM_ID_2);
			i1 = myself::GetGlobalMap(GM_ID_3);
			if( i0 != -1 && i1 != -1 )
			{
				c0 = myself::GetCreatureFromIndex(i0);
				c1 = myself::GetCreatureFromIndex(i1);
				if( c0.db_value == 0 && c1.db_value == 0 )
				{
					myself::SetDBValue(myself.sm,0);
					myself::RemoveAllDesire();
					myself::StopMove();
					myself::Area_SetOnOff(AreaName1,0);
					myself::Area_SetOnOff(AreaName2,0);
					myself::Area_SetOnOff(AreaName3,0);
					myself::Castle_GateOpenClose2("Godad_fritezzaroomDoor",0);
					myself::InstantTeleport(myself.sm,-105233,-251261,-15530);
					myself::AddTimerEx(10004,1000);
				}
				else
				{
					myself::AddTimerEx(1002,60000);
				}
			}
		}
		if( timer_id == 1003 && myself.sm.db_value > 1 )
		{
			i1 = myself::GetGlobalMap(GM_ID_3);
			if( i1 == -1 )
			{
				myself::UnregisterGlobalMap(GM_ID_1);
				myself::EffectMusic(myself.sm,10000,"BS01_D");
				myself::SetDBValue(myself.sm,0);
				myself::SpecialCamera(myself.sm,0,90,0,0,10000,10000,0,0,0,0);
				myself::Area_SetOnOff(AreaName1,0);
				myself::Area_SetOnOff(AreaName2,0);
				myself::Area_SetOnOff(AreaName3,0);
				myself::AddTimerEx(10004,100);
				myself::Suicide();
			}
			else
			{
				myself::AddTimerEx(1003,10000);
			}
		}
		if( timer_id == 2000 && myself.sm.db_value > 1 )
		{
			myself.i_ai1 = gg::Rand(6);
			myself.i_ai3 = 0;
			myself::Area_SetOnOff(AreaName1,0);
			myself::Area_SetOnOff(AreaName2,0);
			myself::Area_SetOnOff(AreaName3,0);
			if( myself.i_ai1 == myself.i_ai0 )
			{
				myself.i_ai1 = ( myself.i_ai1 + 1 );
				if( myself.i_ai1 > 5 )
				{
					myself.i_ai1 = ( myself.i_ai1 - 2 );
				}
			}
			switch(myself.i_ai1)
			{
				case 0:
				{
					myself::Shout("Healing Rhapsody!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
				case 1:
				{
					myself::Shout("Rampaging Opus!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
				case 2:
				{
					myself::Shout("Power Concerto!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
				case 3:
				{
					myself::Shout("Plagued Concerto!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
				case 4:
				{
					myself::Shout("Psycho Symphony!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
				case 5:
				{
					myself::Shout("Frintezzas Melody!");
					myself.i_ai0 = myself.i_ai1;
					myself::AddTimerEx(3000,4000);
					return;
				}
			}
		}
		else if( timer_id == 3000 )
		{
			if( myself::GetAbnormalLevel(myself.sm,myself::Skill_GetAbnormalType(571905)) > 0 )
			{
				myself.i_ai3 = 1;
			}
			else
			{
				myself.i_ai3 = 0;
			}
			switch(myself.i_ai1)
			{
				case 0:
				{
					if( myself.i_ai3 == 0 )
					{
						i0 = myself::GetGlobalMap(GM_ID_2);
						i1 = myself::GetGlobalMap(GM_ID_3);
						c0 = myself::GetCreatureFromIndex(i0);
						c1 = myself::GetCreatureFromIndex(i1);
						if( i0 != -1 && c0.db_value > 0 )
						{
							gg::SendScriptEvent(c0,1,0);
						}
						if( i1 != -1 && c1.db_value > 0 )
						{
							gg::SendScriptEvent(c1,1,0);
						}
					}
					myself::AddUseSkillDesire(myself.sm,1281793,0,1,1000000);
					myself::AddTimerEx(2000,40000);
					return;
				}
				case 1:
				{
					myself::Area_SetOnOff(AreaName3,1);
					i0 = myself::GetGlobalMap(GM_ID_4);
					i1 = myself::GetGlobalMap(GM_ID_5);
					i2 = myself::GetGlobalMap(GM_ID_6);
					i3 = myself::GetGlobalMap(GM_ID_7);
					if( i0 != -1 )
					{
						c0 = myself::GetCreatureFromIndex(i0);
						gg::SendScriptEvent(c0,2,0);
					}
					if( i1 != -1 )
					{
						c1 = myself::GetCreatureFromIndex(i1);
						gg::SendScriptEvent(c1,2,0);
					}
					if( i2 != -1 )
					{
						c2 = myself::GetCreatureFromIndex(i2);
						gg::SendScriptEvent(c2,2,0);
					}
					if( i3 != -1 )
					{
						c3 = myself::GetCreatureFromIndex(i3);
						gg::SendScriptEvent(c3,2,0);
					}
					myself::AddUseSkillDesire(myself.sm,1281794,0,1,1000000);
					myself::AddTimerEx(2000,40000);
					return;
				}
				case 2:
				{
					if( myself.i_ai3 == 0 )
					{
						i0 = myself::GetGlobalMap(GM_ID_2);
						i1 = myself::GetGlobalMap(GM_ID_3);
						c0 = myself::GetCreatureFromIndex(i0);
						c1 = myself::GetCreatureFromIndex(i1);
						if( i0 != -1 && c0.db_value > 0 )
						{
							gg::SendScriptEvent(c0,2,0);
						}
						if( i1 != -1 && c1.db_value > 0 )
						{
							gg::SendScriptEvent(c1,2,0);
						}
					}
					myself::AddUseSkillDesire(myself.sm,1281795,0,1,1000000);
					myself::AddTimerEx(2000,40000);
					return;
				}
				case 3:
				{
					if( myself.i_ai3 == 0 )
					{
						myself::Area_SetOnOff(AreaName2,1);
					}
					myself::AddUseSkillDesire(myself.sm,1281796,0,1,1000000);
					myself::AddTimerEx(2000,40000);
					return;
				}
				case 4:
				{
					if( myself.i_ai3 == 0 )
					{
						myself::Area_SetOnOff(AreaName1,1);
					}
					myself::AddUseSkillDesire(myself.sm,1281797,0,1,1000000);
					myself::AddTimerEx(2000,40000);
					return;
				}
				case 5:
				{
					myself::AddUseSkillDesire(myself.sm,1281537,0,1,1000);
					myself::AddTimerEx(2000,40000);
					return;
				}
			}
		}
	}

	EventHandler MY_DYING()
	{
		myself::Area_SetOnOff(AreaName1,0);
		myself::Area_SetOnOff(AreaName2,0);
		myself::Area_SetOnOff(AreaName3,0);
		myself::UnregisterGlobalMap(GM_ID_1);
		myself::EffectMusic(myself.sm,10000,"BS01_D");
		myself::SetDBValue(myself.sm,0);
	}

}
