class AISetCombatPresetTask extends AIbehaviortaskScript
{
	editable inlined var m_inCommand : AIArgumentMapping;

	protected export override function Update( context : ScriptExecutionContext ) : AIbehaviorUpdateOutcome
	{
		var rawCommand : IScriptable;
		var typedCommand : AISetCombatPresetCommand;
		if( !( m_inCommand ) )
		{
			return AIbehaviorUpdateOutcome.FAILURE;
		}
		rawCommand = ScriptExecutionContext.GetScriptableMappingValue( context, m_inCommand );
		typedCommand = ( ( AISetCombatPresetCommand )( rawCommand ) );
		if( !( typedCommand ) )
		{
			return AIbehaviorUpdateOutcome.FAILURE;
		}
		if( !( RemovePresets( ScriptExecutionContext.GetOwner( context ) ) ) )
		{
			CancelCommand( context, typedCommand );
			return AIbehaviorUpdateOutcome.FAILURE;
		}
		switch( typedCommand.combatPreset )
		{
			case EAICombatPreset.IsReckless:
				RPGManager.ApplyAbility( ScriptExecutionContext.GetOwner( context ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsReckless" ) );
			break;
			case EAICombatPreset.IsAggressive:
				RPGManager.ApplyAbility( ScriptExecutionContext.GetOwner( context ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsAggressive" ) );
			break;
			case EAICombatPreset.IsBalanced:
				RPGManager.ApplyAbility( ScriptExecutionContext.GetOwner( context ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsBalanced" ) );
			break;
			case EAICombatPreset.IsDefensive:
				RPGManager.ApplyAbility( ScriptExecutionContext.GetOwner( context ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsDefensive" ) );
			break;
			case EAICombatPreset.IsCautious:
				RPGManager.ApplyAbility( ScriptExecutionContext.GetOwner( context ), TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsCautious" ) );
			break;
			default:
				break;
		}
		ScriptedPuppet.SendActionSignal( ( ( ScriptedPuppet )( ScriptExecutionContext.GetOwner( context ) ) ), 'InterruptCoverSelection', 0.5 );
		return AIbehaviorUpdateOutcome.SUCCESS;
	}

	protected final function RemovePresets( owner : weak< GameObject > ) : Bool
	{
		if( !( owner ) )
		{
			return false;
		}
		RPGManager.RemoveAbility( owner, TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsReckless" ) );
		RPGManager.RemoveAbility( owner, TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsAggressive" ) );
		RPGManager.RemoveAbility( owner, TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsBalanced" ) );
		RPGManager.RemoveAbility( owner, TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsDefensive" ) );
		RPGManager.RemoveAbility( owner, TweakDBInterface.GetGameplayAbilityRecord( T"Ability.IsCautious" ) );
		return true;
	}

	protected final function CancelCommand( context : ScriptExecutionContext, typedCommand : AISetCombatPresetCommand )
	{
		if( typedCommand && typedCommand.state == AICommandState.Executing )
		{
			GetPuppet( context ).GetAIControllerComponent().StopExecutingCommand( typedCommand, false );
		}
		ScriptExecutionContext.SetMappingValue( context, m_inCommand, NULL );
	}

}

