Skip to content

Commit

Permalink
fix magefree#10607 (Maskwood Nexus)
Browse files Browse the repository at this point in the history
  • Loading branch information
xenohedron committed Sep 7, 2024
1 parent 4c55efb commit 0bba44b
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 40 deletions.
15 changes: 12 additions & 3 deletions Mage.Sets/src/mage/cards/a/AshesOfTheFallen.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package mage.cards.a;

import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
Expand All @@ -14,6 +13,9 @@
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.util.CardUtil;

import java.util.UUID;

/**
*
Expand Down Expand Up @@ -62,7 +64,14 @@ public boolean apply(Game game, Ability source) {
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game) && !card.hasSubtype(subType, game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().add(subType);
MageObject mageObject = game.getObject(card.getId());
if (mageObject != null) {
CardUtil.getObjectPartsAsObjects(mageObject).forEach(objectPart ->{
if (objectPart.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(objectPart, game).getSubtype().add(subType);
}
});
}
}
}
} else {
Expand Down
87 changes: 50 additions & 37 deletions Mage.Sets/src/mage/cards/m/MaskwoodNexus.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mage.cards.m;

import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
Expand All @@ -13,17 +15,19 @@
import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.game.command.CommandObject;
import mage.game.command.Commander;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.ShapeshifterBlueToken;
import mage.game.stack.Spell;
import mage.game.stack.StackObject;
import mage.players.Player;
import mage.util.CardUtil;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

/**
* @author TheElk801
Expand Down Expand Up @@ -81,53 +85,61 @@ public boolean apply(Game game, Ability source) {
}
// Creature cards you own that aren't on the battlefield
// in graveyard
for (UUID cardId : controller.getGraveyard()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
Set<Card> affectedCards = controller.getGraveyard().stream()
.map(game::getCard)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// on Hand
for (UUID cardId : controller.getHand()) {
Card card = game.getCard(cardId);
if (card != null && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
controller.getHand().stream()
.map(game::getCard)
.filter(Objects::nonNull)
.forEach(affectedCards::add);

// in Exile
for (Card card : game.getState().getExile().getAllCards(game)) {
if (card.isCreature(game) && card.isOwnedBy(controller.getId())) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
game.getState().getExile().getAllCards(game, controller.getId()).stream()
.filter(card -> card.isOwnedBy(controller.getId()))
.forEach(affectedCards::add);

// in Library (e.g. for Mystical Teachings)
for (Card card : controller.getLibrary().getCards(game)) {
if (card.isOwnedBy(controller.getId()) && card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
affectedCards.addAll(controller.getLibrary().getCards(game));

// commander in command zone
for (CommandObject commandObject : game.getState().getCommand()) {
if (!(commandObject instanceof Commander)) {
continue;
}
Card card = game.getCard(((Commander) commandObject).getId());
if (card != null
&& card.isOwnedBy(controller.getId())
&& card.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}
game.getState().getCommand().stream()
.filter(Commander.class::isInstance)
.map(MageItem::getId)
.map(game::getCard)
.filter(Objects::nonNull)
.filter(c -> c.isOwnedBy(controller.getId()))
.forEach(affectedCards::add);

// Apply to all affected cards by object parts
affectedCards.stream()
.map(card -> game.getObject(card.getId()))
.filter(Objects::nonNull)
.forEach(mageObject -> {
if (mageObject.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(mageObject, game).getSubtype().setIsAllCreatureTypes(true);
}
CardUtil.getObjectParts(mageObject).stream()
.filter(Objects::nonNull)
.forEach(objectId -> {
MageObject partObject = game.getObject(objectId);
if (partObject != null && partObject.isCreature(game)) {
game.getState().getCreateMageObjectAttribute(partObject, game).getSubtype().setIsAllCreatureTypes(true);
}
});
});

// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext();) {
StackObject stackObject = iterator.next();
for (StackObject stackObject : game.getStack()) {
if (stackObject instanceof Spell
&& stackObject.isControlledBy(source.getControllerId())
&& stackObject.isCreature(game)) {
Card card = ((Spell) stackObject).getCard();
game.getState().getCreateMageObjectAttribute(card, game).getSubtype().setIsAllCreatureTypes(true);
}
}

// creatures you control
List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(
StaticFilters.FILTER_CONTROLLED_CREATURE, source.getControllerId(), game);
Expand All @@ -136,6 +148,7 @@ public boolean apply(Game game, Ability source) {
creature.setIsAllCreatureTypes(game, true);
}
}

return true;

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package org.mage.test.cards.single.khm;

import mage.abilities.keyword.HexproofAbility;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;

/**
* {@link mage.cards.m.MaskwoodNexus Maskwood Nexus}
* {4}
* Artifact
* Creatures you control are every creature type. The same is true for creature spells you control and creature cards you own that aren't on the battlefield.
* {3}, {T}: Create a 2/2 blue Shapeshifter creature token with changeling.
*
* @author grimreap142
*/

public class MaskwoodNexusTest extends CardTestPlayerBase {

private static final String maskwood = "Maskwood Nexus";
private static final String magda = "Magda, Brazen Outlaw";
private static final String pMonk = "Pinnacle Monk";
private static final String jadeOrb = "Jade Orb of Dragonkind";

@Test
public void magdaSearch() {
addCard(Zone.BATTLEFIELD, playerA, magda);
addCard(Zone.LIBRARY, playerA, "Sol Ring");
addCard(Zone.BATTLEFIELD, playerA, maskwood);
addCard(Zone.LIBRARY, playerA, pMonk);
// create 5 treasures
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 10);
addCard(Zone.BATTLEFIELD, playerA, "Treasure Vault", 1);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{X}{X}, {T}, Sacrifice");
setChoice(playerA, "X=5");

// activate Magda and select Pinnacle Monk
setChoice(playerA, "Treasure Token", 5);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Sacrifice five Treasures:");
addTarget(playerA, pMonk);

setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_TURN);
execute();

assertPermanentCount(playerA, pMonk, 1);
assertPermanentCount(playerA, magda, 1);

}

@Test
public void maskwoodAndJadeOrbCounterTest() {
addCard(Zone.HAND, playerA, pMonk);
addCard(Zone.BATTLEFIELD, playerA, maskwood, 1);
addCard(Zone.BATTLEFIELD, playerA, "Forest", 2);
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2);
addCard(Zone.BATTLEFIELD, playerA, jadeOrb);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, pMonk);

setStrictChooseMode(true);
setStopAt(1, PhaseStep.END_COMBAT);
execute();

assertTapped(jadeOrb, true);
assertCounterCount(pMonk, CounterType.P1P1, 1);
assertAbility(playerA, pMonk, HexproofAbility.getInstance(), true);
}

}

0 comments on commit 0bba44b

Please sign in to comment.