Extended DamagePlayersEffect with parameter to deal damage to opponents. Changed way in TapSourceCost to decide if the ability is a ManaAbility.

This commit is contained in:
LevelX2 2013-04-29 11:59:51 +02:00
parent 25bfee6f10
commit 93a8c58f3c
2 changed files with 54 additions and 10 deletions

View file

@ -29,9 +29,9 @@
package mage.abilities.costs.common;
import java.util.UUID;
import mage.Constants.AbilityType;
import mage.abilities.Ability;
import mage.abilities.costs.CostImpl;
import mage.abilities.mana.ManaAbility;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -55,7 +55,7 @@ public class TapSourceCost extends CostImpl<TapSourceCost> {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null) {
paid = permanent.tap(game);
if (paid && ability instanceof ManaAbility) {
if (paid && ability.getAbilityType().equals(AbilityType.MANA)) {
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.TAPPED_FOR_MANA, sourceId, sourceId, controllerId));
}
}

View file

@ -28,7 +28,8 @@
package mage.abilities.effects.common;
import java.util.UUID;
import mage.Constants;
import mage.Constants.Outcome;
import mage.Constants.TargetController;
import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
@ -42,28 +43,55 @@ import mage.players.Player;
*/
public class DamagePlayersEffect extends OneShotEffect<DamagePlayersEffect> {
private DynamicValue amount;
private TargetController controller;
public DamagePlayersEffect(int amount) {
this(Constants.Outcome.Damage, new StaticValue(amount));
this(Outcome.Damage, new StaticValue(amount));
}
public DamagePlayersEffect(Constants.Outcome outcome, DynamicValue amount) {
public DamagePlayersEffect(int amount, TargetController controller) {
this(Outcome.Damage, new StaticValue(amount), controller);
}
public DamagePlayersEffect(Outcome outcome, DynamicValue amount) {
this(outcome, amount, TargetController.ANY);
}
public DamagePlayersEffect(Outcome outcome, DynamicValue amount, TargetController controller) {
super(outcome);
this.amount = amount;
staticText = "{source} deals " + amount + " damage to each player";
this.controller = controller;
setText();
}
public DamagePlayersEffect(final DamagePlayersEffect effect) {
super(effect);
this.amount = effect.amount;
this.controller = effect.controller;
}
@Override
public boolean apply(Game game, Ability source) {
for (UUID playerId: game.getPlayer(source.getControllerId()).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null)
player.damage(amount.calculate(game, source), source.getId(), game, false, true);
switch (controller) {
case ANY:
for (UUID playerId: game.getPlayer(source.getControllerId()).getInRange()) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.damage(amount.calculate(game, source), source.getId(), game, false, true);
}
}
break;
case OPPONENT:
for (UUID playerId: game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player != null) {
player.damage(amount.calculate(game, source), source.getId(), game, false, true);
}
}
break;
default:
throw new UnsupportedOperationException("TargetController type not supported.");
}
return true;
}
@ -73,4 +101,20 @@ public class DamagePlayersEffect extends OneShotEffect<DamagePlayersEffect> {
return new DamagePlayersEffect(this);
}
private void setText()
{
StringBuilder sb = new StringBuilder("{source} deals ").append(amount.toString());
switch (controller) {
case ANY:
sb.append(" damage to each player");
break;
case OPPONENT:
sb.append(" damage to each opponent");
break;
default:
throw new UnsupportedOperationException("TargetController type not supported.");
}
staticText = sb.toString();
}
}