private void AssembleParts(IRocketParts thePart, GameObject selectedPart) { if (AddPart(thePart) == true) { BuildParts(thePart, selectedPart, builtParts); } }
private void BuildParts(IRocketParts thePart, GameObject selectedPart, List <GameObject> building) { if (thePart is BaseCockpit) { if (!building.Contains(builtCockpit)) { builtCockpit = (GameObject)Instantiate(selectedPart) as GameObject; builtCockpit.transform.parent = transform; builtCockpit.transform.localPosition = new Vector3(-2, 0, 5); Cockpit behaviour = builtCockpit.AddComponent <Cockpit>(); behaviour.Create(thePart as BaseCockpit); builtCockpit.name = thePart.Name; building.Add(builtCockpit); } else if (building.Contains(builtCockpit)) { building.Remove(builtCockpit); Destroy(builtCockpit); BuildParts(thePart, selectedPart, building); } } else if (thePart is BaseThrusters) { if (!building.Contains(builtThrusters)) { builtThrusters = (GameObject)Instantiate(selectedPart) as GameObject; builtThrusters.transform.parent = transform; builtThrusters.transform.localPosition = new Vector3(-8, 0, 5); Thrusters behaviour = builtThrusters.AddComponent <Thrusters>(); behaviour.Create(thePart as BaseThrusters); builtThrusters.name = thePart.Name; building.Add(builtThrusters); } else if (building.Contains(builtThrusters)) { building.Remove(builtThrusters); Destroy(builtThrusters); BuildParts(thePart, selectedPart, building); } } else if (thePart is BaseWings) { if (!building.Contains(builtWings)) { builtWings = (GameObject)Instantiate(selectedPart) as GameObject; builtWings.transform.parent = transform; builtWings.transform.localPosition = new Vector3(5, -4, 4); Wings behaviour = builtWings.AddComponent <Wings>(); behaviour.Create(thePart as BaseWings); builtWings.name = thePart.Name; building.Add(builtWings); } else if (building.Contains(builtWings)) { building.Remove(builtWings); Destroy(builtWings); BuildParts(thePart, selectedPart, building); } } }
private void AssembleParts(IRocketParts thePart, GameObject selectedPart) { if (AddPart(thePart) == true) { BuildParts(thePart, selectedPart, builtParts); } else { // Start a coroutine to print the text to the screen - // It is a coroutine to assist in helping prevent text objects from // spawning on top one another. this.StartCoroutine(UnitController.Self.CombatText(null, Color.white, "Not enough resources!")); } }
/// <summary> /// Function for adding and replacing parts in a list. /// Step 1) Checks the integer values that refer to the player's current amount of steel and fuel against the integer values of the object that represent its cost /// Step 2) Checks the type of the selected object that uses the interface IRocketParts. /// Step 3-1) Checks if an object of that type doesn't exists at any index of the list. /// Step 4) If Step 3-1 returns true: /// Adds the object to the list /// Increments the Rocket class's integer value total quality based on the object's integer value quality /// Decrements the values of the player's steel and fuel based on the object's steel and fuel cost values /// Sets an object to be equal to the selected object as current /// Exits the function /// Step 3-2) Else if Step 3-1 returns false, then check if an object of the same type exists in the list at any index and if the list doesn't contain the selected object /// Step 5) If Step 3-2 returns true: /// Decrement the Rocket's total quality based on the quality value the current object in the list, /// Remove the current object from the list, /// And repeat from the start until it meets a condition to exit the function /// </summary> /// <param name="selectedPart"> /// The selected part. /// The object that the player is attempting to add to the list that will be checked. /// </param> public bool AddPart(IRocketParts selectedPart) { var spareList = this.allParts; if (User.SteelCount >= selectedPart.SteelCost && User.FuelCount >= selectedPart.FuelCost) { if (selectedPart is BaseCockpit) { if (selectedPart.Name == currentCockpit.Name) { return(false); } else if (!spareList.OfType <BaseCockpit>().Any()) { this.allParts.Add(selectedPart); this.totalQuality += selectedPart.Quality; User.SteelCount -= selectedPart.SteelCost; User.FuelCount -= selectedPart.FuelCost; this.currentCockpit = selectedPart as BaseCockpit; } else if (spareList.OfType <BaseCockpit>().Any() && !spareList.Contains(selectedPart)) { this.totalQuality -= this.currentCockpit.Quality; this.allParts.Remove(this.currentCockpit); this.AddPart(selectedPart); } } else if (selectedPart is BaseThrusters) { if (selectedPart.Name == currentThrusters.Name) { return(false); } else if (!spareList.OfType <BaseThrusters>().Any()) { this.allParts.Add(selectedPart); this.totalQuality += selectedPart.Quality; User.SteelCount -= selectedPart.SteelCost; User.FuelCount -= selectedPart.FuelCost; this.currentThrusters = selectedPart as BaseThrusters; } else if (spareList.OfType <BaseThrusters>().Any() && !spareList.Contains(selectedPart)) { this.totalQuality -= this.currentThrusters.Quality; this.allParts.Remove(this.currentThrusters); this.AddPart(selectedPart); } } else if (selectedPart is BaseWings) { if (selectedPart.Name == currentWings.Name) { return(false); } else if (!spareList.OfType <BaseWings>().Any()) { this.allParts.Add(selectedPart); this.totalQuality += selectedPart.Quality; User.SteelCount -= selectedPart.SteelCost; User.FuelCount -= selectedPart.FuelCost; this.currentWings = selectedPart as BaseWings; } else if (spareList.OfType <BaseWings>().Any() && !spareList.Contains(selectedPart)) { this.totalQuality -= this.currentWings.Quality; this.allParts.Remove(this.currentWings); this.AddPart(selectedPart); } } return(true); } else { return(false); } }