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

Refactored Infantry Sell Value Calculation to Include Unit Quality Multipliers #4580

Merged
merged 1 commit into from
Aug 8, 2024
Merged
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
36 changes: 25 additions & 11 deletions MekHQ/src/mekhq/campaign/unit/Unit.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static mekhq.campaign.parts.Part.*;

/**
* This is a wrapper class for entity, so that we can add some functionality to it
*
Expand Down Expand Up @@ -1117,18 +1119,30 @@ public String getHeatSinkTypeString(int year) {
}

public Money getSellValue() {
// we use an alternative method of getting sell value for infantry
if (entity instanceof Infantry) {
return Money.of(entity.getAlternateCost());
}

Money partsValue = Money.zero();

partsValue = partsValue
.plus(parts.stream()
.map(x -> x.getActualValue().multipliedBy(x.getQuantity()))
.collect(Collectors.toList()));

// we use an alternative method of getting sell value for infantry
if (entity instanceof Infantry) {
Money unitCost = Money.of(entity.getAlternateCost());
double[] usedPartPriceMultipliers = campaign.getCampaignOptions().getUsedPartPriceMultipliers();

return switch (this.getQuality()) {
case QUALITY_A -> unitCost.multipliedBy(usedPartPriceMultipliers[0]);
case QUALITY_B -> unitCost.multipliedBy(usedPartPriceMultipliers[1]);
case QUALITY_C -> unitCost.multipliedBy(usedPartPriceMultipliers[2]);
case QUALITY_D -> unitCost.multipliedBy(usedPartPriceMultipliers[3]);
case QUALITY_E -> unitCost.multipliedBy(usedPartPriceMultipliers[4]);
case QUALITY_F -> unitCost.multipliedBy(usedPartPriceMultipliers[5]);
default -> throw new IllegalStateException("Unexpected value in mekhq/campaign/unit/Unit.java/getSellValue: "
+ this.getQuality());
};
}

//We need to adjust this for equipment that doesn't show up as parts
//Docking collars, Grav decks, KF Drive - Now parts
//Drive unit - see SpacecraftEngine
Expand Down Expand Up @@ -5024,7 +5038,7 @@ public int getQuality() {
}
}
if (nParts == 0) {
return Part.QUALITY_D;
return QUALITY_D;
}
return (int) Math.round((1.0 * sumQuality) / nParts);
}
Expand Down Expand Up @@ -5669,11 +5683,11 @@ public static int getRandomUnitQuality(int modifier) {
);

return switch (roll) {
case 2, 3, 4, 5 -> Part.QUALITY_A;
case 6, 7, 8 -> Part.QUALITY_B;
case 9, 10 -> Part.QUALITY_C;
case 11 -> Part.QUALITY_D;
case 12 -> Part.QUALITY_F;
case 2, 3, 4, 5 -> QUALITY_A;
case 6, 7, 8 -> QUALITY_B;
case 9, 10 -> QUALITY_C;
case 11 -> QUALITY_D;
case 12 -> QUALITY_F;
default -> throw new IllegalStateException("Unexpected value in mekhq/campaign/unit/Unit.java/getRandomUnitQuality: " + roll);
};
}
Expand Down