public void PurchaseAmmoButton() { if (detectedFirearm == null || original.M.GetNumTokens() < PanelCost) { SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Fail, transform.position); return; } else { SM.PlayCoreSound(FVRPooledAudioType.UIChirp, original.AudEvent_Spawn, transform.position); original.M.SubtractTokens(PanelCost); original.M.Increment(10, false); FVRObject.OTagFirearmRoundPower roundPower = AM.GetRoundPower(detectedFirearm.RoundType); int numSpawned = GetRoundsToSpawn(roundPower); TNHTweakerLogger.Log("Compatible rounds count for " + detectedFirearm.ObjectWrapper.ItemID + ": " + IM.OD[detectedFirearm.ObjectWrapper.ItemID].CompatibleSingleRounds.Count, TNHTweakerLogger.LogType.General); CustomCharacter character = LoadedTemplateManager.LoadedCharactersDict[original.M.C]; MagazineBlacklistEntry blacklistEntry = null; if (character.GetMagazineBlacklist().ContainsKey(detectedFirearm.ObjectWrapper.ItemID)) { blacklistEntry = character.GetMagazineBlacklist()[detectedFirearm.ObjectWrapper.ItemID]; } FVRObject compatibleRound = FirearmUtils.GetCompatibleRounds(detectedFirearm.ObjectWrapper, character.ValidAmmoEras, character.ValidAmmoSets, character.GlobalAmmoBlacklist, blacklistEntry).GetRandom(); AnvilManager.Run(SpawnRounds(compatibleRound, numSpawned)); detectedFirearm = null; UpdateIcons(); } }
private void Scan() { int colliderCount = Physics.OverlapBoxNonAlloc(original.ScanningVolume.position, original.ScanningVolume.localScale * 0.5f, colBuffer, original.ScanningVolume.rotation, original.ScanningLM, QueryTriggerInteraction.Collide); detectedMag = null; detectedSpeedLoader = null; purchaseMag = null; upgradeMag = null; for (int i = 0; i < colliderCount; i++) { if (colBuffer[i].attachedRigidbody != null) { FVRFireArm firearm = colBuffer[i].GetComponent <FVRFireArm>(); if (purchaseMag == null && firearm != null && !firearm.IsHeld && firearm.QuickbeltSlot == null) { MagazineBlacklistEntry entry = null; if (blacklist.ContainsKey(firearm.ObjectWrapper.ItemID)) { entry = blacklist[firearm.ObjectWrapper.ItemID]; } List <FVRObject> spawnableMags = FirearmUtils.GetCompatibleMagazines(firearm.ObjectWrapper, -1, -1, false, entry); if (spawnableMags.Count > 0) { purchaseMag = FirearmUtils.GetSmallestCapacityMagazine(spawnableMags); } } FVRFireArmMagazine mag = colBuffer[i].GetComponent <FVRFireArmMagazine>(); if (mag != null && mag.FireArm == null && (!mag.IsHeld) && mag.QuickbeltSlot == null && (!mag.IsIntegrated)) { detectedMag = mag; } Speedloader speedloader = colBuffer[i].GetComponent <Speedloader>(); if (speedloader != null && (!speedloader.IsHeld) && speedloader.QuickbeltSlot == null && speedloader.IsPretendingToBeAMagazine) { detectedSpeedLoader = speedloader; } //If at this point we have a valid ammo container and firearm, we can stop looping if (purchaseMag != null && (detectedMag != null || detectedSpeedLoader != null)) { break; } } } }
/// <summary> /// Returns a list of magazines, clips, or speedloaders compatible with the firearm, and also within any of the optional criteria /// </summary> /// <param name="firearm">The FVRObject of the firearm</param> /// <param name="minCapacity">The minimum capacity for desired containers</param> /// <param name="maxCapacity">The maximum capacity for desired containers. If this values is zero or negative, it is interpreted as no capacity ceiling</param> /// <param name="smallestIfEmpty">If true, when the returned list would normally be empty, will instead return the smallest capacity magazine compatible with the firearm</param> /// <param name="blacklistedContainers">A list of ItemIDs for magazines, clips, or speedloaders that will be excluded</param> /// <returns> A list of ammo container FVRObjects that are compatible with the given firearm </returns> public static List <FVRObject> GetCompatibleAmmoContainers(FVRObject firearm, int minCapacity = 0, int maxCapacity = 9999, bool smallestIfEmpty = true, MagazineBlacklistEntry blacklist = null) { //Refresh the FVRObject to have data directly from object dictionary firearm = IM.OD[firearm.ItemID]; //If the max capacity is zero or negative, we iterpret that as no limit on max capacity if (maxCapacity <= 0) { maxCapacity = 9999; } //Create a list containing all compatible ammo containers List <FVRObject> compatibleContainers = new List <FVRObject>(); if (firearm.CompatibleSpeedLoaders is not null) { compatibleContainers.AddRange(firearm.CompatibleSpeedLoaders); } //Go through each magazine and add compatible ones foreach (FVRObject magazine in firearm.CompatibleMagazines) { if (blacklist is not null && (!blacklist.IsMagazineAllowed(magazine.ItemID))) { continue; }