class SasquatchComponent extends ScriptableComponent
{
	private var m_owner : weak< NPCPuppet >;
	private var m_owner_id : EntityID;
	private var m_weakspotDestroyed : Bool;
	private var m_player : weak< PlayerPuppet >;

	public export function OnGameAttach()
	{
		m_owner = ( ( NPCPuppet )( GetOwner() ) );
		m_owner_id = m_owner.GetEntityID();
		m_weakspotDestroyed = false;
		if( !( m_owner.IsDead() ) )
		{
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"Sasquatch.Phase1", m_owner.GetEntityID() );
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.PainInhibitors", m_owner.GetEntityID() );
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"Sasquatch.Healing", m_owner.GetEntityID() );
		}
		m_player = ( ( PlayerPuppet )( GetPlayerSystem().GetLocalPlayerControlledGameObject() ) );
		StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.DamageHackNoReaction", m_owner_id );
	}

	protected event OnStatusEffectApplied( evt : ApplyStatusEffectEvent )
	{
		var tags : array< CName >;
		var weapon : weak< WeaponObject >;
		var weaponType : gamedataItemType;
		tags = evt.staticData.GameplayTags();
		weapon = ScriptedPuppet.GetWeaponRight( m_owner );
		weaponType = WeaponObject.GetWeaponType( weapon.GetItemID() );
		if( tags.Contains( 'WeakspotDestruction' ) )
		{
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.BossNoTakeDown", m_owner.GetEntityID() );
			if( weaponType == gamedataItemType.Wea_Hammer )
			{
				m_owner.DropWeapons();
				AIActionHelper.TryStartCombatWithTarget( m_owner, m_player );
			}
		}
		if( tags.Contains( 'BossSuicide' ) )
		{
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.SuicideWithWeapon", m_owner.GetEntityID() );
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"Sasquatch.ForceStaggerSuicide", m_owner_id );
		}
		if( tags.Contains( 'BossGrenadeHackEffect' ) )
		{
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"Sasquatch.BurningGrenade", m_owner_id );
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.SasquatchSuicideWithGrenade", m_owner_id );
		}
	}

	protected event OnStatusEffectRemoved( evt : RemoveStatusEffect )
	{
		var tags : array< CName >;
		tags = evt.staticData.GameplayTags();
		if( tags.Contains( 'Madness' ) )
		{
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"BaseStatusEffect.SuicideWithWeapon", m_owner.GetEntityID() );
			StatusEffectHelper.ApplyStatusEffect( m_owner, T"Sasquatch.ForceStaggerSuicide", m_owner_id );
		}
	}

	private function DestroyAllWeakspots()
	{
		var weakspots : array< weak< WeakspotObject > >;
		var scriptWeakspot : ScriptedWeakspotObject;
		var i : Int32;
		m_owner.GetWeakspotComponent().GetWeakspots( weakspots );
		if( weakspots.Size() > 0 )
		{
			for( i = 0; i < weakspots.Size(); i += 1 )
			{
				scriptWeakspot = ( ( ScriptedWeakspotObject )( weakspots[ i ] ) );
				scriptWeakspot.DestroyWeakspot( m_owner );
				ScriptedWeakspotObject.Kill( weakspots[ i ] );
			}
		}
	}

	protected event OnDefeatedSasquatch( evt : DefeatedEvent )
	{
		var player : weak< PlayerPuppet >;
		player = ( ( PlayerPuppet )( GetPlayerSystem().GetLocalPlayerControlledGameObject() ) );
		StatusEffectHelper.RemoveStatusEffect( player, T"BaseStatusEffect.NetwatcherGeneral" );
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"Sasquatch.Phase1" );
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"BaseStatusEffect.PainInhibitors" );
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"Sasquatch.Healing" );
		StatusEffectHelper.ApplyStatusEffect( m_owner, T"AdamSmasher.InvulnerableDefeated", m_owner_id );
	}

	protected event OnDeath( evt : gameDeathEvent )
	{
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"Sasquatch.Phase1" );
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"BaseStatusEffect.PainInhibitors" );
		StatusEffectHelper.RemoveStatusEffect( m_owner, T"Sasquatch.Healing" );
	}

}

