- Blank Abilities used with Unless Costs will now know the Targets from the Source Ability

- Check life cost now uses calculateAmount instead of xCount
- Added Essence Vortex
This commit is contained in:
Sol
2012-09-26 15:57:18 +00:00
parent 80c7ae0036
commit 950f79b3b9
22 changed files with 66 additions and 50 deletions

View File

@@ -541,7 +541,7 @@ public class GameAction {
public void resolve() {
if (recoverable.getController().isHuman()) {
GameActionUtil.payCostDuringAbilityResolve(abRecover, abRecover.getPayCosts(),
paidCommand, unpaidCommand);
paidCommand, unpaidCommand, null);
} else { // computer
if (ComputerUtil.canPayCost(abRecover)) {
ComputerUtil.playNoStack(abRecover);

View File

@@ -445,8 +445,9 @@ public final class GameActionUtil {
* a {@link forge.Command} object.
* @param unpaid
* a {@link forge.Command} object.
* @param sourceAbility TODO
*/
public static void payCostDuringAbilityResolve(final SpellAbility ability, final Cost cost, final Command paid, final Command unpaid) {
public static void payCostDuringAbilityResolve(final SpellAbility ability, final Cost cost, final Command paid, final Command unpaid, SpellAbility sourceAbility) {
final Card source = ability.getSourceCard();
final ArrayList<CostPart> parts = cost.getCostParts();
if (parts.size() > 1) {
@@ -464,11 +465,13 @@ public final class GameActionUtil {
}
return;
}
if (costPart instanceof CostPayLife) {
String amountString = costPart.getAmount();
//CardFactoryUtil.xCount(source, source.getSVar(amountString))
final int amount = amountString.matches("[0-9][0-9]?") ? Integer.parseInt(amountString)
: CardFactoryUtil.xCount(source, source.getSVar(amountString));
: AbilityFactory.calculateAmount(source, amountString, sourceAbility);
if (AllZone.getHumanPlayer().canPayLife(amount) && showYesNoDialog(source, "Do you want to pay "
+ amount + " life?")) {
AllZone.getHumanPlayer().payLife(amount, null);

View File

@@ -1723,16 +1723,18 @@ public class AbilityFactory {
} else {
final SpellAbility parent = AbilityFactory.findParentsTargetedCard(ability);
final ArrayList<Object> all = parent.getTarget().getTargets();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
list = new CardList();
final ArrayList<SpellAbility> sas = parent.getTarget().getTargetSAs();
for (final SpellAbility sa : sas) {
list.add(sa.getSourceCard());
if (parent != null) {
final ArrayList<Object> all = parent.getTarget().getTargets();
if (!all.isEmpty() && (all.get(0) instanceof SpellAbility)) {
list = new CardList();
final ArrayList<SpellAbility> sas = parent.getTarget().getTargetSAs();
for (final SpellAbility sa : sas) {
list.add(sa.getSourceCard());
}
} else {
final SpellAbility saTargeting = AbilityFactory.findParentsTargetedCard(ability);
list = new CardList(saTargeting.getTarget().getTargetCards());
}
} else {
final SpellAbility saTargeting = AbilityFactory.findParentsTargetedCard(ability);
list = new CardList(saTargeting.getTarget().getTargetCards());
}
}
} else if (calcX[0].startsWith("Triggered")) {
@@ -2796,10 +2798,13 @@ public class AbilityFactory {
};
if (payer.isHuman()) {
GameActionUtil.payCostDuringAbilityResolve(ability, cost, paidCommand, unpaidCommand);
GameActionUtil.payCostDuringAbilityResolve(ability, cost, paidCommand, unpaidCommand, sa);
} else {
if (ComputerUtil.canPayCost(ability) && CostUtil.checkLifeCost(cost, source, 4)
if (ComputerUtil.canPayCost(ability) && CostUtil.checkLifeCost(cost, source, 4, sa)
&& CostUtil.checkDamageCost(cost, source, 4)) {
// AI was crashing because the blank ability used to pay costs
// Didn't have any of the data on the original SA to pay dependant costs
ability.setTarget(sa.getTarget());
ComputerUtil.playNoStack(ability); // Unless cost was payed - no
// resolve
AbilityFactory.resolveSubAbilities(sa);

View File

@@ -338,7 +338,7 @@ public class AbilityFactoryAlterLife {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -756,7 +756,7 @@ public class AbilityFactoryAlterLife {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, amount)) {
if (!CostUtil.checkLifeCost(abCost, source, amount, null)) {
return false;
}
@@ -1255,7 +1255,7 @@ public class AbilityFactoryAlterLife {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 1)) {
if (!CostUtil.checkLifeCost(abCost, source, 1, null)) {
return false;
}

View File

@@ -475,7 +475,7 @@ public final class AbilityFactoryChangeZone {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -1498,7 +1498,7 @@ public final class AbilityFactoryChangeZone {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -2564,7 +2564,7 @@ public final class AbilityFactoryChangeZone {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}

View File

@@ -256,7 +256,7 @@ public class AbilityFactoryCounterMagic {
if (!CostUtil.checkSacrificeCost(abCost, source)) {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
}

View File

@@ -328,7 +328,7 @@ public class AbilityFactoryCounters {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -1006,7 +1006,7 @@ public class AbilityFactoryCounters {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -1873,7 +1873,7 @@ public class AbilityFactoryCounters {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 8)) {
if (!CostUtil.checkLifeCost(abCost, source, 8, null)) {
return false;
}

View File

@@ -384,7 +384,7 @@ public class AbilityFactoryDealDamage {
}
// temporarily disabled until better AI
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -1160,7 +1160,7 @@ public class AbilityFactoryDealDamage {
// abCost stuff that should probably be centralized...
if (abCost != null) {
// AI currently disabled for some costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
}

View File

@@ -303,7 +303,7 @@ public final class AbilityFactoryDebuff {
return false;
}
if (!CostUtil.checkLifeCost(cost, source, 40)) {
if (!CostUtil.checkLifeCost(cost, source, 40, null)) {
return false;
}

View File

@@ -229,7 +229,7 @@ public class AbilityFactoryDestroy {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -959,7 +959,7 @@ public class AbilityFactoryDestroy {
if (abCost != null) {
// AI currently disabled for some costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
}

View File

@@ -274,7 +274,7 @@ public final class AbilityFactoryPlay {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}

View File

@@ -278,7 +278,7 @@ public class AbilityFactoryPreventDamage {
final Cost cost = sa.getPayCosts();
// temporarily disabled until better AI
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(cost, hostCard, 4, null)) {
return false;
}
@@ -723,7 +723,7 @@ public class AbilityFactoryPreventDamage {
final Cost cost = sa.getPayCosts();
// temporarily disabled until better AI
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(cost, hostCard, 4, null)) {
return false;
}

View File

@@ -307,7 +307,7 @@ public final class AbilityFactoryProtection {
final Cost cost = sa.getPayCosts();
// temporarily disabled until better AI
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(cost, hostCard, 4, null)) {
return false;
}
@@ -1033,7 +1033,7 @@ public final class AbilityFactoryProtection {
final Cost cost = sa.getPayCosts();
// temporarily disabled until better AI
if (!CostUtil.checkLifeCost(cost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(cost, hostCard, 4, null)) {
return false;
}

View File

@@ -796,7 +796,7 @@ public class AbilityFactoryPump {
final Cost cost = sa.getPayCosts();
final PhaseHandler ph = Singletons.getModel().getGameState().getPhaseHandler();
if (!CostUtil.checkLifeCost(cost, sa.getSourceCard(), 4)) {
if (!CostUtil.checkLifeCost(cost, sa.getSourceCard(), 4, null)) {
return false;
}

View File

@@ -267,7 +267,7 @@ public class AbilityFactoryRegenerate {
final Cost abCost = af.getAbCost();
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(abCost, hostCard, 4, null)) {
return false;
}
@@ -713,7 +713,7 @@ public class AbilityFactoryRegenerate {
return false;
}
if (!CostUtil.checkLifeCost(abCost, hostCard, 4)) {
if (!CostUtil.checkLifeCost(abCost, hostCard, 4, null)) {
return false;
}
}

View File

@@ -1288,7 +1288,7 @@ public final class AbilityFactoryReveal {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -2272,7 +2272,7 @@ public final class AbilityFactoryReveal {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}

View File

@@ -855,7 +855,7 @@ public class AbilityFactorySacrifice {
if (abCost != null) {
// AI currently disabled for some costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
}

View File

@@ -351,7 +351,7 @@ public class AbilityFactoryToken extends AbilityFactory {
}
if (cost != null) {
if (!CostUtil.checkLifeCost(cost, source, 4)) {
if (!CostUtil.checkLifeCost(cost, source, 4, null)) {
return false;
}

View File

@@ -303,7 +303,7 @@ public class AbilityFactoryZoneAffecting {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -864,7 +864,7 @@ public class AbilityFactoryZoneAffecting {
if (abCost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}
@@ -1572,7 +1572,7 @@ public class AbilityFactoryZoneAffecting {
return false;
}
if (!CostUtil.checkLifeCost(abCost, source, 4)) {
if (!CostUtil.checkLifeCost(abCost, source, 4, null)) {
return false;
}

View File

@@ -136,16 +136,24 @@ public class CostUtil {
* the source
* @param remainingLife
* the remaining life
* @param sourceAbility TODO
* @return true, if successful
*/
public static boolean checkLifeCost(final Cost cost, final Card source, final int remainingLife) {
public static boolean checkLifeCost(final Cost cost, final Card source, final int remainingLife, SpellAbility sourceAbility) {
// TODO - Pass in SA for everything else that calls this function
if (cost == null) {
return true;
}
for (final CostPart part : cost.getCostParts()) {
if (part instanceof CostPayLife) {
final CostPayLife payLife = (CostPayLife) part;
if ((AllZone.getComputerPlayer().getLife() - payLife.convertAmount()) < remainingLife) {
Integer amount = payLife.convertAmount();
if (amount == null) {
amount = AbilityFactory.calculateAmount(source, payLife.getAmount(), sourceAbility);
}
if ((AllZone.getComputerPlayer().getLife() - amount) < remainingLife) {
return false;
}
}

View File

@@ -327,7 +327,7 @@ public class SpellPermanent extends Spell {
if (cost != null) {
// AI currently disabled for these costs
if (!CostUtil.checkLifeCost(cost, card, 4)) {
if (!CostUtil.checkLifeCost(cost, card, 4, null)) {
return false;
}

View File

@@ -194,7 +194,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
public void resolve() {
if (c.getController().isHuman()) {
Cost cost = new Cost(c, c.getEchoCost().trim(), true);
GameActionUtil.payCostDuringAbilityResolve(blankAbility, cost, paidCommand, unpaidCommand);
GameActionUtil.payCostDuringAbilityResolve(blankAbility, cost, paidCommand, unpaidCommand, null);
} else { // computer
if (ComputerUtil.canPayCost(blankAbility)) {
ComputerUtil.playNoStack(blankAbility);
@@ -371,7 +371,7 @@ public class Upkeep extends Phase implements java.io.Serializable {
public void resolve() {
if (controller.isHuman()) {
GameActionUtil.payCostDuringAbilityResolve(blankAbility, blankAbility.getPayCosts(),
paidCommand, unpaidCommand);
paidCommand, unpaidCommand, null);
} else { // computer
if (ComputerUtil.shouldPayCost(c, upkeepCost) && ComputerUtil.canPayCost(blankAbility)) {
ComputerUtil.playNoStack(blankAbility);