* Moved some logic in a framework class. Fixed some problems of Whirlpool creatures.

This commit is contained in:
LevelX2 2015-12-02 16:55:09 +01:00
parent 82d9d12276
commit eb1c738b37
4 changed files with 91 additions and 150 deletions

View file

@ -29,20 +29,13 @@ package mage.sets.apocalypse;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesTriggeredAbility;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.ShuffleHandIntoLibraryDrawThatManySourceEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
@ -61,10 +54,10 @@ public class WhirlpoolDrake extends CardImpl {
// Flying
this.addAbility(FlyingAbility.getInstance());
// When Whirlpool Drake enters the battlefield, shuffle the cards from your hand into your library, then draw that many cards.
this.addAbility(new EntersBattlefieldTriggeredAbility(new WhirlpoolSDrakeTriggeredEffect(), false));
this.addAbility(new EntersBattlefieldTriggeredAbility(new ShuffleHandIntoLibraryDrawThatManySourceEffect(), false));
// When Whirlpool Drake dies, shuffle the cards from your hand into your library, then draw that many cards.
this.addAbility(new DiesTriggeredAbility(new WhirlpoolSDrakeTriggeredEffect(), false));
this.addAbility(new DiesTriggeredAbility(new ShuffleHandIntoLibraryDrawThatManySourceEffect(), false));
}
public WhirlpoolDrake(final WhirlpoolDrake card) {
@ -76,40 +69,3 @@ public class WhirlpoolDrake extends CardImpl {
return new WhirlpoolDrake(this);
}
}
class WhirlpoolSDrakeTriggeredEffect extends OneShotEffect {
public WhirlpoolSDrakeTriggeredEffect() {
super(Outcome.DrawCard);
this.staticText = "shuffle the cards from your hand into your library, then draw that many cards";
}
public WhirlpoolSDrakeTriggeredEffect(final WhirlpoolSDrakeTriggeredEffect effect) {
super(effect);
}
@Override
public WhirlpoolSDrakeTriggeredEffect copy() {
return new WhirlpoolSDrakeTriggeredEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int cardsHand = controller.getHand().size();
if (cardsHand > 0){
for (Card card: controller.getHand().getCards(game)) {
if (card != null) {
controller.removeFromHand(card, game);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
}
controller.shuffleLibrary(game);
controller.drawCards(cardsHand, game);
}
return true;
}
return false;
}
}

View file

@ -29,18 +29,11 @@ package mage.sets.apocalypse;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.ShuffleHandIntoLibraryDrawThatManySourceEffect;
import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
@ -57,7 +50,7 @@ public class WhirlpoolRider extends CardImpl {
this.toughness = new MageInt(1);
// When Whirlpool Rider enters the battlefield, shuffle the cards from your hand into your library, then draw that many cards.
this.addAbility(new EntersBattlefieldTriggeredAbility(new WhirlpoolRiderTriggeredEffect()));
this.addAbility(new EntersBattlefieldTriggeredAbility(new ShuffleHandIntoLibraryDrawThatManySourceEffect()));
}
@ -70,40 +63,3 @@ public class WhirlpoolRider extends CardImpl {
return new WhirlpoolRider(this);
}
}
class WhirlpoolRiderTriggeredEffect extends OneShotEffect {
public WhirlpoolRiderTriggeredEffect() {
super(Outcome.DrawCard);
this.staticText = "shuffle the cards from your hand into your library, then draw that many cards";
}
public WhirlpoolRiderTriggeredEffect(final WhirlpoolRiderTriggeredEffect effect) {
super(effect);
}
@Override
public WhirlpoolRiderTriggeredEffect copy() {
return new WhirlpoolRiderTriggeredEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int cardsHand = controller.getHand().size();
if (cardsHand > 0) {
for (Card card: controller.getHand().getCards(game)) {
if (card != null) {
controller.moveCardToLibraryWithInfo(card, source.getSourceId(), game, Zone.HAND, true, false);
}
}
controller.shuffleLibrary(game);
controller.drawCards(cardsHand, game);
}
return true;
}
return false;
}
}

View file

@ -29,6 +29,7 @@ package mage.sets.planechase2012;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
@ -37,7 +38,7 @@ import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.SacrificeSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.abilities.effects.common.ShuffleHandIntoLibraryDrawThatManySourceEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Outcome;
@ -62,7 +63,7 @@ public class WhirlpoolWarrior extends CardImpl {
this.toughness = new MageInt(2);
// When Whirlpool Warrior enters the battlefield, shuffle the cards from your hand into your library, then draw that many cards.
this.addAbility(new EntersBattlefieldTriggeredAbility(new WhirlpoolWarriorTriggeredEffect()));
this.addAbility(new EntersBattlefieldTriggeredAbility(new ShuffleHandIntoLibraryDrawThatManySourceEffect()));
// {R}, Sacrifice Whirlpool Warrior: Each player shuffles the cards from his or her hand into his or her library, then draws that many cards.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new WhirlpoolWarriorActivatedEffect(), new ManaCostsImpl("{R}"));
@ -80,51 +81,6 @@ public class WhirlpoolWarrior extends CardImpl {
}
}
class WhirlpoolWarriorTriggeredEffect extends OneShotEffect {
public WhirlpoolWarriorTriggeredEffect() {
super(Outcome.DrawCard);
this.staticText = "shuffle the cards from your hand into your library, then draw that many cards";
}
public WhirlpoolWarriorTriggeredEffect(final WhirlpoolWarriorTriggeredEffect effect) {
super(effect);
}
@Override
public WhirlpoolWarriorTriggeredEffect copy() {
return new WhirlpoolWarriorTriggeredEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, Integer> cardsToDraw = new LinkedHashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int cardsInHand = player.getHand().size();
if (cardsInHand > 0) {
cardsToDraw.put(playerId, cardsInHand);
}
player.moveCards(player.getHand(), Zone.HAND, Zone.LIBRARY, source, game);
player.shuffleLibrary(game);
}
}
for (UUID playerId : cardsToDraw.keySet()) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.drawCards(cardsToDraw.get(playerId), game);
}
}
return true;
}
return false;
}
}
class WhirlpoolWarriorActivatedEffect extends OneShotEffect {
public WhirlpoolWarriorActivatedEffect() {
@ -145,23 +101,24 @@ class WhirlpoolWarriorActivatedEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : controller.getInRange()) {
Map<UUID, Integer> playerCards = new LinkedHashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int cardsHand = player.getHand().size();
if (cardsHand > 0) {
for (Card card : player.getHand().getCards(game)) {
if (card != null) {
player.removeFromHand(card, game);
card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, true);
}
}
game.informPlayers(player.getLogName() + " shuffles the cards from his or her hand into his or her library");
playerCards.put(playerId, cardsHand);
player.moveCards(player.getHand(), Zone.LIBRARY, source, game);
player.shuffleLibrary(game);
player.drawCards(cardsHand, game);
}
}
}
for (Entry<UUID, Integer> entry : playerCards.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
player.drawCards(entry.getValue(), game);
}
}
return true;
}
return false;

View file

@ -0,0 +1,72 @@
/*
* 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.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class ShuffleHandIntoLibraryDrawThatManySourceEffect extends OneShotEffect {
public ShuffleHandIntoLibraryDrawThatManySourceEffect() {
super(Outcome.DrawCard);
this.staticText = "shuffle the cards from your hand into your library, then draw that many cards";
}
public ShuffleHandIntoLibraryDrawThatManySourceEffect(final ShuffleHandIntoLibraryDrawThatManySourceEffect effect) {
super(effect);
}
@Override
public ShuffleHandIntoLibraryDrawThatManySourceEffect copy() {
return new ShuffleHandIntoLibraryDrawThatManySourceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int cardsHand = controller.getHand().size();
if (cardsHand > 0) {
controller.moveCards(controller.getHand(), Zone.LIBRARY, source, game);
controller.shuffleLibrary(game);
game.applyEffects(); // then
controller.drawCards(cardsHand, game);
}
return true;
}
return false;
}
}