# ConsumableHandlers ConsumableHandlers are responsible for handle all kinds of consumables in WaspLib. For a list of the consumable types check `ERSConsumable`, there's a TConsumableHandler for each one. - - - ## type TConsumableHandler ```pascal TConsumableHandler = record(TSRLBaseRecord) ConsumableType: ERSConsumable; ConsumableArray: TRSConsumableArray; Amount, MinInvPoints: Int32; Timer, Delay: TCountDown; IsSetup: Boolean; end; ``` Consumable handler is the record responsible to handle `TRSConsumables `_. 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: TRSItem): TRSConsumable; procedure TConsumableHandler.Setup(consumableType: ERSConsumable); overload; ``` Used internally to add a TRSConumable 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 `TRSConsumables`. Example: ```pascal FoodHandler.Setup('Shark'); FoodHandler.Setup(ERSConsumable.FOOD); ``` - - - ## ConsumableHandler.FindInBank() ```pascal function TConsumableHandler.FindInBank(): TRSConsumableArray; ``` Returns an TRSConsumableArray of all TRSConsumables of **TConsumableHandler.consumableType** found in the bank window. - - - ## ConsumableHandler.FindInInventory() ```pascal function TConsumableHandler.FindInInventory(): TRSConsumableArray; ``` Returns an TRSConsumableArray of all TRSConsumables 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; VenomHandler: TConsumableHandler; AntifireHandler: TConsumableHandler; BoostHandler: TConsumableHandler; StrengthBoostHandler: TConsumableHandler; AttackBoostHandler: TConsumableHandler; DefenceBoostHandler: TConsumableHandler; RangingBoostHandler: TConsumableHandler; MagicBoostHandler: TConsumableHandler; CONSUMABLE_HANDLER_ARRAY: array [ERSConsumable] of PConsumableHandler := [ @FoodHandler, @PrayerHandler, @EnergyHandler, @PoisonHandler, @VenomHandler, @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: ERSConsumable): PConsumableHandler; static; ``` Static method to return a pointer to the right handler for each consumableType passed in. - - - ## Inventory.FindItems() ```pascal function TRSInventory.FindItems(Items: TRSConsumableArray; out FoundItems: TRSConsumableArray; 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 TRSInventory.FindConsumable(consumableType: ERSConsumable; out FoundConsumables: TRSConsumableArray; out Slots: TIntegerArray): Boolean; function TRSInventory.FindConsumable(consumableType: ERSConsumable): 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 TRSInventory.Consume(consumableType: ERSConsumable; out Slots: TIntegerArray): Boolean; function TRSInventory.Consume(consumableType: ERSConsumable): Boolean; overload; ``` Methods used to consume consumables. Example: ```pascal Inventory.Consume(ERSConsumable.FOOD); ``` - - - ## Inventory.CountConsumable() ```pascal function TRSInventory.CountConsumable(consumableType: ERSConsumable): Int32; ``` Method used to count each slot that has a consumable of **consumableType**. Example: ```pascal WriteLn Inventory.CountConsumable(ERSConsumable.FOOD); ``` - - - ## Inventory.CountEachConsumable() ```pascal function TRSInventory.CountEachConsumable(consumableType: ERSConsumable): TIntegerArray; ``` Method used to count each type of consumable of **consumableType**. Example: ```pascal WriteLn Inventory.CountEachConsumable(ERSConsumable.FOOD); ``` - - - ## Inventory.CountPoints() ```pascal function TRSInventory.CountPoints(Consumable: TRSConsumable): Int32; function TRSInventory.CountPoints(consumableType: ERSConsumable): Int32; overload; ``` Method used to count the total points value of a **Consumable** or **consumableType**. Example: ```pascal WriteLn Inventory.CountPoints(ERSConsumable.FOOD); //Assumind you have 3 sharks in your inventory, 60 will be printed. ``` - - - ## Inventory.HasEnoughConsumable() ```pascal function TRSInventory.HasEnoughConsumable(consumableType: ERSConsumable): Boolean; ``` Method used to figure out if we are low on a type of consumable. Example: ```pascal if not Inventory.HasEnoughConsumable(ERSConsumable.FOOD) then Bank.WithdrawItem(['Shark', 5, False], False); ``` - - - ## Bank.FindConsumable() ```pascal function TRSBank.FindConsumable(ConsumableArray: TRSConsumableArray; out Consumable: TRSConsumable): Boolean; function TRSBank.FindConsumable(ConsumableArray: TRSConsumableArray): Boolean; overload; function TRSBank.FindConsumable(consumableType: ERSConsumable; out Consumable: TRSConsumable): Boolean; overload; function TRSBank.FindConsumable(consumableType: ERSConsumable): 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(ERSConsumable.FOOD); ``` - - - ## Bank.CountPoints() ```pascal function TRSBank.CountPoints(Consumable: TRSConsumable): 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 TRSBank.WithdrawConsumableAmount(consumableType: ERSConsumable): Int32; function TRSBank.WithdrawConsumableAmount(consumableType: ERSConsumable; consumable: TRSConsumable): Int32; overload; ``` Method used to return the amount we need to withdraw to meet the TRSConsumable.MinInvPoints. - - - ## Bank.WithdrawConsumable() ```pascal function TRSBank.WithdrawConsumable(consumableType: ERSConsumable): Boolean; ``` Method used to withdraw a consumable type. Example: ```pascal FoodHandler.MinInvPoints := 100; Bank.WithdrawConsumable(ERSConsumable.FOOD); //This will withdraw FOODs until we have 100 points value of food in our inventory. ```