ModernUO/Projects/UOContent/Items/Special/Veteran Rewards/Cannon.cs
Kamron Batman ab5f615840
perf: Migrate Veteran Reward gumps to DynamicGump/StaticGump (#2415)
## Summary

Migrates 16 player-facing legacy `Gump` subclasses in the Veteran Rewards system to `DynamicGump` or `StaticGump<T>`, renames every nested `InternalGump`/`ConfirmGump` to system-prefixed names, and updates external callers to use new static `DisplayTo` entry points.

### Reward chain (Engines/Veteran Rewards)

| Gump | Base type | Reasoning |
|---|---|---|
| `RewardNoticeGump` | `StaticGump<T>` | Fixed layout |
| `RewardChoiceGump` | `DynamicGump` | Layout shape varies (per-player categories, entries, pages) |
| `RewardConfirmGump` | `DynamicGump` | `entry.Name` is a dynamic cliloc per reward (cliloc rule) |
| `RewardOptionGump` | `DynamicGump` | Title cliloc and per-option clilocs are dynamic (cliloc rule) |
| `RewardDemolitionGump` | `DynamicGump` | `question` cliloc is dynamic per caller (cliloc rule) |

### Statue (Engines/Veteran Rewards/Character Statue Maker)

| Gump | Base type | Reasoning |
|---|---|---|
| `CharacterStatueGump` | `DynamicGump` | Pose/Direction/Material labels are dynamic clilocs (cliloc rule) |
| `CharacterPlinthGump` | `DynamicGump` | `statue.Name`, sculpted-on date, and statue-type cliloc are dynamic (cliloc rule) |

### Decorations (Items/Special/Veteran Rewards) — every `InternalGump` renamed

| Original | New name | Base type | Reasoning |
|---|---|---|---|
| `Banner.InternalGump` | `BannerGump` | `StaticGump<T>` | Fully fixed item-id picker over `Start..End` range |
| `Brazier.InternalGump` | `BrazierGump` | `StaticGump<T>` | Fixed two-item picker |
| `Cannon.InternalGump` | `CannonGump` | `DynamicGump` | `keg.Validate()` value passed as `~1_CHARGES~` arg (cliloc-arg rule) |
| `DecorativeShield.InternalGump` | `DecorativeShieldGump` | `StaticGump<T>` | Fixed item picker over a constant range |
| `DecorativeShield.FacingGump` | `DecorativeShieldFacingGump` | `DynamicGump` | Item ids depend on instance state |
| `HangingSkeleton.InternalGump` | `HangingSkeletonGump` | `StaticGump<T>` | Fixed item picker (5 hard-coded ids) |
| `PottedCactus.InternalGump` | `PottedCactusGump` | `StaticGump<T>` | Fixed 6-item picker |
| `StoneAnkh.InternalGump` | `StoneAnkhGump` | `StaticGump<T>` | Fixed two-direction picker |
| `WallBanner.InternalGump` | `WallBannerGump` | `StaticGump<T>` | Fixed 30-banner picker across 5 pages |
| `WeaponEngravingTool.InternalGump` | `WeaponEngravingToolGump` | `StaticGump<T>` | Fixed text-entry dialog |
| `WeaponEngravingTool.ConfirmGump` | `WeaponEngravingToolConfirmGump` | `DynamicGump` | Layout branches on `guildmaster != null` |

### External callers updated

`RewardSystem`, `CharacterStatue`, `FireFliesDeed`, `FlamingHead`, `Banner`, `DecorativeShield`, `HangingSkeleton`, `StoneAnkh` (RewardDemolitionGump callers); `AnkhOfSacrifice`, `Cannon`, `MiningCart`, `MinotaurStatue`, `TreeStump` (RewardOptionGump callers); `TinkerGuildmaster` (engraver confirm gump).

The pre-existing `FacingGump` inside `Banner.cs` (already `DynamicGump`) was left as-is — it is private, nested inside `InternalTarget`, and never referenced outside.
2026-04-25 20:09:27 -07:00

440 lines
12 KiB
C#

using ModernUO.Serialization;
using Server.Engines.Quests.Haven;
using Server.Engines.VeteranRewards;
using Server.Gumps;
using Server.Network;
using Server.Targeting;
namespace Server.Items;
[SerializationGenerator(0, false)]
public partial class CannonAddonComponent : AddonComponent
{
public CannonAddonComponent(int itemID) : base(itemID) => LootType = LootType.Blessed;
public override int LabelNumber => 1076157; // Decorative Cannon
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
if (Addon is CannonAddon addon)
{
if (addon.IsRewardItem)
{
list.Add(1076223); // 7th Year Veteran Reward
}
list.Add(1076207, addon.Charges); // Remaining Charges: ~1_val~
}
}
}
[SerializationGenerator(1)]
public partial class CannonAddon : BaseAddon
{
private static readonly int[] m_Effects = { 0x36B0, 0x3728, 0x3709, 0x36FE };
[SerializableField(0, setter: "private")]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private CannonDirection _cannonDirection;
[Constructible]
public CannonAddon(CannonDirection direction)
{
CannonDirection = direction;
switch (direction)
{
case CannonDirection.North:
{
AddComponent(new CannonAddonComponent(0xE8D), 0, 0, 0);
AddComponent(new CannonAddonComponent(0xE8C), 0, 1, 0);
AddComponent(new CannonAddonComponent(0xE8B), 0, 2, 0);
break;
}
case CannonDirection.East:
{
AddComponent(new CannonAddonComponent(0xE96), 0, 0, 0);
AddComponent(new CannonAddonComponent(0xE95), -1, 0, 0);
AddComponent(new CannonAddonComponent(0xE94), -2, 0, 0);
break;
}
case CannonDirection.South:
{
AddComponent(new CannonAddonComponent(0xE91), 0, 0, 0);
AddComponent(new CannonAddonComponent(0xE92), 0, -1, 0);
AddComponent(new CannonAddonComponent(0xE93), 0, -2, 0);
break;
}
default:
{
AddComponent(new CannonAddonComponent(0xE8E), 0, 0, 0);
AddComponent(new CannonAddonComponent(0xE8F), 1, 0, 0);
AddComponent(new CannonAddonComponent(0xE90), 2, 0, 0);
break;
}
}
}
public override BaseAddonDeed Deed =>
new CannonDeed
{
Charges = _charges,
IsRewardItem = _isRewardItem
};
[SerializableProperty(1)]
[CommandProperty(AccessLevel.GameMaster)]
public int Charges
{
get => _charges;
set
{
_charges = value;
foreach (var c in Components)
{
c.InvalidateProperties();
}
this.MarkDirty();
}
}
[SerializableProperty(2)]
[CommandProperty(AccessLevel.GameMaster)]
public bool IsRewardItem
{
get => _isRewardItem;
set
{
_isRewardItem = value;
foreach (var c in Components)
{
c.InvalidateProperties();
}
this.MarkDirty();
}
}
public override void OnComponentUsed(AddonComponent c, Mobile from)
{
if (!from.InRange(Location, 2))
{
from.SendLocalizedMessage(1076766); // That is too far away.
return;
}
if (_charges > 0)
{
from.Target = new InternalTarget(this);
}
else if (from.Backpack != null)
{
var keg = from.Backpack.FindItemByType<PotionKeg>();
if (Validate(keg) > 0)
{
CannonGump.DisplayTo(from, this, keg);
}
else
{
// You do not have a full keg of explosion potions needed to recharge the cannon.
from.SendLocalizedMessage(1076198);
}
}
}
public int Validate(PotionKeg keg)
{
if (keg?.Deleted != false || keg.Held != 100)
{
return 0;
}
return keg.Type switch
{
PotionEffect.ExplosionLesser => 5,
PotionEffect.Explosion => 10,
PotionEffect.ExplosionGreater => 15,
_ => 0
};
}
public void Fill(Mobile from, PotionKeg keg)
{
Charges = Validate(keg);
if (_charges > 0)
{
keg.Delete();
from.SendLocalizedMessage(1076199); // Your cannon is recharged.
}
else
{
// You do not have a full keg of explosion potions needed to recharge the cannon.
from.SendLocalizedMessage(1076198);
}
}
public void DoFireEffect(Point3D target)
{
var map = Map;
if (map == null)
{
return;
}
Effects.PlaySound(target, map, Utility.RandomList(0x11B, 0x11C, 0x11D));
Effects.SendLocationEffect(target, map, m_Effects.RandomElement(), 16, 1);
for (var count = Utility.Random(3); count > 0; count--)
{
var location = new Point3D(
target.X + Utility.RandomMinMax(-1, 1),
target.Y + Utility.RandomMinMax(-1, 1),
target.Z
);
Effects.SendLocationEffect(location, map, m_Effects.RandomElement(), 16, 1);
}
Charges -= 1;
}
private void Deserialize(IGenericReader reader, int version)
{
_cannonDirection = (CannonDirection)reader.ReadInt();
_charges = reader.ReadInt();
_isRewardItem = reader.ReadBool();
}
private class InternalTarget : Target
{
private readonly CannonAddon _cannon;
public InternalTarget(CannonAddon cannon) : base(12, true, TargetFlags.None) => _cannon = cannon;
protected override void OnTarget(Mobile from, object targeted)
{
if (_cannon?.Deleted != false)
{
return;
}
if (targeted is not IPoint3D p)
{
return;
}
if (!from.InLOS(new Point3D(p)))
{
from.SendLocalizedMessage(1049630); // You cannot see that target!
return;
}
if (Utility.InRange(new Point3D(p), _cannon.Location, 2))
{
from.SendLocalizedMessage(1076215); // Cannon must be aimed farther away.
return;
}
var allow = false;
var x = p.X - _cannon.X;
var y = p.Y - _cannon.Y;
switch (_cannon.CannonDirection)
{
case CannonDirection.North:
{
if (y < 0 && x.Abs() <= -y / 3)
{
allow = true;
}
break;
}
case CannonDirection.East:
{
if (x > 0 && y.Abs() <= x / 3)
{
allow = true;
}
break;
}
case CannonDirection.South:
{
if (y > 0 && x.Abs() <= y / 3)
{
allow = true;
}
break;
}
case CannonDirection.West:
{
if (x < 0 && y.Abs() <= -x / 3)
{
allow = true;
}
break;
}
}
var loc = new Point3D(p);
if (allow && Utility.InRange(loc, _cannon.Location, 14))
{
_cannon.DoFireEffect(loc);
}
else
{
from.SendLocalizedMessage(1076203); // Target out of range.
}
}
protected override void OnTargetOutOfRange(Mobile from, object targeted)
{
from.SendLocalizedMessage(1076203); // Target out of range.
}
}
private class CannonGump : DynamicGump
{
private readonly CannonAddon _cannon;
private readonly PotionKeg _keg;
public override bool Singleton => true;
private CannonGump(CannonAddon cannon, PotionKeg keg) : base(50, 50)
{
_cannon = cannon;
_keg = keg;
}
public static void DisplayTo(Mobile from, CannonAddon cannon, PotionKeg keg)
{
if (from?.NetState == null || cannon?.Deleted != false || keg?.Deleted != false)
{
return;
}
from.SendGump(new CannonGump(cannon, keg));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(0, 0, 291, 133, 0x13BE);
builder.AddImageTiled(5, 5, 280, 100, 0xA40);
// You will need a full keg of explosion potions to recharge the cannon. Your keg will provide ~1_CHARGES~ charges.
builder.AddHtmlLocalized(9, 9, 272, 100, 1076196, $"{_cannon.Validate(_keg)}", 0x7FFF);
builder.AddButton(5, 107, 0xFB1, 0xFB2, (int)Buttons.Cancel);
builder.AddHtmlLocalized(40, 109, 100, 20, 1060051, 0x7FFF); // CANCEL
builder.AddButton(160, 107, 0xFB7, 0xFB8, (int)Buttons.Recharge);
builder.AddHtmlLocalized(195, 109, 120, 20, 1076197, 0x7FFF); // Recharge
}
public override void OnResponse(NetState state, in RelayInfo info)
{
if (_cannon?.Deleted == false && info.ButtonID == (int)Buttons.Recharge)
{
_cannon.Fill(state.Mobile, _keg);
}
}
private enum Buttons
{
Cancel,
Recharge
}
}
}
[SerializationGenerator(0)]
public partial class CannonDeed : BaseAddonDeed, IRewardItem, IRewardOption
{
[InvalidateProperties]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private int _charges;
[InvalidateProperties]
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private bool _isRewardItem;
private CannonDirection _direction;
[Constructible]
public CannonDeed() => LootType = LootType.Blessed;
public override int LabelNumber => 1076195; // A deed for a cannon
public override BaseAddon Addon => new CannonAddon(_direction)
{
Charges = _charges,
IsRewardItem = _isRewardItem
};
public void GetOptions(RewardOptionList list)
{
list.Add((int)CannonDirection.South, 1075386); // South
list.Add((int)CannonDirection.East, 1075387); // East
list.Add((int)CannonDirection.North, 1075389); // North
list.Add((int)CannonDirection.West, 1075390); // West
}
public void OnOptionSelected(Mobile from, int option)
{
_direction = (CannonDirection)option;
if (!Deleted)
{
base.OnDoubleClick(from);
}
}
public override void GetProperties(IPropertyList list)
{
base.GetProperties(list);
if (_isRewardItem)
{
list.Add(1076223); // 7th Year Veteran Reward
}
list.Add(1076207, _charges); // Remaining Charges: ~1_val~
}
public override void OnDoubleClick(Mobile from)
{
if (_isRewardItem && !RewardSystem.CheckIsUsableBy(from, this))
{
return;
}
if (IsChildOf(from.Backpack))
{
RewardOptionGump.DisplayTo(from, this);
}
else
{
from.SendLocalizedMessage(1042038); // You must have the object in your backpack to use it.
}
}
}