feat(castle-siege): adopt the upstream Castle Siege data model and persistence

Brings in the database layer of upstream OpenMU PRs #754 and #860 without
touching AdaMu's working Castle Siege gameplay. This is purely additive: the
existing 5-phase implementation still runs exactly as before.

What is included:

- DataModel: CastleSiegeState (the original Season 6 values 0-9, which are
  exactly what the game client's CASTLESIEGE_STATE enum expects),
  CastleSiegeJoinSide, and the zone/NPC/upgrade definition types.
- Entities: CastleSiegeData, CastleSiegeGuildRegistration, CastleSiegeNpcState.
  These identify a guild by its persistent Guid rather than by name.
- Generated persistence: 8 BasicModel + 8 EntityFramework model classes,
  CastleSiegeExtensions, and the regenerated ExtendedTypeContext,
  MapsterConfigurator and GameConfiguration partials.
- Migrations: 20260730194321_AddCastleSiege and
  20260801162427_ConfigureCastleSiegePersistence, plus the model snapshot.
- EntityDataContext gains the two DbSets and the five model registrations.
- EntityFrameworkContextBase only publishes configuration changes for entities
  in the configuration schema, so siege state writes are no longer broadcast as
  configuration changes.

AdaMu-specific adaptations:

- UpdateVersion.AddCastleSiegeData is 105, not upstream's 100. AdaMu already
  ships 95-104, and the applied-update bookkeeping is keyed on this value, so a
  collision would skip or re-run updates on live databases.
- CastleSiegeInitializer does not seed a weekly StateSchedule. Upstream drives
  the cycle from a fixed Saturday schedule; AdaMu drives it manually from
  CastleSiegeEventPlugIn and the AdminPanel, so the schedule is left empty and
  nothing reads it.

The seeded NPC definitions match AdaMu's existing hard-coded coordinates
exactly (6 gates, the two crown switches and the crown), and additionally
provide 4 guardian statues, 6 guardsmen and real gate/statue hit point tables
that the current implementation does not have yet.

Two pre-existing migrations were restyled by upstream (copyright header, using
placement, trailing comma). No functional change.

Verified: full server build succeeds with 0 errors.
This commit is contained in:
Acentech Dev
2026-08-04 03:28:10 +03:00
parent 0fdb455cec
commit 3aa9815b10
42 changed files with 15383 additions and 7 deletions

View File

@@ -0,0 +1,343 @@
// <copyright file="20260801162427_ConfigureCastleSiegePersistence.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
#nullable disable
namespace MUnique.OpenMU.Persistence.EntityFramework.Migrations
{
using System;
using Microsoft.EntityFrameworkCore.Migrations;
/// <inheritdoc />
public partial class ConfigureCastleSiegePersistence : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_CastleSiegeMapDe~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_LandOfTrialsMapD~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_ItemDefinition_RewardItemDefinitio~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeNpcDefinition_MonsterDefinition_MonsterDefinitio~",
schema: "config",
table: "CastleSiegeNpcDefinition");
migrationBuilder.DropIndex(
name: "IX_CastleSiegeNpcDefinition_MonsterDefinitionId",
schema: "config",
table: "CastleSiegeNpcDefinition");
migrationBuilder.Sql(
"""
DO $$
BEGIN
IF EXISTS (SELECT 1 FROM config."CastleSiegeNpcDefinition" WHERE "MonsterDefinitionId" IS NULL) THEN
RAISE EXCEPTION 'CastleSiegeNpcDefinition contains rows without a MonsterDefinitionId. Repair or remove these rows before applying this migration.';
END IF;
END
$$;
""");
migrationBuilder.AlterColumn<Guid>(
name: "MonsterDefinitionId",
schema: "config",
table: "CastleSiegeNpcDefinition",
type: "uuid",
nullable: false,
oldClrType: typeof(Guid),
oldType: "uuid",
oldNullable: true);
migrationBuilder.AlterColumn<int>(
name: "RegisterMinMembers",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
defaultValue: 20,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AlterColumn<int>(
name: "RegisterMinLevel",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
defaultValue: 200,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AlterColumn<int>(
name: "MaxAttackingGuilds",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
defaultValue: 3,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.AlterColumn<int>(
name: "CrownHoldTimeSeconds",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
defaultValue: 30,
oldClrType: typeof(int),
oldType: "integer");
migrationBuilder.CreateTable(
name: "CastleSiegeGuildRegistration",
schema: "data",
columns: table => new
{
Id = table.Column<Guid>(type: "uuid", nullable: false),
GuildId = table.Column<Guid>(type: "uuid", nullable: false),
GuildName = table.Column<string>(type: "character varying(8)", maxLength: 8, nullable: false),
Marks = table.Column<int>(type: "integer", nullable: false),
RegistrationOrder = table.Column<int>(type: "integer", nullable: false),
},
constraints: table =>
{
table.PrimaryKey("PK_CastleSiegeGuildRegistration", x => x.Id);
table.ForeignKey(
name: "FK_CastleSiegeGuildRegistration_Guild_GuildId",
column: x => x.GuildId,
principalSchema: "guild",
principalTable: "Guild",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_CastleSiegeNpcState_MonsterNumber_InstanceId",
schema: "data",
table: "CastleSiegeNpcState",
columns: new[] { "MonsterNumber", "InstanceId" },
unique: true);
migrationBuilder.CreateIndex(
name: "IX_CastleSiegeNpcDefinition_MonsterDefinitionId_InstanceId",
schema: "config",
table: "CastleSiegeNpcDefinition",
columns: new[] { "MonsterDefinitionId", "InstanceId" });
migrationBuilder.CreateIndex(
name: "IX_CastleSiegeData_OwnerGuildId",
schema: "data",
table: "CastleSiegeData",
column: "OwnerGuildId");
migrationBuilder.CreateIndex(
name: "IX_CastleSiegeGuildRegistration_GuildId",
schema: "data",
table: "CastleSiegeGuildRegistration",
column: "GuildId",
unique: true);
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_CastleSiegeMapDe~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "CastleSiegeMapDefinitionId",
principalSchema: "config",
principalTable: "GameMapDefinition",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_LandOfTrialsMapD~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "LandOfTrialsMapDefinitionId",
principalSchema: "config",
principalTable: "GameMapDefinition",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_ItemDefinition_RewardItemDefinitio~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "RewardItemDefinitionId",
principalSchema: "config",
principalTable: "ItemDefinition",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeData_Guild_OwnerGuildId",
schema: "data",
table: "CastleSiegeData",
column: "OwnerGuildId",
principalSchema: "guild",
principalTable: "Guild",
principalColumn: "Id",
onDelete: ReferentialAction.SetNull);
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeNpcDefinition_MonsterDefinition_MonsterDefinitio~",
schema: "config",
table: "CastleSiegeNpcDefinition",
column: "MonsterDefinitionId",
principalSchema: "config",
principalTable: "MonsterDefinition",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_CastleSiegeMapDe~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_LandOfTrialsMapD~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeConfiguration_ItemDefinition_RewardItemDefinitio~",
schema: "config",
table: "CastleSiegeConfiguration");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeData_Guild_OwnerGuildId",
schema: "data",
table: "CastleSiegeData");
migrationBuilder.DropForeignKey(
name: "FK_CastleSiegeNpcDefinition_MonsterDefinition_MonsterDefinitio~",
schema: "config",
table: "CastleSiegeNpcDefinition");
migrationBuilder.DropTable(
name: "CastleSiegeGuildRegistration",
schema: "data");
migrationBuilder.DropIndex(
name: "IX_CastleSiegeNpcState_MonsterNumber_InstanceId",
schema: "data",
table: "CastleSiegeNpcState");
migrationBuilder.DropIndex(
name: "IX_CastleSiegeNpcDefinition_MonsterDefinitionId_InstanceId",
schema: "config",
table: "CastleSiegeNpcDefinition");
migrationBuilder.DropIndex(
name: "IX_CastleSiegeData_OwnerGuildId",
schema: "data",
table: "CastleSiegeData");
migrationBuilder.AlterColumn<Guid>(
name: "MonsterDefinitionId",
schema: "config",
table: "CastleSiegeNpcDefinition",
type: "uuid",
nullable: true,
oldClrType: typeof(Guid),
oldType: "uuid");
migrationBuilder.AlterColumn<int>(
name: "RegisterMinMembers",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer",
oldDefaultValue: 20);
migrationBuilder.AlterColumn<int>(
name: "RegisterMinLevel",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer",
oldDefaultValue: 200);
migrationBuilder.AlterColumn<int>(
name: "MaxAttackingGuilds",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer",
oldDefaultValue: 3);
migrationBuilder.AlterColumn<int>(
name: "CrownHoldTimeSeconds",
schema: "config",
table: "CastleSiegeConfiguration",
type: "integer",
nullable: false,
oldClrType: typeof(int),
oldType: "integer",
oldDefaultValue: 30);
migrationBuilder.CreateIndex(
name: "IX_CastleSiegeNpcDefinition_MonsterDefinitionId",
schema: "config",
table: "CastleSiegeNpcDefinition",
column: "MonsterDefinitionId");
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_CastleSiegeMapDe~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "CastleSiegeMapDefinitionId",
principalSchema: "config",
principalTable: "GameMapDefinition",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_GameMapDefinition_LandOfTrialsMapD~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "LandOfTrialsMapDefinitionId",
principalSchema: "config",
principalTable: "GameMapDefinition",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeConfiguration_ItemDefinition_RewardItemDefinitio~",
schema: "config",
table: "CastleSiegeConfiguration",
column: "RewardItemDefinitionId",
principalSchema: "config",
principalTable: "ItemDefinition",
principalColumn: "Id");
migrationBuilder.AddForeignKey(
name: "FK_CastleSiegeNpcDefinition_MonsterDefinition_MonsterDefinitio~",
schema: "config",
table: "CastleSiegeNpcDefinition",
column: "MonsterDefinitionId",
principalSchema: "config",
principalTable: "MonsterDefinition",
principalColumn: "Id");
}
}
}