mirror of
https://github.com/correl/mage.git
synced 2025-01-11 19:13:02 +00:00
[core] Conditional effect. Condition interface. Metalcraft condition instance. Refactored SnapsailGlider.
This commit is contained in:
parent
47d0adf2f9
commit
d1a8bf399b
7 changed files with 128 additions and 58 deletions
|
@ -7,4 +7,7 @@
|
|||
#
|
||||
#
|
||||
graveyard:player:Plains:1
|
||||
|
||||
battlefield:player:Snapsail Glider:1
|
||||
battlefield:player:Whispersilk Cloak:1
|
||||
battlefield:player:Plains:3
|
||||
hand:player:Whispersilk Cloak:1
|
||||
|
|
|
@ -38,9 +38,12 @@ import mage.Constants.Zone;
|
|||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.condition.common.Metalcraft;
|
||||
import mage.abilities.decorator.ConditionalEffect;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.abilities.effects.common.GainAbilitySourceEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.abilities.keyword.ForestwalkAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
|
@ -48,17 +51,20 @@ import mage.game.permanent.Permanent;
|
|||
|
||||
/**
|
||||
*
|
||||
* @author Loki
|
||||
* @author Loki, nantuko
|
||||
*/
|
||||
public class SnapsailGlider extends CardImpl<SnapsailGlider> {
|
||||
|
||||
protected static String text = "Metalcraft - Snapsail Glider has flying as long as you control three or more artifacts";
|
||||
|
||||
public SnapsailGlider (UUID ownerId) {
|
||||
super(ownerId, 203, "Snapsail Glider", Rarity.COMMON, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}");
|
||||
this.expansionSetCode = "SOM";
|
||||
this.subtype.add("Construct");
|
||||
this.power = new MageInt(2);
|
||||
this.toughness = new MageInt(2);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new SnapsailGliderAbility()));
|
||||
ContinuousEffect effect = new GainAbilitySourceEffect(FlyingAbility.getInstance(), Duration.WhileOnBattlefield);
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalEffect(effect, Metalcraft.getIntance(), text)));
|
||||
}
|
||||
|
||||
public SnapsailGlider (final SnapsailGlider card) {
|
||||
|
@ -70,56 +76,3 @@ public class SnapsailGlider extends CardImpl<SnapsailGlider> {
|
|||
return new SnapsailGlider(this);
|
||||
}
|
||||
}
|
||||
|
||||
class SnapsailGliderAbility extends ContinuousEffectImpl<SnapsailGliderAbility> {
|
||||
|
||||
private static FilterPermanent filter = new FilterPermanent("artifact");
|
||||
|
||||
static {
|
||||
filter.getCardType().add(CardType.ARTIFACT);
|
||||
}
|
||||
|
||||
public SnapsailGliderAbility() {
|
||||
super(Duration.WhileOnBattlefield, Constants.Outcome.AddAbility);
|
||||
}
|
||||
|
||||
public SnapsailGliderAbility(final SnapsailGliderAbility ability) {
|
||||
super(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SnapsailGliderAbility copy() {
|
||||
return new SnapsailGliderAbility(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Constants.Layer layer, Constants.SubLayer sublayer, Ability source, Game game) {
|
||||
Permanent card = game.getPermanent(source.getSourceId());
|
||||
if (card != null && game.getBattlefield().countAll(filter, source.getControllerId()) >= 3) {
|
||||
switch (layer) {
|
||||
case AbilityAddingRemovingEffects_6:
|
||||
if (sublayer == Constants.SubLayer.NA) {
|
||||
card.addAbility(FlyingAbility.getInstance());
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLayer(Constants.Layer layer) {
|
||||
return layer == Constants.Layer.AbilityAddingRemovingEffects_6;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Ability source) {
|
||||
return "Metalcraft - Snapsail Glider has flying as long as you control three or more artifacts";
|
||||
}
|
||||
}
|
15
Mage/src/mage/abilities/condition/Condition.java
Normal file
15
Mage/src/mage/abilities/condition/Condition.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package mage.abilities.condition;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.game.Game;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* Interface describing condition occurrence.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public interface Condition extends Serializable {
|
||||
boolean apply(Game game, Ability source);
|
||||
}
|
32
Mage/src/mage/abilities/condition/common/Metalcraft.java
Normal file
32
Mage/src/mage/abilities/condition/common/Metalcraft.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* Describes condition when Metacraft mechanic is turned on.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class Metalcraft implements Condition {
|
||||
|
||||
private static FilterPermanent filter = new FilterPermanent("artifact");
|
||||
|
||||
static {
|
||||
filter.getCardType().add(Constants.CardType.ARTIFACT);
|
||||
}
|
||||
|
||||
private static Metalcraft fInstance = new Metalcraft();
|
||||
|
||||
public static Condition getIntance() {
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return game.getBattlefield().countAll(filter, source.getControllerId()) >= 3;
|
||||
}
|
||||
}
|
58
Mage/src/mage/abilities/decorator/ConditionalEffect.java
Normal file
58
Mage/src/mage/abilities/decorator/ConditionalEffect.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
package mage.abilities.decorator;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* Adds condition to effect. Acts as decorator.
|
||||
*
|
||||
* @author nantuko
|
||||
*/
|
||||
public class ConditionalEffect extends ContinuousEffectImpl<ConditionalEffect> {
|
||||
|
||||
protected ContinuousEffect effect;
|
||||
protected Condition condition;
|
||||
protected String text;
|
||||
|
||||
public ConditionalEffect(ContinuousEffect effect, Condition condition, String text) {
|
||||
super(effect.getDuration(), effect.getLayer(), effect.getSublayer(), effect.getOutcome());
|
||||
this.effect = effect;
|
||||
this.condition = condition;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Constants.Layer layer, Constants.SubLayer sublayer, Ability source, Game game) {
|
||||
if (condition.apply(game, source)) {
|
||||
return effect.apply(layer, sublayer, source, game);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (condition.apply(game, source)) {
|
||||
return effect.apply(game, source);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLayer(Constants.Layer layer) {
|
||||
return effect.hasLayer(layer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConditionalEffect copy() {
|
||||
return new ConditionalEffect(effect, condition, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Ability source) {
|
||||
return text;
|
||||
}
|
||||
}
|
|
@ -50,5 +50,6 @@ public interface ContinuousEffect<T extends ContinuousEffect<T>> extends Effect<
|
|||
public boolean hasLayer(Layer layer);
|
||||
public boolean isInactive(Ability source, Game game);
|
||||
public void init(Ability source, Game game);
|
||||
|
||||
public Layer getLayer();
|
||||
public SubLayer getSublayer();
|
||||
}
|
||||
|
|
|
@ -150,4 +150,12 @@ public abstract class ContinuousEffectImpl<T extends ContinuousEffectImpl<T>> ex
|
|||
return false;
|
||||
}
|
||||
|
||||
public Layer getLayer() {
|
||||
return layer;
|
||||
}
|
||||
|
||||
public SubLayer getSublayer() {
|
||||
return sublayer;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue