Code Cleanup & Fixes Warnings (#74)

This commit is contained in:
Kamron Batman 2020-01-18 14:56:45 -08:00 • committed by GitHub
parent e11d1f3ad9
commit 57b14ad690
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
143 changed files with 2960 additions and 3427 deletions

View file

@ -587,8 +587,7 @@ namespace Server.Gumps
}
case AdminGumpPage.Accounts:
{
if (m_List == null)
m_List = new List<object>();
m_List ??= new List<object>();
List<Account> rads = state as List<Account>;
@ -1214,7 +1213,6 @@ namespace Server.Gumps
case AccessLevel.Seer: return 0x144;
case AccessLevel.GameMaster: return 0x21;
case AccessLevel.Counselor: return 0x2;
case AccessLevel.Player:
default:
{
if (m.Kills >= 5)
@ -1525,7 +1523,7 @@ namespace Server.Gumps
{
IPAddress[] ips = a.LoginIPs;
if (ips.Length != 0 && ip == ips[0] && AccountHandler.IPTable.ContainsKey(ips[0]))
if (ips.Length != 0 && Equals(ip, ips[0]) && AccountHandler.IPTable.ContainsKey(ips[0]))
--AccountHandler.IPTable[ip];
List<IPAddress> newList = new List<IPAddress>(ips);

View file

@ -1,3 +1,4 @@
using System;
using Server.Guilds;
using Server.Network;
@ -48,12 +49,10 @@ namespace Server.Gumps
if (fealty == null || !guild.IsMember(fealty))
fealty = leader;
if (fealty == null)
fealty = beholder;
fealty ??= beholder;
string fealtyName;
if ((fealtyName = fealty.Name) == null || (fealtyName = fealtyName.Trim()).Length <= 0)
string fealtyName = fealty.Name?.Trim();
if (string.IsNullOrWhiteSpace(fealtyName))
fealtyName = "(empty)";
if (beholder == fealty)

View file

@ -185,9 +185,7 @@ namespace Server.Guilds
public override void OnResponse(NetState sender, RelayInfo info)
{
PlayerMobile pm = sender.Mobile as PlayerMobile;
if (!IsMember(pm, guild))
if (!(sender.Mobile is PlayerMobile pm && IsMember(pm, guild)))
return;
RankDefinition playerRank = pm.GuildRank;

View file

@ -153,9 +153,7 @@ namespace Server.Gumps
if (parent != null)
{
if (m_Stack == null)
m_Stack = new Stack<StackEntry>();
m_Stack ??= new Stack<StackEntry>();
m_Stack.Push(parent);
}
@ -599,7 +597,7 @@ namespace Server.Gumps
{
MethodInfo parseMethod = t.GetMethod("Parse", new[] { typeof(string) });
return parseMethod.Invoke(null, new object[] { s });
return parseMethod?.Invoke(null, new object[] { s });
}
throw new Exception("bad");

View file

@ -127,7 +127,6 @@ namespace Server.Gumps
switch (index)
{
default:
case 0:
type = ModelBodyType.Monsters;
list = m_Monster;
break;
@ -284,12 +283,12 @@ namespace Server.Gumps
public int CompareTo(InternalEntry comp)
{
int v = Name.CompareTo(comp.Name);
if (Name == null && comp.Name == null)
return 0;
if (v == 0)
Body.CompareTo(comp.Body);
int v = Name?.CompareTo(comp.Name) ?? 1;
return v;
return v == 0 ? Body.CompareTo(comp.Body) : v;
}
}
}

View file

@ -71,14 +71,12 @@ namespace Server.Gumps
bool isBody = prop.IsDefined(typeof(BodyAttribute), false);
object val = prop.GetValue(m_Object, null);
string initialText;
if (val == null)
initialText = "";
else if (val is TextDefinition definition)
initialText = definition.GetValue();
else
initialText = val.ToString();
string initialText = val switch
{
null => "",
TextDefinition definition => definition.GetValue(),
_ => val.ToString()
};
AddPage(0);

View file

@ -257,7 +257,7 @@ namespace Server.Gumps
x -= OldStyle ? OffsetSize : 0;
AddImageTiled(x, y, emptyWidth + (OldStyle ? OffsetSize * 2 : 0), EntryHeight, EntryGumpID);
AddLabel(x + TextOffsetX, y, TextHue, group.Name);
AddLabel(x + TextOffsetX, y, TextHue, group?.Name ?? "");
x += emptyWidth + (OldStyle ? OffsetSize * 2 : 0);
x += OffsetSize;
@ -306,7 +306,6 @@ namespace Server.Gumps
switch (sk.Lock)
{
default:
case SkillLock.Up:
buttonID1 = 0x983;
buttonID2 = 0x983;
xOffset = 6;