refactor: PlayFromGraveyardControllerEffect (#13032)

* refactor PlayFromGraveyardControllerEffect for broader usage

* AbandonedSarcophagus to common class

* refactor Player::canPlayCardsFromGraveyard to AsThough common class

* a few more refactors
This commit is contained in:
xenohedron 2024-10-26 16:20:16 -04:00 committed by GitHub
parent 0d63750a81
commit 001f9e866f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 125 additions and 354 deletions

View file

@ -152,7 +152,6 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean canLoseLife = true;
protected PayLifeCostLevel payLifeCostLevel = PayLifeCostLevel.allAbilities;
protected boolean loseByZeroOrLessLife = true;
protected boolean canPlayCardsFromGraveyard = true;
protected boolean canPlotFromTopOfLibrary = false;
protected boolean drawsFromBottom = false;
protected boolean drawsOnOpponentsTurn = false;
@ -252,7 +251,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.canGainLife = player.canGainLife;
this.canLoseLife = player.canLoseLife;
this.loseByZeroOrLessLife = player.loseByZeroOrLessLife;
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard;
this.canPlotFromTopOfLibrary = player.canPlotFromTopOfLibrary;
this.drawsFromBottom = player.drawsFromBottom;
this.drawsOnOpponentsTurn = player.drawsOnOpponentsTurn;
@ -367,7 +365,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.sacrificeCostFilter = player.getSacrificeCostFilter() != null
? player.getSacrificeCostFilter().copy() : null;
this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
this.canPlotFromTopOfLibrary = player.canPlotFromTopOfLibrary();
this.drawsFromBottom = player.isDrawsFromBottom();
this.drawsOnOpponentsTurn = player.isDrawsOnOpponentsTurn();
@ -482,7 +479,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.canLoseLife = true;
this.payLifeCostLevel = PayLifeCostLevel.allAbilities;
this.loseByZeroOrLessLife = true;
this.canPlayCardsFromGraveyard = true;
this.canPlotFromTopOfLibrary = false;
this.drawsFromBottom = false;
this.drawsOnOpponentsTurn = false;
@ -526,7 +522,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.payLifeCostLevel = PayLifeCostLevel.allAbilities;
this.sacrificeCostFilter = null;
this.loseByZeroOrLessLife = true;
this.canPlayCardsFromGraveyard = false;
this.canPlotFromTopOfLibrary = false;
this.drawsFromBottom = false;
this.drawsOnOpponentsTurn = false;
@ -4138,9 +4133,7 @@ public abstract class PlayerImpl implements Player, Serializable {
approvingObjects = new HashSet<>();
}
boolean canActivateAsHandZone = !approvingObjects.isEmpty()
|| (fromZone == Zone.GRAVEYARD && canPlayCardsFromGraveyard());
boolean possibleToPlay = canActivateAsHandZone
boolean possibleToPlay = !approvingObjects.isEmpty()
&& ability.getZone().match(Zone.HAND)
&& (isPlaySpell || isPlayLand);
@ -4164,7 +4157,7 @@ public abstract class PlayerImpl implements Player, Serializable {
}
// from non hand mode (with affected controller)
if (canActivateAsHandZone && ability.getControllerId() != this.getId()) {
if (!approvingObjects.isEmpty() && ability.getControllerId() != this.getId()) {
UUID savedControllerId = ability.getControllerId();
ability.setControllerId(this.getId());
try {
@ -4646,16 +4639,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.loseByZeroOrLessLife = loseByZeroOrLessLife;
}
@Override
public boolean canPlayCardsFromGraveyard() {
return canPlayCardsFromGraveyard;
}
@Override
public void setPlayCardsFromGraveyard(boolean playCardsFromGraveyard) {
this.canPlayCardsFromGraveyard = playCardsFromGraveyard;
}
@Override
public boolean canPlotFromTopOfLibrary() {
return canPlotFromTopOfLibrary;