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

Added Prisoner Ransom & Free Prompts to Mission Completion #4469

Merged
merged 3 commits into from
Jul 23, 2024
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
3 changes: 2 additions & 1 deletion MekHQ/resources/mekhq/resources/GUI.properties
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,15 @@ gained.format=%s gained %s!
confirmRetireQ.format=Do you really want to change the status of %s to a non-active status?
numPrisoners.text=%d prisoners
freeQ.text=Free?
confirmFree.format=Do you really want to set %s free?
confirmFree.format=Do you want to set %s free?
executeQ.text=Execute?
confirmExecute.format=Do you really want to execute %s? This will prompt %s loyalty change rolls.
executeLoyaltyChange.text=A round of executions has prompted everyone to reconsider their loyalties.
jettisonQ.text=Jettison?
confirmJettison.format=Do you really want to push %s out an airlock? This will prompt %s loyalty change rolls.
jettisonLoyaltyChange.text=Seeing prisoners floating into the void has prompted everyone to greatly reconsider their loyalties.
ransomQ.format=Ransom %d prisoners for %s?
ransomFriendlyQ.format=Ransom friendly %d prisoners for %s?
ransom.text=Ransom
ransomReport.format=%d prisoners have been ransomed for %s.
unableToRansom.format=Insufficient funds. Unable to ransom %d prisoners for %s.
Expand Down
10 changes: 10 additions & 0 deletions MekHQ/src/mekhq/campaign/Campaign.java
Original file line number Diff line number Diff line change
Expand Up @@ -1763,6 +1763,16 @@ public List<Person> getCurrentPrisoners() {
.collect(Collectors.toList());
}

/**
* Provides a filtered list of personnel including only friendly PoWs.
* @return a {@link Person} <code>List</code> containing all active personnel
*/
public List<Person> getFriendlyPrisoners() {
return getPersonnel().stream()
.filter(p -> p.getStatus().isPoW())
.collect(Collectors.toList());
}

/**
* Provides a filtered list of personnel including only Persons with the AWOL status.
* @return a {@link Person} <code>List</code> containing all active personnel
Expand Down
127 changes: 122 additions & 5 deletions MekHQ/src/mekhq/gui/BriefingTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.io.File;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;

import static megamek.client.ratgenerator.ForceDescriptor.RATING_5;

Expand Down Expand Up @@ -345,7 +346,11 @@ private void editMission() {
}

private void completeMission() {
ResourceBundle resources = ResourceBundle.getBundle("mekhq.resources.GUI",
MekHQ.getMHQOptions().getLocale());

final Mission mission = comboMission.getSelectedItem();

if (mission == null) {
return;
} else if (mission.hasPendingScenarios()) {
Expand All @@ -370,8 +375,61 @@ private void completeMission() {
}
}

if (getCampaign().getCampaignOptions().isUseRandomRetirement()
&& getCampaign().getCampaignOptions().isUseContractCompletionRandomRetirement()) {
getCampaign().completeMission(mission, status);
MekHQ.triggerEvent(new MissionCompletedEvent(mission));

// resolve friendly PoW ransoming
// this needs to be before turnover and autoAwards so friendly PoWs can be factored into those events
if (getCampaign().getCampaignOptions().isUseAtBPrisonerRansom()) {
List<Person> alliedPoWs = getCampaign().getFriendlyPrisoners();

if (!alliedPoWs.isEmpty()) {
Money total = alliedPoWs.stream()
.map(person -> person.getRansomValue(getCampaign()))
.reduce(Money.zero(), Money::plus);

String message;
int dialogOption;

if (getCampaign().getFunds().isLessThan(total)) {
message = String.format(resources.getString("unableToRansom.format"), alliedPoWs.size(), total.toAmountAndSymbolString());
dialogOption = JOptionPane.OK_CANCEL_OPTION;
} else {
message = String.format(resources.getString("ransomFriendlyQ.format"), alliedPoWs.size(), total.toAmountAndSymbolString());
dialogOption = JOptionPane.YES_NO_CANCEL_OPTION;
}

int optionSelected = JOptionPane.showConfirmDialog(
null,
message,
resources.getString("ransom.text"),
dialogOption
);

if (optionSelected != JOptionPane.OK_OPTION && getCampaign().getFunds().isLessThan(total)) {
return;
}

switch (optionSelected) {
case JOptionPane.YES_OPTION -> {
getCampaign().addReport(String.format(resources.getString("ransomReport.format"),
alliedPoWs.size(), total.toAmountAndSymbolString()));
getCampaign().removeFunds(TransactionType.RANSOM, total, resources.getString("ransom.text"));
alliedPoWs.forEach(ally -> ally.changeStatus(getCampaign(), getCampaign().getLocalDate(), PersonnelStatus.ACTIVE));
}

case JOptionPane.NO_OPTION, JOptionPane.CANCEL_OPTION -> {}

default -> {
return;
}
}
}
}

// resolve turnover
if ((getCampaign().getCampaignOptions().isUseRandomRetirement())
&& (getCampaign().getCampaignOptions().isUseContractCompletionRandomRetirement())) {
RetirementDefectionDialog rdd = new RetirementDefectionDialog(getCampaignGui(), mission, true);
rdd.setLocation(rdd.getLocation().x, 0);
rdd.setVisible(true);
Expand Down Expand Up @@ -403,14 +461,13 @@ && getCampaign().getFinances().getBalance().isGreaterOrEqualThan(rdd.totalPayout
}
}

getCampaign().completeMission(mission, status);
MekHQ.triggerEvent(new MissionCompletedEvent(mission));

// resolve bonus parts exchange
if (getCampaign().getCampaignOptions().isUseAtB() && (mission instanceof AtBContract)) {
((AtBContract) mission).checkForFollowup(getCampaign());
bonusPartExchange((AtBContract) mission);
}

// prompt autoAwards ceremony
if (getCampaign().getCampaignOptions().isEnableAutoAwards()) {
AutoAwardsController autoAwardsController = new AutoAwardsController();

Expand All @@ -419,6 +476,66 @@ && getCampaign().getFinances().getBalance().isGreaterOrEqualThan(rdd.totalPayout
Objects.equals(String.valueOf(cmd.getStatus()), "Success"));
}

// prompt enemy prisoner ransom & freeing
// this should always be placed after autoAwards, so that prisoners are not factored into autoAwards
if (getCampaign().getCampaignOptions().isUseAtBPrisonerRansom()) {
List<Person> prisoners = getCampaign().getCurrentPrisoners();

if (!prisoners.isEmpty()) {
Money total = Money.zero();
total = total.plus(prisoners.stream()
.map(person -> person.getRansomValue(getCampaign()))
.collect(Collectors.toList()));

int optionSelected = JOptionPane.showConfirmDialog(
null,
String.format(resources.getString("ransomQ.format"),
prisoners.size(),
total.toAmountAndSymbolString()),
resources.getString("ransom.text"),
JOptionPane.YES_NO_CANCEL_OPTION);

switch (optionSelected) {
case JOptionPane.YES_OPTION -> {
getCampaign().addReport(String.format(resources.getString("ransomReport.format"),
prisoners.size(),
total.toAmountAndSymbolString()));
getCampaign().addFunds(TransactionType.RANSOM,
total,
resources.getString("ransom.text"));
prisoners.forEach(prisoner -> getCampaign().removePerson(prisoner, false));
}
case JOptionPane.NO_OPTION -> {}
default -> {
return;
}
}
}
}

List<Person> prisoners = getCampaign().getCurrentPrisoners();

if (!prisoners.isEmpty()) {
String title = (prisoners.size() == 1) ? prisoners.get(0).getFullTitle()
: String.format(resources.getString("numPrisoners.text"), prisoners.size());
int option = JOptionPane.showConfirmDialog(null,
String.format(resources.getString("confirmFree.format"), title),
resources.getString("freeQ.text"),
JOptionPane.YES_NO_CANCEL_OPTION);

switch (option) {
case JOptionPane.YES_OPTION -> {
for (Person prisoner : prisoners) {
getCampaign().removePerson(prisoner);
}
}
case JOptionPane.NO_OPTION -> {}
default -> {
return;
}
}
}

final List<Mission> missions = getCampaign().getSortedMissions();
comboMission.setSelectedItem(missions.isEmpty() ? null : missions.get(0));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ public void actionPerformed(ActionEvent action) {

if (0 == JOptionPane.showConfirmDialog(
null,
String.format(resources.getString("ransomQ.format"), people.length, total.toAmountAndSymbolString()),
String.format(resources.getString("ransomFriendlyQ.format"), people.length, total.toAmountAndSymbolString()),
resources.getString("ransom.text"),
JOptionPane.YES_NO_OPTION)) {
gui.getCampaign().addReport(String.format(resources.getString("ransomReport.format"),
Expand Down