Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Post-Scenario Tracking System's Handling of Multiple Personnel in autoAwards #4104

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 15 additions & 7 deletions MekHQ/src/mekhq/campaign/ResolveScenarioTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -1432,20 +1432,28 @@ public void resolveScenario(ScenarioStatus resolution, String report) {
if (status.toRemove()) {
getCampaign().removePerson(person, false);
}
}

if (getCampaign().getCampaignOptions().isEnableAutoAwards()) {
if (!person.getStatus().isDead() || getCampaign().getCampaignOptions().isIssuePosthumousAwards()) {
int injuryCount = 0;
if (getCampaign().getCampaignOptions().isEnableAutoAwards()) {
HashMap<UUID, Integer> personnel = new HashMap<>();

for (UUID personId : peopleStatus.keySet()) {
Person person = campaign.getPerson(personId);
PersonStatus status = peopleStatus.get(personId);
int injuryCount = 0;

if (!person.getStatus().isDead() || getCampaign().getCampaignOptions().isIssuePosthumousAwards()) {
if (status.getHits() > person.getHits()) {
injuryCount = status.getHits() - person.getHits();
}

AutoAwardsController autoAwardsController = new AutoAwardsController();

autoAwardsController.PostScenarioController(campaign, scenario.getId(), person.getId(), injuryCount);
}

personnel.put(personId, injuryCount);
}

AutoAwardsController autoAwardsController = new AutoAwardsController();

autoAwardsController.PostScenarioController(campaign, scenario.getId(), personnel);
}

//region Prisoners
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekhq.campaign.personnel.autoAwards;

import megamek.common.annotations.Nullable;
import mekhq.campaign.Campaign;
import mekhq.campaign.Kill;
import mekhq.campaign.mission.AtBContract;
Expand Down Expand Up @@ -92,28 +91,22 @@ public void PostMissionController(Campaign c, Mission m, Boolean missionWasSucce
*
* @param c the campaign to be processed
* @param scenarioId id number for the Scenario just concluded
* @param person the person to check award eligibility for
* @param injuryCount the number of Hits sustained in the Scenario just concluded
* @param personnel the people to check award eligibility for and their injury counts
*/
public void PostScenarioController(Campaign c, int scenarioId, UUID person, int injuryCount) {
public void PostScenarioController(Campaign c, int scenarioId, HashMap<UUID, Integer> personnel) {
LogManager.getLogger().info("autoAwards (Scenario Conclusion) has started");

campaign = c;

// we convert a person into a Collection, as it allows us to use InjuryAwardsManager
// outside of this function
Collection<UUID> personnel = new ArrayList<>();
personnel.add(person);

buildAwardLists(2);

Map<Integer, Map<Integer, List<Object>>> allAwardData = new HashMap<>();
Map<Integer, List<Object>> processedData;
int allAwardDataKey = 0;

// beginning the processing of Injury Awards
if ((injuryCount > 0) && (!injuryAwards.isEmpty())) {
processedData = InjuryAwardsManager(personnel, injuryCount);
if (!injuryAwards.isEmpty()) {
processedData = InjuryAwardsManager(personnel);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
Expand All @@ -122,20 +115,17 @@ public void PostScenarioController(Campaign c, int scenarioId, UUID person, int
}

// beginning the processing & filtering of Kill (Scenario) Awards
List<Kill> kills = campaign.getKillsFor(campaign.getPerson(person).getId());
kills.removeIf(kill -> kill.getScenarioId() != scenarioId);

if ((!kills.isEmpty()) && (!killAwards.isEmpty())) {
processedData = ScenarioKillAwardsManager(personnel, kills);
if (!killAwards.isEmpty()) {
processedData = ScenarioKillAwardsManager(new ArrayList<>(personnel.keySet()), scenarioId);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
}
}

// beginning the processing & filtering of Misc Awards
if ((injuryCount > 0) && (!kills.isEmpty()) && (!miscAwards.isEmpty())) {
processedData = MiscAwardsManager(personnel, false, kills.size(), injuryCount);
if (!miscAwards.isEmpty()) {
processedData = MiscAwardsManager(personnel, false, scenarioId);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
Expand Down Expand Up @@ -487,7 +477,15 @@ private void ProcessAwards(Collection<UUID> personnel, Boolean missionWasSuccess
}

if (!miscAwards.isEmpty()) {
processedData = MiscAwardsManager(personnel, missionWasSuccessful, null, null);
// we need to use a map when accessing post-scenario,
// so we need to convert to a map here
HashMap<UUID, Integer> personnelMap = new HashMap<>();

for (UUID person : personnel) {
personnelMap.put(person, 0);
}

processedData = MiscAwardsManager(personnelMap, missionWasSuccessful, -1);

if (processedData != null) {
allAwardData.put(allAwardDataKey, processedData);
Expand Down Expand Up @@ -627,15 +625,15 @@ private Map<Integer, List<Object>> FactionHunterAwardsManager(Collection<UUID> p
*
* @param personnel the personnel to be processed
*/
private Map<Integer, List<Object>> InjuryAwardsManager(Collection<UUID> personnel, int injuryCount) {
private Map<Integer, List<Object>> InjuryAwardsManager(HashMap<UUID, Integer> personnel) {
Map<Integer, List<Object>> awardData = new HashMap<>();
int awardDataKey = 0;

for (UUID person : personnel) {
for (UUID person : personnel.keySet()) {
Map<Integer, List<Object>> data;

try {
data = InjuryAwards.InjuryAwardsProcessor(campaign, person, injuryAwards, injuryCount);
data = InjuryAwards.InjuryAwardsProcessor(campaign, person, injuryAwards, personnel.get(person));
} catch (Exception e) {
data = null;
LogManager.getLogger().info("{} is not eligible for any Injury Awards.", campaign.getPerson(person).getFullName());
Expand Down Expand Up @@ -696,13 +694,18 @@ private Map<Integer, List<Object>> KillAwardsManager(Collection<UUID> personnel)
* This is the manager for this type of award, processing eligibility and preparing awardData
*
* @param personnel the personnel to be processed
* @param scenarioId the scenario just completed
*/
private Map<Integer, List<Object>> ScenarioKillAwardsManager(Collection<UUID> personnel, List<Kill> kills) {
private Map<Integer, List<Object>> ScenarioKillAwardsManager(List<UUID> personnel, int scenarioId) {
Map<Integer, List<Object>> awardData = new HashMap<>();
int awardDataKey = 0;

for (UUID person : personnel) {
Map<Integer, List<Object>> data;

List<Kill> kills = campaign.getKillsFor(campaign.getPerson(person).getId());
kills.removeIf(kill -> kill.getScenarioId() != scenarioId);

try {
data = ScenarioKillAwards.ScenarioKillAwardsProcessor(campaign, person, killAwards, kills);
} catch (Exception e) {
Expand Down Expand Up @@ -732,19 +735,24 @@ private Map<Integer, List<Object>> ScenarioKillAwardsManager(Collection<UUID> pe
*
* @param personnel the collection of personnel to be processed for awards
* @param missionWasSuccessful a boolean indicating if the mission was successful
* @param killCount an optional parameter specifying the kill count
* @param injuryCount an optional parameter specifying the injury count
* @param scenarioId the scenario just completed, or -1 if autoAwards was not triggered by scenario completion
* @return a map containing the award data, or null if no awards are applicable
*/
private Map<Integer, List<Object>> MiscAwardsManager(Collection<UUID> personnel, boolean missionWasSuccessful,
@Nullable Integer killCount, @Nullable Integer injuryCount) {
private Map<Integer, List<Object>> MiscAwardsManager(HashMap<UUID, Integer> personnel, boolean missionWasSuccessful, int scenarioId) {
Map<Integer, List<Object>> awardData = new HashMap<>();
int awardDataKey = 0;

for (UUID person : personnel) {
for (UUID person : personnel.keySet()) {
Map<Integer, List<Object>> data;
List<Kill> kills = new ArrayList<>();

if (scenarioId != -1) {
kills = campaign.getKillsFor(campaign.getPerson(person).getId());
kills.removeIf(kill -> kill.getScenarioId() != scenarioId);
}

try {
data = MiscAwards.MiscAwardsProcessor(campaign, mission, person, miscAwards, missionWasSuccessful, killCount, injuryCount);
data = MiscAwards.MiscAwardsProcessor(campaign, mission, person, miscAwards, missionWasSuccessful, kills.size(), personnel.get(person));
} catch (Exception e) {
data = null;
LogManager.getLogger().info("{} is not eligible for any Misc Awards.", campaign.getPerson(person).getFullName());
Expand Down
Loading