mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- Fix AI targeting for Blatant Thievery
This commit is contained in:
@@ -20,6 +20,7 @@ package forge.ai.ability;
|
|||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
import forge.ai.AiCardMemory;
|
import forge.ai.AiCardMemory;
|
||||||
import forge.ai.ComputerUtilCard;
|
import forge.ai.ComputerUtilCard;
|
||||||
import forge.ai.ComputerUtilCombat;
|
import forge.ai.ComputerUtilCombat;
|
||||||
@@ -80,6 +81,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
final TargetRestrictions tgt = sa.getTargetRestrictions();
|
||||||
Player opp = ai.getOpponent();
|
Player opp = ai.getOpponent();
|
||||||
|
List<Player> opponents = ai.getOpponents();
|
||||||
|
|
||||||
// if Defined, then don't worry about targeting
|
// if Defined, then don't worry about targeting
|
||||||
if (tgt == null) {
|
if (tgt == null) {
|
||||||
@@ -98,17 +100,16 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
sa.setTargetingPlayer(targetingPlayer);
|
sa.setTargetingPlayer(targetingPlayer);
|
||||||
return targetingPlayer.getController().chooseTargetsFor(sa);
|
return targetingPlayer.getController().chooseTargetsFor(sa);
|
||||||
}
|
}
|
||||||
|
if (tgt.isRandomTarget()) {
|
||||||
|
sa.getTargets().add(Aggregates.random(tgt.getAllCandidates(sa, false)));
|
||||||
|
}
|
||||||
if (tgt.canOnlyTgtOpponent()) {
|
if (tgt.canOnlyTgtOpponent()) {
|
||||||
if (!opp.canBeTargetedBy(sa)) {
|
if (!opp.canBeTargetedBy(sa)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (tgt.isRandomTarget()) {
|
|
||||||
sa.getTargets().add(Aggregates.random(tgt.getAllCandidates(sa, false)));
|
|
||||||
} else {
|
|
||||||
sa.getTargets().add(opp);
|
sa.getTargets().add(opp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Don't steal something if I can't Attack without, or prevent it from
|
// Don't steal something if I can't Attack without, or prevent it from
|
||||||
// blocking at least
|
// blocking at least
|
||||||
@@ -118,8 +119,12 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CardCollection list =
|
CardCollection list = new CardCollection();
|
||||||
CardLists.getValidCards(opp.getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getHostCard(), sa);
|
for (Player pl : opponents) {
|
||||||
|
list.addAll(pl.getCardsIn(ZoneType.Battlefield));
|
||||||
|
}
|
||||||
|
|
||||||
|
list = CardLists.getValidCards(list, tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getHostCard(), sa);
|
||||||
|
|
||||||
// AI won't try to grab cards that are filtered out of AI decks on purpose
|
// AI won't try to grab cards that are filtered out of AI decks on purpose
|
||||||
list = CardLists.filter(list, new Predicate<Card>() {
|
list = CardLists.filter(list, new Predicate<Card>() {
|
||||||
@@ -143,26 +148,29 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (sa.getTargets().getNumTargeted() < tgt.getMaxTargets(sa.getHostCard(), sa)) {
|
int creatures = 0, artifacts = 0, planeswalkers = 0, lands = 0, enchantments = 0;
|
||||||
Card t = null;
|
|
||||||
for (final Card c : list) {
|
for (final Card c : list) {
|
||||||
if (c.isCreature()) {
|
if (c.isCreature()) {
|
||||||
hasCreature = true;
|
creatures++;
|
||||||
}
|
}
|
||||||
if (c.isArtifact()) {
|
if (c.isArtifact()) {
|
||||||
hasArtifact = true;
|
artifacts++;
|
||||||
}
|
}
|
||||||
if (c.isLand()) {
|
if (c.isLand()) {
|
||||||
hasLand = true;
|
lands++;
|
||||||
}
|
}
|
||||||
if (c.isEnchantment()) {
|
if (c.isEnchantment()) {
|
||||||
hasEnchantment = true;
|
enchantments++;
|
||||||
}
|
}
|
||||||
if (c.isPlaneswalker()) {
|
if (c.isPlaneswalker()) {
|
||||||
hasPW = true;
|
planeswalkers++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
while (sa.getTargets().getNumTargeted() < tgt.getMaxTargets(sa.getHostCard(), sa)) {
|
||||||
|
Card t = null;
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
if ((sa.getTargets().getNumTargeted() < tgt.getMinTargets(sa.getHostCard(), sa)) || (sa.getTargets().getNumTargeted() == 0)) {
|
if ((sa.getTargets().getNumTargeted() < tgt.getMinTargets(sa.getHostCard(), sa)) || (sa.getTargets().getNumTargeted() == 0)) {
|
||||||
sa.resetTargets();
|
sa.resetTargets();
|
||||||
@@ -173,32 +181,45 @@ public class ControlGainAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasPW) {
|
while (t == null) {
|
||||||
|
if (planeswalkers > 0) {
|
||||||
t = ComputerUtilCard.getBestPlaneswalkerAI(list);
|
t = ComputerUtilCard.getBestPlaneswalkerAI(list);
|
||||||
} else if (hasCreature) {
|
} else if (creatures > 0) {
|
||||||
t = ComputerUtilCard.getBestCreatureAI(list);
|
t = ComputerUtilCard.getBestCreatureAI(list);
|
||||||
if (lose != null && lose.contains("EOT")) {
|
} else if (artifacts > 0) {
|
||||||
// Remember to always attack with this creature since it'll bounce back to its owner at end of turn anyway
|
|
||||||
((PlayerControllerAi)ai.getController()).getAi().getCardMemory().rememberCard(t, AiCardMemory.MemorySet.MANDATORY_ATTACKERS);
|
|
||||||
}
|
|
||||||
} else if (hasArtifact) {
|
|
||||||
t = ComputerUtilCard.getBestArtifactAI(list);
|
t = ComputerUtilCard.getBestArtifactAI(list);
|
||||||
} else if (hasLand) {
|
} else if (lands > 0) {
|
||||||
t = ComputerUtilCard.getBestLandAI(list);
|
t = ComputerUtilCard.getBestLandAI(list);
|
||||||
} else if (hasEnchantment) {
|
} else if (enchantments > 0) {
|
||||||
t = ComputerUtilCard.getBestEnchantmentAI(list, sa, true);
|
t = ComputerUtilCard.getBestEnchantmentAI(list, sa, true);
|
||||||
} else {
|
} else {
|
||||||
t = ComputerUtilCard.getMostExpensivePermanentAI(list, sa, true);
|
t = ComputerUtilCard.getMostExpensivePermanentAI(list, sa, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (t.isCreature())
|
||||||
|
creatures--;
|
||||||
|
if (t.isPlaneswalker())
|
||||||
|
planeswalkers--;
|
||||||
|
if (t.isLand())
|
||||||
|
lands--;
|
||||||
|
if (t.isArtifact())
|
||||||
|
artifacts--;
|
||||||
|
if (t.isEnchantment())
|
||||||
|
enchantments--;
|
||||||
|
|
||||||
|
if (!sa.canTarget(t)) {
|
||||||
|
list.remove(t);
|
||||||
|
t = null;
|
||||||
|
if (list.isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (t != null) {
|
||||||
sa.getTargets().add(t);
|
sa.getTargets().add(t);
|
||||||
list.remove(t);
|
list.remove(t);
|
||||||
|
}
|
||||||
hasCreature = false;
|
|
||||||
hasArtifact = false;
|
|
||||||
hasLand = false;
|
|
||||||
hasEnchantment = false;
|
|
||||||
hasPW = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -796,6 +796,17 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tr.isDifferentControllers()) {
|
||||||
|
Player newController;
|
||||||
|
if (entity instanceof Card) {
|
||||||
|
newController = ((Card) entity).getController();
|
||||||
|
for (final Card c : targetChosen.getTargetCards()) {
|
||||||
|
if (entity != c && c.getController().equals(newController))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String[] validTgt = tr.getValidTgts();
|
String[] validTgt = tr.getValidTgts();
|
||||||
if (entity instanceof GameEntity && !((GameEntity) entity).isValid(validTgt, getActivatingPlayer(), getHostCard(), this)) {
|
if (entity instanceof GameEntity && !((GameEntity) entity).isValid(validTgt, getActivatingPlayer(), getHostCard(), this)) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user