forked from External/mage
Merge pull request #6507 from emerald000/abilityResolved
Refactor and add hint for "Ability resolved X times"
This commit is contained in:
commit
8a3ba6729f
9 changed files with 158 additions and 76 deletions
|
|
@ -152,6 +152,9 @@ public abstract class AbilityImpl implements Ability {
|
|||
boolean result = true;
|
||||
//20100716 - 117.12
|
||||
if (checkIfClause(game)) {
|
||||
// Ability has started resolving. Fire event.
|
||||
// Used for abilities counting the number of resolutions like Ashling the Pilgrim.
|
||||
game.fireEvent(new GameEvent(GameEvent.EventType.RESOLVING_ABILITY, this.getOriginalId(), this.getSourceId(), this.getControllerId()));
|
||||
if (this instanceof TriggeredAbility) {
|
||||
for (UUID modeId : this.getModes().getSelectedModes()) {
|
||||
this.getModes().setActiveMode(modeId);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.AbilityResolvedWatcher;
|
||||
|
||||
/**
|
||||
* @author emerald000
|
||||
*/
|
||||
public enum AbilityResolutionCount implements DynamicValue {
|
||||
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
AbilityResolvedWatcher watcher = game.getState().getWatcher(AbilityResolvedWatcher.class);
|
||||
if (watcher != null) {
|
||||
return watcher.getResolutionCount(game, sourceAbility);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbilityResolutionCount copy() {
|
||||
return instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "X";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return "permanents you control";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.game.Game;
|
||||
import mage.util.CardUtil;
|
||||
import mage.watchers.common.AbilityResolvedWatcher;
|
||||
|
||||
/**
|
||||
* @author emerald000
|
||||
*/
|
||||
public class IfAbilityHasResolvedXTimesEffect extends OneShotEffect {
|
||||
|
||||
private final int resolutionNumber;
|
||||
private final Effect effect;
|
||||
|
||||
public IfAbilityHasResolvedXTimesEffect(Outcome outcome, int resolutionNumber, Effect effect) {
|
||||
super(outcome);
|
||||
this.resolutionNumber = resolutionNumber;
|
||||
this.effect = effect;
|
||||
this.staticText = "If this is the " + CardUtil.numberToOrdinalText(resolutionNumber) + " time this ability has resolved this turn, " +
|
||||
effect.getText(null);
|
||||
}
|
||||
|
||||
private IfAbilityHasResolvedXTimesEffect(final IfAbilityHasResolvedXTimesEffect effect) {
|
||||
super(effect);
|
||||
this.resolutionNumber = effect.resolutionNumber;
|
||||
this.effect = effect.effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IfAbilityHasResolvedXTimesEffect copy() {
|
||||
return new IfAbilityHasResolvedXTimesEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
AbilityResolvedWatcher watcher = game.getState().getWatcher(AbilityResolvedWatcher.class);
|
||||
if (watcher != null && watcher.getResolutionCount(game, source) == resolutionNumber) {
|
||||
if (effect instanceof OneShotEffect) {
|
||||
return effect.apply(game, source);
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) effect, source);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package mage.abilities.hint.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.common.AbilityResolutionCount;
|
||||
import mage.abilities.hint.Hint;
|
||||
import mage.abilities.hint.ValueHint;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author emerald000
|
||||
*/
|
||||
public enum AbilityResolutionCountHint implements Hint {
|
||||
|
||||
instance;
|
||||
private static final Hint hint = new ValueHint("Resolution count:", AbilityResolutionCount.instance);
|
||||
|
||||
@Override
|
||||
public String getText(Game game, Ability ability) {
|
||||
return hint.getText(game, ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Hint copy() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue