From ed266ae235bc25c6dae06352c2c07cc68fd399eb Mon Sep 17 00:00:00 2001 From: jendave Date: Sun, 7 Aug 2011 00:50:48 +0000 Subject: [PATCH] - Updated sacrifice cost AI in more AF's. --- .../AbilityFactory_CounterMagic.java | 21 +++++++++++++++++-- .../AbilityFactory_Counters.java | 18 ++++++++++++---- .../AbilityFactory_DealDamage.java | 11 +++++++--- .../AbilityFactory_Destroy.java | 9 ++++++-- 4 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java b/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java index 192ff371de6..4fea29cb399 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java +++ b/src/forge/card/abilityFactory/AbilityFactory_CounterMagic.java @@ -17,6 +17,7 @@ import forge.card.cardFactory.CardFactoryUtil; import forge.card.spellability.Ability; import forge.card.spellability.Ability_Activated; import forge.card.spellability.Ability_Sub; +import forge.card.spellability.Cost; import forge.card.spellability.Spell; import forge.card.spellability.SpellAbility; import forge.card.spellability.Target; @@ -143,10 +144,28 @@ public class AbilityFactory_CounterMagic { private boolean counterCanPlayAI(final AbilityFactory af, final SpellAbility sa){ boolean toReturn = true; + Cost abCost = af.getAbCost(); + final Card source = sa.getSourceCard(); if(AllZone.Stack.size() < 1) { return false; } + if (abCost != null){ + // AI currently disabled for these costs + if (abCost.getSacCost() && !abCost.getSacThis()){ + //only sacrifice something that's supposed to be sacrificed + String type = abCost.getSacType(); + CardList typeList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + typeList = typeList.getValidCards(type.split(","), source.getController(), source); + if(ComputerUtil.getCardPreference(source, "SacCost", typeList) == null) + return false; + } + if (abCost.getLifeCost()){ + if (AllZone.ComputerPlayer.getLife() - abCost.getLifeAmount() < 4) + return false; + } + } + SpellAbility topSA = AllZone.Stack.peek(); if (!CardFactoryUtil.isCounterable(topSA.getSourceCard()) || topSA.getActivatingPlayer().isComputer()) return false; @@ -155,11 +174,9 @@ public class AbilityFactory_CounterMagic { tgt.resetTargets(); if (Target_Selection.matchSpellAbility(sa, topSA, tgt)) tgt.addTarget(topSA); - else return false; - Card source = sa.getSourceCard(); if (unlessCost != null){ // Is this Usable Mana Sources? Or Total Available Mana? int usableManaSources = CardFactoryUtil.getUsableManaSources(AllZone.HumanPlayer); diff --git a/src/forge/card/abilityFactory/AbilityFactory_Counters.java b/src/forge/card/abilityFactory/AbilityFactory_Counters.java index 1726bce71c2..5396bd41b09 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_Counters.java +++ b/src/forge/card/abilityFactory/AbilityFactory_Counters.java @@ -205,8 +205,13 @@ public class AbilityFactory_Counters { if (abCost != null){ // AI currently disabled for these costs - if (abCost.getSacCost()){ - return false; + if (abCost.getSacCost() && !abCost.getSacThis()){ + //only sacrifice something that's supposed to be sacrificed + String sacType = abCost.getSacType(); + CardList typeList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + typeList = typeList.getValidCards(sacType.split(","), source.getController(), source); + if(ComputerUtil.getCardPreference(source, "SacCost", typeList) == null) + return false; } if (abCost.getLifeCost()) return false; if (abCost.getDiscardCost()) return false; @@ -661,8 +666,13 @@ public class AbilityFactory_Counters { if (abCost != null){ // AI currently disabled for these costs - if (abCost.getSacCost()){ - return false; + if (abCost.getSacCost() && !abCost.getSacThis()){ + //only sacrifice something that's supposed to be sacrificed + String sacType = abCost.getSacType(); + CardList typeList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + typeList = typeList.getValidCards(sacType.split(","), source.getController(), source); + if(ComputerUtil.getCardPreference(source, "SacCost", typeList) == null) + return false; } if (abCost.getLifeCost()) return false; if (abCost.getDiscardCost()) return false; diff --git a/src/forge/card/abilityFactory/AbilityFactory_DealDamage.java b/src/forge/card/abilityFactory/AbilityFactory_DealDamage.java index 369dcfd756b..a2f329462af 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_DealDamage.java +++ b/src/forge/card/abilityFactory/AbilityFactory_DealDamage.java @@ -196,6 +196,7 @@ public class AbilityFactory_DealDamage { if (!ComputerUtil.canPayCost(saMe)) return false; + Cost abCost = AF.getAbCost(); Card source = saMe.getSourceCard(); int dmg = 0; @@ -209,9 +210,13 @@ public class AbilityFactory_DealDamage { boolean rr = AF.isSpell(); // temporarily disabled until better AI - if (AF.getAbCost().getSacCost()) { - if(AF.getHostCard().isCreature() && AllZone.HumanPlayer.getLife() - dmg > 0) // only if damage from this ability would kill the human - return false; + if (abCost.getSacCost() && !abCost.getSacThis() && AllZone.HumanPlayer.getLife() - dmg > 0){ + //only sacrifice something that's supposed to be sacrificed + String sacType = abCost.getSacType(); + CardList typeList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + typeList = typeList.getValidCards(sacType.split(","), source.getController(), source); + if(ComputerUtil.getCardPreference(source, "SacCost", typeList) == null) + return false; } if (AF.getAbCost().getSubCounter()) { // +1/+1 counters only if damage from this ability would kill the human, otherwise ok diff --git a/src/forge/card/abilityFactory/AbilityFactory_Destroy.java b/src/forge/card/abilityFactory/AbilityFactory_Destroy.java index 61be26b7a28..518579474ea 100644 --- a/src/forge/card/abilityFactory/AbilityFactory_Destroy.java +++ b/src/forge/card/abilityFactory/AbilityFactory_Destroy.java @@ -141,8 +141,13 @@ public class AbilityFactory_Destroy { if (abCost != null){ // AI currently disabled for some costs - if (abCost.getSacCost() && source.isCreature()){ - return false; + if (abCost.getSacCost() && !abCost.getSacThis()){ + //only sacrifice something that's supposed to be sacrificed + String sacType = abCost.getSacType(); + CardList typeList = AllZoneUtil.getPlayerCardsInPlay(AllZone.ComputerPlayer); + typeList = typeList.getValidCards(sacType.split(","), source.getController(), source); + if(ComputerUtil.getCardPreference(source, "SacCost", typeList) == null) + return false; } if (abCost.getLifeCost()){ if (AllZone.ComputerPlayer.getLife() - abCost.getLifeAmount() < 4)