From b8af8106f6ab6d4aac774d4428851db36e694dd3 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Thu, 21 Nov 2013 14:28:54 +0100 Subject: [PATCH] Added ManaInAnyCombinationEffect and RemoveCountersForCostCondition and some minor formatting and additions. --- .../java/mage/player/ai/ComputerPlayer.java | 3 + .../mage/sets/fallenempires/Seasinger.java | 4 +- .../mage/sets/theros/ProphetOfKruphix.java | 6 -- .../common/EquipmentAttachedCondition.java | 2 +- .../RemoveVariableCountersSourceCost.java | 7 +- .../abilities/costs/common/TapSourceCost.java | 4 +- .../common/RemovedCountersForCostValue.java | 46 +++++++++ .../effects/common/DynamicManaEffect.java | 4 +- .../common/ManaInAnyCombinationEffect.java | 93 +++++++++++++++++++ .../mage/constants/AsThoughEffectType.java | 3 +- .../src/mage/constants/ColoredManaSymbol.java | 2 +- Mage/src/mage/counters/CounterType.java | 49 +++++++++- .../mage/counters/common/StorageCounter.java | 47 ++++++++++ 13 files changed, 250 insertions(+), 20 deletions(-) create mode 100644 Mage/src/mage/abilities/dynamicvalue/common/RemovedCountersForCostValue.java create mode 100644 Mage/src/mage/abilities/effects/common/ManaInAnyCombinationEffect.java create mode 100644 Mage/src/mage/counters/common/StorageCounter.java diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 9993502bb21..675d32e44ab 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1292,6 +1292,9 @@ public class ComputerPlayer> extends PlayerImpl i public int getAmount(int min, int max, String message, Game game) { log.debug("getAmount"); //TODO: improve this + if (min < max && min == 0) { + return new Random().nextInt(max+1); + } return min; } diff --git a/Mage.Sets/src/mage/sets/fallenempires/Seasinger.java b/Mage.Sets/src/mage/sets/fallenempires/Seasinger.java index ebaed495e23..e4a37ffef08 100644 --- a/Mage.Sets/src/mage/sets/fallenempires/Seasinger.java +++ b/Mage.Sets/src/mage/sets/fallenempires/Seasinger.java @@ -87,7 +87,9 @@ public class Seasinger extends CardImpl { this.addAbility(new SkipUntapOptionalAbility()); // {tap}: Gain control of target creature whose controller controls an Island for as long as you control Seasinger and Seasinger remains tapped. - ConditionalContinousEffect effect = new ConditionalContinousEffect(new GainControlTargetEffect(Duration.Custom), new ControlsPermanentCondition(seasinger, ControlsPermanentCondition.CountType.EQUAL_TO, 1, SourceTappedCondition.getInstance()), rule); + ConditionalContinousEffect effect = new ConditionalContinousEffect( + new GainControlTargetEffect(Duration.Custom), + new ControlsPermanentCondition(seasinger, ControlsPermanentCondition.CountType.EQUAL_TO, 1, SourceTappedCondition.getInstance()), rule); Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect, new TapSourceCost()); creatureWhoseControllerControlsIsland.add(new ControllerControlsIslandPredicate()); ability.addTarget(new TargetCreaturePermanent(creatureWhoseControllerControlsIsland)); diff --git a/Mage.Sets/src/mage/sets/theros/ProphetOfKruphix.java b/Mage.Sets/src/mage/sets/theros/ProphetOfKruphix.java index 08d63c6c25c..7cd47b99bba 100644 --- a/Mage.Sets/src/mage/sets/theros/ProphetOfKruphix.java +++ b/Mage.Sets/src/mage/sets/theros/ProphetOfKruphix.java @@ -29,19 +29,14 @@ package mage.sets.theros; import java.util.UUID; import mage.MageInt; -import mage.abilities.Ability; import mage.abilities.common.BeginningOfUntapTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; -import mage.abilities.effects.AsThoughEffectImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.common.UntapAllControllerEffect; import mage.abilities.effects.common.continious.CastAsThoughItHadFlashEffect; -import mage.cards.Card; import mage.cards.CardImpl; -import mage.constants.AsThoughEffectType; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.TargetController; import mage.constants.Zone; @@ -49,7 +44,6 @@ import mage.filter.FilterPermanent; import mage.filter.common.FilterCreatureCard; import mage.filter.predicate.Predicates; import mage.filter.predicate.mageobject.CardTypePredicate; -import mage.game.Game; /** * diff --git a/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java b/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java index f67be3104ca..d5d6bdd9a7e 100644 --- a/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java +++ b/Mage/src/mage/abilities/condition/common/EquipmentAttachedCondition.java @@ -49,7 +49,7 @@ public class EquipmentAttachedCondition implements Condition { @Override public boolean apply(Game game, Ability source) { Permanent attachment = game.getPermanent(source.getSourceId()); - return attachment == null || attachment.getAttachedTo() == null; + return attachment != null && attachment.getAttachedTo() != null; } } diff --git a/Mage/src/mage/abilities/costs/common/RemoveVariableCountersSourceCost.java b/Mage/src/mage/abilities/costs/common/RemoveVariableCountersSourceCost.java index 23c0332552c..c35a4beacd4 100644 --- a/Mage/src/mage/abilities/costs/common/RemoveVariableCountersSourceCost.java +++ b/Mage/src/mage/abilities/costs/common/RemoveVariableCountersSourceCost.java @@ -51,7 +51,7 @@ public class RemoveVariableCountersSourceCost extends CostImpl= minimalCountersToPay) { - return true; - } - return false; + return permanent != null && permanent.getCounters().getCount(name) >= minimalCountersToPay; } @Override diff --git a/Mage/src/mage/abilities/costs/common/TapSourceCost.java b/Mage/src/mage/abilities/costs/common/TapSourceCost.java index 086c308fb87..4872e4f0570 100644 --- a/Mage/src/mage/abilities/costs/common/TapSourceCost.java +++ b/Mage/src/mage/abilities/costs/common/TapSourceCost.java @@ -32,6 +32,7 @@ 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; @@ -66,7 +67,8 @@ public class TapSourceCost extends CostImpl { public boolean canPay(UUID sourceId, UUID controllerId, Game game) { Permanent permanent = game.getPermanent(sourceId); if (permanent != null) { - return !permanent.isTapped() && permanent.canTap(); + return !permanent.isTapped() && + (permanent.canTap() || game.getContinuousEffects().asThough(sourceId, AsThoughEffectType.ACTIVATE_HASTE, game)); } return false; } diff --git a/Mage/src/mage/abilities/dynamicvalue/common/RemovedCountersForCostValue.java b/Mage/src/mage/abilities/dynamicvalue/common/RemovedCountersForCostValue.java new file mode 100644 index 00000000000..d6d36c1ceaf --- /dev/null +++ b/Mage/src/mage/abilities/dynamicvalue/common/RemovedCountersForCostValue.java @@ -0,0 +1,46 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package mage.abilities.dynamicvalue.common; + +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.abilities.costs.common.RemoveVariableCountersSourceCost; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.game.Game; + +/** + * + * @author LevelX2 + */ +public class RemovedCountersForCostValue implements DynamicValue { + + @Override + public int calculate(Game game, Ability sourceAbility) { + for (Cost cost: sourceAbility.getCosts()) { + if (cost instanceof RemoveVariableCountersSourceCost) { + return ((RemoveVariableCountersSourceCost) cost).getAmount(); + } + } + return 0; + } + + @Override + public String getMessage() { + return "number of removed counters"; + } + + @Override + public DynamicValue copy() { + return new RemovedCountersForCostValue(); + } + + @Override + public String toString() { + return "X"; + } + +} diff --git a/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java b/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java index 930574566b7..e950ffd13b7 100644 --- a/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java +++ b/Mage/src/mage/abilities/effects/common/DynamicManaEffect.java @@ -39,8 +39,8 @@ import mage.game.Game; */ public class DynamicManaEffect extends BasicManaEffect { - private Mana computedMana; - private DynamicValue amount; + private final Mana computedMana; + private final DynamicValue amount; private String text = null; public DynamicManaEffect(Mana mana, DynamicValue amount) { diff --git a/Mage/src/mage/abilities/effects/common/ManaInAnyCombinationEffect.java b/Mage/src/mage/abilities/effects/common/ManaInAnyCombinationEffect.java new file mode 100644 index 00000000000..f47cd607044 --- /dev/null +++ b/Mage/src/mage/abilities/effects/common/ManaInAnyCombinationEffect.java @@ -0,0 +1,93 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ + +package mage.abilities.effects.common; + +import java.util.ArrayList; +import java.util.Arrays; +import mage.Mana; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.DynamicValue; +import mage.abilities.dynamicvalue.common.StaticValue; +import mage.constants.ColoredManaSymbol; +import mage.game.Game; +import mage.players.Player; +import mage.util.CardUtil; + +/** + * + * @author LevelX2 + */ +public class ManaInAnyCombinationEffect extends ManaEffect { + + private ArrayList manaSymbols = new ArrayList(); + private final DynamicValue amount; + + public ManaInAnyCombinationEffect(int amount, ColoredManaSymbol... coloredManaSymbols) { + this(new StaticValue(amount), coloredManaSymbols); + } + + public ManaInAnyCombinationEffect(DynamicValue amount, ColoredManaSymbol... coloredManaSymbols) { + super(); + this.manaSymbols.addAll(Arrays.asList(coloredManaSymbols)); + this.amount = amount; + this.staticText = setText(); + } + + public ManaInAnyCombinationEffect(final ManaInAnyCombinationEffect effect) { + super(effect); + this.manaSymbols = effect.manaSymbols; + this.amount = effect.amount; + } + + @Override + public ManaInAnyCombinationEffect copy() { + return new ManaInAnyCombinationEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player != null){ + Mana mana = new Mana(); + int amountOfManaLeft = amount.calculate(game, source); + + while (amountOfManaLeft > 0 && player.isInGame()) { + for (ColoredManaSymbol coloredManaSymbol: manaSymbols) { + int number = player.getAmount(0, amountOfManaLeft, new StringBuilder("How many ").append(coloredManaSymbol.name()).append(" mana?").toString(), game); + if (number > 0) { + for (int i = 0; i < number; i++) { + mana.add(new Mana(coloredManaSymbol)); + } + amountOfManaLeft -= number; + } + if (amountOfManaLeft == 0) { + break; + } + } + } + player.getManaPool().addMana(mana, game, source); + return true; + } + return false; + } + + private String setText() { + StringBuilder sb = new StringBuilder("Add "); + sb.append(CardUtil.numberToText(amount.toString())); + sb.append(" mana in any combination of "); + int i = 0; + for (ColoredManaSymbol coloredManaSymbol: manaSymbols) { + i++; + if (i > 1) { + sb.append(" and/or "); + } + sb.append("{").append(coloredManaSymbol.toString()).append("}"); + } + sb.append(" to your mana pool"); + return sb.toString(); + } +} diff --git a/Mage/src/mage/constants/AsThoughEffectType.java b/Mage/src/mage/constants/AsThoughEffectType.java index f86aec189a2..b910e80f8f0 100644 --- a/Mage/src/mage/constants/AsThoughEffectType.java +++ b/Mage/src/mage/constants/AsThoughEffectType.java @@ -6,13 +6,14 @@ package mage.constants; */ public enum AsThoughEffectType { ATTACK, + ACTIVATE_HASTE, BLOCK_TAPPED, BE_BLOCKED, CAST, DAMAGE, HEXPROOF, - SPEND_ANY_MANA, PAY, REVEAL_FACE_DOWN, + SPEND_ANY_MANA, TARGET } diff --git a/Mage/src/mage/constants/ColoredManaSymbol.java b/Mage/src/mage/constants/ColoredManaSymbol.java index 4520826e585..eea60c1a4dd 100644 --- a/Mage/src/mage/constants/ColoredManaSymbol.java +++ b/Mage/src/mage/constants/ColoredManaSymbol.java @@ -7,7 +7,7 @@ package mage.constants; public enum ColoredManaSymbol { W("W"), U("U"), B("B"), R("R"), G("G"); - private String text; + private final String text; ColoredManaSymbol(String text) { this.text = text; diff --git a/Mage/src/mage/counters/CounterType.java b/Mage/src/mage/counters/CounterType.java index e7e85a69973..f5103368c8e 100644 --- a/Mage/src/mage/counters/CounterType.java +++ b/Mage/src/mage/counters/CounterType.java @@ -28,7 +28,49 @@ package mage.counters; -import mage.counters.common.*; +import mage.counters.common.AgeCounter; +import mage.counters.common.AimCounter; +import mage.counters.common.ArrowheadCounter; +import mage.counters.common.AwakeningCounter; +import mage.counters.common.BlazeCounter; +import mage.counters.common.BriberyCounter; +import mage.counters.common.ChargeCounter; +import mage.counters.common.DespairCounter; +import mage.counters.common.DevotionCounter; +import mage.counters.common.DivinityCounter; +import mage.counters.common.ElixirCounter; +import mage.counters.common.EonCounter; +import mage.counters.common.EyeballCounter; +import mage.counters.common.FadeCounter; +import mage.counters.common.FateCounter; +import mage.counters.common.FeatherCounter; +import mage.counters.common.FuseCounter; +import mage.counters.common.HatchlingCounter; +import mage.counters.common.HoofprintCounter; +import mage.counters.common.IceCounter; +import mage.counters.common.KiCounter; +import mage.counters.common.LevelCounter; +import mage.counters.common.LoreCounter; +import mage.counters.common.LoyaltyCounter; +import mage.counters.common.MiningCounter; +import mage.counters.common.MinusOneCounter; +import mage.counters.common.PageCounter; +import mage.counters.common.PainCounter; +import mage.counters.common.PetrificationCounter; +import mage.counters.common.PlagueCounter; +import mage.counters.common.PlusOneCounter; +import mage.counters.common.PoisonCounter; +import mage.counters.common.PressureCounter; +import mage.counters.common.QuestCounter; +import mage.counters.common.SlimeCounter; +import mage.counters.common.SporeCounter; +import mage.counters.common.StorageCounter; +import mage.counters.common.StudyCounter; +import mage.counters.common.TheftCounter; +import mage.counters.common.TimeCounter; +import mage.counters.common.TowerCounter; +import mage.counters.common.VileCounter; +import mage.counters.common.WishCounter; /** * Enum for counters, names and instances. @@ -72,6 +114,7 @@ public enum CounterType { QUEST(new QuestCounter().name), SLIME(new SlimeCounter().name), SPORE(new SporeCounter().name), + STORAGE(new StorageCounter().name), STUDY(new StudyCounter().name), THEFT(new TheftCounter().name), TIME(new TimeCounter().name), @@ -79,7 +122,7 @@ public enum CounterType { VILE(new VileCounter().name), WISH(new WishCounter().name); - private String name; + private final String name; private CounterType(String name) { this.name = name; @@ -163,6 +206,8 @@ public enum CounterType { return new SlimeCounter(amount); case SPORE: return new SporeCounter(amount); + case STORAGE: + return new StorageCounter(amount); case STUDY: return new StudyCounter(amount); case EYEBALL: diff --git a/Mage/src/mage/counters/common/StorageCounter.java b/Mage/src/mage/counters/common/StorageCounter.java new file mode 100644 index 00000000000..8aa13171dc6 --- /dev/null +++ b/Mage/src/mage/counters/common/StorageCounter.java @@ -0,0 +1,47 @@ +/* + * Copyright 2011 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.counters.common; + +import mage.counters.Counter; + +/** + * + * @author LevelX2 + */ +public class StorageCounter extends Counter { + + public StorageCounter() { + this(1); + } + + public StorageCounter(int amount) { + super("storage"); + this.count = amount; + } +}