struct IceMachineSFX extends VendingMachineSFX
{
	[ customEditor = "AudioEvent" ]
	instanceeditable var m_iceFalls : CName;
	default m_iceFalls = 'dev_ice_machine_ice_cube_falls';
	[ customEditor = "AudioEvent" ]
	instanceeditable var m_processing : CName;
	default m_processing = 'dev_vending_machine_processing';
}

class IceMachineController extends VendingMachineController
{

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

}

class IceMachineControllerPS extends VendingMachineControllerPS
{
	default m_deviceName = "LocKey#1637";
	default m_tweakDBRecord = T"Devices.IceMachine";
	default m_tweakDBDescriptionRecord = T"device_descriptions.IceMachine";
	private var m_vendorTweakID : TweakDBID;
	private instanceeditable var m_iceMachineSFX : IceMachineSFX;

	protected event OnInstantiated()
	{
		super.OnInstantiated();
		if( !( IsStringValid( m_deviceName ) ) )
		{
			m_deviceName = "Gameplay-Devices-DisplayNames-IceMachine";
		}
		m_vendorTweakID = T"Vendors.IceMachine";
	}

	public function GetVendorTweakID() : TweakDBID
	{
		return m_vendorTweakID;
	}

	public function GetProcessingSFX() : CName
	{
		return m_iceMachineSFX.m_processing;
	}

	public override function GetGlitchStartSFX() : CName
	{
		return m_iceMachineSFX.m_glitchingStart;
	}

	public override function GetGlitchStopSFX() : CName
	{
		return m_iceMachineSFX.m_glitchingStop;
	}

	public function GetIceFallSFX() : CName
	{
		return m_iceMachineSFX.m_iceFalls;
	}

	public override function GetTimeToCompletePurchase() : Float
	{
		return 2.5;
	}

	public override function GetHackedItemCount() : Int32
	{
		return 25;
	}

	protected override function PushShopStockActions( actions : ref< array< DeviceAction > >, const context : ref< GetActionsContext > )
	{
		var shopStock : array< SItemStack >;
		if( DispenceItemFromVendor.IsDefaultConditionMet( this, context ) && m_isReady )
		{
			shopStock = MarketSystem.GetVendorItemsForSale( ( ( GameObject )( GetOwnerEntityWeak() ) ), false );
			if( shopStock.Size() > 0 )
			{
				actions.PushBack( ActionDispenceIceCube( shopStock[ 0 ].itemID ) );
			}
		}
	}

	protected function ActionDispenceIceCube( item : ItemID ) : DispenceItemFromVendor
	{
		var action : DispenceItemFromVendor;
		var price : Int32;
		action = new DispenceItemFromVendor;
		price = MarketSystem.GetBuyPrice( GetGameInstance(), GetMyEntityID(), item );
		action.clearanceLevel = DefaultActionsParametersHolder.GetInteractiveClearance();
		action.SetUp( this );
		action.SetProperties( item, price );
		action.AddDeviceName( m_deviceName );
		action.SetDurationValue( GetTimeToCompletePurchase() );
		action.CreateActionWidgetPackage();
		return action;
	}

	public override function OnDispenceItemFromVendor( evt : DispenceItemFromVendor ) : EntityNotificationType
	{
		var transactionSys : TransactionSystem;
		transactionSys = GameInstance.GetTransactionSystem( GetGameInstance() );
		if( evt.IsStarted() )
		{
			ExecutePSActionWithDelay( evt, this, evt.GetDurationValue() );
		}
		else
		{
			if( evt.CanPay( GetPlayer( GetGameInstance() ) ) )
			{
				m_isReady = false;
				transactionSys.RemoveItem( GetPlayer( GetGameInstance() ), MarketSystem.Money(), evt.GetPrice() );
				UseNotifier( evt );
			}
			else
			{
				return EntityNotificationType.DoNotNotifyEntity;
			}
		}
		return EntityNotificationType.SendThisEventToEntity;
	}

}

