public void CreateChore()
        {
            KBatchedAnimController component = GetComponent <KBatchedAnimController>();

            Tag[] tags = GetComponent <TreeFilterable>().GetTags();
            if (tags == null || tags.Length == 0)
            {
                component.TintColour = base.master.noFilterTint;
            }
            else
            {
                component.TintColour = base.master.filterTint;
                Tag[] array = base.master.allowManualPumpingStationFetching ? new Tag[0] : new Tag[1]
                {
                    GameTags.LiquidSource
                };
                Storage   component2     = GetComponent <Storage>();
                ChoreType storageFetch   = Db.Get().ChoreTypes.StorageFetch;
                Storage   destination    = component2;
                float     amount         = component2.Capacity();
                Tag[]     tags2          = GetComponent <TreeFilterable>().GetTags();
                Tag[]     forbidden_tags = array;
                chore = new FetchChore(storageFetch, destination, amount, tags2, null, forbidden_tags, null, true, null, null, null, FetchOrder2.OperationalRequirement.Operational, 0);
            }
        }
예제 #2
0
            public void CreateChore()
            {
                KBatchedAnimController component1 = this.GetComponent <KBatchedAnimController>();

                Tag[] tags = this.GetComponent <TreeFilterable>().GetTags();
                if (tags == null || tags.Length == 0)
                {
                    component1.TintColour = (Color32)VesselInserter.noFilterTint;
                }
                else
                {
                    component1.TintColour = (Color32)VesselInserter.filterTint;
                    Tag[] forbidden_tags;
                    if (!this.master.allowManualPumpingStationFetching)
                    {
                        forbidden_tags = new Tag[1]
                        {
                            GameTags.LiquidSource
                        }
                    }
                    ;
                    else
                    {
                        forbidden_tags = new Tag[0];
                    }
                    Storage component2 = this.GetComponent <Storage>();
                    this.chore = new FetchChore(Db.Get().ChoreTypes.StorageFetch, component2, component2.RemainingCapacity(), this.GetComponent <TreeFilterable>().GetTags(),
                                                (Tag[])null, forbidden_tags, (ChoreProvider)null, true, (System.Action <Chore>)null, (System.Action <Chore>)null, (System.Action <Chore>)null,
                                                FetchOrder2.OperationalRequirement.Operational, 0);
                }
            }
예제 #3
0
        /// <summary>
        /// Uses the stock game logic to look for a usable item, but starts an efficient
        /// fetch search if it is too small.
        /// </summary>
        /// <param name="chore">The chore which is being completed.</param>
        /// <param name="state">The state of that chore.</param>
        /// <param name="result">The item to be picked up.</param>
        /// <returns>true to use the stock logic, or false to skip the stock method</returns>
        internal bool FindFetchTarget(FetchChore chore, ChoreConsumerState state,
                                      out Pickupable result)
        {
            bool cont = true;

            if (chore.destination != null && !state.hasSolidTransferArm && fmPickups != null)
            {
                // Only use if not a storage fetch (tidy)
                var id = chore.choreType?.Id ?? "";
                if (id != choreTypes.StorageFetch.Id && id != choreTypes.CreatureFetch.Id &&
                    id != choreTypes.FoodFetch.Id)
                {
                    result = FindFetchTarget(chore);
                    cont   = false;
                }
                else
                {
                    result = null;
                }
            }
            else
            {
                result = null;
            }
            return(cont);
        }
            public void CreateChore()
            {
                KBatchedAnimController component1 = GetComponent <KBatchedAnimController>();

                Tag[] tags = GetComponent <TreeFilterable>().GetTags();
                if (tags == null || tags.Length == 0)
                {
                    component1.TintColour = master.noFilterTint;
                }
                else
                {
                    component1.TintColour = master.filterTint;
                    Tag[] forbidden_tags;
                    if (!master.allowManualPumpingStationFetching)
                    {
                        forbidden_tags = new Tag[1]
                        {
                            GameTags.LiquidSource
                        }
                    }
                    ;
                    else
                    {
                        forbidden_tags = new Tag[0];
                    }
                    foreach (Tag tag in forbidden_tags)
                    {
                        Console.WriteLine("Emptier Tag:" + tag.Name);
                    }
                    Storage component2 = GetComponent <Storage>();
                    chore = new FetchChore(Db.Get().ChoreTypes.StorageFetch, component2, component2.Capacity(), GetComponent <TreeFilterable>().GetTags(), forbidden_tags: forbidden_tags);
                }
            }
예제 #5
0
        public static bool Prefix(BottleEmptier.StatesInstance __instance)
        {
            if (!(__instance.master is IUserControlledCapacity))
            {
                return(true);
            }
            var controller = __instance.GetComponent <KBatchedAnimController>();
            var tags       = __instance.GetComponent <TreeFilterable>().GetTags();

            if (tags == null || tags.Length == 0)
            {
                controller.TintColour = __instance.master.noFilterTint;
            }
            else
            {
                controller.TintColour = __instance.master.filterTint;
                var forbiddenTags = !__instance.master.allowManualPumpingStationFetching
                    ? new[] { GameTags.LiquidSource }
                    : new Tag[0];

                var amount = ((BottleEmptier2)__instance.master).UserMaxCapacity / 1000f;

                var chore = new FetchChore(Db.Get().ChoreTypes.StorageFetch, __instance.GetComponent <Storage>(), amount,
                                           __instance.GetComponent <TreeFilterable>().GetTags(), null, forbiddenTags);
                Traverse.Create(__instance).Field("chore").SetValue(chore);
            }

            return(false);
        }
예제 #6
0
            public void CreateChore()
            {
                KBatchedAnimController component1 = this.GetComponent <KBatchedAnimController>();

                Tag[] tags = this.GetComponent <TreeFilterable>().GetTags();
                if (tags == null || tags.Length == 0)
                {
                    component1.TintColour = (Color32)this.master.noFilterTint;
                }
                else
                {
                    component1.TintColour = (Color32)this.master.filterTint;
                    Tag[] forbidden_tags;
                    if (!this.master.allowManualPumpingStationFetching)
                    {
                        forbidden_tags = new Tag[1]
                        {
                            GameTags.LiquidSource
                        }
                    }
                    ;
                    else
                    {
                        forbidden_tags = new Tag[0];
                    }
                    Storage component2 = this.GetComponent <Storage>();
                    this.chore = new FetchChore(Db.Get().ChoreTypes.StorageFetch, component2, component2.Capacity(), this.GetComponent <TreeFilterable>().GetTags(), forbidden_tags: forbidden_tags);
                }
            }
        private void OnFetchChoreCancelled(FetchChore chore)
        {
            int num = 0;

            while (true)
            {
                if (num >= deliveries.Count)
                {
                    return;
                }
                if (deliveries[num].chore == chore)
                {
                    break;
                }
                num++;
            }
            if (deliveries.Count == 1)
            {
                StopSM("AllDelivericesCancelled");
            }
            else if (num == 0)
            {
                base.sm.currentdeliverycancelled.Trigger(this);
            }
            else
            {
                deliveries[num].Cleanup();
                deliveries.RemoveAt(num);
            }
        }
예제 #8
0
            /// <summary>
            /// Determines if popups should be hidden from deliveries.
            /// </summary>
            /// <param name="chore">The chore that delivered the item.</param>
            private static bool ShouldHidePopups(FetchChore chore)
            {
                var  opts        = ToastControlPopups.Options;
                bool deliverDupe = opts.Delivered;

                return((deliverDupe != opts.DeliveredMachine) ? (deliverDupe != (chore.fetcher.
                                                                                 GetComponent <MinionBrain>() != null)) : !deliverDupe);
            }
 public void CreateFetchTask()
 {
     chore = new FetchChore(Db.Get().ChoreTypes.FetchCritical, GetComponent <Storage>(), 1f, new Tag[1]
     {
         GameTags.Corpse
     }, null, null, null, true, null, null, null, FetchOrder2.OperationalRequirement.Operational, 0);
     chore.allowMultifetch = false;
 }
 public void CancelChore()
 {
     if (chore != null)
     {
         chore.Cancel("Storage Changed");
         chore = null;
     }
 }
 public void Cleanup()
 {
     if (this.chore != null)
     {
         FetchChore chore = this.chore;
         chore.onCleanup = (Action <Chore>)Delegate.Remove(chore.onCleanup, onFetchChoreCleanup);
         this.chore.FetchAreaEnd(null, null, false);
     }
 }
 public void CancelChore()
 {
     if (chore == null)
     {
         return;
     }
     chore.Cancel("Storage Changed");
     chore = null;
 }
예제 #13
0
 public void Cancel(string reason)
 {
     while (Chores.Count > 0)
     {
         FetchChore fetchChore = Chores[0];
         fetchChore.Cancel(reason);
         Chores.Remove(fetchChore);
     }
 }
예제 #14
0
        /// <summary>
        /// Searches for fetchable pickups for the given chore.
        /// </summary>
        /// <param name="chore">The chore to complete.</param>
        /// <returns>The pickup to fetch, or null if none are currently available.</returns>
        internal Pickupable FindFetchTarget(FetchChore chore)
        {
            Pickupable bestMatch = null;
            var        destination = chore.destination;
            float      required = chore.originalAmount, target = required * thresholdFraction,
                       canGet = 0.0f;

            foreach (var pickup in fmPickups)
            {
                var pickupable = pickup.pickupable;
                // Is this item accessible?
                if (FetchManager.IsFetchablePickup(pickupable, ref chore.tagBits, ref chore.
                                                   requiredTagBits, ref chore.forbiddenTagBits, destination))
                {
                    float amount = pickupable.UnreservedAmount;
                    if (bestMatch == null)
                    {
                        // Indicate if anything can be found at all
                        bestMatch = pickupable;
                        canGet    = amount;
                    }
                    if (amount >= target)
                    {
                        // Already have the best one in our sights
                        bestMatch = pickupable;
                        canGet    = amount;
                        break;
                    }
                }
            }
            // Do not start a fetch entry if nothing is available
            if (bestMatch != null)
            {
                Tag itemType = bestMatch.PrefabID();
                if (outstanding.TryGetValue(itemType, out FetchData current) && !current.
                    NeedsScan)
                {
                    // Retire it, with the best item we could do
                    outstanding.TryRemove(itemType, out _);
#if DEBUG
                    PUtil.LogDebug("{3} {0} ({2}) with {1:F2}".F(destination.name,
                                                                 canGet, itemType, (canGet >= target) ? "Complete" : "Retire"));
#endif
                }
                else if (canGet < target && outstanding.TryAdd(itemType, new FetchData(
                                                                   target)))
                {
                    // Start searching for a better option
#if DEBUG
                    PUtil.LogDebug("Find {0} ({3}): have {1:F2}, want {2:F2}".F(
                                       destination.name, canGet, target, itemType));
#endif
                    bestMatch = null;
                }
            }
            return(bestMatch);
        }
예제 #15
0
 public void CancelChore()
 {
     if (this.chore == null)
     {
         return;
     }
     this.chore.Cancel("Storage Changed");
     this.chore = (FetchChore)null;
 }
예제 #16
0
    public override void AddChore(Chore chore)
    {
        base.AddChore(chore);
        FetchChore fetchChore = chore as FetchChore;

        if (fetchChore != null)
        {
            fetchChores.Add(fetchChore);
        }
    }
예제 #17
0
    private void OnFetchChoreComplete(Chore chore)
    {
        FetchChore fetchChore = (FetchChore)chore;

        Chores.Remove(fetchChore);
        if (Chores.Count == 0 && OnComplete != null)
        {
            OnComplete(this, fetchChore.fetchTarget);
        }
    }
예제 #18
0
    public override void RemoveChore(Chore chore)
    {
        base.RemoveChore(chore);
        FetchChore fetchChore = chore as FetchChore;

        if (fetchChore != null)
        {
            fetchChores.Remove(fetchChore);
        }
    }
 public bool SameDestination(FetchChore fetch)
 {
     foreach (FetchChore chore in chores)
     {
         if ((UnityEngine.Object)chore.destination == (UnityEngine.Object)fetch.destination)
         {
             return(true);
         }
     }
     return(false);
 }
예제 #20
0
    private void OnFetchChoreBegin(Chore chore)
    {
        FetchChore fetchChore = (FetchChore)chore;

        UnfetchedAmount += fetchChore.originalAmount - fetchChore.amount;
        IssueTask();
        if (OnBegin != null)
        {
            OnBegin(this, fetchChore.fetchTarget);
        }
    }
예제 #21
0
            /// <summary>
            /// Applied before FindFetchTarget runs.
            /// </summary>
            internal static bool Prefix(FetchChore __instance, ChoreConsumerState
                                        consumer_state, ref Pickupable __result)
            {
                var  inst = EfficientFetchManager.Instance;
                bool cont = true;

                if (inst != null && options.MinimumAmountPercent > 0)
                {
                    cont = inst.FindFetchTarget(__instance, consumer_state, out __result);
                }
                return(cont);
            }
예제 #22
0
 public void CancelActiveRequest()
 {
     if (fetchChore != null)
     {
         MaterialNeeds.Instance.UpdateNeed(requestedEntityTag, -1f);
         fetchChore.Cancel("User canceled");
         fetchChore = null;
     }
     requestedEntityTag = Tag.Invalid;
     UpdateStatusItem();
     SetPreview(Tag.Invalid, false);
 }
예제 #23
0
    private void OnFetchChoreEnd(Chore chore)
    {
        FetchChore fetchChore = (FetchChore)chore;

        if (Chores.Contains(fetchChore))
        {
            UnfetchedAmount += fetchChore.amount;
            fetchChore.Cancel("FetchChore Redistribution");
            Chores.Remove(fetchChore);
            IssueTask();
        }
    }
    public static void GatherNearbyFetchChores(FetchChore root_chore, Precondition.Context context, int x, int y, int radius, List <Precondition.Context> succeeded_contexts, List <Precondition.Context> failed_contexts)
    {
        ListPool <ScenePartitionerEntry, FetchAreaChore> .PooledList pooledList = ListPool <ScenePartitionerEntry, FetchAreaChore> .Allocate();

        GameScenePartitioner.Instance.GatherEntries(x - radius, y - radius, radius * 2 + 1, radius * 2 + 1, GameScenePartitioner.Instance.fetchChoreLayer, pooledList);
        for (int i = 0; i < pooledList.Count; i++)
        {
            ScenePartitionerEntry scenePartitionerEntry = pooledList[i];
            FetchChore            fetchChore            = scenePartitionerEntry.obj as FetchChore;
            fetchChore.CollectChoresFromGlobalChoreProvider(context.consumerState, succeeded_contexts, failed_contexts, true);
        }
        pooledList.Recycle();
    }
            public Delivery(Precondition.Context context, float amount_to_be_fetched, Action <FetchChore> on_cancelled)
            {
                this        = default(Delivery);
                this.chore  = (context.chore as FetchChore);
                amount      = this.chore.originalAmount;
                destination = this.chore.destination;
                this.chore.SetOverrideTarget(context.consumerState.consumer);
                onCancelled         = on_cancelled;
                onFetchChoreCleanup = OnFetchChoreCleanup;
                this.chore.FetchAreaBegin(context, amount_to_be_fetched);
                FetchChore chore = this.chore;

                chore.onCleanup = (Action <Chore>)Delegate.Combine(chore.onCleanup, onFetchChoreCleanup);
            }
예제 #26
0
 protected void CreateFetchChore()
 {
     if (fetchChore != null)
     {
         fetchChore.Cancel("Overwrite");
     }
     GetComponent <KSelectable>().RemoveStatusItem(Db.Get().BuildingStatusItems.AwaitingBaitDelivery, false);
     if (!(activeBaitSetting == Tag.Invalid))
     {
         fetchChore = new FetchChore(Db.Get().ChoreTypes.Transport, baitStorage, 100f, new Tag[1]
         {
             activeBaitSetting
         }, null, null, null, true, null, null, null, FetchOrder2.OperationalRequirement.None, 0);
         GetComponent <KSelectable>().AddStatusItem(Db.Get().BuildingStatusItems.AwaitingBaitDelivery, null);
     }
 }
 public void Complete(List <Pickupable> deliverables)
 {
     using (new KProfiler.Region("FAC.Delivery.Complete", null))
     {
         if (!((UnityEngine.Object)destination == (UnityEngine.Object)null) && !destination.IsEndOfLife())
         {
             FetchChore chore = this.chore;
             chore.onCleanup = (Action <Chore>)Delegate.Remove(chore.onCleanup, onFetchChoreCleanup);
             float      num        = amount;
             Pickupable pickupable = null;
             for (int i = 0; i < deliverables.Count; i++)
             {
                 if (num <= 0f)
                 {
                     break;
                 }
                 if ((UnityEngine.Object)deliverables[i] == (UnityEngine.Object)null)
                 {
                     if (num < PICKUPABLETUNING.MINIMUM_PICKABLE_AMOUNT)
                     {
                         destination.ForceStore(this.chore.tags[0], num);
                     }
                 }
                 else
                 {
                     Pickupable pickupable2 = deliverables[i].Take(num);
                     if ((UnityEngine.Object)pickupable2 != (UnityEngine.Object)null && pickupable2.TotalAmount > 0f)
                     {
                         num -= pickupable2.TotalAmount;
                         destination.Store(pickupable2.gameObject, false, false, true, false);
                         pickupable = pickupable2;
                         if ((UnityEngine.Object)pickupable2 == (UnityEngine.Object)deliverables[i])
                         {
                             deliverables[i] = null;
                         }
                     }
                 }
             }
             if ((UnityEngine.Object) this.chore.overrideTarget != (UnityEngine.Object)null)
             {
                 this.chore.FetchAreaEnd(this.chore.overrideTarget.GetComponent <ChoreDriver>(), pickupable, true);
             }
             this.chore = null;
         }
     }
 }
예제 #28
0
 protected void CreateFetchChore(Tag entityTag)
 {
     if (fetchChore == null && entityTag.IsValid && entityTag != GameTags.Empty)
     {
         fetchChore = new FetchChore(Db.Get().ChoreTypes.FarmFetch, storage, 1f, new Tag[1]
         {
             entityTag
         }, null, null, null, true, OnFetchComplete, delegate
         {
             UpdateStatusItem();
         }, delegate
         {
             UpdateStatusItem();
         }, FetchOrder2.OperationalRequirement.Functional, 0);
         MaterialNeeds.Instance.UpdateNeed(requestedEntityTag, 1f);
         UpdateStatusItem();
     }
 }
예제 #29
0
    private void OnDepositObject(Pickupable pickupable)
    {
        SetPreview(Tag.Invalid, false);
        MaterialNeeds.Instance.UpdateNeed(requestedEntityTag, -1f);
        KBatchedAnimController component = pickupable.GetComponent <KBatchedAnimController>();

        if ((Object)component != (Object)null)
        {
            component.GetBatchInstanceData().ClearOverrideTransformMatrix();
        }
        occupyingObject = SpawnOccupyingObject(pickupable.gameObject);
        if ((Object)occupyingObject != (Object)null)
        {
            occupyingObject.SetActive(true);
            PositionOccupyingObject();
            SubscribeToOccupant();
        }
        else
        {
            Debug.LogWarning(base.gameObject.name + " EntityReceptacle did not spawn occupying entity.");
        }
        if (fetchChore != null)
        {
            fetchChore.Cancel("receptacle filled");
            fetchChore = null;
        }
        if (!autoReplaceEntity)
        {
            requestedEntityTag = Tag.Invalid;
        }
        UpdateActive();
        UpdateStatusItem();
        if (destroyEntityOnDeposit)
        {
            Util.KDestroyGameObject(pickupable.gameObject);
        }
        Trigger(-731304873, occupyingObject);
    }
    public void QueuePlacement(int target)
    {
        targetCell = target;
        Vector3 position = Grid.CellToPosCBC(targetCell, Grid.SceneLayer.Front);

        if ((UnityEngine.Object)preview == (UnityEngine.Object)null)
        {
            preview = GameUtil.KInstantiate(Assets.GetPrefab(previewTag), position, Grid.SceneLayer.Front, null, 0);
            preview.SetActive(true);
        }
        else
        {
            preview.transform.SetPosition(position);
        }
        if (chore != null)
        {
            chore.Cancel("new target");
        }
        chore = new FetchChore(Db.Get().ChoreTypes.Fetch, preview.GetComponent <Storage>(), 1f, new Tag[1]
        {
            new Tag(prefabId.InstanceID.ToString())
        }, null, null, null, true, OnChoreComplete, null, null, FetchOrder2.OperationalRequirement.None, 0);
    }