Refactor: improved emblem rules generation;

This commit is contained in:
Oleg Agafonov 2019-01-03 11:41:34 +04:00
parent e1630b3c6f
commit a4e374f96a
11 changed files with 63 additions and 91 deletions

View file

@ -2,6 +2,7 @@ package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.constants.Zone;
@ -17,6 +18,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
private final boolean useController;
private final boolean useLKI;
private String copyThatSpellName = "that spell";
public CopyTargetSpellEffect() {
this(false);
@ -38,6 +40,11 @@ public class CopyTargetSpellEffect extends OneShotEffect {
this.useController = effect.useController;
}
public Effect withSpellName(String copyThatSpellName) {
this.copyThatSpellName = copyThatSpellName;
return this;
}
@Override
public boolean apply(Game game, Ability source) {
Spell spell;
@ -81,7 +88,7 @@ public class CopyTargetSpellEffect extends OneShotEffect {
if (!mode.getTargets().isEmpty()) {
sb.append("target ").append(mode.getTargets().get(0).getTargetName());
} else {
sb.append("that spell");
sb.append(copyThatSpellName);
}
sb.append(". You may choose new targets for the copy");

View file

@ -1,4 +1,3 @@
package mage.abilities.effects.common;
import mage.MageObject;
@ -10,8 +9,9 @@ import mage.game.Game;
import mage.game.command.Emblem;
import mage.players.Player;
import java.util.stream.Collectors;
/**
*
* @author LevelX2
*/
public class GetEmblemTargetPlayerEffect extends OneShotEffect {
@ -53,6 +53,6 @@ public class GetEmblemTargetPlayerEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "Target " + mode.getTargets().get(0).getTargetName() + " gets an emblem with \"" + emblem.getAbilities().getRules(null) + '"';
return "Target " + mode.getTargets().get(0).getTargetName() + " gets an emblem with \"" + emblem.getAbilities().getRules(null).stream().collect(Collectors.joining("; ")) + "\"";
}
}

View file

@ -1,24 +1,18 @@
package mage.abilities.effects.common.continuous;
import java.util.Locale;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.constants.DependencyType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.constants.SubLayer;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import java.util.Locale;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GainAbilityTargetEffect extends ContinuousEffectImpl {
@ -88,9 +82,7 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
return true;
}
if (durationPhaseStep != null && durationPhaseStep == game.getPhase().getStep().getType()) {
if (!sameStep && game.isActivePlayer(durationPlayerId) || game.getPlayer(durationPlayerId).hasReachedNextTurnAfterLeaving()) {
return true;
}
return !sameStep && game.isActivePlayer(durationPlayerId) || game.getPlayer(durationPlayerId).hasReachedNextTurnAfterLeaving();
} else {
sameStep = false;
}
@ -137,21 +129,26 @@ public class GainAbilityTargetEffect extends ContinuousEffectImpl {
return staticText;
}
StringBuilder sb = new StringBuilder();
Target target = mode.getTargets().get(0);
if (target.getMaxNumberOfTargets() == Integer.MAX_VALUE) {
sb.append("any number of target ").append(target.getTargetName()).append(" gain ");
} else if (target.getMaxNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("up to ");
}
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" gain ");
} else {
if (!target.getTargetName().toUpperCase(Locale.ENGLISH).startsWith("ANOTHER")) {
sb.append("target ");
}
sb.append(target.getTargetName()).append(" gains ");
if (mode.getTargets().size() > 0) {
Target target = mode.getTargets().get(0);
if (target.getMaxNumberOfTargets() == Integer.MAX_VALUE) {
sb.append("any number of target ").append(target.getTargetName()).append(" gain ");
} else if (target.getMaxNumberOfTargets() > 1) {
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("up to ");
}
sb.append(target.getMaxNumberOfTargets()).append(" target ").append(target.getTargetName()).append(" gain ");
} else {
if (!target.getTargetName().toUpperCase(Locale.ENGLISH).startsWith("ANOTHER")) {
sb.append("target ");
}
sb.append(target.getTargetName()).append(" gains ");
}
} else {
sb.append("gains ");
}
sb.append(ability.getRule());
if (durationPhaseStep != null) {
sb.append(" until your next ").append(durationPhaseStep.toString().toLowerCase(Locale.ENGLISH));

View file

@ -477,7 +477,7 @@ public final class StaticFilters {
FILTER_SPELL_AN_INSTANT_OR_SORCERY.setLockedFilter(true);
}
public static final FilterSpell FILTER_SPELL_INSTANT_OR_SORCERY = new FilterSpell("instant or sorcery spell");
public static final FilterSpell FILTER_SPELL_INSTANT_OR_SORCERY = new FilterSpell("an instant or sorcery spell");
static {
FILTER_SPELL_INSTANT_OR_SORCERY.add(Predicates.or(

View file

@ -1,4 +1,3 @@
package mage.game.command.emblems;
import mage.abilities.Ability;
@ -13,7 +12,6 @@ import mage.constants.Zone;
import mage.game.command.Emblem;
/**
*
* @author spjspj
*/
public final class GarrukApexPredatorEmblem extends Emblem {
@ -25,12 +23,12 @@ public final class GarrukApexPredatorEmblem extends Emblem {
public GarrukApexPredatorEmblem() {
setName("Emblem Garruk");
Effect effect = new BoostTargetEffect(5, 5, Duration.EndOfTurn);
effect.setText("it gets +5/+5");
Effect effect = new BoostTargetEffect(-1, 0, Duration.EndOfTurn);
effect.setText("it gets -1/-0");
Ability ability = new AttackedByCreatureTriggeredAbility(Zone.COMMAND, effect, false, SetTargetPointer.PERMANENT);
effect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn,
"and gains trample until end of turn");
ability.addEffect(effect);
effect = new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn);
ability.addEffect(effect.concatBy("and"));
this.getAbilities().add(ability);
}
}

View file

@ -1,4 +1,3 @@
package mage.game.command.emblems;
import mage.abilities.common.SpellCastControllerTriggeredAbility;
@ -8,7 +7,6 @@ import mage.filter.StaticFilters;
import mage.game.command.Emblem;
/**
*
* @author TheElk801
*/
public final class WillKenrithEmblem extends Emblem {
@ -18,8 +16,7 @@ public final class WillKenrithEmblem extends Emblem {
this.setName("Emblem Will Kenrith");
this.getAbilities().add(new SpellCastControllerTriggeredAbility(
Zone.COMMAND,
new CopyTargetSpellEffect(true)
.setText("copy that spell. You may choose new targets for the copy"),
new CopyTargetSpellEffect(true).withSpellName("it"),
StaticFilters.FILTER_SPELL_INSTANT_OR_SORCERY,
false,
true