From 3969543cde5731c3fc5d89e30d514d9868ef5b1f Mon Sep 17 00:00:00 2001 From: ScrawnyRonnie Date: Mon, 20 Jan 2025 10:41:15 -0500 Subject: [PATCH] fix resecure reward --- .../local/support/HackCaptureActor.scala | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/main/scala/net/psforever/services/local/support/HackCaptureActor.scala b/src/main/scala/net/psforever/services/local/support/HackCaptureActor.scala index 1a88b0e0..d561cd75 100644 --- a/src/main/scala/net/psforever/services/local/support/HackCaptureActor.scala +++ b/src/main/scala/net/psforever/services/local/support/HackCaptureActor.scala @@ -106,7 +106,7 @@ class HackCaptureActor extends Actor { NotifyHackStateChange(target, isResecured = true) building.Participation.RewardFacilityCapture( target.Faction, - faction, + HackCaptureActor.GetAttackingFaction(building, faction), hacker, facilityHackTime, hackTime, @@ -347,6 +347,30 @@ object HackCaptureActor { .get } + def GetAttackingFaction( + building: Building, + excludeThisFaction: PlanetSideEmpire.Value + ): PlanetSideEmpire.Value = { + // Use PlayerContributionRaw to calculate attacking faction + val factionEfforts = building.Participation + .PlayerContributionRaw + .values + .foldLeft(Array.fill(4)(0L)) { case (efforts, (player, duration, _)) => + val factionId = player.Faction.id + efforts.update(factionId, efforts(factionId) + duration) + efforts + } + + // Exclude the specified faction + factionEfforts.update(excludeThisFaction.id, Long.MinValue) + + // Find the faction with the highest contribution + factionEfforts.indices + .maxByOption(factionEfforts) + .map(PlanetSideEmpire.apply) + .getOrElse(PlanetSideEmpire.NEUTRAL) + } + def GetHackingFaction(terminal: CaptureTerminal): Option[PlanetSideEmpire.Value] = { terminal.HackedBy.map { a => a.player.Faction } }