Improved MaximumHandSizeController effect.

This commit is contained in:
LevelX2 2012-12-12 01:05:13 +01:00
parent ef6ae9f5e4
commit 4fe64d99d9
9 changed files with 145 additions and 105 deletions

View file

@ -27,7 +27,12 @@
*/
package mage.sets.avacynrestored;
import mage.Constants.*;
import java.util.UUID;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Outcome;
import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.TriggeredAbilityImpl;
@ -40,6 +45,7 @@ import mage.abilities.effects.common.GetEmblemEffect;
import mage.abilities.effects.common.SkipNextUntapTargetEffect;
import mage.abilities.effects.common.TapTargetEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
@ -54,7 +60,6 @@ import mage.target.TargetPermanent;
import mage.target.TargetPlayer;
import mage.target.targetpointer.FixedTarget;
import java.util.UUID;
/**
*
@ -190,7 +195,7 @@ class TamiyoTheMoonSageEffect extends OneShotEffect<TamiyoTheMoonSageEffect> {
class TamiyoTheMoonSageEmblem extends Emblem {
public TamiyoTheMoonSageEmblem() {
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.EndOfGame, false));
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.EndOfGame, HandSizeModification.SET));
this.getAbilities().add(ability);
this.getAbilities().add(new TamiyoTheMoonSageTriggeredAbility());
}

View file

@ -28,14 +28,15 @@
package mage.sets.championsofkamigawa;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.CardImpl;
/**
@ -55,8 +56,8 @@ public class GracefulAdept extends CardImpl<GracefulAdept> {
this.toughness = new MageInt(3);
// You have no maximum hand size.
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, false);
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect));
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.WhileOnBattlefield, HandSizeModification.SET);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
}
public GracefulAdept(final GracefulAdept card) {

View file

@ -28,13 +28,14 @@
package mage.sets.conflux;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.Constants.Zone;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.abilities.mana.ColorlessManaAbility;
import mage.cards.CardImpl;
@ -49,8 +50,8 @@ public class ReliquaryTower extends CardImpl<ReliquaryTower> {
this.expansionSetCode = "CON";
// You have no maximum hand size.
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, false);
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect));
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.WhileOnBattlefield, HandSizeModification.SET);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
// {tap}: Add {1} to your mana pool.
this.addAbility(new ColorlessManaAbility());

View file

@ -28,13 +28,13 @@
package mage.sets.magic2010;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Rarity;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.CardImpl;
/**
@ -48,7 +48,7 @@ public class Spellbook extends CardImpl<Spellbook> {
this.expansionSetCode = "M10";
// You have no maximum hand size.
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, false);
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, HandSizeModification.SET);
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect));
}

View file

@ -36,6 +36,7 @@ import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ExileSpellEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.game.Game;
@ -53,7 +54,7 @@ public class PraetorsCounsel extends CardImpl<PraetorsCounsel> {
this.color.setGreen(true);
this.getSpellAbility().addEffect(new PraetorsCounselEffect());
this.getSpellAbility().addEffect(ExileSpellEffect.getInstance());
this.getSpellAbility().addEffect(new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.EndOfGame, false));
this.getSpellAbility().addEffect(new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.EndOfGame, HandSizeModification.SET));
}
public PraetorsCounsel(final PraetorsCounsel card) {

View file

@ -28,20 +28,19 @@
package mage.sets.newphyrexia;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.effects.common.DrawCardControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.abilities.keyword.FlashAbility;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.players.Player;
/**
*
@ -59,9 +58,15 @@ public class JinGitaxiasCoreAugur extends CardImpl<JinGitaxiasCoreAugur> {
this.power = new MageInt(5);
this.toughness = new MageInt(4);
// Flash
this.addAbility(FlashAbility.getInstance());
// At the beginning of your end step, draw seven cards.
this.addAbility(new BeginningOfYourEndStepTriggeredAbility(new DrawCardControllerEffect(7), false));
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, new JinGitaxiasCoreAugurEffect()));
// Each opponent's maximum hand size is reduced by seven.
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD,
new MaximumHandSizeControllerEffect(7, Duration.WhileOnBattlefield, HandSizeModification.REDUCE, TargetController.OPPONENT)));
}
public JinGitaxiasCoreAugur(final JinGitaxiasCoreAugur card) {
@ -72,31 +77,4 @@ public class JinGitaxiasCoreAugur extends CardImpl<JinGitaxiasCoreAugur> {
public JinGitaxiasCoreAugur copy() {
return new JinGitaxiasCoreAugur(this);
}
}
class JinGitaxiasCoreAugurEffect extends ContinuousEffectImpl<JinGitaxiasCoreAugurEffect> {
JinGitaxiasCoreAugurEffect() {
super(Constants.Duration.WhileOnBattlefield, Constants.Layer.PlayerEffects, Constants.SubLayer.NA, Constants.Outcome.Detriment);
staticText = "Each opponent's maximum hand size is reduced by seven";
}
JinGitaxiasCoreAugurEffect(final JinGitaxiasCoreAugurEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(opponentId);
if (player != null) {
player.setMaxHandSize(player.getMaxHandSize() - 7);
}
}
return true;
}
@Override
public JinGitaxiasCoreAugurEffect copy() {
return new JinGitaxiasCoreAugurEffect(this);
}
}

View file

@ -28,16 +28,18 @@
package mage.sets.scarsofmirrodin;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.Constants.Zone;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.dynamicvalue.common.CardsInControllerHandCount;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.CardImpl;
/**
@ -51,11 +53,11 @@ public class VensersJournal extends CardImpl<VensersJournal> {
this.expansionSetCode = "SOM";
// You have no maximum hand size.
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, false);
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect));
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.WhileOnBattlefield, HandSizeModification.SET);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
// At the beginning of your upkeep, you gain 1 life for each card in your hand.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new GainLifeEffect(new CardsInControllerHandCount()), Constants.TargetController.YOU, false));
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new GainLifeEffect(new CardsInControllerHandCount()), TargetController.YOU, false));
}
public VensersJournal(final VensersJournal card) {

View file

@ -30,13 +30,17 @@ package mage.sets.visions;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Duration;
import mage.Constants.Rarity;
import mage.Constants.TargetController;
import mage.Constants.Zone;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfDrawTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect;
import mage.abilities.effects.common.continious.MaximumHandSizeControllerEffect.HandSizeModification;
import mage.cards.CardImpl;
import mage.game.Game;
import mage.players.Player;
@ -52,11 +56,11 @@ public class AnvilOfBogardan extends CardImpl<AnvilOfBogardan> {
this.expansionSetCode = "VIS";
// Players have no maximum hand size.
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Constants.Duration.WhileOnBattlefield, false, true);
this.addAbility(new SimpleStaticAbility(Constants.Zone.BATTLEFIELD, effect));
Effect effect = new MaximumHandSizeControllerEffect(Integer.MAX_VALUE, Duration.WhileOnBattlefield, HandSizeModification.SET, TargetController.ANY);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
// At the beginning of each player's draw step, that player draws an additional card, then discards a card.
this.addAbility(new BeginningOfDrawTriggeredAbility(Constants.Zone.BATTLEFIELD, new AnvilOfBogardanEffect(), Constants.TargetController.ANY, false));
this.addAbility(new BeginningOfDrawTriggeredAbility(Zone.BATTLEFIELD, new AnvilOfBogardanEffect(), TargetController.ANY, false));
}
public AnvilOfBogardan(final AnvilOfBogardan card) {

View file

@ -27,99 +27,147 @@
*/
package mage.abilities.effects.common.continious;
import java.util.UUID;
import mage.Constants.Duration;
import mage.Constants.Layer;
import mage.Constants.Outcome;
import mage.Constants.SubLayer;
import mage.Constants.TargetController;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.game.Game;
import mage.players.Player;
/**
* @author nantuko
* @author nantuko, LevelX2
*/
public class MaximumHandSizeControllerEffect extends ContinuousEffectImpl<MaximumHandSizeControllerEffect> {
public static enum HandSizeModification { SET, INCREASE, REDUCE };
protected int handSize;
protected boolean reduce;
protected boolean allPlayers;
protected HandSizeModification handSizeModification;
protected TargetController targetController;
/**
* @param handSize Maximum hand size to set or to reduce by
* @param duration Effect duration
* @param reduce If true, the hand size will be reduced related to current
* value, otherwise it will be set.
* @param handSizeModification SET, INCREASE, REDUCE
*
*/
public MaximumHandSizeControllerEffect(int handSize, Duration duration, boolean reduce) {
super(duration, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
this.handSize = handSize;
this.reduce = reduce;
setText();
public MaximumHandSizeControllerEffect(int handSize, Duration duration, HandSizeModification handSizeModification) {
this(handSize, duration, handSizeModification, TargetController.YOU);
}
public MaximumHandSizeControllerEffect(int handSize, Duration duration, boolean reduce, boolean allPlayers) {
super(duration, Layer.PlayerEffects, SubLayer.NA, Outcome.Benefit);
public MaximumHandSizeControllerEffect(int handSize, Duration duration, HandSizeModification handSizeModification, TargetController targetController) {
super(duration, Layer.PlayerEffects, SubLayer.NA, defineOutcome(handSizeModification, targetController));
this.handSize = handSize;
this.reduce = reduce;
this.allPlayers = allPlayers;
this.handSizeModification = handSizeModification;
this.targetController = targetController;
setText();
}
public MaximumHandSizeControllerEffect(final MaximumHandSizeControllerEffect effect) {
super(effect);
this.handSize = effect.handSize;
this.reduce = effect.reduce;
this.allPlayers = effect.allPlayers;
this.handSizeModification = effect.handSizeModification;
this.targetController = effect.targetController;
}
@Override
public MaximumHandSizeControllerEffect copy() {
return new MaximumHandSizeControllerEffect(this);
}
protected static Outcome defineOutcome(HandSizeModification handSizeModification, TargetController targetController) {
Outcome newOutcome = Outcome.Benefit;
if ((targetController.equals(TargetController.YOU) || targetController.equals(TargetController.ANY))
&& handSizeModification.equals(HandSizeModification.REDUCE)) {
newOutcome = Outcome.Detriment;
}
return newOutcome;
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (allPlayers) {
for (Player playerid : game.getPlayers().values()) {
if (playerid != null) {
if (reduce) {
player.setMaxHandSize(player.getMaxHandSize() - handSize);
} else {
player.setMaxHandSize(handSize);
}
Player controller = game.getPlayer(source.getControllerId());
switch(targetController) {
case ANY:
for (UUID playerId: controller.getInRange()) {
setHandSize(game, playerId);
}
}
return true;
}
if (!allPlayers && player != null) {
if (reduce) {
player.setMaxHandSize(player.getMaxHandSize() - handSize);
} else {
player.setMaxHandSize(handSize);
}
return true;
break;
case OPPONENT:
for (UUID playerId: game.getOpponents(source.getControllerId())) {
setHandSize(game, playerId);
}
break;
case YOU:
setHandSize(game, source.getControllerId());
break;
default:
throw new UnsupportedOperationException("Not supported yet.");
}
return true;
}
private void setText() {
if (allPlayers && handSize == Integer.MAX_VALUE) {
staticText = "All players have no maximum hand size";
}
if (!allPlayers && handSize == Integer.MAX_VALUE) {
staticText = "You have no maximum hand size";
}
if (!allPlayers && staticText == null) {
StringBuilder sb = new StringBuilder("Your maximum hand size is ");
if (reduce) {
sb.append("reduced by ");
sb.append(Integer.toString(handSize));
} else {
sb.append(Integer.toString(handSize));
private void setHandSize(Game game, UUID playerId) {
Player player = game.getPlayer(playerId);
if (player != null) {
switch(handSizeModification) {
case SET:
player.setMaxHandSize(handSize);
break;
case INCREASE:
player.setMaxHandSize(player.getMaxHandSize() + handSize);
break;
case REDUCE:
player.setMaxHandSize(player.getMaxHandSize() - handSize);
break;
}
staticText = sb.toString();
}
}
private void setText() {
StringBuilder sb = new StringBuilder();
switch(targetController) {
case ANY:
if (handSize == Integer.MAX_VALUE) {
sb.append("All players have no ");
} else {
sb.append("All players ");
}
break;
case OPPONENT:
if (handSize == Integer.MAX_VALUE) {
sb.append("Each opponent has no ");
} else {
sb.append("Each opponent's ");
}
break;
case YOU:
if (handSize == Integer.MAX_VALUE) {
sb.append("You have no ");
} else {
sb.append("Your ");
}
break;
}
sb.append("maximum hand size");
if (handSizeModification.equals(HandSizeModification.INCREASE)){
sb.append(" is increased by ");
} else if (handSizeModification.equals(HandSizeModification.REDUCE)){
sb.append(" is reduced by ");
} else if (handSize != Integer.MAX_VALUE) {
sb.append(" is ");
}
if (handSize != Integer.MAX_VALUE) {
sb.append(handSize);
}
if (duration == Duration.EndOfGame) {
sb.append(" for the rest of the game");
}
staticText = sb.toString();
}
}