Skip to main content

Combat System

Hyperscape implements a tick-based combat system inspired by Old School RuneScape. Combat operates on discrete 600ms ticks, with authentic damage formulas, accuracy rolls, and attack styles.
Combat code lives in packages/shared/src/systems/shared/combat/ and uses constants from packages/shared/src/constants/CombatConstants.ts.

Core Constants

From CombatConstants.ts:

Session Interruption

Combat Closes Bank/Store/Dialogue

When a player is attacked, all interaction sessions are automatically closed (OSRS-accurate behavior):
Session Close Reasons:
  • user_action — Player explicitly closed UI
  • distance — Player moved too far from target
  • disconnect — Player disconnected
  • new_session — Replaced by new session
  • target_gone — Target entity no longer exists
  • combat — Player was attacked (OSRS-style)
OSRS-Accurate: Even a splash attack (0 damage) closes the bank/store/dialogue. Being in combat matters, not just taking damage.

Food Consumption & Combat

Eat Delay Mechanics

Food consumption integrates with the combat system using OSRS-accurate timing:
OSRS Rules:
  • 3-tick delay between eating (1.8 seconds)
  • Food consumed even at full health
  • Attack delay only added if already on cooldown
  • If weapon is ready to attack, eating does NOT add delay

Attack Delay Integration

When eating during combat, the system checks if the player is on attack cooldown:
Example Scenario:
  1. Player attacks with longsword (4-tick weapon)
  2. Attack lands at tick 100, next attack at tick 104
  3. Player eats at tick 102 (while on cooldown)
  4. Eat delay adds 3 ticks: next attack now at tick 107
  5. If player eats at tick 104+ (weapon ready), no delay added

Healing Formula

Healing is capped and validated server-side:

Combat Styles

Combat styles determine which skill gains XP and provide stat bonuses.

Combat Style Icons

Each combat style has a unique SVG icon with active state colors:

Action Bar Integration

Combat styles can be dragged from the combat panel to the action bar for quick switching:
Action Bar Features:
  • Drag combat styles from combat panel
  • Click to switch attack style
  • Visual highlight when style is active
  • Supports 4-12 customizable slots (default: 9)
  • Persistent across sessions

Damage Calculation

Damage uses the authentic OSRS formula from the wiki. Prayer bonuses are applied as multipliers to effective levels.

Maximum Hit Formula

Prayer bonuses are applied to effective levels before damage calculation. For example, Burst of Strength (+5%) multiplies effective strength by 1.05.

Accuracy Formula

Prayer bonuses from active prayers (e.g., Clarity of Thought +5% attack, Thick Skin +5% defense) are applied to effective levels before calculating attack and defense rolls.

Damage Roll


Attack Range System

Melee Range

OSRS Accuracy: Standard melee (range 1) can only attack in cardinal directions (N/S/E/W). Diagonal attacks require range 2+ weapons like halberds.

Ranged Combat

Ranged attacks use Chebyshev distance and require:
  • A ranged weapon (bow)
  • Ammunition (arrows)

Attack Speed & Cooldowns

Attacks occur on tick boundaries with weapon-specific speeds.

Weapon Speed Examples


Aggro System

NPCs have configurable aggression behaviors.

Aggro Types

Aggro Constants

Aggro Logic


Death Mechanics

Player Death

When a player dies:
  1. Headstone spawns at death location
  2. Items drop to headstone (kept for 15 minutes)
  3. Player respawns at starter town
  4. 3 most valuable items are kept (Protect Item prayer adds 1)

Mob Death

When a mob dies:
  1. Loot drops based on drop table
  2. XP granted to all attackers
  3. Respawn timer starts (based on mob type)
  4. Entity destroyed after death animation

XP Distribution

XP is granted based on damage dealt and combat style.

Food & Combat Interaction

Eating During Combat

When a player eats food while in combat, OSRS-accurate timing rules apply:

Eat Delay Mechanics

Players cannot eat again until the eat delay expires:
OSRS-Accurate: Food is consumed even at full health. The eat delay and attack delay apply regardless of current HP.

Attack Delay API

The CombatSystem provides methods for eat delay integration:

Combat Events

The combat system emits events for UI and logging:

Duel Arena Integration

The combat system integrates with the Duel Arena for PvP combat:

Rule Enforcement

The DuelSystem provides APIs for rule checking:

Death Handling

Duel deaths are handled differently than normal deaths:
See the Duel Arena documentation for complete PvP mechanics.