Skip to main content

Ranged & Magic Combat System

F2P Ranged and Magic Combat Implementation Guide

Table of Contents

  1. Overview
  2. Attack Type System
  3. Ranged Combat
  4. Magic Combat
  5. Projectile System
  6. Damage Calculators
  7. Ammunition & Runes
  8. Combat Styles
  9. UI Components
  10. Network Protocol

1. Overview

Hyperscape implements OSRS-accurate ranged and magic combat with F2P content (levels 1-40).

1.1 Implemented Features

Ranged Combat:
  • ✅ Bows (shortbow, oak, willow, maple)
  • ✅ Arrows (bronze, iron, steel, mithril, adamant)
  • ✅ Combat styles (accurate, rapid, longrange)
  • ✅ Ammunition consumption (1 arrow per shot)
  • ✅ Projectile visuals with 3D arrow meshes
  • ✅ OSRS-accurate hit delay formulas
  • ✅ Ranged XP distribution
Magic Combat:
  • ✅ Combat spells (Strike and Bolt tiers, levels 1-35)
  • ✅ Rune system (air, water, earth, fire, mind, chaos)
  • ✅ Elemental staves (infinite runes)
  • ✅ Autocast system
  • ✅ Staffless casting support
  • ✅ Spell projectile visuals
  • ✅ OSRS-accurate magic defense formulas
  • ✅ Magic XP distribution

1.2 Architecture


2. Attack Type System

2.1 Attack Type Enum

2.2 Attack Type Routing

The combat system routes attacks based on weapon type and selected spell:
OSRS-Accurate Behavior:
  • You can cast spells without a staff (lower accuracy)
  • Elemental staves provide infinite runes for their element
  • Staff provides magic attack bonus but is not required

2.3 Range Calculation


3. Ranged Combat

3.1 Ranged Weapons

3.2 Ammunition

3.3 Ranged Damage Formula

3.4 Combat Styles

3.5 Ammunition Consumption

F2P Scope:
  • 100% consumption rate (1 arrow per shot)
  • No Ava’s devices (no retrieval)
  • Future: Ava’s attractor (60%), accumulator (72%), assembler (80%)

4. Magic Combat

4.1 Combat Spells

Strike Tier (Levels 1-13): Bolt Tier (Levels 17-35):

4.2 Magic Damage Formula

Key Difference from Melee/Ranged:
  • Magic defense uses 70% magic level + 30% defense level (players only)
  • NPCs use only magic level for defense
  • Max hit comes from spell, not equipment bonuses

4.3 Elemental Staves

4.4 Autocast System

OSRS-Accurate Behavior:
  • Autocast cleared on weapon swap
  • Can cast spells manually without autocast
  • Staffless casting allowed (lower accuracy)

4.5 Rune Consumption

Elemental Staff Logic:

5. Projectile System

5.1 Hit Delay Formulas

5.2 ProjectileService

5.3 Projectile Rendering

Visual Effects: Arrows:
  • 3D arrow mesh (brown shaft, metal tip)
  • Straight-line trajectory
  • 400ms delay before visual spawn (OSRS-accurate)
  • Rotates to face direction
Spells:
  • Colored sphere based on element
  • Homing trajectory (tracks moving targets)
  • Delayed spawn based on hit delay
  • Additive blending for glow effect

5.4 Spell Visual Configuration


6. Damage Calculators

6.1 RangedDamageCalculator

6.2 MagicDamageCalculator


7. Ammunition & Runes

7.1 Ammunition Manifest

7.2 Runes Manifest

7.3 Combat Spells Manifest


8. Combat Styles

8.1 Ranged Styles

8.2 Magic Styles


9. UI Components

9.1 SpellsPanel

Features:
  • 2-4 column adaptive grid based on panel width
  • Element-colored spell icons (💨 💧 🪨 🔥)
  • Locked spells show level requirement
  • Selected spell highlighted with glow effect
  • Tooltip shows max hit, XP, and rune cost

9.2 Equipment Panel Updates

Ammo Slot Added:
  • New equipment slot for arrows
  • Displays arrow quantity
  • Drag-and-drop support
  • Shows ranged strength bonus in tooltip
Layout:

9.3 Combat Panel Updates

New Combat Styles:
  • Rapid (⚡) - Ranged only
  • Longrange (🎯) - Ranged and Magic
  • Autocast (✨) - Magic only
Style Icons:

10. Network Protocol

10.1 Client → Server Packets

10.2 Server → Client Packets

10.3 Server Handlers

Security Measures:
  • Spell ID validation (lowercase letters and underscores only, max 50 chars)
  • Timestamp validation (prevents replay attacks)
  • Server-side spell existence verification
  • Rate limiting (same as combat requests)

Implementation Files

New Files Created

Modified Files


Database Schema Changes

Migration 0026: Add Magic Skill


Testing

Unit Tests

  • ✅ RangedDamageCalculator: effective level formula
  • ✅ RangedDamageCalculator: attack roll formula
  • ✅ RangedDamageCalculator: max hit formula
  • ✅ MagicDamageCalculator: player defense = 0.7 × magic + 0.3 × defense
  • ✅ MagicDamageCalculator: NPC defense uses only magic level
  • ✅ AmmunitionService: arrow validation and consumption
  • ✅ RuneService: rune validation with elemental staff support
  • ✅ SpellService: spell validation and level requirements
  • ✅ ProjectileService: hit delay formulas

Integration Tests

  • ✅ Equip bow + arrows, attack mob, verify damage and consumption
  • ✅ Equip staff, cast Fire Strike, verify rune consumption
  • ✅ Equip staff of fire, cast Fire Strike, verify only mind runes consumed
  • ✅ Run out of arrows → attack stops
  • ✅ Run out of runes → spell fails
  • ✅ Rapid style → attacks faster
  • ✅ Longrange style → +2 range

Future Enhancements

Not in F2P Scope (Future Implementation):
  • Crossbows and bolts
  • Enchanted bolts with special effects
  • Thrown weapons (darts, knives, javelins)
  • Ava’s devices (arrow retrieval)
  • Blast/Wave/Surge spell tiers
  • Ancient Magicks, Lunar spells
  • Powered staves (Trident, etc.)
  • Magic damage % equipment bonuses
  • Chinchompas (AoE ranged)
  • Special attacks

Document generated for Hyperscape Ranged/Magic Combat System v1.0