@LabelIndex 421029
@StringIndex 63733
class 1 manage_teleport_dungeon : default_maker {
parameter:
	int	hunting_level_index = -1;
	int	room_index = -1;
	string	manager_npc_name = "KIN";

handler:
	EventHandler ON_START(i0,def0,i2) {
		if( manager_npc_name == "KIN" ) {
		}
		def0 = myself::GetSpawnDefineByNick(manager_npc_name);
		if( gg::IsNull(def0) == 0 ) {
			i2 = ( def0.total - def0.npc_count );
			if( i2 > 0 ) {
				if( myself::AtomicIncreaseTotal(def0,i2,1) ) {
					def0::Spawn2(i2,0,0);
				}
			}
		} else {
		}
		myself.i_ai0 = 0;
	}

	EventHandler ON_TIMER(timer_id) {
		if( timer_id == 5001 ) {
			if( myself.i_ai0 == 1 ) {
				myself::DoRespawn();
				myself::AddTimerEx(5001,1000);
			}
		}
	}

	EventHandler ON_SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,def0,i0,i1,i2) {
		switch(script_event_arg1) {
			case 0: {
				myself.i_ai0 = 0;
				myself::ResetRespawn();
				for(i0 = 0; i0 < myself.def_count; i0++) {
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 ) {
						if( gg::IsSameString(def0.name,manager_npc_name) == 0 ) {
							def0::Despawn();
						}
					}
				}
				break;
			}
			case 1: {
				if( myself.i_ai0 == 0 ) {
					myself.i_ai0 = 1;
					myself::ResetRespawn();
					for(i0 = 0; i0 < myself.def_count; i0++) {
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 ) {
							if( gg::IsSameString(def0.name,manager_npc_name) == 0 ) {
								if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
									def0::Spawn2(def0.total,0,0);
								}
							}
						}
					}
					myself::AddTimerEx(5001,1000);
				}
				break;
			}
			case 3: {
				for(i0 = 0; i0 < myself.def_count; i0++) {
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 ) {
						if( gg::IsSameString(def0.name,manager_npc_name) ) {
							def0::SendScriptEvent(script_event_arg1,0,0);
						} else {
							def0::Despawn();
						}
					}
				}
				break;
			}
			case 2: {
				for(i0 = 0; i0 < myself.def_count; i0++) {
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 ) {
						if( gg::IsSameString(def0.name,manager_npc_name) ) {
							def0::SendScriptEvent(script_event_arg1,0,0);
						}
					}
				}
				break;
			}
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,i0,i1,maker0,reply) {
		if( myself.i_ai0 == 1 && deleted_def.respawn_time != 0 ) {
			myself::RegisterRespawn(deleted_def.respawn_time,1,deleted_def);
		}
	}

	EventHandler ON_NPC_CREATED(created_def,created_npc,maker0) {
		if( myself.i_ai0 == 0 ) {
			if( gg::IsSameString(created_def.name,manager_npc_name) == 0 ) {
				if( gg::IsNull(created_npc) == 0 ) {
					created_npc::Despawn();
				}
			}
		}
	}

}
