@LabelIndex 23219
@StringIndex 4567
class 0 ai_boss07_heart_of_warding : default_npc {
parameter:
	int	TelPosX = 0;
	int	TelPosY = 0;
	int	TelPosZ = 0;
	string	fnHi = "heart_of_volcano001.htm";
	string	fnBattle = "heart_of_volcano003.htm";
	string	fnNotRespawn = "heart_of_volcano002.htm";
	string	fnNoMoreTicket = "heart_of_volcano004.htm";
	string	Valakas_f_maker = "godard02_npc2416_65m1";
	string	Valakas_f_shock_maker = "godard02_npc2416_62m1";
	string	Valakas_f_shocker_maker = "godard02_npc2416_64m1";
	string	Valakas_f_breath_maker = "godard02_npc2416_63m1";

handler:
	EventHandler CREATED(reply) {
		if( reply == 0 ) {
			myself.i_ai0 = 0;
			myself.i_ai1 = 0;
			myself::SetDBValue(myself.sm,0);
		} else {
			myself.i_ai0 = myself.sm.db_value;
		}
		myself::AddTimerEx(2002,( 60 * 1000 ));
	}

	EventHandler TALKED(talker) {
		myself::ShowPage(talker,fnHi);
	}

	EventHandler ATTACKED(attacker,i0,c0,i1,i2,i3,i4,c3,maker0) {
		if( gg::OwnItemCount(attacker,57) == 1990 ) {
			maker0 = gg::GetNpcMaker(Valakas_f_maker);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,1001,0,0);
			}
			maker0 = gg::GetNpcMaker(Valakas_f_shock_maker);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,1001,0,0);
			}
			maker0 = gg::GetNpcMaker(Valakas_f_breath_maker);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,1001,0,0);
			}
			maker0 = gg::GetNpcMaker(Valakas_f_shocker_maker);
			if( gg::IsNull(maker0) == 0 ) {
				gg::SendMakerScriptEvent(maker0,1001,0,0);
			}
		}
		if( gg::OwnItemCount(attacker,57) != 1980 ) {
			return;
		}
		i0 = myself::GetGlobalMap(3);
		if( i0 != -1 ) {
			c0 = gg::GetCreatureFromIndex(i0);
			if( myself::IsNullCreature(c0) == 0 && c0.alive ) {
				if( c0.db_value == 0 ) {
					gg::SendScriptEvent(c0,1000,1000);
					i3 = myself::MPCC_GetMPCCId(attacker);
					c3 = myself::MPCC_GetMaster(i3);
					if( attacker != c3 ) {
						myself::InstantTeleport(attacker,TelPosX,TelPosY,TelPosZ);
						myself.i_ai0 = ( myself.i_ai0 + 1 );
						myself::SetDBValue(myself.sm,myself.i_ai0);
					} else {
						i4 = myself::MPCC_GetMemberCount(i3);
						if( attacker.builder_level > 0 && attacker.builder_level <= 2 && i4 >= 1 ) {
							myself::MPCC_SetMasterPartyRouting(i3,c0,1);
							myself::InstantTeleportMPCC(attacker,TelPosX,TelPosY,TelPosZ,1000,100,200,0,0);
							return;
						}
						if( i4 > ( 200 - myself.i_ai0 ) ) {
							return;
						}
						myself::InstantTeleportMPCC(attacker,TelPosX,TelPosY,TelPosZ,1000,100,200,0,0);
					}
				}
			}
		}
	}

	EventHandler MPCC_TELEPORTED(talker,reply,c0,c1,i0,i1) {
		i0 = myself::GetGlobalMap(3);
		if( i0 != -1 ) {
			c0 = gg::GetCreatureFromIndex(i0);
		} else {
			return;
		}
		i1 = myself::MPCC_GetMPCCId(talker);
		c1 = myself::MPCC_GetMaster(i1);
		if( talker != c1 ) {
		} else if( myself::IsNullCreature(c0) == 0 ) {
			if( talker.builder_level > 0 && talker.builder_level <= 2 && reply >= 1 ) {
				gg::SendScriptEvent(c0,99999999,i1);
				myself.i_ai0 = ( myself.i_ai0 + reply );
				myself::SetDBValue(myself.sm,myself.i_ai0);
				return;
			}
			if( reply >= 99 ) {
				gg::SendScriptEvent(c0,99999999,i1);
				myself.i_ai1 = i1;
			}
			if( reply > 0 ) {
				myself.i_ai0 = ( myself.i_ai0 + reply );
				myself::SetDBValue(myself.sm,myself.i_ai0);
			}
		}
	}

	EventHandler TELEPORT_REQUESTED(talker,i0,c0,i1,i2,i3,i4,c3) {
		i0 = myself::GetGlobalMap(3);
		if( i0 != -1 ) {
			c0 = gg::GetCreatureFromIndex(i0);
			if( myself::IsNullCreature(c0) == 0 && c0.alive ) {
				if( c0.db_value == 0 ) {
					myself::MPCC_SetMasterPartyRouting(myself.i_ai1,c0,0);
					gg::SendScriptEvent(c0,0,0);
				}
				if( c0.db_value == 0 || c0.db_value == 1 ) {
					if( myself.i_ai0 >= 200 ) {
						myself::ShowPage(talker,fnNoMoreTicket);
					} else {
						i3 = myself::MPCC_GetMPCCId(talker);
						c3 = myself::MPCC_GetMaster(i3);
						if( talker != c3 ) {
							myself::InstantTeleport(talker,TelPosX,TelPosY,TelPosZ);
							myself.i_ai0 = ( myself.i_ai0 + 1 );
							myself::SetDBValue(myself.sm,myself.i_ai0);
						} else {
							i4 = myself::MPCC_GetMemberCount(i3);
							if( talker.builder_level > 0 && talker.builder_level <= 2 && i4 >= 1 ) {
								if( i4 > ( 200 - myself.i_ai0 ) ) {
									myself::Say(" ˆ.");
								} else {
									myself::InstantTeleportMPCC(talker,TelPosX,TelPosY,TelPosZ,1000,100,200,0,0);
								}
								return;
							}
							if( i4 > ( 200 - myself.i_ai0 ) ) {
							} else {
								myself::InstantTeleportMPCC(talker,TelPosX,TelPosY,TelPosZ,1000,100,200,0,0);
							}
						}
					}
				} else if( c0.db_value == 2 || c0.db_value == 3 ) {
					myself::ShowPage(talker,fnBattle);
				}
			} else {
				myself::ShowPage(talker,fnNotRespawn);
			}
		} else {
			myself::ShowPage(talker,fnNotRespawn);
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id,i0,c0) {
		if( timer_id == 2002 ) {
			i0 = myself::GetGlobalMap(3);
			if( i0 != -1 ) {
				c0 = gg::GetCreatureFromIndex(i0);
				if( myself::IsNullCreature(c0) == 0 && c0.alive ) {
					if( c0.db_value == 0 && myself.sm.db_value != 0 ) {
						myself::SetDBValue(myself.sm,0);
						myself.i_ai0 = 0;
					}
				} else if( myself.sm.db_value != 0 ) {
					myself::SetDBValue(myself.sm,0);
					myself.i_ai0 = 0;
				}
			} else if( myself.sm.db_value != 0 ) {
				myself::SetDBValue(myself.sm,0);
				myself.i_ai0 = 0;
			}
			myself::AddTimerEx(2002,( 60 * 1000 ));
		}
	}

}
