refactor text gen for PutOnTopOrBottomLibraryTargetEffect

This commit is contained in:
xenohedron 2024-01-21 23:24:00 -05:00
parent 6eb1cb834d
commit 340156a84b
16 changed files with 32 additions and 63 deletions

View file

@ -15,10 +15,6 @@ public class DamageWithPowerFromSourceToAnotherTargetEffect extends OneShotEffec
String sourceTargetName;
public DamageWithPowerFromSourceToAnotherTargetEffect() {
this("It");
}
public DamageWithPowerFromSourceToAnotherTargetEffect(String sourceTargetName) {
super(Outcome.Damage);
this.sourceTargetName = sourceTargetName;
@ -36,8 +32,8 @@ public class DamageWithPowerFromSourceToAnotherTargetEffect extends OneShotEffec
}
Permanent myPermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
Permanent anotherPermanent = game.getPermanent(source.getTargets().get(0).getFirstTarget());
Player anotherPlayer = game.getPlayer(source.getTargets().get(0).getFirstTarget());
Permanent anotherPermanent = game.getPermanent(source.getFirstTarget());
Player anotherPlayer = game.getPlayer(source.getFirstTarget());
if (myPermanent != null && anotherPermanent != null) {
anotherPermanent.damage(myPermanent.getPower().getValue(), myPermanent.getId(), source, game, false, true);
@ -65,6 +61,7 @@ public class DamageWithPowerFromSourceToAnotherTargetEffect extends OneShotEffec
}
// 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();
return sourceTargetName + " deals damage equal to its power to "
+ getTargetPointer().describeTargets(mode.getTargets(), "that creature");
}
}

View file

@ -1,13 +1,11 @@
package mage.abilities.effects.common;
import mage.MageObject;
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.target.Target;
/**
* @author LevelX2
@ -24,21 +22,14 @@ public class FightTargetSourceEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null) {
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
Permanent creature1 = game.getPermanent(getTargetPointer().getFirst(game, source));
// 20110930 - 701.10
if (creature1 != null && sourcePermanent != null) {
if (creature1.isCreature(game) && sourcePermanent.isCreature(game)) {
return sourcePermanent.fight(creature1, source, game);
}
}
if (!game.isSimulation()) {
game.informPlayers(sourceObject.getLogName() + ": Fighting effect has been fizzled.");
}
// 701.12
Permanent sourceCreature = source.getSourcePermanentIfItStillExists(game);
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (sourceCreature == null || !sourceCreature.isCreature(game)
|| targetCreature == null || !targetCreature.isCreature(game)) {
return false;
}
return false;
return sourceCreature.fight(targetCreature, source, game);
}
@Override
@ -51,15 +42,6 @@ public class FightTargetSourceEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
Target target = mode.getTargets().get(0);
StringBuilder sb = new StringBuilder("{this} fights ");
if (target.getMinNumberOfTargets() == 0 && target.getMaxNumberOfTargets() == 1) {
sb.append("up to one ");
}
if (!target.getTargetName().contains("other")) {
sb.append("target ");
}
sb.append(target.getTargetName());
return sb.toString();
return "{this} fights " + getTargetPointer().describeTargets(mode.getTargets(), "that creature");
}
}

View file

@ -12,17 +12,16 @@ import mage.players.Player;
*/
public class PutOnTopOrBottomLibraryTargetEffect extends OneShotEffect {
public PutOnTopOrBottomLibraryTargetEffect() {
this("");
}
private final boolean textOwnerOf;
public PutOnTopOrBottomLibraryTargetEffect(String text) {
super(Outcome.Benefit);
staticText = text;
public PutOnTopOrBottomLibraryTargetEffect(boolean textOwnerOf) {
super(Outcome.ReturnToHand);
this.textOwnerOf = textOwnerOf;
}
private PutOnTopOrBottomLibraryTargetEffect(final PutOnTopOrBottomLibraryTargetEffect effect) {
super(effect);
this.textOwnerOf = effect.textOwnerOf;
}
@Override
@ -48,7 +47,8 @@ public class PutOnTopOrBottomLibraryTargetEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "the owner of target " + mode.getTargets().get(0).getTargetName() +
String targetText = getTargetPointer().describeTargets(mode.getTargets(), "that permanent");
return (textOwnerOf ? "the owner of " + targetText : targetText + "'s owner") +
" puts it on the top or bottom of their library";
}
}