Clean up: Bugs, LINQ, constructors, default values, and null checks (#18)

This commit is contained in:
Kamron Batman 2019-03-11 14:29:59 -07:00 • committed by GitHub
parent e748af4430
commit 513e54f70e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
1094 changed files with 15913 additions and 21892 deletions

View file

@ -25,37 +25,38 @@ namespace Server.Mobiles
public virtual void RangeCheck()
{
if (!Deleted && ControlMaster != null && !ControlMaster.Deleted)
if (Deleted || ControlMaster?.Deleted != false)
return;
int range = RangeHome - 2;
if (InRange(ControlMaster.Location, RangeHome))
return;
Mobile master = ControlMaster;
Point3D m_Loc = Point3D.Zero;
if (Map != master.Map)
return;
int x = X > master.X ? master.X + range : master.X - range;
int y = Y > master.Y ? master.Y + range : master.Y - range;
for (int i = 0; i < 10; i++)
{
int range = RangeHome - 2;
m_Loc.X = x + Utility.RandomMinMax(-1, 1);
m_Loc.Y = y + Utility.RandomMinMax(-1, 1);
if (!InRange(ControlMaster.Location, RangeHome))
{
Mobile master = ControlMaster;
m_Loc.Z = Map.GetAverageZ(m_Loc.X, m_Loc.Y);
Point3D m_Loc = Point3D.Zero;
if (Map.CanSpawnMobile(m_Loc)) break;
if (Map == master.Map)
{
int x = X > master.X ? master.X + range : master.X - range;
int y = Y > master.Y ? master.Y + range : master.Y - range;
for (int i = 0; i < 10; i++)
{
m_Loc.X = x + Utility.RandomMinMax(-1, 1);
m_Loc.Y = y + Utility.RandomMinMax(-1, 1);
m_Loc.Z = Map.GetAverageZ(m_Loc.X, m_Loc.Y);
if (Map.CanSpawnMobile(m_Loc)) break;
m_Loc = master.Location;
}
if (!Deleted) SetLocation(m_Loc, true);
}
}
m_Loc = master.Location;
}
if (!Deleted)
SetLocation(m_Loc, true);
}
public override void OnThink()
@ -63,7 +64,7 @@ namespace Server.Mobiles
Mobile master = ControlMaster;
if (Deleted) return;
if (master == null || master.Deleted)
if (master?.Deleted != false)
{
DropPackContents();
EndRelease(null);
@ -75,7 +76,7 @@ namespace Server.Mobiles
if (m_LastHidden != master.Hidden)
Hidden = m_LastHidden = master.Hidden;
if (AIObject != null && AIObject.WalkMobileRange(master, 5, true, 1, 1))
if (AIObject?.WalkMobileRange(master, 5, true, 1, 1) == true)
{
Warmode = master.Warmode;
Combatant = master.Combatant;
@ -107,7 +108,7 @@ namespace Server.Mobiles
public virtual void EndRelease(Mobile from)
{
if (from == null || !Deleted && Controlled && from == ControlMaster && from.CheckAlive())
if (from?.CheckAlive() != false && !Deleted && Controlled && from == ControlMaster)
{
Effects.SendLocationParticles(EffectItem.Create(Location, Map, EffectItem.DefaultDuration), 0x3728, 1, 13,
2100, 3, 5042, 0);
@ -171,4 +172,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -52,10 +52,7 @@ namespace Server.Mobiles
m_NextRestore = DateTime.UtcNow + TimeSpan.FromSeconds(2.0);
Mobile caster = ControlMaster;
if (caster == null)
caster = SummonMaster;
Mobile caster = ControlMaster ?? SummonMaster;
if (caster != null)
++caster.Stam;

View file

@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.ContextMenus;
using Server.Gumps;
using Server.Items;
@ -73,18 +73,12 @@ namespace Server.Mobiles
if (pack == null)
return;
List<Item> list = new List<Item>();
foreach (Item item in GetItemsInRange(2))
if (item.Movable && item.Stackable)
list.Add(item);
IEnumerable<Item> eable = GetItemsInRange(2).Where(item => item.Movable && item.Stackable);
int pickedUp = 0;
for (int i = 0; i < list.Count; ++i)
foreach (Item item in eable)
{
Item item = list[i];
if (!pack.CheckHold(this, item, false, true))
return;
@ -193,4 +187,4 @@ namespace Server.Mobiles
#endregion
}
}
}

View file

@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace Server.Mobiles
{
@ -62,19 +62,13 @@ namespace Server.Mobiles
private void Flare()
{
Mobile caster = ControlMaster;
if (caster == null)
caster = SummonMaster;
Mobile caster = ControlMaster ?? SummonMaster;
if (caster == null)
return;
List<Mobile> list = new List<Mobile>();
foreach (Mobile m in GetMobilesInRange(5))
if (m.Player && m.Alive && !m.IsDeadBondedPet && m.Karma <= 0 && m.AccessLevel < AccessLevel.Counselor)
list.Add(m);
List<Mobile> list = GetMobilesInRange(5).Where(m =>
m.Player && m.Alive && !m.IsDeadBondedPet && m.Karma <= 0 && m.AccessLevel < AccessLevel.Counselor).ToList();
for (int i = 0; i < list.Count; ++i)
{
@ -109,4 +103,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}