mirror of
https://github.com/magefree/mage.git
synced 2025-12-28 22:42:03 -08:00
simplify vanishing implementation
This commit is contained in:
parent
c07e6be92b
commit
399b65effb
22 changed files with 193 additions and 333 deletions
|
|
@ -428,7 +428,7 @@ public interface Ability extends Controllable, Serializable {
|
|||
*
|
||||
* @param ruleVisible
|
||||
*/
|
||||
void setRuleVisible(boolean ruleVisible);
|
||||
Ability setRuleVisible(boolean ruleVisible);
|
||||
|
||||
/**
|
||||
* Returns true if the additional costs of the abilitiy should be visible on
|
||||
|
|
|
|||
|
|
@ -1076,10 +1076,11 @@ public abstract class AbilityImpl implements Ability {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void setRuleVisible(boolean ruleVisible) {
|
||||
public AbilityImpl setRuleVisible(boolean ruleVisible) {
|
||||
if (!(this instanceof MageSingleton)) { // prevent to change singletons
|
||||
this.ruleVisible = ruleVisible;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -0,0 +1,97 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
|
||||
import mage.abilities.common.EntersBattlefieldAbility;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.condition.common.SourceHasCounterCondition;
|
||||
import mage.abilities.decorator.ConditionalInterveningIfTriggeredAbility;
|
||||
import mage.abilities.effects.common.SacrificeSourceEffect;
|
||||
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
|
||||
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
|
||||
import mage.constants.TargetController;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class VanishingAbility extends EntersBattlefieldAbility {
|
||||
|
||||
private static final Condition condition = new SourceHasCounterCondition(CounterType.TIME);
|
||||
private final int amount;
|
||||
|
||||
public VanishingAbility(int amount) {
|
||||
super(new AddCountersSourceEffect(CounterType.TIME.createInstance(amount)));
|
||||
this.amount = amount;
|
||||
this.addSubAbility(new ConditionalInterveningIfTriggeredAbility(
|
||||
new BeginningOfUpkeepTriggeredAbility(
|
||||
new RemoveCounterSourceEffect(CounterType.TIME.createInstance()),
|
||||
TargetController.YOU, false
|
||||
), condition, "At the beginning of your upkeep, if this permanent " +
|
||||
"has a time counter on it, remove a time counter from it."
|
||||
).setRuleVisible(false));
|
||||
this.addSubAbility(new VanishingTriggeredAbility());
|
||||
}
|
||||
|
||||
private VanishingAbility(final VanishingAbility ability) {
|
||||
super(ability);
|
||||
this.amount = ability.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanishingAbility copy() {
|
||||
return new VanishingAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
if (amount > 0) {
|
||||
return "Vanishing " + amount + " <i>(This permanent enters the battlefield with " +
|
||||
CardUtil.numberToText(amount) + " time counters on it. At the beginning of your upkeep, " +
|
||||
"remove a time counter from it. When the last is removed, sacrifice it.)</i>";
|
||||
}
|
||||
return "Vanishing <i>(At the beginning of your upkeep, remove a time counter " +
|
||||
"from this permanent. When the last is removed, sacrifice it.)</i>";
|
||||
}
|
||||
}
|
||||
|
||||
class VanishingTriggeredAbility extends TriggeredAbilityImpl {
|
||||
|
||||
VanishingTriggeredAbility() {
|
||||
super(Zone.BATTLEFIELD, new SacrificeSourceEffect());
|
||||
this.setRuleVisible(false);
|
||||
}
|
||||
|
||||
private VanishingTriggeredAbility(final VanishingTriggeredAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanishingTriggeredAbility copy() {
|
||||
return new VanishingTriggeredAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.COUNTERS_REMOVED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (!CounterType.TIME.getName().equals(event.getData())) {
|
||||
return false;
|
||||
}
|
||||
Permanent permanent = getSourcePermanentIfItStillExists(game);
|
||||
return permanent != null && permanent.getCounters(game).getCount(CounterType.TIME) < 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
return "When the last time counter is removed from {this}, sacrifice it.";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,42 +0,0 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.TriggeredAbilityImpl;
|
||||
import mage.abilities.effects.common.SacrificeSourceEffect;
|
||||
import mage.constants.Zone;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
public class VanishingSacrificeAbility extends TriggeredAbilityImpl {
|
||||
public VanishingSacrificeAbility() {
|
||||
super(Zone.BATTLEFIELD, new SacrificeSourceEffect());
|
||||
this.setRuleVisible(false);
|
||||
}
|
||||
|
||||
protected VanishingSacrificeAbility(final VanishingSacrificeAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkEventType(GameEvent event, Game game) {
|
||||
return event.getType() == GameEvent.EventType.COUNTER_REMOVED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean checkTrigger(GameEvent event, Game game) {
|
||||
if (event.getData().equals(CounterType.TIME.getName()) && event.getTargetId().equals(this.getSourceId())) {
|
||||
Permanent p = game.getPermanent(this.getSourceId());
|
||||
if (p != null) {
|
||||
return p.getCounters(game).getCount(CounterType.TIME) == 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanishingSacrificeAbility copy() {
|
||||
return new VanishingSacrificeAbility(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,81 +0,0 @@
|
|||
package mage.abilities.keyword;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.TargetController;
|
||||
import mage.counters.CounterType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
public class VanishingUpkeepAbility extends BeginningOfUpkeepTriggeredAbility {
|
||||
|
||||
private int vanishingAmount;
|
||||
private String permanentType;
|
||||
|
||||
public VanishingUpkeepAbility(int vanishingEffect) {
|
||||
super(new VanishingEffect(), TargetController.YOU, false);
|
||||
this.vanishingAmount = vanishingEffect;
|
||||
this.permanentType = "creature";
|
||||
}
|
||||
|
||||
public VanishingUpkeepAbility(int vanishingEffect, String permanentType) {
|
||||
super(new VanishingEffect(), TargetController.YOU, false);
|
||||
this.vanishingAmount = vanishingEffect;
|
||||
this.permanentType = permanentType;
|
||||
}
|
||||
|
||||
protected VanishingUpkeepAbility(final VanishingUpkeepAbility ability) {
|
||||
super(ability);
|
||||
this.vanishingAmount = ability.vanishingAmount;
|
||||
this.permanentType = ability.permanentType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BeginningOfUpkeepTriggeredAbility copy() {
|
||||
return new VanishingUpkeepAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRule() {
|
||||
if (vanishingAmount > 0) {
|
||||
return "Vanishing " + vanishingAmount
|
||||
+ " <i>(This " + permanentType + " enters the battlefield with " + CardUtil.numberToText(vanishingAmount)
|
||||
+ " time counters on it. At the beginning of your upkeep, remove a time counter from it. When the last is removed, sacrifice it.)</i>";
|
||||
} else {
|
||||
return "Vanishing <i>(At the beginning of your upkeep, remove a time counter from this " + permanentType + ". When the last is removed, sacrifice it.)</i>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class VanishingEffect extends OneShotEffect {
|
||||
|
||||
VanishingEffect() {
|
||||
super(Outcome.Sacrifice);
|
||||
}
|
||||
|
||||
VanishingEffect(final VanishingEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Permanent p = game.getPermanent(source.getSourceId());
|
||||
if (p != null) {
|
||||
int amount = p.getCounters(game).getCount(CounterType.TIME);
|
||||
if (amount > 0) {
|
||||
p.removeCounters(CounterType.TIME.createInstance(), source, game);
|
||||
game.informPlayers("Removed a time counter from " + p.getLogName() + " (" + amount + " left)");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VanishingEffect copy() {
|
||||
return new VanishingEffect(this);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue