Minor changes to the framework.

This commit is contained in:
LevelX2 2014-01-21 17:18:44 +01:00
parent 00b03c91b6
commit a5063ef9ee
4 changed files with 171 additions and 5 deletions

View file

@ -0,0 +1,81 @@
/*
* 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.abilities.dynamicvalue.common;
import java.io.ObjectStreamException;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class SourcePermanentToughnessValue implements DynamicValue {
private static final SourcePermanentToughnessValue fINSTANCE = new SourcePermanentToughnessValue();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
public static SourcePermanentToughnessValue getInstance() {
return fINSTANCE;
}
@Override
public int calculate(Game game, Ability sourceAbility) {
Permanent sourcePermanent = game.getPermanent(sourceAbility.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.BATTLEFIELD);
}
if (sourcePermanent != null) {
return sourcePermanent.getToughness().getValue();
}
return 0;
}
@Override
public SourcePermanentToughnessValue copy() {
return new SourcePermanentToughnessValue();
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return "{source}'s toughness";
}
}

View file

@ -0,0 +1,81 @@
/*
* 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.abilities.dynamicvalue.common;
import java.io.ObjectStreamException;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class TargetPermanenToughnessValue implements DynamicValue {
private static final TargetPermanenToughnessValue fINSTANCE = new TargetPermanenToughnessValue();
private Object readResolve() throws ObjectStreamException {
return fINSTANCE;
}
public static TargetPermanenToughnessValue getInstance() {
return fINSTANCE;
}
@Override
public int calculate(Game game, Ability sourceAbility) {
Permanent sourcePermanent = game.getPermanent(sourceAbility.getFirstTarget());
if (sourcePermanent == null) {
sourcePermanent = (Permanent) game.getLastKnownInformation(sourceAbility.getFirstTarget(), Zone.BATTLEFIELD);
}
if (sourcePermanent != null) {
return sourcePermanent.getToughness().getValue();
}
return 0;
}
@Override
public TargetPermanenToughnessValue copy() {
return new TargetPermanenToughnessValue();
}
@Override
public String toString() {
return "X";
}
@Override
public String getMessage() {
return "target creature's toughness";
}
}

View file

@ -109,7 +109,6 @@ public class DiscardEachPlayerEffect extends OneShotEffect<DiscardEachPlayerEffe
player.discard(card, source, game); player.discard(card, source, game);
} }
} }
game.informPlayers(new StringBuilder(player.getName()).append(" discards ").append(Integer.toString(cardsPlayer.size())).append(" card").append(cardsPlayer.size() > 1 ? "s" : "").toString());
} }
} }
} }

View file

@ -30,6 +30,8 @@ package mage.abilities.effects.common;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.constants.Zone; import mage.constants.Zone;
@ -44,9 +46,12 @@ import mage.util.CardUtil;
public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffect<PutTopCardOfTargetPlayerLibraryIntoGraveEffect> { public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffect<PutTopCardOfTargetPlayerLibraryIntoGraveEffect> {
private int numberCards; private DynamicValue numberCards;
public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(int numberCards) { public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(int numberCards) {
this(new StaticValue(numberCards));
}
public PutTopCardOfTargetPlayerLibraryIntoGraveEffect(DynamicValue numberCards) {
super(Outcome.Discard); super(Outcome.Discard);
this.numberCards = numberCards; this.numberCards = numberCards;
this.staticText = setText(); this.staticText = setText();
@ -66,7 +71,7 @@ public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffec
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source)); Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) { if (player != null) {
int cardsCount = Math.min(numberCards, player.getLibrary().size()); int cardsCount = Math.min(numberCards.calculate(game, source), player.getLibrary().size());
for (int i = 0; i < cardsCount; i++) { for (int i = 0; i < cardsCount; i++) {
Card card = player.getLibrary().removeFromTop(game); Card card = player.getLibrary().removeFromTop(game);
if (card != null) { if (card != null) {
@ -80,10 +85,10 @@ public class PutTopCardOfTargetPlayerLibraryIntoGraveEffect extends OneShotEffec
private String setText() { private String setText() {
StringBuilder sb = new StringBuilder("Target player puts the top "); StringBuilder sb = new StringBuilder("Target player puts the top ");
if (numberCards == 1) { if (numberCards.toString().equals("1")) {
sb.append(" card"); sb.append(" card");
} else { } else {
sb.append(CardUtil.numberToText(numberCards)); sb.append(CardUtil.numberToText(numberCards.toString()));
sb.append(" cards"); sb.append(" cards");
} }
sb.append(" of his or her library into his or her graveyard"); sb.append(" of his or her library into his or her graveyard");