Magic

Group
player
Methods
16
Fields
None

Getting one

player:magic()

Methods

MethodReturnsDescription
runePouch()RunePouchThe rune pouch.
activeSpellbook()Spellbook?The active spellbook.
autocastSpell()SpellInfo?The spell currently set to autocast.
spellInfo(string)SpellInfoA spell's static facts: level, runes, requirements.
canCast(string)boolean?Whether every requirement is met: spellbook, level, runes, items.
castability(string, { number }?)CastabilityEvery requirement and whether it is met, rather than one boolean.
runeCount(Rune)numberHow many of a rune are carried, counting the rune pouch as well as the inventory.
cast(string)booleanCast a direct spell, one with no target, when it can be cast.
select(string, { number }?)booleanSelect a spell, ready for a following inventory:target(itemId). The castOn* members do both halves.
castOnNpc(string, NPC, { number }?)booleanSelect a spell and cast it on an NPC, the two together in one tick.
castOnObject(string, TileObject, { number }?)booleanSelect a spell and cast it on a scene object, the two together in one tick.
castOnPlayer(string, Player, { number }?)booleanSelect a spell and cast it on a player, the two together in one tick. Nothing is selected for a spell that cannot be cast on a player.
castOnGroundItem(string, TileItem, { number }?)booleanSelect a spell and cast it on a ground item (Telekinetic Grab), that stack only, the two together in one tick. Nothing is selected for a sp…
castOnItem(string, Item | ItemHandle | number, { number }?)booleanSelect a spell and cast it on an inventory item, the two together in one tick.
setAutocast(string, boolean?)(RunStatus, string?)One step towards autocasting a spell: opens the autocast chooser, then picks the spell. Call it each tick until it stops answering `"runnin…
clearAutocast()(RunStatus, string?)One step towards no autocast, by picking a combat style. Call it each tick until it stops answering "running".

Returned by

MethodReturnsDescription
PlayerDomain.magicMagicSpellbook, runes, castability, and casting.

Method details

autocastSpell

autocastSpell: (Magic) -> SpellInfo?

The spell currently set to autocast.

Returns
nil when autocast is off, or the game's autocast id is not a spell Bento knows.

spellInfo

spellInfo: (Magic, string) -> SpellInfo

A spell's static facts: level, runes, requirements.

spell
Spell name.

canCast

canCast: (Magic, string) -> boolean?

Whether every requirement is met: spellbook, level, runes, items.

spell
Spell name.
Returns
nil when a requirement could not be read: no scene yet, not logged in.

castability

castability: (Magic, string, { number }?) -> Castability

Every requirement and whether it is met, rather than one boolean.

assumedEquipped is for an equip and a cast queued together, where the gear that satisfies the spell is not on yet; its canCast field is the answer.

spell
Spell name.
assumedEquipped
Item ids to treat as worn. Omit to check what is actually worn.

runeCount

runeCount: (Magic, Rune) -> number

How many of a rune are carried, counting the rune pouch as well as the inventory.

rune
Which rune, e.g. Rune.AIR.

cast

cast: (Magic, string) -> boolean

Cast a direct spell, one with no target, when it can be cast.

spell
A Spells constant or a spell name.

select

select: (Magic, string, { number }?) -> boolean

Select a spell, ready for a following inventory:target(itemId). The castOn* members do both halves.

spell
A Spells constant or a spell name.
assumedEquipped
Item ids to treat as worn for the requirement check.
Returns
false when it takes no target or its requirements are not met.

castOnNpc

castOnNpc: (Magic, string, NPC, { number }?) -> boolean

Select a spell and cast it on an NPC, the two together in one tick.

spell
A Spells constant or a spell name.
npc
An NPC (the top level or the boat the player stands in; false for one outside the top level and the boat the player stands in, one that is gone, or once another NPC has taken its index).
assumedEquipped
Item ids to treat as worn for the requirement check -- ask whether the cast would work once a swap lands, before swapping. Omit to check what is actually equipped.

castOnObject

castOnObject: (Magic, string, TileObject, { number }?) -> boolean

Select a spell and cast it on a scene object, the two together in one tick.

spell
A Spells constant or a spell name.
object
A TileObject (the top level on the player's plane, or the deck of the boat the player stands in; false for one outside the top level and the boat the player stands in, removed, of a reloaded scene, or under a bridge).
assumedEquipped
Item ids to treat as worn for the requirement check -- ask whether the cast would work once a swap lands, before swapping. Omit to check what is actually equipped.

castOnPlayer

castOnPlayer: (Magic, string, Player, { number }?) -> boolean

Select a spell and cast it on a player, the two together in one tick. Nothing is selected for a spell that cannot be cast on a player.

spell
A Spells constant or a spell name.
player
A Player (top-level world view).
assumedEquipped
Item ids to treat as worn for the requirement check.

castOnGroundItem

castOnGroundItem: (Magic, string, TileItem, { number }?) -> boolean

Select a spell and cast it on a ground item (Telekinetic Grab), that stack only, the two together in one tick. Nothing is selected for a spell that cannot be cast on a ground item.

spell
A Spells constant or a spell name.
item
A TileItem (the top level or the boat the player stands in).
assumedEquipped
Item ids to treat as worn for the requirement check.

castOnItem

castOnItem: (Magic, string, Item | ItemHandle | number, { number }?) -> boolean

Select a spell and cast it on an inventory item, the two together in one tick.

spell
A Spells constant or a spell name.
item
An Item (its slot when it carries one, else the first slot holding its id), an item id, or an item handle from a container query.
assumedEquipped
Item ids to treat as worn for the requirement check -- ask whether the cast would work once a swap lands, before swapping. Omit to check what is actually equipped.

setAutocast

setAutocast: (Magic, string, boolean?) -> (RunStatus, string?)

One step towards autocasting a spell: opens the autocast chooser, then picks the spell. Call it each tick until it stops answering "running".

local status, why = player:magic():setAutocast(Spells.FIRE_SURGE)
if status == "blocked" then log:warn(why) end
spell
A Spells constant or a spell name.
defensive
true for defensive autocast.
Returns
"done" when it is set that way, "running" when a step was queued, and "blocked" with the reason when it cannot be set (a spell that cannot be autocast, a spellbook or staff that does not offer it).

clearAutocast

clearAutocast: (Magic) -> (RunStatus, string?)

One step towards no autocast, by picking a combat style. Call it each tick until it stops answering "running".

Returns
"done" when autocast is off, "running" when a step was queued, and "blocked" with the reason when it could not be queued.