Skip to content

Commit

Permalink
Merge pull request #4117 from IllianiCBT/education_BugFixesWaveTwo
Browse files Browse the repository at this point in the history
Even More Education Module Bug Fixes
  • Loading branch information
Sleet01 authored May 29, 2024
2 parents d1e8e45 + 56f9e8b commit 95d0448
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 80 deletions.
10 changes: 5 additions & 5 deletions MekHQ/resources/mekhq/resources/Education.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ facultySkill.text=Faculty Skill:

#### Payment
insufficientFunds.text=Not enough funds to cover %s's tuition.
payment.text=Tuition fee for 0
payment.text=Tuition fee for %s

#### Name Conjoiner
conjoinerOf.text=of
Expand Down Expand Up @@ -51,7 +51,7 @@ returningFromSchool.text=has begun their return journey, which will take approxi
creche.text=has left their Crèche and is awaiting Sibko assignment.

#### Events
eventAcademyMoved.text=has been moved to 0.
eventAcademyMoved.text=has been moved to %s.
eventDestruction.text='s academy has been destroyed. Luckily, they survived the attack. Tomorrow they will begin their journey back to the unit.
eventDestructionKilled.text='s academy has been destroyed. Sadly, they have been missing ever since the attack.
eventClosure.text='s academy has been suddenly shutdown. Booted off campus, they will begin their journey back to the unit tomorrow.
Expand All @@ -64,11 +64,11 @@ dropOut.text=has dropped out of their education or training. Tomorrow they will
dropOutRejected.text=wanted to drop out of their education or training, but was convinced to stick it out.
graduatedFailed.text=has failed to graduate. Tomorrow they will begin their journey back to the unit.
graduatedBarely.text=has barely graduated. Tomorrow they will begin their journey back to the unit.
graduatedClassNeeded.text=still needs to complete one or more classes, and is unable to graduate. 0 days have been added to their education.
graduated.text=has attended their graduation ceremony %s. Tomorrow they will begin their journey back to the unit.
graduatedClassNeeded.text=still needs to complete one or more classes, and is unable to graduate. %s days have been added to their education.
graduated.text=has attended their graduation ceremony%s. Tomorrow they will begin their journey back to the unit.
graduatedHonors.text=has attended their graduation ceremony%s. They have graduated with honors. Tomorrow they will begin their journey back to the unit.
graduatedHonorsLog.text=with honors
graduatedTop.text=has attended their graduation ceremony0. They have graduated top of their class. Tomorrow they will begin their journey back to the unit.
graduatedTop.text=has attended their graduation ceremony%s. They have graduated top of their class. Tomorrow they will begin their journey back to the unit.
graduatedTopLog.text=top of their class
graduatedMasters.text=has completed their Master's Degree.
graduatedDoctorate.text=has completed their Doctorate.
Expand Down
1 change: 1 addition & 0 deletions MekHQ/resources/mekhq/resources/PersonViewPanel.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ lblInit1.text=<html><nobr><b>Init Bonus:</b></nobr></html>;
lblTough1.text=<html><nobr><b>Toughness:</b></nobr></html>;
lblEducationLevel1.text=<html><nobr><b>Education Level:</b></nobr></html>;
lblEducationDurationDays.text=days
lblEducationTravelDuration.text=%s/%s days (travelling from %s)
lblEducationDurationAge.text=years old
lblEducationTravelTo1.text=<html><nobr><b>Journey to Campus:</b></nobr></html>;
lblEducationDays1.text=<html><nobr><b>Ongoing Education:</b></nobr></html>;
Expand Down
15 changes: 10 additions & 5 deletions MekHQ/src/mekhq/campaign/personnel/education/Academy.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@
import mekhq.campaign.universe.PlanetarySystem;
import mekhq.campaign.universe.RandomFactionGenerator;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.*;

/**
* The Academy class represents an academy with various properties and methods.
Expand Down Expand Up @@ -740,7 +737,15 @@ public Integer getTuitionAdjusted(Person person) {
* @return the faction discount as a double value, between 0.00 and 1.00
*/
public Double getFactionDiscountAdjusted(Campaign campaign, Person person) {
if (locationSystems.stream()
List<String> locations;

if (isLocal) {
locations = Collections.singletonList(campaign.getCurrentSystem().getId());
} else {
locations = locationSystems;
}

if (locations.stream()
.flatMap(campus -> campaign.getSystemById(campus)
.getFactions(campaign.getLocalDate())
.stream())
Expand Down
110 changes: 41 additions & 69 deletions MekHQ/src/mekhq/campaign/personnel/education/EducationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public static void processNewDay(Campaign campaign) {
}

// if we reach this point it means Person is already in transit, so we continue their journey
processJourneyHome(campaign, person, daysOfEducation, daysOfTravelFrom);
processJourneyHome(campaign, person, daysOfTravelFrom);
}
}

Expand Down Expand Up @@ -459,87 +459,61 @@ public static void completeEducation(Campaign campaign, Person person) {
* previous travel days
*/
private static Integer beginJourneyHome(Campaign campaign, Person person, Academy academy, Integer daysOfEducation, ResourceBundle resources) {
int daysOfTravelFrom = person.getEduDaysOfTravelFromAcademy();
int travelTime = 0;

int travelTime;

if ((daysOfEducation == 0) && (daysOfTravelFrom == 0)) {
if ((daysOfEducation == 0) && (person.getEduDaysOfTravelFromAcademy() == 0)) {
if ((academy.isClan()) && (academy.isPrepSchool()) && (person.getAge(campaign.getLocalDate()) < 10)) {
// we do this to deliberately create an infinite loop, where the player is pestered
// daily until the student is assigned to a Sibko
travelTime = 0;
person.setEduDaysOfTravelFromAcademy(travelTime);

campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("creche.text"));

return null;
} else if ((academy.isClan()) && (!academy.isLocal())) {
try {
travelTime = campaign.getSimplifiedTravelTime(campaign.getFaction().getStartingPlanet(campaign, campaign.getLocalDate()));
travelTime = Math.max(2, campaign.getSimplifiedTravelTime(campaign.getFaction().getStartingPlanet(campaign, campaign.getLocalDate())));
} catch (Exception e) {
travelTime = campaign.getSimplifiedTravelTime(campaign.getSystemById("Strana Mechty"));
}

// We use a minimum of 2 days travel to avoid awkward grammar in the report.
// This can be hand waved as being the time it takes for Person to get from campus and
// recover from their education.
if (travelTime < 2) {
travelTime = 2;
travelTime = Math.max(2, campaign.getSimplifiedTravelTime(campaign.getSystemById("Strana Mechty")));
}
} else {
travelTime = campaign.getSimplifiedTravelTime(campaign.getSystemById(person.getEduAcademySystem()));

if (travelTime < 2) {
travelTime = 2;
}
travelTime = Math.max(2, campaign.getSimplifiedTravelTime(campaign.getSystemById(person.getEduAcademySystem())));
}

person.setEduDaysOfTravelFromAcademy(travelTime);

if ((academy.isClan()) && (academy.isPrepSchool()) && (person.getAge(campaign.getLocalDate()) < 10)) {
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("creche.text"));
} else {
campaign.addReport(person.getHyperlinkedName() + ' '
campaign.addReport(person.getHyperlinkedName() + ' '
+ String.format(resources.getString("returningFromSchool.text"), travelTime));
}

person.setEduDaysOfTravelFromAcademy(travelTime);

return null;
}
return daysOfTravelFrom;
return travelTime;
}

/**
* Processes the journey home for a person.
*
* @param campaign the campaign the person is in
* @param person the person whose journey home is being processed
* @param daysOfEducation the number education days remaining
* @param daysOfTravelFrom the number of days it takes for the person to travel from the campaign location to the unit
*/
private static void processJourneyHome(Campaign campaign, Person person, Integer daysOfEducation, Integer daysOfTravelFrom) {
if ((daysOfEducation == 0) && (daysOfTravelFrom > 0)) {
int travelTime = 0;
boolean clanException = false;
private static void processJourneyHome(Campaign campaign, Person person, Integer daysOfTravelFrom) {
int travelTime = 0;

try {
travelTime = campaign.getSimplifiedTravelTime(campaign.getSystemById(person.getEduAcademySystem()));
} catch (Exception e) {
clanException = true;
}
try {
travelTime = Math.max(2, campaign.getSimplifiedTravelTime(campaign.getSystemById(person.getEduAcademySystem())));

if (clanException) {
person.setEduDaysOfTravelFromAcademy(daysOfTravelFrom - 1);
person.setEduDaysOfTravel(person.getEduDaysOfTravel() + 1);
} else {
if (travelTime > daysOfTravelFrom) {
person.setEduDaysOfTravelFromAcademy(travelTime);
} else if (travelTime < daysOfTravelFrom) {
person.setEduDaysOfTravelFromAcademy(travelTime / 2);
person.setEduDaysOfTravel(0);
} else {
person.setEduDaysOfTravelFromAcademy(daysOfTravelFrom - 1);
person.setEduDaysOfTravel(person.getEduDaysOfTravel() + 1);
}
if (travelTime != daysOfTravelFrom) {
person.setEduDaysOfTravelFromAcademy(travelTime);
}

if ((person.getEduDaysOfTravelFromAcademy()) == 0) {
person.changeStatus(campaign, campaign.getLocalDate(), PersonnelStatus.ACTIVE);
}
person.setEduDaysOfTravel(person.getEduDaysOfTravel() + 1);
} catch (Exception e) {
person.setEduDaysOfTravel(person.getEduDaysOfTravel() + 1);
}

if ((travelTime - person.getEduDaysOfTravel()) < 1) {
person.changeStatus(campaign, campaign.getLocalDate(), PersonnelStatus.ACTIVE);
}
}

Expand Down Expand Up @@ -593,15 +567,16 @@ private static void processNewWeekChecks(Campaign campaign, Academy academy, Per

// has the academy been moved alongside the faction capital?
if ((academy.isClan()) && (!academy.isLocal())) {
String location;
PlanetarySystem location;

try {
location = campaign.getFaction().getStartingPlanet(campaign, campaign.getLocalDate()).getId();
location = campaign.getFaction().getStartingPlanet(campaign, campaign.getLocalDate());

if (!person.getEduAcademySystem().equalsIgnoreCase(location)) {
person.setEduAcademySystem(location);
if (!person.getEduAcademySystem().equalsIgnoreCase(location.getId())) {
person.setEduAcademySystem(location.getId());

campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("eventAcademyMoved.text"));
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("eventAcademyMoved.text"),
location.getName(campaign.getLocalDate())));
}
} catch (Exception e) {
// it'll only throw an exception if there isn't a starting planet for the faction,
Expand Down Expand Up @@ -1026,8 +1001,7 @@ private static void graduateAdult(Campaign campaign, Person person, Academy acad
// class resits required
if (graduationRoll < 20) {
roll = Compute.d6(3);
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("graduatedClassNeeded.text")
.replace("0", String.valueOf(roll)));
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("graduatedClassNeeded.text"), roll));

person.setEduDaysOfEducation(roll);

Expand All @@ -1036,8 +1010,8 @@ private static void graduateAdult(Campaign campaign, Person person, Academy acad

if (graduationRoll == 99) {
if (Compute.d6(1) > 5) {
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("graduatedTop.text")
.replace("0", ' ' + resources.getString(graduationEventPicker())));
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("graduatedTop.text"),
' ' + resources.getString(graduationEventPicker())));
} else {
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("graduatedTop.text"));
}
Expand Down Expand Up @@ -1086,8 +1060,7 @@ private static void graduateAdult(Campaign campaign, Person person, Academy acad
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("graduated.text"),
' ' + resources.getString(graduationEventPicker())));
} else {
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("graduated.text")
.replace("0", ""));
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("graduated.text"), ""));
}

ServiceLogger.eduGraduated(person, campaign.getLocalDate(), person.getEduAcademyName());
Expand Down Expand Up @@ -1146,8 +1119,7 @@ private static void graduateChild(Campaign campaign, Person person, Academy acad
}

// default graduation
campaign.addReport(person.getHyperlinkedName() + ' ' + resources.getString("graduated.text")
.replace("0", ""));
campaign.addReport(person.getHyperlinkedName() + ' ' + String.format(resources.getString("graduated.text"), ""));

ServiceLogger.eduGraduated(person, campaign.getLocalDate(), person.getEduAcademyName());

Expand Down Expand Up @@ -1575,7 +1547,7 @@ private static void improveSkills(Campaign campaign, Person person, Academy acad

for (String skill : curriculum) {
if (skill.equalsIgnoreCase("bonus xp")) {
person.awardXP(campaign, Compute.d6(educationLevel));
person.awardXP(campaign, Compute.d6(Math.max(1, educationLevel)));
} else {
String skillParsed = Academy.skillParser(skill);
int bonus;
Expand Down Expand Up @@ -1617,7 +1589,7 @@ private static void addBonus(Campaign campaign, Person person, Academy academy,
.collect(Collectors.toList());

for (int i = 0; i < bonusCount; i++) {
int roll = Compute.randomInt(curriculum.size() - 1);
int roll = Compute.randomInt(curriculum.size());

try {
String skillParsed = Academy.skillParser(curriculum.get(roll));
Expand Down
5 changes: 4 additions & 1 deletion MekHQ/src/mekhq/gui/view/PersonViewPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,10 @@ private JPanel fillSkills() {
pnlSkills.add(lblEducationTravelFrom1, gridBagConstraints);

lblEducationTravelFrom2.setName("lblEducationTravelFrom2");
lblEducationTravelFrom2.setText(String.valueOf(person.getEduDaysOfTravelFromAcademy()) + ' ' + resourceMap.getString("lblEducationDurationDays.text"));
lblEducationTravelFrom2.setText(String.format(resourceMap.getString("lblEducationTravelDuration.text"),
person.getEduDaysOfTravel(),
person.getEduDaysOfTravelFromAcademy(),
campaign.getSystemById(person.getEduAcademySystem()).getName(campaign.getLocalDate())));
lblEducationTravelFrom2.setLabelFor(lblEducationTravelFrom2);
gridBagConstraints = new GridBagConstraints();
gridBagConstraints.gridx = 1;
Expand Down

0 comments on commit 95d0448

Please sign in to comment.