Package dev.twilite.game.common
Class InteractionScope
java.lang.Object
dev.twilite.game.common.InteractionScope
World-scoped interaction helpers for simple step-based plugin flows.
Each method performs one tick-friendly action: continue/select dialogue, walk toward a fallback coordinate, interact with a loaded target, use an item on a target, or pick up a ground item. Plugins should call these methods repeatedly until their state changes.
Usage:
Game.interactionScope().talkTo(
npcs -> npcs.id(NpcId.GOTR_CORDELIA).nearestTo(Constants.CELL_TABLE),
Constants.CELL_TABLE,
"repair my pouches",
"yes"
);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancastSpellOnItem(Spell spell, int target) Casts a spell on an inventory item.booleanCasts a spell on an NPC, walking tofallbackif the NPC is not available.booleancastSpellOnNpc(Spell spell, Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on an NPC with optional local reachability checks.booleancastSpellOnObject(Spell spell, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback) Casts a spell on an object, walking tofallbackif the object is not available.booleancastSpellOnObject(Spell spell, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on an object with optional local reachability checks.booleancastSpellOnPlayer(Spell spell, Function<PlayerView, Optional<Player>> query, Coord fallback) Casts a spell on a player, walking tofallbackif the player is not available.booleancastSpellOnPlayer(Spell spell, Function<PlayerView, Optional<Player>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on a player with optional local reachability checks.booleancastSpellOnTileItem(Spell spell, Function<TileItemView, Optional<TileItem>> query, Coord fallback) Casts a spell on a ground item, walking tofallbackif the item is not available.booleancastSpellOnTileItem(Spell spell, Function<TileItemView, Optional<TileItem>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on a ground item with optional local reachability checks.booleanInteracts with a dynamic child component by parent packed id and child index.booleanInteracts with a component by packed id.booleancomponent(int id, Function<ComponentView, Optional<IfComponent>> ccQuery, String op) Interacts with a dynamic child component selected from a parent component's child view.booleanInteracts with an NPC, walking tofallbackif the NPC is not available.booleanInteracts with an NPC using optional local reachability checks.booleannpc(Function<NpcView, Optional<Npc>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with an NPC using optional reachability checks and a custom walk distance.booleanobject(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op) Interacts with an object, walking tofallbackif the object is not available.booleanobject(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with an object using optional local reachability checks.booleanobject(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with an object using optional reachability checks and a custom walk distance.booleanPicks up the nearest matching ground item tofallback.booleanPicks up the nearest matching ground item with optional local reachability checks.booleanpickUp(int item, Function<TileItemView, Optional<TileItem>> query, Coord fallback, boolean skipReachableCheck) Picks up a ground item selected from this scope's tile-item view.booleanInteracts with a player, walking tofallbackif the player is not available.booleanplayer(Function<PlayerView, Optional<Player>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with a player using optional local reachability checks.booleanplayer(Function<PlayerView, Optional<Player>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with a player using optional reachability checks and a custom walk distance.booleanresumePause(int id) Enqueues a resume/pause-button action on a component by packed id.booleanresumePause(int id, int cc) Enqueues a resume/pause-button action on a dynamic child component.booleanresumePause(int id, Function<ComponentView, Optional<IfComponent>> ccQuery) Enqueues a resume/pause-button action on a dynamic child selected from a parent component's child view.booleantalkTo(Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck, String... dialog) Selects matching dialogue or talks to an NPC with optional local reachability checks.booleanSelects matching dialogue or talks to an NPC, walking tofallbackif the NPC is not available.booleanInteracts with a ground item, walking tofallbackif the item is not available.booleantileItem(Function<TileItemView, Optional<TileItem>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with a ground item using optional local reachability checks.booleantileItem(Function<TileItemView, Optional<TileItem>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with a ground item using optional reachability checks and a custom walk distance.booleanuseItemOnItem(int primary, int target) Uses one inventory item on another inventory item.booleanUses an inventory item on an NPC, walking tofallbackif the NPC is not available.booleanuseItemOnNpc(int item, Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on an NPC with optional local reachability checks.booleanuseItemOnObject(int item, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback) Uses an inventory item on an object, walking tofallbackif the object is not available.booleanuseItemOnObject(int item, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on an object with optional local reachability checks.booleanuseItemOnPlayer(int item, Function<PlayerView, Optional<Player>> query, Coord fallback) Uses an inventory item on a player, walking tofallbackif the player is not available.booleanuseItemOnPlayer(int item, Function<PlayerView, Optional<Player>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on a player with optional local reachability checks.
-
Constructor Details
-
InteractionScope
Creates a scope backed by a loaded world.- Parameters:
world- world to query for NPCs, scene objects, and tile items
-
-
Method Details
-
talkTo
Selects matching dialogue or talks to an NPC, walking tofallbackif the NPC is not available.- Parameters:
query- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awaydialog- dialogue option text fragments to select before talking- Returns:
trueif a dialogue, walk, or talk action was performed
-
talkTo
public boolean talkTo(Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck, String... dialog) Selects matching dialogue or talks to an NPC with optional local reachability checks.- Parameters:
query- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before interactingdialog- dialogue option text fragments to select before talking- Returns:
trueif a dialogue, walk, or talk action was performed
-
component
Interacts with a component by packed id.- Parameters:
id- packed interface component idop- component option to invoke- Returns:
trueif the component was found and interacted with
-
component
Interacts with a dynamic child component by parent packed id and child index.- Parameters:
id- packed parent interface component idcc- dynamic child indexop- component option to invoke- Returns:
trueif the child component was found and interacted with
-
component
Interacts with a dynamic child component selected from a parent component's child view.- Parameters:
id- packed parent interface component idccQuery- query selecting a child component from the parent's dynamic childrenop- component option to invoke- Returns:
trueif the child component was found and interacted with
-
resumePause
public boolean resumePause(int id) Enqueues a resume/pause-button action on a component by packed id.- Parameters:
id- packed interface component id- Returns:
trueif the component was found and the action was enqueued
-
resumePause
public boolean resumePause(int id, int cc) Enqueues a resume/pause-button action on a dynamic child component.- Parameters:
id- packed parent interface component idcc- dynamic child index- Returns:
trueif the child component was found and the action was enqueued
-
resumePause
Enqueues a resume/pause-button action on a dynamic child selected from a parent component's child view.- Parameters:
id- packed parent interface component idccQuery- query selecting a child component from the parent's dynamic children- Returns:
trueif the child component was found and the action was enqueued
-
object
public boolean object(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op) Interacts with an object, walking tofallbackif the object is not available.- Parameters:
query- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far awayop- object option to invoke- Returns:
trueif a walk or object interaction was performed
-
object
public boolean object(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with an object using optional local reachability checks.- Parameters:
query- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far awayop- object option to invokeskipReachableCheck- whether to skip loaded collision reachability before interacting- Returns:
trueif a walk or object interaction was performed
-
object
public boolean object(Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with an object using optional reachability checks and a custom walk distance.- Parameters:
query- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far awayop- object option to invokeskipReachableCheck- whether to skip loaded collision reachability before interactingdistance- maximum Chebyshev distance considered close enough- Returns:
trueif a walk or object interaction was performed
-
npc
Interacts with an NPC, walking tofallbackif the NPC is not available.- Parameters:
query- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayop- NPC option to invoke- Returns:
trueif a walk or NPC interaction was performed
-
npc
public boolean npc(Function<NpcView, Optional<Npc>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with an NPC using optional local reachability checks.- Parameters:
query- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayop- NPC option to invokeskipReachableCheck- whether to skip loaded collision reachability before interacting- Returns:
trueif a walk or NPC interaction was performed
-
npc
public boolean npc(Function<NpcView, Optional<Npc>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with an NPC using optional reachability checks and a custom walk distance.- Parameters:
query- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayop- NPC option to invokeskipReachableCheck- whether to skip loaded collision reachability before interactingdistance- maximum Chebyshev distance considered close enough- Returns:
trueif a walk or NPC interaction was performed
-
player
Interacts with a player, walking tofallbackif the player is not available.- Parameters:
query- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far awayop- player option to invoke- Returns:
trueif a walk or player interaction was performed
-
player
public boolean player(Function<PlayerView, Optional<Player>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with a player using optional local reachability checks.- Parameters:
query- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far awayop- player option to invokeskipReachableCheck- whether to skip loaded collision reachability before interacting- Returns:
trueif a walk or player interaction was performed
-
player
public boolean player(Function<PlayerView, Optional<Player>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with a player using optional reachability checks and a custom walk distance.- Parameters:
query- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far awayop- player option to invokeskipReachableCheck- whether to skip loaded collision reachability before interactingdistance- maximum Chebyshev distance considered close enough- Returns:
trueif a walk or player interaction was performed
-
tileItem
Interacts with a ground item, walking tofallbackif the item is not available.- Parameters:
query- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far awayop- ground item option to invoke- Returns:
trueif a walk or ground item interaction was performed
-
tileItem
public boolean tileItem(Function<TileItemView, Optional<TileItem>> query, Coord fallback, String op, boolean skipReachableCheck) Interacts with a ground item using optional local reachability checks.- Parameters:
query- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far awayop- ground item option to invokeskipReachableCheck- whether to skip loaded collision reachability before interacting- Returns:
trueif a walk or ground item interaction was performed
-
tileItem
public boolean tileItem(Function<TileItemView, Optional<TileItem>> query, Coord fallback, String op, boolean skipReachableCheck, int distance) Interacts with a ground item using optional reachability checks and a custom walk distance.- Parameters:
query- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far awayop- ground item option to invokeskipReachableCheck- whether to skip loaded collision reachability before interactingdistance- maximum Chebyshev distance considered close enough- Returns:
trueif a walk or ground item interaction was performed
-
useItemOnItem
public boolean useItemOnItem(int primary, int target) Uses one inventory item on another inventory item.- Parameters:
primary- item id to select firsttarget- item id to target after selectingprimary- Returns:
trueif both items were present and the use-on-item action was enqueued
-
useItemOnObject
public boolean useItemOnObject(int item, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback) Uses an inventory item on an object, walking tofallbackif the object is not available.- Parameters:
item- inventory item id to usequery- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far away- Returns:
trueif a walk or item-on-object action was performed
-
useItemOnObject
public boolean useItemOnObject(int item, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on an object with optional local reachability checks.- Parameters:
item- inventory item id to usequery- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before using the item- Returns:
trueif a walk or item-on-object action was performed
-
useItemOnNpc
Uses an inventory item on an NPC, walking tofallbackif the NPC is not available.- Parameters:
item- inventory item id to usequery- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far away- Returns:
trueif a walk or item-on-NPC action was performed
-
useItemOnNpc
public boolean useItemOnNpc(int item, Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on an NPC with optional local reachability checks.- Parameters:
item- inventory item id to usequery- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before using the item- Returns:
trueif a walk or item-on-NPC action was performed
-
useItemOnPlayer
public boolean useItemOnPlayer(int item, Function<PlayerView, Optional<Player>> query, Coord fallback) Uses an inventory item on a player, walking tofallbackif the player is not available.- Parameters:
item- inventory item id to usequery- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far away- Returns:
trueif a walk or item-on-player action was performed
-
useItemOnPlayer
public boolean useItemOnPlayer(int item, Function<PlayerView, Optional<Player>> query, Coord fallback, boolean skipReachableCheck) Uses an inventory item on a player with optional local reachability checks.- Parameters:
item- inventory item id to usequery- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before using the item- Returns:
trueif a walk or item-on-player action was performed
-
castSpellOnItem
Casts a spell on an inventory item.- Parameters:
spell- spell to casttarget- item id to target after selectingspell- Returns:
trueif the spell and item were present and the action was enqueued
-
castSpellOnObject
public boolean castSpellOnObject(Spell spell, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback) Casts a spell on an object, walking tofallbackif the object is not available.- Parameters:
spell- spell to castquery- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far away- Returns:
trueif a walk or spell-on-object action was performed
-
castSpellOnObject
public boolean castSpellOnObject(Spell spell, Function<SceneObjectView, Optional<SceneObject>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on an object with optional local reachability checks.- Parameters:
spell- spell to castquery- query selecting the object from this scope's object viewfallback- coordinate used when the object is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before casting- Returns:
trueif a walk or spell-on-object action was performed
-
castSpellOnNpc
Casts a spell on an NPC, walking tofallbackif the NPC is not available.- Parameters:
spell- spell to castquery- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far away- Returns:
trueif a walk or spell-on-NPC action was performed
-
castSpellOnNpc
public boolean castSpellOnNpc(Spell spell, Function<NpcView, Optional<Npc>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on an NPC with optional local reachability checks.- Parameters:
spell- spell to castquery- query selecting the NPC from this scope's NPC viewfallback- coordinate used when the NPC is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before casting- Returns:
trueif a walk or spell-on-NPC action was performed
-
castSpellOnPlayer
public boolean castSpellOnPlayer(Spell spell, Function<PlayerView, Optional<Player>> query, Coord fallback) Casts a spell on a player, walking tofallbackif the player is not available.- Parameters:
spell- spell to castquery- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far away- Returns:
trueif a walk or spell-on-player action was performed
-
castSpellOnPlayer
public boolean castSpellOnPlayer(Spell spell, Function<PlayerView, Optional<Player>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on a player with optional local reachability checks.- Parameters:
spell- spell to castquery- query selecting the player from this scope's player viewfallback- coordinate used when the player is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before casting- Returns:
trueif a walk or spell-on-player action was performed
-
castSpellOnTileItem
public boolean castSpellOnTileItem(Spell spell, Function<TileItemView, Optional<TileItem>> query, Coord fallback) Casts a spell on a ground item, walking tofallbackif the item is not available.- Parameters:
spell- spell to castquery- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far away- Returns:
trueif a walk or spell-on-ground-item action was performed
-
castSpellOnTileItem
public boolean castSpellOnTileItem(Spell spell, Function<TileItemView, Optional<TileItem>> query, Coord fallback, boolean skipReachableCheck) Casts a spell on a ground item with optional local reachability checks.- Parameters:
spell- spell to castquery- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before casting- Returns:
trueif a walk or spell-on-ground-item action was performed
-
pickUp
Picks up the nearest matching ground item tofallback.- Parameters:
item- item id to takefallback- coordinate used when the item is missing or too far away- Returns:
trueif a walk or pickup action was performed
-
pickUp
Picks up the nearest matching ground item with optional local reachability checks.- Parameters:
item- item id to takefallback- coordinate used when the item is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before taking the item- Returns:
trueif a walk or pickup action was performed
-
pickUp
public boolean pickUp(int item, Function<TileItemView, Optional<TileItem>> query, Coord fallback, boolean skipReachableCheck) Picks up a ground item selected from this scope's tile-item view.- Parameters:
item- item id used for loggingquery- query selecting the ground item from this scope's tile-item viewfallback- coordinate used when the item is missing or too far awayskipReachableCheck- whether to skip loaded collision reachability before taking the item- Returns:
trueif a walk or pickup action was performed
-