mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 10:18:01 +00:00
ClashEffect: Fix triggering for both players
This commit is contained in:
committed by
Michael Kamensky
parent
6fe299d7c8
commit
2be3a38bb0
@@ -1724,12 +1724,10 @@ public class GameAction {
|
||||
}
|
||||
}
|
||||
|
||||
private void drawStartingHand(Player p1){
|
||||
|
||||
private void drawStartingHand(Player p1) {
|
||||
//check initial hand
|
||||
List<Card> lib1 = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
||||
List<Card> hand1 = lib1.subList(0,p1.getMaxHandSize());
|
||||
System.out.println(hand1.toString());
|
||||
|
||||
//shuffle
|
||||
List<Card> shuffledCards = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
||||
@@ -1737,33 +1735,32 @@ public class GameAction {
|
||||
|
||||
//check a second hand
|
||||
List<Card> hand2 = shuffledCards.subList(0,p1.getMaxHandSize());
|
||||
System.out.println(hand2.toString());
|
||||
|
||||
//choose better hand according to land count
|
||||
float averageLandRatio = getLandRatio(lib1);
|
||||
if(getHandScore(hand1, averageLandRatio)>getHandScore(hand2, averageLandRatio)){
|
||||
if (getHandScore(hand1, averageLandRatio) > getHandScore(hand2, averageLandRatio)) {
|
||||
p1.getZone(ZoneType.Library).setCards(shuffledCards);
|
||||
}
|
||||
p1.drawCards(p1.getMaxHandSize());
|
||||
}
|
||||
|
||||
private float getLandRatio(List<Card> deck){
|
||||
private float getLandRatio(List<Card> deck) {
|
||||
int landCount = 0;
|
||||
for(Card c:deck){
|
||||
if(c.isLand()){
|
||||
for (Card c:deck) {
|
||||
if (c.isLand()){
|
||||
landCount++;
|
||||
}
|
||||
}
|
||||
if (landCount == 0 ){
|
||||
if(landCount == 0) {
|
||||
return 0;
|
||||
}
|
||||
return Float.valueOf(landCount)/Float.valueOf(deck.size());
|
||||
}
|
||||
|
||||
private float getHandScore(List<Card> hand, float landRatio){
|
||||
private float getHandScore(List<Card> hand, float landRatio) {
|
||||
int landCount = 0;
|
||||
for(Card c:hand){
|
||||
if(c.isLand()){
|
||||
for (Card c:hand) {
|
||||
if (c.isLand()) {
|
||||
landCount++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,30 +30,30 @@ public class ClashEffect extends SpellAbilityEffect {
|
||||
*/
|
||||
@Override
|
||||
public void resolve(final SpellAbility sa) {
|
||||
final boolean victory = clashWithOpponent(sa);
|
||||
|
||||
// Run triggers
|
||||
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
||||
runParams.put(AbilityKey.Player, sa.getHostCard().getController());
|
||||
|
||||
if (victory) {
|
||||
final Card source = sa.getHostCard();
|
||||
final Player player = source.getController();
|
||||
final Player opponent = sa.getActivatingPlayer().getController().chooseSingleEntityForEffect(player.getOpponents(), sa, Localizer.getInstance().getMessage("lblChooseOpponent"), null);
|
||||
final Player winner = clashWithOpponent(sa, opponent);
|
||||
|
||||
if (player.equals(winner)) {
|
||||
SpellAbility sub = sa.getAdditionalAbility("WinSubAbility");
|
||||
if (sub != null) {
|
||||
AbilityUtils.resolve(sub);
|
||||
}
|
||||
|
||||
runParams.put(AbilityKey.Won, "True");
|
||||
} else {
|
||||
SpellAbility sub = sa.getAdditionalAbility("OtherwiseSubAbility");
|
||||
if (sub != null) {
|
||||
AbilityUtils.resolve(sub);
|
||||
}
|
||||
|
||||
runParams.put(AbilityKey.Won, "False");
|
||||
}
|
||||
|
||||
|
||||
// Run triggers
|
||||
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
||||
runParams.put(AbilityKey.Player, player);
|
||||
runParams.put(AbilityKey.Won, player.equals(winner) ? "True" : "False");
|
||||
sa.getHostCard().getGame().getTriggerHandler().runTrigger(TriggerType.Clashed, runParams, false);
|
||||
runParams.put(AbilityKey.Player, opponent);
|
||||
runParams.put(AbilityKey.Won, opponent.equals(winner) ? "True" : "False");
|
||||
sa.getHostCard().getGame().getTriggerHandler().runTrigger(TriggerType.Clashed, runParams, false);
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ public class ClashEffect extends SpellAbilityEffect {
|
||||
*
|
||||
* @return a boolean.
|
||||
*/
|
||||
private static boolean clashWithOpponent(final SpellAbility sa) {
|
||||
private static Player clashWithOpponent(final SpellAbility sa, Player opponent) {
|
||||
/*
|
||||
* Each clashing player reveals the top card of his or her library, then
|
||||
* puts that card on the top or bottom. A player wins if his or her card
|
||||
@@ -74,53 +74,63 @@ public class ClashEffect extends SpellAbilityEffect {
|
||||
*/
|
||||
final Card source = sa.getHostCard();
|
||||
final Player player = source.getController();
|
||||
final Player opponent = sa.getActivatingPlayer().getController().chooseSingleEntityForEffect(player.getOpponents(), sa, Localizer.getInstance().getMessage("lblChooseOpponent"), null);
|
||||
final ZoneType lib = ZoneType.Library;
|
||||
|
||||
if (sa.hasParam("RememberClasher")) {
|
||||
source.addRemembered(opponent);
|
||||
}
|
||||
|
||||
|
||||
final PlayerZone pLib = player.getZone(lib);
|
||||
final PlayerZone oLib = opponent.getZone(lib);
|
||||
|
||||
|
||||
if ((pLib.size() == 0) && (oLib.size() == 0)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final StringBuilder reveal = new StringBuilder();
|
||||
|
||||
Card pCard = null;
|
||||
Card oCard = null;
|
||||
|
||||
|
||||
if (pLib.size() > 0) {
|
||||
pCard = pLib.get(0);
|
||||
}
|
||||
if (oLib.size() > 0) {
|
||||
oCard = oLib.get(0);
|
||||
}
|
||||
|
||||
if ((pLib.size() == 0) && (oLib.size() == 0)) {
|
||||
return false;
|
||||
} else if (pLib.isEmpty()) {
|
||||
clashMoveToTopOrBottom(opponent, oCard, sa);
|
||||
return false;
|
||||
} else if (oLib.isEmpty()) {
|
||||
clashMoveToTopOrBottom(player, pCard, sa);
|
||||
return true;
|
||||
} else {
|
||||
final int pCMC = pCard.getCMC();
|
||||
final int oCMC = oCard.getCMC();
|
||||
|
||||
// TODO: Split cards will return two CMC values, so both players may become winners of clash
|
||||
|
||||
|
||||
int pCMC = 0;
|
||||
int oCMC = 0;
|
||||
|
||||
if (!pLib.isEmpty()) {
|
||||
pCMC = pCard.getCMC();
|
||||
|
||||
reveal.append(player).append(" " + Localizer.getInstance().getMessage("lblReveals") + ": ").append(pCard.getName()).append(". " + Localizer.getInstance().getMessage("lblCMC") + "= ").append(pCMC);
|
||||
reveal.append("\r\n");
|
||||
clashMoveToTopOrBottom(player, pCard, sa);
|
||||
}
|
||||
else {
|
||||
pCMC = -1;
|
||||
}
|
||||
if (!oLib.isEmpty()) {
|
||||
oCMC = oCard.getCMC();
|
||||
|
||||
reveal.append(opponent).append(" " + Localizer.getInstance().getMessage("lblReveals") + ": ").append(oCard.getName()).append(". " + Localizer.getInstance().getMessage("lblCMC") + "= ").append(oCMC);
|
||||
reveal.append("\r\n\r\n");
|
||||
reveal.append(player).append(pCMC > oCMC ? " " + Localizer.getInstance().getMessage("lblWinsClash") + "." : " " + Localizer.getInstance().getMessage("lblLosesClash") + ".");
|
||||
|
||||
player.getGame().getAction().notifyOfValue(sa, source, reveal.toString(), null);
|
||||
clashMoveToTopOrBottom(player, pCard, sa);
|
||||
clashMoveToTopOrBottom(opponent, oCard, sa);
|
||||
return pCMC > oCMC;
|
||||
}
|
||||
else {
|
||||
oCMC = -1;
|
||||
}
|
||||
|
||||
// no winner
|
||||
if (pCMC == oCMC) {
|
||||
return null;
|
||||
}
|
||||
|
||||
reveal.append(player).append(pCMC > oCMC ? " " + Localizer.getInstance().getMessage("lblWinsClash") + "." : " " + Localizer.getInstance().getMessage("lblLosesClash") + ".");
|
||||
player.getGame().getAction().notifyOfValue(sa, source, reveal.toString(), null);
|
||||
|
||||
return pCMC > oCMC ? player : opponent;
|
||||
}
|
||||
|
||||
private static void clashMoveToTopOrBottom(final Player p, final Card c, final SpellAbility sa) {
|
||||
|
||||
Reference in New Issue
Block a user