protected override void AddIngredient(int ingredientNum) { if (CheatMenuPlusCtrl.Options.Player.InstantBuild) { BuildIngredients ingredients = _requiredIngredients[ingredientNum]; if (BoltNetwork.isRunning) { AddIngredient ingredient = new AddIngredient(); typeof(Bolt.Event).GetField("Targets", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(ingredient, (byte)Bolt.GlobalTargets.OnlyServer); typeof(Bolt.Event).GetField("TargetConnection", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(ingredient, null); typeof(Bolt.Event).GetField("Reliability", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(ingredient, Bolt.ReliabilityModes.ReliableOrdered); ingredient.IngredientNum = ingredientNum; ingredient.Construction = base.GetComponentInParent <BoltEntity>(); ingredient.Send(); } else { base.AddIngrendient_Actual(ingredientNum, true); } } else { base.AddIngredient(ingredientNum); } }
protected override void SetUpIcons() { if (Application.isPlaying) { if (this._requiredIngredients != null) { float num = 1f / (Screen.width / 70f); Vector3 localPosition = new Vector3(0.5f - num * (float)(this._requiredIngredients.Count / 2), 0.06f, 0f); for (int i = 0; i < this._requiredIngredients.Count; i++) { BuildIngredients buildIngredients = this._requiredIngredients[i]; HudGui.BuildingIngredient icons = this.GetIcons(buildIngredients._itemID); icons._icon.transform.parent = null; icons._text.transform.parent = null; icons._icon.transform.localPosition = localPosition; localPosition.z += 1f; icons._text.transform.localPosition = localPosition; localPosition.z -= 1f; localPosition.x += num; } } else { Destroy(base.gameObject); } } }
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(); } } } }
protected override void Update() { if (CheatMenuPlusCtrl.Options.Player.InstantBuild && ModAPI.Input.GetButtonDown("InstantBuild")) { TheForest.Utils.LocalPlayer.Sfx.PlayHammer(); TheForest.Utils.Scene.HudGui.AddIcon.SetActive(false); for (int i = 0; i < _requiredIngredients.Count; i++) { int left = (_requiredIngredients[i]._amount - _presentIngredients[i]._amount); for (int n = 0; n < left; n++) { AddIngredient(i); } } return; } base.Update(); if (_initialized && CheatMenuPlusCtrl.Options.Player.InstantBuild) { for (int i = 0; i < _requiredIngredients.Count; i++) { if (_requiredIngredients[i]._amount != _presentIngredients[i]._amount) { BuildIngredients ingredients = _requiredIngredients[i]; TheForest.Items.Craft.ReceipeIngredient ingredient = _presentIngredients[i]; if (ingredients._amount > ingredient._amount) { if (!CheatMenuPlusCtrl.Options.Player.InstantBuild && !TheForest.Utils.LocalPlayer.Inventory.Owns(_requiredIngredients[i]._itemID)) { ingredients._icon.GetComponent <GUITexture>().color = ColorRed; } else { ingredients._icon.GetComponent <GUITexture>().color = ColorGrey; TheForest.Utils.Scene.HudGui.AddIcon.SetActive(true); if (TheForest.Utils.Input.GetButtonDown("Take")) { if (CheatMenuPlusCtrl.Options.Player.InstantBuild) { TheForest.Utils.LocalPlayer.Sfx.PlayHammer(); TheForest.Utils.Scene.HudGui.AddIcon.SetActive(false); } AddIngredient(i); break; } } } } } } }
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(); } }