Skip to content

Commit

Permalink
let me tell you how much I've come to
Browse files Browse the repository at this point in the history
  • Loading branch information
ari-steas committed Feb 28, 2024
1 parent 41476e0 commit 36dd8e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ internal class n_MagazineUpdate : PacketBase
[ProtoMember(1)] internal long WeaponEntityId;
[ProtoMember(2)] internal int MillisecondsFromMidnight;
[ProtoMember(3)] internal int MagazinesLoaded;
[ProtoMember(4)] internal short NextMuzzleIdx;

public override void Received(ulong SenderSteamId)
{
var magazine = WeaponManager.I.GetWeapon(WeaponEntityId)?.Magazines;
var weapon = WeaponManager.I.GetWeapon(WeaponEntityId);
var magazine = weapon?.Magazines;
if (magazine == null)
return;

Expand All @@ -27,6 +29,8 @@ public override void Received(ulong SenderSteamId)
magazine.MagazinesLoaded = MagazinesLoaded;
magazine.UpdateReload(timeDelta);

weapon.NextMuzzleIdx = NextMuzzleIdx;

HeartLog.Log($"Magazine updated for weapon {WeaponEntityId}! Delta: " + timeDelta);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Heart_Module.Data.Scripts.HeartModule.Projectiles;
using Heart_Module.Data.Scripts.HeartModule.Weapons.StandardClasses;
using Sandbox.Game;
using Sandbox.ModAPI;
using System;
using VRage.Game;
using VRage.Game.ModAPI;
Expand Down Expand Up @@ -159,12 +160,16 @@ public void UseShot(Vector3D muzzlePos)
if (ShotsInMag % shotsPerMag == 0)
{
MagazinesLoaded--;
HeartData.I.Net.SendToEveryoneInSync(new n_MagazineUpdate()
if (MyAPIGateway.Session.IsServer)
{
WeaponEntityId = Weapon.SorterWep.EntityId,
MillisecondsFromMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds,
MagazinesLoaded = MagazinesLoaded,
}, Weapon.SorterWep.GetPosition());
HeartData.I.Net.SendToEveryoneInSync(new n_MagazineUpdate()
{
WeaponEntityId = Weapon.SorterWep.EntityId,
MillisecondsFromMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds,
MagazinesLoaded = MagazinesLoaded,
NextMuzzleIdx = (short)Weapon.NextMuzzleIdx,
}, Weapon.SorterWep.GetPosition());
}

if (!string.IsNullOrEmpty(DefinitionAudio.ReloadSound))
{
Expand All @@ -173,18 +178,22 @@ public void UseShot(Vector3D muzzlePos)
}
}

public void EmptyMagazines()
public void EmptyMagazines(bool doSync = false)
{
ShotsInMag = 0;
MagazinesLoaded = 0;
NextReloadTime = Definition.ReloadTime;

HeartData.I.Net.SendToEveryoneInSync(new n_MagazineUpdate()
if (MyAPIGateway.Session.IsServer || doSync)
{
WeaponEntityId = Weapon.SorterWep.EntityId,
MillisecondsFromMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds,
MagazinesLoaded = MagazinesLoaded,
}, Weapon.SorterWep.GetPosition());
HeartData.I.Net.SendToEveryoneInSync(new n_MagazineUpdate()
{
WeaponEntityId = Weapon.SorterWep.EntityId,
MillisecondsFromMidnight = (int)DateTime.UtcNow.TimeOfDay.TotalMilliseconds,
MagazinesLoaded = MagazinesLoaded,
NextMuzzleIdx = (short)Weapon.NextMuzzleIdx,
}, Weapon.SorterWep.GetPosition());
}
}
}
}

0 comments on commit 36dd8e3

Please sign in to comment.