No SpellAbilityRestriction in Subs (performance + fix AI mayplay Charms)

This commit is contained in:
tool4EvEr
2022-07-09 17:29:41 +02:00
parent 495cd22897
commit 3c5a3b426c
3 changed files with 10 additions and 7 deletions

View File

@@ -90,6 +90,8 @@ public class CharmAi extends SpellAbilityAi {
for (AbilitySub sub : choices) {
sub.setActivatingPlayer(ai);
sub.getRestrictions().setZone(sub.getParent().getRestrictions().getZone());
// TODO checks from MayPlay fail for subs currently
if (AiPlayDecision.WillPlay == aic.canPlaySa(sub)) {
chosenList.add(sub);
if (chosenList.size() == num) {
@@ -101,8 +103,6 @@ public class CharmAi extends SpellAbilityAi {
// Second pass using doTrigger(false) to fulfill minimum choice
choices.removeAll(chosenList);
for (AbilitySub sub : choices) {
sub.setActivatingPlayer(ai);
sub.getRestrictions().setZone(sub.getParent().getRestrictions().getZone());
if (aic.doTrigger(sub, false)) {
chosenList.add(sub);
if (chosenList.size() == min) {
@@ -114,8 +114,6 @@ public class CharmAi extends SpellAbilityAi {
if (chosenList.size() < min) {
choices.removeAll(chosenList);
for (AbilitySub sub : choices) {
sub.setActivatingPlayer(ai);
sub.getRestrictions().setZone(sub.getParent().getRestrictions().getZone());
if (aic.doTrigger(sub, true)) {
chosenList.add(sub);
if (chosenList.size() == min) {

View File

@@ -426,7 +426,9 @@ public final class AbilityFactory {
private static final void makeRestrictions(final SpellAbility sa) {
// SpellAbilityRestrictions should be added in here
final SpellAbilityRestriction restrict = sa.getRestrictions();
restrict.setRestrictions(sa.getMapParams());
if (restrict != null) {
restrict.setRestrictions(sa.getMapParams());
}
}
/**
@@ -438,7 +440,7 @@ public final class AbilityFactory {
* a {@link forge.game.spellability.SpellAbility} object.
*/
private static final void makeConditions(final SpellAbility sa) {
// SpellAbilityRestrictions should be added in here
// SpellAbilityConditions should be added in here
final SpellAbilityCondition condition = sa.getConditions();
condition.setConditions(sa.getMapParams());
}

View File

@@ -138,7 +138,7 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
/** The pay costs. */
private Cost payCosts;
private SpellAbilityRestriction restrictions = new SpellAbilityRestriction();
private SpellAbilityRestriction restrictions;
private SpellAbilityCondition conditions = new SpellAbilityCondition();
private AbilitySub subAbility;
@@ -214,6 +214,9 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit
view0 = new SpellAbilityView(this);
}
view = view0;
if (!(this instanceof AbilitySub)) {
restrictions = new SpellAbilityRestriction();
}
}
@Override