mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-20 12:48:00 +00:00
checkPropagandaEffects simplified due to synchronous execution
This commit is contained in:
@@ -97,7 +97,7 @@ public class Cost {
|
||||
public final ManaCost getTotalMana() {
|
||||
for (final CostPart part : this.costParts) {
|
||||
if (part instanceof CostPartMana) {
|
||||
return new ManaCost(new ManaCostParser(part.toString()));
|
||||
return ((CostPartMana) part).getManaToPay();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1122,62 +1122,36 @@ public class CombatUtil {
|
||||
* @param bLast
|
||||
* a boolean.
|
||||
*/
|
||||
public static void checkPropagandaEffects(final Card c, final boolean bLast) {
|
||||
public static void checkPropagandaEffects(final GameState game, final Card c) {
|
||||
Cost attackCost = new Cost(c, "0", true);
|
||||
final GameState game = Singletons.getModel().getGame();
|
||||
// Sort abilities to apply them in proper order
|
||||
for (Card card : Singletons.getModel().getGame().getCardsIn(ZoneType.Battlefield)) {
|
||||
for (Card card : game.getCardsIn(ZoneType.Battlefield)) {
|
||||
final ArrayList<StaticAbility> staticAbilities = card.getStaticAbilities();
|
||||
for (final StaticAbility stAb : staticAbilities) {
|
||||
Cost additionalCost = stAb.getCostAbility("CantAttackUnless", c, game.getCombat().getDefenderByAttacker(c));
|
||||
attackCost = Cost.combine(attackCost, additionalCost);
|
||||
}
|
||||
}
|
||||
if (attackCost.toSimpleString().equals("")) {
|
||||
if (!c.hasKeyword("Vigilance")) {
|
||||
c.tap();
|
||||
}
|
||||
|
||||
if (bLast) {
|
||||
PhaseUtil.handleAttackingTriggers();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
final Card crd = c;
|
||||
|
||||
|
||||
final PhaseType phase = game.getPhaseHandler().getPhase();
|
||||
|
||||
if (phase == PhaseType.COMBAT_DECLARE_ATTACKERS || phase == PhaseType.COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY) {
|
||||
final Ability ability = new AbilityStatic(c, attackCost, null) {
|
||||
@Override
|
||||
public void resolve() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
boolean hasPaid = attackCost.getTotalMana().isZero() && attackCost.isOnlyManaCost(); // true if needless to pay
|
||||
if (!hasPaid) {
|
||||
final Ability ability = new AbilityStatic(c, attackCost, null) { @Override public void resolve() {} };
|
||||
ability.setActivatingPlayer(c.getController());
|
||||
|
||||
if (c.getController().isHuman()) {
|
||||
if ( GameActionUtil.payCostDuringAbilityResolve(ability, attackCost, null, game) ) {
|
||||
if (!crd.hasKeyword("Vigilance")) { crd.tap(); }
|
||||
} else {
|
||||
game.getCombat().removeFromCombat(crd);
|
||||
}
|
||||
hasPaid = GameActionUtil.payCostDuringAbilityResolve(ability, attackCost, null, game);
|
||||
} else { // computer
|
||||
if (ComputerUtilCost.canPayCost(ability, c.getController())) {
|
||||
ComputerUtil.playNoStack((AIPlayer)c.getController(), ability, game);
|
||||
if (!crd.hasKeyword("Vigilance")) {
|
||||
crd.tap();
|
||||
}
|
||||
} else {
|
||||
// TODO remove the below line after Propaganda occurs
|
||||
// during Declare_Attackers
|
||||
game.getCombat().removeFromCombat(crd);
|
||||
hasPaid = true;
|
||||
}
|
||||
}
|
||||
if (bLast)
|
||||
PhaseUtil.handleAttackingTriggers();
|
||||
}
|
||||
|
||||
if ( hasPaid ) {
|
||||
if (!c.hasKeyword("Vigilance")) { c.tap(); }
|
||||
} else {
|
||||
game.getCombat().removeFromCombat(c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -292,7 +292,7 @@ public class PhaseHandler extends MyObservable implements java.io.Serializable {
|
||||
|
||||
case COMBAT_DECLARE_ATTACKERS_INSTANT_ABILITY:
|
||||
if (this.inCombat()) {
|
||||
PhaseUtil.handleDeclareAttackers(game.getCombat());
|
||||
PhaseUtil.handleDeclareAttackers(game);
|
||||
CombatUtil.showCombat();
|
||||
} else {
|
||||
this.setPlayersPriorityPermission(false);
|
||||
|
||||
@@ -121,7 +121,8 @@ public class PhaseUtil {
|
||||
* handleDeclareAttackers.
|
||||
* </p>
|
||||
*/
|
||||
public static void handleDeclareAttackers(Combat combat) {
|
||||
public static void handleDeclareAttackers(final GameState game) {
|
||||
final Combat combat = game.getCombat();
|
||||
combat.verifyCreaturesInPlay();
|
||||
|
||||
// Handles removing cards like Mogg Flunkies from combat if group attack
|
||||
@@ -143,9 +144,9 @@ public class PhaseUtil {
|
||||
final int size = list.size();
|
||||
for (int i = 0; i < size; i++) {
|
||||
final Card c = list.get(i);
|
||||
final boolean last = (i == (size - 1));
|
||||
CombatUtil.checkPropagandaEffects(c, last);
|
||||
CombatUtil.checkPropagandaEffects(game, c);
|
||||
}
|
||||
PhaseUtil.handleAttackingTriggers();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user