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(); }
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(); } } }
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(); }
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 SwapToNextGhost() { if (LocalPlayer.Sfx) { LocalPlayer.Sfx.PlayWhoosh(); } if (BoltNetwork.isRunning && !base.entity.isOwner) { SwapGhost swapGhost = SwapGhost.Create(base.entity.source); swapGhost.GhostEntity = base.entity; swapGhost.Send(); } else { GameObject gameObject = UnityEngine.Object.Instantiate <GameObject>(this._swapTo, this._ghost.transform.position, this._ghost.transform.rotation); if (this._ghost.transform.parent) { gameObject.transform.parent = this._ghost.transform.parent; } Craft_Structure componentInChildren = gameObject.GetComponentInChildren <Craft_Structure>(); if (componentInChildren) { componentInChildren._presentIngredients = new ReceipeIngredient[componentInChildren._requiredIngredients.Count]; for (int i = 0; i < this._presentIngredients.Length; i++) { bool flag = false; for (int j = 0; j < componentInChildren._presentIngredients.Length; j++) { if (componentInChildren._presentIngredients[j] == null) { componentInChildren._presentIngredients[j] = new ReceipeIngredient { _itemID = this._presentIngredients[i]._itemID, _amount = 0 }; } if (this._presentIngredients[i]._itemID == componentInChildren._presentIngredients[j]._itemID) { int num = this._requiredIngredients[i]._amount - this._presentIngredients[i]._amount; BuildMission.AddNeededToBuildMission(this._presentIngredients[i]._itemID, -num, true); componentInChildren._presentIngredients[j]._amount = this._presentIngredients[i]._amount; flag = true; break; } } if (!flag) { this.SpawnBackIngredients(i); } } componentInChildren.manualLoading = false; TreeStructure component = this._ghost.GetComponent <TreeStructure>(); if (component) { TreeStructure treeStructure = gameObject.GetComponent <TreeStructure>(); if (!treeStructure) { treeStructure = gameObject.AddComponent <TreeStructure>(); } treeStructure.TreeId = component.TreeId; } if (BoltNetwork.isRunning && !gameObject.GetComponent <BoltEntity>().isAttached) { BoltNetwork.Attach(gameObject); } this.AllOff(false); if (BoltNetwork.isRunning) { BoltNetwork.Destroy(this._ghost); } else { UnityEngine.Object.Destroy(this._ghost); } } else { Debug.Log("Swap target isn't a ghost, aborting"); UnityEngine.Object.Destroy(gameObject); } } }
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; }