Skip to content

Commit

Permalink
Fix community goal progress repetition for expired community goals wi…
Browse files Browse the repository at this point in the history
…thout contributions.
  • Loading branch information
Tkael committed Jun 1, 2021
1 parent 40e9789 commit 40d28dd
Showing 1 changed file with 34 additions and 26 deletions.
60 changes: 34 additions & 26 deletions MissionMonitor/MissionMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<CGUpdate>();
Expand All @@ -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);
}
}
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 40d28dd

Please sign in to comment.