mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-12 00:38:44 +00:00
AI: Basic Logic for Destroy RE
This commit is contained in:
@@ -70,6 +70,7 @@ import io.sentry.Breadcrumb;
|
||||
import io.sentry.Sentry;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -2293,6 +2294,33 @@ public class AiController {
|
||||
if (!prevention.isEmpty()) {
|
||||
return Iterables.getFirst(prevention, null);
|
||||
}
|
||||
} else if (mode.equals(ReplacementType.Destroy)) {
|
||||
List<ReplacementEffect> shield = filterList(list, CardTraitPredicates.hasParam("ShieldCounter"));
|
||||
List<ReplacementEffect> regeneration = filterList(list, CardTraitPredicates.hasParam("Regeneration"));
|
||||
List<ReplacementEffect> umbraArmor = filterList(list, CardTraitPredicates.isKeyword(Keyword.UMBRA_ARMOR));
|
||||
List<ReplacementEffect> umbraArmorIndestructible = filterList(umbraArmor, Predicates.compose(CardPredicates.hasKeyword(Keyword.INDESTRUCTIBLE), CardTraitBase::getHostCard));
|
||||
|
||||
// Indestructible umbra armor is the best
|
||||
if (!umbraArmorIndestructible.isEmpty()) {
|
||||
return Iterables.getFirst(umbraArmorIndestructible, null);
|
||||
}
|
||||
|
||||
// then it might be better to remove shield counter if able?
|
||||
if (!shield.isEmpty()) {
|
||||
return Iterables.getFirst(shield, null);
|
||||
}
|
||||
|
||||
// TODO get the RunParams for Affected to check if the creature already dealt combat damage for Regeneration effects
|
||||
// is using a Regeneration Effect better than using a Umbra Armor?
|
||||
if (!regeneration.isEmpty()) {
|
||||
return Iterables.getFirst(regeneration, null);
|
||||
}
|
||||
|
||||
if (!umbraArmor.isEmpty()) {
|
||||
// sort them by cmc
|
||||
umbraArmor.sort(Comparator.comparing(CardTraitBase::getHostCard, Comparator.comparing(Card::getCMC)));
|
||||
return Iterables.getFirst(umbraArmor, null);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO always lower counters with Vorinclex first, might turn it from 1 to 0 as final
|
||||
|
||||
@@ -1130,7 +1130,7 @@ public class PlayerControllerAi extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers) {
|
||||
public ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> possibleReplacers) {
|
||||
return brains.chooseSingleReplacementEffect(possibleReplacers);
|
||||
}
|
||||
|
||||
|
||||
@@ -6942,7 +6942,7 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
|
||||
shieldCounterReplaceDamage.setOverridingAbility(AbilityFactory.getAbility(sa, this));
|
||||
}
|
||||
if (shieldCounterReplaceDestroy == null) {
|
||||
String reStr = "Event$ Destroy | ActiveZones$ Battlefield | ValidCard$ Card.Self | ValidCause$ SpellAbility | Secondary$ True "
|
||||
String reStr = "Event$ Destroy | ActiveZones$ Battlefield | ValidCard$ Card.Self | ValidCause$ SpellAbility | Secondary$ True | ShieldCounter$ True "
|
||||
+ "| Description$ If this permanent would be destroyed as the result of an effect, instead remove a shield counter from it.";
|
||||
shieldCounterReplaceDestroy = ReplacementHandler.parseReplacement(reStr, this, false, null);
|
||||
shieldCounterReplaceDestroy.setOverridingAbility(AbilityFactory.getAbility(sa, this));
|
||||
|
||||
@@ -251,7 +251,7 @@ public abstract class PlayerController {
|
||||
public abstract String chooseKeywordForPump(List<String> options, SpellAbility sa, String prompt, Card tgtCard);
|
||||
|
||||
public abstract boolean confirmPayment(CostPart costPart, String string, SpellAbility sa);
|
||||
public abstract ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers);
|
||||
public abstract ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> possibleReplacers);
|
||||
public abstract StaticAbility chooseSingleStaticAbility(String prompt, List<StaticAbility> possibleReplacers);
|
||||
public abstract String chooseProtectionType(String string, SpellAbility sa, List<String> choices);
|
||||
|
||||
|
||||
@@ -215,7 +215,7 @@ public class ReplacementHandler {
|
||||
if (layer == ReplacementLayer.CantHappen) {
|
||||
chosenRE = possibleReplacers.get(0);
|
||||
} else {
|
||||
chosenRE = decider.getController().chooseSingleReplacementEffect(Localizer.getInstance().getMessage("lblChooseFirstApplyReplacementEffect"), possibleReplacers);
|
||||
chosenRE = decider.getController().chooseSingleReplacementEffect(possibleReplacers);
|
||||
}
|
||||
|
||||
possibleReplacers.remove(chosenRE);
|
||||
@@ -657,7 +657,7 @@ public class ReplacementHandler {
|
||||
}
|
||||
|
||||
List<ReplacementEffect> possibleReplacers = new ArrayList<>(replaceCandidateMap.keySet());
|
||||
ReplacementEffect chosenRE = decider.getController().chooseSingleReplacementEffect(Localizer.getInstance().getMessage("lblChooseFirstApplyReplacementEffect"), possibleReplacers);
|
||||
ReplacementEffect chosenRE = decider.getController().chooseSingleReplacementEffect(possibleReplacers);
|
||||
List<Map<AbilityKey, Object>> runParamList = replaceCandidateMap.get(chosenRE);
|
||||
|
||||
if (!executedDamageMap.containsKey(chosenRE)) {
|
||||
|
||||
@@ -541,7 +541,7 @@ public class PlayerControllerForTests extends PlayerController {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplacementEffect chooseSingleReplacementEffect(String prompt, List<ReplacementEffect> possibleReplacers) {
|
||||
public ReplacementEffect chooseSingleReplacementEffect(List<ReplacementEffect> possibleReplacers) {
|
||||
// TODO Auto-generated method stub
|
||||
return Iterables.getFirst(possibleReplacers, null);
|
||||
}
|
||||
|
||||
@@ -1891,11 +1891,12 @@ public class PlayerControllerHuman extends PlayerController implements IGameCont
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReplacementEffect chooseSingleReplacementEffect(final String prompt, final List<ReplacementEffect> possibleReplacers) {
|
||||
public ReplacementEffect chooseSingleReplacementEffect(final List<ReplacementEffect> possibleReplacers) {
|
||||
final ReplacementEffect first = possibleReplacers.get(0);
|
||||
if (possibleReplacers.size() == 1) {
|
||||
return first;
|
||||
}
|
||||
String prompt = localizer.getMessage("lblChooseFirstApplyReplacementEffect");
|
||||
final String firstStr = first.toString();
|
||||
for (int i = 1; i < possibleReplacers.size(); i++) {
|
||||
// prompt user if there are multiple different options
|
||||
|
||||
Reference in New Issue
Block a user