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 checkcurrentTick- Current game tick
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 atecurrentTick- Current game tick
getRemainingCooldown(playerId: string, currentTick: number): number
Get remaining cooldown ticks.
Parameters:
playerId- Player to checkcurrentTick- Current game tick
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
ActionResult indicating success/failure
Supported Actions:
eat- Consume food itemdrink- Consume potionbury- Bury bones for Prayer XPwield- Equip weapon or shieldwear- Equip armordrop- Drop item on groundexamine- Show item descriptionuse- Enter targeting mode for “Use X on Y”cancel- Close menu (no-op)
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
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
TickSystem at RESOURCES priority
Handles:
- Resource respawn checks (tick-based)
- Proximity validation (server-authoritative position)
- Inventory capacity checks
- Success/failure rolls using cached success rate
- Drop rolling from manifest harvestYield
- XP awards and inventory updates
- 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”)
getResource(resourceId: string): Resource | undefined
Get resource by ID.
Parameters:
resourceId- Resource entity ID
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:
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
computeCycleTicks(skill: string, baseCycleTicks: number, toolData: GatheringToolData | null, bonusRollTriggered: boolean): number
Compute gathering cycle in ticks (OSRS-accurate, skill-specific).
Parameters:
skill- The gathering skillbaseCycleTicks- Base cycle ticks from resource manifesttoolData- Tool data from tools.json manifestbonusRollTriggered- Whether dragon/crystal pickaxe bonus speed triggered
ticksToMs(ticks: number): number
Convert ticks to milliseconds for client progress bar.
Parameters:
ticks- Number of game ticks
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 fromdefaultLevel- Default level to return if not found (default: 1)
Context Menu Colors
OSRS-accurate entity name colors for context menus. Location:packages/shared/src/constants/interaction.ts
Constants
Related Documentation
- ECS Architecture - Entity Component System
- Event System - Event-driven architecture
- Game Systems Overview - All game systems
- Type Definitions - TypeScript types