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

@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Spells;
@ -388,7 +388,7 @@ namespace Server.Mobiles
public void RegisterDamage(Mobile from, int amount)
{
if (from == null || !from.Player)
if (from?.Player != true)
return;
m_DamageEntries[from] = amount + (m_DamageEntries.TryGetValue(from, out int value) ? value : 0);
@ -437,7 +437,7 @@ namespace Server.Mobiles
Container pack = to.Backpack;
if (pack == null || !pack.TryDropItem(to, artifact, false))
if (pack?.TryDropItem(to, artifact, false) != true)
artifact.Delete();
else
to.SendLocalizedMessage(
@ -446,8 +446,8 @@ namespace Server.Mobiles
public bool IsEligible(Mobile m, Item Artifact)
{
return m.Player && m.Alive && m.InRange(Location, 32) && m.Backpack != null &&
m.Backpack.CheckHold(m, Artifact, false);
return m.Player && m.Alive && m.InRange(Location, 32) &&
m.Backpack?.CheckHold(m, Artifact, false) == true;
}
public Item GetArtifact()
@ -526,61 +526,55 @@ namespace Server.Mobiles
if (0.25 < Utility.RandomDouble())
return;
Mobile toTeleport = null;
Mobile toTeleport = m_Owner.GetMobilesInRange(16)
.FirstOrDefault(mob => mob != m_Owner && mob.Player && m_Owner.CanBeHarmful(mob) && m_Owner.CanSee(mob));
foreach (Mobile m in m_Owner.GetMobilesInRange(16))
if (m != m_Owner && m.Player && m_Owner.CanBeHarmful(m) && m_Owner.CanSee(m))
if (toTeleport == null)
return;
int offset = Utility.Random(8) * 2;
Point3D to = m_Owner.Location;
for (int i = 0; i < m_Offsets.Length; i += 2)
{
int x = m_Owner.X + m_Offsets[(offset + i) % m_Offsets.Length];
int y = m_Owner.Y + m_Offsets[(offset + i + 1) % m_Offsets.Length];
if (map.CanSpawnMobile(x, y, m_Owner.Z))
{
toTeleport = m;
to = new Point3D(x, y, m_Owner.Z);
break;
}
if (toTeleport != null)
{
int offset = Utility.Random(8) * 2;
int z = map.GetAverageZ(x, y);
Point3D to = m_Owner.Location;
for (int i = 0; i < m_Offsets.Length; i += 2)
if (map.CanSpawnMobile(x, y, z))
{
int x = m_Owner.X + m_Offsets[(offset + i) % m_Offsets.Length];
int y = m_Owner.Y + m_Offsets[(offset + i + 1) % m_Offsets.Length];
if (map.CanSpawnMobile(x, y, m_Owner.Z))
{
to = new Point3D(x, y, m_Owner.Z);
break;
}
int z = map.GetAverageZ(x, y);
if (map.CanSpawnMobile(x, y, z))
{
to = new Point3D(x, y, z);
break;
}
to = new Point3D(x, y, z);
break;
}
Mobile m = toTeleport;
Point3D from = m.Location;
m.Location = to;
SpellHelper.Turn(m_Owner, toTeleport);
SpellHelper.Turn(toTeleport, m_Owner);
m.ProcessDelta();
Effects.SendLocationParticles(EffectItem.Create(from, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10,
2023);
Effects.SendLocationParticles(EffectItem.Create(to, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10,
5023);
m.PlaySound(0x1FE);
m_Owner.Combatant = toTeleport;
}
Mobile m = toTeleport;
Point3D from = m.Location;
m.Location = to;
SpellHelper.Turn(m_Owner, toTeleport);
SpellHelper.Turn(toTeleport, m_Owner);
m.ProcessDelta();
Effects.SendLocationParticles(EffectItem.Create(from, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10,
2023);
Effects.SendLocationParticles(EffectItem.Create(to, m.Map, EffectItem.DefaultDuration), 0x3728, 10, 10,
5023);
m.PlaySound(0x1FE);
m_Owner.Combatant = toTeleport;
}
}