class AIStatusEffectCondition extends AIbehaviorconditionScript
{

	protected final function GetShootingBlackboard( context : ScriptExecutionContext ) : IBlackboard
	{
		return GetPuppet( context ).GetAIControllerComponent().GetShootingBlackboard();
	}

}

class CheckCurrentStatusEffect extends AIStatusEffectCondition
{
	editable var m_statusEffectTypeToCompare : gamedataStatusEffectType;
	editable var m_statusEffectTagToCompare : CName;

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var topPriorityEffect : StatusEffect;
		var gameplayTags : array< CName >;
		topPriorityEffect = StatusEffectHelper.GetTopPriorityEffect( GetPuppet( context ) );
		if( topPriorityEffect && topPriorityEffect.GetRecord().StatusEffectType().Type() == m_statusEffectTypeToCompare )
		{
			if( m_statusEffectTagToCompare != '' )
			{
				gameplayTags = topPriorityEffect.GetRecord().GameplayTags();
				return gameplayTags.Contains( m_statusEffectTagToCompare );
			}
			else
			{
				return true;
			}
		}
		return false;
	}

}

class CheckStatusEffect extends AIStatusEffectCondition
{
	[ customEditor = "TweakDBGroupInheritance;StatusEffect" ]
	editable var m_statusEffectID : TweakDBID;

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), m_statusEffectID );
	}

}

class CheckAllStatusEffect extends AIStatusEffectCondition
{
	editable var m_behaviorArgumentNameTag : CName;
	editable var m_behaviorArgumentFloatPriority : CName;
	editable var m_behaviorArgumentNameFlag : CName;

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		var topPriorityEffect : StatusEffect;
		topPriorityEffect = StatusEffectHelper.GetTopPriorityEffect( ScriptExecutionContext.GetOwner( context ) );
		if( topPriorityEffect )
		{
			if( topPriorityEffect.GetRecord().AIData().Priority() > 0.0 )
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		else
		{
			return false;
		}
	}

	protected override function Activate( context : ScriptExecutionContext )
	{
		var flagName : CName;
		var topPriorityEffect : StatusEffect;
		topPriorityEffect = StatusEffectHelper.GetTopPriorityEffect( ScriptExecutionContext.GetOwner( context ) );
		flagName = StringToName( "AIGSF_" + EnumValueToString( "gamedataStatusEffectAIBehaviorFlag", ( ( Int32 )( topPriorityEffect.GetRecord().AIData().BehaviorEventFlag().Type() ) ) ) );
		ScriptExecutionContext.SetArgumentName( context, m_behaviorArgumentNameTag, EnumValueToName( 'gamedataStatusEffectType', ( ( Int32 )( topPriorityEffect.GetRecord().StatusEffectType().Type() ) ) ) );
		ScriptExecutionContext.SetArgumentFloat( context, m_behaviorArgumentFloatPriority, topPriorityEffect.GetRecord().AIData().Priority() );
		ScriptExecutionContext.SetArgumentName( context, m_behaviorArgumentNameFlag, flagName );
	}

}

class CheckStatusEffectState extends AIStatusEffectCondition
{
	editable var m_statusEffectType : gamedataStatusEffectType;
	editable var m_stateToCheck : EstatusEffectsState;
	default m_stateToCheck = EstatusEffectsState.Activating;
	var topPrioStatusEffect : StatusEffect;

	protected export override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		switch( m_stateToCheck )
		{
			case EstatusEffectsState.Deactivated:
				return !( StatusEffectSystem.ObjectHasStatusEffectOfType( GetPuppet( context ), m_statusEffectType ) );
			case EstatusEffectsState.Activating:
				topPrioStatusEffect = StatusEffectHelper.GetTopPriorityEffect( GetPuppet( context ), m_statusEffectType );
			return !( topPrioStatusEffect ) || ( ( GameInstance.GetSimTime( GetPuppet( context ).GetGame() ) - topPrioStatusEffect.GetInitialApplicationSimTimestamp() ) < 1.0 );
			case EstatusEffectsState.Activated:
				return StatusEffectSystem.ObjectHasStatusEffectOfType( GetPuppet( context ), m_statusEffectType );
			default:
				return AIbehaviorConditionOutcomes.Failure;
		}
	}

}

class CheckWoundedStatusEffectState extends AIStatusEffectCondition
{
	editable var m_stateToCheck : EstatusEffectsState;
	default m_stateToCheck = EstatusEffectsState.Activating;

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		switch( m_stateToCheck )
		{
			case EstatusEffectsState.Deactivated:
				return !( StatusEffectSystem.ObjectHasStatusEffectOfType( GetPuppet( context ), gamedataStatusEffectType.Wounded ) );
			case EstatusEffectsState.Activating:
				return ( GameInstance.GetSimTime( GetPuppet( context ).GetGame() ) - StatusEffectHelper.GetTopPriorityEffect( GetPuppet( context ), gamedataStatusEffectType.Wounded ).GetInitialApplicationSimTimestamp() ) < 10.0;
			default:
				return StatusEffectSystem.ObjectHasStatusEffectOfType( GetPuppet( context ), gamedataStatusEffectType.Wounded );
		}
	}

}

class CheckCurrentWoundedState extends AIStatusEffectCondition
{
	editable var m_woundedTypeToCompare : EWoundedBodyPart;

	protected override function Check( context : ScriptExecutionContext ) : AIbehaviorConditionOutcomes
	{
		switch( m_woundedTypeToCompare )
		{
			case EWoundedBodyPart.WoundedLeftArm:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledArmLeft" ) || StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledHandLeft" );
			case EWoundedBodyPart.WoundedRightArm:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledArmRight" ) || StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledHandRight" );
			case EWoundedBodyPart.WoundedLeftLeg:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledLegLeft" );
			case EWoundedBodyPart.WoundedRightLeg:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.CrippledLegRight" );
			case EWoundedBodyPart.DismemberedLeftArm:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedArmLeft" ) || StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedHandLeft" );
			case EWoundedBodyPart.DismemberedRightArm:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedArmRight" ) || StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedHandRight" );
			case EWoundedBodyPart.DismemberedLeftLeg:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedLegLeft" );
			case EWoundedBodyPart.DismemberedRightLeg:
				return StatusEffectSystem.ObjectHasStatusEffect( GetPuppet( context ), T"BaseStatusEffect.DismemberedLegRight" );
			case EWoundedBodyPart.DismemberedBothLegs:
				return false;
			default:
				return false;
		}
	}

}

