feat(CS-P2): Guardsman (NPC 224) talk handler -> register guild during registration phase
Some checks failed
.NET Core / build (push) Has been cancelled

This commit is contained in:
Acentech Dev
2026-07-14 23:11:35 +03:00
parent 268d40acd1
commit 44dcb2fd58

View File

@@ -0,0 +1,74 @@
// <copyright file="CastleSiegeGuardsmanTalkPlugIn.cs" company="MUnique">
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
// </copyright>
namespace MUnique.OpenMU.GameLogic.CastleSiege;
using System.Runtime.InteropServices;
using MUnique.OpenMU.GameLogic.NPC;
using MUnique.OpenMU.GameLogic.PlugIns;
using MUnique.OpenMU.GameLogic.PlugIns.PeriodicTasks;
using MUnique.OpenMU.GameLogic.Views;
using MUnique.OpenMU.Interfaces;
using MUnique.OpenMU.PlugIns;
/// <summary>
/// Handles talking to the Castle Siege 'Guardsman' NPC (number 224): registers the talking
/// player's guild for the current siege while the state machine is in the registration phase.
/// P2 first increment — guild marks, entrance fee and minimum-guild requirements come later.
/// </summary>
[Guid("CA5710A0-7A1B-4C2D-8E3F-000000000224")]
[PlugIn]
[Display(Name = "Castle Siege Guardsman", Description = "Registers a guild for the Castle Siege when talking to the Guardsman (NPC 224).")]
public class CastleSiegeGuardsmanTalkPlugIn : IPlayerTalkToNpcPlugIn
{
/// <summary>Gets the NPC number of the Castle Siege 'Guardsman'.</summary>
public static short GuardsmanNpcNumber => 224;
/// <inheritdoc />
public async ValueTask PlayerTalksToNpcAsync(Player player, NonPlayerCharacter npc, NpcTalkEventArgs eventArgs)
{
if (npc.Definition.Number != GuardsmanNpcNumber)
{
return;
}
// We handle the dialog ourselves (no client-side window), so suppress the default "not implemented" message.
eventArgs.HasBeenHandled = true;
var context = CastleSiegeEventPlugIn.TryGetContext(player.GameContext);
if (context is null)
{
await ShowAsync(player, "Castle Siege is not active on this server.").ConfigureAwait(false);
return;
}
if (context.Phase != CastleSiegePhase.Registration)
{
await ShowAsync(player, "Castle Siege registration is not open right now.").ConfigureAwait(false);
return;
}
if (player.GuildStatus is not { } guildStatus || guildStatus.Position != GuildPosition.GuildMaster)
{
await ShowAsync(player, "Only a guild master can register for the Castle Siege.").ConfigureAwait(false);
return;
}
var guildName = guildStatus.GuildId.ToString();
if (player.GameContext is IGameServerContext serverContext)
{
var guild = await serverContext.GuildServer.GetGuildAsync(guildStatus.GuildId).ConfigureAwait(false);
if (guild?.Name is { Length: > 0 } name)
{
guildName = name;
}
}
context.RegisterGuild(guildName);
await ShowAsync(player, $"Your guild '{guildName}' is registered for the Castle Siege.").ConfigureAwait(false);
}
private static ValueTask ShowAsync(Player player, string text)
=> player.InvokeViewPlugInAsync<IShowMessagePlugIn>(p => p.ShowMessageAsync(text, MessageType.BlueNormal));
}