forked from External/mage
simplify DoIfClashWonEffect
This commit is contained in:
parent
4d3b944b65
commit
63706942db
2 changed files with 24 additions and 42 deletions
|
|
@ -1,5 +1,3 @@
|
|||
|
||||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.MageObject;
|
||||
|
|
@ -12,7 +10,6 @@ import mage.constants.Outcome;
|
|||
import mage.game.Game;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
|
|
@ -22,62 +19,47 @@ import java.util.UUID;
|
|||
|
||||
public class DoIfClashWonEffect extends OneShotEffect {
|
||||
protected final Effect executingEffect;
|
||||
private String chooseUseText;
|
||||
private boolean setTargetPointerToClashedOpponent;
|
||||
private final boolean setTargetPointerToClashedOpponent;
|
||||
|
||||
public DoIfClashWonEffect(Effect effect) {
|
||||
this(effect, false, null);
|
||||
this(effect, false);
|
||||
}
|
||||
|
||||
public DoIfClashWonEffect(Effect effect, boolean setTargetPointerToClashedOpponent, String chooseUseText) {
|
||||
public DoIfClashWonEffect(Effect effect, boolean setTargetPointerToClashedOpponent) {
|
||||
super(Outcome.Benefit);
|
||||
this.executingEffect = effect;
|
||||
this.chooseUseText = chooseUseText;
|
||||
this.setTargetPointerToClashedOpponent = setTargetPointerToClashedOpponent;
|
||||
}
|
||||
|
||||
public DoIfClashWonEffect(final DoIfClashWonEffect effect) {
|
||||
super(effect);
|
||||
this.executingEffect = effect.executingEffect.copy();
|
||||
this.chooseUseText = effect.chooseUseText;
|
||||
this.setTargetPointerToClashedOpponent = effect.setTargetPointerToClashedOpponent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player player = getPayingPlayer(game, source);
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
MageObject mageObject = game.getObject(source);
|
||||
if (player != null && mageObject != null) {
|
||||
String message = null;
|
||||
if (chooseUseText != null) {
|
||||
message = chooseUseText;
|
||||
message = CardUtil.replaceSourceName(message, mageObject.getLogName());
|
||||
}
|
||||
|
||||
if (chooseUseText == null || player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
|
||||
if (new ClashEffect().apply(game, source)) {
|
||||
if (setTargetPointerToClashedOpponent) {
|
||||
Player opponent = game.getPlayer((UUID) getValue("clashOpponent"));
|
||||
if (opponent != null) {
|
||||
executingEffect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
}
|
||||
} else {
|
||||
executingEffect.setTargetPointer(this.targetPointer);
|
||||
}
|
||||
if (executingEffect instanceof OneShotEffect) {
|
||||
return executingEffect.apply(game, source);
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) executingEffect, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (player == null || mageObject == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected Player getPayingPlayer(Game game, Ability source) {
|
||||
return game.getPlayer(source.getControllerId());
|
||||
if (new ClashEffect().apply(game, source)) {
|
||||
if (setTargetPointerToClashedOpponent) {
|
||||
Player opponent = game.getPlayer((UUID) getValue("clashOpponent"));
|
||||
if (opponent != null) {
|
||||
executingEffect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
}
|
||||
} else {
|
||||
executingEffect.setTargetPointer(this.targetPointer);
|
||||
}
|
||||
if (executingEffect instanceof OneShotEffect) {
|
||||
return executingEffect.apply(game, source);
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) executingEffect, source);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -85,7 +67,7 @@ public class DoIfClashWonEffect extends OneShotEffect {
|
|||
if (!staticText.isEmpty()) {
|
||||
return staticText;
|
||||
}
|
||||
return new StringBuilder("clash with an opponent. If you win, ").append(executingEffect.getText(mode)).toString();
|
||||
return "clash with an opponent. If you win, " + executingEffect.getText(mode);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue