abstract class ItemActionsHelper
{

	public static function ConsumeItem( executor : weak< GameObject >, itemID : ItemID, fromInventory : Bool )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetConsumeAction( itemID ).GetID(), fromInventory );
	}

	public static function EatItem( executor : weak< GameObject >, itemID : ItemID, fromInventory : Bool )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetEatAction( itemID ).GetID(), fromInventory );
	}

	public static function DrinkItem( executor : weak< GameObject >, itemID : ItemID, fromInventory : Bool )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetDrinkAction( itemID ).GetID(), fromInventory );
	}

	public static function LearnItem( executor : weak< GameObject >, itemID : ItemID, fromInventory : Bool )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetLearnAction( itemID ).GetID(), fromInventory );
	}

	public static function DropItem( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetDropAction( itemID ).GetID(), true );
	}

	public static function DisassembleItem( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetDisassembleAction( itemID ).GetID(), true );
	}

	public static function DisassembleItem( executor : weak< GameObject >, itemID : ItemID, quantity : Int32 )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetDisassembleAction( itemID ).GetID(), true, quantity );
	}

	public static function ReadItem( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetReadAction( itemID ).GetID(), true );
	}

	public static function CrackItem( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetCrackAction( itemID ).GetID(), true );
	}

	public static function DownloadFunds( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetDownloadFunds( itemID ).GetID(), true );
	}

	public static function UseItem( executor : weak< GameObject >, itemID : ItemID ) : Bool
	{
		var actions : array< weak< ObjectAction_Record > >;
		var i : Int32;
		var actionUsed : Bool;
		actions = ItemActionsHelper.GetItemCustonActions( itemID );
		actionUsed = false;
		for( i = 0; i < actions.Size(); i += 1 )
		{
			actionUsed = ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), actions[ i ].GetID(), true ) || actionUsed;
		}
		return actionUsed;
	}

	public static function UseHealCharge( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetUseHealChargeAction( itemID ).GetID(), true );
	}

	public static function EquipItem( executor : weak< GameObject >, itemID : ItemID )
	{
		ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), ItemActionsHelper.GetEquipAction( itemID ).GetID(), true );
	}

	public static function PerformItemAction( executor : weak< GameObject >, itemID : ItemID )
	{
		var record : weak< ObjectAction_Record >;
		record = GetItemCustomAction( itemID );
		if( record )
		{
			ItemActionsHelper.ProcessItemAction( executor.GetGame(), executor, RPGManager.GetItemData( executor.GetGame(), executor, itemID ), record.GetID(), true );
		}
	}

	public static function GetConsumeAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Consume' );
	}

	public static function GetEatAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Eat' );
	}

	public static function GetDrinkAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Drink' );
	}

	public static function GetLearnAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Learn' );
	}

	public static function GetDownloadFunds( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'DownloadFunds' );
	}

	public static function GetReadAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Read' );
	}

	public static function GetDisassembleAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Disassemble' );
	}

	public static function GetDropAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Drop' );
	}

	public static function GetUseAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Use' );
	}

	public static function GetUseHealChargeAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'UseHealCharge' );
	}

	public static function GetCrackAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Crack' );
	}

	public static function GetEquipAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		return ItemActionsHelper.GetItemActionByType( itemID, 'Equip' );
	}

	public static function GetItemCustomAction( itemID : ItemID ) : weak< ObjectAction_Record >
	{
		var i : Int32;
		var emptyAction : weak< ObjectAction_Record >;
		var actions : array< weak< ObjectAction_Record > >;
		TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).ObjectActions( actions );
		for( i = 0; i < actions.Size(); i += 1 )
		{
			if( actions[ i ].ActionName() != 'Drop' && actions[ i ].ActionName() != 'Disassemble' )
			{
				return actions[ i ];
			}
		}
		return emptyAction;
	}

	public static function GetItemCustonActions( itemID : ItemID ) : array< weak< ObjectAction_Record > >
	{
		var i : Int32;
		var actions : array< weak< ObjectAction_Record > >;
		var returnActions : array< weak< ObjectAction_Record > >;
		TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).ObjectActions( actions );
		for( i = 0; i < actions.Size(); i += 1 )
		{
			if( actions[ i ].ActionName() != 'Drop' && actions[ i ].ActionName() != 'Disassemble' )
			{
				returnActions.PushBack( actions[ i ] );
			}
		}
		return returnActions;
	}

	public static function GetItemActionByType( itemID : ItemID, type : CName ) : weak< ObjectAction_Record >
	{
		var i : Int32;
		var emptyAction : weak< ObjectAction_Record >;
		var actions : array< weak< ObjectAction_Record > >;
		TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).ObjectActions( actions );
		actions.PushBack( TweakDBInterface.GetItemRecord( ItemID.GetTDBID( itemID ) ).ItemSecondaryAction() );
		for( i = 0; i < actions.Size(); i += 1 )
		{
			if( actions[ i ].ActionName() == type )
			{
				return actions[ i ];
			}
		}
		return emptyAction;
	}

	public static function ProcessItemAction( gi : GameInstance, executor : weak< GameObject >, itemData : weak< gameItemData >, actionID : TweakDBID, fromInventory : Bool ) : Bool
	{
		var action : BaseItemAction;
		var actionUsed : Bool;
		actionUsed = false;
		action = ItemActionsHelper.SetupItemAction( gi, executor, itemData, actionID, fromInventory );
		if( action.IsPossible( executor, TweakDBInterface.GetObjectActionRecord( actionID ) ) )
		{
			action.ProcessRPGAction( gi );
			actionUsed = true;
		}
		return actionUsed;
	}

	public static function ProcessItemAction( gi : GameInstance, executor : weak< GameObject >, itemData : weak< gameItemData >, actionID : TweakDBID, fromInventory : Bool, quantity : Int32 ) : Bool
	{
		var action : BaseItemAction;
		var actionUsed : Bool;
		actionUsed = false;
		action = ItemActionsHelper.SetupItemAction( gi, executor, itemData, actionID, fromInventory );
		action.SetRequestQuantity( quantity );
		if( action.IsPossible( executor, TweakDBInterface.GetObjectActionRecord( actionID ) ) )
		{
			action.ProcessRPGAction( gi );
			actionUsed = true;
		}
		return actionUsed;
	}

	public static function SetupItemAction( gi : GameInstance, executor : weak< GameObject >, itemData : weak< gameItemData >, actionID : TweakDBID, fromInventory : Bool ) : BaseItemAction
	{
		var action : BaseItemAction;
		var actionType : CName;
		actionType = TweakDBInterface.GetObjectActionRecord( actionID ).ActionName();
		switch( actionType )
		{
			case 'Use':
				action = new UseAction;
			break;
			case 'Drink':
			case 'Eat':
			case 'Consume':
				action = new ConsumeAction;
			break;
			case 'Learn':
				action = new LearnAction;
			break;
			case 'Disassemble':
				action = new DisassembleAction;
			break;
			case 'Drop':
				action = new DropAction;
			break;
			case 'Read':
				action = new ReadAction;
			break;
			case 'Crack':
				action = new CrackAction;
			break;
			case 'EquipItem':
				action = new EquipAction;
			break;
			case 'DownloadFunds':
				action = new DownloadFundsAction;
			break;
			case 'UseHealCharge':
				action = new UseHealChargeAction;
			break;
			case 'UseSandevistan':
				action = new UseSandevistanAction;
			break;
			case 'DisableSandevistan':
				action = new DisableSandevistanAction;
			break;
			case 'UseCorruptedSandevistan':
				action = new UseCorruptedSandevistanAction;
			break;
			case 'DisableCorruptedSandevistan':
				action = new DisableCorruptedSandevistanAction;
			break;
			case 'UseBerserk':
				action = new UseBerserkAction;
			break;
			case 'DisableBerserk':
				action = new DisableBerserkAction;
			break;
			default:
				return NULL;
		}
		action.SetItemData( itemData );
		action.RegisterAsRequester( StatsObjectID.ExtractEntityID( itemData.GetStatsObjectID() ) );
		action.SetExecutor( executor );
		action.SetObjectActionID( actionID );
		if( fromInventory )
		{
			action.SetRemoveAfterUse();
		}
		return action;
	}

}

