Combat System Documentation
The Complete Technical Reference for Hyperscape’s OSRS-Accurate Combat System
Table of Contents
- Architecture Overview
- Attack Types & Handlers
- Mob Combat Configuration
- Combat Flow
- Damage Calculation
- Animation & Timing
- Projectile System
- Configuration Reference
1. Architecture Overview
Combat System Components
2. Attack Types & Handlers
2.1 Supported Attack Types
Hyperscape supports three attack types for both players and mobs:| Attack Type | Range | Projectile | Resource Cost |
|---|---|---|---|
| Melee | 1-2 tiles | None | None |
| Ranged | Up to 10 tiles | Arrows | Arrows (players only) |
| Magic | Up to 10 tiles | Spells | Runes (players only) |
2.2 Attack Handler Architecture
Each attack type has a dedicated handler that supports both player and mob attackers:2.3 Player vs. Mob Attack Paths
Player Attack Path:- Equipment bonuses applied (weapon, armor stats)
- Resource consumption (arrows, runes)
- Combat style bonuses (accurate, aggressive, defensive)
- Prayer bonuses
- XP rewards on successful hits
- Stats from NPC manifest (
magic,ranged,attack,strength) - Infinite resources (no arrow/rune consumption)
- No equipment bonuses
- No XP rewards
- Spell/arrow type from NPC configuration
2.4 Shared Attack Preparation
TheprepareMobAttack() utility consolidates common validation logic for mob projectile attacks:
- Entity resolution (attacker and target)
- Alive checks
- Range validation
- Position validation
- Cooldown check
- Face target
- Play animation
MobAttackContext with all validated data, or null if any check fails.
3. Mob Combat Configuration
3.1 NPC Manifest Schema
Mobs can be configured with any attack type via JSON manifest:3.2 Combat Configuration Fields
Required Fields:attackable: Can players attack this NPC?aggressive: Does NPC auto-aggro players?retaliates: Does NPC fight back when attacked?combatRange: Maximum attack range in tilesattackSpeedTicks: Ticks between attacks (4 = 2.4 seconds)
attackType:"melee"(default),"ranged", or"magic"spellId: Required for magic mobs (e.g.,"wind_strike","fire_bolt")arrowId: Required for ranged mobs (e.g.,"bronze_arrow","iron_arrow")
heldWeaponModel: Optional GLB model path for visual weapon (bow, staff, sword)- Format:
"asset://weapons/bow_shortbow.glb" - Attached to VRM hand bone using Asset Forge metadata
- Cached and shared across mobs of same type
- Format:
3.3 Attack Type Examples
Melee Mob (Default):3.4 Weapon Visual System
TheMobVisualManager handles weapon attachment for mobs:
- Weapons cached by URL to avoid duplicate loads
- Concurrent load deduplication via
_pendingLoads - Geometry/material sharing via
clone(true) - Proper cleanup on mob destroy and world teardown
- Supports Asset Forge attachment metadata (V1 and V2 formats)
4. Combat Flow
4.1 Mob Attack Routing
4.2 Mob Magic Attack Flow
4.3 Mob Ranged Attack Flow
5. Damage Calculation
5.1 Mob Magic Damage
5.2 Mob Ranged Damage
6. Animation & Timing
6.1 Combat Animations
TheCombatAnimationManager routes animations based on attack type:
- Animation starts immediately on attack
- Held for
attackSpeedTicks - 1ticks - Returns to idle/movement animation on final tick
6.2 Combat Emote Priority
7. Projectile System
7.1 Projectile Creation
Both magic and ranged attacks create projectiles for visual synchronization:7.2 Projectile Launch Timing
7.3 Hit Delay Formulas
| Attack Type | Distance | Hit Delay (ticks) | Hit Delay (ms) |
|---|---|---|---|
| Melee | Any | 0 | 0 |
| Ranged | 1 tile | 1 | 600 |
| Ranged | 5 tiles | 2 | 1200 |
| Ranged | 10 tiles | 3 | 1800 |
| Magic | 1 tile | 1 | 600 |
| Magic | 5 tiles | 3 | 1800 |
| Magic | 10 tiles | 4 | 2400 |
8. Configuration Reference
8.1 Combat Constants
8.2 NPC Combat Defaults
Summary
The combat system now supports full melee/ranged/magic combat for both players and mobs:Key Features
✅ Three attack types: Melee, Ranged, Magic✅ Mob projectile attacks: Mobs can cast spells and fire arrows
✅ Visual weapon system: Bows, staves, and weapons attach to mob hands
✅ Shared attack preparation:
prepareMobAttack() eliminates code duplication✅ Proper animation routing: SPELL_CAST, RANGE, SWORD_SWING emotes
✅ OSRS-accurate timing: Hit delays, projectile travel, launch delays
✅ Resource management: Weapon model caching, proper cleanup
✅ Zero-allocation hot paths: Pre-allocated damage params
Combat Handler Files
CombatSystem.ts- Main orchestration and attack routinghandlers/MeleeAttackHandler.ts- Melee combathandlers/RangedAttackHandler.ts- Ranged combat (players and mobs)handlers/MagicAttackHandler.ts- Magic combat (players and mobs)handlers/AttackContext.ts- Shared utilities (prepareMobAttack,checkProjectileRange)CombatAnimationManager.ts- Animation routing by attack typeProjectileService.ts- Projectile creation and trackingentities/managers/MobVisualManager.ts- Weapon attachment and caching
Document updated for Hyperscape Combat System v3.0 - Mob Projectile Attacks