From 76bdc7ac02ad81c8251f792111df09870a4983fc Mon Sep 17 00:00:00 2001 From: Guyute Date: Sat, 10 Aug 2024 13:16:47 -0400 Subject: [PATCH] fix: Moves pricing from PricedHealer to BaseHealer - Combines Res Gumps (#1920) --- .../UOContent/Gumps/PricedResurrectGump.cs | 146 ------------------ Projects/UOContent/Gumps/ResurrectGump.cs | 100 +++++++++++- .../Server.Mobiles.BaseHealer.v3.json | 14 ++ .../Server.Mobiles.PricedHealer.v1.json | 4 + .../UOContent/Mobiles/Healers/BaseHealer.cs | 27 +++- .../UOContent/Mobiles/Healers/PricedHealer.cs | 25 +-- 6 files changed, 142 insertions(+), 174 deletions(-) delete mode 100644 Projects/UOContent/Gumps/PricedResurrectGump.cs create mode 100644 Projects/UOContent/Migrations/Server.Mobiles.BaseHealer.v3.json create mode 100644 Projects/UOContent/Migrations/Server.Mobiles.PricedHealer.v1.json diff --git a/Projects/UOContent/Gumps/PricedResurrectGump.cs b/Projects/UOContent/Gumps/PricedResurrectGump.cs deleted file mode 100644 index 3d173c38b..000000000 --- a/Projects/UOContent/Gumps/PricedResurrectGump.cs +++ /dev/null @@ -1,146 +0,0 @@ -using Server.Engines.Virtues; -using Server.Misc; -using Server.Mobiles; -using Server.Network; - -namespace Server.Gumps; - -public class PricedResurrectGump : StaticGump -{ - private readonly Mobile _healer; - private readonly int _price; - - public PricedResurrectGump(Mobile healer, int price) : base(150, 50) - { - _healer = healer; - _price = price; - - TypeID = GetTypeId(typeof(ResurrectGump)); - } - - protected override void BuildLayout(ref StaticGumpBuilder builder) - { - builder.SetNoClose(); - - builder.AddPage(); - - builder.AddImage(0, 0, 3600); - - builder.AddImageTiled(0, 14, 15, 200, 3603); - builder.AddImageTiled(380, 14, 14, 200, 3605); - - builder.AddImage(0, 201, 3606); - - builder.AddImageTiled(15, 201, 370, 16, 3607); - builder.AddImageTiled(15, 0, 370, 16, 3601); - - builder.AddImage(380, 0, 3602); - - builder.AddImage(380, 201, 3608); - - builder.AddImageTiled(15, 15, 365, 190, 2624); - - builder.AddRadio(30, 140, 9727, 9730, true, 1); - builder.AddHtmlLocalized(65, 145, 300, 25, 1060015, 0x7FFF); // Grudgingly pay the money - - builder.AddRadio(30, 175, 9727, 9730, false, 0); - builder.AddHtmlLocalized(65, 178, 300, 25, 1060016, 0x7FFF); // I'd rather stay dead, you scoundrel!!! - - // Wishing to rejoin the living, are you? I can restore your body... for a price of course... - builder.AddHtmlLocalized(30, 20, 360, 35, 1060017, 0x7FFF); - - // Do you accept the fee, which will be withdrawn from your bank? - builder.AddHtmlLocalized(30, 105, 345, 40, 1060018, 0x5B2D); - - builder.AddImage(65, 72, 5605); - - builder.AddImageTiled(80, 90, 200, 1, 9107); - builder.AddImageTiled(95, 92, 200, 1, 9157); - - builder.AddLabelPlaceholder(90, 70, 1645, "resurrectionPrice"); - builder.AddHtmlLocalized(140, 70, 100, 25, 1023823, 0x7FFF); // gold coins - - builder.AddButton(290, 175, 247, 248, 2); - - builder.AddImageTiled(15, 14, 365, 1, 9107); - builder.AddImageTiled(380, 14, 1, 190, 9105); - builder.AddImageTiled(15, 205, 365, 1, 9107); - builder.AddImageTiled(15, 14, 1, 190, 9105); - builder.AddImageTiled(0, 0, 395, 1, 9157); - builder.AddImageTiled(394, 0, 1, 217, 9155); - builder.AddImageTiled(0, 216, 395, 1, 9157); - builder.AddImageTiled(0, 0, 1, 217, 9155); - } - - protected override void BuildStrings(ref GumpStringsBuilder builder) - { - builder.SetStringSlot("resurrectionPrice", $"{_price}"); - } - - public override void OnResponse(NetState state, in RelayInfo info) - { - if (info.ButtonID is not 1 and not 2) - { - return; - } - - var from = state.Mobile; - - if (from.Map?.CanFit(from.Location, 16, false, false) != true) - { - from.SendLocalizedMessage(502391); // Thou can not be resurrected there! - return; - } - - if (!info.IsSwitched(1)) - { - from.SendLocalizedMessage(1060019); // You decide against paying the healer, and thus remain dead. - return; - } - - if (Banker.Withdraw(from, _price)) - { - // ~1_AMOUNT~ gold has been withdrawn from your bank to cover the price of the healing. - from.SendLocalizedMessage(1060021, _price.ToString()); - - // You have ~1_AMOUNT~ gold in cash remaining in your bank box. - from.SendLocalizedMessage(1060022, Banker.GetBalance(from).ToString()); - } - else - { - // Unfortunately, you do not have enough cash in your bank to cover the cost of the healing. - from.SendLocalizedMessage(1060020); - return; - } - - from.PlaySound(0x214); - from.FixedEffect(0x376A, 10, 16); - - from.Resurrect(); - - if (_healer != null && from != _healer) - { - var level = VirtueSystem.GetLevel(_healer, VirtueName.Compassion); - - from.Hits = level switch - { - VirtueLevel.Seeker => AOS.Scale(from.HitsMax, 20), - VirtueLevel.Follower => AOS.Scale(from.HitsMax, 40), - VirtueLevel.Knight => AOS.Scale(from.HitsMax, 80), - _ => from.Hits - }; - } - - if (from.Fame > 0) - { - var amount = from.Fame / 10; - - Titles.AwardFame(from, -amount, true); - } - - if (from is PlayerMobile player) - { - ResurrectGump.TryGiveStatLoss(player); - } - } -} diff --git a/Projects/UOContent/Gumps/ResurrectGump.cs b/Projects/UOContent/Gumps/ResurrectGump.cs index cb3e16e3a..6612db956 100644 --- a/Projects/UOContent/Gumps/ResurrectGump.cs +++ b/Projects/UOContent/Gumps/ResurrectGump.cs @@ -22,6 +22,7 @@ public class ResurrectGump : DynamicGump private readonly Mobile _healer; private readonly double _hitsScalar; private readonly ResurrectMessage _resurrectMessage; + private readonly int _price; public override bool Singleton => true; @@ -32,7 +33,11 @@ public class ResurrectGump : DynamicGump return; } - var loss = Math.Clamp((100.0 - (4.0 + player.ShortTermMurders / (double)ShortMurdersForStatLoss)) / 100.0, 0.85, 0.95); // 5 to 15% loss + var loss = Math.Clamp( + (100.0 - (4.0 + player.ShortTermMurders / (double)ShortMurdersForStatLoss)) / 100.0, + 0.85, + 0.95 + ); // 5 to 15% loss var lossStr = (int)(player.RawStr * loss); var lossInt = (int)(player.RawInt * loss); var lossDex = (int)(player.RawDex * loss); @@ -63,23 +68,38 @@ public class ResurrectGump : DynamicGump } } - public ResurrectGump(Mobile healer, double hitsScalar) - : this(healer, ResurrectMessage.Generic, false, hitsScalar) + public ResurrectGump(Mobile healer, double hitsScalar) : this(healer, ResurrectMessage.Generic, false, hitsScalar) + { + } + + public ResurrectGump(Mobile healer, int price) : this(healer, ResurrectMessage.Generic, false, 0, price) { } public ResurrectGump( Mobile healer, ResurrectMessage msg = ResurrectMessage.Generic, - bool fromSacrifice = false, double hitsScalar = 0.0 + bool fromSacrifice = false, double hitsScalar = 0.0, int price = 0 ) : base(100, 0) { _healer = healer; _fromSacrifice = fromSacrifice; _hitsScalar = hitsScalar; _resurrectMessage = msg; + _price = price; } protected override void BuildLayout(ref DynamicGumpBuilder builder) + { + if (_price > 0) + { + BuildPricedLayout(ref builder); + return; + } + + BuildDefaultLayout(ref builder); + } + + private void BuildDefaultLayout(ref DynamicGumpBuilder builder) { builder.AddPage(); @@ -100,6 +120,60 @@ public class ResurrectGump : DynamicGump builder.AddHtmlLocalized(100, 230, 110, 35, 1011011); // CONTINUE } + private void BuildPricedLayout(ref DynamicGumpBuilder builder) + { + builder.SetNoClose(); + + builder.AddPage(); + + builder.AddImage(0, 0, 3600); + + builder.AddImageTiled(0, 14, 15, 200, 3603); + builder.AddImageTiled(380, 14, 14, 200, 3605); + + builder.AddImage(0, 201, 3606); + + builder.AddImageTiled(15, 201, 370, 16, 3607); + builder.AddImageTiled(15, 0, 370, 16, 3601); + + builder.AddImage(380, 0, 3602); + + builder.AddImage(380, 201, 3608); + + builder.AddImageTiled(15, 15, 365, 190, 2624); + + builder.AddRadio(30, 140, 9727, 9730, true, 1); + builder.AddHtmlLocalized(65, 145, 300, 25, 1060015, 0x7FFF); // Grudgingly pay the money + + builder.AddRadio(30, 175, 9727, 9730, false, 0); + builder.AddHtmlLocalized(65, 178, 300, 25, 1060016, 0x7FFF); // I'd rather stay dead, you scoundrel!!! + + // Wishing to rejoin the living, are you? I can restore your body... for a price of course... + builder.AddHtmlLocalized(30, 20, 360, 35, 1060017, 0x7FFF); + + // Do you accept the fee, which will be withdrawn from your bank? + builder.AddHtmlLocalized(30, 105, 345, 40, 1060018, 0x5B2D); + + builder.AddImage(65, 72, 5605); + + builder.AddImageTiled(80, 90, 200, 1, 9107); + builder.AddImageTiled(95, 92, 200, 1, 9157); + + builder.AddLabel(90, 70, 1645, $"{_price}"); + builder.AddHtmlLocalized(140, 70, 100, 25, 1023823, 0x7FFF); // gold coins + + builder.AddButton(290, 175, 247, 248, 2); + + builder.AddImageTiled(15, 14, 365, 1, 9107); + builder.AddImageTiled(380, 14, 1, 190, 9105); + builder.AddImageTiled(15, 205, 365, 1, 9107); + builder.AddImageTiled(15, 14, 1, 190, 9105); + builder.AddImageTiled(0, 0, 395, 1, 9157); + builder.AddImageTiled(394, 0, 1, 217, 9155); + builder.AddImageTiled(0, 216, 395, 1, 9157); + builder.AddImageTiled(0, 0, 1, 217, 9155); + } + public override void OnResponse(NetState state, in RelayInfo info) { if (info.ButtonID is not 1 and not 2) @@ -115,6 +189,24 @@ public class ResurrectGump : DynamicGump return; } + if (_price > 0) + { + if (Banker.Withdraw(from, _price)) + { + // ~1_AMOUNT~ gold has been withdrawn from your bank to cover the price of the healing. + from.SendLocalizedMessage(1060021, _price.ToString()); + + // You have ~1_AMOUNT~ gold in cash remaining in your bank box. + from.SendLocalizedMessage(1060022, Banker.GetBalance(from).ToString()); + } + else + { + // Unfortunately, you do not have enough cash in your bank to cover the cost of the healing. + from.SendLocalizedMessage(1060020); + return; + } + } + from.PlaySound(0x214); from.FixedEffect(0x376A, 10, 16); diff --git a/Projects/UOContent/Migrations/Server.Mobiles.BaseHealer.v3.json b/Projects/UOContent/Migrations/Server.Mobiles.BaseHealer.v3.json new file mode 100644 index 000000000..3641c633b --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Mobiles.BaseHealer.v3.json @@ -0,0 +1,14 @@ +{ + "version": 3, + "type": "Server.Mobiles.BaseHealer", + "properties": [ + { + "name": "Price", + "type": "int", + "rule": "PrimitiveTypeMigrationRule", + "ruleArguments": [ + "" + ] + } + ] +} \ No newline at end of file diff --git a/Projects/UOContent/Migrations/Server.Mobiles.PricedHealer.v1.json b/Projects/UOContent/Migrations/Server.Mobiles.PricedHealer.v1.json new file mode 100644 index 000000000..cbb82d31a --- /dev/null +++ b/Projects/UOContent/Migrations/Server.Mobiles.PricedHealer.v1.json @@ -0,0 +1,4 @@ +{ + "version": 1, + "type": "Server.Mobiles.PricedHealer" +} \ No newline at end of file diff --git a/Projects/UOContent/Mobiles/Healers/BaseHealer.cs b/Projects/UOContent/Mobiles/Healers/BaseHealer.cs index f80acda72..577ab51f1 100644 --- a/Projects/UOContent/Mobiles/Healers/BaseHealer.cs +++ b/Projects/UOContent/Mobiles/Healers/BaseHealer.cs @@ -7,15 +7,25 @@ using Server.Items; namespace Server.Mobiles; -[SerializationGenerator(2, false)] +[SerializationGenerator(3, false)] public abstract partial class BaseHealer : BaseVendor { private static readonly TimeSpan ResurrectDelay = TimeSpan.FromSeconds(2.0); private DateTime _nextResurrect; - public BaseHealer() + [SerializableField(0)] + [SerializedCommandProperty(AccessLevel.GameMaster)] + private int _price; + + public BaseHealer() : this(0) { + } + + public BaseHealer(int price) + { + _price = price; + if (!IsInvulnerable) { AI = AIType.AI_Mage; @@ -86,7 +96,13 @@ public abstract partial class BaseHealer : BaseVendor m.PlaySound(0x1F2); m.FixedEffect(0x376A, 10, 16); - m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer)); + if (_price > 0) + { + m.SendGump(new ResurrectGump(this, _price), true); + return; + } + + m.SendGump(new ResurrectGump(m, ResurrectMessage.Healer), true); } public virtual void OfferHeal(PlayerMobile m) @@ -151,4 +167,9 @@ public abstract partial class BaseHealer : BaseVendor FightMode = FightMode.Aggressor; } } + + private void MigrateFrom(V2Content content) + { + _price = 0; + } } diff --git a/Projects/UOContent/Mobiles/Healers/PricedHealer.cs b/Projects/UOContent/Mobiles/Healers/PricedHealer.cs index 4517cbceb..fdf127374 100644 --- a/Projects/UOContent/Mobiles/Healers/PricedHealer.cs +++ b/Projects/UOContent/Mobiles/Healers/PricedHealer.cs @@ -3,18 +3,12 @@ using Server.Gumps; namespace Server.Mobiles; -[SerializationGenerator(0, false)] +[SerializationGenerator(1, false)] public partial class PricedHealer : BaseHealer { - [SerializableField(0)] - [SerializedCommandProperty(AccessLevel.GameMaster)] - private int _price; - [Constructible] - public PricedHealer(int price = 5000) + public PricedHealer(int price = 5000) : base(price) { - Price = price; - if (!Core.AOS) { NameHue = 0x35; @@ -25,19 +19,8 @@ public partial class PricedHealer : BaseHealer public override bool HealsYoungPlayers => false; - public override void InitSBInfo() + private void MigrateFrom(V0Content content) { + Price = content.Price; } - - public override void OfferResurrection(Mobile m) - { - Direction = GetDirectionTo(m); - - m.PlaySound(0x214); - m.FixedEffect(0x376A, 10, 16); - - m.SendGump(new PricedResurrectGump(this, Price)); - } - - public override bool CheckResurrect(Mobile m) => true; }