use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class AnathemancerCount method calculate.
@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
if (sourceAbility != null) {
UUID playerId = (UUID) game.getState().getValue(sourceAbility.getSourceId() + ChooseOpponentEffect.VALUE_KEY);
Player chosenPlayer = game.getPlayer(playerId);
if (chosenPlayer != null) {
FilterLandPermanent filter = new FilterLandPermanent("tapped lands the chosen player controls");
filter.add(TappedPredicate.TAPPED);
filter.add(new ControllerIdPredicate(playerId));
return game.getBattlefield().count(filter, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
}
}
return 0;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class WardOfBonesEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (game.getOpponents(source.getControllerId()).contains(event.getPlayerId())) {
final Card card = game.getCard(event.getSourceId());
final Player opponent = game.getPlayer(event.getPlayerId());
if (card == null || opponent == null) {
return false;
}
if (card.isCreature(game) && game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game) > game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
return true;
}
if (card.isArtifact(game) && game.getBattlefield().countAll(new FilterArtifactPermanent(), opponent.getId(), game) > game.getBattlefield().countAll(new FilterArtifactPermanent(), source.getControllerId(), game)) {
return true;
}
if (card.isEnchantment(game) && game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, opponent.getId(), game) > game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_ENCHANTMENT, source.getControllerId(), game)) {
return true;
}
final int yourLands = game.getBattlefield().countAll(new FilterLandPermanent(), source.getControllerId(), game);
if (card.isLand(game) && game.getBattlefield().countAll(new FilterLandPermanent(), opponent.getId(), game) > yourLands) {
return true;
}
}
return false;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class PreventRepeatedActionsTest method testEquipOnlyOnce.
/**
* Check that an equipment is not switched again an again between creatures
*/
@Test
public void testEquipOnlyOnce() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
// Equipped creature gets +1/+1.
// Equip {1}({1}: Attach to target creature you control. Equip only as a sorcery.)
addCard(Zone.BATTLEFIELD, playerA, "Fireshrieker", 1);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 2);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
int tappedLands = 0;
for (Permanent permanent : currentGame.getBattlefield().getAllActivePermanents(new FilterLandPermanent(), playerA.getId(), currentGame)) {
if (permanent.isTapped()) {
tappedLands++;
}
}
Assert.assertEquals("AI should only used Equipment once", 2, tappedLands);
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class HeraldOfLeshracLeavesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (playerId.equals(source.getControllerId())) {
continue;
}
FilterPermanent filter = new FilterLandPermanent();
filter.add(new OwnerIdPredicate(playerId));
filter.add(new ControllerIdPredicate(source.getControllerId()));
for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, playerId);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
return true;
}
use of mage.filter.common.FilterLandPermanent in project mage by magefree.
the class SasayasEssenceManaEffect method produceMana.
/**
* RULINGS 6/1/2005 If Sasaya’s Essence’s controller has four Forests and
* taps one of them for Green, the Essence will add GreenGreenGreen to that
* player’s mana pool for a total of GreenGreenGreenGreen.
*
* 6/1/2005 If Sasaya’s Essence’s controller has four Mossfire Valley and
* taps one of them for RedGreen, the Essence will add three mana (one for
* each other Mossfire Valley) of any combination of Red and/or Green to
* that player’s mana pool.
*
* 6/1/2005 If Sasaya’s Essence’s controller has two Brushlands and taps one
* of them for White, Sasaya’s Essence adds another White to that player’s
* mana pool. It won’t produce Green or Colorless unless the land was tapped
* for Green or Colorless instead.
*/
@Override
public Mana produceMana(Game game, Ability source) {
Mana newMana = new Mana();
if (game == null) {
return newMana;
}
Player controller = game.getPlayer(source.getControllerId());
Mana mana = (Mana) this.getValue("mana");
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (controller != null && mana != null && permanent != null) {
FilterPermanent filter = new FilterLandPermanent();
filter.add(Predicates.not(new PermanentIdPredicate(permanent.getId())));
filter.add(new NamePredicate(permanent.getName()));
int count = game.getBattlefield().countAll(filter, controller.getId(), game);
if (count > 0) {
Choice choice = new ChoiceColor(true);
choice.getChoices().clear();
choice.setMessage("Pick the type of mana to produce");
if (mana.getBlack() > 0) {
choice.getChoices().add("Black");
}
if (mana.getRed() > 0) {
choice.getChoices().add("Red");
}
if (mana.getBlue() > 0) {
choice.getChoices().add("Blue");
}
if (mana.getGreen() > 0) {
choice.getChoices().add("Green");
}
if (mana.getWhite() > 0) {
choice.getChoices().add("White");
}
if (mana.getColorless() > 0) {
choice.getChoices().add("Colorless");
}
if (!choice.getChoices().isEmpty()) {
for (int i = 0; i < count; i++) {
choice.clearChoice();
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!controller.choose(outcome, choice, game)) {
return newMana;
}
}
switch(choice.getChoice()) {
case "Black":
newMana.increaseBlack();
break;
case "Blue":
newMana.increaseBlue();
break;
case "Red":
newMana.increaseRed();
break;
case "Green":
newMana.increaseGreen();
break;
case "White":
newMana.increaseWhite();
break;
case "Colorless":
newMana.increaseColorless();
break;
}
}
}
}
}
return newMana;
}
Aggregations