From 40d28dd0e6ca723b18cb7470b000e4c9efdeaced Mon Sep 17 00:00:00 2001 From: Tkael Date: Mon, 31 May 2021 23:32:38 -0700 Subject: [PATCH] Fix community goal progress repetition for expired community goals without contributions. --- MissionMonitor/MissionMonitor.cs | 60 ++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/MissionMonitor/MissionMonitor.cs b/MissionMonitor/MissionMonitor.cs index 4166ec6393..b673dedabb 100644 --- a/MissionMonitor/MissionMonitor.cs +++ b/MissionMonitor/MissionMonitor.cs @@ -493,15 +493,15 @@ public void _handleCommunityGoalsEvent(CommunityGoalsEvent @event) // Update missions status foreach (var goal in @event.goals) { - // Find or create our mission + // Find or create our mission (excluding completed goals without contributions) Mission mission = missions.FirstOrDefault(m => m.missionid == goal.cgid); - if (mission == null) + if (mission == null && (!goal.iscomplete || goal.iscomplete && goal.contribution > 0)) { mission = new Mission(goal.cgid, "MISSION_CommunityGoal", goal.expiryDateTime, MissionStatus.FromEDName("Active")); - missions.Add(mission); + AddMission(mission); } - if (!@event.fromLoad) + if (!@event.fromLoad && mission != null) { // Raise events for the notable changes in community goal status. var cgUpdates = new List(); @@ -527,28 +527,28 @@ public void _handleCommunityGoalsEvent(CommunityGoalsEvent @event) { EDDI.Instance.enqueueEvent(new CommunityGoalEvent(DateTime.UtcNow, cgUpdates, goal)); } - } - // Update our mission records - mission.localisedname = goal.name; - mission.originsystem = goal.system; - mission.originstation = goal.station; - mission.destinationsystem = goal.system; - mission.destinationstation = goal.station; - mission.reward = goal.tierreward; - mission.communal = true; - mission.communalPercentileBand = goal.percentileband; - mission.communalTier = goal.tier; - mission.expiry = goal.expiryDateTime; - if (goal.iscomplete) - { - if (goal.contribution > 0) - { - mission.statusDef = MissionStatus.FromEDName("Claim"); - } - else + // Update our mission records + mission.localisedname = goal.name; + mission.originsystem = goal.system; + mission.originstation = goal.station; + mission.destinationsystem = goal.system; + mission.destinationstation = goal.station; + mission.reward = goal.tierreward; + mission.communal = true; + mission.communalPercentileBand = goal.percentileband; + mission.communalTier = goal.tier; + mission.expiry = goal.expiryDateTime; + if (goal.iscomplete) { - RemoveMissionWithMissionId(mission.missionid); + if (goal.contribution > 0) + { + mission.statusDef = MissionStatus.FromEDName("Claim"); + } + else + { + RemoveMissionWithMissionId(mission.missionid); + } } } } @@ -866,8 +866,16 @@ public bool _handleMissionExpiredEvent(MissionExpiredEvent @event) Mission mission = missions.FirstOrDefault(m => m.missionid == @event.missionid); if (mission != null) { - mission.statusDef = MissionStatus.FromEDName("Failed"); - update = true; + if (mission.communal && mission.communalPercentileBand != 100) + { + mission.statusDef = MissionStatus.FromEDName("Claim"); + update = true; + } + else + { + mission.statusDef = MissionStatus.FromEDName("Failed"); + update = true; + } } } return update;