public void BuildWeapon() { // Yeah this is pretty shit. It'll do, though. if (isBuild) { Debug.LogError ("Tried building already build weapon."); return; } weapon = transform.parent.GetComponent<Weapon>(); if (barrelPrefab) { weapon.muzzles = new Transform[barrelAttachmentPoint.Length]; weapon.barrels = new WeaponBarrel[barrelAttachmentPoint.Length]; for (int i = 0; i < barrelAttachmentPoint.Length; i++) { GameObject b = (GameObject)Instantiate (barrelPrefab, barrelAttachmentPoint[i].position, Quaternion.identity); barrel = b.GetComponent<WeaponBarrel>(); barrel.transform.parent = barrelAttachmentPoint[i]; weapon.barrels[i] = barrel; weapon.muzzles[i] = barrel.muzzle; weapon.weaponParts.Add (barrel); } } if (stockPrefab && stockAttachmentPoint) { GameObject s = (GameObject)Instantiate (stockPrefab, stockAttachmentPoint.position, Quaternion.identity); stock = s.GetComponent<WeaponStock>(); stock.transform.parent = stockAttachmentPoint; weapon.weaponParts.Add (stock); } if (opticPrefab && opticsAttachmentPoint) { GameObject o = (GameObject)Instantiate (opticPrefab, opticsAttachmentPoint.position, Quaternion.identity); optic = o.GetComponent<WeaponOptic>(); optic.transform.parent = opticsAttachmentPoint; weapon.weaponParts.Add (optic); } if (underBarrelPrefab && underBarrelAttachmentPoint) { GameObject ub = (GameObject)Instantiate (underBarrelPrefab, underBarrelAttachmentPoint.position, Quaternion.identity); underBarrel = ub.GetComponent<WeaponUnderbarrelAttachment>(); underBarrel.transform.parent = underBarrelAttachmentPoint; weapon.weaponParts.Add (underBarrel); } if (magazinePrefab) { GameObject ma = (GameObject)Instantiate (magazinePrefab, magazineAttachmentPoint.position, Quaternion.identity); magazine = ma.GetComponent<WeaponMagazine>(); magazine.transform.parent = magazineAttachmentPoint; weapon.weaponParts.Add (magazine); } weapon.CombineData (); isBuild = true; }
public void BuyWeapons() { for (var i = 0; i < this.WeaponStock.Count(); i++) { Console.WriteLine($"{(i + 1)}. {this.WeaponStock[i].Name}: {this.WeaponStock[i].Strength} Strength : ({this.WeaponStock[i].OriginalValue} gp)"); } var tryParse = int.TryParse(Console.ReadLine(), out var input); var itemToBePurchased = WeaponStock.ElementAtOrDefault(input - 1); if (itemToBePurchased != null && tryParse) { if (Game.hero.Gold >= itemToBePurchased.OriginalValue && !Game.hero.WeaponsBag.Contains(itemToBePurchased) && Game.hero.EquippedWeapon != itemToBePurchased) { Console.ForegroundColor = ConsoleColor.DarkYellow; Game.hero.WeaponsBag.Add(itemToBePurchased); Game.hero.Gold = Game.hero.Gold - itemToBePurchased.OriginalValue; Console.WriteLine($"Purchased for {itemToBePurchased.OriginalValue} gp. You have {Game.hero.Gold}gp left!"); Console.WriteLine("Press any key to return to the previous menu"); Console.ResetColor(); var purchaseInput = Console.ReadLine(); ShopMenu(); } } else if (Game.hero.Gold < itemToBePurchased.OriginalValue) { Console.WriteLine("Sorry, you don't have enough gp to purchase this. Please come back when you're a bit more affluent!"); Console.ReadLine(); ShopMenu(); } else { Console.WriteLine("Invalid input. Press any key to go to the previous menu."); Console.ReadLine(); ShopMenu(); } }