Skip to content

Commit

Permalink
Fix for Android(work only once bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaneYork committed Apr 13, 2020
1 parent 46ab660 commit 66b5a38
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
1 change: 1 addition & 0 deletions DeluxeGrabber/DeluxeGrabber.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
<Compile Include="ModAPI.cs" />
<Compile Include="ModConfig.cs" />
<Compile Include="ModEntry.cs" />
<Compile Include="NetListExtend.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
26 changes: 13 additions & 13 deletions DeluxeGrabber/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
continue;
}

if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
return;
}

Expand Down Expand Up @@ -118,7 +118,7 @@ private void OnObjectListChanged(object sender, ObjectListChangedEventArgs e) {
}
}

if ((grabber.heldObject.Value as Chest).items.Count > 0) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ private void AutograbBuildings() {
bool full = false;
foreach (Vector2 tile in grabbables) {

if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log($" Grabber is full", LogLevel.Trace);
full = true;
break;
Expand Down Expand Up @@ -217,7 +217,7 @@ private void AutograbBuildings() {
}

// update sprite if grabber has items in it
if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand All @@ -234,10 +234,10 @@ private void AutograbCrops() {
foreach (KeyValuePair<Vector2, Object> pair in location.Objects.Pairs) {
if (pair.Value.Name.Contains("Grabber")) {
Object grabber = pair.Value;
if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value == null) || (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
continue;
}
bool full = (grabber.heldObject.Value as Chest).items.Count >= 36;
bool full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36;
for (int x = (int)pair.Key.X - range; x < pair.Key.X + range + 1; x ++) {
for (int y = (int)pair.Key.Y - range; y < pair.Key.Y + range + 1 && !full; y++) {
Vector2 tile = new Vector2(x, y);
Expand Down Expand Up @@ -277,10 +277,10 @@ private void AutograbCrops() {
}
}
}
full = (grabber.heldObject.Value as Chest).items.Count >= 36;
full = (grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36;
}
}
if (grabber != null && (grabber.heldObject.Value as Chest).items.Count > 0) {
if (grabber != null && (grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down Expand Up @@ -439,7 +439,7 @@ private void AutograbWorld() {
if (location.Name.Equals("Forest")) {
foreach (TerrainFeature feature in location.terrainFeatures.Values) {

if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -497,7 +497,7 @@ private void AutograbWorld() {
break;
}

if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -527,7 +527,7 @@ private void AutograbWorld() {
// add items to grabber and remove from floor
foreach (Vector2 tile in grabbables) {

if ((grabber.heldObject.Value as Chest).items.Count >= 36) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36) {
Monitor.Log("Global grabber full", LogLevel.Info);
return;
}
Expand Down Expand Up @@ -570,7 +570,7 @@ private void AutograbWorld() {
foreach (Object obj in location.Objects.Values)
{

if ((grabber.heldObject.Value as Chest).items.Count >= 36)
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() >= 36)
{
Monitor.Log("Global grabber full", LogLevel.Info);
return;
Expand Down Expand Up @@ -603,7 +603,7 @@ private void AutograbWorld() {
Monitor.Log($" {location} - found {pair.Value} {pair.Key}{plural}", LogLevel.Trace);
}

if ((grabber.heldObject.Value as Chest).items.Count > 0) {
if ((grabber.heldObject.Value as Chest).items.CountIgnoreNull() > 0) {
grabber.showNextIndex.Value = true;
}
}
Expand Down
13 changes: 13 additions & 0 deletions DeluxeGrabber/NetListExtend.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using Netcode;
using System.Linq;

namespace DeluxeGrabber
{
public static class NetListExtend
{
public static int CountIgnoreNull<T>(this NetObjectList<T> list) where T : class, INetObject<INetSerializable>
{
return list.Count(item => item != null);
}
}
}

0 comments on commit 66b5a38

Please sign in to comment.