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

@ -53,7 +53,7 @@ namespace Server.Gumps
string fealtyName;
if (fealty == null || (fealtyName = fealty.Name) == null || (fealtyName = fealtyName.Trim()).Length <= 0)
if ((fealtyName = fealty.Name) == null || (fealtyName = fealtyName.Trim()).Length <= 0)
fealtyName = "(empty)";
if (beholder == fealty)

View file

@ -652,23 +652,15 @@ namespace Server.Gumps
private class CustomItem
{
public CustomItem(int itemID, int loc) : this(null, itemID, loc, 0, false)
public CustomItem(int itemID, int loc, bool longText = false) : this(null, itemID, loc, 0, longText)
{
}
public CustomItem(int itemID, int loc, bool longText) : this(null, itemID, loc, 0, longText)
public CustomItem(Type type, int loc, int art = 0) : this(type, 0, loc, art)
{
}
public CustomItem(Type type, int loc) : this(type, loc, 0)
{
}
public CustomItem(Type type, int loc, int art) : this(type, 0, loc, art, false)
{
}
public CustomItem(Type type, int itemID, int loc, int art, bool longText)
public CustomItem(Type type, int itemID = 0, int loc = 0, int art = 0, bool longText = false)
{
Type = type;
ItemID = itemID;
@ -702,6 +694,7 @@ namespace Server.Gumps
}
catch
{
// ignored
}
return i;

View file

@ -452,9 +452,7 @@ namespace Server.Gumps
private static bool HasAttribute(Type type, Type check, bool inherit)
{
object[] objs = type.GetCustomAttributes(check, inherit);
return objs != null && objs.Length > 0;
return type.GetCustomAttributes(check, inherit).Length > 0;
}
private static bool IsType(Type type, Type check)

View file

@ -140,8 +140,7 @@ namespace Server.Gumps
public override void OnResponse(NetState sender, RelayInfo info)
{
object toSet;
bool shouldSet, shouldSend = true;
bool shouldSend = true;
object viewProps = null;
switch (info.ButtonID)
@ -149,25 +148,17 @@ namespace Server.Gumps
case 0: // closed
{
m_Mobile.SendGump(new PropertiesGump(m_Mobile, m_Object, m_Stack, m_List, m_Page));
toSet = null;
shouldSet = false;
shouldSend = false;
break;
}
case 1: // Change by Target
{
m_Mobile.Target = new SetObjectTarget(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List);
toSet = null;
shouldSet = false;
shouldSend = false;
break;
}
case 2: // Change by Serial
{
toSet = null;
shouldSet = false;
shouldSend = false;
m_Mobile.SendMessage("Enter the serial you wish to find:");
@ -177,16 +168,20 @@ namespace Server.Gumps
}
case 3: // Nullify
{
toSet = null;
shouldSet = true;
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name, "(null)");
m_Property.SetValue(m_Object, null, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
break;
}
case 4: // View Properties
{
toSet = null;
shouldSet = false;
object obj = m_Property.GetValue(m_Object, null);
if (obj == null)
@ -196,30 +191,10 @@ namespace Server.Gumps
else
viewProps = obj;
break;
}
default:
{
toSet = null;
shouldSet = false;
break;
}
}
if (shouldSet)
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet == null ? "(null)" : toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
if (shouldSend)
m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List));
@ -256,52 +231,41 @@ namespace Server.Gumps
public override void OnResponse(Mobile from, string text)
{
object toSet;
bool shouldSet;
try
{
int serial = Utility.ToInt32(text);
toSet = World.FindEntity(serial);
IEntity toSet = World.FindEntity(serial);
if (toSet == null)
{
shouldSet = false;
m_Mobile.SendMessage("No object with that serial was found.");
}
else if (!m_Type.IsAssignableFrom(toSet.GetType()))
else if (!m_Type.IsInstanceOfType(toSet))
{
toSet = null;
shouldSet = false;
m_Mobile.SendMessage("The object with that serial could not be assigned to a property of type : {0}",
m_Type.Name);
}
else
{
shouldSet = true;
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
}
}
catch
{
toSet = null;
shouldSet = false;
m_Mobile.SendMessage("Bad format");
}
if (shouldSet)
try
{
CommandLogging.LogChangeProperty(m_Mobile, m_Object, m_Property.Name,
toSet == null ? "(null)" : toSet.ToString());
m_Property.SetValue(m_Object, toSet, null);
PropertiesGump.OnValueChanged(m_Object, m_Property, m_Stack);
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
m_Mobile.SendGump(new SetObjectGump(m_Property, m_Mobile, m_Object, m_Stack, m_Type, m_Page, m_List));
}
}

View file

@ -44,7 +44,7 @@ namespace Server.Gumps
AddHtmlLocalized(45, 110, 150, 20, 1061279, GetColor(SecureLevel.Friends), false, false); // Friends
Mobile houseOwner = house.Owner;
if (Guild.NewGuildSystem && house != null && houseOwner?.Guild != null &&
if (Guild.NewGuildSystem && houseOwner?.Guild != null &&
((Guild)houseOwner.Guild).Leader == houseOwner
) //Only the actual House owner AND guild master can set guild secures
{