From 6518b56d9d267c83334fc160287ad5a27e74171b Mon Sep 17 00:00:00 2001 From: Styxo Date: Mon, 29 Aug 2016 13:04:40 +0200 Subject: [PATCH] Refactored multiple CreatureCondition classes into one CreatureCountCondition class --- .../sets/avacynrestored/DemonicRising.java | 6 +- .../avacynrestored/HomicidalSeclusion.java | 7 +- .../sets/avacynrestored/PredatorsGambit.java | 6 +- .../dragonsoftarkir/DeadlyWanderings.java | 11 ++- .../sets/fatereforged/JeskaiInfiltrator.java | 5 +- .../mage/sets/magic2012/CallToTheGrave.java | 5 +- .../src/mage/sets/planarchaos/Pyrohemia.java | 9 +- .../src/mage/sets/tempest/Kezzerdrix.java | 10 ++- .../src/mage/sets/theros/ErebossEmissary.java | 12 +-- .../src/mage/sets/urzassaga/Pestilence.java | 6 +- .../common/CreatureCountCondition.java | 82 +++++++++++++++++++ .../common/NoControlledCreatureCondition.java | 52 ------------ .../condition/common/NoCreatureCondition.java | 52 ------------ .../common/NoCreatureOpponentCondition.java | 62 -------------- .../OneControlledCreatureCondition.java | 58 ------------- .../common/SourceHasSubtypeCondition.java | 18 ++-- 16 files changed, 136 insertions(+), 265 deletions(-) create mode 100644 Mage/src/main/java/mage/abilities/condition/common/CreatureCountCondition.java delete mode 100644 Mage/src/main/java/mage/abilities/condition/common/NoControlledCreatureCondition.java delete mode 100644 Mage/src/main/java/mage/abilities/condition/common/NoCreatureCondition.java delete mode 100644 Mage/src/main/java/mage/abilities/condition/common/NoCreatureOpponentCondition.java delete mode 100644 Mage/src/main/java/mage/abilities/condition/common/OneControlledCreatureCondition.java diff --git a/Mage.Sets/src/mage/sets/avacynrestored/DemonicRising.java b/Mage.Sets/src/mage/sets/avacynrestored/DemonicRising.java index 5e6550a2a95..831bfe57a46 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/DemonicRising.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/DemonicRising.java @@ -31,13 +31,13 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.abilities.TriggeredAbility; import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility; -import mage.abilities.condition.common.OneControlledCreatureCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.CreateTokenEffect; import mage.cards.CardImpl; import mage.game.permanent.token.DemonToken; - import java.util.UUID; +import mage.abilities.condition.common.CreatureCountCondition; +import mage.constants.TargetController; /** * @author noxx @@ -52,7 +52,7 @@ public class DemonicRising extends CardImpl { // At the beginning of your end step, if you control exactly one creature, put a 5/5 black Demon creature token with flying onto the battlefield. TriggeredAbility ability = new BeginningOfYourEndStepTriggeredAbility(new CreateTokenEffect(new DemonToken()), false); - this.addAbility(new ConditionalTriggeredAbility(ability, OneControlledCreatureCondition.getInstance(), ruleText)); + this.addAbility(new ConditionalTriggeredAbility(ability, new CreatureCountCondition(1, TargetController.YOU), ruleText)); } public DemonicRising(final DemonicRising card) { diff --git a/Mage.Sets/src/mage/sets/avacynrestored/HomicidalSeclusion.java b/Mage.Sets/src/mage/sets/avacynrestored/HomicidalSeclusion.java index e335e302a94..c4cbc9dea81 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/HomicidalSeclusion.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/HomicidalSeclusion.java @@ -30,7 +30,7 @@ package mage.sets.avacynrestored; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.common.OneControlledCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; @@ -41,6 +41,7 @@ import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Rarity; +import mage.constants.TargetController; import mage.constants.Zone; /** @@ -56,10 +57,10 @@ public class HomicidalSeclusion extends CardImpl { // As long as you control exactly one creature, that creature gets +3/+1 and has lifelink. ContinuousEffect boostEffect = new BoostControlledEffect(3, 1, Duration.WhileOnBattlefield); - Effect effect = new ConditionalContinuousEffect(boostEffect, new OneControlledCreatureCondition(), rule); + Effect effect = new ConditionalContinuousEffect(boostEffect, new CreatureCountCondition(1, TargetController.YOU), rule); Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, effect); ContinuousEffect lifelinkEffect = new GainAbilityControlledEffect(LifelinkAbility.getInstance(), Duration.WhileOnBattlefield); - effect = new ConditionalContinuousEffect(lifelinkEffect, new OneControlledCreatureCondition(), "and has lifelink"); + effect = new ConditionalContinuousEffect(lifelinkEffect, new CreatureCountCondition(1, TargetController.YOU), "and has lifelink"); ability.addEffect(effect); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/PredatorsGambit.java b/Mage.Sets/src/mage/sets/avacynrestored/PredatorsGambit.java index 6a5a1f54a0f..a7214753414 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/PredatorsGambit.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/PredatorsGambit.java @@ -30,7 +30,6 @@ package mage.sets.avacynrestored; import mage.constants.*; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.common.OneControlledCreatureCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.common.AttachEffect; @@ -41,8 +40,8 @@ import mage.abilities.keyword.IntimidateAbility; import mage.cards.CardImpl; import mage.target.TargetPermanent; import mage.target.common.TargetCreaturePermanent; - import java.util.UUID; +import mage.abilities.condition.common.CreatureCountCondition; /** * @author noxx @@ -56,7 +55,6 @@ public class PredatorsGambit extends CardImpl { this.expansionSetCode = "AVR"; this.subtype.add("Aura"); - // Enchant creature TargetPermanent auraTarget = new TargetCreaturePermanent(); this.getSpellAbility().addTarget(auraTarget); @@ -70,7 +68,7 @@ public class PredatorsGambit extends CardImpl { // Enchanted creature has intimidate as long as its controller controls no other creatures. ContinuousEffect effect = new GainAbilityAttachedEffect(IntimidateAbility.getInstance(), AttachmentType.AURA); - ConditionalContinuousEffect intimidate = new ConditionalContinuousEffect(effect, new OneControlledCreatureCondition(), rule); + ConditionalContinuousEffect intimidate = new ConditionalContinuousEffect(effect, new CreatureCountCondition(1, TargetController.YOU), rule); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, intimidate)); } diff --git a/Mage.Sets/src/mage/sets/dragonsoftarkir/DeadlyWanderings.java b/Mage.Sets/src/mage/sets/dragonsoftarkir/DeadlyWanderings.java index 8558668fb45..b4ac3daf25d 100644 --- a/Mage.Sets/src/mage/sets/dragonsoftarkir/DeadlyWanderings.java +++ b/Mage.Sets/src/mage/sets/dragonsoftarkir/DeadlyWanderings.java @@ -30,7 +30,7 @@ package mage.sets.dragonsoftarkir; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.common.OneControlledCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.Effect; @@ -42,6 +42,7 @@ import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Rarity; +import mage.constants.TargetController; import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; @@ -57,14 +58,16 @@ public class DeadlyWanderings extends CardImpl { // As long as you control exactly one creature, that creature gets +2/+0 and has deathtouch and lifelink. ContinuousEffect boostEffect = new BoostControlledEffect(2, 0, Duration.WhileOnBattlefield); - Effect effect = new ConditionalContinuousEffect(boostEffect, new OneControlledCreatureCondition(), + Effect effect = new ConditionalContinuousEffect(boostEffect, new CreatureCountCondition(1, TargetController.YOU), "As long as you control exactly one creature, that creature gets +2/+0"); Ability ability = new SimpleStaticAbility(Zone.BATTLEFIELD, effect); ContinuousEffect deathtouchEffect = new GainAbilityControlledEffect(DeathtouchAbility.getInstance(), Duration.WhileOnBattlefield, new FilterCreaturePermanent()); - effect = new ConditionalContinuousEffect(deathtouchEffect, new OneControlledCreatureCondition(), "and has deathtouch"); + effect = new ConditionalContinuousEffect(deathtouchEffect, new CreatureCountCondition(1, TargetController.YOU), + "and has deathtouch"); ability.addEffect(effect); ContinuousEffect lifelinkEffect = new GainAbilityControlledEffect(LifelinkAbility.getInstance(), Duration.WhileOnBattlefield, new FilterCreaturePermanent()); - effect = new ConditionalContinuousEffect(lifelinkEffect, new OneControlledCreatureCondition(), "and lifelink"); + effect = new ConditionalContinuousEffect(lifelinkEffect, new CreatureCountCondition(1, TargetController.YOU), + "and lifelink"); ability.addEffect(effect); this.addAbility(ability); } diff --git a/Mage.Sets/src/mage/sets/fatereforged/JeskaiInfiltrator.java b/Mage.Sets/src/mage/sets/fatereforged/JeskaiInfiltrator.java index 30fc48f26c6..e650c98bf48 100644 --- a/Mage.Sets/src/mage/sets/fatereforged/JeskaiInfiltrator.java +++ b/Mage.Sets/src/mage/sets/fatereforged/JeskaiInfiltrator.java @@ -38,7 +38,7 @@ import mage.MageObjectReference; import mage.abilities.Ability; import mage.abilities.common.DealsCombatDamageToAPlayerTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.condition.common.OneControlledCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalRestrictionEffect; @@ -53,6 +53,7 @@ import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; +import mage.constants.TargetController; import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; @@ -73,7 +74,7 @@ public class JeskaiInfiltrator extends CardImpl { this.toughness = new MageInt(3); // Jeskai Infiltrator can't be blocked as long as you control no other creatures. - Effect effect = new ConditionalRestrictionEffect(new CantBeBlockedSourceEffect(), new OneControlledCreatureCondition()); + Effect effect = new ConditionalRestrictionEffect(new CantBeBlockedSourceEffect(), new CreatureCountCondition(1, TargetController.YOU)); effect.setText("{this} can't be blocked as long as you control no other creatures"); this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); diff --git a/Mage.Sets/src/mage/sets/magic2012/CallToTheGrave.java b/Mage.Sets/src/mage/sets/magic2012/CallToTheGrave.java index ea04b9077fb..b3e0be28741 100644 --- a/Mage.Sets/src/mage/sets/magic2012/CallToTheGrave.java +++ b/Mage.Sets/src/mage/sets/magic2012/CallToTheGrave.java @@ -32,7 +32,7 @@ import mage.abilities.Ability; import mage.abilities.TriggeredAbility; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.OnEventTriggeredAbility; -import mage.abilities.condition.common.NoCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.SacrificeEffect; import mage.abilities.effects.common.SacrificeSourceEffect; @@ -62,13 +62,12 @@ public class CallToTheGrave extends CardImpl { super(ownerId, 85, "Call to the Grave", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{4}{B}"); this.expansionSetCode = "M12"; - // At the beginning of each player's upkeep, that player sacrifices a non-Zombie creature. Ability ability = new BeginningOfUpkeepTriggeredAbility(new SacrificeEffect(filter, 1, "that player "), TargetController.ANY, false); this.addAbility(ability); // At the beginning of the end step, if no creatures are on the battlefield, sacrifice Call to the Grave. TriggeredAbility triggered = new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect()); - this.addAbility(new ConditionalTriggeredAbility(triggered, new NoCreatureCondition(), ruleText)); + this.addAbility(new ConditionalTriggeredAbility(triggered, new CreatureCountCondition(0, TargetController.ANY), ruleText)); } public CallToTheGrave(final CallToTheGrave card) { diff --git a/Mage.Sets/src/mage/sets/planarchaos/Pyrohemia.java b/Mage.Sets/src/mage/sets/planarchaos/Pyrohemia.java index 1c79bd7b92d..b7fb9bf3d30 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/Pyrohemia.java +++ b/Mage.Sets/src/mage/sets/planarchaos/Pyrohemia.java @@ -31,7 +31,7 @@ import java.util.UUID; import mage.abilities.TriggeredAbility; import mage.abilities.common.OnEventTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.common.NoCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.DamageEverythingEffect; @@ -39,6 +39,7 @@ import mage.abilities.effects.common.SacrificeSourceEffect; import mage.cards.CardImpl; import mage.constants.CardType; import mage.constants.Rarity; +import mage.constants.TargetController; import mage.constants.Zone; import mage.game.events.GameEvent; @@ -47,7 +48,7 @@ import mage.game.events.GameEvent; * @author fireshoes */ public class Pyrohemia extends CardImpl { - + private static final String ruleText = "At the beginning of the end step, if no creatures are on the battlefield, sacrifice Pyrohemia."; public Pyrohemia(UUID ownerId) { @@ -56,8 +57,8 @@ public class Pyrohemia extends CardImpl { // At the beginning of the end step, if no creatures are on the battlefield, sacrifice Pyrohemia. TriggeredAbility triggered = new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect()); - this.addAbility(new ConditionalTriggeredAbility(triggered, new NoCreatureCondition(), ruleText)); - + this.addAbility(new ConditionalTriggeredAbility(triggered, new CreatureCountCondition(0, TargetController.ANY), ruleText)); + // {R}: Pyrohemia deals 1 damage to each creature and each player. this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new DamageEverythingEffect(1), new ManaCostsImpl("{R}"))); } diff --git a/Mage.Sets/src/mage/sets/tempest/Kezzerdrix.java b/Mage.Sets/src/mage/sets/tempest/Kezzerdrix.java index e03c0b94e37..29aa8d97598 100644 --- a/Mage.Sets/src/mage/sets/tempest/Kezzerdrix.java +++ b/Mage.Sets/src/mage/sets/tempest/Kezzerdrix.java @@ -33,7 +33,7 @@ import mage.constants.CardType; import mage.constants.Rarity; import mage.MageInt; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; -import mage.abilities.condition.common.NoCreatureOpponentCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.DamageControllerEffect; import mage.abilities.keyword.FirstStrikeAbility; @@ -58,10 +58,12 @@ public class Kezzerdrix extends CardImpl { // First strike this.addAbility(FirstStrikeAbility.getInstance()); - + // At the beginning of your upkeep, if your opponents control no creatures, Kezzerdrix deals 4 damage to you. - ConditionalTriggeredAbility ability = new ConditionalTriggeredAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new DamageControllerEffect(4), TargetController.YOU, false), NoCreatureOpponentCondition.getInstance(), "At the beginning of your upkeep, if your opponents control no creatures, {this} deals 4 damage to you."); - this.addAbility(ability); + this.addAbility(new ConditionalTriggeredAbility( + new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new DamageControllerEffect(4), TargetController.YOU, false), + new CreatureCountCondition(0, TargetController.OPPONENT), + "At the beginning of your upkeep, if your opponents control no creatures, {this} deals 4 damage to you.")); } public Kezzerdrix(final Kezzerdrix card) { diff --git a/Mage.Sets/src/mage/sets/theros/ErebossEmissary.java b/Mage.Sets/src/mage/sets/theros/ErebossEmissary.java index 914d90d2493..3fe02cd87a8 100644 --- a/Mage.Sets/src/mage/sets/theros/ErebossEmissary.java +++ b/Mage.Sets/src/mage/sets/theros/ErebossEmissary.java @@ -27,6 +27,7 @@ */ package mage.sets.theros; +import java.util.Arrays; import java.util.UUID; import mage.MageInt; import mage.abilities.common.SimpleActivatedAbility; @@ -55,21 +56,22 @@ public class ErebossEmissary extends CardImpl { super(ownerId, 86, "Erebos's Emissary", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT, CardType.CREATURE}, "{3}{B}"); this.expansionSetCode = "THS"; this.subtype.add("Snake"); - this.power = new MageInt(3); this.toughness = new MageInt(3); // Bestow {5}{B} this.addAbility(new BestowAbility(this, "{5}{B}")); + // Discard a creature card: Erebos's Emissary gets +2/+2 until end of turn. If Erebos's Emissary is an Aura, enchanted creature gets +2/+2 until end of turn instead. this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect( - new BoostEnchantedEffect(2,2, Duration.EndOfTurn), - new BoostSourceEffect(2,2, Duration.EndOfTurn), - new SourceHasSubtypeCondition("Aura"), + new BoostEnchantedEffect(2, 2, Duration.EndOfTurn), + new BoostSourceEffect(2, 2, Duration.EndOfTurn), + new SourceHasSubtypeCondition(Arrays.asList("Aura")), "{this} gets +2/+2 until end of turn. If Erebos's Emissary is an Aura, enchanted creature gets +2/+2 until end of turn instead"), new DiscardTargetCost(new TargetCardInHand(new FilterCreatureCard())))); + // Enchanted creature gets +3/+3 - this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(3,3, Duration.WhileOnBattlefield))); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEnchantedEffect(3, 3, Duration.WhileOnBattlefield))); } public ErebossEmissary(final ErebossEmissary card) { diff --git a/Mage.Sets/src/mage/sets/urzassaga/Pestilence.java b/Mage.Sets/src/mage/sets/urzassaga/Pestilence.java index 375939ea64a..ddda1f21cbd 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/Pestilence.java +++ b/Mage.Sets/src/mage/sets/urzassaga/Pestilence.java @@ -34,12 +34,13 @@ import mage.constants.Rarity; import mage.abilities.TriggeredAbility; import mage.abilities.common.OnEventTriggeredAbility; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.common.NoCreatureCondition; +import mage.abilities.condition.common.CreatureCountCondition; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.decorator.ConditionalTriggeredAbility; import mage.abilities.effects.common.DamageEverythingEffect; import mage.abilities.effects.common.SacrificeSourceEffect; import mage.cards.CardImpl; +import mage.constants.TargetController; import mage.constants.Zone; import mage.game.events.GameEvent; @@ -55,10 +56,9 @@ public class Pestilence extends CardImpl { super(ownerId, 147, "Pestilence", Rarity.COMMON, new CardType[]{CardType.ENCHANTMENT}, "{2}{B}{B}"); this.expansionSetCode = "USG"; - // At the beginning of the end step, if no creatures are on the battlefield, sacrifice Pestilence. TriggeredAbility triggered = new OnEventTriggeredAbility(GameEvent.EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect()); - this.addAbility(new ConditionalTriggeredAbility(triggered, new NoCreatureCondition(), ruleText)); + this.addAbility(new ConditionalTriggeredAbility(triggered, new CreatureCountCondition(0, TargetController.ANY), ruleText)); // {B}: Pestilence deals 1 damage to each creature and each player. this.addAbility(new SimpleActivatedAbility(Zone.BATTLEFIELD, new DamageEverythingEffect(1), new ManaCostsImpl("{B}"))); diff --git a/Mage/src/main/java/mage/abilities/condition/common/CreatureCountCondition.java b/Mage/src/main/java/mage/abilities/condition/common/CreatureCountCondition.java new file mode 100644 index 00000000000..c4cfce4e977 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/CreatureCountCondition.java @@ -0,0 +1,82 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package mage.abilities.condition.common; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.constants.TargetController; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; + +/** + * + * @author Styxo + */ +public class CreatureCountCondition implements Condition { + + private FilterCreaturePermanent filter; + private int creatureCount; + private TargetController targetController; + + public CreatureCountCondition(FilterCreaturePermanent filter, int creatureCount, TargetController targetController) { + this.filter = filter; + this.creatureCount = creatureCount; + this.targetController = targetController; + } + + public CreatureCountCondition(int creatureCount, TargetController targetController) { + this.filter = new FilterCreaturePermanent(); + this.creatureCount = creatureCount; + this.targetController = targetController; + + } + + @Override + public boolean apply(Game game, Ability source) { + switch (targetController) { + case YOU: + return game.getBattlefield().countAll(filter, source.getControllerId(), game) == creatureCount; + case OPPONENT: + for (UUID opponent : game.getOpponents(source.getControllerId())) { + if (game.getBattlefield().countAll(filter, opponent, game) != creatureCount) { + return false; + } + } + return true; + case ANY: + return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == creatureCount; + default: + throw new UnsupportedOperationException("Value for targetController not supported: " + targetController.toString()); + } + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + switch (targetController) { + case YOU: + sb.append("you"); + break; + case OPPONENT: + sb.append("your opponents"); + break; + case ANY: + sb.append("if "); + sb.append(creatureCount); + sb.append(" "); + sb.append(filter.getMessage()); + sb.append(" are on the battlefield"); + return sb.toString(); + } + sb.append(" control exactly "); + sb.append(creatureCount); + sb.append(" "); + sb.append(filter.getMessage()); + + return sb.toString(); + } +} diff --git a/Mage/src/main/java/mage/abilities/condition/common/NoControlledCreatureCondition.java b/Mage/src/main/java/mage/abilities/condition/common/NoControlledCreatureCondition.java deleted file mode 100644 index d41a8682ae9..00000000000 --- a/Mage/src/main/java/mage/abilities/condition/common/NoControlledCreatureCondition.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of BetaSteward_at_googlemail.com. - */ -package mage.abilities.condition.common; - -import mage.abilities.Ability; -import mage.abilities.condition.Condition; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; - -/** - * @author noxx - */ -public class NoControlledCreatureCondition implements Condition { - - private static NoControlledCreatureCondition fInstance = new NoControlledCreatureCondition(); - - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); - - public static Condition getInstance() { - return fInstance; - } - - @Override - public boolean apply(Game game, Ability source) { - return game.getBattlefield().countAll(filter, source.getControllerId(), game) == 0; - } -} diff --git a/Mage/src/main/java/mage/abilities/condition/common/NoCreatureCondition.java b/Mage/src/main/java/mage/abilities/condition/common/NoCreatureCondition.java deleted file mode 100644 index 9bfdc3b92a2..00000000000 --- a/Mage/src/main/java/mage/abilities/condition/common/NoCreatureCondition.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of BetaSteward_at_googlemail.com. - */ -package mage.abilities.condition.common; - -import mage.abilities.Ability; -import mage.abilities.condition.Condition; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; - -/** - * @author nantuko - */ -public class NoCreatureCondition implements Condition { - - private static final NoCreatureCondition fInstance = new NoCreatureCondition(); - - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); - - public static Condition getInstance() { - return fInstance; - } - - @Override - public boolean apply(Game game, Ability source) { - return game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0; - } -} diff --git a/Mage/src/main/java/mage/abilities/condition/common/NoCreatureOpponentCondition.java b/Mage/src/main/java/mage/abilities/condition/common/NoCreatureOpponentCondition.java deleted file mode 100644 index f658c684007..00000000000 --- a/Mage/src/main/java/mage/abilities/condition/common/NoCreatureOpponentCondition.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of BetaSteward_at_googlemail.com. - */ -package mage.abilities.condition.common; - -import java.util.UUID; -import mage.abilities.Ability; -import mage.abilities.condition.Condition; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; - -/** - * @author jeff - */ -public class NoCreatureOpponentCondition implements Condition { - - private static NoCreatureOpponentCondition fInstance = new NoCreatureOpponentCondition(); - - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); - - public static Condition getInstance() { - return fInstance; - } - - @Override - public boolean apply(Game game, Ability source) { - int condition = 0; - for (UUID opponent : game.getOpponents(source.getControllerId())) { - if (game.getBattlefield().countAll(filter, opponent, game) == 0) { - condition++; - } - } - if (condition == 0) - return false; - else return true; - } -} - diff --git a/Mage/src/main/java/mage/abilities/condition/common/OneControlledCreatureCondition.java b/Mage/src/main/java/mage/abilities/condition/common/OneControlledCreatureCondition.java deleted file mode 100644 index 44e38f97f41..00000000000 --- a/Mage/src/main/java/mage/abilities/condition/common/OneControlledCreatureCondition.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, are - * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED - * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * The views and conclusions contained in the software and documentation are those of the - * authors and should not be interpreted as representing official policies, either expressed - * or implied, of BetaSteward_at_googlemail.com. - */ -package mage.abilities.condition.common; - -import mage.abilities.Ability; -import mage.abilities.condition.Condition; -import mage.filter.common.FilterCreaturePermanent; -import mage.game.Game; - -/** - * @author noxx - */ -public class OneControlledCreatureCondition implements Condition { - - private static final OneControlledCreatureCondition fInstance = new OneControlledCreatureCondition(); - - private static final FilterCreaturePermanent filter = new FilterCreaturePermanent(); - - public static Condition getInstance() { - return fInstance; - } - - @Override - public boolean apply(Game game, Ability source) { - return game.getBattlefield().countAll(filter, source.getControllerId(), game) == 1; - } - - @Override - public String toString() { - return "you control exactly one creature"; - } - -} diff --git a/Mage/src/main/java/mage/abilities/condition/common/SourceHasSubtypeCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SourceHasSubtypeCondition.java index 21852e227e3..bcd187e2c08 100644 --- a/Mage/src/main/java/mage/abilities/condition/common/SourceHasSubtypeCondition.java +++ b/Mage/src/main/java/mage/abilities/condition/common/SourceHasSubtypeCondition.java @@ -1,5 +1,7 @@ package mage.abilities.condition.common; +import java.util.List; +import java.util.Set; import mage.abilities.Ability; import mage.abilities.condition.Condition; import mage.game.Game; @@ -11,17 +13,21 @@ import mage.game.permanent.Permanent; */ public class SourceHasSubtypeCondition implements Condition { - private final String subtype; - - public SourceHasSubtypeCondition(String subtype) { - this.subtype = subtype; + private final List subtypes; + + public SourceHasSubtypeCondition(List subtypes) { + this.subtypes = subtypes; } - + @Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { - return permanent.hasSubtype(subtype); + for (String subtype : subtypes) { + if (permanent.hasSubtype(subtype)) { + return true; + } + } } return false; }