Skip to main content

Game Systems API Reference

This page documents the public APIs for Hyperscape’s core game systems.

EatDelayManager

Manages eating cooldowns per player with OSRS-accurate 3-tick delays. Location: packages/shared/src/systems/shared/character/EatDelayManager.ts

Methods

canEat(playerId: string, currentTick: number): boolean

Check if player can eat (not on cooldown). Parameters:
  • playerId - Player to check
  • currentTick - Current game tick
Returns: true if player can eat, false if still on cooldown Example:

recordEat(playerId: string, currentTick: number): void

Record that player just ate. Parameters:
  • playerId - Player who ate
  • currentTick - Current game tick
Example:

getRemainingCooldown(playerId: string, currentTick: number): number

Get remaining cooldown ticks. Parameters:
  • playerId - Player to check
  • currentTick - Current game tick
Returns: 0 if ready to eat, otherwise ticks remaining Example:

clearPlayer(playerId: string): void

Clear player’s eat cooldown (on death, disconnect). Parameters:
  • playerId - Player to clear

clear(): void

Clear all state (for testing or server reset).

getTrackedCount(): number

Get the number of tracked players (for debugging/monitoring). Returns: Number of players with active eat cooldowns

InventoryActionDispatcher

Centralized inventory action dispatching for context menus and left-click actions. Location: packages/client/src/game/systems/InventoryActionDispatcher.ts

Types

Functions

dispatchInventoryAction(action: string, ctx: InventoryActionContext): ActionResult

Dispatch an inventory action to the appropriate handler. Parameters:
  • action - The action ID (e.g., “eat”, “wield”, “drop”)
  • ctx - Context containing world, itemId, slot, and optional quantity
Returns: ActionResult indicating success/failure Supported Actions:
  • eat - Consume food item
  • drink - Consume potion
  • bury - Bury bones for Prayer XP
  • wield - Equip weapon or shield
  • wear - Equip armor
  • drop - Drop item on ground
  • examine - Show item description
  • use - Enter targeting mode for “Use X on Y”
  • cancel - Close menu (no-op)
Example:

Item Helpers

Utility functions for item type detection and primary action determination. Location: packages/shared/src/utils/item-helpers.ts

Type Detection

isFood(item: Item | null): boolean

Check if item is food (consumable with healAmount, excludes potions). Example:

isPotion(item: Item | null): boolean

Check if item is a potion (consumable with “potion” in ID).

isBone(item: Item | null): boolean

Check if item is bones (can be buried for Prayer XP).

isWeapon(item: Item | null): boolean

Check if item is a weapon (equipSlot is weapon or 2h).

isShield(item: Item | null): boolean

Check if item is a shield (equipSlot is shield).

usesWield(item: Item | null): boolean

Check if item uses “Wield” action (weapons + shields).

usesWear(item: Item | null): boolean

Check if item uses “Wear” action (all other equipment).

isNotedItem(item: Item | null): boolean

Check if item is a bank note (cannot be eaten/equipped).

Primary Action Detection

getPrimaryAction(item: Item | null, isNoted: boolean): PrimaryActionType

Get primary action using manifest-first approach with heuristic fallback. Returns: One of: "eat", "drink", "bury", "wield", "wear", "use" Example:

getPrimaryActionFromManifest(item: Item | null): PrimaryActionType | null

Get primary action from manifest’s inventoryActions (first action in array). Returns: Primary action or null if no actions defined

SmithingSystem

Handles smelting and smithing with tick-based timing and auto-crafting. Location: packages/shared/src/systems/shared/interaction/SmithingSystem.ts

Methods

isPlayerSmithing(playerId: string): boolean

Check if player is currently smithing. Parameters:
  • playerId - Player to check
Returns: true if player has an active smithing session Example:

Events

SMITHING_INTERACT

Player clicked an anvil. Data:

SMITHING_INTERFACE_OPEN

Show smithing UI with available recipes. Data:

PROCESSING_SMITHING_REQUEST

Start smithing a specific item. Data:

SMITHING_START

Smithing session started. Data:

SMITHING_COMPLETE

Smithing session finished. Data:

ResourceSystem

Manages resource gathering for all skills (woodcutting, mining, fishing). Location: packages/shared/src/systems/shared/entities/ResourceSystem.ts

Methods

processGatheringTick(tickNumber: number): void

Process all active gathering sessions on each server tick (600ms). Parameters:
  • tickNumber - Current server tick number
Called by: TickSystem at RESOURCES priority Handles:
  1. Resource respawn checks (tick-based)
  2. Proximity validation (server-authoritative position)
  3. Inventory capacity checks
  4. Success/failure rolls using cached success rate
  5. Drop rolling from manifest harvestYield
  6. XP awards and inventory updates
  7. Resource depletion with tick-based respawn scheduling

getAllResources(): Resource[]

Get all resources for testing/debugging. Returns: Array of all resources in the world

getResourcesByType(type: string): Resource[]

Get resources by type. Parameters:
  • type - Resource type (“tree”, “ore”, “fishing_spot”)
Returns: Array of resources matching the type

getResource(resourceId: string): Resource | undefined

Get resource by ID. Parameters:
  • resourceId - Resource entity ID
Returns: Resource data or undefined if not found

Events

RESOURCE_GATHER

Player attempts to gather from a resource. Data:

RESOURCE_GATHERING_STARTED

Gathering session started. Data:

RESOURCE_GATHERING_STOPPED

Gathering session ended. Data:

RESOURCE_DEPLETED

Resource exhausted and needs respawn. Data:

RESOURCE_RESPAWNED

Resource respawned and is available again. Data:

Gathering Utilities

SuccessRateCalculator

OSRS-accurate success rate and cycle calculations. Location: packages/shared/src/systems/shared/entities/gathering/SuccessRateCalculator.ts

computeSuccessRate(skillLevel: number, skill: string, resourceVariant: string, toolTier: string | null): number

Compute success rate using OSRS’s LERP interpolation formula. Formula:
Parameters:
  • skillLevel - Player’s current skill level (1-99)
  • skill - The gathering skill (“woodcutting”, “mining”, “fishing”)
  • resourceVariant - Resource type key (e.g., “tree_oak”, “ore_iron”)
  • toolTier - Tool tier for woodcutting (e.g., “rune”), ignored for other skills
Returns: Success probability (0-1) Example:

computeCycleTicks(skill: string, baseCycleTicks: number, toolData: GatheringToolData | null, bonusRollTriggered: boolean): number

Compute gathering cycle in ticks (OSRS-accurate, skill-specific). Parameters:
  • skill - The gathering skill
  • baseCycleTicks - Base cycle ticks from resource manifest
  • toolData - Tool data from tools.json manifest
  • bonusRollTriggered - Whether dragon/crystal pickaxe bonus speed triggered
Returns: Number of ticks between gathering attempts Example:

ticksToMs(ticks: number): number

Convert ticks to milliseconds for client progress bar. Parameters:
  • ticks - Number of game ticks
Returns: Duration in milliseconds (ticks × 600)

SmithingConstants

Centralized constants for smelting and smithing systems. Location: packages/shared/src/constants/SmithingConstants.ts

Constants

Helper Functions

formatMessage(message: string, values: Record<string, string | number>): string

Format messages with placeholders. Example:

clampQuantity(quantity: unknown): number

Validate and clamp quantity to safe bounds (1-10000). Example:

isValidItemId(id: unknown): id is string

Validate a string ID (barItemId, furnaceId, recipeId, anvilId). Returns: Type guard - true if valid string ID

isLooseInventoryItem(item: unknown): item is LooseInventoryItem

Type guard to validate an object is a valid inventory item. Example:

getSmithingLevelSafe(entity: unknown, defaultLevel: number): number

Get smithing level from an entity safely. Parameters:
  • entity - The entity to get smithing level from
  • defaultLevel - Default level to return if not found (default: 1)
Returns: The entity’s smithing level

Context Menu Colors

OSRS-accurate entity name colors for context menus. Location: packages/shared/src/constants/interaction.ts

Constants

Example: