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

@ -107,12 +107,12 @@ namespace Server.Mobiles
{
Item disarm = m.FindItemOnLayer(Layer.OneHanded);
if (disarm != null && disarm.Movable)
if (disarm?.Movable == true)
m.AddToBackpack(disarm);
disarm = m.FindItemOnLayer(Layer.TwoHanded);
if (disarm != null && disarm.Movable)
if (disarm?.Movable == true)
m.AddToBackpack(disarm);
m.BodyMod = 42;
@ -166,7 +166,7 @@ namespace Server.Mobiles
public void DoSpecialAbility(Mobile target)
{
if (target == null || target.Deleted) //sanity
if (target?.Deleted != false) //sanity
return;
if (0.6 >= Utility.RandomDouble()) // 60% chance to polymorph attacker into a ratman

View file

@ -7,11 +7,8 @@ namespace Server.Mobiles
{
public abstract class BaseChampion : BaseCreature
{
public BaseChampion(AIType aiType) : this(aiType, FightMode.Closest)
{
}
public BaseChampion(AIType aiType, FightMode mode) : base(aiType, mode, 18, 1, 0.1, 0.2)
public BaseChampion(AIType aiType, FightMode mode = FightMode.Closest) :
base(aiType, mode, 18, 1, 0.1, 0.2)
{
}
@ -166,54 +163,56 @@ namespace Server.Mobiles
}
else
{
if (m.Corpse != null && !m.Corpse.Deleted)
if (m.Corpse?.Deleted == false)
m.Corpse.DropItem(ps);
else
m.AddToBackpack(ps);
}
if (m is PlayerMobile pm)
for (int j = 0; j < pm.JusticeProtectors.Count; ++j)
if (!(m is PlayerMobile pm))
return;
for (int j = 0; j < pm.JusticeProtectors.Count; ++j)
{
Mobile prot = pm.JusticeProtectors[j];
if (prot.Map != pm.Map || prot.Kills >= 5 || prot.Criminal || !JusticeVirtue.CheckMapRegion(pm, prot))
continue;
int chance = 0;
switch (VirtueHelper.GetLevel(prot, VirtueName.Justice))
{
Mobile prot = pm.JusticeProtectors[j];
case VirtueLevel.Seeker:
chance = 60;
break;
case VirtueLevel.Follower:
chance = 80;
break;
case VirtueLevel.Knight:
chance = 100;
break;
}
if (prot.Map != pm.Map || prot.Kills >= 5 || prot.Criminal || !JusticeVirtue.CheckMapRegion(pm, prot))
continue;
if (chance > Utility.Random(100))
{
PowerScroll powerScroll = new PowerScroll(ps.Skill, ps.Value);
int chance = 0;
prot.SendLocalizedMessage(1049368); // You have been rewarded for your dedication to Justice!
switch (VirtueHelper.GetLevel(prot, VirtueName.Justice))
if (!Core.SE || prot.Alive)
{
case VirtueLevel.Seeker:
chance = 60;
break;
case VirtueLevel.Follower:
chance = 80;
break;
case VirtueLevel.Knight:
chance = 100;
break;
prot.AddToBackpack(powerScroll);
}
if (chance > Utility.Random(100))
else
{
PowerScroll powerScroll = new PowerScroll(ps.Skill, ps.Value);
prot.SendLocalizedMessage(1049368); // You have been rewarded for your dedication to Justice!
if (!Core.SE || prot.Alive)
{
prot.AddToBackpack(powerScroll);
}
if (prot.Corpse?.Deleted == false)
prot.Corpse.DropItem(powerScroll);
else
{
if (prot.Corpse != null && !prot.Corpse.Deleted)
prot.Corpse.DropItem(powerScroll);
else
prot.AddToBackpack(powerScroll);
}
prot.AddToBackpack(powerScroll);
}
}
}
}
public override bool OnBeforeDeath()
@ -328,4 +327,4 @@ namespace Server.Mobiles
}
}
}
}
}

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;
}
}

View file

@ -1,6 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Mobiles
{
@ -8,12 +6,8 @@ namespace Server.Mobiles
{
private DrainTimer m_Timer;
[Constructible]
public HarrowerTentacles() : this(null)
{
}
public HarrowerTentacles(Mobile harrower) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public HarrowerTentacles(Mobile harrower = null) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Harrower = harrower;
Body = 129;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using Server.Engines.CannedEvil;
using Server.Items;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using Server.Engines.CannedEvil;
using Server.Items;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using Server.Engines.CannedEvil;
using Server.Engines.Plants;
using Server.Items;