mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
* DoIfCostPaid - Added support to add multiple effects.
This commit is contained in:
parent
5860ff265d
commit
094d398081
2 changed files with 24 additions and 15 deletions
|
@ -107,6 +107,6 @@ class ParalyzeEffect extends DoIfCostPaid {
|
||||||
@Override
|
@Override
|
||||||
public String getText(Mode mode) {
|
public String getText(Mode mode) {
|
||||||
return new StringBuilder("that player may ").append(getCostText())
|
return new StringBuilder("that player may ").append(getCostText())
|
||||||
.append(". If he or she does, ").append(executingEffect.getText(mode)).toString();
|
.append(". If he or she does, ").append(executingEffects.getText(mode)).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,6 +6,7 @@ import mage.abilities.Mode;
|
||||||
import mage.abilities.costs.Cost;
|
import mage.abilities.costs.Cost;
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
import mage.abilities.effects.ContinuousEffect;
|
||||||
import mage.abilities.effects.Effect;
|
import mage.abilities.effects.Effect;
|
||||||
|
import mage.abilities.effects.Effects;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.PostResolveEffect;
|
import mage.abilities.effects.PostResolveEffect;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
|
@ -14,7 +15,7 @@ import mage.players.Player;
|
||||||
import mage.util.CardUtil;
|
import mage.util.CardUtil;
|
||||||
|
|
||||||
public class DoIfCostPaid extends OneShotEffect {
|
public class DoIfCostPaid extends OneShotEffect {
|
||||||
protected final Effect executingEffect;
|
protected Effects executingEffects = new Effects();
|
||||||
private final Cost cost;
|
private final Cost cost;
|
||||||
private String chooseUseText;
|
private String chooseUseText;
|
||||||
|
|
||||||
|
@ -24,18 +25,22 @@ public class DoIfCostPaid extends OneShotEffect {
|
||||||
|
|
||||||
public DoIfCostPaid(Effect effect, Cost cost, String chooseUseText) {
|
public DoIfCostPaid(Effect effect, Cost cost, String chooseUseText) {
|
||||||
super(Outcome.Benefit);
|
super(Outcome.Benefit);
|
||||||
this.executingEffect = effect;
|
this.executingEffects.add(effect);
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
this.chooseUseText = chooseUseText;
|
this.chooseUseText = chooseUseText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DoIfCostPaid(final DoIfCostPaid effect) {
|
public DoIfCostPaid(final DoIfCostPaid effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
this.executingEffect = effect.executingEffect.copy();
|
this.executingEffects = effect.executingEffects.copy();
|
||||||
this.cost = effect.cost.copy();
|
this.cost = effect.cost.copy();
|
||||||
this.chooseUseText = effect.chooseUseText;
|
this.chooseUseText = effect.chooseUseText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addEffect(Effect effect) {
|
||||||
|
executingEffects.add(effect);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = getPayingPlayer(game, source);
|
Player player = getPayingPlayer(game, source);
|
||||||
|
@ -43,26 +48,30 @@ public class DoIfCostPaid extends OneShotEffect {
|
||||||
if (player != null && mageObject != null) {
|
if (player != null && mageObject != null) {
|
||||||
String message;
|
String message;
|
||||||
if (chooseUseText == null) {
|
if (chooseUseText == null) {
|
||||||
message = new StringBuilder(getCostText()).append(" and ").append(executingEffect.getText(source.getModes().getMode())).append("?").toString();
|
message = new StringBuilder(getCostText()).append(" and ").append(executingEffects.getText(source.getModes().getMode())).append("?").toString();
|
||||||
} else {
|
} else {
|
||||||
message = chooseUseText;
|
message = chooseUseText;
|
||||||
}
|
}
|
||||||
message = CardUtil.replaceSourceName(message, mageObject.getName());
|
message = CardUtil.replaceSourceName(message, mageObject.getName());
|
||||||
if (cost.canPay(source, source.getSourceId(), player.getId(), game) && player.chooseUse(executingEffect.getOutcome(), message, game)) {
|
boolean result = true;
|
||||||
|
if (cost.canPay(source, source.getSourceId(), player.getId(), game) && player.chooseUse(executingEffects.get(0).getOutcome(), message, game)) {
|
||||||
cost.clearPaid();
|
cost.clearPaid();
|
||||||
if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) {
|
if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) {
|
||||||
executingEffect.setTargetPointer(this.targetPointer);
|
|
||||||
if (executingEffect instanceof OneShotEffect) {
|
for(Effect effect: executingEffects) {
|
||||||
if (!(executingEffect instanceof PostResolveEffect)) {
|
effect.setTargetPointer(this.targetPointer);
|
||||||
return executingEffect.apply(game, source);
|
if (effect instanceof OneShotEffect) {
|
||||||
|
if (!(effect instanceof PostResolveEffect)) {
|
||||||
|
result &= effect.apply(game, source);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
game.addEffect((ContinuousEffect) effect, source);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
game.addEffect((ContinuousEffect) executingEffect, source);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return result;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -76,7 +85,7 @@ public class DoIfCostPaid extends OneShotEffect {
|
||||||
if (!staticText.isEmpty()) {
|
if (!staticText.isEmpty()) {
|
||||||
return staticText;
|
return staticText;
|
||||||
}
|
}
|
||||||
return new StringBuilder("you may ").append(getCostText()).append(". If you do, ").append(executingEffect.getText(mode)).toString();
|
return new StringBuilder("you may ").append(getCostText()).append(". If you do, ").append(executingEffects.getText(mode)).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getCostText() {
|
protected String getCostText() {
|
||||||
|
|
Loading…
Reference in a new issue