- Fix issue with animation setting -1 to unset PT.

This commit is contained in:
Sol
2016-10-14 14:24:22 +00:00
parent 18b6701993
commit d7947be4c4
5 changed files with 35 additions and 29 deletions

View File

@@ -38,11 +38,11 @@ public class AnimateAllEffect extends AnimateEffectBase {
final Map<String, String> svars = host.getSVars();
// AF specific sa
int power = -1;
Integer power = null;
if (sa.hasParam("Power")) {
power = AbilityUtils.calculateAmount(host, sa.getParam("Power"), sa);
}
int toughness = -1;
Integer toughness = null;
if (sa.hasParam("Toughness")) {
toughness = AbilityUtils.calculateAmount(host, sa.getParam("Toughness"), sa);
}

View File

@@ -49,11 +49,11 @@ public class AnimateEffect extends AnimateEffectBase {
}
// AF specific sa
int power = -1;
Integer power = null;
if (sa.hasParam("Power")) {
power = AbilityUtils.calculateAmount(source, sa.getParam("Power"), sa);
}
int toughness = -1;
Integer toughness = null;
if (sa.hasParam("Toughness")) {
toughness = AbilityUtils.calculateAmount(source, sa.getParam("Toughness"), sa);
}

View File

@@ -31,7 +31,7 @@ import java.util.HashMap;
import java.util.List;
public abstract class AnimateEffectBase extends SpellAbilityEffect {
void doAnimate(final Card c, final SpellAbility sa, final int power, final int toughness,
void doAnimate(final Card c, final SpellAbility sa, final Integer power, final Integer toughness,
final CardType addType, final CardType removeType, final String colors,
final List<String> keywords, final List<String> removeKeywords,
final List<String> hiddenKeywords, final long timestamp) {
@@ -76,7 +76,7 @@ public abstract class AnimateEffectBase extends SpellAbilityEffect {
removeCreatureTypes = true;
}
if ((power != -1) || (toughness != -1)) {
if ((power != null) || (toughness != null)) {
c.addNewPT(power, toughness, timestamp);
}

View File

@@ -2708,29 +2708,35 @@ public class Card extends GameEntity implements Comparable<Card> {
*/
private synchronized Pair<Integer, Integer> getLatestPT() {
// Find latest set power
long maxPowerTimestamp = -2;
int latestPower = Integer.MAX_VALUE;
for (final CardPowerToughness pt : newPT) {
if (pt.getTimestamp() >= maxPowerTimestamp && pt.getPower() != Integer.MAX_VALUE) {
maxPowerTimestamp = pt.getTimestamp();
latestPower = pt.getPower();
newPT.sort(new Comparator<CardPowerToughness>() {
@Override
public int compare(CardPowerToughness o1, CardPowerToughness o2) {
return o1.getTimestamp() < o2.getTimestamp() ? -1 : o1.getTimestamp() == o2.getTimestamp() ? 0 : 1;
}
});
Integer power = null,
toughness = null;
int size = newPT.size();
for(int i = size - 1; i >= 0; i--) {
CardPowerToughness pt = newPT.get(i);
if (power == null && pt.getPower() != null)
power = pt.getPower();
if (toughness == null && pt.getToughness() != null)
toughness = pt.getToughness();
}
// Find latest set toughness
long maxToughnessTimestamp = -2;
int latestToughness = Integer.MAX_VALUE;
for (final CardPowerToughness pt : newPT) {
if (pt.getTimestamp() >= maxToughnessTimestamp && pt.getToughness() != Integer.MAX_VALUE) {
maxToughnessTimestamp = pt.getTimestamp();
latestToughness = pt.getToughness();
}
}
if (power == null)
power = Integer.MAX_VALUE;
return Pair.of(latestPower, latestToughness);
if (toughness == null)
toughness = Integer.MAX_VALUE;
return Pair.of(power, toughness);
}
public final void addNewPT(final int power, final int toughness, final long timestamp) {
public final void addNewPT(final Integer power, final Integer toughness, final long timestamp) {
newPT.add(new CardPowerToughness(power, toughness, timestamp));
currentState.getView().updatePower(this);
currentState.getView().updateToughness(this);

View File

@@ -27,8 +27,8 @@ package forge.game.card;
*/
public class CardPowerToughness {
private final int power;
private final int toughness;
private final Integer power;
private final Integer toughness;
private long timeStamp = 0;
/**
@@ -54,7 +54,7 @@ public class CardPowerToughness {
* @param stamp
* a long.
*/
CardPowerToughness(final int newPower, final int newToughness, final long stamp) {
CardPowerToughness(final Integer newPower, final Integer newToughness, final long stamp) {
this.power = newPower;
this.toughness = newToughness;
this.timeStamp = stamp;
@@ -66,7 +66,7 @@ public class CardPowerToughness {
*
* @return int
*/
public final int getPower() {
public final Integer getPower() {
return this.power;
}
@@ -76,7 +76,7 @@ public class CardPowerToughness {
*
* @return int
*/
public final int getToughness() {
public final Integer getToughness() {
return this.toughness;
}
@@ -93,7 +93,7 @@ public class CardPowerToughness {
* a long.
* @return a boolean.
*/
public final boolean equals(final int newPower, final int newToughness, final long stamp) {
public final boolean equals(final Integer newPower, final Integer newToughness, final long stamp) {
return (this.timeStamp == stamp) && (this.power == newPower) && (this.toughness == newToughness);
}
}