mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
rewrote how coins are flipped
This commit is contained in:
parent
f5fffcf417
commit
535fe221e3
64 changed files with 157 additions and 86 deletions
|
|
@ -60,7 +60,7 @@ public class FlipCoinEffect extends OneShotEffect {
|
|||
MageObject mageObject = game.getObject(source.getSourceId());
|
||||
if (controller != null && mageObject != null) {
|
||||
boolean result = true;
|
||||
for (Effect effect : controller.flipCoin(game, true) ? executingEffectsWon : executingEffectsLost) {
|
||||
for (Effect effect : controller.flipCoin(source, game, true) ? executingEffectsWon : executingEffectsLost) {
|
||||
effect.setTargetPointer(this.targetPointer);
|
||||
if (effect instanceof OneShotEffect) {
|
||||
result &= effect.apply(game, source);
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public class FlipUntilLoseEffect extends OneShotEffect {
|
|||
return false;
|
||||
}
|
||||
while (true) {
|
||||
if (!player.flipCoin(game, true)) {
|
||||
if (!player.flipCoin(source, game, true)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
28
Mage/src/main/java/mage/game/events/CoinFlippedEvent.java
Normal file
28
Mage/src/main/java/mage/game/events/CoinFlippedEvent.java
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
package mage.game.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class CoinFlippedEvent extends GameEvent {
|
||||
private final boolean result;
|
||||
private final boolean chosen;
|
||||
private final boolean winnable;
|
||||
|
||||
CoinFlippedEvent(UUID playerId, UUID sourceId, boolean result, boolean chosen, boolean winnable) {
|
||||
super(EventType.FLIP_COIN, playerId, sourceId, playerId);
|
||||
this.result = result;
|
||||
this.chosen = chosen;
|
||||
this.winnable = winnable;
|
||||
}
|
||||
|
||||
public boolean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean getChosen() {
|
||||
return chosen;
|
||||
}
|
||||
|
||||
public boolean isWinnable() {
|
||||
return winnable;
|
||||
}
|
||||
}
|
||||
36
Mage/src/main/java/mage/game/events/FlipCoinEvent.java
Normal file
36
Mage/src/main/java/mage/game/events/FlipCoinEvent.java
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package mage.game.events;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class FlipCoinEvent extends GameEvent {
|
||||
private boolean result;
|
||||
private final boolean chosen;
|
||||
private final boolean winnable;
|
||||
|
||||
public FlipCoinEvent(UUID playerId, UUID sourceId, boolean result, boolean chosen, boolean winnable) {
|
||||
super(EventType.FLIP_COIN, playerId, sourceId, playerId);
|
||||
this.result = result;
|
||||
this.chosen = chosen;
|
||||
this.winnable = winnable;
|
||||
}
|
||||
|
||||
public boolean getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(boolean result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public boolean getChosen() {
|
||||
return chosen;
|
||||
}
|
||||
|
||||
public boolean isWinnable() {
|
||||
return winnable;
|
||||
}
|
||||
|
||||
public CoinFlippedEvent getFlippedEvent() {
|
||||
return new CoinFlippedEvent(playerId, sourceId, result, chosen, winnable);
|
||||
}
|
||||
}
|
||||
|
|
@ -395,9 +395,9 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
|
||||
boolean hasProtectionFrom(MageObject source, Game game);
|
||||
|
||||
boolean flipCoin(Game game, boolean winnable);
|
||||
boolean flipCoin(Ability source, Game game, boolean winnable);
|
||||
|
||||
boolean flipCoin(Game game, boolean winnable, ArrayList<UUID> appliedEffects);
|
||||
boolean flipCoin(Ability source, Game game, boolean winnable, ArrayList<UUID> appliedEffects);
|
||||
|
||||
int rollDice(Game game, int numSides);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,11 +42,8 @@ import mage.filter.predicate.permanent.PermanentIdPredicate;
|
|||
import mage.game.*;
|
||||
import mage.game.combat.CombatGroup;
|
||||
import mage.game.command.CommandObject;
|
||||
import mage.game.events.DamagePlayerEvent;
|
||||
import mage.game.events.DamagedPlayerEvent;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.*;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.permanent.PermanentCard;
|
||||
|
|
@ -2560,28 +2557,38 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean flipCoin(Game game, boolean winnable) {
|
||||
return this.flipCoin(game, true, null);
|
||||
public boolean flipCoin(Ability source, Game game, boolean winnable) {
|
||||
return this.flipCoin(source, game, true, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param source
|
||||
* @param game
|
||||
* @param winnable
|
||||
* @param appliedEffects
|
||||
* @return true if player won the toss
|
||||
* @return if winnable, true if player won the toss, if not winnable, true for heads and false for tails
|
||||
*/
|
||||
@Override
|
||||
public boolean flipCoin(Game game, boolean winnable, ArrayList<UUID> appliedEffects) {
|
||||
public boolean flipCoin(Ability source, Game game, boolean winnable, ArrayList<UUID> appliedEffects) {
|
||||
boolean chosen = false;
|
||||
if (winnable) {
|
||||
chosen = this.chooseUse(Outcome.Benefit, "Heads or tails?", "", "Heads", "Tails", source, game);
|
||||
game.informPlayers(getLogName() + " chose " + (chosen ? "heads." : "tails."));
|
||||
}
|
||||
boolean result = RandomUtil.nextBoolean();
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("[Flip a coin] " + getLogName() + (result ? " won (head)." : " lost (tail)."));
|
||||
FlipCoinEvent event = new FlipCoinEvent(playerId, source.getSourceId(), result, chosen, winnable);
|
||||
event.addAppliedEffects(appliedEffects);
|
||||
game.replaceEvent(event);
|
||||
game.informPlayers(getLogName() + " got " + (event.getResult() ? "heads" : "tails"));
|
||||
if (event.isWinnable()) {
|
||||
game.informPlayers(getLogName() + " " + (event.getResult() == event.getChosen() ? "won" : "lost") + " the flip");
|
||||
}
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.FLIP_COIN, playerId, null, playerId, 0, result);
|
||||
event.setAppliedEffects(appliedEffects);
|
||||
if (!game.replaceEvent(event)) {
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.COIN_FLIPPED, playerId, null, playerId, 0, event.getFlag()));
|
||||
game.fireEvent(event.getFlippedEvent());
|
||||
if (event.isWinnable()) {
|
||||
return event.getResult() == event.getChosen();
|
||||
}
|
||||
return event.getFlag();
|
||||
return event.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -2599,7 +2606,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
public int rollDice(Game game, ArrayList<UUID> appliedEffects, int numSides) {
|
||||
int result = RandomUtil.nextInt(numSides) + 1;
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers("[Roll a die] " + getLogName() + " rolled a " + result + " on a " + numSides + " sided dice");
|
||||
game.informPlayers("[Roll a die] " + getLogName() + " rolled a " + result + " on a " + numSides + " sided die");
|
||||
}
|
||||
GameEvent event = new GameEvent(GameEvent.EventType.ROLL_DICE, playerId, null, playerId, result, true);
|
||||
event.setAppliedEffects(appliedEffects);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue