Merge pull request #8400 from weirddan455/decayed

Add sub abilities in TokenImpl.addAbility and PermanentImpl.addAbility (fixes #8343)
This commit is contained in:
Oleg Agafonov 2021-10-23 10:27:49 +04:00 committed by GitHub
commit 05222f3bdc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 3 deletions

View file

@ -0,0 +1,51 @@
package org.mage.test.cards.abilities.keywords;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
public class DecayedTest extends CardTestPlayerBase {
@Test
public void decayedToken() {
addCard(Zone.HAND, playerA, "Falcon Abomination", 1);
addCard(Zone.BATTLEFIELD, playerA, "Island", 3);
setStrictChooseMode(true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Falcon Abomination");
attack(3, playerA, "Zombie");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Falcon Abomination", 1);
assertPermanentCount(playerA, "Zombie", 0);
}
@Test
public void decayedPermanent() {
addCard(Zone.BATTLEFIELD, playerA, "Gisa, Glorious Resurrector", 1);
addCard(Zone.BATTLEFIELD, playerB, "Grizzly Bears", 1);
addCard(Zone.HAND, playerA, "Doom Blade", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
setStrictChooseMode(true);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Doom Blade");
addTarget(playerA, "Grizzly Bears");
// Gisa - "If a creature an opponent controls would die, exile it instead."
checkExileCount("Gisa Exile Ability", 1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Grizzly Bears", 1);
attack(5, playerA, "Grizzly Bears");
setStopAt(5, PhaseStep.POSTCOMBAT_MAIN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Gisa, Glorious Resurrector", 1);
assertPermanentCount(playerA, "Grizzly Bears", 0);
assertPermanentCount(playerB, "Grizzly Bears", 0);
assertExileCount("Grizzly Bears", 0);
// Grizzly Bears should sacrifice after combat and go to playerB's graveyard
assertGraveyardCount(playerB, "Grizzly Bears", 1);
}
}

View file

@ -305,9 +305,7 @@ public abstract class CardImpl extends MageObjectImpl implements Card {
public void addAbility(Ability ability) {
ability.setSourceId(this.getId());
abilities.add(ability);
for (Ability subAbility : ability.getSubAbilities()) {
abilities.add(subAbility);
}
abilities.addAll(ability.getSubAbilities());
// dynamic check: you can't add ability to the PermanentCard, use permanent.addAbility(a, source, game) instead
// reason: triggered abilities are not processing here

View file

@ -119,6 +119,7 @@ public abstract class Designation implements MageObject {
public void addAbility(Ability ability) {
ability.setSourceId(id);
abilites.add(ability);
abilites.addAll(ability.getSubAbilities());
}
@Override

View file

@ -386,6 +386,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
game.getState().addAbility(copyAbility, sourceId, this);
}
abilities.add(copyAbility);
abilities.addAll(ability.getSubAbilities());
}
}

View file

@ -125,6 +125,7 @@ public abstract class TokenImpl extends MageObjectImpl implements Token {
public void addAbility(Ability ability) {
ability.setSourceId(this.getId());
abilities.add(ability);
abilities.addAll(ability.getSubAbilities());
}
@Override

View file

@ -2298,6 +2298,7 @@ public abstract class PlayerImpl implements Player, Serializable {
public void addAbility(Ability ability) {
ability.setSourceId(playerId);
this.abilities.add(ability);
this.abilities.addAll(ability.getSubAbilities());
}
@Override