New AttachedPermanentToughnessValue, updated DamageAttachedControllerEffect to take DynamicValue (ex. to work with AttachedPermanentToughnessValue), and updated Creature Bond to use AttachedPermanentToughnessValue and DamageAttachedControllerEffect. Corrected Gaea's Liege, Kor Scythemaster, Soltari Lancer, and Spirit of the Night to use SourceAttackingCondition. Rmoved the AttackingCondition we creature for Gaea's Liege since it duplicated the already existing SourceAttackingCondition. For the other three using SourceAttackingCondition and the minor changes to the code for them should make their code more efficient.

This commit is contained in:
MTGfan 2016-11-26 03:57:46 -05:00
parent cd6917be93
commit 36d6c006ca
8 changed files with 136 additions and 168 deletions

View file

@ -29,24 +29,21 @@ package mage.cards.c;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.common.DiesAttachedTriggeredAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.dynamicvalue.common.AttachedPermanentToughnessValue;
import mage.abilities.effects.common.AttachEffect;
import mage.abilities.effects.common.DamageAttachedControllerEffect;
import mage.abilities.keyword.EnchantAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetPermanent;
import mage.target.common.TargetCreaturePermanent;
/**
*
* @author Styxo
* @author MTGfan
*/
public class CreatureBond extends CardImpl {
@ -58,13 +55,12 @@ public class CreatureBond extends CardImpl {
// Enchant creature
TargetPermanent auraTarget = new TargetCreaturePermanent();
this.getSpellAbility().addTarget(auraTarget);
this.getSpellAbility().addEffect(new AttachEffect(Outcome.Benefit));
this.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));
Ability ability = new EnchantAbility(auraTarget.getTargetName());
this.addAbility(ability);
// When enchanted creature dies, Creature Bond deals damage equal to that creature's toughness to the creature's controller.
this.addAbility(new DiesAttachedTriggeredAbility(new CreatureBondEffect(), "enchanted creature"));
this.addAbility( new DiesAttachedTriggeredAbility(new DamageAttachedControllerEffect(new AttachedPermanentToughnessValue()), "enchanted creature"));
}
public CreatureBond(final CreatureBond card) {
@ -76,38 +72,3 @@ public class CreatureBond extends CardImpl {
return new CreatureBond(this);
}
}
class CreatureBondEffect extends OneShotEffect {
public CreatureBondEffect() {
super(Outcome.Damage);
}
public CreatureBondEffect(CreatureBondEffect copy) {
super(copy);
}
@Override
public CreatureBondEffect copy() {
return new CreatureBondEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = (Permanent) getValue("attachedTo");
if (creature != null) {
Player player = game.getPlayer(creature.getOwnerId());
if (player != null) {
player.damage(creature.getToughness().getValue(), source.getId(), game, false, true);
return true;
}
}
return false;
}
@Override
public String getText(Mode mode) {
return "{this} deals damage equal to that creature's toughness to the creature's controller";
}
}

View file

@ -32,7 +32,7 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.AttackingCondition;
import mage.abilities.condition.common.SourceAttackingCondition;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.dynamicvalue.DynamicValue;
@ -76,7 +76,7 @@ public class GaeasLiege extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.ALL, new ConditionalContinuousEffect(
new SetPowerToughnessSourceEffect(new DefendersForestCount(), Duration.EndOfCombat),
new SetPowerToughnessSourceEffect(new PermanentsOnBattlefieldCount(filterLands), Duration.EndOfGame),
AttackingCondition.getInstance(),
SourceAttackingCondition.getInstance(),
"As long as {this} isn't attacking, its power and toughness are each equal to the number of Forests you control. As long as {this} is attacking, its power and toughness are each equal to the number of Forests defending player controls.")));
// {tap}: Target land becomes a Forest until Gaea's Liege leaves the battlefield.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesBasicLandTargetEffect(Duration.WhileOnBattlefield, "Forest"), new TapSourceCost());

View file

@ -30,7 +30,7 @@ package mage.cards.k;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.condition.common.SourceAttackingCondition;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.FirstStrikeAbility;
@ -38,7 +38,6 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Zone;
import mage.filter.common.FilterAttackingCreature;
/**
*
@ -46,8 +45,6 @@ import mage.filter.common.FilterAttackingCreature;
*/
public class KorScythemaster extends CardImpl {
private static final String rule = "{this} has first strike as long as it's attacking";
public KorScythemaster(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}");
this.subtype.add("Kor");
@ -57,9 +54,7 @@ public class KorScythemaster extends CardImpl {
this.toughness = new MageInt(1);
// Kor Scythemaster has first strike as long as its attacking.
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()),
new SourceMatchesFilterCondition(new FilterAttackingCreature()), rule);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()), SourceAttackingCondition.getInstance(), "{this} has first strike as long as it's attacking")));
}
public KorScythemaster(final KorScythemaster card) {

View file

@ -30,7 +30,7 @@ package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.condition.common.SourceAttackingCondition;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.FirstStrikeAbility;
@ -39,7 +39,6 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Zone;
import mage.filter.common.FilterAttackingCreature;
/**
*
@ -47,8 +46,6 @@ import mage.filter.common.FilterAttackingCreature;
*/
public class SoltariLancer extends CardImpl {
private static final String rule = "{this} has first strike as long as it's attacking";
public SoltariLancer(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{W}");
this.subtype.add("Soltari");
@ -60,8 +57,7 @@ public class SoltariLancer extends CardImpl {
this.addAbility(ShadowAbility.getInstance());
// Soltari Lancer has first strike as long as it's attacking.
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()), new SourceMatchesFilterCondition(new FilterAttackingCreature()), rule);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()), SourceAttackingCondition.getInstance(), "{this} has first strike as long as it's attacking")));
}
public SoltariLancer(final SoltariLancer card) {

View file

@ -31,16 +31,15 @@ import mage.constants.CardType;
import mage.MageInt;
import mage.ObjectColor;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.common.continuous.GainAbilitySourceEffect;
import mage.abilities.keyword.*;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.Zone;
import mage.filter.common.FilterAttackingCreature;
import java.util.UUID;
import mage.abilities.condition.common.SourceAttackingCondition;
/**
*
@ -48,8 +47,6 @@ import java.util.UUID;
*/
public class SpiritOfTheNight extends CardImpl {
private static final String rule = "Spirit of the Night has first strike as long as it's attacking";
public SpiritOfTheNight(UUID ownerId, CardSetInfo setInfo) {
super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{6}{B}{B}{B}");
this.supertype.add("Legendary");
@ -72,8 +69,7 @@ public class SpiritOfTheNight extends CardImpl {
this.addAbility(ProtectionAbility.from(ObjectColor.BLACK));
// Spirit of the Night has first strike as long as it's attacking.
ConditionalContinuousEffect effect = new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()), new SourceMatchesFilterCondition(new FilterAttackingCreature()), rule);
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, effect));
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new ConditionalContinuousEffect(new GainAbilitySourceEffect(FirstStrikeAbility.getInstance()), SourceAttackingCondition.getInstance(), "{this} has first strike as long as it's attacking")));
}
public SpiritOfTheNight(final SpiritOfTheNight card) {

View file

@ -1,30 +0,0 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author anonymous
*/
public class AttackingCondition implements Condition {
private static final AttachedCondition fInstance = new AttachedCondition();
public static AttachedCondition getInstance() {
return fInstance;
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
return permanent != null && permanent.isAttacking();
}
}

View file

@ -0,0 +1,41 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
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.game.permanent.Permanent;
/**
*
* @author MTGfan
*/
public class AttachedPermanentToughnessValue implements DynamicValue {
@Override
public int calculate(Game game, Ability source, Effect effect) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
Permanent enchanted = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
return enchanted.getToughness().getValue();
}
@Override
public AttachedPermanentToughnessValue copy(){
return new AttachedPermanentToughnessValue();
}
@Override
public String toString() {
return "equal to";
}
@Override
public String getMessage() {
return "that creature's toughness";
}
}

View file

@ -30,6 +30,8 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
@ -42,9 +44,14 @@ import mage.players.Player;
*/
public class DamageAttachedControllerEffect extends OneShotEffect {
protected int amount;
protected DynamicValue amount;
public DamageAttachedControllerEffect(int amount) {
super(Outcome.Damage);
this.amount = new StaticValue(amount);
}
public DamageAttachedControllerEffect(DynamicValue amount) {
super(Outcome.Damage);
this.amount = amount;
}
@ -71,7 +78,7 @@ public class DamageAttachedControllerEffect extends OneShotEffect {
}
Player player = game.getPlayer(enchanted.getControllerId());
if(player != null) {
player.damage(amount, source.getSourceId(), game, false, true);
player.damage(amount.calculate(game, source, this), source.getSourceId(), game, false, true);
return true;
}
return false;
@ -81,8 +88,10 @@ public class DamageAttachedControllerEffect extends OneShotEffect {
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
if ("equal to".equals(amount.toString())) {
return "{this} deals damage " + amount + " that creatures toughness to that creature's controller";
}
return "{this} deals " + amount + " damage to that creature's controller";
}
}