Updated implementation of Unpredictable Cyclone (#6423)

* updated implementation of Unpredictable Cyclone, refactored drawCard method

* fixed another small implementation error

* added test for Unpredictable Cyclone

* updated Unpredictable Cyclone test
This commit is contained in:
Evan Kranzler 2020-04-16 08:04:21 -04:00 committed by GitHub
parent 80b7f8493b
commit 378dfbf89a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
279 changed files with 465 additions and 378 deletions

View file

@ -29,7 +29,7 @@ public class BrainstormEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
player.drawCards(3, game);
player.drawCards(3, source.getSourceId(), game);
putOnLibrary(player, source, game);
putOnLibrary(player, source, game);
return true;

View file

@ -59,7 +59,7 @@ public class DrawCardAllEffect extends OneShotEffect {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.drawCards(amount.calculate(game, source, this), game);
player.drawCards(amount.calculate(game, source, this), source.getSourceId(), game);
}
}
break;
@ -67,7 +67,7 @@ public class DrawCardAllEffect extends OneShotEffect {
for (UUID playerId : game.getOpponents(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.drawCards(amount.calculate(game, source, this), game);
player.drawCards(amount.calculate(game, source, this), source.getSourceId(), game);
}
}
break;

View file

@ -54,7 +54,7 @@ public class DrawCardSourceControllerEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
if (player != null
&& player.canRespond()) {
player.drawCards(amount.calculate(game, source, this), game);
player.drawCards(amount.calculate(game, source, this), source.getSourceId(), game);
return true;
}
return false;

View file

@ -70,7 +70,7 @@ public class DrawCardTargetEffect extends OneShotEffect {
}
if (!optional
|| player.chooseUse(outcome, "Use draw effect?", source, game)) {
player.drawCards(cardsToDraw, game);
player.drawCards(cardsToDraw, source.getSourceId(), game);
}
}
}

View file

@ -58,7 +58,7 @@ public class DrawDiscardControllerEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
if (!optional || player.chooseUse(outcome, "Use draw, then discard effect?", source, game)) {
player.drawCards(cardsToDraw, game);
player.drawCards(cardsToDraw, source.getSourceId(), game);
player.discard(cardsToDiscard, false, source, game);
}
return true;

View file

@ -46,7 +46,7 @@ public class DrawDiscardOneOfThemEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Cards initialHand = controller.getHand().copy();
controller.drawCards(cardsToDraw, game);
controller.drawCards(cardsToDraw, source.getSourceId(), game);
Cards drawnCards = new CardsImpl(controller.getHand().copy());
drawnCards.removeAll(initialHand);
if (!drawnCards.isEmpty()) {

View file

@ -49,7 +49,7 @@ public class DrawDiscardTargetEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(getTargetPointer().getFirst(game, source));
if (player != null) {
player.drawCards(cardsToDraw, game);
player.drawCards(cardsToDraw, source.getSourceId(), game);
player.discard(cardsToDiscard, false, source, game);
return true;
}

View file

@ -37,7 +37,7 @@ public class ShuffleHandIntoLibraryDrawThatManySourceEffect extends OneShotEffec
controller.moveCards(controller.getHand(), Zone.LIBRARY, source, game);
controller.shuffleLibrary(source, game);
game.applyEffects(); // then
controller.drawCards(cardsHand, game);
controller.drawCards(cardsHand, source.getSourceId(), game);
}
return true;
}

View file

@ -28,7 +28,7 @@ public class DiscardHandDrawSameNumberSourceEffect extends OneShotEffect {
if (player != null) {
int amount = player.getHand().getCards(game).size();
player.discard(amount, false, source, game);
player.drawCards(amount, game);
player.drawCards(amount, source.getSourceId(), game);
return true;
}
return false;

View file

@ -1,18 +1,13 @@
package mage.abilities.keyword;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbilityImpl;
import mage.abilities.costs.Cost;
import mage.abilities.costs.common.CyclingDiscardCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DrawCardSourceControllerEffect;
import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.players.Player;
import mage.target.common.TargetCardInLibrary;
/**
@ -24,7 +19,7 @@ public class CyclingAbility extends ActivatedAbilityImpl {
private final String text;
public CyclingAbility(Cost cost) {
super(Zone.HAND, new CyclingDrawEffect(), cost);
super(Zone.HAND, new DrawCardSourceControllerEffect(1), cost);
this.addCost(new CyclingDiscardCost());
this.cost = cost;
this.text = "Cycling";
@ -60,37 +55,3 @@ public class CyclingAbility extends ActivatedAbilityImpl {
return rule.toString();
}
}
class CyclingDrawEffect extends OneShotEffect {
CyclingDrawEffect() {
super(Outcome.Benefit);
staticText = "draw a card";
}
private CyclingDrawEffect(final CyclingDrawEffect effect) {
super(effect);
}
@Override
public CyclingDrawEffect copy() {
return new CyclingDrawEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getSourceId());
if (player == null) {
return false;
}
GameEvent event = GameEvent.getEvent(
GameEvent.EventType.CYCLE_DRAW, source.getSourceId(),
source.getSourceId(), source.getControllerId()
);
if (game.replaceEvent(event)) {
return true;
}
player.drawCards(1, game);
return true;
}
}

View file

@ -1,8 +1,5 @@
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;
@ -12,6 +9,10 @@ import mage.game.events.GameEvent;
import mage.players.Player;
import mage.util.CardUtil;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/**
* Action for drawing cards.
*
@ -37,11 +38,12 @@ public class MageDrawAction extends MageAction {
/**
* Draw and set action score.
*
* @param game Game context.
* @param sourceId
* @param game Game context.
* @return
*/
@Override
public int doAction(Game game) {
public int doAction(UUID sourceId, Game game) {
int numDrawn = 0;
int score = 0;
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARDS, player.getId(), null, player.getId(), null, amount);
@ -49,7 +51,7 @@ public class MageDrawAction extends MageAction {
if (amount < 2 || !game.replaceEvent(event)) {
amount = event.getAmount();
for (int i = 0; i < amount; i++) {
int value = drawCard(game);
int value = drawCard(sourceId, game);
if (value == NEGATIVE_VALUE) {
continue;
}
@ -62,7 +64,7 @@ public class MageDrawAction extends MageAction {
if (player.isEmptyDraw()) {
event = GameEvent.getEvent(GameEvent.EventType.EMPTY_DRAW, player.getId(), player.getId());
if (!game.replaceEvent(event)) {
game.doAction(new MageLoseGameAction(player, MageLoseGameAction.DRAW_REASON));
game.doAction(new MageLoseGameAction(player, MageLoseGameAction.DRAW_REASON), sourceId);
}
}
@ -76,11 +78,12 @@ 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.
*
* @param sourceId
* @param game
* @return
*/
protected int drawCard(Game game) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), player.getId());
protected int drawCard(UUID sourceId, Game game) {
GameEvent event = GameEvent.getEvent(GameEvent.EventType.DRAW_CARD, player.getId(), sourceId, player.getId());
event.addAppliedEffects(appliedEffects);
if (!game.replaceEvent(event)) {
Card card = player.getLibrary().removeFromTop(game);

View file

@ -5,6 +5,8 @@ import mage.actions.score.ArtificialScoringSystem;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* Lose game action.
*
@ -26,7 +28,7 @@ public class MageLoseGameAction extends MageAction {
}
@Override
public int doAction(final Game game) {
public int doAction(UUID sourceId, final Game game) {
oldLosingPlayer = game.getLosingPlayer();
if (oldLosingPlayer == null && player.canLose(game)) {
setScore(player, ArtificialScoringSystem.inst.getLoseGameScore(game));

View file

@ -3,6 +3,8 @@ package mage.actions.impl;
import mage.game.Game;
import mage.players.Player;
import java.util.UUID;
/**
* Base class for mage actions.
*
@ -52,10 +54,12 @@ public abstract class MageAction {
/**
* Execute action.
*
*
* @param sourceId
* @param game Game context.
* @return
*/
public abstract int doAction(final Game game);
public abstract int doAction(UUID sourceId, final Game game);
/**
* Undo action.

View file

@ -408,7 +408,7 @@ public interface Game extends MageItem, Serializable {
boolean endTurn(Ability source);
int doAction(MageAction action);
int doAction(MageAction action, UUID sourceId);
//game transaction methods
void saveState(boolean bookmark);

View file

@ -1026,7 +1026,7 @@ public abstract class GameImpl implements Game, Serializable {
player.initLife(this.getLife());
}
if (!gameOptions.testMode) {
player.drawCards(startingHandSize, this);
player.drawCards(startingHandSize, null, this);
}
}
@ -3021,9 +3021,9 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public int doAction(MageAction action) {
public int doAction(MageAction action, UUID sourceId) {
//actions.add(action);
int value = action.doAction(this);
int value = action.doAction(sourceId, this);
// score += action.getScore(scorePlayer);
return value;
}

View file

@ -93,7 +93,7 @@ class DrawCardsActivePlayerEffect extends OneShotEffect {
}
Player player = game.getPlayer(game.getActivePlayerId());
if (player != null) {
player.drawCards(amount.calculate(game, source, this), game);
player.drawCards(amount.calculate(game, source, this), source.getSourceId(), game);
return true;
}
return false;

View file

@ -118,7 +118,7 @@ public class CanadianHighlanderMulligan extends VancouverMulligan {
.append(" mulligans to ")
.append(Integer.toString(numToMulliganTo))
.append(numToMulliganTo == 1 ? " card" : " cards").toString());
player.drawCards(numToMulliganTo, game);
player.drawCards(numToMulliganTo, null, game);
}
}

View file

@ -103,7 +103,7 @@ public class LondonMulligan extends Mulligan {
.append(newHandSize)
.append(newHandSize == 1 ? " card" : " cards").toString());
}
player.drawCards(numCards, game);
player.drawCards(numCards, null, game);
if (player.getHand().size() > newHandSize) {
int cardsToDiscard = player.getHand().size() - newHandSize;

View file

@ -53,7 +53,7 @@ public class ParisMulligan extends Mulligan {
.append(deduction == 0 ? " for free and draws " : " down to ")
.append((numCards - deduction))
.append(numCards - deduction == 1 ? " card" : " cards").toString());
player.drawCards(numCards - deduction, game);
player.drawCards(numCards - deduction, null, game);
}
@Override

View file

@ -1,15 +1,13 @@
package mage.game.turn;
import java.util.UUID;
import mage.constants.PhaseStep;
import mage.game.Game;
import mage.game.events.GameEvent.EventType;
import mage.players.Player;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class DrawStep extends Step {
@ -29,7 +27,7 @@ public class DrawStep extends Step {
public void beginStep(Game game, UUID activePlayerId) {
Player activePlayer = game.getPlayer(activePlayerId);
//20091005 - 504.1/703.4c
activePlayer.drawCards(1, game);
activePlayer.drawCards(1, null, game);
// game.saveState();
game.applyEffects();
super.beginStep(game, activePlayerId);

View file

@ -311,9 +311,9 @@ public interface Player extends MageItem, Copyable<Player> {
void shuffleLibrary(Ability source, Game game);
int drawCards(int num, Game game);
int drawCards(int num, UUID sourceId, Game game);
int drawCards(int num, Game game, List<UUID> appliedEffects);
int drawCards(int num, UUID sourceId, Game game, List<UUID> appliedEffects);
boolean cast(SpellAbility ability, Game game, boolean noMana, MageObjectReference reference);

View file

@ -673,16 +673,16 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public int drawCards(int num, Game game) {
public int drawCards(int num, UUID sourceId, Game game) {
if (num > 0) {
return game.doAction(new MageDrawAction(this, num, null));
return game.doAction(new MageDrawAction(this, num, null), sourceId);
}
return 0;
}
@Override
public int drawCards(int num, Game game, List<UUID> appliedEffects) {
return game.doAction(new MageDrawAction(this, num, appliedEffects));
public int drawCards(int num, UUID sourceId, Game game, List<UUID> appliedEffects) {
return game.doAction(new MageDrawAction(this, num, appliedEffects), sourceId);
}
@Override