cleanup GainAbilityTargetEffect

remove unused parameters

strip reminder text
This commit is contained in:
xenohedron 2023-08-23 22:24:40 -04:00
parent 53768c17b3
commit 6624e141c6

View file

@ -9,6 +9,7 @@ import mage.cards.Card;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import java.util.*;
@ -23,11 +24,6 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
private final boolean useOnCard; // only one card per ability supported
private boolean waitingCardPermanent = false; // wait the permanent from card's resolve (for inner usage only)
// Duration until next phase step of player
private PhaseStep durationPhaseStep = null;
private UUID durationPlayerId;
private boolean sameStep;
public GainAbilityTargetEffect(Ability ability) {
this(ability, Duration.EndOfTurn);
}
@ -55,30 +51,12 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
this.ability = copyAbility(effect.ability); // See the method's comment, ability.copy() is not enough.
this.useOnCard = effect.useOnCard;
this.waitingCardPermanent = effect.waitingCardPermanent;
this.durationPhaseStep = effect.durationPhaseStep;
this.durationPlayerId = effect.durationPlayerId;
this.sameStep = effect.sameStep;
}
/**
* Used to set a duration to the next durationPhaseStep of the first
* controller of the effect.
*
* @param phaseStep
*/
public void setDurationToPhase(PhaseStep phaseStep) {
durationPhaseStep = phaseStep;
}
@Override
public void init(Ability source, Game game) {
super.init(source, game);
if (durationPhaseStep != null) {
durationPlayerId = source.getControllerId();
sameStep = true;
}
// must support dynamic targets from static ability and static targets from activated abilities
if (this.affectedObjectsSet) {
// target permanents (by default)
@ -107,19 +85,6 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
}
}
@Override
public boolean isInactive(Ability source, Game game) {
if (super.isInactive(source, game)) {
return true;
}
if (durationPhaseStep != null && durationPhaseStep == game.getPhase().getStep().getType()) {
return !sameStep && game.isActivePlayer(durationPlayerId) || game.getPlayer(durationPlayerId).hasReachedNextTurnAfterLeaving();
} else {
sameStep = false;
}
return false;
}
@Override
public GainAbilityTargetEffect copy() {
return new GainAbilityTargetEffect(this);
@ -208,14 +173,13 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
* by a clone, or in the case of an activated ability, called multiple times on the same target,
* and thus the ability should be gained multiple times.
*/
private Ability copyAbility(Ability toCopyAbility) {
Ability ability = toCopyAbility.copy();
ability.newId();
if (ability instanceof LinkedEffectIdStaticAbility) {
((LinkedEffectIdStaticAbility) ability).setEffectIdManually();
Ability abilityToCopy = toCopyAbility.copy();
abilityToCopy.newId();
if (abilityToCopy instanceof LinkedEffectIdStaticAbility) {
((LinkedEffectIdStaticAbility) abilityToCopy).setEffectIdManually();
}
return ability;
return abilityToCopy;
}
@Override
@ -223,12 +187,10 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), ""));
StringBuilder sb = new StringBuilder(getTargetPointer().describeTargets(mode.getTargets(), "it"));
sb.append(getTargetPointer().isPlural(mode.getTargets()) ? " gain " : " gains ");
sb.append(ability.getRule());
if (durationPhaseStep != null) {
sb.append(" until your next ").append(durationPhaseStep.toString().toLowerCase(Locale.ENGLISH));
} else if (!duration.toString().isEmpty()) {
sb.append(CardUtil.stripReminderText(ability.getRule()));
if (!duration.toString().isEmpty()) {
sb.append(' ').append(duration.toString());
}
return sb.toString();