mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
Optimize the logic around for attaching cards to other cards/players
This commit is contained in:
@@ -715,21 +715,19 @@ public class ComputerUtil {
|
||||
}
|
||||
|
||||
Card c;
|
||||
|
||||
if (CardLists.getNotType(remaining, "Creature").size() == 0) {
|
||||
c = ComputerUtilCard.getWorstCreatureAI(remaining);
|
||||
} else if (CardLists.getNotType(remaining, "Land").size() == 0) {
|
||||
}
|
||||
else if (CardLists.getNotType(remaining, "Land").size() == 0) {
|
||||
c = ComputerUtilCard.getWorstLand(CardLists.filter(remaining, CardPredicates.Presets.LANDS));
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
c = ComputerUtilCard.getWorstPermanentAI(remaining, false, false, false, false);
|
||||
}
|
||||
|
||||
final ArrayList<Card> auras = c.getEnchantedBy();
|
||||
|
||||
if (auras.size() > 0) {
|
||||
if (c.isEnchanted()) {
|
||||
// TODO: choose "worst" controlled enchanting Aura
|
||||
for (int j = 0; j < auras.size(); j++) {
|
||||
final Card aura = auras.get(j);
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
if (aura.getController().equals(c.getController()) && remaining.contains(aura)) {
|
||||
return aura;
|
||||
}
|
||||
|
||||
@@ -716,8 +716,10 @@ public class ComputerUtilCard {
|
||||
int curCMC = card.getCMC();
|
||||
|
||||
// Add all cost of all auras with the same controller
|
||||
final List<Card> auras = CardLists.filterControlledBy(card.getEnchantedBy(), card.getController());
|
||||
curCMC += Aggregates.sum(auras, CardPredicates.Accessors.fnGetCmc) + auras.size();
|
||||
if (card.isEnchanted()) {
|
||||
final List<Card> auras = CardLists.filterControlledBy(card.getEnchantedBy(false), card.getController());
|
||||
curCMC += Aggregates.sum(auras, CardPredicates.Accessors.fnGetCmc) + auras.size();
|
||||
}
|
||||
|
||||
if (curCMC >= bigCMC) {
|
||||
bigCMC = curCMC;
|
||||
@@ -1040,7 +1042,7 @@ public class ComputerUtilCard {
|
||||
}
|
||||
if (c.isEnchanted()) {
|
||||
boolean myEnchants = false;
|
||||
for (Card enc : c.getEnchantedBy()) {
|
||||
for (Card enc : c.getEnchantedBy(false)) {
|
||||
if (enc.getOwner().equals(ai)) {
|
||||
myEnchants = true;
|
||||
break;
|
||||
|
||||
@@ -418,11 +418,13 @@ public class ComputerUtilCombat {
|
||||
*/
|
||||
public static int totalDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
||||
int damage = 0;
|
||||
|
||||
for (Card equipment : attacker.getEquippedBy()) {
|
||||
if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) {
|
||||
defenders.remove(0);
|
||||
}
|
||||
|
||||
if (attacker.isEquipped()) {
|
||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) {
|
||||
defenders.remove(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final Card defender : defenders) {
|
||||
@@ -439,7 +441,7 @@ public class ComputerUtilCombat {
|
||||
public static int totalFirstStrikeDamageOfBlockers(final Card attacker, final List<Card> defenders) {
|
||||
int damage = 0;
|
||||
|
||||
for (Card equipment : attacker.getEquippedBy()) {
|
||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) {
|
||||
defenders.remove(0);
|
||||
}
|
||||
@@ -1567,10 +1569,12 @@ public class ComputerUtilCombat {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Card equipment : defender.getEquippedBy()) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return true;
|
||||
}
|
||||
if (defender.isEquipped()) {
|
||||
for (Card equipment : defender.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int flankingMagnitude = 0;
|
||||
@@ -1599,10 +1603,12 @@ public class ComputerUtilCombat {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Card equipment : attacker.getEquippedBy()) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return false;
|
||||
}
|
||||
if (attacker.isEquipped()) {
|
||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (attacker.hasKeyword("PreventAllDamageBy Creature.blockingSource")) {
|
||||
@@ -1729,10 +1735,12 @@ public class ComputerUtilCombat {
|
||||
final boolean withoutAbilities) {
|
||||
final Game game = ai.getGame();
|
||||
|
||||
for (Card equipment : attacker.getEquippedBy()) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return true;
|
||||
}
|
||||
if (attacker.isEquipped()) {
|
||||
for (Card equipment : attacker.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int flankingMagnitude = 0;
|
||||
@@ -1761,10 +1769,12 @@ public class ComputerUtilCombat {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Card equipment : defender.getEquippedBy()) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return false;
|
||||
}
|
||||
if (defender.isEquipped()) {
|
||||
for (Card equipment : defender.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals("Godsend")) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int defenderDamage = defender.getNetAttack()
|
||||
|
||||
@@ -16,7 +16,6 @@ import forge.util.TextUtil;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -244,13 +243,12 @@ public class ComputerUtilCost {
|
||||
final CostSacrifice sac = (CostSacrifice) part;
|
||||
|
||||
final String type = sac.getType();
|
||||
|
||||
|
||||
if (type.equals("CARDNAME")) {
|
||||
if (!important) {
|
||||
return false;
|
||||
}
|
||||
List<Card> auras = new ArrayList<Card>(source.getEnchantedBy());
|
||||
if (!CardLists.filterControlledBy(auras, source.getController()).isEmpty()) {
|
||||
if (!CardLists.filterControlledBy(source.getEnchantedBy(false), source.getController()).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
continue;
|
||||
|
||||
@@ -1118,7 +1118,7 @@ public class ComputerUtilMana {
|
||||
&& replacementEffect.zonesCheck(game.getZoneOf(crd))) {
|
||||
String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement"));
|
||||
if (repType.contains("Chosen")) {
|
||||
repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColors().get(0)));
|
||||
repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor()));
|
||||
}
|
||||
mp.setManaReplaceType(repType);
|
||||
}
|
||||
|
||||
@@ -325,9 +325,9 @@ public class AnimateAi extends SpellAbilityAi {
|
||||
if (sa.hasParam("Colors")) {
|
||||
final String colors = sa.getParam("Colors");
|
||||
if (colors.equals("ChosenColor")) {
|
||||
|
||||
tmpDesc = CardUtil.getShortColorsString(source.getChosenColors());
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
tmpDesc = CardUtil.getShortColorsString(new ArrayList<String>(Arrays.asList(colors.split(","))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ public class AttachAi extends SpellAbilityAi {
|
||||
return true;
|
||||
}
|
||||
|
||||
final ArrayList<Card> auras = c.getEnchantedBy();
|
||||
final Iterable<Card> auras = c.getEnchantedBy(false);
|
||||
final Iterator<Card> itr = auras.iterator();
|
||||
while (itr.hasNext()) {
|
||||
final Card aura = itr.next();
|
||||
@@ -626,9 +626,10 @@ public class AttachAi extends SpellAbilityAi {
|
||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
if (aura.getName().equals(attachSource.getName()))
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
if (aura.getName().equals(attachSource.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -684,9 +685,10 @@ public class AttachAi extends SpellAbilityAi {
|
||||
}
|
||||
// don't equip creatures that don't gain anything
|
||||
if (card.hasSVar("NonStackingAttachEffect")) {
|
||||
for (Card equipment : newTarget.getEquippedBy()) {
|
||||
if (equipment.getName().equals(card.getName()))
|
||||
for (Card equipment : newTarget.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals(card.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -907,13 +909,19 @@ public class AttachAi extends SpellAbilityAi {
|
||||
prefList = CardLists.filter(prefList, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card equipment : c.getEquippedBy()) {
|
||||
if (equipment.getName().equals(attachSource.getName()))
|
||||
return false;
|
||||
if (c.isEquipped()) {
|
||||
for (Card equipment : c.getEquippedBy(false)) {
|
||||
if (equipment.getName().equals(attachSource.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
if (aura.getName().equals(attachSource.getName()))
|
||||
return false;
|
||||
if (c.isEnchanted()) {
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
if (aura.getName().equals(attachSource.getName())) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -811,7 +811,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
if (aura.getController().isOpponentOf(ai)) {
|
||||
return true;
|
||||
} else {
|
||||
@@ -885,7 +885,7 @@ public class ChangeZoneAi extends SpellAbilityAi {
|
||||
list = CardLists.filter(list, new Predicate<Card>() {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
for (Card aura : c.getEnchantedBy()) {
|
||||
for (Card aura : c.getEnchantedBy(false)) {
|
||||
if (c.getOwner().isOpponentOf(ai) && aura.getController().equals(ai)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
if (sa.hasParam("LevelUp")) {
|
||||
// creatures enchanted by curse auras have low priority
|
||||
if (source.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) {
|
||||
for (Card aura : source.getEnchantedBy()) {
|
||||
for (Card aura : source.getEnchantedBy(false)) {
|
||||
if (aura.getController().isOpponentOf(ai)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -175,7 +175,7 @@ public class DestroyAi extends SpellAbilityAi {
|
||||
} else {
|
||||
// Don't destroy stolen permanents when the stealing aura can be destroyed
|
||||
if (choice.getOwner() == ai) {
|
||||
for (Card aura : choice.getEnchantedBy()) {
|
||||
for (Card aura : choice.getEnchantedBy(false)) {
|
||||
SpellAbility sp = aura.getFirstSpellAbility();
|
||||
if (sp != null && "GainControl".equals(sp.getParam("AILogic"))
|
||||
&& aura.getController() != ai && sa.canTarget(aura)) {
|
||||
|
||||
@@ -296,7 +296,7 @@ public class TokenAi extends SpellAbilityAi {
|
||||
for (int i = 0; i < substitutedColors.length; i++) {
|
||||
if (substitutedColors[i].equals("ChosenColor")) {
|
||||
// this currently only supports 1 chosen color
|
||||
substitutedColors[i] = host.getChosenColors().get(0);
|
||||
substitutedColors[i] = host.getChosenColor();
|
||||
}
|
||||
}
|
||||
String colorDesc = "";
|
||||
|
||||
Reference in New Issue
Block a user