Skip to content

Commit

Permalink
Merge pull request #822 from zymex22/issue566
Browse files Browse the repository at this point in the history
Fixed issue where pawn Access Patch was affecting Pullers
  • Loading branch information
Sn1p3rr3c0n authored Dec 19, 2024
2 parents 6fa2c1e + da9889a commit 60ab5ae
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
30 changes: 16 additions & 14 deletions Source/ProjectRimFactory/AutoMachineTool/Building_BaseLimitation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using ProjectRimFactory.Common;
using RimWorld;
using System.Linq;
using ProjectRimFactory.Common.HarmonyPatches;
using Verse;
using static ProjectRimFactory.AutoMachineTool.Ops;

Expand Down Expand Up @@ -71,26 +72,27 @@ public bool IsLimit(ThingDef def)
public bool IsLimit(Thing thing)
{
if (!productLimitation) return false;

var targetSG = targetSlotGroup;

if (targetSG == null)

if (targetSlotGroup == null)
{
return this.CountFromMap(thing.def) >= productLimitCount;
}

// Use the faster limitWatcher if Available
if (targetSlotGroup.parent is ILimitWatcher limitWatcher)
{
if (limitWatcher.ItemIsLimit(thing.def,this.countStacks, productLimitCount)) return true;
}
else
{
if (targetSG.parent is ILimitWatcher limitWatcher)
{
return (limitWatcher.ItemIsLimit(thing.def,this.countStacks, productLimitCount) || !targetSG.CellsList.Any(c => c.IsValidStorageFor(this.Map, thing)));
}
else
{
return (this.CheckSlotGroup(targetSG, thing.def, productLimitCount) || !targetSG.CellsList.Any(c => c.IsValidStorageFor(this.Map, thing)));
}


if (this.CheckSlotGroup(targetSlotGroup, thing.def, productLimitCount)) return true;
}

// Disable Accepts Patch override for this call(s) of IsValidStorageFor
PatchStorageUtil.SkippAcceptsPatch = true;
bool isValidCheck = !targetSlotGroup.CellsList.Any(c => c.IsValidStorageFor(this.Map, thing));
PatchStorageUtil.SkippAcceptsPatch = false;
return isValidCheck;

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ static bool Prefix(Building_Storage __instance, Thing t, out bool __result)
{
__result = false;
//Check if pawn input is forbidden
if ((__instance as IForbidPawnInputItem)?.ForbidPawnInput ?? false)
if (!PatchStorageUtil.SkippAcceptsPatch && ((__instance as IForbidPawnInputItem)?.ForbidPawnInput ?? false))
{
//#699 #678
//This check is needed to support the use of the Limit function for the IO Ports
Expand All @@ -57,7 +57,7 @@ static bool Prefix(IStoreSettingsParent ___owner, Thing t, out bool __result)
if (___owner is Building_Storage storage)
{
//Check if pawn input is forbidden
if ((storage as IForbidPawnInputItem)?.ForbidPawnInput ?? false)
if (!PatchStorageUtil.SkippAcceptsPatch && ((storage as IForbidPawnInputItem)?.ForbidPawnInput ?? false))
{
//#699 #678
//This check is needed to support the use of the Limit function for the IO Ports
Expand Down Expand Up @@ -152,7 +152,9 @@ static class PatchStorageUtil
private static Dictionary<Tuple<Map, IntVec3, Type>, object> cache = new Dictionary<Tuple<Map, IntVec3, Type>, object>();
private static int lastTick = 0;
private static Dictionary<Map, PRFMapComponent> mapComps = new Dictionary<Map, PRFMapComponent>();

public static bool SkippAcceptsPatch = false;


public static PRFMapComponent GetPRFMapComponent(Map map)
{
PRFMapComponent outval = null;
Expand Down

0 comments on commit 60ab5ae

Please sign in to comment.