private void RebalanceFetches()
    {
        TreeFilterable component = GetComponent <TreeFilterable>();

        Tag[]     tags          = component.GetTags();
        ChoreType creatureFetch = Db.Get().ChoreTypes.CreatureFetch;
        Storage   component2    = GetComponent <Storage>();
        int       num           = creatureLimit - storedCreatureCount;
        int       count         = fetches.Count;
        int       num2          = 0;
        int       num3          = 0;
        int       num4          = 0;
        int       num5          = 0;

        for (int num6 = fetches.Count - 1; num6 >= 0; num6--)
        {
            if (fetches[num6].IsComplete())
            {
                fetches.RemoveAt(num6);
                num2++;
            }
        }
        int num7 = 0;

        for (int i = 0; i < fetches.Count; i++)
        {
            if (!fetches[i].InProgress)
            {
                num7++;
            }
        }
        if (num7 == 0 && fetches.Count < num)
        {
            FetchOrder2 fetchOrder = new FetchOrder2(creatureFetch, tags, requiredFetchTags, null, component2, 1f, FetchOrder2.OperationalRequirement.Operational, 0);
            fetchOrder.Submit(OnFetchComplete, false, OnFetchBegun);
            fetches.Add(fetchOrder);
            num3++;
        }
        int num8 = fetches.Count - num;
        int num9 = fetches.Count - 1;

        while (num9 >= 0 && num8 > 0)
        {
            if (!fetches[num9].InProgress)
            {
                fetches[num9].Cancel("fewer creatures in room");
                fetches.RemoveAt(num9);
                num8--;
                num4++;
            }
            num9--;
        }
        while (num8 > 0 && fetches.Count > 0)
        {
            fetches[fetches.Count - 1].Cancel("fewer creatures in room");
            fetches.RemoveAt(fetches.Count - 1);
            num8--;
            num5++;
        }
    }
Exemplo n.º 2
0
                private static void ApplyColorToBuilding(BuildingComplete building)
                {
                    if (building.name.ToString().StartsWith("BigLiquidStorage") || building.name.ToString().StartsWith("BigGasReservoir"))
                    {
                        KAnimControllerBase kanim = building.GetComponent <KAnimControllerBase>();
                        if (kanim != null)
                        {
                            kanim.TintColour = defaultColor;
                            CaiLib.Logger.Logger.Log(string.Concat("Updating Object Color:", building.name.ToString()));
                        }
                    }

                    if (building.name.ToString().StartsWith("BigSolidStorage") || building.name.ToString().StartsWith("BigBeautifulStorage"))
                    {
                        TreeFilterable treeFilterable = building.GetComponent <TreeFilterable>();
                        if (treeFilterable != null)
                        {
                            Traverse traverse = Traverse.Create(treeFilterable);
                            if (building.name.ToString().StartsWith("BigSolidStorage"))
                            {
                                traverse.Field("filterTint").SetValue(defaultColor);
                            }
                            if (building.name.ToString().StartsWith("BigBeautifulStorage"))
                            {
                                traverse.Field("filterTint").SetValue(beautifulColor);
                            }
                            Tag[] array = traverse.Field <List <Tag> >("acceptedTags").Value.ToArray();
                            treeFilterable.OnFilterChanged(array);
                        }
                    }
                }
 /// <summary>
 /// Applied after OnDiscover runs.
 /// </summary>
 internal static void Postfix(ref TreeFilterable __instance, ref Storage ___storage,
                              Tag category_tag, Tag tag)
 {
     if (___storage.storageFilters.Contains(category_tag))
     {
         __instance.RemoveTagFromFilter(tag);
     }
 }
    protected override void OnCleanUp()
    {
        base.smi.StopSM("OnCleanUp");
        TreeFilterable component = GetComponent <TreeFilterable>();

        component.OnFilterChanged = (Action <Tag[]>)Delegate.Remove(component.OnFilterChanged, new Action <Tag[]>(OnFilterChanged));
        base.OnCleanUp();
    }
        public StatesInstance(BottleEmptier smi)
            : base(smi)
        {
            TreeFilterable component = base.master.GetComponent <TreeFilterable>();

            component.OnFilterChanged = (Action <Tag[]>)Delegate.Combine(component.OnFilterChanged, new Action <Tag[]>(OnFilterChanged));
            meter = new MeterController(GetComponent <KBatchedAnimController>(), "meter_target", "meter", Meter.Offset.Infront, Grid.SceneLayer.NoLayer, "meter_target", "meter_arrow", "meter_scale");
            Subscribe(-1697596308, OnStorageChange);
        }
Exemplo n.º 6
0
 static void Postfix(TreeFilterable __instance)
 {
     // TreeFilterableSideScreen.IsValidForTarget manually blacklists FlatTagFilterables
     // Without this, rocket oxidizer tanks get set to sweep only despite not having the UI
     // Must use reflection since FlatTagFilterable doesn't exist in vanilla currently
     if (Options.Opts.SweepOnly && __instance.GetComponent(nameof(FlatTagFilterable)) == null && __instance.storage.allowSettingOnlyFetchMarkedItems)
     {
         __instance.storage.SetOnlyFetchMarkedItems(true);
     }
 }
Exemplo n.º 7
0
            /// <summary>
            /// Applied after OnDiscover runs.
            /// </summary>
            internal static void Postfix(TreeFilterable __instance, Storage ___storage,
                                         Tag category_tag, Tag tag)
            {
                // Check the value of the storage-specific accepts/rejects new materials
                bool accept = ___storage.gameObject.GetComponentSafe <NewMaterialsSettings>()?.
                              AcceptsNewMaterials ?? false;

                if (!accept && ___storage.storageFilters.Contains(category_tag))
                {
                    __instance.RemoveTagFromFilter(tag);
                }
            }
 public void CleanUp()
 {
     if ((UnityEngine.Object)filterable != (UnityEngine.Object)null)
     {
         TreeFilterable treeFilterable = filterable;
         treeFilterable.OnFilterChanged = (Action <Tag[]>)Delegate.Remove(treeFilterable.OnFilterChanged, new Action <Tag[]>(OnFilterChanged));
     }
     if (fetchList != null)
     {
         fetchList.Cancel("Parent destroyed");
     }
 }
            /// <summary>
            /// Applied after OnDiscover runs.
            /// </summary>
            internal static void Postfix(TreeFilterable __instance, Storage ___storage,
                                         Tag category_tag, Tag tag, List <Tag> ___acceptedTags)
            {
                // Check the value of the storage-specific accepts/rejects new materials
                bool accept = ___storage.gameObject.GetComponentSafe <NewMaterialsSettings>()?.
                              AcceptsNewMaterials ?? false;

                if (!accept && ___storage.storageFilters.Contains(category_tag))
                {
                    // There should not be anything in the storage matching types that were
                    // just found, but there were racy crashes on load of legacy saves
                    // Update filter without dropping any items
                    ___acceptedTags.Remove(tag);
                    __instance.OnFilterChanged?.Invoke(___acceptedTags.ToArray());
                }
            }
            /// <summary>
            /// Applied after OnDiscover runs.
            /// </summary>
            internal static void Postfix(TreeFilterable __instance, Storage ___storage,
                                         Tag category_tag, Tag tag)
            {
                GameObject obj;

                if ((obj = __instance.gameObject) != null)
                {
                    // Ignore fridges and ration boxes if the check box is set
                    bool isFood = obj.GetComponent <Refrigerator>() != null || obj.
                                  GetComponent <RationBox>() != null;
                    if (obj != null && (!options.IgnoreFoodBoxes || !isFood) && ___storage.
                        storageFilters.Contains(category_tag))
                    {
                        __instance.RemoveTagFromFilter(tag);
                    }
                }
            }
        private static bool CanCapturableBeCapturedAtCapturePoint(FixedCapturableMonitor.Instance capturable, Instance capture_point, CavityInfo capture_cavity_info, int capture_cell)
        {
            if (!capturable.IsRunning())
            {
                return(false);
            }
            if (capturable.HasTag(GameTags.Creatures.Bagged))
            {
                return(false);
            }
            if (capturable.targetCapturePoint != capture_point && !capturable.targetCapturePoint.IsNullOrStopped())
            {
                return(false);
            }
            if (capture_point.def.isCreatureEligibleToBeCapturedCb != null && !capture_point.def.isCreatureEligibleToBeCapturedCb(capturable.gameObject, capture_point))
            {
                return(false);
            }
            if (!capturable.GetComponent <ChoreConsumer>().IsChoreEqualOrAboveCurrentChorePriority <FixedCaptureStates>())
            {
                return(false);
            }
            int        cell          = Grid.PosToCell(capturable.transform.GetPosition());
            CavityInfo cavityForCell = Game.Instance.roomProber.GetCavityForCell(cell);

            if (cavityForCell == null || cavityForCell != capture_cavity_info)
            {
                return(false);
            }
            int navigationCost = capturable.GetComponent <Navigator>().GetNavigationCost(capture_cell);

            if (navigationCost == -1)
            {
                return(false);
            }
            TreeFilterable          component  = capture_point.GetComponent <TreeFilterable>();
            IUserControlledCapacity component2 = capture_point.GetComponent <IUserControlledCapacity>();

            if (component.ContainsTag(capturable.GetComponent <KPrefabID>().PrefabTag) && component2.AmountStored <= component2.UserMaxCapacity)
            {
                return(false);
            }
            return(true);
        }
    public FilteredStorage(KMonoBehaviour root, Tag[] required_tags, Tag[] forbidden_tags, IUserControlledCapacity capacity_control, bool use_logic_meter, ChoreType fetch_chore_type)
    {
        this.root       = root;
        requiredTags    = required_tags;
        forbiddenTags   = forbidden_tags;
        capacityControl = capacity_control;
        useLogicMeter   = use_logic_meter;
        choreType       = fetch_chore_type;
        root.Subscribe(-1697596308, OnStorageChanged);
        root.Subscribe(-543130682, OnUserSettingsChanged);
        filterable = root.FindOrAdd <TreeFilterable>();
        TreeFilterable treeFilterable = filterable;

        treeFilterable.OnFilterChanged = (Action <Tag[]>)Delegate.Combine(treeFilterable.OnFilterChanged, new Action <Tag[]>(OnFilterChanged));
        storage = root.GetComponent <Storage>();
        storage.Subscribe(644822890, OnOnlyFetchMarkedItemsSettingChanged);
        if (capacityStatusItem == null)
        {
            capacityStatusItem = new StatusItem("StorageLocker", "BUILDING", string.Empty, StatusItem.IconType.Info, NotificationType.Neutral, false, OverlayModes.None.ID, true, 129022);
            capacityStatusItem.resolveStringCallback = delegate(string str, object data)
            {
                FilteredStorage filteredStorage = (FilteredStorage)data;
                float           amountStored    = filteredStorage.GetAmountStored();
                float           num             = filteredStorage.storage.capacityKg;
                amountStored = ((!(amountStored > num - filteredStorage.storage.storageFullMargin) || !(amountStored < num)) ? Mathf.Floor(amountStored) : num);
                string newValue = Util.FormatWholeNumber(amountStored);
                IUserControlledCapacity component = filteredStorage.root.GetComponent <IUserControlledCapacity>();
                if (component != null)
                {
                    num = Mathf.Min(component.UserMaxCapacity, num);
                }
                string newValue2 = Util.FormatWholeNumber(num);
                str = str.Replace("{Stored}", newValue);
                str = str.Replace("{Capacity}", newValue2);
                str = ((component == null) ? str.Replace("{Units}", GameUtil.GetCurrentMassUnit(false)) : str.Replace("{Units}", component.CapacityUnits));
                return(str);
            };
            noFilterStatusItem = new StatusItem("NoStorageFilterSet", "BUILDING", "status_item_no_filter_set", StatusItem.IconType.Custom, NotificationType.BadMinor, false, OverlayModes.None.ID, true, 129022);
        }
        root.GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, capacityStatusItem, this);
    }
Exemplo n.º 13
0
        private static bool TryApplyTintViaTreeFilterable(TreeFilterable treeFilterable, Color32 targetColor)
        {
            try
            {
                var traversedTreeFilterable = Traverse.Create(treeFilterable);

                traversedTreeFilterable.Field("filterTint").SetValue(targetColor);

                var tags = traversedTreeFilterable.Field <List <Tag> >("acceptedTags").Value.ToArray();

                treeFilterable.OnFilterChanged(tags);

                return(true);
            }
            catch (Exception e)
            {
                State.Common.Logger.LogOnce("Failed to apply tint using TreeFiltertable traverse", e);
            }

            return(false);
        }
    protected override void OnPrefabInit()
    {
        base.OnPrefabInit();
        fetches = new List <FetchOrder2>();
        TreeFilterable component = GetComponent <TreeFilterable>();

        component.OnFilterChanged = (Action <Tag[]>)Delegate.Combine(component.OnFilterChanged, new Action <Tag[]>(OnFilterChanged));
        GetComponent <Storage>().SetOffsets(deliveryOffsets);
        Prioritizable.AddRef(base.gameObject);
        if (capacityStatusItem == null)
        {
            capacityStatusItem = new StatusItem("StorageLocker", "BUILDING", string.Empty, StatusItem.IconType.Info, NotificationType.Neutral, false, OverlayModes.None.ID, true, 129022);
            capacityStatusItem.resolveStringCallback = delegate(string str, object data)
            {
                IUserControlledCapacity userControlledCapacity = (IUserControlledCapacity)data;
                string newValue        = Util.FormatWholeNumber(Mathf.Floor(userControlledCapacity.AmountStored));
                float  userMaxCapacity = userControlledCapacity.UserMaxCapacity;
                string newValue2       = Util.FormatWholeNumber(userMaxCapacity);
                str = str.Replace("{Stored}", newValue).Replace("{Capacity}", newValue2).Replace("{Units}", userControlledCapacity.CapacityUnits);
                return(str);
            };
        }
        GetComponent <KSelectable>().SetStatusItem(Db.Get().StatusItemCategories.Main, capacityStatusItem, this);
    }
Exemplo n.º 15
0
 /// <summary>
 /// Applied after OnPrefabInit runs.
 /// </summary>
 internal static void Postfix(TreeFilterable __instance)
 {
     __instance.gameObject.AddOrGet <NewMaterialsSettings>();
 }