ModernUO/Projects/UOContent/Engines/Quests/Collector/Mobiles/Impresario.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

164 lines
4.3 KiB
C#

using ModernUO.Serialization;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Engines.Quests.Collector;
[SerializationGenerator(0, false)]
public partial class Impresario : BaseQuester
{
[Constructible]
public Impresario() : base("the impresario")
{
}
public override void InitBody()
{
InitStats(100, 100, 25);
Hue = Race.Human.RandomSkinHue();
Female = false;
Body = 0x190;
Name = NameList.RandomName("male");
}
public override void InitOutfit()
{
AddItem(new FancyShirt(Utility.RandomDyedHue()));
AddItem(new LongPants(Utility.RandomNondyedHue()));
AddItem(new Shoes(Utility.RandomNeutralHue()));
Utility.AssignRandomHair(this);
Utility.AssignRandomFacialHair(this);
}
public override bool CanTalkTo(PlayerMobile to) =>
to.Quest is CollectorQuest qs && qs.IsObjectiveInProgress(typeof(FindSheetMusicObjective));
public override void OnTalk(PlayerMobile player, bool contextMenu)
{
var qs = player.Quest;
if (qs is not CollectorQuest)
{
return;
}
var obj = qs.FindObjective<FindSheetMusicObjective>();
if (obj?.Completed == false)
{
Direction = GetDirectionTo(player);
if (obj.IsInRightTheater())
{
SheetMusicOfferGump.DisplayTo(player);
}
else
{
qs.AddConversation(new NoSheetMusicConversation());
}
}
}
}
public class SheetMusicOfferGump : BaseQuestGump
{
public override bool Singleton => true;
private SheetMusicOfferGump() : base(75, 25)
{
}
public static void DisplayTo(Mobile from)
{
if (from?.NetState == null)
{
return;
}
from.SendGump(new SheetMusicOfferGump());
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
builder.AddPage();
builder.AddImage(349, 10, 0x24B0);
builder.AddImageTiled(349, 130, 100, 120, 0x24B3);
builder.AddImageTiled(149, 10, 200, 140, 0x24AF);
builder.AddImageTiled(149, 300, 200, 140, 0x24B5);
builder.AddImage(349, 300, 0x24B6);
builder.AddImage(35, 10, 0x24AE);
builder.AddImageTiled(35, 150, 120, 100, 0x24B1);
builder.AddImage(35, 300, 0x24B4);
builder.AddHtmlLocalized(110, 60, 200, 20, 1049069, White); // <STRONG>Conversation Event</STRONG>
builder.AddImage(65, 14, 0x2776);
builder.AddImageTiled(81, 14, 349, 17, 0x2775);
builder.AddImage(426, 14, 0x2778);
builder.AddImageTiled(50, 37, 400, 376, 0xA40);
builder.AddAlphaRegion(50, 37, 400, 376);
builder.AddImage(0, 0, 0x28C8);
builder.AddImageTiled(75, 90, 200, 1, 0x238D);
builder.AddImage(75, 58, 0x2635);
builder.AddImage(380, 45, 0xDF);
// Sure, I have some sheet music for a Gabriel Piete song. I'd be happy to sell you a copy for 10 gold.
builder.AddHtmlLocalized(98, 140, 312, 200, 1055107, LightGreen, false, true);
builder.AddRadio(85, 350, 0x25F8, 0x25FB, true, 1);
builder.AddHtmlLocalized(120, 356, 280, 20, 1014088, White); // I accept.
builder.AddRadio(85, 385, 0x25F8, 0x25FB, false, 0);
builder.AddHtmlLocalized(120, 391, 280, 20, 1049012, White); // No thanks, I decline.
builder.AddButton(340, 390, 0xF7, 0xF8, 1);
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (info.ButtonID != 1 || !info.IsSwitched(1))
{
return;
}
if (sender.Mobile is not PlayerMobile player)
{
return;
}
var qs = player.Quest;
if (qs is not CollectorQuest)
{
return;
}
var obj = qs.FindObjective<FindSheetMusicObjective>();
if (obj?.Completed != false)
{
return;
}
if (player.Backpack?.ConsumeTotal(typeof(Gold), 10) == true || Banker.Withdraw(player, 10))
{
obj.Complete();
}
else
{
// You don't have enough gold to buy the sheet music.
player.SendLocalizedMessage(1055108);
}
}
}