Removes old comparable/comparers. (#31)

This commit is contained in:
Kamron Batman 2019-03-11 15:35:04 -07:00 committed by GitHub
parent 513e54f70e
commit a45094f2dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 95 additions and 249 deletions

View file

@ -11,7 +11,7 @@ using Server.Network;
namespace Server.Accounting
{
public class Account : IAccount, IComparable, IComparable<Account>
public class Account : IAccount, IComparable<Account>
{
public static readonly TimeSpan YoungDuration = TimeSpan.FromHours( 40.0 );
@ -1121,28 +1121,14 @@ namespace Server.Accounting
}
public int CompareTo( Account other )
{
if ( other == null )
return 1;
return Username.CompareTo( other.Username );
}
{
return other == null ? 1 : Username.CompareTo( other.Username );
}
public int CompareTo( IAccount other )
{
if ( other == null )
return 1;
return Username.CompareTo( other.Username );
}
public int CompareTo( object obj )
{
if ( obj is Account account )
return CompareTo( account );
throw new ArgumentException();
}
{
return other == null ? 1 : Username.CompareTo( other.Username );
}
#region Gold Account
/// <summary>

View file

@ -392,7 +392,8 @@ namespace Server.Commands
v = 1;
}
if (v == 0) v = GetNameFrom(aCtor, aProp, aMethod).CompareTo(GetNameFrom(bCtor, bProp, bMethod));
if (v == 0)
v = GetNameFrom(aCtor, aProp, aMethod).CompareTo(GetNameFrom(bCtor, bProp, bMethod));
if (v == 0 && aCtor != null && bCtor != null)
v = aCtor.GetParameters().Length.CompareTo(bCtor.GetParameters().Length);

View file

@ -172,7 +172,7 @@ namespace Server.Engines.ConPVP
}
[PropertyObject]
public class Arena : IComparable
public class Arena : IComparable<Arena>
{
private bool m_Active;
private Rectangle2D m_Bounds;
@ -456,10 +456,8 @@ namespace Server.Engines.ConPVP
public static List<Arena> Arenas{ get; } = new List<Arena>();
public int CompareTo(object obj)
public int CompareTo(Arena c)
{
Arena c = (Arena)obj;
string a = m_Name;
string b = c.m_Name;
@ -475,18 +473,13 @@ namespace Server.Engines.ConPVP
public Ladder AcquireLadder()
{
if (Ladder != null)
return Ladder.Ladder;
return ConPVP.Ladder.Instance;
return Ladder?.Ladder ?? ConPVP.Ladder.Instance;
}
public void Delete()
{
Active = false;
m_Region?.Unregister();
m_Region = null;
}

View file

@ -1116,7 +1116,7 @@ namespace Server.Engines.ConPVP
}
}
public sealed class BRPlayerInfo : IRankedCTF, IComparable
public sealed class BRPlayerInfo : IRankedCTF, IComparable<BRPlayerInfo>
{
private int m_Captures;
@ -1133,17 +1133,16 @@ namespace Server.Engines.ConPVP
public Mobile Player{ get; }
public int CompareTo(object obj)
public int CompareTo(BRPlayerInfo pi)
{
BRPlayerInfo pi = (BRPlayerInfo)obj;
int res = pi.Captures.CompareTo(Captures);
if (res == 0)
{
res = pi.Score.CompareTo(Score);
if (res != 0)
return res;
if (res == 0)
res = pi.Kills.CompareTo(Kills);
}
res = pi.Score.CompareTo(Score);
if (res == 0)
res = pi.Kills.CompareTo(Kills);
return res;
}

View file

@ -555,7 +555,7 @@ namespace Server.Engines.ConPVP
}
[PropertyObject]
public sealed class KHTeamInfo : IRankedCTF, IComparable
public sealed class KHTeamInfo : IRankedCTF, IComparable<KHTeamInfo>
{
public KHTeamInfo(int teamID)
{
@ -609,30 +609,21 @@ namespace Server.Engines.ConPVP
[CommandProperty(AccessLevel.GameMaster)]
public string TeamName{ get; set; }
public int CompareTo(object obj)
public int CompareTo(KHTeamInfo ti)
{
KHTeamInfo ti = (KHTeamInfo)obj;
int res = ti.Score.CompareTo(Score);
if (res == 0)
{
res = ti.Captures.CompareTo(Captures);
if (res != 0)
return res;
if (res == 0)
res = ti.Kills.CompareTo(Kills);
}
res = ti.Captures.CompareTo(Captures);
if (res == 0)
res = ti.Kills.CompareTo(Kills);
return res;
}
public string Name
{
get
{
if (TeamName == null)
return "(null) Team";
return $"{TeamName} Team";
}
}
public string Name => $"{TeamName ?? "(none)"} Team";
public int Kills{ get; set; }
@ -661,9 +652,7 @@ namespace Server.Engines.ConPVP
public override string ToString()
{
if (TeamName != null)
return $"({Name}) ...";
return "...";
return TeamName != null ? $"({Name}) ..." : "...";
}
}

View file

@ -296,7 +296,7 @@ namespace Server.Engines.ConPVP
}
}
public class LadderEntry : IComparable
public class LadderEntry : IComparable<LadderEntry>
{
private int m_Experience;
private Ladder m_Ladder;
@ -350,9 +350,9 @@ namespace Server.Engines.ConPVP
[CommandProperty(AccessLevel.GameMaster)]
public int Rank => Index;
public int CompareTo(object obj)
public int CompareTo(LadderEntry l)
{
return ((LadderEntry)obj).m_Experience - m_Experience;
return (l?.m_Experience ?? 0) - m_Experience;
}
public void Serialize(GenericWriter writer)

View file

@ -15,10 +15,10 @@ using Server.Targeting;
namespace Server.Factions
{
[CustomEnum(new[] { "Minax", "Council of Mages", "True Britannians", "Shadowlords" })]
public abstract class Faction : IComparable
public abstract class Faction : IComparable<Faction>
{
public const int StabilityFactor = 300; // 300% greater (3 times) than smallest faction
public const int StabilityActivation = 200; // Stablity code goes into effect when largest faction has > 200 people
public const int StabilityActivation = 200; // Stability code goes into effect when largest faction has > 200 people
public static readonly TimeSpan LeavePeriod = TimeSpan.FromDays(3.0);
@ -88,9 +88,9 @@ namespace Server.Factions
public static List<Faction> Factions => Reflector.Factions;
public int CompareTo(object obj)
public int CompareTo(Faction f)
{
return m_Definition.Sort - ((Faction)obj).m_Definition.Sort;
return m_Definition.Sort - (f?.m_Definition.Sort ?? 0);
}
public void Broadcast(string text)

View file

@ -4,7 +4,7 @@ using Server.Mobiles;
namespace Server.Factions
{
public class PlayerState : IComparable
public class PlayerState : IComparable<PlayerState>
{
private Town m_Finance;
@ -241,17 +241,14 @@ namespace Server.Factions
public bool IsActive{ get; set; }
public int CompareTo(object obj)
public int CompareTo(PlayerState ps)
{
return ((PlayerState)obj).m_KillPoints - m_KillPoints;
return (ps?.m_KillPoints ?? 0) - m_KillPoints;
}
public bool CanGiveSilverTo(Mobile mob)
{
if (SilverGiven == null)
return true;
for (int i = 0; i < SilverGiven.Count; ++i)
for (int i = 0; i < SilverGiven?.Count; ++i)
{
SilverGivenEntry sge = SilverGiven[i];
@ -307,4 +304,4 @@ namespace Server.Factions
return mob is PlayerMobile mobile ? mobile.FactionPlayerState : null;
}
}
}
}

View file

@ -6,7 +6,7 @@ using Server.Targeting;
namespace Server.Factions
{
[CustomEnum(new[] { "Britain", "Magincia", "Minoc", "Moonglow", "Skara Brae", "Trinsic", "Vesper", "Yew" })]
public abstract class Town : IComparable, IComparable<Town>
public abstract class Town : IComparable<Town>
{
public const int SilverCaptureBonus = 10000;
@ -134,12 +134,7 @@ namespace Server.Factions
public int CompareTo(Town other)
{
return Definition.Sort - other.Definition.Sort;
}
public int CompareTo(object obj)
{
return Definition.Sort - ((Town)obj).Definition.Sort;
return Definition.Sort - (other?.Definition.Sort ?? 0);
}
public static Town FromRegion(Region reg)

View file

@ -3,7 +3,7 @@ using Server.Accounting;
namespace Server.Engines.Reports
{
public abstract class BaseInfo : IComparable
public abstract class BaseInfo : IComparable<BaseInfo>
{
private string m_Display;
@ -51,19 +51,14 @@ namespace Server.Engines.Reports
}
}
public int CompareTo(object obj)
public int CompareTo(BaseInfo cmp)
{
BaseInfo cmp = obj as BaseInfo;
int v = cmp.GetPageCount(cmp is StaffInfo ? PageResolution.Handled : PageResolution.None,
DateTime.UtcNow - SortRange, DateTime.UtcNow)
int v = cmp?.GetPageCount(cmp is StaffInfo ? PageResolution.Handled : PageResolution.None,
DateTime.UtcNow - SortRange, DateTime.UtcNow) ?? 0
- GetPageCount(this is StaffInfo ? PageResolution.Handled : PageResolution.None,
DateTime.UtcNow - SortRange, DateTime.UtcNow);
if (v == 0)
v = string.Compare(Display, cmp.Display);
return v;
return v == 0 ? string.Compare(Display, cmp.Display) : v;
}
public int GetPageCount(PageResolution res, DateTime min, DateTime max)
@ -95,4 +90,4 @@ namespace Server.Engines.Reports
{
}
}
}
}

View file

@ -133,7 +133,7 @@ namespace Server.Engines.Reports
if (ladder == null)
return chart;
List<LadderEntry> entries = ladder.Entries;
for (int i = entries.Count - 1; i >= 0; --i)
@ -205,7 +205,7 @@ namespace Server.Engines.Reports
if (prefs == null)
return chart;
List<Arena> arenas = Arena.Arenas;
for (int i = 0; i < arenas.Count; ++i)
@ -528,7 +528,7 @@ namespace Server.Engines.Reports
return report;
}
public class SkillDistribution : IComparable
public class SkillDistribution : IComparable<SkillDistribution>
{
public int m_NumberOfGMs;
public SkillInfo m_Skill;
@ -538,10 +538,10 @@ namespace Server.Engines.Reports
m_Skill = skill;
}
public int CompareTo(object obj)
public int CompareTo(SkillDistribution sd)
{
return ((SkillDistribution)obj).m_NumberOfGMs - m_NumberOfGMs;
return sd?.m_NumberOfGMs ?? 0 - m_NumberOfGMs;
}
}
}
}
}

View file

@ -1,5 +1,5 @@
using System;
using System.Collections;
using System.Collections.Generic;
using Server.Commands;
using Server.Network;
@ -542,13 +542,10 @@ namespace Server.Gumps
})
};
private class SkillNameComparer : IComparer
private class SkillNameComparer : IComparer<SkillName>
{
public int Compare(object x, object y)
public int Compare(SkillName a, SkillName b)
{
SkillName a = (SkillName)x;
SkillName b = (SkillName)y;
string aName = SkillInfo.Table[(int)a].Name;
string bName = SkillInfo.Table[(int)b].Name;

View file

@ -118,7 +118,7 @@ namespace Server.Mobiles
#endregion
public class DamageStore : IComparable
public class DamageStore : IComparable<DamageStore>
{
public int m_Damage;
public bool m_HasRight;
@ -130,12 +130,9 @@ namespace Server.Mobiles
m_Damage = damage;
}
public int CompareTo(object obj)
public int CompareTo(DamageStore ds)
{
if (!(obj is DamageStore ds))
return -1;
return ds.m_Damage - m_Damage;
return ds?.m_Damage ?? 0 - m_Damage;
}
}
@ -157,11 +154,7 @@ namespace Server.Mobiles
object[] objs = t.GetCustomAttributes(typeof(FriendlyNameAttribute), false);
if (objs.Length > 0)
{
FriendlyNameAttribute friendly = objs[0] as FriendlyNameAttribute;
return friendly?.FriendlyName ?? "";
}
return (objs[0] as FriendlyNameAttribute)?.FriendlyName ?? "";
}
return t.Name;