Added support of DynamicValues to DamageMultiEffect and TargetAmount.

This commit is contained in:
LevelX2 2013-01-28 23:59:08 +01:00
parent 695368dae7
commit d921b15dd0
4 changed files with 56 additions and 26 deletions

View file

@ -32,6 +32,8 @@ import java.util.UUID;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.Mode;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.effects.OneShotEffect;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -44,15 +46,15 @@ import mage.target.Target;
*/
public class DamageMultiEffect extends OneShotEffect<DamageMultiEffect> {
protected int amount;
protected DynamicValue amount;
public DamageMultiEffect(int amount) {
super(Outcome.Damage);
this.amount = amount;
this(new StaticValue(amount));
}
public int getAmount() {
return amount;
public DamageMultiEffect(DynamicValue amount) {
super(Outcome.Damage);
this.amount = amount;
}
public DamageMultiEffect(final DamageMultiEffect effect) {
@ -88,10 +90,8 @@ public class DamageMultiEffect extends OneShotEffect<DamageMultiEffect> {
@Override
public String getText(Mode mode) {
StringBuilder sb = new StringBuilder();
sb.append("{source} deals ").append(Integer.toString(amount));
sb.append("{source} deals ").append(amount.toString());
sb.append(" damage divided as you choose among any number of target ").append(mode.getTargets().get(0).getTargetName());
return sb.toString();
}
}

View file

@ -31,6 +31,8 @@ package mage.target;
import java.util.*;
import mage.Constants.Outcome;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.game.Game;
import mage.players.Player;
@ -40,12 +42,18 @@ import mage.players.Player;
*/
public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl<T> {
int amount;
boolean amountWasSet = false;
DynamicValue amount;
int remainingAmount;
public TargetAmount(int amount) {
this(new StaticValue(amount));
}
public TargetAmount(DynamicValue amount) {
this.amount = amount;
this.remainingAmount = amount;
//this.remainingAmount = amount;
amountWasSet = false;
this.required = true;
}
@ -53,6 +61,7 @@ public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl
super(target);
this.amount = target.amount;
this.remainingAmount = target.remainingAmount;
this.amountWasSet = target.amountWasSet;
}
public int getAmountRemaining() {
@ -66,17 +75,30 @@ public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl
@Override
public boolean doneChosing() {
if (amountWasSet == false) {
return false;
}
return remainingAmount == 0;
}
@Override
public void clearChosen() {
super.clearChosen();
remainingAmount = amount;
amountWasSet = false;
// remainingAmount = amount;
}
public void setAmount(Ability source, Game game) {
remainingAmount = amount.calculate(game, source);
amountWasSet = true;
}
@Override
public void addTarget(UUID id, int amount, Ability source, Game game, boolean skipEvent) {
if (!amountWasSet) {
setAmount(source, game);
}
if (amount <= remainingAmount) {
super.addTarget(id, amount, source, game, skipEvent);
remainingAmount -= amount;
@ -85,6 +107,9 @@ public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl
@Override
public boolean chooseTarget(Outcome outcome, UUID playerId, Ability source, Game game) {
if (!amountWasSet) {
setAmount(source, game);
}
Player player = game.getPlayer(playerId);
chosen = remainingAmount == 0;
while (remainingAmount > 0) {
@ -107,6 +132,9 @@ public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl
}
protected void addTargets(TargetAmount<T> target, Set<UUID> targets, List<T> options, Ability source, Game game) {
if (!amountWasSet) {
setAmount(source, game);
}
for (UUID targetId: targets) {
for (int n = 1; n <= target.remainingAmount; n++) {
T t = target.copy();
@ -115,8 +143,9 @@ public abstract class TargetAmount<T extends TargetAmount<T>> extends TargetImpl
if (targets.size() > 1) {
Set<UUID> newTargets = new HashSet<UUID>();
for (UUID newTarget: targets) {
if (!newTarget.equals(targetId))
if (!newTarget.equals(targetId)) {
newTargets.add(newTarget);
}
}
addTargets(t, newTargets, options, source, game);
}

View file

@ -28,9 +28,14 @@
package mage.target.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.Constants.Zone;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.filter.Filter;
import mage.filter.common.FilterCreatureOrPlayer;
import mage.filter.common.FilterCreaturePermanent;
@ -39,10 +44,6 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetAmount;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -52,6 +53,10 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
protected FilterCreatureOrPlayer filter;
public TargetCreatureOrPlayerAmount(int amount) {
this(new StaticValue(amount));
}
public TargetCreatureOrPlayerAmount(DynamicValue amount) {
super(amount);
this.zone = Zone.ALL;
this.filter = new FilterCreatureOrPlayer();
@ -193,11 +198,11 @@ public class TargetCreatureOrPlayerAmount extends TargetAmount<TargetCreatureOrP
for (UUID targetId: getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
sb.append(permanent.getName()).append(" ");
sb.append(permanent.getName()).append("(").append(getTargetAmount(targetId)).append(") ");
}
else {
Player player = game.getPlayer(targetId);
sb.append(player.getName()).append(" ");
sb.append(player.getName()).append("(").append(getTargetAmount(targetId)).append(") ");
}
}
return sb.toString();

View file

@ -27,6 +27,9 @@
*/
package mage.target.common;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import mage.Constants.Zone;
import mage.MageObject;
import mage.abilities.Ability;
@ -34,12 +37,8 @@ import mage.filter.Filter;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.TargetAmount;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
/**
*
@ -151,10 +150,7 @@ public class TargetCreaturePermanentAmount extends TargetAmount<TargetCreaturePe
for (UUID targetId : getTargets()) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null) {
sb.append(permanent.getName()).append(" ");
} else {
Player player = game.getPlayer(targetId);
sb.append(player.getName()).append(" ");
sb.append(permanent.getName()).append("(").append(getTargetAmount(targetId)).append(") ");
}
}
return sb.toString();