Summary
Implement the Castle Siege NPC types: Castle Gates, Guardian Statues, Crown, Crown Switches, Gate Levers, and Siege Machines. This includes NPC classes, AI intelligence plug-ins, the upgrade/buy/repair system, and gate terrain blocking.
Prerequisites
Background
OpenMU NPC hierarchy:
NonPlayerCharacter — base NPC (not attackable).
AttackableNpcBase : NonPlayerCharacter — attackable, has IAttributeSystem, MagicEffectsList.
Monster : AttackableNpcBase — full AI with movement, attack, drops.
Destructible : AttackableNpcBase — attackable but no AI/movement/attack.
NPC AI is provided via INpcIntelligence implementations wired through PlugInManager.
The Valley of Loren map (Persistence/Initialization/VersionSeasonSix/Maps/ValleyOfLoren.cs) already defines spawn positions for Crown (NPC 216), Crown Switch 1 (217), Crown Switch 2 (218), Guard (220), Sinior (223), Guardsman (224).
Requirements
1. NPC Classes — New files in GameLogic/CastleSiege/NPC/
CastleSiegeGate : AttackableNpcBase
- Monster ID 277.
- Attackable, no movement, no attack ability.
- Tracks upgrade levels:
DefenseLevel, LifeLevel.
- Can block terrain (6×2 tile area) when closed.
- State: open or closed.
- Override
OnDiedAsync to remove terrain blocking.
CastleSiegeStatue : AttackableNpcBase
- Monster ID 283.
- Attackable, no movement, no attack ability.
- Tracks upgrade levels:
DefenseLevel, LifeLevel, RegenLevel.
- Regenerates HP based on
RegenLevel (on AI tick).
CastleSiegeCrown : NonPlayerCharacter
- Monster ID 219.
- Non-attackable. Interactive.
- Tracks: current crown user, accumulated time, availability state.
- States: idle (0), locked (1), captured (2).
CastleSiegeSwitch : NonPlayerCharacter
- Two instances (ID 0 and ID 1).
- Non-attackable. Interactive.
- Tracks: current player standing on the switch.
CastleSiegeLever : NonPlayerCharacter
- Interactive NPC.
- Associates with a specific gate.
- On interaction: toggles the associated gate open/closed.
CastleSiegeMachine : NonPlayerCharacter
- Monster IDs 221 (attack) and 222 (defense).
- Interactive. Non-attackable.
- Tracks: current operator (Player), active state.
2. NPC Intelligence Plug-ins — New files in GameLogic/CastleSiege/Intelligence/
Each implements INpcIntelligence:
CastleSiegeGateIntelligence
- No autonomous behavior. Gate just exists and takes damage.
- On death: remove terrain blocking, update context.
CastleSiegeStatueIntelligence
- Regeneration tick: if
RegenLevel > 0 and IsAlive, restore HP periodically.
- Rate depends on regen level (from
CastleSiegeConfiguration.StatueRegenUpgrades).
CastleSiegeCrownIntelligence
- Track player proximity / interaction.
- If a player "stands on" the crown → set as crown user in
CastleSiegeContext.
- If the player leaves/dies → clear crown user, send
CrownAccessState.Fail.
- Accumulate time while player is on crown.
CastleSiegeSwitchIntelligence
- Track player proximity / interaction.
- If a player stands on the switch → set as switch user in
CastleSiegeContext.
- If the player leaves/dies → clear switch user.
- Report state changes to context for
SendSwitchInfo().
CastleSiegeLeverIntelligence
- No autonomous behavior.
- Responds to player interaction (talk/use) by toggling the associated gate.
CastleSiegeMachineIntelligence
- No autonomous behavior.
- Responds to player commands (Phase 8).
3. NPC Upgrade System
CastleSiegeNpcUpgradeAction — New file: GameLogic/CastleSiege/Actions/CastleSiegeNpcUpgradeAction.cs
Validation:
- Player is castle owner guild's master or
AssistantMaster.
- Current state is NOT
Start (can't upgrade during battle).
- Target NPC is alive and active.
- Current level < max level (3) for the requested upgrade type.
- Player has enough Zen and Jewels of Guardian (consume from inventory).
Effect:
- Increment the upgrade level on the NPC runtime and persisted state.
- Apply the stat change:
- Defense: Set monster's defense attribute to the value from
GateDefenseUpgrades / StatueDefenseUpgrades.
- Life: Set monster's max HP. Increase current HP by the difference.
- Regen: Increment regen level (used by statue AI).
- Persist
CastleSiegeNpcState.
- Send result to player.
CastleSiegeNpcBuyAction — New file: GameLogic/CastleSiege/Actions/CastleSiegeNpcBuyAction.cs
Re-purchase a destroyed NPC:
- Only castle owner guild master or assistant.
- NPC must not currently be alive.
- Player must have enough Zen (
GateBuyPrice or StatueBuyPrice).
- Reset upgrade levels to 0. Set initial HP.
- Spawn the NPC on the map.
CastleSiegeNpcRepairAction — New file: GameLogic/CastleSiege/Actions/CastleSiegeNpcRepairAction.cs
Restore NPC to full HP:
- Cost formula for Gate (277):
(MaxHP - CurrentHP) * 5 + defenseLevel * 1,000,000.
- Cost formula for Statue (283):
(MaxHP - CurrentHP) * 3 + (defenseLevel + regenLevel) * 1,000,000.
- Cannot repair during active battle.
4. Gate Terrain Blocking
CastleSiegeGateOperateAction — New file: GameLogic/CastleSiege/Actions/CastleSiegeGateOperateAction.cs
When a gate is closed (CloseCastleGate):
- Apply a terrain lock attribute to a 6×2 tile area around the gate position in
GameMapTerrain.
- This blocks player movement through the gate.
- Method: use
GameMapTerrain's attribute bytes (similar to safezone flags).
When a gate is opened (via lever interaction):
- Remove the terrain lock attribute from the same area.
Validation for gate operation:
- During
Start state: only Defense side can operate.
- Outside
Start state: only castle owner or alliance member.
5. NPC Lifecycle & Spawning
In CastleSiegePlugIn:
On Ready enter:
- Load
CastleSiegeNpcState records from DB.
- For each DB-persisted NPC definition in
CastleSiegeConfiguration.NpcDefinitions:
- If a saved state exists: apply upgrade levels and HP.
- Spawn the NPC on the Castle Siege map.
- Store reference in
CastleSiegeContext.ActiveNpcs.
- Close all gates and apply terrain blocking.
On Start enter:
- Spawn non-DB NPCs (machines) at their configured positions.
On End enter:
- Save all DB-persisted NPC states.
- Despawn all non-DB NPCs (machines).
Every 120 seconds (outside Start):
- Call
VerifyNpcExist() to sync runtime state with actual monster state.
- Call
SaveNpcStatesAsync() to persist.
6. NPC List Packet Handlers
CastleSiegeGateListHandlerPlugIn — handles C1-B3-01. Returns list of gate NPCs with upgrade levels and HP.
CastleSiegeStatueListHandlerPlugIn — handles C1-B3-02. Returns list of statue NPCs.
7. Message Handlers for Upgrade/Buy/Repair
CastleSiegeDefenseBuyHandlerPlugIn — C1-B2-05
CastleSiegeDefenseRepairHandlerPlugIn — C1-B2-06
CastleSiegeDefenseUpgradeHandlerPlugIn — C1-B2-07
CastleSiegeGateOperateHandlerPlugIn — C1-B2-12
Files to Create
| File |
Description |
GameLogic/CastleSiege/NPC/CastleSiegeGate.cs |
Gate NPC class |
GameLogic/CastleSiege/NPC/CastleSiegeStatue.cs |
Statue NPC class |
GameLogic/CastleSiege/NPC/CastleSiegeCrown.cs |
Crown NPC class |
GameLogic/CastleSiege/NPC/CastleSiegeSwitch.cs |
Switch NPC class |
GameLogic/CastleSiege/NPC/CastleSiegeLever.cs |
Lever NPC class |
GameLogic/CastleSiege/NPC/CastleSiegeMachine.cs |
Machine NPC class |
GameLogic/CastleSiege/Intelligence/CastleSiegeGateIntelligence.cs |
Gate AI |
GameLogic/CastleSiege/Intelligence/CastleSiegeStatueIntelligence.cs |
Statue AI |
GameLogic/CastleSiege/Intelligence/CastleSiegeCrownIntelligence.cs |
Crown AI |
GameLogic/CastleSiege/Intelligence/CastleSiegeSwitchIntelligence.cs |
Switch AI |
GameLogic/CastleSiege/Intelligence/CastleSiegeLeverIntelligence.cs |
Lever AI |
GameLogic/CastleSiege/Intelligence/CastleSiegeMachineIntelligence.cs |
Machine AI |
GameLogic/CastleSiege/Actions/CastleSiegeNpcUpgradeAction.cs |
Upgrade logic |
GameLogic/CastleSiege/Actions/CastleSiegeNpcBuyAction.cs |
Buy logic |
GameLogic/CastleSiege/Actions/CastleSiegeNpcRepairAction.cs |
Repair logic |
GameLogic/CastleSiege/Actions/CastleSiegeGateOperateAction.cs |
Gate open/close |
GameServer/MessageHandler/CastleSiege/CastleSiegeDefenseBuyHandlerPlugIn.cs |
Packet handler |
GameServer/MessageHandler/CastleSiege/CastleSiegeDefenseRepairHandlerPlugIn.cs |
Packet handler |
GameServer/MessageHandler/CastleSiege/CastleSiegeDefenseUpgradeHandlerPlugIn.cs |
Packet handler |
GameServer/MessageHandler/CastleSiege/CastleSiegeGateOperateHandlerPlugIn.cs |
Packet handler |
GameServer/MessageHandler/CastleSiege/CastleSiegeGateListHandlerPlugIn.cs |
Packet handler |
GameServer/MessageHandler/CastleSiege/CastleSiegeStatueListHandlerPlugIn.cs |
Packet handler |
Acceptance Criteria
Summary
Implement the Castle Siege NPC types: Castle Gates, Guardian Statues, Crown, Crown Switches, Gate Levers, and Siege Machines. This includes NPC classes, AI intelligence plug-ins, the upgrade/buy/repair system, and gate terrain blocking.
Prerequisites
CastleSiegeNpcState.CastleSiegeContextand event state awareness.Background
OpenMU NPC hierarchy:
NonPlayerCharacter— base NPC (not attackable).AttackableNpcBase : NonPlayerCharacter— attackable, hasIAttributeSystem,MagicEffectsList.Monster : AttackableNpcBase— full AI with movement, attack, drops.Destructible : AttackableNpcBase— attackable but no AI/movement/attack.NPC AI is provided via
INpcIntelligenceimplementations wired throughPlugInManager.The Valley of Loren map (
Persistence/Initialization/VersionSeasonSix/Maps/ValleyOfLoren.cs) already defines spawn positions for Crown (NPC 216), Crown Switch 1 (217), Crown Switch 2 (218), Guard (220), Sinior (223), Guardsman (224).Requirements
1. NPC Classes — New files in
GameLogic/CastleSiege/NPC/CastleSiegeGate : AttackableNpcBaseDefenseLevel,LifeLevel.OnDiedAsyncto remove terrain blocking.CastleSiegeStatue : AttackableNpcBaseDefenseLevel,LifeLevel,RegenLevel.RegenLevel(on AI tick).CastleSiegeCrown : NonPlayerCharacterCastleSiegeSwitch : NonPlayerCharacterCastleSiegeLever : NonPlayerCharacterCastleSiegeMachine : NonPlayerCharacter2. NPC Intelligence Plug-ins — New files in
GameLogic/CastleSiege/Intelligence/Each implements
INpcIntelligence:CastleSiegeGateIntelligenceCastleSiegeStatueIntelligenceRegenLevel > 0andIsAlive, restore HP periodically.CastleSiegeConfiguration.StatueRegenUpgrades).CastleSiegeCrownIntelligenceCastleSiegeContext.CrownAccessState.Fail.CastleSiegeSwitchIntelligenceCastleSiegeContext.SendSwitchInfo().CastleSiegeLeverIntelligenceCastleSiegeMachineIntelligence3. NPC Upgrade System
CastleSiegeNpcUpgradeAction— New file:GameLogic/CastleSiege/Actions/CastleSiegeNpcUpgradeAction.csValidation:
AssistantMaster.Start(can't upgrade during battle).Effect:
GateDefenseUpgrades/StatueDefenseUpgrades.CastleSiegeNpcState.CastleSiegeNpcBuyAction— New file:GameLogic/CastleSiege/Actions/CastleSiegeNpcBuyAction.csRe-purchase a destroyed NPC:
GateBuyPriceorStatueBuyPrice).CastleSiegeNpcRepairAction— New file:GameLogic/CastleSiege/Actions/CastleSiegeNpcRepairAction.csRestore NPC to full HP:
(MaxHP - CurrentHP) * 5 + defenseLevel * 1,000,000.(MaxHP - CurrentHP) * 3 + (defenseLevel + regenLevel) * 1,000,000.4. Gate Terrain Blocking
CastleSiegeGateOperateAction— New file:GameLogic/CastleSiege/Actions/CastleSiegeGateOperateAction.csWhen a gate is closed (
CloseCastleGate):GameMapTerrain.GameMapTerrain's attribute bytes (similar to safezone flags).When a gate is opened (via lever interaction):
Validation for gate operation:
Startstate: onlyDefenseside can operate.Startstate: only castle owner or alliance member.5. NPC Lifecycle & Spawning
In
CastleSiegePlugIn:On
Readyenter:CastleSiegeNpcStaterecords from DB.CastleSiegeConfiguration.NpcDefinitions:CastleSiegeContext.ActiveNpcs.On
Startenter:On
Endenter:Every 120 seconds (outside
Start):VerifyNpcExist()to sync runtime state with actual monster state.SaveNpcStatesAsync()to persist.6. NPC List Packet Handlers
CastleSiegeGateListHandlerPlugIn— handlesC1-B3-01. Returns list of gate NPCs with upgrade levels and HP.CastleSiegeStatueListHandlerPlugIn— handlesC1-B3-02. Returns list of statue NPCs.7. Message Handlers for Upgrade/Buy/Repair
CastleSiegeDefenseBuyHandlerPlugIn—C1-B2-05CastleSiegeDefenseRepairHandlerPlugIn—C1-B2-06CastleSiegeDefenseUpgradeHandlerPlugIn—C1-B2-07CastleSiegeGateOperateHandlerPlugIn—C1-B2-12Files to Create
GameLogic/CastleSiege/NPC/CastleSiegeGate.csGameLogic/CastleSiege/NPC/CastleSiegeStatue.csGameLogic/CastleSiege/NPC/CastleSiegeCrown.csGameLogic/CastleSiege/NPC/CastleSiegeSwitch.csGameLogic/CastleSiege/NPC/CastleSiegeLever.csGameLogic/CastleSiege/NPC/CastleSiegeMachine.csGameLogic/CastleSiege/Intelligence/CastleSiegeGateIntelligence.csGameLogic/CastleSiege/Intelligence/CastleSiegeStatueIntelligence.csGameLogic/CastleSiege/Intelligence/CastleSiegeCrownIntelligence.csGameLogic/CastleSiege/Intelligence/CastleSiegeSwitchIntelligence.csGameLogic/CastleSiege/Intelligence/CastleSiegeLeverIntelligence.csGameLogic/CastleSiege/Intelligence/CastleSiegeMachineIntelligence.csGameLogic/CastleSiege/Actions/CastleSiegeNpcUpgradeAction.csGameLogic/CastleSiege/Actions/CastleSiegeNpcBuyAction.csGameLogic/CastleSiege/Actions/CastleSiegeNpcRepairAction.csGameLogic/CastleSiege/Actions/CastleSiegeGateOperateAction.csGameServer/MessageHandler/CastleSiege/CastleSiegeDefenseBuyHandlerPlugIn.csGameServer/MessageHandler/CastleSiege/CastleSiegeDefenseRepairHandlerPlugIn.csGameServer/MessageHandler/CastleSiege/CastleSiegeDefenseUpgradeHandlerPlugIn.csGameServer/MessageHandler/CastleSiege/CastleSiegeGateOperateHandlerPlugIn.csGameServer/MessageHandler/CastleSiege/CastleSiegeGateListHandlerPlugIn.csGameServer/MessageHandler/CastleSiege/CastleSiegeStatueListHandlerPlugIn.csAcceptance Criteria
Startstate.