class MinotaurOnStatusEffectAppliedListener extends ScriptStatusEffectListener
{
	var m_owner : weak< NPCPuppet >;
	private var m_minotaurMechComponent : MinotaurMechComponent;

	public virtual function OnStatusEffectApplied( statusEffect : weak< StatusEffect_Record > )
	{
		if( statusEffect.GetID() == T"Minotaur.LeftArmDestroyed" )
		{
			DisableLeftArmMesh();
		}
		else if( statusEffect.GetID() == T"Minotaur.RightArmDestroyed" )
		{
			DisableRightArmMesh();
		}
	}

	public function DisableLeftArmMesh()
	{
		if( m_owner )
		{
			AnimationControllerComponent.SetInputBoolToReplicate( m_owner, 'disable_left_weak_spot_visibility', false );
		}
	}

	public function DisableRightArmMesh()
	{
		if( m_owner )
		{
			AnimationControllerComponent.SetInputBoolToReplicate( m_owner, 'disable_right_weak_spot_visibility', false );
		}
	}

}

class MinotaurMechComponent extends ScriptableComponent
{
	editable var m_deathAttackRecordID : TweakDBID;
	private var m_owner : weak< NPCPuppet >;
	private var m_statusEffectListener : MinotaurOnStatusEffectAppliedListener;
	private var m_npcCollisionComponent : SimpleColliderComponent;
	private var m_npcDeathCollisionComponent : SimpleColliderComponent;
	private var m_npcSystemCollapseCollisionComponent : SimpleColliderComponent;
	private var m_currentScanType : MechanicalScanType;
	private var m_currentScanAnimation : CName;

	public export function OnGameAttach()
	{
		m_owner = ( ( NPCPuppet )( GetOwner() ) );
		m_statusEffectListener = new MinotaurOnStatusEffectAppliedListener;
		m_statusEffectListener.m_owner = m_owner;
		m_currentScanType = MechanicalScanType.None;
		GameInstance.GetStatusEffectSystem( GetOwner().GetGame() ).RegisterListener( m_owner.GetEntityID(), m_statusEffectListener );
	}

	public export function OnGameDetach()
	{
		m_statusEffectListener = NULL;
	}

	protected event OnStatusEffectApplied( evt : ApplyStatusEffectEvent )
	{
		var tags : array< CName >;
		tags = evt.staticData.GameplayTags();
		if( StatusEffectSystem.ObjectHasStatusEffect( m_owner, T"Minotaur.DefeatedMinotaur" ) )
		{
			if( m_npcCollisionComponent )
			{
				m_npcDeathCollisionComponent.Toggle( true );
			}
		}
		if( tags.Contains( 'JamWeapon' ) )
		{
			DisableWeapons();
		}
		if( tags.Contains( 'SystemCollapse' ) )
		{
			EnableSystemCollapse();
		}
	}

	protected event OnStatusEffectRemoved( evt : RemoveStatusEffect )
	{
		var tags : array< CName >;
		tags = evt.staticData.GameplayTags();
		if( tags.Contains( 'JamWeapon' ) )
		{
			EnableWeapons();
		}
	}

	public function DisableWeapons()
	{
		if( m_owner )
		{
			AnimationControllerComponent.SetInputBoolToReplicate( m_owner, 'weapon_off', true );
		}
	}

	public function EnableWeapons()
	{
		if( m_owner )
		{
			AnimationControllerComponent.SetInputBoolToReplicate( m_owner, 'weapon_off', false );
		}
	}

	public function EnableSystemCollapse()
	{
		if( m_owner )
		{
			AnimationControllerComponent.SetInputBoolToReplicate( m_owner, 'system_collapse', true );
		}
	}

	protected event OnEnableColliderDelayEvent( enableColliderEvent : EnableColliderDelayEvent )
	{
		m_npcCollisionComponent.Toggle( true );
	}

	protected event OnRequestComponents( ri : EntityRequestComponentsInterface )
	{
		EntityRequestComponentsInterface.RequestComponent( ri, 'npcCollision', 'SimpleColliderComponent', true );
		EntityRequestComponentsInterface.RequestComponent( ri, 'deathCollision', 'SimpleColliderComponent', true );
		EntityRequestComponentsInterface.RequestComponent( ri, 'systemCollapseCollision', 'SimpleColliderComponent', true );
	}

	protected event OnTakeControl( ri : EntityResolveComponentsInterface )
	{
		m_npcCollisionComponent = ( ( SimpleColliderComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'npcCollision' ) ) );
		m_npcDeathCollisionComponent = ( ( SimpleColliderComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'deathCollision' ) ) );
		m_npcSystemCollapseCollisionComponent = ( ( SimpleColliderComponent )( EntityResolveComponentsInterface.GetComponent( ri, 'systemCollapseCollision' ) ) );
		m_npcDeathCollisionComponent.Toggle( false );
		m_npcSystemCollapseCollisionComponent.Toggle( false );
	}

	protected event OnAudioEvent( evt : AudioEvent )
	{
		var evtFootstep : HeavyFootstepEvent;
		var player : weak< PlayerPuppet >;
		evtFootstep = new HeavyFootstepEvent;
		player = ( ( PlayerPuppet )( GetPlayerSystem().GetLocalPlayerControlledGameObject() ) );
		if( !( player ) )
		{
			return false;
		}
		if( evt.eventName == 'enm_mech_minotaur_loco_fs_heavy' )
		{
			evtFootstep.instigator = m_owner;
			evtFootstep.audioEventName = evt.eventName;
			player.QueueEvent( evtFootstep );
		}
	}

	protected event OnMinotaurDeath( evt : gameDeathEvent )
	{
		if( !( StatusEffectSystem.ObjectHasStatusEffect( m_owner, T"BaseStatusEffect.SystemCollapse" ) ) )
		{
			GameObject.StartReplicatedEffectEvent( m_owner, 'explode_death' );
			if( m_npcCollisionComponent )
			{
				m_npcDeathCollisionComponent.Toggle( true );
			}
		}
		else
		{
			m_npcSystemCollapseCollisionComponent.Toggle( true );
		}
	}

	public function FireAttack()
	{
		var attack : Attack_GameEffect;
		var hitFlags : array< SHitFlag >;
		var flag : SHitFlag;
		flag.flag = hitFlag.FriendlyFire;
		flag.source = 'Attack';
		hitFlags.PushBack( flag );
		attack = RPGManager.PrepareGameEffectAttack( m_owner.GetGame(), ( ( GameObject )( m_owner ) ), ( ( GameObject )( m_owner ) ), m_deathAttackRecordID, , hitFlags );
		attack.StartAttack();
	}

}

