Skip to content

Castle Siege NPCs (Gates, Statues, Crown, Switches, Levers) #725

@sven-n

Description

@sven-n

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

CastleSiegeNpcUpgradeActionNew 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.

CastleSiegeNpcBuyActionNew 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.

CastleSiegeNpcRepairActionNew 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

CastleSiegeGateOperateActionNew 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:

  1. Load CastleSiegeNpcState records from DB.
  2. 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.
  3. 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

  • CastleSiegeDefenseBuyHandlerPlugInC1-B2-05
  • CastleSiegeDefenseRepairHandlerPlugInC1-B2-06
  • CastleSiegeDefenseUpgradeHandlerPlugInC1-B2-07
  • CastleSiegeGateOperateHandlerPlugInC1-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

  • Gates can be spawned, take damage, die, and be re-purchased.
  • Statues regenerate HP based on regen upgrade level.
  • NPCs can be upgraded (defense, life, regen) with correct cost validation.
  • Gate terrain blocking prevents player movement through closed gates.
  • Gate levers correctly toggle gates open/closed with proper side validation.
  • Crown tracks the current user and accumulated time.
  • Switches track occupant players.
  • NPC state persists between server restarts (upgrade levels, HP).
  • Non-DB NPCs (machines) only exist during the Start state.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions