## 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.
244 lines
7.1 KiB
C#
244 lines
7.1 KiB
C#
using System;
|
|
using Server.Collections;
|
|
using Server.Gumps;
|
|
using Server.Items;
|
|
using Server.Logging;
|
|
|
|
namespace Server.Engines.MLQuests.Objectives
|
|
{
|
|
public class DeliverObjective : BaseObjective
|
|
{
|
|
private static readonly ILogger logger = LogFactory.GetLogger(typeof(DeliverObjective));
|
|
|
|
public DeliverObjective(Type delivery, int amount, TextDefinition name, Type destination, bool spawnsDelivery = true)
|
|
{
|
|
Delivery = delivery;
|
|
Amount = amount;
|
|
Name = name;
|
|
Destination = destination;
|
|
SpawnsDelivery = spawnsDelivery;
|
|
|
|
if (MLQuestSystem.Debug && name.Number > 0)
|
|
{
|
|
var itemid = CollectObjective.LabelToItemID(name.Number);
|
|
|
|
if (itemid is <= 0 or > 0x4000)
|
|
{
|
|
logger.Warning("Cliloc {Number} is likely giving the wrong item ID", name.Number);
|
|
}
|
|
}
|
|
}
|
|
|
|
public Type Delivery { get; set; }
|
|
|
|
public int Amount { get; set; }
|
|
|
|
public TextDefinition Name { get; set; }
|
|
|
|
public Type Destination { get; set; }
|
|
|
|
public bool SpawnsDelivery { get; set; }
|
|
|
|
public virtual void SpawnDelivery(Container pack)
|
|
{
|
|
if (!SpawnsDelivery || pack == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
using var delivery = PooledRefQueue<Item>.Create();
|
|
|
|
for (var i = 0; i < Amount; ++i)
|
|
{
|
|
var item = Delivery.CreateEntityInstance<Item>();
|
|
|
|
if (item != null)
|
|
{
|
|
delivery.Enqueue(item);
|
|
|
|
if (item.Stackable && Amount > 1)
|
|
{
|
|
item.Amount = Amount;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
while (delivery.Count > 0)
|
|
{
|
|
pack.DropItem(delivery.Dequeue()); // Confirmed: on OSI items are added even if your pack is full
|
|
}
|
|
}
|
|
|
|
public override void WriteToGump(ref DynamicGumpBuilder builder, ref int y)
|
|
{
|
|
var amount = Amount.ToString();
|
|
|
|
builder.AddHtmlLocalized(98, y, 312, 16, 1072207, 0x5F90); // Deliver
|
|
builder.AddLabel(143, y, 0x481, amount);
|
|
|
|
if (Name.Number > 0)
|
|
{
|
|
builder.AddHtmlLocalized(143 + amount.Length * 15, y, 190, 18, Name.Number, 0x77BF);
|
|
builder.AddItem(350, y, CollectObjective.LabelToItemID(Name.Number));
|
|
}
|
|
else if (Name.String != null)
|
|
{
|
|
builder.AddLabel(143 + amount.Length * 15, y, 0x481, Name.String);
|
|
}
|
|
|
|
y += 32;
|
|
|
|
builder.AddHtmlLocalized(103, y, 120, 16, 1072379, 0x5F90); // Deliver to
|
|
builder.AddLabel(223, y, 0x481, QuesterNameAttribute.GetQuesterNameFor(Destination));
|
|
|
|
y += 16;
|
|
}
|
|
|
|
public override BaseObjectiveInstance CreateInstance(MLQuestInstance instance) =>
|
|
new DeliverObjectiveInstance(this, instance);
|
|
}
|
|
|
|
public class TimedDeliverObjective : DeliverObjective
|
|
{
|
|
public TimedDeliverObjective(
|
|
TimeSpan duration, Type delivery, int amount, TextDefinition name, Type destination,
|
|
bool spawnsDelivery = true
|
|
)
|
|
: base(delivery, amount, name, destination, spawnsDelivery) =>
|
|
Duration = duration;
|
|
|
|
public override bool IsTimed => true;
|
|
public override TimeSpan Duration { get; }
|
|
}
|
|
|
|
public class DeliverObjectiveInstance : BaseObjectiveInstance
|
|
{
|
|
public DeliverObjectiveInstance(DeliverObjective objective, MLQuestInstance instance)
|
|
: base(instance, objective) =>
|
|
Objective = objective;
|
|
|
|
public DeliverObjective Objective { get; set; }
|
|
|
|
public bool HasCompleted { get; set; }
|
|
|
|
public override DataType ExtraDataType => DataType.DeliverObjective;
|
|
|
|
public virtual bool IsDestination(IQuestGiver quester, Type type)
|
|
{
|
|
var destType = Objective.Destination;
|
|
|
|
return destType?.IsAssignableFrom(type) == true;
|
|
}
|
|
|
|
public override bool IsCompleted() => HasCompleted;
|
|
|
|
public override void OnQuestAccepted()
|
|
{
|
|
Objective.SpawnDelivery(Instance.Player.Backpack);
|
|
}
|
|
|
|
// This is VERY similar to CollectObjective.GetCurrentTotal
|
|
private int GetCurrentTotal()
|
|
{
|
|
var pack = Instance.Player.Backpack;
|
|
|
|
if (pack == null)
|
|
{
|
|
return 0;
|
|
}
|
|
|
|
var total = 0;
|
|
foreach (var item in pack.FindItems(false))
|
|
{
|
|
if (ClaimTypePredicate(item))
|
|
{
|
|
total += item.Amount;
|
|
}
|
|
}
|
|
|
|
return total;
|
|
}
|
|
|
|
public override bool OnBeforeClaimReward()
|
|
{
|
|
var pm = Instance.Player;
|
|
|
|
var total = GetCurrentTotal();
|
|
var desired = Objective.Amount;
|
|
|
|
if (total < desired)
|
|
{
|
|
pm.SendLocalizedMessage(1074861); // You do not have everything you need!
|
|
pm.SendLocalizedMessage(1074885, $"{total}\t{desired}"); // You have ~1_val~ item(s) but require ~2_val~
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
// Note: subclasses are included
|
|
private bool ClaimTypePredicate(Item item) => Objective.Delivery.IsInstanceOfType(item);
|
|
|
|
// TODO: This is VERY similar to CollectObjective.OnClaimReward
|
|
public override void OnClaimReward()
|
|
{
|
|
var pack = Instance.Player.Backpack;
|
|
|
|
if (pack == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var left = Objective.Amount;
|
|
|
|
using var queue = pack.EnumerateItems(false, ClaimTypePredicate);
|
|
foreach (var item in queue)
|
|
{
|
|
if (left == 0)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if (item.Amount > left)
|
|
{
|
|
item.Consume(left);
|
|
left = 0;
|
|
}
|
|
else
|
|
{
|
|
item.Delete();
|
|
left -= item.Amount;
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnQuestCancelled()
|
|
{
|
|
OnClaimReward(); // same effect
|
|
}
|
|
|
|
public override void OnExpire()
|
|
{
|
|
OnQuestCancelled();
|
|
|
|
Instance.Player.SendLocalizedMessage(1074813); // You have failed to complete your delivery.
|
|
}
|
|
|
|
public override void WriteToGump(ref DynamicGumpBuilder builder, ref int y)
|
|
{
|
|
Objective.WriteToGump(ref builder, ref y);
|
|
|
|
base.WriteToGump(ref builder, ref y);
|
|
|
|
// No extra instance stuff printed for this objective
|
|
}
|
|
|
|
public override void Serialize(IGenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.Write(HasCompleted);
|
|
}
|
|
}
|
|
}
|