@LabelIndex 422976
@StringIndex 63827
class 1 naia_main_maker : default_maker {
parameter:
	string	area_naia_floor = "18_25_core_naia";
	string	area_naia_pillar_1 = "18_25_naia_pillar_green";
	string	area_naia_pillar_2 = "18_25_naia_pillar_red";
	string	naia_door_name = "c_tower_xxx";
	int	death_count_positive = 120;
	int	death_count_negative = -120;
	int	reset_count = 600;
	int	babble_mode = 0;

handler:
	EventHandler ON_START(i0,def0) {
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
		myself.i_ai3 = 0;
		myself.i_ai4 = 0;
		def0 = myself::GetSpawnDefine(10);
		if( gg::IsNull(def0) == 0 && def0.has_dbname ) {
			def0::LoadDBNpcInfo(1010);
		}
	}

	EventHandler ON_DB_NPC_INFO(loaded_def,record0,i0,maker0,def0) {
		if( babble_mode == 1 ) {
			gg::Announce("DB  ");
		}
		if( record0.is_alive ) {
			if( babble_mode == 1 ) {
				gg::Announce(" DB   -  ");
			}
			loaded_def::SetDBLoaded(1);
			def0 = myself::GetSpawnDefine(0);
			if( gg::IsNull(def0) == 0 ) {
				if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
					def0::Spawn2(def0.total,0,0);
				}
			}
		} else if( loaded_def.respawn_time != 0 ) {
			if( record0.death_time == 0 ) {
				if( babble_mode == 1 ) {
					gg::Announce(" DB  ˆ (" + gg::IntToStr(record0.death_time) + ") -  ");
				}
				def0 = myself::GetSpawnDefine(0);
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
						def0::Spawn2(def0.total,0,0);
					}
				}
			} else if( babble_mode == 1 ) {
				gg::Announce(" DB  (" + gg::IntToStr(record0.death_time) + ") -       ");
			}
			i0 = ( ( record0.death_time + loaded_def.respawn_time ) + loaded_def.respawn_rand );
			def0 = myself::GetSpawnDefine(0);
			if( gg::IsNull(def0) == 0 ) {
				if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
					if( babble_mode == 1 ) {
						gg::Announce(gg::IntToStr(i0) + "  ");
					}
					def0::RegToRespawnTimer(i0);
				}
			}
		} else if( babble_mode == 1 ) {
			gg::Announce("DB (" + gg::IntToStr(record0.death_time) + ")");
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,def0,reply,died,i0) {
		if( myself.i_ai2 < 3 && myself.i_ai4 == 0 ) {
			if( deleted_def == myself::GetSpawnDefine(0) ) {
				if( babble_mode == 1 ) {
					gg::Announce(" 0ˆ-  ˆ ");
				}
				gg::Castle_GateOpenClose2(naia_door_name,1);
				gg::Area_SetOnOff(area_naia_floor,1);
				myself.i_ai2 = 1;
				if( babble_mode == 1 ) {
					gg::Announce(" 1ˆ- spore  ");
				}
				def0 = myself::GetSpawnDefine(1);
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
						def0::Spawn2(def0.total,0,0);
					}
				}
			} else if( deleted_def == myself::GetSpawnDefine(1) ) {
				myself.i_ai2 = 2;
				if( babble_mode == 1 ) {
					gg::Announce(" 2ˆ- spore  ");
				}
				def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
				def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			} else if( deleted_def == myself::GetSpawnDefine(2) ) {
				if( died == 0 ) {
					def0 = myself::GetSpawnDefine(3);
					if( gg::IsNull(def0) == 0 ) {
						if( myself::AtomicIncreaseTotal(def0,1,1) ) {
							def0::Spawn2(1,0,0);
						}
					}
					if( myself.i_ai2 == 2 ) {
						myself.i_ai3 = ( myself.i_ai3 + 1 );
						if( babble_mode == 1 ) {
							gg::Announce("  :" + gg::IntToStr(myself.i_ai3) + "/ " + gg::IntToStr(reset_count));
						}
						if( myself.i_ai3 >= reset_count ) {
							gg::SendMakerScriptEvent(myself,78010035,0,0);
							myself.i_ai2 = 5;
						}
					}
				} else if( myself.i_ai2 == 2 ) {
					myself.i_ai3 = ( myself.i_ai3 - 1 );
				}
				myself.i_ai0 = ( myself.i_ai0 + 2 );
				if( myself.i_ai1 > 0 ) {
					myself.i_ai1 = ( myself.i_ai1 - 1 );
				} else if( myself.i_ai1 < 0 ) {
					myself.i_ai1 = ( myself.i_ai1 + 1 );
				}
				if( babble_mode == 1 ) {
					gg::Announce("fire-water counter: " + myself.i_ai0 + "/ wind-earth counter: " + myself.i_ai1);
				}
				if( myself.i_ai0 == 20 || myself.i_ai0 == 40 || myself.i_ai0 == 60 || myself.i_ai0 == 80 || myself.i_ai0 == 100 ) {
					def0 = myself::GetSpawnDefine(3);
					if( gg::IsNull(def0) == 0 ) {
						def0::SendScriptEvent(78010012,0,2);
					}
				}
				if( myself.i_ai0 >= death_count_positive ) {
					if( babble_mode == 1 ) {
						gg::Announce(" 3ˆ-   ");
					}
					myself.i_ai0 = 0;
					myself.i_ai2 = 3;
					myself.i_ai4 = 2;
					for(i0 = 1; i0 <= 5; i0++) {
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 ) {
							def0::SendScriptEvent(78010012,myself.i_ai4,0);
						}
					}
				} else if( myself.i_ai0 >= 0 && gg::Rand(1000) > 200 ) {
					def0 = myself::GetSpawnDefine(3);
				} else {
					def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				}
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			} else if( deleted_def == myself::GetSpawnDefine(3) ) {
				if( died == 0 ) {
					def0 = myself::GetSpawnDefine(2);
					if( gg::IsNull(def0) == 0 ) {
						if( myself::AtomicIncreaseTotal(def0,1,1) ) {
							def0::Spawn2(1,0,0);
						}
					}
					if( myself.i_ai2 == 2 ) {
						myself.i_ai3 = ( myself.i_ai3 + 1 );
						if( babble_mode == 1 ) {
							gg::Announce("  :" + gg::IntToStr(myself.i_ai3) + "/ " + gg::IntToStr(reset_count));
						}
						if( myself.i_ai3 >= reset_count ) {
							gg::SendMakerScriptEvent(myself,78010035,0,0);
							myself.i_ai2 = 5;
						}
					}
				} else if( myself.i_ai2 == 2 ) {
					myself.i_ai3 = ( myself.i_ai3 - 1 );
				}
				myself.i_ai0 = ( myself.i_ai0 - 2 );
				if( myself.i_ai1 > 0 ) {
					myself.i_ai1 = ( myself.i_ai1 - 1 );
				} else if( myself.i_ai1 < 0 ) {
					myself.i_ai1 = ( myself.i_ai1 + 1 );
				}
				if( babble_mode == 1 ) {
					gg::Announce("fire-water counter: " + myself.i_ai0 + "/ wind-earth counter: " + myself.i_ai1);
				}
				if( myself.i_ai0 == -20 || myself.i_ai0 == -40 || myself.i_ai0 == -60 || myself.i_ai0 == -80 || myself.i_ai0 == -100 ) {
					def0 = myself::GetSpawnDefine(2);
					if( gg::IsNull(def0) == 0 ) {
						def0::SendScriptEvent(78010012,0,3);
					}
				}
				if( myself.i_ai0 <= death_count_negative ) {
					if( babble_mode == 1 ) {
						gg::Announce(" 3ˆ-   ");
					}
					myself.i_ai0 = 0;
					myself.i_ai2 = 3;
					myself.i_ai4 = 1;
					for(i0 = 1; i0 <= 5; i0++) {
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 ) {
							def0::SendScriptEvent(78010012,myself.i_ai4,0);
						}
					}
				} else if( myself.i_ai0 <= 0 && gg::Rand(1000) > 200 ) {
					def0 = myself::GetSpawnDefine(2);
				} else {
					def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				}
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			} else if( deleted_def == myself::GetSpawnDefine(4) ) {
				if( died == 0 ) {
					def0 = myself::GetSpawnDefine(5);
					if( gg::IsNull(def0) == 0 ) {
						if( myself::AtomicIncreaseTotal(def0,1,1) ) {
							def0::Spawn2(1,0,0);
						}
					}
					if( myself.i_ai2 == 2 ) {
						myself.i_ai3 = ( myself.i_ai3 + 1 );
						if( babble_mode == 1 ) {
							gg::Announce("  :" + gg::IntToStr(myself.i_ai3) + "/ " + gg::IntToStr(reset_count));
						}
						if( myself.i_ai3 >= reset_count ) {
							gg::SendMakerScriptEvent(myself,78010035,0,0);
							myself.i_ai2 = 5;
						}
					}
				} else if( myself.i_ai2 == 2 ) {
					myself.i_ai3 = ( myself.i_ai3 - 1 );
				}
				myself.i_ai1 = ( myself.i_ai1 + 2 );
				if( myself.i_ai0 > 0 ) {
					myself.i_ai0 = ( myself.i_ai0 - 1 );
				} else if( myself.i_ai0 < 0 ) {
					myself.i_ai0 = ( myself.i_ai0 + 1 );
				}
				if( babble_mode == 1 ) {
					gg::Announce("fire-water counter: " + myself.i_ai0 + "/ wind-earth counter: " + myself.i_ai1);
				}
				if( myself.i_ai1 == 20 || myself.i_ai1 == 40 || myself.i_ai1 == 60 || myself.i_ai1 == 80 || myself.i_ai1 == 100 ) {
					def0 = myself::GetSpawnDefine(5);
					if( gg::IsNull(def0) == 0 ) {
						def0::SendScriptEvent(78010012,0,4);
					}
				}
				if( myself.i_ai1 >= death_count_positive ) {
					if( babble_mode == 1 ) {
						gg::Announce(" 3ˆ-   ");
					}
					myself.i_ai0 = 0;
					myself.i_ai2 = 3;
					myself.i_ai4 = 4;
					for(i0 = 1; i0 <= 5; i0++) {
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 ) {
							def0::SendScriptEvent(78010012,myself.i_ai4,0);
						}
					}
				} else if( myself.i_ai1 >= 0 && gg::Rand(1000) > 200 ) {
					def0 = myself::GetSpawnDefine(5);
				} else {
					def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				}
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			} else if( deleted_def == myself::GetSpawnDefine(5) ) {
				if( died == 0 ) {
					def0 = myself::GetSpawnDefine(4);
					if( gg::IsNull(def0) == 0 ) {
						if( myself::AtomicIncreaseTotal(def0,1,1) ) {
							def0::Spawn2(1,0,0);
						}
					}
					if( myself.i_ai2 == 2 ) {
						myself.i_ai3 = ( myself.i_ai3 + 1 );
						if( babble_mode == 1 ) {
							gg::Announce("  :" + gg::IntToStr(myself.i_ai3) + "/ " + gg::IntToStr(reset_count));
						}
						if( myself.i_ai3 >= reset_count ) {
							gg::SendMakerScriptEvent(myself,78010035,0,0);
							myself.i_ai2 = 5;
						}
					}
				} else if( myself.i_ai2 == 2 ) {
					myself.i_ai3 = ( myself.i_ai3 - 1 );
				}
				myself.i_ai1 = ( myself.i_ai1 - 2 );
				if( myself.i_ai0 > 0 ) {
					myself.i_ai0 = ( myself.i_ai0 - 1 );
				} else if( myself.i_ai0 < 0 ) {
					myself.i_ai0 = ( myself.i_ai0 + 1 );
				}
				if( babble_mode == 1 ) {
					gg::Announce("fire-water counter: " + myself.i_ai0 + "/ wind-earth counter: " + myself.i_ai1);
				}
				if( myself.i_ai1 == -20 || myself.i_ai1 == -40 || myself.i_ai1 == -60 || myself.i_ai1 == -80 || myself.i_ai1 == -100 ) {
					def0 = myself::GetSpawnDefine(4);
					if( gg::IsNull(def0) == 0 ) {
						def0::SendScriptEvent(78010012,0,5);
					}
				}
				if( myself.i_ai1 <= death_count_negative ) {
					if( babble_mode == 1 ) {
						gg::Announce(" 3ˆ -   ");
					}
					myself.i_ai0 = 0;
					myself.i_ai2 = 3;
					myself.i_ai4 = 3;
					for(i0 = 1; i0 <= 5; i0++) {
						def0 = myself::GetSpawnDefine(i0);
						if( gg::IsNull(def0) == 0 ) {
							def0::SendScriptEvent(78010012,myself.i_ai4,0);
						}
					}
				} else if( myself.i_ai1 <= 0 && gg::Rand(1000) > 200 ) {
					def0 = myself::GetSpawnDefine(4);
				} else {
					def0 = myself::GetSpawnDefine(( gg::Rand(4) + 2 ));
				}
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			}
		} else if( myself.i_ai2 >= 4 && myself.i_ai4 != 0 && ( deleted_def == myself::GetSpawnDefine(6) || deleted_def == myself::GetSpawnDefine(7) || deleted_def == myself::GetSpawnDefine(8) || deleted_def == myself::GetSpawnDefine(9) ) ) {
			if( died == 1 ) {
				if( babble_mode == 1 ) {
					gg::Announce("  -  ˆ  ");
				}
				def0 = myself::GetSpawnDefine(10);
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
					}
				}
			}
		} else if( myself.i_ai2 >= 4 && myself.i_ai4 != 0 && deleted_def == myself::GetSpawnDefine(10) ) {
			if( died == 1 ) {
				if( babble_mode == 1 ) {
					gg::Announce("   ");
				}
				deleted_def::SetDBLoaded(0);
			}
			myself::AddTimerEx(78002,( ( 1 * 60 ) * 1000 ));
		}
	}

	EventHandler ON_SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,def0,i0) {
		if( script_event_arg1 == 78010031 ) {
			myself.i_ai0 = ( myself.i_ai0 + 1 );
			if( babble_mode == 1 ) {
				gg::Announce(" : " + myself.i_ai0);
			}
			if( myself.i_ai0 >= 10 ) {
				if( babble_mode == 1 ) {
					gg::Announce(" 10  ");
				}
				for(i0 = 1; i0 <= 5; i0++) {
					def0 = myself::GetSpawnDefine(i0);
					if( gg::IsNull(def0) == 0 ) {
						def0::Despawn();
					}
				}
				def0 = myself::GetSpawnDefine(( myself.i_ai4 + 5 ));
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						def0::Spawn2(1,0,0);
						myself::AddTimerEx(78001,( 3 * 1000 ));
					}
				}
				myself.i_ai0 = 0;
			}
		} else if( script_event_arg1 == 78010035 ) {
			if( babble_mode == 1 ) {
				gg::Announce("  - 1   ");
			}
			myself::AddTimerEx(78003,( 60 * 1000 ));
		}
	}

	EventHandler ON_TIMER(timer_id,def0,i0) {
		if( timer_id == 78001 ) {
			if( babble_mode == 1 ) {
				gg::Announce(" 4ˆ-    ");
			}
			myself.i_ai2 = 4;
			def0 = myself::GetSpawnDefine(( myself.i_ai4 + 5 ));
			if( gg::IsNull(def0) == 0 ) {
				def0::SendScriptEvent(78010031,myself.i_ai4,0);
			}
		} else if( timer_id == 78002 ) {
			if( babble_mode == 1 ) {
				gg::Announce("  -  ");
			}
			myself.i_ai0 = 0;
			myself.i_ai1 = 0;
			myself.i_ai2 = 0;
			myself.i_ai3 = 0;
			myself.i_ai4 = 0;
			gg::Area_SetOnOff(area_naia_floor,0);
			gg::Area_SetOnOff(area_naia_pillar_1,0);
			gg::Area_SetOnOff(area_naia_pillar_2,1);
			def0 = myself::GetSpawnDefine(10);
			if( gg::IsNull(def0) == 0 && def0.has_dbname ) {
				def0::LoadDBNpcInfo(1010);
			}
		} else if( timer_id == 78003 ) {
			if( babble_mode == 1 ) {
				gg::Announce(" 5ˆ- ");
			}
			myself.i_ai3 = 0;
			myself.i_ai2 = 5;
			for(i0 = 1; i0 <= 9; i0++) {
				def0 = myself::GetSpawnDefine(i0);
				if( gg::IsNull(def0) == 0 ) {
					def0::Despawn();
				}
			}
			myself::AddTimerEx(78002,( ( 1 * 60 ) * 1000 ));
		}
	}

}
