Overview
The spawn management system handles NPC spawning, respawning, territory-based spawning, and spawn data persistence in L2J Mobius Chronicle 4. Key Classes:org.l2jmobius.gameserver.model.Spawn- Individual spawn instanceorg.l2jmobius.gameserver.data.xml.SpawnData- XML spawn loader (singleton)org.l2jmobius.gameserver.data.SpawnTable- Central spawn registry (singleton)org.l2jmobius.gameserver.managers.DayNightSpawnManager- Day/night spawn control
Spawn Class
Location:org.l2jmobius.gameserver.model.Spawn
Represents a single NPC spawn point with respawn mechanics.
Constructor
Core Properties
Maximum number of NPCs this spawn manages.
Current number of spawned NPCs (read-only).
Minimum respawn delay in milliseconds.
Maximum respawn delay in milliseconds.
Whether automatic respawning is enabled.
Key Methods
Initialization
Initializes the spawn and creates all NPCs.Process:
- Spawns NPCs until
_currentCountreaches_maximumCount - Sets
_doRespawnbased on respawn delay (enabled if > 0)
Spawns a single NPC instance.Parameters:
isSummonSpawn- If true, shows summon animation
null on failureProcess:- Creates NPC from template using reflection
- Sets instance ID
- Calculates spawn position (random if territory-based)
- Corrects Z coordinate using GeoEngine
- Sets HP/MP to maximum
- Sets random or fixed heading
- Spawns NPC into world
- Increments
_currentCount
Respawn Control
Handles NPC death and schedules respawn.Process:
- Decrements
_currentCount - Removes NPC from spawn list
- If respawn enabled and under max count:
- Increments
_scheduledCount - Schedules respawn via
RespawnTaskManager - Uses random delay if
_respawnMaxDelaydiffers from_respawnMinDelay
- Increments
Immediately respawns an NPC.Reinitializes the NPC at spawn location (used by RespawnTaskManager).
Location Management
Sets spawn coordinates (inherited from Location).
Sets spawn location from Location object.
Sets spawn territory for random position spawning.When territory is set, NPCs spawn at random positions within the territory boundaries.
Checks if spawn uses territory-based positioning.Returns:
true if territory is set and X/Y coordinates are 0Respawn Timing
Sets respawn delay with optional randomization.Parameters:Converted to milliseconds internally:
delay- Base respawn delay in secondsrandomInterval- Random variance in seconds (±)
_respawnMinDelay = (delay - randomInterval) * 1000_respawnMaxDelay = (delay + randomInterval) * 1000
Gets average respawn delay.Returns: Average of min and max delays in milliseconds
Checks if respawn has random component.
Other Properties
Sets maximum chase distance for monsters.NPCs won’t pursue targets beyond this range from spawn point.
Enables/disables random walking.
Sets spawn identifier name.
Spawned NPC Tracking
Gets all NPCs currently spawned by this spawn.Returns: Thread-safe deque of spawned NPCs
Gets the most recently spawned NPC.
SpawnData
Location:org.l2jmobius.gameserver.data.xml.SpawnData
Loads and manages NPC spawns from XML files.
Singleton Pattern
XML Spawn Format
File Location:data/spawns/
Key Methods
Adds a new spawn and persists to XML.Process:
- Adds to SpawnTable
- Determines XML file based on world tile coordinates
- Appends spawn entry to existing file or creates new one
- Creates directory
data/spawns/Others/if needed
Removes spawn from table and XML file.Process:
- Removes from SpawnTable
- Locates XML file
- Removes matching spawn entry
- Deletes file if it becomes empty
Gets the XML file path for a spawn template ID.
Territory Shapes
Supported Shapes:-
NPoly - N-sided polygon (3+ vertices)
-
Cuboid - Rectangular box (2 vertices)
-
Cylinder - Circular area (1 center point + radius)
Banned Territories
Exclude areas within spawn territories:SpawnTable
Location:org.l2jmobius.gameserver.data.SpawnTable
Central registry for all active spawns.
Singleton Pattern
Key Methods
Gets complete spawn table.Returns: Map of NPC ID → Set of spawns
Gets all spawns for an NPC ID.Returns: Set of spawns or empty set if none
Counts spawns for an NPC.
Gets any spawn for an NPC ID.Returns: First spawn found or
nullRegisters a spawn.Creates new spawn set if needed (thread-safe).
Unregisters a spawn.Removes spawn set if it becomes empty.
Usage Examples
Create and Initialize Spawn
Territory-Based Spawning
Day/Night Spawns
Query Spawns from Table
Dynamic Spawn Creation
Delete Spawn
Stop/Start Respawning
Random Spawn System
If enabled in configuration (RandomSpawnsConfig.ENABLE_RANDOM_MONSTER_SPAWNS):
- Heading must not be -1 (fixed heading disables random)
- Must be monster (not NPC/quest monster)
- Not in water zone
- Not raid/minion/flying
- Not in instance
- Not in exclusion list
Related Systems
- RespawnTaskManager - Schedules NPC respawns
- DayNightSpawnManager - Manages day/night creature spawning
- RaidBossSpawnManager - Handles raid boss spawns
- GrandBossManager - Manages grand boss spawns
- NpcPersonalAIData - Custom AI parameters per spawn
- ZoneManager - Spawn territory management
Source Reference
- Source:
java/org/l2jmobius/gameserver/model/Spawn.java:50 - Source:
java/org/l2jmobius/gameserver/data/xml/SpawnData.java:62 - Source:
java/org/l2jmobius/gameserver/data/SpawnTable.java:33