ModernUO/Projects/UOContent/Engines/Quests/Core/QuestConversation.cs
Kamron Batman b90ac0d481
perf: Migrate Quest gumps to DynamicGump (#2416)
## Summary

Migrates the Quest system gumps from legacy `Gump` to `DynamicGump` / `StaticGump<T>`.

**Renames** `Engines/ML Quests/Gumps/BaseQuestGump` to **`BaseMLQuestGump`** to
disambiguate from the Core quest abstract (`Engines/Quests/Core/QuestSystem.cs`).
Both abstracts now extend `DynamicGump`.

**Abstract bases**:
- `Server.Engines.Quests.BaseQuestGump` (Core) - now `abstract DynamicGump`. Holds constants and a static `AddHtmlObject(ref DynamicGumpBuilder, ...)` helper. Concrete subclasses each provide their own `BuildLayout`.
- `Server.Engines.MLQuests.Gumps.BaseMLQuestGump` (ML, renamed) - now `abstract DynamicGump` with a `protected abstract BuildContent(ref DynamicGumpBuilder)` hook. The base's `BuildLayout` draws shared chrome (background art, frame, label header) and then invokes `BuildContent`; subclasses use `BuildPage`, `SetTitle`, `RegisterButton`, `SetPageCount`, and content helpers (`AddDescription`, `AddObjectives`, `AddObjectivesProgress`, `AddRewardsPage`, `AddRewards`, `AddConversation`).

**Concrete Core gumps** migrated to `DynamicGump`:
- `QuestCancelGump`, `QuestOfferGump` (Core), `QuestObjectivesGump`, `QuestConversationsGump`, `QuestLogUpdatedGump`, `QuestItemInfoGump`, `SheetMusicOfferGump` (Impresario), `PaintedImageGump` (renamed from `PaintedImage.InternalGump`).

**Concrete ML gumps** migrated to `DynamicGump` (extending `BaseMLQuestGump` or directly):
- `InfoNPCGump`, `QuestConversationGump`, `QuestLogDetailedGump`, `QuestLogGump`, `QuestOfferGump` (ML), `QuestReportBackGump`, `QuestRewardGump`, `QuestCancelConfirmGump`, `RaceChangeConfirmGump`.

**`StaticGump<T>` migrations**:
- `ScrollOfAbraxusGump` (Dark Tides). Its layout is a single hard-coded cliloc (1060116) with no per-instance dynamic content - safe to cache.

**Cliloc rule**: Every other quest dialog bakes per-instance cliloc IDs into its layout (quest titles, NPC names, race-specific prompts, era-conditional progress messages, escort destinations). Per the cliloc rule, baking different cliloc numbers into a cached layout would defeat `StaticGump<T>` caching - so all of these are `DynamicGump`.

**Signature changes** to support the migration:
- `QuestObjective.RenderMessage`/`RenderProgress` now take `ref DynamicGumpBuilder builder` (15 overrides updated across Collector, Solen Matriarch, Ambitious Solen Queen, Study of the Solen Hive, Terrible Hatchlings, The Summoning, Uzeraan Turmoil, Witch Apprentice, Emino's Undertaking).
- ML `BaseObjective.WriteToGump` / `BaseObjectiveInstance.WriteToGump` / `BaseReward.WriteToGump` now take `ref DynamicGumpBuilder` (KillObjective, GainSkillObjective, EscortObjective, CollectObjective, DeliverObjective, BaseReward).

**Empty-gump and `Singleton` rules**: All concrete gumps now have private constructors with static `DisplayTo` entry points that null-check the player NetState before allocation. All gumps that shouldn't stack are `Singleton => true`.

**External callers updated**: `MLQuest.SendOffer`/`OnRefuse`, `MLQuestEntry.SendProgressGump`/`SendRewardGump`/`SendReportBackGump`, `MLQuestSystem.QuestGumpRequest` and `ViewQuestsCommand`, `BoonCollector` (Darius/Nedrick), `SirHelper.OnDoubleClick` (no longer caches a single shared `InfoNPCGump` instance - `DisplayTo` constructs one per click and the gump's `Singleton => true` handles deduplication), `RaceChangeDeed.OnDoubleClick`, `PaintedImage.OnDoubleClick`, `ScrollOfAbraxus.OnDoubleClick`, `Impresario.OnTalk`, and `PlayerMobile`'s `BaseQuestGump` alias is now `BaseMLQuestGump`.

**Concrete subclasses found beyond the listed entry points**: `SheetMusicOfferGump` (in Impresario.cs), `PaintedImageGump` (was `PaintedImage.InternalGump`), `QuestObjectivesGump`, `QuestConversationsGump`, `QuestLogUpdatedGump`, `QuestItemInfoGump` (the Core base has these embedded across `QuestSystem.cs`/`QuestObjective.cs`/`QuestConversation.cs`/`QuestItemInfo.cs`).

**Code-standards cleanup**: Renamed legacy `m_X` private fields to `_x` in rewritten files; braces on all control flow.
2026-04-25 20:23:13 -07:00

155 lines
4.6 KiB
C#

using System.Collections.Generic;
using Server.Gumps;
using Server.Network;
namespace Server.Engines.Quests
{
public abstract class QuestConversation
{
public abstract int Message { get; }
public virtual QuestItemInfo[] Info => null;
public virtual bool Logged => true;
public QuestSystem System { get; set; }
public bool HasBeenRead { get; set; }
public virtual void BaseDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
switch (version)
{
case 0:
{
HasBeenRead = reader.ReadBool();
break;
}
}
ChildDeserialize(reader);
}
public virtual void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
}
public virtual void BaseSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.Write(HasBeenRead);
ChildSerialize(writer);
}
public virtual void ChildSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
}
public virtual void OnRead()
{
}
}
public class QuestConversationsGump : BaseQuestGump
{
private readonly List<QuestConversation> _conversations;
private QuestConversationsGump(List<QuestConversation> conversations) : base(30, 50) =>
_conversations = conversations;
public static void DisplayTo(Mobile from, QuestConversation conv)
{
if (from?.NetState == null || conv == null)
{
return;
}
from.SendGump(new QuestConversationsGump(new List<QuestConversation> { conv }));
}
public static void DisplayTo(Mobile from, List<QuestConversation> conversations)
{
if (from?.NetState == null || conversations == null || conversations.Count == 0)
{
return;
}
from.SendGump(new QuestConversationsGump(conversations));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
builder.AddPage();
builder.AddImage(349, 10, 9392);
builder.AddImageTiled(349, 130, 100, 120, 9395);
builder.AddImageTiled(149, 10, 200, 140, 9391);
builder.AddImageTiled(149, 250, 200, 140, 9397);
builder.AddImage(349, 250, 9398);
builder.AddImage(35, 10, 9390);
builder.AddImageTiled(35, 150, 120, 100, 9393);
builder.AddImage(35, 250, 9396);
builder.AddHtmlLocalized(110, 60, 200, 20, 1049069, White); // <STRONG>Conversation Event</STRONG>
builder.AddImage(65, 14, 10102);
builder.AddImageTiled(81, 14, 349, 17, 10101);
builder.AddImage(426, 14, 10104);
builder.AddImageTiled(55, 40, 388, 323, 2624);
builder.AddAlphaRegion(55, 40, 388, 323);
builder.AddImageTiled(75, 90, 200, 1, 9101);
builder.AddImage(75, 58, 9781);
builder.AddImage(380, 45, 223);
builder.AddButton(220, 335, 2313, 2312, 1);
builder.AddImage(0, 0, 10440);
builder.AddPage(1);
for (var i = 0; i < _conversations.Count; ++i)
{
var conv = _conversations[_conversations.Count - 1 - i];
if (i > 0)
{
builder.AddButton(65, 366, 9909, 9911, 0, GumpButtonType.Page, 1 + i);
builder.AddHtmlLocalized(90, 367, 50, 20, 1043354, Black); // Previous
builder.AddPage(1 + i);
}
AddHtmlObject(ref builder, 70, 110, 365, 220, conv.Message, LightGreen, false, true);
if (i > 0)
{
builder.AddButton(420, 366, 9903, 9905, 0, GumpButtonType.Page, i);
builder.AddHtmlLocalized(370, 367, 50, 20, 1043353, Black); // Next
}
}
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
for (var i = _conversations.Count - 1; i >= 0; --i)
{
var qc = _conversations[i];
if (!qc.HasBeenRead)
{
qc.HasBeenRead = true;
qc.OnRead();
}
}
}
}
}