ModernUO/Projects/UOContent/Engines/Quests/Study of the Solen Hive/Objectives.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

188 lines
6.5 KiB
C#

using System;
using System.Collections.Generic;
using Server.Gumps;
namespace Server.Engines.Quests.Naturalist
{
public class StudyNestsObjective : QuestObjective
{
private readonly List<NestArea> m_StudiedNests = new();
private NestArea m_CurrentNest;
private DateTime m_StudyBegin;
private StudyState m_StudyState;
public override int Message => 1054044;
public override int MaxProgress => NestArea.NonSpecialCount;
public bool StudiedSpecialNest { get; private set; }
public override bool GetTimerEvent() => true;
public override void CheckProgress()
{
var from = System.From;
if (m_CurrentNest != null)
{
var nest = m_CurrentNest;
if ((from.Map == Map.Trammel || from.Map == Map.Felucca) && nest.Contains(from.Location))
{
if (m_StudyState != StudyState.Inactive)
{
var time = Core.Now - m_StudyBegin;
if (time > TimeSpan.FromSeconds(30.0))
{
m_StudiedNests.Add(nest);
m_StudyState = StudyState.Inactive;
if (m_CurrentNest.Special)
{
// You complete your examination of this bizarre Egg Nest. The Naturalist will undoubtedly be quite interested in these notes!
from.SendLocalizedMessage(1054057);
StudiedSpecialNest = true;
}
else
{
// You have completed your study of this Solen Egg Nest. You put your notes away.
from.SendLocalizedMessage(1054054);
CurProgress++;
}
}
else if (m_StudyState == StudyState.FirstStep && time > TimeSpan.FromSeconds(15.0))
{
if (!nest.Special)
{
// You begin recording your completed notes on a bit of parchment.
from.SendLocalizedMessage(1054058);
}
m_StudyState = StudyState.SecondStep;
}
}
}
else
{
if (m_StudyState != StudyState.Inactive)
{
// You abandon your study of the Solen Egg Nest without gathering the needed information.
from.SendLocalizedMessage(1054046);
}
m_CurrentNest = null;
}
}
else if (from.Map == Map.Trammel || from.Map == Map.Felucca)
{
var nest = NestArea.Find(from.Location);
if (nest != null)
{
m_CurrentNest = nest;
m_StudyBegin = Core.Now;
if (m_StudiedNests.Contains(nest))
{
m_StudyState = StudyState.Inactive;
// You glance at the Egg Nest, realizing you've already studied this one.
from.SendLocalizedMessage(1054047);
}
else
{
m_StudyState = StudyState.FirstStep;
if (nest.Special)
{
// You notice something very odd about this Solen Egg Nest. You begin taking notes.
from.SendLocalizedMessage(105405);
}
else
{
// You begin studying the Solen Egg Nest to gather information.
from.SendLocalizedMessage(1054045);
}
if (from.Female)
{
from.PlaySound(0x30B);
}
else
{
from.PlaySound(0x419);
}
}
}
}
}
public override void RenderProgress(ref DynamicGumpBuilder builder)
{
if (!Completed)
{
builder.AddHtmlLocalized(70, 260, 270, 100, 1054055, BaseQuestGump.Blue); // Solen Nests Studied :
builder.AddLabel(70, 280, 0x64, $"{CurProgress}");
builder.AddLabel(100, 280, 0x64, "/");
builder.AddLabel(130, 280, 0x64, $"{MaxProgress}");
}
else
{
base.RenderProgress(ref builder);
}
}
public override void OnComplete()
{
System.AddObjective(new ReturnToNaturalistObjective());
}
public override void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
var count = reader.ReadEncodedInt();
for (var i = 0; i < count; i++)
{
var nest = NestArea.GetByID(reader.ReadEncodedInt());
m_StudiedNests.Add(nest);
}
StudiedSpecialNest = reader.ReadBool();
}
public override void ChildSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.WriteEncodedInt(m_StudiedNests.Count);
foreach (var nest in m_StudiedNests)
{
writer.WriteEncodedInt(nest.ID);
}
writer.Write(StudiedSpecialNest);
}
private enum StudyState
{
Inactive,
FirstStep,
SecondStep
}
}
public class ReturnToNaturalistObjective : QuestObjective
{
public override int Message => 1054048;
public override void RenderProgress(ref DynamicGumpBuilder builder)
{
builder.AddHtmlLocalized(70, 260, 270, 100, 1054055, BaseQuestGump.Blue); // Solen Nests Studied :
builder.AddLabel(70, 280, 0x64, $"{NestArea.NonSpecialCount}");
builder.AddLabel(100, 280, 0x64, "/");
builder.AddLabel(130, 280, 0x64, $"{NestArea.NonSpecialCount}");
}
}
}