Fixes casting, default parameters and null propogation in more files.

This commit is contained in:
Kamron Batman 2018-09-09 22:05:44 -07:00
parent 067dca8393
commit 403e2a8b9d
21 changed files with 328 additions and 523 deletions

View file

@ -8,11 +8,7 @@ namespace Server.Guilds
{ {
public class CreateGuildGump : Gump public class CreateGuildGump : Gump
{ {
public CreateGuildGump( PlayerMobile pm ) : this( pm, "Guild Name", "" ) public CreateGuildGump( PlayerMobile pm, string guildName = "Guild Name", string guildAbbrev = "") : base ( 10, 10 )
{
}
public CreateGuildGump( PlayerMobile pm, string guildName, string guildAbbrev ) : base( 10, 10 )
{ {
pm.CloseGump( typeof( CreateGuildGump ) ); pm.CloseGump( typeof( CreateGuildGump ) );
pm.CloseGump( typeof( BaseGuildGump ) ); pm.CloseGump( typeof( BaseGuildGump ) );

View file

@ -216,9 +216,7 @@ namespace Server.Misc
op.Write( "+ {0}:", state ); op.Write( "+ {0}:", state );
Account a = state.Account as Account; if ( state.Account is Account a )
if ( a != null )
op.Write( " (account = {0})", a.Username ); op.Write( " (account = {0})", a.Username );
Mobile m = state.Mobile; Mobile m = state.Mobile;

View file

@ -62,9 +62,9 @@ namespace Server.Items
{ {
Item deed = this.Deed; Item deed = this.Deed;
if ( this.Parent is Item ) if ( this.Parent is Item item )
{ {
((Item)this.Parent).AddItem( deed ); item.AddItem( deed );
deed.Location = this.Location; deed.Location = this.Location;
} }
else else
@ -241,9 +241,7 @@ namespace Server.Items
public void Placement_OnTarget( Mobile from, object targeted, object state ) public void Placement_OnTarget( Mobile from, object targeted, object state )
{ {
IPoint3D p = targeted as IPoint3D; if ( !(targeted is IPoint3D p) )
if ( p == null )
return; return;
Point3D loc = new Point3D( p ); Point3D loc = new Point3D( p );

View file

@ -107,9 +107,8 @@ namespace Server.Items
{ {
from.SendLocalizedMessage( 1005576 ); // You can't throw this at yourself. from.SendLocalizedMessage( 1005576 ); // You can't throw this at yourself.
} }
else if ( target is Mobile ) else if ( target is Mobile targ )
{ {
Mobile targ = (Mobile) target;
Container pack = targ.Backpack; Container pack = targ.Backpack;
if ( from.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) || targ.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) ) if ( from.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) || targ.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) )

View file

@ -93,16 +93,15 @@ namespace Server.Items
{ {
from.SendLocalizedMessage( 1005576 ); // You can't throw this at yourself. from.SendLocalizedMessage( 1005576 ); // You can't throw this at yourself.
} }
else if ( target is Mobile ) else if ( target is Mobile targ )
{ {
Mobile targ = (Mobile) target;
Container pack = targ.Backpack; Container pack = targ.Backpack;
if ( from.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) || targ.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) ) if ( from.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) || targ.Region.IsPartOf( typeof( Engines.ConPVP.SafeZone ) ) )
{ {
from.SendMessage( "You may not throw snow here." ); from.SendMessage( "You may not throw snow here." );
} }
else if ( pack != null && pack.FindItemByType( new Type[]{ typeof( SnowPile ), typeof( PileOfGlacialSnow ) } ) != null ) else if ( pack?.FindItemByType( new Type[]{ typeof( SnowPile ), typeof( PileOfGlacialSnow ) } ) != null )
{ {
if ( from.BeginAction( typeof( SnowPile ) ) ) if ( from.BeginAction( typeof( SnowPile ) ) )
{ {

View file

@ -598,27 +598,15 @@ namespace Server.Guilds
} }
else else
{ {
Guild g = null; Guild g = int.TryParse( arg, out int id ) ? Find( id ) as Guild :
FindByAbbrev( arg ) as Guild ?? FindByName( arg ) as Guild;
int id;
if ( int.TryParse( arg, out id ) )
g = Guild.Find( id ) as Guild;
if ( g == null )
{
g = Guild.FindByAbbrev( arg ) as Guild;
if ( g == null )
g = Guild.FindByName( arg ) as Guild;
}
if ( g != null ) if ( g != null )
{ {
from.SendGump( new PropertiesGump( from, g ) ); from.SendGump( new PropertiesGump( from, g ) );
if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && from is PlayerMobile ) if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && from is PlayerMobile mobile )
from.SendGump( new GuildInfoGump( (PlayerMobile)from, g ) ); mobile.SendGump( new GuildInfoGump( mobile, g ) );
} }
} }
@ -640,33 +628,31 @@ namespace Server.Guilds
Guild g = null; Guild g = null;
if ( o is Guildstone ) if ( o is Guildstone stone )
{ {
Guildstone stone = o as Guildstone;
if ( stone.Guild == null || stone.Guild.Disbanded ) if ( stone.Guild == null || stone.Guild.Disbanded )
{ {
from.SendMessage( "The guild associated with that Guildstone no longer exists" ); from.SendMessage( "The guild associated with that Guildstone no longer exists" );
return; return;
} }
else
g = stone.Guild; g = stone.Guild;
} }
else if ( o is Mobile ) else if ( o is Mobile mobile )
{ {
g = ((Mobile)o).Guild as Guild; g = mobile.Guild as Guild;
} }
if ( g != null ) if (g == null)
{ {
from.SendGump( new PropertiesGump( from, g ) ); from.SendMessage("That is not in a guild!");
return;
}
if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && from is PlayerMobile ) from.SendGump( new PropertiesGump( from, g ) );
from.SendGump( new GuildInfoGump( (PlayerMobile)from, g ) );
} if ( NewGuildSystem && from.AccessLevel >= AccessLevel.GameMaster && @from is PlayerMobile pm )
else pm.SendGump( new GuildInfoGump( pm, g ) );
{
from.SendMessage( "That is not in a guild!" );
}
} }
} }
#endregion #endregion
@ -674,8 +660,7 @@ namespace Server.Guilds
#region EventSinks #region EventSinks
public static void EventSink_GuildGumpRequest( GuildGumpRequestArgs args ) public static void EventSink_GuildGumpRequest( GuildGumpRequestArgs args )
{ {
PlayerMobile pm = args.Mobile as PlayerMobile; if ( !NewGuildSystem || !(args.Mobile is PlayerMobile pm) )
if ( !NewGuildSystem || pm == null )
return; return;
if ( pm.Guild == null ) if ( pm.Guild == null )
@ -707,10 +692,8 @@ namespace Server.Guilds
get{ get{
if ( m_AllianceInfo != null ) if ( m_AllianceInfo != null )
return m_AllianceInfo; return m_AllianceInfo;
else if ( m_AllianceLeader != null )
return m_AllianceLeader.m_AllianceInfo; return m_AllianceLeader?.m_AllianceInfo;
else
return null;
} }
set set
{ {
@ -719,10 +702,7 @@ namespace Server.Guilds
if ( value == current ) if ( value == current )
return; return;
if ( current != null ) current?.RemoveGuild( this );
{
current.RemoveGuild( this );
}
if ( value != null ) if ( value != null )
{ {
@ -747,11 +727,7 @@ namespace Server.Guilds
{ {
get get
{ {
AllianceInfo al = this.Alliance; return Alliance?.Name;
if ( al != null )
return al.Name;
return null;
} }
} }
@ -760,12 +736,7 @@ namespace Server.Guilds
{ {
get get
{ {
AllianceInfo al = this.Alliance; return Alliance?.Leader;
if ( al != null )
return al.Leader;
return null;
} }
} }
@ -774,12 +745,7 @@ namespace Server.Guilds
{ {
get get
{ {
AllianceInfo al = this.Alliance; return Alliance?.IsMember( this ) == true;
if ( al != null )
return al.IsMember( this );
return false;
} }
} }
@ -788,12 +754,7 @@ namespace Server.Guilds
{ {
get get
{ {
AllianceInfo al = this.Alliance; return Alliance?.IsPendingMember( this ) == true;
if ( al != null )
return al.IsPendingMember( this );
return false;
} }
} }
@ -801,7 +762,7 @@ namespace Server.Guilds
{ {
AllianceInfo alliance = g.Alliance; AllianceInfo alliance = g.Alliance;
if ( alliance != null && alliance.Leader != null && alliance.IsMember( g ) ) if ( alliance?.Leader != null && alliance.IsMember( g ) )
return alliance.Leader; return alliance.Leader;
return g; return g;
@ -859,9 +820,9 @@ namespace Server.Guilds
if ( status != WarStatus.InProgress ) if ( status != WarStatus.InProgress )
{ {
AllianceInfo myAlliance = this.Alliance; AllianceInfo myAlliance = this.Alliance;
bool inAlliance = ( myAlliance != null && myAlliance.IsMember( this ) ); bool inAlliance = myAlliance?.IsMember( this ) == true;
AllianceInfo otherAlliance = ((g != null) ? g.Alliance : null); AllianceInfo otherAlliance = g?.Alliance;
bool otherInAlliance = ( otherAlliance != null && otherAlliance.IsMember( this ) ); bool otherInAlliance = ( otherAlliance != null && otherAlliance.IsMember( this ) );
if ( inAlliance ) if ( inAlliance )
@ -908,10 +869,7 @@ namespace Server.Guilds
//All sanity in here //All sanity in here
this.PendingWars.Remove( w ); this.PendingWars.Remove( w );
if ( g != null ) g?.PendingWars.Remove( g.FindPendingWar( this ) );
{
g.PendingWars.Remove( g.FindPendingWar( this ) );
}
} }
} }
} }
@ -1006,8 +964,8 @@ namespace Server.Guilds
AddMember( m_Leader ); AddMember( m_Leader );
if ( m_Leader is PlayerMobile ) if ( m_Leader is PlayerMobile mobile )
((PlayerMobile)m_Leader).GuildRank = RankDefinition.Leader; mobile.GuildRank = RankDefinition.Leader;
m_AcceptedWars = new List<WarDeclaration>(); m_AcceptedWars = new List<WarDeclaration>();
m_PendingWars = new List<WarDeclaration>(); m_PendingWars = new List<WarDeclaration>();
@ -1018,12 +976,7 @@ namespace Server.Guilds
{ {
} }
public void InvalidateMemberProperties() public void InvalidateMemberProperties( bool onlyOPL = false)
{
InvalidateMemberProperties( false );
}
public void InvalidateMemberProperties( bool onlyOPL )
{ {
if ( m_Members != null ) if ( m_Members != null )
{ {
@ -1042,7 +995,7 @@ namespace Server.Guilds
{ {
if ( m_Members != null ) if ( m_Members != null )
{ {
for (int i=0;i<m_Members.Count;i++) for (int i=0; i < m_Members.Count; i++)
m_Members[i].Delta( MobileDelta.Noto ); m_Members[i].Delta( MobileDelta.Noto );
} }
} }
@ -1085,13 +1038,13 @@ namespace Server.Guilds
if ( value != null ) if ( value != null )
this.AddMember( value ); //Also removes from old guild. this.AddMember( value ); //Also removes from old guild.
if ( m_Leader is PlayerMobile && m_Leader.Guild == this ) if ( m_Leader is PlayerMobile leader && leader?.Guild == this )
((PlayerMobile)m_Leader).GuildRank = RankDefinition.Member; leader.GuildRank = RankDefinition.Member;
m_Leader = value; m_Leader = value;
if ( m_Leader is PlayerMobile ) if ( m_Leader is PlayerMobile mobile )
((PlayerMobile)m_Leader).GuildRank = RankDefinition.Leader; mobile.GuildRank = RankDefinition.Leader;
} }
} }
@ -1120,8 +1073,8 @@ namespace Server.Guilds
{ {
m.SendLocalizedMessage( 502131 ); // Your guild has disbanded. m.SendLocalizedMessage( 502131 ); // Your guild has disbanded.
if ( m is PlayerMobile ) if ( m is PlayerMobile mobile )
((PlayerMobile)m).GuildRank = RankDefinition.Lowest; mobile.GuildRank = RankDefinition.Lowest;
m.Guild = null; m.Guild = null;
} }
@ -1136,8 +1089,8 @@ namespace Server.Guilds
if ( i < m_Enemies.Count ) if ( i < m_Enemies.Count )
RemoveEnemy( m_Enemies[i] ); RemoveEnemy( m_Enemies[i] );
if ( !NewGuildSystem && m_Guildstone != null ) if ( !NewGuildSystem )
m_Guildstone.Delete(); m_Guildstone?.Delete();
m_Guildstone = null; m_Guildstone = null;
@ -1198,8 +1151,7 @@ namespace Server.Guilds
CheckExpiredWars(); CheckExpiredWars();
if ( Alliance != null ) Alliance?.CheckLeader();
Alliance.CheckLeader();
writer.Write( (int) 5 );//version writer.Write( (int) 5 );//version
@ -1324,8 +1276,8 @@ namespace Server.Guilds
{ {
m_Leader = reader.ReadMobile(); m_Leader = reader.ReadMobile();
if ( m_Leader is PlayerMobile ) if ( m_Leader is PlayerMobile mobile )
((PlayerMobile)m_Leader).GuildRank = RankDefinition.Leader; mobile.GuildRank = RankDefinition.Leader;
m_Name = reader.ReadString(); m_Name = reader.ReadString();
m_Abbreviation = reader.ReadString(); m_Abbreviation = reader.ReadString();
@ -1380,8 +1332,7 @@ namespace Server.Guilds
AllianceInfo alliance = this.Alliance; AllianceInfo alliance = this.Alliance;
if ( alliance != null ) alliance?.CheckLeader();
alliance.CheckLeader();
alliance = this.Alliance; //CheckLeader could possibly change the value of this.Alliance alliance = this.Alliance; //CheckLeader could possibly change the value of this.Alliance
@ -1408,13 +1359,10 @@ namespace Server.Guilds
else else
m.GuildFealty = null; m.GuildFealty = null;
if ( m is PlayerMobile ) if ( m is PlayerMobile mobile )
((PlayerMobile)m).GuildRank = RankDefinition.Lowest; mobile.GuildRank = RankDefinition.Lowest;
Guild guild = m.Guild as Guild; ((Guild)m.Guild).InvalidateWarNotoriety();
if ( guild != null )
guild.InvalidateWarNotoriety();
} }
} }
@ -1432,8 +1380,8 @@ namespace Server.Guilds
m.Guild = null; m.Guild = null;
if ( m is PlayerMobile ) if ( m is PlayerMobile mobile )
((PlayerMobile)m).GuildRank = RankDefinition.Lowest; mobile.GuildRank = RankDefinition.Lowest;
if ( message > 0 ) if ( message > 0 )
m.SendLocalizedMessage( message ); m.SendLocalizedMessage( message );
@ -1449,8 +1397,7 @@ namespace Server.Guilds
if ( m_Members.Count == 0 ) if ( m_Members.Count == 0 )
Disband(); Disband();
if ( guild != null ) guild?.InvalidateWarNotoriety();
guild.InvalidateWarNotoriety();
m.Delta( MobileDelta.Noto ); m.Delta( MobileDelta.Noto );
} }
@ -1508,24 +1455,14 @@ namespace Server.Guilds
for ( int i = 0; i < m_Members.Count; ++i ) for ( int i = 0; i < m_Members.Count; ++i )
m_Members[i].SendLocalizedMessage( number ); m_Members[i].SendLocalizedMessage( number );
} }
public void GuildMessage( int number, string args )
{ public void GuildMessage( int number, string args, int hue = 0x3B2)
GuildMessage( number, args, 0x3B2 );
}
public void GuildMessage( int number, string args, int hue )
{ {
for ( int i = 0; i < m_Members.Count; ++i ) for ( int i = 0; i < m_Members.Count; ++i )
m_Members[i].SendLocalizedMessage( number, args, hue ); m_Members[i].SendLocalizedMessage( number, args, hue );
} }
public void GuildMessage( int number, bool append, string affix )
{ public void GuildMessage( int number, bool append, string affix, string args = "", int hue = 0x3B2)
GuildMessage( number, append, affix, "", 0x3B2 );
}
public void GuildMessage( int number, bool append, string affix, string args )
{
GuildMessage( number, append, affix, args, 0x3B2 );
}
public void GuildMessage( int number, bool append, string affix, string args, int hue )
{ {
for ( int i = 0; i < m_Members.Count; ++i ) for ( int i = 0; i < m_Members.Count; ++i )
m_Members[i].SendLocalizedMessage( number, append, affix, args, hue ); m_Members[i].SendLocalizedMessage( number, append, affix, args, hue );
@ -1552,7 +1489,7 @@ namespace Server.Guilds
public void GuildChat( Mobile from, int hue, string text ) public void GuildChat( Mobile from, int hue, string text )
{ {
Packet p = null; Packet p = null;
for( int i = 0; i < m_Members.Count; i++ ) for ( int i = 0; i < m_Members.Count; i++ )
{ {
Mobile m = m_Members[i]; Mobile m = m_Members[i];
@ -1574,7 +1511,7 @@ namespace Server.Guilds
{ {
PlayerMobile pm = from as PlayerMobile; PlayerMobile pm = from as PlayerMobile;
GuildChat( from, (pm == null) ? 0x3B2 : pm.GuildMessageHue, text ); GuildChat( from, pm?.GuildMessageHue ?? 0x3B2, text );
} }
#endregion #endregion
@ -1583,8 +1520,7 @@ namespace Server.Guilds
{ {
if ( NewGuildSystem ) if ( NewGuildSystem )
{ {
PlayerMobile pm = m as PlayerMobile; if ( !(m is PlayerMobile pm) || !pm.GuildRank.GetFlag( RankFlags.CanVote ) )
if ( pm == null || !pm.GuildRank.GetFlag( RankFlags.CanVote ) )
return false; return false;
} }
@ -1594,8 +1530,7 @@ namespace Server.Guilds
{ {
if ( NewGuildSystem ) if ( NewGuildSystem )
{ {
PlayerMobile pm = m as PlayerMobile; if ( !(m is PlayerMobile pm) || pm.LastOnline + InactiveTime < DateTime.UtcNow )
if ( pm == null || pm.LastOnline + InactiveTime < DateTime.UtcNow )
return false; return false;
} }
@ -1641,8 +1576,8 @@ namespace Server.Guilds
foreach ( KeyValuePair<Mobile, int> kvp in votes ) foreach ( KeyValuePair<Mobile, int> kvp in votes )
{ {
Mobile m = (Mobile)kvp.Key; Mobile m = kvp.Key;
int val = (int)kvp.Value; int val = kvp.Value;
if ( winner == null || val > highVotes ) if ( winner == null || val > highVotes )
{ {
@ -1703,8 +1638,7 @@ namespace Server.Guilds
InvalidateMemberProperties( true ); InvalidateMemberProperties( true );
if ( m_Guildstone != null ) m_Guildstone?.InvalidateProperties();
m_Guildstone.InvalidateProperties();
} }
} }
@ -1734,8 +1668,7 @@ namespace Server.Guilds
InvalidateMemberProperties( true ); InvalidateMemberProperties( true );
if ( m_Guildstone != null ) m_Guildstone?.InvalidateProperties();
m_Guildstone.InvalidateProperties();
} }
} }
@ -1864,7 +1797,6 @@ namespace Server.Guilds
return m_Members; return m_Members;
} }
} }
#endregion #endregion
} }
} }

View file

@ -117,12 +117,9 @@ namespace Server
public static void HWInfo_OnTarget( Mobile from, object obj ) public static void HWInfo_OnTarget( Mobile from, object obj )
{ {
if ( obj is Mobile && ((Mobile)obj).Player ) if ( obj is Mobile m && m.Player )
{ {
Mobile m = (Mobile)obj; if ( m.Account is Account acct )
Account acct = m.Account as Account;
if ( acct != null )
{ {
HardwareInfo hwInfo = acct.HardwareInfo; HardwareInfo hwInfo = acct.HardwareInfo;
@ -180,9 +177,7 @@ namespace Server
info.m_TimeReceived = DateTime.UtcNow; info.m_TimeReceived = DateTime.UtcNow;
Account acct = state.Account as Account; if ( state.Account is Account acct )
if ( acct != null )
acct.HardwareInfo = info; acct.HardwareInfo = info;
} }
} }

View file

@ -26,8 +26,7 @@ namespace Server.Misc
{ {
case 0x002A: // *i resign from my guild* case 0x002A: // *i resign from my guild*
{ {
if ( from.Guild != null ) ((Guild)@from.Guild)?.RemoveMember( @from );
((Guild)from.Guild).RemoveMember( from );
break; break;
} }
@ -46,9 +45,9 @@ namespace Server.Misc
} }
case 0x0035: // i renounce my young player status* case 0x0035: // i renounce my young player status*
{ {
if ( from is PlayerMobile && ((PlayerMobile)from).Young && !from.HasGump( typeof( RenounceYoungGump ) ) ) if ( @from is PlayerMobile mobile && mobile.Young && !mobile.HasGump( typeof( RenounceYoungGump ) ) )
{ {
from.SendGump( new RenounceYoungGump() ); mobile.SendGump( new RenounceYoungGump() );
} }
break; break;

View file

@ -16,8 +16,7 @@ namespace Server
int luck = killer.Luck; int luck = killer.Luck;
PlayerMobile pmKiller = killer as PlayerMobile; if ( killer is PlayerMobile pmKiller && pmKiller.SentHonorContext != null && pmKiller.SentHonorContext.Target == victim )
if ( pmKiller != null && pmKiller.SentHonorContext != null && pmKiller.SentHonorContext.Target == victim )
luck += pmKiller.SentHonorContext.PerfectionLuckBonus; luck += pmKiller.SentHonorContext.PerfectionLuckBonus;
if ( luck < 0 ) if ( luck < 0 )
@ -661,21 +660,19 @@ namespace Server
if ( props > m_MaxProps ) if ( props > m_MaxProps )
props = m_MaxProps; props = m_MaxProps;
if ( item is BaseWeapon ) if ( item is BaseWeapon weapon )
BaseRunicTool.ApplyAttributesTo( (BaseWeapon)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity ); BaseRunicTool.ApplyAttributesTo( weapon, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
else if ( item is BaseArmor ) else if ( item is BaseArmor armor )
BaseRunicTool.ApplyAttributesTo( (BaseArmor)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity ); BaseRunicTool.ApplyAttributesTo( armor, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
else if ( item is BaseJewel ) else if ( item is BaseJewel jewel )
BaseRunicTool.ApplyAttributesTo( (BaseJewel)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity ); BaseRunicTool.ApplyAttributesTo( jewel, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
else if ( item is BaseHat ) else
BaseRunicTool.ApplyAttributesTo( (BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity ); BaseRunicTool.ApplyAttributesTo( (BaseHat)item, false, luckChance, props, m_MinIntensity, m_MaxIntensity );
} }
else // not aos else // not aos
{ {
if ( item is BaseWeapon ) if ( item is BaseWeapon weapon )
{ {
BaseWeapon weapon = (BaseWeapon)item;
if ( 80 > Utility.Random( 100 ) ) if ( 80 > Utility.Random( 100 ) )
weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus(); weapon.AccuracyLevel = (WeaponAccuracyLevel)GetRandomOldBonus();
@ -691,10 +688,8 @@ namespace Server
if ( from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random( 100 ) ) if ( from != null && weapon.AccuracyLevel == 0 && weapon.DamageLevel == 0 && weapon.DurabilityLevel == 0 && weapon.Slayer == SlayerName.None && 5 > Utility.Random( 100 ) )
weapon.Slayer = SlayerGroup.GetLootSlayerType( from.GetType() ); weapon.Slayer = SlayerGroup.GetLootSlayerType( from.GetType() );
} }
else if ( item is BaseArmor ) else if ( item is BaseArmor armor )
{ {
BaseArmor armor = (BaseArmor)item;
if ( 80 > Utility.Random( 100 ) ) if ( 80 > Utility.Random( 100 ) )
armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus(); armor.ProtectionLevel = (ArmorProtectionLevel)GetRandomOldBonus();
@ -703,7 +698,7 @@ namespace Server
} }
} }
} }
else if ( item is BaseInstrument ) else if ( item is BaseInstrument instr )
{ {
SlayerName slayer = SlayerName.None; SlayerName slayer = SlayerName.None;
@ -714,12 +709,10 @@ namespace Server
if ( slayer == SlayerName.None ) if ( slayer == SlayerName.None )
{ {
item.Delete(); instr.Delete();
return null; return null;
} }
BaseInstrument instr = (BaseInstrument)item;
instr.Quality = InstrumentQuality.Regular; instr.Quality = InstrumentQuality.Regular;
instr.Slayer = slayer; instr.Slayer = slayer;
} }
@ -777,28 +770,23 @@ namespace Server
if ( rnd < p5 ) if ( rnd < p5 )
return 5; return 5;
else
rnd -= p5; rnd -= p5;
if ( rnd < p4 ) if ( rnd < p4 )
return 4; return 4;
else
rnd -= p4; rnd -= p4;
if ( rnd < p3 ) if ( rnd < p3 )
return 3; return 3;
else
rnd -= p3; rnd -= p3;
if ( rnd < p2 ) if ( rnd < p2 )
return 2; return 2;
else
rnd -= p2;
if ( rnd < p1 ) return rnd - p2 < p1 ? 1 : 0;
return 1;
return 0;
} }
} }
@ -861,13 +849,11 @@ namespace Server
if ( index == 0 && rnd < m_BlankTypes.Length ) if ( index == 0 && rnd < m_BlankTypes.Length )
return Loot.Construct( m_BlankTypes ); return Loot.Construct( m_BlankTypes );
else if ( index == 0 ) if ( index == 0 )
rnd -= m_BlankTypes.Length; rnd -= m_BlankTypes.Length;
if ( Core.AOS && rnd < m_NecroTypes.Length ) if ( Core.AOS && rnd < m_NecroTypes.Length )
return Loot.Construct( m_NecroTypes[index] ); return Loot.Construct( m_NecroTypes[index] );
else if ( Core.AOS )
rnd -= m_NecroTypes[index].Length;
return Loot.RandomScroll( minCircle * 8, (maxCircle * 8) + 7, SpellbookType.Regular ); return Loot.RandomScroll( minCircle * 8, (maxCircle * 8) + 7, SpellbookType.Regular );
} }
@ -959,12 +945,12 @@ namespace Server
m_Count = Utility.ToInt32( str.Substring( start, index-start ) ); m_Count = Utility.ToInt32( str.Substring( start, index-start ) );
bool negative;
start = index + 1; start = index + 1;
index = str.IndexOf( '+', start ); index = str.IndexOf( '+', start );
if ( negative = (index < start) ) bool negative = index < start;
if ( negative )
index = str.IndexOf( '-', start ); index = str.IndexOf( '-', start );
if ( index < start ) if ( index < start )

View file

@ -42,9 +42,8 @@ namespace Server.Misc
private static void OnGuildTrack( NetState state, PacketReader pvSrc ) private static void OnGuildTrack( NetState state, PacketReader pvSrc )
{ {
Mobile from = state.Mobile; Mobile from = state.Mobile;
Guild guild = from.Guild as Guild;
if ( guild != null ) if ( @from.Guild is Guild guild )
{ {
bool locations = pvSrc.ReadByte() != 0; bool locations = pvSrc.ReadByte() != 0;
@ -78,7 +77,7 @@ namespace Server.Misc
m_Stream.Write( (int) mob.Serial ); m_Stream.Write( (int) mob.Serial );
m_Stream.Write( (short) mob.X ); m_Stream.Write( (short) mob.X );
m_Stream.Write( (short) mob.Y ); m_Stream.Write( (short) mob.Y );
m_Stream.Write( (byte) ( mob.Map == null ? 0 : mob.Map.MapID ) ); m_Stream.Write( (byte) (mob.Map?.MapID ?? 0) );
} }
m_Stream.Write( (int) 0 ); m_Stream.Write( (int) 0 );
@ -113,7 +112,7 @@ namespace Server.Misc
{ {
m_Stream.Write( (short) mob.X ); m_Stream.Write( (short) mob.X );
m_Stream.Write( (short) mob.Y ); m_Stream.Write( (short) mob.Y );
m_Stream.Write( (byte) ( mob.Map == null ? 0 : mob.Map.MapID ) ); m_Stream.Write( (byte) (mob.Map?.MapID ?? 0) );
if ( Settings.GuildHitsPercent && mob.Alive ) if ( Settings.GuildHitsPercent && mob.Alive )
m_Stream.Write( (byte) ( mob.Hits / Math.Max( mob.HitsMax, 1.0 ) * 100 ) ); m_Stream.Write( (byte) ( mob.Hits / Math.Max( mob.HitsMax, 1.0 ) * 100 ) );

View file

@ -29,9 +29,7 @@ namespace Server
public static void GiveArtifactTo( Mobile m ) public static void GiveArtifactTo( Mobile m )
{ {
Item item = Activator.CreateInstance( m_Artifacts[Utility.Random( m_Artifacts.Length )] ) as Item; if ( !(Activator.CreateInstance( m_Artifacts[Utility.Random( m_Artifacts.Length )] ) is Item item) )
if ( item == null )
return; return;
if ( m.AddToBackpack( item ) ) if ( m.AddToBackpack( item ) )
@ -51,14 +49,9 @@ namespace Server
} }
} }
public static bool CheckML( Mobile from ) public static bool CheckML( Mobile from, bool message = true)
{ {
return CheckML( from, true ); if ( @from?.NetState == null )
}
public static bool CheckML( Mobile from, bool message )
{
if ( from == null || from.NetState == null )
return false; return false;
if ( from.NetState.SupportsExpansion( Expansion.ML ) ) if ( from.NetState.SupportsExpansion( Expansion.ML ) )

View file

@ -2,6 +2,7 @@ using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using Server; using Server;
using Server.Engines.ConPVP;
using Server.Items; using Server.Items;
using Server.Guilds; using Server.Guilds;
using Server.Multis; using Server.Multis;
@ -69,18 +70,14 @@ namespace Server.Misc
PlayerMobile pmFrom = from as PlayerMobile; PlayerMobile pmFrom = from as PlayerMobile;
PlayerMobile pmTarg = target as PlayerMobile; PlayerMobile pmTarg = target as PlayerMobile;
if ( pmFrom == null && from is BaseCreature ) if ( pmFrom == null && @from is BaseCreature bcFrom )
{ {
BaseCreature bcFrom = (BaseCreature)from;
if ( bcFrom.Summoned ) if ( bcFrom.Summoned )
pmFrom = bcFrom.SummonMaster as PlayerMobile; pmFrom = bcFrom.SummonMaster as PlayerMobile;
} }
if ( pmTarg == null && target is BaseCreature ) if ( pmTarg == null && target is BaseCreature bcTarg )
{ {
BaseCreature bcTarg = (BaseCreature)target;
if ( bcTarg.Summoned ) if ( bcTarg.Summoned )
pmTarg = bcTarg.SummonMaster as PlayerMobile; pmTarg = bcTarg.SummonMaster as PlayerMobile;
} }
@ -103,12 +100,10 @@ namespace Server.Misc
return true; return true;
} }
if ( (pmFrom != null && pmFrom.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg != null && pmTarg.DuelContext != null && pmTarg.DuelContext.Started) ) if ( (pmFrom?.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) )
return false; return false;
Engines.ConPVP.SafeZone sz = from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; if ( @from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ )
if ( sz != null /*&& sz.IsDisabled()*/ )
return false; return false;
sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone;
@ -136,16 +131,13 @@ namespace Server.Misc
if ( !from.Player ) if ( !from.Player )
return true; // NPCs have no restrictions return true; // NPCs have no restrictions
if ( target is BaseCreature && !((BaseCreature)target).Controlled ) if ( target is BaseCreature creature && !creature.Controlled )
return false; // Players cannot heal uncontrolled mobiles return false; // Players cannot heal uncontrolled mobiles
if ( from is PlayerMobile && ((PlayerMobile)from).Young && (!(target is PlayerMobile) || !((PlayerMobile)target).Young) ) if ( pmFrom?.Young == true || pmTarg?.Young == true )
return false; // Young players cannot perform beneficial actions towards older players return false; // Young players cannot perform beneficial actions towards older players
Guild fromGuild = from.Guild as Guild; if ( @from.Guild is Guild fromGuild && target.Guild is Guild targetGuild && (targetGuild == fromGuild || fromGuild.IsAlly( targetGuild )) )
Guild targetGuild = target.Guild as Guild;
if ( fromGuild != null && targetGuild != null && (targetGuild == fromGuild || fromGuild.IsAlly( targetGuild )) )
return true; // Guild members can be beneficial return true; // Guild members can be beneficial
return CheckBeneficialStatus( GetGuildStatus( from ), GetGuildStatus( target ) ); return CheckBeneficialStatus( GetGuildStatus( from ), GetGuildStatus( target ) );
@ -159,22 +151,13 @@ namespace Server.Misc
#region Dueling #region Dueling
PlayerMobile pmFrom = from as PlayerMobile; PlayerMobile pmFrom = from as PlayerMobile;
PlayerMobile pmTarg = target as PlayerMobile; PlayerMobile pmTarg = target as PlayerMobile;
BaseCreature bcTarg = target as BaseCreature;
if ( pmFrom == null && from is BaseCreature ) if ( pmFrom == null && @from is BaseCreature bcFrom && bcFrom.Summoned )
{ pmFrom = bcFrom.SummonMaster as PlayerMobile;
BaseCreature bcFrom = (BaseCreature)from;
if ( bcFrom.Summoned ) if ( pmTarg == null && bcTarg?.Summoned == true )
pmFrom = bcFrom.SummonMaster as PlayerMobile; pmTarg = bcTarg.SummonMaster as PlayerMobile;
}
if ( pmTarg == null && target is BaseCreature )
{
BaseCreature bcTarg = (BaseCreature)target;
if ( bcTarg.Summoned )
pmTarg = bcTarg.SummonMaster as PlayerMobile;
}
if ( pmFrom != null && pmTarg != null ) if ( pmFrom != null && pmTarg != null )
{ {
@ -191,12 +174,10 @@ namespace Server.Misc
return true; return true;
} }
if ( (pmFrom != null && pmFrom.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg != null && pmTarg.DuelContext != null && pmTarg.DuelContext.Started) ) if ( (pmFrom?.DuelContext != null && pmFrom.DuelContext.Started) || (pmTarg?.DuelContext != null && pmTarg.DuelContext.Started) )
return false; return false;
Engines.ConPVP.SafeZone sz = from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; if ( @from.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) is SafeZone sz /*&& sz.IsDisabled()*/ )
if ( sz != null /*&& sz.IsDisabled()*/ )
return false; return false;
sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone; sz = target.Region.GetRegion( typeof( Engines.ConPVP.SafeZone ) ) as Engines.ConPVP.SafeZone;
@ -210,11 +191,9 @@ namespace Server.Misc
if ( map != null && (map.Rules & MapRules.HarmfulRestrictions) == 0 ) if ( map != null && (map.Rules & MapRules.HarmfulRestrictions) == 0 )
return true; // In felucca, anything goes return true; // In felucca, anything goes
BaseCreature bc = from as BaseCreature; if ( !from.Player && !(@from is BaseCreature bc && bc.GetMaster() != null && bc.GetMaster().AccessLevel == AccessLevel.Player ) )
if ( !from.Player && !(bc != null && bc.GetMaster() != null && bc.GetMaster().AccessLevel == AccessLevel.Player ) )
{ {
if ( !CheckAggressor( from.Aggressors, target ) && !CheckAggressed( from.Aggressed, target ) && target is PlayerMobile && ((PlayerMobile)target).CheckYoungProtection( from ) ) if ( !CheckAggressor( from.Aggressors, target ) && !CheckAggressed( from.Aggressed, target ) && pmTarg?.CheckYoungProtection( from ) == true )
return false; return false;
return true; // Uncontrolled NPCs are only restricted by the young system return true; // Uncontrolled NPCs are only restricted by the young system
@ -226,13 +205,13 @@ namespace Server.Misc
if ( fromGuild != null && targetGuild != null && (fromGuild == targetGuild || fromGuild.IsAlly( targetGuild ) || fromGuild.IsEnemy( targetGuild )) ) if ( fromGuild != null && targetGuild != null && (fromGuild == targetGuild || fromGuild.IsAlly( targetGuild ) || fromGuild.IsEnemy( targetGuild )) )
return true; // Guild allies or enemies can be harmful return true; // Guild allies or enemies can be harmful
if ( target is BaseCreature && (((BaseCreature)target).Controlled || (((BaseCreature)target).Summoned && from != ((BaseCreature)target).SummonMaster)) ) if ( bcTarg?.Controlled == true || bcTarg?.Summoned == true && bcTarg?.SummonMaster != from )
return false; // Cannot harm other controlled mobiles return false; // Cannot harm other controlled mobiles
if ( target.Player ) if ( target.Player )
return false; // Cannot harm other players return false; // Cannot harm other players
if ( !(target is BaseCreature && ((BaseCreature)target).InitialInnocent) ) if ( bcTarg?.InitialInnocent != true )
{ {
if ( Notoriety.Compute( from, target ) == Notoriety.Innocent ) if ( Notoriety.Compute( from, target ) == Notoriety.Innocent )
return false; // Cannot harm innocent mobiles return false; // Cannot harm innocent mobiles
@ -245,9 +224,7 @@ namespace Server.Misc
{ {
Guild g = def; Guild g = def;
BaseCreature c = m as BaseCreature; if ( m is BaseCreature c && c.Controlled && c.ControlMaster != null )
if ( c != null && c.Controlled && c.ControlMaster != null )
{ {
c.DisplayGuildTitle = false; c.DisplayGuildTitle = false;
@ -265,119 +242,94 @@ namespace Server.Misc
if ( target.AccessLevel > AccessLevel.Player ) if ( target.AccessLevel > AccessLevel.Player )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
Body body = (Body)target.Amount; Body body = target.Amount;
BaseCreature cretOwner = target.Owner as BaseCreature; Guild sourceGuild = GetGuildFor( source.Guild as Guild, source );
Guild targetGuild = GetGuildFor( target.Guild, target.Owner );
if ( cretOwner != null ) Faction srcFaction = Faction.Find( source, true, true );
Faction trgFaction = Faction.Find( target.Owner, true, true );
List<Mobile> list = target.Aggressors;
if ( sourceGuild != null && targetGuild != null )
{ {
Guild sourceGuild = GetGuildFor( source.Guild as Guild, source ); if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
Guild targetGuild = GetGuildFor( target.Guild as Guild, target.Owner ); return Notoriety.Ally;
if ( sourceGuild.IsEnemy( targetGuild ) )
if ( sourceGuild != null && targetGuild != null ) return Notoriety.Enemy;
{ }
if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
return Notoriety.Ally;
else if ( sourceGuild.IsEnemy( targetGuild ) )
return Notoriety.Enemy;
}
Faction srcFaction = Faction.Find( source, true, true );
Faction trgFaction = Faction.Find( target.Owner, true, true );
if ( target.Owner is BaseCreature creature )
{
if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet ) if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
return Notoriety.Enemy; return Notoriety.Enemy;
if ( CheckHouseFlag( source, target.Owner, target.Location, target.Map ) ) if ( CheckHouseFlag( source, creature, target.Location, target.Map ) )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
int actual = Notoriety.CanBeAttacked; int actual = Notoriety.CanBeAttacked;
if ( target.Kills >= 5 || (body.IsMonster && IsSummoned( target.Owner as BaseCreature )) || (target.Owner is BaseCreature && (((BaseCreature)target.Owner).AlwaysMurderer || ((BaseCreature)target.Owner).IsAnimatedDead)) ) if ( target.Kills >= 5 || body.IsMonster && IsSummoned( creature ) || creature.AlwaysMurderer || creature.IsAnimatedDead )
actual = Notoriety.Murderer; actual = Notoriety.Murderer;
if ( DateTime.UtcNow >= (target.TimeOfDeath + Corpse.MonsterLootRightSacrifice) ) if ( DateTime.UtcNow >= target.TimeOfDeath + Corpse.MonsterLootRightSacrifice )
return actual; return actual;
Party sourceParty = Party.Get( source ); Party sourceParty = Party.Get( source );
List<Mobile> list = target.Aggressors;
for( int i = 0; i < list.Count; ++i ) for( int i = 0; i < list.Count; ++i )
{ {
if ( list[i] == source || (sourceParty != null && Party.Get( list[i] ) == sourceParty) ) if ( list[i] == source || sourceParty != null && Party.Get( list[i] ) == sourceParty )
return actual; return actual;
} }
return Notoriety.Innocent; return Notoriety.Innocent;
} }
else
if ( target.Kills >= 5 || body.IsMonster )
return Notoriety.Murderer;
if (target.Criminal && target.Map != null && (target.Map.Rules & MapRules.HarmfulRestrictions) == 0)
return Notoriety.Criminal;
if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
{ {
if ( target.Kills >= 5 || (body.IsMonster && IsSummoned( target.Owner as BaseCreature )) || (target.Owner is BaseCreature && (((BaseCreature)target.Owner).AlwaysMurderer || ((BaseCreature)target.Owner).IsAnimatedDead)) ) for ( int i = 0; i < list.Count; ++i )
return Notoriety.Murderer;
if (target.Criminal && target.Map != null && ((target.Map.Rules & MapRules.HarmfulRestrictions) == 0))
return Notoriety.Criminal;
Guild sourceGuild = GetGuildFor( source.Guild as Guild, source );
Guild targetGuild = GetGuildFor( target.Guild as Guild, target.Owner );
if ( sourceGuild != null && targetGuild != null )
{ {
if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) ) if ( list[i] == source || list[i] is BaseFactionGuard )
return Notoriety.Ally;
else if ( sourceGuild.IsEnemy( targetGuild ) )
return Notoriety.Enemy; return Notoriety.Enemy;
} }
Faction srcFaction = Faction.Find( source, true, true );
Faction trgFaction = Faction.Find( target.Owner, true, true );
if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
{
List<Mobile> secondList = target.Aggressors;
for( int i = 0; i < secondList.Count; ++i )
{
if ( secondList[i] == source || secondList[i] is BaseFactionGuard )
return Notoriety.Enemy;
}
}
if ( target.Owner != null && target.Owner is BaseCreature && ((BaseCreature)target.Owner).AlwaysAttackable )
return Notoriety.CanBeAttacked;
if ( CheckHouseFlag( source, target.Owner, target.Location, target.Map ) )
return Notoriety.CanBeAttacked;
if ( !(target.Owner is PlayerMobile) && !IsPet( target.Owner as BaseCreature ) )
return Notoriety.CanBeAttacked;
List<Mobile> list = target.Aggressors;
for( int i = 0; i < list.Count; ++i )
{
if ( list[i] == source )
return Notoriety.CanBeAttacked;
}
return Notoriety.Innocent;
} }
if ( CheckHouseFlag( source, target.Owner, target.Location, target.Map ) )
return Notoriety.CanBeAttacked;
if ( !(target.Owner is PlayerMobile) )
return Notoriety.CanBeAttacked;
for ( int i = 0; i < list.Count; ++i )
{
if ( list[i] == source )
return Notoriety.CanBeAttacked;
}
return Notoriety.Innocent;
} }
/* Must be thread-safe */ /* Must be thread-safe */
public static int MobileNotoriety( Mobile source, Mobile target ) public static int MobileNotoriety( Mobile source, Mobile target )
{ {
if ( Core.AOS && ( target.Blessed || ( target is BaseCreature && ( (BaseCreature)target ).IsInvulnerable ) || target is PlayerVendor || target is TownCrier ) ) BaseCreature bcTarg = target as BaseCreature;
if ( Core.AOS && ( target.Blessed || bcTarg?.IsInvulnerable == true || target is PlayerVendor || target is TownCrier ) )
return Notoriety.Invulnerable; return Notoriety.Invulnerable;
#region Dueling PlayerMobile pmFrom = source as PlayerMobile;
if ( source is PlayerMobile && target is PlayerMobile ) PlayerMobile pmTarg = target as PlayerMobile;
{
PlayerMobile pmFrom = (PlayerMobile)source;
PlayerMobile pmTarg = (PlayerMobile)target;
#region Dueling
if ( pmFrom != null && pmTarg != null )
{
if ( pmFrom.DuelContext != null && pmFrom.DuelContext.StartedBeginCountdown && !pmFrom.DuelContext.Finished && pmFrom.DuelContext == pmTarg.DuelContext ) if ( pmFrom.DuelContext != null && pmFrom.DuelContext.StartedBeginCountdown && !pmFrom.DuelContext.Finished && pmFrom.DuelContext == pmTarg.DuelContext )
return pmFrom.DuelContext.IsAlly( pmFrom, pmTarg ) ? Notoriety.Ally : Notoriety.Enemy; return pmFrom.DuelContext.IsAlly( pmFrom, pmTarg ) ? Notoriety.Ally : Notoriety.Enemy;
} }
@ -386,30 +338,28 @@ namespace Server.Misc
if ( target.AccessLevel > AccessLevel.Player ) if ( target.AccessLevel > AccessLevel.Player )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
if ( source.Player && !target.Player && source is PlayerMobile && target is BaseCreature ) if ( source.Player && !target.Player && pmFrom != null && bcTarg != null )
{ {
BaseCreature bc = (BaseCreature)target; Mobile master = bcTarg.GetMaster();
Mobile master = bc.GetMaster();
if ( master != null && master.AccessLevel > AccessLevel.Player ) if ( master != null && master.AccessLevel > AccessLevel.Player )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
master = bc.ControlMaster; master = bcTarg.ControlMaster;
if ( Core.ML && master != null ) if ( Core.ML && master != null )
{ {
if ( ( source == master && CheckAggressor( target.Aggressors, source ) ) || ( CheckAggressor( source.Aggressors, bc ) ) ) if ( ( source == master && CheckAggressor( bcTarg.Aggressors, source ) ) || ( CheckAggressor( source.Aggressors, bcTarg ) ) )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
else
return MobileNotoriety( source, master ); return MobileNotoriety( source, master );
} }
if ( !bc.Summoned && !bc.Controlled && ((PlayerMobile)source).EnemyOfOneType == target.GetType() ) if ( !bcTarg.Summoned && !bcTarg.Controlled && pmFrom.EnemyOfOneType == bcTarg.GetType() )
return Notoriety.Enemy; return Notoriety.Enemy;
} }
if ( target.Kills >= 5 || ( target.Body.IsMonster && IsSummoned( target as BaseCreature ) && !( target is BaseFamiliar ) && !( target is ArcaneFey ) && !( target is Golem ) ) || ( target is BaseCreature && ( ( (BaseCreature)target ).AlwaysMurderer || ( (BaseCreature)target ).IsAnimatedDead ) ) ) if ( target.Kills >= 5 || target.Body.IsMonster && IsSummoned( bcTarg ) && !( target is BaseFamiliar ) && !( target is ArcaneFey ) && !( target is Golem ) || bcTarg?.AlwaysMurderer == true || bcTarg?.IsAnimatedDead == true )
return Notoriety.Murderer; return Notoriety.Murderer;
if ( target.Criminal ) if ( target.Criminal )
@ -422,7 +372,7 @@ namespace Server.Misc
{ {
if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) ) if ( sourceGuild == targetGuild || sourceGuild.IsAlly( targetGuild ) )
return Notoriety.Ally; return Notoriety.Ally;
else if ( sourceGuild.IsEnemy( targetGuild ) ) if ( sourceGuild.IsEnemy( targetGuild ) )
return Notoriety.Enemy; return Notoriety.Enemy;
} }
@ -432,18 +382,18 @@ namespace Server.Misc
if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet ) if ( srcFaction != null && trgFaction != null && srcFaction != trgFaction && source.Map == Faction.Facet )
return Notoriety.Enemy; return Notoriety.Enemy;
if ( SkillHandlers.Stealing.ClassicMode && target is PlayerMobile && ((PlayerMobile)target).PermaFlags.Contains( source ) ) if ( SkillHandlers.Stealing.ClassicMode && pmTarg?.PermaFlags.Contains( source ) == true )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
if ( target is BaseCreature && ((BaseCreature)target).AlwaysAttackable ) if ( bcTarg?.AlwaysAttackable == true )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
if ( CheckHouseFlag( source, target, target.Location, target.Map ) ) if ( CheckHouseFlag( source, target, target.Location, target.Map ) )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
if ( !(target is BaseCreature && ((BaseCreature)target).InitialInnocent) ) //If Target is NOT A baseCreature, OR it's a BC and the BC is initial innocent... if ( bcTarg?.InitialInnocent != true )
{ {
if ( !target.Body.IsHuman && !target.Body.IsGhost && !IsPet( target as BaseCreature ) && !(target is PlayerMobile) || !Core.ML && !target.CanBeginAction( typeof( Server.Spells.Seventh.PolymorphSpell ) ) ) if ( !target.Body.IsHuman && !target.Body.IsGhost && !IsPet( bcTarg ) && pmTarg == null || !Core.ML && !target.CanBeginAction( typeof( Server.Spells.Seventh.PolymorphSpell ) ) )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
} }
@ -453,22 +403,15 @@ namespace Server.Misc
if ( CheckAggressed( source.Aggressed, target ) ) if ( CheckAggressed( source.Aggressed, target ) )
return Notoriety.CanBeAttacked; return Notoriety.CanBeAttacked;
if ( target is BaseCreature ) if ( bcTarg != null && bcTarg.Controlled && bcTarg.ControlOrder == OrderType.Guard && bcTarg.ControlTarget == source )
{ return Notoriety.CanBeAttacked;
BaseCreature bc = (BaseCreature)target;
if ( bc.Controlled && bc.ControlOrder == OrderType.Guard && bc.ControlTarget == source ) if ( source is BaseCreature bc )
return Notoriety.CanBeAttacked;
}
if ( source is BaseCreature )
{ {
BaseCreature bc = (BaseCreature)source;
Mobile master = bc.GetMaster(); Mobile master = bc.GetMaster();
if ( master != null ) if ( master != null && CheckAggressor( master.Aggressors, target ) || MobileNotoriety( master, target ) == Notoriety.CanBeAttacked || bcTarg != null )
if ( CheckAggressor( master.Aggressors, target ) || MobileNotoriety( master, target ) == Notoriety.CanBeAttacked || target is BaseCreature ) return Notoriety.CanBeAttacked;
return Notoriety.CanBeAttacked;
} }
return Notoriety.Innocent; return Notoriety.Innocent;
@ -484,9 +427,7 @@ namespace Server.Misc
if ( m != null && house.IsFriend( m ) ) if ( m != null && house.IsFriend( m ) )
return false; return false;
BaseCreature c = m as BaseCreature; if ( m is BaseCreature c && !c.Deleted && c.Controlled && c.ControlMaster != null )
if ( c != null && !c.Deleted && c.Controlled && c.ControlMaster != null )
return !house.IsFriend( c.ControlMaster ); return !house.IsFriend( c.ControlMaster );
return true; return true;

View file

@ -36,7 +36,7 @@ namespace Server
{ {
Poison newPoison = ( oldPoison == null ? null : GetPoison( oldPoison.Level + 1 ) ); Poison newPoison = ( oldPoison == null ? null : GetPoison( oldPoison.Level + 1 ) );
return ( newPoison == null ? oldPoison : newPoison ); return newPoison ?? oldPoison;
} }
// Info // Info
@ -131,12 +131,10 @@ namespace Server
m_LastDamage = damage; m_LastDamage = damage;
} }
if ( m_From != null ) m_From?.DoHarmful( m_Mobile, true );
m_From.DoHarmful( m_Mobile, true );
IHonorTarget honorTarget = m_Mobile as IHonorTarget; if ( m_Mobile is IHonorTarget honorTarget )
if ( honorTarget != null && honorTarget.ReceivedHonorContext != null ) honorTarget.ReceivedHonorContext?.OnTargetPoisoned();
honorTarget.ReceivedHonorContext.OnTargetPoisoned();
AOS.Damage( m_Mobile, m_From, damage, 0, 0, 0, 100, 0 ); AOS.Damage( m_Mobile, m_From, damage, 0, 0, 0, 100, 0 );

View file

@ -59,9 +59,7 @@ namespace Server.Misc
private static string GetAccountDuration( Mobile m ) private static string GetAccountDuration( Mobile m )
{ {
Account a = m.Account as Account; if ( !(m.Account is Account a) )
if ( a == null )
return ""; return "";
TimeSpan ts = DateTime.UtcNow - a.Created; TimeSpan ts = DateTime.UtcNow - a.Created;

View file

@ -54,10 +54,12 @@ namespace Server.Misc
{ {
int points = AosAttributes.GetValue( from, AosAttribute.RegenHits ); int points = AosAttributes.GetValue( from, AosAttribute.RegenHits );
if ( from is BaseCreature && !((BaseCreature)from).IsAnimatedDead ) BaseCreature bc = from as BaseCreature;
if ( bc != null && !bc.IsAnimatedDead )
points += 4; points += 4;
if ( (from is BaseCreature && ((BaseCreature)from).IsParagon) || from is Leviathan ) if ( bc?.IsParagon == true || from is Leviathan )
points += 40; points += 40;
if ( Core.ML && from.Race == Race.Human ) //Is this affected by the cap? if ( Core.ML && from.Race == Race.Human ) //Is this affected by the cap?
@ -87,7 +89,7 @@ namespace Server.Misc
int points =(int)(from.Skills[SkillName.Focus].Value * 0.1); int points =(int)(from.Skills[SkillName.Focus].Value * 0.1);
if ( (from is BaseCreature && ((BaseCreature)from).IsParagon) || from is Leviathan ) if ( (@from is BaseCreature creature && creature.IsParagon) || from is Leviathan )
points += 40; points += 40;
int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenStam ); int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenStam );
@ -135,7 +137,7 @@ namespace Server.Misc
double totalPoints = focusPoints + medPoints + (from.Meditating ? (medPoints > 13.0 ? 13.0 : medPoints) : 0.0); double totalPoints = focusPoints + medPoints + (from.Meditating ? (medPoints > 13.0 ? 13.0 : medPoints) : 0.0);
if ( (from is BaseCreature && ((BaseCreature)from).IsParagon) || from is Leviathan ) if ( (@from is BaseCreature creature && creature.IsParagon) || from is Leviathan )
totalPoints += 40; totalPoints += 40;
int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenMana ); int cappedPoints = AosAttributes.GetValue( from, AosAttribute.RegenMana );

View file

@ -135,7 +135,7 @@ namespace Server.Misc
if ( gc < 0.01 ) if ( gc < 0.01 )
gc = 0.01; gc = 0.01;
if ( from is BaseCreature && ((BaseCreature)from).Controlled ) if ( @from is BaseCreature creature && creature.Controlled )
gc *= 2; gc *= 2;
if ( from.Alive && ( ( gc >= Utility.RandomDouble() && AllowGain( from, skill, amObj ) ) || skill.Base < 10.0 ) ) if ( from.Alive && ( ( gc >= Utility.RandomDouble() && AllowGain( from, skill, amObj ) ) || skill.Base < 10.0 ) )
@ -155,7 +155,7 @@ namespace Server.Misc
if ( value < minSkill ) if ( value < minSkill )
return false; // Too difficult return false; // Too difficult
else if ( value >= maxSkill ) if ( value >= maxSkill )
return true; // No challenge return true; // No challenge
double chance = (value - minSkill) / (maxSkill - minSkill); double chance = (value - minSkill) / (maxSkill - minSkill);
@ -172,7 +172,7 @@ namespace Server.Misc
if ( chance < 0.0 ) if ( chance < 0.0 )
return false; // Too difficult return false; // Too difficult
else if ( chance >= 1.0 ) if ( chance >= 1.0 )
return true; // No challenge return true; // No challenge
return CheckSkill( from, skill, target, chance ); return CheckSkill( from, skill, target, chance );
@ -183,10 +183,10 @@ namespace Server.Misc
if ( Core.AOS && Faction.InSkillLoss( from ) ) //Changed some time between the introduction of AoS and SE. if ( Core.AOS && Faction.InSkillLoss( from ) ) //Changed some time between the introduction of AoS and SE.
return false; return false;
if ( AntiMacroCode && from is PlayerMobile && UseAntiMacro[skill.Info.SkillID] ) if ( AntiMacroCode && @from is PlayerMobile mobile && UseAntiMacro[skill.Info.SkillID] )
return ((PlayerMobile)from).AntiMacroCheck( skill, obj ); return mobile.AntiMacroCheck( skill, obj );
else
return true; return true;
} }
public enum Stat { Str, Dex, Int } public enum Stat { Str, Dex, Int }
@ -196,7 +196,7 @@ namespace Server.Misc
if ( from.Region.IsPartOf( typeof( Regions.Jail ) ) ) if ( from.Region.IsPartOf( typeof( Regions.Jail ) ) )
return; return;
if ( from is BaseCreature && ((BaseCreature)from).IsDeadPet ) if ( @from is BaseCreature creature && creature.IsDeadPet )
return; return;
if ( skill.SkillName == SkillName.Focus && from is BaseCreature ) if ( skill.SkillName == SkillName.Focus && from is BaseCreature )
@ -226,9 +226,8 @@ namespace Server.Misc
} }
#region Scroll of Alacrity #region Scroll of Alacrity
PlayerMobile pm = from as PlayerMobile;
if ( pm != null && skill.SkillName == pm.AcceleratedSkill && pm.AcceleratedStart > DateTime.UtcNow ) if ( @from is PlayerMobile pm && skill.SkillName == pm.AcceleratedSkill && pm.AcceleratedStart > DateTime.UtcNow )
toGain *= Utility.RandomMinMax(2, 5); toGain *= Utility.RandomMinMax(2, 5);
#endregion #endregion
@ -265,7 +264,7 @@ namespace Server.Misc
public static bool CanRaise( Mobile from, Stat stat ) public static bool CanRaise( Mobile from, Stat stat )
{ {
if ( !(from is BaseCreature && ((BaseCreature)from).Controlled) ) if ( !(@from is BaseCreature creature && creature.Controlled) )
{ {
if ( from.RawStatTotal >= from.StatCap ) if ( from.RawStatTotal >= from.StatCap )
return false; return false;
@ -344,8 +343,8 @@ namespace Server.Misc
{ {
case Stat.Str: case Stat.Str:
{ {
if ( from is BaseCreature && ((BaseCreature)from).Controlled ) { if ( @from is BaseCreature creature && creature.Controlled ) {
if ( (from.LastStrGain + m_PetStatGainDelay) >= DateTime.UtcNow ) if ( (creature.LastStrGain + m_PetStatGainDelay) >= DateTime.UtcNow )
return; return;
} }
else if ( (from.LastStrGain + m_StatGainDelay) >= DateTime.UtcNow ) else if ( (from.LastStrGain + m_StatGainDelay) >= DateTime.UtcNow )
@ -356,8 +355,8 @@ namespace Server.Misc
} }
case Stat.Dex: case Stat.Dex:
{ {
if ( from is BaseCreature && ((BaseCreature)from).Controlled ) { if ( @from is BaseCreature creature && creature.Controlled ) {
if ( (from.LastDexGain + m_PetStatGainDelay) >= DateTime.UtcNow ) if ( (creature.LastDexGain + m_PetStatGainDelay) >= DateTime.UtcNow )
return; return;
} }
else if ( (from.LastDexGain + m_StatGainDelay) >= DateTime.UtcNow ) else if ( (from.LastDexGain + m_StatGainDelay) >= DateTime.UtcNow )
@ -368,8 +367,8 @@ namespace Server.Misc
} }
case Stat.Int: case Stat.Int:
{ {
if ( from is BaseCreature && ((BaseCreature)from).Controlled ) { if ( @from is BaseCreature creature && creature.Controlled ) {
if ( (from.LastIntGain + m_PetStatGainDelay) >= DateTime.UtcNow ) if ( (creature.LastIntGain + m_PetStatGainDelay) >= DateTime.UtcNow )
return; return;
} }

View file

@ -67,9 +67,11 @@ namespace Server.Misc
public static void AwardKarma( Mobile m, int offset, bool message ) public static void AwardKarma( Mobile m, int offset, bool message )
{ {
PlayerMobile pm = m as PlayerMobile;
if ( offset > 0 ) if ( offset > 0 )
{ {
if ( m is PlayerMobile && ((PlayerMobile)m).KarmaLocked ) if ( pm?.KarmaLocked == true )
return; return;
if ( m.Karma >= MaxKarma ) if ( m.Karma >= MaxKarma )
@ -120,9 +122,9 @@ namespace Server.Misc
m.SendLocalizedMessage( 1019063 ); // You have lost a little karma. m.SendLocalizedMessage( 1019063 ); // You have lost a little karma.
} }
if ( !Core.AOS && wasPositiveKarma && m.Karma < 0 && m is PlayerMobile && !((PlayerMobile)m).KarmaLocked ) if ( !Core.AOS && wasPositiveKarma && m.Karma < 0 && pm != null && !pm.KarmaLocked )
{ {
((PlayerMobile)m).KarmaLocked = true; pm.KarmaLocked = true;
m.SendLocalizedMessage( 1042511, "", 0x22 ); // Karma is locked. A mantra spoken at a shrine will unlock it again. m.SendLocalizedMessage( 1042511, "", 0x22 ); // Karma is locked. A mantra spoken at a shrine will unlock it again.
} }
} }
@ -172,9 +174,9 @@ namespace Server.Misc
title.Append( beheld.Name ); title.Append( beheld.Name );
} }
if ( beheld is PlayerMobile && ((PlayerMobile)beheld).DisplayChampionTitle ) if ( beheld is PlayerMobile mobile && mobile.DisplayChampionTitle )
{ {
PlayerMobile.ChampionTitleInfo info = ((PlayerMobile)beheld).ChampionTitles; PlayerMobile.ChampionTitleInfo info = mobile.ChampionTitles;
if ( info.Harrower > 0 ) if ( info.Harrower > 0 )
title.AppendFormat( ": {0} of Evil", HarrowerTitles[Math.Min( HarrowerTitles.Length, info.Harrower )-1] ); title.AppendFormat( ": {0} of Evil", HarrowerTitles[Math.Min( HarrowerTitles.Length, info.Harrower )-1] );

View file

@ -21,9 +21,9 @@ namespace Server.Items
public override void Execute( CommandEventArgs e, object obj ) public override void Execute( CommandEventArgs e, object obj )
{ {
if ( obj is ToggleItem ) if ( obj is ToggleItem item )
{ {
((ToggleItem)obj).Toggle(); item.Toggle();
AddResponse( "The item has been toggled." ); AddResponse( "The item has been toggled." );
} }
else else
@ -64,13 +64,7 @@ namespace Server.Items
} }
[Constructible] [Constructible]
public ToggleItem( int inactiveItemID, int activeItemID ) public ToggleItem( int inactiveItemID, int activeItemID, bool playersCanToggle = false)
: this( inactiveItemID, activeItemID, false )
{
}
[Constructible]
public ToggleItem( int inactiveItemID, int activeItemID, bool playersCanToggle )
: base( inactiveItemID ) : base( inactiveItemID )
{ {
Movable = false; Movable = false;

View file

@ -96,13 +96,12 @@ namespace Server.Misc
return; return;
} }
if ( from is PlayerMobile ) if ( @from is PlayerMobile pm )
{ {
int amt = ( from.Mounted ? 48 : 16 ); int amt = ( pm.Mounted ? 48 : 16 );
PlayerMobile pm = (PlayerMobile)from;
if ( (++pm.StepsTaken % amt) == 0 ) if ( (++pm.StepsTaken % amt) == 0 )
--from.Stam; --pm.Stam;
} }
Spells.Ninjitsu.DeathStrike.AddStep( from ); Spells.Ninjitsu.DeathStrike.AddStep( from );

View file

@ -33,8 +33,8 @@ namespace Server.Targets
protected override void OnTarget( Mobile from, object o ) protected override void OnTarget( Mobile from, object o )
{ {
if ( o is Mobile ) { if ( o is Mobile m )
Mobile m = (Mobile)o; {
for ( int i = 0; i < m_List.Count; ++i ) for ( int i = 0; i < m_List.Count; ++i )
m_List[i].EndPickTarget( from, m, m_Order ); m_List[i].EndPickTarget( from, m, m_Order );
} }

View file

@ -225,10 +225,8 @@ namespace Server.Mobiles
from.Target = new AIControlMobileTarget(this, order); from.Target = new AIControlMobileTarget(this, order);
} }
else if (from.Target is AIControlMobileTarget) else if (@from.Target is AIControlMobileTarget t)
{ {
AIControlMobileTarget t = (AIControlMobileTarget)from.Target;
if (t.Order == order) if (t.Order == order)
t.AddAI(this); t.AddAI(this);
} }
@ -384,10 +382,7 @@ namespace Server.Mobiles
} }
else else
{ {
int generalNumber; Clock.GetTime(m_Mobile, out int generalNumber, out _);
string exactTime;
Clock.GetTime(m_Mobile, out generalNumber, out exactTime);
m_Mobile.PublicOverheadMessage(MessageType.Regular, 0x3B2, generalNumber); m_Mobile.PublicOverheadMessage(MessageType.Regular, 0x3B2, generalNumber);
} }
@ -1232,9 +1227,7 @@ namespace Server.Mobiles
{ {
if (distance < 1 && target.X == 1076 && target.Y == 450 && (m_Mobile is HordeMinionFamiliar)) if (distance < 1 && target.X == 1076 && target.Y == 450 && (m_Mobile is HordeMinionFamiliar))
{ {
PlayerMobile pm = m_Mobile.ControlMaster as PlayerMobile; if (m_Mobile.ControlMaster is PlayerMobile pm)
if (pm != null)
{ {
QuestSystem qs = pm.Quest; QuestSystem qs = pm.Quest;
@ -1328,8 +1321,8 @@ namespace Server.Mobiles
} }
else else
{ {
bool youngFrom = from is PlayerMobile ? ((PlayerMobile)from).Young : false; bool youngFrom = @from is PlayerMobile mobile && mobile.Young;
bool youngTo = to is PlayerMobile ? ((PlayerMobile)to).Young : false; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young;
if (youngFrom && !youngTo) if (youngFrom && !youngTo)
{ {
@ -1560,8 +1553,7 @@ namespace Server.Mobiles
m_Mobile.OwnerAbandonTime = DateTime.MinValue; m_Mobile.OwnerAbandonTime = DateTime.MinValue;
m_Mobile.IsBonded = false; m_Mobile.IsBonded = false;
SpawnEntry se = m_Mobile.Spawner as SpawnEntry; if (m_Mobile.Spawner is SpawnEntry se && se.HomeLocation != Point3D.Zero)
if (se != null && se.HomeLocation != Point3D.Zero)
{ {
m_Mobile.Home = se.HomeLocation; m_Mobile.Home = se.HomeLocation;
m_Mobile.RangeHome = se.HomeRange; m_Mobile.RangeHome = se.HomeRange;
@ -1683,8 +1675,8 @@ namespace Server.Mobiles
if (from.Map != m_Creature.Map || !from.InRange(m_Creature, 14)) if (from.Map != m_Creature.Map || !from.InRange(m_Creature, 14))
return false; return false;
bool youngFrom = from is PlayerMobile ? ((PlayerMobile)from).Young : false; bool youngFrom = @from is PlayerMobile mobile && mobile.Young;
bool youngTo = to is PlayerMobile ? ((PlayerMobile)to).Young : false; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young;
if (accepted && youngFrom && !youngTo) if (accepted && youngFrom && !youngTo)
{ {
@ -1777,8 +1769,8 @@ namespace Server.Mobiles
{ {
m_Mobile.DebugSay("Begin transfer with {0}", to.Name); m_Mobile.DebugSay("Begin transfer with {0}", to.Name);
bool youngFrom = from is PlayerMobile ? ((PlayerMobile)from).Young : false; bool youngFrom = @from is PlayerMobile mobile && mobile.Young;
bool youngTo = to is PlayerMobile ? ((PlayerMobile)to).Young : false; bool youngTo = to is PlayerMobile playerMobile && playerMobile.Young;
if (youngFrom && !youngTo) if (youngFrom && !youngTo)
{ {
@ -2032,7 +2024,7 @@ namespace Server.Mobiles
{ {
if (m_Mobile.Deleted || m_Mobile.Frozen || m_Mobile.Paralyzed || (m_Mobile.Spell != null && m_Mobile.Spell.IsCasting) || m_Mobile.DisallowAllMoves) if (m_Mobile.Deleted || m_Mobile.Frozen || m_Mobile.Paralyzed || (m_Mobile.Spell != null && m_Mobile.Spell.IsCasting) || m_Mobile.DisallowAllMoves)
return MoveResult.BadState; return MoveResult.BadState;
else if (!CheckMove()) if (!CheckMove())
return MoveResult.BadState; return MoveResult.BadState;
// This makes them always move one step, never any direction changes // This makes them always move one step, never any direction changes
@ -2056,7 +2048,7 @@ namespace Server.Mobiles
MoveImpl.IgnoreMovableImpassables = false; MoveImpl.IgnoreMovableImpassables = false;
return (v ? MoveResult.Success : MoveResult.Blocked); return (v ? MoveResult.Success : MoveResult.Blocked);
} }
else if (!m_Mobile.Move(d)) if (!m_Mobile.Move(d))
{ {
bool wasPushing = m_Mobile.Pushing; bool wasPushing = m_Mobile.Pushing;
@ -2082,13 +2074,11 @@ namespace Server.Mobiles
foreach (Item item in eable) foreach (Item item in eable)
{ {
if (canOpenDoors && item is BaseDoor && (item.Z + item.ItemData.Height) > m_Mobile.Z && (m_Mobile.Z + 16) > item.Z) if (canOpenDoors && item is BaseDoor door && (door.Z + door.ItemData.Height) > m_Mobile.Z && (m_Mobile.Z + 16) > door.Z)
{ {
if (item.X != x || item.Y != y) if (door.X != x || door.Y != y)
continue; continue;
BaseDoor door = (BaseDoor)item;
if (!door.Locked || !door.UseLocks()) if (!door.Locked || !door.UseLocks())
m_Obstacles.Enqueue(door); m_Obstacles.Enqueue(door);
@ -2117,26 +2107,24 @@ namespace Server.Mobiles
{ {
Item item = m_Obstacles.Dequeue(); Item item = m_Obstacles.Dequeue();
if (item is BaseDoor) if (item is BaseDoor door)
{ {
m_Mobile.DebugSay("Little do they expect, I've learned how to open doors. Didn't they read the script??"); m_Mobile.DebugSay("Little do they expect, I've learned how to open doors. Didn't they read the script??");
m_Mobile.DebugSay("*twist*"); m_Mobile.DebugSay("*twist*");
((BaseDoor)item).Use(m_Mobile); door.Use(m_Mobile);
} }
else else
{ {
m_Mobile.DebugSay("Ugabooga. I'm so big and tough I can destroy it: {0}", item.GetType().Name); m_Mobile.DebugSay("Ugabooga. I'm so big and tough I can destroy it: {0}", item.GetType().Name);
if (item is Container) if (item is Container cont)
{ {
Container cont = (Container)item;
for (int i = 0; i < cont.Items.Count; ++i) for (int i = 0; i < cont.Items.Count; ++i)
{ {
Item check = cont.Items[i]; Item check = cont.Items[i];
if (check.Movable && check.ItemData.Impassable && (item.Z + check.ItemData.Height) > m_Mobile.Z) if (check.Movable && check.ItemData.Impassable && (cont.Z + check.ItemData.Height) > m_Mobile.Z)
m_Obstacles.Enqueue(check); m_Obstacles.Enqueue(check);
} }
@ -2172,11 +2160,9 @@ namespace Server.Mobiles
MoveImpl.IgnoreMovableImpassables = false; MoveImpl.IgnoreMovableImpassables = false;
return (wasPushing ? MoveResult.BadState : MoveResult.Blocked); return (wasPushing ? MoveResult.BadState : MoveResult.Blocked);
} }
else
{ MoveImpl.IgnoreMovableImpassables = false;
MoveImpl.IgnoreMovableImpassables = false; return MoveResult.Success;
return MoveResult.Success;
}
} }
MoveImpl.IgnoreMovableImpassables = false; MoveImpl.IgnoreMovableImpassables = false;
@ -2190,9 +2176,9 @@ namespace Server.Mobiles
if (m_Mobile.Home == Point3D.Zero) if (m_Mobile.Home == Point3D.Zero)
{ {
if (m_Mobile.Spawner is SpawnEntry) if (m_Mobile.Spawner is SpawnEntry entry)
{ {
Region region = ((SpawnEntry)m_Mobile.Spawner).Region; Region region = entry.Region;
if (m_Mobile.Region.AcceptsSpawnsFrom(region)) if (m_Mobile.Region.AcceptsSpawnsFrom(region))
{ {
@ -2346,65 +2332,63 @@ namespace Server.Mobiles
if (m_Mobile.Deleted || m_Mobile.DisallowAllMoves) if (m_Mobile.Deleted || m_Mobile.DisallowAllMoves)
return false; return false;
if (m != null) if (m == null)
return false;
for (int i = 0; i < iSteps; i++)
{ {
for (int i = 0; i < iSteps; i++) // Get the current distance
int iCurrDist = (int)m_Mobile.GetDistanceToSqrt(m);
if (iCurrDist < iWantDistMin || iCurrDist > iWantDistMax)
{ {
// Get the current distance bool needCloser = (iCurrDist > iWantDistMax);
int iCurrDist = (int)m_Mobile.GetDistanceToSqrt(m); bool needFurther = !needCloser;
if (iCurrDist < iWantDistMin || iCurrDist > iWantDistMax) if (needCloser && m_Path != null && m_Path.Goal == m)
{ {
bool needCloser = (iCurrDist > iWantDistMax); if (m_Path.Follow(bRun, 1))
bool needFurther = !needCloser; m_Path = null;
}
else
{
Direction dirTo;
if (needCloser && m_Path != null && m_Path.Goal == m) if (iCurrDist > iWantDistMax)
dirTo = m_Mobile.GetDirectionTo(m);
else
dirTo = m.GetDirectionTo(m_Mobile);
// Add the run flag
if (bRun)
dirTo = dirTo | Direction.Running;
if (!DoMove(dirTo, true) && needCloser)
{ {
m_Path = new PathFollower(m_Mobile, m);
m_Path.Mover = new MoveMethod(DoMoveImpl);
if (m_Path.Follow(bRun, 1)) if (m_Path.Follow(bRun, 1))
m_Path = null; m_Path = null;
} }
else else
{ {
Direction dirTo; m_Path = null;
if (iCurrDist > iWantDistMax)
dirTo = m_Mobile.GetDirectionTo(m);
else
dirTo = m.GetDirectionTo(m_Mobile);
// Add the run flag
if (bRun)
dirTo = dirTo | Direction.Running;
if (!DoMove(dirTo, true) && needCloser)
{
m_Path = new PathFollower(m_Mobile, m);
m_Path.Mover = new MoveMethod(DoMoveImpl);
if (m_Path.Follow(bRun, 1))
m_Path = null;
}
else
{
m_Path = null;
}
} }
} }
else
{
return true;
}
} }
// Get the current distance
int iNewDist = (int)m_Mobile.GetDistanceToSqrt(m);
if (iNewDist >= iWantDistMin && iNewDist <= iWantDistMax)
return true;
else else
return false; {
return true;
}
} }
// Get the current distance
int iNewDist = (int)m_Mobile.GetDistanceToSqrt(m);
if (iNewDist >= iWantDistMin && iNewDist <= iWantDistMax)
return true;
return false; return false;
} }
@ -2430,11 +2414,9 @@ namespace Server.Mobiles
m_Mobile.FocusMob = null; m_Mobile.FocusMob = null;
return false; return false;
} }
else
{ m_Mobile.FocusMob = m_Mobile.BardTarget;
m_Mobile.FocusMob = m_Mobile.BardTarget; return (m_Mobile.FocusMob != null);
return (m_Mobile.FocusMob != null);
}
} }
else if (m_Mobile.Controlled) else if (m_Mobile.Controlled)
{ {
@ -2446,11 +2428,9 @@ namespace Server.Mobiles
m_Mobile.FocusMob = null; m_Mobile.FocusMob = null;
return false; return false;
} }
else
{ m_Mobile.FocusMob = m_Mobile.ControlTarget;
m_Mobile.FocusMob = m_Mobile.ControlTarget; return (m_Mobile.FocusMob != null);
return (m_Mobile.FocusMob != null);
}
} }
if (m_Mobile.ConstantFocus != null) if (m_Mobile.ConstantFocus != null)
@ -2488,7 +2468,6 @@ namespace Server.Mobiles
{ {
Mobile newFocusMob = null; Mobile newFocusMob = null;
double val = double.MinValue; double val = double.MinValue;
double theirVal;
IPooledEnumerable<Mobile> eable = map.GetMobilesInRange(m_Mobile.Location, iRange); IPooledEnumerable<Mobile> eable = map.GetMobilesInRange(m_Mobile.Location, iRange);
@ -2517,7 +2496,10 @@ namespace Server.Mobiles
if (!m_Mobile.CanSee(m)) if (!m_Mobile.CanSee(m))
continue; continue;
if (Core.AOS && m is BaseCreature && (m as BaseCreature).Summoned && !(m as BaseCreature).Controlled) BaseCreature bc = m as BaseCreature;
PlayerMobile pm = m as PlayerMobile;
if (Core.AOS && bc?.Summoned == true && bc?.Controlled != true)
continue; continue;
if (m_Mobile.Summoned && m_Mobile.SummonMaster != null) if (m_Mobile.Summoned && m_Mobile.SummonMaster != null)
@ -2531,7 +2513,7 @@ namespace Server.Mobiles
continue; continue;
// Animated creatures cannot attack players directly. // Animated creatures cannot attack players directly.
if (m is PlayerMobile && m_Mobile.IsAnimatedDead) if (pm != null && m_Mobile.IsAnimatedDead)
continue; continue;
} }
@ -2544,7 +2526,7 @@ namespace Server.Mobiles
continue; continue;
// Ignore players with activated honor // Ignore players with activated honor
if (m is PlayerMobile && ((PlayerMobile)m).HonorActive && !(m_Mobile.Combatant == m)) if (pm?.HonorActive == true && m_Mobile.Combatant != m)
continue; continue;
if (acqType == FightMode.Aggressor || acqType == FightMode.Evil) if (acqType == FightMode.Aggressor || acqType == FightMode.Evil)
@ -2556,8 +2538,8 @@ namespace Server.Mobiles
if (acqType == FightMode.Evil && !bValid) if (acqType == FightMode.Evil && !bValid)
{ {
if (m is BaseCreature && ((BaseCreature)m).Controlled && ((BaseCreature)m).ControlMaster != null) if (bc?.Controlled == true && bc?.ControlMaster != null)
bValid = (((BaseCreature)m).ControlMaster.Karma < 0); bValid = bc.ControlMaster.Karma < 0;
else else
bValid = (m.Karma < 0); bValid = (m.Karma < 0);
} }
@ -2576,7 +2558,7 @@ namespace Server.Mobiles
continue; continue;
} }
theirVal = m_Mobile.GetFightModeRanking(m, acqType, bPlayerOnly); var theirVal = m_Mobile.GetFightModeRanking(m, acqType, bPlayerOnly);
if (theirVal > val && m_Mobile.InLOS(m)) if (theirVal > val && m_Mobile.InLOS(m))
{ {
@ -2667,9 +2649,7 @@ namespace Server.Mobiles
{ {
m_Timer.Stop(); m_Timer.Stop();
SpawnEntry se = m_Mobile.Spawner as SpawnEntry; if (m_Mobile.Spawner is SpawnEntry se && se.ReturnOnDeactivate && !m_Mobile.Controlled)
if (se != null && se.ReturnOnDeactivate && !m_Mobile.Controlled)
{ {
if (se.HomeLocation == Point3D.Zero) if (se.HomeLocation == Point3D.Zero)
{ {
@ -2688,9 +2668,7 @@ namespace Server.Mobiles
private void ReturnToHome() private void ReturnToHome()
{ {
SpawnEntry se = m_Mobile.Spawner as SpawnEntry; if (m_Mobile.Spawner is SpawnEntry se)
if (se != null)
{ {
Point3D loc = se.RandomSpawnLocation(16, !m_Mobile.CantWalk, m_Mobile.CanSwim); Point3D loc = se.RandomSpawnLocation(16, !m_Mobile.CantWalk, m_Mobile.CanSwim);
@ -2750,12 +2728,12 @@ namespace Server.Mobiles
Stop(); Stop();
return; return;
} }
else if (m_Owner.m_Mobile.Map == null || m_Owner.m_Mobile.Map == Map.Internal) if (m_Owner.m_Mobile.Map == null || m_Owner.m_Mobile.Map == Map.Internal)
{ {
m_Owner.Deactivate(); m_Owner.Deactivate();
return; return;
} }
else if (m_Owner.m_Mobile.PlayerRangeSensitive)//have to check this in the timer.... if (m_Owner.m_Mobile.PlayerRangeSensitive)//have to check this in the timer....
{ {
Sector sect = m_Owner.m_Mobile.Map.GetSector(m_Owner.m_Mobile); Sector sect = m_Owner.m_Mobile.Map.GetSector(m_Owner.m_Mobile);
if (!sect.Active) if (!sect.Active)
@ -2772,7 +2750,7 @@ namespace Server.Mobiles
Stop(); Stop();
return; return;
} }
else if (m_Owner.m_Mobile.Map == null || m_Owner.m_Mobile.Map == Map.Internal) if (m_Owner.m_Mobile.Map == null || m_Owner.m_Mobile.Map == Map.Internal)
{ {
m_Owner.Deactivate(); m_Owner.Deactivate();
return; return;