Improved handling of applied efffects for replacement effects.

This commit is contained in:
LevelX2 2013-04-21 22:34:44 +02:00
parent 8678da6051
commit 768ef9a4fc
4 changed files with 26 additions and 6 deletions

View file

@ -253,6 +253,11 @@ public class ContinuousEffects implements Serializable {
}
//get all applicable transient Replacement effects
for (ReplacementEffect effect: replacementEffects) {
if (event.getAppliedEffects() != null && event.getAppliedEffects().contains(effect.getId())) {
// Effect already applied to this event, ignore it
// TODO: Handle also gained effect that are connected to different abilities.
continue;
}
HashSet<Ability> abilities = replacementEffects.getAbility(effect.getId());
HashSet<Ability> applicableAbilities = new HashSet<Ability>();
for (Ability ability : abilities) {
@ -450,6 +455,7 @@ public class ContinuousEffects implements Serializable {
}
if (rEffect != null) {
event.getAppliedEffects().add(rEffect.getId());
caught = rEffect.replaceEvent(event, rAbility, game);
}
if (caught) { // Event was completely replaced -> stop applying effects to it

View file

@ -1,5 +1,6 @@
package mage.actions;
import java.util.ArrayList;
import mage.Constants;
import mage.actions.impl.MageAction;
import mage.actions.score.ArtificialScoringSystem;
@ -9,6 +10,7 @@ import mage.game.events.GameEvent;
import mage.players.Player;
import java.util.List;
import java.util.UUID;
/**
* Action for drawing cards.
@ -19,13 +21,15 @@ public class MageDrawAction extends MageAction {
private final Player player;
private final int amount;
private ArrayList<UUID> appliedEffects;
private List<Card> drawnCards;
private static final int NEGATIVE_VALUE = -1000000;
public MageDrawAction(Player player, int amount) {
public MageDrawAction(Player player, int amount, ArrayList<UUID> appliedEffects) {
this.player = player;
this.amount = amount;
this.appliedEffects = appliedEffects;
}
/**
@ -39,13 +43,15 @@ public class MageDrawAction extends MageAction {
int score = 0;
for (int i = 0; i < amount; i++) {
int value = drawCard(game);
if (value == -1) {
break;
if (value == NEGATIVE_VALUE) {
continue;
}
numDrawn++;
score += value;
}
if (numDrawn > 0) {
game.fireInformEvent(player.getName() + " draws " + Integer.toString(numDrawn) + " card" + (numDrawn > 1 ? "s" : ""));
}
if (player.isEmptyDraw()) {
game.doAction(new MageLoseGameAction(player, MageLoseGameAction.DRAW_REASON));
}
@ -64,7 +70,9 @@ public class MageDrawAction extends MageAction {
* @return
*/
protected int drawCard(Game game) {
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), player.getId()))) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), player.getId());
event.setAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) {
Card card = player.getLibrary().removeFromTop(game);
if (card != null) {
card.moveToZone(Constants.Zone.HAND, null, game, false);

View file

@ -165,6 +165,7 @@ public interface Player extends MageItem, Copyable<Player> {
void reset();
void shuffleLibrary(Game game);
int drawCards(int num, Game game);
int drawCards(int num, Game game, ArrayList<UUID> appliedEffects);
boolean cast(SpellAbility ability, Game game, boolean noMana);
boolean putInHand(Card card, Game game);
boolean removeFromHand(Card card, Game game);

View file

@ -380,7 +380,12 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
@Override
public int drawCards(int num, Game game) {
return game.doAction(new MageDrawAction(this, num));
return game.doAction(new MageDrawAction(this, num, null));
}
@Override
public int drawCards(int num, Game game, ArrayList<UUID> appliedEffects) {
return game.doAction(new MageDrawAction(this, num, appliedEffects));
}
@Override