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
FromCombatConstants.ts:
Session Interruption
Combat Closes Bank/Store/Dialogue
When a player is attacked, all interaction sessions are automatically closed (OSRS-accurate behavior):user_action— Player explicitly closed UIdistance— Player moved too far from targetdisconnect— Player disconnectednew_session— Replaced by new sessiontarget_gone— Target entity no longer existscombat— 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:- 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:- Player attacks with longsword (4-tick weapon)
- Attack lands at tick 100, next attack at tick 104
- Player eats at tick 102 (while on cooldown)
- Eat delay adds 3 ticks: next attack now at tick 107
- 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:- 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
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:- Headstone spawns at death location
- Items drop to headstone (kept for 15 minutes)
- Player respawns at starter town
- 3 most valuable items are kept (Protect Item prayer adds 1)
Mob Death
When a mob dies:- Loot drops based on drop table
- XP granted to all attackers
- Respawn timer starts (based on mob type)
- 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
TheCombatSystem 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.
Related Documentation
- Duel Arena (PvP dueling system)
- Inventory System (for food consumption)
- Tile Movement System
- Skills & Progression
- NPC Data Structure
- Item Stats