From 03b5aea22999afa381d81355b68f0313b1e638e4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 18 Jun 2013 08:33:27 +0200 Subject: [PATCH] Added DrawDiscardTargetEffect, improved DrawDiscardControllerEffect. --- .../common/DrawDiscardControllerEffect.java | 25 +++++- .../common/DrawDiscardTargetEffect.java | 85 +++++++++++++++++++ 2 files changed, 106 insertions(+), 4 deletions(-) create mode 100644 Mage/src/mage/abilities/effects/common/DrawDiscardTargetEffect.java diff --git a/Mage/src/mage/abilities/effects/common/DrawDiscardControllerEffect.java b/Mage/src/mage/abilities/effects/common/DrawDiscardControllerEffect.java index c37d692d13e..251843ae5c3 100644 --- a/Mage/src/mage/abilities/effects/common/DrawDiscardControllerEffect.java +++ b/Mage/src/mage/abilities/effects/common/DrawDiscardControllerEffect.java @@ -28,11 +28,12 @@ package mage.abilities.effects.common; -import mage.constants.Outcome; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; +import mage.constants.Outcome; import mage.game.Game; import mage.players.Player; +import mage.util.CardUtil; /** * @@ -40,13 +41,29 @@ import mage.players.Player; */ public class DrawDiscardControllerEffect extends OneShotEffect { + private int cardsToDraw; + private int cardsToDiscard; + public DrawDiscardControllerEffect() { + this(1,1); + } + + public DrawDiscardControllerEffect(int cardsToDraw, int cardsToDiscard) { super(Outcome.DrawCard); - staticText = "Draw a card, then discard a card"; + this.cardsToDraw = cardsToDraw; + this.cardsToDiscard = cardsToDiscard; + staticText = new StringBuilder("Draw ") + .append(cardsToDraw == 1?"a": CardUtil.numberToText(cardsToDraw)) + .append(" card").append(cardsToDraw == 1?" ": "s") + .append(", then discard ") + .append(cardsToDiscard == 1?"a": CardUtil.numberToText(cardsToDiscard)) + .append(" card").append(cardsToDiscard == 1?" ": "s").toString(); } public DrawDiscardControllerEffect(final DrawDiscardControllerEffect effect) { super(effect); + this.cardsToDraw = effect.cardsToDraw; + this.cardsToDiscard = effect.cardsToDiscard; } @Override @@ -58,8 +75,8 @@ public class DrawDiscardControllerEffect extends OneShotEffect { + + private int cardsToDraw; + private int cardsToDiscard; + + public DrawDiscardTargetEffect() { + this(1,1); + } + + public DrawDiscardTargetEffect(int cardsToDraw, int cardsToDiscard) { + super(Outcome.DrawCard); + this.cardsToDraw = cardsToDraw; + this.cardsToDiscard = cardsToDiscard; + staticText = new StringBuilder("Target player draws ") + .append(cardsToDraw == 1?"a": CardUtil.numberToText(cardsToDraw)) + .append(" card").append(cardsToDraw == 1?" ": "s") + .append(", then discard ") + .append(cardsToDiscard == 1?"a": CardUtil.numberToText(cardsToDiscard)) + .append(" card").append(cardsToDiscard == 1?" ": "s").toString(); + } + + public DrawDiscardTargetEffect(final DrawDiscardTargetEffect effect) { + super(effect); + this.cardsToDraw = effect.cardsToDraw; + this.cardsToDiscard = effect.cardsToDiscard; + } + + @Override + public DrawDiscardTargetEffect copy() { + return new DrawDiscardTargetEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(getTargetPointer().getFirst(game, source)); + if (player != null) { + player.drawCards(cardsToDraw, game); + player.discard(cardsToDiscard, source, game); + return true; + } + return false; + } + +}