Merge branch 'master' into 'master'

Check to make sure the cards are targetable by AI in DamageDealAi (mandatory).

See merge request core-developers/forge!2481
This commit is contained in:
Michael Kamensky
2020-01-31 14:38:37 +00:00

View File

@@ -802,7 +802,7 @@ public class DamageDealAi extends DamageAiBase {
return false;
} else {
// If the trigger is mandatory, gotta choose my own stuff now
return this.damageChooseRequiredTargets(ai, sa, tgt, dmg, mandatory);
return this.damageChooseRequiredTargets(ai, sa, tgt, dmg);
}
} else {
// TODO is this good enough? for up to amounts?
@@ -879,12 +879,9 @@ public class DamageDealAi extends DamageAiBase {
* a {@link forge.game.spellability.TargetRestrictions} object.
* @param dmg
* a int.
* @param mandatory
* a boolean.
* @return a boolean.
*/
private boolean damageChooseRequiredTargets(final Player ai, final SpellAbility sa, final TargetRestrictions tgt, final int dmg,
final boolean mandatory) {
private boolean damageChooseRequiredTargets(final Player ai, final SpellAbility sa, final TargetRestrictions tgt, final int dmg) {
// this is for Triggered targets that are mandatory
final boolean noPrevention = sa.hasParam("NoPrevention");
final boolean divided = sa.hasParam("DividedAsYouChoose");
@@ -892,7 +889,7 @@ public class DamageDealAi extends DamageAiBase {
while (sa.getTargets().getNumTargeted() < tgt.getMinTargets(sa.getHostCard(), sa)) {
if (tgt.canTgtPlaneswalker()) {
final Card c = this.dealDamageChooseTgtPW(ai, sa, dmg, noPrevention, ai, mandatory);
final Card c = this.dealDamageChooseTgtPW(ai, sa, dmg, noPrevention, ai, true);
if (c != null) {
sa.getTargets().add(c);
if (divided) {
@@ -905,7 +902,7 @@ public class DamageDealAi extends DamageAiBase {
// TODO: This currently also catches planeswalkers that can be killed (still necessary? Or can be removed?)
if (tgt.canTgtCreature()) {
final Card c = this.dealDamageChooseTgtC(ai, sa, dmg, noPrevention, ai, mandatory);
final Card c = this.dealDamageChooseTgtC(ai, sa, dmg, noPrevention, ai, true);
if (c != null) {
sa.getTargets().add(c);
if (divided) {
@@ -928,7 +925,7 @@ public class DamageDealAi extends DamageAiBase {
// See if there's an indestructible target that can be used
CardCollection indestructible = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield),
Predicates.and(CardPredicates.Presets.CREATURES, CardPredicates.Presets.PLANESWALKERS, CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE)));
Predicates.and(CardPredicates.Presets.CREATURES, CardPredicates.Presets.PLANESWALKERS, CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE), CardPredicates.isTargetableBy(sa)));
if (!indestructible.isEmpty()) {
Card c = ComputerUtilCard.getWorstPermanentAI(indestructible, false, false, false, false);
@@ -941,7 +938,7 @@ public class DamageDealAi extends DamageAiBase {
}
else if (tgt.canTgtPlaneswalker()) {
// Second pass for planeswalkers: choose AI's worst planeswalker
final Card c = getWorstPlaneswalkerToDamage(CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.PLANESWALKERS));
final Card c = getWorstPlaneswalkerToDamage(CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), Predicates.and(CardPredicates.Presets.PLANESWALKERS), CardPredicates.isTargetableBy(sa)));
if (c != null) {
sa.getTargets().add(c);
if (divided) {