From 9a443aa05671fc035a0e3d44d49f672fa421bf7b Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 25 Mar 2014 16:43:48 +0100 Subject: [PATCH] Added Fist of Suns and Haze of Rage. --- .../src/mage/sets/fifthdawn/FistOfSuns.java | 109 ++++++++++++++++++ .../src/mage/sets/futuresight/HazeOfRage.java | 70 +++++++++++ Mage/src/mage/abilities/AbilityImpl.java | 49 +++++--- .../costs/AlternativeCostSourceAbility.java | 2 +- .../common/DamageEverythingEffect.java | 4 +- Mage/src/mage/players/Player.java | 31 +++-- Mage/src/mage/players/PlayerImpl.java | 11 ++ 7 files changed, 247 insertions(+), 29 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/fifthdawn/FistOfSuns.java create mode 100644 Mage.Sets/src/mage/sets/futuresight/HazeOfRage.java diff --git a/Mage.Sets/src/mage/sets/fifthdawn/FistOfSuns.java b/Mage.Sets/src/mage/sets/fifthdawn/FistOfSuns.java new file mode 100644 index 00000000000..13c4e6196f7 --- /dev/null +++ b/Mage.Sets/src/mage/sets/fifthdawn/FistOfSuns.java @@ -0,0 +1,109 @@ +/* + * 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.fifthdawn; + +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.costs.AlternativeCostSourceAbility; +import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.ContinuousEffectImpl; +import mage.cards.CardImpl; +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.game.Game; +import mage.players.Player; + +/** + * + * @author LevelX2 + */ +public class FistOfSuns extends CardImpl { + + public FistOfSuns(UUID ownerId) { + super(ownerId, 123, "Fist of Suns", Rarity.RARE, new CardType[]{CardType.ARTIFACT}, "{3}"); + this.expansionSetCode = "5DN"; + + // You may pay {W}{U}{B}{R}{G} rather than pay the mana cost for spells that you cast. + this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new MirrorGalleryRuleEffect())); + } + + public FistOfSuns(final FistOfSuns card) { + super(card); + } + + @Override + public FistOfSuns copy() { + return new FistOfSuns(this); + } + +} + +class MirrorGalleryRuleEffect extends ContinuousEffectImpl { + + static AlternativeCostSourceAbility alternativeCastingCostAbility = new AlternativeCostSourceAbility(new ManaCostsImpl("{W}{U}{B}{R}{G}")); + + public MirrorGalleryRuleEffect() { + super(Duration.WhileOnBattlefield, Outcome.Detriment); + staticText = "You may pay {W}{U}{B}{R}{G} rather than pay the mana cost for spells that you cast"; + } + + public MirrorGalleryRuleEffect(final MirrorGalleryRuleEffect effect) { + super(effect); + } + + @Override + public MirrorGalleryRuleEffect copy() { + return new MirrorGalleryRuleEffect(this); + } + + @Override + public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + controller.getAlternativeSourceCosts().add(alternativeCastingCostAbility); + return true; + } + return false; + } + + @Override + public boolean apply(Game game, Ability source) { + return false; + } + + @Override + public boolean hasLayer(Layer layer) { + return layer == Layer.RulesEffects; + } +} diff --git a/Mage.Sets/src/mage/sets/futuresight/HazeOfRage.java b/Mage.Sets/src/mage/sets/futuresight/HazeOfRage.java new file mode 100644 index 00000000000..ea27f696eb6 --- /dev/null +++ b/Mage.Sets/src/mage/sets/futuresight/HazeOfRage.java @@ -0,0 +1,70 @@ +/* + * 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.futuresight; + +import java.util.UUID; +import mage.abilities.effects.common.continious.BoostControlledEffect; +import mage.abilities.keyword.BuybackAbility; +import mage.abilities.keyword.StormAbility; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Rarity; + +/** + * + * @author LevelX2 + */ +public class HazeOfRage extends CardImpl { + + public HazeOfRage(UUID ownerId) { + super(ownerId, 100, "Haze of Rage", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{1}{R}"); + this.expansionSetCode = "FUT"; + + this.color.setRed(true); + + // Buyback {2} + this.addAbility(new BuybackAbility("{2}")); + + // Creatures you control get +1/+0 until end of turn. + this.getSpellAbility().addEffect(new BoostControlledEffect(1,0, Duration.EndOfTurn)); + + // Storm + this.addAbility(new StormAbility()); + + } + + public HazeOfRage(final HazeOfRage card) { + super(card); + } + + @Override + public HazeOfRage copy() { + return new HazeOfRage(this); + } +} diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index f2282b787fe..0dcb267c3bc 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -184,6 +184,11 @@ public abstract class AbilityImpl> implements Ability { @Override public boolean activate(Game game, boolean noMana) { + Player controller = game.getPlayer(this.getControllerId()); + if (controller == null) { + return false; + } + /* 20130201 - 601.2b * If the spell is modal the player announces the mode choice (see rule 700.2). */ @@ -199,7 +204,7 @@ public abstract class AbilityImpl> implements Ability { game.getContinuousEffects().applySpliceEffects(this, game); } - + Card card = game.getCard(sourceId); if (card != null) { card.adjustChoices(this, game); @@ -218,27 +223,41 @@ public abstract class AbilityImpl> implements Ability { // or her intentions to pay any or all of those costs (see rule 601.2e). // A player can't apply two alternative methods of casting or two alternative costs to a single spell. if (card != null) { + boolean alternativeCostisUsed = false; for (Ability ability : card.getAbilities()) { if (ability instanceof AlternativeSourceCosts) { AlternativeSourceCosts alternativeSpellCosts = (AlternativeSourceCosts) ability; if (alternativeSpellCosts.isAvailable(this, game)) { if (alternativeSpellCosts.askToActivateAlternativeCosts(this, game)) { // only one alternative costs may be activated + alternativeCostisUsed = true; break; } } - } + } if (ability instanceof OptionalAdditionalSourceCosts) { ((OptionalAdditionalSourceCosts)ability).addOptionalAdditionalCosts(this, game); } } + if (!alternativeCostisUsed) { + if (this.getAbilityType().equals(AbilityType.SPELL)) { + for (AlternativeSourceCosts alternativeSourceCosts: controller.getAlternativeSourceCosts()) { + if (alternativeSourceCosts.isAvailable(this, game)) { + if (alternativeSourceCosts.askToActivateAlternativeCosts(this, game)) { + // only one alternative costs may be activated + break; + } + } + } + } + } } // 20121001 - 601.2b // If the spell has a variable cost that will be paid as it's being cast (such as an {X} in // its mana cost; see rule 107.3), the player announces the value of that variable. - VariableManaCost variableManaCost = handleManaXCosts(game, noMana); - String announceString = handleOtherXCosts(game); + VariableManaCost variableManaCost = handleManaXCosts(game, noMana, controller); + String announceString = handleOtherXCosts(game, controller); for (UUID modeId :this.getModes().getSelectedModes()) { this.getModes().setMode(this.getModes().get(modeId)); @@ -264,10 +283,7 @@ public abstract class AbilityImpl> implements Ability { } if (getTargets().size() > 0 && getTargets().chooseTargets(getEffects().get(0).getOutcome(), this.controllerId, this, game) == false) { if (variableManaCost != null || announceString != null) { - Player controller = game.getPlayer(this.getControllerId()); - if (controller != null) { - game.informPlayer(controller, new StringBuilder(card != null ? card.getName(): "").append(": no valid targets with this value of X").toString()); - } + game.informPlayer(controller, new StringBuilder(card != null ? card.getName(): "").append(": no valid targets with this value of X").toString()); } else { logger.debug("activate failed - target"); } @@ -279,7 +295,7 @@ public abstract class AbilityImpl> implements Ability { for (Cost cost : optionalCosts) { if (cost instanceof ManaCost) { cost.clearPaid(); - if (game.getPlayer(this.controllerId).chooseUse(Outcome.Benefit, "Pay optional cost " + cost.getText() + "?", game)) { + if (controller.chooseUse(Outcome.Benefit, "Pay optional cost " + cost.getText() + "?", game)) { manaCostsToPay.add((ManaCost) cost); } } @@ -308,7 +324,7 @@ public abstract class AbilityImpl> implements Ability { activatorId = ((ActivatedAbilityImpl)this).getActivatorId(); } - if (!useAlternativeCost(game)) { + if (!useAlternativeCost(game)) { // old way still used? //20100716 - 601.2f if (!manaCostsToPay.pay(this, game, sourceId, activatorId, noMana)) { @@ -329,19 +345,19 @@ public abstract class AbilityImpl> implements Ability { } if (variableManaCost != null) { int xValue = getManaCostsToPay().getX(); - game.informPlayers(new StringBuilder(game.getPlayer(this.controllerId).getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString()); + game.informPlayers(new StringBuilder(controller.getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString()); } return true; } /** * Handles the setting of non mana X costs - * + * @param controller * * @param game * @return announce message * */ - protected String handleOtherXCosts(Game game) { + protected String handleOtherXCosts(Game game, Player controller) { String announceString = null; for (VariableCost variableCost : this.costs.getVariableCosts()) { if (!(variableCost instanceof VariableManaCost)) { @@ -350,7 +366,7 @@ public abstract class AbilityImpl> implements Ability { // set the xcosts to paid variableCost.setAmount(xValue); ((Cost) variableCost).setPaid(); - String message = new StringBuilder(game.getPlayer(this.controllerId).getName()) + String message = new StringBuilder(controller.getName()) .append(" announces a value of ").append(xValue).append(" (").append(variableCost.getActionText()).append(")").toString(); if (announceString == null) { announceString = message; @@ -369,7 +385,7 @@ public abstract class AbilityImpl> implements Ability { * @param noMana * @return variableManaCost for posting to log later */ - protected VariableManaCost handleManaXCosts(Game game, boolean noMana) { + protected VariableManaCost handleManaXCosts(Game game, boolean noMana, Player controller) { // 20121001 - 601.2b // If the spell has a variable cost that will be paid as it's being cast (such as an {X} in // its mana cost; see rule 107.3), the player announces the value of that variable. @@ -385,7 +401,7 @@ public abstract class AbilityImpl> implements Ability { int xValue; if (!variableManaCost.isPaid()) { // should only happen for human players if (!noMana) { - xValue = game.getPlayer(this.controllerId).announceXMana(variableManaCost.getMinX(), variableManaCost.getMaxX(), "Announce the value for " + variableManaCost.getText(), game, this); + xValue = controller.announceXMana(variableManaCost.getMinX(), variableManaCost.getMaxX(), "Announce the value for " + variableManaCost.getText(), game, this); int amountMana = xValue * variableManaCost.getMultiplier(); StringBuilder manaString = new StringBuilder(); if (variableManaCost.getFilter() == null || variableManaCost.getFilter().isColorless()) { @@ -423,6 +439,7 @@ public abstract class AbilityImpl> implements Ability { @Override public void reset(Game game) {} + // Is this still needed? protected boolean useAlternativeCost(Game game) { for (AlternativeCost cost: alternativeCosts) { if (cost.isAvailable(game, this)) { diff --git a/Mage/src/mage/abilities/costs/AlternativeCostSourceAbility.java b/Mage/src/mage/abilities/costs/AlternativeCostSourceAbility.java index 529b505fd5e..6859ab699e9 100644 --- a/Mage/src/mage/abilities/costs/AlternativeCostSourceAbility.java +++ b/Mage/src/mage/abilities/costs/AlternativeCostSourceAbility.java @@ -101,7 +101,7 @@ public class AlternativeCostSourceAbility extends StaticAbility permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game); for (Permanent permanent: permanents) { - permanent.damage(amount.calculate(game, source), source.getId(), game, true, false); + permanent.damage(amount.calculate(game, source), source.getSourceId(), game, true, false); } for (UUID playerId: game.getPlayer(source.getControllerId()).getInRange()) { Player player = game.getPlayer(playerId); if (player != null) { - player.damage(amount.calculate(game, source), source.getId(), game, false, true); + player.damage(amount.calculate(game, source), source.getSourceId(), game, false, true); } } return true; diff --git a/Mage/src/mage/players/Player.java b/Mage/src/mage/players/Player.java index 0f1ad4f34ba..302d2a93743 100644 --- a/Mage/src/mage/players/Player.java +++ b/Mage/src/mage/players/Player.java @@ -43,6 +43,7 @@ import mage.abilities.Mode; import mage.abilities.Modes; import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbility; +import mage.abilities.costs.AlternativeSourceCosts; import mage.abilities.costs.VariableCost; import mage.abilities.costs.mana.ManaCost; import mage.cards.Card; @@ -85,19 +86,29 @@ public interface Player extends MageItem, Copyable { int getLife(); void setLife(int life, Game game); int loseLife(int amount, Game game); - boolean isCanLoseLife(); - void setCanLoseLife(boolean canLoseLife); int gainLife(int amount, Game game); - boolean isCanGainLife(); - void setCanGainLife(boolean canGainLife); - boolean isLifeTotalCanChange(); - void setCanPayLifeCost(boolean canPayLifeCost); - boolean canPayLifeCost(); - void setCanPaySacrificeCost(boolean canPaySacrificeCost); - boolean canPaySacrificeCost(); - void setLifeTotalCanChange(boolean lifeTotalCanChange); int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable); int damage(int damage, UUID sourceId, Game game, boolean combatDamage, boolean preventable, ArrayList appliedEffects); + + // to handle rule changing effects (613.10) + boolean isCanLoseLife(); + void setCanLoseLife(boolean canLoseLife); + void setCanGainLife(boolean canGainLife); + boolean isCanGainLife(); + void setCanPayLifeCost(boolean canPayLifeCost); + boolean canPayLifeCost(); + void setCanPaySacrificeCost(boolean canPaySacrificeCost); + boolean canPaySacrificeCost(); + void setLifeTotalCanChange(boolean lifeTotalCanChange); + boolean isLifeTotalCanChange(); + /** + * Returns alternative casting costs a player can cast spells for + * + * @return + */ + List getAlternativeSourceCosts(); + + Cards getHand(); int getLandsPlayed(); int getLandsPerTurn(); diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index df9e804150e..1100a94a06b 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -57,6 +57,7 @@ import mage.abilities.common.PassAbility; import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility; import mage.abilities.costs.AdjustingSourceCosts; import mage.abilities.costs.AlternativeCost; +import mage.abilities.costs.AlternativeSourceCosts; import mage.abilities.effects.RestrictionEffect; import mage.abilities.effects.RestrictionUntapNotMoreThanEffect; import mage.abilities.effects.common.LoseControlOnOtherPlayersControllerEffect; @@ -167,6 +168,8 @@ public abstract class PlayerImpl> implements Player, Ser protected boolean canLoseLife = true; protected boolean canPayLifeCost = true; protected boolean canPaySacrificeCost = true; + protected final List alternativeSourceCosts = new ArrayList<>(); + protected boolean isGameUnderControl = true; protected UUID turnController; protected Set playersUnderYourControl = new HashSet<>(); @@ -237,6 +240,7 @@ public abstract class PlayerImpl> implements Player, Ser this.userData = player.userData; this.canPayLifeCost = player.canPayLifeCost; this.canPaySacrificeCost = player.canPaySacrificeCost; + this.alternativeSourceCosts.addAll(player.alternativeSourceCosts); this.storedBookmark = player.storedBookmark; this.topCardRevealed = player.topCardRevealed; @@ -290,6 +294,7 @@ public abstract class PlayerImpl> implements Player, Ser this.userData = player.getUserData(); this.canPayLifeCost = player.canPayLifeCost(); this.canPaySacrificeCost = player.canPaySacrificeCost(); + this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts()); this.storedBookmark = player.getStoredBookmark(); this.topCardRevealed = player.isTopCardRevealed(); @@ -355,6 +360,7 @@ public abstract class PlayerImpl> implements Player, Ser this.canPayLifeCost = true; this.canPaySacrificeCost = true; this.topCardRevealed = false; + this.alternativeSourceCosts.clear(); } @Override @@ -1265,6 +1271,11 @@ public abstract class PlayerImpl> implements Player, Ser return canGainLife | canLoseLife; } + @Override + public List getAlternativeSourceCosts() { + return alternativeSourceCosts; + } + @Override public boolean isCanLoseLife() { return canLoseLife;