class HerculesCrosshairtGameController extends IronsightGameController
{
	protected editable var m_appearanceFill : Int32;
	protected editable var m_appearanceOutline : Int32;
	protected editable var m_appearanceShowThroughWalls : Bool;
	protected editable var m_appearanceTransitionTime : Float;
	private var m_weaponParamsListenerId : CallbackHandle;
	private var m_game : GameInstance;
	private var m_visionModeSystem : VisionModeSystem;
	private var m_targetedApperance : VisionAppearance;
	private var m_targets : array< EntityID >;

	protected event OnPlayerAttach( playerPuppet : GameObject )
	{
		super.OnPlayerAttach( playerPuppet );
		m_weaponParamsListenerId = m_weaponDataBB.RegisterDelayedListenerVariant( GetAllBlackboardDefs().UI_ActiveWeaponData.SmartGunParams, this, 'OnSmartGunParams' );
		m_game = playerPuppet.GetGame();
		m_visionModeSystem = GameInstance.GetVisionModeSystem( m_game );
		m_targetedApperance.fill = m_appearanceFill;
		m_targetedApperance.outline = m_appearanceOutline;
		m_targetedApperance.showThroughWalls = m_appearanceShowThroughWalls;
		m_targetedApperance.patternType = VisionModePatternType.Default;
	}

	protected event OnPlayerDetach( playerPuppet : GameObject )
	{
		super.OnPlayerDetach( playerPuppet );
		m_weaponDataBB.UnregisterDelayedListener( GetAllBlackboardDefs().UI_ActiveWeaponData.SmartGunParams, m_weaponParamsListenerId );
	}

	protected event OnSmartGunParams( argParams : Variant )
	{
		var smartData : smartGunUIParameters;
		var newTargets : array< smartGunUITargetParameters >;
		var numTargets : Int32;
		var i : Int32;
		var currTargetData : smartGunUITargetParameters;
		var contains : Bool;
		smartData = ( ( smartGunUIParameters )argParams );
		newTargets = smartData.targets;
		numTargets = smartData.targets.Size();
		if( IsWeaponActive() && m_upperBodyState == gamePSMUpperBodyStates.Aim )
		{
			for( i = 0; i < numTargets; i += 1 )
			{
				currTargetData = newTargets[ i ];
				contains = m_targets.Contains( currTargetData.entityID );
				if( currTargetData.state == gamesmartGunTargetState.Locked )
				{
					if( !( contains ) )
					{
						m_visionModeSystem.ForceVisionAppearance( ( ( GameObject )( GameInstance.FindEntityByID( m_game, currTargetData.entityID ) ) ), m_targetedApperance, m_appearanceTransitionTime );
						m_targets.PushBack( currTargetData.entityID );
					}
				}
				else
				{
					if( contains )
					{
						m_targets.Remove( currTargetData.entityID );
						if( currTargetData.state == gamesmartGunTargetState.Unlocking )
						{
							m_visionModeSystem.CancelForceVisionAppearance( ( ( GameObject )( GameInstance.FindEntityByID( m_game, currTargetData.entityID ) ) ), smartData.timeToUnlock );
						}
						else
						{
							m_visionModeSystem.CancelForceVisionAppearance( ( ( GameObject )( GameInstance.FindEntityByID( m_game, currTargetData.entityID ) ) ), m_appearanceTransitionTime );
						}
					}
				}
			}
		}
	}

	protected event OnUpperBodyChanged( state : Int32 )
	{
		var i, limit : Int32;
		var target : GameObject;
		super.OnUpperBodyChanged( state );
		if( state != ( ( Int32 )( gamePSMUpperBodyStates.Aim ) ) )
		{
			for( i = 0, limit = m_targets.Size(); i < limit; i += 1 )
			{
				target = ( ( GameObject )( GameInstance.FindEntityByID( m_game, m_targets[ i ] ) ) );
				if( target )
				{
					m_visionModeSystem.CancelForceVisionAppearance( target, m_appearanceTransitionTime );
				}
			}
			m_targets.Clear();
		}
	}

}

