ModernUO/Projects/UOContent/Engines/Quests/Witch Apprentice/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

464 lines
13 KiB
C#

using System;
using Server.Gumps;
using Server.Items;
using Server.Mobiles;
namespace Server.Engines.Quests.Hag
{
public class FindApprenticeObjective : QuestObjective
{
private static readonly Point3D[] m_CorpseLocations =
{
new(778, 1158, 0),
new(698, 1443, 0),
new(785, 1548, 0),
new(734, 1504, 0),
new(819, 1266, 0)
};
private Point3D m_CorpseLocation;
public FindApprenticeObjective(bool init)
{
if (init)
{
m_CorpseLocation = RandomCorpseLocation();
}
}
public FindApprenticeObjective()
{
}
public override int Message => 1055014;
public Corpse Corpse { get; private set; }
private static Point3D RandomCorpseLocation() => m_CorpseLocations.RandomElement();
public override void CheckProgress()
{
var player = System.From;
var map = player.Map;
if (Corpse?.Deleted == false || map != Map.Trammel && map != Map.Felucca ||
!player.InRange(m_CorpseLocation, 8))
{
return;
}
Corpse = new HagApprenticeCorpse();
Corpse.MoveToWorld(m_CorpseLocation, map);
Effects.SendLocationEffect(m_CorpseLocation, map, 0x3728, 10);
Effects.PlaySound(m_CorpseLocation, map, 0x1FE);
var imp = new Zeefzorpul();
imp.MoveToWorld(m_CorpseLocation, map);
// * You see a strange imp stealing a scrap of paper from the bloodied corpse *
Corpse.SendLocalizedMessageTo(player, 1055049);
Timer.StartTimer(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
}
private static void DeleteImp(Mobile m)
{
if (m?.Deleted == false)
{
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10);
Effects.PlaySound(m.Location, m.Map, 0x1FE);
m.Delete();
}
}
public override void OnComplete()
{
System.AddConversation(new ApprenticeCorpseConversation());
}
public override void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
switch (version)
{
case 1:
{
m_CorpseLocation = reader.ReadPoint3D();
goto case 0;
}
case 0:
{
Corpse = (Corpse)reader.ReadEntity<Item>();
break;
}
}
if (version == 0)
{
m_CorpseLocation = RandomCorpseLocation();
}
}
public override void ChildSerialize(IGenericWriter writer)
{
if (Corpse?.Deleted == true)
{
Corpse = null;
}
writer.WriteEncodedInt(1); // version
writer.Write(m_CorpseLocation);
writer.Write(Corpse);
}
}
public class FindGrizeldaAboutMurderObjective : QuestObjective
{
public override int Message => 1055015;
public override void OnComplete()
{
System.AddConversation(new MurderConversation());
}
}
public class KillImpsObjective : QuestObjective
{
private int m_MaxProgress;
public KillImpsObjective(bool init)
{
if (init)
{
m_MaxProgress = Utility.RandomMinMax(1, 4);
}
}
public KillImpsObjective()
{
}
public override int Message => 1055016;
public override int MaxProgress => m_MaxProgress;
public override bool IgnoreYoungProtection(Mobile from)
{
if (!Completed && from is Imp)
{
return true;
}
return false;
}
public override void OnKill(BaseCreature creature, Container corpse)
{
if (creature is Imp)
{
CurProgress++;
}
}
public override void OnComplete()
{
var from = System.From;
var loc = WitchApprenticeQuest.RandomZeefzorpulLocation();
var mapItem = new MapItem();
mapItem.SetDisplay(loc.X - 200, loc.Y - 200, loc.X + 200, loc.Y + 200, 200, 200);
mapItem.AddWorldPin(loc.X, loc.Y);
from.AddToBackpack(mapItem);
from.AddToBackpack(new MagicFlute());
from.SendLocalizedMessage(1055061); // You have received a map and a magic flute.
System.AddConversation(new ImpDeathConversation(loc));
}
public override void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
m_MaxProgress = reader.ReadInt();
}
public override void ChildSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.Write(m_MaxProgress);
}
}
public class FindZeefzorpulObjective : QuestObjective
{
public FindZeefzorpulObjective(Point3D impLocation) => ImpLocation = impLocation;
public FindZeefzorpulObjective()
{
}
public override int Message => 1055017;
public Point3D ImpLocation { get; private set; }
public override void OnComplete()
{
Mobile from = System.From;
var map = from.Map;
Effects.SendLocationEffect(ImpLocation, map, 0x3728, 10);
Effects.PlaySound(ImpLocation, map, 0x1FE);
var imp = new Zeefzorpul();
imp.MoveToWorld(ImpLocation, map);
imp.Direction = imp.GetDirectionTo(from);
Timer.StartTimer(TimeSpan.FromSeconds(3.0), () => DeleteImp(imp));
}
private void DeleteImp(object imp)
{
if (imp is Mobile m && !m.Deleted)
{
Effects.SendLocationEffect(m.Location, m.Map, 0x3728, 10);
Effects.PlaySound(m.Location, m.Map, 0x1FE);
m.Delete();
}
System.From.SendLocalizedMessage(1055062); // You have received the Magic Brew Recipe.
System.AddConversation(new ZeefzorpulConversation());
}
public override void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
ImpLocation = reader.ReadPoint3D();
}
public override void ChildSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.Write(ImpLocation);
}
}
public class ReturnRecipeObjective : QuestObjective
{
public override int Message => 1055018;
public override void OnComplete()
{
System.AddConversation(new RecipeConversation());
}
}
public class FindIngredientObjective : QuestObjective
{
public FindIngredientObjective(Ingredient[] oldIngredients, bool blackheartMet = false)
{
if (!blackheartMet)
{
Ingredients = new Ingredient[oldIngredients.Length + 1];
for (var i = 0; i < oldIngredients.Length; i++)
{
Ingredients[i] = oldIngredients[i];
}
Ingredients[^1] = IngredientInfo.RandomIngredient(oldIngredients);
}
else
{
Ingredients = new Ingredient[oldIngredients.Length];
for (var i = 0; i < oldIngredients.Length; i++)
{
Ingredients[i] = oldIngredients[i];
}
}
BlackheartMet = blackheartMet;
}
public FindIngredientObjective()
{
}
public override int Message
{
get
{
if (!BlackheartMet)
{
return Step switch
{
1 =>
/* You must gather each ingredient on the Hag's list so that she can cook
* up her vile Magic Brew. The first ingredient is :
*/
1055019,
2 =>
/* You must gather each ingredient on the Hag's list so that she can cook
* up her vile Magic Brew. The second ingredient is :
*/
1055044,
_ => 1055045
};
}
/* You are still attempting to obtain a jug of Captain Blackheart's
* Whiskey, but the drunkard Captain refuses to share his unique brew.
* You must prove your worthiness as a pirate to Blackheart before he'll
* offer you a jug.
*/
return 1055055;
}
}
public override int MaxProgress
{
get
{
var info = IngredientInfo.Get(Ingredient);
return info.Quantity;
}
}
public Ingredient[] Ingredients { get; private set; }
public Ingredient Ingredient => Ingredients[^1];
public int Step => Ingredients.Length;
public bool BlackheartMet { get; private set; }
public override void RenderProgress(ref DynamicGumpBuilder builder)
{
if (!Completed)
{
var info = IngredientInfo.Get(Ingredient);
builder.AddHtmlLocalized(70, 260, 270, 100, info.Name, BaseQuestGump.Blue);
builder.AddLabel(70, 280, 0x64, $"{CurProgress}");
builder.AddLabel(100, 280, 0x64, "/");
builder.AddLabel(130, 280, 0x64, $"{info.Quantity}");
}
else
{
base.RenderProgress(ref builder);
}
}
public override bool IgnoreYoungProtection(Mobile from)
{
if (Completed)
{
return false;
}
var info = IngredientInfo.Get(Ingredient);
var fromType = from.GetType();
for (var i = 0; i < info.Creatures.Length; i++)
{
if (fromType == info.Creatures[i])
{
return true;
}
}
return false;
}
public override void OnKill(BaseCreature creature, Container corpse)
{
var info = IngredientInfo.Get(Ingredient);
for (var i = 0; i < info.Creatures.Length; i++)
{
var type = info.Creatures[i];
if (creature.GetType() == type)
{
// You gather a ~1_INGREDIENT_NAME~ from the corpse.
System.From.SendLocalizedMessage(1055043, $"#{info.Name}");
CurProgress++;
break;
}
}
}
public override void OnComplete()
{
if (Ingredient != Ingredient.Whiskey)
{
NextStep();
}
}
public void NextStep()
{
System.From.SendLocalizedMessage(
1055046
); // You have completed your current task on the Hag's Magic Brew Recipe list.
if (Step < 3)
{
System.AddObjective(new FindIngredientObjective(Ingredients));
}
else
{
System.AddObjective(new ReturnIngredientsObjective());
}
}
public override void ChildDeserialize(IGenericReader reader)
{
var version = reader.ReadEncodedInt();
Ingredients = new Ingredient[reader.ReadEncodedInt()];
for (var i = 0; i < Ingredients.Length; i++)
{
Ingredients[i] = (Ingredient)reader.ReadEncodedInt();
}
BlackheartMet = reader.ReadBool();
}
public override void ChildSerialize(IGenericWriter writer)
{
writer.WriteEncodedInt(0); // version
writer.WriteEncodedInt(Ingredients.Length);
for (var i = 0; i < Ingredients.Length; i++)
{
writer.WriteEncodedInt((int)Ingredients[i]);
}
writer.Write(BlackheartMet);
}
}
public class ReturnIngredientsObjective : QuestObjective
{
public override int Message => 1055050;
public override void OnComplete()
{
System.AddConversation(new EndConversation());
}
}
}