- Started adding doTrigger functions to Spell AF's, because canPlayAI is not suited for cases like a spell revealed by a Cascade ability. First AF to test this is AF DealDamage.

This commit is contained in:
Sloth
2012-01-14 09:32:04 +00:00
parent 32f72a0c4e
commit 33304bcc1f
2 changed files with 21 additions and 11 deletions

View File

@@ -155,7 +155,7 @@ public final class GameActionUtil {
final ArrayList<SpellAbility> choices = cascadedCard.getBasicSpells(); final ArrayList<SpellAbility> choices = cascadedCard.getBasicSpells();
for (final SpellAbility sa : choices) { for (final SpellAbility sa : choices) {
if (sa.canPlayAI()) { if (sa.canPlayAI() || sa.doTrigger(false)) {
ComputerUtil.playStackFree(sa); ComputerUtil.playStackFree(sa);
revealed.remove(cascadedCard); revealed.remove(cascadedCard);
break; break;

View File

@@ -139,6 +139,11 @@ public class AbilityFactoryDealDamage {
AbilityFactoryDealDamage.this.dealDamageResolve(this); AbilityFactoryDealDamage.this.dealDamageResolve(this);
} }
@Override
public boolean doTrigger(final boolean mandatory) {
return AbilityFactoryDealDamage.this.dealDamageDoTriggerAINoCost(
AbilityFactoryDealDamage.this.abilityFactory, this, mandatory);
}
}; // Spell }; // Spell
return spDealDamage; return spDealDamage;
@@ -514,7 +519,7 @@ public class AbilityFactoryDealDamage {
return this.damageChooseNontargeted(saMe, dmg); return this.damageChooseNontargeted(saMe, dmg);
} }
return this.damageChoosingTargets(saMe, tgt, dmg, false); return this.damageChoosingTargets(saMe, tgt, dmg, false, false);
} }
/** /**
@@ -533,7 +538,7 @@ public class AbilityFactoryDealDamage {
* @return a boolean. * @return a boolean.
*/ */
private boolean damageChoosingTargets(final SpellAbility saMe, final Target tgt, final int dmg, private boolean damageChoosingTargets(final SpellAbility saMe, final Target tgt, final int dmg,
final boolean mandatory) { final boolean isTrigger, final boolean mandatory) {
final boolean noPrevention = this.abilityFactory.getMapParams().containsKey("NoPrevention"); final boolean noPrevention = this.abilityFactory.getMapParams().containsKey("NoPrevention");
// target loop // target loop
@@ -562,9 +567,9 @@ public class AbilityFactoryDealDamage {
// TODO: add check here if card is about to die from something // TODO: add check here if card is about to die from something
// on the stack // on the stack
// or from taking combat damage // or from taking combat damage
final boolean freePing = mandatory || (tgt.getNumTargeted() > 0 final boolean freePing = isTrigger || saMe.getPayCosts() == null || tgt.getNumTargeted() > 0
|| (AllZone.getPhase().is(Constant.Phase.END_OF_TURN) && saMe.isAbility() || (AllZone.getPhase().is(Constant.Phase.END_OF_TURN) && saMe.isAbility()
&& AllZone.getPhase().isNextTurn(AllZone.getComputerPlayer()))); && AllZone.getPhase().isNextTurn(AllZone.getComputerPlayer()));
if (freePing && tgt.addTarget(AllZone.getHumanPlayer())) { if (freePing && tgt.addTarget(AllZone.getHumanPlayer())) {
continue; continue;
@@ -581,8 +586,9 @@ public class AbilityFactoryDealDamage {
// because we can // because we can
else if (tgt.canTgtPlayer() && ((AllZone.getPhase().is(Constant.Phase.END_OF_TURN) else if (tgt.canTgtPlayer() && ((AllZone.getPhase().is(Constant.Phase.END_OF_TURN)
&& AllZone.getPhase().isNextTurn(AllZone.getComputerPlayer())) && AllZone.getPhase().isNextTurn(AllZone.getComputerPlayer()))
|| saMe.getPayCosts() == null)) { || saMe.getPayCosts() == null || isTrigger)) {
if (tgt.addTarget(AllZone.getHumanPlayer())) { if (tgt.addTarget(AllZone.getHumanPlayer())) {
System.out.println(saMe.getSourceCard() + "damageChoosingTargets");
continue; continue;
} }
} }
@@ -687,6 +693,13 @@ public class AbilityFactoryDealDamage {
return true; return true;
} }
private boolean dealDamageDoTriggerAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
if (!ComputerUtil.canPayCost(sa) && !mandatory) {
return false;
}
return dealDamageDoTriggerAINoCost(af, sa, mandatory);
}
/** /**
* <p> * <p>
* damageDoTriggerAI. * damageDoTriggerAI.
@@ -700,10 +713,7 @@ public class AbilityFactoryDealDamage {
* a boolean. * a boolean.
* @return a boolean. * @return a boolean.
*/ */
private boolean dealDamageDoTriggerAI(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) { private boolean dealDamageDoTriggerAINoCost(final AbilityFactory af, final SpellAbility sa, final boolean mandatory) {
if (!ComputerUtil.canPayCost(sa) && !mandatory) {
return false;
}
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
int dmg; int dmg;
@@ -722,7 +732,7 @@ public class AbilityFactoryDealDamage {
return false; return false;
} }
} else { } else {
if (!this.damageChoosingTargets(sa, tgt, dmg, mandatory) && !mandatory) { if (!this.damageChoosingTargets(sa, tgt, dmg, true, mandatory) && !mandatory) {
return false; return false;
} }