From 2c55591172e53f8f2f53fa177938e38e0e2d0295 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 3 Sep 2013 17:10:52 +0200 Subject: [PATCH] Added MonstrosityAbility for Theros. --- .../condition/common/MonstrousCondition.java | 63 ++++++++++ .../abilities/keyword/MonstrosityAbility.java | 114 ++++++++++++++++++ Mage/src/mage/game/events/GameEvent.java | 1 + Mage/src/mage/game/permanent/Permanent.java | 3 + .../mage/game/permanent/PermanentImpl.java | 12 ++ 5 files changed, 193 insertions(+) create mode 100644 Mage/src/mage/abilities/condition/common/MonstrousCondition.java create mode 100644 Mage/src/mage/abilities/keyword/MonstrosityAbility.java diff --git a/Mage/src/mage/abilities/condition/common/MonstrousCondition.java b/Mage/src/mage/abilities/condition/common/MonstrousCondition.java new file mode 100644 index 00000000000..1ea4aad5638 --- /dev/null +++ b/Mage/src/mage/abilities/condition/common/MonstrousCondition.java @@ -0,0 +1,63 @@ +/* +* 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.abilities.condition.common; + +import mage.abilities.Ability; +import mage.abilities.condition.Condition; +import mage.game.Game; +import mage.game.permanent.Permanent; + + +/** + * Checks if a Permanent is monstrous + * + * @author LevelX2 + */ +public class MonstrousCondition implements Condition { + + private static MonstrousCondition fInstance = null; + + private MonstrousCondition() {} + + public static Condition getInstance() { + if (fInstance == null) { + fInstance = new MonstrousCondition(); + } + return fInstance; + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + return permanent.isMonstrous(); + } + return false; + } +} diff --git a/Mage/src/mage/abilities/keyword/MonstrosityAbility.java b/Mage/src/mage/abilities/keyword/MonstrosityAbility.java new file mode 100644 index 00000000000..10560141cf1 --- /dev/null +++ b/Mage/src/mage/abilities/keyword/MonstrosityAbility.java @@ -0,0 +1,114 @@ +/* +* 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.abilities.keyword; + +import mage.abilities.Ability; +import mage.abilities.ActivatedAbilityImpl; +import mage.abilities.condition.InvertCondition; +import mage.abilities.condition.common.MonstrousCondition; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.counter.AddCountersSourceEffect; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.counters.CounterType; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.util.CardUtil; + +/** + * + * + * @author LevelX2 + */ + +public class MonstrosityAbility extends ActivatedAbilityImpl { + + private int monstrosityValue; + + public MonstrosityAbility(String manaString, int monstrosityValue) { + super(Zone.BATTLEFIELD, new ConditionalOneShotEffect( + new AddCountersSourceEffect(CounterType.P1P1.createInstance(monstrosityValue)), + new InvertCondition(MonstrousCondition.getInstance()), + ""), new ManaCostsImpl(manaString)); + this.addEffect(new ConditionalOneShotEffect( + new BecomeMonstrousSourceEffect(), + new InvertCondition(MonstrousCondition.getInstance()),"")); + + this.monstrosityValue = monstrosityValue; + } + + public MonstrosityAbility(final MonstrosityAbility ability) { + super(ability); + this.monstrosityValue = ability.monstrosityValue; + } + + @Override + public MonstrosityAbility copy() { + return new MonstrosityAbility(this); + } + + @Override + public String getRule() { + return new StringBuilder(manaCosts.getText()).append(": Monstrosity ").append(monstrosityValue) + .append(". (If this creature isn't monstrous, put ").append(CardUtil.numberToText(monstrosityValue)) + .append(" +1/+1 counters on it and it becomes monstrous.)").toString(); + } + +} + +class BecomeMonstrousSourceEffect extends OneShotEffect { + + public BecomeMonstrousSourceEffect() { + super(Outcome.BoostCreature); + this.staticText = ""; + } + + public BecomeMonstrousSourceEffect(final BecomeMonstrousSourceEffect effect) { + super(effect); + } + + @Override + public BecomeMonstrousSourceEffect copy() { + return new BecomeMonstrousSourceEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + if (permanent != null) { + permanent.setMonstrous(true); + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.BECOMES_MONSTROUS, source.getSourceId(), source.getSourceId(), source.getControllerId())); + return true; + } + return false; + } +} diff --git a/Mage/src/mage/game/events/GameEvent.java b/Mage/src/mage/game/events/GameEvent.java index 87fc546ded0..82db0c6345c 100644 --- a/Mage/src/mage/game/events/GameEvent.java +++ b/Mage/src/mage/game/events/GameEvent.java @@ -112,6 +112,7 @@ public class GameEvent { FLIP, FLIPPED, UNFLIP, UNFLIPPED, TRANSFORM, TRANSFORMED, + BECOMES_MONSTROUS, PHASE_OUT, PHASED_OUT, PHASE_IN, PHASED_IN, TURNFACEUP, TURNEDFACEUP, diff --git a/Mage/src/mage/game/permanent/Permanent.java b/Mage/src/mage/game/permanent/Permanent.java index 76a47103b49..464b6282364 100644 --- a/Mage/src/mage/game/permanent/Permanent.java +++ b/Mage/src/mage/game/permanent/Permanent.java @@ -72,6 +72,9 @@ public interface Permanent extends Card, Controllable { boolean turnFaceUp(Game game); boolean turnFaceDown(Game game); + boolean isMonstrous(); + void setMonstrous(boolean value); + List getAttachments(); UUID getAttachedTo(); void attachTo(UUID permanentId, Game game); diff --git a/Mage/src/mage/game/permanent/PermanentImpl.java b/Mage/src/mage/game/permanent/PermanentImpl.java index a0a453fbe62..f72e9858cc9 100644 --- a/Mage/src/mage/game/permanent/PermanentImpl.java +++ b/Mage/src/mage/game/permanent/PermanentImpl.java @@ -57,6 +57,7 @@ public abstract class PermanentImpl> extends CardImpl protected boolean tapped; protected boolean flipped; protected boolean transformed; + protected boolean monstrous; protected UUID originalControllerId; protected UUID controllerId; protected UUID beforeResetControllerId; @@ -130,6 +131,7 @@ public abstract class PermanentImpl> extends CardImpl this.minBlockedBy = permanent.minBlockedBy; this.maxBlockedBy = permanent.maxBlockedBy; this.transformed = permanent.transformed; + this.monstrous = permanent.monstrous; this.pairedCard = permanent.pairedCard; } @@ -1008,6 +1010,16 @@ public abstract class PermanentImpl> extends CardImpl this.transformed = value; } + @Override + public boolean isMonstrous() { + return this.monstrous; + } + + @Override + public void setMonstrous(boolean value) { + this.monstrous = value; + } + @Override public void setPairedCard(UUID pairedCard) { this.pairedCard = pairedCard;