@LabelIndex 422840
@StringIndex 63812
class 1 rim_maker : (null) {
parameter:
	int	inzone_type_param = 0;
	int	spawn_event_id = -2;
	int	despawn_event_id = -1;
	int	on_start_spawn = 1;
	int	script_event_enable = 1;
	int	inzone_cluster_id = 0;
	int	Level = 0;
	int	TimeLimit = 1200;
	int	KillCountForD = 1;
	int	KillCountForC = 2;
	int	KillCountForB = 3;
	int	KillCountForA = 4;
	int	KillCountForS = 5;
	int	KillCountForG = 7;
	int	Bonus_ChainSpawnSuccess = 10;
	int	Bonus_MobClearing = 50;
	int	Bonus_KillCount = 2;
	int	KillCountTime = 10;
	int	TM_EntireTimeCheck = 78001;
	int	TM_EntireTimeCheck2 = 78003;
	int	TM_KillCountTimeCheck = 78002;
	int	TM_GiftgiverEventDelay = 78004;
	int	GiftgiverEventDelayTime = 5;
	int	Log_ChainSpawnSuccess = 1013;
	int	Log_MobClearing = 1014;
	int	Log_NoKilling = 1015;
	int	ScaleModValue = 10;
	int	babble_mode = 0;
	int	log_mode = 1;

handler:
	EventHandler ON_START() {
		if( script_event_enable == 1 ) {
			myself.enabled = script_event_enable;
		} else {
			myself.enabled = 0;
		}
		myself::RegisterInstantZoneEventEx(inzone_type_param,inzone_cluster_id,spawn_event_id,1);
	}

	EventHandler ON_INSTANT_ZONE_EVENT(inzone_type_id,inzone_id,event_id,reply,i0,def0) {
		myself.i_ai0 = 0;
		myself.i_ai1 = 0;
		myself.i_ai2 = 0;
		myself.i_ai3 = 0;
		myself.i_ai4 = 0;
		myself.enabled = reply;
		if( myself.enabled == 1 ) {
			myself.i_ai4 = 1;
			myself::AddTimerEx(TM_EntireTimeCheck,( ( ( TimeLimit * ScaleModValue ) / 10 ) * 1000 ));
			myself::AddTimerEx(TM_KillCountTimeCheck,( ( ( KillCountTime * ScaleModValue ) / 10 ) * 1000 ));
			if( babble_mode == 1 ) {
				gg::Announce("  :" + gg::IntToStr(gg::FloatToInt(( ( TimeLimit * ScaleModValue ) / 10 ))) + "");
			}
			def0 = myself::GetSpawnDefine(0);
			if( gg::IsNull(def0) == 0 ) {
				if( myself::AtomicIncreaseTotal(def0,def0.total,1) ) {
					def0::Spawn(def0.total,0);
				}
			}
		} else if( myself.enabled == 0 ) {
			for(i0 = 0; i0 < myself.def_count; i0++) {
				def0 = myself::GetSpawnDefine(i0);
				if( gg::IsNull(def0) == 0 && def0.npc_count > 0 ) {
					def0::Despawn();
				}
			}
		}
	}

	EventHandler ON_NPC_CREATED(created_npc,created_def) {
		if( babble_mode == 1 ) {
			gg::Announce("npc :" + gg::IntToStr(created_def.npc_count));
		}
		if( myself.enabled == 0 || ( myself.i_ai4 == 0 && created_def != myself::GetSpawnDefine(1) ) ) {
			created_npc::Despawn();
		}
	}

	EventHandler ON_SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,def0,i0) {
		if( myself.enabled == 0 || myself.i_ai4 == 0 ) {
			return;
		}
		if( script_event_arg1 == 78010044 ) {
			if( babble_mode == 1 ) {
				gg::Announce("NPC : " + gg::IntToStr(script_event_arg2));
			}
			myself.i_ai0 = ( myself.i_ai0 + script_event_arg2 );
		} else if( script_event_arg1 == 78010046 ) {
			if( script_event_arg2 < 0 && script_event_arg2 != -99 ) {
				if( myself.i_ai1 > 0 && myself.i_ai1 < 10 ) {
					myself.i_ai1 = ( myself.i_ai1 + ( script_event_arg2 + 3 ) );
					if( babble_mode == 1 ) {
						gg::Announce("  - " + gg::IntToStr(myself.i_ai1) + "");
					}
				} else {
					myself.i_ai1 = ( 0 + ( script_event_arg2 + 3 ) );
					if( babble_mode == 1 ) {
						gg::Announce("  -   " + gg::IntToStr(myself.i_ai1));
					}
				}
				i0 = ( myself.i_ai1 * Bonus_ChainSpawnSuccess );
				if( i0 > 0 ) {
					myself.i_ai0 = ( myself.i_ai0 + i0 );
					if( babble_mode == 1 ) {
						gg::Announce("  : " + gg::IntToStr(i0));
					}
					if( log_mode == 1 ) {
						gg::AddLogExWithoutCreature(Log_ChainSpawnSuccess,i0,0);
					}
				}
			} else if( babble_mode == 1 ) {
				gg::Announce("  : ");
			}
			myself.i_ai1 = 0;
		}
	}

	EventHandler ON_NPC_DELETED(deleted_def,died,i0) {
		if( myself.enabled == 0 || myself.i_ai4 == 0 ) {
			return;
		}
		if( died != 0 ) {
			myself.i_ai2 = ( myself.i_ai2 + 1 );
			if( gg::IsNull(deleted_def) == 0 && deleted_def == myself::GetSpawnDefine(0) && deleted_def.respawn_time != 0 ) {
				if( myself.npc_count < myself.maximum_npc ) {
					if( myself::AtomicIncreaseTotal(deleted_def,1,1) ) {
						deleted_def::Spawn(1,deleted_def.respawn_time);
					}
				}
			}
		}
	}

	EventHandler ON_ALL_NPC_DELETED(i0,def0) {
		if( myself.enabled == 0 || myself.i_ai4 == 0 ) {
			return;
		}
		i0 = gg::FloatToInt(Bonus_MobClearing);
		if( i0 > 0 ) {
			myself.i_ai0 = ( myself.i_ai0 + i0 );
			if( babble_mode == 1 ) {
				gg::Announce("NPC  :" + gg::IntToStr(i0));
			}
			if( log_mode == 1 ) {
				gg::AddLogExWithoutCreature(Log_MobClearing,i0,0);
			}
		}
	}

	EventHandler ON_TIMER(timer_id,def0,i0) {
		if( timer_id == TM_EntireTimeCheck ) {
			if( babble_mode == 1 ) {
				gg::Announce("** ˆ:  » " + gg::IntToStr(myself.i_ai0));
			}
			myself.i_ai4 = 0;
			def0 = myself::GetSpawnDefine(0);
			if( gg::IsNull(def0) == 0 && def0.npc_count > 0 ) {
				def0::Despawn();
			}
			myself::AddTimerEx(TM_EntireTimeCheck2,( 1 * 1000 ));
		} else if( timer_id == TM_EntireTimeCheck2 ) {
			if( myself.npc_count < myself.maximum_npc ) {
				def0 = myself::GetSpawnDefine(1);
				if( gg::IsNull(def0) == 0 ) {
					if( myself::AtomicIncreaseTotal(def0,1,1) ) {
						if( babble_mode == 1 ) {
							gg::Announce(" ");
						}
						def0::Spawn(1,0);
						myself::AddTimerEx(TM_GiftgiverEventDelay,( GiftgiverEventDelayTime * 1000 ));
					}
				} else if( babble_mode == 1 ) {
					gg::Announce("rim_gift_giver  ");
				}
			} else {
				myself::AddTimerEx(TM_EntireTimeCheck2,( 10 * 1000 ));
			}
		} else if( timer_id == TM_GiftgiverEventDelay && myself.i_ai4 == 0 ) {
			def0 = myself::GetSpawnDefine(1);
			if( gg::IsNull(def0) == 0 ) {
				if( babble_mode == 1 ) {
					gg::Announce("ˆ ");
				}
				def0::SendScriptEvent(78010045,myself.i_ai0,ScaleModValue);
			}
		} else if( timer_id == TM_KillCountTimeCheck && myself.i_ai4 > 0 ) {
			if( myself.i_ai2 != 0 ) {
				if( myself.i_ai2 >= KillCountForG ) {
					i0 = ( ( myself.i_ai2 * Bonus_KillCount ) * KillCountForG );
				} else if( myself.i_ai2 >= KillCountForS ) {
					i0 = ( Bonus_KillCount * KillCountForS );
				} else if( myself.i_ai2 >= KillCountForA ) {
					i0 = ( Bonus_KillCount * KillCountForA );
				} else if( myself.i_ai2 >= KillCountForB ) {
					i0 = ( Bonus_KillCount * KillCountForB );
				} else if( myself.i_ai2 >= KillCountForC ) {
					i0 = ( Bonus_KillCount * KillCountForC );
				} else if( myself.i_ai2 >= KillCountForD ) {
					i0 = ( Bonus_KillCount * KillCountForD );
				} else {
					i0 = ( myself.i_ai2 * Bonus_KillCount );
				}
				if( babble_mode == 1 ) {
					gg::Announce(" : " + gg::IntToStr(i0));
				}
				myself.i_ai0 = ( myself.i_ai0 + i0 );
				myself.i_ai2 = 0;
				if( log_mode == 1 ) {
					gg::AddLogExWithoutCreature(Log_NoKilling,i0,0);
				}
			}
			myself::AddTimerEx(TM_KillCountTimeCheck,( ( ( KillCountTime * ScaleModValue ) / 10 ) * 1000 ));
		}
	}

}
