예제 #1
0
        public int Add(int itemId, int amount = 1, WeaponStatUpgrade.Types activeBonus = (WeaponStatUpgrade.Types)(-2))
        {
            ReceipeIngredient receipeIngredient = this._ingredients.FirstOrDefault((ReceipeIngredient i) => i._itemID == itemId);
            int num;

            if (this.Storage || !this._itemViewsCache.ContainsKey(itemId))
            {
                num = 2147483647;
            }
            else if (this._itemViewsCache[itemId]._allowMultiView)
            {
                num = this._itemViewsCache[itemId]._maxMultiViews;
            }
            else
            {
                num = 1;
            }
            if (receipeIngredient == null)
            {
                receipeIngredient = new ReceipeIngredient
                {
                    _itemID = itemId
                };
                this._ingredients.Add(receipeIngredient);
            }
            int result = Mathf.Max(receipeIngredient._amount + amount - num, 0);

            receipeIngredient._amount = Mathf.Min(receipeIngredient._amount + amount, num);
            this.CheckForValidRecipe();
            this.ToggleItemInventoryView(itemId, activeBonus);
            return(result);
        }
예제 #2
0
        public int Remove(int itemId, int amount = 1, WeaponStatUpgrade.Types activeBonus = (WeaponStatUpgrade.Types)(-2))
        {
            if (this._upgradeCog.enabled)
            {
                this._upgradeCog.Shutdown();
            }
            ReceipeIngredient receipeIngredient = this._ingredients.FirstOrDefault((ReceipeIngredient i) => i._itemID == itemId);

            if (receipeIngredient != null)
            {
                if (this._itemViewsCache.ContainsKey(itemId) && (this._itemViewsCache[itemId].ItemCache._maxAmount == 0 || this._itemViewsCache[itemId].ItemCache._maxAmount > LocalPlayer.Inventory.InventoryItemViewsCache[itemId].Count || !this._itemViewsCache[itemId]._allowMultiView))
                {
                    if (activeBonus == (WeaponStatUpgrade.Types)(-2) || this._itemViewsCache[itemId].ActiveBonus == activeBonus)
                    {
                        int result = Mathf.Max(amount - receipeIngredient._amount, 0);
                        if ((receipeIngredient._amount -= amount) <= 0)
                        {
                            this._ingredients.Remove(receipeIngredient);
                        }
                        this.CheckForValidRecipe();
                        this.ToggleItemInventoryView(itemId, (WeaponStatUpgrade.Types)(-2));
                        return(result);
                    }
                }
                else
                {
                    if (this._itemViewsCache.ContainsKey(itemId))
                    {
                        int num  = this._itemViewsCache[itemId].AmountOfMultiviewWithBonus(itemId, activeBonus);
                        int num2 = Mathf.Max(amount - num, 0);
                        if ((receipeIngredient._amount -= amount - num2) <= 0)
                        {
                            this._ingredients.Remove(receipeIngredient);
                        }
                        this.CheckForValidRecipe();
                        this._itemViewsCache[itemId].RemovedMultiViews(itemId, amount, activeBonus);
                        return(num2);
                    }
                    if (LocalPlayer.Inventory.InventoryItemViewsCache.ContainsKey(itemId))
                    {
                        int num3 = this._lambdaMultiView.AmountOfMultiviewWithBonus(itemId, activeBonus);
                        int num4 = Mathf.Max(amount - num3, 0);
                        if ((receipeIngredient._amount -= amount - num4) <= 0)
                        {
                            this._ingredients.Remove(receipeIngredient);
                        }
                        this.CheckForValidRecipe();
                        this._lambdaMultiView.RemovedMultiViews(itemId, amount - num4, activeBonus);
                        return(num4);
                    }
                }
            }
            return(amount);
        }
예제 #3
0
        private void Update()
        {
            bool flag  = this.CheckStorage() && this._ingredients.Count > 0;
            bool flag2 = this._validRecipe != null;

            if ((flag2 || flag) && (TheForest.Utils.Input.GetButtonDown("Combine") || TheForest.Utils.Input.GetButtonDown("Build")))
            {
                Receipe validRecipe = this._validRecipe;
                this._craftSfxEmitter.Play();
                LocalPlayer.Tuts.CloseRecipeTut();
                if (flag)
                {
                    this.DoStorage();
                }
                else if (validRecipe._type.Equals(Receipe.Types.Upgrade))
                {
                    WeaponStatUpgrade.Types types = (WeaponStatUpgrade.Types)(-1);
                    for (int i = 0; i < validRecipe._ingredients.Length; i++)
                    {
                        ReceipeIngredient recipeIngredient  = validRecipe._ingredients[i];
                        ReceipeIngredient receipeIngredient = this._ingredients.FirstOrDefault((ReceipeIngredient ig) => ig._itemID == recipeIngredient._itemID);
                        int num = recipeIngredient._amount * ((i != 0) ? this._upgradeCount : 1);
                        receipeIngredient._amount -= num;
                        if (i == 1)
                        {
                            types = ((!this._itemViewsCache[receipeIngredient._itemID]._allowMultiView) ? this._itemViewsCache[receipeIngredient._itemID].ActiveBonus : this._itemViewsCache[receipeIngredient._itemID].GetFirstViewBonus());
                        }
                        if (receipeIngredient._amount <= 0)
                        {
                            this._ingredients.Remove(receipeIngredient);
                        }
                        else if (recipeIngredient._amount == 0)
                        {
                            this._inventory.AddItem(recipeIngredient._itemID, receipeIngredient._amount, true, true, types);
                            this.Remove(recipeIngredient._itemID, receipeIngredient._amount, (WeaponStatUpgrade.Types)(-2));
                        }
                        this.ToggleItemInventoryView(recipeIngredient._itemID, (WeaponStatUpgrade.Types)(-2));
                    }
                    int upgradeCount = this._upgradeCount;
                    this.Add(validRecipe._productItemID, validRecipe._productItemAmount, (WeaponStatUpgrade.Types)(-2));
                    this.ApplyUpgrade(validRecipe, types, upgradeCount);
                }
                else
                {
                    GameStats.ItemCrafted.Invoke(validRecipe._productItemID);
                    this.IngredientCleanUp();
                    this.Add(validRecipe._productItemID, validRecipe._productItemAmount, (WeaponStatUpgrade.Types)(-2));
                }
            }
            else if (!flag2 && !flag)
            {
                base.enabled = false;
            }
        }
예제 #4
0
 public override bool Equals(object obj)
 {
     if (obj is ReceipeIngredient)
     {
         ReceipeIngredient receipeIngredient = (ReceipeIngredient)obj;
         return(this._itemID == receipeIngredient._itemID && this._amount == receipeIngredient._amount);
     }
     if (obj is int)
     {
         int num = (int)obj;
         return(this._itemID == num);
     }
     return(base.Equals(obj));
 }
예제 #5
0
        private void ToggleItemInventoryView(int itemId, WeaponStatUpgrade.Types activeBonus)
        {
            ReceipeIngredient receipeIngredient = this._ingredients.FirstOrDefault((ReceipeIngredient i) => i._itemID == itemId);
            int  num  = (receipeIngredient == null) ? 0 : receipeIngredient._amount;
            bool flag = num > 0;

            if (this._itemViewsCache.ContainsKey(itemId))
            {
                if (this._itemViewsCache[itemId]._allowMultiView)
                {
                    if (activeBonus == (WeaponStatUpgrade.Types)(-2))
                    {
                        this._itemViewsCache[itemId].SetMultiViewAmount(num, activeBonus);
                    }
                    else
                    {
                        this._itemViewsCache[itemId].SetMultiViewAmount(num - this._itemViewsCache[itemId].AmountOfMultiviewWithoutBonus(itemId, activeBonus), activeBonus);
                    }
                }
                else
                {
                    if (activeBonus != (WeaponStatUpgrade.Types)(-2))
                    {
                        this._itemViewsCache[itemId].ActiveBonus = activeBonus;
                    }
                    if (this._itemViewsCache[itemId].gameObject.activeSelf != flag)
                    {
                        this._itemViewsCache[itemId].gameObject.SetActive(flag);
                    }
                }
            }
            else if (LocalPlayer.Inventory.InventoryItemViewsCache.ContainsKey(itemId))
            {
                this._lambdaMultiView.SetAnyMultiViewAmount(LocalPlayer.Inventory.InventoryItemViewsCache[itemId][0], this._lambdaMultiView.transform, num, activeBonus);
            }
        }
예제 #6
0
 private void OnDeserialized()
 {
     base.enabled = false;
     if (this._presentIngredients != null && this._presentIngredients.Length > this._presentIngredientsCount)
     {
         ReceipeIngredient[] array = new ReceipeIngredient[this._presentIngredientsCount];
         for (int i = 0; i < this._presentIngredientsCount; i++)
         {
             array[i] = this._presentIngredients[i];
         }
         this._presentIngredients = array;
     }
     if (this.manualLoading)
     {
         this.WasLoaded = true;
     }
     else
     {
         this.Initialize();
     }
 }
예제 #7
0
 public bool HasIngredient(ReceipeIngredient searchIngredient)
 {
     return(this._ingredients != null && this._ingredients.Any((ReceipeIngredient eachIngredient) => searchIngredient._itemID == eachIngredient._itemID));
 }
예제 #8
0
        private void CheckForValidUpgrade()
        {
            Receipe receipe = null;
            string  b       = Receipe.IngredientsToRecipeHash(this._ingredients);

            foreach (Receipe current in this._receipeBook.AvailableUpgradeCache)
            {
                if (current.IngredientHash == b)
                {
                    receipe = current;
                    break;
                }
            }
            if (receipe != null)
            {
                if (!this.CanCarryProduct(receipe) && receipe._ingredients[0]._itemID != receipe._productItemID)
                {
                    this._validRecipeFull = true;
                    receipe = null;
                }
                else
                {
                    IEnumerable <ReceipeIngredient> source = from vri in receipe._ingredients
                                                             join i in this._ingredients on vri._itemID equals i._itemID
                                                             select i;
                    ReceipeIngredient[] array = source.ToArray <ReceipeIngredient>();
                    if (array.Length > 1)
                    {
                        this._upgradeCount = ItemDatabase.ItemById(receipe._productItemID)._maxUpgradesAmount;
                        int itemID = array[1]._itemID;
                        if (this._upgradeCog.SupportedItemsCache.ContainsKey(itemID) && this._upgradeCog.SupportedItemsCache[itemID]._pattern != UpgradeCog.Patterns.NoView)
                        {
                            this._upgradeCount -= LocalPlayer.Inventory.GetAmountOfUpgrades(receipe._productItemID);
                        }
                        bool flag = this._upgradeCount == 0;
                        for (int j = 1; j < receipe._ingredients.Length; j++)
                        {
                            ReceipeIngredient receipeIngredient = receipe._ingredients[j];
                            if (receipeIngredient._amount > 0)
                            {
                                int num = array[j]._amount / receipeIngredient._amount;
                                if (num < this._upgradeCount)
                                {
                                    this._upgradeCount = num;
                                }
                            }
                            else
                            {
                                this._upgradeCount = 1;
                                flag = true;
                            }
                        }
                        if (this._upgradeCount <= 0 && !flag)
                        {
                            receipe = null;
                        }
                    }
                    else
                    {
                        receipe = null;
                    }
                }
            }
            bool flag2 = receipe != null;

            if (flag2)
            {
                this._validRecipe     = receipe;
                this._validRecipeFill = 1f;
                Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(false);
                Scene.HudGui.ShowValidCraftingRecipes(null);
                Scene.HudGui.ShowUpgradesDistribution(this._validRecipe._productItemID, this._validRecipe._ingredients[1]._itemID, this._upgradeCount);
            }
            else
            {
                Scene.HudGui.HideUpgradesDistribution();
                this._upgradeCount = 0;
            }
            if (base.gameObject.GetComponent <Renderer>().enabled != this._upgradeCount > 0)
            {
                if (!base.gameObject.GetComponent <Renderer>().enabled)
                {
                    this._craftSfx2Emitter.Play();
                }
                base.gameObject.GetComponent <Renderer>().enabled = (this._upgradeCount > 0);
            }
        }
예제 #9
0
        public void CheckForValidRecipe()
        {
            if (this.CheckStorage())
            {
                return;
            }
            IOrderedEnumerable <Receipe> orderedEnumerable  = null;
            IOrderedEnumerable <Receipe> orderedEnumerable2 = null;

            if (this._ingredients.Count > 0)
            {
                orderedEnumerable = from ar in this._receipeBook.AvailableReceipesCache
                                    where this._ingredients.All((ReceipeIngredient i) => ar._ingredients.Any((ReceipeIngredient i2) => i._itemID == i2._itemID))
                                    where this.CanCarryProduct(ar)
                                    orderby ar._ingredients.Length
                                    select ar;
                orderedEnumerable2 = from ar in this._receipeBook.AvailableUpgradeCache
                                     where this._ingredients.All((ReceipeIngredient i) => ar._ingredients.Any((ReceipeIngredient i2) => i._itemID == i2._itemID))
                                     where this.CanCarryProduct(ar)
                                     orderby ar._ingredients.Length
                                     select ar;
                this._validRecipe = orderedEnumerable.FirstOrDefault <Receipe>();
            }
            else
            {
                this._validRecipe = null;
            }
            bool flag = this._validRecipe != null;

            if (flag)
            {
                if (!this.CanCarryProduct(this._validRecipe))
                {
                    Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(false);
                    this._validRecipeFull = true;
                    flag = false;
                }
                else
                {
                    int num  = 0;
                    int num2 = this._validRecipe._ingredients.Sum((ReceipeIngredient i) => i._amount);
                    foreach (ReceipeIngredient cogIngredients in this._ingredients)
                    {
                        ReceipeIngredient receipeIngredient = this._validRecipe._ingredients.First((ReceipeIngredient i) => i._itemID == cogIngredients._itemID);
                        if (cogIngredients._amount > receipeIngredient._amount)
                        {
                            this._validRecipe = null;
                            flag = false;
                            break;
                        }
                        num += cogIngredients._amount;
                    }
                    this._validRecipeFull = false;
                    this._validRecipeFill = (float)num / (float)num2;
                    HudGui arg_25D_0 = Scene.HudGui;
                    IOrderedEnumerable <Receipe> arg_25D_1;
                    if (flag)
                    {
                        IOrderedEnumerable <Receipe> orderedEnumerable3 = from r in orderedEnumerable.Concat(orderedEnumerable2)
                                                                          orderby r._type, r._ingredients.Length
                        select r;
                        arg_25D_1 = orderedEnumerable3;
                    }
                    else
                    {
                        arg_25D_1 = null;
                    }
                    arg_25D_0.ShowValidCraftingRecipes(arg_25D_1);
                    Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(false);
                    if (num != num2 && flag)
                    {
                        Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(true);
                        Scene.HudGui.CraftingReceipeProgress.fillAmount = this._validRecipeFill;
                        flag = false;
                        this._validRecipe = null;
                    }
                }
            }
            else
            {
                Scene.HudGui.ShowValidCraftingRecipes(orderedEnumerable2);
                Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(false);
            }
            if (flag)
            {
                Scene.HudGui.HideUpgradesDistribution();
                this._craftSfx2Emitter.Play();
                base.gameObject.GetComponent <Renderer>().enabled = true;
            }
            if (!flag || !this.CanCraft)
            {
                this.CheckForValidUpgrade();
            }
        }