From 764d303543fb3bcbd3c0f5e8ba75de8c20c30931 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 10 Jan 2021 09:14:03 -0800 Subject: [PATCH] chore: Code cleanup (#399) - [X] Code cleanup --- Projects/Server/Geometry/Rectangle2D.cs | 6 +- Projects/Server/Items/Item.cs | 2 + .../Json/Converters/IPEndPointConverter.cs | 2 +- .../Json/Converters/TimeSpanConverter.cs | 2 +- Projects/Server/Json/JsonConfig.cs | 2 +- Projects/Server/Mobiles/Mobile.cs | 1 - .../Network/Packets/IncomingEntityPackets.cs | 2 - Projects/Server/Network/Pipe.cs | 4 +- Projects/Server/TileMatrix.cs | 15 +- Projects/Server/TileMatrixPatch.cs | 18 ++- Projects/UOContent/Commands/Handlers.cs | 52 ------- .../Engines/BulkOrders/SmallSmithBOD.cs | 3 +- .../Engines/BulkOrders/SmallTailorBOD.cs | 3 +- .../CannedEvil/ChampionSkullBrazier.cs | 8 +- Projects/UOContent/Engines/Chat/Channel.cs | 2 +- .../UOContent/Engines/Craft/Core/CraftItem.cs | 6 +- .../UOContent/Engines/Craft/DefBlacksmithy.cs | 18 +-- .../UOContent/Engines/Craft/DefCarpentry.cs | 1 + .../Engines/Craft/DefGlassblowing.cs | 13 -- .../UOContent/Engines/Craft/DefMasonry.cs | 13 -- .../Doom/LeverPuzzle/LeverPuzzleItems.cs | 2 +- .../Engines/Events/BroadcastEvent.cs | 2 +- .../Engines/Khaldun/KhaldunPitTeleporter.cs | 19 +-- .../Engines/MLQuests/Mobiles/BoonCollector.cs | 2 - .../Engines/Pathing/SlowAStarAlgorithm.cs | 8 +- .../UOContent/Engines/Plants/PlantItem.cs | 2 +- Projects/UOContent/Items/Misc/TrashBarrel.cs | 2 +- Projects/UOContent/Misc/CharacterCreation.cs | 143 ++++-------------- Projects/UOContent/Skills/Anatomy.cs | 2 +- Projects/UOContent/Skills/EvalInt.cs | 3 +- 30 files changed, 93 insertions(+), 265 deletions(-) diff --git a/Projects/Server/Geometry/Rectangle2D.cs b/Projects/Server/Geometry/Rectangle2D.cs index 7c334377d..0b1bd4793 100644 --- a/Projects/Server/Geometry/Rectangle2D.cs +++ b/Projects/Server/Geometry/Rectangle2D.cs @@ -135,13 +135,13 @@ namespace Server } } - public bool Contains(Point3D p) => + public readonly bool Contains(Point3D p) => m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y; - public bool Contains(Point2D p) => + public readonly bool Contains(Point2D p) => m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y; - public bool Contains(IPoint2D p) => m_Start <= p && m_End > p; + public readonly bool Contains(IPoint2D p) => m_Start <= p && m_End > p; public override string ToString() => $"({X}, {Y})+({Width}, {Height})"; } diff --git a/Projects/Server/Items/Item.cs b/Projects/Server/Items/Item.cs index 428823e25..088566bdc 100644 --- a/Projects/Server/Items/Item.cs +++ b/Projects/Server/Items/Item.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; +using System.Runtime.CompilerServices; using Server.ContextMenus; using Server.Items; using Server.Network; @@ -2487,6 +2488,7 @@ namespace Server { } + [MethodImpl(MethodImplOptions.AggressiveInlining)] private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf) { if (setIf) diff --git a/Projects/Server/Json/Converters/IPEndPointConverter.cs b/Projects/Server/Json/Converters/IPEndPointConverter.cs index 586513786..d6c74d0da 100644 --- a/Projects/Server/Json/Converters/IPEndPointConverter.cs +++ b/Projects/Server/Json/Converters/IPEndPointConverter.cs @@ -24,7 +24,7 @@ namespace Server.Json { public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) { - if (IPEndPoint.TryParse(reader.GetString(), out var ipep)) + if (IPEndPoint.TryParse(reader.GetString()!, out var ipep)) { return ipep; } diff --git a/Projects/Server/Json/Converters/TimeSpanConverter.cs b/Projects/Server/Json/Converters/TimeSpanConverter.cs index a72a96e51..3115e2440 100644 --- a/Projects/Server/Json/Converters/TimeSpanConverter.cs +++ b/Projects/Server/Json/Converters/TimeSpanConverter.cs @@ -22,7 +22,7 @@ namespace Server.Json public class TimeSpanConverter : JsonConverter { public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) - => TimeSpan.Parse(reader.GetString()); + => TimeSpan.Parse(reader.GetString()!); public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options) => writer.WriteStringValue(value.ToString()); diff --git a/Projects/Server/Json/JsonConfig.cs b/Projects/Server/Json/JsonConfig.cs index 9a1614e29..bcd7994ba 100644 --- a/Projects/Server/Json/JsonConfig.cs +++ b/Projects/Server/Json/JsonConfig.cs @@ -78,7 +78,7 @@ namespace Server.Json File.Delete(filePath); } - Directory.CreateDirectory(Path.GetDirectoryName(filePath)); + Directory.CreateDirectory(Path.GetDirectoryName(filePath)!); File.WriteAllText(filePath, contents); } diff --git a/Projects/Server/Mobiles/Mobile.cs b/Projects/Server/Mobiles/Mobile.cs index c7bae14a5..2b78dc929 100644 --- a/Projects/Server/Mobiles/Mobile.cs +++ b/Projects/Server/Mobiles/Mobile.cs @@ -6,7 +6,6 @@ using System.Linq; using System.Runtime.CompilerServices; using System.Runtime.Serialization; using Microsoft.Toolkit.HighPerformance.Extensions; -using Microsoft.Toolkit.HighPerformance.Memory; using Server.Accounting; using Server.Buffers; using Server.ContextMenus; diff --git a/Projects/Server/Network/Packets/IncomingEntityPackets.cs b/Projects/Server/Network/Packets/IncomingEntityPackets.cs index d2ebe2af8..ab629a83f 100644 --- a/Projects/Server/Network/Packets/IncomingEntityPackets.cs +++ b/Projects/Server/Network/Packets/IncomingEntityPackets.cs @@ -13,8 +13,6 @@ * along with this program. If not, see . * *************************************************************************/ -using System; - namespace Server.Network { public static class IncomingEntityPackets diff --git a/Projects/Server/Network/Pipe.cs b/Projects/Server/Network/Pipe.cs index ec4753f0a..7f98fda72 100644 --- a/Projects/Server/Network/Pipe.cs +++ b/Projects/Server/Network/Pipe.cs @@ -239,7 +239,7 @@ namespace Server.Network _pipe._readContinuation = null; _pipe._readAwaitBeginning = false; - ThreadPool.UnsafeQueueUserWorkItem(state => continuation(), true); + ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true); } #region Awaitable @@ -385,7 +385,7 @@ namespace Server.Network _pipe._writeContinuation = null; _pipe._readAwaitBeginning = false; - ThreadPool.UnsafeQueueUserWorkItem(state => continuation(), true); + ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true); } #region Awaitable diff --git a/Projects/Server/TileMatrix.cs b/Projects/Server/TileMatrix.cs index 1c112aad2..b31002f8a 100644 --- a/Projects/Server/TileMatrix.cs +++ b/Projects/Server/TileMatrix.cs @@ -343,7 +343,13 @@ namespace Server fixed (StaticTile* pTiles = staTiles) { - NativeReader.Read(DataStream.SafeFileHandle.DangerousGetHandle(), pTiles, length); + var ptr = DataStream.SafeFileHandle?.DangerousGetHandle(); + if (ptr == null) + { + throw new Exception($"Cannot open {DataStream.Name}"); + } + NativeReader.Read(ptr.Value, pTiles, length); + if (m_Lists == null) { m_Lists = new TileList[8][]; @@ -422,7 +428,12 @@ namespace Server fixed (LandTile* pTiles = tiles) { - NativeReader.Read(m_MapStream.SafeFileHandle.DangerousGetHandle(), pTiles, 192); + var ptr = m_MapStream.SafeFileHandle?.DangerousGetHandle(); + if (ptr == null) + { + throw new Exception($"Cannot open {m_MapStream.Name}"); + } + NativeReader.Read(ptr.Value, pTiles, 192); } return tiles; diff --git a/Projects/Server/TileMatrixPatch.cs b/Projects/Server/TileMatrixPatch.cs index f27b8bb53..eb2f76ce6 100644 --- a/Projects/Server/TileMatrixPatch.cs +++ b/Projects/Server/TileMatrixPatch.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Runtime.CompilerServices; @@ -60,7 +61,13 @@ namespace Server fixed (LandTile* pTiles = tiles) { - NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192); + var ptr = fsData.SafeFileHandle?.DangerousGetHandle(); + if (ptr == null) + { + throw new Exception($"Cannot open {fsData.Name}"); + } + + NativeReader.Read(ptr.Value, pTiles, 192); } matrix.SetLandBlock(x, y, tiles); @@ -123,7 +130,14 @@ namespace Server fixed (StaticTile* pTiles = staTiles) { - NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length); + var ptr = fsData.SafeFileHandle?.DangerousGetHandle(); + if (ptr == null) + { + throw new Exception($"Cannot open {fsData.Name}"); + } + + NativeReader.Read(ptr.Value, pTiles, length); + StaticTile* pCur = pTiles, pEnd = pTiles + tileCount; while (pCur < pEnd) diff --git a/Projects/UOContent/Commands/Handlers.cs b/Projects/UOContent/Commands/Handlers.cs index 097997cc4..f3be00890 100644 --- a/Projects/UOContent/Commands/Handlers.cs +++ b/Projects/UOContent/Commands/Handlers.cs @@ -1009,58 +1009,6 @@ namespace Server.Commands } } - private class DismountTarget : Target - { - public DismountTarget() : base(-1, false, TargetFlags.None) - { - } - - protected override void OnTarget(Mobile from, object targeted) - { - if (targeted is Mobile targ) - { - CommandLogging.WriteLine( - from, - "{0} {1} dismounting {2}", - from.AccessLevel, - CommandLogging.Format(from), - CommandLogging.Format(targ) - ); - - for (var i = 0; i < targ.Items.Count; ++i) - { - var item = targ.Items[i]; - - if (item is IMountItem mountItem) - { - var mount = mountItem.Mount; - - if (mount != null) - { - mount.Rider = null; - } - - if (targ.Items.IndexOf(item) == -1) - { - --i; - } - } - } - - for (var i = 0; i < targ.Items.Count; ++i) - { - var item = targ.Items[i]; - - if (item.Layer == Layer.Mount) - { - item.Delete(); - --i; - } - } - } - } - } - private class ClientTarget : Target { public ClientTarget() : base(-1, false, TargetFlags.None) diff --git a/Projects/UOContent/Engines/BulkOrders/SmallSmithBOD.cs b/Projects/UOContent/Engines/BulkOrders/SmallSmithBOD.cs index 940f4fdce..3af93d217 100644 --- a/Projects/UOContent/Engines/BulkOrders/SmallSmithBOD.cs +++ b/Projects/UOContent/Engines/BulkOrders/SmallSmithBOD.cs @@ -140,8 +140,7 @@ namespace Server.Engines.BulkOrders if (item != null) { - var allRequiredSkills = true; - var chance = item.GetSuccessChance(m, null, system, false, out allRequiredSkills); + var chance = item.GetSuccessChance(m, null, system, false, out var allRequiredSkills); if (allRequiredSkills && chance >= 0.0) { diff --git a/Projects/UOContent/Engines/BulkOrders/SmallTailorBOD.cs b/Projects/UOContent/Engines/BulkOrders/SmallTailorBOD.cs index 60e678441..a96611b2f 100644 --- a/Projects/UOContent/Engines/BulkOrders/SmallTailorBOD.cs +++ b/Projects/UOContent/Engines/BulkOrders/SmallTailorBOD.cs @@ -142,8 +142,7 @@ namespace Server.Engines.BulkOrders if (item != null) { - var allRequiredSkills = true; - var chance = item.GetSuccessChance(m, null, system, false, out allRequiredSkills); + var chance = item.GetSuccessChance(m, null, system, false, out var allRequiredSkills); if (allRequiredSkills && chance >= 0.0) { diff --git a/Projects/UOContent/Engines/CannedEvil/ChampionSkullBrazier.cs b/Projects/UOContent/Engines/CannedEvil/ChampionSkullBrazier.cs index f1bb20a25..ca96884c2 100644 --- a/Projects/UOContent/Engines/CannedEvil/ChampionSkullBrazier.cs +++ b/Projects/UOContent/Engines/CannedEvil/ChampionSkullBrazier.cs @@ -83,7 +83,7 @@ namespace Server.Engines.CannedEvil } else { - SendLocalizedMessageTo(from, 1049487, ""); // I already have my champions awakening skull! + SendLocalizedMessageTo(from, 1049487); // I already have my champions awakening skull! } } @@ -109,11 +109,11 @@ namespace Server.Engines.CannedEvil } else if (skull == null) { - SendLocalizedMessageTo(from, 1049488, ""); // That is not my champions awakening skull! + SendLocalizedMessageTo(from, 1049488); // That is not my champions awakening skull! } else if (m_Skull != null) { - SendLocalizedMessageTo(from, 1049487, ""); // I already have my champions awakening skull! + SendLocalizedMessageTo(from, 1049487); // I already have my champions awakening skull! } else if (!skull.IsChildOf(from.Backpack)) { @@ -130,7 +130,7 @@ namespace Server.Engines.CannedEvil } else { - SendLocalizedMessageTo(from, 1049488, ""); // That is not my champions awakening skull! + SendLocalizedMessageTo(from, 1049488); // That is not my champions awakening skull! } } } diff --git a/Projects/UOContent/Engines/Chat/Channel.cs b/Projects/UOContent/Engines/Chat/Channel.cs index 2128eeb21..09b8f6cb3 100644 --- a/Projects/UOContent/Engines/Chat/Channel.cs +++ b/Projects/UOContent/Engines/Chat/Channel.cs @@ -76,7 +76,7 @@ namespace Server.Engines.Chat public bool IsVoiced(ChatUser user) => m_Voices.Contains(user); - public bool ValidatePassword(string password) => m_Password == null || m_Password.InsensitiveEquals(password); + public bool ValidatePassword(string password) => m_Password?.InsensitiveEquals(password) != false; public bool ValidateModerator(ChatUser user) { diff --git a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs index 3c586790b..27505a8c5 100644 --- a/Projects/UOContent/Engines/Craft/Core/CraftItem.cs +++ b/Projects/UOContent/Engines/Craft/Core/CraftItem.cs @@ -950,8 +950,7 @@ namespace Server.Engines.Craft if (RequiredExpansion == Expansion.None || from.NetState?.SupportsExpansion(RequiredExpansion) == true) { - bool allRequiredSkills; - var chance = GetSuccessChance(from, typeRes, craftSystem, false, out allRequiredSkills); + var chance = GetSuccessChance(from, typeRes, craftSystem, false, out var allRequiredSkills); if (allRequiredSkills && chance >= 0.0) { @@ -1414,9 +1413,8 @@ namespace Server.Engines.Craft } var quality = 1; - var allRequiredSkills = true; - m_CraftItem.CheckSkills(m_From, m_TypeRes, m_CraftSystem, ref quality, out allRequiredSkills, false); + m_CraftItem.CheckSkills(m_From, m_TypeRes, m_CraftSystem, ref quality, out _, false); var context = m_CraftSystem.GetContext(m_From); diff --git a/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs b/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs index d29bf354b..a2e09b687 100644 --- a/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs +++ b/Projects/UOContent/Engines/Craft/DefBlacksmithy.cs @@ -136,11 +136,10 @@ namespace Server.Engines.Craft public override void PlayCraftEffect(Mobile from) { - // no animation, instant sound + // To animate and synchronize with sound // if (from.Body.Type == BodyType.Human && !from.Mounted) // from.Animate( 9, 5, 1, true, false, 0 ); - // new InternalTimer( from ).Start(); - + // 0.7 second delay from.PlaySound(0x2A); } @@ -1336,19 +1335,6 @@ namespace Server.Engines.Craft MarkOption = true; CanEnhance = Core.AOS; } - - // Delay to synchronize the sound with the hit on the anvil - private class InternalTimer : Timer - { - private readonly Mobile m_From; - - public InternalTimer(Mobile from) : base(TimeSpan.FromSeconds(0.7)) => m_From = from; - - protected override void OnTick() - { - m_From.PlaySound(0x2A); - } - } } [AttributeUsage(AttributeTargets.Class)] diff --git a/Projects/UOContent/Engines/Craft/DefCarpentry.cs b/Projects/UOContent/Engines/Craft/DefCarpentry.cs index e4ffa5ed8..c440eda2c 100644 --- a/Projects/UOContent/Engines/Craft/DefCarpentry.cs +++ b/Projects/UOContent/Engines/Craft/DefCarpentry.cs @@ -39,6 +39,7 @@ namespace Server.Engines.Craft // no animation // if (from.Body.Type == BodyType.Human && !from.Mounted) // from.Animate( 9, 5, 1, true, false, 0 ); + // 0.7 second delay from.PlaySound(0x23D); } diff --git a/Projects/UOContent/Engines/Craft/DefGlassblowing.cs b/Projects/UOContent/Engines/Craft/DefGlassblowing.cs index c7a2c8091..6dbdb7dcf 100644 --- a/Projects/UOContent/Engines/Craft/DefGlassblowing.cs +++ b/Projects/UOContent/Engines/Craft/DefGlassblowing.cs @@ -120,18 +120,5 @@ namespace Server.Engines.Craft SetNeededExpansion(index, Expansion.ML); } } - - // Delay to synchronize the sound with the hit on the anvil - private class InternalTimer : Timer - { - private readonly Mobile m_From; - - public InternalTimer(Mobile from) : base(TimeSpan.FromSeconds(0.7)) => m_From = from; - - protected override void OnTick() - { - m_From.PlaySound(0x2A); - } - } } } diff --git a/Projects/UOContent/Engines/Craft/DefMasonry.cs b/Projects/UOContent/Engines/Craft/DefMasonry.cs index b52eceba4..52c8a8d9c 100644 --- a/Projects/UOContent/Engines/Craft/DefMasonry.cs +++ b/Projects/UOContent/Engines/Craft/DefMasonry.cs @@ -143,18 +143,5 @@ namespace Server.Engines.Craft AddSubRes(typeof(VeriteGranite), 1044029, 95.0, 1044514, 1044527); AddSubRes(typeof(ValoriteGranite), 1044030, 99.0, 1044514, 1044527); } - - // Delay to synchronize the sound with the hit on the anvil - private class InternalTimer : Timer - { - private readonly Mobile m_From; - - public InternalTimer(Mobile from) : base(TimeSpan.FromSeconds(0.7)) => m_From = from; - - protected override void OnTick() - { - m_From.PlaySound(0x23D); - } - } } } diff --git a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs index 91eee421e..c10c70888 100644 --- a/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs +++ b/Projects/UOContent/Engines/Doom/LeverPuzzle/LeverPuzzleItems.cs @@ -44,7 +44,7 @@ namespace Server.Engines.Doom public void CallBackMessage() { - PublicOverheadMessage(MessageType.Regular, 0x3B2, 1060003, ""); // You try to pry the box open... + PublicOverheadMessage(MessageType.Regular, 0x3B2, 1060003); // You try to pry the box open... } public override void OnAfterDelete() diff --git a/Projects/UOContent/Engines/Events/BroadcastEvent.cs b/Projects/UOContent/Engines/Events/BroadcastEvent.cs index aa0b9467c..a900d263b 100644 --- a/Projects/UOContent/Engines/Events/BroadcastEvent.cs +++ b/Projects/UOContent/Engines/Events/BroadcastEvent.cs @@ -3,7 +3,7 @@ namespace Server.Engines.Events public class BroadcastEvent : IEvent { private readonly int _hue; - private readonly string _text = ""; + private readonly string _text; public BroadcastEvent(int hue, string text) { diff --git a/Projects/UOContent/Engines/Khaldun/KhaldunPitTeleporter.cs b/Projects/UOContent/Engines/Khaldun/KhaldunPitTeleporter.cs index bd0457308..66e910959 100644 --- a/Projects/UOContent/Engines/Khaldun/KhaldunPitTeleporter.cs +++ b/Projects/UOContent/Engines/Khaldun/KhaldunPitTeleporter.cs @@ -33,8 +33,8 @@ namespace Server.Items [CommandProperty(AccessLevel.GameMaster)] public Map MapDest { get; set; } - public override int LabelNumber => - 1016511; // the floor of the cavern seems to have collapsed here - a faint light is visible at the bottom of the pit + // the floor of the cavern seems to have collapsed here - a faint light is visible at the bottom of the pit + public override int LabelNumber => 1016511; public override void OnDoubleClick(Mobile m) { @@ -45,22 +45,9 @@ namespace Server.Items var map = MapDest; - if (map == null || map == Map.Internal) - { - map = m.Map; - } - - var p = PointDest; - - if (p == Point3D.Zero) - { - p = m.Location; - } - - if (m.InRange(this, 3)) + if (map != null && map != Map.Internal && m.InRange(this, 3)) { BaseCreature.TeleportPets(m, PointDest, MapDest); - m.MoveToWorld(PointDest, MapDest); } else diff --git a/Projects/UOContent/Engines/MLQuests/Mobiles/BoonCollector.cs b/Projects/UOContent/Engines/MLQuests/Mobiles/BoonCollector.cs index 89fa3e49f..9ab500594 100644 --- a/Projects/UOContent/Engines/MLQuests/Mobiles/BoonCollector.cs +++ b/Projects/UOContent/Engines/MLQuests/Mobiles/BoonCollector.cs @@ -10,8 +10,6 @@ namespace Server.Engines.MLQuests.Mobiles { public abstract class DoneQuestCollector : BaseCreature, IRaceChanger { - private static Type typeOfRaceChangeConfirmGump = typeof(RaceChangeConfirmGump); - private InternalTimer m_Timer; public DoneQuestCollector() diff --git a/Projects/UOContent/Engines/Pathing/SlowAStarAlgorithm.cs b/Projects/UOContent/Engines/Pathing/SlowAStarAlgorithm.cs index bc83f0938..53ae6b473 100644 --- a/Projects/UOContent/Engines/Pathing/SlowAStarAlgorithm.cs +++ b/Projects/UOContent/Engines/Pathing/SlowAStarAlgorithm.cs @@ -101,10 +101,10 @@ namespace Server.PathAlgorithms.SlowAStar path[pathCount++] = (Direction)curNode.dir; - if (pathCount == MaxNodes) - { - break; - } + // if (pathCount == MaxNodes) + // { + // break; + // } while (xBacktrack != startNode.x || yBacktrack != startNode.y || zBacktrack != startNode.z) { diff --git a/Projects/UOContent/Engines/Plants/PlantItem.cs b/Projects/UOContent/Engines/Plants/PlantItem.cs index 3615be705..edf59eab2 100644 --- a/Projects/UOContent/Engines/Plants/PlantItem.cs +++ b/Projects/UOContent/Engines/Plants/PlantItem.cs @@ -96,7 +96,7 @@ namespace Server.Engines.Plants if (hits == 0 && m_PlantStatus > PlantStatus.BowlOfDirt) { - PlantSystem.Hits = hits + 1; + PlantSystem.Hits = 1; } else { diff --git a/Projects/UOContent/Items/Misc/TrashBarrel.cs b/Projects/UOContent/Items/Misc/TrashBarrel.cs index e06cbd52c..b22cd34c1 100644 --- a/Projects/UOContent/Items/Misc/TrashBarrel.cs +++ b/Projects/UOContent/Items/Misc/TrashBarrel.cs @@ -123,7 +123,7 @@ namespace Server.Items if (items.Count > 0) { - PublicOverheadMessage(MessageType.Regular, 0x3B2, message, ""); + PublicOverheadMessage(MessageType.Regular, 0x3B2, message); for (var i = items.Count - 1; i >= 0; --i) { diff --git a/Projects/UOContent/Misc/CharacterCreation.cs b/Projects/UOContent/Misc/CharacterCreation.cs index 032bc6221..275508b90 100644 --- a/Projects/UOContent/Misc/CharacterCreation.cs +++ b/Projects/UOContent/Misc/CharacterCreation.cs @@ -9,6 +9,8 @@ namespace Server.Misc { public static class CharacterCreation { + private static readonly TimeSpan BadStartMessageDelay = TimeSpan.FromSeconds(3.5); + private static readonly CityInfo m_NewHavenInfo = new("New Haven", "The Bountiful Harvest Inn", 3503, 2574, 14, Map.Trammel); @@ -81,9 +83,7 @@ namespace Server.Misc Container cont; // Begin box of money - cont = new WoodenBox(); - cont.ItemID = 0xE7D; - cont.Hue = 0x489; + cont = new WoodenBox { ItemID = 0xE7D, Hue = 0x489 }; PlaceItemIn(cont, 16, 51, new BankCheck(500000)); PlaceItemIn(cont, 28, 51, new BankCheck(250000)); @@ -98,8 +98,7 @@ namespace Server.Misc // End box of money // Begin bag of potion kegs - cont = new Backpack(); - cont.Name = "Various Potion Kegs"; + cont = new Backpack { Name = "Various Potion Kegs" }; PlaceItemIn(cont, 45, 149, MakePotionKeg(PotionEffect.CureGreater, 0x2D)); PlaceItemIn(cont, 69, 149, MakePotionKeg(PotionEffect.HealGreater, 0x499)); @@ -113,8 +112,7 @@ namespace Server.Misc // End bag of potion kegs // Begin bag of tools - cont = new Bag(); - cont.Name = "Tool Bag"; + cont = new Bag { Name = "Tool Bag" }; PlaceItemIn(cont, 30, 35, new TinkerTools(1000)); PlaceItemIn(cont, 60, 35, new HousePlacementTool()); @@ -144,8 +142,7 @@ namespace Server.Misc // End bag of tools // Begin bag of archery ammo - cont = new Bag(); - cont.Name = "Bag Of Archery Ammo"; + cont = new Bag { Name = "Bag Of Archery Ammo" }; PlaceItemIn(cont, 48, 76, new Arrow(5000)); PlaceItemIn(cont, 72, 76, new Bolt(5000)); @@ -154,8 +151,7 @@ namespace Server.Misc // End bag of archery ammo // Begin bag of treasure maps - cont = new Bag(); - cont.Name = "Bag Of Treasure Maps"; + cont = new Bag { Name = "Bag Of Treasure Maps" }; PlaceItemIn(cont, 30, 35, new TreasureMap(1, Map.Trammel)); PlaceItemIn(cont, 45, 35, new TreasureMap(2, Map.Trammel)); @@ -178,9 +174,7 @@ namespace Server.Misc // End bag of treasure maps // Begin bag of raw materials - cont = new Bag(); - cont.Hue = 0x835; - cont.Name = "Raw Materials Bag"; + cont = new Bag { Hue = 0x835, Name = "Raw Materials Bag" }; PlaceItemIn(cont, 92, 60, new BarbedLeather(5000)); PlaceItemIn(cont, 92, 68, new HornedLeather(5000)); @@ -212,9 +206,7 @@ namespace Server.Misc // End bag of raw materials // Begin bag of spell casting stuff - cont = new Backpack(); - cont.Hue = 0x480; - cont.Name = "Spell Casting Stuff"; + cont = new Backpack { Hue = 0x480, Name = "Spell Casting Stuff" }; PlaceItemIn(cont, 45, 105, new Spellbook(ulong.MaxValue)); PlaceItemIn(cont, 65, 105, new NecromancerSpellbook(0xFFFFUL)); @@ -226,12 +218,10 @@ namespace Server.Misc runebook.CurCharges = runebook.MaxCharges; PlaceItemIn(cont, 145, 105, runebook); - Item toHue = new BagOfReagents(150); - toHue.Hue = 0x2D; + Item toHue = new BagOfReagents(150) { Hue = 0x2D }; PlaceItemIn(cont, 45, 150, toHue); - toHue = new BagOfNecroReagents(150); - toHue.Hue = 0x488; + toHue = new BagOfNecroReagents(150) { Hue = 0x488 }; PlaceItemIn(cont, 65, 150, toHue); PlaceItemIn(cont, 140, 150, new BagOfAllReagents(500)); @@ -247,9 +237,7 @@ namespace Server.Misc // End bag of spell casting stuff // Begin bag of ethereals - cont = new Backpack(); - cont.Hue = 0x490; - cont.Name = "Bag Of Ethy's!"; + cont = new Backpack { Hue = 0x490, Name = "Bag Of Ethy's!" }; PlaceItemIn(cont, 45, 66, new EtherealHorse()); PlaceItemIn(cont, 69, 82, new EtherealOstard()); @@ -264,9 +252,7 @@ namespace Server.Misc // End bag of ethereals // Begin first bag of artifacts - cont = new Backpack(); - cont.Hue = 0x48F; - cont.Name = "Bag of Artifacts"; + cont = new Backpack { Hue = 0x48F, Name = "Bag of Artifacts" }; PlaceItemIn(cont, 45, 66, new TitansHammer()); PlaceItemIn(cont, 69, 82, new InquisitorsResolution()); @@ -277,9 +263,7 @@ namespace Server.Misc // End first bag of artifacts // Begin second bag of artifacts - cont = new Backpack(); - cont.Hue = 0x48F; - cont.Name = "Bag of Artifacts"; + cont = new Backpack { Hue = 0x48F, Name = "Bag of Artifacts" }; PlaceItemIn(cont, 45, 66, new GauntletsOfNobility()); PlaceItemIn(cont, 69, 82, new MidnightBracers()); @@ -319,9 +303,7 @@ namespace Server.Misc // End second bag of artifacts // Begin bag of minor artifacts - cont = new Backpack(); - cont.Hue = 0x48F; - cont.Name = "Bag of Minor Artifacts"; + cont = new Backpack { Hue = 0x48F, Name = "Bag of Minor Artifacts" }; PlaceItemIn(cont, 45, 66, new LunaLance()); PlaceItemIn(cont, 69, 82, new VioletCourage()); @@ -364,9 +346,7 @@ namespace Server.Misc if (Core.SE) { - cont = new Bag(); - cont.Hue = 0x501; - cont.Name = "Tokuno Minor Artifacts"; + cont = new Bag { Hue = 0x501, Name = "Tokuno Minor Artifacts" }; PlaceItemIn(cont, 42, 70, new Exiler()); PlaceItemIn(cont, 38, 53, new HanzosBow()); @@ -394,8 +374,7 @@ namespace Server.Misc if (Core.SE) // This bag came only after SE. { - cont = new Bag(); - cont.Name = "Bag of Bows"; + cont = new Bag { Name = "Bag of Bows" }; PlaceItemIn(cont, 31, 84, new Bow()); PlaceItemIn(cont, 78, 74, new CompositeBow()); @@ -430,9 +409,7 @@ namespace Server.Misc bank.DropItem(new BankCheck(1000000)); // Full spellbook - var book = new Spellbook(); - - book.Content = ulong.MaxValue; + var book = new Spellbook { Content = ulong.MaxValue }; bank.DropItem(book); @@ -482,11 +459,7 @@ namespace Server.Misc bank.DropItem(new DyeTub()); bank.DropItem(new BlackDyeTub()); - var darkRedTub = new DyeTub(); - - darkRedTub.DyedHue = 0x485; - darkRedTub.Redyable = false; - + var darkRedTub = new DyeTub { DyedHue = 0x485, Redyable = false }; bank.DropItem(darkRedTub); // Some food @@ -667,20 +640,8 @@ namespace Server.Misc newChar.Player = true; newChar.AccessLevel = args.Account.AccessLevel; newChar.Female = args.Female; - // newChar.Body = newChar.Female ? 0x191 : 0x190; - - if (Core.Expansion >= args.Race.RequiredExpansion) - { - newChar.Race = args.Race; // Sets body - } - else - { - newChar.Race = Race.DefaultRace; - } - - // newChar.Hue = Utility.ClipSkinHue( args.Hue & 0x3FFF ) | 0x8000; + newChar.Race = Core.Expansion >= args.Race.RequiredExpansion ? args.Race : Race.DefaultRace; newChar.Hue = newChar.Race.ClipSkinHue(args.Hue & 0x3FFF) | 0x8000; - newChar.Hunger = 20; var young = false; @@ -746,30 +707,9 @@ namespace Server.Misc new WelcomeTimer(newChar).Start(); } - public static bool VerifyProfession(int profession) - { - if (profession < 0) - { - return false; - } + public static bool VerifyProfession(int profession) => + profession >= 0 && (profession < 4 || Core.AOS && profession < 6 || Core.SE && profession < 8); - if (profession < 4) - { - return true; - } - - if (Core.AOS && profession < 6) - { - return true; - } - - if (Core.SE && profession < 8) - { - return true; - } - - return false; - } private static CityInfo GetStartLocation(CharacterCreatedEventArgs args, bool isYoung) { @@ -794,15 +734,14 @@ namespace Server.Misc useHaven = true; - // ReSharper disable once CA1806 - new BadStartMessage(m, 1062205); /* * Unfortunately you are playing on a *NON-Age-Of-Shadows* game * installation and cannot be transported to Malas. * You will not be able to take your new player quest in Malas * without an AOS client. You are now being taken to the city of * Haven on the Trammel facet. - * */ + */ + Timer.DelayCall(BadStartMessageDelay, from => from.SendLocalizedMessage(1062205), m); break; } @@ -819,15 +758,14 @@ namespace Server.Misc useHaven = true; - // ReSharper disable once CA1806 - new BadStartMessage(m, 1063487); /* * Unfortunately you are playing on a *NON-Samurai-Empire* game * installation and cannot be transported to Tokuno. * You will not be able to take your new player quest in Tokuno * without an SE client. You are now being taken to the city of * Haven on the Trammel facet. - * */ + */ + Timer.DelayCall(BadStartMessageDelay, from => from.SendLocalizedMessage(1063487), m); break; } @@ -840,25 +778,20 @@ namespace Server.Misc useHaven = true; - new BadStartMessage(m, 1063487); /* * Unfortunately you are playing on a *NON-Samurai-Empire* game * installation and cannot be transported to Tokuno. * You will not be able to take your new player quest in Tokuno * without an SE client. You are now being taken to the city of * Haven on the Trammel facet. - * */ + */ + Timer.DelayCall(BadStartMessageDelay, from => from.SendLocalizedMessage(1063487), m); break; } } - if (useHaven) - { - return m_NewHavenInfo; - } - - return args.City; + return useHaven ? m_NewHavenInfo : args.City; } private static void FixStats(ref int str, ref int dex, ref int intel, int max) @@ -1890,22 +1823,4 @@ namespace Server.Misc } } } - - internal class BadStartMessage : Timer - { - private readonly int m_Message; - private readonly Mobile m_Mobile; - - public BadStartMessage(Mobile m, int message) : base(TimeSpan.FromSeconds(3.5)) - { - m_Mobile = m; - m_Message = message; - Start(); - } - - protected override void OnTick() - { - m_Mobile.SendLocalizedMessage(m_Message); - } - } } diff --git a/Projects/UOContent/Skills/Anatomy.cs b/Projects/UOContent/Skills/Anatomy.cs index aeff35f7e..7d2721c59 100644 --- a/Projects/UOContent/Skills/Anatomy.cs +++ b/Projects/UOContent/Skills/Anatomy.cs @@ -126,7 +126,7 @@ namespace Server.SkillHandlers } else { - (targeted as Item)?.SendLocalizedMessageTo(from, 500323, ""); // Only living things have anatomies! + (targeted as Item)?.SendLocalizedMessageTo(from, 500323); // Only living things have anatomies! } } } diff --git a/Projects/UOContent/Skills/EvalInt.cs b/Projects/UOContent/Skills/EvalInt.cs index 5c9c8db04..0c3ac639d 100644 --- a/Projects/UOContent/Skills/EvalInt.cs +++ b/Projects/UOContent/Skills/EvalInt.cs @@ -106,8 +106,7 @@ namespace Server.SkillHandlers { (targeted as Item)?.SendLocalizedMessageTo( from, - 500908, - "" + 500908 ); // It looks smarter than a rock, but dumber than a piece of wood. } }