mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 03:38:01 +00:00
- Improved ControlGainAI.
This commit is contained in:
@@ -31,6 +31,7 @@ import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.game.Game;
|
||||
import forge.game.ai.ComputerUtilCard;
|
||||
import forge.game.phase.CombatUtil;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
@@ -61,7 +62,7 @@ import forge.game.zone.ZoneType;
|
||||
*/
|
||||
public class ControlGainAi extends SpellAbilityAi {
|
||||
@Override
|
||||
protected boolean canPlayAI(Player ai, final SpellAbility sa) {
|
||||
protected boolean canPlayAI(final Player ai, final SpellAbility sa) {
|
||||
boolean hasCreature = false;
|
||||
boolean hasArtifact = false;
|
||||
boolean hasEnchantment = false;
|
||||
@@ -69,7 +70,6 @@ public class ControlGainAi extends SpellAbilityAi {
|
||||
|
||||
final List<String> lose = sa.hasParam("LoseControl") ? Arrays.asList(sa.getParam("LoseControl").split(",")) : null;
|
||||
|
||||
|
||||
final Target tgt = sa.getTarget();
|
||||
Player opp = ai.getOpponent();
|
||||
|
||||
@@ -93,6 +93,13 @@ public class ControlGainAi extends SpellAbilityAi {
|
||||
}
|
||||
}
|
||||
|
||||
// Don't steal something if I can't Attack without, or prevent it from
|
||||
// blocking at least
|
||||
if (lose != null && lose.contains("EOT")
|
||||
&& ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Card> list =
|
||||
CardLists.getValidCards(opp.getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), sa.getActivatingPlayer(), sa.getSourceCard());
|
||||
// AI won't try to grab cards that are filtered out of AI decks on
|
||||
@@ -101,7 +108,7 @@ public class ControlGainAi extends SpellAbilityAi {
|
||||
@Override
|
||||
public boolean apply(final Card c) {
|
||||
final Map<String, String> vars = c.getSVars();
|
||||
return !vars.containsKey("RemAIDeck") && c.canBeTargetedBy(sa);
|
||||
return !vars.containsKey("RemAIDeck") && c.canBeTargetedBy(sa) && CombatUtil.canAttackNextTurn(c, ai.getOpponent());
|
||||
}
|
||||
});
|
||||
|
||||
@@ -109,13 +116,6 @@ public class ControlGainAi extends SpellAbilityAi {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Don't steal something if I can't Attack without, or prevent it from
|
||||
// blocking at least
|
||||
if ((lose != null) && lose.contains("EOT")
|
||||
&& ai.getGame().getPhaseHandler().getPhase().isAfter(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (tgt.getNumTargeted() < tgt.getMaxTargets(sa.getSourceCard(), sa)) {
|
||||
Card t = null;
|
||||
for (final Card c : list) {
|
||||
|
||||
@@ -13,6 +13,7 @@ import forge.card.spellability.Ability;
|
||||
import forge.card.spellability.SpellAbility;
|
||||
import forge.card.spellability.Target;
|
||||
import forge.game.Game;
|
||||
import forge.game.phase.PhaseType;
|
||||
import forge.game.player.Player;
|
||||
import forge.game.zone.ZoneType;
|
||||
|
||||
@@ -164,6 +165,7 @@ public class ControlGainEffect extends SpellAbilityEffect {
|
||||
}
|
||||
if (lose.contains("EOT")) {
|
||||
game.getEndOfTurn().addAt(this.getLoseControlCommand(tgtC, tStamp, bTapOnLose, source, kws));
|
||||
tgtC.setSVar("SacMe", "6");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -245,7 +247,10 @@ public class ControlGainEffect extends SpellAbilityEffect {
|
||||
private static final long serialVersionUID = 878543373519872418L;
|
||||
|
||||
@Override
|
||||
public void run() { doLoseControl(c, hostCard, bTapOnLose, kws, tStamp); }
|
||||
public void run() {
|
||||
doLoseControl(c, hostCard, bTapOnLose, kws, tStamp);
|
||||
c.getSVars().remove("SacMe");
|
||||
}
|
||||
};
|
||||
|
||||
return loseControl;
|
||||
|
||||
@@ -350,7 +350,7 @@ public class ComputerUtil {
|
||||
}
|
||||
}
|
||||
if (pref.contains("SacCost")) { // search for permanents with SacMe
|
||||
for (int ip = 0; ip < 6; ip++) { // priority 0 is the lowest,
|
||||
for (int ip = 1; ip < 6; ip++) { // priority 1 is the lowest,
|
||||
// priority 5 the highest
|
||||
final int priority = 6 - ip;
|
||||
final List<Card> sacMeList = CardLists.filter(typeList, new Predicate<Card>() {
|
||||
@@ -359,7 +359,7 @@ public class ComputerUtil {
|
||||
return (c.hasSVar("SacMe") && (Integer.parseInt(c.getSVar("SacMe")) == priority));
|
||||
}
|
||||
});
|
||||
if (sacMeList.size() != 0) {
|
||||
if (!sacMeList.isEmpty()) {
|
||||
CardLists.shuffle(sacMeList);
|
||||
return sacMeList.get(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user