fix: Updates BOB/BOD gumps to the new API (#2250)

### Summary

* Moves BOBGump to DynamicGump.
* BOBGump no longer creates a whole new gump context object on every send.
* Moves BODBuyGump to StaticGump.
This commit is contained in:
Kamron Batman 2025-09-07 12:50:20 -07:00 committed by GitHub
parent 340acafcb3
commit 641a3eb1f8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 750 additions and 769 deletions

File diff suppressed because it is too large Load diff

View file

@ -3,135 +3,142 @@ using Server.Items;
using Server.Mobiles;
using Server.Network;
namespace Server.Engines.BulkOrders
namespace Server.Engines.BulkOrders;
public class BODBuyGump : StaticGump<BODBuyGump>
{
public class BODBuyGump : Gump
private BOBGump _gump;
private readonly IBOBEntry _entry;
private readonly int _price;
public BODBuyGump(BOBGump gump, IBOBEntry entry, int price) : base(100, 200)
{
private readonly BulkOrderBook m_Book;
private readonly IBOBEntry m_Entry;
private readonly PlayerMobile m_From;
private readonly int m_Page;
private readonly int m_Price;
_gump = gump;
_entry = entry;
_price = price;
}
public BODBuyGump(PlayerMobile from, BulkOrderBook book, IBOBEntry entry, int page, int price) : base(100, 200)
protected override void BuildLayout(ref StaticGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(100, 10, 300, 150, 5054);
builder.AddHtmlLocalized(125, 20, 250, 24, 1019070); // You have agreed to purchase:
builder.AddHtmlLocalized(125, 45, 250, 24, 1045151); // a bulk order deed
builder.AddHtmlLocalized(125, 70, 250, 24, 1019071); // for the amount of:
builder.AddLabelPlaceholder(125, 95, 0, "price");
builder.AddButton(250, 130, 4005, 4007, 1);
builder.AddHtmlLocalized(282, 130, 100, 24, 1011012); // CANCEL
builder.AddButton(120, 130, 4005, 4007, 2);
builder.AddHtmlLocalized(152, 130, 100, 24, 1011036); // OKAY
}
protected override void BuildStrings(ref GumpStringsBuilder builder)
{
builder.SetStringSlot("price", $"{_price:N0}");
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (sender.Mobile is not PlayerMobile pm)
{
m_From = from;
m_Book = book;
m_Entry = entry;
m_Price = price;
m_Page = page;
AddPage(0);
AddBackground(100, 10, 300, 150, 5054);
AddHtmlLocalized(125, 20, 250, 24, 1019070); // You have agreed to purchase:
AddHtmlLocalized(125, 45, 250, 24, 1045151); // a bulk order deed
AddHtmlLocalized(125, 70, 250, 24, 1019071); // for the amount of:
AddLabel(125, 95, 0, price.ToString());
AddButton(250, 130, 4005, 4007, 1);
AddHtmlLocalized(282, 130, 100, 24, 1011012); // CANCEL
AddButton(120, 130, 4005, 4007, 2);
AddHtmlLocalized(152, 130, 100, 24, 1011036); // OKAY
return;
}
public override void OnResponse(NetState sender, in RelayInfo info)
if (info.ButtonID != 2)
{
if (info.ButtonID != 2)
{
m_From.SendLocalizedMessage(503207); // Cancelled purchase.
return;
}
pm.SendLocalizedMessage(503207); // Cancelled purchase.
return;
}
if (m_Book.RootParent is not PlayerVendor pv)
{
m_From.SendLocalizedMessage(1062382); // The deed selected is not available.
return;
}
var book = _gump.Book;
if (!m_Book.Entries.Contains(m_Entry))
{
pv.SayTo(m_From, 1062382); // The deed selected is not available.
return;
}
if (book.RootParent is not PlayerVendor pv)
{
pm.SendLocalizedMessage(1062382); // The deed selected is not available.
return;
}
var price = 0;
if (!book.Entries.Contains(_entry))
{
pv.SayTo(pm, 1062382); // The deed selected is not available.
return;
}
if (pv.GetVendorItem(m_Book)?.IsForSale == false)
{
price = m_Entry.Price;
}
var price = 0;
if (price != m_Price)
{
pv.SayTo(
m_From,
"The price has been been changed. If you like, you may offer to purchase the item again."
);
return;
}
if (pv.GetVendorItem(book)?.IsForSale == false)
{
price = _entry.Price;
}
if (price == 0)
{
pv.SayTo(m_From, 1062382); // The deed selected is not available.
return;
}
if (price != _price)
{
pv.SayTo(
pm,
"The price has been been changed. If you like, you may offer to purchase the item again."
);
return;
}
var item = m_Entry.Reconstruct();
if (price == 0)
{
pv.SayTo(pm, 1062382); // The deed selected is not available.
return;
}
pv.Say(m_From.Name);
var item = _entry.Reconstruct();
var pack = m_From.Backpack;
pv.Say(pm.Name);
if (pack?.CheckHold(
m_From,
var pack = pm.Backpack;
if (pack?.CheckHold(
pm,
item,
true,
true,
0,
item.PileWeight + item.TotalWeight
) != true)
{
pv.SayTo(pm, 503204); // You do not have room in your backpack for this
pm.SendGump(_gump);
item.Delete();
}
else if (pack.ConsumeTotal(typeof(Gold), price) || Banker.Withdraw(pm, price))
{
book.RemoveEntry(_entry);
pv.HoldGold += price;
pm.AddToBackpack(item);
// The bulk order deed has been placed in your backpack.
pm.SendLocalizedMessage(1045152);
if (book.Entries.Count / 5 < book.ItemCount)
{
pv.SayTo(m_From, 503204); // You do not have room in your backpack for this
m_From.SendGump(new BOBGump(m_From, m_Book, m_Page));
item.Delete();
book.ItemCount--;
book.InvalidateItems();
}
if (book.Entries.Count > 0)
{
_gump.ResetList();
pm.SendGump(_gump);
}
else
{
if (pack.ConsumeTotal(typeof(Gold), price) || Banker.Withdraw(m_From, price))
{
m_Book.RemoveEntry(m_Entry);
m_Book.InvalidateProperties();
pv.HoldGold += price;
m_From.AddToBackpack(item);
// The bulk order deed has been placed in your backpack.
m_From.SendLocalizedMessage(1045152);
if (m_Book.Entries.Count / 5 < m_Book.ItemCount)
{
m_Book.ItemCount--;
m_Book.InvalidateItems();
}
if (m_Book.Entries.Count > 0)
{
m_From.SendGump(new BOBGump(m_From, m_Book, m_Page));
}
else
{
m_From.SendLocalizedMessage(1062381); // The book is empty.
}
}
else
{
pv.SayTo(m_From, 503205); // You cannot afford this item.
item.Delete();
}
pm.SendLocalizedMessage(1062381); // The book is empty.
}
}
else
{
pv.SayTo(pm, 503205); // You cannot afford this item.
item.Delete();
}
}
}