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

@ -550,4 +550,4 @@ namespace Server.Factions
Campaign,
Election
}
}
}

View file

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Server.Accounting;
using Server.Commands;
using Server.Commands.Generic;
@ -239,36 +240,18 @@ namespace Server.Factions
return false;
IPooledEnumerable<IEntity> eable = mob.Map.GetObjectsInRange(mob.Location, range, items, mobs);
foreach (IEntity obj in eable)
if (type.IsInstanceOfType(obj))
{
eable.Free();
return true;
}
bool isInstance = eable.Any(type.IsInstanceOfType);
eable.Free();
return false;
return isInstance;
}
public static bool IsNearType(Mobile mob, Type[] types, int range)
{
IPooledEnumerable<IEntity> eable = mob.GetObjectsInRange(range);
foreach (IEntity obj in eable)
{
Type objType = obj.GetType();
for (int i = 0; i < types.Length; i++)
if (types[i].IsAssignableFrom(objType))
{
eable.Free();
return true;
}
}
bool found = eable.Any(obj => types.Any(t => t.IsInstanceOfType(obj)));
eable.Free();
return false;
return found;
}
public void RemovePlayerState(PlayerState pl)
@ -475,7 +458,7 @@ namespace Server.Factions
pm.SendLocalizedMessage(
1042161); // You cannot join a faction because your guild is an Order or Chaos type.
}
else if (!Guild.NewGuildSystem && guild.Enemies != null && guild.Enemies.Count > 0
else if (!Guild.NewGuildSystem && guild.Enemies?.Count > 0
) //CAN join w/wars in new system
{
pm.SendLocalizedMessage(1005056); // You cannot join a faction with active Wars
@ -1016,7 +999,7 @@ namespace Server.Factions
Player killerEPL = Player.Find(killer);
Player victimEPL = Player.Find(victim);
if (killerEPL != null && victimEPL != null && victimEPL.Power > 0 && victimState.CanGiveSilverTo(killer))
if (killerEPL != null && victimEPL?.Power > 0 && victimState.CanGiveSilverTo(killer))
{
int powerTransfer = Math.Max(1, victimEPL.Power / 5);
@ -1078,7 +1061,7 @@ namespace Server.Factions
Player killerEPL = Player.Find(killer);
Player victimEPL = Player.Find(victim);
if (killerEPL != null && victimEPL != null && victimEPL.Power > 0)
if (killerEPL != null && victimEPL?.Power > 0)
{
int powerTransfer = Math.Max(1, victimEPL.Power / 5);
@ -1385,4 +1368,4 @@ namespace Server.Factions
}
}
}
}
}

View file

@ -44,7 +44,7 @@ namespace Server.Factions
{
get
{
if (Item == null || Item.Deleted)
if (Item?.Deleted != false)
return true;
return Expiration != DateTime.MinValue && DateTime.UtcNow >= Expiration;
@ -77,7 +77,7 @@ namespace Server.Factions
if (Item is IFactionItem item)
item.FactionItemState = null;
if (Faction != null && Faction.State.FactionItems.Contains(this))
if (Faction?.State.FactionItems.Contains(this) == true)
Faction.State.FactionItems.Remove(this);
}
@ -93,13 +93,7 @@ namespace Server.Factions
{
PlayerState pl = PlayerState.Find(mob);
if (pl == null)
return 0;
if (pl.Faction.IsCommander(mob))
return 9;
return pl.Rank.MaxWearables;
return pl == null ? 0 : pl.Faction.IsCommander(mob) ? 9 : pl.Rank.MaxWearables;
}
public static FactionItem Find(Item item)
@ -140,4 +134,4 @@ namespace Server.Factions
return item;
}
}
}
}

View file

@ -8,7 +8,7 @@ namespace Server.Factions
{
Movable = false;
if (Instance == null || Instance.Deleted)
if (Instance?.Deleted == true)
Instance = this;
else
base.Delete();
@ -87,4 +87,4 @@ namespace Server.Factions
Town
}
}
}
}

View file

@ -136,7 +136,7 @@ namespace Server.Factions
{
return Definition.Sort - other.Definition.Sort;
}
public int CompareTo(object obj)
{
return Definition.Sort - ((Town)obj).Definition.Sort;
@ -386,18 +386,14 @@ namespace Server.Factions
public bool IsSheriff(Mobile mob)
{
if (mob == null || mob.Deleted)
return false;
return mob.AccessLevel >= AccessLevel.GameMaster || mob == Sheriff;
return mob?.Deleted == false &&
(mob.AccessLevel >= AccessLevel.GameMaster || mob == Sheriff);
}
public bool IsFinance(Mobile mob)
{
if (mob == null || mob.Deleted)
return false;
return mob.AccessLevel >= AccessLevel.GameMaster || mob == Finance;
return mob?.Deleted == false &&
(mob.AccessLevel >= AccessLevel.GameMaster || mob == Finance);
}
public void Capture(Faction f)
@ -511,4 +507,4 @@ namespace Server.Factions
}
}
}
}
}