From 85430928d8629f57fdbe8c51942bf9c0a05c3215 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Sun, 21 Aug 2011 19:30:10 +0400 Subject: [PATCH] [M12] Adaptive Automaton --- Mage.Sets/src/mage/sets/Sets.java | 11 ++ .../sets/magic2012/AdaptiveAutomaton.java | 179 ++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java diff --git a/Mage.Sets/src/mage/sets/Sets.java b/Mage.Sets/src/mage/sets/Sets.java index e9be05b736..41f85c32bf 100644 --- a/Mage.Sets/src/mage/sets/Sets.java +++ b/Mage.Sets/src/mage/sets/Sets.java @@ -55,6 +55,7 @@ public class Sets extends HashMap { private static final Sets fINSTANCE = new Sets(); private static Set names; private static Set nonLandNames; + private static Set creatureTypes; private static List cards; protected static Random rnd = new Random(); @@ -66,6 +67,7 @@ public class Sets extends HashMap { names = new TreeSet(); nonLandNames = new TreeSet(); cards = new ArrayList(); + creatureTypes = new TreeSet(); this.addSet(AlaraReborn.getInstance()); this.addSet(Apocalypse.getInstance()); this.addSet(ChampionsOfKamigawa.getInstance()); @@ -101,6 +103,11 @@ public class Sets extends HashMap { for (Card card: set.getCards()) { cards.add(card); names.add(card.getName()); + if (card.getCardType().contains(CardType.CREATURE)) { + for (String type : card.getSubtype()) { + creatureTypes.add(type); + } + } if (!card.getCardType().contains(CardType.LAND)) nonLandNames.add(card.getName()); } } @@ -113,6 +120,10 @@ public class Sets extends HashMap { return nonLandNames; } + public static Set getCreatureTypes() { + return creatureTypes; + } + public static Card getRandomCard() { return cards.get(rnd.nextInt(cards.size())); } diff --git a/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java new file mode 100644 index 0000000000..8de273b2c7 --- /dev/null +++ b/Mage.Sets/src/mage/sets/magic2012/AdaptiveAutomaton.java @@ -0,0 +1,179 @@ +/* + * 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.sets.magic2012; + +import mage.Constants; +import mage.Constants.CardType; +import mage.Constants.Rarity; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.OneShotEffect; +import mage.cards.CardImpl; +import mage.choices.Choice; +import mage.choices.ChoiceImpl; +import mage.filter.common.FilterCreaturePermanent; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.sets.Sets; + +import java.util.UUID; + +import static mage.Constants.Duration; + +/** + * @author nantuko + */ +public class AdaptiveAutomaton extends CardImpl { + + public AdaptiveAutomaton(UUID ownerId) { + super(ownerId, 201, "Adaptive Automaton", Rarity.RARE, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); + this.expansionSetCode = "M12"; + this.subtype.add("Construct"); + + this.power = new MageInt(2); + this.toughness = new MageInt(2); + + // As Adaptive Automaton enters the battlefield, choose a creature type. + this.addAbility(new EntersBattlefieldAbility(new AdaptiveAutomatonEffect())); + // Adaptive Automaton is the chosen type in addition to its other types. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new AdaptiveAutomatonAddSubtypeEffect())); + // Other creatures you control of the chosen type get +1/+1. + this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new AdaptiveAutomatonBoostControlledEffect())); + } + + public AdaptiveAutomaton(final AdaptiveAutomaton card) { + super(card); + } + + @Override + public AdaptiveAutomaton copy() { + return new AdaptiveAutomaton(this); + } +} + +class AdaptiveAutomatonEffect extends OneShotEffect { + + public AdaptiveAutomatonEffect() { + super(Constants.Outcome.DrawCard); + staticText = "As Adaptive Automaton enters the battlefield, choose a creature type"; + } + + public AdaptiveAutomatonEffect(final AdaptiveAutomatonEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = game.getPermanent(source.getSourceId()); + if (player != null && permanent != null) { + Choice typeChoice = new ChoiceImpl(true); + typeChoice.setChoices(Sets.getCreatureTypes()); + if (player.choose(Constants.Outcome.BoostCreature, typeChoice, game)) { + game.informPlayers(permanent.getName() + ": " + player.getName() + " has chosen " + typeChoice.getChoice()); + game.getState().setValue(permanent.getId() + "_type", typeChoice.getChoice()); + } + } + return false; + } + + @Override + public AdaptiveAutomatonEffect copy() { + return new AdaptiveAutomatonEffect(this); + } + +} + +class AdaptiveAutomatonAddSubtypeEffect extends ContinuousEffectImpl { + public AdaptiveAutomatonAddSubtypeEffect() { + super(Duration.WhileOnBattlefield, Constants.Layer.TypeChangingEffects_4, Constants.SubLayer.NA, Constants.Outcome.Benefit); + staticText = "Adaptive Automaton is the chosen type in addition to its other types"; + } + + public AdaptiveAutomatonAddSubtypeEffect(final AdaptiveAutomatonAddSubtypeEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + String subtype = (String) game.getState().getValue(permanent.getId() + "_type"); + if (subtype != null && !permanent.getSubtype().contains(subtype)) { + permanent.getSubtype().add(subtype); + } + } + return true; + } + + @Override + public AdaptiveAutomatonAddSubtypeEffect copy() { + return new AdaptiveAutomatonAddSubtypeEffect(this); + } +} + +class AdaptiveAutomatonBoostControlledEffect extends ContinuousEffectImpl { + + private static final FilterCreaturePermanent filter = FilterCreaturePermanent.getDefault(); + + public AdaptiveAutomatonBoostControlledEffect() { + super(Duration.WhileOnBattlefield, Constants.Layer.PTChangingEffects_7, Constants.SubLayer.ModifyPT_7c, Constants.Outcome.BoostCreature); + staticText = "Other creatures you control of the chosen type get +1/+1"; + } + + public AdaptiveAutomatonBoostControlledEffect(final AdaptiveAutomatonBoostControlledEffect effect) { + super(effect); + } + + @Override + public AdaptiveAutomatonBoostControlledEffect copy() { + return new AdaptiveAutomatonBoostControlledEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + String subtype = (String) game.getState().getValue(permanent.getId() + "_type"); + if (subtype != null) { + for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId())) { + if (!perm.getId().equals(source.getSourceId()) && perm.hasSubtype(subtype)) { + perm.addPower(1); + perm.addToughness(1); + } + } + } + } + return true; + } + +}