# MonsterSetBase

Controls where and how monsters spawn across all maps. Uses a master registry file that references per-map spawn files.

## File Location

**Master registry:** `GameServer/Data/Monster/MonsterSetBase.xml`

**Per-map spawns:** `GameServer/Data/Monster/MonsterSetBase/*.xml` (one file per map)

## Dependencies

| Depends On                                                                 | Purpose                                         |
| -------------------------------------------------------------------------- | ----------------------------------------------- |
| [Monster.xml](https://axiomemu.gitbook.io/docs/gameserver/monster/monster) | Spawns reference monster stats by Class (Index) |

| Used By     | Purpose                                            |
| ----------- | -------------------------------------------------- |
| Map loading | Server reads spawn files during map initialization |

## File Structure

### MonsterSetBase.xml (Master Registry - NOT USED)

The main file exists for legacy/compatibility but is **NOT loaded** by the server. All spawns are loaded from per-map files in the `MonsterSetBase/` folder.

```xml
<?xml version="1.0" ?>
<MonsterSetBase>
  <!-- This file is NOT read by the server -->
  <!-- All spawns come from MonsterSetBase/*.xml files -->
</MonsterSetBase>
```

{% hint style="warning" %}
**The server does NOT load MonsterSetBase.xml**. It only loads files from the `MonsterSetBase/` or `MonsterSetBaseCS/` folder via `LoadMapFolder()`. Any edits to the master XML file will have no effect. Always edit the per-map files in the folder.
{% endhint %}

### Per-Map Spawn Files

Each map has its own file: `MonsterSetBase/000 - Lorencia.xml`, `MonsterSetBase/001 - Dungeon.xml`, etc.

Map numbers match the game's internal map IDs (00 = Lorencia, 01 = Dungeon, 02 = Devias, etc.).

## Spawn Entry Attributes

| Attribute | Type   | Description                                                                |
| --------- | ------ | -------------------------------------------------------------------------- |
| `Type`    | int    | Spawn type (see Spawn Types below)                                         |
| `Class`   | int    | Monster Index from Monster.xml                                             |
| `Map`     | int    | Map number (00 = Lorencia, 01 = Dungeon, etc.)                             |
| `Dis`     | int    | Roaming distance from spawn point (in tiles)                               |
| `X`       | int    | Spawn X coordinate                                                         |
| `Y`       | int    | Spawn Y coordinate                                                         |
| `TX`      | int    | Target X coordinate (Type 1/3 only) - defines spawn area with X            |
| `TY`      | int    | Target Y coordinate (Type 1/3 only) - defines spawn area with Y            |
| `Dir`     | int    | Facing direction (0-7, or -1 for random)                                   |
| `Count`   | int    | Number of monsters to spawn (Type 1/3 only, minimum 1 if 0)                |
| `Value`   | int    | Event identifier (Type 3 only) - used by Invasion Manager to filter spawns |
| `Comment` | string | Description (optional, for admin reference)                                |

## Spawn Types

| Type | Name        | Behavior                                                                                          | Use Case                                    |
| ---- | ----------- | ------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| 0    | Fixed       | Single monster at exact X/Y, respawns at same location                                            | NPCs, guards, stationary bosses             |
| 1    | Group       | Count monsters spawn randomly between (X,Y) and (TX,TY), each respawns at random location in area | Normal hunting zones                        |
| 2    | Spot        | Single monster spawns at random location in X/Y±3 range (randomized at server start, then fixed)  | Scattered individual spawns                 |
| 3    | Event       | Count monsters for invasion events, uses Value for event filtering                                | Invasion Manager, White Wizard events       |
| 4    | Event Fixed | Single monster for event systems, spawns at exact X/Y                                             | Blood Castle, Devil Square, Illusion Temple |

### Type 0: Fixed Spawn

```xml
<Monster Type="0" Class="226" Map="00" Dis="00" X="122" Y="110" Dir="03" Comment="Trainer"/>
```

* Spawns exactly 1 monster at X=122, Y=110
* Dis="00" means monster cannot move (stuck in place)
* Dir="03" faces south (0=north, 1=NE, 2=east, 3=SE, etc.)
* Use for NPCs and bosses at specific locations

### Type 1: Group Spawn

```xml
<Monster Type="1" Class="003" Map="00" Dis="10" X="187" Y="121" TX="187" TY="121" Dir="-1" Count="007" Comment="Spider"/>
```

* Spawns 7 spiders randomly within a 10-tile radius of (187,121)
* TX/TY define the spawn area bounds (if different from X/Y, creates rectangular area)
* Dis="10" allows monsters to roam 10 tiles from their spawn point
* Dir="-1" means random facing direction
* Use for normal monster packs in hunting zones

### Type 2: Spot Spawn

```xml
<Monster Type="2" Class="028" Map="03" Dis="05" X="202" Y="155" Dir="-1" Comment="BeetleMonster"/>
```

* Spawns 1 monster at a random location within X±3, Y±3 tiles
* **Important**: Location is randomized ONCE when server starts, then becomes fixed
* After death, monster respawns at the same randomized location (not re-randomized)
* Good for scattered individual monsters that shouldn't cluster
* Commonly used in Noria for BeetleMonster and ForestMonster

### Type 3: Event Spawn (Invasion Manager)

```xml
<Monster Type="3" Class="089" Map="00" Dis="10" X="100" Y="100" TX="120" TY="120" Dir="-1" Count="010" Value="1" Comment="White Wizard Event"/>
```

* Similar to Type 1 but controlled by Invasion Manager and event systems
* Count monsters spawn randomly between (X,Y) and (TX,TY)
* **Value attribute** is used by event systems to filter/identify spawn groups
* Used by White Wizard invasions and custom event systems
* NOT directly used by Blood Castle, Devil Square (they use Type 4)

### Type 4: Event Fixed Spawn

```xml
<Monster Type="4" Class="131" Map="11" Dis="00" X="100" Y="100" Dir="03" Comment="Blood Castle Gate"/>
```

* Single monster at exact X/Y for event systems
* Behaves like Type 0 but filtered by event code (Type 3/4 are excluded from normal spawns)
* Used by Blood Castle, Devil Square, Illusion Temple, Imperial Guardian, Raklion
* Event systems programmatically control when these spawns are activated

## Direction Values

| Dir | Direction     | Dir | Direction     |
| --- | ------------- | --- | ------------- |
| 0   | North (↑)     | 4   | South (↓)     |
| 1   | Northeast (↗) | 5   | Southwest (↙) |
| 2   | East (→)      | 6   | West (←)      |
| 3   | Southeast (↘) | 7   | Northwest (↖) |
| -1  | Random        |     |               |

## Important Behavior

### Spawn Timing

{% hint style="info" %}
**Initial spawn**: All Type 0, 1, and 2 monsters spawn when the GameServer starts and loads maps. Type 3 and 4 are skipped during normal spawn and only activated by event systems.

**Respawn**: After death, monsters respawn based on their `RegenTime` in Monster.xml. The respawn location depends on spawn type:

* Type 0/4: Exact same X/Y location
* Type 1/3: New random location within the spawn area
* Type 2: Same randomized location (not re-randomized)
  {% endhint %}

### Coordinate System

* Coordinates are in tiles (not pixels)
* Origin (0,0) is typically top-left corner
* Maximum coordinates vary by map (usually 255x255 or similar)
* Invalid coordinates = monster spawns but is unreachable/invisible

### Dis (Roaming Distance)

* Dis="00" = Monster cannot move (stays at spawn point)
* Dis="10" = Monster can wander up to 10 tiles from spawn point before AI forces return
* Distance is calculated as Euclidean distance from spawn point (sqrt formula)
* Too high Dis on maps with walls = monsters may appear to walk through walls when returning
* NPCs should always have Dis="00" to prevent walking away

{% hint style="warning" %}
The roaming distance check uses **spawn point** (StartX/StartY), not the original config X/Y. For Type 2, this means the monster roams from its randomized location, not the original config coordinates.
{% endhint %}

### Count Behavior

Type 1 and 3 spawn exactly `Count` monsters:

* Count="007" spawns 7 monsters
* Count="000" spawns 1 monster (zero is converted to 1 automatically)
* Each monster spawns at a random point within the spawn area
* When one dies, it respawns at a new random location in the same area (Type 1/3 only)

### TX/TY as Spawn Area

For Type 1/3, (X,Y) and (TX,TY) define a rectangular spawn area:

* If TX=X and TY=Y, spawns are clustered around that point
* If TX≠X or TY≠Y, spawns are spread across the rectangle
* Example: X="100" Y="100" TX="120" TY="120" = 20x20 tile spawn zone
* The system tries up to 100 times to find a walkable location in the area

### Event Spawn Filtering (Type 3/4)

{% hint style="info" %}
Type 3 and 4 spawns are **NOT included** in the normal monster spawn during map initialization. They are filtered out and only activated by event systems:

* **Type 3**: Invasion Manager uses the `Value` attribute to match spawn groups
* **Type 4**: Blood Castle, Devil Square, Illusion Temple, Imperial Guardian, and Raklion use `MonsterClass` and `Map` to find specific spawns

This allows event monsters to be defined alongside normal monsters without interfering with regular gameplay.
{% endhint %}

## Examples

{% tabs %}
{% tab title="NPC (Fixed)" %}

```xml
<Monster Type="0" Class="226" Map="00" Dis="00" X="122" Y="110" Dir="03" Comment="Trainer"/>
```

Spawns Trainer NPC at fixed location in Lorencia, cannot move (Dis=0), faces southeast.
{% endtab %}

{% tab title="Monster Group" %}

```xml
<Monster Type="1" Class="000" Map="00" Dis="10" X="201" Y="069" TX="201" TY="069" Dir="-1" Count="007" Comment="BullFighter"/>
```

Spawns 7 Bull Fighters around (201,69) with 10-tile roaming range, random facing.
{% endtab %}

{% tab title="Scattered Spawns" %}

```xml
<Monster Type="1" Class="003" Map="00" Dis="10" X="140" Y="080" TX="220" TY="180" Dir="-1" Count="050" Comment="Spider Zone"/>
```

Spawns 50 Spiders across an 80x100 tile zone (from 140,80 to 220,180), creating a dense hunting area.
{% endtab %}

{% tab title="Boss Spawn" %}

```xml
<Monster Type="0" Class="018" Map="00" Dis="05" X="125" Y="125" Dir="00" Comment="Gorgon Boss"/>
```

Spawns Gorgon boss at (125,125), can move 5 tiles, faces north. Respawn time controlled by Monster.xml RegenTime.
{% endtab %}

{% tab title="Event Spawn (Blood Castle)" %}

```xml
<Monster Type="4" Class="131" Map="11" Dis="00" X="015" Y="075" Dir="00" Comment="Blood Castle Gate"/>
```

Defines gate spawn for Blood Castle event. Type 4 means it won't spawn during normal map initialization - only when Blood Castle event activates.
{% endtab %}

{% tab title="Scattered Individual Monsters" %}

```xml
<Monster Type="2" Class="028" Map="03" Dis="05" X="202" Y="155" Dir="-1" Comment="BeetleMonster"/>
<Monster Type="2" Class="028" Map="03" Dis="05" X="212" Y="157" Dir="-1" Comment="BeetleMonster"/>
```

Each monster spawns at a randomized location (±3 tiles) when server starts. After that, each respawns at its own fixed location. Creates scattered but predictable spawns.
{% endtab %}
{% endtabs %}

## Per-Map Spawn Files

Each map has its own spawn file. Common maps:

| Map ID | File                                                     | Map Name     |
| ------ | -------------------------------------------------------- | ------------ |
| 00     | `000 - Lorencia.xml`                                     | Lorencia     |
| 01     | `001 - Dungeon.xml`                                      | Dungeon      |
| 02     | `002 - Devias.xml`                                       | Devias       |
| 03     | `003 - Noria.xml`                                        | Noria        |
| 04     | `004 - Lost Tower.xml`                                   | Lost Tower   |
| 07     | `007 - Atlans.xml`                                       | Atlans       |
| 08     | `008 - Tarkan.xml`                                       | Tarkan       |
| 11-17  | `011 - Blood Castle 1.xml` to `017 - Blood Castle 7.xml` | Blood Castle |
| 24-29  | `024 - Kalima 1.xml` to `029 - Kalima 6.xml`             | Kalima       |
| 37-39  | `037 - Kanturu 1.xml` to `039 - Kanturu 3.xml`           | Kanturu      |

{% hint style="info" %}
When adding spawns to a map, edit the corresponding map file (e.g., `000 - Lorencia.xml` for Lorencia spawns), not the master MonsterSetBase.xml.
{% endhint %}

## Common Tasks

### Add Monster Spawn to Map

1. Find the map file (e.g., `002 - Devias.xml`)
2. Add a new `<Monster>` entry
3. Set Type (usually 1 for monster groups)
4. Set Class to monster Index from Monster.xml
5. Set X/Y coordinates and Count

### Increase Monster Density

Find existing spawn entries and increase `Count`:

```xml
<!-- Before -->
<Monster Type="1" Class="003" Map="00" Dis="10" X="187" Y="121" TX="187" TY="121" Dir="-1" Count="007" Comment="Spider"/>

<!-- After -->
<Monster Type="1" Class="003" Map="00" Dis="10" X="187" Y="121" TX="187" TY="121" Dir="-1" Count="020" Comment="Spider"/>
```

### Create Dense Hunting Zone

Add multiple spawn entries with overlapping areas:

```xml
<Monster Type="1" Class="005" Map="02" Dis="10" X="100" Y="100" TX="120" TY="120" Dir="-1" Count="015"/>
<Monster Type="1" Class="005" Map="02" Dis="10" X="110" Y="110" TX="130" TY="130" Dir="-1" Count="015"/>
<Monster Type="1" Class="005" Map="02" Dis="10" X="120" Y="100" TX="140" TY="120" Dir="-1" Count="015"/>
```

Creates 45 Hell Hounds across overlapping zones for intense hunting.

### Remove Monster from Map

Delete or comment out the spawn entry:

```xml
<!-- <Monster Type="1" Class="003" Map="00" Dis="10" X="187" Y="121" TX="187" TY="121" Dir="-1" Count="007" Comment="Spider"/> -->
```

### Move Boss Location

Change X and Y coordinates:

```xml
<!-- Before -->
<Monster Type="0" Class="018" Map="01" Dis="05" X="125" Y="125" Dir="00" Comment="Gorgon"/>

<!-- After -->
<Monster Type="0" Class="018" Map="01" Dis="05" X="200" Y="200" Dir="00" Comment="Gorgon"/>
```

## Common Issues

{% hint style="warning" %}
**Monsters spawn inside walls.** Check that X/Y coordinates are on walkable terrain. Use in-game /move command to verify coordinates are valid.
{% endhint %}

{% hint style="warning" %}
**Count="000" spawns 1 monster, not 0** (only for Type 1/3). The code automatically converts Count=0 to Count=1. To disable a spawn, delete the entry or comment it out with `<!-- -->`.
{% endhint %}

{% hint style="warning" %}
**Changes don't appear immediately.** Monsters already spawned remain until they die. For immediate updates, restart the GameServer or use /reload commands if available.
{% endhint %}

{% hint style="info" %}
**Dis too high causes wall clipping.** If monsters appear to walk through walls, reduce their Dis value to keep them within the intended area. The pathfinding return-to-spawn logic can cause monsters to walk through obstacles.
{% endhint %}

{% hint style="warning" %}
**Type 2 spawns are unpredictable between server restarts.** Each Type 2 spawn randomizes location when the server starts. Restarting the server will place the monster at a different random location within the ±3 tile range. This makes Type 2 unsuitable for precise placement needs.
{% endhint %}

{% hint style="danger" %}
**Too many spawns cause lag.** The server has a hard limit of MAX\_MSB\_MONSTER = 10000 total spawn entries across ALL maps. This counts individual spawn slots, not Count multiplier. Example: Type 1 with Count="050" creates 50 spawn slots. Monitor total spawn count when adding large groups.
{% endhint %}

{% hint style="info" %}
**LoadMapFolder behavior**: The server loads all .xml files from `MonsterSetBase/` or `MonsterSetBaseCS/` folder (depending on server type). The master `MonsterSetBase.xml` file is NOT loaded - all spawns come from per-map files in the folder.
{% endhint %}
