Пример #1
0
    public void Render1000ms(float dt)
    {
        DictionaryPool <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary = DictionaryPool <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList, FetchListStatusItemUpdater> .Allocate();

        foreach (FetchList2 fetchList in fetchLists)
        {
            if (!((Object)fetchList.Destination == (Object)null))
            {
                ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList value = null;
                int instanceID = fetchList.Destination.GetInstanceID();
                if (!pooledDictionary.TryGetValue(instanceID, out value))
                {
                    value = (pooledDictionary[instanceID] = ListPool <FetchList2, FetchListStatusItemUpdater> .Allocate());
                }
                value.Add(fetchList);
            }
        }
        DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary2 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

        DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary3 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

        foreach (KeyValuePair <int, ListPool <FetchList2, FetchListStatusItemUpdater> .PooledList> item in pooledDictionary)
        {
            ListPool <Tag, FetchListStatusItemUpdater> .PooledList pooledList2 = ListPool <Tag, FetchListStatusItemUpdater> .Allocate();

            Storage destination = item.Value[0].Destination;
            foreach (FetchList2 item2 in item.Value)
            {
                item2.UpdateRemaining();
                Dictionary <Tag, float> remaining = item2.GetRemaining();
                foreach (KeyValuePair <Tag, float> item3 in remaining)
                {
                    if (!pooledList2.Contains(item3.Key))
                    {
                        pooledList2.Add(item3.Key);
                    }
                }
            }
            ListPool <Pickupable, FetchListStatusItemUpdater> .PooledList pooledList3 = ListPool <Pickupable, FetchListStatusItemUpdater> .Allocate();

            foreach (GameObject item4 in destination.items)
            {
                if (!((Object)item4 == (Object)null))
                {
                    Pickupable component = item4.GetComponent <Pickupable>();
                    if (!((Object)component == (Object)null))
                    {
                        pooledList3.Add(component);
                    }
                }
            }
            DictionaryPool <Tag, float, FetchListStatusItemUpdater> .PooledDictionary pooledDictionary4 = DictionaryPool <Tag, float, FetchListStatusItemUpdater> .Allocate();

            foreach (Tag item5 in pooledList2)
            {
                float num = 0f;
                foreach (Pickupable item6 in pooledList3)
                {
                    if (item6.KPrefabID.HasTag(item5))
                    {
                        num += item6.TotalAmount;
                    }
                }
                pooledDictionary4[item5] = num;
            }
            foreach (Tag item7 in pooledList2)
            {
                if (!pooledDictionary2.ContainsKey(item7))
                {
                    pooledDictionary2[item7] = WorldInventory.Instance.GetTotalAmount(item7);
                }
                if (!pooledDictionary3.ContainsKey(item7))
                {
                    pooledDictionary3[item7] = WorldInventory.Instance.GetAmount(item7);
                }
            }
            foreach (FetchList2 item8 in item.Value)
            {
                bool should_add  = false;
                bool should_add2 = true;
                bool should_add3 = false;
                Dictionary <Tag, float> remaining2 = item8.GetRemaining();
                foreach (KeyValuePair <Tag, float> item9 in remaining2)
                {
                    Tag   key           = item9.Key;
                    float value2        = item9.Value;
                    float num2          = pooledDictionary4[key];
                    float b             = pooledDictionary2[key];
                    float num3          = pooledDictionary3[key];
                    float num4          = Mathf.Min(value2, b);
                    float num5          = num3 + num4;
                    float minimumAmount = item8.GetMinimumAmount(key);
                    if (num2 + num5 < minimumAmount)
                    {
                        should_add = true;
                    }
                    if (num5 < value2)
                    {
                        should_add2 = false;
                    }
                    if (num2 + num5 > value2 && value2 > num5)
                    {
                        should_add3 = true;
                    }
                }
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.WaitingForMaterials, ref item8.waitingForMaterialsHandle, should_add2);
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.MaterialsUnavailable, ref item8.materialsUnavailableHandle, should_add);
                item8.UpdateStatusItem(Db.Get().BuildingStatusItems.MaterialsUnavailableForRefill, ref item8.materialsUnavailableForRefillHandle, should_add3);
            }
            pooledDictionary4.Recycle();
            pooledList3.Recycle();
            pooledList2.Recycle();
            item.Value.Recycle();
        }
        pooledDictionary3.Recycle();
        pooledDictionary2.Recycle();
        pooledDictionary.Recycle();
    }
Пример #2
0
    private void UpdateOpenOrders()
    {
        ComplexRecipe[] recipes = GetRecipes();
        if (recipes.Length != openOrderCounts.Count)
        {
            Debug.LogErrorFormat(base.gameObject, "Recipe count {0} doesn't match open order count {1}", recipes.Length, openOrderCounts.Count);
        }
        bool flag = false;

        hasOpenOrders = false;
        for (int i = 0; i < recipes.Length; i++)
        {
            ComplexRecipe recipe = recipes[i];
            int           recipePrefetchCount = GetRecipePrefetchCount(recipe);
            if (recipePrefetchCount > 0)
            {
                hasOpenOrders = true;
            }
            int num = openOrderCounts[i];
            if (num != recipePrefetchCount)
            {
                if (recipePrefetchCount < num)
                {
                    flag = true;
                }
                openOrderCounts[i] = recipePrefetchCount;
            }
        }
        DictionaryPool <Tag, float, ComplexFabricator> .PooledDictionary pooledDictionary = DictionaryPool <Tag, float, ComplexFabricator> .Allocate();

        DictionaryPool <Tag, float, ComplexFabricator> .PooledDictionary pooledDictionary2 = DictionaryPool <Tag, float, ComplexFabricator> .Allocate();

        for (int j = 0; j < openOrderCounts.Count; j++)
        {
            int num2 = openOrderCounts[j];
            if (num2 > 0)
            {
                ComplexRecipe complexRecipe = recipe_list[j];
                ComplexRecipe.RecipeElement[] ingredients = complexRecipe.ingredients;
                ComplexRecipe.RecipeElement[] array       = ingredients;
                foreach (ComplexRecipe.RecipeElement recipeElement in array)
                {
                    pooledDictionary[recipeElement.material] = inStorage.GetAmountAvailable(recipeElement.material);
                }
            }
        }
        for (int l = 0; l < recipe_list.Length; l++)
        {
            int num3 = openOrderCounts[l];
            if (num3 > 0)
            {
                ComplexRecipe complexRecipe2 = recipe_list[l];
                ComplexRecipe.RecipeElement[] ingredients2 = complexRecipe2.ingredients;
                ComplexRecipe.RecipeElement[] array2       = ingredients2;
                foreach (ComplexRecipe.RecipeElement recipeElement2 in array2)
                {
                    float num4 = recipeElement2.amount * (float)num3;
                    float num5 = num4 - pooledDictionary[recipeElement2.material];
                    if (num5 > 0f)
                    {
                        pooledDictionary2.TryGetValue(recipeElement2.material, out float value);
                        pooledDictionary2[recipeElement2.material] = value + num5;
                        pooledDictionary[recipeElement2.material]  = 0f;
                    }
                    else
                    {
                        DictionaryPool <Tag, float, ComplexFabricator> .PooledDictionary pooledDictionary3;
                        Tag material;
                        (pooledDictionary3 = pooledDictionary)[material = recipeElement2.material] = pooledDictionary3[material] - num4;
                    }
                }
            }
        }
        if (flag)
        {
            CancelFetches();
        }
        if (pooledDictionary2.Count > 0)
        {
            UpdateFetches(pooledDictionary2);
        }
        UpdateMaterialNeeds(pooledDictionary2);
        pooledDictionary2.Recycle();
        pooledDictionary.Recycle();
    }