Class Magic
Spells are defined in the shared spell table. For WIDGET_TARGET spells, the spell widget is selected first, then the target entity action is sent. For self-cast spells (CC_OP / no target), only a single event is needed.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumWhatautocastWidget(int, java.lang.String)did.static enumWhat happened to a cast's target click.static final classA cast's outcome plus, for REFUSED, the gate that held it (the outcome's gate) and, for UNREACHABLE, the name of the reason the action could not be reached.static enumThe magic tab as the client holds it. -
Method Summary
Modifier and TypeMethodDescriptionbooleanSelects the named spell for autocast.Current autocast selection, or null if the profile cannot observe it.autocastWidget(int widgetId, String label) Turns autocast back on with the spell whose spellbook widget iswidgetId(one the caller saw the server accept), for a spell PrivBot does not know by name.booleanCasts the spell whose in-game label matchesname(display name, enum constant, or colour-stripped menu target).booleancastOnInventoryItem(String name, int itemId, int slot) Castsname(e.g.booleanCasts a spell by in-game name on an NPC.booleancastOnObject(String name, PrivObject target) Casts a spell by in-game name on a scene object.booleancastOnPlayer(String name, PrivPlayer target) Castsnameontarget.castOnPlayerOutcome(String name, PrivPlayer target) Castsnameontargetand reports what happened to the target click.booleanisAutocasting(String name) Whether the exact named spell is selected for autocast.Opens the book without waiting: one TAB_SELECT on a readable closed book, nothing otherwise, and never a sleep.The magic tab's state, read in oneGameThread.ensure(java.util.function.Supplier<T>, T)(EDT-ordered on the EDT-marshal servers, so it sees a tab click queued before it).spellbookTab()for a caller that already owns the client-thread batch.
-
Method Details
-
autocastSpellWidgetId
Current autocast selection, or null if the profile cannot observe it. -
isAutocasting
Whether the exact named spell is selected for autocast. The client sets its selection on the click, before the server answers, so where the server's autocast flag can be read it must also read on (1); otherwise a spell the account cannot cast would read as selected. An unreadable flag answers false. -
autocast
Selects the named spell for autocast. The click is a toggle, so the selection is read again right before it goes out. True means already selected or sent; confirm withisAutocasting(java.lang.String)afterwards. An unknown state sends nothing. -
autocastWidget
Turns autocast back on with the spell whose spellbook widget iswidgetId(one the caller saw the server accept), for a spell PrivBot does not know by name. The magic tab is opened first (a readable open book is never clicked again), then the spell's Autocast click goes out.Only while the server's autocast flag reads 2 (off) or 0 (not sent this login): read before the tab is touched and again right before the click. Never while it reads 1 (on) or cannot be read: the server treats the click as a toggle on its own state, so a click on an autocast that is already on could turn it off. On a server where the flag cannot be read or the click cannot be sent, nothing is sent. The client's own selection is not read (it is set on the click even for a spell the server refuses, and not when the login restores autocast); callers confirm the outcome by the flag reading 1.
Only on a spell the open book draws: once the tab reads open, the click goes out only while the client reports the widget as drawn for
widgetId. A widget from another spellbook (a spell learned on another account, or before a book change) is not drawn: an Autocast on it is a click no real client makes, which the server refuses anyway. That answer isMagic.AutocastClick.NOT_IN_OPEN_BOOK, apart from every other refusal (Magic.AutocastClick.NOT_SENT, an unanswerable visibility included), so a caller can tell "this spell is not in the book" from "the click did not go out".- Parameters:
label- the menu target text for the click (the spell's name when known; may be blank)- Returns:
- what happened; only
Magic.AutocastClick.SENTdispatched (queued) the click
-
cast
Casts the spell whose in-game label matchesname(display name, enum constant, or colour-stripped menu target). If it is not in the spell table, clicks the live spellbook widget by that exact name.- Returns:
- true if a click was dispatched
-
castOnNpc
-
spellbookTab
The magic tab's state, read in oneGameThread.ensure(java.util.function.Supplier<T>, T)(EDT-ordered on the EDT-marshal servers, so it sees a tab click queued before it). UNKNOWN whenever anything is unreadable, and always under the legacy switch. -
spellbookTabInBatch
spellbookTab()for a caller that already owns the client-thread batch. -
openSpellbook
Opens the book without waiting: one TAB_SELECT on a readable closed book, nothing otherwise, and never a sleep. Returns the state read before the click. -
castOnPlayer
Castsnameontarget. True when the target click went out or was queued behind the select (Magic.CastResult.sent()). On Elorin this can now be false where it used to be true: a held or refused target click is no longer reported as a cast.castOnPlayerOutcome(java.lang.String, privbot.wrappers.PrivPlayer)says why. -
castOnPlayerOutcome
Castsnameontargetand reports what happened to the target click.On Elorin the target is resolved BEFORE the spell is selected, so a cast that could not be aimed sends nothing. Once the select is confirmed the target click always goes out, queued behind it. A worker waits at most
CAST_DISPATCH_WAIT_MSfor the outcome; on the EDT, the client thread or a timeout the answer isMagic.CastOutcome.POSTED_UNCONFIRMED.On other servers the answer is POSTED_UNCONFIRMED once the clicks are queued.
-
castOnObject
Casts a spell by in-game name on a scene object.- Parameters:
name- the spell's nametarget- the object- Returns:
- dispatch acceptance; false for a null target
-
castOnInventoryItem
Castsname(e.g. High Level Alchemy) on the inventory itemitemIdinslot: selects the spell, then clicks the item, the way the client's own spell-on-item click is sent (Elorin). Returns false with nothing sent on a server where PrivBot cannot send that click, including the servers that use RuneLite menu actions, which alch through the item-interaction helper.
-