public void Awake() { if (!this._initialized) { this._initialized = true; this._validRecipeFill = 0f; this._validRecipe = null; this._normalMaterial = base.gameObject.GetComponent <Renderer>().sharedMaterial; this._upgradeCog = base.GetComponent <UpgradeCog>(); this._ingredients = new HashSet <ReceipeIngredient>(); this._itemViewsCache = this._itemViews.ToDictionary((InventoryItemView iv) => iv._itemId, (InventoryItemView iv) => iv); if (this._inventory && Scene.HudGui) { this._clickToCombineButton = Scene.HudGui.ClickToCombineInfo; } if (this._craftSfx) { this._craftSfxEmitter = this._craftSfx.GetComponent <FMOD_StudioEventEmitter>(); } if (this._craftSfx2) { this._craftSfx2Emitter = this._craftSfx2.GetComponent <FMOD_StudioEventEmitter>(); } for (int i = 0; i < this._itemViews.Length; i++) { this._itemViews[i].Init(); } } }
public void ApplyUpgradeRecipe(InventoryItemView craftView, Receipe receipe, int amount) { this._currentIngredientIndex = 0; this._recipe = receipe; this._craftView = craftView; this._currentReceiver = null; this._receivers = this._craftView.GetAllComponentsInChildren <UpgradeViewReceiver>(); Transform parent = craftView.transform.parent; Transform child = craftView.transform.GetChild(0); this._downPosition = this._craftView.transform.position; this._downRotation = this._craftView.transform.rotation; child.parent = this._upPosition; craftView.transform.parent = child; child.localPosition = Vector3.zero; child.localRotation = Quaternion.identity; this._upRotation = this._craftView.transform.rotation; this._upPositionV = craftView.transform.position; craftView.transform.parent = parent; child.parent = craftView.transform; child.SetAsFirstSibling(); craftView.transform.position = this._downPosition; craftView.transform.rotation = this._downRotation; this._state = UpgradeCog.States.MoveUp; this._stateStartTime = Time.realtimeSinceStartup; this._totalUpgrades = amount; this._implantsDone = 0; this._totalIngredientImplants = 0; this._craftingCog.enabled = false; this._disableWhenActive.SetActive(false); base.enabled = true; Scene.HudGui.ShowValidCraftingRecipes(null); Scene.HudGui.ShowUpgradesDistribution(this._recipe._productItemID, this._recipe._ingredients[1]._itemID, 1); }
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; } }
private void ApplyUpgrade(Receipe craftedRecipe, WeaponStatUpgrade.Types lastIngredientActiveBonus, int upgradeCount) { bool flag = this._itemViewsCache[craftedRecipe._productItemID]._held && !this._itemViewsCache[craftedRecipe._productItemID]._held.activeInHierarchy; if (flag) { this._itemViewsCache[craftedRecipe._productItemID]._held.SetActive(true); } if (!this.ApplyWeaponStatsUpgrades(craftedRecipe._productItemID, craftedRecipe._ingredients[1]._itemID, craftedRecipe._weaponStatUpgrades, craftedRecipe._batchUpgrade, upgradeCount, lastIngredientActiveBonus)) { this._upgradeCog.ApplyUpgradeRecipe(this._itemViewsCache[craftedRecipe._productItemID], craftedRecipe, upgradeCount); } if (flag) { this._itemViewsCache[craftedRecipe._productItemID]._held.SetActive(false); } }
private bool CheckStorage() { if (this.Storage) { this._validRecipe = null; Scene.HudGui.CraftingReceipeBacking.gameObject.SetActive(false); Scene.HudGui.ShowValidCraftingRecipes(null); Scene.HudGui.HideUpgradesDistribution(); base.gameObject.GetComponent <Renderer>().enabled = (this._ingredients.Count > 1); return(true); } if (this._validRecipe == null) { base.gameObject.GetComponent <Renderer>().enabled = false; } return(false); }
public void ApplyUpgradeRecipe(InventoryItemView craftView, Receipe receipe, int amount) { this._currentIngredientIndex = 0; this._recipe = receipe; this._craftView = craftView; this._currentReceiver = null; this._upPositionV = craftView.transform.position + this._upPosition.parent.TransformDirection(new Vector3(0.5f, -1.05f, 0f)); this._upRotation = craftView.transform.rotation * Quaternion.Euler(30f, 0f, 0f); this._receivers = this._craftView.GetAllComponentsInChildren <UpgradeViewReceiver>(); this._downPosition = this._craftView.transform.position; this._downRotation = this._craftView.transform.rotation; this._state = UpgradeCog.States.MoveUp; this._totalUpgrades = amount; this._implantsDone = 0; this._totalIngredientImplants = 0; this._craftingCog.enabled = false; base.enabled = true; Scene.HudGui.ShowValidCraftingRecipes(null); Scene.HudGui.ShowUpgradesDistribution(this._recipe._productItemID, this._recipe._ingredients[1]._itemID, 1); }
public bool RemoveReceipe(Receipe receipe) { return(this.RemoveReceipe(receipe._id)); }
public bool AddReceipe(Receipe receipe) { return(this.AddReceipe(receipe._id)); }
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); } }
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(); } }
private bool CanCarryProduct(Receipe recipe) { int maxAmountOf = LocalPlayer.Inventory.GetMaxAmountOf(recipe._productItemID); return(this._inventory.AmountOf(recipe._productItemID, true) < maxAmountOf); }