Skip to content

Commit

Permalink
Fixed logic error assigning incorrect ammos to weapons
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 26, 2024
1 parent 2db4fbd commit 0058d1a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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)
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down

0 comments on commit 0058d1a

Please sign in to comment.