cleanup AbilityType for easier check that an ability is an activated ability (#12153)

* cleanup AbilityType

* further cleanup

* cleanup instanceof

* tweak formatting

* rework Rex

* fix mistake in PlayerImpl

* cleanup 'instanceof' for 'ActivatedManaAbilityImpl'
This commit is contained in:
Susucre 2024-05-04 04:13:34 +02:00 committed by GitHub
parent 62cc49ffa3
commit 85cad4ff1e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
118 changed files with 486 additions and 574 deletions

View file

@ -162,6 +162,31 @@ public abstract class AbilityImpl implements Ability {
return this.abilityType;
}
@Override
public boolean isActivatedAbility() {
return this.abilityType.isActivatedAbility();
}
@Override
public boolean isTriggeredAbility() {
return this.abilityType.isTriggeredAbility();
}
@Override
public boolean isNonManaActivatedAbility() {
return this.abilityType.isNonManaActivatedAbility();
}
@Override
public boolean isManaActivatedAbility() {
return this.abilityType.isManaActivatedAbility();
}
@Override
public boolean isManaAbility() {
return this.abilityType.isManaAbility();
}
@Override
public boolean resolve(Game game) {
boolean result = true;
@ -193,7 +218,7 @@ public abstract class AbilityImpl implements Ability {
boolean effectResult = effect.apply(game, this);
result &= effectResult;
if (logger.isDebugEnabled()) {
if (this.getAbilityType() != AbilityType.MANA) {
if (!this.isManaAbility()) {
if (!effectResult) {
if (this.getSourceId() != null) {
MageObject mageObject = game.getObject(this.getSourceId());
@ -351,7 +376,7 @@ public abstract class AbilityImpl implements Ability {
// and/or zones become the target of a spell trigger at this point; they'll wait to be put on
// the stack until the spell has finished being cast.)
if (this.getAbilityType() != AbilityType.TRIGGERED) { // triggered abilities check this already in playerImpl.triggerAbility
if (!this.getAbilityType().isTriggeredAbility()) { // triggered abilities check this already in playerImpl.triggerAbility
adjustTargets(game);
}
@ -359,6 +384,7 @@ public abstract class AbilityImpl implements Ability {
Outcome outcome = getEffects().getOutcome(this);
// only activated abilities can be canceled by human user (not triggered)
// Note: ActivatedAbility does include SpellAbility & PlayLandAbility, but those should be able to be canceled too.
boolean canCancel = this instanceof ActivatedAbility && controller.isHuman();
if (!getTargets().chooseTargets(outcome, this.controllerId, this, noMana, game, canCancel)) {
// was canceled during targer selection