/// <summary> /// Applied before AndTagBits runs. /// </summary> internal static bool Prefix(KPrefabID __instance, ref TagBits ___tagBits, ref TagBits rhs) { __instance.UpdateTagBits(); TagBitOps.And(ref rhs, ref ___tagBits); return(false); }
public bool ClearableHasDestination(Pickupable pickupable) { KPrefabID kPrefabID = pickupable.KPrefabID; kPrefabID.UpdateTagBits(); return(kPrefabID.HasAnyTags_AssumeLaundered(ref storageFetchableBits)); }
public void CollectChores(ChoreConsumerState consumer_state, List <Chore.Precondition.Context> succeeded, List <Chore.Precondition.Context> failed_contexts) { ChoreType transport = Db.Get().ChoreTypes.Transport; int personalPriority = consumer_state.consumer.GetPersonalPriority(transport); int priority = (!Game.Instance.advancedPersonalPriorities) ? transport.priority : transport.explicitPriority; CollectSortedClearables(consumer_state.navigator, markedClearables, sortedClearables); bool flag = false; foreach (SortedClearable sortedClearable in sortedClearables) { SortedClearable current = sortedClearable; Pickupable pickupable = current.pickupable; PrioritySetting masterPriority = current.masterPriority; Chore.Precondition.Context item = default(Chore.Precondition.Context); item.personalPriority = personalPriority; KPrefabID kPrefabID = pickupable.KPrefabID; kPrefabID.UpdateTagBits(); foreach (GlobalChoreProvider.Fetch fetch in GlobalChoreProvider.Instance.fetches) { GlobalChoreProvider.Fetch current2 = fetch; if (kPrefabID.HasAnyTags_AssumeLaundered(ref current2.chore.tagBits)) { item.Set(current2.chore, consumer_state, false, pickupable); item.choreTypeForPermission = transport; item.RunPreconditions(); if (item.IsSuccess()) { item.masterPriority = masterPriority; item.priority = priority; item.interruptPriority = transport.interruptPriority; succeeded.Add(item); flag = true; break; } } } if (flag) { break; } } }
public static bool IsFetchablePickup(KPrefabID pickup_id, Storage source, float pickup_unreserved_amount, ref TagBits tag_bits, ref TagBits required_tags, ref TagBits forbid_tags, Storage destination) { if (pickup_unreserved_amount <= 0f) { return(false); } if ((Object)pickup_id == (Object)null) { return(false); } pickup_id.UpdateTagBits(); if (!pickup_id.HasAnyTags_AssumeLaundered(ref tag_bits)) { return(false); } if (!pickup_id.HasAllTags_AssumeLaundered(ref required_tags)) { return(false); } if (pickup_id.HasAnyTags_AssumeLaundered(ref forbid_tags)) { return(false); } if ((Object)source != (Object)null) { if (!source.ignoreSourcePriority && destination.ShouldOnlyTransferFromLowerPriority && destination.masterPriority <= source.masterPriority) { return(false); } if (destination.storageNetworkID != -1 && destination.storageNetworkID == source.storageNetworkID) { return(false); } } return(true); }
/// <summary> /// A version of OvercrowdingMonitor.UpdateCavity that updates the correct rooms. /// </summary> /// <param name="smi">The overcrowding monitor to update.</param> /// <param name="prefabID">The critter to be updated.</param> /// <returns>The new room of the critter.</returns> private static CavityInfo UpdateRoom(OvercrowdingMonitor.Instance smi, KPrefabID prefabID) { CavityInfo room = smi.cavity, newRoom; bool background = FastTrackOptions.Instance.BackgroundRoomRebuild; int cell = Grid.PosToCell(smi.transform.position); if (background) { newRoom = GamePatches.BackgroundRoomProber.Instance.GetCavityForCell(cell); } else { newRoom = Game.Instance.roomProber.GetCavityForCell(cell); } prefabID.UpdateTagBits(); if (newRoom != room) { bool isEgg = prefabID.HasAnyTags_AssumeLaundered(ref EGG), light = smi.GetComponent <Light2D>() != null; // Currently no rooms (checked I Love Slicksters, Butcher Stations, and Rooms // Expanded) use the WILDANIMAL criterion, so only light emitting critters // would need to actually update the rooms. if (room != null) { if (isEgg) { room.eggs.Remove(prefabID); } else { room.creatures.Remove(prefabID); } if (light) { if (background) { GamePatches.BackgroundRoomProber.Instance.UpdateRoom(room); } else { Game.Instance.roomProber.UpdateRoom(room); } } } smi.cavity = newRoom; if (newRoom != null) { if (isEgg) { newRoom.eggs.Add(prefabID); } else { newRoom.creatures.Add(prefabID); } if (light) { if (background) { GamePatches.BackgroundRoomProber.Instance.UpdateRoom(newRoom); } else { Game.Instance.roomProber.UpdateRoom(newRoom); } } } } return(newRoom); }
public void Begin(Precondition.Context context) { base.sm.fetcher.Set(context.consumerState.gameObject, base.smi); chores.Clear(); chores.Add(rootChore); Grid.CellToXY(Grid.PosToCell(rootChore.destination.transform.GetPosition()), out int x, out int y); ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList = ListPool <Precondition.Context, FetchAreaChore> .Allocate(); ListPool <Precondition.Context, FetchAreaChore> .PooledList pooledList2 = ListPool <Precondition.Context, FetchAreaChore> .Allocate(); if (rootChore.allowMultifetch) { GatherNearbyFetchChores(rootChore, context, x, y, 3, pooledList, pooledList2); } float num = Mathf.Max(1f, Db.Get().Attributes.CarryAmount.Lookup(context.consumerState.consumer).GetTotalValue()); Pickupable pickupable = context.data as Pickupable; if ((UnityEngine.Object)pickupable == (UnityEngine.Object)null) { Debug.Assert(pooledList.Count > 0, "succeeded_contexts was empty"); Precondition.Context context2 = pooledList[0]; FetchChore fetchChore = (FetchChore)context2.chore; Debug.Assert(fetchChore != null, "fetch_chore was null"); DebugUtil.LogWarningArgs("Missing root_fetchable for FetchAreaChore", fetchChore.destination, fetchChore.tags[0]); pickupable = fetchChore.FindFetchTarget(context.consumerState); } Debug.Assert((UnityEngine.Object)pickupable != (UnityEngine.Object)null, "root_fetchable was null"); List <Pickupable> list = new List <Pickupable>(); list.Add(pickupable); float num2 = pickupable.UnreservedAmount; float minTakeAmount = pickupable.MinTakeAmount; int x2 = 0; int y2 = 0; Grid.CellToXY(Grid.PosToCell(pickupable.transform.GetPosition()), out x2, out y2); int num3 = 6; x2 -= num3 / 2; y2 -= num3 / 2; ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList3 = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate(); GameScenePartitioner.Instance.GatherEntries(x2, y2, num3, num3, GameScenePartitioner.Instance.pickupablesLayer, pooledList3); Tag prefabTag = pickupable.GetComponent <KPrefabID>().PrefabTag; for (int i = 0; i < pooledList3.Count; i++) { ScenePartitionerEntry scenePartitionerEntry = pooledList3[i]; if (num2 > num) { break; } Pickupable pickupable2 = scenePartitionerEntry.obj as Pickupable; KPrefabID component = pickupable2.GetComponent <KPrefabID>(); if (!(component.PrefabTag != prefabTag) && !(pickupable2.UnreservedAmount <= 0f)) { component.UpdateTagBits(); if (component.HasAllTags_AssumeLaundered(ref rootChore.requiredTagBits) && !component.HasAnyTags_AssumeLaundered(ref rootChore.forbiddenTagBits) && !list.Contains(pickupable2) && rootContext.consumerState.consumer.CanReach(pickupable2)) { float unreservedAmount = pickupable2.UnreservedAmount; list.Add(pickupable2); num2 += unreservedAmount; if (list.Count >= 10) { break; } } } } pooledList3.Recycle(); num2 = Mathf.Min(num, num2); if (minTakeAmount > 0f) { num2 -= num2 % minTakeAmount; } deliveries.Clear(); float num4 = Mathf.Min(rootChore.originalAmount, num2); if (minTakeAmount > 0f) { num4 -= num4 % minTakeAmount; } deliveries.Add(new Delivery(rootContext, num4, OnFetchChoreCancelled)); float num5 = num4; for (int j = 0; j < pooledList.Count; j++) { if (num5 >= num2) { break; } Precondition.Context context3 = pooledList[j]; FetchChore fetchChore2 = context3.chore as FetchChore; if (fetchChore2 != rootChore && context3.IsSuccess() && (UnityEngine.Object)fetchChore2.overrideTarget == (UnityEngine.Object)null && (UnityEngine.Object)fetchChore2.driver == (UnityEngine.Object)null && fetchChore2.tagBits.AreEqual(ref rootChore.tagBits)) { num4 = Mathf.Min(fetchChore2.originalAmount, num2 - num5); if (minTakeAmount > 0f) { num4 -= num4 % minTakeAmount; } chores.Add(fetchChore2); deliveries.Add(new Delivery(context3, num4, OnFetchChoreCancelled)); num5 += num4; if (deliveries.Count >= 10) { break; } } } num5 = Mathf.Min(num5, num2); float num6 = num5; fetchables.Clear(); for (int k = 0; k < list.Count; k++) { if (num6 <= 0f) { break; } Pickupable pickupable3 = list[k]; num6 -= pickupable3.UnreservedAmount; fetchables.Add(pickupable3); } fetchAmountRequested = num5; reservations.Clear(); pooledList.Recycle(); pooledList2.Recycle(); }