public void AddIngrendient_Actual(int ingredientNum, bool local, BoltConnection from = null) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientNum]; int num = 0; for (int i = 0; i < this._requiredIngredients.Count; i++) { num += this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount; } if (receipeIngredient._amount >= buildIngredients._amount || (num == 1 && (this._lockBuild || (this.CustomLockCheck != null && this.CustomLockCheck())))) { if (BoltNetwork.isRunning && from && !Cheats.Creative) { PlayerAddItem playerAddItem = PlayerAddItem.Create(from); playerAddItem.ItemId = buildIngredients._itemID; playerAddItem.Amount = 1; playerAddItem.Send(); } this.UpdateNetworkIngredients(); return; } receipeIngredient._amount++; this.UpdateNeededRenderers(); BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -1, false); if (BoltNetwork.isRunning) { this.UpdateNetworkIngredients(); } this.CheckNeeded(); }
private void Update() { if (base.entity && base.entity.isAttached && this._cs.Component) { bool flag = false; if (base.state == null) { base.enabled = false; return; } for (int i = 0; i < this._cs.Component.GetPresentIngredients().Length; i++) { ReceipeIngredient receipeIngredient = this._cs.Component.GetPresentIngredients()[i]; if (receipeIngredient != null && receipeIngredient._amount != base.state.Ingredients[i].Count) { receipeIngredient._amount = base.state.Ingredients[i].Count; flag = true; } } if (flag) { this._cs.Component.UpdateNeededRenderers(); } } }
public void UpdateNeededRenderers() { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; buildIngredients.SetBuilt(receipeIngredient._amount); } }
public override void Initialize() { if (!_initialized) { if (_presentIngredients == null) { _presentIngredients = new ReceipeIngredient[base._requiredIngredients.Count]; } this.SetUpIcons(); if (_presentIngredients.Length != base._requiredIngredients.Count) { _presentIngredients = new ReceipeIngredient[base._requiredIngredients.Count]; } for (int i = 0; i < base._requiredIngredients.Count; i++) { BuildIngredients buildIngredients = _requiredIngredients[i]; if (_presentIngredients[i] == null) { _presentIngredients[i] = new ReceipeIngredient { _itemID = buildIngredients._itemID }; } ReceipeIngredient receipeIngredient = _presentIngredients[i]; if (buildIngredients._amount != 1) { buildIngredients._amount /= 2; } if (receipeIngredient._amount != 1) { receipeIngredient._amount /= 2; } int amount = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(buildIngredients._itemID, amount); for (int j = 0; (j < receipeIngredient._amount) && (j >= buildIngredients._renderers.Length); j++) { buildIngredients._renderers[j].SetActive(true); } } _initialized = true; if (BoltNetwork.isRunning) { base.gameObject.AddComponent <CoopConstruction>(); if (BoltNetwork.isServer && base.entity.isAttached) { this.UpdateNetworkIngredients(); } if (!BoltNetwork.isClient) { this.CheckNeeded(); } } } }
private void CheckText() { if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID); if (buildIngredients != null && receipeIngredient != null && receipeIngredient._amount != buildIngredients._amount) { if (!icons._iconGo.activeSelf || !icons._label.gameObject.activeSelf) { icons._iconGo.SetActive(true); icons._label.gameObject.SetActive(true); Scene.HudGui.BuildingIngredientsGrid.repositionNow = true; if (!Scene.HudGui.BuildingIngredientsFollow.gameObject.activeSelf) { Scene.HudGui.BuildingIngredientsFollow.gameObject.SetActive(true); } } Craft_Structure.BuildIngredients.TextOptions textDisplayMode = buildIngredients._textDisplayMode; if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.PresentOverTotal) { if (textDisplayMode != Craft_Structure.BuildIngredients.TextOptions.Present) { if (textDisplayMode == Craft_Structure.BuildIngredients.TextOptions.Total) { icons._label.text = buildIngredients._amount.ToString(); } } else { icons._label.text = receipeIngredient._amount.ToString(); } } else if (icons.DisplayedPresent != receipeIngredient._amount || icons.DisplayedNeeded != buildIngredients._amount) { icons.DisplayedPresent = receipeIngredient._amount; icons.DisplayedNeeded = buildIngredients._amount; icons._label.text = receipeIngredient._amount + "/" + buildIngredients._amount; } } else if (icons._iconGo.activeSelf || icons._label.gameObject.activeSelf) { icons._iconGo.SetActive(false); icons._label.gameObject.SetActive(false); } } } }
public void Initialize() { if (!this._initialized) { if (this._presentIngredients == null) { this._presentIngredients = new ReceipeIngredient[this._requiredIngredients.Count]; } this.SetUpIcons(); if (this._presentIngredients.Length != this._requiredIngredients.Count) { this._presentIngredients = new ReceipeIngredient[this._requiredIngredients.Count]; } for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; if (this._presentIngredients[i] == null) { this._presentIngredients[i] = new ReceipeIngredient { _itemID = buildIngredients._itemID }; } ReceipeIngredient receipeIngredient = this._presentIngredients[i]; int amount = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(buildIngredients._itemID, amount); for (int j = 0; j < receipeIngredient._amount; j++) { if (j >= buildIngredients._renderers.Length) { break; } buildIngredients._renderers[j].SetActive(true); } } this._initialized = true; if (BoltNetwork.isRunning) { base.gameObject.AddComponent <CoopConstruction>(); if (BoltNetwork.isServer && this.entity.isAttached) { this.UpdateNetworkIngredients(); } } if (!BoltNetwork.isClient) { this.CheckNeeded(); } } }
private void MakeComplete(Craft_Structure structure) { try { if (structure._requiredIngredients.Count <= 0) { return; } for (int i = 0; i < structure._requiredIngredients.Count; ++i) { Craft_Structure.BuildIngredients buildIngredients = structure._requiredIngredients[i]; if (structure.GetPresentIngredients().Length <= i) { continue; } ReceipeIngredient receipeIngredient = structure.GetPresentIngredients()[i]; if (receipeIngredient._amount >= buildIngredients._amount) { continue; } for (int j = 0; j < buildIngredients._amount - receipeIngredient._amount; j++) { if (BoltNetwork.isRunning) { AddIngredient ingredient = AddIngredient.Create(GlobalTargets.OnlyServer); ingredient.IngredientNum = i; ingredient.ItemId = buildIngredients._itemID; ingredient.Construction = structure.entity; ingredient.Send(); } else { structure.AddIngrendient_Actual(i, true); } SleepFor(0.300f); } SleepFor(0.300f); } } catch { } }
public bool CanCombine() { if (!this._isCombining && this._crafting.Ingredients.Count == 1) { ReceipeIngredient receipeIngredient = this._crafting.Ingredients.First <ReceipeIngredient>(); if (receipeIngredient._amount == 1) { int itemID = receipeIngredient._itemID; Item item = ItemDatabase.ItemById(itemID); if ((item.MatchType(this._acceptedTypes) && item._equipmentSlot == Item.EquipmentSlot.RightHand) || item._allowQuickSelect) { return(true); } } } return(false); }
public void UpdateNeededRenderers() { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; int num = 0; while (num < receipeIngredient._amount && num < buildIngredients._renderers.Length) { if (!buildIngredients._renderers[num].activeSelf) { buildIngredients._renderers[num].SetActive(true); } num++; } } }
public void AddIngrendient_Actual(int ingredientNum, bool local) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientNum]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientNum]; if (receipeIngredient._amount >= buildIngredients._amount) { this.UpdateNetworkIngredients(); return; } receipeIngredient._amount++; this.UpdateNeededRenderers(); BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -1); if (BoltNetwork.isRunning) { this.UpdateNetworkIngredients(); } this.CheckNeeded(); }
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(); } }
private void Update() { if (this._initialized) { this.CheckText(); this.CheckNeeded(); Scene.HudGui.DestroyIcon.gameObject.SetActive(true); if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f)) { this.CancelBlueprint(); return; } for (int i = 0; i < this._requiredIngredients.Count; i++) { if (this._requiredIngredients[i]._amount != this._presentIngredients[i]._amount) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; if (buildIngredients._amount > receipeIngredient._amount) { if (!LocalPlayer.Inventory.Owns(this._requiredIngredients[i]._itemID) && !Cheats.Creative) { buildIngredients._icon.GetComponent <GUITexture>().color = this.ColorRed; } else { buildIngredients._icon.GetComponent <GUITexture>().color = this.ColorGrey; Scene.HudGui.AddIcon.SetActive(true); if (TheForest.Utils.Input.GetButtonDown("Take") || (Cheats.Creative && TheForest.Utils.Input.GetButton("Take"))) { this.AddIngredient(i); break; } } } } } } }
public static void InstantBuilder(Craft_Structure structure) { try { if (structure._requiredIngredients.Count > 0) { for (int i = 0; i < structure._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = structure._requiredIngredients[i]; if (structure.GetPresentIngredients().Length > i) { ReceipeIngredient receipeIngredient = structure.GetPresentIngredients()[i]; if (receipeIngredient._amount < buildIngredients._amount) { for (int j = 0; j < buildIngredients._amount - receipeIngredient._amount; j++) { if (BoltNetwork.isRunning) { AddIngredient ingredient = AddIngredient.Create(GlobalTargets.OnlyServer); ingredient.IngredientNum = i; ingredient.ItemId = buildIngredients._itemID; ingredient.Construction = structure.entity; ingredient.Send(); } else { structure.AddIngrendient_Actual(i, true, null); } } } } } } } catch (System.Exception) { } }
private void CheckText() { if (Application.isPlaying) { for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; if (buildIngredients != null && receipeIngredient != null && receipeIngredient._amount != buildIngredients._amount) { if (!buildIngredients._text.activeSelf) { buildIngredients._text.SetActive(true); buildIngredients._icon.SetActive(true); } switch (buildIngredients._textDisplayMode) { case Craft_Structure.BuildIngredients.TextOptions.PresentOverTotal: buildIngredients._text.GetComponent <GUIText>().text = receipeIngredient._amount + "/" + buildIngredients._amount; break; case Craft_Structure.BuildIngredients.TextOptions.Present: buildIngredients._text.GetComponent <GUIText>().text = receipeIngredient._amount.ToString(); break; case Craft_Structure.BuildIngredients.TextOptions.Total: buildIngredients._text.GetComponent <GUIText>().text = buildIngredients._amount.ToString(); break; } } else if (buildIngredients._text.activeSelf) { buildIngredients._text.SetActive(false); buildIngredients._icon.SetActive(false); } } } }
public void SpawnBackIngredients(int ingredientId) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[ingredientId]; ReceipeIngredient receipeIngredient = this._presentIngredients[ingredientId]; if (buildIngredients != null && receipeIngredient != null) { int num = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -num, true); int amount = this._presentIngredients[ingredientId]._amount; if (amount > 0) { Transform transform = BoltNetwork.isRunning ? ItemDatabase.ItemById(this._presentIngredients[ingredientId]._itemID)._pickupPrefabMP : ItemDatabase.ItemById(this._presentIngredients[ingredientId]._itemID)._pickupPrefab; if (transform) { Craft_Structure.PickupAxis pickupAxis = this._requiredIngredients[ingredientId]._pickupAxis; float f = (float)amount * 0.428571433f + 1f; int num2 = Mathf.Min(Mathf.RoundToInt(f), 10); int i = 0; while (i < num2) { int num3 = Mathf.RoundToInt((float)i / (float)num2 * (float)amount); int j; for (j = 0; j < this._requiredIngredients[ingredientId]._subIngredients.Count; j++) { if (this._requiredIngredients[ingredientId]._subIngredients[j]._renderers.Length > num3) { Transform transform2 = this._requiredIngredients[ingredientId]._subIngredients[j]._renderers[num3].transform; Transform transform3 = BoltNetwork.isRunning ? BoltNetwork.Instantiate(transform.gameObject).transform : UnityEngine.Object.Instantiate <Transform>(transform); transform3.position = transform2.position; if (pickupAxis != Craft_Structure.PickupAxis.X) { if (pickupAxis != Craft_Structure.PickupAxis.Y) { if (pickupAxis == Craft_Structure.PickupAxis.Z) { transform3.rotation = transform2.rotation; } } else { transform3.rotation = Quaternion.LookRotation(transform2.up); } } else { transform3.rotation = Quaternion.LookRotation(transform2.right); } i++; if (i >= num2) { break; } } else { num3 -= this._requiredIngredients[ingredientId]._subIngredients[j]._renderers.Length; } } if (j >= this._requiredIngredients[ingredientId]._subIngredients.Count) { break; } } } } } }
public void CancelBlueprintSafe() { GameStats.CancelledStructure.Invoke(); for (int i = 0; i < this._requiredIngredients.Count; i++) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[i]; ReceipeIngredient receipeIngredient = this._presentIngredients[i]; if (buildIngredients != null && receipeIngredient != null) { int num = buildIngredients._amount - receipeIngredient._amount; BuildMission.AddNeededToBuildMission(receipeIngredient._itemID, -num); int amount = this._presentIngredients[i]._amount; if (amount > 0) { Transform transform = BoltNetwork.isRunning ? ItemDatabase.ItemById(this._presentIngredients[i]._itemID)._pickupPrefabMP : ItemDatabase.ItemById(this._presentIngredients[i]._itemID)._pickupPrefab; if (transform) { Craft_Structure.PickupAxis pickupAxis = this._requiredIngredients[i]._pickupAxis; float f = (float)amount * 0.428571433f + 1f; int num2 = Mathf.Min(Mathf.RoundToInt(f), 10); for (int j = 0; j < num2; j++) { int num3 = Mathf.RoundToInt((float)j / (float)num2 * (float)amount); if (this._requiredIngredients[i]._renderers.Length <= num3) { break; } Transform transform2 = this._requiredIngredients[i]._renderers[num3].transform; Transform transform3 = BoltNetwork.isRunning ? BoltNetwork.Instantiate(transform.gameObject).transform : UnityEngine.Object.Instantiate <Transform>(transform); transform3.position = transform2.position; switch (pickupAxis) { case Craft_Structure.PickupAxis.Z: transform3.rotation = transform2.rotation; break; case Craft_Structure.PickupAxis.X: transform3.rotation = Quaternion.LookRotation(transform2.right); break; case Craft_Structure.PickupAxis.Y: transform3.rotation = Quaternion.LookRotation(transform2.up); break; } } } } } } this.CheckText(); this.AllOff(); if (BoltNetwork.isRunning && this.entity.isAttached) { BoltNetwork.Destroy(this.entity); } else { UnityEngine.Object.Destroy(this._ghost); } base.enabled = false; }
protected override void Update() { if (!_initialized) { return; } CheckText(); CheckNeeded(); Scene.HudGui.DestroyIcon.gameObject.SetActive(true); if (_swapTo) { if (!Scene.HudGui.ToggleVariationIcon.activeSelf) { Scene.HudGui.ToggleVariationIcon.SetActive(true); } if (TheForest.Utils.Input.GetButtonDown("Rotate")) { SwapToNextGhost(); return; } } if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.25f)) { CancelBlueprint(); return; } if (_lockBuild || (CustomLockCheck != null && CustomLockCheck())) { int num = 0; for (int i = 0; i < _requiredIngredients.Count; i++) { num += _requiredIngredients[i]._amount - _presentIngredients[i]._amount; } if (num == 1) { AllOff(); Scene.HudGui.CantPlaceIcon.SetActive(true); return; } } Scene.HudGui.CantPlaceIcon.SetActive(false); bool flag = false; for (int j = 0; j < _requiredIngredients.Count; j++) { HudGui.BuildingIngredient icons = GetIcons(_requiredIngredients[j]._itemID); if (_requiredIngredients[j]._amount != _presentIngredients[j]._amount) { BuildIngredients buildIngredients = _requiredIngredients[j]; ReceipeIngredient receipeIngredient = _presentIngredients[j]; if (buildIngredients._amount > receipeIngredient._amount) { if (!LocalPlayer.Inventory.Owns(_requiredIngredients[j]._itemID) && !Cheats.Creative) { icons.SetMissingIngredientColor(); } else { icons.SetAvailableIngredientColor(); if (_nextAddItem < Time.time && !flag) { flag = true; if (!Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(true); } Scene.HudGui.AddBuildingIngredientIcon.transform.localPosition = icons._iconGo.transform.localPosition + new Vector3(0f, -50f, 0f); Scene.HudGui.AddBuildingIngredientIcon.transform.rotation = icons._iconGo.transform.rotation; if (TheForest.Utils.Input.GetButtonDown("Build")) { _nextAddItem = Time.time + 0.25f; AddIngredient(j); break; } if (TheForest.Utils.Input.GetButton("Build") && (_nextAddItem < Time.time)) { _nextAddItem = Time.time + 0.05f; AddIngredient(j); break; } } } } } } if (!flag && Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(false); } if (Vector3.Dot(LocalPlayer.Transform.forward, _uiFollowTarget.forward) < 0.75f || LocalPlayer.Transform.InverseTransformPoint(_uiFollowTarget.position).z < 0f) { SetUpIcons(); } }
private void Update() { if (this._initialized) { this.CheckText(); this.CheckNeeded(); Scene.HudGui.DestroyIcon.gameObject.SetActive(true); if (this._swapTo) { if (!Scene.HudGui.ToggleVariationIcon.activeSelf) { Scene.HudGui.ToggleVariationIcon.SetActive(true); } if (TheForest.Utils.Input.GetButtonDown("Rotate")) { this.SwapToNextGhost(); return; } } if (TheForest.Utils.Input.GetButtonAfterDelay("Craft", 0.5f, false)) { this.CancelBlueprint(); return; } if (this._lockBuild || (this.CustomLockCheck != null && this.CustomLockCheck())) { int num = 0; for (int i = 0; i < this._requiredIngredients.Count; i++) { num += this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount; } if (num == 1) { this.AllOff(false); Scene.HudGui.CantPlaceIcon.SetActive(true); return; } } Scene.HudGui.CantPlaceIcon.SetActive(false); bool flag = false; for (int j = 0; j < this._requiredIngredients.Count; j++) { HudGui.BuildingIngredient icons = this.GetIcons(this._requiredIngredients[j]._itemID); if (this._requiredIngredients[j]._amount != this._presentIngredients[j]._amount) { Craft_Structure.BuildIngredients buildIngredients = this._requiredIngredients[j]; ReceipeIngredient receipeIngredient = this._presentIngredients[j]; if (buildIngredients._amount > receipeIngredient._amount) { if (!LocalPlayer.Inventory.Owns(this._requiredIngredients[j]._itemID, true) && !Cheats.Creative) { icons.SetMissingIngredientColor(); } else { icons.SetAvailableIngredientColor(); if (this._nextAddItem < Time.time && !flag) { flag = true; if (!Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(true); } Scene.HudGui.AddBuildingIngredientIcon.transform.localPosition = icons._iconGo.transform.localPosition + new Vector3(0f, -50f, 0f); Scene.HudGui.AddBuildingIngredientIcon.transform.rotation = icons._iconGo.transform.rotation; if (this.GetBuildInputDown() || (Cheats.Creative && TheForest.Utils.Input.GetButton("Build"))) { if (Cheats.Creative) { this._nextAddItem = Time.time + 0.065f; } this.AddIngredient(j); break; } } } } } } if (!flag && Scene.HudGui.AddBuildingIngredientIcon.activeSelf) { Scene.HudGui.AddBuildingIngredientIcon.SetActive(false); } if (Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward) < 0.75f || LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z < 0f) { this.SetUpIcons(); } else if (SteamClientDSConfig.isDedicatedClient) { bool flag2 = LocalPlayer.Transform.InverseTransformPoint(this._uiFollowTarget.position).z >= 0f; float num2 = Vector3.Dot(LocalPlayer.Transform.forward, this._uiFollowTarget.forward); bool flag3 = num2 > 0.35f && num2 < 0.8f; if (flag2 && flag3) { this.SetUpIcons(); } } } }