From 4dddc8d3f1389169b630ca508c76559268d58db3 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 27 Jul 2023 09:17:52 -0700 Subject: [PATCH] fix: Fixes NPE in BaseRanged.OnMiss (#1433) --- Projects/UOContent/Items/Weapons/Ranged/BaseRanged.cs | 9 +++++++-- Projects/UOContent/Mobiles/PlayerMobile.cs | 4 ++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/Projects/UOContent/Items/Weapons/Ranged/BaseRanged.cs b/Projects/UOContent/Items/Weapons/Ranged/BaseRanged.cs index a76eac33d..017440db9 100644 --- a/Projects/UOContent/Items/Weapons/Ranged/BaseRanged.cs +++ b/Projects/UOContent/Items/Weapons/Ranged/BaseRanged.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using ModernUO.Serialization; using Server.Mobiles; using Server.Network; @@ -134,8 +135,12 @@ namespace Server.Items { var ammo = AmmoType; - pm.RecoverableAmmo.TryGetValue(ammo, out var result); - pm.RecoverableAmmo[ammo] = result + 1; + if (ammo != null) + { + pm.RecoverableAmmo ??= new Dictionary(); + pm.RecoverableAmmo.TryGetValue(ammo, out var result); + pm.RecoverableAmmo[ammo] = result + 1; + } if (!pm.Warmode) { diff --git a/Projects/UOContent/Mobiles/PlayerMobile.cs b/Projects/UOContent/Mobiles/PlayerMobile.cs index c17366662..fcb93e317 100644 --- a/Projects/UOContent/Mobiles/PlayerMobile.cs +++ b/Projects/UOContent/Mobiles/PlayerMobile.cs @@ -528,7 +528,7 @@ namespace Server.Mobiles set => SetFlag(PlayerFlag.RefuseTrades, value); } - public Dictionary RecoverableAmmo { get; } = new(); + public Dictionary RecoverableAmmo { get; set; } [CommandProperty(AccessLevel.GameMaster)] public DateTime AcceleratedStart { get; set; } @@ -3702,7 +3702,7 @@ namespace Server.Mobiles public void RecoverAmmo() { - if (!Core.SE || !Alive) + if (!Core.SE || !Alive || RecoverableAmmo == null) { return; }