From 181d48e24b2245806415887dd8ead5074dfd68b7 Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Thu, 19 May 2011 22:38:13 -0400 Subject: [PATCH] added Auriok Replica --- .../sets/scarsofmirrodin/AuriokReplica.java | 138 ++++++++++++++++ Mage/src/mage/target/TargetSource.java | 151 ++++++++++++++++++ 2 files changed, 289 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/scarsofmirrodin/AuriokReplica.java create mode 100644 Mage/src/mage/target/TargetSource.java diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/AuriokReplica.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/AuriokReplica.java new file mode 100644 index 0000000000..8c39f90242 --- /dev/null +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/AuriokReplica.java @@ -0,0 +1,138 @@ +/* + * Copyright 2011 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.sets.scarsofmirrodin; + +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.Zone; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.common.SacrificeSourceCost; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.PreventionEffectImpl; +import mage.cards.CardImpl; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.target.TargetSource; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class AuriokReplica extends CardImpl { + + public AuriokReplica(UUID ownerId) { + super(ownerId, 138, "Auriok Replica", Rarity.COMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); + this.expansionSetCode = "SOM"; + this.subtype.add("Cleric"); + this.power = new MageInt(2); + this.toughness = new MageInt(3); + + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AuriokReplicaEffect(), new ManaCostsImpl("{W}")); + ability.addCost(new SacrificeSourceCost()); + this.addAbility(ability); + } + + public AuriokReplica(final AuriokReplica card) { + super(card); + } + + @Override + public AuriokReplica copy() { + return new AuriokReplica(this); + } + +} + +class AuriokReplicaEffect extends PreventionEffectImpl { + + private TargetSource target = new TargetSource(); + + public AuriokReplicaEffect() { + super(Duration.EndOfTurn); + } + + public AuriokReplicaEffect(final AuriokReplicaEffect effect) { + super(effect); + this.target = effect.target.copy(); + } + + @Override + public AuriokReplicaEffect copy() { + return new AuriokReplicaEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public void init(Ability source, Game game) { + this.target.choose(Outcome.PreventDamage, source.getControllerId(), game); + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { + preventDamage(event, source, target.getFirstTarget(), game); + return true; + } + return false; + } + + private void preventDamage(GameEvent event, Ability source, UUID target, Game game) { + GameEvent preventEvent = new GameEvent(GameEvent.EventType.PREVENT_DAMAGE, target, source.getId(), source.getControllerId(), event.getAmount(), false); + if (!game.replaceEvent(preventEvent)) { + int damage = event.getAmount(); + event.setAmount(0); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.PREVENTED_DAMAGE, target, source.getId(), source.getControllerId(), damage)); + } + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (!this.used && super.applies(event, source, game)) { + if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(target.getFirstTarget())) { + return true; + } + } + return false; + } + + @Override + public String getText(Ability source) { + return "Prevent all damage a source of your choice would deal to you this turn"; + } + +} \ No newline at end of file diff --git a/Mage/src/mage/target/TargetSource.java b/Mage/src/mage/target/TargetSource.java new file mode 100644 index 0000000000..880160c81c --- /dev/null +++ b/Mage/src/mage/target/TargetSource.java @@ -0,0 +1,151 @@ +/* + * Copyright 2011 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.target; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.Constants.Zone; +import mage.MageObject; +import mage.abilities.Ability; +import mage.filter.FilterObject; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.game.stack.StackObject; + +/** + * + * @author BetaSteward_at_googlemail.com + */ +public class TargetSource extends TargetObject { + + protected FilterObject filter; + + public TargetSource() { + this(1, 1, new FilterObject("source of your choice")); + } + + public TargetSource(FilterObject filter) { + this(1, 1, filter); + } + + public TargetSource(int numTargets, FilterObject filter) { + this(numTargets, numTargets, filter); + } + + public TargetSource(int minNumTargets, int maxNumTargets, FilterObject filter) { + this.minNumberOfTargets = minNumTargets; + this.maxNumberOfTargets = maxNumTargets; + this.zone = Zone.ALL; + this.filter = filter; + this.targetName = filter.getMessage(); + } + + public TargetSource(final TargetSource target) { + super(target); + this.filter = target.filter.copy(); + } + + @Override + public FilterObject getFilter() { + return filter; + } + + @Override + public void add(UUID id, Game game) { + if (targets.size() < maxNumberOfTargets) { + if (!targets.containsKey(id)) { + MageObject object = game.getObject(id); + if (object != null && object instanceof StackObject) { + targets.put(((StackObject) object).getSourceId(), 0); + } + else { + targets.put(id, 0); + } + } + } + } + + @Override + public boolean canTarget(UUID id, Ability source, Game game) { + return true; + } + + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + return canChoose(sourceControllerId, game); + } + + @Override + public boolean canChoose(UUID sourceControllerId, Game game) { + int count = 0; + for (StackObject stackObject: game.getStack()) { + if (game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match(stackObject)) { + count++; + if (count >= this.minNumberOfTargets) + return true; + } + } + for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) { + if (filter.match(permanent)) { + count++; + if (count >= this.minNumberOfTargets) + return true; + } + } + return false; + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + return possibleTargets(sourceControllerId, game); + } + + @Override + public Set possibleTargets(UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet(); + for (StackObject stackObject: game.getStack()) { + if (game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getControllerId()) && filter.match(stackObject)) { + possibleTargets.add(stackObject.getId()); + } + } + for (Permanent permanent: game.getBattlefield().getActivePermanents(sourceControllerId, game)) { + if (filter.match(permanent)) { + possibleTargets.add(permanent.getId()); + } + } + return possibleTargets; + } + + @Override + public TargetSource copy() { + return new TargetSource(this); + } + +}