Skip to main content

Migration Guide: v2.x to v3.0

This guide helps you migrate to Hyperscape v3.0, which introduces mob magic and ranged attacks.

Overview

Version 3.0 adds support for mob projectile attacks (magic and ranged). All changes are backward compatible—existing mobs continue to work without modification.

What’s New

Mob Attack Types

Mobs can now use three attack types:
  • Melee (default) - Close-range combat
  • Ranged (new) - Bow and arrow attacks
  • Magic (new) - Spell casting

New NPC Configuration Fields


Breaking Changes

None. All changes are backward compatible.

Deprecations

None. All existing APIs remain unchanged.

Migration Steps

Step 1: Update Dependencies

Step 2: Review Existing Mobs (Optional)

All existing mobs default to attackType: "melee" and continue to work without changes. No action required unless you want to convert mobs to ranged/magic.

Step 3: Add Ranged/Magic Mobs (Optional)

To convert an existing mob to ranged or magic: Before (v2.x):
After (v3.0) - Magic:
After (v3.0) - Ranged:

Step 4: Test Your Changes


API Changes

New Functions

prepareMobAttack()

Shared utility for mob projectile attack validation.
Use Case: Called by MagicAttackHandler and RangedAttackHandler to validate mob attacks.

getMobAttackType()

Type guard for safely reading mob attack type.
Use Case: Resolving mob attack type for retaliation and auto-attacks.

Modified Functions

MagicAttackHandler.handle()

Now supports mob attackers:

RangedAttackHandler.handle()

Now supports mob attackers:

CombatSystem.handleAttack()

Now requires attackType parameter:
Migration: All callers must provide attackType. The CombatTickProcessor automatically resolves this from combat state.

Event Changes

COMBAT_MOB_NPC_ATTACK

Added Fields:
Removed Fields:
Reason: Damage is now calculated by attack handlers using NPC stats, not passed in events.

COMBAT_PROJECTILE_LAUNCHED

Added Fields:

Configuration Changes

Combat Constants

New Constants:
Existing Constants (Unchanged):

Code Examples

Creating a Magic Mob

Creating a Ranged Mob

Handling Mob Attacks in Custom Code


Performance Notes

Weapon Model Caching

Weapon GLB models are cached statically and shared across all mobs:
Benefits:
  • Reduces network requests
  • Shares geometry/material buffers
  • Concurrent loads deduplicated
Cleanup:
  • Cache cleared on world teardown
  • Individual mobs only remove from scene graph (no disposal)

Pre-Allocated Damage Params

Attack handlers reuse pre-allocated parameter objects:
Safety Invariant:
  • Tick loop is single-threaded
  • Mob paths are synchronous
  • Player paths claim cooldown before any await
⚠️ Do NOT add await between params mutation and damage calculation.

Troubleshooting

Mob Not Using Ranged/Magic

Symptoms:
  • Mob uses melee animation instead of ranged/magic
  • No projectile appears
Fixes:
  1. Verify attackType is set in NPC combat config
  2. For magic: Verify spellId is specified
  3. For ranged: Verify arrowId is specified
  4. Check console for warnings:
    • "Mob X has no spellId configured"
    • "Mob X has no arrowId configured"

Weapon Not Showing on Mob

Symptoms:
  • Mob attacks correctly but no weapon visible
Fixes:
  1. Verify heldWeaponModel uses asset:// prefix
  2. Verify weapon GLB exists in assets directory
  3. Check browser console for GLTF load errors
  4. Ensure CDN is running (bun run cdn:up)

Wrong Projectile Visual

Symptoms:
  • Projectile appears but wrong color/type
Fixes:
  1. For magic: Verify spellId matches spell data
    • Check packages/shared/src/data/combat-spells.ts
  2. For ranged: Verify arrowId matches ammunition data
    • Check packages/shared/src/data/ammunition.ts

Rollback Instructions

If you need to rollback to v2.x:
Note: Rolling back will disable mob ranged/magic attacks. Existing NPC manifests with attackType: "ranged" or attackType: "magic" will fall back to melee.

Support

For questions or issues:
Migration Guide for Hyperscape v3.0