From 0058d1ac3919c0f4b7eab2412f46f82f6bb8721e Mon Sep 17 00:00:00 2001 From: Aristeas <94058548+Jnick-24@users.noreply.github.com> Date: Sun, 25 Feb 2024 22:40:48 -0600 Subject: [PATCH] Fixed logic error assigning incorrect ammos to weapons --- .../HeartModule/Weapons/Heart_Settings.cs | 10 +++++----- .../Weapons/WeaponLogic_Magazines.cs | 17 ++++++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs index 1b336456..44d83d2e 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/Heart_Settings.cs @@ -20,7 +20,7 @@ public void Sync() if (MyAPIGateway.Session.IsServer) { HeartData.I.Net.SendToEveryone(this); - HeartLog.Log("Sent settings to all.\n" + ToString() + "\n---------------------------"); + //HeartLog.Log("Sent settings to all.\n" + ToString() + "\n---------------------------"); } else { @@ -41,8 +41,8 @@ public static void RequestSync(long weaponEntityId) public override void Received(ulong SenderSteamId) { //HeartLog.Log("Recieve called: Sender: " + SenderSteamId + " | Self: " + HeartData.I.SteamId + "\n" + ToString()); - if (!IsSyncRequest) - HeartLog.Log("Recieved: " + ToString()); + //if (!IsSyncRequest) + // HeartLog.Log("Recieved: " + ToString()); var weapon = WeaponManager.I.GetWeapon(WeaponEntityId); if (weapon == null) @@ -59,8 +59,8 @@ public override void Received(ulong SenderSteamId) weapon.Settings = this; weapon.Magazines.SelectedAmmoIndex = AmmoLoadedIdx; - HeartLog.Log("UPDATED Id: " + weapon.Magazines.SelectedAmmoId + " | Idx: " + weapon.Magazines.SelectedAmmoIndex); - HeartLog.Log("SHOULD BE Idx: " + AmmoLoadedIdx); + //HeartLog.Log("UPDATED Id: " + weapon.Magazines.SelectedAmmoId + " | Idx: " + weapon.Magazines.SelectedAmmoIndex); + //HeartLog.Log("SHOULD BE Idx: " + AmmoLoadedIdx); if (MyAPIGateway.Session.IsServer) weapon.Settings.Sync(); } diff --git a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/WeaponLogic_Magazines.cs b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/WeaponLogic_Magazines.cs index c4aba64b..26652fb7 100644 --- a/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/WeaponLogic_Magazines.cs +++ b/Orrery Combat Framework - Heart Module/Data/Scripts/HeartModule/Weapons/WeaponLogic_Magazines.cs @@ -1,4 +1,5 @@ -using Heart_Module.Data.Scripts.HeartModule.Projectiles; +using Heart_Module.Data.Scripts.HeartModule.ExceptionHandler; +using Heart_Module.Data.Scripts.HeartModule.Projectiles; using Heart_Module.Data.Scripts.HeartModule.Weapons.StandardClasses; using Sandbox.Game; using System; @@ -28,12 +29,17 @@ public int SelectedAmmoId set { int idx = Array.IndexOf(Definition.Ammos, value); - if (idx == -1 || _selectedAmmo == value) + if (idx == -1) return; _selectedAmmo = value; _selectedAmmoIndex = idx; shotsPerMag = ProjectileDefinitionManager.GetDefinition(SelectedAmmoId).Ungrouped.ShotsPerMagazine; + + if (value == _selectedAmmo) + return; EmptyMagazines(); + + HeartLog.Log("Set Loaded AmmoId: " + SelectedAmmoId + " | IDX " + SelectedAmmoIndex); } } @@ -45,12 +51,17 @@ public int SelectedAmmoIndex } set { - if (Definition.Ammos.Length <= value || value < 0 || _selectedAmmoIndex == value) + if (Definition.Ammos.Length <= value || value < 0) return; _selectedAmmo = ProjectileDefinitionManager.GetId(Definition.Ammos[value]); _selectedAmmoIndex = value; shotsPerMag = ProjectileDefinitionManager.GetDefinition(SelectedAmmoId).Ungrouped.ShotsPerMagazine; + + if (value == _selectedAmmoIndex) + return; EmptyMagazines(); + + HeartLog.Log("Set Loaded AmmoIdx: " + SelectedAmmoId + " | IDX " + SelectedAmmoIndex); } }