Refactor damage with power effect, added checking for wrong targets;

This commit is contained in:
Oleg Agafonov 2020-01-13 13:49:40 +04:00
parent 62530b3880
commit 4a004a27b3
16 changed files with 212 additions and 131 deletions

View file

@ -1,7 +1,6 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -10,8 +9,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class AggressiveInstinct extends CardImpl {
@ -26,7 +26,7 @@ public final class AggressiveInstinct extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{G}");
// Target creature you control deals damage equal to its power to target creature you don't control.
this.getSpellAbility().addEffect(new DamageWithPowerTargetEffect());
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect());
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
}

View file

@ -1,9 +1,7 @@
package mage.cards.a;
import java.util.UUID;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -14,8 +12,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author ciaccona007
*/
public final class Ambuscade extends CardImpl {
@ -31,14 +30,12 @@ public final class Ambuscade extends CardImpl {
// Target creature you control gets +1/+0 until end of turn.
Effect effect = new BoostTargetEffect(1, 0, Duration.EndOfTurn);
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
// It deals damage equal to its power to target creature you don't control.
effect = new DamageWithPowerTargetEffect();
effect.setText("It deals damage equal to its power to target creature you don't control");
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect("It"));
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); // second target for effect
}
public Ambuscade(final Ambuscade card) {

View file

@ -1,9 +1,7 @@
package mage.cards.c;
import java.util.UUID;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.continuous.BoostTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
@ -14,8 +12,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class ClearShot extends CardImpl {
@ -35,10 +34,9 @@ public final class ClearShot extends CardImpl {
this.getSpellAbility().addEffect(effect);
// It deals damage equal to its power to target creature you don't control.
effect = new DamageWithPowerTargetEffect();
effect.setText("It deals damage equal to its power to target creature you don't control");
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect("It"));
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); // second target
}
public ClearShot(final ClearShot card) {

View file

@ -2,7 +2,8 @@ package mage.cards.d;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -33,9 +34,12 @@ public final class DomrisAmbush extends CardImpl {
public DomrisAmbush(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{R}{G}");
// Put a +1/+1 counter on target creature you control. Then that creature deals damage equal to its power to target creature or planeswalker you don't control.
this.getSpellAbility().addEffect(new DomrisAmbushEffect());
// Put a +1/+1 counter on target creature you control.
this.getSpellAbility().addEffect(new AddCountersTargetEffect(CounterType.P1P1.createInstance()));
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
// Then that creature deals damage equal to its power to target creature or planeswalker you don't control.
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect("that creature").concatBy("Then"));
this.getSpellAbility().addTarget(new TargetPermanent(filter));
}
@ -75,6 +79,6 @@ class DomrisAmbushEffect extends OneShotEffect {
}
permanent.addCounters(CounterType.P1P1.createInstance(), source, game);
game.applyEffects();
return new DamageWithPowerTargetEffect().apply(game, source);
return new DamageWithPowerFromOneToAnotherTargetEffect().apply(game, source);
}
}

View file

@ -1,9 +1,6 @@
package mage.cards.n;
import java.util.UUID;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.abilities.keyword.VigilanceAbility;
@ -16,8 +13,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class NaturesWay extends CardImpl {
@ -32,19 +30,15 @@ public final class NaturesWay extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{G}");
// Target creature you control gains vigilance and trample until end of turn.
Effect effect = new GainAbilityTargetEffect(VigilanceAbility.getInstance(), Duration.EndOfTurn);
effect.setText("Target creature you control gains vigilance");
this.getSpellAbility().addEffect(effect);
effect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
effect.setText("and trample until end of turn");
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addEffect(new GainAbilityTargetEffect(VigilanceAbility.getInstance(), Duration.EndOfTurn)
.setText("Target creature you control gains vigilance"));
this.getSpellAbility().addEffect(new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn)
.setText("and trample until end of turn"));
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
// It deals damage equal to its power to target creature you don't control.
effect = new DamageWithPowerTargetEffect();
effect.setText("It deals damage equal to its power to target creature you don't control");
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(effect);
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect("It"));
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter)); // second target
}
public NaturesWay(final NaturesWay card) {

View file

@ -1,8 +1,6 @@
package mage.cards.r;
import java.util.UUID;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -11,8 +9,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author fireshoes
*/
public final class RabidBite extends CardImpl {
@ -27,9 +26,9 @@ public final class RabidBite extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{G}");
// Target creature you control deals damage equal to its power to target creature you don't control.
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect());
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(new DamageWithPowerTargetEffect());
}
public RabidBite(final RabidBite card) {

View file

@ -1,7 +1,5 @@
package mage.cards.s;
import java.util.UUID;
import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.DiesCreatureTriggeredAbility;
@ -9,19 +7,16 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.HasteAbility;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.constants.*;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetPlayerOrPlaneswalker;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class StalkingVengeance extends CardImpl {
@ -42,7 +37,8 @@ public final class StalkingVengeance extends CardImpl {
// Haste
this.addAbility(HasteAbility.getInstance());
// Whenever another creature you control dies, it deals damage equal to its power to target player.
// Whenever another creature you control dies, it deals damage equal to its power to target player or planeswalker.
Ability ability = new DiesCreatureTriggeredAbility(new StalkingVengeanceDamageEffect(), false, filter, true);
ability.addTarget(new TargetPlayerOrPlaneswalker());
this.addAbility(ability);

View file

@ -1,8 +1,6 @@
package mage.cards.t;
import java.util.UUID;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
@ -11,8 +9,9 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author LevelX2
*/
public final class TailSlash extends CardImpl {
@ -27,9 +26,9 @@ public final class TailSlash extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{R}");
// Target creature you control deals damage equal to its power to target creature you don't control.
this.getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect());
this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
this.getSpellAbility().addTarget(new TargetCreaturePermanent(filter));
this.getSpellAbility().addEffect(new DamageWithPowerTargetEffect());
}
public TailSlash(final TailSlash card) {

View file

@ -1,7 +1,7 @@
package mage.cards.t;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.cards.CardSetInfo;
import mage.cards.SplitCard;
import mage.constants.CardType;
@ -32,11 +32,7 @@ public final class ThrashThreat extends SplitCard {
// Thrash
// Target creature you control deals damage equal to its power to target creature or planeswalker you don't control.
this.getLeftHalfCard().getSpellAbility().addEffect(
new DamageWithPowerTargetEffect()
.setText("Target creature you control deals damage equal to its power " +
"to target creature or planeswalker you don't control.")
);
this.getLeftHalfCard().getSpellAbility().addEffect(new DamageWithPowerFromOneToAnotherTargetEffect());
this.getLeftHalfCard().getSpellAbility().addTarget(new TargetControlledCreaturePermanent());
this.getLeftHalfCard().getSpellAbility().addTarget(new TargetPermanent(filter));

View file

@ -3,7 +3,7 @@ package mage.cards.v;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.WishEffect;
import mage.abilities.effects.common.continuous.GainAbilityTargetEffect;
import mage.abilities.effects.common.counter.DistributeCountersEffect;
@ -16,13 +16,13 @@ import mage.constants.SubType;
import mage.constants.SuperType;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreatureOrPlaneswalker;
import mage.target.common.TargetCreaturePermanentAmount;
import mage.target.targetadjustment.TargetAdjuster;
import java.util.UUID;
import mage.game.Game;
import mage.target.targetadjustment.TargetAdjuster;
/**
* @author TheElk801
@ -48,14 +48,11 @@ public final class VivienArkbowRanger extends CardImpl {
target.setMaxNumberOfTargets(2);
ability.addTarget(target);
// ability.setTargetAdjuster(VivienArkbowRangerAdjuster.instance);
// ability.setTargetAdjuster(VivienArkbowRangerAdjuster.instance);
this.addAbility(ability);
// 3: Target creature you control deals damage equal to its power to target creature or planeswalker.
ability = new LoyaltyAbility(
new DamageWithPowerTargetEffect().setText("Target creature you control deals damage "
+ "equal to its power to target creature or planeswalker."), -3
);
ability = new LoyaltyAbility(new DamageWithPowerFromOneToAnotherTargetEffect(), -3);
ability.addTarget(new TargetControlledCreaturePermanent());
ability.addTarget(new TargetCreatureOrPlaneswalker());
this.addAbility(ability);

View file

@ -1,29 +1,25 @@
package mage.cards.v;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.LoyaltyAbility;
import mage.abilities.common.PlaneswalkerEntersWithLoyaltyCountersAbility;
import mage.abilities.effects.common.DamageWithPowerTargetEffect;
import mage.abilities.effects.common.DamageWithPowerFromOneToAnotherTargetEffect;
import mage.abilities.effects.common.continuous.BoostControlledEffect;
import mage.abilities.effects.common.continuous.GainAbilityControlledEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.abilities.keyword.TrampleAbility;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.TargetController;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.target.common.TargetCreaturePermanent;
import java.util.UUID;
/**
*
* @author TheElk801
*/
public final class VivienOfTheArkbow extends CardImpl {
@ -47,7 +43,7 @@ public final class VivienOfTheArkbow extends CardImpl {
this.addAbility(ability);
// 3: Target creature you control deals damage equal to its power to target creature you don't control.
ability = new LoyaltyAbility(new DamageWithPowerTargetEffect(), -3);
ability = new LoyaltyAbility(new DamageWithPowerFromOneToAnotherTargetEffect(), -3);
ability.addTarget(new TargetControlledCreaturePermanent());
ability.addTarget(new TargetCreaturePermanent(filter));
this.addAbility(ability);

View file

@ -921,7 +921,12 @@ public class VerifyCardDataTest {
CardSetInfo testSet = new CardSetInfo(cardName, "test", "123", Rarity.COMMON);
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
card.getRules().stream().forEach(System.out::println);
System.out.println(card.getName());
if (card instanceof SplitCard) {
card.getAbilities().getRules(card.getName()).stream().forEach(System.out::println);
} else {
card.getRules().stream().forEach(System.out::println);
}
}
private void checkWrongAbilitiesText(Card card, JsonCard ref) {

View file

@ -0,0 +1,73 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author JayDi85
*/
public class DamageWithPowerFromOneToAnotherTargetEffect extends OneShotEffect {
String firstTargetName;
public DamageWithPowerFromOneToAnotherTargetEffect() {
this((String) null);
}
public DamageWithPowerFromOneToAnotherTargetEffect(String firstTargetName) {
super(Outcome.Damage);
this.firstTargetName = firstTargetName;
}
public DamageWithPowerFromOneToAnotherTargetEffect(final DamageWithPowerFromOneToAnotherTargetEffect effect) {
super(effect);
this.firstTargetName = effect.firstTargetName;
}
@Override
public boolean apply(Game game, Ability source) {
if (source.getTargets().size() != 2) {
throw new IllegalStateException("It must have two targets, but found " + source.getTargets().size());
}
Permanent myPermanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
Permanent anotherPermanent = game.getPermanent(source.getTargets().get(1).getFirstTarget());
Player anotherPlayer = game.getPlayer(source.getTargets().get(1).getFirstTarget());
if (myPermanent != null && anotherPermanent != null) {
anotherPermanent.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
return true;
} else if (myPermanent != null && anotherPlayer != null) {
anotherPlayer.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
return true;
}
return false;
}
@Override
public DamageWithPowerFromOneToAnotherTargetEffect copy() {
return new DamageWithPowerFromOneToAnotherTargetEffect(this);
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
if (mode.getTargets().size() != 2) {
throw new IllegalStateException("It must have two targets, but found " + mode.getTargets().size());
}
// Target creature you control deals damage equal to its power to target creature you don't control
String sb = (this.firstTargetName != null ? this.firstTargetName : "Target " + mode.getTargets().get(0).getTargetName()) +
" deals damage equal to its power to target " +
mode.getTargets().get(1).getTargetName();
return sb;
}
}

View file

@ -0,0 +1,70 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
* @author JayDi85
*/
public class DamageWithPowerFromSourceToAnotherTargetEffect extends OneShotEffect {
String sourceTargetName;
public DamageWithPowerFromSourceToAnotherTargetEffect() {
this("It");
}
public DamageWithPowerFromSourceToAnotherTargetEffect(String sourceTargetName) {
super(Outcome.Damage);
this.sourceTargetName = sourceTargetName;
}
public DamageWithPowerFromSourceToAnotherTargetEffect(final DamageWithPowerFromSourceToAnotherTargetEffect effect) {
super(effect);
this.sourceTargetName = effect.sourceTargetName;
}
@Override
public boolean apply(Game game, Ability source) {
if (source.getTargets().size() != 1) {
throw new IllegalStateException("It must have one target, but found " + source.getTargets().size());
}
Permanent myPermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Permanent anotherPermanent = game.getPermanent(source.getTargets().get(0).getFirstTarget());
Player anotherPlayer = game.getPlayer(source.getTargets().get(0).getFirstTarget());
if (myPermanent != null && anotherPermanent != null) {
anotherPermanent.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
return true;
} else if (myPermanent != null && anotherPlayer != null) {
anotherPlayer.damage(myPermanent.getPower().getValue(), myPermanent.getId(), game, false, true);
return true;
}
return false;
}
@Override
public DamageWithPowerFromSourceToAnotherTargetEffect copy() {
return new DamageWithPowerFromSourceToAnotherTargetEffect(this);
}
@Override
public String getText(Mode mode) {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
if (mode.getTargets().size() != 1) {
throw new IllegalStateException("It must have one targets, but found " + mode.getTargets().size());
}
// It deals damage equal to its power to target creature you don't control
return this.sourceTargetName + " deals damage equal to its power to target " + mode.getTargets().get(0).getTargetName();
}
}

View file

@ -1,45 +0,0 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
/**
*
* @author Styxo
*/
public class DamageWithPowerTargetEffect extends OneShotEffect {
public DamageWithPowerTargetEffect() {
super(Outcome.Damage);
staticText = "Target creature you control deals damage equal to its power to target creature you don't control";
}
public DamageWithPowerTargetEffect(final DamageWithPowerTargetEffect effect) {
super(effect);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent controlledCreature = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
Permanent targetCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
if (controller != null) {
if (targetCreature != null && controlledCreature != null) {
targetCreature.damage(controlledCreature.getPower().getValue(), controlledCreature.getId(), game, false, true);
}
return true;
}
return false;
}
@Override
public DamageWithPowerTargetEffect copy() {
return new DamageWithPowerTargetEffect(this);
}
}

View file

@ -144,7 +144,9 @@ public final class RateCard {
return 1;
}
}
if (effect instanceof FightTargetsEffect || effect instanceof DamageWithPowerTargetEffect) {
if (effect instanceof FightTargetsEffect
|| effect instanceof DamageWithPowerFromOneToAnotherTargetEffect
|| effect instanceof DamageWithPowerFromSourceToAnotherTargetEffect) {
return 1;
}
if (effect.getOutcome() == Outcome.Damage || effect instanceof DamageTargetEffect) {