Class Combat

java.lang.Object
privbot.hooks.Combat
All Implemented Interfaces:
CombatCollision.Source

public final class Combat extends Object implements CombatCollision.Source
Thread-safe combat reads and player/spec interactions for scripts.

Use via PrivContext.combat (ctx.combat). It keeps the behavior of the older combat helper it replaces (SpawnPK spec bar, Orion spec orb dispatch, Roat attack row, etc.).

Special attack orb dispatch is server-specific:

  • Orion: CC_OP, identifier=1, packed widget param1=38862884.
  • Impact: widget 12311, toggled through the client's own special attack control.
  • Default / SpawnPK: WIDGET_TYPE_1, param1=12311.
  • RoatPkz: WIDGET_TYPE_1, param1=7537.
  • Method Details

    • getAttackStyle

      public int getAttackStyle()
      Zero-based selected attack style; -1 means unavailable, never a guessed default.
    • setAttackStyle

      public boolean setAttackStyle(int index)
      Dispatch acceptance only. Open the combat tab first and re-read getAttackStyle afterwards.
    • getAutoRetaliate

      public Boolean getAutoRetaliate()
      Returns:
      whether auto retaliate is on; null when it cannot be read
    • setAutoRetaliate

      public boolean setAutoRetaliate(boolean enabled)
      Parameters:
      enabled - the wanted state
      Returns:
      dispatch acceptance; re-read getAutoRetaliate()
    • corridor

      public CombatCollision corridor()
      One immutable collision read from the local player's tile, reusable for every candidate NPC of one decision. It proves a conservative walls-only corridor, not that the server accepts the attack. Unreadable: the result has CombatCollision.isAvailable() false and every check answers false or null (never throws). Thread: marshals its own client-thread read; call from the runner worker or a node.
      Specified by:
      corridor in interface CombatCollision.Source
      Returns:
      the same object collision() returns, typed as the public interface; never null
    • npcSize

      public int npcSize(net.runelite.api.NPC npc)
      Current transformed footprint size; unavailable definitions conservatively use one tile.
    • isInCombat

      public boolean isInCombat()
      Returns:
      the adapter's in-combat read; false when unreadable
    • getOpponentCurrentHp

      public int getOpponentCurrentHp()
      Returns:
      the opponent's current hitpoints from the adapter; 0 when unknown
    • getOpponentMaxHp

      public int getOpponentMaxHp()
      Returns:
      the opponent's maximum hitpoints from the adapter; 0 when unknown
    • getOpponentName

      public String getOpponentName()
      Returns:
      the opponent's name, or ""
    • getSpecialAttackPercent

      public int getSpecialAttackPercent()
      Special attack energy 0–100 (SpawnPK widget path when applicable, else adapter).
    • getSpecialAttackPercentage

      @Deprecated public int getSpecialAttackPercentage()
      Deprecated.
      use getSpecialAttackPercent() (or specialAttackPercentOrNull() to tell 0 from "cannot read")
      Same as getSpecialAttackPercent() — kept for callers migrating from the older name getSpecialAttackPercentage().
      Returns:
      the same answer as getSpecialAttackPercent()
    • isSpecialAttackEnabled

      public boolean isSpecialAttackEnabled()
      Whether the spec orb is armed (varp on the client thread). Safe from script/task threads.
    • isSpecialAttackActive

      public boolean isSpecialAttackActive()
      Same as isSpecialAttackEnabled() — name aligned with the older isSpecialAttackActive().
    • specialAttackPercentOrNull

      public Integer specialAttackPercentOrNull()
      Special attack energy 0–100, or null when it could not be read.

      getSpecialAttackPercent() cannot say "unknown": it answers 0 for a failed read too, and on Impact, Elorin and SpawnPK a raw varp read also answers 0 when it cannot read. A caller that must not act on a read that never happened (an arm click is a toggle) uses this instead. A readable answer always equals getSpecialAttackPercent()'s.

    • specialAttackArmedOrNull

      public Boolean specialAttackArmedOrNull()
      Whether the spec orb is armed, or null when it could not be read. The same contract as specialAttackPercentOrNull().
    • hasEnoughSpecialEnergy

      public boolean hasEnoughSpecialEnergy(int requiredPercentage)
      Parameters:
      requiredPercentage - energy needed, 0..100
      Returns:
      whether getSpecialAttackPercent() reaches it (an unreadable 0 reads as not enough)
    • toggleSpecialAttack

      public boolean toggleSpecialAttack()
      Clicks the special attack orb once, whatever its state.
      Returns:
      dispatch acceptance
    • activateSpecialAttack

      public boolean activateSpecialAttack()
      Arms the special attack orb unless it already reads armed.
      Returns:
      dispatch acceptance (true also when already armed)
    • activateSpecialAttackWithImpactFallback

      public boolean activateSpecialAttackWithImpactFallback(int impactWidgetFallback)
      Arms the current Impact special orb, using the supplied weapon widget only if the live holder has not populated its active-row field yet. Other servers ignore the Impact fallback.
    • tryArmSpecialAttackOrb

      public boolean tryArmSpecialAttackOrb()
      Arms the orb unless armed, then re-reads it in the same client-thread call.
      Returns:
      whether the orb reads armed afterwards
    • deactivateSpecialAttack

      public boolean deactivateSpecialAttack()
      Disarms the special attack orb when it reads armed.
      Returns:
      dispatch acceptance (true also when already disarmed)
    • attack

      public boolean attack(String playerName)
      Attacks the loaded player whose name equals playerName (ignore case). Alias of attackPlayer(String).
    • attackPlayer

      public boolean attackPlayer(String playerName)
      Parameters:
      playerName - the exact name of a loaded player
      Returns:
      dispatch acceptance; false when no loaded player has that name
    • attackPlayer

      public boolean attackPlayer(net.runelite.api.Player target)
      Parameters:
      target - a loaded player
      Returns:
      dispatch acceptance
    • isPlayerValid

      public boolean isPlayerValid(net.runelite.api.Player target)
      Parameters:
      target - a player object
      Returns:
      whether it is still in the client's loaded player list
    • resolvePlayerMenuIndex

      public static int resolvePlayerMenuIndex(net.runelite.api.Client client, net.runelite.api.Player target)
      Resolves the menu identifier index for a player (list index first).
    • getCurrentTarget

      public net.runelite.api.Actor getCurrentTarget()
      Returns:
      who the local player is interacting with, or null (also when unreadable: see ctx.player.interacting())
    • castVengeance

      public boolean castVengeance()
      Casts Vengeance (Lunar spellbook; by name through the spellbook on Elorin).
      Returns:
      dispatch acceptance
    • observedSpecialAttackPercent

      public Observed<Integer> observedSpecialAttackPercent()
      Special attack energy 0–100 as an Observed: specialAttackPercentOrNull() with its null turned into UNREADABLE (never the 0 getSpecialAttackPercent() answers for that).
      Returns:
      the energy, or UNREADABLE
    • observedSpecialAttackArmed

      public Observed<Boolean> observedSpecialAttackArmed()
      Whether the special attack orb is armed as an Observed: specialAttackArmedOrNull() with its null turned into UNREADABLE. Arming is a toggle: never click it on an unreadable answer.
      Returns:
      TRUE / FALSE, or UNREADABLE