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

@ -171,7 +171,7 @@ namespace Server.Mobiles
Container pack = to.Backpack;
if (pack == null || !pack.TryDropItem(to, artifact, false))
if (pack?.TryDropItem(to, artifact, false) != true)
to.BankBox.DropItem(artifact);
to.SendLocalizedMessage(
@ -287,4 +287,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -145,7 +145,7 @@ namespace Server.Mobiles
{
Mobile combatant = Combatant;
if (DateTime.UtcNow < m_NextAbilityTime || combatant == null || combatant.Deleted || combatant.Map != Map ||
if (DateTime.UtcNow < m_NextAbilityTime || combatant?.Deleted != false || combatant.Map != Map ||
!InRange(combatant, 3) || !CanBeHarmful(combatant) || !InLOS(combatant))
return;
@ -176,4 +176,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -65,14 +65,15 @@ namespace Server.Mobiles
public override void OnDamagedBySpell(Mobile from)
{
if (from != null && from.Alive && 0.4 > Utility.RandomDouble()) ThrowHatchet(from);
if (from?.Alive == true && 0.4 > Utility.RandomDouble())
ThrowHatchet(from);
}
public override void OnGotMeleeAttack(Mobile attacker)
{
base.OnGotMeleeAttack(attacker);
if (attacker != null && attacker.Alive && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
if (attacker?.Alive == true && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
ThrowHatchet(attacker);
}
@ -96,4 +97,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -1,7 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Spells;

View file

@ -1,5 +1,3 @@
using System.Collections;
namespace Server.Mobiles
{
public class Succubus : BaseCreature

View file

@ -94,7 +94,7 @@ namespace Server.Mobiles
break;
}
Utility.AssignRandomHair(this, true);
Utility.AssignRandomHair(this);
}
public ElfBrigand(Serial serial) : base(serial)
@ -132,4 +132,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

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

View file

@ -98,7 +98,7 @@ namespace Server.Mobiles
{
Mobile combatant = Combatant;
if (combatant == null || combatant.Deleted || combatant.Map != Map || !InRange(combatant, 12) ||
if (combatant?.Deleted != false || combatant.Map != Map || !InRange(combatant, 12) ||
!CanBeHarmful(combatant) || !InLOS(combatant))
return;
@ -154,4 +154,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -110,16 +110,16 @@ namespace Server.Mobiles
return;
IPooledEnumerable<OrcishLord> eable = GetMobilesInRange<OrcishLord>(10);
int orcs = eable.Count();
eable.Free();
if (orcs < 10)
if (eable.Count() < 10)
{
BaseCreature orc = new SpawnedOrcishLord{ Team = Team };
orc.MoveToWorld(map.GetRandomNearbyLocation(target.Location), map);
orc.Combatant = target;
}
eable.Free();
}
public override void Serialize(GenericWriter writer)

View file

@ -115,7 +115,7 @@ namespace Server.Mobiles
public override void OnDamagedBySpell(Mobile from)
{
if (from != null && from.Alive && 0.4 > Utility.RandomDouble()) SendEBolt(from);
if (from?.Alive == true && 0.4 > Utility.RandomDouble()) SendEBolt(from);
if (!FieldActive)
{
@ -144,7 +144,7 @@ namespace Server.Mobiles
attacker.SendAsciiMessage("Your weapon cannot penetrate the creature's magical barrier");
}
if (attacker != null && attacker.Alive && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
if (attacker?.Alive == true && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
SendEBolt(attacker);
}
@ -192,4 +192,4 @@ namespace Server.Mobiles
Name = null;
}
}
}
}

View file

@ -105,7 +105,7 @@ namespace Server.Mobiles
public override void OnDamagedBySpell(Mobile from)
{
if (from != null && from.Alive && 0.4 > Utility.RandomDouble()) SendEBolt(from);
if (from?.Alive == true && 0.4 > Utility.RandomDouble()) SendEBolt(from);
if (!FieldActive)
{
@ -134,7 +134,7 @@ namespace Server.Mobiles
attacker.SendAsciiMessage("Your weapon cannot penetrate the creature's magical barrier");
}
if (attacker != null && attacker.Alive && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
if (attacker?.Alive == true && attacker.Weapon is BaseRanged && 0.4 > Utility.RandomDouble())
SendEBolt(attacker);
}
@ -182,4 +182,4 @@ namespace Server.Mobiles
Name = null;
}
}
}
}

View file

@ -74,7 +74,7 @@ namespace Server.Mobiles
public override void OnDamage(int amount, Mobile from, bool willKill)
{
if (from != null && !willKill && amount > 5 && from.Player && 5 > Utility.Random(100))
if (!willKill && amount > 5 && from?.Player == true && 5 > Utility.Random(100))
{
string[] toSay =
{
@ -122,4 +122,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -217,7 +217,7 @@ namespace Server.Mobiles
public override void OnThink()
{
if (SummonMaster == null || SummonMaster.Deleted)
if (SummonMaster?.Deleted != false)
{
Delete();
}
@ -252,10 +252,7 @@ namespace Server.Mobiles
private bool Combat(Mobile mobile)
{
Mobile combatant = mobile.Combatant;
if (combatant == null || combatant.Deleted || combatant.IsDeadBondedPet || !combatant.Alive)
return false;
return true;
return combatant?.Deleted == false && !combatant.IsDeadBondedPet && combatant.Alive;
}
public override void OnSingleClick(Mobile from)
@ -282,4 +279,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -1,7 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Items;
using Server.Spells;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
@ -95,9 +94,7 @@ namespace Server.Mobiles
private void DoAreaLeech_Finish()
{
IPooledEnumerable<Mobile> eable = GetMobilesInRange(6);
List<Mobile> list = eable.Where(m => CanBeHarmful(m) && IsEnemy(m)).ToList();
eable.Free();
if (list.Count == 0)

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Items;
using Server.Network;
@ -96,7 +95,7 @@ namespace Server.Mobiles
m_NextAbilityTime = DateTime.UtcNow + TimeSpan.FromSeconds(Utility.RandomMinMax(20, 30));
if (combatant is BaseCreature bc)
if (bc.Controlled && bc.ControlMaster != null && !bc.ControlMaster.Deleted && bc.ControlMaster.Alive)
if (bc.Controlled && bc.ControlMaster?.Deleted == false && bc.ControlMaster.Alive)
if (bc.ControlMaster.Map == Map && bc.ControlMaster.InRange(this, 12) &&
!UnderEffect(bc.ControlMaster))
Combatant = combatant = bc.ControlMaster;

View file

@ -5,12 +5,8 @@ namespace Server.Mobiles
public class CuSidhe : BaseMount
{
[Constructible]
public CuSidhe() : this(null)
{
}
[Constructible]
public CuSidhe(string name) : base(name, 277, 0x3E91, AIType.AI_Animal, FightMode.Aggressor, 10, 1, 0.2, 0.4)
public CuSidhe(string name = null) :
base(name, 277, 0x3E91, AIType.AI_Animal, FightMode.Aggressor, 10, 1, 0.2, 0.4)
{
double chance = Utility.RandomDouble() * 23301;
@ -150,4 +146,4 @@ namespace Server.Mobiles
Name = null;
}
}
}
}

View file

@ -1,3 +1,5 @@
using System.Linq;
namespace Server.Mobiles
{
public class InterredGrizzle : BaseCreature
@ -134,16 +136,8 @@ namespace Server.Mobiles
for (int j = 0; j < 5; j++)
{
p = GetSpawnPosition(2);
bool found = false;
foreach (Item item in Map.GetItemsInRange(p, 0))
if (item is StainedOoze)
{
found = true;
break;
}
if (!found)
if (!Map.GetItemsInRange(p, 0).OfType<StainedOoze>().Any())
break;
}
@ -171,4 +165,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -116,11 +116,8 @@ namespace Server.Mobiles
public bool IsValidTarget(PlayerMobile m)
{
if (m != null && m.PeacedUntil < DateTime.UtcNow && !m.Hidden && m.AccessLevel == AccessLevel.Player &&
CanBeHarmful(m))
return true;
return false;
return m?.PeacedUntil < DateTime.UtcNow && !m.Hidden && m.AccessLevel == AccessLevel.Player &&
CanBeHarmful(m);
}
#endregion
@ -135,7 +132,7 @@ namespace Server.Mobiles
return;
foreach (Mobile m in GetMobilesInRange(RangePerception))
if (m != null && m.Player && !m.Female && !m.Hidden && m.AccessLevel == AccessLevel.Player &&
if (m?.Player == true && !m.Female && !m.Hidden && m.AccessLevel == AccessLevel.Player &&
CanBeHarmful(m))
{
UndressItem(m, Layer.OuterTorso);
@ -155,10 +152,10 @@ namespace Server.Mobiles
{
Item item = m.FindItemOnLayer(layer);
if (item != null && item.Movable)
if (item?.Movable == true)
m.PlaceInBackpack(item);
}
#endregion
}
}
}

View file

@ -1,6 +1,6 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Server.Engines.CannedEvil;
using Server.Items;
using Server.Network;
@ -265,16 +265,8 @@ namespace Server.Mobiles
for (int j = 0; j < 5; j++)
{
p = GetSpawnPosition(2);
bool found = false;
foreach (Item item in Map.GetItemsInRange(p, 0))
if (item is StainedOoze)
{
found = true;
break;
}
if (!found)
if (!Map.GetItemsInRange(p, 0).OfType<StainedOoze>().Any())
break;
}

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 System.Collections.Generic;
namespace Server.Mobiles

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

View file

@ -9,12 +9,8 @@ namespace Server.Mobiles
private bool m_Stunning;
[Constructible]
public Golem() : this(false, 1.0)
{
}
[Constructible]
public Golem(bool summoned, double scalar) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.4, 0.8)
public Golem(bool summoned = false, double scalar = 1.0) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.4, 0.8)
{
Body = 752;
@ -192,12 +188,9 @@ namespace Server.Mobiles
{
if (Controlled || Summoned)
{
Mobile master = ControlMaster;
Mobile master = ControlMaster ?? SummonMaster;
if (master == null)
master = SummonMaster;
if (master != null && master.Player && master.Map == Map && master.InRange(Location, 20))
if (master?.Player == true && master.Map == Map && master.InRange(Location, 20))
{
if (master.Mana >= amount)
{
@ -227,4 +220,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -205,10 +205,10 @@ namespace Server.Mobiles
foreach (Corpse item in eable)
// Ensure that the corpse was killed by us
if (item.Killer == this && item.Owner != null)
if (!item.DevourCorpse() && !item.Devoured)
PublicOverheadMessage(MessageType.Emote, 0x3B2,
1053032); // * The plague beast attempts to absorb the remains, but cannot! *
if (item.Killer == this && item.Owner != null && !item.DevourCorpse() && !item.Devoured)
PublicOverheadMessage(MessageType.Emote, 0x3B2,
1053032); // * The plague beast attempts to absorb the remains, but cannot! *
eable.Free();
}
@ -245,4 +245,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -92,7 +92,7 @@ namespace Server.Mobiles
{
Mobile m = state.Mobile;
if (m != null && m.Player && m != from)
if (m?.Player == true && m != from)
PrivateOverheadMessage(MessageType.Regular, 0x3B2, 1071919, from.Name,
m.NetState); // * ~1_VAL~ slices through the plague beast's amorphous tissue *
}
@ -305,7 +305,7 @@ namespace Server.Mobiles
protected override void OnTick()
{
if (m_Lord == null || m_Lord.Deleted)
if (m_Lord?.Deleted != false)
{
Stop();
return;
@ -350,4 +350,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -6,12 +6,8 @@ namespace Server.Mobiles
{
public class PlagueSpawn : BaseCreature
{
[Constructible]
public PlagueSpawn() : this(null)
{
}
public PlagueSpawn(Mobile owner) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public PlagueSpawn(Mobile owner = null) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Owner = owner;
ExpireTime = DateTime.UtcNow + TimeSpan.FromMinutes(1.0);
@ -132,4 +128,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -57,7 +57,7 @@ namespace Server.Mobiles
{
Mobile combatant = Combatant;
if (combatant == null || combatant.Deleted || combatant.Map != Map || !InRange(combatant, 12) ||
if (combatant?.Deleted != false || combatant.Map != Map || !InRange(combatant, 12) ||
!CanBeHarmful(combatant) || !InLOS(combatant))
return;
@ -109,4 +109,4 @@ namespace Server.Mobiles
}
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Mobiles
public class AgapiteElemental : BaseCreature
{
[Constructible]
public AgapiteElemental() : this(2)
{
}
[Constructible]
public AgapiteElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public AgapiteElemental(int oreAmount = 2) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 107;
BaseSoundID = 268;
@ -74,4 +69,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,8 @@ namespace Server.Mobiles
public class BronzeElemental : BaseCreature
{
[Constructible]
public BronzeElemental() : this(2)
{
}
[Constructible]
public BronzeElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public BronzeElemental(int oreAmount = 2) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
// TODO: Gas attack
Body = 108;
@ -76,4 +72,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Mobiles
public class CopperElemental : BaseCreature
{
[Constructible]
public CopperElemental() : this(2)
{
}
[Constructible]
public CopperElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public CopperElemental(int oreAmount = 2) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 109;
BaseSoundID = 268;
@ -79,4 +74,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,8 @@ namespace Server.Mobiles
public class DullCopperElemental : BaseCreature
{
[Constructible]
public DullCopperElemental() : this(2)
{
}
[Constructible]
public DullCopperElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public DullCopperElemental(int oreAmount = 2) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 110;
BaseSoundID = 268;
@ -74,4 +70,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,8 @@ namespace Server.Mobiles
public class GoldenElemental : BaseCreature
{
[Constructible]
public GoldenElemental() : this(2)
{
}
[Constructible]
public GoldenElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public GoldenElemental(int oreAmount = 2) :
base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 166;
BaseSoundID = 268;
@ -74,4 +70,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Mobiles
public class ShadowIronElemental : BaseCreature
{
[Constructible]
public ShadowIronElemental() : this(2)
{
}
[Constructible]
public ShadowIronElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public ShadowIronElemental(int oreAmount = 2) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 111;
BaseSoundID = 268;
@ -92,4 +87,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Mobiles
public class ValoriteElemental : BaseCreature
{
[Constructible]
public ValoriteElemental() : this(2)
{
}
[Constructible]
public ValoriteElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public ValoriteElemental(int oreAmount = 2) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
// TODO: Gas attack
Body = 112;
@ -90,4 +85,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -5,12 +5,7 @@ namespace Server.Mobiles
public class VeriteElemental : BaseCreature
{
[Constructible]
public VeriteElemental() : this(2)
{
}
[Constructible]
public VeriteElemental(int oreAmount) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
public VeriteElemental(int oreAmount = 2) : base(AIType.AI_Melee, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Body = 113;
BaseSoundID = 268;
@ -75,4 +70,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

@ -1,5 +1,3 @@
using System.Collections;
using System.Collections.Generic;
using Server.Engines.Plants;
using Server.Items;

View file

@ -6,12 +6,8 @@ namespace Server.Mobiles
public class Leviathan : BaseCreature
{
[Constructible]
public Leviathan() : this(null)
{
}
[Constructible]
public Leviathan(Mobile fisher) : base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4)
public Leviathan(Mobile fisher = null) :
base(AIType.AI_Mage, FightMode.Closest, 10, 1, 0.2, 0.4)
{
Fisher = fisher;
@ -171,4 +167,4 @@ namespace Server.Mobiles
Fisher = null;
}
}
}
}

View file

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

View file

@ -128,7 +128,7 @@ namespace Server.Mobiles
{
Mobile combatant = Combatant;
if (combatant == null || combatant.Deleted || combatant.Map != Map || !InRange(combatant, 12) ||
if (combatant?.Deleted != false || combatant.Map != Map || !InRange(combatant, 12) ||
!CanBeHarmful(combatant) || !InLOS(combatant))
return;
@ -158,4 +158,4 @@ namespace Server.Mobiles
int version = reader.ReadInt();
}
}
}
}

View file

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

View file

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

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Mobiles

View file

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

View file

@ -1,5 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace Server.Mobiles

View file

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

View file

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

View file

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