From 7badc7ff967b7993296c8cc95a2269434ffc0d82 Mon Sep 17 00:00:00 2001 From: North Date: Sat, 3 Sep 2011 17:26:52 +0300 Subject: [PATCH] [NPH] Bludgeon Brawl --- .../mage/sets/newphyrexia/BludgeonBrawl.java | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 Mage.Sets/src/mage/sets/newphyrexia/BludgeonBrawl.java diff --git a/Mage.Sets/src/mage/sets/newphyrexia/BludgeonBrawl.java b/Mage.Sets/src/mage/sets/newphyrexia/BludgeonBrawl.java new file mode 100644 index 00000000000..09921a81f2a --- /dev/null +++ b/Mage.Sets/src/mage/sets/newphyrexia/BludgeonBrawl.java @@ -0,0 +1,227 @@ +/* + * 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.newphyrexia; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Layer; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.SubLayer; +import mage.Constants.Zone; +import mage.abilities.Ability; +import mage.abilities.StaticAbility; +import mage.abilities.TriggeredAbilityImpl; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.continious.BoostEquippedEffect; +import mage.abilities.keyword.EquipAbility; +import mage.cards.CardImpl; +import mage.filter.common.FilterArtifactPermanent; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; + +/** + * + * @author North + */ +public class BludgeonBrawl extends CardImpl { + + public BludgeonBrawl(UUID ownerId) { + super(ownerId, 80, "Bludgeon Brawl", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{2}{R}"); + this.expansionSetCode = "NPH"; + + this.color.setRed(true); + + this.addAbility(new BludgeonBrawlAbility()); + this.addAbility(new BludgeonBrawlTriggeredAbility()); + } + + public BludgeonBrawl(final BludgeonBrawl card) { + super(card); + } + + @Override + public BludgeonBrawl copy() { + return new BludgeonBrawl(this); + } +} + +class BludgeonBrawlAbility extends StaticAbility { + + public BludgeonBrawlAbility() { + super(Zone.BATTLEFIELD, new BludgeonBrawlAddSubtypeEffect()); + this.addEffect(new BludgeonBrawlGainAbilityEffect()); + } + + public BludgeonBrawlAbility(BludgeonBrawlAbility ability) { + super(ability); + } + + @Override + public BludgeonBrawlAbility copy() { + return new BludgeonBrawlAbility(this); + } + + @Override + public String getRule() { + return "Each noncreature, non-Equipment artifact is an Equipment with equip {X} and \"Equipped creature gets +X/+0,\" where X is that artifact's converted mana cost."; + } +} + +class BludgeonBrawlAddSubtypeEffect extends ContinuousEffectImpl { + + public BludgeonBrawlAddSubtypeEffect() { + super(Duration.WhileOnBattlefield, Layer.TypeChangingEffects_4, SubLayer.NA, Outcome.Benefit); + } + + public BludgeonBrawlAddSubtypeEffect(final BludgeonBrawlAddSubtypeEffect effect) { + super(effect); + } + + @Override + public boolean apply(Game game, Ability source) { + FilterArtifactPermanent filter = new FilterArtifactPermanent("noncreature, non-Equipment artifact"); + filter.getNotCardType().add(CardType.CREATURE); + filter.getSubtype().add("Equipment"); + filter.setNotSubtype(true); + + List affectedPermanents = new ArrayList(); + List permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); + for (Permanent permanent : permanents) { + if (permanent != null) { + permanent.getSubtype().add("Equipment"); + affectedPermanents.add(permanent.getId()); + } + } + game.getState().setValue(source.getSourceId() + "BludgeonBrawlAffectedPermanents", affectedPermanents); + return true; + } + + @Override + public BludgeonBrawlAddSubtypeEffect copy() { + return new BludgeonBrawlAddSubtypeEffect(this); + } +} + +class BludgeonBrawlGainAbilityEffect extends ContinuousEffectImpl { + + public BludgeonBrawlGainAbilityEffect() { + super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); + } + + public BludgeonBrawlGainAbilityEffect(final BludgeonBrawlGainAbilityEffect effect) { + super(effect); + } + + @Override + public BludgeonBrawlGainAbilityEffect copy() { + return new BludgeonBrawlGainAbilityEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + List permanents = (List) game.getState().getValue(source.getSourceId() + "BludgeonBrawlAffectedPermanents"); + if (permanents != null) { + for (UUID permanentId : permanents) { + Permanent permanent = game.getPermanent(permanentId); + if (permanent != null) { + int convertedManaCost = permanent.getManaCost().convertedManaCost(); + permanent.addAbility(new EquipAbility(Outcome.BoostCreature, new GenericManaCost(convertedManaCost))); + permanent.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new BoostEquippedEffect(convertedManaCost, 0))); + } + } + return true; + } + + return false; + } +} + +class BludgeonBrawlTriggeredAbility> extends TriggeredAbilityImpl { + + public BludgeonBrawlTriggeredAbility() { + super(Zone.BATTLEFIELD, new BludgeonBrawlExitEffect(), false); + } + + public BludgeonBrawlTriggeredAbility(BludgeonBrawlTriggeredAbility ability) { + super(ability); + } + + @Override + public T copy() { + return (T) new BludgeonBrawlTriggeredAbility(this); + } + + @Override + public boolean checkTrigger(GameEvent event, Game game) { + if (event.getType() == EventType.ZONE_CHANGE && event.getTargetId().equals(this.getSourceId()) + && ((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) { + return true; + } + return false; + } +} + +class BludgeonBrawlExitEffect extends OneShotEffect { + + public BludgeonBrawlExitEffect() { + super(Outcome.Neutral); + } + + public BludgeonBrawlExitEffect(final BludgeonBrawlExitEffect effect) { + super(effect); + } + + @Override + public BludgeonBrawlExitEffect copy() { + return new BludgeonBrawlExitEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + List permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game); + for (Permanent permanent : permanents) { + if (permanent != null && permanent.getAttachedTo() != null) { + Permanent other = game.getPermanent(permanent.getAttachedTo()); + if (other != null && !other.hasSubtype("Equipment") && !other.hasSubtype("Aura")) { + other.getAttachments().remove(permanent.getId()); + } + } + } + return true; + } +}