From eaf903d8847f577efa316a59329d5be44d4d7a73 Mon Sep 17 00:00:00 2001 From: CWX Date: Thu, 23 Jan 2025 22:32:58 +0000 Subject: [PATCH] first check pointless, implement probobjarray --- Libraries/Core/Helpers/ItemHelper.cs | 38 ++++++++++------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/Libraries/Core/Helpers/ItemHelper.cs b/Libraries/Core/Helpers/ItemHelper.cs index 40db215c..55071ded 100644 --- a/Libraries/Core/Helpers/ItemHelper.cs +++ b/Libraries/Core/Helpers/ItemHelper.cs @@ -9,6 +9,7 @@ using Core.Models.Utils; using Core.Services; using Core.Utils; using Core.Utils.Cloners; +using Core.Utils.Collections; using SptCommon.Extensions; @@ -1569,7 +1570,7 @@ public class ItemHelper( List? cartridgeWhitelist = null ) { - var ammos = staticAmmoDist[caliber]; + var ammos = staticAmmoDist.GetValueOrDefault(caliber, []); if (ammos is null && fallbackCartridgeTpl is not null) { _logger.Error($"Unable to pick a cartridge for caliber: {caliber} as staticAmmoDist has no data. using fallback value of {fallbackCartridgeTpl}"); @@ -1577,15 +1578,6 @@ public class ItemHelper( return fallbackCartridgeTpl; } - // STATICAMMODIST CANT NOT BE AN LIST? - // if (!Array.(ammos) && fallbackCartridgeTpl) { - // this.logger.error( - // `Unable to pick a cartridge for caliber: ${caliber}, the chosen staticAmmoDist data is not an array. Using fallback value of ${fallbackCartridgeTpl}`, - // ); - // - // return fallbackCartridgeTpl; - // } - if (ammos is null && fallbackCartridgeTpl is null) { _logger.Debug($"Unable to pick a cartridge for caliber: {caliber} as staticAmmoDist has no data. No fallback value provided"); @@ -1593,21 +1585,17 @@ public class ItemHelper( return null; } - _logger.Error($"FINISH IMPLEMENTATION: ItemHelper::DrawAmmoTpl"); - return null; - - // TODO: implement ProbabilityObjectArray Type - // var ammoArray = new ProbabilityObjectArray(_mathUtil, _cloner); - // for (const icd of ammos) { - // // Whitelist exists and tpl not inside it, skip - // // Fixes 9x18mm kedr issues - // if (cartridgeWhitelist && !cartridgeWhitelist.includes(icd.tpl)) { - // continue; - // } - // - // ammoArray.push(new ProbabilityObject(icd.tpl, icd.relativeProbability)); - // } - // return ammoArray.draw(1)[0]; + var ammoArray = new ProbabilityObjectArray, string, float?>(_mathUtil, _cloner, []); + foreach (var icd in ammos) { + // Whitelist exists and tpl not inside it, skip + // Fixes 9x18mm kedr issues + if (cartridgeWhitelist is not null && !cartridgeWhitelist.Contains(icd.Tpl)) { + continue; + } + + ammoArray.Add(new ProbabilityObject(icd.Tpl, (double)icd.RelativeProbability, null)); + } + return ammoArray.Draw(1)[0]; } ///