Skip to content

Commit

Permalink
Merge pull request #2832 from Windchild292/dev_Windchild_2496
Browse files Browse the repository at this point in the history
2496: Maintenance Properly Includes Unofficial SPAs
  • Loading branch information
Windchild292 authored Sep 29, 2021
2 parents 070f6c4 + 54760a3 commit 8c73408
Showing 1 changed file with 82 additions and 57 deletions.
139 changes: 82 additions & 57 deletions MekHQ/src/mekhq/campaign/parts/Part.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.StringJoiner;
import java.util.UUID;

import megamek.common.options.OptionsConstants;
import megamek.common.util.EncodeControl;
import mekhq.campaign.finances.Money;

Expand Down Expand Up @@ -935,103 +936,127 @@ public boolean canChangeWorkMode() {
}

@Override
public TargetRoll getAllMods(Person tech) {
public TargetRoll getAllMods(final @Nullable Person tech) {
int difficulty = getDifficulty();

if (isOmniPodded() && (isSalvaging() || this instanceof MissingPart)
&& (null != unit) && !(unit.getEntity() instanceof Tank)) {
if (isOmniPodded() && (isSalvaging() || (this instanceof MissingPart))
&& (getUnit() != null) && !(getUnit().getEntity() instanceof Tank)) {
difficulty -= 2;
}

if (null == mode) {
mode = WorkTime.NORMAL;
if (getMode() == null) {
resetModeToNormal();
}

TargetRoll mods = new TargetRoll(difficulty, "difficulty");
int modeMod = mode.getMod(campaign.getCampaignOptions().isDestroyByMargin());
final TargetRoll mods = new TargetRoll(difficulty, "difficulty");
final int modeMod = getMode().getMod(getCampaign().getCampaignOptions().isDestroyByMargin());
if (modeMod != 0) {
mods.addModifier(modeMod, getCurrentModeName());
}
if (null != unit) {
mods.append(unit.getSiteMod());
if (unit.getEntity().hasQuirk("easy_maintain")) {

if (getUnit() != null) {
mods.append(getUnit().getSiteMod());
if (getUnit().getEntity().hasQuirk(OptionsConstants.QUIRK_POS_EASY_MAINTAIN)) {
mods.addModifier(-1, "easy to maintain");
} else if (unit.getEntity().hasQuirk("difficult_maintain")) {
} else if (getUnit().getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_DIFFICULT_MAINTAIN)) {
mods.addModifier(1, "difficult to maintain");
}
if (unit.hasPrototypeTSM() &&

if (getUnit().hasPrototypeTSM() &&
((this instanceof MekLocation)
|| (this instanceof MissingMekLocation)
|| (this instanceof MekActuator)
|| (this instanceof MissingMekActuator))) {
mods.addModifier(2, "prototype TSM");
}
}
if (isClanTechBase() || (this instanceof MekLocation && this.getUnit() != null && this.getUnit().getEntity().isClan())) {
if (null != tech && !tech.isClanner()
&& !tech.getOptions().booleanOption(PersonnelOptions.TECH_CLAN_TECH_KNOWLEDGE)) {

if (tech != null) {
if ((isClanTechBase()
|| ((this instanceof MekLocation) && (getUnit() != null) && getUnit().getEntity().isClan()))
&& (!tech.isClanner()
&& !tech.getOptions().booleanOption(PersonnelOptions.TECH_CLAN_TECH_KNOWLEDGE))) {
mods.addModifier(2, "Clan tech");
}
}
if (null != tech
&& tech.getOptions().booleanOption(PersonnelOptions.TECH_WEAPON_SPECIALIST)
&& (IPartWork.findCorrectRepairType(this) == PartRepairType.WEAPON
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.PHYSICAL_WEAPON)) {
mods.addModifier(-1, "Weapon specialist");
}
if (null != tech
&& tech.getOptions().booleanOption(PersonnelOptions.TECH_ARMOR_SPECIALIST)
&& IPartWork.findCorrectRepairType(this) == PartRepairType.ARMOR) {
mods.addModifier(-1, "Armor specialist");
}
if (null != tech
&& tech.getOptions().booleanOption(PersonnelOptions.TECH_INTERNAL_SPECIALIST)
&& (IPartWork.findCorrectRepairType(this) == PartRepairType.ACTUATOR
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.ELECTRONICS
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.ENGINE
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.GYRO
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.MEK_LOCATION
|| IPartWork.findCorrectMassRepairType(this) == PartRepairType.GENERAL_LOCATION)) {
mods.addModifier(-1, "Internal specialist");

if (tech.getOptions().booleanOption(PersonnelOptions.TECH_WEAPON_SPECIALIST)
&& ((IPartWork.findCorrectRepairType(this) == PartRepairType.WEAPON)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.PHYSICAL_WEAPON))) {
mods.addModifier(-1, "Weapon specialist");
}

if (tech.getOptions().booleanOption(PersonnelOptions.TECH_ARMOR_SPECIALIST)
&& (IPartWork.findCorrectRepairType(this) == PartRepairType.ARMOR)) {
mods.addModifier(-1, "Armor specialist");
}

if (tech.getOptions().booleanOption(PersonnelOptions.TECH_INTERNAL_SPECIALIST)
&& ((IPartWork.findCorrectRepairType(this) == PartRepairType.ACTUATOR)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.ELECTRONICS)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.ENGINE)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.GYRO)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.MEK_LOCATION)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.GENERAL_LOCATION))) {
mods.addModifier(-1, "Internal specialist");
}
}

return getQualityMods(mods, tech);
}

@Override
public TargetRoll getAllModsForMaintenance() {
//according to StratOps you get a -1 mod when checking on individual parts
//but we will make this user customizable
TargetRoll mods = new TargetRoll(campaign.getCampaignOptions().getMaintenanceBonus(), "maintenance");
// according to StratOps you get a -1 mod when checking on individual parts
// but we will make this user customizable
final TargetRoll mods = new TargetRoll(campaign.getCampaignOptions().getMaintenanceBonus(), "maintenance");
mods.addModifier(Availability.getTechModifier(getTechRating()), "tech rating " + ITechnology.getRatingName(getTechRating()));

if (null != getUnit()) {
mods.append(getUnit().getSiteMod());
if (getUnit().getEntity().hasQuirk("easy_maintain")) {
mods.addModifier(-1, "easy to maintain");
if (getUnit() == null) {
return mods;
}

mods.append(getUnit().getSiteMod());
if (getUnit().getEntity().hasQuirk(OptionsConstants.QUIRK_POS_EASY_MAINTAIN)) {
mods.addModifier(-1, "easy to maintain");
} else if (getUnit().getEntity().hasQuirk(OptionsConstants.QUIRK_NEG_DIFFICULT_MAINTAIN)) {
mods.addModifier(1, "difficult to maintain");
}

if (getUnit().getTech() != null) {
if ((isClanTechBase() || ((this instanceof MekLocation) && getUnit().getEntity().isClan()))
&& (!getUnit().getTech().isClanner()
&& !getUnit().getTech().getOptions().booleanOption(PersonnelOptions.TECH_CLAN_TECH_KNOWLEDGE))) {
mods.addModifier(2, "Clan tech");
}
else if (getUnit().getEntity().hasQuirk("difficult_maintain")) {
mods.addModifier(1, "difficult to maintain");

if (getUnit().getTech().getOptions().booleanOption(PersonnelOptions.TECH_WEAPON_SPECIALIST)
&& ((IPartWork.findCorrectRepairType(this) == PartRepairType.WEAPON)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.PHYSICAL_WEAPON))) {
mods.addModifier(-1, "Weapon specialist");
}

if (isClanTechBase() || ((this instanceof MekLocation) && getUnit().getEntity().isClan())) {
if (getUnit().getTech() == null) {
mods.addModifier(2, "Clan tech");
} else if (!getUnit().getTech().isClanner()
&& !getUnit().getTech().getOptions().booleanOption(PersonnelOptions.TECH_CLAN_TECH_KNOWLEDGE)) {
mods.addModifier(2, "Clan tech");
}
if (getUnit().getTech().getOptions().booleanOption(PersonnelOptions.TECH_ARMOR_SPECIALIST)
&& (IPartWork.findCorrectRepairType(this) == PartRepairType.ARMOR)) {
mods.addModifier(-1, "Armor specialist");
}

if (getUnit().hasPrototypeTSM()) {
mods.addModifier(1, "prototype TSM");
if (getUnit().getTech().getOptions().booleanOption(PersonnelOptions.TECH_INTERNAL_SPECIALIST)
&& ((IPartWork.findCorrectRepairType(this) == PartRepairType.ACTUATOR)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.ELECTRONICS)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.ENGINE)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.GYRO)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.MEK_LOCATION)
|| (IPartWork.findCorrectMassRepairType(this) == PartRepairType.GENERAL_LOCATION))) {
mods.addModifier(-1, "Internal specialist");
}
}

if (campaign.getCampaignOptions().useQualityMaintenance()) {
mods = getQualityMods(mods, getUnit().getTech());
if (getUnit().hasPrototypeTSM()) {
mods.addModifier(1, "prototype TSM");
}
return mods;

return getCampaign().getCampaignOptions().useQualityMaintenance()
? getQualityMods(mods, getUnit().getTech()) : mods;
}

/**
Expand Down

0 comments on commit 8c73408

Please sign in to comment.