Skip to content

Commit

Permalink
Fix kills not tracking
Browse files Browse the repository at this point in the history
- Weapon was null, causing early return
Fixes #207
  • Loading branch information
Lacyway committed Dec 7, 2024
1 parent 01c56d0 commit 5b959e3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 25 deletions.
30 changes: 5 additions & 25 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart,
return;
}

#if DEBUG
FikaPlugin.Instance.FikaLogger.LogWarning($"HandleTeammateKill: Weapon {(damage.Weapon != null ? damage.Weapon.Name.Localized() : "None")}");
#endif

if (role != WildSpawnType.pmcBEAR)
{
if (role == WildSpawnType.pmcUSEC)
Expand Down Expand Up @@ -813,37 +817,13 @@ public override void OnDead(EDamageType damageType)
{
StartCoroutine(LocalPlayerDied());
}
}

private void FindKillerWeapon()
{
GStruct448<Item> itemResult = FindItemById(lastWeaponId, false, false);
if (!itemResult.Succeeded)
{
foreach (ThrowWeapItemClass grenadeClass in Singleton<IFikaNetworkManager>.Instance.CoopHandler.LocalGameInstance.ThrownGrenades)
{
if (grenadeClass.Id == lastWeaponId)
{
LastDamageInfo.Weapon = grenadeClass;
break;
}
}
return;
}

LastDamageInfo.Weapon = itemResult.Value;
}
}

/// <summary>
/// TODO: Refactor... BSG code makes this difficult
/// </summary>
private void GenerateDogtagDetails()
{
if (LastDamageInfo.Weapon is null && !string.IsNullOrEmpty(lastWeaponId))
{
FindKillerWeapon();
}

string accountId = AccountId;
string profileId = ProfileId;
string nickname = Profile.Nickname;
Expand Down
24 changes: 24 additions & 0 deletions Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,30 @@ public void SetAggressorData(string killerId, EBodyPart bodyPart, string weaponI
}
LastBodyPart = bodyPart;
lastWeaponId = weaponId;

if (LastDamageInfo.Weapon is null && !string.IsNullOrEmpty(lastWeaponId))
{
FindKillerWeapon();
}
}

private void FindKillerWeapon()
{
GStruct448<Item> itemResult = FindItemById(lastWeaponId, false, false);
if (!itemResult.Succeeded)
{
foreach (ThrowWeapItemClass grenadeClass in Singleton<IFikaNetworkManager>.Instance.CoopHandler.LocalGameInstance.ThrownGrenades)
{
if (grenadeClass.Id == lastWeaponId)
{
LastDamageInfo.Weapon = grenadeClass;
break;
}
}
return;
}

LastDamageInfo.Weapon = itemResult.Value;
}

private class RemoveHandsControllerHandler(ObservedCoopPlayer coopPlayer, Callback callback)
Expand Down

0 comments on commit 5b959e3

Please sign in to comment.