/// <summary> /// Awake is called when the script instance is being loaded. /// </summary> void Awake() { if (Instance != null && Instance != this) { Destroy(gameObject); } else { Instance = this; } weaponStats = Resources.Load <WeaponStatsSO>("ScriptableObjects/WeaponStats"); Weapons = new List <RangedWeapon>(); Object[] objects = Resources.LoadAll("Weapons"); foreach (Object obj in objects) { GameObject weapon = (GameObject)obj; weapon = Instantiate(weapon); weapon.transform.position = transform.position; weapon.transform.SetParent(this.transform); weapon.SetActive(false); RangedWeapon rangedWeapon = weapon.GetComponent <RangedWeapon>(); RangedWeaponStats stats = new RangedWeaponStats(); foreach (RangedWeaponStats s in weaponStats.stats) { if (s.name == rangedWeapon.GetType().Name) { stats = s; break; } } rangedWeapon.stats = stats; rangedWeapon.CalculateUpgradeCost(); Weapons.Add(rangedWeapon); } //have to subtract 1 since pistol is not part of drops weaponDrops = new string[Weapons.Count - 1]; int weaponIndex = 0; int dropIndex = 0; while (weaponIndex < Weapons.Count) { RangedWeapon weapon = Weapons[weaponIndex]; if (weapon.GetType() == typeof(Pistol)) { weaponIndex++; } else { weaponDrops[dropIndex] = weapon.GetType().Name + "Drop"; weaponIndex++; dropIndex++; } } }
private bool SalvageWeaponForAmmo(RangedWeapon itemToSalvage) { bool salvagedSuccess = false; if (itemToSalvage != null) { salvagedSuccess = player.Ammunition.Add((itemToSalvage).AmmoClip.CurrentAmmoRaw); if (salvagedSuccess) { if (itemToSalvage == player.CurrentWeapon) { player.UpdatePlayerCurrentWeapon(null); } EventAggregator.GetInstance().Publish <OnPlayerAmmoChangedEvent>(new OnPlayerAmmoChangedEvent(player.playerNumber, player.Ammunition)); AudioManager.Play("SalvagedWeapon"); ItemFocused = false; player.InteractionPanel.RemoveInteractionPanel(); Debug.Log("InventoryHandler: " + itemToSalvage.GetType() + " weapon salvaged for ammo."); Destroy(itemToSalvage.gameObject); if (InventoryHUDFocused) { InventoryHUD.OnItemRemove(0); player.InteractionPanel.RemoveLoadBar(); } } else { Debug.Log("InventoryHandler: Cannot salvage weapon, Im already maxed out on ammo"); player.InteractionPanel.ShowRejectedLoadBar(); } } return(salvagedSuccess); }