fix: Fixes edge cases with on off items (#1832)
### Summary - Generalizes the On/Off toggle items concept - Updates the OnOffGump so it is static - Standardizes OnOff items so they can be used by staff ### Notes Decided to not fix #1417 because it is not clear that the clilocs or errors are for that purpose. Can't test this on OSI anyways.
This commit is contained in:
parent
f756cce0c7
commit
19f65dcabe
10 changed files with 141 additions and 146 deletions
|
|
@ -1,6 +1,5 @@
|
|||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
|
||||
namespace Server.Tests;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
using Server.Compression;
|
||||
using Server.Gumps;
|
||||
|
|
|
|||
|
|
@ -14,8 +14,6 @@
|
|||
*************************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server;
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
*************************************************************************/
|
||||
|
||||
using System.Drawing;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
using System;
|
||||
using System.Buffers;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using Server.Compression;
|
||||
|
||||
namespace Server.Network
|
||||
|
|
|
|||
75
Projects/UOContent/Items/Misc/GumpToggleItems.cs
Normal file
75
Projects/UOContent/Items/Misc/GumpToggleItems.cs
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items;
|
||||
|
||||
public interface IGumpToggleItem
|
||||
{
|
||||
public bool IsLockedDown { get; }
|
||||
public bool TurnedOn { get; set; }
|
||||
}
|
||||
|
||||
public sealed class TurnOnGump : TurnOnOffGump<TurnOnGump>
|
||||
{
|
||||
public TurnOnGump(IGumpToggleItem item) : base(item)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void BuildLayout(ref StaticGumpBuilder builder)
|
||||
{
|
||||
base.BuildLayout(ref builder);
|
||||
|
||||
builder.AddHtmlLocalized(45, 20, 300, 35, 1011034); // Activate this item
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TurnOffGump : TurnOnOffGump<TurnOffGump>
|
||||
{
|
||||
public TurnOffGump(IGumpToggleItem item) : base(item)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void BuildLayout(ref StaticGumpBuilder builder)
|
||||
{
|
||||
base.BuildLayout(ref builder);
|
||||
|
||||
builder.AddHtmlLocalized(45, 20, 300, 35, 1011035); // Deactivate this item
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class TurnOnOffGump<T> : StaticGump<T> where T : TurnOnOffGump<T>
|
||||
{
|
||||
protected readonly IGumpToggleItem _item;
|
||||
|
||||
public TurnOnOffGump(IGumpToggleItem item) : base(150, 200) => _item = item;
|
||||
|
||||
protected override void BuildLayout(ref StaticGumpBuilder builder)
|
||||
{
|
||||
builder.AddBackground(0, 0, 300, 150, 0xA28);
|
||||
|
||||
builder.AddButton(40, 53, 0xFA5, 0xFA7, 1);
|
||||
builder.AddHtmlLocalized(80, 55, 65, 35, 1011036); // OKAY
|
||||
|
||||
builder.AddButton(150, 53, 0xFA5, 0xFA7, 0);
|
||||
builder.AddHtmlLocalized(190, 55, 100, 35, 1011012); // CANCEL
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, in RelayInfo info)
|
||||
{
|
||||
var from = sender.Mobile;
|
||||
|
||||
if (info.ButtonID != 1)
|
||||
{
|
||||
from.SendLocalizedMessage(502694); // Cancelled action.
|
||||
return;
|
||||
}
|
||||
|
||||
var newValue = !_item.TurnedOn;
|
||||
_item.TurnedOn = newValue;
|
||||
|
||||
if (newValue && !_item.IsLockedDown)
|
||||
{
|
||||
from.SendLocalizedMessage(502693); // Remember, this only works when locked down.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,10 @@
|
|||
using ModernUO.Serialization;
|
||||
using Server.Gumps;
|
||||
using Server.Multis;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items;
|
||||
|
||||
[SerializationGenerator(0, false)]
|
||||
public abstract partial class BaseWindChimes : Item
|
||||
public abstract partial class BaseWindChimes : Item, IGumpToggleItem
|
||||
{
|
||||
[InvalidateProperties]
|
||||
[SerializableField(0)]
|
||||
|
|
@ -46,55 +44,22 @@ public abstract partial class BaseWindChimes : Item
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsOwner(Mobile mob) => BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;
|
||||
public bool HasAccess(Mobile mob) => mob.AccessLevel >= AccessLevel.GameMaster ||
|
||||
BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if (IsOwner(from))
|
||||
{
|
||||
from.SendGump(new OnOffGump(this));
|
||||
}
|
||||
else
|
||||
if (!HasAccess(from))
|
||||
{
|
||||
from.SendLocalizedMessage(502691); // You must be the owner to use this.
|
||||
}
|
||||
}
|
||||
|
||||
private class OnOffGump : Gump
|
||||
{
|
||||
private readonly BaseWindChimes m_Chimes;
|
||||
|
||||
public OnOffGump(BaseWindChimes chimes) : base(150, 200)
|
||||
else if (TurnedOn)
|
||||
{
|
||||
m_Chimes = chimes;
|
||||
|
||||
AddBackground(0, 0, 300, 150, 0xA28);
|
||||
AddHtmlLocalized(45, 20, 300, 35, chimes.TurnedOn ? 1011035 : 1011034); // [De]Activate this item
|
||||
AddButton(40, 53, 0xFA5, 0xFA7, 1);
|
||||
AddHtmlLocalized(80, 55, 65, 35, 1011036); // OKAY
|
||||
AddButton(150, 53, 0xFA5, 0xFA7, 0);
|
||||
AddHtmlLocalized(190, 55, 100, 35, 1011012); // CANCEL
|
||||
from.SendGump(new TurnOffGump(this));
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, in RelayInfo info)
|
||||
else
|
||||
{
|
||||
var from = sender.Mobile;
|
||||
|
||||
if (info.ButtonID == 1)
|
||||
{
|
||||
var newValue = !m_Chimes.TurnedOn;
|
||||
|
||||
m_Chimes.TurnedOn = newValue;
|
||||
|
||||
if (newValue && !m_Chimes.IsLockedDown)
|
||||
{
|
||||
from.SendLocalizedMessage(502693); // Remember, this only works when locked down.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(502694); // Cancelled action.
|
||||
}
|
||||
from.SendGump(new TurnOnGump(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,6 @@
|
|||
using System;
|
||||
using ModernUO.Serialization;
|
||||
using Server.Engines.VeteranRewards;
|
||||
using Server.Gumps;
|
||||
using Server.Multis;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Items;
|
||||
|
||||
|
|
@ -53,55 +50,55 @@ public enum MonsterStatuetteType
|
|||
|
||||
public class MonsterStatuetteInfo
|
||||
{
|
||||
private static readonly MonsterStatuetteInfo[] m_Table =
|
||||
{
|
||||
/* Crocodile */ new(1041249, 0x20DA, 660),
|
||||
/* Daemon */ new(1041250, 0x20D3, 357),
|
||||
/* Dragon */ new(1041251, 0x20D6, 362),
|
||||
/* EarthElemental */ new(1041252, 0x20D7, 268),
|
||||
/* Ettin */ new(1041253, 0x20D8, 367),
|
||||
/* Gargoyle */ new(1041254, 0x20D9, 372),
|
||||
/* Gorilla */ new(1041255, 0x20F5, 158),
|
||||
/* Lich */ new(1041256, 0x20F8, 1001),
|
||||
/* Lizardman */ new(1041257, 0x20DE, 417),
|
||||
/* Ogre */ new(1041258, 0x20DF, 427),
|
||||
/* Orc */ new(1041259, 0x20E0, 1114),
|
||||
/* Ratman */ new(1041260, 0x20E3, 437),
|
||||
/* Skeleton */ new(1041261, 0x20E7, 1165),
|
||||
/* Troll */ new(1041262, 0x20E9, 461),
|
||||
/* Cow */ new(1041263, 0x2103, 120),
|
||||
/* Zombie */ new(1041264, 0x20EC, 471),
|
||||
/* Llama */ new(1041265, 0x20F6, 1011),
|
||||
/* Ophidian */ new(1049742, 0x2133, 634),
|
||||
/* Reaper */ new(1049743, 0x20FA, 442),
|
||||
/* Mongbat */ new(1049744, 0x20F9, 422),
|
||||
/* Gazer */ new(1049768, 0x20F4, 377),
|
||||
/* FireElemental */ new(1049769, 0x20F3, 838),
|
||||
/* Wolf */ new(1049770, 0x2122, 229),
|
||||
/* Phillip's Steed */ new(1063488, 0x3FFE, 168),
|
||||
/* Seahorse */ new(1070819, 0x25BA, 138),
|
||||
/* Harrower */ new(1080520, 0x25BB, new[] { 0x289, 0x28A, 0x28B }),
|
||||
/* Efreet */ new(1080521, 0x2590, 0x300),
|
||||
/* Slime */ new(1015246, 0x20E8, 456),
|
||||
/* PlagueBeast */ new(1029747, 0x2613, 0x1BF),
|
||||
/* RedDeath */ new(1094932, 0x2617, Array.Empty<int>()),
|
||||
/* Spider */ new(1029668, 0x25C4, 1170),
|
||||
/* OphidianArchMage */ new(1029641, 0x25A9, 639),
|
||||
/* OphidianWarrior */ new(1029645, 0x25AD, 634),
|
||||
/* OphidianKnight */ new(1029642, 0x25aa, 634),
|
||||
/* OphidianMage */ new(1029643, 0x25ab, 639),
|
||||
/* DreadHorn */ new(1031651, 0x2D83, 0xA8),
|
||||
/* Minotaur */ new(1031657, 0x2D89, 0x596),
|
||||
/* Black Cat */ new(1096928, 0x4688, 0x69),
|
||||
/* HalloweenGhoul */ new(1076782, 0x2109, 0x482),
|
||||
/* Santa */ new(1097968, 0x4A98, 0x669)
|
||||
};
|
||||
private static readonly MonsterStatuetteInfo[] _table =
|
||||
[
|
||||
/* Crocodile */new MonsterStatuetteInfo(1041249, 0x20DA, 660),
|
||||
/* Daemon */ new MonsterStatuetteInfo(1041250, 0x20D3, 357),
|
||||
/* Dragon */ new MonsterStatuetteInfo(1041251, 0x20D6, 362),
|
||||
/* EarthElemental */ new MonsterStatuetteInfo(1041252, 0x20D7, 268),
|
||||
/* Ettin */ new MonsterStatuetteInfo(1041253, 0x20D8, 367),
|
||||
/* Gargoyle */ new MonsterStatuetteInfo(1041254, 0x20D9, 372),
|
||||
/* Gorilla */ new MonsterStatuetteInfo(1041255, 0x20F5, 158),
|
||||
/* Lich */ new MonsterStatuetteInfo(1041256, 0x20F8, 1001),
|
||||
/* Lizardman */ new MonsterStatuetteInfo(1041257, 0x20DE, 417),
|
||||
/* Ogre */ new MonsterStatuetteInfo(1041258, 0x20DF, 427),
|
||||
/* Orc */ new MonsterStatuetteInfo(1041259, 0x20E0, 1114),
|
||||
/* Ratman */ new MonsterStatuetteInfo(1041260, 0x20E3, 437),
|
||||
/* Skeleton */ new MonsterStatuetteInfo(1041261, 0x20E7, 1165),
|
||||
/* Troll */ new MonsterStatuetteInfo(1041262, 0x20E9, 461),
|
||||
/* Cow */ new MonsterStatuetteInfo(1041263, 0x2103, 120),
|
||||
/* Zombie */ new MonsterStatuetteInfo(1041264, 0x20EC, 471),
|
||||
/* Llama */ new MonsterStatuetteInfo(1041265, 0x20F6, 1011),
|
||||
/* Ophidian */ new MonsterStatuetteInfo(1049742, 0x2133, 634),
|
||||
/* Reaper */ new MonsterStatuetteInfo(1049743, 0x20FA, 442),
|
||||
/* Mongbat */ new MonsterStatuetteInfo(1049744, 0x20F9, 422),
|
||||
/* Gazer */ new MonsterStatuetteInfo(1049768, 0x20F4, 377),
|
||||
/* FireElemental */ new MonsterStatuetteInfo(1049769, 0x20F3, 838),
|
||||
/* Wolf */ new MonsterStatuetteInfo(1049770, 0x2122, 229),
|
||||
/* Phillip's Steed */ new MonsterStatuetteInfo(1063488, 0x3FFE, 168),
|
||||
/* Seahorse */ new MonsterStatuetteInfo(1070819, 0x25BA, 138),
|
||||
/* Harrower */ new MonsterStatuetteInfo(1080520, 0x25BB, [0x289, 0x28A, 0x28B]),
|
||||
/* Efreet */ new MonsterStatuetteInfo(1080521, 0x2590, 0x300),
|
||||
/* Slime */ new MonsterStatuetteInfo(1015246, 0x20E8, 456),
|
||||
/* PlagueBeast */ new MonsterStatuetteInfo(1029747, 0x2613, 0x1BF),
|
||||
/* RedDeath */ new MonsterStatuetteInfo(1094932, 0x2617, []),
|
||||
/* Spider */ new MonsterStatuetteInfo(1029668, 0x25C4, 1170),
|
||||
/* OphidianArchMage */ new MonsterStatuetteInfo(1029641, 0x25A9, 639),
|
||||
/* OphidianWarrior */ new MonsterStatuetteInfo(1029645, 0x25AD, 634),
|
||||
/* OphidianKnight */ new MonsterStatuetteInfo(1029642, 0x25aa, 634),
|
||||
/* OphidianMage */ new MonsterStatuetteInfo(1029643, 0x25ab, 639),
|
||||
/* DreadHorn */ new MonsterStatuetteInfo(1031651, 0x2D83, 0xA8),
|
||||
/* Minotaur */ new MonsterStatuetteInfo(1031657, 0x2D89, 0x596),
|
||||
/* Black Cat */ new MonsterStatuetteInfo(1096928, 0x4688, 0x69),
|
||||
/* HalloweenGhoul */ new MonsterStatuetteInfo(1076782, 0x2109, 0x482),
|
||||
/* Santa */ new MonsterStatuetteInfo(1097968, 0x4A98, 0x669)
|
||||
];
|
||||
|
||||
public MonsterStatuetteInfo(int labelNumber, int itemID, int baseSoundID)
|
||||
{
|
||||
LabelNumber = labelNumber;
|
||||
ItemID = itemID;
|
||||
Sounds = new[] { baseSoundID, baseSoundID + 1, baseSoundID + 2, baseSoundID + 3, baseSoundID + 4 };
|
||||
Sounds = [baseSoundID, baseSoundID + 1, baseSoundID + 2, baseSoundID + 3, baseSoundID + 4];
|
||||
}
|
||||
|
||||
public MonsterStatuetteInfo(int labelNumber, int itemID, int[] sounds)
|
||||
|
|
@ -121,17 +118,17 @@ public class MonsterStatuetteInfo
|
|||
{
|
||||
var v = (int)type;
|
||||
|
||||
if (v < 0 || v >= m_Table.Length)
|
||||
if (v < 0 || v >= _table.Length)
|
||||
{
|
||||
v = 0;
|
||||
}
|
||||
|
||||
return m_Table[v];
|
||||
return _table[v];
|
||||
}
|
||||
}
|
||||
|
||||
[SerializationGenerator(0, false)]
|
||||
public partial class MonsterStatuette : Item, IRewardItem
|
||||
public partial class MonsterStatuette : Item, IRewardItem, IGumpToggleItem
|
||||
{
|
||||
[InvalidateProperties]
|
||||
[SerializableField(1)]
|
||||
|
|
@ -203,13 +200,16 @@ public partial class MonsterStatuette : Item, IRewardItem
|
|||
base.OnMovement(m, oldLocation);
|
||||
}
|
||||
|
||||
private static readonly object[] _typeArgs = new object[1];
|
||||
|
||||
public override void GetProperties(IPropertyList list)
|
||||
{
|
||||
base.GetProperties(list);
|
||||
|
||||
if (Core.ML && IsRewardItem)
|
||||
{
|
||||
list.Add(RewardSystem.GetRewardYearLabel(this, new object[] { _type })); // X Year Veteran Reward
|
||||
_typeArgs[0] = _type;
|
||||
list.Add(RewardSystem.GetRewardYearLabel(this, _typeArgs)); // X Year Veteran Reward
|
||||
}
|
||||
|
||||
if (_turnedOn)
|
||||
|
|
@ -222,58 +222,22 @@ public partial class MonsterStatuette : Item, IRewardItem
|
|||
}
|
||||
}
|
||||
|
||||
public bool IsOwner(Mobile mob) => BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;
|
||||
public bool HasAccess(Mobile mob) => mob.AccessLevel >= AccessLevel.GameMaster ||
|
||||
BaseHouse.FindHouseAt(this)?.IsOwner(mob) == true;
|
||||
|
||||
public override void OnDoubleClick(Mobile from)
|
||||
{
|
||||
if (IsOwner(from))
|
||||
{
|
||||
var onOffGump = new OnOffGump(this);
|
||||
from.SendGump(onOffGump);
|
||||
}
|
||||
else
|
||||
if (!HasAccess(from))
|
||||
{
|
||||
from.SendLocalizedMessage(502691); // You must be the owner to use this.
|
||||
}
|
||||
}
|
||||
|
||||
private class OnOffGump : Gump
|
||||
{
|
||||
private readonly MonsterStatuette m_Statuette;
|
||||
|
||||
public OnOffGump(MonsterStatuette statuette) : base(150, 200)
|
||||
else if (TurnedOn)
|
||||
{
|
||||
m_Statuette = statuette;
|
||||
|
||||
AddBackground(0, 0, 300, 150, 0xA28);
|
||||
|
||||
AddHtmlLocalized(45, 20, 300, 35, statuette.TurnedOn ? 1011035 : 1011034); // [De]Activate this item
|
||||
|
||||
AddButton(40, 53, 0xFA5, 0xFA7, 1);
|
||||
AddHtmlLocalized(80, 55, 65, 35, 1011036); // OKAY
|
||||
|
||||
AddButton(150, 53, 0xFA5, 0xFA7, 0);
|
||||
AddHtmlLocalized(190, 55, 100, 35, 1011012); // CANCEL
|
||||
from.SendGump(new TurnOffGump(this));
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, in RelayInfo info)
|
||||
else
|
||||
{
|
||||
var from = sender.Mobile;
|
||||
|
||||
if (info.ButtonID == 1)
|
||||
{
|
||||
var newValue = !m_Statuette.TurnedOn;
|
||||
m_Statuette.TurnedOn = newValue;
|
||||
|
||||
if (newValue && !m_Statuette.IsLockedDown)
|
||||
{
|
||||
from.SendLocalizedMessage(502693); // Remember, this only works when locked down.
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
from.SendLocalizedMessage(502694); // Cancelled action.
|
||||
}
|
||||
from.SendGump(new TurnOnGump(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using Server.Accounting;
|
||||
using Server.Logging;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue