mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
Added SacrificeOpponentsEffect.
This commit is contained in:
parent
dbedca4eb8
commit
2cea0215a2
4 changed files with 128 additions and 98 deletions
|
@ -27,21 +27,12 @@
|
|||
*/
|
||||
package mage.sets.magic2010;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.SacrificeOpponentsEffect;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Rarity;
|
||||
import mage.filter.common.FilterControlledLandPermanent;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -56,7 +47,7 @@ public class YawningFissure extends CardImpl<YawningFissure> {
|
|||
this.color.setRed(true);
|
||||
|
||||
// Each opponent sacrifices a land.
|
||||
this.getSpellAbility().addEffect(new YawningFissureEffect());
|
||||
this.getSpellAbility().addEffect(new SacrificeOpponentsEffect(new FilterControlledLandPermanent()));
|
||||
}
|
||||
|
||||
public YawningFissure(final YawningFissure card) {
|
||||
|
@ -68,44 +59,3 @@ public class YawningFissure extends CardImpl<YawningFissure> {
|
|||
return new YawningFissure(this);
|
||||
}
|
||||
}
|
||||
|
||||
class YawningFissureEffect extends OneShotEffect<YawningFissureEffect> {
|
||||
|
||||
private static final FilterControlledPermanent filter = new FilterControlledLandPermanent();
|
||||
|
||||
public YawningFissureEffect() {
|
||||
super(Outcome.Sacrifice);
|
||||
this.staticText = "Each opponent sacrifices a land";
|
||||
}
|
||||
|
||||
public YawningFissureEffect(final YawningFissureEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public YawningFissureEffect copy() {
|
||||
return new YawningFissureEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Set<UUID> opponents = game.getOpponents(source.getControllerId());
|
||||
for (UUID opponentId : opponents) {
|
||||
Player player = game.getPlayer(opponentId);
|
||||
Target target = new TargetControlledPermanent(filter);
|
||||
|
||||
if (target.canChoose(player.getId(), game)) {
|
||||
while (!target.isChosen() && target.canChoose(player.getId(), game)) {
|
||||
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
|
||||
}
|
||||
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
|
||||
if (permanent != null) {
|
||||
permanent.sacrifice(source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,22 +29,16 @@ package mage.sets.worldwake;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.MageInt;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.DiesThisOrAnotherCreatureTriggeredAbility;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.abilities.effects.common.SacrificeOpponentsEffect;
|
||||
import mage.abilities.keyword.FlyingAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.Rarity;
|
||||
import mage.constants.TargetController;
|
||||
import mage.filter.common.FilterControlledCreaturePermanent;
|
||||
import mage.filter.common.FilterCreaturePermanent;
|
||||
import mage.filter.predicate.permanent.ControllerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.common.TargetControlledCreaturePermanent;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -71,7 +65,7 @@ public class ButcherOfMalakir extends CardImpl<ButcherOfMalakir> {
|
|||
this.addAbility(FlyingAbility.getInstance());
|
||||
|
||||
// Whenever Butcher of Malakir or another creature you control dies, each opponent sacrifices a creature.
|
||||
this.addAbility(new DiesThisOrAnotherCreatureTriggeredAbility(new ButcherOfMalakirEffect(), false, filter));
|
||||
this.addAbility(new DiesThisOrAnotherCreatureTriggeredAbility(new SacrificeOpponentsEffect(new FilterControlledCreaturePermanent()), false, filter));
|
||||
}
|
||||
|
||||
public ButcherOfMalakir(final ButcherOfMalakir card) {
|
||||
|
@ -83,36 +77,3 @@ public class ButcherOfMalakir extends CardImpl<ButcherOfMalakir> {
|
|||
return new ButcherOfMalakir(this);
|
||||
}
|
||||
}
|
||||
class ButcherOfMalakirEffect extends OneShotEffect<ButcherOfMalakirEffect> {
|
||||
|
||||
public ButcherOfMalakirEffect() {
|
||||
super(Outcome.Sacrifice);
|
||||
this.staticText = "Each opponent sacrifices a creature";
|
||||
}
|
||||
|
||||
public ButcherOfMalakirEffect(final ButcherOfMalakirEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ButcherOfMalakirEffect copy() {
|
||||
return new ButcherOfMalakirEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
for (UUID opponentId : game.getOpponents(source.getControllerId())) {
|
||||
Player player = game.getPlayer(opponentId);
|
||||
Target target = new TargetControlledCreaturePermanent(true);
|
||||
|
||||
if (target.canChoose(player.getId(), game)) {
|
||||
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
|
||||
Permanent permanent = game.getPermanent(target.getFirstTarget());
|
||||
if (permanent != null) {
|
||||
permanent.sacrifice(source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,6 @@
|
|||
*/
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
|
@ -37,6 +35,8 @@ import mage.game.Game;
|
|||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
/**
|
||||
* The controlling player of the source ability has to sacrifice [count] permanents
|
||||
* that match the [filter].
|
||||
*
|
||||
* @author LevelX
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification, are
|
||||
* permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this list of
|
||||
* conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
|
||||
* of conditions and the following disclaimer in the documentation and/or other materials
|
||||
* provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
||||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* The views and conclusions contained in the software and documentation are those of the
|
||||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.effects.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.dynamicvalue.common.StaticValue;
|
||||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.common.FilterControlledPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
/**
|
||||
* All opponents have to sacrifice [amount] permanents
|
||||
* that match the [filter].
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public class SacrificeOpponentsEffect extends OneShotEffect<SacrificeOpponentsEffect> {
|
||||
|
||||
protected DynamicValue amount;
|
||||
protected FilterControlledPermanent filter;
|
||||
|
||||
public SacrificeOpponentsEffect(FilterControlledPermanent filter) {
|
||||
this(1, filter);
|
||||
}
|
||||
public SacrificeOpponentsEffect(int amount, FilterControlledPermanent filter) {
|
||||
this(new StaticValue(amount), filter);
|
||||
}
|
||||
|
||||
public SacrificeOpponentsEffect(DynamicValue amount, FilterControlledPermanent filter) {
|
||||
super(Outcome.Sacrifice);
|
||||
this.amount = amount;
|
||||
this.filter = filter;
|
||||
setText();
|
||||
}
|
||||
|
||||
public SacrificeOpponentsEffect(final SacrificeOpponentsEffect effect) {
|
||||
super(effect);
|
||||
this.amount = effect.amount;
|
||||
this.filter = effect.filter.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SacrificeOpponentsEffect copy() {
|
||||
return new SacrificeOpponentsEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
List<UUID> perms = new ArrayList<UUID>();
|
||||
for (UUID playerId : game.getOpponents(source.getControllerId())) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
int numTargets = Math.min(amount.calculate(game, source), game.getBattlefield().countAll(filter, player.getId(), game));
|
||||
TargetControlledPermanent target = new TargetControlledPermanent(numTargets, numTargets, filter, false);
|
||||
if (target.canChoose(player.getId(), game)) {
|
||||
while (!target.isChosen()) {
|
||||
player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
|
||||
}
|
||||
perms.addAll(target.getTargets());
|
||||
}
|
||||
}
|
||||
}
|
||||
for (UUID permID : perms) {
|
||||
Permanent permanent = game.getPermanent(permID);
|
||||
if (permanent != null) {
|
||||
permanent.sacrifice(source.getSourceId(), game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Each opponent sacrifices ");
|
||||
if (amount.toString().equals("X")) {
|
||||
sb.append(amount.toString()).append(" ");
|
||||
} else {
|
||||
sb.append(CardUtil.numberToText(amount.toString()));
|
||||
}
|
||||
sb.append(filter.getMessage());
|
||||
staticText = sb.toString();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue