diff --git a/Mage.Tests/src/test/java/org/mage/test/utils/BoostCountTest.java b/Mage.Tests/src/test/java/org/mage/test/utils/BoostCountTest.java new file mode 100644 index 00000000000..6121fb2bad6 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/utils/BoostCountTest.java @@ -0,0 +1,24 @@ +package org.mage.test.utils; + +import mage.util.CardUtil; +import org.junit.Assert; +import org.junit.Test; + +/** + * @author JayDi85 + */ +public class BoostCountTest { + + @Test + public void test_BoostCountSigns() { + Assert.assertEquals(CardUtil.getBoostCountAsStr(0, 0), "+0/+0"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(1, 0), "+1/+0"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(0, 1), "+0/+1"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(1, 1), "+1/+1"); + + Assert.assertEquals(CardUtil.getBoostCountAsStr(-1, 0), "-1/-0"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(0, -1), "-0/-1"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(-1, 1), "-1/+1"); + Assert.assertEquals(CardUtil.getBoostCountAsStr(1, -1), "+1/-1"); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostOpponentsEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostOpponentsEffect.java index 22208383088..449534640e1 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostOpponentsEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostOpponentsEffect.java @@ -1,6 +1,6 @@ package mage.abilities.effects.common.continuous; -import java.util.Iterator; +import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.effects.ContinuousEffectImpl; import mage.constants.Duration; @@ -10,10 +10,11 @@ import mage.constants.SubLayer; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.util.CardUtil; +import java.util.Iterator; import java.util.Set; import java.util.UUID; -import mage.MageObjectReference; public class BoostOpponentsEffect extends ContinuousEffectImpl { protected int power; @@ -49,7 +50,7 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { super.init(source, game); if (this.affectedObjectsSet) { Set opponents = game.getOpponents(source.getControllerId()); - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (opponents.contains(perm.getControllerId())) { affectedObjectList.add(new MageObjectReference(perm, game)); } @@ -61,7 +62,7 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { public boolean apply(Game game, Ability source) { Set opponents = game.getOpponents(source.getControllerId()); if (this.affectedObjectsSet) { - for (Iterator it = affectedObjectList.iterator(); it.hasNext();) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost + for (Iterator it = affectedObjectList.iterator(); it.hasNext(); ) { // filter may not be used again, because object can have changed filter relevant attributes but still geets boost Permanent perm = it.next().getPermanent(game); if (perm != null) { if (opponents.contains(perm.getControllerId())) { @@ -73,7 +74,7 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { } } } else { - for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { if (opponents.contains(perm.getControllerId())) { perm.addPower(power); perm.addToughness(toughness); @@ -86,8 +87,8 @@ public class BoostOpponentsEffect extends ContinuousEffectImpl { private void setText() { StringBuilder sb = new StringBuilder(); sb.append(filter.getMessage()); - sb.append(" your opponents control get ").append(String.format("%1$+d/%2$+d", power, toughness)); - sb.append((duration== Duration.EndOfTurn?" until end of turn":"")); + sb.append(" your opponents control get ").append(CardUtil.getBoostCountAsStr(power, toughness)); + sb.append((duration == Duration.EndOfTurn ? " until end of turn" : "")); staticText = sb.toString(); } } diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostSourceWhileControlsEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostSourceWhileControlsEffect.java index 4bc2ec8b966..ddc30d4fd15 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostSourceWhileControlsEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/BoostSourceWhileControlsEffect.java @@ -1,20 +1,18 @@ - - package mage.abilities.effects.common.continuous; +import mage.abilities.Ability; +import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; +import mage.abilities.effects.WhileConditionContinuousEffect; import mage.constants.Duration; import mage.constants.Layer; import mage.constants.Outcome; import mage.constants.SubLayer; -import mage.abilities.Ability; -import mage.abilities.condition.common.PermanentsOnTheBattlefieldCondition; -import mage.abilities.effects.WhileConditionContinuousEffect; import mage.filter.FilterPermanent; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.util.CardUtil; /** - * * @author BetaSteward_at_googlemail.com */ public class BoostSourceWhileControlsEffect extends WhileConditionContinuousEffect { @@ -28,10 +26,10 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContinuousEffe this.power = power; this.toughness = toughness; this.filterDescription = filter.getMessage(); - staticText = "{this} gets " - + String.format("%1$+d/%2$+d", power, toughness) + staticText = "{this} gets " + + CardUtil.getBoostCountAsStr(power, toughness) + " as long as you control " - + (filterDescription.startsWith("an ") ? "":"a ") + + (filterDescription.startsWith("an ") ? "" : "a ") + filterDescription; } diff --git a/Mage/src/main/java/mage/counters/BoostCounter.java b/Mage/src/main/java/mage/counters/BoostCounter.java index 3c793ca810e..a2b40d7f99e 100644 --- a/Mage/src/main/java/mage/counters/BoostCounter.java +++ b/Mage/src/main/java/mage/counters/BoostCounter.java @@ -1,9 +1,8 @@ - - package mage.counters; +import mage.util.CardUtil; + /** - * * @author BetaSteward_at_googlemail.com */ public class BoostCounter extends Counter { @@ -16,7 +15,7 @@ public class BoostCounter extends Counter { } public BoostCounter(int power, int toughness, int count) { - super(String.format("%1$+d/%2$+d", power, toughness), count); + super(CardUtil.getBoostCountAsStr(power, toughness), count); this.power = power; this.toughness = toughness; } diff --git a/Mage/src/main/java/mage/util/CardUtil.java b/Mage/src/main/java/mage/util/CardUtil.java index 64bc15c843f..99022d44aef 100644 --- a/Mage/src/main/java/mage/util/CardUtil.java +++ b/Mage/src/main/java/mage/util/CardUtil.java @@ -16,7 +16,6 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.game.permanent.token.Token; import mage.util.functions.CopyTokenFunction; -import org.junit.Assert; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; @@ -747,4 +746,16 @@ public final class CardUtil { throw new IllegalArgumentException("Wrong mana type " + manaType); } } + + public static String getBoostCountAsStr(int power, int toughness) { + // sign fix for zero values + // -1/+0 must be -1/-0 + // +0/-1 must be -0/-1 + String signedP = String.format("%1$+d", power); + String signedT = String.format("%1$+d", toughness); + if (signedP.equals("+0") && signedT.startsWith("-")) signedP = "-0"; + if (signedT.equals("+0") && signedP.startsWith("-")) signedT = "-0"; + + return signedP + "/" + signedT; + } }