mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
merge latest trunk
This commit is contained in:
@@ -125,6 +125,7 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
private final ArrayList<Card> encodedCards = new ArrayList<Card>();
|
||||
private Card championedCard = null;
|
||||
private final List<Card> devouredCards = new ArrayList<Card>();
|
||||
private Map<Player, String> flipResult = new TreeMap<Player, String>();
|
||||
|
||||
private Map<Card, Integer> receivedDamageFromThisTurn = new TreeMap<Card, Integer>();
|
||||
private Map<Card, Integer> dealtDamageToThisTurn = new TreeMap<Card, Integer>();
|
||||
@@ -758,6 +759,39 @@ public class Card extends GameEntity implements Comparable<Card> {
|
||||
this.encodedCards.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* addFlipResult.
|
||||
* </p>
|
||||
*
|
||||
* @param flipper The Player who flipped the coin.
|
||||
* @param result The result of the coin flip as a String.
|
||||
*/
|
||||
public final void addFlipResult(final Player flipper, final String result) {
|
||||
this.flipResult.put(flipper, result);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* getFlipResult.
|
||||
* </p>
|
||||
*
|
||||
* @param flipper The Player who flipped the coin.
|
||||
* @return a String result - Heads or Tails.
|
||||
*/
|
||||
public final String getFlipResult(final Player flipper) {
|
||||
return this.flipResult.get(flipper);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* clearFlipResult.
|
||||
* </p>
|
||||
*/
|
||||
public final void clearFlipResult() {
|
||||
this.flipResult.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* Setter for the field <code>championedCard</code>.
|
||||
|
||||
@@ -4,7 +4,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -26,12 +25,10 @@ import forge.game.GameActionUtil;
|
||||
import forge.game.GameState;
|
||||
import forge.game.ai.ComputerUtil;
|
||||
import forge.game.ai.ComputerUtilCost;
|
||||
import forge.game.event.FlipCoinEvent;
|
||||
import forge.game.player.AIPlayer;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Expressions;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
/**
|
||||
* TODO: Write javadoc for this type.
|
||||
@@ -708,6 +705,12 @@ public class AbilityUtils {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
} else if (defined.equals("TargetedAndYou")) {
|
||||
final SpellAbility saTargeting = sa.getSATargetingPlayer();
|
||||
if (saTargeting != null) {
|
||||
players.addAll(saTargeting.getTarget().getTargetPlayers());
|
||||
players.add(sa.getActivatingPlayer());
|
||||
}
|
||||
} else if (defined.equals("Remembered")) {
|
||||
for (final Object rem : card.getRemembered()) {
|
||||
if (rem instanceof Player) {
|
||||
@@ -864,6 +867,14 @@ public class AbilityUtils {
|
||||
if (!players.contains(p)) {
|
||||
players.add(p);
|
||||
}
|
||||
} else if (defined.startsWith("Flipped")) {
|
||||
for (Player p : Singletons.getModel().getGame().getPlayers()) {
|
||||
if (null != sa.getSourceCard().getFlipResult(p)) {
|
||||
if (sa.getSourceCard().getFlipResult(p).equals(defined.substring(7))) {
|
||||
players.add(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (defined.equals("You")) {
|
||||
players.add(sa.getActivatingPlayer());
|
||||
} else if (defined.equals("Each")) {
|
||||
@@ -1257,28 +1268,4 @@ public class AbilityUtils {
|
||||
return CardFactoryUtil.xCount(c, s);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* flipACoin without call.
|
||||
* </p>
|
||||
*
|
||||
* @param source
|
||||
* a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean flipCoin(final Card source) {
|
||||
final boolean resultIsHeads = MyRandom.getRandom().nextBoolean();
|
||||
|
||||
Singletons.getModel().getGame().getEvents().post(new FlipCoinEvent());
|
||||
final StringBuilder msgTitle = new StringBuilder();
|
||||
msgTitle.append(source);
|
||||
msgTitle.append(" Flip result:");
|
||||
final StringBuilder result = new StringBuilder();
|
||||
result.append("Flip comes up");
|
||||
result.append(resultIsHeads ? " heads." : " tails.");
|
||||
JOptionPane.showMessageDialog(null, result, msgTitle.toString(), JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
return resultIsHeads;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -59,6 +59,9 @@ public class AddTurnEffect extends SpellAbilityEffect {
|
||||
if (sa.hasParam("SkipUntap")) {
|
||||
extra.setSkipUntap(true);
|
||||
}
|
||||
if (sa.hasParam("NoSchemes")) {
|
||||
extra.setCantSetSchemesInMotion(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,15 +87,7 @@ public class ChooseTypeEffect extends SpellAbilityEffect {
|
||||
for (final String s : invalidTypes) {
|
||||
validChoices.remove(s);
|
||||
}
|
||||
final Object o = GuiChoose.one("Choose a creature type", validChoices);
|
||||
if (null == o) {
|
||||
return;
|
||||
}
|
||||
final String choice = (String) o;
|
||||
if (CardType.isACreatureType(choice) && !invalidTypes.contains(choice)) {
|
||||
valid = true;
|
||||
card.setChosenType(choice);
|
||||
}
|
||||
chosenType = GuiChoose.one("Choose a creature type", validChoices);
|
||||
} else {
|
||||
Player ai = sa.getActivatingPlayer();
|
||||
Player opp = ai.getOpponent();
|
||||
|
||||
@@ -37,6 +37,9 @@ public class CleanUpEffect extends SpellAbilityEffect {
|
||||
if (sa.hasParam("ClearTriggered")) {
|
||||
Singletons.getModel().getGame().getTriggerHandler().clearDelayedTrigger(source);
|
||||
}
|
||||
if (sa.hasParam("ClearCoinFlips")) {
|
||||
source.clearFlipResult();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,14 +2,19 @@ package forge.card.ability.effects;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.card.ability.AbilityFactory;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
import forge.card.ability.SpellAbilityEffect;
|
||||
import forge.card.spellability.AbilitySub;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.game.event.FlipCoinEvent;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
|
||||
@@ -32,7 +37,12 @@ public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
final Card host = sa.getSourceCard();
|
||||
final Player player = host.getController();
|
||||
|
||||
final List<Player> caller = AbilityUtils.getDefinedPlayers(sa.getSourceCard(), sa.getParam("Caller"), sa);
|
||||
final List<Player> playersToFlip = AbilityUtils.getDefinedPlayers(host, sa.getParam("Flipper"), sa);
|
||||
if (playersToFlip.isEmpty()) {
|
||||
playersToFlip.add(sa.getActivatingPlayer());
|
||||
}
|
||||
|
||||
final List<Player> caller = AbilityUtils.getDefinedPlayers(host, sa.getParam("Caller"), sa);
|
||||
if (caller.isEmpty()) {
|
||||
caller.add(player);
|
||||
}
|
||||
@@ -40,66 +50,93 @@ public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
final boolean noCall = sa.hasParam("NoCall");
|
||||
boolean victory = false;
|
||||
if (!noCall) {
|
||||
victory = GuiDialog.flipCoin(caller.get(0), sa.getSourceCard());
|
||||
victory = GuiDialog.flipCoin(caller.get(0), host);
|
||||
}
|
||||
|
||||
// Run triggers
|
||||
// HashMap<String,Object> runParams = new HashMap<String,Object>();
|
||||
// runParams.put("Player", player);
|
||||
if (sa.getParam("RememberAll") != null) {
|
||||
host.addRemembered(host);
|
||||
}
|
||||
final boolean rememberResult = sa.hasParam("RememberResult");
|
||||
|
||||
if (noCall) {
|
||||
final boolean resultIsHeads = AbilityUtils.flipCoin(sa.getSourceCard());
|
||||
for (final Player flipper : playersToFlip) {
|
||||
if (noCall) {
|
||||
final boolean resultIsHeads = FlipCoinEffect.flipCoinNoCall(sa.getSourceCard(), flipper);
|
||||
if (rememberResult) {
|
||||
host.addFlipResult(flipper, resultIsHeads ? "Heads" : "Tails");
|
||||
}
|
||||
|
||||
System.out.println("Flipped coin result:" + (resultIsHeads ? " Heads" : " Tails"));
|
||||
if (resultIsHeads) {
|
||||
if (sa.hasParam("HeadsSubAbility")) {
|
||||
final SpellAbility heads = AbilityFactory.getAbility(host.getSVar(sa.getParam("HeadsSubAbility")), host);
|
||||
heads.setActivatingPlayer(player);
|
||||
((AbilitySub) heads).setParent(sa);
|
||||
if (resultIsHeads) {
|
||||
if (sa.hasParam("HeadsSubAbility")) {
|
||||
final SpellAbility heads = AbilityFactory.getAbility(host.getSVar(sa.getParam("HeadsSubAbility")), host);
|
||||
heads.setActivatingPlayer(player);
|
||||
((AbilitySub) heads).setParent(sa);
|
||||
|
||||
AbilityUtils.resolve(heads, false);
|
||||
AbilityUtils.resolve(heads, false);
|
||||
}
|
||||
} else {
|
||||
if (sa.hasParam("TailsSubAbility")) {
|
||||
final SpellAbility tails = AbilityFactory.getAbility(host.getSVar(sa.getParam("TailsSubAbility")), host);
|
||||
tails.setActivatingPlayer(player);
|
||||
((AbilitySub) tails).setParent(sa);
|
||||
|
||||
AbilityUtils.resolve(tails, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (sa.hasParam("TailsSubAbility")) {
|
||||
final SpellAbility tails = AbilityFactory.getAbility(host.getSVar(sa.getParam("TailsSubAbility")), host);
|
||||
tails.setActivatingPlayer(player);
|
||||
((AbilitySub) tails).setParent(sa);
|
||||
if (victory) {
|
||||
if (sa.getParam("RememberWinner") != null) {
|
||||
host.addRemembered(host);
|
||||
}
|
||||
if (sa.hasParam("WinSubAbility")) {
|
||||
final SpellAbility win = AbilityFactory.getAbility(host.getSVar(sa.getParam("WinSubAbility")), host);
|
||||
win.setActivatingPlayer(player);
|
||||
((AbilitySub) win).setParent(sa);
|
||||
|
||||
AbilityUtils.resolve(tails, false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (victory) {
|
||||
if (sa.getParam("RememberWinner") != null) {
|
||||
host.addRemembered(host);
|
||||
}
|
||||
if (sa.hasParam("WinSubAbility")) {
|
||||
final SpellAbility win = AbilityFactory.getAbility(host.getSVar(sa.getParam("WinSubAbility")), host);
|
||||
win.setActivatingPlayer(player);
|
||||
((AbilitySub) win).setParent(sa);
|
||||
AbilityUtils.resolve(win, false);
|
||||
}
|
||||
// runParams.put("Won","True");
|
||||
} else {
|
||||
if (sa.getParam("RememberLoser") != null) {
|
||||
host.addRemembered(host);
|
||||
}
|
||||
if (sa.hasParam("LoseSubAbility")) {
|
||||
final SpellAbility lose = AbilityFactory.getAbility(host.getSVar(sa.getParam("LoseSubAbility")), host);
|
||||
lose.setActivatingPlayer(player);
|
||||
((AbilitySub) lose).setParent(sa);
|
||||
|
||||
AbilityUtils.resolve(win, false);
|
||||
AbilityUtils.resolve(lose, false);
|
||||
}
|
||||
// runParams.put("Won","False");
|
||||
}
|
||||
// runParams.put("Won","True");
|
||||
} else {
|
||||
if (sa.getParam("RememberLoser") != null) {
|
||||
host.addRemembered(host);
|
||||
}
|
||||
if (sa.hasParam("LoseSubAbility")) {
|
||||
final SpellAbility lose = AbilityFactory.getAbility(host.getSVar(sa.getParam("LoseSubAbility")), host);
|
||||
lose.setActivatingPlayer(player);
|
||||
((AbilitySub) lose).setParent(sa);
|
||||
|
||||
AbilityUtils.resolve(lose, false);
|
||||
}
|
||||
// runParams.put("Won","False");
|
||||
}
|
||||
}
|
||||
|
||||
// AllZone.getTriggerHandler().runTrigger("FlipsACoin",runParams);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* flipCoinNoCall Flip a coin without any call.
|
||||
* </p>
|
||||
*
|
||||
* @param source the source card.
|
||||
* @param flipper the player flipping the coin.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean flipCoinNoCall(final Card source, final Player flipper) {
|
||||
final boolean resultIsHeads = MyRandom.getRandom().nextBoolean();
|
||||
|
||||
Singletons.getModel().getGame().getEvents().post(new FlipCoinEvent());
|
||||
final StringBuilder msgTitle = new StringBuilder();
|
||||
msgTitle.append(source);
|
||||
msgTitle.append(" Flip result:");
|
||||
final StringBuilder result = new StringBuilder();
|
||||
result.append(flipper.getName());
|
||||
result.append("'s flip comes up");
|
||||
result.append(resultIsHeads ? " heads." : " tails.");
|
||||
JOptionPane.showMessageDialog(null, result, msgTitle.toString(), JOptionPane.PLAIN_MESSAGE);
|
||||
|
||||
return resultIsHeads;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -159,10 +159,12 @@ public class MatchController {
|
||||
|
||||
getInput().clearInput();
|
||||
getInput().resetInput();
|
||||
getInput().setNewInput(currentGame);
|
||||
|
||||
Thread thGame = new GameInputUpdatesThread(this, currentGame);
|
||||
thGame.setName("Game input updater");
|
||||
thGame.start();
|
||||
|
||||
// Thread thGame = new GameInputUpdatesThread(this, currentGame);
|
||||
// thGame.setName("Game input updater");
|
||||
// thGame.start();
|
||||
|
||||
// TODO restore this functionality!!!
|
||||
//VMatchUI.SINGLETON_INSTANCE.getViewDevMode().getDocument().setVisible(Preferences.DEV_MODE);
|
||||
|
||||
@@ -33,6 +33,7 @@ public class ExtraTurn {
|
||||
private Player player = null;
|
||||
private boolean loseAtEndStep = false;
|
||||
private boolean skipUntap = false;
|
||||
private boolean cantSetSchemesInMotion = false;
|
||||
/**
|
||||
* TODO: Write javadoc for Constructor.
|
||||
* @param player the player
|
||||
@@ -83,4 +84,18 @@ public class ExtraTurn {
|
||||
this.skipUntap = skipUntap;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if Schemes can't be played during the extra turn
|
||||
*/
|
||||
public boolean isCantSetSchemesInMotion() {
|
||||
return cantSetSchemesInMotion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param noSchemes set boolean if schemes can't be played this extra turn
|
||||
*/
|
||||
public void setCantSetSchemesInMotion(boolean noSchemes) {
|
||||
this.cantSetSchemesInMotion = noSchemes;
|
||||
}
|
||||
|
||||
} //end class Untap
|
||||
|
||||
@@ -62,7 +62,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
private int nCombatsThisTurn = 0;
|
||||
private boolean bPreventCombatDamageThisTurn = false;
|
||||
private int planarDiceRolledthisTurn = 0;
|
||||
|
||||
|
||||
private Player playerTurn = null;
|
||||
|
||||
// priority player
|
||||
@@ -540,16 +540,16 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
|
||||
p.removeKeyword("At the beginning of this turn's end step, you lose the game.");
|
||||
p.removeKeyword("Skip the untap step of this turn.");
|
||||
p.removeKeyword("Schemes can't be set in motion this turn.");
|
||||
}
|
||||
|
||||
Player next = getNextActivePlayer();
|
||||
VField nextField = CMatchUI.SINGLETON_INSTANCE.getFieldViewFor(next);
|
||||
SDisplayUtil.showTab(nextField);
|
||||
|
||||
if(game.getType() == GameType.Planechase) {
|
||||
|
||||
if (game.getType() == GameType.Planechase) {
|
||||
Card p = game.getActivePlane();
|
||||
if(p != null)
|
||||
{
|
||||
if (p != null) {
|
||||
p.clearControllers();
|
||||
p.addController(next);
|
||||
game.getAction().controllerChangeZoneCorrection(p);
|
||||
@@ -580,6 +580,9 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
if (extraTurn.isSkipUntap()) {
|
||||
nextTurn.addKeyword("Skip the untap step of this turn.");
|
||||
}
|
||||
if (extraTurn.isCantSetSchemesInMotion()) {
|
||||
nextTurn.addKeyword("Schemes can't be set in motion this turn.");
|
||||
}
|
||||
return nextTurn;
|
||||
}
|
||||
if (nextTurn.skipTurnTimeVault()) {
|
||||
|
||||
@@ -224,6 +224,11 @@ public abstract class Player extends GameEntity implements Comparable<Player> {
|
||||
}
|
||||
|
||||
public void setSchemeInMotion() {
|
||||
for (final Player p : game.getPlayers()) {
|
||||
if (p.hasKeyword("Schemes can't be set in motion this turn.")) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Replacement effects
|
||||
final HashMap<String, Object> repRunParams = new HashMap<String, Object>();
|
||||
|
||||
@@ -21,10 +21,11 @@ import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import forge.Card;
|
||||
import forge.Singletons;
|
||||
import forge.control.input.Input;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.PlayerZone;
|
||||
import forge.util.MyObservable;
|
||||
import forge.view.ButtonUtil;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -34,7 +35,7 @@ import forge.util.MyObservable;
|
||||
* @author Forge
|
||||
* @version $Id$
|
||||
*/
|
||||
public class InputProxy extends MyObservable implements Observer {
|
||||
public class InputProxy implements Observer {
|
||||
|
||||
/** The input. */
|
||||
private Input input;
|
||||
@@ -42,7 +43,10 @@ public class InputProxy extends MyObservable implements Observer {
|
||||
|
||||
@Override
|
||||
public final synchronized void update(final Observable observable, final Object obj) {
|
||||
ButtonUtil.disableAll();
|
||||
valid = false;
|
||||
|
||||
Singletons.getModel().getMatch().getInput().setNewInput(Singletons.getModel().getGame());
|
||||
}
|
||||
/**
|
||||
* <p>
|
||||
|
||||
Reference in New Issue
Block a user