diff --git a/Mage.Server/src/main/java/mage/server/game/GameWorker.java b/Mage.Server/src/main/java/mage/server/game/GameWorker.java index 50ec2f75b9..e36dce24b2 100644 --- a/Mage.Server/src/main/java/mage/server/game/GameWorker.java +++ b/Mage.Server/src/main/java/mage/server/game/GameWorker.java @@ -1,31 +1,30 @@ /* -* 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. -*/ - + * 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.server.game; import java.util.UUID; @@ -56,7 +55,7 @@ public class GameWorker implements Callable { @Override public Object call() { try { - logger.debug("GAME WORKER started gameId "+ game.getId()); + logger.debug("GAME WORKER started gameId " + game.getId()); Thread.currentThread().setName("GAME " + game.getId()); game.start(choosingPlayerId); game.fireUpdatePlayersEvent(); @@ -64,13 +63,10 @@ public class GameWorker implements Callable { game.cleanUp(); } catch (MageException ex) { logger.fatal("GameWorker mage error [" + game.getId() + "]" + ex, ex); - ex.printStackTrace(); } catch (Exception e) { logger.fatal("GameWorker general exception [" + game.getId() + "]" + e.getMessage(), e); - e.printStackTrace(); } catch (Error err) { - logger.fatal("GameWorker general error [" + game.getId() + "]" +err, err); - err.printStackTrace(); + logger.fatal("GameWorker general error [" + game.getId() + "]" + err, err); } return null; } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/DevastationTide.java b/Mage.Sets/src/mage/sets/avacynrestored/DevastationTide.java index 126fc303e6..0984530713 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/DevastationTide.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/DevastationTide.java @@ -91,7 +91,7 @@ class DevastationTideEffect extends OneShotEffect { for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) { cardsToHand.add((Card) permanent); } - controller.moveCards(cardsToHand, null, Zone.HAND, source, game); + controller.moveCards(cardsToHand, Zone.HAND, source, game); return true; } diff --git a/Mage.Sets/src/mage/sets/oathofthegatewatch/CrushOfTentacles.java b/Mage.Sets/src/mage/sets/oathofthegatewatch/CrushOfTentacles.java new file mode 100644 index 0000000000..4db3a1354d --- /dev/null +++ b/Mage.Sets/src/mage/sets/oathofthegatewatch/CrushOfTentacles.java @@ -0,0 +1,86 @@ +/* + * 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.oathofthegatewatch; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.condition.common.SurgedCondition; +import mage.abilities.decorator.ConditionalOneShotEffect; +import mage.abilities.effects.Effect; +import mage.abilities.effects.common.CreateTokenEffect; +import mage.abilities.effects.common.ReturnToHandFromBattlefieldAllEffect; +import mage.abilities.keyword.SurgeAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Rarity; +import mage.filter.common.FilterNonlandPermanent; +import mage.game.permanent.token.Token; + +/** + * + * @author LevelX2 + */ +public class CrushOfTentacles extends CardImpl { + + public CrushOfTentacles(UUID ownerId) { + super(ownerId, 53, "Crush of Tentacles", Rarity.MYTHIC, new CardType[]{CardType.SORCERY}, "{4}{U}{U}"); + this.expansionSetCode = "OGW"; + + // Return all nonland permanents to their owners' hands. If Crush of Tentacles surge cost was paid, put an 8/8 blue Octopus creature token onto the battlefield. + getSpellAbility().addEffect(new ReturnToHandFromBattlefieldAllEffect(new FilterNonlandPermanent("nonland permanents"))); + Effect effect = new ConditionalOneShotEffect(new CreateTokenEffect(new CrushOfTentaclesToken()), SurgedCondition.getInstance()); + effect.setText("If {this} surge cost was paid, put an 8/8 blue Octopus creature token onto the battlefield"); + getSpellAbility().addEffect(effect); + + // Has to be placed last here, because added spellAbility objects (e.g. effects) have to be copied from this + // Surge {3}{U}{U} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) + addAbility(new SurgeAbility(this, "{3}{U}{U}")); + + } + + public CrushOfTentacles(final CrushOfTentacles card) { + super(card); + } + + @Override + public CrushOfTentacles copy() { + return new CrushOfTentacles(this); + } +} + +class CrushOfTentaclesToken extends Token { + + public CrushOfTentaclesToken() { + super("Octopus", "8/8 blue Octopus creature"); + this.cardType.add(CardType.CREATURE); + this.color.setBlue(true); + this.subtype.add("Octopus"); + this.power = new MageInt(8); + this.toughness = new MageInt(8); + } +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java new file mode 100644 index 0000000000..6c4b97d488 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/SurgeTest.java @@ -0,0 +1,91 @@ +/* + * 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 org.mage.test.cards.abilities.keywords; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class SurgeTest extends CardTestPlayerBase { + + /** + * + */ + @Test + public void testWithoutSurge() { + addCard(Zone.BATTLEFIELD, playerA, "Island", 6); + // Surge {3}{U}{U} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) + // Return all nonland permanents to their owners' hands. If Crush of Tentacles surge cost was paid, put an 8/8 blue Octopus creature token onto the battlefield. + addCard(Zone.HAND, playerA, "Crush of Tentacles"); // {4}{U}{U} + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crush of Tentacles"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Crush of Tentacles", 1); + assertHandCount(playerA, "Silvercoat Lion", 1); + assertHandCount(playerB, "Silvercoat Lion", 1); + assertPermanentCount(playerA, 6); + } + + @Test + public void testWithSurge() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerA, "Island", 5); + // Surge {3}{U}{U} (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn) + // Return all nonland permanents to their owners' hands. If Crush of Tentacles surge cost was paid, put an 8/8 blue Octopus creature token onto the battlefield. + addCard(Zone.HAND, playerA, "Crush of Tentacles"); // {4}{U}{U} + addCard(Zone.HAND, playerA, "Lightning Bolt"); + addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion"); + addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Lightning Bolt", playerB); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Crush of Tentacles with surge"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Lightning Bolt", 1); + assertGraveyardCount(playerA, "Crush of Tentacles", 1); + assertPermanentCount(playerA, "Octopus", 1); + assertHandCount(playerA, "Silvercoat Lion", 1); + assertHandCount(playerB, "Silvercoat Lion", 1); + assertPermanentCount(playerA, 7); + + assertLife(playerB, 17); + } + +} diff --git a/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java new file mode 100644 index 0000000000..333832322e --- /dev/null +++ b/Mage/src/main/java/mage/abilities/condition/common/SurgedCondition.java @@ -0,0 +1,58 @@ +/* + * 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.abilities.keyword.SurgeAbility; +import mage.game.Game; + +/** + * + * @author LevelX2 + */ +public class SurgedCondition implements Condition { + + private static SurgedCondition fInstance = null; + + private SurgedCondition() { + } + + public static Condition getInstance() { + if (fInstance == null) { + fInstance = new SurgedCondition(); + } + return fInstance; + } + + @Override + public boolean apply(Game game, Ability source) { + // if surge is used for permanents we have to chnage implementation + return source instanceof SurgeAbility; + } +} diff --git a/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java new file mode 100644 index 0000000000..f7f13273bc --- /dev/null +++ b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java @@ -0,0 +1,99 @@ +/* + * 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 java.util.UUID; +import mage.abilities.SpellAbility; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.cards.Card; +import mage.constants.SpellAbilityType; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Player; +import mage.watchers.common.CastSpellLastTurnWatcher; + +/** + * + * @author LevelX2 + */ +public class SurgeAbility extends SpellAbility { + + private String rule; + + public SurgeAbility(Card card, String surgeCosts) { + super(new ManaCostsImpl<>(surgeCosts), card.getName() + " with surge", Zone.HAND, SpellAbilityType.BASE_ALTERNATE); + this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); + this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); + this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); + this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); + this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; + this.timing = card.getSpellAbility().getTiming(); + this.setRuleAtTheTop(true); + rule = "Surge " + surgeCosts + + " (You may cast this spell for its surge cost if you or a teammate has cast another spell this turn.)"; + } + + public SurgeAbility(final SurgeAbility ability) { + super(ability); + } + + @Override + public boolean canActivate(UUID playerId, Game game) { + // check if controller or teammate has already cast a spell this turn + CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get("CastSpellLastTurnWatcher"); + if (watcher != null) { + Player player = game.getPlayer(playerId); + if (player != null) { + for (UUID playerToCheckId : game.getState().getPlayersInRange(playerId, game)) { + if (!player.hasOpponent(playerToCheckId, game)) { + if (watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(playerToCheckId) > 0) { + return super.canActivate(playerId, game); + } + } + } + } + } + return false; + } + + @Override + public SurgeAbility copy() { + return new SurgeAbility(this); + } + + @Override + public String getRule(boolean all) { + return getRule(); + } + + @Override + public String getRule() { + return rule; + } + +} diff --git a/Mage/src/main/java/mage/constants/AbilityType.java b/Mage/src/main/java/mage/constants/AbilityType.java index 5a24e3bf3b..bc6da81ba4 100644 --- a/Mage/src/main/java/mage/constants/AbilityType.java +++ b/Mage/src/main/java/mage/constants/AbilityType.java @@ -5,6 +5,7 @@ package mage.constants; * @author North */ public enum AbilityType { + PLAY_LAND("Play land"), MANA("Mana"), SPELL("Spell"), @@ -15,7 +16,7 @@ public enum AbilityType { LOYALTY("Loyalty"), SPECIAL_ACTION("Special Action"); - private String text; + private final String text; AbilityType(String text) { this.text = text;