enum ETrapEffects
{
	Explosion = 0,
	Poisoned = 1,
	Bleeding = 2,
	Burning = 3,
	Blind = 4,
	SmokeScreen = 5,
	Stun = 6,
	Unconcious = 7,
}

struct VentilationAreaSetup
{
	instanceeditable var m_areaEffect : ETrapEffects;
	default m_areaEffect = ETrapEffects.Explosion;
	instanceeditable var m_actionName : CName;
	default m_actionName = 'Activate';
}

class VentilationAreaController extends MasterController
{

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

}

class VentilationAreaControllerPS extends MasterControllerPS
{
	default m_deviceName = "VentilationArea";
	default m_tweakDBRecord = T"Devices.VentilationArea";
	default m_tweakDBDescriptionRecord = T"device_descriptions.VentilationArea";
	default m_revealDevicesGrid = true;
	default m_drawGridLink = false;
	private instanceeditable persistent var m_ventilationAreaSetup : VentilationAreaSetup;
	private var isActive : Bool;

	public function GetActionName() : CName
	{
		return m_ventilationAreaSetup.m_actionName;
	}

	public function GetAreaEffect() : ETrapEffects
	{
		return m_ventilationAreaSetup.m_areaEffect;
	}

	protected override function ActionActivateDevice() : ActivateDevice
	{
		var action : ActivateDevice;
		action = super.ActionActivateDevice();
		action.CreateActionWidgetPackage( T"DevicesUIDefinitions.VentilationSystemActionWidget" );
		return action;
	}

	public override function GetActions( out outActions : array< DeviceAction >, context : GetActionsContext ) : Bool
	{
		super.GetActions( outActions, context );
		if( !( isActive ) )
		{
			outActions.PushBack( ActionActivateDevice() );
		}
		SetActionIllegality( outActions, m_illegalActions.regularActions );
		return true;
	}

	protected override function OnActivateDevice( evt : ActivateDevice ) : EntityNotificationType
	{
		super.OnActivateDevice( evt );
		ActivateEffectors();
		return EntityNotificationType.SendThisEventToEntity;
	}

	private function ActivateEffectors()
	{
		var i : Int32;
		var action : ToggleEffect;
		var entityID : EntityID;
		var devices : array< DeviceComponentPS >;
		entityID = PersistentID.ExtractEntityID( GetID() );
		GameInstance.GetDeviceSystem( GetGameInstance() ).GetChildren( entityID, devices );
		for( i = 0; i < devices.Size(); i += 1 )
		{
			action = ( ( ToggleEffect )( ( ( ScriptableDeviceComponentPS )( devices[ i ] ) ).GetActionByName( 'ToggleEffect' ) ) );
			if( action )
			{
				GetPersistencySystem().QueuePSDeviceEvent( action );
			}
		}
	}

	public quest const function IsAreaActive() : Bool
	{
		return isActive;
	}

	protected override function GetInkWidgetTweakDBID( const context : ref< GetActionsContext > ) : TweakDBID
	{
		return T"DevicesUIDefinitions.VentilationSystemDeviceWidget";
	}

	public override function GetThumbnailWidget() : SThumbnailWidgetPackage
	{
		var widgetData : SThumbnailWidgetPackage;
		widgetData = super.GetThumbnailWidget();
		widgetData.widgetTweakDBID = T"DevicesUIDefinitions.VentilationSystemThumnbnailWidget";
		return widgetData;
	}

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

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

}

