Skip to content

Commit

Permalink
added null checks for PlayerCollection.sacks
Browse files Browse the repository at this point in the history
  • Loading branch information
NorthFury authored and NorthFury committed Jan 3, 2018
1 parent 32f6072 commit 0866100
Showing 1 changed file with 37 additions and 25 deletions.
62 changes: 37 additions & 25 deletions src/TQVaultAE.DAL/PlayerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ public int NumberOfSacks
/// <returns>Each Sack in the sack array.</returns>
public IEnumerator<SackCollection> GetEnumerator()
{
if (this.sacks == null)
{
yield break;
}
foreach (SackCollection sack in this.sacks)
{
yield return sack;
Expand Down Expand Up @@ -278,11 +282,12 @@ public byte[] Encode()
/// <returns>Sack instace for the corresponding sack number</returns>
public SackCollection GetSack(int sackNumber)
{
if (sackNumber < this.sacks.Length){
return this.sacks[sackNumber];
}else{
if (this.sacks == null || this.sacks.Length <= sackNumber)
{
return null;
}

return this.sacks[sackNumber];
}

/// <summary>
Expand All @@ -294,7 +299,9 @@ public SackCollection GetSack(int sackNumber)
public bool MoveSack(int source, int destination)
{
// Do a little bit of error handling
if (destination < 0 || destination > this.sacks.Length || source < 0 || source > this.sacks.Length || source == destination)
if (this.sacks == null ||
destination < 0 || destination > this.sacks.Length ||
source < 0 || source > this.sacks.Length || source == destination)
{
return false;
}
Expand Down Expand Up @@ -327,7 +334,9 @@ public bool MoveSack(int source, int destination)
public bool CopySack(int source, int destination)
{
// Do a little bit of error handling
if (destination < 0 || destination > this.sacks.Length || source < 0 || source > this.sacks.Length || source == destination)
if (this.sacks == null ||
destination < 0 || destination > this.sacks.Length ||
source < 0 || source > this.sacks.Length || source == destination)
{
return false;
}
Expand Down Expand Up @@ -475,31 +484,34 @@ private void ParseRawData()
outStream.WriteLine("Number of Sacks = {0}", this.numberOfSacks);

int sackNumber = 0;
foreach (SackCollection sack in this.sacks)
if (this.sacks != null)
{
if (!sack.IsEmpty)
foreach (SackCollection sack in this.sacks)
{
outStream.WriteLine();
outStream.WriteLine("SACK {0}", sackNumber);

int itemNumber = 0;
foreach (Item item in sack)
if (!sack.IsEmpty)
{
object[] params1 = new object[20];

params1[0] = itemNumber;
params1[1] = item.ToString();
params1[2] = item.PositionX;
params1[3] = item.PositionY;
params1[4] = item.Seed;
////params1[5] =

outStream.WriteLine(" {0,5:n0} {1}", params1);
itemNumber++;
outStream.WriteLine();
outStream.WriteLine("SACK {0}", sackNumber);

int itemNumber = 0;
foreach (Item item in sack)
{
object[] params1 = new object[20];

params1[0] = itemNumber;
params1[1] = item.ToString();
params1[2] = item.PositionX;
params1[3] = item.PositionY;
params1[4] = item.Seed;
////params1[5] =

outStream.WriteLine(" {0,5:n0} {1}", params1);
itemNumber++;
}
}
}

sackNumber++;
sackNumber++;
}
}
}
}
Expand Down

0 comments on commit 0866100

Please sign in to comment.