Fix Adventures exiling themselves before applying their effects (#10793)

* Rework adventures to exiles themself after applying other effects

* fix duelist

* finalize all adventures

* apply review

* add card name to error

* fix remaining adventures

* finalize the last adventures.
This commit is contained in:
Susucre 2023-08-31 01:15:47 +02:00 committed by GitHub
parent 3ed0dd4f84
commit fe165f1fd0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
108 changed files with 322 additions and 18 deletions

View file

@ -26,6 +26,10 @@ public abstract class AdventureCard extends CardImpl {
this.spellCard = new AdventureCardSpellImpl(ownerId, setInfo, adventureName, typesSpell, costsSpell, this);
}
public void finalizeAdventure() {
spellCard.finalizeAdventure();
}
public AdventureCard(AdventureCard card) {
super(card);
this.spellCard = card.getSpellCard().copy();

View file

@ -7,4 +7,6 @@ public interface AdventureCardSpell extends SubCard<AdventureCard> {
@Override
AdventureCardSpell copy();
void finalizeAdventure();
}

View file

@ -35,6 +35,12 @@ public class AdventureCardSpellImpl extends CardImpl implements AdventureCardSpe
this.adventureCardParent = adventureCardParent;
}
public void finalizeAdventure() {
if (spellAbility instanceof AdventureCardSpellAbility) {
((AdventureCardSpellAbility) spellAbility).finalizeAdventure();
}
}
protected AdventureCardSpellImpl(final AdventureCardSpellImpl card) {
super(card);
this.adventureCardParent = card.adventureCardParent;
@ -100,18 +106,35 @@ public class AdventureCardSpellImpl extends CardImpl implements AdventureCardSpe
class AdventureCardSpellAbility extends SpellAbility {
String nameFull;
private String nameFull;
private boolean finalized = false;
public AdventureCardSpellAbility(final SpellAbility baseSpellAbility, String adventureName, CardType[] cardTypes, String costs) {
super(baseSpellAbility);
this.setName(cardTypes, adventureName, costs);
this.addEffect(ExileAdventureSpellEffect.getInstance());
this.setCardName(adventureName);
}
// The exile effect needs to be added last.
public void finalizeAdventure() {
if (finalized) {
throw new IllegalStateException("Wrong code usage. "
+ "Adventure (" + cardName + ") "
+ "need to call finalizeAdventure() exactly once.");
}
this.addEffect(ExileAdventureSpellEffect.getInstance());
this.finalized = true;
}
protected AdventureCardSpellAbility(final AdventureCardSpellAbility ability) {
super(ability);
this.nameFull = ability.nameFull;
if (!ability.finalized) {
throw new IllegalStateException("Wrong code usage. "
+ "Adventure (" + cardName + ") "
+ "need to call finalizeAdventure() at the very end of the card's constructor.");
}
this.finalized = true;
}
@Override
@ -155,7 +178,7 @@ class AdventureCardSpellAbility extends SpellAbility {
}
@Override
public SpellAbility copy() {
public AdventureCardSpellAbility copy() {
return new AdventureCardSpellAbility(this);
}
}