Refactor: Add proper support for modifying and querying base P/T (#9409)

This commit is contained in:
Alex Vasile 2022-09-01 19:57:30 -04:00 committed by GitHub
parent d83eb41073
commit 07a142c9e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
415 changed files with 1844 additions and 2095 deletions

View file

@ -6,6 +6,9 @@ import mage.util.Copyable;
import java.io.Serializable;
import java.util.Objects;
/**
* Wrapper class for the Integer used to represent power and toughness.
*/
public class MageInt implements Serializable, Copyable<MageInt> {
public static final MageInt EmptyMageInt = new MageInt(Integer.MIN_VALUE, "") {
@ -13,38 +16,39 @@ public class MageInt implements Serializable, Copyable<MageInt> {
private static final String exceptionMessage = "MageInt.EmptyMageInt can't be modified.";
@Override
public void boostValue(int amount) {
public void increaseBoostedValue(int amount) {
throw new RuntimeException(exceptionMessage);
}
@Override
public void setValue(int value) {
public void setBoostedValue(int value) {
throw new RuntimeException(exceptionMessage);
}
};
protected int baseValue;
protected int baseValueModified;
// The original P/T value, can never change
protected final int baseValue;
// The current base value. Can be changed by effects such as Biomass Mutation
protected int modifiedBaseValue;
// The curent final value: current base + any modifications (e.g. +1/+1 counters or "creature gets +1/+1")
protected int boostedValue;
protected String cardValue = "";
// String representation of the current base value, update automatically
protected String cardValue;
public MageInt(int value) {
this.baseValue = value;
this.baseValueModified = baseValue;
this.boostedValue = baseValue;
this.cardValue = Integer.toString(value);
this(value, Integer.toString(value));
}
public MageInt(int baseValue, String cardValue) {
this.baseValue = baseValue;
this.baseValueModified = baseValue;
this.boostedValue = baseValue;
this.modifiedBaseValue = this.baseValue;
this.boostedValue = this.baseValue;
this.cardValue = cardValue;
}
public MageInt(int baseValue, int baseValueModified, int boostedValue, String cardValue) {
this.baseValue = baseValue;
this.baseValueModified = baseValueModified;
this.modifiedBaseValue = baseValueModified;
this.boostedValue = boostedValue;
this.cardValue = cardValue;
}
@ -54,42 +58,41 @@ public class MageInt implements Serializable, Copyable<MageInt> {
if (Objects.equals(this, EmptyMageInt)) {
return this;
}
return new MageInt(baseValue, baseValueModified, boostedValue, cardValue);
return new MageInt(baseValue, modifiedBaseValue, boostedValue, cardValue);
}
public int getBaseValue() {
return baseValue;
}
public int getBaseValueModified() {
return baseValueModified;
public int getModifiedBaseValue() {
return modifiedBaseValue;
}
public int getValue() {
return boostedValue;
}
public void modifyBaseValue(int value) {
this.baseValueModified = value;
public void setModifiedBaseValue(int value) {
this.modifiedBaseValue = value;
this.boostedValue = value;
this.cardValue = Integer.toString(value);
}
public void setValue(int value) {
public void setBoostedValue(int value) {
this.boostedValue = value;
}
public void boostValue(int amount) {
public void increaseBoostedValue(int amount) {
this.boostedValue = CardUtil.overflowInc(this.boostedValue, amount);
}
public void resetToBaseValue() {
this.boostedValue = this.baseValueModified;
setModifiedBaseValue(this.baseValue);
}
@Override
public String toString() {
return cardValue;
}
}