mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-15 18:28:00 +00:00
temporarily inlined PhaseUtil.handleDeclareAttackers and handleAttackingTriggers,
fixed multiple triggering for Souverigns of the Lost Alara, extracted method for their 2nd ability
This commit is contained in:
@@ -1300,62 +1300,57 @@ public class CombatUtil {
|
||||
|
||||
game.getStack().addSimultaneousStackEntry(ability);
|
||||
}
|
||||
}
|
||||
|
||||
final Player phasingPlayer = c.getController();
|
||||
|
||||
if (phasingPlayer.getCardsIn(ZoneType.Battlefield, "Sovereigns of Lost Alara").size() > 0) {
|
||||
for (int i = 0; i < phasingPlayer.getCardsIn(ZoneType.Battlefield, "Sovereigns of Lost Alara").size(); i++) {
|
||||
final Card attacker = c;
|
||||
final Ability ability4 = new Ability(c, ManaCost.ZERO) {
|
||||
public static void souverignsOfAlara2ndAbility(final Game game, final Card attacker) {
|
||||
final Ability ability4 = new Ability(attacker, ManaCost.ZERO) {
|
||||
@Override
|
||||
public void resolve() {
|
||||
List<Card> enchantments =
|
||||
CardLists.filter(attacker.getController().getCardsIn(ZoneType.Library), new Predicate<Card>() {
|
||||
@Override
|
||||
public void resolve() {
|
||||
List<Card> enchantments =
|
||||
CardLists.filter(attacker.getController().getCardsIn(ZoneType.Library), new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
if (attacker.hasKeyword("Protection from enchantments")
|
||||
|| (attacker.hasKeyword("Protection from everything"))) {
|
||||
return false;
|
||||
}
|
||||
return (c.isEnchantment() && c.hasKeyword("Enchant creature") && !CardFactoryUtil
|
||||
.hasProtectionFrom(c, attacker));
|
||||
}
|
||||
});
|
||||
final Player player = attacker.getController();
|
||||
Card enchantment = null;
|
||||
if (player.isHuman()) {
|
||||
final Card[] target = new Card[enchantments.size()];
|
||||
for (int j = 0; j < enchantments.size(); j++) {
|
||||
final Card crd = enchantments.get(j);
|
||||
target[j] = crd;
|
||||
}
|
||||
final Object check = GuiChoose.oneOrNone(
|
||||
"Select enchantment to enchant exalted creature", target);
|
||||
if (check != null) {
|
||||
enchantment = ((Card) check);
|
||||
}
|
||||
} else {
|
||||
enchantment = ComputerUtilCard.getBestEnchantmentAI(enchantments, this, false);
|
||||
public boolean apply(final Card c) {
|
||||
if (attacker.hasKeyword("Protection from enchantments")
|
||||
|| (attacker.hasKeyword("Protection from everything"))) {
|
||||
return false;
|
||||
}
|
||||
if ((enchantment != null) && attacker.isInPlay()) {
|
||||
game.getAction().changeZone(game.getZoneOf(enchantment),
|
||||
enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null);
|
||||
enchantment.enchantEntity(attacker);
|
||||
}
|
||||
attacker.getController().shuffle();
|
||||
} // resolve
|
||||
}; // ability4
|
||||
return (c.isEnchantment() && c.hasKeyword("Enchant creature") && !CardFactoryUtil
|
||||
.hasProtectionFrom(c, attacker));
|
||||
}
|
||||
});
|
||||
final Player player = attacker.getController();
|
||||
Card enchantment = null;
|
||||
if (player.isHuman()) {
|
||||
final Card[] target = new Card[enchantments.size()];
|
||||
for (int j = 0; j < enchantments.size(); j++) {
|
||||
final Card crd = enchantments.get(j);
|
||||
target[j] = crd;
|
||||
}
|
||||
final Object check = GuiChoose.oneOrNone(
|
||||
"Select enchantment to enchant exalted creature", target);
|
||||
if (check != null) {
|
||||
enchantment = ((Card) check);
|
||||
}
|
||||
} else {
|
||||
enchantment = ComputerUtilCard.getBestEnchantmentAI(enchantments, this, false);
|
||||
}
|
||||
if ((enchantment != null) && attacker.isInPlay()) {
|
||||
game.getAction().changeZone(game.getZoneOf(enchantment),
|
||||
enchantment.getOwner().getZone(ZoneType.Battlefield), enchantment, null);
|
||||
enchantment.enchantEntity(attacker);
|
||||
}
|
||||
attacker.getController().shuffle();
|
||||
} // resolve
|
||||
}; // ability4
|
||||
|
||||
final StringBuilder sb4 = new StringBuilder();
|
||||
sb4.append(c).append(
|
||||
" - (Exalted) searches library for an Aura card that could enchant that creature, ");
|
||||
sb4.append("put it onto the battlefield attached to that creature, then shuffles library.");
|
||||
ability4.setDescription(sb4.toString());
|
||||
ability4.setStackDescription(sb4.toString());
|
||||
final StringBuilder sb4 = new StringBuilder();
|
||||
sb4.append(attacker).append(
|
||||
" - (Exalted) searches library for an Aura card that could enchant that creature, ");
|
||||
sb4.append("put it onto the battlefield attached to that creature, then shuffles library.");
|
||||
ability4.setDescription(sb4.toString());
|
||||
ability4.setStackDescription(sb4.toString());
|
||||
|
||||
game.getStack().addSimultaneousStackEntry(ability4);
|
||||
} // For
|
||||
}
|
||||
game.getStack().addSimultaneousStackEntry(ability4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -268,10 +268,63 @@ public class PhaseHandler implements java.io.Serializable {
|
||||
|
||||
playerTurn.getController().declareAttackers();
|
||||
|
||||
PhaseUtil.handleDeclareAttackers(game);
|
||||
game.getCombat().verifyCreaturesInPlay();
|
||||
|
||||
// Handles removing cards like Mogg Flunkies from combat if group attack
|
||||
// didn't occur
|
||||
for (Card c1 : game.getCombat().getAttackers()) {
|
||||
if (c1.hasKeyword("CARDNAME can't attack or block alone.") && c1.isAttacking()) {
|
||||
if (game.getCombat().getAttackers().size() < 2) {
|
||||
game.getCombat().removeFromCombat(c1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO move propaganda to happen as the Attacker is Declared
|
||||
|
||||
for (final Card c2 : game.getCombat().getAttackers()) {
|
||||
boolean canAttack = CombatUtil.checkPropagandaEffects(game, c2);
|
||||
if ( canAttack ) {
|
||||
if (!c2.hasKeyword("Vigilance"))
|
||||
c2.tap();
|
||||
} else {
|
||||
game.getCombat().removeFromCombat(c2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Then run other Attacker bonuses
|
||||
// check for exalted:
|
||||
if (game.getCombat().getAttackers().size() == 1) {
|
||||
final Player attackingPlayer = game.getCombat().getAttackingPlayer();
|
||||
final Card attacker = game.getCombat().getAttackers().get(0);
|
||||
for (Card card : attackingPlayer.getCardsIn(ZoneType.Battlefield)) {
|
||||
int exaltedMagnitude = card.getKeywordAmount("Exalted");
|
||||
if (exaltedMagnitude > 0) {
|
||||
CombatUtil.executeExaltedAbility(game, attacker, exaltedMagnitude, card);
|
||||
// Make sure exalted effects get applied only once per combat
|
||||
}
|
||||
|
||||
if ("Sovereigns of Lost Alara".equals(card.getName())) {
|
||||
CombatUtil.souverignsOfAlara2ndAbility(game, attacker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
game.getGameLog().addCombatAttackers(game.getCombat());
|
||||
|
||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
||||
runParams.put("Attackers", game.getCombat().getAttackers());
|
||||
runParams.put("AttackingPlayer", game.getCombat().getAttackingPlayer());
|
||||
game.getTriggerHandler().runTrigger(TriggerType.AttackersDeclared, runParams, false);
|
||||
|
||||
for (final Card c : game.getCombat().getAttackers()) {
|
||||
CombatUtil.checkDeclareAttackers(game, c);
|
||||
}
|
||||
game.getStack().unfreezeStack();
|
||||
|
||||
this.bCombat = !game.getCombat().getAttackers().isEmpty();
|
||||
game.getStack().unfreezeStack();
|
||||
this.nCombatsThisTurn++;
|
||||
|
||||
break;
|
||||
|
||||
@@ -68,81 +68,6 @@ public class PhaseUtil {
|
||||
}
|
||||
|
||||
|
||||
// ********* Declare Attackers ***********
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* handleDeclareAttackers.
|
||||
* </p>
|
||||
*/
|
||||
public static void handleDeclareAttackers(final Game game) {
|
||||
final Combat combat = game.getCombat();
|
||||
combat.verifyCreaturesInPlay();
|
||||
|
||||
// Handles removing cards like Mogg Flunkies from combat if group attack
|
||||
// didn't occur
|
||||
final List<Card> filterList = combat.getAttackers();
|
||||
for (Card c : filterList) {
|
||||
if (c.hasKeyword("CARDNAME can't attack or block alone.") && c.isAttacking()) {
|
||||
if (combat.getAttackers().size() < 2) {
|
||||
combat.removeFromCombat(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final List<Card> list = combat.getAttackers();
|
||||
|
||||
// TODO move propaganda to happen as the Attacker is Declared
|
||||
// Remove illegal Propaganda attacks first only for attacking the Player
|
||||
|
||||
|
||||
for (final Card c : list) {
|
||||
boolean canAttack = CombatUtil.checkPropagandaEffects(game, c);
|
||||
if ( canAttack ) {
|
||||
if (!c.hasKeyword("Vigilance")) { c.tap(); }
|
||||
} else {
|
||||
game.getCombat().removeFromCombat(c);
|
||||
}
|
||||
}
|
||||
PhaseUtil.handleAttackingTriggers(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* handleAttackingTriggers.
|
||||
* </p>
|
||||
* @param game
|
||||
*/
|
||||
public static void handleAttackingTriggers(Game game) {
|
||||
final List<Card> list = game.getCombat().getAttackers();
|
||||
game.getStack().freezeStack();
|
||||
// Then run other Attacker bonuses
|
||||
// check for exalted:
|
||||
if (list.size() == 1) {
|
||||
final Player attackingPlayer = game.getCombat().getAttackingPlayer();
|
||||
final Card attacker = list.get(0);
|
||||
for (Card card : attackingPlayer.getCardsIn(ZoneType.Battlefield)) {
|
||||
int exaltedMagnitude = card.getKeywordAmount("Exalted");
|
||||
if (exaltedMagnitude > 0) {
|
||||
CombatUtil.executeExaltedAbility(game, attacker, exaltedMagnitude, card);
|
||||
// Make sure exalted effects get applied only once per combat
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
game.getGameLog().addCombatAttackers(game.getCombat());
|
||||
|
||||
final HashMap<String, Object> runParams = new HashMap<String, Object>();
|
||||
runParams.put("Attackers", list);
|
||||
runParams.put("AttackingPlayer", game.getCombat().getAttackingPlayer());
|
||||
game.getTriggerHandler().runTrigger(TriggerType.AttackersDeclared, runParams, false);
|
||||
|
||||
for (final Card c : list) {
|
||||
CombatUtil.checkDeclareAttackers(game, c);
|
||||
}
|
||||
game.getStack().unfreezeStack();
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* handleDeclareBlockers.
|
||||
|
||||
Reference in New Issue
Block a user