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

  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 <https://torwent.github.io/WaspLib/consumables.html>_. This will handle caching all found consumables to this point, bank withdraw amounts, timer if the last consumable had a timer, etc.


type PConsumableHandler

PConsumableHandler = ^TConsumableHandler;

Wrapper type of a TConsumableHandler pointer.


ConsumableHandler.Setup()

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:

FoodHandler.Setup('Shark');
FoodHandler.Setup(EConsumable.FOOD);

ConsumableHandler.FindInBank()

function TConsumableHandler.FindInBank(): TConsumableArray;

Returns an TConsumableArray of all TConsumables of TConsumableHandler.consumableType found in the bank window.


ConsumableHandler.FindInInventory()

function TConsumableHandler.FindInInventory(): TConsumableArray;

Returns an TConsumableArray of all TConsumables of TConsumableHandler.ConsumableType found in the inventory.


ConsumableHandler.NeedToConsume()

function TConsumableHandler.NeedToConsume(): Boolean;

Returns an True if there’s a timer setup and it has ran out.


var Handlers

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()

function TConsumableHandler.GetHandler(consumableType: EConsumable): PConsumableHandler; static;

Static method to return a pointer to the right handler for each consumableType passed in.


Inventory.FindItems()

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()

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

function TInventory.Consume(consumableType: EConsumable; out Slots: TIntegerArray): Boolean;
function TInventory.Consume(consumableType: EConsumable): Boolean; overload;

Methods used to consume consumables.

Example:

Inventory.Consume(EConsumable.FOOD);

Inventory.CountConsumable()

function TInventory.CountConsumable(consumableType: EConsumable): Int32;

Method used to count each slot that has a consumable of consumableType.

Example:

WriteLn Inventory.CountConsumable(EConsumable.FOOD);

Inventory.CountEachConsumable()

function TInventory.CountEachConsumable(consumableType: EConsumable): TIntegerArray;

Method used to count each type of consumable of consumableType.

Example:

WriteLn Inventory.CountEachConsumable(EConsumable.FOOD);

Inventory.CountPoints()

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:

WriteLn Inventory.CountPoints(EConsumable.FOOD); //Assumind you have 3 sharks in your inventory, 60 will be printed.

Inventory.HasEnoughConsumable()

function TInventory.HasEnoughConsumable(consumableType: EConsumable): Boolean;

Method used to figure out if we are low on a type of consumable.

Example:

if not Inventory.HasEnoughConsumable(EConsumable.FOOD) then
  Bank.WithdrawItem(['Shark', 5, False], False);

Bank.FindConsumable()

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:

WriteLn Bank.FindConsumable(EConsumable.FOOD);

Bank.CountPoints()

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()

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()

function TBank.WithdrawConsumable(consumableType: EConsumable): Boolean;

Method used to withdraw a consumable type.

Example:

FoodHandler.MinInvPoints := 100;
Bank.WithdrawConsumable(EConsumable.FOOD); //This will withdraw FOODs until we have 100 points value of food in our inventory.