public void Shutdown() { if (this.SupportedItemsCache[this._currentIngredientItemId]._amount > 0) { float num = (float)((this._totalIngredientImplants - this._implantsDone) / this.SupportedItemsCache[this._currentIngredientItemId]._amount); for (int i = 1; i < this._recipe._ingredients.Length; i++) { this._craftingCog.Add(this._recipe._ingredients[i]._itemID, Mathf.FloorToInt((float)this._recipe._ingredients[i]._amount * num), (WeaponStatUpgrade.Types)(-2)); } } this._currentReceiver = null; this._craftView.transform.position = Vector3.Slerp(this._upPositionV, this._downPosition, 1f); this._craftView.transform.rotation = Quaternion.Slerp(this._upRotation, this._downRotation, 1f); this._state = UpgradeCog.States.Idle; base.enabled = false; this._craftingCog.CheckForValidRecipe(); Scene.HudGui.UpgradePlacementGizmo.gameObject.SetActive(false); Scene.HudGui.ManualUpgradingInfo.SetActive(false); Scene.HudGui.HideUpgradesDistribution(); }
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); }
private void NextIngredient() { if (this._currentReceiver != null) { if (this._disableMainColliderAfter) { this._currentReceiver._mainCollider.enabled = false; this._disableMainColliderAfter = false; } if (this._disableFilterColliderAfter) { this._currentReceiver._filterCollider.enabled = false; this._disableFilterColliderAfter = false; } this._currentReceiver = null; } if (++this._currentIngredientIndex < this._recipe._ingredients.Length) { if (this._supportedItemsCache.ContainsKey(this._recipe._ingredients[this._currentIngredientIndex]._itemID)) { this._currentIngredientItemId = this._recipe._ingredients[this._currentIngredientIndex]._itemID; UpgradeViewReceiver[] receivers = this._receivers; for (int i = 0; i < receivers.Length; i++) { UpgradeViewReceiver upgradeViewReceiver = receivers[i]; foreach (int current in upgradeViewReceiver._acceptedItemIds) { if (current == this._currentIngredientItemId) { this._currentReceiver = upgradeViewReceiver; break; } } if (this._currentReceiver != null) { break; } } if (this._currentReceiver != null) { this._implantsDone = 0; this._totalIngredientImplants = this._totalUpgrades * this._recipe._ingredients[this._currentIngredientIndex]._amount * this.SupportedItemsCache[this._currentIngredientItemId]._amount; int amountOfUpgrades = this._craftingCog._inventory.GetAmountOfUpgrades(this._recipe._productItemID, this._currentIngredientItemId); if (this._totalIngredientImplants + amountOfUpgrades >= this.SupportedItemsCache[this._currentIngredientItemId]._maxViewsPerItem) { this._totalIngredientImplants = this.SupportedItemsCache[this._currentIngredientItemId]._maxViewsPerItem - amountOfUpgrades; } this._stateStartTime = Time.realtimeSinceStartup; if (!this._currentReceiver._mainCollider.enabled) { this._currentReceiver._mainCollider.enabled = true; this._disableMainColliderAfter = true; } if (!this._currentReceiver._filterCollider.enabled) { this._currentReceiver._filterCollider.enabled = true; this._disableFilterColliderAfter = true; } if (this._currentReceiver._filterCollider is CapsuleCollider) { CapsuleCollider capsuleCollider = (CapsuleCollider)this._currentReceiver._filterCollider; this._circlePatternCapsuleFilterPivot = this.GetCapsuleAxis(this._currentReceiver, capsuleCollider) * ((float)UnityEngine.Random.Range(-1, 1) * (capsuleCollider.height / 2f)) + capsuleCollider.center; } this._circlePatternRotation = UnityEngine.Random.rotation; } else { Debug.Log(string.Concat(new string[] { "No upgrade receiver for '", ItemDatabase.ItemById(this._recipe._ingredients[this._currentIngredientIndex]._itemID)._name, "' found on '", this._craftView.name, "' (for '", this._recipe._name, "')" })); } } else { Debug.Log(string.Concat(new string[] { "Unsupported item used in upgrade receipe : '", this._recipe._name, "', UpgradeCog is missing view for '", ItemDatabase.ItemById(this._recipe._ingredients[this._currentIngredientIndex]._itemID)._name, "'" })); } } else { this._stateStartTime = Time.realtimeSinceStartup; this._state = UpgradeCog.States.MoveDown; } }
private void Update() { float num = (!this._fastForward) ? (Time.realtimeSinceStartup - this._stateStartTime) : 3.40282347E+38f; switch (this._state) { case UpgradeCog.States.Idle: Scene.HudGui.UpgradePlacementGizmo.gameObject.SetActive(false); Scene.HudGui.ManualUpgradingInfo.SetActive(false); this._craftingCog.enabled = true; base.enabled = false; break; case UpgradeCog.States.MoveUp: num = MathEx.Easing.EaseInOutQuad(num, 0f, 1f, this._moveUpDuration); this._craftView.transform.position = Vector3.Slerp(this._downPosition, this._upPositionV, num); this._craftView.transform.rotation = Quaternion.Slerp(this._downRotation, this._upRotation, num); if (Mathf.Approximately(num, 1f)) { this._stateStartTime = Time.realtimeSinceStartup; this._state = UpgradeCog.States.Aiming; Scene.HudGui.ManualUpgradingInfo.SetActive(true); } break; case UpgradeCog.States.Aiming: if (!this._currentReceiver) { this.NextIngredient(); } else if (this._implantsDone < this._totalIngredientImplants) { float num2 = TheForest.Utils.Input.GetAxis("Vertical") * (float)((!PlayerPreferences.MouseInvert) ? 1 : -1); float num3 = -TheForest.Utils.Input.GetAxis("Horizontal") * (float)((!PlayerPreferences.MouseInvert) ? 1 : -1); if (Mathf.Abs(num2) > 0.05f || Mathf.Abs(num3) > 0.05f) { if (Mathf.Abs(num2) > 0.05f) { this._craftView.transform.RotateAround(this._currentReceiver._centerAndRotationAxisUpDirection.position, LocalPlayer.InventoryCam.transform.right, Time.unscaledDeltaTime * 150f * num2); } if (Mathf.Abs(num3) > 0.05f) { this._craftView.transform.RotateAround(this._currentReceiver._centerAndRotationAxisUpDirection.position, LocalPlayer.InventoryCam.transform.up, Time.unscaledDeltaTime * 150f * num3); } this.ThrowUpgradePart(true); } if (this.ThrowUpgradePart(true) && TheForest.Utils.Input.GetButtonDown("Fire1")) { Scene.HudGui.UpgradePlacementGizmo.gameObject.SetActive(false); this._state = UpgradeCog.States.Applying; } if (TheForest.Utils.Input.GetButtonDown("AltFire")) { Scene.HudGui.UpgradePlacementGizmo.gameObject.SetActive(false); Scene.HudGui.ManualUpgradingInfo.SetActive(false); this._stateStartTime = Time.realtimeSinceStartup; this._state = UpgradeCog.States.MoveDown; } } else if (!this.TryPayMoreIngredients()) { this.NextIngredient(); } break; case UpgradeCog.States.Applying: if (this._implantsDone < this._totalIngredientImplants) { LocalPlayer.Sfx.PlayWhoosh(); if (this.ThrowUpgradePart(false)) { this._failCount = 0; this._stateStartTime = Time.realtimeSinceStartup; this._state = UpgradeCog.States.Implanting; } else if (this._failCount++ > 10) { this.NextIngredient(); } else { this._state = UpgradeCog.States.Aiming; } } else { this.NextIngredient(); } break; case UpgradeCog.States.Rotating: { float num4 = (!this._fastForward) ? (Time.unscaledDeltaTime / this._rotationDuration) : 1f; this._craftView.transform.RotateAround(this._currentReceiver._centerAndRotationAxisUpDirection.position, this._rotateAxis, this._rotateAngle * num4); this._stateStartTime += Time.unscaledDeltaTime; if (this._stateStartTime >= this._rotationDuration || this._fastForward) { this._failCount = 0; this._stateStartTime = Time.realtimeSinceStartup; this._state = UpgradeCog.States.Aiming; } break; } case UpgradeCog.States.Implanting: num = Mathf.Clamp01(num / this._singleImplantDuration); this._currentUpgradePartTr.localPosition = Vector3.Slerp(this._upgradePartStartPosition, this._upgradePartTargetPosition, num); if (Mathf.Approximately(num, 1f)) { this._currentUpgradePartTr.localPosition = this._upgradePartTargetPosition; this._currentReceiver.AddView(this._currentIngredientItemId, this._currentUpgradePartTr); this._implantsDone++; if (this.SupportedItemsCache[this._currentIngredientItemId]._amount == 1 || this._implantsDone % this.SupportedItemsCache[this._currentIngredientItemId]._amount == 1) { this.ApplyBonus(); Scene.HudGui.ShowUpgradesDistribution(this._recipe._productItemID, this._recipe._ingredients[1]._itemID, 1); } this._state = UpgradeCog.States.Aiming; LocalPlayer.Sfx.PlayUpgradeSuccess(this._currentUpgradePartTr.gameObject); } break; case UpgradeCog.States.MoveDown: num = MathEx.Easing.EaseInOutQuad(num, 0f, 1f, this._moveUpDuration); this._craftView.transform.position = Vector3.Slerp(this._upPositionV, this._downPosition, num); this._craftView.transform.rotation = Quaternion.Slerp(this._upRotation, this._downRotation, num); if (Mathf.Approximately(num, 1f)) { this.Shutdown(); } break; } }
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); }