From 0a435644ebdda0fe7165b0ce72e3b94cc94f04ed Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 28 Feb 2021 22:49:52 -0800 Subject: [PATCH] feat(spawners): Adds Respawn, EditSpawner, and SpawnProps commands (#532) - [X] Adds `Respawn` command - [X] Adds `EditSpawner` command - Usage: `[global editspawner set ` - This command replaces the arguments (optional) and properties of the affected spawners for that type - [X] Adds `SpawnProps` command - Usage: `[area spawnprops` - This command brings up a gump to modify targeted spawners based on the targeted entity. - To do this, the props/values are copied and then used to construct a properties list for the spawner entry. Closes #531 --- Projects/Server/Commands.cs | 3 +- Projects/Server/World/World.cs | 5 +- Projects/UOContent/Accounting/IPLimiter.cs | 2 + .../Commands/Generic/Commands/BaseCommand.cs | 14 +- .../Commands/Object Creation/Decorate.cs | 2 +- .../Commands/Object Creation/DecorateMag.cs | 2 +- Projects/UOContent/Commands/Properties.cs | 5 +- .../Engines/Harvest/Core/HarvestDefinition.cs | 9 +- .../UOContent/Engines/ML Quests/MLQuest.cs | 2 +- .../Engines/Spawners/EditSpawnCommand.cs | 113 +++++ .../Engines/Spawners/RespawnCommand.cs | 63 +++ .../Engines/Spawners/SpawnPropsGump.cs | 155 +++++++ .../Engines/Spawners/SpawnPropsGumpCommand.cs | 73 ++++ Projects/UOContent/Gumps/Props/PropsConfig.cs | 1 + Projects/UOContent/Gumps/Props/PropsGump.cs | 390 +++++++++--------- Projects/UOContent/Gumps/Props/SetBodyGump.cs | 28 +- .../Gumps/Props/SetCustomEnumGump.cs | 10 +- Projects/UOContent/Gumps/Props/SetGump.cs | 49 +-- .../Gumps/Props/SetListOptionGump.cs | 16 +- .../UOContent/Gumps/Props/SetObjectGump.cs | 43 +- .../UOContent/Gumps/Props/SetObjectTarget.cs | 18 +- .../UOContent/Gumps/Props/SetPoint2DGump.cs | 32 +- .../UOContent/Gumps/Props/SetPoint3DGump.cs | 35 +- .../UOContent/Gumps/Props/SetTimeSpanGump.cs | 15 +- 24 files changed, 708 insertions(+), 377 deletions(-) create mode 100644 Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs create mode 100644 Projects/UOContent/Engines/Spawners/RespawnCommand.cs create mode 100644 Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs create mode 100644 Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs diff --git a/Projects/Server/Commands.cs b/Projects/Server/Commands.cs index 4a3be1edf..29f48bb0a 100644 --- a/Projects/Server/Commands.cs +++ b/Projects/Server/Commands.cs @@ -178,8 +178,7 @@ namespace Server { public static string Prefix { get; set; } = "["; - public static Dictionary Entries { get; } = - new(StringComparer.OrdinalIgnoreCase); + public static Dictionary Entries { get; } = new(StringComparer.OrdinalIgnoreCase); public static AccessLevel BadCommandIgnoreLevel { get; set; } = AccessLevel.Player; diff --git a/Projects/Server/World/World.cs b/Projects/Server/World/World.cs index 08244d57a..bc3bb857c 100644 --- a/Projects/Server/World/World.cs +++ b/Projects/Server/World/World.cs @@ -274,13 +274,14 @@ namespace Server watch.Stop(); Utility.PushColor(ConsoleColor.Green); + Console.Write("done"); + Utility.PopColor(); Console.WriteLine( - "done ({1} items, {2} mobiles) ({0:F2} seconds)", + " ({1} items, {2} mobiles) ({0:F2} seconds)", watch.Elapsed.TotalSeconds, Items.Count, Mobiles.Count ); - Utility.PopColor(); WorldState = WorldState.Running; } diff --git a/Projects/UOContent/Accounting/IPLimiter.cs b/Projects/UOContent/Accounting/IPLimiter.cs index dd2739107..49c72af89 100644 --- a/Projects/UOContent/Accounting/IPLimiter.cs +++ b/Projects/UOContent/Accounting/IPLimiter.cs @@ -26,7 +26,9 @@ namespace Server.Misc for (int i = 0; i < Exemptions.Length; i++) { if (ip.Equals(Exemptions[i])) + { return true; + } } return false; diff --git a/Projects/UOContent/Commands/Generic/Commands/BaseCommand.cs b/Projects/UOContent/Commands/Generic/Commands/BaseCommand.cs index 82160550c..4d5a79d92 100644 --- a/Projects/UOContent/Commands/Generic/Commands/BaseCommand.cs +++ b/Projects/UOContent/Commands/Generic/Commands/BaseCommand.cs @@ -36,16 +36,12 @@ namespace Server.Commands.Generic return true; } - Mobile mob = null; - - if (obj is Mobile m) + Mobile mob = obj switch { - mob = m; - } - else if (obj is Item item) - { - mob = item.RootParent as Mobile; - } + Mobile m => m, + Item item => item.RootParent as Mobile, + _ => null + }; return mob == null || mob == from || from.AccessLevel > mob.AccessLevel; } diff --git a/Projects/UOContent/Commands/Object Creation/Decorate.cs b/Projects/UOContent/Commands/Object Creation/Decorate.cs index ba9979e88..4a99370e9 100644 --- a/Projects/UOContent/Commands/Object Creation/Decorate.cs +++ b/Projects/UOContent/Commands/Object Creation/Decorate.cs @@ -511,7 +511,7 @@ namespace Server.Commands light.ItemID = m_ItemID; } } - else if (item is Spawner sp) + else if (item is BaseSpawner sp) { sp.NextSpawn = TimeSpan.Zero; diff --git a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs index aa05a4653..330d296a0 100644 --- a/Projects/UOContent/Commands/Object Creation/DecorateMag.cs +++ b/Projects/UOContent/Commands/Object Creation/DecorateMag.cs @@ -508,7 +508,7 @@ namespace Server.Commands light.ItemID = m_ItemID; } } - else if (item is Spawner sp) + else if (item is BaseSpawner sp) { sp.NextSpawn = TimeSpan.Zero; diff --git a/Projects/UOContent/Commands/Properties.cs b/Projects/UOContent/Commands/Properties.cs index b889d8422..187cba09a 100644 --- a/Projects/UOContent/Commands/Properties.cs +++ b/Projects/UOContent/Commands/Properties.cs @@ -49,8 +49,8 @@ namespace Server.Commands CommandSystem.Register("Props", AccessLevel.Counselor, Props_OnCommand); } - [Usage("Props [serial]"), - Description("Opens a menu where you can view and edit all properties of a targeted (or specified) object.")] + [Usage("Props [serial]")] + [Description("Opens a menu where you can view and edit all properties of a targeted (or specified) object.")] private static void Props_OnCommand(CommandEventArgs e) { if (e.Length == 1) @@ -597,6 +597,7 @@ namespace Server.Commands return result ?? SetDirect(o, p, toSet); } + private class PropsTarget : Target { public PropsTarget() : base(-1, true, TargetFlags.None) diff --git a/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs b/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs index 5cc7412da..bc7d70bbf 100644 --- a/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs +++ b/Projects/UOContent/Engines/Harvest/Core/HarvestDefinition.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Runtime.CompilerServices; using Server.Random; namespace Server.Engines.Harvest @@ -83,16 +84,16 @@ namespace Server.Engines.Harvest public uint VeinWeights { get; private set; } - public Dictionary> Banks { get; } - = new(); + public Dictionary> Banks { get; } = new(); + [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SendMessageTo(Mobile from, TextDefinition message) { - if (message.Number > 0) + if (message?.Number > 0) { from.SendLocalizedMessage(message.Number); } - else + else if (!string.IsNullOrWhiteSpace(message)) { from.SendMessage(message); } diff --git a/Projects/UOContent/Engines/ML Quests/MLQuest.cs b/Projects/UOContent/Engines/ML Quests/MLQuest.cs index 91d9e60a5..52b1d171a 100644 --- a/Projects/UOContent/Engines/ML Quests/MLQuest.cs +++ b/Projects/UOContent/Engines/ML Quests/MLQuest.cs @@ -269,7 +269,7 @@ namespace Server.Engines.MLQuests { var name = $"MLQS-{GetType().Name}"; - var toDelete = map.GetItemsInRange(loc, 0).Where(item => item is Spawner && item.Name == name); + var toDelete = map.GetItemsInRange(loc, 0).Where(item => item is BaseSpawner && item.Name == name); foreach (var item in toDelete) { diff --git a/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs new file mode 100644 index 000000000..4f78f053d --- /dev/null +++ b/Projects/UOContent/Engines/Spawners/EditSpawnCommand.cs @@ -0,0 +1,113 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019-2021 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: EditSpawnCommand.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System; +using System.Collections.Generic; +using Server.Commands; +using Server.Commands.Generic; +using Server.Network; + +namespace Server.Engines.Spawners +{ + public class EditSpawnCommand : BaseCommand + { + public static void Initialize() + { + TargetCommands.Register(new EditSpawnCommand()); + } + + public EditSpawnCommand() + { + AccessLevel = AccessLevel.GameMaster; + Supports = CommandSupport.Complex | CommandSupport.Simple; + Commands = new[] { "EditSpawner" }; + ObjectTypes = ObjectTypes.Items; + Usage = "EditSpawner set "; + Description = "Modifies spawners arguments and properties for the given type"; + ListOptimized = true; + } + + public override void ExecuteList(CommandEventArgs e, List list) + { + var args = e.Arguments; + + if (args.Length <= 1) + { + LogFailure(Usage); + return; + } + + if (list.Count == 0) + { + LogFailure("No matching objects found."); + return; + } + + var name = args[0]; + + var type = AssemblyHandler.FindTypeByName(name); + + if (!Add.IsEntity(type)) + { + LogFailure("No type with that name was found."); + return; + } + + var argSpan = e.ArgString.AsSpan(name.Length + 1); + var setIndex = argSpan.InsensitiveIndexOf("set "); + + ReadOnlySpan props = null; + + if (setIndex > -1) + { + var start = setIndex + 4; + props = argSpan.Slice(start, argSpan.Length - start); + argSpan = argSpan.SliceToLength(setIndex); + } + + var argStr = argSpan.ToString().DefaultIfNullOrEmpty(null); + var propsStr = props.ToString().DefaultIfNullOrEmpty(null); + + e.Mobile.SendMessage("Updating spawners..."); + + foreach (var obj in list) + { + if (obj is BaseSpawner spawner) + { + UpdateSpawner(spawner, name, argStr, propsStr); + } + } + + e.Mobile.SendMessage("Update completed."); + } + + public static void UpdateSpawner(BaseSpawner spawner, string name, string arguments, string properties) + { + foreach (var entry in spawner.Entries) + { + // TODO: Should cache spawn type on the entry + if (entry.SpawnedName.InsensitiveEquals(name)) + { + if (arguments != null) + { + entry.Parameters = arguments; + } + + entry.Properties = properties; + } + } + } + } +} diff --git a/Projects/UOContent/Engines/Spawners/RespawnCommand.cs b/Projects/UOContent/Engines/Spawners/RespawnCommand.cs new file mode 100644 index 000000000..b9654334f --- /dev/null +++ b/Projects/UOContent/Engines/Spawners/RespawnCommand.cs @@ -0,0 +1,63 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019-2021 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: RespawnCommand.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System.Collections.Generic; +using Server.Commands.Generic; +using Server.Network; + +namespace Server.Engines.Spawners +{ + public class RespawnCommand : BaseCommand + { + public static void Initialize() + { + TargetCommands.Register(new RespawnCommand()); + } + + public RespawnCommand() + { + AccessLevel = AccessLevel.GameMaster; + Supports = CommandSupport.Complex | CommandSupport.Simple; + Commands = new[] { "Respawn" }; + ObjectTypes = ObjectTypes.Items; + Usage = "Respawn"; + Description = "Respawns the given the spawners."; + ListOptimized = true; + } + + public override void ExecuteList(CommandEventArgs e, List list) + { + if (list.Count == 0) + { + LogFailure("No matching objects found."); + return; + } + + e.Mobile.SendMessage("Respawning..."); + + NetState.FlushAll(); + + foreach (var obj in list) + { + if (obj is ISpawner spawner) + { + spawner.Respawn(); + } + } + + e.Mobile.SendMessage("Respawn completed."); + } + } +} diff --git a/Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs b/Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs new file mode 100644 index 000000000..94a089e95 --- /dev/null +++ b/Projects/UOContent/Engines/Spawners/SpawnPropsGump.cs @@ -0,0 +1,155 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019-2021 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: GlobalPropsGump.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System.Collections.Generic; +using System.Reflection; +using Server.Buffers; +using Server.Commands.Generic; +using Server.Engines.Spawners; +using Server.Mobiles; +using Server.Network; +using CPA = Server.CommandPropertyAttribute; + +namespace Server.Gumps +{ + public class SpawnPropsGump : PropertiesGump + { + public static readonly HashSet MobileAttributes = new() + { + nameof(Mobile.Hue), + nameof(Mobile.Str), + nameof(Mobile.Dex), + nameof(Mobile.Int), + nameof(BaseCreature.HitsMaxSeed), + nameof(BaseCreature.Hits), + nameof(BaseCreature.DamageMin), + nameof(BaseCreature.DamageMax), + nameof(BaseCreature.ActiveSpeed), + nameof(BaseCreature.PassiveSpeed), + nameof(BaseCreature.VirtualArmor) + }; + + private List _spawners; + + public SpawnPropsGump(Mobile mobile, object o, List spawners) : base(mobile, o) + { + _spawners = spawners; + } + + public SpawnPropsGump(Mobile mobile, object o, Stack stack, StackEntry parent, List spawners) : base( + mobile, o, stack, parent + ) + { + _spawners = spawners; + } + + public SpawnPropsGump(Mobile mobile, object o, Stack stack, List list, int page, List spawners) : base( + mobile, o, stack, list, page + ) + { + _spawners = spawners; + } + + protected override int TotalHeight => base.TotalHeight + PropsConfig.ApplySize; + + protected override void Initialize(int page) + { + base.Initialize(page); + var totalHeight = TotalHeight - PropsConfig.ApplySize; + + AddButton(BackWidth / 3, PropsConfig.BorderSize + totalHeight + PropsConfig.BorderSize, 5204, 5205, 3); + } + + public override void SendPropertiesGump() => + m_Mobile.SendGump(new SpawnPropsGump(m_Mobile, m_Object, m_Stack, m_List, m_Page, _spawners)); + + public static object GetPropValue(object src, string propName) => + src.GetType().GetProperty(propName)?.GetValue(src, null); + + public override void OnResponse(NetState state, RelayInfo info) + { + var from = state.Mobile; + + if (!BaseCommand.IsAccessible(from, m_Object)) + { + from.SendMessage("You may no longer access their properties."); + return; + } + + switch (info.ButtonID) + { + default: + { + base.OnResponse(state, info); + break; + } + case 3: // Apply + { + using var propsBuilder = new ValueStringBuilder(64); + bool first = true; + foreach (var attr in MobileAttributes) + { + var prop = GetPropValue(m_Object, attr); + if (prop != null) + { + if (first) + { + first = false; + } + else + { + propsBuilder.Append(' '); + } + + propsBuilder.Append(attr); + propsBuilder.Append(' '); + propsBuilder.Append(prop.ToString()); // TODO: Replace with ZString, or IFormatter code + } + } + + var name = m_Object.GetType().Name; + var props = propsBuilder.ToString(); + + m_Mobile.SendMessage("Updating spawners..."); + + foreach (var obj in _spawners) + { + if (obj is BaseSpawner spawner) + { + EditSpawnCommand.UpdateSpawner(spawner, name, null, props); + } + } + + m_Mobile.SendMessage("Update completed."); + + break; + } + } + } + + protected override bool ShowAttribute(string name) + { + foreach (var item in MobileAttributes) + { + if (item.InsensitiveEquals(name)) + { + return true; + } + } + + return false; + } + } +} diff --git a/Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs b/Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs new file mode 100644 index 000000000..6681067c3 --- /dev/null +++ b/Projects/UOContent/Engines/Spawners/SpawnPropsGumpCommand.cs @@ -0,0 +1,73 @@ +/************************************************************************* + * ModernUO * + * Copyright (C) 2019-2021 - ModernUO Development Team * + * Email: hi@modernuo.com * + * File: SpawnPropsGump.cs * + * * + * This program is free software: you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation, either version 3 of the License, or * + * (at your option) any later version. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program. If not, see . * + *************************************************************************/ + +using System.Collections.Generic; +using Server.Commands; +using Server.Commands.Generic; +using Server.Gumps; +using Server.Targeting; + +namespace Server.Engines.Spawners +{ + public class SpawnPropsGumpCommand : BaseCommand + { + public static void Initialize() + { + TargetCommands.Register(new SpawnPropsGumpCommand()); + } + + public SpawnPropsGumpCommand() + { + AccessLevel = AccessLevel.GameMaster; + Supports = CommandSupport.Complex | CommandSupport.Simple; + Commands = new[] { "SpawnProps" }; + ObjectTypes = ObjectTypes.Items; + Usage = "SpawnProps"; + Description = "Shows a props gump that will modify the properties of spawn entries related to the chosen entity"; + ListOptimized = true; + } + + public override void ExecuteList(CommandEventArgs e, List list) + { + if (list.Count == 0) + { + LogFailure("No matching objects found."); + return; + } + + e.Mobile.SendMessage("Target the object you want to use as a template for modifying the spawner properties."); + e.Mobile.Target = new InternalTarget(list); + } + + private class InternalTarget : Target + { + private List _list; + + public InternalTarget(List list) : base(-1, false, TargetFlags.None) => + _list = list; + + protected override void OnTarget(Mobile from, object targeted) + { + var type = targeted.GetType(); + if (!Add.IsEntity(type)) + { + from.SendMessage("No type with that name was found."); + } + + from.SendGump(new SpawnPropsGump(from, targeted, _list)); + } + } + } +} diff --git a/Projects/UOContent/Gumps/Props/PropsConfig.cs b/Projects/UOContent/Gumps/Props/PropsConfig.cs index 1b8737b16..bf1cdad0e 100644 --- a/Projects/UOContent/Gumps/Props/PropsConfig.cs +++ b/Projects/UOContent/Gumps/Props/PropsConfig.cs @@ -38,5 +38,6 @@ namespace Server.Gumps public static readonly int EntryHeight = 20; public static readonly int BorderSize = 10; + public static readonly int ApplySize = 30; } } diff --git a/Projects/UOContent/Gumps/Props/PropsGump.cs b/Projects/UOContent/Gumps/Props/PropsGump.cs index bf0722d88..83ded0010 100644 --- a/Projects/UOContent/Gumps/Props/PropsGump.cs +++ b/Projects/UOContent/Gumps/Props/PropsGump.cs @@ -60,7 +60,7 @@ namespace Server.Gumps private static readonly bool NextLabel = OldStyle; private static readonly bool TypeLabel = !OldStyle; - private static readonly int PrevLabelOffsetX = PrevWidth + 1; + public static readonly int PrevLabelOffsetX = PrevWidth + 1; private static readonly int PrevLabelOffsetY = 0; private static readonly int NextLabelOffsetX = -29; @@ -69,50 +69,50 @@ namespace Server.Gumps private static readonly int NameWidth = 107; private static readonly int ValueWidth = 128; - private static readonly int EntryCount = 15; + public static readonly int MaxEntriesPerPage = 15; private static readonly int TypeWidth = NameWidth + OffsetSize + ValueWidth; private static readonly int TotalWidth = OffsetSize + NameWidth + OffsetSize + ValueWidth + OffsetSize + SetWidth + OffsetSize; - private static readonly int TotalHeight = OffsetSize + (EntryHeight + OffsetSize) * (EntryCount + 1); + private static readonly int MaxHeight = OffsetSize + (EntryHeight + OffsetSize) * (MaxEntriesPerPage + 1); - private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; - private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; + protected static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; + protected static readonly int BackHeight = BorderSize + MaxHeight + BorderSize; - public static string[] m_BoolNames = { "True", "False" }; - public static object[] m_BoolValues = { true, false }; + public static readonly string[] BoolNames = { "True", "False" }; + public static readonly object[] BoolValues = { true, false }; - public static string[] m_PoisonNames = { "None", "Lesser", "Regular", "Greater", "Deadly", "Lethal" }; + public static readonly string[] PoisonNames = { "None", "Lesser", "Regular", "Greater", "Deadly", "Lethal" }; - public static object[] m_PoisonValues = + public static readonly object[] PoisonValues = { null, Poison.Lesser, Poison.Regular, Poison.Greater, Poison.Deadly, Poison.Lethal }; - private static readonly Type typeofMobile = typeof(Mobile); - private static readonly Type typeofItem = typeof(Item); - private static readonly Type typeofType = typeof(Type); - private static readonly Type typeofPoint3D = typeof(Point3D); - private static readonly Type typeofPoint2D = typeof(Point2D); - private static readonly Type typeofTimeSpan = typeof(TimeSpan); - private static readonly Type typeofCustomEnum = typeof(CustomEnumAttribute); - private static readonly Type typeofEnum = typeof(Enum); - private static readonly Type typeofBool = typeof(bool); - private static readonly Type typeofString = typeof(string); - private static readonly Type typeofText = typeof(TextDefinition); - private static readonly Type typeofPoison = typeof(Poison); - private static readonly Type typeofMap = typeof(Map); - private static readonly Type typeofSkills = typeof(Skills); - private static readonly Type typeofPropertyObject = typeof(PropertyObjectAttribute); - private static readonly Type typeofNoSort = typeof(NoSortAttribute); + public static readonly Type TypeofMobile = typeof(Mobile); + public static readonly Type TypeofItem = typeof(Item); + public static readonly Type TypeofType = typeof(Type); + public static readonly Type TypeofPoint3D = typeof(Point3D); + public static readonly Type TypeofPoint2D = typeof(Point2D); + public static readonly Type TypeofTimeSpan = typeof(TimeSpan); + public static readonly Type TypeofCustomEnum = typeof(CustomEnumAttribute); + public static readonly Type TypeofEnum = typeof(Enum); + public static readonly Type TypeofBool = typeof(bool); + public static readonly Type TypeofString = typeof(string); + public static readonly Type TypeofText = typeof(TextDefinition); + public static readonly Type TypeofPoison = typeof(Poison); + public static readonly Type TypeofMap = typeof(Map); + public static readonly Type TypeofSkills = typeof(Skills); + public static readonly Type TypeofPropertyObject = typeof(PropertyObjectAttribute); + public static readonly Type TypeofNoSort = typeof(NoSortAttribute); - private static readonly Type[] typeofReal = + public static readonly Type[] DecimalTypes = { typeof(float), typeof(double) }; - private static readonly Type[] typeofNumeric = + public static readonly Type[] NumericTypes = { typeof(byte), typeof(short), @@ -124,14 +124,18 @@ namespace Server.Gumps typeof(ulong) }; - private static readonly Type typeofCPA = typeof(CPA); - private static readonly Type typeofObject = typeof(object); - private readonly List m_List; - private readonly Mobile m_Mobile; - private readonly object m_Object; - private readonly Stack m_Stack; - private readonly Type m_Type; - private int m_Page; + private static readonly Type TypeofCPA = typeof(CPA); + private static readonly Type TypeofObject = typeof(object); + + protected readonly List m_List; + protected readonly Mobile m_Mobile; + protected readonly object m_Object; + protected readonly Stack m_Stack; + protected readonly Type m_Type; + protected int m_Page; + protected int m_EntryCount; + + protected virtual int TotalHeight => OffsetSize + (EntryHeight + OffsetSize) * (m_EntryCount + 1); public PropertiesGump(Mobile mobile, object o) : base(GumpOffsetX, GumpOffsetY) { @@ -182,20 +186,19 @@ namespace Server.Gumps Initialize(page); } - private void Initialize(int page) + protected virtual void Initialize(int page) { m_Page = page; + var indexOnPage = m_Page * MaxEntriesPerPage; - var count = Math.Clamp(m_List.Count - page * EntryCount, 0, EntryCount); - - var lastIndex = page * EntryCount + count - 1; - + m_EntryCount = Math.Clamp(m_List.Count - indexOnPage, 0, MaxEntriesPerPage); + var lastIndex = indexOnPage + m_EntryCount - 1; if (lastIndex >= 0 && lastIndex < m_List.Count && m_List[lastIndex] == null) { - --count; + --m_EntryCount; } - var totalHeight = OffsetSize + (EntryHeight + OffsetSize) * (count + 1); + var totalHeight = TotalHeight; AddPage(0); @@ -204,7 +207,7 @@ namespace Server.Gumps BorderSize, BorderSize, TotalWidth - (OldStyle ? SetWidth + OffsetSize : 0), - totalHeight, + OffsetSize + (EntryHeight + OffsetSize) * (m_EntryCount + 1), OffsetGumpID ); @@ -257,7 +260,7 @@ namespace Server.Gumps AddImageTiled(x, y, NextWidth, EntryHeight, HeaderGumpID); } - if ((page + 1) * EntryCount < m_List.Count) + if ((page + 1) * MaxEntriesPerPage < m_List.Count) { AddButton(x + NextOffsetX, y + NextOffsetY, NextButtonID1, NextButtonID2, 2, GumpButtonType.Reply, 1); @@ -267,7 +270,7 @@ namespace Server.Gumps } } - for (int i = 0, index = page * EntryCount; i < count && index < m_List.Count; ++i, ++index) + for (int i = 0, index = page * MaxEntriesPerPage; i < m_EntryCount && index < m_List.Count; ++i, ++index) { x = BorderSize + OffsetSize; y += EntryHeight + OffsetSize; @@ -347,7 +350,7 @@ namespace Server.Gumps } case 2: // Next { - if ((m_Page + 1) * EntryCount < m_List.Count) + if ((m_Page + 1) * MaxEntriesPerPage < m_List.Count) { from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page + 1)); } @@ -356,143 +359,136 @@ namespace Server.Gumps } default: { - var index = m_Page * EntryCount + (info.ButtonID - 3); + var index = m_Page * MaxEntriesPerPage + (info.ButtonID - 3); - if (index >= 0 && index < m_List.Count) + if (index < 0 || index >= m_List.Count) { - var prop = m_List[index] as PropertyInfo; + break; + } - if (prop == null) - { - return; - } + var prop = m_List[index] as PropertyInfo; - var attr = GetCPA(prop); + if (prop == null) + { + return; + } - if (prop.GetType().IsValueType && !prop.CanWrite || attr == null || - from.AccessLevel < attr.WriteLevel || attr.ReadOnly) - { - return; - } + var attr = GetCPA(prop); - var type = prop.PropertyType; + if (prop.GetType().IsValueType && !prop.CanWrite || attr == null || + from.AccessLevel < attr.WriteLevel || attr.ReadOnly) + { + return; + } - if (IsType(type, typeofMobile) || IsType(type, typeofItem)) - { - from.SendGump(new SetObjectGump(prop, from, m_Object, m_Stack, type, m_Page, m_List)); - } - else if (IsType(type, typeofType)) - { - from.Target = new SetObjectTarget(prop, from, m_Object, m_Stack, type, m_Page, m_List); - } - else if (IsType(type, typeofPoint3D)) - { - from.SendGump(new SetPoint3DGump(prop, from, m_Object, m_Stack, m_Page, m_List)); - } - else if (IsType(type, typeofPoint2D)) - { - from.SendGump(new SetPoint2DGump(prop, from, m_Object, m_Stack, m_Page, m_List)); - } - else if (IsType(type, typeofTimeSpan)) - { - from.SendGump(new SetTimeSpanGump(prop, from, m_Object, m_Stack, m_Page, m_List)); - } - else if (IsCustomEnum(type)) - { - from.SendGump( - new SetCustomEnumGump( - prop, - from, - m_Object, - m_Stack, - m_Page, - m_List, - GetCustomEnumNames(type) - ) - ); - } - else if (IsType(type, typeofEnum)) - { - from.SendGump( - new SetListOptionGump( - prop, - from, - m_Object, - m_Stack, - m_Page, - m_List, - Enum.GetNames(type), - GetObjects(Enum.GetValues(type)) - ) - ); - } - else if (IsType(type, typeofBool)) - { - from.SendGump( - new SetListOptionGump( - prop, - from, - m_Object, - m_Stack, - m_Page, - m_List, - m_BoolNames, - m_BoolValues - ) - ); - } - else if (IsType(type, typeofString) || IsType(type, typeofReal) || IsType(type, typeofNumeric) || - IsType(type, typeofText)) - { - from.SendGump(new SetGump(prop, from, m_Object, m_Stack, m_Page, m_List)); - } - else if (IsType(type, typeofPoison)) - { - from.SendGump( - new SetListOptionGump( - prop, - from, - m_Object, - m_Stack, - m_Page, - m_List, - m_PoisonNames, - m_PoisonValues - ) - ); - } - else if (IsType(type, typeofMap)) - { - from.SendGump( - new SetListOptionGump( - prop, - from, - m_Object, - m_Stack, - m_Page, - m_List, - Map.GetMapNames(), - Map.GetMapValues().ToArray() - ) - ); - } - else if (IsType(type, typeofSkills) && m_Object is Mobile mobile) - { - from.SendGump(new PropertiesGump(from, mobile, m_Stack, m_List, m_Page)); - from.SendGump(new SkillsGump(from, mobile)); - } - else if (HasAttribute(type, typeofPropertyObject, true)) - { - var obj = prop.GetValue(m_Object, null); + var type = prop.PropertyType; - if (obj != null) - { - from.SendGump(new PropertiesGump(from, obj, m_Stack, new StackEntry(m_Object, prop))); - } - else - { - from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page)); - } + if (IsType(type, TypeofMobile) || IsType(type, TypeofItem)) + { + from.SendGump(new SetObjectGump(prop, from, m_Object, type, this)); + } + else if (IsType(type, TypeofType)) + { + from.Target = new SetObjectTarget(prop, from, m_Object, type, this); + } + else if (IsType(type, TypeofPoint3D)) + { + from.SendGump(new SetPoint3DGump(prop, from, m_Object, this)); + } + else if (IsType(type, TypeofPoint2D)) + { + from.SendGump(new SetPoint2DGump(prop, from, m_Object, this)); + } + else if (IsType(type, TypeofTimeSpan)) + { + from.SendGump(new SetTimeSpanGump(prop, from, m_Object, this)); + } + else if (IsCustomEnum(type)) + { + from.SendGump( + new SetCustomEnumGump( + prop, + from, + m_Object, + this, + GetCustomEnumNames(type) + ) + ); + } + else if (IsType(type, TypeofEnum)) + { + from.SendGump( + new SetListOptionGump( + prop, + from, + m_Object, + this, + Enum.GetNames(type), + GetObjects(Enum.GetValues(type)) + ) + ); + } + else if (IsType(type, TypeofBool)) + { + from.SendGump( + new SetListOptionGump( + prop, + from, + m_Object, + this, + BoolNames, + BoolValues + ) + ); + } + else if (IsType(type, TypeofString) || IsType(type, DecimalTypes) || + IsType(type, NumericTypes) || + IsType(type, TypeofText)) + { + from.SendGump(new SetGump(prop, from, m_Object, this)); + } + else if (IsType(type, TypeofPoison)) + { + from.SendGump( + new SetListOptionGump( + prop, + from, + m_Object, + this, + PoisonNames, + PoisonValues + ) + ); + } + else if (IsType(type, TypeofMap)) + { + from.SendGump( + new SetListOptionGump( + prop, + from, + m_Object, + this, + Map.GetMapNames(), + Map.GetMapValues().ToArray() + ) + ); + } + else if (IsType(type, TypeofSkills) && m_Object is Mobile mobile) + { + from.SendGump(new PropertiesGump(from, mobile, m_Stack, m_List, m_Page)); + from.SendGump(new SkillsGump(from, mobile)); + } + else if (HasAttribute(type, TypeofPropertyObject, true)) + { + var obj = prop.GetValue(m_Object, null); + + if (obj != null) + { + from.SendGump(new PropertiesGump(from, obj, m_Stack, new StackEntry(m_Object, prop))); + } + else + { + from.SendGump(new PropertiesGump(from, m_Object, m_Stack, m_List, m_Page)); } } @@ -501,6 +497,9 @@ namespace Server.Gumps } } + public virtual void SendPropertiesGump() => + m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + private static object[] GetObjects(Array a) { var list = new object[a.Length]; @@ -513,11 +512,11 @@ namespace Server.Gumps return list; } - private static bool IsCustomEnum(Type type) => type.IsDefined(typeofCustomEnum, false); + private static bool IsCustomEnum(Type type) => type.IsDefined(TypeofCustomEnum, false); - public static void OnValueChanged(object obj, PropertyInfo prop, Stack stack) + public void OnValueChanged(object obj, PropertyInfo prop) { - if (stack == null || stack.Count == 0) + if (m_Stack == null || m_Stack.Count == 0) { return; } @@ -527,7 +526,7 @@ namespace Server.Gumps return; } - var peek = stack.Peek(); + var peek = m_Stack.Peek(); if (peek.m_Property.CanWrite) { @@ -537,7 +536,7 @@ namespace Server.Gumps private static string[] GetCustomEnumNames(Type type) { - var attrs = type.GetCustomAttributes(typeofCustomEnum, false); + var attrs = type.GetCustomAttributes(TypeofCustomEnum, false); if (attrs.Length == 0) { @@ -552,12 +551,12 @@ namespace Server.Gumps return ce.Names; } - private static bool HasAttribute(Type type, Type check, bool inherit) => + public static bool HasAttribute(Type type, Type check, bool inherit) => type.GetCustomAttributes(check, inherit).Length > 0; - private static bool IsType(Type type, Type check) => type == check || type.IsSubclassOf(check); + public static bool IsType(Type type, Type check) => type == check || type.IsSubclassOf(check); - private static bool IsType(Type type, Type[] check) + public static bool IsType(Type type, Type[] check) { for (var i = 0; i < check.Length; ++i) { @@ -570,7 +569,7 @@ namespace Server.Gumps return false; } - private string ValueToString(PropertyInfo prop) => ValueToString(m_Object, prop); + public string ValueToString(PropertyInfo prop) => ValueToString(m_Object, prop); public static string ValueToString(object obj, PropertyInfo prop) { @@ -669,7 +668,7 @@ namespace Server.Gumps { var kvp = groups[i]; - if (!HasAttribute(kvp.Key, typeofNoSort, false)) + if (!HasAttribute(kvp.Key, TypeofNoSort, false)) { kvp.Value.Sort(PropertySorter.Instance); } @@ -680,15 +679,24 @@ namespace Server.Gumps } list.Add(kvp.Key); - list.AddRange(kvp.Value); + + foreach (var item in kvp.Value) + { + if (ShowAttribute(item.Name)) + { + list.Add(item); + } + } } return list; } - private static CPA GetCPA(PropertyInfo prop) + protected virtual bool ShowAttribute(string name) => true; + + public static CPA GetCPA(PropertyInfo prop) { - var attrs = prop.GetCustomAttributes(typeofCPA, false); + var attrs = prop.GetCustomAttributes(TypeofCPA, false); if (attrs.Length > 0) { @@ -718,7 +726,7 @@ namespace Server.Gumps { var baseType = type?.BaseType; - if (baseType == typeofObject || baseType?.GetProperty(prop.Name, prop.PropertyType) == null) + if (baseType == TypeofObject || baseType?.GetProperty(prop.Name, prop.PropertyType) == null) { break; } @@ -868,7 +876,7 @@ namespace Server.Gumps return -1; } - return y == null ? 1 : string.CompareOrdinal(x.Name, x.Name); + return x.Name.CompareOrdinal(y?.Name); } } @@ -887,7 +895,7 @@ namespace Server.Gumps int dist; - for (dist = 0; current != null && current != typeofObject && current != type; ++dist) + for (dist = 0; current != null && current != TypeofObject && current != type; ++dist) { current = current.BaseType; } diff --git a/Projects/UOContent/Gumps/Props/SetBodyGump.cs b/Projects/UOContent/Gumps/Props/SetBodyGump.cs index 045ecafce..de7f07dbe 100644 --- a/Projects/UOContent/Gumps/Props/SetBodyGump.cs +++ b/Projects/UOContent/Gumps/Props/SetBodyGump.cs @@ -24,28 +24,24 @@ namespace Server.Gumps private const int TextColor32 = 0xFFFFFF; private static List m_Monster, m_Animal, m_Sea, m_Human; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; private readonly List m_OurList; private readonly int m_OurPage; private readonly ModelBodyType m_OurType; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public SetBodyGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list, + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump, int ourPage = 0, List ourList = null, ModelBodyType ourType = ModelBodyType.Invalid ) : base(20, 30) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; m_OurPage = ourPage; m_OurList = ourList; m_OurType = ourType; @@ -131,7 +127,7 @@ namespace Server.Gumps if (index == -1) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } else if (index >= 0 && index < 4) { @@ -163,7 +159,7 @@ namespace Server.Gumps break; } - m_Mobile.SendGump(new SetBodyGump(m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List, 0, list, type)); + m_Mobile.SendGump(new SetBodyGump(m_Property, m_Mobile, m_Object, m_PropertiesGump, 0, list, type)); } else if (m_OurList != null) { @@ -176,9 +172,7 @@ namespace Server.Gumps m_Property, m_Mobile, m_Object, - m_Stack, - m_Page, - m_List, + m_PropertiesGump, m_OurPage - 1, m_OurList, m_OurType @@ -192,9 +186,7 @@ namespace Server.Gumps m_Property, m_Mobile, m_Object, - m_Stack, - m_Page, - m_List, + m_PropertiesGump, m_OurPage + 1, m_OurList, m_OurType @@ -213,7 +205,7 @@ namespace Server.Gumps CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, entry.Body.ToString()); m_Property.SetValue(m_Object, entry.Body, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -225,9 +217,7 @@ namespace Server.Gumps m_Property, m_Mobile, m_Object, - m_Stack, - m_Page, - m_List, + m_PropertiesGump, m_OurPage, m_OurList, m_OurType diff --git a/Projects/UOContent/Gumps/Props/SetCustomEnumGump.cs b/Projects/UOContent/Gumps/Props/SetCustomEnumGump.cs index d2e304155..de0d86f6f 100644 --- a/Projects/UOContent/Gumps/Props/SetCustomEnumGump.cs +++ b/Projects/UOContent/Gumps/Props/SetCustomEnumGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Network; @@ -11,9 +10,8 @@ namespace Server.Gumps private readonly string[] m_Names; public SetCustomEnumGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, - List list, string[] names - ) : base(prop, mobile, o, stack, propspage, list, names, null) => + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump, string[] names + ) : base(prop, mobile, o, propertiesGump, names, null) => m_Names = names; public override void OnResponse(NetState sender, RelayInfo relayInfo) @@ -61,7 +59,7 @@ namespace Server.Gumps if (result == "Property has been set.") { - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } } catch @@ -70,7 +68,7 @@ namespace Server.Gumps } } - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } } diff --git a/Projects/UOContent/Gumps/Props/SetGump.cs b/Projects/UOContent/Gumps/Props/SetGump.cs index 1e82952a9..15501de37 100644 --- a/Projects/UOContent/Gumps/Props/SetGump.cs +++ b/Projects/UOContent/Gumps/Props/SetGump.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.HuePickers; @@ -49,26 +48,17 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private PropertiesGump m_PropertiesGump; - public SetGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list - ) : base( - GumpOffsetX, - GumpOffsetY - ) + public SetGump(PropertyInfo prop, Mobile from, object o, PropertiesGump propertiesGump) : base(GumpOffsetX, GumpOffsetY) { - m_Property = prop; - m_Mobile = mobile; + m_Mobile = from; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; + m_Property = prop; + m_PropertiesGump = propertiesGump; var canNull = !prop.PropertyType.IsValueType; var canDye = prop.IsDefined(typeof(HueAttribute), false); @@ -77,9 +67,9 @@ namespace Server.Gumps var val = prop.GetValue(m_Object, null); var initialText = val switch { - null => "", + null => "", TextDefinition definition => definition.GetValue(), - _ => val.ToString() + _ => val.ToString() }; AddPage(0); @@ -179,6 +169,7 @@ namespace Server.Gumps } } + public override void OnResponse(NetState sender, RelayInfo info) { object toSet; @@ -225,7 +216,7 @@ namespace Server.Gumps shouldSet = false; shouldSend = false; - m_Mobile.SendHuePicker(new InternalPicker(m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List)); + m_Mobile.SendHuePicker(new InternalPicker(m_Property, m_Mobile, m_Object, m_PropertiesGump)); break; } @@ -235,7 +226,7 @@ namespace Server.Gumps shouldSet = false; shouldSend = false; - m_Mobile.SendGump(new SetBodyGump(m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List)); + m_Mobile.SendGump(new SetBodyGump(m_Property, m_Mobile, m_Object, m_PropertiesGump)); break; } @@ -259,7 +250,7 @@ namespace Server.Gumps toSet?.ToString() ?? "(null)" ); m_Property.SetValue(m_Object, toSet, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -269,30 +260,24 @@ namespace Server.Gumps if (shouldSend) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } private class InternalPicker : HuePicker { - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public InternalPicker( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - List list - ) : base(((IHued)o).HuedItemID) + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump) : base(((IHued)o).HuedItemID) { m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; + m_PropertiesGump = propertiesGump; } public override void OnResponse(int hue) @@ -301,14 +286,14 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, hue.ToString()); m_Property.SetValue(m_Object, hue, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { m_Mobile.SendMessage("An exception was caught. The property may not have changed."); } - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } } diff --git a/Projects/UOContent/Gumps/Props/SetListOptionGump.cs b/Projects/UOContent/Gumps/Props/SetListOptionGump.cs index 389cd58d9..6dcc2611c 100644 --- a/Projects/UOContent/Gumps/Props/SetListOptionGump.cs +++ b/Projects/UOContent/Gumps/Props/SetListOptionGump.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Network; @@ -58,24 +57,19 @@ namespace Server.Gumps private static readonly int NextLabelOffsetY = 0; private readonly object[] m_Values; - protected List m_List; protected Mobile m_Mobile; protected object m_Object; - protected int m_Page; protected PropertyInfo m_Property; - protected Stack m_Stack; + protected PropertiesGump m_PropertiesGump; public SetListOptionGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int propspage, - List list, string[] names, object[] values + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump, string[] names, object[] values ) : base(GumpOffsetX, GumpOffsetY) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = propspage; - m_List = list; m_Values = values; @@ -224,7 +218,7 @@ namespace Server.Gumps if (result == "Property has been set.") { - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } } catch @@ -233,7 +227,7 @@ namespace Server.Gumps } } - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } } diff --git a/Projects/UOContent/Gumps/Props/SetObjectGump.cs b/Projects/UOContent/Gumps/Props/SetObjectGump.cs index 8bd85b7b1..5979fdd2d 100644 --- a/Projects/UOContent/Gumps/Props/SetObjectGump.cs +++ b/Projects/UOContent/Gumps/Props/SetObjectGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Commands.Generic; @@ -51,26 +50,21 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; private readonly Type m_Type; + private readonly PropertiesGump m_PropertiesGump; public SetObjectGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - List list + PropertyInfo prop, Mobile mobile, object o, Type type, PropertiesGump propertiesGump ) : base(GumpOffsetX, GumpOffsetY) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; m_Type = type; - m_Page = page; - m_List = list; var initialText = PropertiesGump.ValueToString(o, prop); @@ -163,7 +157,7 @@ namespace Server.Gumps { case 0: // closed { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); shouldSend = false; break; } @@ -173,10 +167,8 @@ namespace Server.Gumps m_Property, m_Mobile, m_Object, - m_Stack, m_Type, - m_Page, - m_List + m_PropertiesGump ); shouldSend = false; break; @@ -190,10 +182,8 @@ namespace Server.Gumps m_Property, m_Mobile, m_Object, - m_Stack, m_Type, - m_Page, - m_List + m_PropertiesGump ); break; @@ -204,7 +194,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, "(null)"); m_Property.SetValue(m_Object, null, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -236,7 +226,7 @@ namespace Server.Gumps if (shouldSend) { - m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List)); + m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Type, m_PropertiesGump)); } if (viewProps != null) @@ -247,31 +237,26 @@ namespace Server.Gumps private class InternalPrompt : Prompt { - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; private readonly Type m_Type; + private readonly PropertiesGump m_PropertiesGump; public InternalPrompt( - PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - List list + PropertyInfo prop, Mobile mobile, object o, Type type, PropertiesGump propertiesGump ) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; m_Type = type; - m_Page = page; - m_List = list; } public override void OnCancel(Mobile from) { - m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List)); + m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Type, m_PropertiesGump)); } public override void OnResponse(Mobile from, string text) @@ -304,7 +289,7 @@ namespace Server.Gumps toSet.ToString() ); m_Property.SetValue(m_Object, toSet, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -317,7 +302,7 @@ namespace Server.Gumps m_Mobile.SendMessage("Bad format"); } - m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List)); + m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Type, m_PropertiesGump)); } } } diff --git a/Projects/UOContent/Gumps/Props/SetObjectTarget.cs b/Projects/UOContent/Gumps/Props/SetObjectTarget.cs index 19fa34dd2..a01e7b061 100644 --- a/Projects/UOContent/Gumps/Props/SetObjectTarget.cs +++ b/Projects/UOContent/Gumps/Props/SetObjectTarget.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Items; @@ -9,26 +8,21 @@ namespace Server.Gumps { public class SetObjectTarget : Target { - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; private readonly Type m_Type; + private readonly PropertiesGump m_PropertiesGump; public SetObjectTarget( - PropertyInfo prop, Mobile mobile, object o, Stack stack, Type type, int page, - List list + PropertyInfo prop, Mobile mobile, object o, Type type, PropertiesGump propertiesGump ) : base(-1, false, TargetFlags.None) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; m_Type = type; - m_Page = page; - m_List = list; } protected override void OnTarget(Mobile from, object targeted) @@ -49,7 +43,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, targeted.ToString()); m_Property.SetValue(m_Object, targeted, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } else { @@ -66,11 +60,11 @@ namespace Server.Gumps { if (m_Type == typeof(Type)) { - from.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } else { - from.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List)); + from.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Type, m_PropertiesGump)); } } } diff --git a/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs b/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs index 9666e247b..89ca174dc 100644 --- a/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs +++ b/Projects/UOContent/Gumps/Props/SetPoint2DGump.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Network; @@ -50,24 +49,20 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public SetPoint2DGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump ) : base(GumpOffsetX, GumpOffsetY) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; var p = (Point2D)(prop?.GetValue(o, null) ?? new Point2D()); @@ -160,7 +155,7 @@ namespace Server.Gumps } case 2: // Pick location { - m_Mobile.Target = new InternalTarget(m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List); + m_Mobile.Target = new InternalTarget(m_Property, m_Mobile, m_Object, m_PropertiesGump); toSet = Point2D.Zero; shouldSet = false; @@ -198,7 +193,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, toSet.ToString()); m_Property.SetValue(m_Object, toSet, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -208,30 +203,25 @@ namespace Server.Gumps if (shouldSend) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } private class InternalTarget : Target { - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public InternalTarget( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - List list + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump ) : base(-1, true, TargetFlags.None) { m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; + m_PropertiesGump = propertiesGump; } protected override void OnTarget(Mobile from, object targeted) @@ -242,7 +232,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, new Point2D(p).ToString()); m_Property.SetValue(m_Object, new Point2D(p), null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -253,7 +243,7 @@ namespace Server.Gumps protected override void OnTargetFinish(Mobile from) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } } diff --git a/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs b/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs index 0b721b478..19f76df74 100644 --- a/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs +++ b/Projects/UOContent/Gumps/Props/SetPoint3DGump.cs @@ -1,4 +1,3 @@ -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Network; @@ -50,24 +49,20 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public SetPoint3DGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump ) : base(GumpOffsetX, GumpOffsetY) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; var p = (Point3D)(prop?.GetValue(o, null) ?? new Point3D()); @@ -165,7 +160,7 @@ namespace Server.Gumps } case 2: // Pick location { - m_Mobile.Target = new InternalTarget(m_Property, m_Mobile, m_Object, m_Stack, m_Page, m_List); + m_Mobile.Target = new InternalTarget(m_Property, m_Mobile, m_Object, m_PropertiesGump); toSet = Point3D.Zero; shouldSet = false; @@ -205,7 +200,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, toSet.ToString()); m_Property.SetValue(m_Object, toSet, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -215,30 +210,25 @@ namespace Server.Gumps if (shouldSend) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } private class InternalTarget : Target { - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public InternalTarget( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, - List list + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump ) : base(-1, true, TargetFlags.None) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; } protected override void OnTarget(Mobile from, object targeted) @@ -249,7 +239,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, new Point3D(p).ToString()); m_Property.SetValue(m_Object, new Point3D(p), null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -258,10 +248,7 @@ namespace Server.Gumps } } - protected override void OnTargetFinish(Mobile from) - { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); - } + protected override void OnTargetFinish(Mobile from) => m_PropertiesGump.SendPropertiesGump(); } } } diff --git a/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs b/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs index 41dc268c7..23538da83 100644 --- a/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs +++ b/Projects/UOContent/Gumps/Props/SetTimeSpanGump.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.Reflection; using Server.Commands; using Server.Network; @@ -49,24 +48,20 @@ namespace Server.Gumps private static readonly int BackWidth = BorderSize + TotalWidth + BorderSize; private static readonly int BackHeight = BorderSize + TotalHeight + BorderSize; - private readonly List m_List; private readonly Mobile m_Mobile; private readonly object m_Object; - private readonly int m_Page; private readonly PropertyInfo m_Property; - private readonly Stack m_Stack; + private readonly PropertiesGump m_PropertiesGump; public SetTimeSpanGump( - PropertyInfo prop, Mobile mobile, object o, Stack stack, int page, List list + PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump ) : base(GumpOffsetX, GumpOffsetY) { + m_PropertiesGump = propertiesGump; m_Property = prop; m_Mobile = mobile; m_Object = o; - m_Stack = stack; - m_Page = page; - m_List = list; var ts = (TimeSpan)(prop?.GetValue(o, null) ?? new TimeSpan()); @@ -239,7 +234,7 @@ namespace Server.Gumps { CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, toSet.ToString()); m_Property.SetValue(m_Object, toSet, null); - PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack); + m_PropertiesGump.OnValueChanged(m_Object, m_Property); } catch { @@ -249,7 +244,7 @@ namespace Server.Gumps if (shouldSend) { - m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page)); + m_PropertiesGump.SendPropertiesGump(); } } }