mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 02:08:00 +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
|
//check initial hand
|
||||||
List<Card> lib1 = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
List<Card> lib1 = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
||||||
List<Card> hand1 = lib1.subList(0,p1.getMaxHandSize());
|
List<Card> hand1 = lib1.subList(0,p1.getMaxHandSize());
|
||||||
System.out.println(hand1.toString());
|
|
||||||
|
|
||||||
//shuffle
|
//shuffle
|
||||||
List<Card> shuffledCards = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
List<Card> shuffledCards = Lists.newArrayList(p1.getZone(ZoneType.Library).getCards().threadSafeIterable());
|
||||||
@@ -1737,33 +1735,32 @@ public class GameAction {
|
|||||||
|
|
||||||
//check a second hand
|
//check a second hand
|
||||||
List<Card> hand2 = shuffledCards.subList(0,p1.getMaxHandSize());
|
List<Card> hand2 = shuffledCards.subList(0,p1.getMaxHandSize());
|
||||||
System.out.println(hand2.toString());
|
|
||||||
|
|
||||||
//choose better hand according to land count
|
//choose better hand according to land count
|
||||||
float averageLandRatio = getLandRatio(lib1);
|
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.getZone(ZoneType.Library).setCards(shuffledCards);
|
||||||
}
|
}
|
||||||
p1.drawCards(p1.getMaxHandSize());
|
p1.drawCards(p1.getMaxHandSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
private float getLandRatio(List<Card> deck){
|
private float getLandRatio(List<Card> deck) {
|
||||||
int landCount = 0;
|
int landCount = 0;
|
||||||
for(Card c:deck){
|
for (Card c:deck) {
|
||||||
if(c.isLand()){
|
if (c.isLand()){
|
||||||
landCount++;
|
landCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (landCount == 0 ){
|
if(landCount == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return Float.valueOf(landCount)/Float.valueOf(deck.size());
|
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;
|
int landCount = 0;
|
||||||
for(Card c:hand){
|
for (Card c:hand) {
|
||||||
if(c.isLand()){
|
if (c.isLand()) {
|
||||||
landCount++;
|
landCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,30 +30,30 @@ public class ClashEffect extends SpellAbilityEffect {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void resolve(final SpellAbility sa) {
|
public void resolve(final SpellAbility sa) {
|
||||||
final boolean victory = clashWithOpponent(sa);
|
final Card source = sa.getHostCard();
|
||||||
|
final Player player = source.getController();
|
||||||
// Run triggers
|
final Player opponent = sa.getActivatingPlayer().getController().chooseSingleEntityForEffect(player.getOpponents(), sa, Localizer.getInstance().getMessage("lblChooseOpponent"), null);
|
||||||
final Map<AbilityKey, Object> runParams = AbilityKey.newMap();
|
final Player winner = clashWithOpponent(sa, opponent);
|
||||||
runParams.put(AbilityKey.Player, sa.getHostCard().getController());
|
|
||||||
|
|
||||||
if (victory) {
|
|
||||||
|
|
||||||
|
if (player.equals(winner)) {
|
||||||
SpellAbility sub = sa.getAdditionalAbility("WinSubAbility");
|
SpellAbility sub = sa.getAdditionalAbility("WinSubAbility");
|
||||||
if (sub != null) {
|
if (sub != null) {
|
||||||
AbilityUtils.resolve(sub);
|
AbilityUtils.resolve(sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
runParams.put(AbilityKey.Won, "True");
|
|
||||||
} else {
|
} else {
|
||||||
SpellAbility sub = sa.getAdditionalAbility("OtherwiseSubAbility");
|
SpellAbility sub = sa.getAdditionalAbility("OtherwiseSubAbility");
|
||||||
if (sub != null) {
|
if (sub != null) {
|
||||||
AbilityUtils.resolve(sub);
|
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);
|
sa.getHostCard().getGame().getTriggerHandler().runTrigger(TriggerType.Clashed, runParams, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ public class ClashEffect extends SpellAbilityEffect {
|
|||||||
*
|
*
|
||||||
* @return a boolean.
|
* @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
|
* 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
|
* 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 Card source = sa.getHostCard();
|
||||||
final Player player = source.getController();
|
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;
|
final ZoneType lib = ZoneType.Library;
|
||||||
|
|
||||||
if (sa.hasParam("RememberClasher")) {
|
if (sa.hasParam("RememberClasher")) {
|
||||||
source.addRemembered(opponent);
|
source.addRemembered(opponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
final PlayerZone pLib = player.getZone(lib);
|
final PlayerZone pLib = player.getZone(lib);
|
||||||
final PlayerZone oLib = opponent.getZone(lib);
|
final PlayerZone oLib = opponent.getZone(lib);
|
||||||
|
|
||||||
|
if ((pLib.size() == 0) && (oLib.size() == 0)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
final StringBuilder reveal = new StringBuilder();
|
final StringBuilder reveal = new StringBuilder();
|
||||||
|
|
||||||
Card pCard = null;
|
Card pCard = null;
|
||||||
Card oCard = null;
|
Card oCard = null;
|
||||||
|
|
||||||
if (pLib.size() > 0) {
|
if (pLib.size() > 0) {
|
||||||
pCard = pLib.get(0);
|
pCard = pLib.get(0);
|
||||||
}
|
}
|
||||||
if (oLib.size() > 0) {
|
if (oLib.size() > 0) {
|
||||||
oCard = oLib.get(0);
|
oCard = oLib.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((pLib.size() == 0) && (oLib.size() == 0)) {
|
int pCMC = 0;
|
||||||
return false;
|
int oCMC = 0;
|
||||||
} else if (pLib.isEmpty()) {
|
|
||||||
clashMoveToTopOrBottom(opponent, oCard, sa);
|
if (!pLib.isEmpty()) {
|
||||||
return false;
|
pCMC = pCard.getCMC();
|
||||||
} 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
|
|
||||||
|
|
||||||
reveal.append(player).append(" " + Localizer.getInstance().getMessage("lblReveals") + ": ").append(pCard.getName()).append(". " + Localizer.getInstance().getMessage("lblCMC") + "= ").append(pCMC);
|
reveal.append(player).append(" " + Localizer.getInstance().getMessage("lblReveals") + ": ").append(pCard.getName()).append(". " + Localizer.getInstance().getMessage("lblCMC") + "= ").append(pCMC);
|
||||||
reveal.append("\r\n");
|
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(opponent).append(" " + Localizer.getInstance().getMessage("lblReveals") + ": ").append(oCard.getName()).append(". " + Localizer.getInstance().getMessage("lblCMC") + "= ").append(oCMC);
|
||||||
reveal.append("\r\n\r\n");
|
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);
|
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) {
|
private static void clashMoveToTopOrBottom(final Player p, final Card c, final SpellAbility sa) {
|
||||||
|
|||||||
Reference in New Issue
Block a user