diff --git a/Mage.Sets/src/mage/cards/g/GoblinBarrage.java b/Mage.Sets/src/mage/cards/g/GoblinBarrage.java new file mode 100644 index 00000000000..5f52d742092 --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GoblinBarrage.java @@ -0,0 +1,93 @@ +/* + * 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.cards.g; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.condition.common.KickedCondition; +import mage.abilities.costs.common.SacrificeTargetCost; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DamageTargetEffect; +import mage.abilities.keyword.KickerAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.filter.common.FilterControlledPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.game.Game; +import mage.target.common.TargetControlledPermanent; +import mage.target.common.TargetCreaturePermanent; +import mage.target.common.TargetPlayerOrPlaneswalker; +import mage.target.targetpointer.SecondTargetPointer; + +/** + * + * @author LevelX2 + */ +public class GoblinBarrage extends CardImpl { + + public GoblinBarrage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{3}{R}"); + + // Kicker—Sacrifice an artifact or Goblin. + FilterControlledPermanent filter = new FilterControlledPermanent("an artifact or Goblin"); + filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT), new SubtypePredicate(SubType.GOBLIN))); + this.addAbility(new KickerAbility(new SacrificeTargetCost(new TargetControlledPermanent(filter)))); + + // Goblin Barrage deals 4 damage to target creature. If this spell was kicked, it also deals 4 damage to target player or planeswalker. + this.getSpellAbility().addEffect(new DamageTargetEffect(4).setUseOnlyTargetPointer(true)); + this.getSpellAbility().addTarget(new TargetCreaturePermanent()); + + ConditionalOneShotEffect effect = new ConditionalOneShotEffect( + (OneShotEffect) new DamageTargetEffect(4).setUseOnlyTargetPointer(true), KickedCondition.instance, + "If this spell was kicked, it also deals 4 damage to target player or planeswalker."); + effect.setTargetPointer(new SecondTargetPointer()); + this.getSpellAbility().addEffect(effect); + + } + + @Override + public void adjustTargets(Ability ability, Game game) { + if (KickedCondition.instance.apply(game, ability)) { + ability.addTarget(new TargetPlayerOrPlaneswalker()); + } + } + + public GoblinBarrage(final GoblinBarrage card) { + super(card); + } + + @Override + public GoblinBarrage copy() { + return new GoblinBarrage(this); + } +} diff --git a/Mage.Sets/src/mage/sets/Dominaria.java b/Mage.Sets/src/mage/sets/Dominaria.java index 5dae8dfa313..94fa160217f 100644 --- a/Mage.Sets/src/mage/sets/Dominaria.java +++ b/Mage.Sets/src/mage/sets/Dominaria.java @@ -130,6 +130,7 @@ public class Dominaria extends ExpansionSet { cards.add(new SetCardInfo("Gideon's Reproach", 19, Rarity.COMMON, mage.cards.g.GideonsReproach.class)); cards.add(new SetCardInfo("Gift of Growth", 163, Rarity.COMMON, mage.cards.g.GiftofGrowth.class)); cards.add(new SetCardInfo("Gilded Lotus", 215, Rarity.RARE, mage.cards.g.GildedLotus.class)); + cards.add(new SetCardInfo("Goblin Barrage", 128, Rarity.UNCOMMON, mage.cards.g.GoblinBarrage.class)); cards.add(new SetCardInfo("Goblin Chainwhirler", 129, Rarity.RARE, mage.cards.g.GoblinChainwhirler.class)); cards.add(new SetCardInfo("Goblin Warchief", 130, Rarity.UNCOMMON, mage.cards.g.GoblinWarchief.class)); cards.add(new SetCardInfo("Grow from the Ashes", 164, Rarity.COMMON, mage.cards.g.GrowFromTheAshes.class)); diff --git a/Mage/src/main/java/mage/filter/common/FilterPlayerOrPlaneswalker.java b/Mage/src/main/java/mage/filter/common/FilterPlayerOrPlaneswalker.java new file mode 100644 index 00000000000..63848adb214 --- /dev/null +++ b/Mage/src/main/java/mage/filter/common/FilterPlayerOrPlaneswalker.java @@ -0,0 +1,84 @@ +/* + * 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.filter.common; + +import java.util.UUID; +import mage.MageItem; +import mage.filter.FilterImpl; +import mage.filter.FilterInPlay; +import mage.filter.FilterPlayer; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public class FilterPlayerOrPlaneswalker extends FilterImpl implements FilterInPlay { + + protected FilterPlaneswalkerPermanent planeswalkerFilter; + protected final FilterPlayer playerFilter; + + public FilterPlayerOrPlaneswalker() { + this("player or planeswalker"); + } + + public FilterPlayerOrPlaneswalker(String name) { + super(name); + planeswalkerFilter = new FilterPlaneswalkerPermanent(); + playerFilter = new FilterPlayer(); + } + + public FilterPlayerOrPlaneswalker(final FilterPlayerOrPlaneswalker filter) { + super(filter); + this.planeswalkerFilter = filter.planeswalkerFilter.copy(); + this.playerFilter = filter.playerFilter.copy(); + } + + @Override + public boolean checkObjectClass(Object object) { + return true; + } + + @Override + public boolean match(MageItem o, Game game) { + if (o instanceof Player) { + return playerFilter.match((Player) o, game); + } else if (o instanceof Permanent) { + return planeswalkerFilter.match((Permanent) o, game); + } + return false; + } + + @Override + public boolean match(MageItem o, UUID sourceId, UUID playerId, Game game) { + if (o instanceof Player) { + return playerFilter.match((Player) o, sourceId, playerId, game); + } else if (o instanceof Permanent) { + return planeswalkerFilter.match((Permanent) o, sourceId, playerId, game); + } + return false; + } + + public FilterPlaneswalkerPermanent getPlaneswalkerFilter() { + return this.planeswalkerFilter; + } + + public FilterPlayer getPlayerFilter() { + return this.playerFilter; + } + + public void setPlaneswalkerFilter(FilterPlaneswalkerPermanent planeswalkerFilter) { + this.planeswalkerFilter = planeswalkerFilter; + } + + @Override + public FilterPlayerOrPlaneswalker copy() { + return new FilterPlayerOrPlaneswalker(this); + } + +} diff --git a/Mage/src/main/java/mage/target/common/TargetPlayerOrPlaneswalker.java b/Mage/src/main/java/mage/target/common/TargetPlayerOrPlaneswalker.java new file mode 100644 index 00000000000..5de959572c9 --- /dev/null +++ b/Mage/src/main/java/mage/target/common/TargetPlayerOrPlaneswalker.java @@ -0,0 +1,221 @@ +/* + * 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.target.common; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; +import mage.constants.Zone; +import mage.filter.Filter; +import mage.filter.common.FilterPlayerOrPlaneswalker; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.TargetImpl; + +/** + * + * @author LevelX2 + */ +public class TargetPlayerOrPlaneswalker extends TargetImpl { + + protected FilterPlayerOrPlaneswalker filter; + + public TargetPlayerOrPlaneswalker() { + this(1, 1, new FilterPlayerOrPlaneswalker()); + } + + public TargetPlayerOrPlaneswalker(int numTargets) { + this(numTargets, numTargets, new FilterPlayerOrPlaneswalker()); + } + + public TargetPlayerOrPlaneswalker(FilterPlayerOrPlaneswalker filter) { + this(1, 1, filter); + } + + public TargetPlayerOrPlaneswalker(int minNumTargets, int maxNumTargets, FilterPlayerOrPlaneswalker filter) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.ALL; + this.filter = filter; + this.targetName = filter.getMessage(); + } + + public TargetPlayerOrPlaneswalker(final TargetPlayerOrPlaneswalker target) { + super(target); + this.filter = target.filter.copy(); + } + + @Override + public Filter getFilter() { + return this.filter; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Permanent permanent = game.getPermanent(id); + if (permanent != null) { + return filter.match(permanent, game); + } + Player player = game.getPlayer(id); + return player != null && filter.match(player, game); + } + + @Override + public boolean canTarget(UUID id, Ability source, Game game) { + return canTarget(source.getControllerId(), id, source, game); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + Permanent permanent = game.getPermanent(id); + Player player = game.getPlayer(id); + + if (source != null) { + MageObject targetSource = game.getObject(source.getSourceId()); + if (permanent != null) { + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); + } + if (player != null) { + return player.canBeTargetedBy(targetSource, source.getControllerId(), game) && filter.match(player, game); + } + } + + if (permanent != null) { + return filter.match(permanent, game); + } + return player != null && filter.match(player, game); + } + + /** + * Checks if there are enough {@link Permanent} or {@link Player} that can + * be chosen. Should only be used for Ability targets since this checks for + * protection, shroud etc. + * + * @param sourceId - the target event source + * @param sourceControllerId - controller of the target event source + * @param game + * @return - true if enough valid {@link Permanent} or {@link Player} exist + */ + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + int count = 0; + MageObject targetSource = game.getObject(sourceId); + for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { + Player player = game.getPlayer(playerId); + if (player != null && player.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(player, game)) { + count++; + if (count >= this.minNumberOfTargets) { + return true; + } + } + } + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { + count++; + if (count >= this.minNumberOfTargets) { + return true; + } + } + } + return false; + } + + /** + * Checks if there are enough {@link Permanent} or {@link Player} that can + * be selected. Should not be used for Ability targets since this does not + * check for protection, shroud etc. + * + * @param sourceControllerId - controller of the select event + * @param game + * @return - true if enough valid {@link Permanent} or {@link Player} exist + */ + @Override + public boolean canChoose(UUID sourceControllerId, Game game) { + int count = 0; + for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { + Player player = game.getPlayer(playerId); + if (player != null && filter.match(player, game)) { + count++; + if (count >= this.minNumberOfTargets) { + return true; + } + } + } + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) { + if (filter.match(permanent, null, sourceControllerId, game)) { + count++; + if (count >= this.minNumberOfTargets) { + return true; + } + } + } + return false; + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(); + MageObject targetSource = game.getObject(sourceId); + for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { + Player player = game.getPlayer(playerId); + if (player != null + && player.canBeTargetedBy(targetSource, sourceControllerId, game) + && filter.getPlayerFilter().match(player, sourceId, sourceControllerId, game)) { + possibleTargets.add(playerId); + } + } + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game) + && filter.getPlaneswalkerFilter().match(permanent, sourceId, sourceControllerId, game)) { + possibleTargets.add(permanent.getId()); + } + } + return possibleTargets; + } + + @Override + public Set possibleTargets(UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(); + for (UUID playerId : game.getState().getPlayersInRange(sourceControllerId, game)) { + Player player = game.getPlayer(playerId); + if (player != null && filter.getPlayerFilter().match(player, game)) { + possibleTargets.add(playerId); + } + } + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPlaneswalkerFilter(), sourceControllerId, game)) { + if (filter.getPlaneswalkerFilter().match(permanent, null, sourceControllerId, game)) { + possibleTargets.add(permanent.getId()); + } + } + return possibleTargets; + } + + @Override + public String getTargetedName(Game game) { + StringBuilder sb = new StringBuilder(); + for (UUID targetId : getTargets()) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + sb.append(permanent.getLogName()).append(' '); + } else { + Player player = game.getPlayer(targetId); + if (player != null) { + sb.append(player.getLogName()).append(' '); + } + } + } + return sb.toString(); + } + + @Override + public TargetPlayerOrPlaneswalker copy() { + return new TargetPlayerOrPlaneswalker(this); + } + +}