Skip to main content

Combat System Documentation

The Complete Technical Reference for Hyperscape’s OSRS-Accurate Combat System

Table of Contents

  1. Architecture Overview
  2. Attack Types & Handlers
  3. Mob Combat Configuration
  4. Combat Flow
  5. Damage Calculation
  6. Animation & Timing
  7. Projectile System
  8. 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:

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
Mob Attack Path:
  • 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

The prepareMobAttack() utility consolidates common validation logic for mob projectile attacks:
Validation Steps:
  1. Entity resolution (attacker and target)
  2. Alive checks
  3. Range validation
  4. Position validation
  5. Cooldown check
  6. Face target
  7. Play animation
Returns 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 tiles
  • attackSpeedTicks: Ticks between attacks (4 = 2.4 seconds)
Attack Type Fields:
  • 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")
Visual Fields:
  • 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

3.3 Attack Type Examples

Melee Mob (Default):
Ranged Mob:
Magic Mob:

3.4 Weapon Visual System

The MobVisualManager handles weapon attachment for mobs:
Features:
  • 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

The CombatAnimationManager routes animations based on attack type:
Animation Timing:
  • Animation starts immediately on attack
  • Held for attackSpeedTicks - 1 ticks
  • 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

Examples:

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 routing
  • handlers/MeleeAttackHandler.ts - Melee combat
  • handlers/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 type
  • ProjectileService.ts - Projectile creation and tracking
  • entities/managers/MobVisualManager.ts - Weapon attachment and caching

Document updated for Hyperscape Combat System v3.0 - Mob Projectile Attacks