* Fixed a lot of cards where order of card discarding/hand,graveyard,permanents into library shuffling and card draw order was not correctly implemented. This could cause bugs for draw replacement effects (e.g. Notion Thief).

This commit is contained in:
LevelX2 2015-08-19 03:31:44 +02:00
parent 72c4f458ce
commit bd6fa770aa
17 changed files with 329 additions and 215 deletions

View file

@ -0,0 +1,99 @@
/*
* 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.UUID;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.TargetController;
import static mage.constants.TargetController.ANY;
import static mage.constants.TargetController.OPPONENT;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class SetPlayerLifeAllEffect extends OneShotEffect {
private TargetController targetController;
protected DynamicValue amount;
public SetPlayerLifeAllEffect(int amount) {
this(amount, TargetController.ANY);
}
public SetPlayerLifeAllEffect(DynamicValue amount) {
this(amount, TargetController.ANY);
}
public SetPlayerLifeAllEffect(int amount, TargetController targetController) {
this(new StaticValue(amount), targetController);
}
public SetPlayerLifeAllEffect(DynamicValue amount, TargetController targetController) {
super(Outcome.DrawCard);
this.amount = amount;
this.targetController = targetController;
staticText = setText();
}
public SetPlayerLifeAllEffect(final SetPlayerLifeAllEffect effect) {
super(effect);
this.amount = effect.amount;
this.targetController = effect.targetController;
}
@Override
public SetPlayerLifeAllEffect copy() {
return new SetPlayerLifeAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player sourcePlayer = game.getPlayer(source.getControllerId());
switch (targetController) {
case ANY:
for (UUID playerId : sourcePlayer.getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.setLife(amount.calculate(game, source, this), game);
}
}
break;
case OPPONENT:
for (UUID playerId : game.getOpponents(sourcePlayer.getId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.setLife(amount.calculate(game, source, this), game);
}
}
break;
}
return true;
}
private String setText() {
StringBuilder sb = new StringBuilder("Each ");
switch (targetController) {
case ANY:
sb.append("player");
break;
case OPPONENT:
sb.append("opponent");
break;
default:
throw new UnsupportedOperationException("Not supported value for targetController");
}
sb.append(" 's life total becomes ");
sb.append(amount.toString());
return sb.toString();
}
}

View file

@ -1,7 +1,8 @@
package mage.actions;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.actions.impl.MageAction;
import mage.actions.score.ArtificialScoringSystem;
import mage.cards.Card;
@ -9,9 +10,6 @@ import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import java.util.List;
import java.util.UUID;
import mage.util.CardUtil;
/**
@ -39,7 +37,7 @@ public class MageDrawAction extends MageAction {
* Draw and set action score.
*
* @param game Game context.
* @return
* @return
*/
@Override
public int doAction(Game game) {
@ -70,8 +68,8 @@ public class MageDrawAction extends MageAction {
}
/**
* Draw a card if possible (there is no replacement effect that prevent us from drawing).
* Fire event about card drawn.
* Draw a card if possible (there is no replacement effect that prevent us
* from drawing). Fire event about card drawn.
*
* @param game
* @return