class HitReactionMechComponent extends HitReactionComponent
{

	public override function OnGameAttached()
	{
		if( MechIsDeadOnInit() )
		{
			SetHitReactionType( animHitReactionType.None );
			SendMechDataToAIBehavior( animHitReactionType.Death );
		}
	}

	private function MechIsDeadOnInit() : Bool
	{
		var puppet : NPCPuppet;
		puppet = ( ( NPCPuppet )( GetOwner() ) );
		if( puppet.IsDead() )
		{
			if( StatusEffectSystem.ObjectHasStatusEffect( GetOwner(), T"WorkspotStatus.Death" ) )
			{
				return false;
			}
			return true;
		}
		if( puppet.GetHighLevelStateFromBlackboard() == gamedataNPCHighLevelState.Dead )
		{
			return true;
		}
		return false;
	}

	public override function EvaluateHit( newHitEvent : gameHitEvent )
	{
		var npc : NPCPuppet;
		var hitFeedbackSound : CName;
		var wasNPCAliveBeforeProcessingHit : Bool;
		var broadcaster : StimBroadcasterComponent;
		var guardBreakImpulse : Float;
		npc = ( ( NPCPuppet )( GetOwner() ) );
		if( !( npc ) )
		{
			return;
		}
		CacheVars( newHitEvent );
		GetDBParameters();
		GetBodyPart( newHitEvent );
		wasNPCAliveBeforeProcessingHit = m_isAlive;
		if( !( m_deathHasBeenPlayed ) )
		{
			ProcessMechDeath( newHitEvent, npc );
		}
		if( !( newHitEvent ) )
		{
			if( !( m_isAlive ) )
			{
				if( npc.ShouldSkipDeathAnimation() )
				{
					m_animHitReaction.hitType = ( ( Int32 )( animHitReactionType.None ) );
				}
				else
				{
					m_animHitReaction.hitDirection = 0;
					m_animHitReaction.hitIntensity = 1;
					m_animHitReaction.hitType = ( ( Int32 )( animHitReactionType.Death ) );
					m_animHitReaction.hitBodyPart = 4;
					m_animHitReaction.npcMovementSpeed = 0;
					m_animHitReaction.npcMovementDirection = 0;
				}
				m_hitReactionAction.Stop();
				m_hitReactionAction.Setup( m_animHitReaction );
				m_hitReactionAction.Launch();
				AnimationControllerComponent.ApplyFeatureToReplicate( GetOwner(), 'hit', m_animHitReaction );
			}
			else
			{
				return;
			}
		}
		if( AttackData.IsRangedOrDirect( newHitEvent.attackData.GetAttackType() ) )
		{
			if( ( !( GetHitTimerAvailability() ) && ( m_previousRangedHitTimeStamp != GetCurrentTime() ) ) && m_isAlive )
			{
				return;
			}
		}
		SetCumulatedDamages( newHitEvent.target, guardBreakImpulse );
		SetHitSource( newHitEvent.attackData.GetAttackType() );
		SetStance();
		SetHitReactionThresholds();
		SetHitReactionImmunities();
		m_reactionType = GetReactionType( guardBreakImpulse, newHitEvent );
		if( ( ( GetCurrentTime() <= ( m_previousHitTime + 0.09 ) ) && m_lastHitReactionPlayed != EAILastHitReactionPlayed.Twitch ) && m_reactionType == animHitReactionType.Twitch )
		{
			return;
		}
		StoreHitData( GameObject.GetAttackAngleInInt( newHitEvent, m_animHitReaction.hitSource ), m_hitIntensity, m_reactionType, HitShapeUserDataBase.GetHitReactionZone( GetHitShapeUserData() ), m_animVariation );
		m_previousHitTime = GetCurrentTime();
		if( m_animHitReaction.hitType == ( ( Int32 )( animHitReactionType.Twitch ) ) )
		{
			SendTwitchDataToAnimationGraph();
			broadcaster = m_attackData.GetSource().GetStimBroadcasterComponent();
			if( broadcaster )
			{
				broadcaster.SendDrirectStimuliToTarget( GetOwner(), gamedataStimType.CombatHit, GetOwner() );
			}
		}
		else
		{
			SendMechDataToAIBehavior( m_reactionType );
		}
		if( AttackData.IsRangedOrDirect( newHitEvent.attackData.GetAttackType() ) )
		{
			if( !( m_isAlive ) && wasNPCAliveBeforeProcessingHit )
			{
				hitFeedbackSound = 'w_feedback_kill_human_body';
			}
			GameInstance.GetAudioSystem( GetOwner().GetGame() ).Play( hitFeedbackSound );
		}
	}

	protected event OnForcedDeathEvent( forcedDeath : ForcedDeathEvent )
	{
		super.OnForcedDeathEvent( forcedDeath );
		m_animHitReaction.hitDirection = 0;
		m_animHitReaction.hitIntensity = 1;
		m_animHitReaction.hitType = 7;
		m_animHitReaction.hitBodyPart = 4;
		m_animHitReaction.npcMovementSpeed = 0;
		m_animHitReaction.npcMovementDirection = 0;
		AnimationControllerComponent.ApplyFeatureToReplicate( GetOwner(), 'hit', m_animHitReaction );
	}

	protected final function ProcessMechDeath( hitEvent : gameHitEvent, npc : NPCPuppet ) : Bool
	{
		var attackData : AttackData;
		attackData = hitEvent.attackData;
		if( ScriptedPuppet.IsAlive( npc ) )
		{
			return false;
		}
		StatusEffectHelper.RemoveStatusEffect( npc, T"BaseStatusEffect.Immortal" );
		if( DefeatedRemoveConditions( npc ) )
		{
			GetOwner().Record1DamageInHistory( attackData.GetInstigator() );
			npc.Kill( attackData.GetInstigator() );
			m_reactionType = animHitReactionType.Death;
			StatusEffectHelper.ApplyStatusEffect( npc, T"Minotaur.DefeatedMinotaur", npc.GetEntityID() );
			m_isAlive = false;
			return true;
		}
		AnimationControllerComponent.PushEventToReplicate( GetOwner(), 'e3_2019_boss_defeated_face' );
		return false;
	}

}

