From f46c06066a808ec928f219b91a41f63f06c66cae Mon Sep 17 00:00:00 2001 From: spjspj Date: Thu, 11 Aug 2016 23:03:22 +1000 Subject: [PATCH 1/2] spjspj - Implement Guardian Beast (ARN) --- .../sets/arabiannights/GuardianBeast.java | 158 ++++++++++++++++++ .../sets/masterseditioniv/GuardianBeast.java | 52 ++++++ .../continuous/GainControlTargetEffect.java | 22 ++- .../mage/game/permanent/PermanentImpl.java | 7 + 4 files changed, 232 insertions(+), 7 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java create mode 100644 Mage.Sets/src/mage/sets/masterseditioniv/GuardianBeast.java diff --git a/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java b/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java new file mode 100644 index 00000000000..d58aec6ffee --- /dev/null +++ b/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java @@ -0,0 +1,158 @@ +/* + * 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.arabiannights; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.InvertCondition; +import mage.abilities.condition.common.SourceTappedCondition; +import mage.abilities.decorator.ConditionalContinuousEffect; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.Effect; +import mage.abilities.keyword.IndestructibleAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; +import mage.constants.Zone; +import mage.filter.common.FilterControlledArtifactPermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.CardTypePredicate; +import mage.abilities.effects.common.continuous.GainAbilityControlledEffect; +import mage.constants.Outcome; +import mage.filter.FilterObject; +import mage.filter.FilterStackObject; +import mage.filter.predicate.mageobject.SubtypePredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.GameEvent.EventType; +import mage.game.permanent.Permanent; +import mage.game.stack.StackObject; + +/** + * + * @author spjspj + */ +public class GuardianBeast extends CardImpl { + + private static final FilterObject filterAura = new FilterStackObject("auras"); + private static final FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("Noncreature artifacts"); + + static { + filterAura.add(new CardTypePredicate(CardType.ENCHANTMENT)); + filterAura.add(new SubtypePredicate("Aura")); + filter.add(Predicates.not(new CardTypePredicate(CardType.CREATURE))); + } + + public GuardianBeast(UUID ownerId) { + super(ownerId, 5, "Guardian Beast", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{3}{B}"); + this.expansionSetCode = "ARN"; + this.subtype.add("Beast"); + this.power = new MageInt(2); + this.toughness = new MageInt(4); + + // As long as Guardian Beast is untapped, noncreature artifacts you control can't be enchanted, they're indestructible, and other players can't gain control of them. This effect doesn't remove Auras already attached to those artifacts. + Effect effect = new ConditionalContinuousEffect(new GainAbilityControlledEffect(IndestructibleAbility.getInstance(), Duration.WhileOnBattlefield, filter), new InvertCondition(new SourceTappedCondition()), "noncreature artifacts you control can't be enchanted, they're indestructible, and other players can't gain control of them"); + GuardianBeastConditionalEffect effect2 = new GuardianBeastConditionalEffect(this.getId()); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect2)); + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect)); + } + + public GuardianBeast(final GuardianBeast card) { + super(card); + } + + @Override + public GuardianBeast copy() { + return new GuardianBeast(this); + } +} + +class GuardianBeastConditionalEffect extends ContinuousRuleModifyingEffectImpl { + + private static final FilterControlledArtifactPermanent filter = new FilterControlledArtifactPermanent("Noncreature artifacts"); + private UUID guardianBeastId; + + static { + filter.add(Predicates.not(new CardTypePredicate(CardType.CREATURE))); + } + + public GuardianBeastConditionalEffect(UUID guardianBeastId) { + super(Duration.WhileOnBattlefield, Outcome.Neutral); + staticText = "Non-creature artifacts you control have they can't be enchanted, they're indestructible, and other players can't gain control of them"; + this.guardianBeastId = guardianBeastId; + } + + public GuardianBeastConditionalEffect(final GuardianBeastConditionalEffect effect) { + super(effect); + this.guardianBeastId = effect.guardianBeastId; + } + + @Override + public GuardianBeastConditionalEffect copy() { + return new GuardianBeastConditionalEffect(this); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return true || (event.getType() == EventType.TARGET || event.getType() == EventType.LOSE_CONTROL); + } + + @Override + public boolean apply(Game game, Ability source) { + return true; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + Permanent sourceObject = game.getPermanent(source.getSourceId()); + Permanent targetPermanent = game.getPermanent(event.getTargetId()); + Permanent guardianBeast = game.getPermanent(guardianBeastId); + + if (guardianBeast == null || guardianBeast.isTapped() || sourceObject == null || targetPermanent == null) { + return false; + } + + if (targetPermanent.getControllerId() != guardianBeast.getControllerId()) { + return false; + } + + StackObject spell = game.getStack().getStackObject(event.getSourceId()); + if (event.getType() == EventType.LOSE_CONTROL || event.getType() == EventType.ATTACH || event.getType() == EventType.TARGET && spell != null && spell.getCardType().contains(CardType.ENCHANTMENT) && spell.getSubtype().contains("Aura")) { + for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) { + if (perm != null && perm.getId() == targetPermanent.getId() && !perm.getCardType().contains(CardType.CREATURE)) { + return true; + } + } + } + return false; + } + +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/masterseditioniv/GuardianBeast.java b/Mage.Sets/src/mage/sets/masterseditioniv/GuardianBeast.java new file mode 100644 index 00000000000..e9493e46811 --- /dev/null +++ b/Mage.Sets/src/mage/sets/masterseditioniv/GuardianBeast.java @@ -0,0 +1,52 @@ +/* + * 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.masterseditioniv; + +import java.util.UUID; + +/** + * + * @author spjspj + */ +public class GuardianBeast extends mage.sets.arabiannights.GuardianBeast { + + public GuardianBeast(UUID ownerId) { + super(ownerId); + this.cardNumber = "85"; + this.expansionSetCode = "ME4"; + } + + public GuardianBeast(final GuardianBeast card) { + super(card); + } + + @Override + public GuardianBeast copy() { + return new GuardianBeast(this); + } +} diff --git a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainControlTargetEffect.java b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainControlTargetEffect.java index 4f0e79921db..51cc61485b2 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/continuous/GainControlTargetEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/common/continuous/GainControlTargetEffect.java @@ -24,8 +24,7 @@ * 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.abilities.effects.common.continuous; import java.util.UUID; @@ -37,6 +36,7 @@ import mage.constants.Layer; import mage.constants.Outcome; import mage.constants.SubLayer; import mage.game.Game; +import mage.game.events.GameEvent; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.Target; @@ -73,6 +73,7 @@ public class GainControlTargetEffect extends ContinuousEffectImpl { this(duration, true, controllingPlayerId); } + public GainControlTargetEffect(Duration duration, boolean fixedControl, UUID controllingPlayerId) { super(duration, Layer.ControlChangingEffects_2, SubLayer.NA, Outcome.GainControl); this.controllingPlayerId = controllingPlayerId; @@ -100,13 +101,20 @@ public class GainControlTargetEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Player controller = game.getPlayer(source.getControllerId()); + Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { boolean targetStillExists = false; for (UUID permanentId: getTargetPointer().getTargets(game, source)) { Permanent permanent = game.getPermanent(permanentId); if (permanent != null) { targetStillExists = true; + + GameEvent loseControlEvent = GameEvent.getEvent(GameEvent.EventType.LOSE_CONTROL, permanentId, source.getId(), permanent.getControllerId()); + + if (game.replaceEvent(loseControlEvent)) { + return false; + } + if (controllingPlayerId != null) { permanent.changeControllerId(controllingPlayerId, game); permanent.getAbilities().setControllerId(controllingPlayerId); @@ -114,14 +122,14 @@ public class GainControlTargetEffect extends ContinuousEffectImpl { permanent.changeControllerId(source.getControllerId(), game); permanent.getAbilities().setControllerId(source.getControllerId()); } - } + } } if (!targetStillExists) { // no valid target exists, effect can be discarded discard(); } return true; - } + } return false; } @@ -139,8 +147,8 @@ public class GainControlTargetEffect extends ContinuousEffectImpl { sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target "); } else { if (!target.getTargetName().startsWith("another")) { - sb.append("target "); - } + sb.append("target "); + } } sb.append(mode.getTargets().get(0).getTargetName()); if (!duration.toString().isEmpty()) { diff --git a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java index 5f8f7763184..be11024c3e0 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentImpl.java @@ -613,6 +613,13 @@ public abstract class PermanentImpl extends CardImpl implements Permanent { @Override public boolean changeControllerId(UUID controllerId, Game game) { Player newController = game.getPlayer(controllerId); + + GameEvent loseControlEvent = GameEvent.getEvent(GameEvent.EventType.LOSE_CONTROL, this.getId(), null, controllerId); + + if (game.replaceEvent(loseControlEvent)) { + return false; + } + if (newController != null && (!newController.hasLeft() || !newController.hasLost())) { this.controllerId = controllerId; return true; From d5ab9df255a3234f2162874b93839c87d95d428a Mon Sep 17 00:00:00 2001 From: spjspj Date: Thu, 11 Aug 2016 23:12:06 +1000 Subject: [PATCH 2/2] spjspj - Implement Guardian Beast (ARN) --- Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java b/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java index d58aec6ffee..b357ed6dea9 100644 --- a/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java +++ b/Mage.Sets/src/mage/sets/arabiannights/GuardianBeast.java @@ -106,7 +106,7 @@ class GuardianBeastConditionalEffect extends ContinuousRuleModifyingEffectImpl { public GuardianBeastConditionalEffect(UUID guardianBeastId) { super(Duration.WhileOnBattlefield, Outcome.Neutral); - staticText = "Non-creature artifacts you control have they can't be enchanted, they're indestructible, and other players can't gain control of them"; + staticText = "Noncreature artifacts you control have they can't be enchanted, they're indestructible, and other players can't gain control of them"; this.guardianBeastId = guardianBeastId; } @@ -122,7 +122,7 @@ class GuardianBeastConditionalEffect extends ContinuousRuleModifyingEffectImpl { @Override public boolean checksEventType(GameEvent event, Game game) { - return true || (event.getType() == EventType.TARGET || event.getType() == EventType.LOSE_CONTROL); + return true; } @Override @@ -155,4 +155,4 @@ class GuardianBeastConditionalEffect extends ContinuousRuleModifyingEffectImpl { return false; } -} \ No newline at end of file +}