mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
ManifestAi: rewrote it to use new SpellAbilityAi logic
also add some logic if ai can see its top card
This commit is contained in:
@@ -3,7 +3,7 @@ package forge.ai.ability;
|
|||||||
import forge.ai.*;
|
import forge.ai.*;
|
||||||
import forge.game.Game;
|
import forge.game.Game;
|
||||||
import forge.game.card.Card;
|
import forge.game.card.Card;
|
||||||
import forge.game.cost.Cost;
|
import forge.game.card.CardCollectionView;
|
||||||
import forge.game.phase.PhaseHandler;
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
@@ -18,21 +18,24 @@ import forge.util.MyRandom;
|
|||||||
public class ManifestAi extends SpellAbilityAi {
|
public class ManifestAi extends SpellAbilityAi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
||||||
final Cost cost = sa.getPayCosts();
|
// Manifest doesn't have any "Pay X to manifest X triggers"
|
||||||
final Game game = ai.getGame();
|
|
||||||
|
|
||||||
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
return true;
|
||||||
return false;
|
}
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sa.hasParam("AILogic")) {
|
/**
|
||||||
if ("Never".equals(sa.getParam("AILogic"))) {
|
* Checks if the AI will play a SpellAbility based on its phase restrictions
|
||||||
return false;
|
*/
|
||||||
}
|
protected boolean checkPhaseRestrictions(final Player ai, final SpellAbility sa, final PhaseHandler ph) {
|
||||||
}
|
final Card source = sa.getHostCard();
|
||||||
|
|
||||||
PhaseHandler ph = game.getPhaseHandler();
|
|
||||||
// Only manifest things on your turn if sorcery speed, or would pump one of my creatures
|
// Only manifest things on your turn if sorcery speed, or would pump one of my creatures
|
||||||
if (ph.isPlayerTurn(ai)) {
|
if (ph.isPlayerTurn(ai)) {
|
||||||
if (ph.getPhase().isBefore(PhaseType.MAIN2)
|
if (ph.getPhase().isBefore(PhaseType.MAIN2)
|
||||||
@@ -57,27 +60,6 @@ public class ManifestAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final Card source = sa.getHostCard();
|
|
||||||
|
|
||||||
if (cost != null) {
|
|
||||||
// Sacrifice is the only cost Manifest actually has, but i'll leave these others for now
|
|
||||||
if (!ComputerUtilCost.checkLifeCost(ai, cost, source, 4, null)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkDiscardCost(ai, cost, source)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkSacrificeCost(ai, cost, source)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ComputerUtilCost.checkRemoveCounterCost(cost, source)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (source.getSVar("X").equals("Count$xPaid")) {
|
if (source.getSVar("X").equals("Count$xPaid")) {
|
||||||
// Handle either Manifest X cards, or Manifest 1 card and give it X P1P1s
|
// Handle either Manifest X cards, or Manifest 1 card and give it X P1P1s
|
||||||
// Set PayX here to maximum value.
|
// Set PayX here to maximum value.
|
||||||
@@ -88,6 +70,46 @@ public class ManifestAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean checkApiLogic(final Player ai, final SpellAbility sa) {
|
||||||
|
final Game game = ai.getGame();
|
||||||
|
if (ComputerUtil.preventRunAwayActivations(sa)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Library is empty, no Manifest
|
||||||
|
final CardCollectionView library = ai.getCardsIn(ZoneType.Library);
|
||||||
|
if (library.isEmpty())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// try not to mill himself with Manifest
|
||||||
|
if (library.size() < 5 && !ai.isCardInPlay("Laboratory Maniac")) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
final Card topCard = library.getFirst();
|
||||||
|
if (topCard.getView().mayPlayerLook(ai.getView())) {
|
||||||
|
// try to avoid manifest a non Permanent
|
||||||
|
if (!topCard.isPermanent())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// do not manifest a card with X in its cost
|
||||||
|
if (topCard.getManaCost().countX() > 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// try to avoid manifesting a creature with zero or less thoughness
|
||||||
|
if (topCard.isCreature() && topCard.getNetToughness() <= 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// card has ETBTrigger or ETBReplacement
|
||||||
|
if (topCard.hasETBTrigger(false) || topCard.hasETBReplacement()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Probably should be a little more discerning on playing during OPPs turn
|
// Probably should be a little more discerning on playing during OPPs turn
|
||||||
if (SpellAbilityAi.playReusable(ai, sa)) {
|
if (SpellAbilityAi.playReusable(ai, sa)) {
|
||||||
return true;
|
return true;
|
||||||
@@ -102,19 +124,4 @@ public class ManifestAi extends SpellAbilityAi {
|
|||||||
|
|
||||||
return MyRandom.getRandom().nextFloat() < .8;
|
return MyRandom.getRandom().nextFloat() < .8;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean doTriggerAINoCost(Player ai, SpellAbility sa, boolean mandatory) {
|
|
||||||
// Manifest doesn't have any "Pay X to manifest X triggers"
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see forge.card.ability.SpellAbilityAi#confirmAction(forge.game.player.Player, forge.card.spellability.SpellAbility, forge.game.player.PlayerActionConfirmMode, java.lang.String)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean confirmAction(Player player, SpellAbility sa, PlayerActionConfirmMode mode, String message) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user