From 92439a1aac427b9c1adb3c9075d13222b299e99c Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:25:05 +0100 Subject: [PATCH 1/2] Fix and tweak kill sharing - Converted to method - Fixed broken logic for host player --- Fika.Core/Coop/Players/CoopBot.cs | 29 +-------- Fika.Core/Coop/Players/CoopPlayer.cs | 68 ++++++++++++++++++-- Fika.Core/Coop/Players/ObservedCoopPlayer.cs | 48 +------------- 3 files changed, 67 insertions(+), 78 deletions(-) diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index 2f38635b..469d6e36 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -147,31 +147,8 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct WildSpawnType role = Profile.Info.Settings.Role; bool countAsBoss = role.CountAsBossForStatistics() && !(role is WildSpawnType.pmcUSEC or WildSpawnType.pmcBEAR); int experience = Profile.Info.Settings.Experience; - - if (experience < 0) - { - experience = Singleton.Instance.Experience.Kill.VictimBotLevelExp; - } - - if (FikaPlugin.SharedKillExperience.Value && !countAsBoss) - { - int toReceive = experience / 2; -#if DEBUG - FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared kill XP of {toReceive} from {aggressor.Profile.Nickname}"); -#endif - mainPlayer.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); - mainPlayer.Profile.EftStats.SessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); - } - - if (FikaPlugin.SharedBossExperience.Value && countAsBoss) - { - int toReceive = experience / 2; -#if DEBUG - FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared boss XP of {toReceive} from {aggressor.Profile.Nickname}"); -#endif - mainPlayer.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); - mainPlayer.Profile.EftStats.SessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); - } + SessionCountersClass sessionCounters = mainPlayer.Profile.EftStats.SessionCounters; + HandleSharedExperience(countAsBoss, experience, sessionCounters); if (FikaPlugin.Instance.SharedQuestProgression && FikaPlugin.EasyKillConditions.Value) { @@ -185,7 +162,7 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct (CoopPlayer)aggressor); } } - } + } public override ShotInfoClass ApplyShot(DamageInfoStruct damageInfo, EBodyPart bodyPartType, EBodyPartColliderType colliderType, EArmorPlateCollider armorPlateCollider, ShotIdStruct shotId) { diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index b1064c1b..ce3bc6bc 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -410,7 +410,7 @@ public override void DropCurrentController(Action callback, bool fastDrop, Item } public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct damageInfo, EBodyPart bodyPart, EDamageType lethalDamageType) - { + { base.OnBeenKilledByAggressor(aggressor, damageInfo, bodyPart, lethalDamageType); // Handle 'Help Scav' rep gains @@ -433,6 +433,28 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct } } + protected void FindKillerWeapon() + { +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogWarning($"Finding weapon '{lastWeaponId}'!"); +#endif + GStruct448 itemResult = FindItemById(lastWeaponId, false, false); + if (!itemResult.Succeeded) + { + foreach (ThrowWeapItemClass grenadeClass in Singleton.Instance.CoopHandler.LocalGameInstance.ThrownGrenades) + { + if (grenadeClass.Id == lastWeaponId) + { + LastDamageInfo.Weapon = grenadeClass; + break; + } + } + return; + } + + LastDamageInfo.Weapon = itemResult.Value; + } + public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart, EPlayerSide playerSide, WildSpawnType role, string playerProfileId, float distance, List targetEquipment, @@ -491,6 +513,34 @@ public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart, } } + protected void HandleSharedExperience(bool countAsBoss, int experience, SessionCountersClass sessionCounters) + { + if (experience <= 0) + { + experience = Singleton.Instance.Experience.Kill.VictimBotLevelExp; + } + + if (FikaPlugin.SharedKillExperience.Value && !countAsBoss) + { + int toReceive = experience / 2; +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared kill XP of {toReceive}"); +#endif + sessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); + sessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); + } + + if (FikaPlugin.SharedBossExperience.Value && countAsBoss) + { + int toReceive = experience / 2; +#if DEBUG + FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared boss XP of {toReceive}"); +#endif + sessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); + sessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); + } + } + #if DEBUG public override void ShowStringNotification(string message) { @@ -801,6 +851,16 @@ public HealthSyncPacket SetupCorpseSyncPacket(NetworkHealthSyncPacketStruct pack public override void OnDead(EDamageType damageType) { + if (LastDamageInfo.Weapon == null && !string.IsNullOrEmpty(lastWeaponId)) + { + FindKillerWeapon(); +#if DEBUG + if (LastDamageInfo.Weapon != null) + { + FikaPlugin.Instance.FikaLogger.LogWarning($"Found weapon '{LastDamageInfo.Weapon.Name.Localized()}'!"); + } +#endif + } base.OnDead(damageType); PacketSender.Enabled = false; if (IsYourPlayer) @@ -1243,12 +1303,6 @@ public virtual void HandleDamagePacket(ref DamagePacket packet) } } } - - /*// TODO: Fix this and consistently get the correct data... - if (Singleton.Instance.GetAlivePlayerByProfileID(packet.ProfileId).HandsController.Item is Weapon weapon) - { - damageInfo.Weapon = weapon; - }*/ lastWeaponId = packet.WeaponId; } diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index cc9f05c2..92d3a2d1 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -926,31 +926,8 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct WildSpawnType role = Profile.Info.Settings.Role; bool countAsBoss = role.CountAsBossForStatistics() && !(role is WildSpawnType.pmcUSEC or WildSpawnType.pmcBEAR); int experience = Profile.Info.Settings.Experience; - - if (experience < 0) - { - experience = Singleton.Instance.Experience.Kill.VictimBotLevelExp; - } - - if (FikaPlugin.SharedKillExperience.Value && !countAsBoss) - { - int toReceive = experience / 2; -#if DEBUG - FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared kill XP of {toReceive} from {aggressor.Profile.Nickname}"); -#endif - mainPlayer.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); - mainPlayer.Profile.EftStats.SessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); - } - - if (FikaPlugin.SharedBossExperience.Value && countAsBoss) - { - int toReceive = experience / 2; -#if DEBUG - FikaPlugin.Instance.FikaLogger.LogInfo($"Received shared boss XP of {toReceive} from {aggressor.Profile.Nickname}"); -#endif - mainPlayer.Profile.EftStats.SessionCounters.AddLong(1L, SessionCounterTypesAbstractClass.Kills); - mainPlayer.Profile.EftStats.SessionCounters.AddInt(toReceive, SessionCounterTypesAbstractClass.ExpKillBase); - } + SessionCountersClass sessionCounters = mainPlayer.Profile.EftStats.SessionCounters; + HandleSharedExperience(countAsBoss, experience, sessionCounters); if (FikaPlugin.Instance.SharedQuestProgression && FikaPlugin.EasyKillConditions.Value) { @@ -1590,26 +1567,7 @@ public void SetAggressorData(string killerId, EBodyPart bodyPart, string weaponI { FindKillerWeapon(); } - } - - private void FindKillerWeapon() - { - GStruct448 itemResult = FindItemById(lastWeaponId, false, false); - if (!itemResult.Succeeded) - { - foreach (ThrowWeapItemClass grenadeClass in Singleton.Instance.CoopHandler.LocalGameInstance.ThrownGrenades) - { - if (grenadeClass.Id == lastWeaponId) - { - LastDamageInfo.Weapon = grenadeClass; - break; - } - } - return; - } - - LastDamageInfo.Weapon = itemResult.Value; - } + } private class RemoveHandsControllerHandler(ObservedCoopPlayer coopPlayer, Callback callback) { From e33c9cc218d4935dd7b98d3c873154860873024d Mon Sep 17 00:00:00 2001 From: Lacyway <20912169+Lacyway@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:25:58 +0100 Subject: [PATCH 2/2] Cleanup --- .../Coop/Patches/Class1374_ReloadBackendLocale_Patch.cs | 2 +- Fika.Core/Coop/Players/CoopBot.cs | 2 +- Fika.Core/Coop/Players/CoopPlayer.cs | 6 +++--- Fika.Core/Coop/Players/ObservedCoopPlayer.cs | 2 +- Fika.Core/Networking/FikaClient.cs | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Fika.Core/Coop/Patches/Class1374_ReloadBackendLocale_Patch.cs b/Fika.Core/Coop/Patches/Class1374_ReloadBackendLocale_Patch.cs index 174c40b9..2c68e932 100644 --- a/Fika.Core/Coop/Patches/Class1374_ReloadBackendLocale_Patch.cs +++ b/Fika.Core/Coop/Patches/Class1374_ReloadBackendLocale_Patch.cs @@ -15,7 +15,7 @@ protected override MethodBase GetTargetMethod() [PatchPostfix] public static void Postfix(Task __result) - { + { if (!HasBeenSet) { FikaPlugin.Instance.StartCoroutine(FikaPlugin.Instance.WaitForLocales(__result)); diff --git a/Fika.Core/Coop/Players/CoopBot.cs b/Fika.Core/Coop/Players/CoopBot.cs index 469d6e36..acabc5c4 100644 --- a/Fika.Core/Coop/Players/CoopBot.cs +++ b/Fika.Core/Coop/Players/CoopBot.cs @@ -162,7 +162,7 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct (CoopPlayer)aggressor); } } - } + } public override ShotInfoClass ApplyShot(DamageInfoStruct damageInfo, EBodyPart bodyPartType, EBodyPartColliderType colliderType, EArmorPlateCollider armorPlateCollider, ShotIdStruct shotId) { diff --git a/Fika.Core/Coop/Players/CoopPlayer.cs b/Fika.Core/Coop/Players/CoopPlayer.cs index ce3bc6bc..97c5148e 100644 --- a/Fika.Core/Coop/Players/CoopPlayer.cs +++ b/Fika.Core/Coop/Players/CoopPlayer.cs @@ -410,7 +410,7 @@ public override void DropCurrentController(Action callback, bool fastDrop, Item } public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct damageInfo, EBodyPart bodyPart, EDamageType lethalDamageType) - { + { base.OnBeenKilledByAggressor(aggressor, damageInfo, bodyPart, lethalDamageType); // Handle 'Help Scav' rep gains @@ -436,7 +436,7 @@ public override void OnBeenKilledByAggressor(IPlayer aggressor, DamageInfoStruct protected void FindKillerWeapon() { #if DEBUG - FikaPlugin.Instance.FikaLogger.LogWarning($"Finding weapon '{lastWeaponId}'!"); + FikaPlugin.Instance.FikaLogger.LogWarning($"Finding weapon '{lastWeaponId}'!"); #endif GStruct448 itemResult = FindItemById(lastWeaponId, false, false); if (!itemResult.Succeeded) @@ -466,7 +466,7 @@ public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart, } #if DEBUG - FikaPlugin.Instance.FikaLogger.LogWarning($"HandleTeammateKill: Weapon {(damage.Weapon != null ? damage.Weapon.Name.Localized() : "None")}"); + FikaPlugin.Instance.FikaLogger.LogWarning($"HandleTeammateKill: Weapon {(damage.Weapon != null ? damage.Weapon.Name.Localized() : "None")}"); #endif if (role != WildSpawnType.pmcBEAR) diff --git a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs index 92d3a2d1..2628962a 100644 --- a/Fika.Core/Coop/Players/ObservedCoopPlayer.cs +++ b/Fika.Core/Coop/Players/ObservedCoopPlayer.cs @@ -1567,7 +1567,7 @@ public void SetAggressorData(string killerId, EBodyPart bodyPart, string weaponI { FindKillerWeapon(); } - } + } private class RemoveHandsControllerHandler(ObservedCoopPlayer coopPlayer, Callback callback) { diff --git a/Fika.Core/Networking/FikaClient.cs b/Fika.Core/Networking/FikaClient.cs index d9816773..9b585076 100644 --- a/Fika.Core/Networking/FikaClient.cs +++ b/Fika.Core/Networking/FikaClient.cs @@ -214,7 +214,7 @@ private void OnLoadingProfilePacketReceived(LoadingProfilePacket packet) if (packet.Profiles != null) { #if DEBUG - logger.LogWarning($"OnLoadingProfilePacketReceived: Received {packet.Profiles.Count} profiles"); + logger.LogWarning($"OnLoadingProfilePacketReceived: Received {packet.Profiles.Count} profiles"); #endif FikaBackendUtils.AddPartyMembers(packet.Profiles); return;