Merge pull request #1611 from spjspj/master

spjspj - implement ClockSpinning (TSP) - Modified AddCountersTargetEf…
This commit is contained in:
LevelX2 2016-03-07 16:20:42 +01:00
commit 633995060e
2 changed files with 245 additions and 11 deletions

View file

@ -0,0 +1,226 @@
/*
* 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.timespiral;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.SpellAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.abilities.effects.common.counter.RemoveCounterTargetEffect;
import mage.abilities.keyword.BuybackAbility;
import mage.abilities.keyword.SuspendAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.counters.Counter;
import mage.counters.CounterType;
import mage.filter.FilterCard;
import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.filter.predicate.other.CounterCardPredicate;
import mage.filter.predicate.permanent.CounterAnyPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.target.TargetPermanent;
import mage.target.common.TargetCardInExile;
import mage.target.targetpointer.FixedTarget;
/**
*
* @author spjspj
*/
public class Clockspinning extends CardImpl {
public Clockspinning(UUID ownerId) {
super(ownerId, 53, "Clockspinning", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{U}");
this.expansionSetCode = "TSP";
// Buyback {3}
this.addAbility(new BuybackAbility("{3}"));
// Choose a counter on target permanent or suspended card. Remove that counter from that permanent or card or put another of those counters on it.
Choice targetChoice = new ChoiceImpl();
targetChoice.setMessage("Choose what to target");
targetChoice.getChoices().add("Permanent");
targetChoice.getChoices().add("Suspended Card");
this.getSpellAbility().addChoice(targetChoice);
this.getSpellAbility().addEffect(new ClockspinningAddOrRemoveCounterEffect());
}
@Override
public void adjustTargets(Ability ability, Game game) {
if (ability instanceof SpellAbility) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof ClockspinningAddOrRemoveCounterEffect) {
Choice targetChoice = ability.getChoices().get(0);
if (targetChoice.getChoice().equals("Permanent")) {
FilterPermanent filter = new FilterPermanent("target permanent with a counter");
filter.add(new CounterAnyPredicate());
ability.addTarget(new TargetPermanent(filter));
}
if (targetChoice.getChoice().equals("Suspended Card")) {
FilterCard suspendFilter = new FilterCard("suspended card");
suspendFilter.add(new AbilityPredicate(SuspendAbility.class));
suspendFilter.add(new CounterCardPredicate(CounterType.TIME));
Target target = new TargetCardInExile(1, 1, suspendFilter, null, true);
ability.addTarget(target);
}
}
}
}
}
public Clockspinning(final Clockspinning card) {
super(card);
}
@Override
public Clockspinning copy() {
return new Clockspinning(this);
}
}
class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect {
ClockspinningAddOrRemoveCounterEffect() {
super(Outcome.Removal);
this.staticText = "Remove or add a counter from a target suspended card or a target permanent";
}
ClockspinningAddOrRemoveCounterEffect(final ClockspinningAddOrRemoveCounterEffect effect) {
super(effect);
}
@Override
public ClockspinningAddOrRemoveCounterEffect copy() {
return new ClockspinningAddOrRemoveCounterEffect(this);
}
private Counter selectCounterType(Game game, Ability source, Permanent permanent) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && permanent.getCounters().size() > 0) {
String counterName = null;
if (permanent.getCounters().size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : permanent.getCounters().values()) {
if (permanent.getCounters().getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter type to add to " + permanent.getName());
controller.choose(Outcome.Neutral, choice, game);
counterName = choice.getChoice();
} else {
for (Counter counter : permanent.getCounters().values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
return new Counter(counterName);
}
return null;
}
private Counter selectCounterType(Game game, Ability source, Card card) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && card.getCounters(game).size() > 0) {
String counterName = null;
if (card.getCounters(game).size() > 1) {
Choice choice = new ChoiceImpl(true);
Set<String> choices = new HashSet<>();
for (Counter counter : card.getCounters(game).values()) {
if (card.getCounters(game).getCount(counter.getName()) > 0) {
choices.add(counter.getName());
}
}
choice.setChoices(choices);
choice.setMessage("Choose a counter type to add to " + card.getName());
controller.choose(Outcome.Neutral, choice, game);
counterName = choice.getChoice();
} else {
for (Counter counter : card.getCounters(game).values()) {
if (counter.getCount() > 0) {
counterName = counter.getName();
}
}
}
return new Counter(counterName);
}
return null;
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
Card card = game.getCard(source.getFirstTarget());
if (player != null && permanent != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, permanent);
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
}
}
if (player != null && card != null) {
if (player.chooseUse(Outcome.Neutral, "Do you want to to remove a counter?", source, game)) {
Counter counter = selectCounterType(game, source, card);
RemoveCounterTargetEffect effect = new RemoveCounterTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
} else {
Counter counter = selectCounterType(game, source, card);
AddCountersTargetEffect effect = new AddCountersTargetEffect(counter);
effect.setTargetPointer(new FixedTarget(source.getFirstTarget()));
return effect.apply(game, source);
}
}
return false;
}
}

View file

@ -34,6 +34,7 @@ import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue; import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.counters.Counter; import mage.counters.Counter;
import mage.counters.CounterType; import mage.counters.CounterType;
@ -85,6 +86,8 @@ public class AddCountersTargetEffect extends OneShotEffect {
int affectedTargets = 0; int affectedTargets = 0;
for (UUID uuid : targetPointer.getTargets(game, source)) { for (UUID uuid : targetPointer.getTargets(game, source)) {
Permanent permanent = game.getPermanent(uuid); Permanent permanent = game.getPermanent(uuid);
Player player = game.getPlayer(uuid);
Card card = game.getCard(targetPointer.getFirst(game, source));
if (permanent != null) { if (permanent != null) {
if (counter != null) { if (counter != null) {
Counter newCounter = counter.copy(); Counter newCounter = counter.copy();
@ -102,18 +105,23 @@ public class AddCountersTargetEffect extends OneShotEffect {
+ numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName()); + numberAdded + " " + counter.getName().toLowerCase() + " counter on " + permanent.getLogName());
} }
} }
} else { } else if (player != null) {
Player player = game.getPlayer(uuid); Counter newCounter = counter.copy();
if (player != null) { newCounter.add(amount.calculate(game, source, this));
Counter newCounter = counter.copy(); player.addCounters(newCounter, game);
newCounter.add(amount.calculate(game, source, this)); affectedTargets++;
player.addCounters(newCounter, game); if (!game.isSimulation()) {
affectedTargets++; game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
if (!game.isSimulation()) { + counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName());
game.informPlayers(sourceObject.getLogName() + ": " + controller.getLogName() + " puts "
+ counter.getCount() + " " + counter.getName().toLowerCase() + " counter on " + player.getLogName());
}
} }
} else if (card != null && counter != null) {
card.addCounters(counter.getName(), counter.getCount(), game);
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder("Added ").append(counter.getCount()).append(" ").append(counter.getName())
.append(" counter to ").append(card.getName())
.append(" (").append(card.getCounters(game).getCount(counter.getName())).append(")").toString());
}
return true;
} }
} }
return affectedTargets > 0; return affectedTargets > 0;