mirror of
https://github.com/correl/mage.git
synced 2025-03-07 20:53:18 -10:00
Tests for LevelUpAbility
This commit is contained in:
parent
76c6362df1
commit
c2ea8246d2
7 changed files with 148 additions and 39 deletions
|
@ -27,7 +27,6 @@
|
|||
*/
|
||||
package mage.sets.riseoftheeldrazi;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.MageInt;
|
||||
|
@ -35,14 +34,12 @@ import mage.abilities.Abilities;
|
|||
import mage.abilities.AbilitiesImpl;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.costs.mana.ManaCostsImpl;
|
||||
import mage.abilities.keyword.IndestructibleAbility;
|
||||
import mage.abilities.keyword.LevelAbility;
|
||||
import mage.abilities.keyword.LevelUpAbility;
|
||||
import mage.abilities.keyword.LifelinkAbility;
|
||||
import mage.abilities.keyword.*;
|
||||
import mage.cards.LevelerCard;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author North
|
||||
*/
|
||||
public class TranscendentMaster extends LevelerCard<TranscendentMaster> {
|
||||
|
@ -60,14 +57,14 @@ public class TranscendentMaster extends LevelerCard<TranscendentMaster> {
|
|||
|
||||
this.addAbility(new LevelUpAbility(new ManaCostsImpl("{1}")));
|
||||
|
||||
Abilities<Ability> abilities1 = new AbilitiesImpl<Ability>();
|
||||
abilities1.add(LifelinkAbility.getInstance());
|
||||
this.getLevels().add(new LevelAbility(6, 11, abilities1, 6, 6));
|
||||
Abilities<Ability> abilities1 = new AbilitiesImpl<Ability>(LifelinkAbility.getInstance());
|
||||
Abilities<Ability> abilities2 = new AbilitiesImpl<Ability>(LifelinkAbility.getInstance(),
|
||||
IndestructibleAbility.getInstance());
|
||||
|
||||
Abilities<Ability> abilities2 = new AbilitiesImpl<Ability>();
|
||||
abilities2.add(LifelinkAbility.getInstance());
|
||||
abilities2.add(IndestructibleAbility.getInstance());
|
||||
this.getLevels().add(new LevelAbility(12, -1, abilities2, 9, 9));
|
||||
LevelAbilityBuilder.construct(this,
|
||||
new LevelAbility(6, 11, abilities1, 6, 6),
|
||||
new LevelAbility(12, -1, abilities2, 9, 9)
|
||||
);
|
||||
}
|
||||
|
||||
public TranscendentMaster(final TranscendentMaster card) {
|
||||
|
|
|
@ -14,11 +14,79 @@ import org.mage.test.serverside.base.CardTestPlayerBase;
|
|||
*/
|
||||
public class LevelUpAbilityTest extends CardTestPlayerBase {
|
||||
|
||||
/**
|
||||
* Tests creature without any level up counter
|
||||
*/
|
||||
@Test
|
||||
public void testFirstLevel() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Transcendent Master");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 15);
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Permanent master = getPermanent("Transcendent Master", playerA.getId());
|
||||
Assert.assertTrue(master.getCounters().isEmpty());
|
||||
|
||||
Assert.assertEquals(3, master.getPower().getValue());
|
||||
Assert.assertEquals(3, master.getToughness().getValue());
|
||||
Assert.assertFalse(master.getAbilities().contains(LifelinkAbility.getInstance()));
|
||||
Assert.assertFalse(master.getAbilities().contains(IndestructibleAbility.getInstance()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that putting level up counters really makes effect
|
||||
*/
|
||||
@Test
|
||||
public void testLevelChanged() {
|
||||
public void testFirstLevelWithOneCounter() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Transcendent Master");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 15);
|
||||
|
||||
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Level up {1}");
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Permanent master = getPermanent("Transcendent Master", playerA.getId());
|
||||
Assert.assertEquals(1, master.getCounters().getCount(CounterType.LEVEL));
|
||||
|
||||
Assert.assertEquals(3, master.getPower().getValue());
|
||||
Assert.assertEquals(3, master.getToughness().getValue());
|
||||
Assert.assertFalse(master.getAbilities().contains(LifelinkAbility.getInstance()));
|
||||
Assert.assertFalse(master.getAbilities().contains(IndestructibleAbility.getInstance()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests second level that gives Lifelink as well as 6/6
|
||||
*/
|
||||
@Test
|
||||
public void testSecondLevel() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Transcendent Master");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 15);
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Level up {1}");
|
||||
}
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Permanent master = getPermanent("Transcendent Master", playerA.getId());
|
||||
Assert.assertEquals(6, master.getCounters().getCount(CounterType.LEVEL));
|
||||
|
||||
Assert.assertEquals(6, master.getPower().getValue());
|
||||
Assert.assertEquals(6, master.getToughness().getValue());
|
||||
// since now Lifelink will appear
|
||||
Assert.assertTrue(master.getAbilities().contains(LifelinkAbility.getInstance()));
|
||||
// but still no Indestructible
|
||||
Assert.assertFalse(master.getAbilities().contains(IndestructibleAbility.getInstance()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests third level that gives both Lifelink and Indestructible as well as 9/9
|
||||
*/
|
||||
@Test
|
||||
public void testThirdLevel() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Transcendent Master");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 15);
|
||||
|
||||
|
@ -30,10 +98,6 @@ public class LevelUpAbilityTest extends CardTestPlayerBase {
|
|||
execute();
|
||||
|
||||
Permanent master = getPermanent("Transcendent Master", playerA.getId());
|
||||
Assert.assertNotNull(master);
|
||||
|
||||
Assert.assertNotNull(master.getCounters());
|
||||
Assert.assertFalse(master.getCounters().isEmpty());
|
||||
Assert.assertEquals(12, master.getCounters().getCount(CounterType.LEVEL));
|
||||
|
||||
Assert.assertEquals("Power different", 9, master.getPower().getValue());
|
||||
|
@ -41,4 +105,29 @@ public class LevelUpAbilityTest extends CardTestPlayerBase {
|
|||
Assert.assertTrue(master.getAbilities().contains(LifelinkAbility.getInstance()));
|
||||
Assert.assertTrue(master.getAbilities().contains(IndestructibleAbility.getInstance()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that extra counters won't make any effect over third level
|
||||
*/
|
||||
@Test
|
||||
public void testExtraCounters() {
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Transcendent Master");
|
||||
addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 15);
|
||||
|
||||
for (int i = 0; i < 15; i++) {
|
||||
activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "Level up {1}");
|
||||
}
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
Permanent master = getPermanent("Transcendent Master", playerA.getId());
|
||||
Assert.assertEquals(15, master.getCounters().getCount(CounterType.LEVEL));
|
||||
|
||||
Assert.assertEquals("Power different", 9, master.getPower().getValue());
|
||||
Assert.assertEquals("Toughness different", 9, master.getToughness().getValue());
|
||||
Assert.assertTrue(master.getAbilities().contains(LifelinkAbility.getInstance()));
|
||||
Assert.assertTrue(master.getAbilities().contains(IndestructibleAbility.getInstance()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -71,7 +71,6 @@ public class PhantasmalImageTest extends CardTestPlayerBase {
|
|||
|
||||
castSpell(2, Constants.PhaseStep.PRECOMBAT_MAIN, playerB, "Phantasmal Image");
|
||||
|
||||
|
||||
setStopAt(2, Constants.PhaseStep.END_TURN);
|
||||
execute();
|
||||
|
||||
|
|
|
@ -28,10 +28,6 @@
|
|||
|
||||
package mage.abilities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
||||
import mage.abilities.keyword.KickerAbility;
|
||||
|
@ -39,6 +35,11 @@ import mage.abilities.keyword.ProtectionAbility;
|
|||
import mage.abilities.mana.ManaAbility;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
@ -46,6 +47,12 @@ import mage.game.Game;
|
|||
public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Abilities<T> {
|
||||
|
||||
public AbilitiesImpl() {}
|
||||
|
||||
public AbilitiesImpl(T... abilities) {
|
||||
for (T ability : abilities) {
|
||||
add(ability);
|
||||
}
|
||||
}
|
||||
|
||||
public AbilitiesImpl(final AbilitiesImpl<T> abilities) {
|
||||
for (T ability: abilities) {
|
||||
|
|
|
@ -37,8 +37,11 @@ import mage.game.Game;
|
|||
* @author nantuko
|
||||
*/
|
||||
public class HasCounterCondition implements Condition {
|
||||
private CounterType counterType;
|
||||
|
||||
private CounterType counterType;
|
||||
private int amount = 1;
|
||||
private int from = -1;
|
||||
private int to;
|
||||
|
||||
public HasCounterCondition(CounterType type) {
|
||||
this.counterType = type;
|
||||
|
@ -49,8 +52,22 @@ public class HasCounterCondition implements Condition {
|
|||
this.amount = amount;
|
||||
}
|
||||
|
||||
public HasCounterCondition(CounterType type, int from, int to) {
|
||||
this.counterType = type;
|
||||
this.from = from;
|
||||
this.to = to;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getPermanent(source.getSourceId()).getCounters().getCount(counterType) >= amount;
|
||||
if (from != -1) { //range compare
|
||||
int count = game.getPermanent(source.getSourceId()).getCounters().getCount(counterType);
|
||||
if (to == Integer.MAX_VALUE) {
|
||||
return count >= from;
|
||||
}
|
||||
return count >= from && count <= to;
|
||||
} else { // single compare (lte)
|
||||
return game.getPermanent(source.getSourceId()).getCounters().getCount(counterType) >= amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,16 +35,21 @@ import mage.abilities.Ability;
|
|||
import mage.abilities.StaticAbility;
|
||||
|
||||
/**
|
||||
* The implementation by BetaSteward was discarded as requires special handling in Mage.Core.
|
||||
*
|
||||
* Instead it was replaced by conditional continuous effects and builder pattern.
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
* @author noxx
|
||||
*/
|
||||
public class LevelAbility extends StaticAbility<LevelAbility> {
|
||||
|
||||
private int level1;
|
||||
private int level2;
|
||||
private Abilities<Ability> abilities = new AbilitiesImpl<Ability>();
|
||||
private int power;
|
||||
private int toughness;
|
||||
private int level1;
|
||||
private int level2;
|
||||
private int power;
|
||||
private int toughness;
|
||||
|
||||
private Abilities<Ability> abilities = new AbilitiesImpl<Ability>();
|
||||
|
||||
public LevelAbility(int level1, int level2, Abilities<Ability> abilities, int power, int toughness) {
|
||||
super(Zone.BATTLEFIELD, null);
|
||||
|
|
|
@ -29,13 +29,8 @@
|
|||
package mage.game.permanent;
|
||||
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.TriggeredAbility;
|
||||
import mage.abilities.common.ZoneChangeTriggeredAbility;
|
||||
import mage.abilities.keyword.LevelAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.LevelerCard;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.players.Player;
|
||||
|
@ -103,7 +98,7 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
this.manaCost = card.getManaCost().copy();
|
||||
this.power = card.getPower().copy();
|
||||
this.toughness = card.getToughness().copy();
|
||||
if (card instanceof LevelerCard) {
|
||||
/*if (card instanceof LevelerCard) {
|
||||
LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL));
|
||||
if (level != null) {
|
||||
this.power.setValue(level.getPower());
|
||||
|
@ -112,7 +107,7 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
this.addAbility(ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (card instanceof PermanentCard) {
|
||||
this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters;
|
||||
}
|
||||
|
@ -142,7 +137,7 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
this.manaCost = card.getManaCost().copy();
|
||||
this.power = card.getPower().copy();
|
||||
this.toughness = card.getToughness().copy();
|
||||
if (card instanceof LevelerCard) {
|
||||
/*if (card instanceof LevelerCard) {
|
||||
LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL));
|
||||
if (level != null) {
|
||||
this.power.setValue(level.getPower());
|
||||
|
@ -151,7 +146,7 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
this.addAbility(ability, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}*/
|
||||
if (card instanceof PermanentCard) {
|
||||
this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue