@LabelIndex 109174
@StringIndex 0
class 0 warrior_fortress_private : warrior_basic {
parameter:
	int	fortress_id = 0;
	int	barrack_id = 0;
	int	toggle_buff = 0;
	int	out_of_territory_use = 1;
	int	comeback_timer = 5;
	int	selfheal_skill = 458752001;

handler:
	EventHandler CREATED(i0,i1) {
		i0 = gg::Fortress_GetFacilityLevel(fortress_id,1);
		if( i0 > 0 ) {
			i1 = ( ( toggle_buff + i0 ) - 1 );
			if( myself::Skill_GetConsumeMP(i1) < myself.sm.mp && myself::Skill_GetConsumeHP(i1) < myself.sm.hp && myself::Skill_InReuseDelay(i1) == 0 ) {
				myself::AddUseSkillDesire(myself.sm,i1,1,0,1000000);
			}
		}
		super;
	}

	EventHandler SEE_CREATURE(creature) {
		if( myself::Fortress_GetPledgeSiegeState(creature) == 2 || ( myself::IsNullCreature(creature.master) == 0 && myself::Fortress_GetPledgeSiegeState(creature.master) == 2 ) ) {
			return;
		}
		super;
	}

	EventHandler SCRIPT_EVENT(script_event_arg1,script_event_arg2,script_event_arg3,i0,c0) {
		if( script_event_arg1 == 15000001 ) {
			c0 = gg::GetCreatureFromIndex(script_event_arg2);
			if( myself::IsNullCreature(c0) == 0 ) {
				myself::RemoveAllAttackDesire();
				if( MovingAttack == 1 ) {
					myself::MakeAttackEvent(c0,100,0);
				} else {
					myself::MakeAttackEvent(c0,100,0);
				}
			}
		} else if( script_event_arg1 == 11039 ) {
			c0 = gg::GetCreatureFromIndex(script_event_arg2);
			if( myself::IsNullCreature(c0) == 0 ) {
				if( c0 == myself.boss ) {
					myself::Despawn();
					return;
				}
			}
		}
		super;
	}

	EventHandler OUT_OF_TERRITORY() {
		if( out_of_territory_use == 0 ) {
			return;
		}
		if( comeback_timer > 0 ) {
			myself::AddTimerEx(3079,( comeback_timer * 1000 ));
		} else if( myself::InMyTerritory(myself.sm) != 1 ) {
			myself::RemoveAllAttackDesire();
			if( myself::Skill_GetConsumeMP(selfheal_skill) < myself.sm.mp && myself::Skill_GetConsumeHP(selfheal_skill) < myself.sm.hp && myself::Skill_InReuseDelay(selfheal_skill) == 0 ) {
				myself::AddUseSkillDesire(myself.sm,selfheal_skill,1,1,1000000);
			}
			myself::AddMoveToDesire(myself.start_x,myself.start_y,myself.start_z,1000000);
			return;
		}
	}

	EventHandler TIMER_FIRED_EX(timer_id) {
		if( timer_id == 3079 ) {
			if( out_of_territory_use == 0 ) {
				return;
			}
			if( myself::InMyTerritory(myself.sm) != 1 ) {
				myself::RemoveAllAttackDesire();
				if( myself::Skill_GetConsumeMP(selfheal_skill) < myself.sm.mp && myself::Skill_GetConsumeHP(selfheal_skill) < myself.sm.hp && myself::Skill_InReuseDelay(selfheal_skill) == 0 ) {
					myself::AddUseSkillDesire(myself.sm,selfheal_skill,1,1,1000000);
				}
				myself::AddMoveToDesire(myself.start_x,myself.start_y,myself.start_z,1000000);
				return;
			}
		}
	}

}
