From 551f03a5420719a5c043466e257c06459ba6cb12 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 30 Sep 2014 14:42:25 +0200 Subject: [PATCH] * Market Festival - Fixed that the mana generated by Market Festival could be used to pay mana costs of a mana ability of the land Market Festival enchants (e.g. second ability of Nykthos, Shrine to Nyx). --- .../mage/sets/journeyintonyx/MarketFestival.java | 9 ++++++++- .../src/mage/sets/theros/NykthosShrineToNyx.java | 15 ++++++++++++--- Mage/src/mage/abilities/AbilityImpl.java | 11 +++++++++++ .../abilities/costs/common/TapSourceCost.java | 5 ----- Mage/src/mage/choices/ChoiceColor.java | 16 +++++++++++----- 5 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Mage.Sets/src/mage/sets/journeyintonyx/MarketFestival.java b/Mage.Sets/src/mage/sets/journeyintonyx/MarketFestival.java index 63016568e51..2116abb39e8 100644 --- a/Mage.Sets/src/mage/sets/journeyintonyx/MarketFestival.java +++ b/Mage.Sets/src/mage/sets/journeyintonyx/MarketFestival.java @@ -28,6 +28,7 @@ package mage.sets.journeyintonyx; import java.util.UUID; +import mage.MageObject; import mage.Mana; import mage.abilities.Ability; import mage.abilities.effects.common.AttachEffect; @@ -134,12 +135,18 @@ class MarketFestivalManaEffect extends ManaEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if(controller != null){ + MageObject sourceObject = game.getObject(source.getSourceId()); + if(controller != null && sourceObject != null){ int x = 2; Mana mana = new Mana(); for(int i = 0; i < x; i++){ ChoiceColor choiceColor = new ChoiceColor(); + if (i == 0) { + choiceColor.setMessage("First mana color for " + sourceObject.getLogName()); + } else { + choiceColor.setMessage("Second mana color for " + sourceObject.getLogName()); + } while (!controller.choose(Outcome.Benefit, choiceColor, game)) { if (!controller.isInGame()) { return false; diff --git a/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java b/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java index ba13ef8ad64..41ebb75db7c 100644 --- a/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java +++ b/Mage.Sets/src/mage/sets/theros/NykthosShrineToNyx.java @@ -27,6 +27,7 @@ */ package mage.sets.theros; +import java.util.ArrayList; import java.util.UUID; import mage.Mana; import mage.abilities.Ability; @@ -74,7 +75,7 @@ public class NykthosShrineToNyx extends CardImpl { } class NykthosShrineToNyxManaAbility extends ManaAbility { - + public NykthosShrineToNyxManaAbility() { super(Zone.BATTLEFIELD, new NykthosDynamicManaEffect(), new GenericManaCost(2)); this.addCost(new TapSourceCost()); @@ -94,8 +95,16 @@ class NykthosShrineToNyxManaAbility extends ManaAbility { if (game == null) { return new Mana(); } - // TODO: Give back a list with t he 5 different mana options - return new Mana(((NykthosDynamicManaEffect)this.getEffects().get(0)).computeMana("Green", game, this)); + // TODO: Give back at least the highest amount (https://github.com/magefree/mage/issues/585) + int amount = 0; + for (String colorChoice :ChoiceColor.colorChoices) { + Mana newMana = ((NykthosDynamicManaEffect)this.getEffects().get(0)).computeMana(colorChoice, game, this); + if (newMana.count() > amount) { + netMana = newMana; + amount = newMana.count(); + } + } + return netMana; } } diff --git a/Mage/src/mage/abilities/AbilityImpl.java b/Mage/src/mage/abilities/AbilityImpl.java index 3f9e63dde0c..dfc8b57dff1 100644 --- a/Mage/src/mage/abilities/AbilityImpl.java +++ b/Mage/src/mage/abilities/AbilityImpl.java @@ -54,6 +54,8 @@ import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; import java.util.UUID; +import mage.abilities.costs.common.TapSourceCost; +import mage.game.events.GameEvent; /** * @@ -365,6 +367,15 @@ public abstract class AbilityImpl implements Ability { game.informPlayers(new StringBuilder(controller.getName()).append(" announces a value of ").append(xValue).append(" for ").append(variableManaCost.getText()).toString()); } activated = true; + // fire if tapped for mana (may only fires now because else costs of ability itself can be payed with mana of abilities that trigger for that event + if (this.getAbilityType().equals(AbilityType.MANA)) { + for (Cost cost: costs) { + if (cost instanceof TapSourceCost) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId)); + break; + } + } + } return true; } diff --git a/Mage/src/mage/abilities/costs/common/TapSourceCost.java b/Mage/src/mage/abilities/costs/common/TapSourceCost.java index c5df637bfc8..2faab014371 100644 --- a/Mage/src/mage/abilities/costs/common/TapSourceCost.java +++ b/Mage/src/mage/abilities/costs/common/TapSourceCost.java @@ -29,12 +29,10 @@ package mage.abilities.costs.common; import java.util.UUID; -import mage.constants.AbilityType; import mage.abilities.Ability; import mage.abilities.costs.CostImpl; import mage.constants.AsThoughEffectType; import mage.game.Game; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; /** @@ -56,9 +54,6 @@ public class TapSourceCost extends CostImpl { Permanent permanent = game.getPermanent(sourceId); if (permanent != null) { paid = permanent.tap(game); - if (paid && ability.getAbilityType().equals(AbilityType.MANA)) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId)); - } } return paid; } diff --git a/Mage/src/mage/choices/ChoiceColor.java b/Mage/src/mage/choices/ChoiceColor.java index 82828201cc9..35a1f3ba01a 100644 --- a/Mage/src/mage/choices/ChoiceColor.java +++ b/Mage/src/mage/choices/ChoiceColor.java @@ -28,6 +28,7 @@ package mage.choices; +import java.util.ArrayList; import mage.ObjectColor; /** @@ -36,17 +37,22 @@ import mage.ObjectColor; */ public class ChoiceColor extends ChoiceImpl { + public static final ArrayList colorChoices = new ArrayList<>(); + static { + colorChoices.add("Green"); + colorChoices.add("Blue"); + colorChoices.add("Black"); + colorChoices.add("Red"); + colorChoices.add("White"); + } + public ChoiceColor() { this(true); } public ChoiceColor(boolean required) { super(required); - this.choices.add("Black"); - this.choices.add("Blue"); - this.choices.add("Green"); - this.choices.add("Red"); - this.choices.add("White"); + this.choices.addAll(colorChoices); this.message = "Choose color"; }