mirror of
https://github.com/correl/mage.git
synced 2025-03-07 20:53:18 -10:00
* Boost effects - fixed wrong text for zero values (-0/-1, -1/-0, etc);
This commit is contained in:
parent
d366da6f6b
commit
ccd95cdd71
5 changed files with 54 additions and 21 deletions
|
@ -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");
|
||||
}
|
||||
}
|
|
@ -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<UUID> 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<UUID> opponents = game.getOpponents(source.getControllerId());
|
||||
if (this.affectedObjectsSet) {
|
||||
for (Iterator<MageObjectReference> 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<MageObjectReference> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue