# New Gump API We are pleased to release a new API that is faster, allocates nearly zero memory, and still feels very similar to the original API. The API is broken into 3 types of gumps, dynamic, static with placeholders, and static without placeholders. ### Dynamic Gumps These gumps will inherit `DynamicGump` and are meant for gumps that have a dynamic layout. This includes specifying dynamic arguments to HtmlLocalized entries. ## Static Gumps Static gumps are those where the function to the build the layout is called only once and cached forever. They can optionally have placeholders. These placeholders allow the developer to specify the string values later, dynamically in a `BuildStrings` method on the gump. If a gump does not have any placeholders, the string entries will also be cached forever. ## Benchmarks To make sure we were going in the right direction and not wasting time, we took copious benchmarks. Here are the final benchmarks for a really simple gump. Note: * The majority of creating a gump is compressing the layout and the strings. Compressing each section takes ~6,000ns (12us total). ```cs | Method | Mean | Error | StdDev | Median | Ratio | RatioSD | Gen0 | Allocated | Alloc Ratio | |------------------------------- |-------------:|-------------:|-------------:|-------------:|------:|--------:|-------:|----------:|------------:| | OldGump | 13,308.29 ns | 1,059.695 ns | 1,883.608 ns | 14,330.72 ns | 1.000 | 0.00 | 0.1526 | 2400 B | 1.00 | | DynamicLayoutGump | 13,357.86 ns | 129.144 ns | 226.185 ns | 13,323.60 ns | 1.029 | 0.17 | - | 48 B | 0.02 | | StaticLayoutDynamicStringsGump | 6,653.10 ns | 81.815 ns | 143.292 ns | 6,617.45 ns | 0.514 | 0.09 | - | 40 B | 0.02 | | StaticLayoutGump | 86.33 ns | 0.760 ns | 1.350 ns | 86.07 ns | 0.007 | 0.00 | 0.0020 | 32 B | 0.01 | ``` # Non-Breaking Changes * All gump components in the core have been moved to `Gumps/Legacy`. * All legacy gumps will still inherit `Gump`, which now inherits `BaseGump` # Special Thanks Thank you to @stefanomerotta for considerable contributions/benchmarking/testing to make this effort a reality! We collectively went through over 10 iterations, but it is finally ready.
88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
using Server.Mobiles;
|
|
using Server.Network;
|
|
|
|
namespace Server.Gumps;
|
|
|
|
public class PetResurrectGump : StaticGump<PetResurrectGump>
|
|
{
|
|
private readonly double _hitsScalar;
|
|
private readonly BaseCreature _pet;
|
|
|
|
public PetResurrectGump(Mobile from, BaseCreature pet, double hitsScalar = 0.0) : base(50, 50)
|
|
{
|
|
from.CloseGump<PetResurrectGump>();
|
|
|
|
_pet = pet;
|
|
_hitsScalar = hitsScalar;
|
|
}
|
|
|
|
protected override void BuildLayout(ref StaticGumpBuilder builder)
|
|
{
|
|
builder.AddPage();
|
|
|
|
builder.AddBackground(10, 10, 265, 140, 0x242C);
|
|
|
|
builder.AddItem(205, 40, 0x4);
|
|
builder.AddItem(227, 40, 0x5);
|
|
|
|
builder.AddItem(180, 78, 0xCAE);
|
|
builder.AddItem(195, 90, 0xCAD);
|
|
builder.AddItem(218, 95, 0xCB0);
|
|
|
|
// <div align=center>Wilt thou sanctify the resurrection of:</div>
|
|
builder.AddHtmlLocalized(30, 30, 150, 75, 1049665);
|
|
builder.AddHtmlPlaceholder(30, 70, 150, 25, "petName", true);
|
|
|
|
builder.AddButton(40, 105, 0x81A, 0x81B, 0x1); // Okay
|
|
builder.AddButton(110, 105, 0x819, 0x818, 0x2); // Cancel
|
|
}
|
|
|
|
protected override void BuildStrings(ref GumpStringsBuilder builder)
|
|
{
|
|
builder.SetStringSlot("petName", $"<CENTER>{_pet.Name}</CENTER>");
|
|
}
|
|
|
|
public override void OnResponse(NetState state, in RelayInfo info)
|
|
{
|
|
if (_pet.Deleted || !_pet.IsBonded || !_pet.IsDeadPet)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var from = state.Mobile;
|
|
|
|
if (info.ButtonID != 1)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_pet.Map?.CanFit(_pet.Location, 16, false, false) != true)
|
|
{
|
|
from.SendLocalizedMessage(503256); // You fail to resurrect the creature.
|
|
return;
|
|
}
|
|
|
|
if (_pet.Region?.IsPartOf("Khaldun") == true) // TODO: Confirm for pets, as per Bandage's script.
|
|
{
|
|
// The veil of death in this area is too strong and resists thy efforts to restore life.
|
|
from.SendLocalizedMessage(1010395);
|
|
return;
|
|
}
|
|
|
|
_pet.PlaySound(0x214);
|
|
_pet.FixedEffect(0x376A, 10, 16);
|
|
_pet.ResurrectPet();
|
|
|
|
var decreaseAmount = from == _pet.ControlMaster ? 0.1 : 0.2;
|
|
|
|
for (var i = 0; i < _pet.Skills.Length; ++i) // Decrease all skills on pet.
|
|
{
|
|
_pet.Skills[i].Base -= decreaseAmount;
|
|
}
|
|
|
|
if (!_pet.IsDeadPet && _hitsScalar > 0)
|
|
{
|
|
_pet.Hits = (int)(_pet.HitsMax * _hitsScalar);
|
|
}
|
|
}
|
|
}
|