- Fix potential NPE in SetStateAI

- Unroll UntapAI into new style
This commit is contained in:
Sol
2016-05-14 19:49:57 +00:00
parent 96276cb896
commit 06ff1215b9
3 changed files with 23 additions and 15 deletions

View File

@@ -64,7 +64,7 @@ public abstract class SpellAbilityAi {
* Checks if the AI will play a SpellAbility with the specified AiLogic
*/
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
return true;
return !("Never".equals(aiLogic));
}
/**
@@ -204,8 +204,8 @@ public abstract class SpellAbilityAi {
/**
* TODO: Write javadoc for this method.
* @param ai
* @param subAb
* @param aiPlayer
* @param ab
* @return
*/
public boolean chkDrawbackWithSubs(Player aiPlayer, AbilitySub ab) {

View File

@@ -19,7 +19,7 @@ public class SetStateAi extends SpellAbilityAi {
// check if the other side is legendary and if such Card already is in Play
final CardState other = source.getAlternateState();
if (other.getType().isLegendary() && aiPlayer.isCardInPlay(other.getName())) {
if (other != null && other.getType().isLegendary() && aiPlayer.isCardInPlay(other.getName())) {
return false;
}
}

View File

@@ -20,12 +20,17 @@ import forge.game.zone.ZoneType;
import java.util.List;
public class UntapAi extends SpellAbilityAi {
@Override
protected boolean canPlayAI(Player ai, SpellAbility sa) {
final TargetRestrictions tgt = sa.getTargetRestrictions();
protected boolean checkAiLogic(final Player ai, final SpellAbility sa, final String aiLogic) {
final Card source = sa.getHostCard();
final Cost cost = sa.getPayCosts();
if ("EOT".equals(sa.getParam("AILogic")) && (source.getGame().getPhaseHandler().getNextTurn() != ai
|| !source.getGame().getPhaseHandler().getPhase().equals(PhaseType.END_OF_TURN))) {
return false;
}
return !("Never".equals(aiLogic));
}
protected boolean willPayCosts(final Player ai, final SpellAbility sa, final Cost cost, final Card source) {
if (!ComputerUtilCost.checkAddM1M1CounterCost(cost, source)) {
return false;
}
@@ -34,17 +39,20 @@ public class UntapAi extends SpellAbilityAi {
return false;
}
return true;
}
@Override
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
final TargetRestrictions tgt = sa.getTargetRestrictions();
final Card source = sa.getHostCard();
if (ComputerUtil.preventRunAwayActivations(sa)) {
return false;
}
if ("EOT".equals(sa.getParam("AILogic")) && (source.getGame().getPhaseHandler().getNextTurn() != ai
|| !source.getGame().getPhaseHandler().getPhase().equals(PhaseType.END_OF_TURN))) {
return false;
return false;
}
if (tgt == null) {
final List<Card> pDefined = AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa);
final List<Card> pDefined = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa);
if (pDefined != null && pDefined.get(0).isUntapped() && pDefined.get(0).getController() == ai) {
return false;
}