diff --git a/Scripts/Commands/ConvertPlayers.cs b/Scripts/Commands/ConvertPlayers.cs index 5d4395cc6..fc0dcd3e8 100644 --- a/Scripts/Commands/ConvertPlayers.cs +++ b/Scripts/Commands/ConvertPlayers.cs @@ -24,9 +24,8 @@ namespace Server.Commands if ( m.Player && !(m is PlayerMobile ) ) { count++; - if ( m.NetState != null ) - m.NetState.Dispose(); - + m.NetState?.Dispose(); + PlayerMobile pm = new PlayerMobile( m.Serial ); pm.DefaultMobileInit(); diff --git a/Scripts/Commands/Decorate.cs b/Scripts/Commands/Decorate.cs index c4fb38bc2..470705759 100644 --- a/Scripts/Commands/Decorate.cs +++ b/Scripts/Commands/Decorate.cs @@ -1018,8 +1018,7 @@ namespace Server.Commands } } - if ( item != null ) - item.Delete(); + item?.Delete(); return count; } diff --git a/Scripts/Commands/DecorateMag.cs b/Scripts/Commands/DecorateMag.cs index f2a540b14..4ae744531 100644 --- a/Scripts/Commands/DecorateMag.cs +++ b/Scripts/Commands/DecorateMag.cs @@ -1015,8 +1015,7 @@ namespace Server.Commands } } - if ( item != null ) - item.Delete(); + item?.Delete(); return count; } diff --git a/Scripts/Commands/Generic/Implementors/ScreenCommandImplementor.cs b/Scripts/Commands/Generic/Implementors/ScreenCommandImplementor.cs index c90736721..d62b23274 100644 --- a/Scripts/Commands/Generic/Implementors/ScreenCommandImplementor.cs +++ b/Scripts/Commands/Generic/Implementors/ScreenCommandImplementor.cs @@ -16,10 +16,7 @@ namespace Server.Commands.Generic { RangeCommandImplementor impl = RangeCommandImplementor.Instance; - if ( impl == null ) - return; - - impl.Process( 18, from, command, args ); + impl?.Process( 18, @from, command, args ); } } } diff --git a/Scripts/Engines/BulkOrders/LargeBulkEntry.cs b/Scripts/Engines/BulkOrders/LargeBulkEntry.cs index 43567cb02..ebc8f970e 100644 --- a/Scripts/Engines/BulkOrders/LargeBulkEntry.cs +++ b/Scripts/Engines/BulkOrders/LargeBulkEntry.cs @@ -13,7 +13,9 @@ namespace Server.Engines.BulkOrders set => m_Owner = value; } public int Amount{ get => m_Amount; - set{ m_Amount = value; if ( m_Owner != null ) m_Owner.InvalidateProperties(); } } + set{ m_Amount = value; + m_Owner?.InvalidateProperties(); + } } public SmallBulkEntry Details => m_Details; public static SmallBulkEntry[] LargeRing => GetEntries( "Blacksmith", "largering" ); diff --git a/Scripts/Engines/BulkOrders/LargeSmithBOD.cs b/Scripts/Engines/BulkOrders/LargeSmithBOD.cs index 7c1ccf05c..24fd8a6cc 100644 --- a/Scripts/Engines/BulkOrders/LargeSmithBOD.cs +++ b/Scripts/Engines/BulkOrders/LargeSmithBOD.cs @@ -101,13 +101,10 @@ namespace Server.Engines.BulkOrders { RewardItem rewardItem = rewardGroup.AcquireItem(); - if ( rewardItem != null ) - { - Item item = rewardItem.Construct(); + Item item = rewardItem?.Construct(); - if ( item != null ) - list.Add( item ); - } + if ( item != null ) + list.Add( item ); } } diff --git a/Scripts/Engines/BulkOrders/LargeTailorBOD.cs b/Scripts/Engines/BulkOrders/LargeTailorBOD.cs index 8ab88b196..890514a7f 100644 --- a/Scripts/Engines/BulkOrders/LargeTailorBOD.cs +++ b/Scripts/Engines/BulkOrders/LargeTailorBOD.cs @@ -96,13 +96,10 @@ namespace Server.Engines.BulkOrders { RewardItem rewardItem = rewardGroup.AcquireItem(); - if ( rewardItem != null ) - { - Item item = rewardItem.Construct(); + Item item = rewardItem?.Construct(); - if ( item != null ) - list.Add( item ); - } + if ( item != null ) + list.Add( item ); } } diff --git a/Scripts/Engines/BulkOrders/SmallSmithBOD.cs b/Scripts/Engines/BulkOrders/SmallSmithBOD.cs index ae54ea07f..ca3299a05 100644 --- a/Scripts/Engines/BulkOrders/SmallSmithBOD.cs +++ b/Scripts/Engines/BulkOrders/SmallSmithBOD.cs @@ -52,13 +52,10 @@ namespace Server.Engines.BulkOrders { RewardItem rewardItem = rewardGroup.AcquireItem(); - if ( rewardItem != null ) - { - Item item = rewardItem.Construct(); + Item item = rewardItem?.Construct(); - if ( item != null ) - list.Add( item ); - } + if ( item != null ) + list.Add( item ); } } diff --git a/Scripts/Engines/BulkOrders/SmallTailorBOD.cs b/Scripts/Engines/BulkOrders/SmallTailorBOD.cs index 54ed19d1a..3b8b8d43c 100644 --- a/Scripts/Engines/BulkOrders/SmallTailorBOD.cs +++ b/Scripts/Engines/BulkOrders/SmallTailorBOD.cs @@ -45,13 +45,10 @@ namespace Server.Engines.BulkOrders { RewardItem rewardItem = rewardGroup.AcquireItem(); - if ( rewardItem != null ) - { - Item item = rewardItem.Construct(); + Item item = rewardItem?.Construct(); - if ( item != null ) - list.Add( item ); - } + if ( item != null ) + list.Add( item ); } } diff --git a/Scripts/Engines/CannedEvil/ChampionAltar.cs b/Scripts/Engines/CannedEvil/ChampionAltar.cs index ce02765a6..20d58b39e 100644 --- a/Scripts/Engines/CannedEvil/ChampionAltar.cs +++ b/Scripts/Engines/CannedEvil/ChampionAltar.cs @@ -15,8 +15,7 @@ namespace Server.Engines.CannedEvil { base.OnAfterDelete(); - if ( m_Spawn != null ) - m_Spawn.Delete(); + m_Spawn?.Delete(); } public ChampionAltar( Serial serial ) : base( serial ) diff --git a/Scripts/Engines/CannedEvil/ChampionPlatform.cs b/Scripts/Engines/CannedEvil/ChampionPlatform.cs index 434924f77..87172e6b2 100644 --- a/Scripts/Engines/CannedEvil/ChampionPlatform.cs +++ b/Scripts/Engines/CannedEvil/ChampionPlatform.cs @@ -46,8 +46,7 @@ namespace Server.Engines.CannedEvil { base.OnAfterDelete(); - if ( m_Spawn != null ) - m_Spawn.Delete(); + m_Spawn?.Delete(); } public ChampionPlatform( Serial serial ) : base( serial ) diff --git a/Scripts/Engines/CannedEvil/ChampionSkullBrazier.cs b/Scripts/Engines/CannedEvil/ChampionSkullBrazier.cs index 5c79acdb7..974a29577 100644 --- a/Scripts/Engines/CannedEvil/ChampionSkullBrazier.cs +++ b/Scripts/Engines/CannedEvil/ChampionSkullBrazier.cs @@ -19,7 +19,9 @@ namespace Server.Engines.CannedEvil [CommandProperty( AccessLevel.GameMaster )] public Item Skull{ get => m_Skull; - set{ m_Skull = value; if ( m_Platform != null ) m_Platform.Validate(); } } + set{ m_Skull = value; + m_Platform?.Validate(); + } } public override int LabelNumber => 1049489 + (int)m_Type; @@ -38,8 +40,7 @@ namespace Server.Engines.CannedEvil public override void OnDoubleClick( Mobile from ) { - if ( m_Platform != null ) - m_Platform.Validate(); + m_Platform?.Validate(); BeginSacrifice( from ); } diff --git a/Scripts/Engines/CannedEvil/ChampionSkullPlatform.cs b/Scripts/Engines/CannedEvil/ChampionSkullPlatform.cs index bafb2ea5b..b9a7096da 100644 --- a/Scripts/Engines/CannedEvil/ChampionSkullPlatform.cs +++ b/Scripts/Engines/CannedEvil/ChampionSkullPlatform.cs @@ -75,8 +75,7 @@ namespace Server.Engines.CannedEvil { Effects.SendBoltEffect( brazier ); - if ( brazier.Skull != null ) - brazier.Skull.Delete(); + brazier.Skull?.Delete(); } } diff --git a/Scripts/Engines/CannedEvil/ChampionSpawn.cs b/Scripts/Engines/CannedEvil/ChampionSpawn.cs index 57923ca20..3a4b868a8 100644 --- a/Scripts/Engines/CannedEvil/ChampionSpawn.cs +++ b/Scripts/Engines/CannedEvil/ChampionSpawn.cs @@ -91,8 +91,7 @@ namespace Server.Engines.CannedEvil public void UpdateRegion() { - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); if ( !Deleted && Map != Map.Internal ) { @@ -274,8 +273,7 @@ namespace Server.Engines.CannedEvil m_Timer = new SliceTimer( this ); m_Timer.Start(); - if ( m_RestartTimer != null ) - m_RestartTimer.Stop(); + m_RestartTimer?.Stop(); m_RestartTimer = null; @@ -303,8 +301,7 @@ namespace Server.Engines.CannedEvil m_Timer = null; - if ( m_RestartTimer != null ) - m_RestartTimer.Stop(); + m_RestartTimer?.Stop(); m_RestartTimer = null; @@ -317,8 +314,7 @@ namespace Server.Engines.CannedEvil public void BeginRestart( TimeSpan ts ) { - if ( m_RestartTimer != null ) - m_RestartTimer.Stop(); + m_RestartTimer?.Stop(); m_RestartTime = DateTime.UtcNow + ts; @@ -596,8 +592,7 @@ namespace Server.Engines.CannedEvil } catch { } - if ( m_Champion != null ) - m_Champion.MoveToWorld( new Point3D( X, Y, Z - 15 ), Map ); + m_Champion?.MoveToWorld( new Point3D( X, Y, Z - 15 ), Map ); } public void Respawn() @@ -905,14 +900,11 @@ namespace Server.Engines.CannedEvil { base.OnAfterDelete(); - if ( m_Platform != null ) - m_Platform.Delete(); + m_Platform?.Delete(); - if ( m_Altar != null ) - m_Altar.Delete(); + m_Altar?.Delete(); - if ( m_Idol != null ) - m_Idol.Delete(); + m_Idol?.Delete(); if ( m_RedSkulls != null ) { @@ -1235,8 +1227,7 @@ namespace Server.Engines.CannedEvil { base.OnAfterDelete(); - if ( m_Spawn != null ) - m_Spawn.Delete(); + m_Spawn?.Delete(); } public IdolOfTheChampion( Serial serial ) : base( serial ) diff --git a/Scripts/Engines/Chat/Channel.cs b/Scripts/Engines/Chat/Channel.cs index c0bea6fa0..be903be46 100644 --- a/Scripts/Engines/Chat/Channel.cs +++ b/Scripts/Engines/Chat/Channel.cs @@ -133,8 +133,7 @@ namespace Server.Engines.Chat } else { - if ( user.CurrentChannel != null ) - user.CurrentChannel.RemoveUser( user ); // Remove them from their current channel first + user.CurrentChannel?.RemoveUser( user ); // Remove them from their current channel first ChatSystem.SendCommandTo( user.Mobile, ChatCommand.JoinedChannel, m_Name ); @@ -226,8 +225,8 @@ namespace Server.Engines.Chat SendMessage( 44, user.Username ) ; // %1 has been kicked out of the conference. } - if ( wasBanned && moderator != null ) - moderator.SendMessage( 62, user.Username ); // You are banning %1 from this conference. + if ( wasBanned ) + moderator?.SendMessage( 62, user.Username ); // You are banning %1 from this conference. } public bool VoiceRestricted diff --git a/Scripts/Engines/Chat/Chat.cs b/Scripts/Engines/Chat/Chat.cs index 21bd8d120..2d0362ca7 100644 --- a/Scripts/Engines/Chat/Chat.cs +++ b/Scripts/Engines/Chat/Chat.cs @@ -33,8 +33,7 @@ namespace Server.Engines.Chat public static void SendCommandTo( Mobile to, ChatCommand type, string param1, string param2 ) { - if ( to != null ) - to.Send( new ChatMessagePacket( null, (int)type + 20, param1, param2 ) ); + to?.Send( new ChatMessagePacket( null, (int)type + 20, param1, param2 ) ); } public static void OpenChatWindowRequest( NetState state, PacketReader pvSrc ) @@ -57,8 +56,7 @@ namespace Server.Engines.Chat if ( acct != null ) accountChatName = acct.GetTag( "ChatName" ); - if ( accountChatName != null ) - accountChatName = accountChatName.Trim(); + accountChatName = accountChatName?.Trim(); if ( accountChatName != null && accountChatName.Length > 0 ) { @@ -96,8 +94,7 @@ namespace Server.Engines.Chat accountChatName = chatName; - if ( acct != null ) - acct.AddTag( "ChatName", chatName ); + acct?.AddTag( "ChatName", chatName ); } else { diff --git a/Scripts/Engines/Chat/ChatActionHandlers.cs b/Scripts/Engines/Chat/ChatActionHandlers.cs index c540865be..49890c7eb 100644 --- a/Scripts/Engines/Chat/ChatActionHandlers.cs +++ b/Scripts/Engines/Chat/ChatActionHandlers.cs @@ -175,8 +175,7 @@ namespace Server.Engines.Chat } } - if ( password != null ) - password = password.Trim(); + password = password?.Trim(); if ( password != null && password.Length == 0 ) password = null; @@ -213,8 +212,7 @@ namespace Server.Engines.Chat name = param; } - if ( password != null ) - password = password.Trim(); + password = password?.Trim(); if ( password != null && password.Length == 0 ) password = null; diff --git a/Scripts/Engines/Chat/ChatUser.cs b/Scripts/Engines/Chat/ChatUser.cs index 840e8fbe6..5dabc181a 100644 --- a/Scripts/Engines/Chat/ChatUser.cs +++ b/Scripts/Engines/Chat/ChatUser.cs @@ -190,8 +190,7 @@ namespace Server.Engines.Chat { ChatSystem.SendCommandTo( user.Mobile, ChatCommand.CloseChatWindow ); - if ( user.m_Channel != null ) - user.m_Channel.RemoveUser( user ); + user.m_Channel?.RemoveUser( user ); m_Users.Remove( user ); m_Table.Remove( user.m_Mobile ); diff --git a/Scripts/Engines/ConPVP/Arena.cs b/Scripts/Engines/ConPVP/Arena.cs index d9e3e17a5..b4111fe33 100644 --- a/Scripts/Engines/ConPVP/Arena.cs +++ b/Scripts/Engines/ConPVP/Arena.cs @@ -228,13 +228,11 @@ namespace Server.Engines.ConPVP get => m_Tournament; set { - if ( m_Tournament != null ) - m_Tournament.Tournament.Arenas.Remove( this ); + m_Tournament?.Tournament.Arenas.Remove( this ); m_Tournament = value; - if ( m_Tournament != null ) - m_Tournament.Tournament.Arenas.Add( this ); + m_Tournament?.Tournament.Arenas.Add( this ); } } @@ -263,8 +261,7 @@ namespace Server.Engines.ConPVP if ( m_Teleporter != null ) m_Teleporter.Map = value; - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); if ( m_Zone.Start != Point2D.Zero && m_Zone.End != Point2D.Zero && m_Facet != null ) m_Region = new SafeZone( m_Zone, m_Outside, m_Facet, m_IsGuarded ); @@ -306,15 +303,13 @@ namespace Server.Engines.ConPVP if ( m_Zone.Start != Point2D.Zero && m_Zone.End != Point2D.Zero && m_Facet != null ) { - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); m_Region = new SafeZone( m_Zone, m_Outside, m_Facet, m_IsGuarded ); } else { - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); m_Region = null; } @@ -380,10 +375,9 @@ namespace Server.Engines.ConPVP { Active = false; - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); - m_Region = null; + m_Region = null; } public override string ToString() @@ -589,8 +583,7 @@ namespace Server.Engines.ConPVP private void AttachToTournament_Sandbox() { - if ( m_Tournament != null ) - m_Tournament.Tournament.Arenas.Add( this ); + m_Tournament?.Tournament.Arenas.Add( this ); } [CommandProperty( AccessLevel.Administrator, AccessLevel.Administrator )] diff --git a/Scripts/Engines/ConPVP/DuelContext.cs b/Scripts/Engines/ConPVP/DuelContext.cs index 5f01cf80d..f53d71643 100644 --- a/Scripts/Engines/ConPVP/DuelContext.cs +++ b/Scripts/Engines/ConPVP/DuelContext.cs @@ -641,8 +641,8 @@ namespace Server.Engines.ConPVP { loser.Broadcast( 0x22, null, loser.Players.Length == 1 ? "{0} has lost the duel." : "{0} and {1} team have lost the duel.", loser.Players.Length == 1 ? "You have lost the duel." : "Your team has lost the duel." ); - if ( m_Tournament != null && loser.TournyPart != null ) - loser.TournyPart.LostMatch( m_Match ); + if ( m_Tournament != null ) + loser.TournyPart?.LostMatch( m_Match ); } for ( int j = 0; j < loser.Players.Length; ++j ) @@ -671,8 +671,7 @@ namespace Server.Engines.ConPVP } } - if ( m_EventGame != null ) - m_EventGame.OnStop(); + m_EventGame?.OnStop(); Timer.DelayCall( TimeSpan.FromSeconds( 9.0 ), new TimerCallback( UnregisterRematch ) ); } @@ -739,8 +738,7 @@ namespace Server.Engines.ConPVP m_Registered = false; - if ( m_Arena != null ) - m_Arena.Evict(); + m_Arena?.Evict(); StopSDTimers(); @@ -868,8 +866,7 @@ namespace Server.Engines.ConPVP public void StopCountdown() { - if ( m_Countdown != null ) - m_Countdown.Stop(); + m_Countdown?.Stop(); m_Countdown = null; } @@ -883,8 +880,7 @@ namespace Server.Engines.ConPVP if ( count==0 ) { - if ( m_Countdown != null ) - m_Countdown.Stop(); + m_Countdown?.Stop(); m_Countdown=null; } @@ -909,26 +905,22 @@ namespace Server.Engines.ConPVP public void StopSDTimers() { - if ( m_SDWarnTimer != null ) - m_SDWarnTimer.Stop(); + m_SDWarnTimer?.Stop(); m_SDWarnTimer = null; - if ( m_SDActivateTimer != null ) - m_SDActivateTimer.Stop(); + m_SDActivateTimer?.Stop(); m_SDActivateTimer = null; } public void StartSuddenDeath( TimeSpan timeUntilActive ) { - if ( m_SDWarnTimer != null ) - m_SDWarnTimer.Stop(); + m_SDWarnTimer?.Stop(); m_SDWarnTimer = Timer.DelayCall( TimeSpan.FromMinutes( timeUntilActive.TotalMinutes * 0.9 ), new TimerCallback( WarnSuddenDeath ) ); - if ( m_SDActivateTimer != null ) - m_SDActivateTimer.Stop(); + m_SDActivateTimer?.Stop(); m_SDActivateTimer = Timer.DelayCall( timeUntilActive, new TimerCallback( ActivateSuddenDeath ) ); } @@ -952,11 +944,9 @@ namespace Server.Engines.ConPVP } } - if ( m_Tournament != null ) - m_Tournament.Alert( m_Arena, "Sudden death will be active soon!" ); + m_Tournament?.Alert( m_Arena, "Sudden death will be active soon!" ); - if ( m_SDWarnTimer != null ) - m_SDWarnTimer.Stop(); + m_SDWarnTimer?.Stop(); m_SDWarnTimer = null; } @@ -985,21 +975,18 @@ namespace Server.Engines.ConPVP } } - if ( m_Tournament != null ) - m_Tournament.Alert( m_Arena, "Sudden death has been activated!" ); + m_Tournament?.Alert( m_Arena, "Sudden death has been activated!" ); m_IsSuddenDeath = true; - if ( m_SDActivateTimer != null ) - m_SDActivateTimer.Stop(); + m_SDActivateTimer?.Stop(); m_SDActivateTimer = null; } public void BeginAutoTie() { - if ( m_AutoTieTimer != null ) - m_AutoTieTimer.Stop(); + m_AutoTieTimer?.Stop(); TimeSpan ts = ( m_Tournament == null || m_Tournament.TournyType == TournyType.Standard ) ? AutoTieDelay @@ -1010,8 +997,7 @@ namespace Server.Engines.ConPVP public void EndAutoTie() { - if ( m_AutoTieTimer != null ) - m_AutoTieTimer.Stop(); + m_AutoTieTimer?.Stop(); m_AutoTieTimer = null; } @@ -1066,8 +1052,7 @@ namespace Server.Engines.ConPVP } } - if ( m_Tournament != null ) - m_Tournament.HandleTie( m_Arena, m_Match, remaining ); + m_Tournament?.HandleTie( m_Arena, m_Match, remaining ); Timer.DelayCall( TimeSpan.FromSeconds( 10.0 ), new TimerCallback( Unregister ) ); } @@ -2297,10 +2282,7 @@ namespace Server.Engines.ConPVP { DuelPlayer pl = p.Players[j]; - if ( pl == null ) - continue; - - Mobile mob = pl.Mobile; + Mobile mob = pl?.Mobile; if ( mob != null ) { @@ -2390,8 +2372,7 @@ namespace Server.Engines.ConPVP { DuelPlayer dp = p.Players[j]; - if ( dp != null ) - dp.Mobile.SendMessage( "The duel could not be started because {0}.", error ); + dp?.Mobile.SendMessage( "The duel could not be started because {0}.", error ); } } @@ -2432,8 +2413,7 @@ namespace Server.Engines.ConPVP { DuelPlayer dp = p.Players[j]; - if ( dp != null ) - dp.Mobile.SendMessage( "The duel could not be started because there are no arenas. If you want to stop waiting for a free arena, yield the duel." ); + dp?.Mobile.SendMessage( "The duel could not be started because there are no arenas. If you want to stop waiting for a free arena, yield the duel." ); } } @@ -2491,8 +2471,7 @@ namespace Server.Engines.ConPVP arena.MoveInside( p.Players, i ); } - if ( m_EventGame != null ) - m_EventGame.OnStart(); + m_EventGame?.OnStart(); StartCountdown( 10, new CountdownCallback( SendBeginGump ) ); @@ -2508,8 +2487,7 @@ namespace Server.Engines.ConPVP { DuelPlayer dp = p.Players[j]; - if ( dp != null ) - dp.Mobile.SendMessage( "The duel could not be started because all arenas are full. If you want to stop waiting for a free arena, yield the duel." ); + dp?.Mobile.SendMessage( "The duel could not be started because all arenas are full. If you want to stop waiting for a free arena, yield the duel." ); } } @@ -2561,16 +2539,14 @@ namespace Server.Engines.ConPVP public static void CloseAndSendGump( NetState ns, Gump g, params Type[] types ) { - if ( ns != null ) { - Mobile mob = ns.Mobile; + Mobile mob = ns?.Mobile; - if ( mob != null ) { - foreach ( Type type in types ) { - mob.CloseGump( type ); - } - - mob.SendGump( g ); + if ( mob != null ) { + foreach ( Type type in types ) { + mob.CloseGump( type ); } + + mob.SendGump( g ); } /*if ( ns == null ) diff --git a/Scripts/Engines/ConPVP/Games/BombingRun.cs b/Scripts/Engines/ConPVP/Games/BombingRun.cs index 97dbe34f4..dec498436 100644 --- a/Scripts/Engines/ConPVP/Games/BombingRun.cs +++ b/Scripts/Engines/ConPVP/Games/BombingRun.cs @@ -149,8 +149,10 @@ namespace Server.Engines.ConPVP MoveToWorld( mob.Location, mob.Map ); else if ( killer != null && !killer.Deleted ) MoveToWorld( killer.Location, killer.Map ); - else if ( m_Game != null ) - m_Game.ReturnBomb(); + else + { + m_Game?.ReturnBomb(); + } } public override bool OnMoveOver( Mobile m ) @@ -1564,8 +1566,7 @@ namespace Server.Engines.ConPVP public void Alert( string text ) { - if ( m_Context.m_Tournament != null ) - m_Context.m_Tournament.Alert( text ); + m_Context.m_Tournament?.Alert( text ); for ( int i = 0; i < m_Context.Participants.Count; ++i ) { @@ -1734,8 +1735,7 @@ namespace Server.Engines.ConPVP for ( int i = 0; i < m_Context.Participants.Count; ++i ) ApplyHues( m_Context.Participants[i] as Participant, m_Controller.TeamInfo[i % m_Controller.TeamInfo.Length].Color ); - if ( m_FinishTimer != null ) - m_FinishTimer.Stop(); + m_FinishTimer?.Stop(); m_Bomb = new BRBomb( this ); ReturnBomb(); diff --git a/Scripts/Engines/ConPVP/Games/CTF.cs b/Scripts/Engines/ConPVP/Games/CTF.cs index a144a041e..35565356b 100644 --- a/Scripts/Engines/ConPVP/Games/CTF.cs +++ b/Scripts/Engines/ConPVP/Games/CTF.cs @@ -334,8 +334,7 @@ namespace Server.Engines.ConPVP private void StopCountdown() { - if ( m_ReturnTimer != null ) - m_ReturnTimer.Stop(); + m_ReturnTimer?.Stop(); m_ReturnTimer = null; } @@ -364,8 +363,7 @@ namespace Server.Engines.ConPVP case 2: case 1: { - if ( owner != null ) - owner.SendMessage( 0x26, "You have {0} {1} to capture the cookies!", m_ReturnCount, m_ReturnCount == 1 ? "second" : "seconds" ); + owner?.SendMessage( 0x26, "You have {0} {1} to capture the cookies!", m_ReturnCount, m_ReturnCount == 1 ? "second" : "seconds" ); break; } @@ -380,8 +378,7 @@ namespace Server.Engines.ConPVP SendHome(); - if ( m_TeamInfo?.Game != null ) - m_TeamInfo.Game.Alert( "The {0} cookies have been returned.", m_TeamInfo.Name ); + m_TeamInfo?.Game?.Alert( "The {0} cookies have been returned.", m_TeamInfo.Name ); return; } @@ -908,8 +905,7 @@ namespace Server.Engines.ConPVP public void Alert( string text ) { - if ( m_Context.m_Tournament != null ) - m_Context.m_Tournament.Alert( text ); + m_Context.m_Tournament?.Alert( text ); for ( int i = 0; i < m_Context.Participants.Count; ++i ) { @@ -1112,8 +1108,7 @@ namespace Server.Engines.ConPVP for ( int i = 0; i < m_Context.Participants.Count; ++i ) ApplyHues( m_Context.Participants[i] as Participant, m_Controller.TeamInfo[i % 8].Color ); - if ( m_FinishTimer != null ) - m_FinishTimer.Stop(); + m_FinishTimer?.Stop(); m_FinishTimer = Timer.DelayCall( m_Controller.Duration, new TimerCallback( Finish_Callback ) ); } @@ -1304,8 +1299,7 @@ namespace Server.Engines.ConPVP for ( int i = 0; i < m_Context.Participants.Count; ++i ) ApplyHues( m_Context.Participants[i] as Participant, -1 ); - if ( m_FinishTimer != null ) - m_FinishTimer.Stop(); + m_FinishTimer?.Stop(); m_FinishTimer = null; } diff --git a/Scripts/Engines/ConPVP/Games/DoubleDom.cs b/Scripts/Engines/ConPVP/Games/DoubleDom.cs index 8046a359d..d11174b3d 100644 --- a/Scripts/Engines/ConPVP/Games/DoubleDom.cs +++ b/Scripts/Engines/ConPVP/Games/DoubleDom.cs @@ -542,8 +542,7 @@ namespace Server.Engines.ConPVP public void Alert( string text ) { - if ( m_Context.m_Tournament != null ) - m_Context.m_Tournament.Alert( text ); + m_Context.m_Tournament?.Alert( text ); for ( int i = 0; i < m_Context.Participants.Count; ++i ) { diff --git a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs index a74efcb89..bad0a917a 100644 --- a/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs +++ b/Scripts/Engines/ConPVP/Games/KingOfTheHill.cs @@ -67,9 +67,8 @@ namespace Server.Engines.ConPVP { if (m_Game != value) { - if (m_KingTimer != null) - m_KingTimer.Stop(); - m_Game = value; + m_KingTimer?.Stop(); + m_Game = value; m_King = null; } } @@ -171,10 +170,9 @@ namespace Server.Engines.ConPVP { PublicOverheadMessage(MessageType.Regular, 0x0481, false, "Free!"); - if (m_KingTimer != null) - m_KingTimer.Stop(); + m_KingTimer?.Stop(); - m_King = null; + m_King = null; } private void ReKingify(Mobile m) @@ -308,11 +306,9 @@ namespace Server.Engines.ConPVP { if (m_Controller != value) { - if (m_Controller != null) - m_Controller.RemoveBoard(this); - m_Controller = value; - if (m_Controller != null) - m_Controller.AddBoard(this); + m_Controller?.RemoveBoard(this); + m_Controller = value; + m_Controller?.AddBoard(this); } } } @@ -930,10 +926,9 @@ namespace Server.Engines.ConPVP public void Alert(string text) { - if (m_Context.m_Tournament != null) - m_Context.m_Tournament.Alert(text); + m_Context.m_Tournament?.Alert(text); - for (int i = 0; i < m_Context.Participants.Count; ++i) + for (int i = 0; i < m_Context.Participants.Count; ++i) { Participant p = m_Context.Participants[i] as Participant; @@ -1097,10 +1092,9 @@ namespace Server.Engines.ConPVP for (int i = 0; i < m_Context.Participants.Count; ++i) ApplyHues(m_Context.Participants[i] as Participant, m_Controller.TeamInfo[i % m_Controller.TeamInfo.Length].Color); - if (m_FinishTimer != null) - m_FinishTimer.Stop(); + m_FinishTimer?.Stop(); - for (int i = 0; i < m_Controller.Hills.Length; i++) + for (int i = 0; i < m_Controller.Hills.Length; i++) { if (m_Controller.Hills[i] != null) m_Controller.Hills[i].Game = this; diff --git a/Scripts/Engines/ConPVP/Tournament.cs b/Scripts/Engines/ConPVP/Tournament.cs index 05df0edc9..f06c3bf43 100644 --- a/Scripts/Engines/ConPVP/Tournament.cs +++ b/Scripts/Engines/ConPVP/Tournament.cs @@ -75,13 +75,10 @@ namespace Server.Engines.ConPVP { Ladder ladder = Ladder.Instance; - if ( ladder != null ) - { - LadderEntry entry = ladder.Find( m ); + LadderEntry entry = ladder?.Find( m ); - if ( entry != null && Ladder.GetLevel( entry.Experience ) < tourny.LevelRequirement ) - return; - } + if ( entry != null && Ladder.GetLevel( entry.Experience ) < tourny.LevelRequirement ) + return; if ( tourny.IsFactionRestricted && Faction.Find( m ) == null ) { @@ -603,9 +600,8 @@ namespace Server.Engines.ConPVP } case TournamentStage.Inactive: { - if ( m_Registrar != null ) - m_Registrar.PrivateOverheadMessage( MessageType.Regular, - 0x35, false, "The tournament is closed.", from.NetState ); + m_Registrar?.PrivateOverheadMessage( MessageType.Regular, + 0x35, false, "The tournament is closed.", @from.NetState ); break; } @@ -613,11 +609,8 @@ namespace Server.Engines.ConPVP { if ( m_Players.Count != tourny.PlayersPerParticipant ) { - if ( m_Registrar != null ) - { - m_Registrar.PrivateOverheadMessage( MessageType.Regular, - 0x35, false, "You have not yet chosen your team.", from.NetState ); - } + m_Registrar?.PrivateOverheadMessage( MessageType.Regular, + 0x35, false, "You have not yet chosen your team.", @from.NetState ); m_From.SendGump( new ConfirmSignupGump( m_From, m_Registrar, m_Tournament, m_Players ) ); break; @@ -2253,8 +2246,7 @@ namespace Server.Engines.ConPVP { object[] states = (object[])state; - if ( states[0] != null ) - ((Mobile)states[0]).PublicOverheadMessage( MessageType.Regular, 0x35, false, (string)states[1] ); + ((Mobile) states[0])?.PublicOverheadMessage( MessageType.Regular, 0x35, false, (string)states[1] ); } } diff --git a/Scripts/Engines/Craft/Core/CraftItem.cs b/Scripts/Engines/Craft/Core/CraftItem.cs index bd8d16858..a05e8e32a 100644 --- a/Scripts/Engines/Craft/Core/CraftItem.cs +++ b/Scripts/Engines/Craft/Core/CraftItem.cs @@ -780,8 +780,9 @@ namespace Server.Engines.Craft if ( index == -1 ) { if ( consumeType != ConsumeType.None ) - if ( consumeExtra != null ) - consumeExtra.Delete(); + { + consumeExtra?.Delete(); + } return true; } @@ -948,8 +949,7 @@ namespace Server.Engines.Craft { CraftContext context = craftSystem.GetContext( from ); - if ( context != null ) - context.OnMade( this ); + context?.OnMade( this ); int iMin = craftSystem.MinCraftEffect; int iMax = (craftSystem.MaxCraftEffect - iMin) + 1; @@ -1286,8 +1286,7 @@ namespace Server.Engines.Craft try{ cc = Activator.CreateInstance( m_CraftItem.ItemType, new object[] { m_From, m_CraftItem, m_CraftSystem, m_TypeRes, m_Tool, quality } ) as CustomCraft; } catch{} - if ( cc != null ) - cc.EndCraftAction(); + cc?.EndCraftAction(); return; } diff --git a/Scripts/Engines/Craft/Core/CraftSystem.cs b/Scripts/Engines/Craft/Core/CraftSystem.cs index e86b229c4..6984677b1 100644 --- a/Scripts/Engines/Craft/Core/CraftSystem.cs +++ b/Scripts/Engines/Craft/Core/CraftSystem.cs @@ -77,8 +77,7 @@ namespace Server.Engines.Craft { CraftContext c = GetContext( m ); - if ( c != null ) - c.OnMade( item ); + c?.OnMade( item ); } public bool Resmelt diff --git a/Scripts/Engines/Doom/GauntletSpawner.cs b/Scripts/Engines/Doom/GauntletSpawner.cs index 1f9316e7b..118204aba 100644 --- a/Scripts/Engines/Doom/GauntletSpawner.cs +++ b/Scripts/Engines/Doom/GauntletSpawner.cs @@ -151,8 +151,7 @@ namespace Server.Engines.Doom ClearTraps(); DestroyRegion(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } @@ -194,8 +193,7 @@ namespace Server.Engines.Doom public virtual void DestroyRegion() { - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); m_Region = null; } diff --git a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs index f2c6b83c5..ca3bc692a 100644 --- a/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs +++ b/Scripts/Engines/Doom/LeverPuzzle/LeverPuzzleController.cs @@ -146,10 +146,7 @@ namespace Server.Engines.Doom NukeItemList( m_Statues ); NukeItemList( m_Levers ); - if ( m_LampRoom != null ) - { - m_LampRoom.Unregister(); - } + m_LampRoom?.Unregister(); if ( m_Tiles != null ) { foreach( Region region in m_Tiles ) @@ -181,12 +178,9 @@ namespace Server.Engines.Doom { LeverPuzzleRegion region = (LeverPuzzleRegion)m_Tiles[index]; - if ( region != null ) + if ( region?.Occupant != null && region.Occupant.Alive ) { - if ( region.Occupant != null && region.Occupant.Alive ) - { - return (PlayerMobile)region.Occupant; - } + return (PlayerMobile)region.Occupant; } return null; } diff --git a/Scripts/Engines/Factions/Core/Election.cs b/Scripts/Engines/Factions/Core/Election.cs index 35292e7d6..ee784d782 100644 --- a/Scripts/Engines/Factions/Core/Election.cs +++ b/Scripts/Engines/Factions/Core/Election.cs @@ -267,8 +267,7 @@ namespace Server.Factions { if ( m_Faction.Election != this ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; diff --git a/Scripts/Engines/Factions/Core/FactionState.cs b/Scripts/Engines/Factions/Core/FactionState.cs index afdb81e99..8c66bf57a 100644 --- a/Scripts/Engines/Factions/Core/FactionState.cs +++ b/Scripts/Engines/Factions/Core/FactionState.cs @@ -105,8 +105,7 @@ namespace Server.Factions get => m_Commander; set { - if ( m_Commander != null ) - m_Commander.InvalidateProperties(); + m_Commander?.InvalidateProperties(); m_Commander = value; diff --git a/Scripts/Engines/Factions/Core/Keywords.cs b/Scripts/Engines/Factions/Core/Keywords.cs index c0836ba6e..66d10fb59 100644 --- a/Scripts/Engines/Factions/Core/Keywords.cs +++ b/Scripts/Engines/Factions/Core/Keywords.cs @@ -15,8 +15,7 @@ namespace Server.Factions { PlayerState pl = (PlayerState)state; - if ( pl != null ) - pl.Mobile.PublicOverheadMessage( MessageType.Regular, pl.Mobile.SpeechHue, true, pl.KillPoints.ToString( "N0" ) ); // NOTE: Added 'N0' + pl?.Mobile.PublicOverheadMessage( MessageType.Regular, pl.Mobile.SpeechHue, true, pl.KillPoints.ToString( "N0" ) ); // NOTE: Added 'N0' } private static void EventSink_Speech( SpeechEventArgs e ) @@ -144,8 +143,7 @@ namespace Server.Factions { Faction faction = Faction.Find( from ); - if ( faction != null ) - faction.BeginHonorLeadership( from ); + faction?.BeginHonorLeadership( @from ); break; } diff --git a/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs b/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs index 8b0d5275e..2a54e440f 100644 --- a/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs +++ b/Scripts/Engines/Factions/Items/Traps/BaseFactionTrap.cs @@ -172,13 +172,9 @@ namespace Server.Factions public void PrivateOverheadLocalizedMessage( Mobile to, int number, int hue, string name, string args ) { - if ( to == null ) - return; + NetState ns = to?.NetState; - NetState ns = to.NetState; - - if ( ns != null ) - ns.Send( new MessageLocalized( Serial, ItemID, MessageType.Regular, hue, 3, number, name, args ) ); + ns?.Send( new MessageLocalized( Serial, ItemID, MessageType.Regular, hue, 3, number, name, args ) ); } public BaseFactionTrap( Faction f, Mobile m, int itemID ) : base( itemID ) @@ -212,16 +208,14 @@ namespace Server.Factions public virtual void BeginConceal() { - if ( m_Concealing != null ) - m_Concealing.Stop(); + m_Concealing?.Stop(); m_Concealing = Timer.DelayCall( ConcealPeriod, new TimerCallback( Conceal ) ); } public virtual void Conceal() { - if ( m_Concealing != null ) - m_Concealing.Stop(); + m_Concealing?.Stop(); m_Concealing = null; diff --git a/Scripts/Engines/Factions/Items/Traps/FactionTrapRemovalKit.cs b/Scripts/Engines/Factions/Items/Traps/FactionTrapRemovalKit.cs index 8f9257a98..d2d48f0f5 100644 --- a/Scripts/Engines/Factions/Items/Traps/FactionTrapRemovalKit.cs +++ b/Scripts/Engines/Factions/Items/Traps/FactionTrapRemovalKit.cs @@ -28,8 +28,7 @@ namespace Server.Factions { Delete(); - if ( consumer != null ) - consumer.SendLocalizedMessage( 1042531 ); // You have used all of the parts in your trap removal kit. + consumer?.SendLocalizedMessage( 1042531 ); // You have used all of the parts in your trap removal kit. } } diff --git a/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs b/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs index 8ac931afc..ae651913a 100644 --- a/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs +++ b/Scripts/Engines/Factions/Mobiles/Guards/BaseFactionGuard.cs @@ -39,8 +39,7 @@ namespace Server.Factions public void Unregister() { - if ( m_Town != null ) - m_Town.UnregisterGuard( this ); + m_Town?.UnregisterGuard( this ); } public abstract GuardAI GuardAI{ get; } diff --git a/Scripts/Engines/Factions/Mobiles/Vendors/BaseFactionVendor.cs b/Scripts/Engines/Factions/Mobiles/Vendors/BaseFactionVendor.cs index 92d6dbfdb..210631065 100644 --- a/Scripts/Engines/Factions/Mobiles/Vendors/BaseFactionVendor.cs +++ b/Scripts/Engines/Factions/Mobiles/Vendors/BaseFactionVendor.cs @@ -38,8 +38,7 @@ namespace Server.Factions public void Unregister() { - if ( m_Town != null ) - m_Town.UnregisterVendor( this ); + m_Town?.UnregisterVendor( this ); } private List m_SBInfos = new List(); diff --git a/Scripts/Engines/Khaldun/Mobiles/LysanderGathenwale.cs b/Scripts/Engines/Khaldun/Mobiles/LysanderGathenwale.cs index d8506a5e4..b328642d2 100644 --- a/Scripts/Engines/Khaldun/Mobiles/LysanderGathenwale.cs +++ b/Scripts/Engines/Khaldun/Mobiles/LysanderGathenwale.cs @@ -95,8 +95,7 @@ namespace Server.Mobiles if ( !base.OnBeforeDeath() ) return false; - if ( Backpack != null ) - Backpack.Destroy(); + Backpack?.Destroy(); if ( Utility.Random( 3 ) == 0 ) { diff --git a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs index f8861d235..6c01fdbc7 100644 --- a/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs +++ b/Scripts/Engines/MLQuests/Gumps/RaceChangeGump.cs @@ -54,8 +54,7 @@ namespace Server.Engines.MLQuests.Gumps { case 0: // Cancel { - if ( m_Owner != null ) - m_Owner.OnCancel( m_From ); + m_Owner?.OnCancel( m_From ); break; } diff --git a/Scripts/Engines/MLQuests/MLQuestEntry.cs b/Scripts/Engines/MLQuests/MLQuestEntry.cs index 93030b380..71cc6bd1f 100644 --- a/Scripts/Engines/MLQuests/MLQuestEntry.cs +++ b/Scripts/Engines/MLQuests/MLQuestEntry.cs @@ -63,8 +63,7 @@ namespace Server.Engines.MLQuests private void Register() { - if ( m_Quest?.Instances != null ) - m_Quest.Instances.Add( this ); + m_Quest?.Instances?.Add( this ); if ( m_Player != null ) PlayerContext.QuestInstances.Add( this ); @@ -72,8 +71,7 @@ namespace Server.Engines.MLQuests private void Unregister() { - if ( m_Quest?.Instances != null ) - m_Quest.Instances.Remove( this ); + m_Quest?.Instances?.Remove( this ); if ( m_Player != null ) PlayerContext.QuestInstances.Remove( this ); @@ -255,8 +253,7 @@ namespace Server.Engines.MLQuests { MLQuest nextQuest = MLQuestSystem.FindQuest( nextQuestType ); - if ( nextQuest != null ) - nextQuest.SendOffer( m_Quester, m_Player ); + nextQuest?.SendOffer( m_Quester, m_Player ); } } else @@ -514,8 +511,7 @@ namespace Server.Engines.MLQuests for ( int i = 0; i < objectives; ++i ) BaseObjectiveInstance.Deserialize( reader, version, ( instance != null && i < instance.Objectives.Length ) ? instance.Objectives[i] : null ); - if ( instance != null ) - instance.Slice(); + instance?.Slice(); return instance; } diff --git a/Scripts/Engines/MLQuests/MLQuestSystem.cs b/Scripts/Engines/MLQuests/MLQuestSystem.cs index de1f423e1..366ff954e 100644 --- a/Scripts/Engines/MLQuests/MLQuestSystem.cs +++ b/Scripts/Engines/MLQuests/MLQuestSystem.cs @@ -578,8 +578,7 @@ namespace Server.Engines.MLQuests { MLQuestContext context = GetContext( pm ); - if ( context != null ) - context.HandleDeath(); + context?.HandleDeath(); } public static void HandleDeletion( PlayerMobile pm ) diff --git a/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs b/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs index 650fba371..748909fe6 100644 --- a/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs +++ b/Scripts/Engines/MyRunUO/DatabaseCommandQueue.cs @@ -136,16 +136,28 @@ namespace Server.Engines.MyRunUO } catch ( Exception e ) { - try{ if ( transact != null ) transact.Rollback(); } + try + { + transact?.Rollback(); + } catch{} - try{ if ( connection != null ) connection.Close(); } + try + { + connection?.Close(); + } catch{} - try{ if ( connection != null ) connection.Dispose(); } + try + { + connection?.Dispose(); + } catch{} - try{ if ( command != null ) command.Dispose(); } + try + { + command?.Dispose(); + } catch{} try{ m_Sync.Close(); } diff --git a/Scripts/Engines/MyRunUO/MyRunUOStatus.cs b/Scripts/Engines/MyRunUO/MyRunUOStatus.cs index e365a5bb0..3386d7077 100644 --- a/Scripts/Engines/MyRunUO/MyRunUOStatus.cs +++ b/Scripts/Engines/MyRunUO/MyRunUOStatus.cs @@ -66,8 +66,7 @@ namespace Server.Engines.MyRunUO Console.WriteLine( e ); } - if ( m_Command != null ) - m_Command.Enqueue( null ); + m_Command?.Enqueue( null ); } } } \ No newline at end of file diff --git a/Scripts/Engines/Party/DeclineTimer.cs b/Scripts/Engines/Party/DeclineTimer.cs index f4cb4a8d6..858e0f683 100644 --- a/Scripts/Engines/Party/DeclineTimer.cs +++ b/Scripts/Engines/Party/DeclineTimer.cs @@ -13,8 +13,7 @@ namespace Server.Engines.PartySystem { DeclineTimer t = (DeclineTimer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table[m] = t = new DeclineTimer( m, leader ); t.Start(); diff --git a/Scripts/Engines/Party/Party.cs b/Scripts/Engines/Party/Party.cs index 553706da5..117f61a1a 100644 --- a/Scripts/Engines/Party/Party.cs +++ b/Scripts/Engines/Party/Party.cs @@ -129,18 +129,14 @@ namespace Server.Engines.PartySystem Mobile from = e.Mobile; Party p = Get( from ); - if ( p != null ) - p.Remove( from ); + p?.Remove( @from ); from.Party = null; } public static Party Get( Mobile m ) { - if ( m == null ) - return null; - - return m.Party as Party; + return m?.Party as Party; } public Party( Mobile leader ) diff --git a/Scripts/Engines/Pathing/FastMovement.cs b/Scripts/Engines/Pathing/FastMovement.cs index 15f5d7aaf..f8d2ab176 100644 --- a/Scripts/Engines/Pathing/FastMovement.cs +++ b/Scripts/Engines/Pathing/FastMovement.cs @@ -702,10 +702,7 @@ namespace Server.Movement public static void ClearMoveCache(ref List cache, bool free) { - if (cache != null) - { - cache.Clear(); - } + cache?.Clear(); if (!free) { diff --git a/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs b/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs index b512d0cda..dd662decd 100644 --- a/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs +++ b/Scripts/Engines/Quests/Collector/Mobiles/TomasONeerlan.cs @@ -83,8 +83,7 @@ namespace Server.Engines.Quests.Collector if ( obj != null && !obj.Completed ) { - if ( player.Backpack != null ) - player.Backpack.ConsumeUpTo( typeof( EnchantedPaints ), 1 ); + player.Backpack?.ConsumeUpTo( typeof( EnchantedPaints ), 1 ); obj.Complete(); } diff --git a/Scripts/Engines/Quests/Core/QuestCallbackEntry.cs b/Scripts/Engines/Quests/Core/QuestCallbackEntry.cs index 261f18f14..f922db41b 100644 --- a/Scripts/Engines/Quests/Core/QuestCallbackEntry.cs +++ b/Scripts/Engines/Quests/Core/QuestCallbackEntry.cs @@ -17,8 +17,7 @@ namespace Server.Engines.Quests public override void OnClick() { - if ( m_Callback != null ) - m_Callback(); + m_Callback?.Invoke(); } } } \ No newline at end of file diff --git a/Scripts/Engines/Quests/Core/QuestSerializer.cs b/Scripts/Engines/Quests/Core/QuestSerializer.cs index bd3c69fa4..38bd094f0 100644 --- a/Scripts/Engines/Quests/Core/QuestSerializer.cs +++ b/Scripts/Engines/Quests/Core/QuestSerializer.cs @@ -88,8 +88,7 @@ namespace Server.Engines.Quests QuestSystem qs = Construct( type ) as QuestSystem; - if ( qs != null ) - qs.BaseDeserialize( reader ); + qs?.BaseDeserialize( reader ); return qs; } @@ -129,8 +128,7 @@ namespace Server.Engines.Quests QuestObjective obj = Construct( type ) as QuestObjective; - if ( obj != null ) - obj.BaseDeserialize( reader ); + obj?.BaseDeserialize( reader ); return obj; } @@ -170,8 +168,7 @@ namespace Server.Engines.Quests QuestConversation conv = Construct( type ) as QuestConversation; - if ( conv != null ) - conv.BaseDeserialize( reader ); + conv?.BaseDeserialize( reader ); return conv; } diff --git a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs index 38618c1da..c37e5b5df 100644 --- a/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs +++ b/Scripts/Engines/Quests/Haochi's Trials/Mobiles/Haochi.cs @@ -114,20 +114,17 @@ namespace Server.Engines.Quests.Samurai if ( obj != null && !obj.Completed ) { Container pack = player.Backpack; - if ( pack != null ) + Item katana = pack?.FindItemByType( typeof( HaochisKatana ) ); + if ( katana != null ) { - Item katana = pack.FindItemByType( typeof( HaochisKatana ) ); - if ( katana != null ) - { - katana.Delete(); - obj.Complete(); + katana.Delete(); + obj.Complete(); - obj = qs.FindObjective( typeof( FifthTrialIntroObjective ) ); - if ( obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure ) - qs.AddConversation( new SixthTrialIntroConversation( true ) ); - else - qs.AddConversation( new SixthTrialIntroConversation( false ) ); - } + obj = qs.FindObjective( typeof( FifthTrialIntroObjective ) ); + if ( obj != null && ((FifthTrialIntroObjective)obj).StolenTreasure ) + qs.AddConversation( new SixthTrialIntroConversation( true ) ); + else + qs.AddConversation( new SixthTrialIntroConversation( false ) ); } return; diff --git a/Scripts/Engines/Quests/Study of the Solen Hive/StudyOfSolenQuest.cs b/Scripts/Engines/Quests/Study of the Solen Hive/StudyOfSolenQuest.cs index 198cb4f46..efcffdd81 100644 --- a/Scripts/Engines/Quests/Study of the Solen Hive/StudyOfSolenQuest.cs +++ b/Scripts/Engines/Quests/Study of the Solen Hive/StudyOfSolenQuest.cs @@ -59,8 +59,7 @@ namespace Server.Engines.Quests.Naturalist { base.Accept(); - if ( m_Naturalist != null ) - m_Naturalist.PlaySound( 0x431 ); + m_Naturalist?.PlaySound( 0x431 ); AddConversation( new AcceptConversation() ); } diff --git a/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs b/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs index 531bb2ac2..ae29f82d7 100644 --- a/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs +++ b/Scripts/Engines/Quests/The Summoning/Items/BellOfTheDead.cs @@ -127,8 +127,7 @@ namespace Server.Engines.Quests.Doom m_Chyloth = reader.ReadMobile() as Chyloth; m_Dragon = reader.ReadMobile() as SkeletalDragon; - if ( m_Chyloth != null ) - m_Chyloth.Delete(); + m_Chyloth?.Delete(); } } } diff --git a/Scripts/Engines/Quests/The Summoning/Objectives.cs b/Scripts/Engines/Quests/The Summoning/Objectives.cs index a63f72110..ab91c3da9 100644 --- a/Scripts/Engines/Quests/The Summoning/Objectives.cs +++ b/Scripts/Engines/Quests/The Summoning/Objectives.cs @@ -102,13 +102,9 @@ namespace Server.Engines.Quests.Doom { Victoria victoria = ((TheSummoningQuest)System).Victoria; - if ( victoria != null ) - { - SummoningAltar altar = victoria.Altar; + SummoningAltar altar = victoria?.Altar; - if ( altar != null ) - altar.CheckDaemon(); - } + altar?.CheckDaemon(); PlayerMobile from = System.From; diff --git a/Scripts/Engines/RemoteAdmin/Network.cs b/Scripts/Engines/RemoteAdmin/Network.cs index d08e8b6e0..49e2b4fab 100644 --- a/Scripts/Engines/RemoteAdmin/Network.cs +++ b/Scripts/Engines/RemoteAdmin/Network.cs @@ -263,20 +263,17 @@ namespace Server.RemoteAdmin public override void Write( char ch ) { - if ( m_OnChar != null ) - m_OnChar( ch ); + m_OnChar?.Invoke( ch ); } public override void Write( string str ) { - if ( m_OnStr != null ) - m_OnStr( str ); + m_OnStr?.Invoke( str ); } public override void WriteLine( string line ) { - if ( m_OnLine != null ) - m_OnLine( line ); + m_OnLine?.Invoke( line ); } public override Encoding Encoding => Encoding.ASCII; diff --git a/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs b/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs index 8fba785f9..5c00d9013 100644 --- a/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs +++ b/Scripts/Engines/Reports/Objects/Staffing/PageInfo.cs @@ -40,13 +40,11 @@ namespace Server.Engines.Reports lock ( StaffHistory.RenderLock ) { - if ( m_Resolver != null ) - m_Resolver.Unregister( this ); + m_Resolver?.Unregister( this ); m_Resolver = value; - if ( m_Resolver != null ) - m_Resolver.Register( this ); + m_Resolver?.Register( this ); } } } @@ -61,13 +59,11 @@ namespace Server.Engines.Reports lock ( StaffHistory.RenderLock ) { - if ( m_Sender != null ) - m_Sender.Unregister( this ); + m_Sender?.Unregister( this ); m_Sender = value; - if ( m_Sender != null ) - m_Sender.Register( this ); + m_Sender?.Register( this ); } } } diff --git a/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs b/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs index d7c4a3e2d..48d60afcd 100644 --- a/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs +++ b/Scripts/Engines/Reports/Rendering/BarGraphRenderer.cs @@ -460,9 +460,9 @@ namespace Server.Engines.Reports } finally { - if (brsFont != null) brsFont.Dispose(); - if (valFont != null) valFont.Dispose(); - if (sfFormat != null) sfFormat.Dispose(); + brsFont?.Dispose(); + valFont?.Dispose(); + sfFormat?.Dispose(); } } @@ -536,11 +536,11 @@ namespace Server.Engines.Reports } finally { - if (lblFont != null) lblFont.Dispose(); - if (brs != null) brs.Dispose(); - if (lblFormat != null) lblFormat.Dispose(); - if (pen != null) pen.Dispose(); - if (sfVLabel != null) sfVLabel.Dispose(); + lblFont?.Dispose(); + brs?.Dispose(); + lblFormat?.Dispose(); + pen?.Dispose(); + sfVLabel?.Dispose(); } } @@ -571,10 +571,10 @@ namespace Server.Engines.Reports } finally { - if (lblFont != null) lblFont.Dispose(); - if (brs != null) brs.Dispose(); - if (lblFormat != null) lblFormat.Dispose(); - if (pen != null) pen.Dispose(); + lblFont?.Dispose(); + brs?.Dispose(); + lblFormat?.Dispose(); + pen?.Dispose(); } } @@ -642,10 +642,10 @@ namespace Server.Engines.Reports } finally { - if (lblFont != null) lblFont.Dispose(); - if (brs != null) brs.Dispose(); - if (lblFormat != null) lblFormat.Dispose(); - if (pen != null) pen.Dispose(); + lblFont?.Dispose(); + brs?.Dispose(); + lblFormat?.Dispose(); + pen?.Dispose(); } } @@ -698,10 +698,10 @@ namespace Server.Engines.Reports } finally { - if (lblFont != null) lblFont.Dispose(); - if (brs != null) brs.Dispose(); - if (lblFormat != null) lblFormat.Dispose(); - if (pen != null) pen.Dispose(); + lblFont?.Dispose(); + brs?.Dispose(); + lblFormat?.Dispose(); + pen?.Dispose(); } } @@ -805,9 +805,9 @@ namespace Server.Engines.Reports } finally { - if (graph != null) graph.Dispose(); - if (bmp != null) bmp.Dispose(); - if (font != null) font.Dispose(); + graph?.Dispose(); + bmp?.Dispose(); + font?.Dispose(); } } diff --git a/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs b/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs index 1b20dafa6..0401bfa7f 100644 --- a/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs +++ b/Scripts/Engines/Reports/Rendering/PieChartRenderer.cs @@ -183,8 +183,7 @@ namespace Server.Engines.Reports } finally { - if (brs !=null) - brs.Dispose(); + brs?.Dispose(); } } @@ -198,8 +197,7 @@ namespace Server.Engines.Reports } finally { - if (brs !=null) - brs.Dispose(); + brs?.Dispose(); } } @@ -224,11 +222,11 @@ namespace Server.Engines.Reports } finally { - if (sf != null) sf.Dispose(); - if (grp != null) grp.Dispose(); - if (sfp != null) sfp.Dispose(); - if (fnt != null) fnt.Dispose(); - if (pen != null) pen.Dispose(); + sf?.Dispose(); + grp?.Dispose(); + sfp?.Dispose(); + fnt?.Dispose(); + pen?.Dispose(); } return bmp; } diff --git a/Scripts/Engines/Spawner/Spawner.cs b/Scripts/Engines/Spawner/Spawner.cs index 90aa95a73..53feb73ed 100644 --- a/Scripts/Engines/Spawner/Spawner.cs +++ b/Scripts/Engines/Spawner/Spawner.cs @@ -250,8 +250,7 @@ namespace Server.Mobiles { if ( m_Running ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Running = false; } } @@ -714,8 +713,7 @@ namespace Server.Mobiles { ISpawnable e = entry.Spawned[i]; entry.Spawned.RemoveAt( i ); - if ( e != null ) - e.Delete(); + e?.Delete(); } m_Entries.Remove( entry ); @@ -734,8 +732,7 @@ namespace Server.Mobiles { m_Spawned.TryGetValue( spawn, out SpawnerEntry entry ); - if ( entry != null ) - entry.Spawned.Remove( spawn ); + entry?.Spawned.Remove( spawn ); m_Spawned.Remove( spawn ); } @@ -798,8 +795,9 @@ namespace Server.Mobiles Defrag(); foreach( ISpawnable e in m_Spawned.Keys ) - if ( e != null ) - e.MoveToWorld( Location, Map ); + { + e?.MoveToWorld( Location, Map ); + } } public override void OnDelete() diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs index f6ab16fc2..9f5def128 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/CharacterStatue.cs @@ -257,8 +257,7 @@ namespace Server.Mobiles deed.StatueType = m_Type; deed.IsRewardItem = m_IsRewardItem; - if ( m_Plinth != null ) - m_Plinth.Delete(); + m_Plinth?.Delete(); return true; } @@ -332,8 +331,7 @@ namespace Server.Mobiles for ( int i = Items.Count - 1; i >= 0; i -- ) Items[ i ].Hue = Hue; - if ( m_Plinth != null ) - m_Plinth.InvalidateHue(); + m_Plinth?.InvalidateHue(); } private int m_Animation; @@ -526,8 +524,7 @@ namespace Server.Mobiles { base.OnDelete(); - if ( m_Statue != null ) - m_Statue.Delete(); + m_Statue?.Delete(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs b/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs index f928fd57a..32eed5cde 100644 --- a/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs +++ b/Scripts/Engines/VeteranRewards/Character Statue Maker/Gumps/CharacterStatueGump.cs @@ -134,12 +134,10 @@ namespace Server.Gumps { CharacterStatue backup = deed.Statue; - if ( backup != null ) - backup.Delete(); + backup?.Delete(); } - if ( m_Maker != null ) - m_Maker.Delete(); + m_Maker?.Delete(); m_Statue.Sculpt( state.Mobile ); } diff --git a/Scripts/Engines/VeteranRewards/RewardOptionGump.cs b/Scripts/Engines/VeteranRewards/RewardOptionGump.cs index cb04a7b85..55b595e1a 100644 --- a/Scripts/Engines/VeteranRewards/RewardOptionGump.cs +++ b/Scripts/Engines/VeteranRewards/RewardOptionGump.cs @@ -22,8 +22,7 @@ namespace Server.Gumps { m_Option = option; - if ( m_Option != null ) - m_Option.GetOptions( m_Options ); + m_Option?.GetOptions( m_Options ); AddPage( 0 ); diff --git a/Scripts/Gumps/Guilds/GuildmasterGump.cs b/Scripts/Gumps/Guilds/GuildmasterGump.cs index 4fadd674d..d75f1ea04 100644 --- a/Scripts/Gumps/Guilds/GuildmasterGump.cs +++ b/Scripts/Gumps/Guilds/GuildmasterGump.cs @@ -168,8 +168,7 @@ namespace Server.Gumps { GuildTeleporter item = new GuildTeleporter( m_Guild.Guildstone ); - if ( m_Guild.Teleporter != null ) - m_Guild.Teleporter.Delete(); + m_Guild.Teleporter?.Delete(); m_Mobile.SendLocalizedMessage( 501133 ); // Use the teleporting object placed in your backpack to move this guildstone. diff --git a/Scripts/Gumps/HouseGump.cs b/Scripts/Gumps/HouseGump.cs index 7fef89368..13a48f01a 100644 --- a/Scripts/Gumps/HouseGump.cs +++ b/Scripts/Gumps/HouseGump.cs @@ -516,8 +516,7 @@ namespace Server.Gumps { if ( isOwner ) { - if ( m_House.CoOwners != null ) - m_House.CoOwners.Clear(); + m_House.CoOwners?.Clear(); from.SendLocalizedMessage( 501333 ); // All co-owners have been removed from this house. } @@ -571,8 +570,7 @@ namespace Server.Gumps { if ( isCoOwner ) { - if ( m_House.Friends != null ) - m_House.Friends.Clear(); + m_House.Friends?.Clear(); from.SendLocalizedMessage( 501332 ); // All friends have been removed from this house. } diff --git a/Scripts/Gumps/HouseGumpAOS.cs b/Scripts/Gumps/HouseGumpAOS.cs index d998f4c6f..d1f560b13 100644 --- a/Scripts/Gumps/HouseGumpAOS.cs +++ b/Scripts/Gumps/HouseGumpAOS.cs @@ -617,8 +617,7 @@ namespace Server.Gumps if ( okay && house.IsOwner( from ) ) { - if ( house.CoOwners != null ) - house.CoOwners.Clear(); + house.CoOwners?.Clear(); from.SendLocalizedMessage( 501333 ); // All co-owners have been removed from this house. } @@ -635,8 +634,7 @@ namespace Server.Gumps if ( okay && house.IsCoOwner( from ) ) { - if ( house.Friends != null ) - house.Friends.Clear(); + house.Friends?.Clear(); from.SendLocalizedMessage( 501332 ); // All friends have been removed from this house. } @@ -653,8 +651,7 @@ namespace Server.Gumps if ( okay && house.IsFriend( from ) ) { - if ( house.Bans != null ) - house.Bans.Clear(); + house.Bans?.Clear(); from.SendLocalizedMessage( 1060754 ); // All bans for this house have been lifted. } @@ -673,8 +670,7 @@ namespace Server.Gumps { ArrayList list = new ArrayList( house.Access ); - if ( house.Access != null ) - house.Access.Clear(); + house.Access?.Clear(); for ( int i = 0; i < list.Count; ++i ) { diff --git a/Scripts/Gumps/PlayerVendorGumps.cs b/Scripts/Gumps/PlayerVendorGumps.cs index 0afe255d9..ebc16c37f 100644 --- a/Scripts/Gumps/PlayerVendorGumps.cs +++ b/Scripts/Gumps/PlayerVendorGumps.cs @@ -568,8 +568,7 @@ namespace Server.Gumps { Item item = m_Vendor.FindItemOnLayer( Categories[cat].Layer ); - if ( item != null ) - item.Delete(); + item?.Delete(); List items = m_Vendor.Items; @@ -585,8 +584,7 @@ namespace Server.Gumps } } - if ( item != null ) - item.Delete(); + item?.Delete(); if ( Categories[cat].Layer == Layer.FacialHair ) { @@ -706,8 +704,7 @@ namespace Server.Gumps } } - if ( item != null ) - item.Delete(); + item?.Delete(); } from.SendGump( new PlayerVendorCustomizeGump( m_Vendor, from ) ); diff --git a/Scripts/Items/Addons/AddonComponent.cs b/Scripts/Items/Addons/AddonComponent.cs index 2a2265e90..718fa079a 100644 --- a/Scripts/Items/Addons/AddonComponent.cs +++ b/Scripts/Items/Addons/AddonComponent.cs @@ -151,8 +151,7 @@ namespace Server.Items public override void OnDoubleClick( Mobile from ) { - if ( m_Addon != null ) - m_Addon.OnComponentUsed( this, from ); + m_Addon?.OnComponentUsed( this, @from ); } public void OnChop( Mobile from ) @@ -179,8 +178,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Addon != null ) - m_Addon.Delete(); + m_Addon?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -207,8 +205,7 @@ namespace Server.Items m_Addon = reader.ReadItem() as BaseAddon; m_Offset = reader.ReadPoint3D(); - if ( m_Addon != null ) - m_Addon.OnComponentLoaded( this ); + m_Addon?.OnComponentLoaded( this ); ApplyLightTo( this ); diff --git a/Scripts/Items/Addons/AddonContainerComponent.cs b/Scripts/Items/Addons/AddonContainerComponent.cs index 58b932ded..2651d9d3c 100644 --- a/Scripts/Items/Addons/AddonContainerComponent.cs +++ b/Scripts/Items/Addons/AddonContainerComponent.cs @@ -60,8 +60,7 @@ namespace Server.Items public override void OnDoubleClick( Mobile from ) { - if ( m_Addon != null ) - m_Addon.OnComponentUsed( this, from ); + m_Addon?.OnComponentUsed( this, @from ); } public override void OnLocationChange( Point3D old ) @@ -72,8 +71,7 @@ namespace Server.Items public override void GetContextMenuEntries( Mobile from, List list ) { - if ( m_Addon != null ) - m_Addon.GetContextMenuEntries( from, list ); + m_Addon?.GetContextMenuEntries( @from, list ); } public override void OnMapChange() @@ -86,8 +84,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Addon != null ) - m_Addon.Delete(); + m_Addon?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -109,8 +106,7 @@ namespace Server.Items m_Addon = reader.ReadItem() as BaseAddonContainer; m_Offset = reader.ReadPoint3D(); - if ( m_Addon != null ) - m_Addon.OnComponentLoaded( this ); + m_Addon?.OnComponentLoaded( this ); AddonComponent.ApplyLightTo( this ); } diff --git a/Scripts/Items/Addons/BaseAddonContainer.cs b/Scripts/Items/Addons/BaseAddonContainer.cs index 4e44b8c69..e76c306ed 100644 --- a/Scripts/Items/Addons/BaseAddonContainer.cs +++ b/Scripts/Items/Addons/BaseAddonContainer.cs @@ -96,8 +96,7 @@ namespace Server.Items { BaseHouse house = BaseHouse.FindHouseAt( this ); - if ( house != null ) - house.Addons.Remove( this ); + house?.Addons.Remove( this ); base.OnDelete(); } diff --git a/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs b/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs index 1fcc079ed..5bf7a4a85 100644 --- a/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs +++ b/Scripts/Items/Addons/ElvenSpinningwheelEastAddon.cs @@ -77,8 +77,7 @@ namespace Server.Items } } - if ( callback != null ) - callback( this, from, hue ); + callback?.Invoke( this, @from, hue ); } private class SpinTimer : Timer diff --git a/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs b/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs index 227b355eb..e2ca8c1e9 100644 --- a/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs +++ b/Scripts/Items/Addons/ElvenSpinningwheelSouthAddon.cs @@ -79,8 +79,7 @@ namespace Server.Items } } - if ( callback != null ) - callback( this, from, hue ); + callback?.Invoke( this, @from, hue ); } private class SpinTimer : Timer diff --git a/Scripts/Items/Addons/SpinningwheelEastAddon.cs b/Scripts/Items/Addons/SpinningwheelEastAddon.cs index ee54fd219..ed183d021 100644 --- a/Scripts/Items/Addons/SpinningwheelEastAddon.cs +++ b/Scripts/Items/Addons/SpinningwheelEastAddon.cs @@ -87,8 +87,7 @@ namespace Server.Items } } - if ( callback != null ) - callback( this, from, hue ); + callback?.Invoke( this, @from, hue ); } private class SpinTimer : Timer diff --git a/Scripts/Items/Addons/SpinningwheelSouthAddon.cs b/Scripts/Items/Addons/SpinningwheelSouthAddon.cs index 1bedeaa18..79c5280c2 100644 --- a/Scripts/Items/Addons/SpinningwheelSouthAddon.cs +++ b/Scripts/Items/Addons/SpinningwheelSouthAddon.cs @@ -79,8 +79,7 @@ namespace Server.Items } } - if ( callback != null ) - callback( this, from, hue ); + callback?.Invoke( this, @from, hue ); } private class SpinTimer : Timer diff --git a/Scripts/Items/Aquarium/Aquarium.cs b/Scripts/Items/Aquarium/Aquarium.cs index 0c4e43d47..e9f6f3a11 100644 --- a/Scripts/Items/Aquarium/Aquarium.cs +++ b/Scripts/Items/Aquarium/Aquarium.cs @@ -822,8 +822,7 @@ namespace Server.Items if ( IsFull || m_LiveCreatures >= MaxLiveCreatures || fish.Dead ) { - if ( from != null ) - from.SendLocalizedMessage( 1073633 ); // The aquarium can not hold the creature. + @from?.SendLocalizedMessage( 1073633 ); // The aquarium can not hold the creature. return false; } @@ -833,8 +832,7 @@ namespace Server.Items m_LiveCreatures += 1; - if ( from != null ) - from.SendLocalizedMessage( 1073632, $"#{fish.LabelNumber}"); // You add the following creature to your aquarium: ~1_FISH~ + @from?.SendLocalizedMessage( 1073632, $"#{fish.LabelNumber}"); // You add the following creature to your aquarium: ~1_FISH~ InvalidateProperties(); return true; diff --git a/Scripts/Items/Armor/BaseArmor.cs b/Scripts/Items/Armor/BaseArmor.cs index 15fc93ebe..12ca9e196 100644 --- a/Scripts/Items/Armor/BaseArmor.cs +++ b/Scripts/Items/Armor/BaseArmor.cs @@ -620,13 +620,10 @@ namespace Server.Items CraftResourceInfo info = CraftResources.GetInfo( m_Resource ); - if ( info != null ) - { - CraftAttributeInfo attrInfo = info.AttributeInfo; + CraftAttributeInfo attrInfo = info?.AttributeInfo; - if ( attrInfo != null ) - v += attrInfo.ArmorLowerRequirements; - } + if ( attrInfo != null ) + v += attrInfo.ArmorLowerRequirements; if ( v > 100 ) v = 100; @@ -1382,10 +1379,7 @@ namespace Server.Items { CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); - if ( resInfo == null ) - return 0; - - CraftAttributeInfo attrInfo = resInfo.AttributeInfo; + CraftAttributeInfo attrInfo = resInfo?.AttributeInfo; if ( attrInfo == null ) return 0; diff --git a/Scripts/Items/Clothing/BaseClothing.cs b/Scripts/Items/Clothing/BaseClothing.cs index b29157a84..9f6fde811 100644 --- a/Scripts/Items/Clothing/BaseClothing.cs +++ b/Scripts/Items/Clothing/BaseClothing.cs @@ -558,8 +558,7 @@ namespace Server.Items if ( RequiredRace == Race.Elf ) list.Add( 1075086 ); // Elves Only - if ( m_AosSkillBonuses != null ) - m_AosSkillBonuses.GetProperties( list ); + m_AosSkillBonuses?.GetProperties( list ); int prop; diff --git a/Scripts/Items/Clothing/OuterTorso.cs b/Scripts/Items/Clothing/OuterTorso.cs index c551a58e8..f65d97544 100644 --- a/Scripts/Items/Clothing/OuterTorso.cs +++ b/Scripts/Items/Clothing/OuterTorso.cs @@ -128,8 +128,7 @@ namespace Server.Items private void BeginDecay( TimeSpan delay ) { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTime = DateTime.UtcNow + delay; @@ -157,8 +156,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTimer = null; } diff --git a/Scripts/Items/Construction/Ankhs.cs b/Scripts/Items/Construction/Ankhs.cs index 95db23205..c36a2d89e 100644 --- a/Scripts/Items/Construction/Ankhs.cs +++ b/Scripts/Items/Construction/Ankhs.cs @@ -159,8 +159,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -212,8 +211,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override bool HandlesOnMovement => true; // Tell the core that we implement OnMovement @@ -327,8 +325,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -382,8 +379,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override bool HandlesOnMovement => true; // Tell the core that we implement OnMovement diff --git a/Scripts/Items/Construction/Decorative/DecorativeWeapon.cs b/Scripts/Items/Construction/Decorative/DecorativeWeapon.cs index 0da87b7a5..4d2c9973f 100644 --- a/Scripts/Items/Construction/Decorative/DecorativeWeapon.cs +++ b/Scripts/Items/Construction/Decorative/DecorativeWeapon.cs @@ -144,8 +144,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -196,8 +195,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -251,8 +249,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -303,8 +300,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -358,8 +354,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -410,8 +405,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -465,8 +459,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -517,8 +510,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Items/Construction/Decorative/Tapestry.cs b/Scripts/Items/Construction/Decorative/Tapestry.cs index 6718fb19b..8cc25f18b 100644 --- a/Scripts/Items/Construction/Decorative/Tapestry.cs +++ b/Scripts/Items/Construction/Decorative/Tapestry.cs @@ -32,8 +32,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -84,8 +83,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -140,8 +138,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -192,8 +189,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -247,8 +243,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -299,8 +294,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -355,8 +349,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -407,8 +400,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -463,8 +455,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -515,8 +506,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -571,8 +561,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -623,8 +612,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -678,8 +666,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -731,8 +718,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -787,8 +773,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -839,8 +824,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -894,8 +878,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -947,8 +930,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -1003,8 +985,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -1055,8 +1036,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -1110,8 +1090,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -1163,8 +1142,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Items/Containers/MarkContainer.cs b/Scripts/Items/Containers/MarkContainer.cs index 997619334..8bab9d3ed 100644 --- a/Scripts/Items/Containers/MarkContainer.cs +++ b/Scripts/Items/Containers/MarkContainer.cs @@ -157,8 +157,7 @@ namespace Server.Items public void StopTimer() { - if ( m_RelockTimer != null ) - m_RelockTimer.Stop(); + m_RelockTimer?.Stop(); m_RelockTimer = null; } diff --git a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs index 8080bfb4f..391e9c0bb 100644 --- a/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs +++ b/Scripts/Items/Decoration Artifacts/StealableArtifactsSpawner.cs @@ -240,10 +240,7 @@ namespace Server.Items public static StealableInstance GetStealableInstance( Item item ) { - if ( Instance == null ) - return null; - - return (StealableInstance) Instance.m_Table[item]; + return (StealableInstance) Instance?.m_Table[item]; } @@ -341,8 +338,7 @@ namespace Server.Items foreach ( StealableInstance si in m_Artifacts ) { - if ( si.Item != null ) - si.Item.Delete(); + si.Item?.Delete(); } m_Instance = null; diff --git a/Scripts/Items/Deeds/CommodityDeed.cs b/Scripts/Items/Deeds/CommodityDeed.cs index bce9623e4..bbaba3a90 100644 --- a/Scripts/Items/Deeds/CommodityDeed.cs +++ b/Scripts/Items/Deeds/CommodityDeed.cs @@ -83,8 +83,7 @@ namespace Server.Items public override void OnDelete() { - if ( m_Commodity != null ) - m_Commodity.Delete(); + m_Commodity?.Delete(); base.OnDelete(); } diff --git a/Scripts/Items/Deeds/VendorRentalContract.cs b/Scripts/Items/Deeds/VendorRentalContract.cs index 42bc7e39d..48775384e 100644 --- a/Scripts/Items/Deeds/VendorRentalContract.cs +++ b/Scripts/Items/Deeds/VendorRentalContract.cs @@ -139,10 +139,7 @@ namespace Server.Items { BaseHouse house = BaseHouse.FindHouseAt( this ); - if ( house != null ) - { - house.VendorRentalContracts.Remove( this ); - } + house?.VendorRentalContracts.Remove( this ); } } diff --git a/Scripts/Items/Farming/FarmableCrop.cs b/Scripts/Items/Farming/FarmableCrop.cs index 8a87bcd42..0039f3c38 100644 --- a/Scripts/Items/Farming/FarmableCrop.cs +++ b/Scripts/Items/Farming/FarmableCrop.cs @@ -35,8 +35,7 @@ namespace Server.Items Item spawn = GetCropObject(); - if ( spawn != null ) - spawn.MoveToWorld( loc, map ); + spawn?.MoveToWorld( loc, map ); m_Picked = true; diff --git a/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs b/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs index 5f01b88a0..190d6e851 100644 --- a/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs +++ b/Scripts/Items/Games/Mahjong/MahjongPacketHandlers.cs @@ -47,8 +47,7 @@ namespace Server.Engines.Mahjong { MahjongGame game = World.FindItem( pvSrc.ReadInt32() ) as MahjongGame; - if ( game != null ) - game.Players.CheckPlayers(); + game?.Players.CheckPlayers(); pvSrc.ReadByte(); diff --git a/Scripts/Items/Maps/TreasureMap.cs b/Scripts/Items/Maps/TreasureMap.cs index 609dbee9d..bd728646e 100644 --- a/Scripts/Items/Maps/TreasureMap.cs +++ b/Scripts/Items/Maps/TreasureMap.cs @@ -470,8 +470,7 @@ namespace Server.Items Stop(); m_From.EndAction( typeof( TreasureMap ) ); - if ( m_Chest != null ) - m_Chest.Delete(); + m_Chest?.Delete(); if ( m_Dirt1 != null ) { diff --git a/Scripts/Items/Misc/Corpses/Corpse.cs b/Scripts/Items/Misc/Corpses/Corpse.cs index df6c934b9..e9eb28690 100644 --- a/Scripts/Items/Misc/Corpses/Corpse.cs +++ b/Scripts/Items/Misc/Corpses/Corpse.cs @@ -368,8 +368,7 @@ namespace Server.Items public void BeginDecay( TimeSpan delay ) { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTime = DateTime.UtcNow + delay; @@ -379,8 +378,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTimer = null; } diff --git a/Scripts/Items/Misc/Corpses/DecayedCorpse.cs b/Scripts/Items/Misc/Corpses/DecayedCorpse.cs index 0434caca8..2f34b143d 100644 --- a/Scripts/Items/Misc/Corpses/DecayedCorpse.cs +++ b/Scripts/Items/Misc/Corpses/DecayedCorpse.cs @@ -19,8 +19,7 @@ namespace Server.Items public void BeginDecay( TimeSpan delay ) { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTime = DateTime.UtcNow + delay; @@ -30,8 +29,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); m_DecayTimer = null; } diff --git a/Scripts/Items/Misc/SerpentPillar.cs b/Scripts/Items/Misc/SerpentPillar.cs index 77102fc03..d6692158b 100644 --- a/Scripts/Items/Misc/SerpentPillar.cs +++ b/Scripts/Items/Misc/SerpentPillar.cs @@ -62,8 +62,7 @@ namespace Server.Items if ( !Active ) { - if ( boat.TillerMan != null ) - boat.TillerMan.Say( 502507 ); // Ar, Legend has it that these pillars are inactive! No man knows how it might be undone! + boat.TillerMan?.Say( 502507 ); // Ar, Legend has it that these pillars are inactive! No man knows how it might be undone! return; } @@ -90,8 +89,7 @@ namespace Server.Items } } - if ( boat.TillerMan != null ) - boat.TillerMan.Say( 502508 ); // Ar, I refuse to take that matey through here! + boat.TillerMan?.Say( 502508 ); // Ar, I refuse to take that matey through here! } } diff --git a/Scripts/Items/Misc/Teleporter.cs b/Scripts/Items/Misc/Teleporter.cs index a1ff12239..bbb8d053e 100644 --- a/Scripts/Items/Misc/Teleporter.cs +++ b/Scripts/Items/Misc/Teleporter.cs @@ -862,8 +862,7 @@ namespace Server.Items public override bool OnMoveOver(Mobile m) { - if (m_Teleporter != null) - m_Teleporter.StopTimer(m); + m_Teleporter?.StopTimer(m); return true; } diff --git a/Scripts/Items/Skill Items/Blacksmith Items/Misc/LargeForge.cs b/Scripts/Items/Skill Items/Blacksmith Items/Misc/LargeForge.cs index 5f10caf81..84477df8a 100644 --- a/Scripts/Items/Skill Items/Blacksmith Items/Misc/LargeForge.cs +++ b/Scripts/Items/Skill Items/Blacksmith Items/Misc/LargeForge.cs @@ -39,10 +39,8 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); - if ( m_Item2 != null ) - m_Item2.Delete(); + m_Item?.Delete(); + m_Item2?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -97,8 +95,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -152,8 +149,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -215,10 +211,8 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); - if ( m_Item2 != null ) - m_Item2.Delete(); + m_Item?.Delete(); + m_Item2?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -273,8 +267,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) @@ -328,8 +321,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Item != null ) - m_Item.Delete(); + m_Item?.Delete(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs index e7f1f72a1..5ecaea6c8 100644 --- a/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs +++ b/Scripts/Items/Skill Items/Magical/Potions/Conflagration Potions/BaseConflagrationPotion.cs @@ -206,8 +206,7 @@ namespace Server.Items { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public InternalItem( Serial serial ) : base( serial ) @@ -316,8 +315,7 @@ namespace Server.Items if ( (m.Z + 16) > m_Item.Z && (m_Item.Z + 12) > m.Z && (!Core.AOS || m != from) && SpellHelper.ValidIndirectTarget( from, m ) && from.CanBeHarmful( m, false ) ) { - if ( from != null ) - from.DoHarmful( m ); + @from?.DoHarmful( m ); AOS.Damage( m, from, m_Item.GetDamage(), 0, 100, 0, 0, 0 ); m.PlaySound( 0x208 ); diff --git a/Scripts/Items/Skill Items/Magical/Spellbook.cs b/Scripts/Items/Skill Items/Magical/Spellbook.cs index bf0eff98d..e39b0091e 100644 --- a/Scripts/Items/Skill Items/Magical/Spellbook.cs +++ b/Scripts/Items/Skill Items/Magical/Spellbook.cs @@ -104,8 +104,7 @@ namespace Server.Items Spellbook book = Find( from, -1, type ); - if ( book != null ) - book.DisplayTo( from ); + book?.DisplayTo( @from ); } private static void EventSink_CastSpellRequest( CastSpellRequestEventArgs e ) diff --git a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs index e09feab8d..8ab58579b 100644 --- a/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs +++ b/Scripts/Items/Skill Items/Musical Instruments/BaseInstrument.cs @@ -153,8 +153,7 @@ namespace Server.Items } else { - if ( from != null ) - from.SendLocalizedMessage( 502079 ); // The instrument played its last tune. + @from?.SendLocalizedMessage( 502079 ); // The instrument played its last tune. Delete(); } @@ -187,8 +186,7 @@ namespace Server.Items if ( instrument != null ) { - if ( callback != null ) - callback( from, instrument ); + callback?.Invoke( @from, instrument ); } else { @@ -233,10 +231,7 @@ namespace Server.Items public static int GetPoisonLevel( BaseCreature bc ) { - if ( bc == null ) - return 0; - - Poison p = bc.HitPoison; + Poison p = bc?.HitPoison; if ( p == null ) return 0; diff --git a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs index e458ff8d6..34df71f7f 100644 --- a/Scripts/Items/Skill Items/Thief/DisguiseKit.cs +++ b/Scripts/Items/Skill Items/Thief/DisguiseKit.cs @@ -309,8 +309,7 @@ namespace Server.Items { m_Timers.TryGetValue( m, out Timer t ); - if ( t != null ) - t.Start(); + t?.Start(); } public static bool IsDisguised( Mobile m ) diff --git a/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs b/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs index 0ced510dd..4d8557a8e 100644 --- a/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs +++ b/Scripts/Items/Skill Items/Tools/BaseRunicTool.cs @@ -239,10 +239,7 @@ namespace Server.Items { CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); - if ( resInfo == null ) - return; - - CraftAttributeInfo attrs = resInfo.AttributeInfo; + CraftAttributeInfo attrs = resInfo?.AttributeInfo; if ( attrs == null ) return; @@ -438,10 +435,7 @@ namespace Server.Items { CraftResourceInfo resInfo = CraftResources.GetInfo( m_Resource ); - if ( resInfo == null ) - return; - - CraftAttributeInfo attrs = resInfo.AttributeInfo; + CraftAttributeInfo attrs = resInfo?.AttributeInfo; if ( attrs == null ) return; diff --git a/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs b/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs index 1cc715916..55dd8cf4c 100644 --- a/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs +++ b/Scripts/Items/Special/Evil Home Decor Collection/SacrificialAltar.cs @@ -39,8 +39,7 @@ namespace Server.Items { SendLocalizedMessageTo( from, 1010442 ); // The item will be deleted in three minutes - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = Timer.DelayCall( TimeSpan.FromMinutes( 3 ), new TimerCallback( Empty ) ); } @@ -62,8 +61,7 @@ namespace Server.Items { SendLocalizedMessageTo( from, 1010442 ); // The item will be deleted in three minutes - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = Timer.DelayCall( TimeSpan.FromMinutes( 3 ), new TimerCallback( Empty ) ); } diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs index bb43bdd9c..0cd0761a9 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastBlood.cs @@ -47,17 +47,14 @@ namespace Server.Items ItemID = 0x1765; - if ( Owner != null ) - { - Container pack = Owner.Backpack; + Container pack = Owner?.Backpack; - if ( pack != null ) + if ( pack != null ) + { + for ( int i = 0; i < pack.Items.Count; i++ ) { - for ( int i = 0; i < pack.Items.Count; i++ ) - { - if ( pack.Items[ i ] is PlagueBeastMainOrgan main && main.Complete ) - main.FinishOpening( from ); - } + if ( pack.Items[ i ] is PlagueBeastMainOrgan main && main.Complete ) + main.FinishOpening( @from ); } } @@ -74,8 +71,7 @@ namespace Server.Items if ( Patched ) return; - if ( Owner != null ) - Owner.PlaySound( 0x25 ); + Owner?.PlaySound( 0x25 ); if ( ItemID == 0x122A ) { diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs index 9b0ca042d..41b0b90eb 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastOrgans.cs @@ -98,8 +98,7 @@ namespace Server.Items { m_Opened = true; - if ( Owner != null ) - Owner.PlaySound( 0x50 ); + Owner?.PlaySound( 0x50 ); } public PlagueBeastOrgan( Serial serial ) : base( serial ) @@ -145,8 +144,7 @@ namespace Server.Items { ItemID = 0x1249; - if ( Owner != null ) - Owner.PlaySound( 0x187 ); + Owner?.PlaySound( 0x187 ); AddComponent( new PlagueBeastComponent( 0x1D0D, 0x0 ), 22, 3 ); AddComponent( new PlagueBeastComponent( 0x1D12, 0x0 ), 15, 18 ); @@ -398,8 +396,7 @@ namespace Server.Items from.SendAsciiMessage( 0x3B2, "* You place the healthy gland inside the organ sac *" ); item.Movable = false; - if ( Owner != null ) - Owner.PlaySound( 0x20 ); + Owner?.PlaySound( 0x20 ); return true; } diff --git a/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs b/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs index 13f5b63eb..d4e1b7985 100644 --- a/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs +++ b/Scripts/Items/Special/Mutation Core/PlagueBeastVein.cs @@ -48,8 +48,7 @@ namespace Server.Items else ItemID = 0x1B1C; - if ( Owner != null ) - Owner.PlaySound( 0x199 ); + Owner?.PlaySound( 0x199 ); if ( Organ is PlagueBeastRubbleOrgan organ ) organ.OnVeinCut( from, this ); diff --git a/Scripts/Items/Special/Veteran Rewards/Brazier.cs b/Scripts/Items/Special/Veteran Rewards/Brazier.cs index eed38fe12..01739934c 100644 --- a/Scripts/Items/Special/Veteran Rewards/Brazier.cs +++ b/Scripts/Items/Special/Veteran Rewards/Brazier.cs @@ -92,8 +92,7 @@ namespace Server.Items public override void OnLocationChange( Point3D old ) { - if ( m_Fire != null ) - m_Fire.MoveToWorld( new Point3D( X, Y, Z + ItemData.Height ), Map ); + m_Fire?.MoveToWorld( new Point3D( X, Y, Z + ItemData.Height ), Map ); } public override void GetProperties( ObjectPropertyList list ) diff --git a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs index 4ddc2c8da..ee10bd4e7 100644 --- a/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs +++ b/Scripts/Items/Special/Veteran Rewards/WeaponEngravingTool.cs @@ -168,10 +168,7 @@ namespace Server.Items public static WeaponEngravingTool Find( Mobile from ) { - if ( from.Backpack != null ) - return from.Backpack.FindItemByType( typeof( WeaponEngravingTool ) ) as WeaponEngravingTool; - - return null; + return @from.Backpack?.FindItemByType( typeof( WeaponEngravingTool ) ) as WeaponEngravingTool; } private class TargetWeapon : Target diff --git a/Scripts/Items/Talismans/BaseTalisman.cs b/Scripts/Items/Talismans/BaseTalisman.cs index a750e5991..b0cc7ecad 100644 --- a/Scripts/Items/Talismans/BaseTalisman.cs +++ b/Scripts/Items/Talismans/BaseTalisman.cs @@ -727,8 +727,7 @@ namespace Server.Items public virtual void StopTimer() { - if (m_Timer != null) - m_Timer.Stop(); + m_Timer?.Stop(); m_Timer = null; } diff --git a/Scripts/Items/Traps/FlameSpurtTrap.cs b/Scripts/Items/Traps/FlameSpurtTrap.cs index fd331f2d8..e6dec2565 100644 --- a/Scripts/Items/Traps/FlameSpurtTrap.cs +++ b/Scripts/Items/Traps/FlameSpurtTrap.cs @@ -68,8 +68,7 @@ namespace Server.Items { base.OnDelete(); - if ( m_Spurt != null ) - m_Spurt.Delete(); + m_Spurt?.Delete(); } public virtual void Refresh() @@ -93,8 +92,7 @@ namespace Server.Items if ( !foundPlayer ) { - if ( m_Spurt != null ) - m_Spurt.Delete(); + m_Spurt?.Delete(); m_Spurt = null; } @@ -167,8 +165,7 @@ namespace Server.Items { Item item = reader.ReadItem(); - if ( item != null ) - item.Delete(); + item?.Delete(); CheckTimer(); diff --git a/Scripts/Items/Weapons/Abilities/MortalStrike.cs b/Scripts/Items/Weapons/Abilities/MortalStrike.cs index 784516014..4c48b438d 100644 --- a/Scripts/Items/Weapons/Abilities/MortalStrike.cs +++ b/Scripts/Items/Weapons/Abilities/MortalStrike.cs @@ -50,8 +50,7 @@ namespace Server.Items { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( m, duration ); m_Table[m] = t; @@ -68,8 +67,7 @@ namespace Server.Items Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); diff --git a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs index 7dffade8e..37c01487b 100644 --- a/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs +++ b/Scripts/Items/Weapons/Abilities/ParalyzingBlow.cs @@ -96,8 +96,7 @@ namespace Server.Items { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( m, duration ); m_Table[m] = t; @@ -109,8 +108,7 @@ namespace Server.Items { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); } diff --git a/Scripts/Misc/Assistants.cs b/Scripts/Misc/Assistants.cs index 2dc8ed2b7..4d1957f96 100644 --- a/Scripts/Misc/Assistants.cs +++ b/Scripts/Misc/Assistants.cs @@ -110,8 +110,8 @@ namespace Server.Misc if (Settings.KickOnFailure) m.Send(new BeginHandshake()); - if (m_Dictionary.TryGetValue(m, out Timer t) && t != null) - t.Stop(); + if (m_Dictionary.TryGetValue(m, out Timer t)) + t?.Stop(); m_Dictionary[m] = t = Timer.DelayCall(Settings.HandshakeTimeout, OnHandshakeTimeout_Callback, m); t.Start(); diff --git a/Scripts/Misc/DoorGenerator.cs b/Scripts/Misc/DoorGenerator.cs index 24182abc1..bc5b9a4c5 100644 --- a/Scripts/Misc/DoorGenerator.cs +++ b/Scripts/Misc/DoorGenerator.cs @@ -513,11 +513,9 @@ namespace Server } else { - if ( first != null ) - first.Delete(); + first?.Delete(); - if ( second != null ) - second.Delete(); + second?.Delete(); } } } @@ -539,11 +537,9 @@ namespace Server } else { - if ( first != null ) - first.Delete(); + first?.Delete(); - if ( second != null ) - second.Delete(); + second?.Delete(); } } } diff --git a/Scripts/Misc/LanguageStatistics.cs b/Scripts/Misc/LanguageStatistics.cs index c16e5abbd..98eb9807a 100644 --- a/Scripts/Misc/LanguageStatistics.cs +++ b/Scripts/Misc/LanguageStatistics.cs @@ -257,10 +257,7 @@ namespace Server.Misc { Mobile mob = acc[i]; - if ( mob == null ) - continue; - - string lang = mob.Language; + string lang = mob?.Language; if ( lang != null ) { diff --git a/Scripts/Misc/LightCycle.cs b/Scripts/Misc/LightCycle.cs index 89a5da3b4..5b5f9cd34 100644 --- a/Scripts/Misc/LightCycle.cs +++ b/Scripts/Misc/LightCycle.cs @@ -25,8 +25,7 @@ namespace Server NetState ns = NetState.Instances[i]; Mobile m = ns.Mobile; - if ( m != null ) - m.CheckLightLevels( false ); + m?.CheckLightLevels( false ); } } } @@ -113,8 +112,7 @@ namespace Server NetState ns = NetState.Instances[i]; Mobile m = ns.Mobile; - if ( m != null ) - m.CheckLightLevels( false ); + m?.CheckLightLevels( false ); } } } diff --git a/Scripts/Misc/ProfanityProtection.cs b/Scripts/Misc/ProfanityProtection.cs index 2fd88db5a..8d1eb8c72 100644 --- a/Scripts/Misc/ProfanityProtection.cs +++ b/Scripts/Misc/ProfanityProtection.cs @@ -35,8 +35,7 @@ namespace Server.Misc { NetState ns = from.NetState; - if ( ns != null ) - ns.Dispose(); + ns?.Dispose(); return false; } diff --git a/Scripts/Misc/TextDefinition.cs b/Scripts/Misc/TextDefinition.cs index a5a15cb39..5ef54e320 100644 --- a/Scripts/Misc/TextDefinition.cs +++ b/Scripts/Misc/TextDefinition.cs @@ -131,10 +131,7 @@ namespace Server public static implicit operator string( TextDefinition m ) { - if ( m == null ) - return null; - - return m.m_String; + return m?.m_String; } public static void AddHtmlText( Gump g, int x, int y, int width, int height, TextDefinition def, bool back, bool scroll, int numberColor, int stringColor ) diff --git a/Scripts/Misc/ValidationQueue.cs b/Scripts/Misc/ValidationQueue.cs index c18149496..95ce79ce6 100644 --- a/Scripts/Misc/ValidationQueue.cs +++ b/Scripts/Misc/ValidationQueue.cs @@ -12,8 +12,7 @@ namespace Server public static void Initialize() { - if ( StartValidation != null ) - StartValidation(); + StartValidation?.Invoke(); StartValidation = null; } diff --git a/Scripts/Misc/Weather.cs b/Scripts/Misc/Weather.cs index 8e6d6f2f5..1ee00335c 100644 --- a/Scripts/Misc/Weather.cs +++ b/Scripts/Misc/Weather.cs @@ -198,8 +198,7 @@ namespace Server.Misc List list = GetWeatherList( facet ); - if ( list != null ) - list.Add( this ); + list?.Add( this ); Timer.DelayCall( TimeSpan.FromSeconds( (0.2+(Utility.RandomDouble()*0.8)) * interval.TotalSeconds ), interval, new TimerCallback( OnTick ) ); } diff --git a/Scripts/Mobiles/AI/MageAI.cs b/Scripts/Mobiles/AI/MageAI.cs index 5ab66ccbb..c929029e0 100644 --- a/Scripts/Mobiles/AI/MageAI.cs +++ b/Scripts/Mobiles/AI/MageAI.cs @@ -75,8 +75,7 @@ namespace Server.Mobiles { Spell spell = CheckCastHealingSpell(); - if ( spell != null ) - spell.Cast(); + spell?.Cast(); } } @@ -183,8 +182,7 @@ namespace Server.Mobiles { if ( !m_Mobile.DisallowAllMoves && ( SmartAI ? Utility.Random( 4 ) == 0 : ScaleBySkill( TeleportChance, SkillName.Magery ) > Utility.RandomDouble() ) ) { - if ( m_Mobile.Target != null ) - m_Mobile.Target.Cancel( m_Mobile, TargetCancelType.Canceled ); + m_Mobile.Target?.Cancel( m_Mobile, TargetCancelType.Canceled ); new TeleportSpell( m_Mobile, null ).Cast(); @@ -705,8 +703,7 @@ namespace Server.Mobiles RunTo( c ); } - if ( spell != null ) - spell.Cast(); + spell?.Cast(); m_NextCastTime = Core.TickCount + (int)GetDelay(spell).TotalMilliseconds; } @@ -762,8 +759,7 @@ namespace Server.Mobiles Spell spell = CheckCastHealingSpell(); - if ( spell != null ) - spell.Cast(); + spell?.Cast(); } base.DoActionGuard(); diff --git a/Scripts/Mobiles/AI/ThiefAI.cs b/Scripts/Mobiles/AI/ThiefAI.cs index 85c27bfc1..4e553ed44 100644 --- a/Scripts/Mobiles/AI/ThiefAI.cs +++ b/Scripts/Mobiles/AI/ThiefAI.cs @@ -68,8 +68,7 @@ namespace Server.Mobiles { m_Mobile.DebugSay( "Trying to steal from combatant." ); m_Mobile.UseSkill( SkillName.Stealing ); - if ( m_Mobile.Target != null ) - m_Mobile.Target.Invoke( m_Mobile, m_toDisarm ); + m_Mobile.Target?.Invoke( m_Mobile, m_toDisarm ); } else if (m_toDisarm == null && Core.TickCount - m_Mobile.NextSkillTime >= 0) { @@ -82,24 +81,21 @@ namespace Server.Mobiles { m_Mobile.DebugSay( "Trying to steal from combatant." ); m_Mobile.UseSkill( SkillName.Stealing ); - if ( m_Mobile.Target != null ) - m_Mobile.Target.Invoke( m_Mobile, steala ); + m_Mobile.Target?.Invoke( m_Mobile, steala ); } Item stealb = cpack.FindItemByType( typeof ( Nightshade ) ); if ( stealb != null ) { m_Mobile.DebugSay( "Trying to steal from combatant." ); m_Mobile.UseSkill( SkillName.Stealing ); - if ( m_Mobile.Target != null ) - m_Mobile.Target.Invoke( m_Mobile, stealb ); + m_Mobile.Target?.Invoke( m_Mobile, stealb ); } Item stealc = cpack.FindItemByType( typeof ( BlackPearl ) ); if ( stealc != null ) { m_Mobile.DebugSay( "Trying to steal from combatant." ); m_Mobile.UseSkill( SkillName.Stealing ); - if ( m_Mobile.Target != null ) - m_Mobile.Target.Invoke( m_Mobile, stealc ); + m_Mobile.Target?.Invoke( m_Mobile, stealc ); } Item steald = cpack.FindItemByType( typeof ( MandrakeRoot ) ); @@ -107,8 +103,7 @@ namespace Server.Mobiles { m_Mobile.DebugSay( "Trying to steal from combatant." ); m_Mobile.UseSkill( SkillName.Stealing ); - if ( m_Mobile.Target != null ) - m_Mobile.Target.Invoke( m_Mobile, steald ); + m_Mobile.Target?.Invoke( m_Mobile, steald ); } else if ( steala == null && stealb == null && stealc == null && steald == null ) { diff --git a/Scripts/Mobiles/Animals/Misc/PackHorse.cs b/Scripts/Mobiles/Animals/Misc/PackHorse.cs index acf256704..3d499a5fc 100644 --- a/Scripts/Mobiles/Animals/Misc/PackHorse.cs +++ b/Scripts/Mobiles/Animals/Misc/PackHorse.cs @@ -48,8 +48,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); pack = new StrongBackpack(); pack.Movable = false; diff --git a/Scripts/Mobiles/Animals/Misc/PackLlama.cs b/Scripts/Mobiles/Animals/Misc/PackLlama.cs index 6ee1c4112..8e0f3058c 100644 --- a/Scripts/Mobiles/Animals/Misc/PackLlama.cs +++ b/Scripts/Mobiles/Animals/Misc/PackLlama.cs @@ -48,8 +48,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); pack = new StrongBackpack(); pack.Movable = false; diff --git a/Scripts/Mobiles/Animals/Mounts/Beetle.cs b/Scripts/Mobiles/Animals/Mounts/Beetle.cs index feb1f9eec..0154e0452 100644 --- a/Scripts/Mobiles/Animals/Mounts/Beetle.cs +++ b/Scripts/Mobiles/Animals/Mounts/Beetle.cs @@ -49,8 +49,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); pack = new StrongBackpack(); pack.Movable = false; diff --git a/Scripts/Mobiles/Familiars/HordeMinion.cs b/Scripts/Mobiles/Familiars/HordeMinion.cs index 626f735a4..761c7db3c 100644 --- a/Scripts/Mobiles/Familiars/HordeMinion.cs +++ b/Scripts/Mobiles/Familiars/HordeMinion.cs @@ -44,8 +44,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); pack = new Backpack(); pack.Movable = false; diff --git a/Scripts/Mobiles/Monsters/AOS/Revenant.cs b/Scripts/Mobiles/Monsters/AOS/Revenant.cs index 71fb1502e..dbbd2cfa8 100644 --- a/Scripts/Mobiles/Monsters/AOS/Revenant.cs +++ b/Scripts/Mobiles/Monsters/AOS/Revenant.cs @@ -138,8 +138,7 @@ namespace Server.Mobiles { Target targ = Target; - if ( targ != null ) - targ.Invoke( this, this ); + targ?.Invoke( this, this ); } Combatant = m_Target; diff --git a/Scripts/Mobiles/Monsters/AOS/ShadowKnight.cs b/Scripts/Mobiles/Monsters/AOS/ShadowKnight.cs index 27be90dbe..806bfda7f 100644 --- a/Scripts/Mobiles/Monsters/AOS/ShadowKnight.cs +++ b/Scripts/Mobiles/Monsters/AOS/ShadowKnight.cs @@ -106,8 +106,7 @@ namespace Server.Mobiles { Frozen = false; - if ( m_SoundTimer != null ) - m_SoundTimer.Stop(); + m_SoundTimer?.Stop(); m_SoundTimer = null; } diff --git a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs index 51da8434f..61e7d3521 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Magic/SavageShaman.cs @@ -231,8 +231,7 @@ namespace Server.Mobiles DoHarmful( m ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs index 07b9b84bf..430d6d214 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/ShadowFiend.cs @@ -79,8 +79,7 @@ namespace Server.Mobiles public override bool OnBeforeDeath() { - if ( Backpack != null ) - Backpack.Destroy(); + Backpack?.Destroy(); Effects.SendLocationEffect( Location, Map, 0x376A, 10, 1 ); return true; diff --git a/Scripts/Mobiles/Monsters/Humanoid/Melee/SpawnedOrcishLord.cs b/Scripts/Mobiles/Monsters/Humanoid/Melee/SpawnedOrcishLord.cs index 713808387..7c269342d 100644 --- a/Scripts/Mobiles/Monsters/Humanoid/Melee/SpawnedOrcishLord.cs +++ b/Scripts/Mobiles/Monsters/Humanoid/Melee/SpawnedOrcishLord.cs @@ -10,8 +10,7 @@ namespace Server.Mobiles { Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); NoKillAwards = true; } diff --git a/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs b/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs index 50c340fad..cf80ed9c5 100644 --- a/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs +++ b/Scripts/Mobiles/Monsters/LBR/Meers/EnragedCreatures.cs @@ -222,10 +222,7 @@ namespace Server.Mobiles else if ( !Combat( this )) { - if ( AIObject != null ) - { - AIObject.MoveTo( SummonMaster, false , 5 ); - } + AIObject?.MoveTo( SummonMaster, false , 5 ); } /* diff --git a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs index fa67bee05..55f15a184 100644 --- a/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs +++ b/Scripts/Mobiles/Monsters/SE/BakeKitsune.cs @@ -146,8 +146,7 @@ namespace Server.Mobiles { Item item = FindItemOnLayer( layer ); - if ( item != null ) - item.Delete(); + item?.Delete(); } #endregion diff --git a/Scripts/Mobiles/Monsters/SE/Kappa.cs b/Scripts/Mobiles/Monsters/SE/Kappa.cs index b40ec67fd..de2e1b0d5 100644 --- a/Scripts/Mobiles/Monsters/SE/Kappa.cs +++ b/Scripts/Mobiles/Monsters/SE/Kappa.cs @@ -110,8 +110,7 @@ namespace Server.Mobiles { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( from, m ); m_Table[m] = t; @@ -136,8 +135,7 @@ namespace Server.Mobiles { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); diff --git a/Scripts/Mobiles/PlayerMobile.cs b/Scripts/Mobiles/PlayerMobile.cs index 2639655f6..81e05f794 100644 --- a/Scripts/Mobiles/PlayerMobile.cs +++ b/Scripts/Mobiles/PlayerMobile.cs @@ -2518,8 +2518,7 @@ namespace Server.Mobiles { BandageContext c = BandageContext.GetContext( this ); - if ( c != null ) - c.Slip(); + c?.Slip(); } if ( Confidence.IsRegenerating( this ) ) diff --git a/Scripts/Mobiles/Special/Harrower.cs b/Scripts/Mobiles/Special/Harrower.cs index 06d4b985c..714e5600c 100644 --- a/Scripts/Mobiles/Special/Harrower.cs +++ b/Scripts/Mobiles/Special/Harrower.cs @@ -372,8 +372,7 @@ namespace Server.Mobiles RegisterDamageTo( this ); AwardArtifact( GetArtifact() ); - if ( m_GateItem != null ) - m_GateItem.Delete(); + m_GateItem?.Delete(); } return base.OnBeforeDeath(); diff --git a/Scripts/Mobiles/Special/Neira.cs b/Scripts/Mobiles/Special/Neira.cs index 17da1e943..6650fffb0 100644 --- a/Scripts/Mobiles/Special/Neira.cs +++ b/Scripts/Mobiles/Special/Neira.cs @@ -87,8 +87,7 @@ namespace Server.Mobiles if ( mount != null ) mount.Rider = null; - if ( mount is Mobile ) - ((Mobile)mount).Delete(); + (mount as Mobile)?.Delete(); return base.OnBeforeDeath(); } diff --git a/Scripts/Mobiles/Townfolk/BaseEscortable.cs b/Scripts/Mobiles/Townfolk/BaseEscortable.cs index 5fb46e232..b9e9e2904 100644 --- a/Scripts/Mobiles/Townfolk/BaseEscortable.cs +++ b/Scripts/Mobiles/Townfolk/BaseEscortable.cs @@ -303,8 +303,7 @@ namespace Server.Mobiles public override void OnAfterDelete() { - if (m_DeleteTimer != null) - m_DeleteTimer.Stop(); + m_DeleteTimer?.Stop(); m_DeleteTimer = null; @@ -408,8 +407,7 @@ namespace Server.Mobiles public virtual void BeginDelete() { - if (m_DeleteTimer != null) - m_DeleteTimer.Stop(); + m_DeleteTimer?.Stop(); m_DeleteTime = DateTime.UtcNow + DeleteTime; diff --git a/Scripts/Mobiles/Townfolk/TownCrier.cs b/Scripts/Mobiles/Townfolk/TownCrier.cs index 789f1f5ac..9d90683a4 100644 --- a/Scripts/Mobiles/Townfolk/TownCrier.cs +++ b/Scripts/Mobiles/Townfolk/TownCrier.cs @@ -384,8 +384,7 @@ namespace Server.Mobiles if ( m_Entries == null && GlobalTownCrierEntryList.Instance.IsEmpty ) { - if ( m_AutoShoutTimer != null ) - m_AutoShoutTimer.Stop(); + m_AutoShoutTimer?.Stop(); m_AutoShoutTimer = null; } @@ -397,8 +396,7 @@ namespace Server.Mobiles if ( tce == null ) { - if ( m_AutoShoutTimer != null ) - m_AutoShoutTimer.Stop(); + m_AutoShoutTimer?.Stop(); m_AutoShoutTimer = null; } @@ -418,8 +416,7 @@ namespace Server.Mobiles if ( index < 0 || index >= tce.Lines.Length ) { - if ( m_NewsTimer != null ) - m_NewsTimer.Stop(); + m_NewsTimer?.Stop(); m_NewsTimer = null; } diff --git a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs index 56ee430b9..c3ad9546c 100644 --- a/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs +++ b/Scripts/Mobiles/Vendors/NPC/AnimalTrainer.cs @@ -230,8 +230,7 @@ namespace Server.Mobiles from.Stabled.Remove( pet ); - if ( from is PlayerMobile ) - ((PlayerMobile)from).AutoStabled.Remove( pet ); + (@from as PlayerMobile)?.AutoStabled.Remove( pet ); } else { @@ -374,8 +373,7 @@ namespace Server.Mobiles from.Stabled.RemoveAt( i ); - if ( from is PlayerMobile ) - ((PlayerMobile)from).AutoStabled.Remove( pet ); + (@from as PlayerMobile)?.AutoStabled.Remove( pet ); --i; diff --git a/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs b/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs index 40fa1f2b6..4cf7ebff9 100644 --- a/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs +++ b/Scripts/Mobiles/Vendors/NPC/CustomHairstylist.cs @@ -515,8 +515,7 @@ namespace Server.Mobiles { ChangeHairstyleEntry entry = m_Entries[index]; - if ( m_From is PlayerMobile ) - ((PlayerMobile)m_From).SetHairMods( -1, -1 ); + (m_From as PlayerMobile)?.SetHairMods( -1, -1 ); int hairID = m_From.HairItemID; int facialHairID = m_From.FacialHairItemID; diff --git a/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs index 2defb8586..51008f829 100644 --- a/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Scripts/Mobiles/Vendors/PlayerBarkeeper.cs @@ -160,11 +160,9 @@ namespace Server.Mobiles get => m_House; set { - if ( m_House != null ) - m_House.PlayerBarkeepers.Remove( this ); + m_House?.PlayerBarkeepers.Remove( this ); - if ( value != null ) - value.PlayerBarkeepers.Add( this ); + value?.PlayerBarkeepers.Add( this ); m_House = value; } @@ -200,8 +198,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); } public override void InitBody() @@ -215,8 +212,7 @@ namespace Server.Mobiles Container pack = Backpack; - if ( pack != null ) - pack.Delete(); + pack?.Delete(); } public PlayerBarkeeper( Mobile owner, BaseHouse house ) : base( "the barkeeper" ) @@ -246,8 +242,7 @@ namespace Server.Mobiles if ( index < 0 || index >= tce.Lines.Length ) { - if ( m_NewsTimer != null ) - m_NewsTimer.Stop(); + m_NewsTimer?.Stop(); m_NewsTimer = null; } @@ -304,10 +299,7 @@ namespace Server.Mobiles { BarkeeperRumor rumor = m_Rumors[i]; - if ( rumor == null ) - continue; - - string keyword = rumor.Keyword; + string keyword = rumor?.Keyword; if ( keyword == null || (keyword = keyword.Trim()).Length == 0 ) continue; diff --git a/Scripts/Mobiles/Vendors/PlayerVendor.cs b/Scripts/Mobiles/Vendors/PlayerVendor.cs index bf2c4d794..962c75e09 100644 --- a/Scripts/Mobiles/Vendors/PlayerVendor.cs +++ b/Scripts/Mobiles/Vendors/PlayerVendor.cs @@ -193,10 +193,7 @@ namespace Server.Mobiles PlayerVendor pv = RootParent as PlayerVendor; - if ( pv == null ) - return; - - VendorItem vi = pv.GetVendorItem( item ); + VendorItem vi = pv?.GetVendorItem( item ); if ( vi == null ) return; @@ -215,10 +212,7 @@ namespace Server.Mobiles PlayerVendor pv = RootParent as PlayerVendor; - if ( pv == null ) - return; - - VendorItem vi = pv.GetVendorItem( item ); + VendorItem vi = pv?.GetVendorItem( item ); if ( vi?.Description != null && vi.Description.Length > 0 ) list.Add( 1043305, vi.Description ); //
Seller's Description:
"~1_DESC~" @@ -558,11 +552,9 @@ namespace Server.Mobiles get => m_House; set { - if ( m_House != null ) - m_House.PlayerVendors.Remove( this ); + m_House?.PlayerVendors.Remove( this ); - if ( value != null ) - value.PlayerVendors.Add( this ); + value?.PlayerVendors.Add( this ); m_House = value; } @@ -753,8 +745,7 @@ namespace Server.Mobiles House = null; - if ( Placeholder != null ) - Placeholder.Delete(); + Placeholder?.Delete(); } public override bool IsSnoop( Mobile from ) @@ -1234,8 +1225,7 @@ namespace Server.Mobiles public void Return() { - if ( Placeholder != null ) - Placeholder.Delete(); + Placeholder?.Delete(); } public override void GetContextMenuEntries( Mobile from, List list ) diff --git a/Scripts/Mobiles/Vendors/RentedVendor.cs b/Scripts/Mobiles/Vendors/RentedVendor.cs index d4e8a373f..5faf82ab7 100644 --- a/Scripts/Mobiles/Vendors/RentedVendor.cs +++ b/Scripts/Mobiles/Vendors/RentedVendor.cs @@ -128,10 +128,7 @@ namespace Server.Mobiles { get { - if ( House != null ) - return House.Owner; - - return null; + return House?.Owner; } } diff --git a/Scripts/Mobiles/Vendors/VendorInventory.cs b/Scripts/Mobiles/Vendors/VendorInventory.cs index 589d23ceb..9466034c8 100644 --- a/Scripts/Mobiles/Vendors/VendorInventory.cs +++ b/Scripts/Mobiles/Vendors/VendorInventory.cs @@ -83,8 +83,7 @@ namespace Server.Mobiles Items.Clear(); Gold = 0; - if ( House != null ) - House.VendorInventories.Remove( this ); + House?.VendorInventories.Remove( this ); m_ExpireTimer.Stop(); } diff --git a/Scripts/Multis/BaseHouse.cs b/Scripts/Multis/BaseHouse.cs index 6ee4ea8bb..3ddef6c50 100644 --- a/Scripts/Multis/BaseHouse.cs +++ b/Scripts/Multis/BaseHouse.cs @@ -235,8 +235,7 @@ namespace Server.Multis if ( DynamicDecay.Enabled ) ResetDynamicDecay(); - if ( m_Sign != null ) - m_Sign.InvalidateProperties(); + m_Sign?.InvalidateProperties(); return ( oldLevel > DecayLevel.LikeNew ); } @@ -542,8 +541,7 @@ namespace Server.Multis { RelocatedEntities.Clear(); - if ( MovingCrate != null ) - MovingCrate.Hide(); + MovingCrate?.Hide(); if ( m_Trash != null ) { @@ -676,8 +674,7 @@ namespace Server.Multis { List list = new List(); - if ( MovingCrate != null ) - MovingCrate.Hide(); + MovingCrate?.Hide(); if ( m_Trash != null && m_Trash.Map != Map.Internal ) list.Add( m_Trash ); @@ -1293,8 +1290,7 @@ namespace Server.Multis public virtual void UpdateRegion() { - if ( m_Region != null ) - m_Region.Unregister(); + m_Region?.Unregister(); if ( Map != null ) { @@ -1917,8 +1913,7 @@ namespace Server.Multis SetLockdown( item, false ); //TidyItemList( m_LockDowns ); - if ( item is RewardBrazier ) - ((RewardBrazier) item).TurnOff(); + (item as RewardBrazier)?.TurnOff(); } else if ( IsSecure( item ) ) { @@ -2824,8 +2819,7 @@ namespace Server.Multis m_Owner.Delta( MobileDelta.Noto ); } - if ( m_Sign != null ) - m_Sign.InvalidateProperties(); + m_Sign?.InvalidateProperties(); } } @@ -2849,8 +2843,7 @@ namespace Server.Multis if ( !m_Public ) // Privatizing the house, change to brass sign ChangeSignType( 0xBD2 ); - if ( m_Sign != null ) - m_Sign.InvalidateProperties(); + m_Sign?.InvalidateProperties(); } } } @@ -3073,11 +3066,9 @@ namespace Server.Multis m_Region = null; } - if ( m_Sign != null ) - m_Sign.Delete(); + m_Sign?.Delete(); - if ( m_Trash != null ) - m_Trash.Delete(); + m_Trash?.Delete(); if ( m_Doors != null ) { @@ -3085,8 +3076,7 @@ namespace Server.Multis { Item item = (Item)m_Doors[i]; - if ( item != null ) - item.Delete(); + item?.Delete(); } m_Doors.Clear(); @@ -3199,8 +3189,7 @@ namespace Server.Multis foreach ( VendorInventory inventory in inventories ) inventory.Delete(); - if ( MovingCrate != null ) - MovingCrate.Delete(); + MovingCrate?.Delete(); KillVendors(); diff --git a/Scripts/Multis/Boats/BaseBoat.cs b/Scripts/Multis/Boats/BaseBoat.cs index 2f0bb3e40..2b0f79d95 100644 --- a/Scripts/Multis/Boats/BaseBoat.cs +++ b/Scripts/Multis/Boats/BaseBoat.cs @@ -110,7 +110,9 @@ namespace Server.Multis [CommandProperty( AccessLevel.GameMaster )] public string ShipName{ get => m_ShipName; - set{ m_ShipName = value; if ( m_TillerMan != null ) m_TillerMan.InvalidateProperties(); } } + set{ m_ShipName = value; + m_TillerMan?.InvalidateProperties(); + } } [CommandProperty( AccessLevel.GameMaster )] public BoatOrder Order{ get => m_Order; @@ -129,7 +131,9 @@ namespace Server.Multis [CommandProperty( AccessLevel.GameMaster )] public DateTime TimeOfDecay{ get => m_DecayTime; - set{ m_DecayTime = value; if ( m_TillerMan != null ) m_TillerMan.InvalidateProperties(); } } + set{ m_DecayTime = value; + m_TillerMan?.InvalidateProperties(); + } } public int Status { @@ -366,23 +370,17 @@ namespace Server.Multis public override void OnAfterDelete() { - if ( m_TillerMan != null ) - m_TillerMan.Delete(); + m_TillerMan?.Delete(); - if ( m_Hold != null ) - m_Hold.Delete(); + m_Hold?.Delete(); - if ( m_PPlank != null ) - m_PPlank.Delete(); + m_PPlank?.Delete(); - if ( m_SPlank != null ) - m_SPlank.Delete(); + m_SPlank?.Delete(); - if ( m_TurnTimer != null ) - m_TurnTimer.Stop(); + m_TurnTimer?.Stop(); - if ( m_MoveTimer != null ) - m_MoveTimer.Stop(); + m_MoveTimer?.Stop(); m_Instances.Remove( this ); } @@ -490,8 +488,7 @@ namespace Server.Multis { m_DecayTime = DateTime.UtcNow + BoatDecayDelay; - if ( m_TillerMan != null ) - m_TillerMan.InvalidateProperties(); + m_TillerMan?.InvalidateProperties(); } private class DecayTimer : Timer @@ -517,8 +514,7 @@ namespace Server.Multis { m_Boat.Location = new Point3D( m_Boat.X, m_Boat.Y, m_Boat.Z - 1 ); - if ( m_Boat.TillerMan != null ) - m_Boat.TillerMan.Say( 1007168 + m_Count ); + m_Boat.TillerMan?.Say( 1007168 + m_Count ); ++m_Count; } @@ -549,8 +545,8 @@ namespace Server.Multis if ( m_Anchored ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501445 ); // Ar, the anchor was already dropped sir. + if ( message ) + m_TillerMan?.Say( 501445 ); // Ar, the anchor was already dropped sir. return false; } @@ -559,8 +555,8 @@ namespace Server.Multis m_Anchored = true; - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501444 ); // Ar, anchor dropped sir. + if ( message ) + m_TillerMan?.Say( 501444 ); // Ar, anchor dropped sir. return true; } @@ -572,16 +568,16 @@ namespace Server.Multis if ( !m_Anchored ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501447 ); // Ar, the anchor has not been dropped sir. + if ( message ) + m_TillerMan?.Say( 501447 ); // Ar, the anchor has not been dropped sir. return false; } m_Anchored = false; - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501446 ); // Ar, anchor raised sir. + if ( message ) + m_TillerMan?.Say( 501446 ); // Ar, anchor raised sir. return true; } @@ -598,8 +594,7 @@ namespace Server.Multis if ( StartMove( dir, speed, clientSpeed, interval, false, true ) ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 501429 ); // Aye aye sir. + m_TillerMan?.Say( 501429 ); // Aye aye sir. return true; } @@ -618,8 +613,7 @@ namespace Server.Multis if ( StartMove( dir, speed, 0x1, interval, true, true ) ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 501429 ); // Aye aye sir. + m_TillerMan?.Say( 501429 ); // Aye aye sir. return true; } @@ -634,14 +628,12 @@ namespace Server.Multis if ( from.AccessLevel < AccessLevel.GameMaster && from != m_Owner ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( Utility.Random( 1042876, 4 ) ); // Arr, don't do that! | Arr, leave me alone! | Arr, watch what thour'rt doing, matey! | Arr! Do that again and I’ll throw ye overhead! + m_TillerMan?.Say( Utility.Random( 1042876, 4 ) ); // Arr, don't do that! | Arr, leave me alone! | Arr, watch what thour'rt doing, matey! | Arr! Do that again and I’ll throw ye overhead! return; } - if ( m_TillerMan != null ) - m_TillerMan.Say( 502580 ); // What dost thou wish to name thy ship? + m_TillerMan?.Say( 502580 ); // What dost thou wish to name thy ship? from.Prompt = new RenameBoatPrompt( this ); } @@ -653,15 +645,13 @@ namespace Server.Multis if ( from.AccessLevel < AccessLevel.GameMaster && from != m_Owner ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! + m_TillerMan?.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! return; } else if ( !from.Alive ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 502582 ); // You appear to be dead. + m_TillerMan?.Say( 502582 ); // You appear to be dead. return; } @@ -771,15 +761,13 @@ namespace Server.Multis if ( e.Mobile.AccessLevel < AccessLevel.GameMaster && e.Mobile != m_Owner ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! + m_TillerMan?.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! return; } else if ( !e.Mobile.Alive ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 502582 ); // You appear to be dead. + m_TillerMan?.Say( 502582 ); // You appear to be dead. return; } @@ -805,8 +793,7 @@ namespace Server.Multis if ( m_ShipName == newName ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 502531 ); // Yes, sir. + m_TillerMan?.Say( 502531 ); // Yes, sir. return; } @@ -815,8 +802,10 @@ namespace Server.Multis if ( m_TillerMan != null && m_ShipName != null ) m_TillerMan.Say( 1042885, m_ShipName ); // This ship is now called the ~1_NEW_SHIP_NAME~. - else if ( m_TillerMan != null ) - m_TillerMan.Say( 502534 ); // This ship now has no name. + else + { + m_TillerMan?.Say( 502534 ); // This ship now has no name. + } } public void RemoveName( Mobile m ) @@ -826,31 +815,27 @@ namespace Server.Multis if ( m.AccessLevel < AccessLevel.GameMaster && m != m_Owner ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! + m_TillerMan?.Say( 1042880 ); // Arr! Only the owner of the ship may change its name! return; } else if ( !m.Alive ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 502582 ); // You appear to be dead. + m_TillerMan?.Say( 502582 ); // You appear to be dead. return; } if ( m_ShipName == null ) { - if ( m_TillerMan != null ) - m_TillerMan.Say( 502526 ); // Ar, this ship has no name. + m_TillerMan?.Say( 502526 ); // Ar, this ship has no name. return; } ShipName = null; - if ( m_TillerMan != null ) - m_TillerMan.Say( 502534 ); // This ship now has no name. + m_TillerMan?.Say( 502534 ); // This ship now has no name. } public void GiveName( Mobile m ) @@ -882,13 +867,11 @@ namespace Server.Multis if ( map is BlankMap ) { - if ( TillerMan != null ) - TillerMan.Say( 502575 ); // Ar, that is not a map, tis but a blank piece of paper! + TillerMan?.Say( 502575 ); // Ar, that is not a map, tis but a blank piece of paper! } else if ( map.Pins.Count == 0 ) { - if ( TillerMan != null ) - TillerMan.Say( 502576 ); // Arrrr, this map has no course on it! + TillerMan?.Say( 502576 ); // Arrrr, this map has no course on it! } else { @@ -897,8 +880,7 @@ namespace Server.Multis MapItem = map; NextNavPoint = -1; - if ( TillerMan != null ) - TillerMan.Say( 502577 ); // A map! + TillerMan?.Say( 502577 ); // A map! } } @@ -936,8 +918,8 @@ namespace Server.Multis if ( number == -1 ) { - if ( message && TillerMan != null ) - TillerMan.Say( 1042551 ); // I don't see that navpoint, sir. + if ( message ) + TillerMan?.Say( 1042551 ); // I don't see that navpoint, sir. return false; } @@ -953,29 +935,29 @@ namespace Server.Multis if ( Anchored ) { - if ( message && TillerMan != null ) - TillerMan.Say( 501419 ); // Ar, the anchor is down sir! + if ( message ) + TillerMan?.Say( 501419 ); // Ar, the anchor is down sir! return false; } else if ( MapItem == null || MapItem.Deleted ) { - if ( message && TillerMan != null ) - TillerMan.Say( 502513 ); // I have seen no map, sir. + if ( message ) + TillerMan?.Say( 502513 ); // I have seen no map, sir. return false; } else if ( Map != MapItem.Map || !Contains( MapItem.GetWorldLocation() ) ) { - if ( message && TillerMan != null ) - TillerMan.Say( 502514 ); // The map is too far away from me, sir. + if ( message ) + TillerMan?.Say( 502514 ); // The map is too far away from me, sir. return false; } else if ( ( Map != Map.Trammel && Map != Map.Felucca ) || NextNavPoint < 0 || NextNavPoint >= MapItem.Pins.Count ) { - if ( message && TillerMan != null ) - TillerMan.Say( 1042551 ); // I don't see that navpoint, sir. + if ( message ) + TillerMan?.Say( 1042551 ); // I don't see that navpoint, sir. return false; } @@ -983,14 +965,13 @@ namespace Server.Multis Speed = FastSpeed; Order = single ? BoatOrder.Single : BoatOrder.Course; - if ( m_MoveTimer != null ) - m_MoveTimer.Stop(); + m_MoveTimer?.Stop(); m_MoveTimer = new MoveTimer( this, FastInterval, false ); m_MoveTimer.Start(); - if ( message && TillerMan != null ) - TillerMan.Say( 501429 ); // Aye aye sir. + if ( message ) + TillerMan?.Say( 501429 ); // Aye aye sir. return true; } @@ -1082,14 +1063,13 @@ namespace Server.Multis m_MoveTimer = null; } - if ( m_TurnTimer != null ) - m_TurnTimer.Stop(); + m_TurnTimer?.Stop(); m_TurnTimer = new TurnTimer( this, offset ); m_TurnTimer.Start(); - if ( message && TillerMan != null ) - TillerMan.Say( 501429 ); // Aye aye sir. + if ( message ) + TillerMan?.Say( 501429 ); // Aye aye sir. return true; } @@ -1153,8 +1133,8 @@ namespace Server.Multis if ( m_Anchored ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501419 ); // Ar, the anchor is down sir! + if ( message ) + m_TillerMan?.Say( 501419 ); // Ar, the anchor is down sir! return false; } @@ -1164,8 +1144,7 @@ namespace Server.Multis m_ClientSpeed = clientSpeed; m_Order = BoatOrder.Move; - if ( m_MoveTimer != null ) - m_MoveTimer.Stop(); + m_MoveTimer?.Stop(); m_MoveTimer = new MoveTimer( this, interval, single ); m_MoveTimer.Start(); @@ -1180,8 +1159,8 @@ namespace Server.Multis if ( m_MoveTimer == null ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501443 ); // Er, the ship is not moving sir. + if ( message ) + m_TillerMan?.Say( 501443 ); // Er, the ship is not moving sir. return false; } @@ -1192,8 +1171,8 @@ namespace Server.Multis m_MoveTimer.Stop(); m_MoveTimer = null; - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501429 ); // Aye aye sir. + if ( message ) + m_TillerMan?.Say( 501429 ); // Aye aye sir. return true; } @@ -1363,22 +1342,22 @@ namespace Server.Multis } else if ( MapItem == null || MapItem.Deleted ) { - if ( message && TillerMan != null ) - TillerMan.Say( 502513 ); // I have seen no map, sir. + if ( message ) + TillerMan?.Say( 502513 ); // I have seen no map, sir. return false; } else if ( Map != MapItem.Map || !Contains( MapItem.GetWorldLocation() ) ) { - if ( message && TillerMan != null ) - TillerMan.Say( 502514 ); // The map is too far away from me, sir. + if ( message ) + TillerMan?.Say( 502514 ); // The map is too far away from me, sir. return false; } else if ( ( Map != Map.Trammel && Map != Map.Felucca ) || NextNavPoint < 0 || NextNavPoint >= MapItem.Pins.Count ) { - if ( message && TillerMan != null ) - TillerMan.Say( 1042551 ); // I don't see that navpoint, sir. + if ( message ) + TillerMan?.Say( 1042551 ); // I don't see that navpoint, sir. return false; } @@ -1394,8 +1373,8 @@ namespace Server.Multis if ( maxSpeed == 0 ) { - if ( message && Order == BoatOrder.Single && TillerMan != null ) - TillerMan.Say( 1042874, (NextNavPoint + 1).ToString() ); // We have arrived at nav point ~1_POINT_NUM~ , sir. + if ( message && Order == BoatOrder.Single ) + TillerMan?.Say( 1042874, (NextNavPoint + 1).ToString() ); // We have arrived at nav point ~1_POINT_NUM~ , sir. if ( NextNavPoint + 1 < MapItem.Pins.Count ) { @@ -1403,8 +1382,8 @@ namespace Server.Multis if ( Order == BoatOrder.Course ) { - if ( message && TillerMan != null ) - TillerMan.Say( 1042875, (NextNavPoint + 1).ToString() ); // Heading to nav point ~1_POINT_NUM~, sir. + if ( message ) + TillerMan?.Say( 1042875, (NextNavPoint + 1).ToString() ); // Heading to nav point ~1_POINT_NUM~, sir. return true; } @@ -1415,8 +1394,8 @@ namespace Server.Multis { NextNavPoint = -1; - if ( message && Order == BoatOrder.Course && TillerMan != null ) - TillerMan.Say( 502515 ); // The course is completed, sir. + if ( message && Order == BoatOrder.Course ) + TillerMan?.Say( 502515 ); // The course is completed, sir. return false; } @@ -1443,8 +1422,8 @@ namespace Server.Multis if ( m_Anchored ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501419 ); // Ar, the anchor is down sir! + if ( message ) + m_TillerMan?.Say( 501419 ); // Ar, the anchor is down sir! return false; } @@ -1459,8 +1438,8 @@ namespace Server.Multis { if ( i == 1 ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501424 ); // Ar, we've stopped sir. + if ( message ) + m_TillerMan?.Say( 501424 ); // Ar, we've stopped sir. return false; } @@ -1498,8 +1477,8 @@ namespace Server.Multis { if ( !CanFit( new Point3D( newX + (j * rx), newY + (j * ry), Z ), Map, ItemID ) ) { - if ( message && m_TillerMan != null ) - m_TillerMan.Say( 501424 ); // Ar, we've stopped sir. + if ( message ) + m_TillerMan?.Say( 501424 ); // Ar, we've stopped sir. return false; } @@ -1658,17 +1637,13 @@ namespace Server.Multis m_Facing = facing; - if ( m_TillerMan != null ) - m_TillerMan.SetFacing( facing ); + m_TillerMan?.SetFacing( facing ); - if ( m_Hold != null ) - m_Hold.SetFacing( facing ); + m_Hold?.SetFacing( facing ); - if ( m_PPlank != null ) - m_PPlank.SetFacing( facing ); + m_PPlank?.SetFacing( facing ); - if ( m_SPlank != null ) - m_SPlank.SetFacing( facing ); + m_SPlank?.SetFacing( facing ); List toMove = GetMovingEntities(); diff --git a/Scripts/Multis/Boats/Hold.cs b/Scripts/Multis/Boats/Hold.cs index 5a6111d10..a39551852 100644 --- a/Scripts/Multis/Boats/Hold.cs +++ b/Scripts/Multis/Boats/Hold.cs @@ -62,21 +62,18 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Boat != null ) - m_Boat.Delete(); + m_Boat?.Delete(); } public override void OnDoubleClick( Mobile from ) { if ( m_Boat == null || !m_Boat.Contains( from ) ) { - if ( m_Boat.TillerMan != null ) - m_Boat.TillerMan.Say( 502490 ); // You must be on the ship to open the hold. + m_Boat.TillerMan?.Say( 502490 ); // You must be on the ship to open the hold. } else if ( m_Boat.IsMoving ) { - if ( m_Boat.TillerMan != null ) - m_Boat.TillerMan.Say( 502491 ); // I can not open the hold while the ship is moving. + m_Boat.TillerMan?.Say( 502491 ); // I can not open the hold while the ship is moving. } else { diff --git a/Scripts/Multis/Boats/Plank.cs b/Scripts/Multis/Boats/Plank.cs index a5f0972da..f0d34d213 100644 --- a/Scripts/Multis/Boats/Plank.cs +++ b/Scripts/Multis/Boats/Plank.cs @@ -125,8 +125,7 @@ namespace Server.Items if ( IsOpen || Deleted ) return; - if ( m_CloseTimer != null ) - m_CloseTimer.Stop(); + m_CloseTimer?.Stop(); m_CloseTimer = new CloseTimer( this ); m_CloseTimer.Start(); @@ -139,8 +138,7 @@ namespace Server.Items case 0x3E85: ItemID = 0x3E84; break; } - if ( m_Boat != null ) - m_Boat.Refresh(); + m_Boat?.Refresh(); } public override bool OnMoveOver( Mobile from ) @@ -230,8 +228,7 @@ namespace Server.Items if ( !IsOpen || !CanClose() || Deleted ) return; - if ( m_CloseTimer != null ) - m_CloseTimer.Stop(); + m_CloseTimer?.Stop(); m_CloseTimer = null; @@ -243,8 +240,7 @@ namespace Server.Items case 0x3E84: ItemID = 0x3E85; break; } - if ( m_Boat != null ) - m_Boat.Refresh(); + m_Boat?.Refresh(); } public override void OnDoubleClickDead( Mobile from ) diff --git a/Scripts/Multis/Boats/TillerMan.cs b/Scripts/Multis/Boats/TillerMan.cs index 1172893da..f7b2e19d9 100644 --- a/Scripts/Multis/Boats/TillerMan.cs +++ b/Scripts/Multis/Boats/TillerMan.cs @@ -65,8 +65,10 @@ namespace Server.Items { if ( m_Boat != null && m_Boat.Contains( from ) ) m_Boat.BeginRename( from ); - else if ( m_Boat != null ) - m_Boat.BeginDryDock( from ); + else + { + m_Boat?.BeginDryDock( @from ); + } } public override bool OnDragDrop( Mobile from, Item dropped ) @@ -81,8 +83,7 @@ namespace Server.Items public override void OnAfterDelete() { - if ( m_Boat != null ) - m_Boat.Delete(); + m_Boat?.Delete(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Multis/Camps/BaseCamp.cs b/Scripts/Multis/Camps/BaseCamp.cs index 80ab833d2..4497304ba 100644 --- a/Scripts/Multis/Camps/BaseCamp.cs +++ b/Scripts/Multis/Camps/BaseCamp.cs @@ -52,8 +52,7 @@ namespace Server.Multis if ( Deleted ) return; - if ( m_DecayTimer != null ) - m_DecayTimer.Stop(); + m_DecayTimer?.Stop(); if ( setDecayTime ) m_DecayTime = DateTime.UtcNow + DecayDelay; diff --git a/Scripts/Multis/HouseFoundation.cs b/Scripts/Multis/HouseFoundation.cs index 49fc5aff4..cb2ff1326 100644 --- a/Scripts/Multis/HouseFoundation.cs +++ b/Scripts/Multis/HouseFoundation.cs @@ -124,11 +124,9 @@ namespace Server.Multis { base.OnAfterDelete(); - if ( m_SignHanger != null ) - m_SignHanger.Delete(); + m_SignHanger?.Delete(); - if ( m_Signpost != null ) - m_Signpost.Delete(); + m_Signpost?.Delete(); if ( m_Fixtures == null ) return; @@ -137,8 +135,7 @@ namespace Server.Multis { Item item = m_Fixtures[i]; - if ( item != null ) - item.Delete(); + item?.Delete(); } m_Fixtures.Clear(); @@ -152,11 +149,9 @@ namespace Server.Multis int y = Location.Y - oldLocation.Y; int z = Location.Z - oldLocation.Z; - if ( m_SignHanger != null ) - m_SignHanger.MoveToWorld( new Point3D( m_SignHanger.X + x, m_SignHanger.Y + y, m_SignHanger.Z + z ), Map ); + m_SignHanger?.MoveToWorld( new Point3D( m_SignHanger.X + x, m_SignHanger.Y + y, m_SignHanger.Z + z ), Map ); - if ( m_Signpost != null ) - m_Signpost.MoveToWorld( new Point3D( m_Signpost.X + x, m_Signpost.Y + y, m_Signpost.Z + z ), Map ); + m_Signpost?.MoveToWorld( new Point3D( m_Signpost.X + x, m_Signpost.Y + y, m_Signpost.Z + z ), Map ); if ( m_Fixtures == null ) return; @@ -589,8 +584,7 @@ namespace Server.Multis if ( CheckWall( mcl, x, y ) ) { - if ( m_Signpost != null ) - m_Signpost.Delete(); + m_Signpost?.Delete(); m_Signpost = null; } @@ -1696,8 +1690,7 @@ namespace Server.Multis if ( m_PacketCache == value ) return; - if ( m_PacketCache != null ) - m_PacketCache.Release(); + m_PacketCache?.Release(); m_PacketCache = value; } @@ -1788,8 +1781,7 @@ namespace Server.Multis { m_Revision = ++m_Foundation.LastRevision; - if ( m_PacketCache != null ) - m_PacketCache.Release(); + m_PacketCache?.Release(); m_PacketCache = null; } @@ -1797,8 +1789,7 @@ namespace Server.Multis public void SendGeneralInfoTo( NetState state ) { - if ( state != null ) - state.Send( new DesignStateGeneral( m_Foundation, this ) ); + state?.Send( new DesignStateGeneral( m_Foundation, this ) ); } public void SendDetailedInfoTo( NetState state ) @@ -2095,14 +2086,11 @@ namespace Server.Multis item.SendInfoTo( state ); } - if ( context.Foundation.Signpost != null ) - context.Foundation.Signpost.SendInfoTo( state ); + context.Foundation.Signpost?.SendInfoTo( state ); - if ( context.Foundation.SignHanger != null ) - context.Foundation.SignHanger.SendInfoTo( state ); + context.Foundation.SignHanger?.SendInfoTo( state ); - if ( context.Foundation.Sign != null ) - context.Foundation.Sign.SendInfoTo( state ); + context.Foundation.Sign?.SendInfoTo( state ); } } diff --git a/Scripts/Multis/MovingCrate.cs b/Scripts/Multis/MovingCrate.cs index 7b9b058ec..c567f196d 100644 --- a/Scripts/Multis/MovingCrate.cs +++ b/Scripts/Multis/MovingCrate.cs @@ -72,9 +72,9 @@ namespace Server.Multis // 2. Try to drop the item into an existing container foreach ( Item item in Items ) { - if ( item is PackingBox ) + if ( item is PackingBox packingBox ) { - Container box = (Container) item; + Container box = packingBox; List subItems = box.Items; if ( subItems.Count < MaxItemsPerSubcontainer ) @@ -216,8 +216,7 @@ namespace Server.Multis if ( House != null && House.MovingCrate == this ) House.MovingCrate = null; - if ( m_InternalizeTimer != null ) - m_InternalizeTimer.Stop(); + m_InternalizeTimer?.Stop(); } public override void Serialize( GenericWriter writer ) diff --git a/Scripts/Regions/HouseRegion.cs b/Scripts/Regions/HouseRegion.cs index 820bd8c10..e4dfd799d 100644 --- a/Scripts/Regions/HouseRegion.cs +++ b/Scripts/Regions/HouseRegion.cs @@ -109,11 +109,11 @@ namespace Server.Regions m.Location = m_House.BanLocation; m.SendLocalizedMessage( 1061637 ); // You are not allowed to access this. } - else if ( m_House is HouseFoundation ) + else { - HouseFoundation foundation = (HouseFoundation)m_House; + HouseFoundation foundation = m_House as HouseFoundation; - if ( foundation.Customizer != null && foundation.Customizer != m && m_House.IsInside( m ) ) + if ( foundation?.Customizer != null && foundation.Customizer != m && m_House.IsInside( m ) ) m.Location = m_House.BanLocation; } @@ -172,11 +172,11 @@ namespace Server.Regions from.SendLocalizedMessage( 1061637 ); // You are not allowed to access this. return false; } - else if ( m_House is HouseFoundation ) + else { - HouseFoundation foundation = (HouseFoundation)m_House; + HouseFoundation foundation = m_House as HouseFoundation; - if ( foundation.Customizer != null && foundation.Customizer != from && m_House.IsInside( newLocation, 16 ) ) + if ( foundation?.Customizer != null && foundation.Customizer != @from && m_House.IsInside( newLocation, 16 ) ) return false; } diff --git a/Scripts/Regions/Spawning/SpawnEntry.cs b/Scripts/Regions/Spawning/SpawnEntry.cs index ab9145074..35daa5fe9 100644 --- a/Scripts/Regions/Spawning/SpawnEntry.cs +++ b/Scripts/Regions/Spawning/SpawnEntry.cs @@ -261,8 +261,7 @@ namespace Server.Regions if ( Spawning ) { - if ( m_SpawnTimer != null ) - m_SpawnTimer.Stop(); + m_SpawnTimer?.Stop(); TimeSpan delay = m_NextSpawn - DateTime.UtcNow; m_SpawnTimer = Timer.DelayCall( delay > TimeSpan.Zero ? delay : TimeSpan.Zero, new TimerCallback( TimerCallback ) ); diff --git a/Scripts/Skills/Anatomy.cs b/Scripts/Skills/Anatomy.cs index b9809253b..0184d6b10 100644 --- a/Scripts/Skills/Anatomy.cs +++ b/Scripts/Skills/Anatomy.cs @@ -76,9 +76,9 @@ namespace Server.SkillHandlers targ.PrivateOverheadMessage( MessageType.Regular, 0x3B2, 1042666, from.NetState ); // You can not quite get a sense of their physical characteristics. } } - else if ( targeted is Item ) + else { - ((Item)targeted).SendLocalizedMessageTo( from, 500323, "" ); // Only living things have anatomies! + (targeted as Item)?.SendLocalizedMessageTo( @from, 500323, "" ); // Only living things have anatomies! } } } diff --git a/Scripts/Skills/AnimalTaming.cs b/Scripts/Skills/AnimalTaming.cs index 4e8f74fa3..603a30fcc 100644 --- a/Scripts/Skills/AnimalTaming.cs +++ b/Scripts/Skills/AnimalTaming.cs @@ -202,8 +202,7 @@ namespace Server.SkillHandlers creature.BardPacified = false; - if ( creature.AIObject != null ) - creature.AIObject.DoMove( creature.Direction ); + creature.AIObject?.DoMove( creature.Direction ); if ( from is PlayerMobile && !(( (PlayerMobile)from ).HonorActive || TransformationSpellHelper.UnderTransformation( from, typeof( EtherealVoyageSpell )))) creature.Combatant = from; diff --git a/Scripts/Skills/Discordance.cs b/Scripts/Skills/Discordance.cs index d7fc10f65..329081b20 100644 --- a/Scripts/Skills/Discordance.cs +++ b/Scripts/Skills/Discordance.cs @@ -117,8 +117,7 @@ namespace Server.SkillHandlers if ( ends && info.m_Ending && info.m_EndTime < DateTime.UtcNow ) { - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); info.Clear(); m_Table.Remove( targ ); diff --git a/Scripts/Skills/EvalInt.cs b/Scripts/Skills/EvalInt.cs index 3eb5b0ea4..93d3fd809 100644 --- a/Scripts/Skills/EvalInt.cs +++ b/Scripts/Skills/EvalInt.cs @@ -78,9 +78,9 @@ namespace Server.SkillHandlers targ.PrivateOverheadMessage( MessageType.Regular, 0x3B2, 1038166 + (body / 11), from.NetState ); // You cannot judge his/her/its mental abilities. } } - else if ( targeted is Item ) + else { - ((Item)targeted).SendLocalizedMessageTo( from, 500908, "" ); // It looks smarter than a rock, but dumber than a piece of wood. + (targeted as Item)?.SendLocalizedMessageTo( @from, 500908, "" ); // It looks smarter than a rock, but dumber than a piece of wood. } } } diff --git a/Scripts/Skills/RemoveTrap.cs b/Scripts/Skills/RemoveTrap.cs index 0b6819511..a7fc746f0 100644 --- a/Scripts/Skills/RemoveTrap.cs +++ b/Scripts/Skills/RemoveTrap.cs @@ -113,8 +113,8 @@ namespace Server.SkillHandlers from.SendLocalizedMessage( 502372 ); // You fail to disarm the trap... but you don't set it off } - if ( !isOwner && kit != null ) - kit.ConsumeCharge( from ); + if ( !isOwner ) + kit?.ConsumeCharge( @from ); } } else diff --git a/Scripts/Spells/Base/Spell.cs b/Scripts/Spells/Base/Spell.cs index 041f3a907..6e88b187f 100644 --- a/Scripts/Spells/Base/Spell.cs +++ b/Scripts/Spells/Base/Spell.cs @@ -96,8 +96,7 @@ namespace Server.Spells public void HarmfulSpell( Mobile m ) { - if ( m is BaseCreature ) - ((BaseCreature)m).OnHarmfulSpell( m_Caster ); + (m as BaseCreature)?.OnHarmfulSpell( m_Caster ); } public Spell( Mobile caster, Item scroll, SpellInfo info ) @@ -311,11 +310,9 @@ namespace Server.Spells scalar *= 2.0; // Double magery damage to monsters/animals if not AOS } - if ( target is BaseCreature ) - ((BaseCreature)target).AlterDamageScalarFrom( m_Caster, ref scalar ); + (target as BaseCreature)?.AlterDamageScalarFrom( m_Caster, ref scalar ); - if ( m_Caster is BaseCreature ) - ((BaseCreature)m_Caster).AlterDamageScalarTo( target, ref scalar ); + (m_Caster as BaseCreature)?.AlterDamageScalarTo( target, ref scalar ); if ( Core.SE ) scalar *= GetSlayerDamageScalar( target ); @@ -417,11 +414,9 @@ namespace Server.Spells OnDisturb( type, true ); - if ( m_CastTimer != null ) - m_CastTimer.Stop(); + m_CastTimer?.Stop(); - if ( m_AnimTimer != null ) - m_AnimTimer.Stop(); + m_AnimTimer?.Stop(); if ( Core.AOS && m_Caster.Player && type == DisturbType.Hurt ) DoHurtFizzle(); @@ -908,8 +903,7 @@ namespace Server.Spells m_Spell.m_State = SpellState.Sequencing; m_Spell.m_CastTimer = null; m_Spell.m_Caster.OnSpellCast( m_Spell ); - if ( m_Spell.m_Caster.Region != null ) - m_Spell.m_Caster.Region.OnSpellCast( m_Spell.m_Caster, m_Spell ); + m_Spell.m_Caster.Region?.OnSpellCast( m_Spell.m_Caster, m_Spell ); m_Spell.m_Caster.NextSpellTime = Core.TickCount + (int)m_Spell.GetCastRecovery().TotalMilliseconds; // Spell.NextSpellDelay; Target originalTarget = m_Spell.m_Caster.Target; diff --git a/Scripts/Spells/Base/SpellHelper.cs b/Scripts/Spells/Base/SpellHelper.cs index 55e410dfd..9d51b3271 100644 --- a/Scripts/Spells/Base/SpellHelper.cs +++ b/Scripts/Spells/Base/SpellHelper.cs @@ -924,8 +924,7 @@ namespace Server.Spells bool reflect = (target.MagicDamageAbsorb >= 0); - if ( target is BaseCreature ) - ((BaseCreature)target).CheckReflect( caster, ref reflect ); + (target as BaseCreature)?.CheckReflect( caster, ref reflect ); if ( target.MagicDamageAbsorb <= 0 ) { @@ -982,11 +981,9 @@ namespace Server.Spells if ( delay == TimeSpan.Zero ) { - if ( from is BaseCreature ) - ((BaseCreature)from).AlterSpellDamageTo( target, ref iDamage ); + (@from as BaseCreature)?.AlterSpellDamageTo( target, ref iDamage ); - if ( target is BaseCreature ) - ((BaseCreature)target).AlterSpellDamageFrom( from, ref iDamage ); + (target as BaseCreature)?.AlterSpellDamageFrom( @from, ref iDamage ); target.Damage( iDamage, from ); } @@ -1039,11 +1036,9 @@ namespace Server.Spells if ( delay == TimeSpan.Zero ) { - if ( from is BaseCreature ) - ((BaseCreature)from).AlterSpellDamageTo( target, ref iDamage ); + (@from as BaseCreature)?.AlterSpellDamageTo( target, ref iDamage ); - if ( target is BaseCreature ) - ((BaseCreature)target).AlterSpellDamageFrom( from, ref iDamage ); + (target as BaseCreature)?.AlterSpellDamageFrom( @from, ref iDamage ); WeightOverloading.DFA = dfa; @@ -1126,15 +1121,12 @@ namespace Server.Spells protected override void OnTick() { - if ( m_From is BaseCreature ) - ((BaseCreature)m_From).AlterSpellDamageTo( m_Target, ref m_Damage ); + (m_From as BaseCreature)?.AlterSpellDamageTo( m_Target, ref m_Damage ); - if ( m_Target is BaseCreature ) - ((BaseCreature)m_Target).AlterSpellDamageFrom( m_From, ref m_Damage ); + (m_Target as BaseCreature)?.AlterSpellDamageFrom( m_From, ref m_Damage ); m_Target.Damage( m_Damage ); - if ( m_Spell != null ) - m_Spell.RemoveDelayedDamageContext( m_Target ); + m_Spell?.RemoveDelayedDamageContext( m_Target ); } } @@ -1192,8 +1184,7 @@ namespace Server.Spells c.OnDamagedBySpell( m_From ); } - if ( m_Spell != null ) - m_Spell.RemoveDelayedDamageContext( m_Target ); + m_Spell?.RemoveDelayedDamageContext( m_Target ); } } diff --git a/Scripts/Spells/Bushido/Confidence.cs b/Scripts/Spells/Bushido/Confidence.cs index 48050d02a..8e55c9a4b 100644 --- a/Scripts/Spells/Bushido/Confidence.cs +++ b/Scripts/Spells/Bushido/Confidence.cs @@ -56,8 +56,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( m ); @@ -70,8 +69,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); @@ -106,8 +104,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_RegenTable[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new RegenTimer( m ); @@ -120,8 +117,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_RegenTable[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_RegenTable.Remove( m ); } diff --git a/Scripts/Spells/Bushido/CounterAttack.cs b/Scripts/Spells/Bushido/CounterAttack.cs index d8840a2c8..777e0d5b6 100644 --- a/Scripts/Spells/Bushido/CounterAttack.cs +++ b/Scripts/Spells/Bushido/CounterAttack.cs @@ -71,8 +71,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( m ); @@ -85,8 +84,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); diff --git a/Scripts/Spells/Bushido/Evasion.cs b/Scripts/Spells/Bushido/Evasion.cs index d098a4a02..ea8021f6a 100644 --- a/Scripts/Spells/Bushido/Evasion.cs +++ b/Scripts/Spells/Bushido/Evasion.cs @@ -181,8 +181,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); t = new InternalTimer( m, GetEvadeDuration( m ) ); @@ -195,8 +194,7 @@ namespace Server.Spells.Bushido { Timer t = (Timer)m_Table[m]; - if ( t != null ) - t.Stop(); + t?.Stop(); m_Table.Remove( m ); diff --git a/Scripts/Spells/Bushido/HonorableExecution.cs b/Scripts/Spells/Bushido/HonorableExecution.cs index 4cc6bbce7..ebe643dbd 100644 --- a/Scripts/Spells/Bushido/HonorableExecution.cs +++ b/Scripts/Spells/Bushido/HonorableExecution.cs @@ -35,8 +35,7 @@ namespace Server.Spells.Bushido { info.Clear(); - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); } if ( !defender.Alive ) @@ -110,8 +109,7 @@ namespace Server.Spells.Bushido info.Clear(); - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( target ); } diff --git a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs index 8ab16722b..00ac14e29 100644 --- a/Scripts/Spells/Chivalry/ConsecrateWeapon.cs +++ b/Scripts/Spells/Chivalry/ConsecrateWeapon.cs @@ -69,8 +69,7 @@ namespace Server.Spells.Chivalry Timer t = (Timer)m_Table[weapon]; - if ( t != null ) - t.Stop(); + t?.Stop(); weapon.Consecrated = true; diff --git a/Scripts/Spells/Chivalry/DivineFury.cs b/Scripts/Spells/Chivalry/DivineFury.cs index 1b0edbb31..dfaccc104 100644 --- a/Scripts/Spells/Chivalry/DivineFury.cs +++ b/Scripts/Spells/Chivalry/DivineFury.cs @@ -36,8 +36,7 @@ namespace Server.Spells.Chivalry Timer t = (Timer)m_Table[Caster]; - if ( t != null ) - t.Stop(); + t?.Stop(); int delay = ComputePowerValue( 10 ); diff --git a/Scripts/Spells/Chivalry/EnemyOfOne.cs b/Scripts/Spells/Chivalry/EnemyOfOne.cs index 4dc53f395..8b31d128a 100644 --- a/Scripts/Spells/Chivalry/EnemyOfOne.cs +++ b/Scripts/Spells/Chivalry/EnemyOfOne.cs @@ -35,8 +35,7 @@ namespace Server.Spells.Chivalry Timer t = (Timer)m_Table[Caster]; - if ( t != null ) - t.Stop(); + t?.Stop(); double delay = (double)ComputePowerValue( 1 ) / 60; diff --git a/Scripts/Spells/Eighth/EnergyVortex.cs b/Scripts/Spells/Eighth/EnergyVortex.cs index cea656e3a..a65cb7679 100644 --- a/Scripts/Spells/Eighth/EnergyVortex.cs +++ b/Scripts/Spells/Eighth/EnergyVortex.cs @@ -92,8 +92,7 @@ namespace Server.Spells.Eighth protected override void OnTargetFinish( Mobile from ) { - if ( m_Owner != null ) - m_Owner.FinishSequence(); + m_Owner?.FinishSequence(); } } } diff --git a/Scripts/Spells/Fifth/BladeSpirits.cs b/Scripts/Spells/Fifth/BladeSpirits.cs index eeba5e125..d37420032 100644 --- a/Scripts/Spells/Fifth/BladeSpirits.cs +++ b/Scripts/Spells/Fifth/BladeSpirits.cs @@ -99,8 +99,7 @@ namespace Server.Spells.Fifth protected override void OnTargetFinish( Mobile from ) { - if ( m_Owner != null ) - m_Owner.FinishSequence(); + m_Owner?.FinishSequence(); } } } diff --git a/Scripts/Spells/Fifth/Incognito.cs b/Scripts/Spells/Fifth/Incognito.cs index 23b766d5d..4b06639cd 100644 --- a/Scripts/Spells/Fifth/Incognito.cs +++ b/Scripts/Spells/Fifth/Incognito.cs @@ -171,8 +171,7 @@ namespace Server.Spells.Fifth { if ( !m_Owner.CanBeginAction( typeof( IncognitoSpell ) ) ) { - if ( m_Owner is PlayerMobile ) - ((PlayerMobile)m_Owner).SetHairMods( -1, -1 ); + (m_Owner as PlayerMobile)?.SetHairMods( -1, -1 ); m_Owner.BodyMod = 0; m_Owner.HueMod = -1; diff --git a/Scripts/Spells/Fifth/PoisonField.cs b/Scripts/Spells/Fifth/PoisonField.cs index 407774c9d..999d35bd6 100644 --- a/Scripts/Spells/Fifth/PoisonField.cs +++ b/Scripts/Spells/Fifth/PoisonField.cs @@ -114,8 +114,7 @@ namespace Server.Spells.Fifth { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public InternalItem( Serial serial ) : base( serial ) @@ -187,8 +186,7 @@ namespace Server.Spells.Fifth if ( SpellHelper.CanRevealCaster( m ) ) m_Caster.RevealingAction(); - if ( m is BaseCreature ) - ( (BaseCreature) m ).OnHarmfulSpell( m_Caster ); + (m as BaseCreature)?.OnHarmfulSpell( m_Caster ); } public override bool OnMoveOver( Mobile m ) diff --git a/Scripts/Spells/First/Clumsy.cs b/Scripts/Spells/First/Clumsy.cs index ec4173fef..00d29a1f7 100644 --- a/Scripts/Spells/First/Clumsy.cs +++ b/Scripts/Spells/First/Clumsy.cs @@ -38,8 +38,7 @@ namespace Server.Spells.First SpellHelper.AddStatCurse( Caster, m, StatType.Dex ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/First/Feeblemind.cs b/Scripts/Spells/First/Feeblemind.cs index 8f90c4f86..6f0a184a4 100644 --- a/Scripts/Spells/First/Feeblemind.cs +++ b/Scripts/Spells/First/Feeblemind.cs @@ -38,8 +38,7 @@ namespace Server.Spells.First SpellHelper.AddStatCurse( Caster, m, StatType.Int ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/First/Weaken.cs b/Scripts/Spells/First/Weaken.cs index 19983fd08..411523855 100644 --- a/Scripts/Spells/First/Weaken.cs +++ b/Scripts/Spells/First/Weaken.cs @@ -38,8 +38,7 @@ namespace Server.Spells.First SpellHelper.AddStatCurse( Caster, m, StatType.Str ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/Fourth/Curse.cs b/Scripts/Spells/Fourth/Curse.cs index 51d5dae4e..3cd89e956 100644 --- a/Scripts/Spells/Fourth/Curse.cs +++ b/Scripts/Spells/Fourth/Curse.cs @@ -67,8 +67,7 @@ namespace Server.Spells.Fourth m.UpdateResistances(); } - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/Fourth/FireField.cs b/Scripts/Spells/Fourth/FireField.cs index 5a2cc3502..37b3cdafe 100644 --- a/Scripts/Spells/Fourth/FireField.cs +++ b/Scripts/Spells/Fourth/FireField.cs @@ -127,8 +127,7 @@ namespace Server.Spells.Fourth { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public FireFieldItem( Serial serial ) : base( serial ) @@ -201,8 +200,7 @@ namespace Server.Spells.Fourth AOS.Damage( m, m_Caster, damage, 0, 100, 0, 0, 0 ); m.PlaySound( 0x208 ); - if ( m is BaseCreature ) - ((BaseCreature) m).OnHarmfulSpell( m_Caster ); + (m as BaseCreature)?.OnHarmfulSpell( m_Caster ); } return true; @@ -281,8 +279,7 @@ namespace Server.Spells.Fourth AOS.Damage( m, caster, damage, 0, 100, 0, 0, 0 ); m.PlaySound( 0x208 ); - if ( m is BaseCreature ) - ((BaseCreature) m).OnHarmfulSpell( caster ); + (m as BaseCreature)?.OnHarmfulSpell( caster ); } } } diff --git a/Scripts/Spells/Fourth/ManaDrain.cs b/Scripts/Spells/Fourth/ManaDrain.cs index 5eba78d55..91a1d7456 100644 --- a/Scripts/Spells/Fourth/ManaDrain.cs +++ b/Scripts/Spells/Fourth/ManaDrain.cs @@ -58,8 +58,7 @@ namespace Server.Spells.Fourth SpellHelper.CheckReflect( (int)Circle, Caster, ref m ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs index 677db0d2a..dafc215a0 100644 --- a/Scripts/Spells/Mysticism/NetherCycloneSpell.cs +++ b/Scripts/Spells/Mysticism/NetherCycloneSpell.cs @@ -142,9 +142,7 @@ namespace Server.Spells.Mysticism protected override void OnTarget( Mobile from, object o ) { - var p = o as IPoint3D; - - if ( p != null ) + if ( o is IPoint3D p ) m_Owner.Target( p ); } diff --git a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs index d6d2848d1..65e01b126 100644 --- a/Scripts/Spells/Mysticism/SpellPlagueSpell.cs +++ b/Scripts/Spells/Mysticism/SpellPlagueSpell.cs @@ -193,8 +193,7 @@ namespace Server.Spells.Mysticism public void EndPlague( bool restart ) { - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); if ( restart && m_Next != null ) { diff --git a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs index e9a517434..3481015f3 100644 --- a/Scripts/Spells/Necromancy/AnimateDeadSpell.cs +++ b/Scripts/Spells/Necromancy/AnimateDeadSpell.cs @@ -153,32 +153,26 @@ namespace Server.Spells.Necromancy { MaabusCoffinComponent comp = obj as MaabusCoffinComponent; - if ( comp != null ) + MaabusCoffin addon = comp?.Addon as MaabusCoffin; + + if ( addon != null ) { - MaabusCoffin addon = comp.Addon as MaabusCoffin; + PlayerMobile pm = Caster as PlayerMobile; - if ( addon != null ) + QuestSystem qs = pm?.Quest; + + if ( qs is DarkTidesQuest ) { - PlayerMobile pm = Caster as PlayerMobile; + QuestObjective objective = qs.FindObjective( typeof( AnimateMaabusCorpseObjective ) ); - if ( pm != null ) + if ( objective != null && !objective.Completed ) { - QuestSystem qs = pm.Quest; - - if ( qs is DarkTidesQuest ) - { - QuestObjective objective = qs.FindObjective( typeof( AnimateMaabusCorpseObjective ) ); - - if ( objective != null && !objective.Completed ) - { - addon.Awake( Caster ); - objective.Complete(); - } - } + addon.Awake( Caster ); + objective.Complete(); } - - return; } + + return; } Corpse c = obj as Corpse; diff --git a/Scripts/Spells/Necromancy/BloodOathSpell.cs b/Scripts/Spells/Necromancy/BloodOathSpell.cs index 4638d1d90..693fa52a5 100644 --- a/Scripts/Spells/Necromancy/BloodOathSpell.cs +++ b/Scripts/Spells/Necromancy/BloodOathSpell.cs @@ -58,14 +58,12 @@ namespace Server.Spells.Necromancy */ ExpireTimer timer = (ExpireTimer)m_Table[m]; - if ( timer != null ) - timer.DoExpire(); + timer?.DoExpire(); m_OathTable[Caster] = Caster; m_OathTable[m] = Caster; - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); Caster.PlaySound( 0x175 ); diff --git a/Scripts/Spells/Necromancy/CorpseSkin.cs b/Scripts/Spells/Necromancy/CorpseSkin.cs index f7bc502b6..f3cbccd66 100644 --- a/Scripts/Spells/Necromancy/CorpseSkin.cs +++ b/Scripts/Spells/Necromancy/CorpseSkin.cs @@ -53,8 +53,7 @@ namespace Server.Spells.Necromancy else m.SendLocalizedMessage( 1061689 ); // Your skin turns dry and corpselike. - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.FixedParticles( 0x373A, 1, 15, 9913, 67, 7, EffectLayer.Head ); m.PlaySound( 0x1BB ); diff --git a/Scripts/Spells/Necromancy/CurseWeapon.cs b/Scripts/Spells/Necromancy/CurseWeapon.cs index c2b55f9e7..e297495f1 100644 --- a/Scripts/Spells/Necromancy/CurseWeapon.cs +++ b/Scripts/Spells/Necromancy/CurseWeapon.cs @@ -52,8 +52,7 @@ namespace Server.Spells.Necromancy Timer t = (Timer)m_Table[weapon]; - if ( t != null ) - t.Stop(); + t?.Stop(); weapon.Cursed = true; diff --git a/Scripts/Spells/Necromancy/EvilOmen.cs b/Scripts/Spells/Necromancy/EvilOmen.cs index c67f6069b..70be14083 100644 --- a/Scripts/Spells/Necromancy/EvilOmen.cs +++ b/Scripts/Spells/Necromancy/EvilOmen.cs @@ -48,8 +48,7 @@ namespace Server.Spells.Necromancy * The effect lasts for one harmful event only. */ - if (m.Spell != null) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.PlaySound(0xFC); m.FixedParticles(0x3728, 1, 13, 9912, 1150, 7, EffectLayer.Head); diff --git a/Scripts/Spells/Necromancy/MindRot.cs b/Scripts/Spells/Necromancy/MindRot.cs index 5c0a007b5..122ccb35b 100644 --- a/Scripts/Spells/Necromancy/MindRot.cs +++ b/Scripts/Spells/Necromancy/MindRot.cs @@ -44,8 +44,7 @@ namespace Server.Spells.Necromancy * The effect lasts for ((Spirit Speak skill level - target's Resist Magic skill level) / 50 ) + 20 seconds. */ - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.PlaySound( 0x1FB ); m.PlaySound( 0x258 ); diff --git a/Scripts/Spells/Necromancy/Strangle.cs b/Scripts/Spells/Necromancy/Strangle.cs index 602cf300e..f99304655 100644 --- a/Scripts/Spells/Necromancy/Strangle.cs +++ b/Scripts/Spells/Necromancy/Strangle.cs @@ -50,8 +50,7 @@ namespace Server.Spells.Necromancy * for a target at 20% Stamina the damage multiplier is 2.6 */ - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.PlaySound( 0x22F ); m.FixedParticles( 0x36CB, 1, 9, 9911, 67, 5, EffectLayer.Head ); diff --git a/Scripts/Spells/Ninjitsu/DeathStrike.cs b/Scripts/Spells/Ninjitsu/DeathStrike.cs index 2f8824976..36451cd6c 100644 --- a/Scripts/Spells/Ninjitsu/DeathStrike.cs +++ b/Scripts/Spells/Ninjitsu/DeathStrike.cs @@ -61,8 +61,7 @@ namespace Server.Spells.Ninjitsu if ( info.m_Steps > 0 ) damageBonus = attacker.Skills[SkillName.Ninjitsu].Fixed / 150; - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( defender ); } @@ -160,8 +159,7 @@ namespace Server.Spells.Ninjitsu else AOS.Damage( info.m_Target, info.m_Attacker, damage, true, 100, 0, 0, 0, 0, 0, 0, false, false, true ); // Damage is physical. - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( info.m_Target ); } diff --git a/Scripts/Spells/Ninjitsu/KiAttack.cs b/Scripts/Spells/Ninjitsu/KiAttack.cs index 2708a8662..fe7fbb2e5 100644 --- a/Scripts/Spells/Ninjitsu/KiAttack.cs +++ b/Scripts/Spells/Ninjitsu/KiAttack.cs @@ -90,8 +90,7 @@ namespace Server.Spells.Ninjitsu if ( info != null ) { - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( info.m_Mobile ); } @@ -134,8 +133,7 @@ namespace Server.Spells.Ninjitsu { KiAttackInfo info = (KiAttackInfo)state; - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); ClearCurrentMove( info.m_Mobile ); info.m_Mobile.SendLocalizedMessage( 1063102 ); // You failed to complete your Ki Attack in time. diff --git a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs index 397b48f61..c551049a5 100644 --- a/Scripts/Spells/Ninjitsu/SurpriseAttack.cs +++ b/Scripts/Spells/Ninjitsu/SurpriseAttack.cs @@ -61,8 +61,7 @@ namespace Server.Spells.Ninjitsu { info = (SurpriseAttackInfo)m_Table[defender]; - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); m_Table.Remove( defender ); } @@ -119,8 +118,7 @@ namespace Server.Spells.Ninjitsu { SurpriseAttackInfo info = (SurpriseAttackInfo)state; - if ( info.m_Timer != null ) - info.m_Timer.Stop(); + info.m_Timer?.Stop(); info.m_Target.SendLocalizedMessage( 1063131 ); // Your defenses have returned to normal. diff --git a/Scripts/Spells/Seventh/EnergyField.cs b/Scripts/Spells/Seventh/EnergyField.cs index e8a7f3096..4d4df4a43 100644 --- a/Scripts/Spells/Seventh/EnergyField.cs +++ b/Scripts/Spells/Seventh/EnergyField.cs @@ -162,8 +162,7 @@ namespace Server.Spells.Seventh { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } private class InternalTimer : Timer diff --git a/Scripts/Spells/Seventh/ManaVampire.cs b/Scripts/Spells/Seventh/ManaVampire.cs index 9ce3e8891..df6dd1346 100644 --- a/Scripts/Spells/Seventh/ManaVampire.cs +++ b/Scripts/Spells/Seventh/ManaVampire.cs @@ -37,8 +37,7 @@ namespace Server.Spells.Seventh SpellHelper.CheckReflect( (int)Circle, Caster, ref m ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/Sixth/Explosion.cs b/Scripts/Spells/Sixth/Explosion.cs index f1f79834a..1f35fa7f6 100644 --- a/Scripts/Spells/Sixth/Explosion.cs +++ b/Scripts/Spells/Sixth/Explosion.cs @@ -64,8 +64,7 @@ namespace Server.Spells.Sixth m_Defender = defender; m_Target = target; - if ( m_Spell != null ) - m_Spell.StartDelayedDamageContext( attacker, this ); + m_Spell?.StartDelayedDamageContext( attacker, this ); Priority = TimerPriority.FiftyMS; } @@ -99,8 +98,7 @@ namespace Server.Spells.Sixth SpellHelper.Damage( m_Spell, m_Target, damage, 0, 100, 0, 0, 0 ); - if ( m_Spell != null ) - m_Spell.RemoveDelayedDamageContext( m_Attacker ); + m_Spell?.RemoveDelayedDamageContext( m_Attacker ); } } } diff --git a/Scripts/Spells/Sixth/ParalyzeField.cs b/Scripts/Spells/Sixth/ParalyzeField.cs index 3f9eaee5c..6da3cadbf 100644 --- a/Scripts/Spells/Sixth/ParalyzeField.cs +++ b/Scripts/Spells/Sixth/ParalyzeField.cs @@ -118,8 +118,7 @@ namespace Server.Spells.Sixth { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } public InternalItem( Serial serial ) : base( serial ) @@ -188,8 +187,7 @@ namespace Server.Spells.Sixth m.PlaySound( 0x204 ); m.FixedEffect( 0x376A, 10, 16 ); - if ( m is BaseCreature ) - ((BaseCreature) m).OnHarmfulSpell( m_Caster ); + (m as BaseCreature)?.OnHarmfulSpell( m_Caster ); } return true; diff --git a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs index 8ea4d6b62..20dd1a8d1 100644 --- a/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs +++ b/Scripts/Spells/Spellweaving/ImmolatingWeapon.cs @@ -94,8 +94,7 @@ namespace Server.Spells.Spellweaving { if (m_WeaponDamageTable.TryGetValue( weapon, out ImmolatingWeaponEntry entry )) { - if ( entry.m_Caster != null ) - entry.m_Caster.PlaySound( 0x27 ); + entry.m_Caster?.PlaySound( 0x27 ); entry.m_Timer.Stop(); diff --git a/Scripts/Spells/Spellweaving/Items/TransientItem.cs b/Scripts/Spells/Spellweaving/Items/TransientItem.cs index 286427de2..d7829b060 100644 --- a/Scripts/Spells/Spellweaving/Items/TransientItem.cs +++ b/Scripts/Spells/Spellweaving/Items/TransientItem.cs @@ -38,8 +38,7 @@ namespace Server.Items public virtual void Expire( Mobile parent ) { - if ( parent != null ) - parent.SendLocalizedMessage( 1072515, (Name == null ? $"#{LabelNumber}" : Name) ); // The ~1_name~ expired... + parent?.SendLocalizedMessage( 1072515, (Name == null ? $"#{LabelNumber}" : Name) ); // The ~1_name~ expired... Effects.PlaySound( GetWorldLocation(), Map, 0x201 ); diff --git a/Scripts/Spells/Spellweaving/NatureFury.cs b/Scripts/Spells/Spellweaving/NatureFury.cs index dc5a38890..2dbfee766 100644 --- a/Scripts/Spells/Spellweaving/NatureFury.cs +++ b/Scripts/Spells/Spellweaving/NatureFury.cs @@ -90,8 +90,7 @@ namespace Server.Spells.Spellweaving protected override void OnTargetFinish( Mobile from ) { - if ( m_Owner != null ) - m_Owner.FinishSequence(); + m_Owner?.FinishSequence(); } } diff --git a/Scripts/Spells/Third/Poison.cs b/Scripts/Spells/Third/Poison.cs index 7e1e5dc02..870b04c1e 100644 --- a/Scripts/Spells/Third/Poison.cs +++ b/Scripts/Spells/Third/Poison.cs @@ -34,8 +34,7 @@ namespace Server.Spells.Third SpellHelper.CheckReflect( (int)Circle, Caster, ref m ); - if ( m.Spell != null ) - m.Spell.OnCasterHurt(); + m.Spell?.OnCasterHurt(); m.Paralyzed = false; diff --git a/Scripts/Spells/Third/WallOfStone.cs b/Scripts/Spells/Third/WallOfStone.cs index b8fb6279d..49eccd666 100644 --- a/Scripts/Spells/Third/WallOfStone.cs +++ b/Scripts/Spells/Third/WallOfStone.cs @@ -179,8 +179,7 @@ namespace Server.Spells.Third { base.OnAfterDelete(); - if ( m_Timer != null ) - m_Timer.Stop(); + m_Timer?.Stop(); } private class InternalTimer : Timer diff --git a/Scripts/Targets/BladedItemTarget.cs b/Scripts/Targets/BladedItemTarget.cs index 43d5bc8fd..8a6372a6e 100644 --- a/Scripts/Targets/BladedItemTarget.cs +++ b/Scripts/Targets/BladedItemTarget.cs @@ -52,20 +52,17 @@ namespace Server.Targets { PlayerMobile player = from as PlayerMobile; - if ( player != null ) + QuestSystem qs = player?.Quest; + + if ( qs is WitchApprenticeQuest ) { - QuestSystem qs = player.Quest; + FindIngredientObjective obj = qs.FindObjective( typeof( FindIngredientObjective ) ) as FindIngredientObjective; - if ( qs is WitchApprenticeQuest ) + if ( obj != null && !obj.Completed && obj.Ingredient == Ingredient.RedMushrooms ) { - FindIngredientObjective obj = qs.FindObjective( typeof( FindIngredientObjective ) ) as FindIngredientObjective; - - if ( obj != null && !obj.Completed && obj.Ingredient == Ingredient.RedMushrooms ) - { - player.SendLocalizedMessage( 1055036 ); // You slice a red cap mushroom from its stem. - obj.Complete(); - return; - } + player.SendLocalizedMessage( 1055036 ); // You slice a red cap mushroom from its stem. + obj.Complete(); + return; } } } diff --git a/Server/EventSink.cs b/Server/EventSink.cs index 830a03f57..7f1d0cd67 100644 --- a/Server/EventSink.cs +++ b/Server/EventSink.cs @@ -940,260 +940,217 @@ namespace Server public static void InvokeClientVersionReceived( ClientVersionReceivedArgs e ) { - if ( ClientVersionReceived != null ) - ClientVersionReceived( e ); + ClientVersionReceived?.Invoke( e ); } public static void InvokeServerStarted() { - if ( ServerStarted != null ) - ServerStarted(); + ServerStarted?.Invoke(); } public static void InvokeCreateGuild( CreateGuildEventArgs e ) { - if ( CreateGuild != null ) - CreateGuild( e ); + CreateGuild?.Invoke( e ); } public static void InvokeSetAbility( SetAbilityEventArgs e ) { - if ( SetAbility != null ) - SetAbility( e ); + SetAbility?.Invoke( e ); } public static void InvokeGuildGumpRequest( GuildGumpRequestArgs e ) { - if ( GuildGumpRequest != null ) - GuildGumpRequest( e ); + GuildGumpRequest?.Invoke( e ); } public static void InvokeQuestGumpRequest( QuestGumpRequestArgs e ) { - if ( QuestGumpRequest != null ) - QuestGumpRequest( e ); + QuestGumpRequest?.Invoke( e ); } public static void InvokeFastWalk( FastWalkEventArgs e ) { - if ( FastWalk != null ) - FastWalk( e ); + FastWalk?.Invoke( e ); } public static void InvokeDeleteRequest( DeleteRequestEventArgs e ) { - if ( DeleteRequest != null ) - DeleteRequest( e ); + DeleteRequest?.Invoke( e ); } public static void InvokeGameLogin( GameLoginEventArgs e ) { - if ( GameLogin != null ) - GameLogin( e ); + GameLogin?.Invoke( e ); } public static void InvokeCommand( CommandEventArgs e ) { - if ( Command != null ) - Command( e ); + Command?.Invoke( e ); } public static void InvokeAggressiveAction( AggressiveActionEventArgs e ) { - if ( AggressiveAction != null ) - AggressiveAction( e ); + AggressiveAction?.Invoke( e ); } public static void InvokeProfileRequest( ProfileRequestEventArgs e ) { - if ( ProfileRequest != null ) - ProfileRequest( e ); + ProfileRequest?.Invoke( e ); } public static void InvokeChangeProfileRequest( ChangeProfileRequestEventArgs e ) { - if ( ChangeProfileRequest != null ) - ChangeProfileRequest( e ); + ChangeProfileRequest?.Invoke( e ); } public static void InvokePaperdollRequest( PaperdollRequestEventArgs e ) { - if ( PaperdollRequest != null ) - PaperdollRequest( e ); + PaperdollRequest?.Invoke( e ); } public static void InvokeAccountLogin( AccountLoginEventArgs e ) { - if ( AccountLogin != null ) - AccountLogin( e ); + AccountLogin?.Invoke( e ); } public static void InvokeChatRequest( ChatRequestEventArgs e ) { - if ( ChatRequest != null ) - ChatRequest( e ); + ChatRequest?.Invoke( e ); } public static void InvokeVirtueItemRequest( VirtueItemRequestEventArgs e ) { - if ( VirtueItemRequest != null ) - VirtueItemRequest( e ); + VirtueItemRequest?.Invoke( e ); } public static void InvokeVirtueGumpRequest( VirtueGumpRequestEventArgs e ) { - if ( VirtueGumpRequest != null ) - VirtueGumpRequest( e ); + VirtueGumpRequest?.Invoke( e ); } public static void InvokeVirtueMacroRequest( VirtueMacroRequestEventArgs e ) { - if ( VirtueMacroRequest != null ) - VirtueMacroRequest( e ); + VirtueMacroRequest?.Invoke( e ); } public static void InvokePlayerDeath( PlayerDeathEventArgs e ) { - if ( PlayerDeath != null ) - PlayerDeath( e ); + PlayerDeath?.Invoke( e ); } public static void InvokeRenameRequest( RenameRequestEventArgs e ) { - if ( RenameRequest != null ) - RenameRequest( e ); + RenameRequest?.Invoke( e ); } public static void InvokeLogout( LogoutEventArgs e ) { - if ( Logout != null ) - Logout( e ); + Logout?.Invoke( e ); } public static void InvokeSocketConnect( SocketConnectEventArgs e ) { - if ( SocketConnect != null ) - SocketConnect( e ); + SocketConnect?.Invoke( e ); } public static void InvokeConnected( ConnectedEventArgs e ) { - if ( Connected != null ) - Connected( e ); + Connected?.Invoke( e ); } public static void InvokeDisconnected( DisconnectedEventArgs e ) { - if ( Disconnected != null ) - Disconnected( e ); + Disconnected?.Invoke( e ); } public static void InvokeAnimateRequest( AnimateRequestEventArgs e ) { - if ( AnimateRequest != null ) - AnimateRequest( e ); + AnimateRequest?.Invoke( e ); } public static void InvokeCastSpellRequest( CastSpellRequestEventArgs e ) { - if ( CastSpellRequest != null ) - CastSpellRequest( e ); + CastSpellRequest?.Invoke( e ); } public static void InvokeBandageTargetRequest( BandageTargetRequestEventArgs e ) { - if ( BandageTargetRequest != null ) - BandageTargetRequest( e ); + BandageTargetRequest?.Invoke( e ); } public static void InvokeOpenSpellbookRequest( OpenSpellbookRequestEventArgs e ) { - if ( OpenSpellbookRequest != null ) - OpenSpellbookRequest( e ); + OpenSpellbookRequest?.Invoke( e ); } public static void InvokeDisarmRequest( DisarmRequestEventArgs e ) { - if ( DisarmRequest != null ) - DisarmRequest( e ); + DisarmRequest?.Invoke( e ); } public static void InvokeStunRequest( StunRequestEventArgs e ) { - if ( StunRequest != null ) - StunRequest( e ); + StunRequest?.Invoke( e ); } public static void InvokeHelpRequest( HelpRequestEventArgs e ) { - if ( HelpRequest != null ) - HelpRequest( e ); + HelpRequest?.Invoke( e ); } public static void InvokeShutdown( ShutdownEventArgs e ) { - if ( Shutdown != null ) - Shutdown( e ); + Shutdown?.Invoke( e ); } public static void InvokeCrashed( CrashedEventArgs e ) { - if ( Crashed != null ) - Crashed( e ); + Crashed?.Invoke( e ); } public static void InvokeHungerChanged( HungerChangedEventArgs e ) { - if ( HungerChanged != null ) - HungerChanged( e ); + HungerChanged?.Invoke( e ); } public static void InvokeMovement( MovementEventArgs e ) { - if ( Movement != null ) - Movement( e ); + Movement?.Invoke( e ); } public static void InvokeServerList( ServerListEventArgs e ) { - if ( ServerList != null ) - ServerList( e ); + ServerList?.Invoke( e ); } public static void InvokeLogin( LoginEventArgs e ) { - if ( Login != null ) - Login( e ); + Login?.Invoke( e ); } public static void InvokeSpeech( SpeechEventArgs e ) { - if ( Speech != null ) - Speech( e ); + Speech?.Invoke( e ); } public static void InvokeCharacterCreated( CharacterCreatedEventArgs e ) { - if ( CharacterCreated != null ) - CharacterCreated( e ); + CharacterCreated?.Invoke( e ); } public static void InvokeOpenDoorMacroUsed( OpenDoorMacroEventArgs e ) { - if ( OpenDoorMacroUsed != null ) - OpenDoorMacroUsed( e ); + OpenDoorMacroUsed?.Invoke( e ); } public static void InvokeWorldLoad() { - if ( WorldLoad != null ) - WorldLoad(); + WorldLoad?.Invoke(); } public static void InvokeWorldSave( WorldSaveEventArgs e ) { - if ( WorldSave != null ) - WorldSave( e ); + WorldSave?.Invoke( e ); } public static void Reset() diff --git a/Server/Gumps/GumpButton.cs b/Server/Gumps/GumpButton.cs index f6a95c163..bacecfc83 100644 --- a/Server/Gumps/GumpButton.cs +++ b/Server/Gumps/GumpButton.cs @@ -89,10 +89,7 @@ namespace Server.Gumps Gump parent = Parent; - if ( parent != null ) - { - parent.Invalidate(); - } + parent?.Invalidate(); } } } diff --git a/Server/Gumps/GumpEntry.cs b/Server/Gumps/GumpEntry.cs index e4826bae7..df02aa4d7 100644 --- a/Server/Gumps/GumpEntry.cs +++ b/Server/Gumps/GumpEntry.cs @@ -69,13 +69,11 @@ namespace Server.Gumps { if ( m_Parent != value ) { - if ( m_Parent != null ) - m_Parent.Remove( this ); + m_Parent?.Remove( this ); m_Parent = value; - if ( m_Parent != null ) - m_Parent.Add( this ); + m_Parent?.Add( this ); } } } diff --git a/Server/Gumps/GumpHtmlLocalized.cs b/Server/Gumps/GumpHtmlLocalized.cs index 32be06b58..22c8a1e75 100644 --- a/Server/Gumps/GumpHtmlLocalized.cs +++ b/Server/Gumps/GumpHtmlLocalized.cs @@ -104,8 +104,7 @@ namespace Server.Gumps { m_Type = value; - if ( Parent != null ) - Parent.Invalidate(); + Parent?.Invalidate(); } } } diff --git a/Server/Gumps/GumpImageTileButton.cs b/Server/Gumps/GumpImageTileButton.cs index 1e4befe76..42946db30 100644 --- a/Server/Gumps/GumpImageTileButton.cs +++ b/Server/Gumps/GumpImageTileButton.cs @@ -101,10 +101,7 @@ namespace Server.Gumps Gump parent = Parent; - if ( parent != null ) - { - parent.Invalidate(); - } + parent?.Invalidate(); } } } diff --git a/Server/Item.cs b/Server/Item.cs index 1b67438ab..734520220 100644 --- a/Server/Item.cs +++ b/Server/Item.cs @@ -663,10 +663,7 @@ namespace Server { CompactInfo info = LookupCompactInfo(); - if ( info != null ) - return info.m_HeldBy; - - return null; + return info?.m_HeldBy; } set { @@ -4490,10 +4487,7 @@ namespace Server { CompactInfo info = LookupCompactInfo(); - if ( info != null ) - return info.m_BlessedFor; - - return null; + return info?.m_BlessedFor; } set { diff --git a/Server/Items/BaseMulti.cs b/Server/Items/BaseMulti.cs index 37aa5ffee..a7276fb22 100644 --- a/Server/Items/BaseMulti.cs +++ b/Server/Items/BaseMulti.cs @@ -41,15 +41,11 @@ namespace Server.Items if ( base.ItemID != value ) { Map facet = ( Parent == null ? Map : null ); - if ( facet != null ) { - facet.OnLeave( this ); - } + facet?.OnLeave( this ); base.ItemID = value; - if ( facet != null ) { - facet.OnEnter( this ); - } + facet?.OnEnter( this ); } } } diff --git a/Server/Items/Container.cs b/Server/Items/Container.cs index afaccc4f0..205f7724e 100644 --- a/Server/Items/Container.cs +++ b/Server/Items/Container.cs @@ -151,8 +151,7 @@ namespace Server.Items public override void OnSnoop( Mobile from ) { - if ( m_SnoopHandler != null ) - m_SnoopHandler( this, from ); + m_SnoopHandler?.Invoke( this, @from ); } public override bool CheckLift( Mobile from, Item item, ref LRReason reject ) @@ -349,16 +348,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); break; @@ -449,16 +446,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); break; @@ -549,16 +544,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); break; @@ -614,16 +607,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); break; @@ -675,16 +666,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); break; @@ -729,16 +718,14 @@ namespace Server.Items if ( theirAmount < need ) { - if ( callback != null ) - callback( item, theirAmount ); + callback?.Invoke( item, theirAmount ); item.Consume( theirAmount ); need -= theirAmount; } else { - if ( callback != null ) - callback( item, need ); + callback?.Invoke( item, need ); item.Consume( need ); diff --git a/Server/Network/Listener.cs b/Server/Network/Listener.cs index ce99f0cb5..e3d4755cd 100644 --- a/Server/Network/Listener.cs +++ b/Server/Network/Listener.cs @@ -268,10 +268,7 @@ namespace Server.Network { Socket socket = Interlocked.Exchange(ref m_Listener, null); - if (socket != null) - { - socket.Close(); - } + socket?.Close(); } } diff --git a/Server/Network/MessagePump.cs b/Server/Network/MessagePump.cs index 64964fe4c..b67f3c1ed 100644 --- a/Server/Network/MessagePump.cs +++ b/Server/Network/MessagePump.cs @@ -238,9 +238,7 @@ namespace Server.Network if (Core.Profiling) prof = PacketReceiveProfile.Acquire( packetID ); - if ( prof != null ) { - prof.Start(); - } + prof?.Start(); byte[] packetBuffer; @@ -259,9 +257,7 @@ namespace Server.Network if ( BufferSize >= packetLength ) m_Buffers.ReleaseBuffer( packetBuffer ); - if ( prof != null ) { - prof.Finish( packetLength ); - } + prof?.Finish( packetLength ); } else { break; } diff --git a/Server/Network/NetState.cs b/Server/Network/NetState.cs index a362b161d..c3e172bfc 100644 --- a/Server/Network/NetState.cs +++ b/Server/Network/NetState.cs @@ -349,22 +349,19 @@ namespace Server.Network { } } - public void RemoveMenu( IMenu menu ) { - if ( m_Menus != null ) { - m_Menus.Remove( menu ); - } + public void RemoveMenu( IMenu menu ) + { + m_Menus?.Remove( menu ); } - public void RemoveMenu( int index ) { - if ( m_Menus != null ) { - m_Menus.RemoveAt( index ); - } + public void RemoveMenu( int index ) + { + m_Menus?.RemoveAt( index ); } - public void ClearMenus() { - if ( m_Menus != null ) { - m_Menus.Clear(); - } + public void ClearMenus() + { + m_Menus?.Clear(); } public void AddHuePicker( HuePicker huePicker ) { @@ -380,22 +377,19 @@ namespace Server.Network { } } - public void RemoveHuePicker( HuePicker huePicker ) { - if ( m_HuePickers != null ) { - m_HuePickers.Remove( huePicker ); - } + public void RemoveHuePicker( HuePicker huePicker ) + { + m_HuePickers?.Remove( huePicker ); } - public void RemoveHuePicker( int index ) { - if ( m_HuePickers != null ) { - m_HuePickers.RemoveAt( index ); - } + public void RemoveHuePicker( int index ) + { + m_HuePickers?.RemoveAt( index ); } - public void ClearHuePickers() { - if ( m_HuePickers != null ) { - m_HuePickers.Clear(); - } + public void ClearHuePickers() + { + m_HuePickers?.Clear(); } public void AddGump( Gump gump ) { @@ -411,22 +405,19 @@ namespace Server.Network { } } - public void RemoveGump( Gump gump ) { - if ( m_Gumps != null ) { - m_Gumps.Remove( gump ); - } + public void RemoveGump( Gump gump ) + { + m_Gumps?.Remove( gump ); } - public void RemoveGump( int index ) { - if ( m_Gumps != null ) { - m_Gumps.RemoveAt( index ); - } + public void RemoveGump( int index ) + { + m_Gumps?.RemoveAt( index ); } - public void ClearGumps() { - if ( m_Gumps != null ) { - m_Gumps.Clear(); - } + public void ClearGumps() + { + m_Gumps?.Clear(); } public void LaunchBrowser( string url ) { @@ -494,10 +485,7 @@ namespace Server.Network { m_ConnectedOn = DateTime.UtcNow; - if ( m_CreatedCallback != null ) - { - m_CreatedCallback( this ); - } + m_CreatedCallback?.Invoke( this ); } private bool _sending; @@ -522,13 +510,9 @@ namespace Server.Network { if (Core.Profiling) prof = PacketSendProfile.Acquire(p.GetType()); - if ( prof != null ) { - prof.Start(); - } + prof?.Start(); - if ( m_Encoder != null ) { - m_Encoder.EncodeOutgoingPacket( this, ref buffer, ref length ); - } + m_Encoder?.EncodeOutgoingPacket( this, ref buffer, ref length ); try { SendQueue.Gram gram; @@ -560,9 +544,7 @@ namespace Server.Network { p.OnSend(); - if ( prof != null ) { - prof.Finish( length ); - } + prof?.Finish( length ); } else { Console.WriteLine( "Client: {0}: null buffer send, disconnecting...", this ); using ( StreamWriter op = new StreamWriter( "null_send.log", true ) ) @@ -637,8 +619,7 @@ namespace Server.Network { byte[] buffer = m_RecvBuffer; - if ( m_Encoder != null ) - m_Encoder.DecodeIncomingPacket( this, ref buffer, ref byteCount ); + m_Encoder?.DecodeIncomingPacket( this, ref buffer, ref byteCount ); lock ( m_Buffer ) m_Buffer.Enqueue( buffer, 0, byteCount ); diff --git a/Server/Network/PacketHandlers.cs b/Server/Network/PacketHandlers.cs index 63c82196d..787e9cb7f 100644 --- a/Server/Network/PacketHandlers.cs +++ b/Server/Network/PacketHandlers.cs @@ -1098,8 +1098,7 @@ namespace Server.Network { Skill s = state.Mobile.Skills[pvSrc.ReadInt16()]; - if ( s != null ) - s.SetLockNoRelay( (SkillLock)pvSrc.ReadByte() ); + s?.SetLockNoRelay( (SkillLock)pvSrc.ReadByte() ); } public static void HelpRequest( NetState state, PacketReader pvSrc ) @@ -1127,9 +1126,7 @@ namespace Server.Network { TargetProfile prof = TargetProfile.Acquire( t.GetType() ); - if ( prof != null ) { - prof.Start(); - } + prof?.Start(); try { if ( x == -1 && y == -1 && !serial.IsValid ) @@ -1208,10 +1205,9 @@ namespace Server.Network t.Invoke( from, toTarget ); } - } finally { - if ( prof != null ) { - prof.Finish(); - } + } finally + { + prof?.Finish(); } } } @@ -1291,15 +1287,11 @@ namespace Server.Network GumpProfile prof = GumpProfile.Acquire( gump.GetType() ); - if ( prof != null ) { - prof.Start(); - } + prof?.Start(); gump.OnResponse( state, new RelayInfo( buttonID, switches, textEntries ) ); - if ( prof != null ) { - prof.Finish(); - } + prof?.Finish(); return; } @@ -1609,8 +1601,7 @@ namespace Server.Network bool rightClick = pvSrc.ReadBoolean(); Mobile from = state.Mobile; - if ( @from?.QuestArrow != null ) - from.QuestArrow.OnClick( rightClick ); + @from?.QuestArrow?.OnClick( rightClick ); } public static void ExtendedCommand( NetState state, PacketReader pvSrc ) diff --git a/Server/Network/Packets.cs b/Server/Network/Packets.cs index 577e592c0..78a35b769 100644 --- a/Server/Network/Packets.cs +++ b/Server/Network/Packets.cs @@ -3118,8 +3118,7 @@ namespace Server.Network int min = 0, max = 0; - if ( weapon != null ) - weapon.GetStatusDamage( m, out min, out max ); + weapon?.GetStatusDamage( m, out min, out max ); m_Stream.Write( (short) min ); // Damage min m_Stream.Write( (short) max ); // Damage max @@ -3220,8 +3219,7 @@ namespace Server.Network int min = 0, max = 0; - if ( weapon != null ) - weapon.GetStatusDamage( beheld, out min, out max ); + weapon?.GetStatusDamage( beheld, out min, out max ); m_Stream.Write( (short) min ); // Damage min m_Stream.Write( (short) max ); // Damage max @@ -4477,48 +4475,42 @@ namespace Server.Network public static void Release( ref ObjectPropertyList p ) { - if ( p != null ) - p.Release(); + p?.Release(); p = null; } public static void Release( ref RemoveItem p ) { - if ( p != null ) - p.Release(); + p?.Release(); p = null; } public static void Release( ref RemoveMobile p ) { - if ( p != null ) - p.Release(); + p?.Release(); p = null; } public static void Release( ref OPLInfo p ) { - if ( p != null ) - p.Release(); + p?.Release(); p = null; } public static void Release( ref Packet p ) { - if ( p != null ) - p.Release(); + p?.Release(); p = null; } public static void Release( Packet p ) { - if ( p != null ) - p.Release(); + p?.Release(); } public void SetStatic() diff --git a/Server/Network/SendQueue.cs b/Server/Network/SendQueue.cs index adb79456e..a8e0b0e73 100644 --- a/Server/Network/SendQueue.cs +++ b/Server/Network/SendQueue.cs @@ -87,8 +87,7 @@ namespace Server.Network { BufferPool old = m_UnusedBuffers; lock (old) { - if ( m_UnusedBuffers != null ) - m_UnusedBuffers.Free(); + m_UnusedBuffers?.Free(); m_CoalesceBufferSize = value; m_UnusedBuffers = new BufferPool( "Coalesced", 2048, m_CoalesceBufferSize ); diff --git a/Server/Persistence/DynamicSaveStrategy.cs b/Server/Persistence/DynamicSaveStrategy.cs index 827b3c065..3ce16093c 100644 --- a/Server/Persistence/DynamicSaveStrategy.cs +++ b/Server/Persistence/DynamicSaveStrategy.cs @@ -131,10 +131,7 @@ namespace Server _decayBag.Add(item); } - if (_metrics != null) - { - _metrics.OnItemSaved(size); - } + _metrics?.OnItemSaved(size); return writer; }, @@ -169,10 +166,7 @@ namespace Server writer.QueueForIndex(mobile, size); - if (_metrics != null) - { - _metrics.OnMobileSaved(size); - } + _metrics?.OnMobileSaved(size); return writer; }, @@ -207,10 +201,7 @@ namespace Server writer.QueueForIndex(guild, size); - if (_metrics != null) - { - _metrics.OnGuildSaved(size); - } + _metrics?.OnGuildSaved(size); return writer; }, diff --git a/Server/Persistence/ParallelSaveStrategy.cs b/Server/Persistence/ParallelSaveStrategy.cs index 414432d5b..90746234c 100644 --- a/Server/Persistence/ParallelSaveStrategy.cs +++ b/Server/Persistence/ParallelSaveStrategy.cs @@ -176,9 +176,7 @@ namespace Server { private void Save( Item item, BinaryMemoryWriter writer ) { int length = writer.CommitTo( itemData, itemIndex, item.m_TypeRef, item.Serial ); - if ( metrics != null ) { - metrics.OnItemSaved( length ); - } + metrics?.OnItemSaved( length ); if (item.Decays && item.Parent == null && item.Map != Map.Internal && DateTime.UtcNow > (item.LastMoved + item.DecayTime)) { @@ -189,17 +187,13 @@ namespace Server { private void Save( Mobile mob, BinaryMemoryWriter writer ) { int length = writer.CommitTo( mobileData, mobileIndex, mob.m_TypeRef, mob.Serial ); - if ( metrics != null ) { - metrics.OnMobileSaved( length ); - } + metrics?.OnMobileSaved( length ); } private void Save( BaseGuild guild, BinaryMemoryWriter writer ) { int length = writer.CommitTo( guildData, guildIndex, 0, guild.Id ); - if ( metrics != null ) { - metrics.OnGuildSaved( length ); - } + metrics?.OnGuildSaved( length ); } private bool Enqueue( ISerializable value ) { diff --git a/Server/Persistence/SequentialFileWriter.cs b/Server/Persistence/SequentialFileWriter.cs index 43a3551ba..55e09a9eb 100644 --- a/Server/Persistence/SequentialFileWriter.cs +++ b/Server/Persistence/SequentialFileWriter.cs @@ -54,9 +54,7 @@ namespace Server { if ( FileOperations.AreSynchronous ) { fileStream.Write( chunk.Buffer, chunk.Offset, chunk.Size ); - if ( metrics != null ) { - metrics.OnFileWritten( chunk.Size ); - } + metrics?.OnFileWritten( chunk.Size ); chunk.Commit(); } else { @@ -73,9 +71,7 @@ namespace Server { fileStream.EndWrite( asyncResult ); - if ( metrics != null ) { - metrics.OnFileWritten( chunk.Size ); - } + metrics?.OnFileWritten( chunk.Size ); chunk.Commit(); } diff --git a/Server/Persistence/StandardSaveStrategy.cs b/Server/Persistence/StandardSaveStrategy.cs index fc0cdedba..35405af49 100644 --- a/Server/Persistence/StandardSaveStrategy.cs +++ b/Server/Persistence/StandardSaveStrategy.cs @@ -88,9 +88,7 @@ namespace Server { m.Serialize( bin ); - if ( metrics != null ) { - metrics.OnMobileSaved( ( int ) ( bin.Position - start ) ); - } + metrics?.OnMobileSaved( ( int ) ( bin.Position - start ) ); idx.Write( ( int ) ( bin.Position - start ) ); @@ -144,9 +142,7 @@ namespace Server { item.Serialize( bin ); - if ( metrics != null ) { - metrics.OnItemSaved( ( int ) ( bin.Position - start ) ); - } + metrics?.OnItemSaved( ( int ) ( bin.Position - start ) ); idx.Write( ( int ) ( bin.Position - start ) ); @@ -186,9 +182,7 @@ namespace Server { guild.Serialize( bin ); - if ( metrics != null ) { - metrics.OnGuildSaved( ( int ) ( bin.Position - start ) ); - } + metrics?.OnGuildSaved( ( int ) ( bin.Position - start ) ); idx.Write( ( int ) ( bin.Position - start ) ); } diff --git a/Server/Region.cs b/Server/Region.cs index fea55d434..b9a360c00 100644 --- a/Server/Region.cs +++ b/Server/Region.cs @@ -562,8 +562,7 @@ namespace Server public virtual void MakeGuard( Mobile focus ) { - if ( m_Parent != null ) - m_Parent.MakeGuard( focus ); + m_Parent?.MakeGuard( focus ); } public virtual Type GetResource( Type type ) @@ -584,26 +583,22 @@ namespace Server public virtual void OnAggressed( Mobile aggressor, Mobile aggressed, bool criminal ) { - if ( m_Parent != null ) - m_Parent.OnAggressed( aggressor, aggressed, criminal ); + m_Parent?.OnAggressed( aggressor, aggressed, criminal ); } public virtual void OnDidHarmful( Mobile harmer, Mobile harmed ) { - if ( m_Parent != null ) - m_Parent.OnDidHarmful( harmer, harmed ); + m_Parent?.OnDidHarmful( harmer, harmed ); } public virtual void OnGotHarmful( Mobile harmer, Mobile harmed ) { - if ( m_Parent != null ) - m_Parent.OnGotHarmful( harmer, harmed ); + m_Parent?.OnGotHarmful( harmer, harmed ); } public virtual void OnLocationChanged( Mobile m, Point3D oldLocation ) { - if ( m_Parent != null ) - m_Parent.OnLocationChanged( m, oldLocation ); + m_Parent?.OnLocationChanged( m, oldLocation ); } public virtual bool OnTarget( Mobile m, Target t, object o ) @@ -686,26 +681,22 @@ namespace Server public virtual void OnBeneficialAction( Mobile helper, Mobile target ) { - if ( m_Parent != null ) - m_Parent.OnBeneficialAction( helper, target ); + m_Parent?.OnBeneficialAction( helper, target ); } public virtual void OnGotBeneficialAction( Mobile helper, Mobile target ) { - if ( m_Parent != null ) - m_Parent.OnGotBeneficialAction( helper, target ); + m_Parent?.OnGotBeneficialAction( helper, target ); } public virtual void SpellDamageScalar( Mobile caster, Mobile target, ref double damage ) { - if ( m_Parent != null ) - m_Parent.SpellDamageScalar( caster, target, ref damage ); + m_Parent?.SpellDamageScalar( caster, target, ref damage ); } public virtual void OnSpeech( SpeechEventArgs args ) { - if ( m_Parent != null ) - m_Parent.OnSpeech( args ); + m_Parent?.OnSpeech( args ); } public virtual bool OnSkillUse( Mobile m, int Skill ) @@ -726,8 +717,7 @@ namespace Server public virtual void OnSpellCast( Mobile m, ISpell s ) { - if ( m_Parent != null ) - m_Parent.OnSpellCast( m, s ); + m_Parent?.OnSpellCast( m, s ); } public virtual bool OnResurrect( Mobile m ) @@ -748,8 +738,7 @@ namespace Server public virtual void OnDeath( Mobile m ) { - if ( m_Parent != null ) - m_Parent.OnDeath( m ); + m_Parent?.OnDeath( m ); } public virtual bool OnDamage( Mobile m, ref int Damage ) @@ -794,8 +783,7 @@ namespace Server public virtual void AlterLightLevel( Mobile m, ref int global, ref int personal ) { - if ( m_Parent != null ) - m_Parent.AlterLightLevel( m, ref global, ref personal ); + m_Parent?.AlterLightLevel( m, ref global, ref personal ); } public virtual TimeSpan GetLogoutDelay( Mobile m ) diff --git a/Server/SecureTrade.cs b/Server/SecureTrade.cs index a70d674f2..df79a5459 100644 --- a/Server/SecureTrade.cs +++ b/Server/SecureTrade.cs @@ -185,17 +185,11 @@ namespace Server var ns = m_From.Mobile.NetState; - if (ns != null) - { - ns.RemoveTrade(this); - } + ns?.RemoveTrade(this); ns = m_To.Mobile.NetState; - if (ns != null) - { - ns.RemoveTrade(this); - } + ns?.RemoveTrade(this); Timer.DelayCall(m_From.Dispose); Timer.DelayCall(m_To.Dispose); diff --git a/Server/Skills.cs b/Server/Skills.cs index 229f0e474..889b83c62 100644 --- a/Server/Skills.cs +++ b/Server/Skills.cs @@ -251,8 +251,7 @@ namespace Server Mobile m = m_Owner.Owner; - if ( m != null ) - m.OnSkillChange( SkillName, (double)oldBase / 10 ); + m?.OnSkillChange( SkillName, (double)oldBase / 10 ); } } } @@ -1021,8 +1020,7 @@ namespace Server NetState ns = m_Owner.NetState; - if ( ns != null ) - ns.Send( new SkillChange( skill ) ); + ns?.Send( new SkillChange( skill ) ); } public IEnumerator GetEnumerator() diff --git a/Server/Targeting/Target.cs b/Server/Targeting/Target.cs index 74b04ca47..748290710 100644 --- a/Server/Targeting/Target.cs +++ b/Server/Targeting/Target.cs @@ -60,13 +60,11 @@ namespace Server.Targeting { NetState ns = m.NetState; - if ( ns != null ) - ns.Send( CancelTarget.Instance ); + ns?.Send( CancelTarget.Instance ); Target targ = m.Target; - if ( targ != null ) - targ.OnTargetCancel( m, TargetCancelType.Canceled ); + targ?.OnTargetCancel( m, TargetCancelType.Canceled ); } private Timer m_TimeoutTimer; @@ -75,8 +73,7 @@ namespace Server.Targeting { m_TimeoutTime = DateTime.UtcNow + delay; - if ( m_TimeoutTimer != null ) - m_TimeoutTimer.Stop(); + m_TimeoutTimer?.Stop(); m_TimeoutTimer = new TimeoutTimer( this, from, delay ); m_TimeoutTimer.Start(); @@ -84,8 +81,7 @@ namespace Server.Targeting public void CancelTimeout() { - if ( m_TimeoutTimer != null ) - m_TimeoutTimer.Stop(); + m_TimeoutTimer?.Stop(); m_TimeoutTimer = null; } diff --git a/Server/TileMatrix.cs b/Server/TileMatrix.cs index 6917e9e0c..ae3ee2f8e 100644 --- a/Server/TileMatrix.cs +++ b/Server/TileMatrix.cs @@ -516,14 +516,14 @@ namespace Server { if ( m_MapIndex != null ) m_MapIndex.Close(); - else if ( m_Map != null ) - m_Map.Close(); + else + { + m_Map?.Close(); + } - if ( m_Statics != null ) - m_Statics.Close(); + m_Statics?.Close(); - if ( m_IndexReader != null ) - m_IndexReader.Close(); + m_IndexReader?.Close(); } } diff --git a/Server/Timer.cs b/Server/Timer.cs index 78e86edf7..7927c3ff2 100644 --- a/Server/Timer.cs +++ b/Server/Timer.cs @@ -271,8 +271,7 @@ namespace Server Timer timer = tce.m_Timer; int newIndex = tce.m_NewIndex; - if (timer.m_List != null) - timer.m_List.Remove(timer); + timer.m_List?.Remove(timer); if (tce.m_IsAdd) { timer.m_Next = curTicks + timer.m_Delay; @@ -379,17 +378,13 @@ namespace Server Timer t = m_Queue.Dequeue(); TimerProfile prof = t.GetProfile(); - if ( prof != null ) { - prof.Start(); - } + prof?.Start(); t.OnTick(); t.m_Queued = false; ++index; - if ( prof != null ) { - prof.Finish(); - } + prof?.Finish(); } } } @@ -569,8 +564,7 @@ namespace Server protected override void OnTick() { - if ( m_Callback != null ) - m_Callback(); + m_Callback?.Invoke(); } public override string ToString() @@ -598,8 +592,7 @@ namespace Server protected override void OnTick() { - if ( m_Callback != null ) - m_Callback( m_State ); + m_Callback?.Invoke( m_State ); } public override string ToString() @@ -628,8 +621,7 @@ namespace Server protected override void OnTick() { - if ( m_Callback != null ) - m_Callback( m_State ); + m_Callback?.Invoke( m_State ); } public override string ToString()