From d2bc10d214deed0ef4e5a66df84736972476b2a0 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sun, 12 Nov 2017 09:51:12 +0100 Subject: [PATCH] Implemented Spawnbroker --- Mage.Sets/src/mage/cards/s/Spawnbroker.java | 174 ++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/s/Spawnbroker.java diff --git a/Mage.Sets/src/mage/cards/s/Spawnbroker.java b/Mage.Sets/src/mage/cards/s/Spawnbroker.java new file mode 100644 index 00000000000..fcd1688cf4f --- /dev/null +++ b/Mage.Sets/src/mage/cards/s/Spawnbroker.java @@ -0,0 +1,174 @@ +/* + * 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.s; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.MageInt; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.common.continuous.ExchangeControlTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.TargetController; +import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.TargetPermanent; +import mage.target.common.TargetControlledPermanent; + +/** + * + * @author jeffwadsworth & L_J + */ +public class Spawnbroker extends CardImpl { + + private static final String rule = "you may exchange control of target creature you control and target creature with power less than or equal to that creature's power an opponent controls"; + + public Spawnbroker(UUID ownerId, CardSetInfo setInfo) { + super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{U}"); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WIZARD); + this.power = new MageInt(1); + this.toughness = new MageInt(1); + + // When Spawnbroker enters the battlefield, you may exchange control of target creature you control and target creature with power less than or equal to that creature's power an opponent controls. + Ability ability = new EntersBattlefieldTriggeredAbility(new ExchangeControlTargetEffect(Duration.Custom, rule, false, true), true); + ability.addTarget(new TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent()); + ability.addTarget(new SpawnbrokerSecondTarget()); + this.addAbility(ability); + + } + + public Spawnbroker(final Spawnbroker card) { + super(card); + } + + @Override + public Spawnbroker copy() { + return new Spawnbroker(this); + } +} + +class TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent extends TargetControlledPermanent { + + public TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent() { + super(); + filter.add(new CardTypePredicate(CardType.CREATURE)); + setTargetName("creature you control"); + } + + public TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent(final TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent target) { + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + return super.canTarget(controllerId, id, source, game); + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(); + MageObject targetSource = game.getObject(sourceId); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { + if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { + possibleTargets.add(permanent.getId()); + } + } + return possibleTargets; + } + + @Override + public TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent copy() { + return new TargetControlledCreatureWithPowerGreaterOrLessThanOpponentPermanent(this); + } +} + +class SpawnbrokerSecondTarget extends TargetPermanent { + + private Permanent firstTarget = null; + + public SpawnbrokerSecondTarget() { + super(); + filter.add(new ControllerPredicate(TargetController.OPPONENT)); + filter.add(new CardTypePredicate(CardType.CREATURE)); + setTargetName("creature with power less than or equal to that creature's power an opponent controls"); + } + + public SpawnbrokerSecondTarget(final SpawnbrokerSecondTarget target) { + super(target); + this.firstTarget = target.firstTarget; + } + + @Override + public boolean canTarget(UUID id, Ability source, Game game) { + if (super.canTarget(id, source, game)) { + Permanent target1 = game.getPermanent(source.getFirstTarget()); + Permanent opponentPermanent = game.getPermanent(id); + if (target1 != null && opponentPermanent != null) { + return target1.getPower().getValue() >= opponentPermanent.getPower().getValue(); + } + } + return false; + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(); + if (firstTarget != null) { + MageObject targetSource = game.getObject(sourceId); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { + if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { + if (firstTarget.getPower().getValue() >= permanent.getPower().getValue()) { + possibleTargets.add(permanent.getId()); + } + } + } + } + return possibleTargets; + } + + @Override + public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) { + firstTarget = game.getPermanent(source.getFirstTarget()); + return super.chooseTarget(Outcome.GainControl, playerId, source, game); + } + + @Override + public SpawnbrokerSecondTarget copy() { + return new SpawnbrokerSecondTarget(this); + } +}