## Summary Migrates 11 player-facing Item Interaction gumps from legacy `Gump` to `StaticGump<T>` or `DynamicGump`. | File | Gump | Base | Reason | |---|---|---|---| | `Items/Deeds/NameChangeDeed.cs` | `NameChangeDeedGump` | `StaticGump<T>` | Fully fixed layout | | `Items/Deeds/HairRestylingDeed.cs` | `HairRestylingDeedGump` (renamed from `InternalGump`) | `DynamicGump` | Per-race/per-gender cliloc IDs and gump images vary every instance | | `Items/Deeds/HolidayTreeDeed.cs` | `HolidayTreeChoiceGump` | `StaticGump<T>` | Fully fixed (Classic/Modern radio) | | `Items/Deeds/NewPlayerTicket.cs` | `NewPlayerTicketGump` (renamed from `InternalGump`) | `StaticGump<T>` | Fully fixed gift menu | | `Items/Misc/PromotionalToken.cs` | `PromotionalTokenGump` | `DynamicGump` | `TextDefinition` (`ItemGumpName`) varies per token subclass — cliloc/string differs | | `Items/Misc/SpecialHairDye.cs` | `SpecialHairDyeGump` | `StaticGump<T>` | Static entry array drives a fixed layout | | `Items/Misc/InteriorDecorator.cs` | `InteriorDecoratorGump` (renamed from `InternalGump`) | `DynamicGump` | Button art flips per `decorator.Command` (Turn/Up/Down) | | `Items/Special/8th Anniversary Items/Dawn's Music Box/DawnsMusicBoxGump.cs` | `DawnsMusicBoxGump` | `DynamicGump` | Page count derived from variable `Tracks.Count` | | `Items/Misc/PowerGenerator.cs` | `PowerGeneratorGump` (renamed from `GameGump`) | `DynamicGump` | Variable side length 3-6 and per-step node hues | | `Gumps/HeritageTokenGump.cs` | `HeritageTokenGump` | `StaticGump<T>` | All 7 pages fully baked — only static cliloc IDs | | `Gumps/ConfirmHeritageGump.cs` | `ConfirmHeritageGump` | `DynamicGump` | Confirmation cliloc chosen at runtime per item selected | All gumps use `Singleton => true`, private constructors, and a static `DisplayTo` entry point that validates prerequisites before constructing. External callers updated (`HeritageToken`, `DawnsMusicBox`) to the new `DisplayTo` entry points. `Console.WriteLine` in `ConfirmHeritageGump` exception handler replaced with `LogFactory`-backed logger.
560 lines
15 KiB
C#
560 lines
15 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using ModernUO.Serialization;
|
|
using Server.Gumps;
|
|
using Server.Network;
|
|
|
|
namespace Server.Items;
|
|
|
|
[SerializationGenerator(0)]
|
|
public partial class PowerGenerator : BaseAddon
|
|
{
|
|
[Constructible]
|
|
public PowerGenerator() : this(Utility.RandomMinMax(3, 6))
|
|
{
|
|
}
|
|
|
|
[Constructible]
|
|
public PowerGenerator(int sideLength)
|
|
{
|
|
AddGeneratorComponent(0x4FA1, 0, 0, 0);
|
|
AddGeneratorComponent(0x76, -1, 0, 0);
|
|
AddGeneratorComponent(0x75, 0, -1, 0);
|
|
AddGeneratorComponent(0x37F4, 0, 0, 13);
|
|
|
|
AddComponent(new ControlPanel(sideLength), 1, 0, -2);
|
|
}
|
|
|
|
public override bool ShareHue => false;
|
|
|
|
private void AddGeneratorComponent(int itemID, int x, int y, int z)
|
|
{
|
|
var component = new AddonComponent(itemID);
|
|
component.Name = "a power generator";
|
|
component.Hue = 0x451;
|
|
|
|
AddComponent(component, x, y, z);
|
|
}
|
|
}
|
|
|
|
[SerializationGenerator(1)]
|
|
public partial class ControlPanel : AddonComponent
|
|
{
|
|
private static readonly TimeSpan m_UseTimeout = TimeSpan.FromMinutes(2.0);
|
|
|
|
private readonly HashSet<Mobile> m_DamageTable = new();
|
|
private DateTime m_LastUse;
|
|
|
|
private int m_SideLength;
|
|
|
|
private Mobile m_User;
|
|
|
|
[SerializableField(1, setter: "private")]
|
|
private Point2D[] _path;
|
|
|
|
public ControlPanel(int sideLength) : base(0xBDC)
|
|
{
|
|
Hue = 0x835;
|
|
|
|
m_SideLength = sideLength;
|
|
}
|
|
|
|
[SerializableProperty(0, useField: nameof(m_SideLength))]
|
|
[CommandProperty(AccessLevel.GameMaster)]
|
|
public int SideLength
|
|
{
|
|
get => m_SideLength;
|
|
set
|
|
{
|
|
value = Math.Clamp(value, 3, 6);
|
|
|
|
if (m_SideLength != value)
|
|
{
|
|
m_SideLength = value;
|
|
InitPath();
|
|
this.MarkDirty();
|
|
}
|
|
}
|
|
}
|
|
|
|
public override string DefaultName => "a control panel";
|
|
|
|
public void InitPath()
|
|
{
|
|
// Depth-First Search algorithm
|
|
|
|
var totalNodes = SideLength * SideLength;
|
|
|
|
var stack = new Point2D[totalNodes];
|
|
var current = stack[0] = new Point2D(0, 0);
|
|
var stackSize = 1;
|
|
|
|
var visited = new bool[SideLength, SideLength];
|
|
visited[0, 0] = true;
|
|
|
|
while (true)
|
|
{
|
|
var choices = new PathDirection[4];
|
|
var count = 0;
|
|
|
|
if (current.X > 0 && !visited[current.X - 1, current.Y])
|
|
{
|
|
choices[count++] = PathDirection.Left;
|
|
}
|
|
|
|
if (current.Y > 0 && !visited[current.X, current.Y - 1])
|
|
{
|
|
choices[count++] = PathDirection.Up;
|
|
}
|
|
|
|
if (current.X < SideLength - 1 && !visited[current.X + 1, current.Y])
|
|
{
|
|
choices[count++] = PathDirection.Right;
|
|
}
|
|
|
|
if (current.Y < SideLength - 1 && !visited[current.X, current.Y + 1])
|
|
{
|
|
choices[count++] = PathDirection.Down;
|
|
}
|
|
|
|
if (count > 0)
|
|
{
|
|
var dir = choices[Utility.Random(count)];
|
|
|
|
current = dir switch
|
|
{
|
|
PathDirection.Left => new Point2D(current.X - 1, current.Y),
|
|
PathDirection.Up => new Point2D(current.X, current.Y - 1),
|
|
PathDirection.Right => new Point2D(current.X + 1, current.Y),
|
|
_ => new Point2D(current.X, current.Y + 1)
|
|
};
|
|
|
|
stack[stackSize++] = current;
|
|
|
|
if (current.X == SideLength - 1 && current.Y == SideLength - 1)
|
|
{
|
|
break;
|
|
}
|
|
|
|
visited[current.X, current.Y] = true;
|
|
}
|
|
else
|
|
{
|
|
current = stack[--stackSize - 1];
|
|
}
|
|
}
|
|
|
|
Path = new Point2D[stackSize];
|
|
|
|
for (var i = 0; i < stackSize; i++)
|
|
{
|
|
Path[i] = stack[i];
|
|
}
|
|
|
|
if (m_User != null)
|
|
{
|
|
m_User.CloseGump<PowerGeneratorGump>();
|
|
m_User = null;
|
|
}
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (!from.InRange(this, 3))
|
|
{
|
|
from.SendLocalizedMessage(500446); // That is too far away.
|
|
return;
|
|
}
|
|
|
|
if (m_User != null)
|
|
{
|
|
if (m_User == from)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (m_User.Deleted || m_User.Map != Map || !m_User.InRange(this, 3)
|
|
|| m_User.NetState == null || Core.Now - m_LastUse >= m_UseTimeout)
|
|
{
|
|
m_User.CloseGump<PowerGeneratorGump>();
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage("Someone is currently using the control panel.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
m_User = from;
|
|
m_LastUse = Core.Now;
|
|
|
|
PowerGeneratorGump.DisplayTo(from, this, 0, false);
|
|
}
|
|
|
|
public void DoDamage(Mobile to)
|
|
{
|
|
to.NetState.SendMessage(
|
|
Serial,
|
|
ItemID,
|
|
MessageType.Regular,
|
|
0x3B2,
|
|
3,
|
|
false,
|
|
"ENU",
|
|
"",
|
|
"The generator shoots an arc of electricity at you!"
|
|
);
|
|
|
|
to.BoltEffect(0);
|
|
|
|
// * Your body convulses from electric shock *
|
|
to.LocalOverheadMessage(MessageType.Regular, 0xC9, 1114443);
|
|
|
|
// * ~1_NAME~ spasms from electric shock *
|
|
to.NonlocalOverheadMessage(MessageType.Regular, 0xC9, 1114444, to.Name);
|
|
|
|
AOS.Damage(to, to, 60, 0, 0, 0, 0, 100);
|
|
|
|
if (!to.Alive)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!m_DamageTable.Contains(to))
|
|
{
|
|
to.Frozen = true;
|
|
|
|
var timer = new DamageTimer(this, to);
|
|
m_DamageTable.Add(to);
|
|
|
|
timer.Start();
|
|
}
|
|
}
|
|
|
|
public void Solve(Mobile from)
|
|
{
|
|
Effects.PlaySound(Location, Map, 0x211);
|
|
Effects.PlaySound(Location, Map, 0x1F3);
|
|
|
|
Effects.SendLocationEffect(Location, Map, 0x36B0, 4, 4);
|
|
Effects.SendLocationEffect(new Point3D(X - 1, Y - 1, Z + 2), Map, 0x36B0, 4, 4);
|
|
Effects.SendLocationEffect(new Point3D(X - 2, Y - 1, Z + 2), Map, 0x36B0, 4, 4);
|
|
|
|
from.SendMessage("You scrounge some gems from the wreckage.");
|
|
|
|
for (var i = 0; i < SideLength; i++)
|
|
{
|
|
from.AddToBackpack(new ArcaneGem());
|
|
}
|
|
|
|
from.AddToBackpack(new Diamond(SideLength));
|
|
|
|
Item ore = new ShadowIronOre(9);
|
|
ore.MoveToWorld(new Point3D(X - 1, Y, Z + 2), Map);
|
|
|
|
ore = new ShadowIronOre(14);
|
|
ore.MoveToWorld(new Point3D(X - 2, Y - 1, Z + 2), Map);
|
|
|
|
Delete();
|
|
}
|
|
|
|
private void Deserialize(IGenericReader reader, int version)
|
|
{
|
|
m_SideLength = reader.ReadEncodedInt();
|
|
|
|
Path = new Point2D[reader.ReadEncodedInt()];
|
|
for (var i = 0; i < Path.Length; i++)
|
|
{
|
|
Path[i] = new Point2D(reader.ReadEncodedInt(), reader.ReadEncodedInt());
|
|
}
|
|
}
|
|
|
|
private enum PathDirection
|
|
{
|
|
Left,
|
|
Up,
|
|
Right,
|
|
Down
|
|
}
|
|
|
|
private class PowerGeneratorGump : DynamicGump
|
|
{
|
|
private readonly Mobile _from;
|
|
|
|
private readonly ControlPanel _panel;
|
|
private readonly int _step;
|
|
private readonly bool _hint;
|
|
|
|
public override bool Singleton => true;
|
|
|
|
private PowerGeneratorGump(ControlPanel panel, Mobile from, int step, bool hint) : base(5, 30)
|
|
{
|
|
_panel = panel;
|
|
_from = from;
|
|
_step = step;
|
|
_hint = hint;
|
|
}
|
|
|
|
public static void DisplayTo(Mobile from, ControlPanel panel, int step, bool hint)
|
|
{
|
|
if (from?.NetState == null || panel?.Deleted != false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
from.SendGump(new PowerGeneratorGump(panel, from, step, hint));
|
|
}
|
|
|
|
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
|
{
|
|
var sideLength = _panel.SideLength;
|
|
|
|
builder.AddBackground(50, 0, 530, 410, 0xA28);
|
|
|
|
builder.AddImage(0, 0, 0x28C8);
|
|
builder.AddImage(547, 0, 0x28C9);
|
|
|
|
builder.AddBackground(95, 20, 442, 90, 0xA28);
|
|
|
|
builder.AddHtml(229, 35, 300, 45, "GENERATOR CONTROL PANEL");
|
|
|
|
builder.AddHtml(223, 60, 300, 70, "Use the Directional Controls to");
|
|
builder.AddHtml(253, 75, 300, 85, "Close the Grid Circuit");
|
|
|
|
builder.AddImage(140, 40, 0x28D3);
|
|
builder.AddImage(420, 40, 0x28D3);
|
|
|
|
builder.AddBackground(365, 120, 178, 210, 0x1400);
|
|
|
|
builder.AddImage(365, 115, 0x28D4);
|
|
builder.AddImage(365, 288, 0x28D4);
|
|
|
|
builder.AddImage(414, 189, 0x589);
|
|
builder.AddImage(435, 210, 0xA52);
|
|
|
|
builder.AddButton(408, 222, 0x29EA, 0x29EC, 1); // Left
|
|
builder.AddButton(448, 185, 0x29CC, 0x29CE, 2); // Up
|
|
builder.AddButton(473, 222, 0x29D6, 0x29D8, 3); // Right
|
|
builder.AddButton(448, 243, 0x29E0, 0x29E2, 4); // Down
|
|
|
|
builder.AddBackground(90, 115, 30 + 40 * sideLength, 30 + 40 * sideLength, 0xA28);
|
|
builder.AddBackground(100, 125, 10 + 40 * sideLength, 10 + 40 * sideLength, 0x1400);
|
|
|
|
for (var i = 0; i < sideLength; i++)
|
|
{
|
|
for (var j = 0; j < sideLength - 1; j++)
|
|
{
|
|
builder.AddImage(120 + 40 * i, 162 + 40 * j, 0x13F9);
|
|
}
|
|
}
|
|
|
|
for (var i = 0; i < sideLength - 1; i++)
|
|
{
|
|
for (var j = 0; j < sideLength; j++)
|
|
{
|
|
builder.AddImage(138 + 40 * i, 147 + 40 * j, 0x13FD);
|
|
}
|
|
}
|
|
|
|
var path = _panel.Path;
|
|
|
|
var hues = new NodeHue[sideLength, sideLength];
|
|
|
|
for (var i = 0; i <= _step; i++)
|
|
{
|
|
var n = path[i];
|
|
hues[n.X, n.Y] = NodeHue.Blue;
|
|
}
|
|
|
|
var lastNode = path[^1];
|
|
hues[lastNode.X, lastNode.Y] = NodeHue.Red;
|
|
|
|
for (var i = 0; i < sideLength; i++)
|
|
{
|
|
for (var j = 0; j < sideLength; j++)
|
|
{
|
|
AddNode(ref builder, 110 + 40 * i, 135 + 40 * j, hues[i, j]);
|
|
}
|
|
}
|
|
|
|
var curNode = path[_step];
|
|
builder.AddImage(118 + 40 * curNode.X, 143 + 40 * curNode.Y, 0x13A8);
|
|
|
|
if (_hint)
|
|
{
|
|
var nextNode = path[_step + 1];
|
|
builder.AddImage(119 + 40 * nextNode.X, 143 + 40 * nextNode.Y, 0x939);
|
|
}
|
|
|
|
if (_from.Skills.Lockpicking.Value >= 65.0)
|
|
{
|
|
builder.AddButton(365, 350, 0xFA6, 0xFA7, 5);
|
|
builder.AddHtml(405, 345, 140, 40, "Attempt to Decipher the Circuit Path");
|
|
}
|
|
}
|
|
|
|
private static void AddNode(ref DynamicGumpBuilder builder, int x, int y, NodeHue hue)
|
|
{
|
|
var id = hue switch
|
|
{
|
|
NodeHue.Gray => 0x25F8,
|
|
NodeHue.Blue => 0x868,
|
|
_ => 0x9A8
|
|
};
|
|
|
|
builder.AddImage(x, y, id);
|
|
}
|
|
|
|
public override void OnResponse(NetState sender, in RelayInfo info)
|
|
{
|
|
if (_panel.Deleted || info.ButtonID == 0 || !_from.CheckAlive())
|
|
{
|
|
_panel.m_User = null;
|
|
return;
|
|
}
|
|
|
|
if (_from.Map != _panel.Map || !_from.InRange(_panel, 3))
|
|
{
|
|
_from.SendLocalizedMessage(500446); // That is too far away.
|
|
_panel.m_User = null;
|
|
return;
|
|
}
|
|
|
|
var nextNode = _panel.Path[_step + 1];
|
|
|
|
if (info.ButtonID == 5) // Attempt to Decipher
|
|
{
|
|
var lockpicking = _from.Skills.Lockpicking.Value;
|
|
|
|
if (lockpicking < 65.0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_from.PlaySound(0x241);
|
|
|
|
if (40.0 + Utility.RandomDouble() * 80.0 < lockpicking)
|
|
{
|
|
DisplayTo(_from, _panel, _step, true);
|
|
_panel.m_LastUse = Core.Now;
|
|
}
|
|
else
|
|
{
|
|
_panel.DoDamage(_from);
|
|
_panel.m_User = null;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
var curNode = _panel.Path[_step];
|
|
|
|
int newX, newY;
|
|
switch (info.ButtonID)
|
|
{
|
|
case 1: // Left
|
|
{
|
|
newX = curNode.X - 1;
|
|
newY = curNode.Y;
|
|
break;
|
|
}
|
|
case 2: // Up
|
|
{
|
|
newX = curNode.X;
|
|
newY = curNode.Y - 1;
|
|
break;
|
|
}
|
|
case 3: // Right
|
|
{
|
|
newX = curNode.X + 1;
|
|
newY = curNode.Y;
|
|
break;
|
|
}
|
|
case 4: // Down
|
|
{
|
|
newX = curNode.X;
|
|
newY = curNode.Y + 1;
|
|
break;
|
|
}
|
|
|
|
default:
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
|
|
if (nextNode.X == newX && nextNode.Y == newY)
|
|
{
|
|
if (_step + 1 == _panel.Path.Length - 1)
|
|
{
|
|
_panel.Solve(_from);
|
|
_panel.m_User = null;
|
|
}
|
|
else
|
|
{
|
|
_from.PlaySound(0x1F4);
|
|
DisplayTo(_from, _panel, _step + 1, false);
|
|
_panel.m_LastUse = Core.Now;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
_panel.DoDamage(_from);
|
|
_panel.m_User = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum NodeHue
|
|
{
|
|
Gray,
|
|
Blue,
|
|
Red
|
|
}
|
|
}
|
|
|
|
private class DamageTimer : Timer
|
|
{
|
|
private readonly ControlPanel m_Panel;
|
|
private readonly Mobile m_To;
|
|
private int m_Step;
|
|
|
|
public DamageTimer(ControlPanel panel, Mobile to) : base(TimeSpan.FromSeconds(5.0), TimeSpan.FromSeconds(5.0))
|
|
{
|
|
m_Panel = panel;
|
|
m_To = to;
|
|
m_Step = 0;
|
|
}
|
|
|
|
protected override void OnTick()
|
|
{
|
|
if (m_Panel.Deleted || m_To.Deleted || !m_To.Alive)
|
|
{
|
|
End();
|
|
return;
|
|
}
|
|
|
|
m_To.PlaySound(0x28);
|
|
|
|
// * Your body convulses from electric shock *
|
|
m_To.LocalOverheadMessage(MessageType.Regular, 0xC9, 1114443);
|
|
|
|
// * ~1_NAME~ spasms from electric shock *
|
|
m_To.NonlocalOverheadMessage(MessageType.Regular, 0xC9, 1114444, m_To.Name);
|
|
|
|
AOS.Damage(m_To, m_To, 20, 0, 0, 0, 0, 100);
|
|
|
|
if (++m_Step >= 3 || !m_To.Alive)
|
|
{
|
|
End();
|
|
}
|
|
}
|
|
|
|
private void End()
|
|
{
|
|
m_Panel.m_DamageTable.Remove(m_To);
|
|
m_To.Frozen = false;
|
|
|
|
Stop();
|
|
}
|
|
}
|
|
}
|