Skip to content

Commit

Permalink
Merge pull request #227 from project-fika/fix-and-tweak-kill-sharing
Browse files Browse the repository at this point in the history
Fix and tweak kill sharing
  • Loading branch information
Lacyway authored Dec 12, 2024
2 parents 9ffda62 + e33c9cc commit 60d1049
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected override MethodBase GetTargetMethod()

[PatchPostfix]
public static void Postfix(Task __result)
{
{
if (!HasBeenSet)
{
FikaPlugin.Instance.StartCoroutine(FikaPlugin.Instance.WaitForLocales(__result));
Expand Down
27 changes: 2 additions & 25 deletions Fika.Core/Coop/Players/CoopBot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BackendConfigSettingsClass>.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)
{
Expand Down
68 changes: 61 additions & 7 deletions Fika.Core/Coop/Players/CoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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;
}

public void HandleTeammateKill(ref DamageInfoStruct damage, EBodyPart bodyPart,
EPlayerSide playerSide, WildSpawnType role, string playerProfileId,
float distance, List<string> targetEquipment,
Expand All @@ -444,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)
Expand Down Expand Up @@ -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<BackendConfigSettingsClass>.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)
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1243,12 +1303,6 @@ public virtual void HandleDamagePacket(ref DamagePacket packet)
}
}
}

/*// TODO: Fix this and consistently get the correct data...
if (Singleton<GameWorld>.Instance.GetAlivePlayerByProfileID(packet.ProfileId).HandsController.Item is Weapon weapon)
{
damageInfo.Weapon = weapon;
}*/
lastWeaponId = packet.WeaponId;
}

Expand Down
46 changes: 2 additions & 44 deletions Fika.Core/Coop/Players/ObservedCoopPlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<BackendConfigSettingsClass>.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)
{
Expand Down Expand Up @@ -1592,25 +1569,6 @@ public void SetAggressorData(string killerId, EBodyPart bodyPart, string weaponI
}
}

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)
{
private readonly ObservedCoopPlayer coopPlayer = coopPlayer;
Expand Down
2 changes: 1 addition & 1 deletion Fika.Core/Networking/FikaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 60d1049

Please sign in to comment.