# ConsumableHandlers ConsumableHandlers are responsible for handle all kinds of consumables in WaspLib. For a list of the consumable types check `EConsumable`, there's a TConsumableHandler for each one. - - - ## type TConsumableHandler ```pascal TConsumableHandler = record(TSRLBaseRecord) ConsumableType: EConsumable; ConsumableArray: TConsumableArray; Amount, MinInvPoints: Int32; Timer, Delay: TCountDown; IsSetup: Boolean; end; ``` Consumable handler is the record responsible to handle `TConsumables `_. This will handle caching all found consumables to this point, bank withdraw amounts, timer if the last consumable had a timer, etc. - - - ## type PConsumableHandler ```pascal PConsumableHandler = ^TConsumableHandler; ``` Wrapper type of a TConsumableHandler pointer. - - - ## ConsumableHandler.Setup() ```pascal function TConsumableHandler.Setup(Item: TItem): TConsumable; procedure TConsumableHandler.Setup(consumableType: EConsumable); overload; ``` Used internally to add a TConumable to TConsumableHandler.ConsumableArray. The overloaded method is used to setup `TConsumableHandler.ConsumableArray` with a `TConsumableHandler.ConsumableType`. This will use TConsumableHandler.FindInInventory() or TConsumableHandler.FindInBank() by that order to setup found `TConsumables`. Example: ```pascal FoodHandler.Setup('Shark'); FoodHandler.Setup(EConsumable.FOOD); ``` - - - ## ConsumableHandler.FindInBank() ```pascal function TConsumableHandler.FindInBank(): TConsumableArray; ``` Returns an TConsumableArray of all TConsumables of **TConsumableHandler.consumableType** found in the bank window. - - - ## ConsumableHandler.FindInInventory() ```pascal function TConsumableHandler.FindInInventory(): TConsumableArray; ``` Returns an TConsumableArray of all TConsumables of **TConsumableHandler.ConsumableType** found in the inventory. - - - ## ConsumableHandler.NeedToConsume() ```pascal function TConsumableHandler.NeedToConsume(): Boolean; ``` Returns an **True** if there's a timer setup and it has ran out. - - - ## var Handlers ```pascal FoodHandler: TConsumableHandler; PrayerHandler: TConsumableHandler; EnergyHandler: TConsumableHandler; PoisonHandler: TConsumableHandler; AntifireHandler: TConsumableHandler; BoostHandler: TConsumableHandler; StrengthBoostHandler: TConsumableHandler; AttackBoostHandler: TConsumableHandler; DefenceBoostHandler: TConsumableHandler; RangingBoostHandler: TConsumableHandler; MagicBoostHandler: TConsumableHandler; CONSUMABLE_HANDLER_ARRAY: array [EConsumable] of PConsumableHandler := [ @FoodHandler, @PrayerHandler, @EnergyHandler, @PoisonHandler, @AntifireHandler, @BoostHandler, @StrengthBoostHandler, @AttackBoostHandler, @DefenceBoostHandler, @RangingBoostHandler, @MagicBoostHandler ]; ``` Global handler variables. This handlers are the ones responsible for handling consumables. - - - ## ConsumableHandler.GetHandler() ```pascal function TConsumableHandler.GetHandler(consumableType: EConsumable): PConsumableHandler; static; ``` Static method to return a pointer to the right handler for each consumableType passed in. - - - ## Inventory.FindItems() ```pascal function TInventory.FindItems(Items: TConsumableArray; out FoundItems: TConsumableArray; out Slots: TIntegerArray): Boolean; overload; ``` Method used to find consumables in the inventory. Can be used directly but in most cases is used internally. - - - ## Inventory.FindConsumable() ```pascal function TInventory.FindConsumable(consumableType: EConsumable; out FoundConsumables: TConsumableArray; out Slots: TIntegerArray): Boolean; function TInventory.FindConsumable(consumableType: EConsumable): Boolean; overload; ``` Method used to find already setup consumables in the inventory. Can be used directly but in most cases is used internally. - - - ## Inventory.Consume ```pascal function TInventory.Consume(consumableType: EConsumable; out Slots: TIntegerArray): Boolean; function TInventory.Consume(consumableType: EConsumable): Boolean; overload; ``` Methods used to consume consumables. Example: ```pascal Inventory.Consume(EConsumable.FOOD); ``` - - - ## Inventory.CountConsumable() ```pascal function TInventory.CountConsumable(consumableType: EConsumable): Int32; ``` Method used to count each slot that has a consumable of **consumableType**. Example: ```pascal WriteLn Inventory.CountConsumable(EConsumable.FOOD); ``` - - - ## Inventory.CountEachConsumable() ```pascal function TInventory.CountEachConsumable(consumableType: EConsumable): TIntegerArray; ``` Method used to count each type of consumable of **consumableType**. Example: ```pascal WriteLn Inventory.CountEachConsumable(EConsumable.FOOD); ``` - - - ## Inventory.CountPoints() ```pascal function TInventory.CountPoints(Consumable: TConsumable): Int32; function TInventory.CountPoints(consumableType: EConsumable): Int32; overload; ``` Method used to count the total points value of a **Consumable** or **consumableType**. Example: ```pascal WriteLn Inventory.CountPoints(EConsumable.FOOD); //Assumind you have 3 sharks in your inventory, 60 will be printed. ``` - - - ## Inventory.HasEnoughConsumable() ```pascal function TInventory.HasEnoughConsumable(consumableType: EConsumable): Boolean; ``` Method used to figure out if we are low on a type of consumable. Example: ```pascal if not Inventory.HasEnoughConsumable(EConsumable.FOOD) then Bank.WithdrawItem(['Shark', 5, False], False); ``` - - - ## Bank.FindConsumable() ```pascal function TBank.FindConsumable(ConsumableArray: TConsumableArray; out Consumable: TConsumable): Boolean; function TBank.FindConsumable(ConsumableArray: TConsumableArray): Boolean; overload; function TBank.FindConsumable(consumableType: EConsumable; out Consumable: TConsumable): Boolean; overload; function TBank.FindConsumable(consumableType: EConsumable): Boolean; overload; ``` Method used to find already setup consumables in the bank. Can be used directly but in most cases is used internally. Example: ```pascal WriteLn Bank.FindConsumable(EConsumable.FOOD); ``` - - - ## Bank.CountPoints() ```pascal function TBank.CountPoints(Consumable: TConsumable): Int32; ``` Method used to count the points of the first dose/portion of a consumable found in bank. This prioritizes higher dosage visible ones first and returns only just that one. - - - ## Bank.WithdrawConsumableAmount() ```pascal function TBank.WithdrawConsumableAmount(consumableType: EConsumable): Int32; function TBank.WithdrawConsumableAmount(consumableType: EConsumable; consumable: TConsumable): Int32; overload; ``` Method used to return the amount we need to withdraw to meet the TConsumable.MinInvPoints. - - - ## Bank.WithdrawConsumable() ```pascal function TBank.WithdrawConsumable(consumableType: EConsumable): Boolean; ``` Method used to withdraw a consumable type. Example: ```pascal FoodHandler.MinInvPoints := 100; Bank.WithdrawConsumable(EConsumable.FOOD); //This will withdraw FOODs until we have 100 points value of food in our inventory. ```