Fixes bad expressions, bad bool checks in loops, a few null pointer exceptions, and optimizes constructors.

This commit is contained in:
Kamron Batman 2018-09-15 23:16:45 -07:00
parent 8da55d6043
commit f93c3b992e
62 changed files with 318 additions and 634 deletions

View file

@ -340,16 +340,11 @@ namespace Server.Gumps
return Encoding.ASCII.GetBytes(str);
}
private Packet Compile()
{
return Compile(null);
}
private Packet Compile(NetState ns)
private Packet Compile(NetState ns = null)
{
IGumpWriter disp;
if (ns != null && ns.Unpack)
if (ns?.Unpack == true)
disp = new DisplayGumpPacked(this);
else
disp = new DisplayGumpFast(this);
@ -367,11 +362,10 @@ namespace Server.Gumps
disp.AppendLayout(m_NoResize);
int count = Entries.Count;
GumpEntry e;
for (int i = 0; i < count; ++i)
{
e = Entries[i];
GumpEntry e = Entries[i];
disp.AppendLayout(m_BeginLayout);
e.AppendTo(ns, disp);

View file

@ -93,13 +93,13 @@ namespace Server
public static IEnumerable<T> SelectMobiles<T>(Sector s, Rectangle2D bounds) where T : Mobile
{
return s.Mobiles.OfType<T>().Where(o => o != null && !o.Deleted && bounds.Contains(o));
return s.Mobiles.OfType<T>().Where(o => !o.Deleted && bounds.Contains(o));
}
public static IEnumerable<T> SelectItems<T>(Sector s, Rectangle2D bounds) where T : Item
{
return s.Items.OfType<T>()
.Where(o => o != null && !o.Deleted && o.Parent == null && o is T && bounds.Contains(o));
.Where(o => !o.Deleted && o.Parent == null && bounds.Contains(o));
}
public static IEnumerable<BaseMulti> SelectMultis(Sector s, Rectangle2D bounds)
@ -151,12 +151,7 @@ namespace Server
return Map.PooledEnumerable<NetState>.Instantiate(map, bounds, ClientSelector ?? SelectClients);
}
public static Map.PooledEnumerable<IEntity> GetEntities(Map map, Rectangle2D bounds)
{
return GetEntities(map, bounds, true, true);
}
public static Map.PooledEnumerable<IEntity> GetEntities(Map map, Rectangle2D bounds, bool items, bool mobiles)
public static Map.PooledEnumerable<IEntity> GetEntities(Map map, Rectangle2D bounds, bool items = true, bool mobiles = true)
{
return Map.PooledEnumerable<IEntity>.Instantiate(map, bounds, EntitySelector ?? SelectEntities);
}

View file

@ -8207,20 +8207,15 @@ namespace Server
m_CancelCallback = cancelCallback;
}
public SimplePrompt(PromptCallback callback, bool callbackHandlesCancel)
public SimplePrompt(PromptCallback callback, bool callbackHandlesCancel = false)
{
m_Callback = callback;
m_CallbackHandlesCancel = callbackHandlesCancel;
}
public SimplePrompt(PromptCallback callback)
: this(callback, false)
{
}
public override void OnResponse(Mobile from, string text)
{
m_Callback?.Invoke(@from, text);
m_Callback?.Invoke(from, text);
}
public override void OnCancel(Mobile from)
@ -8229,7 +8224,7 @@ namespace Server
m_Callback(from, "");
else
{
m_CancelCallback?.Invoke(@from, "");
m_CancelCallback?.Invoke(from, "");
}
}
}
@ -8285,7 +8280,7 @@ namespace Server
public override void OnResponse(Mobile from, string text)
{
m_Callback?.Invoke(@from, text, m_State);
m_Callback?.Invoke(from, text, m_State);
}
public override void OnCancel(Mobile from)
@ -8294,7 +8289,7 @@ namespace Server
m_Callback(from, "", m_State);
else
{
m_CancelCallback?.Invoke(@from, "", m_State);
m_CancelCallback?.Invoke(from, "", m_State);
}
}
}
@ -8350,7 +8345,7 @@ namespace Server
public override void OnResponse(Mobile from, string text)
{
m_Callback?.Invoke(@from, text, m_State);
m_Callback?.Invoke(from, text, m_State);
}
public override void OnCancel(Mobile from)
@ -8359,7 +8354,7 @@ namespace Server
m_Callback(from, "", m_State);
else
{
m_CancelCallback?.Invoke(@from, "", m_State);
m_CancelCallback?.Invoke(from, "", m_State);
}
}
}

View file

@ -934,8 +934,7 @@ namespace Server
}
catch
{
double val;
if (double.TryParse(doubleString, out val))
if (double.TryParse(doubleString, out double val))
return val;
return defaultValue;
@ -950,8 +949,7 @@ namespace Server
}
catch
{
int val;
if (int.TryParse(intString, out val))
if (int.TryParse(intString, out int val))
return val;
return defaultValue;
@ -966,9 +964,7 @@ namespace Server
}
catch
{
DateTime d;
if (DateTime.TryParse(dateTimeString, out d))
if (DateTime.TryParse(dateTimeString, out DateTime d))
return d;
return defaultValue;
@ -983,9 +979,7 @@ namespace Server
}
catch
{
DateTimeOffset d;
if (DateTimeOffset.TryParse(dateTimeOffsetString, out d))
if (DateTimeOffset.TryParse(dateTimeOffsetString, out DateTimeOffset d))
return d;
return defaultValue;