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

@ -220,9 +220,6 @@ namespace Server.Engines.Doom
else
trap = new MushroomTrap();
if (trap == null)
return;
if (trap is FireColumnTrap || trap is MushroomTrap)
trap.Hue = 0x451;

View file

@ -327,7 +327,7 @@ namespace Server.Factions
{
double prio = m_Mobile.GetDistanceToSqrt(m);
if (!activeOnly && (inactive == null || prio < inactPrio))
if (inactive == null || prio < inactPrio)
{
inactive = m;
inactPrio = prio;

View file

@ -160,48 +160,48 @@ namespace Server.PathAlgorithms.FastAStar
bool wasTouched = m_Touched[newNode];
if (!wasTouched)
if (wasTouched)
continue;
int newCost = m_Nodes[bestNode].cost + 1;
int newTotal = newCost + Heuristic(newNode % AreaSize, newNode / AreaSize % AreaSize,
m_Nodes[newNode].z);
if (m_Nodes[newNode].total <= newTotal)
continue;
m_Nodes[newNode].parent = bestNode;
m_Nodes[newNode].cost = newCost;
m_Nodes[newNode].total = newTotal;
if (m_OnOpen[newNode])
continue;
AddToChain(newNode);
if (newNode != destNode)
continue;
pathCount = 0;
parent = m_Nodes[newNode].parent;
while (parent != -1)
{
int newCost = m_Nodes[bestNode].cost + 1;
int newTotal = newCost + Heuristic(newNode % AreaSize, newNode / AreaSize % AreaSize,
m_Nodes[newNode].z);
path[pathCount++] = GetDirection(parent % AreaSize, parent / AreaSize % AreaSize,
newNode % AreaSize, newNode / AreaSize % AreaSize);
newNode = parent;
parent = m_Nodes[newNode].parent;
if (!wasTouched || m_Nodes[newNode].total > newTotal)
{
m_Nodes[newNode].parent = bestNode;
m_Nodes[newNode].cost = newCost;
m_Nodes[newNode].total = newTotal;
if (!wasTouched || !m_OnOpen[newNode])
{
AddToChain(newNode);
if (newNode == destNode)
{
pathCount = 0;
parent = m_Nodes[newNode].parent;
while (parent != -1)
{
path[pathCount++] = GetDirection(parent % AreaSize, parent / AreaSize % AreaSize,
newNode % AreaSize, newNode / AreaSize % AreaSize);
newNode = parent;
parent = m_Nodes[newNode].parent;
if (newNode == fromNode)
break;
}
Direction[] dirs = new Direction[pathCount];
while (pathCount > 0)
dirs[backtrack++] = path[--pathCount];
return dirs;
}
}
}
if (newNode == fromNode)
break;
}
Direction[] dirs = new Direction[pathCount];
while (pathCount > 0)
dirs[backtrack++] = path[--pathCount];
return dirs;
}
}

View file

@ -529,7 +529,7 @@ namespace Server.Movement
zLow = landZ;
zCenter = landCenter;
if (!isSet || landTop > zTop)
if (landTop > zTop)
zTop = landTop;
isSet = true;

View file

@ -152,10 +152,10 @@ namespace Server.Engines.Plants
if (firstPrimary && secondPrimary)
return notBrightFirst | notBrightSecond;
if (firstPrimary && !secondPrimary)
if (firstPrimary)
return notBrightFirst;
if (!firstPrimary && secondPrimary)
if (secondPrimary)
return notBrightSecond;
return notBrightFirst & notBrightSecond;

View file

@ -125,15 +125,8 @@ namespace Server.Engines.Plants
private int m_SeedLabelPlural;
private PlantTypeInfo(int itemID, int offsetX, int offsetY, PlantType plantType, bool containsPlant, bool flowery,
bool crossable, bool reproduces, PlantCategory plantCategory)
: this(itemID, offsetX, offsetY, plantType, containsPlant, flowery, crossable, reproduces, plantCategory, -1, -1,
-1, -1, -1, -1)
{
}
private PlantTypeInfo(int itemID, int offsetX, int offsetY, PlantType plantType, bool containsPlant, bool flowery,
bool crossable, bool reproduces, PlantCategory plantCategory, int plantLabelSeed, int plantLabelPlant,
int plantLabelFullGrown, int plantLabelDecorative, int seedLabel, int seedLabelPlural)
bool crossable, bool reproduces, PlantCategory plantCategory, int plantLabelSeed = -1, int plantLabelPlant = -1,
int plantLabelFullGrown = -1, int plantLabelDecorative = -1, int seedLabel = -1, int seedLabelPlural = -1)
{
ItemID = itemID;
OffsetX = offsetX;

View file

@ -110,7 +110,7 @@ namespace Server.Engines.Quests.Doom
}
else
{
bool hasRights = true;
bool hasRights = false;
if (m_Daemon != null)
{

View file

@ -72,11 +72,12 @@ namespace Server.RemoteAdmin
{
LazyInitialize();
if (!Enabled) return;
if (!Enabled)
return;
try
{
Account acct = state.Account as Account;
Account acct = state?.Account as Account;
string name = acct == null ? "(UNKNOWN)" : acct.Username;
string accesslevel = acct == null ? "NoAccount" : acct.AccessLevel.ToString();
string statestr = state == null ? "NULLSTATE" : state.ToString();
@ -97,6 +98,7 @@ namespace Server.RemoteAdmin
}
catch
{
// ignored
}
}
}

View file

@ -188,15 +188,14 @@ namespace Server.Engines.Reports
for (int i = 0; i < _chartItems.Count; i++)
{
DataItem item = (DataItem)_chartItems[i];
SolidBrush brs = null;
DataItem item = (DataItem)_chartItems[i];
try
{
grp.DrawPie(new Pen(_borderColor, 0.5f), pieRect, item.StartPos, item.SweepSize);
}
finally
catch
{
brs?.Dispose();
// ignored
}
}
@ -226,8 +225,8 @@ namespace Server.Engines.Reports
}
finally
{
sf?.Dispose();
grp?.Dispose();
sf.Dispose();
grp.Dispose();
sfp?.Dispose();
fnt?.Dispose();
pen?.Dispose();

View file

@ -354,44 +354,40 @@ namespace Server.Mobiles
{
Defrag();
if (Entries.Count > 0 && !IsFull)
if (Entries.Count <= 0 || IsFull)
return;
int probsum = 0;
for (int i = 0; i < Entries.Count; i++)
if (!Entries[i].IsFull)
probsum += Entries[i].SpawnedProbability;
if (probsum <= 0)
return;
int rand = Utility.RandomMinMax(1, probsum);
for (int i = 0; i < Entries.Count; i++)
{
int probsum = 0;
SpawnerEntry entry = Entries[i];
if (entry.IsFull)
continue;
for (int i = 0; i < Entries.Count; i++)
if (!Entries[i].IsFull)
probsum += Entries[i].SpawnedProbability;
if (probsum > 0)
if (rand <= entry.SpawnedProbability)
{
int rand = Utility.RandomMinMax(1, probsum);
for (int i = 0; i < Entries.Count; i++)
{
SpawnerEntry entry = Entries[i];
if (!entry.IsFull)
{
bool success = true;
if (rand <= entry.SpawnedProbability)
{
EntryFlags flags;
success = Spawn(entry, out flags);
entry.Valid = flags;
return;
}
if (success)
rand -= entry.SpawnedProbability;
}
}
Spawn(entry, out EntryFlags flags);
entry.Valid = flags;
return;
}
rand -= entry.SpawnedProbability;
}
}
private static string[,] FormatProperties(string[] args)
{
string[,] props = null;
string[,] props;
int remains = args.Length;

View file

@ -11,15 +11,7 @@ namespace Server.Mobiles
private int m_Page;
private Spawner m_Spawner;
public SpawnerGump(Spawner spawner) : this(spawner, 0)
{
}
public SpawnerGump(Spawner spawner, int page) : this(spawner, null, page)
{
}
public SpawnerGump(Spawner spawner, SpawnerEntry focusentry, int page) : base(50, 50)
public SpawnerGump(Spawner spawner, SpawnerEntry focusentry = null, int page = 0) : base(50, 50)
{
m_Spawner = spawner;
m_Entry = focusentry;
@ -51,7 +43,7 @@ namespace Server.Mobiles
AddButton(5, 22 * i + 21 + offset, entry != null ? 0xFBA : 0xFA5, entry != null ? 0xFBC : 0xFA7,
GetButtonID(2, i * 2), GumpButtonType.Reply, 0); //Expand
else
AddButton(5, 22 * i + 21 + offset, entry != null ? 0xFBB : 0xFA5, entry != null ? 0xFBC : 0xFA7,
AddButton(5, 22 * i + 21 + offset, 0xFBB, 0xFBC,
GetButtonID(2, i * 2), GumpButtonType.Reply, 0); //Unexpand
AddButton(38, 22 * i + 21 + offset, 0xFA2, 0xFA4, GetButtonID(2, 1 + i * 2), GumpButtonType.Reply,
@ -163,7 +155,7 @@ namespace Server.Mobiles
if (type != null)
{
SpawnerEntry entry = null;
SpawnerEntry entry;
if (entryindex < ocount)
{
@ -221,8 +213,6 @@ namespace Server.Mobiles
if (m_Spawner.Deleted)
return;
Mobile from = state.Mobile;
int val = info.ButtonID - 1;
if (val < 0)
@ -309,7 +299,7 @@ namespace Server.Mobiles
}
}
if (m_Entry != null && m_Spawner.Entries.Contains(m_Entry))
if (m_Entry != null && m_Spawner.Entries?.Contains(m_Entry) == true)
state.Mobile.SendGump(new SpawnerGump(m_Spawner, m_Entry, m_Page));
else
state.Mobile.SendGump(new SpawnerGump(m_Spawner, null, m_Page));