mirror of
https://github.com/correl/mage.git
synced 2024-12-25 03:00:15 +00:00
Merge pull request #5532 from magefree/coinFlips
Added support for multiple copies of Krark's Thumb
This commit is contained in:
commit
908d8acc9f
4 changed files with 75 additions and 60 deletions
|
@ -6,13 +6,13 @@ import mage.abilities.common.SimpleStaticAbility;
|
|||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.*;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SuperType;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.FlipCoinEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.players.Player;
|
||||
import mage.util.CardUtil;
|
||||
import mage.util.RandomUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
@ -26,7 +26,7 @@ public final class KrarksThumb extends CardImpl {
|
|||
addSuperType(SuperType.LEGENDARY);
|
||||
|
||||
// If you would flip a coin, instead flip two coins and ignore one.
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new KrarksThumbEffect()));
|
||||
this.addAbility(new SimpleStaticAbility(new KrarksThumbEffect()));
|
||||
}
|
||||
|
||||
private KrarksThumb(final KrarksThumb card) {
|
||||
|
@ -43,33 +43,22 @@ class KrarksThumbEffect extends ReplacementEffectImpl {
|
|||
|
||||
KrarksThumbEffect() {
|
||||
super(Duration.WhileOnBattlefield, Outcome.Benefit);
|
||||
staticText = "If you would flip a coin, instead flip two coins and ignore one";
|
||||
staticText = "If you would flip a coin, instead flip two coins and ignore one.";
|
||||
}
|
||||
|
||||
private KrarksThumbEffect(final KrarksThumbEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public KrarksThumbEffect copy() {
|
||||
return new KrarksThumbEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
Player player = game.getPlayer(event.getPlayerId());
|
||||
if (player == null || !player.getId().equals(source.getControllerId())) {
|
||||
return false;
|
||||
}
|
||||
FlipCoinEvent flipEvent = (FlipCoinEvent) event;
|
||||
boolean secondFlip = RandomUtil.nextBoolean();
|
||||
game.informPlayers(player.getLogName() + " flipped a " + flipEvent.getResultName()
|
||||
+ " and a " + CardUtil.booleanToFlipName(secondFlip)
|
||||
);
|
||||
boolean chosenFlip = player.chooseUse(
|
||||
Outcome.Benefit, "Choose which coin you want",
|
||||
(flipEvent.isWinnable() ? "(You chose " + flipEvent.getChosenName() + ")" : null),
|
||||
flipEvent.getResultName(), CardUtil.booleanToFlipName(secondFlip), source, game
|
||||
);
|
||||
if (!chosenFlip) {
|
||||
flipEvent.setResult(secondFlip);
|
||||
}
|
||||
game.informPlayers(player.getLogName() + " chooses to keep " + flipEvent.getResultName());
|
||||
FlipCoinEvent flipCoinEvent = (FlipCoinEvent) event;
|
||||
flipCoinEvent.setFlipCount(2 * flipCoinEvent.getFlipCount());
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -87,9 +76,4 @@ class KrarksThumbEffect extends ReplacementEffectImpl {
|
|||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public KrarksThumbEffect copy() {
|
||||
return new KrarksThumbEffect(this);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ public class FlipCoinEvent extends GameEvent {
|
|||
private boolean result;
|
||||
private final boolean chosen;
|
||||
private final boolean winnable;
|
||||
private int flipCount = 1;
|
||||
|
||||
public FlipCoinEvent(UUID playerId, UUID sourceId, boolean result, boolean chosen, boolean winnable) {
|
||||
super(EventType.FLIP_COIN, playerId, sourceId, playerId);
|
||||
|
@ -43,6 +44,14 @@ public class FlipCoinEvent extends GameEvent {
|
|||
return winnable;
|
||||
}
|
||||
|
||||
public int getFlipCount() {
|
||||
return flipCount;
|
||||
}
|
||||
|
||||
public void setFlipCount(int flipCount) {
|
||||
this.flipCount = flipCount;
|
||||
}
|
||||
|
||||
public CoinFlippedEvent getFlippedEvent() {
|
||||
return new CoinFlippedEvent(playerId, sourceId, result, chosen, winnable);
|
||||
}
|
||||
|
|
|
@ -74,7 +74,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
void setLife(int life, Game game, UUID sourceId);
|
||||
|
||||
/**
|
||||
* @param amount amount of life loss
|
||||
* @param amount amount of life loss
|
||||
* @param game
|
||||
* @param atCombat was the source combat damage
|
||||
* @return
|
||||
|
@ -347,7 +347,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
* @param target
|
||||
* @param game
|
||||
* @param targetPlayerId player whose library will be searched
|
||||
* @param triggerEvents whether searching will trigger any game events
|
||||
* @param triggerEvents whether searching will trigger any game events
|
||||
* @return true if search was successful
|
||||
*/
|
||||
boolean searchLibrary(TargetCardInLibrary target, Game game, UUID targetPlayerId, boolean triggerEvents);
|
||||
|
@ -355,6 +355,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Reveals all players' libraries. Useful for abilities like Jace, Architect of Thought's -8
|
||||
* that have effects that require information from all libraries.
|
||||
*
|
||||
* @param source
|
||||
* @param game
|
||||
* @return
|
||||
|
@ -366,23 +367,23 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Plays a card if possible
|
||||
*
|
||||
* @param card the card that can be cast
|
||||
* @param card the card that can be cast
|
||||
* @param game
|
||||
* @param noMana if it's a spell i can be cast without paying mana
|
||||
* @param noMana if it's a spell i can be cast without paying mana
|
||||
* @param ignoreTiming if it's cast during the resolution of another spell
|
||||
* no sorcery or play land timing restriction are checked. For a land it has
|
||||
* to be the turn of the player playing that card.
|
||||
* @param reference mage object that allows to play the card
|
||||
* no sorcery or play land timing restriction are checked. For a land it has
|
||||
* to be the turn of the player playing that card.
|
||||
* @param reference mage object that allows to play the card
|
||||
* @return
|
||||
*/
|
||||
boolean playCard(Card card, Game game, boolean noMana, boolean ignoreTiming, MageObjectReference reference);
|
||||
|
||||
/**
|
||||
* @param card the land card to play
|
||||
* @param card the land card to play
|
||||
* @param game
|
||||
* @param ignoreTiming false - it won't be checked if the stack is empty and
|
||||
* you are able to play a Sorcery. It's still checked, if you are able to
|
||||
* play a land concerning the number of lands you already played.
|
||||
* you are able to play a Sorcery. It's still checked, if you are able to
|
||||
* play a land concerning the number of lands you already played.
|
||||
* @return
|
||||
*/
|
||||
boolean playLand(Card card, Game game, boolean ignoreTiming);
|
||||
|
@ -528,11 +529,11 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Moves the cards from cards to the bottom of the players library.
|
||||
*
|
||||
* @param cards - list of cards that have to be moved
|
||||
* @param game - game
|
||||
* @param cards - list of cards that have to be moved
|
||||
* @param game - game
|
||||
* @param anyOrder - true if player can determine the order of the cards
|
||||
* else random order
|
||||
* @param source - source ability
|
||||
* else random order
|
||||
* @param source - source ability
|
||||
* @return
|
||||
*/
|
||||
boolean putCardsOnBottomOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder);
|
||||
|
@ -553,10 +554,10 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Moves the cards from cards to the top of players library.
|
||||
*
|
||||
* @param cards - list of cards that have to be moved
|
||||
* @param game - game
|
||||
* @param cards - list of cards that have to be moved
|
||||
* @param game - game
|
||||
* @param anyOrder - true if player can determine the order of the cards
|
||||
* @param source - source ability
|
||||
* @param source - source ability
|
||||
* @return
|
||||
*/
|
||||
boolean putCardsOnTopOfLibrary(Cards cards, Game game, Ability source, boolean anyOrder);
|
||||
|
@ -582,8 +583,8 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
/**
|
||||
* Choose the order in which blockers get damage assigned to
|
||||
*
|
||||
* @param blockers list of blockers where to choose the next one from
|
||||
* @param combatGroup the concerning combat group
|
||||
* @param blockers list of blockers where to choose the next one from
|
||||
* @param combatGroup the concerning combat group
|
||||
* @param blockerOrder the already set order of blockers
|
||||
* @param game
|
||||
* @return blocker next to add to the blocker order
|
||||
|
@ -722,11 +723,11 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
* @param toZone
|
||||
* @param source
|
||||
* @param game
|
||||
* @param tapped the cards are tapped on the battlefield
|
||||
* @param faceDown the cards are face down in the to zone
|
||||
* @param byOwner the card is moved (or put onto battlefield) by the owner
|
||||
* of the card and if target zone is battlefield controls the permanent
|
||||
* (instead of the controller of the source)
|
||||
* @param tapped the cards are tapped on the battlefield
|
||||
* @param faceDown the cards are face down in the to zone
|
||||
* @param byOwner the card is moved (or put onto battlefield) by the owner
|
||||
* of the card and if target zone is battlefield controls the permanent
|
||||
* (instead of the controller of the source)
|
||||
* @param appliedEffects
|
||||
* @return
|
||||
*/
|
||||
|
@ -762,7 +763,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
* list of applied effects is not saved
|
||||
*
|
||||
* @param card
|
||||
* @param exileId exile zone id (optional)
|
||||
* @param exileId exile zone id (optional)
|
||||
* @param exileName name of exile zone (optional)
|
||||
* @param sourceId
|
||||
* @param game
|
||||
|
@ -804,7 +805,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
* @param sourceId
|
||||
* @param game
|
||||
* @param fromZone if null, this info isn't postet
|
||||
* @param toTop to the top of the library else to the bottom
|
||||
* @param toTop to the top of the library else to the bottom
|
||||
* @param withName show the card name in the log
|
||||
* @return
|
||||
*/
|
||||
|
@ -829,10 +830,10 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
* without mana (null) or the mana set to manaCosts instead of its normal
|
||||
* mana costs.
|
||||
*
|
||||
* @param sourceId the source that can be cast without mana
|
||||
* @param sourceId the source that can be cast without mana
|
||||
* @param manaCosts alternate ManaCost, null if it can be cast without mana
|
||||
* cost
|
||||
* @param costs alternate other costs you need to pay
|
||||
* cost
|
||||
* @param costs alternate other costs you need to pay
|
||||
*/
|
||||
void setCastSourceIdWithAlternateMana(UUID sourceId, ManaCosts<ManaCost> manaCosts, Costs<Cost> costs);
|
||||
|
||||
|
|
|
@ -2573,13 +2573,34 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
boolean chosen = false;
|
||||
if (winnable) {
|
||||
chosen = this.chooseUse(Outcome.Benefit, "Heads or tails?", "", "Heads", "Tails", source, game);
|
||||
game.informPlayers(getLogName() + " chose " + (chosen ? "heads." : "tails."));
|
||||
game.informPlayers(getLogName() + " chose " + CardUtil.booleanToFlipName(chosen));
|
||||
}
|
||||
boolean result = RandomUtil.nextBoolean();
|
||||
FlipCoinEvent event = new FlipCoinEvent(playerId, source.getSourceId(), result, chosen, winnable);
|
||||
event.addAppliedEffects(appliedEffects);
|
||||
game.replaceEvent(event);
|
||||
game.informPlayers(getLogName() + " got " + (event.getResult() ? "heads" : "tails"));
|
||||
game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(event.getResult()));
|
||||
if (event.getFlipCount() > 1) {
|
||||
boolean canChooseHeads = event.getResult();
|
||||
boolean canChooseTails = !event.getResult();
|
||||
for (int i = 1; i < event.getFlipCount(); i++) {
|
||||
boolean tempFlip = RandomUtil.nextBoolean();
|
||||
canChooseHeads = canChooseHeads || tempFlip;
|
||||
canChooseTails = canChooseTails || !tempFlip;
|
||||
game.informPlayers(getLogName() + " flipped " + CardUtil.booleanToFlipName(tempFlip));
|
||||
}
|
||||
if (canChooseHeads && canChooseTails) {
|
||||
event.setResult(chooseUse(Outcome.Benefit, "Choose which flip to keep",
|
||||
(event.isWinnable() ? "(You called " + event.getChosenName() + ")" : null),
|
||||
"Heads", "Tails", source, game
|
||||
));
|
||||
} else if (canChooseHeads) {
|
||||
event.setResult(true);
|
||||
} else {
|
||||
event.setResult(false);
|
||||
}
|
||||
game.informPlayers(getLogName() + " chose to keep " + CardUtil.booleanToFlipName(event.getResult()));
|
||||
}
|
||||
if (event.isWinnable()) {
|
||||
game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue