- Added Mana Clash

This commit is contained in:
moomarc
2013-03-10 14:57:18 +00:00
parent 40641f2b41
commit 4f114411e1
6 changed files with 132 additions and 51 deletions

View File

@@ -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>();
@@ -759,6 +760,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>.

View File

@@ -705,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) {
@@ -861,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")) {

View File

@@ -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();
}
}
}

View File

@@ -37,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);
}
@@ -45,62 +50,64 @@ 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 = FlipCoinEffect.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");
}
}
@@ -109,25 +116,26 @@ public class FlipCoinEffect extends SpellAbilityEffect {
/**
* <p>
* flipACoin without call.
* flipCoinNoCall Flip a coin without any call.
* </p>
*
* @param source
* a {@link forge.Card} object.
* @param source the source card.
* @param flipper the player flipping the coin.
* @return a boolean.
*/
private static boolean flipCoin(final Card source) {
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("Flip comes up");
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;
}