mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 03:08:02 +00:00
- Renamed TriggerFlippedCoin
- Move GuiDialog.flipCoin to FlipCoin effect - Added Krark's Thumb
This commit is contained in:
@@ -2,7 +2,6 @@ package forge.card.ability.effects;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import forge.Card;
|
||||
import forge.card.ability.AbilityFactory;
|
||||
import forge.card.ability.AbilityUtils;
|
||||
@@ -12,6 +11,7 @@ import forge.card.spellability.SpellAbility;
|
||||
import forge.card.trigger.TriggerType;
|
||||
import forge.game.event.GameEventFlipCoin;
|
||||
import forge.game.player.Player;
|
||||
import forge.gui.GuiChoose;
|
||||
import forge.gui.GuiDialog;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
@@ -38,6 +38,7 @@ public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
public void resolve(SpellAbility sa) {
|
||||
final Card host = sa.getSourceCard();
|
||||
final Player player = host.getController();
|
||||
int flipMultiplier = 1; // For multiple copies of Krark's Thumb
|
||||
|
||||
final List<Player> playersToFlip = AbilityUtils.getDefinedPlayers(host, sa.getParam("Flipper"), sa);
|
||||
if (playersToFlip.isEmpty()) {
|
||||
@@ -52,20 +53,22 @@ public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
final boolean noCall = sa.hasParam("NoCall");
|
||||
boolean victory = false;
|
||||
if (!noCall) {
|
||||
victory = GuiDialog.flipCoin(caller.get(0), host);
|
||||
flipMultiplier = getFilpMultiplier(caller.get(0));
|
||||
victory = flipCoinCall(caller.get(0), host, flipMultiplier);
|
||||
}
|
||||
|
||||
// Run triggers
|
||||
HashMap<String,Object> runParams = new HashMap<String,Object>();
|
||||
runParams.put("Player", caller.get(0));
|
||||
runParams.put("Result", (Boolean) victory);
|
||||
player.getGame().getTriggerHandler().runTrigger(TriggerType.Flipped, runParams, false);
|
||||
player.getGame().getTriggerHandler().runTrigger(TriggerType.FlippedCoin, runParams, false);
|
||||
|
||||
final boolean rememberResult = sa.hasParam("RememberResult");
|
||||
|
||||
for (final Player flipper : playersToFlip) {
|
||||
if (noCall) {
|
||||
final boolean resultIsHeads = FlipCoinEffect.flipCoinNoCall(sa.getSourceCard(), flipper);
|
||||
flipMultiplier = getFilpMultiplier(flipper);
|
||||
final boolean resultIsHeads = FlipCoinEffect.flipCoinNoCall(sa.getSourceCard(), flipper, flipMultiplier);
|
||||
if (rememberResult) {
|
||||
host.addFlipResult(flipper, resultIsHeads ? "Heads" : "Tails");
|
||||
}
|
||||
@@ -126,19 +129,79 @@ public class FlipCoinEffect extends SpellAbilityEffect {
|
||||
*
|
||||
* @param source the source card.
|
||||
* @param flipper the player flipping the coin.
|
||||
* @param multiplier
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean flipCoinNoCall(final Card source, final Player flipper) {
|
||||
final boolean resultIsHeads = MyRandom.getRandom().nextBoolean();
|
||||
public static boolean flipCoinNoCall(final Card source, final Player flipper, final int multiplier) {
|
||||
String[] results = new String[multiplier];
|
||||
String result;
|
||||
for (int i = 0; i < multiplier; i++) {
|
||||
final boolean resultIsHeads = MyRandom.getRandom().nextBoolean();
|
||||
flipper.getGame().fireEvent(new GameEventFlipCoin());
|
||||
results[i] = resultIsHeads ? " heads." : " tails.";
|
||||
}
|
||||
if (multiplier == 1) {
|
||||
result = results[0];
|
||||
} else {
|
||||
result = flipper.getController().chooseFilpResult(source, flipper, results, false);
|
||||
}
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
sb.append(flipper.getName());
|
||||
sb.append("'s flip comes up");
|
||||
sb.append(result);
|
||||
GuiDialog.message(sb.toString(), source + " Flip result:");
|
||||
return result.equals(" heads.");
|
||||
}
|
||||
|
||||
flipper.getGame().fireEvent(new GameEventFlipCoin());
|
||||
final StringBuilder result = new StringBuilder();
|
||||
result.append(flipper.getName());
|
||||
result.append("'s flip comes up");
|
||||
result.append(resultIsHeads ? " heads." : " tails.");
|
||||
GuiDialog.message(result.toString(), source + " Flip result:");
|
||||
/**
|
||||
* <p>
|
||||
* flipCoinCall.
|
||||
* </p>
|
||||
*
|
||||
* @param caller
|
||||
* a {@link forge.game.player.Player} object.
|
||||
* @param source
|
||||
* a {@link forge.Card} object.
|
||||
* @param multiplier
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean flipCoinCall(final Player caller, final Card source, final int multiplier) {
|
||||
String choice;
|
||||
final String[] choices = { "heads", "tails" };
|
||||
String[] results = new String[multiplier];
|
||||
for (int i = 0; i < multiplier; i++) {
|
||||
// Play the Flip A Coin sound
|
||||
caller.getGame().fireEvent(new GameEventFlipCoin());
|
||||
final boolean flip = MyRandom.getRandom().nextBoolean();
|
||||
if (caller.isHuman()) {
|
||||
choice = GuiChoose.one(source.getName() + " - Call coin flip", choices);
|
||||
} else {
|
||||
choice = choices[MyRandom.getRandom().nextInt(2)];
|
||||
}
|
||||
final boolean winFlip = flip == choice.equals(choices[0]);
|
||||
final String winMsg = winFlip ? " wins flip." : " loses flip.";
|
||||
results[i] = winMsg;
|
||||
}
|
||||
String result;
|
||||
if (multiplier == 1) {
|
||||
result = results[0];
|
||||
} else {
|
||||
result = caller.getController().chooseFilpResult(source, caller, results, true);
|
||||
}
|
||||
|
||||
GuiDialog.message(source.getName() + " - " + caller + result, source.getName());
|
||||
|
||||
return result.equals(" wins flip.");
|
||||
}
|
||||
|
||||
return resultIsHeads;
|
||||
public static int getFilpMultiplier(final Player flipper) {
|
||||
int i = 0;
|
||||
for (String kw : flipper.getKeywords()) {
|
||||
if (kw.startsWith("If you would flip a coin")) {
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return 1 << i;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import forge.card.spellability.SpellAbility;
|
||||
* @author Forge
|
||||
* @version $Id: TriggerFlipped.java 17802 2012-10-31 08:05:14Z Max mtg $
|
||||
*/
|
||||
public class TriggerFlipped extends Trigger {
|
||||
public class TriggerFlippedCoin extends Trigger {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -42,7 +42,7 @@ public class TriggerFlipped extends Trigger {
|
||||
* @param intrinsic
|
||||
* the intrinsic
|
||||
*/
|
||||
public TriggerFlipped(final java.util.Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
public TriggerFlippedCoin(final java.util.Map<String, String> params, final Card host, final boolean intrinsic) {
|
||||
super(params, host, intrinsic);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ public enum TriggerType {
|
||||
|
||||
Clashed(TriggerClashed.class),
|
||||
PayCumulativeUpkeep(TriggerPayCumulativeUpkeep.class),
|
||||
Flipped(TriggerFlipped.class),
|
||||
FlippedCoin(TriggerFlippedCoin.class),
|
||||
Attached(TriggerAttached.class),
|
||||
Destroyed(TriggerDestroyed.class),
|
||||
Devoured(TriggerDevoured.class),
|
||||
|
||||
@@ -144,4 +144,6 @@ public abstract class PlayerController {
|
||||
|
||||
public abstract int chooseNumber(SpellAbility sa, String title, int min, int max);
|
||||
|
||||
public abstract String chooseFilpResult(Card source, Player flipper, String[] results, boolean call);
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ import forge.game.ai.ComputerUtilCombat;
|
||||
import forge.game.ai.ComputerUtilCost;
|
||||
import forge.game.zone.ZoneType;
|
||||
import forge.util.Aggregates;
|
||||
import forge.util.MyRandom;
|
||||
|
||||
|
||||
/**
|
||||
@@ -355,4 +356,26 @@ public class PlayerControllerAi extends PlayerController {
|
||||
public int chooseNumber(SpellAbility sa, String title, int min, int max) {
|
||||
return brains.chooseNumber(sa, title, min, max);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#chooseFilpResult(forge.Card, forge.game.player.Player, java.lang.String[], boolean)
|
||||
*/
|
||||
@Override
|
||||
public String chooseFilpResult(Card source, Player flipper, String[] results, boolean call) {
|
||||
if (call) {
|
||||
// Win if possible
|
||||
String result = " loses flip.";
|
||||
for (String s : results) {
|
||||
if (s.equals(" wins flip.")) {
|
||||
result = s;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
// heads or tails, AI doesn't know which is better now
|
||||
int i = MyRandom.getRandom().nextInt(results.length);
|
||||
return results[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,4 +610,13 @@ public class PlayerControllerHuman extends PlayerController {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see forge.game.player.PlayerController#chooseFilpResult(forge.game.player.Player, java.lang.String[], boolean)
|
||||
*/
|
||||
@Override
|
||||
public String chooseFilpResult(Card source, Player flipper, String[] results, boolean call) {
|
||||
return GuiChoose.one(source.getName() + " - Choose a result", results);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,37 +80,4 @@ public class GuiDialog {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* flipACoin.
|
||||
* </p>
|
||||
*
|
||||
* @param caller
|
||||
* a {@link forge.game.player.Player} object.
|
||||
* @param source
|
||||
* a {@link forge.Card} object.
|
||||
* @return a boolean.
|
||||
*/
|
||||
public static boolean flipCoin(final Player caller, final Card source) {
|
||||
String choice;
|
||||
final String[] choices = { "heads", "tails" };
|
||||
|
||||
final boolean flip = MyRandom.getRandom().nextBoolean();
|
||||
if (caller.isHuman()) {
|
||||
choice = GuiChoose.one(source.getName() + " - Call coin flip", choices);
|
||||
} else {
|
||||
choice = choices[MyRandom.getRandom().nextInt(2)];
|
||||
}
|
||||
|
||||
final boolean winFlip = flip == choice.equals(choices[0]);
|
||||
final String winMsg = winFlip ? " wins flip." : " loses flip.";
|
||||
|
||||
// Play the Flip A Coin sound
|
||||
caller.getGame().fireEvent(new GameEventFlipCoin());
|
||||
|
||||
message(source.getName() + " - " + caller + winMsg, source.getName());
|
||||
|
||||
return winFlip;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user