mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- CheckStyle.
This commit is contained in:
@@ -42,14 +42,14 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
final Random r = MyRandom.getRandom();
|
final Random r = MyRandom.getRandom();
|
||||||
final Cost abCost = sa.getPayCosts();
|
final Cost abCost = sa.getPayCosts();
|
||||||
final Card source = sa.getSourceCard();
|
final Card source = sa.getSourceCard();
|
||||||
|
|
||||||
if (abCost != null) {
|
if (abCost != null) {
|
||||||
// No Aura spells have Additional Costs
|
// No Aura spells have Additional Costs
|
||||||
}
|
}
|
||||||
|
|
||||||
// prevent run-away activations - first time will always return true
|
// prevent run-away activations - first time will always return true
|
||||||
final boolean chance = r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
final boolean chance = r.nextFloat() <= Math.pow(.6667, sa.getActivationsThisTurn());
|
||||||
|
|
||||||
// Attach spells always have a target
|
// Attach spells always have a target
|
||||||
final Target tgt = sa.getTarget();
|
final Target tgt = sa.getTarget();
|
||||||
if (tgt != null) {
|
if (tgt != null) {
|
||||||
@@ -58,24 +58,24 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (abCost.getTotalMana().contains("X") && source.getSVar("X").equals("Count$xPaid")) {
|
if (abCost.getTotalMana().contains("X") && source.getSVar("X").equals("Count$xPaid")) {
|
||||||
// Set PayX here to maximum value. (Endless Scream and Venarian
|
// Set PayX here to maximum value. (Endless Scream and Venarian
|
||||||
// Gold)
|
// Gold)
|
||||||
final int xPay = ComputerUtil.determineLeftoverMana(sa, ai);
|
final int xPay = ComputerUtil.determineLeftoverMana(sa, ai);
|
||||||
|
|
||||||
if (xPay == 0) {
|
if (xPay == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.setSVar("PayX", Integer.toString(xPay));
|
source.setSVar("PayX", Integer.toString(xPay));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
|
if (Singletons.getModel().getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
|
||||||
&& !"Curse".equals(sa.getParam("AILogic"))) {
|
&& !"Curse".equals(sa.getParam("AILogic"))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return chance;
|
return chance;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,7 +92,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO If Not Mandatory, make sure the card is "good enough"
|
// TODO If Not Mandatory, make sure the card is "good enough"
|
||||||
if (c.isCreature()) {
|
if (c.isCreature()) {
|
||||||
final int eval = CardFactoryUtil.evaluateCreature(c);
|
final int eval = CardFactoryUtil.evaluateCreature(c);
|
||||||
@@ -100,7 +100,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CardFactoryUtil.getWorstPermanentAI(list, true, true, true, false);
|
return CardFactoryUtil.getWorstPermanentAI(list, true, true, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,7 +134,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return CardFactoryUtil.getBestAI(list);
|
return CardFactoryUtil.getBestAI(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,31 +154,31 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
private static Card attachAIChangeTypePreference(final SpellAbility sa, List<Card> list, final boolean mandatory,
|
private static Card attachAIChangeTypePreference(final SpellAbility sa, List<Card> list, final boolean mandatory,
|
||||||
final Card attachSource) {
|
final Card attachSource) {
|
||||||
// AI For Cards like Evil Presence or Spreading Seas
|
// AI For Cards like Evil Presence or Spreading Seas
|
||||||
|
|
||||||
String type = "";
|
String type = "";
|
||||||
|
|
||||||
for (final StaticAbility stAb : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAb : attachSource.getStaticAbilities()) {
|
||||||
final HashMap<String, String> stab = stAb.getMapParams();
|
final HashMap<String, String> stab = stAb.getMapParams();
|
||||||
if (stab.get("Mode").equals("Continuous") && stab.containsKey("AddType")) {
|
if (stab.get("Mode").equals("Continuous") && stab.containsKey("AddType")) {
|
||||||
type = stab.get("AddType");
|
type = stab.get("AddType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
list = CardLists.getNotType(list, type); // Filter out Basic Lands that have the
|
list = CardLists.getNotType(list, type); // Filter out Basic Lands that have the
|
||||||
// same type as the changing type
|
// same type as the changing type
|
||||||
|
|
||||||
final Card c = CardFactoryUtil.getBestAI(list);
|
final Card c = CardFactoryUtil.getBestAI(list);
|
||||||
|
|
||||||
// TODO Port over some of the existing code, but rewrite most of it.
|
// TODO Port over some of the existing code, but rewrite most of it.
|
||||||
// Ultimately, these spells need to be used to reduce mana base of a
|
// Ultimately, these spells need to be used to reduce mana base of a
|
||||||
// color. So it might be better to choose a Basic over a Nonbasic
|
// color. So it might be better to choose a Basic over a Nonbasic
|
||||||
// Although a nonbasic card with a nasty ability, might be worth it to
|
// Although a nonbasic card with a nasty ability, might be worth it to
|
||||||
// cast on
|
// cast on
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return acceptableChoice(c, mandatory);
|
return acceptableChoice(c, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,16 +204,16 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (c.isCreature() && c.hasKeyword("Vigilance") && c.isUntapped()) {
|
if (c.isCreature() && c.hasKeyword("Vigilance") && c.isUntapped()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!c.isEnchanted()) {
|
if (!c.isEnchanted()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final ArrayList<Card> auras = c.getEnchantedBy();
|
final ArrayList<Card> auras = c.getEnchantedBy();
|
||||||
final Iterator<Card> itr = auras.iterator();
|
final Iterator<Card> itr = auras.iterator();
|
||||||
while (itr.hasNext()) {
|
while (itr.hasNext()) {
|
||||||
final Card aura = itr.next();
|
final Card aura = itr.next();
|
||||||
SpellAbility auraSA = aura.getSpellPermanent();
|
SpellAbility auraSA = aura.getSpellPermanent();
|
||||||
if (auraSA.getApi() == ApiType.Attach) {
|
if (auraSA.getApi() == ApiType.Attach) {
|
||||||
if ("KeepTapped".equals(auraSA.getParam("AILogic"))) {
|
if ("KeepTapped".equals(auraSA.getParam("AILogic"))) {
|
||||||
// Don't attach multiple KeepTapped Auras to one
|
// Don't attach multiple KeepTapped Auras to one
|
||||||
@@ -222,17 +222,17 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
final Card c = CardFactoryUtil.getBestAI(prefList);
|
final Card c = CardFactoryUtil.getBestAI(prefList);
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return acceptableChoice(c, mandatory);
|
return acceptableChoice(c, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,26 +250,26 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
private static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa,
|
private static Player attachToPlayerAIPreferences(final Player aiPlayer, final SpellAbility sa,
|
||||||
final boolean mandatory) {
|
final boolean mandatory) {
|
||||||
Player p;
|
Player p;
|
||||||
|
|
||||||
if (sa.isCurse()) {
|
if (sa.isCurse()) {
|
||||||
p = aiPlayer.getOpponent();
|
p = aiPlayer.getOpponent();
|
||||||
} else {
|
} else {
|
||||||
p = aiPlayer;
|
p = aiPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.canTarget(p)) {
|
if (sa.canTarget(p)) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mandatory) {
|
if (!mandatory) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
p = p.getOpponent();
|
p = p.getOpponent();
|
||||||
if (sa.canTarget(p)) {
|
if (sa.canTarget(p)) {
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,15 +298,15 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card c = CardFactoryUtil.getMostExpensivePermanentAI(betterList);
|
final Card c = CardFactoryUtil.getMostExpensivePermanentAI(betterList);
|
||||||
|
|
||||||
// If Mandatory (brought directly into play without casting) gotta
|
// If Mandatory (brought directly into play without casting) gotta
|
||||||
// choose something
|
// choose something
|
||||||
if (c == null && mandatory) {
|
if (c == null && mandatory) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,23 +327,23 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
private static Card attachAIControlPreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
private static Card attachAIControlPreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
||||||
final Card attachSource) {
|
final Card attachSource) {
|
||||||
// AI For choosing a Card to Gain Control of.
|
// AI For choosing a Card to Gain Control of.
|
||||||
|
|
||||||
if (sa.getTarget().canTgtPermanent()) {
|
if (sa.getTarget().canTgtPermanent()) {
|
||||||
// If can target all Permanents, and Life isn't in eminent danger,
|
// If can target all Permanents, and Life isn't in eminent danger,
|
||||||
// grab Planeswalker first, then Creature
|
// grab Planeswalker first, then Creature
|
||||||
// if Life < 5 grab Creature first, then Planeswalker. Lands,
|
// if Life < 5 grab Creature first, then Planeswalker. Lands,
|
||||||
// Enchantments and Artifacts are probably "not good enough"
|
// Enchantments and Artifacts are probably "not good enough"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card c = CardFactoryUtil.getBestAI(list);
|
final Card c = CardFactoryUtil.getBestAI(list);
|
||||||
|
|
||||||
// If Mandatory (brought directly into play without casting) gotta
|
// If Mandatory (brought directly into play without casting) gotta
|
||||||
// choose something
|
// choose something
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return acceptableChoice(c, mandatory);
|
return acceptableChoice(c, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,7 +363,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
private static Card attachAICursePreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
private static Card attachAICursePreference(final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
||||||
final Card attachSource) {
|
final Card attachSource) {
|
||||||
// AI For choosing a Card to Curse of.
|
// AI For choosing a Card to Curse of.
|
||||||
|
|
||||||
// TODO Figure out some way to combine The "gathering of data" from
|
// TODO Figure out some way to combine The "gathering of data" from
|
||||||
// statics used in both Pump and Curse
|
// statics used in both Pump and Curse
|
||||||
String stCheck = null;
|
String stCheck = null;
|
||||||
@@ -372,21 +372,21 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
} else if (attachSource.isEquipment()) {
|
} else if (attachSource.isEquipment()) {
|
||||||
stCheck = "EquippedBy";
|
stCheck = "EquippedBy";
|
||||||
}
|
}
|
||||||
|
|
||||||
int totToughness = 0;
|
int totToughness = 0;
|
||||||
// int totPower = 0;
|
// int totPower = 0;
|
||||||
final ArrayList<String> keywords = new ArrayList<String>();
|
final ArrayList<String> keywords = new ArrayList<String>();
|
||||||
// boolean grantingAbilities = false;
|
// boolean grantingAbilities = false;
|
||||||
|
|
||||||
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
||||||
final Map<String, String> stabMap = stAbility.getMapParams();
|
final Map<String, String> stabMap = stAbility.getMapParams();
|
||||||
|
|
||||||
if (!stabMap.get("Mode").equals("Continuous")) {
|
if (!stabMap.get("Mode").equals("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String affected = stabMap.get("Affected");
|
final String affected = stabMap.get("Affected");
|
||||||
|
|
||||||
if (affected == null) {
|
if (affected == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -394,9 +394,9 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
totToughness += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddToughness"));
|
totToughness += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddToughness"));
|
||||||
// totPower += CardFactoryUtil.parseSVar(attachSource,
|
// totPower += CardFactoryUtil.parseSVar(attachSource,
|
||||||
// sa.get("AddPower"));
|
// sa.get("AddPower"));
|
||||||
|
|
||||||
// grantingAbilities |= sa.containsKey("AddAbility");
|
// grantingAbilities |= sa.containsKey("AddAbility");
|
||||||
|
|
||||||
final String kws = stabMap.get("AddKeyword");
|
final String kws = stabMap.get("AddKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
for (final String kw : kws.split(" & ")) {
|
for (final String kw : kws.split(" & ")) {
|
||||||
@@ -405,7 +405,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> prefList = null;
|
List<Card> prefList = null;
|
||||||
if (totToughness < 0) {
|
if (totToughness < 0) {
|
||||||
// Kill a creature if we can
|
// Kill a creature if we can
|
||||||
@@ -416,7 +416,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (!c.hasKeyword("Indestructible") && (c.getLethalDamage() <= Math.abs(tgh))) {
|
if (!c.hasKeyword("Indestructible") && (c.getLethalDamage() <= Math.abs(tgh))) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.getNetDefense() <= Math.abs(tgh);
|
return c.getNetDefense() <= Math.abs(tgh);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -430,7 +430,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!keywords.isEmpty()) {
|
if (!keywords.isEmpty()) {
|
||||||
// Don't give Can't Attack or Defender to cards that can't do these
|
// Don't give Can't Attack or Defender to cards that can't do these
|
||||||
// things to begin with
|
// things to begin with
|
||||||
@@ -444,18 +444,17 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
c = CardFactoryUtil.getBestAI(prefList);
|
c = CardFactoryUtil.getBestAI(prefList);
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return acceptableChoice(c, mandatory);
|
return acceptableChoice(c, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attach do trigger ai.
|
* Attach do trigger ai.
|
||||||
* @param sa
|
* @param sa
|
||||||
@@ -476,14 +475,14 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (tgt == null) {
|
if (tgt == null) {
|
||||||
targets = AbilityFactory.getDefinedObjects(sa.getSourceCard(), sa.getParam("Defined"), sa);
|
targets = AbilityFactory.getDefinedObjects(sa.getSourceCard(), sa.getParam("Defined"), sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mandatory && card.isEquipment() && !targets.isEmpty()) {
|
if (!mandatory && card.isEquipment() && !targets.isEmpty()) {
|
||||||
Card newTarget = (Card) targets.get(0);
|
Card newTarget = (Card) targets.get(0);
|
||||||
//don't equip human creatures
|
//don't equip human creatures
|
||||||
if (newTarget.getController().isHuman()) {
|
if (newTarget.getController().isHuman()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//don't equip a worse creature
|
//don't equip a worse creature
|
||||||
if (card.isEquipping()) {
|
if (card.isEquipping()) {
|
||||||
Card oldTarget = card.getEquipping().get(0);
|
Card oldTarget = card.getEquipping().get(0);
|
||||||
@@ -492,7 +491,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -518,11 +517,11 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
} else {
|
} else {
|
||||||
o = attachToCardAIPreferences(sa.getActivatingPlayer(), sa, mandatory);
|
o = attachToCardAIPreferences(sa.getActivatingPlayer(), sa, mandatory);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
tgt.addTarget(o);
|
tgt.addTarget(o);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -551,7 +550,9 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
magnetList = CardLists.filter(list, new Predicate<Card>() {
|
magnetList = CardLists.filter(list, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
if ( !c.isCreature() ) return false;
|
if (!c.isCreature()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
String sVar = c.getSVar("EnchantMe");
|
String sVar = c.getSVar("EnchantMe");
|
||||||
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEnchanted());
|
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEnchanted());
|
||||||
}
|
}
|
||||||
@@ -561,51 +562,53 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
magnetList = CardLists.filter(list, new Predicate<Card>() {
|
magnetList = CardLists.filter(list, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
if ( !c.isCreature() ) return false;
|
if (!c.isCreature()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
String sVar = c.getSVar("EquipMe");
|
String sVar = c.getSVar("EquipMe");
|
||||||
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEquipped());
|
return sVar.equals("Multiple") || (sVar.equals("Once") && !c.isEquipped());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((magnetList != null) && !magnetList.isEmpty()) {
|
if ((magnetList != null) && !magnetList.isEmpty()) {
|
||||||
// Always choose something from the Magnet List.
|
// Always choose something from the Magnet List.
|
||||||
// Probably want to "weight" the list by amount of Enchantments and
|
// Probably want to "weight" the list by amount of Enchantments and
|
||||||
// choose the "lightest"
|
// choose the "lightest"
|
||||||
|
|
||||||
magnetList = CardLists.filter(magnetList, new Predicate<Card>() {
|
magnetList = CardLists.filter(magnetList, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(final Card c) {
|
public boolean apply(final Card c) {
|
||||||
return CombatUtil.canAttack(c, ai.getOpponent());
|
return CombatUtil.canAttack(c, ai.getOpponent());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return CardFactoryUtil.getBestAI(magnetList);
|
return CardFactoryUtil.getBestAI(magnetList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int totToughness = 0;
|
int totToughness = 0;
|
||||||
int totPower = 0;
|
int totPower = 0;
|
||||||
final ArrayList<String> keywords = new ArrayList<String>();
|
final ArrayList<String> keywords = new ArrayList<String>();
|
||||||
boolean grantingAbilities = false;
|
boolean grantingAbilities = false;
|
||||||
|
|
||||||
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
for (final StaticAbility stAbility : attachSource.getStaticAbilities()) {
|
||||||
final Map<String, String> stabMap = stAbility.getMapParams();
|
final Map<String, String> stabMap = stAbility.getMapParams();
|
||||||
|
|
||||||
if (!stabMap.get("Mode").equals("Continuous")) {
|
if (!stabMap.get("Mode").equals("Continuous")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String affected = stabMap.get("Affected");
|
final String affected = stabMap.get("Affected");
|
||||||
|
|
||||||
if (affected == null) {
|
if (affected == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if ((affected.contains(stCheck) || affected.contains("AttachedBy"))) {
|
if ((affected.contains(stCheck) || affected.contains("AttachedBy"))) {
|
||||||
totToughness += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddToughness"));
|
totToughness += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddToughness"));
|
||||||
totPower += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddPower"));
|
totPower += CardFactoryUtil.parseSVar(attachSource, stabMap.get("AddPower"));
|
||||||
|
|
||||||
grantingAbilities |= stabMap.containsKey("AddAbility");
|
grantingAbilities |= stabMap.containsKey("AddAbility");
|
||||||
|
|
||||||
String kws = stabMap.get("AddKeyword");
|
String kws = stabMap.get("AddKeyword");
|
||||||
if (kws != null) {
|
if (kws != null) {
|
||||||
for (final String kw : kws.split(" & ")) {
|
for (final String kw : kws.split(" & ")) {
|
||||||
@@ -620,7 +623,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> prefList = new ArrayList<Card>(list);
|
List<Card> prefList = new ArrayList<Card>(list);
|
||||||
if (totToughness < 0) {
|
if (totToughness < 0) {
|
||||||
// Don't kill my own stuff with Negative toughness Auras
|
// Don't kill my own stuff with Negative toughness Auras
|
||||||
@@ -632,7 +635,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//only add useful keywords unless P/T bonus is significant
|
//only add useful keywords unless P/T bonus is significant
|
||||||
if (totToughness + totPower < 4 && !keywords.isEmpty()) {
|
if (totToughness + totPower < 4 && !keywords.isEmpty()) {
|
||||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
||||||
@@ -642,7 +645,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't pump cards that will die.
|
// Don't pump cards that will die.
|
||||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
||||||
@Override
|
@Override
|
||||||
@@ -650,13 +653,13 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
return !c.getSVar("Targeting").equals("Dies");
|
return !c.getSVar("Targeting").equals("Dies");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (attachSource.isAura()) {
|
if (attachSource.isAura()) {
|
||||||
// TODO For Auras like Rancor, that aren't as likely to lead to
|
// TODO For Auras like Rancor, that aren't as likely to lead to
|
||||||
// card disadvantage, this check should be skipped
|
// card disadvantage, this check should be skipped
|
||||||
prefList = CardLists.filter(prefList, Predicates.not(Presets.ENCHANTED));
|
prefList = CardLists.filter(prefList, Predicates.not(Presets.ENCHANTED));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!grantingAbilities) {
|
if (!grantingAbilities) {
|
||||||
// Probably prefer to Enchant Creatures that Can Attack
|
// Probably prefer to Enchant Creatures that Can Attack
|
||||||
// Filter out creatures that can't Attack or have Defender
|
// Filter out creatures that can't Attack or have Defender
|
||||||
@@ -672,11 +675,11 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
// Possibly more defensive?
|
// Possibly more defensive?
|
||||||
c = CardFactoryUtil.getWorstPermanentAI(prefList, false, false, false, false);
|
c = CardFactoryUtil.getWorstPermanentAI(prefList, false, false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
return chooseLessPreferred(mandatory, list);
|
return chooseLessPreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -696,15 +699,15 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
final Card attachSource = sa.getSourceCard();
|
final Card attachSource = sa.getSourceCard();
|
||||||
// TODO AttachSource is currently set for the Source of the Spell, but
|
// TODO AttachSource is currently set for the Source of the Spell, but
|
||||||
// at some point can support attaching a different card
|
// at some point can support attaching a different card
|
||||||
|
|
||||||
// Don't equip if already equipping
|
// Don't equip if already equipping
|
||||||
if (attachSource.getEquippingCard() != null && attachSource.getEquippingCard().getController().isComputer()) {
|
if (attachSource.getEquippingCard() != null && attachSource.getEquippingCard().getController().isComputer()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Card> list = Singletons.getModel().getGame().getCardsIn(tgt.getZone());
|
List<Card> list = Singletons.getModel().getGame().getCardsIn(tgt.getZone());
|
||||||
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource);
|
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), attachSource);
|
||||||
|
|
||||||
// TODO If Attaching without casting, don't need to actually target.
|
// TODO If Attaching without casting, don't need to actually target.
|
||||||
// I believe this is the only case where mandatory will be true, so just
|
// I believe this is the only case where mandatory will be true, so just
|
||||||
// check that when starting that work
|
// check that when starting that work
|
||||||
@@ -714,7 +717,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
} else {
|
} else {
|
||||||
list = CardLists.filter(list, Predicates.not(CardPredicates.isProtectedFrom(attachSource)));
|
list = CardLists.filter(list, Predicates.not(CardPredicates.isProtectedFrom(attachSource)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -722,14 +725,14 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
if (sa.hasParam("AITgts")) {
|
if (sa.hasParam("AITgts")) {
|
||||||
prefList = CardLists.getValidCards(list, sa.getParam("AITgts"), sa.getActivatingPlayer(), attachSource);
|
prefList = CardLists.getValidCards(list, sa.getParam("AITgts"), sa.getActivatingPlayer(), attachSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
Card c = attachGeneralAI(aiPlayer, sa, prefList, mandatory, attachSource, sa.getParam("AILogic"));
|
Card c = attachGeneralAI(aiPlayer, sa, prefList, mandatory, attachSource, sa.getParam("AILogic"));
|
||||||
|
|
||||||
if ((c == null) && mandatory) {
|
if ((c == null) && mandatory) {
|
||||||
CardLists.shuffle(list);
|
CardLists.shuffle(list);
|
||||||
c = list.get(0);
|
c = list.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -751,18 +754,18 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
private static Card attachGeneralAI(final Player ai, final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
private static Card attachGeneralAI(final Player ai, final SpellAbility sa, final List<Card> list, final boolean mandatory,
|
||||||
final Card attachSource, final String logic) {
|
final Card attachSource, final String logic) {
|
||||||
Player prefPlayer = ai.getOpponent();
|
Player prefPlayer = ai.getOpponent();
|
||||||
if ("Pump".equals(logic) || "Animate".equals(logic) ) {
|
if ("Pump".equals(logic) || "Animate".equals(logic)) {
|
||||||
prefPlayer = ai;
|
prefPlayer = ai;
|
||||||
}
|
}
|
||||||
// Some ChangeType cards are beneficial, and PrefPlayer should be
|
// Some ChangeType cards are beneficial, and PrefPlayer should be
|
||||||
// changed to represent that
|
// changed to represent that
|
||||||
final List<Card> prefList = CardLists.filterControlledBy(list, prefPlayer);
|
final List<Card> prefList = CardLists.filterControlledBy(list, prefPlayer);
|
||||||
|
|
||||||
// If there are no preferred cards, and not mandatory bail out
|
// If there are no preferred cards, and not mandatory bail out
|
||||||
if (prefList.size() == 0) {
|
if (prefList.size() == 0) {
|
||||||
return chooseUnpreferred(mandatory, list);
|
return chooseUnpreferred(mandatory, list);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Preferred list has at least one card in it to make to the actual
|
// Preferred list has at least one card in it to make to the actual
|
||||||
// Logic
|
// Logic
|
||||||
Card c = null;
|
Card c = null;
|
||||||
@@ -779,7 +782,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
} else if ("Animate".equals(logic)) {
|
} else if ("Animate".equals(logic)) {
|
||||||
c = attachAIAnimatePreference(sa, prefList, mandatory, attachSource);
|
c = attachAIAnimatePreference(sa, prefList, mandatory, attachSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,7 +844,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
return true;
|
return true;
|
||||||
} else if (keyword.endsWith("Deathtouch") || keyword.endsWith("Wither")) {
|
} else if (keyword.endsWith("Deathtouch") || keyword.endsWith("Wither")) {
|
||||||
if (card.getNetCombatDamage() <= 0
|
if (card.getNetCombatDamage() <= 0
|
||||||
|| ((!CombatUtil.canBeBlocked(card) || !CombatUtil.canAttackNextTurn(card))
|
|| ((!CombatUtil.canBeBlocked(card) || !CombatUtil.canAttackNextTurn(card))
|
||||||
&& !CombatUtil.canBlock(card, true))) {
|
&& !CombatUtil.canBlock(card, true))) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -867,7 +870,7 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
} else if (keyword.equals("Trample")) {
|
} else if (keyword.equals("Trample")) {
|
||||||
if (card.getNetCombatDamage() <= 1
|
if (card.getNetCombatDamage() <= 1
|
||||||
|| !CombatUtil.canBeBlocked(card)
|
|| !CombatUtil.canBeBlocked(card)
|
||||||
|| !CombatUtil.canAttackNextTurn(card)) {
|
|| !CombatUtil.canAttackNextTurn(card)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -897,5 +900,5 @@ public class AttachAi extends SpellAiLogic {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user