class C4Controller extends ExplosiveDeviceController
{

	public const override function GetPS() : C4ControllerPS
	{
		return ( ( C4ControllerPS )( GetBasePS() ) );
	}

}

class C4ControllerPS extends ExplosiveDeviceControllerPS
{
	default m_isScanned = true;
	default m_exposeQuickHacks = true;
	default m_tweakDBRecord = T"Devices.C4";
	default m_tweakDBDescriptionRecord = T"device_descriptions.C4";
	private instanceeditable persistent var m_itemTweakDBString : CName;
	default m_itemTweakDBString = 'C4';

	protected override function GameAttached() {}

	private function ActionActivate() : ActivateC4
	{
		var action : ActivateC4;
		action = new ActivateC4;
		action.clearanceLevel = 1;
		action.SetUp( this );
		action.SetProperties();
		action.CreateInteraction();
		return action;
	}

	private function ActionDeactivate() : DeactivateC4
	{
		var action : DeactivateC4;
		action = new DeactivateC4;
		action.clearanceLevel = 1;
		action.SetUp( this );
		action.SetProperties();
		action.CreateInteraction();
		return action;
	}

	private function ActionDetonate() : DetonateC4
	{
		var action : DetonateC4;
		action = new DetonateC4;
		action.clearanceLevel = 1;
		action.SetUp( this );
		action.SetProperties();
		action.CreateInteraction();
		return action;
	}

	public override function GetActions( out actions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		super.GetActions( actions, context );
		if( IsOFF() && GameInstance.GetTransactionSystem( GetGameInstance() ).HasItem( GetPlayerMainObject(), GetInventoryItemID() ) )
		{
			actions.PushBack( ActionActivate() );
		}
		if( IsON() )
		{
			actions.PushBack( ActionDeactivate() );
		}
		SetActionIllegality( actions, m_illegalActions.regularActions );
		return true;
	}

	protected const override function CanCreateAnyQuickHackActions() : Bool
	{
		return true;
	}

	protected override function GetQuickHackActions( out outActions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		var currentAction : ScriptableDeviceAction;
		currentAction = ActionDetonate();
		currentAction.SetObjectActionID( T"DeviceAction.OverloadClassHack" );
		currentAction.SetInactiveWithReason( IsON(), "LocKey#7005" );
		outActions.PushBack( currentAction );
		FinalizeGetQuickHackActions( outActions, context );
	}

	protected override function PushInactiveInteractionChoice( const context : ref< GetActionsContext >, choices : ref< array< InteractionChoice > > )
	{
		var baseAction : ActivateC4;
		var inactiveChoice : InteractionChoice;
		baseAction = ActionActivate();
		inactiveChoice.choiceMetaData.tweakDBName = baseAction.GetTweakDBChoiceRecord();
		inactiveChoice.caption = "DEBUG: Reason Unhandled";
		ChoiceTypeWrapper.SetType( inactiveChoice.choiceMetaData.type, gameinteractionsChoiceType.Inactive );
		if( IsOFF() )
		{
			inactiveChoice.caption = "[NEED C4]";
			choices.PushBack( inactiveChoice );
			return;
		}
	}

	public function OnActivateC4( evt : ActivateC4 ) : EntityNotificationType
	{
		var executor : weak< GameObject >;
		executor = evt.GetExecutor();
		if( executor )
		{
			GameInstance.GetTransactionSystem( GetGameInstance() ).RemoveItem( executor, GetInventoryItemID(), 1 );
		}
		UseNotifier( evt );
		SetDeviceState( EDeviceStatus.ON );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function OnDeactivateC4( evt : DeactivateC4 ) : EntityNotificationType
	{
		var executor : weak< GameObject >;
		executor = evt.GetExecutor();
		if( executor )
		{
			GameInstance.GetTransactionSystem( GetGameInstance() ).GiveItem( executor, GetInventoryItemID(), 1 );
		}
		UseNotifier( evt );
		SetDeviceState( EDeviceStatus.OFF );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public function OnDetonateC4( evt : DetonateC4 ) : EntityNotificationType
	{
		SetDeviceState( EDeviceStatus.DISABLED );
		return EntityNotificationType.SendThisEventToEntity;
	}

	public const function GetItemTweakDBString() : CName
	{
		return m_itemTweakDBString;
	}

	public const function GetInventoryItemID() : ItemID
	{
		return ItemID.FromTDBID( TDBID.Create( "Items." + ( ( String )( m_itemTweakDBString ) ) ) );
	}

	protected override function GetDeviceIconTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.ExplosionDeviceIcon";
	}

	protected override function GetBackgroundTextureTweakDBID() : TweakDBID
	{
		return T"DeviceIcons.ExplosionDeviceBackground";
	}

}

class ActivateC4 extends ActionBool
{
	var itemID : ItemID;

	public function SetProperties()
	{
		actionName = 'ActivateC4';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, true, 'LocKey#562', 'LocKey#562' );
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		if( TDBID.IsValid( m_objectActionID ) )
		{
			return super.GetTweakDBChoiceRecord();
		}
		else
		{
			return "PlaceC4";
		}
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsOFF() )
		{
			return true;
		}
		return false;
	}

}

class DeactivateC4 extends ActionBool
{
	var itemID : ItemID;

	public function SetProperties()
	{
		actionName = 'DeactivateC4';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, true, 'LocKey#563', 'LocKey#563' );
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		return "DeactivateC4";
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsON() )
		{
			return true;
		}
		return false;
	}

}

class DetonateC4 extends ActionBool
{
	var itemID : ItemID;

	public function SetProperties()
	{
		actionName = 'DetonateC4';
		prop = DeviceActionPropertyFunctions.SetUpProperty_Bool( actionName, true, 'LocKey#564', 'LocKey#564' );
	}

	public override function GetTweakDBChoiceRecord() : String
	{
		if( TDBID.IsValid( m_objectActionID ) )
		{
			return super.GetTweakDBChoiceRecord();
		}
		else
		{
			return "DetonateC4";
		}
	}

	public static function IsDefaultConditionMet( device : ScriptableDeviceComponentPS, const context : ref< GetActionsContext > ) : Bool
	{
		if( IsAvailable( device ) )
		{
			return true;
		}
		return false;
	}

	public static function IsAvailable( device : ScriptableDeviceComponentPS ) : Bool
	{
		if( device.IsON() )
		{
			return true;
		}
		return false;
	}

}

