diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index cfcaeb003..5868e2285 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -3188,16 +3188,8 @@ namespace Server.Multis { base.GetProperties(list); - string houseName, owner, location; - - houseName = m_House == null ? "an unnamed house" : m_House.Sign.GetName(); - - Mobile houseOwner = m_House?.Owner; - - if (houseOwner == null) - owner = "nobody"; - else - owner = houseOwner.Name; + string houseName = m_House == null ? "an unnamed house" : m_House.Sign.GetName(); + string owner = m_House?.Owner?.Name ?? "nobody"; int xLong = 0, yLat = 0, xMins = 0, yMins = 0; bool xEast = false, ySouth = false; @@ -3205,10 +3197,8 @@ namespace Server.Multis bool valid = m_House != null && Sextant.Format(m_House.Location, m_House.Map, ref xLong, ref yLat, ref xMins, ref yMins, ref xEast, ref ySouth); - if (valid) - location = $"{yLat}° {yMins}'{(ySouth ? "S" : "N")}, {xLong}° {xMins}'{(xEast ? "E" : "W")}"; - else - location = "unknown"; + string location = + valid ? $"{yLat}° {yMins}'{(ySouth ? "S" : "N")}, {xLong}° {xMins}'{(xEast ? "E" : "W")}" : "unknown"; list.Add(1061112, Utility.FixHtml(houseName)); // House Name: ~1_val~ list.Add(1061113, owner); // Owner: ~1_val~ @@ -3764,7 +3754,7 @@ namespace Server.Multis ISecurable sec = null; - if (item is ISecurable) + if (item is ISecurable securable) { bool isOwned = house.Doors.Contains(item); @@ -3775,7 +3765,7 @@ namespace Server.Multis isOwned = house.HasLockedDownItem(item); if (isOwned) - sec = (ISecurable)item; + sec = securable; } else { diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index 4eb16b535..e6ea8a6a8 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -913,8 +913,8 @@ namespace Server.Spells m_Spell.OnCast(); - if (m_Spell.Caster.Player && m_Spell.Caster.Target != originalTarget && m_Spell.Caster.Target != null) - m_Spell.Caster.Target.BeginTimeout(m_Spell.Caster, TimeSpan.FromSeconds(30.0)); + if (m_Spell.Caster.Player && m_Spell.Caster.Target != originalTarget) + m_Spell.Caster.Target?.BeginTimeout(m_Spell.Caster, TimeSpan.FromSeconds(30.0)); m_Spell.m_CastTimer = null; } diff --git a/Server/Mobile.cs b/Server/Mobile.cs index 38f01b6a1..f9ef79ecc 100644 --- a/Server/Mobile.cs +++ b/Server/Mobile.cs @@ -3189,8 +3189,7 @@ namespace Server private void StopAggrExpire() { - if (m_ExpireAggrTimer != null) - m_ExpireAggrTimer.Stop(); + m_ExpireAggrTimer?.Stop(); m_ExpireAggrTimer = null; } @@ -8221,16 +8220,17 @@ namespace Server public override void OnResponse(Mobile from, string text) { - if (m_Callback != null) - m_Callback(from, text); + m_Callback?.Invoke(@from, text); } public override void OnCancel(Mobile from) { if (m_CallbackHandlesCancel && m_Callback != null) m_Callback(from, ""); - else if (m_CancelCallback != null) - m_CancelCallback(from, ""); + else + { + m_CancelCallback?.Invoke(@from, ""); + } } } @@ -8285,16 +8285,17 @@ namespace Server public override void OnResponse(Mobile from, string text) { - if (m_Callback != null) - m_Callback(from, text, m_State); + m_Callback?.Invoke(@from, text, m_State); } public override void OnCancel(Mobile from) { if (m_CallbackHandlesCancel && m_Callback != null) m_Callback(from, "", m_State); - else if (m_CancelCallback != null) - m_CancelCallback(from, "", m_State); + else + { + m_CancelCallback?.Invoke(@from, "", m_State); + } } } @@ -8349,16 +8350,17 @@ namespace Server public override void OnResponse(Mobile from, string text) { - if (m_Callback != null) - m_Callback(from, text, m_State); + m_Callback?.Invoke(@from, text, m_State); } public override void OnCancel(Mobile from) { if (m_CallbackHandlesCancel && m_Callback != null) m_Callback(from, "", m_State); - else if (m_CancelCallback != null) - m_CancelCallback(from, "", m_State); + else + { + m_CancelCallback?.Invoke(@from, "", m_State); + } } } @@ -10058,10 +10060,7 @@ namespace Server public void PrivateOverheadMessage(MessageType type, int hue, int number, string args, NetState state) { - if (state == null) - return; - - state.Send(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); + state?.Send(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); } public void LocalOverheadMessage(MessageType type, int hue, bool ascii, string text) @@ -10086,8 +10085,7 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); + ns?.Send(new MessageLocalized(Serial, Body, type, hue, 3, number, Name, args)); } public void NonlocalOverheadMessage(MessageType type, int hue, int number) @@ -10146,8 +10144,7 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(MessageLocalized.InstantiateGeneric(number)); + ns?.Send(MessageLocalized.InstantiateGeneric(number)); } public void SendLocalizedMessage(int number, string args) @@ -10161,15 +10158,13 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(MessageLocalized.InstantiateGeneric(number)); + ns?.Send(MessageLocalized.InstantiateGeneric(number)); } else { NetState ns = m_NetState; - if (ns != null) - ns.Send(new MessageLocalized(Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", args)); + ns?.Send(new MessageLocalized(Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", args)); } } @@ -10187,9 +10182,8 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(new MessageLocalizedAffix(Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", - (append ? AffixType.Append : AffixType.Prepend) | AffixType.System, affix, args)); + ns?.Send(new MessageLocalizedAffix(Serial.MinusOne, -1, MessageType.Regular, hue, 3, number, "System", + (append ? AffixType.Append : AffixType.Prepend) | AffixType.System, affix, args)); } #endregion @@ -10210,8 +10204,7 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text)); + ns?.Send(new UnicodeMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "ENU", "System", text)); } public void SendMessage(int hue, string format, params object[] args) @@ -10233,8 +10226,7 @@ namespace Server { NetState ns = m_NetState; - if (ns != null) - ns.Send(new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text)); + ns?.Send(new AsciiMessage(Serial.MinusOne, -1, MessageType.Regular, hue, 3, "System", text)); } public void SendAsciiMessage(int hue, string format, params object[] args) diff --git a/Server/Network/Packets.cs b/Server/Network/Packets.cs index 67d7bd8ee..b60627c7d 100644 --- a/Server/Network/Packets.cs +++ b/Server/Network/Packets.cs @@ -518,7 +518,7 @@ namespace Server.Network { EquipInfoAttribute[] attrs = info.Attributes; - EnsureCapacity(17 + (info.Crafter == null ? 0 : 6 + info.Crafter.Name == null ? 0 : info.Crafter.Name.Length) + + EnsureCapacity(17 + (info.Crafter?.Name.Length ?? 0) + (info.Unidentified ? 4 : 0) + attrs.Length * 6); m_Stream.Write((short)0x10); diff --git a/Server/ScriptCompiler.cs b/Server/ScriptCompiler.cs index 145069a41..d03f08b1c 100644 --- a/Server/ScriptCompiler.cs +++ b/Server/ScriptCompiler.cs @@ -716,10 +716,9 @@ namespace Server { object[] attrs = type.GetCustomAttributes(typeofTypeAliasAttribute, false); - if (attrs != null && attrs.Length > 0) - if (attrs[0] is TypeAliasAttribute attr) - for (int j = 0; j < attr.Aliases.Length; ++j) - FullNames.Add(attr.Aliases[j], type); + if (attrs.Length > 0 && attrs[0] is TypeAliasAttribute attr) + for (int j = 0; j < attr.Aliases.Length; ++j) + FullNames.Add(attr.Aliases[j], type); } } } diff --git a/Server/Timer.cs b/Server/Timer.cs index 230de2a9f..6ce81605e 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -154,8 +154,6 @@ namespace Server string name = ToString(); - if (name == null) name = "null"; - return TimerProfile.Acquire(name); }