forked from External/mage
Rework sacrifice effects to support "can't be sacrificed" (#11587)
* add TargetSacrifice and canBeSacrificed
* SacrificeTargetCost refactor, now uses TargetSacrifice, constructors simplified, subclasses aligned
* fix text errors introduced by refactor
* refactor SacrificeEffect, SacrificeAllEffect, SacrificeOpponentsEffect
* cleanup keyword abilities involving sacrifice
* fix a bunch of custom effect classes involving sacrifice
* fix test choices
* update Assault Suit implementation
* fix filter check arguments
* add documentation to refactored common classes
* [CLB] Implement Jon Irenicus, Shattered One
* implement "{this} can't be sacrificed"
* add tests for Assault Suit and Jon Irenicus
* refactor out PlayerToRightGainsControlOfSourceEffect
* implement [LTC] Hithlain Rope
* add choose hint to all TargetSacrifice
---------
Co-authored-by: Evan Kranzler <theelk801@gmail.com>
Co-authored-by: PurpleCrowbar <26198472+PurpleCrowbar@users.noreply.github.com>
This commit is contained in:
parent
f28c5c4fc5
commit
9b3ff32a33
699 changed files with 1837 additions and 1619 deletions
|
|
@ -6,12 +6,10 @@ import mage.abilities.dynamicvalue.common.StaticValue;
|
|||
import mage.abilities.effects.OneShotEffect;
|
||||
import mage.constants.Outcome;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
import mage.target.Target;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.target.common.TargetSacrifice;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
|
@ -21,14 +19,20 @@ import java.util.UUID;
|
|||
*/
|
||||
public class SacrificeEffect extends OneShotEffect {
|
||||
|
||||
private FilterPermanent filter;
|
||||
private String preText;
|
||||
private final FilterPermanent filter;
|
||||
private final String preText;
|
||||
private DynamicValue count;
|
||||
|
||||
/**
|
||||
* Target player sacrifices N permanents matching the filter
|
||||
*/
|
||||
public SacrificeEffect(FilterPermanent filter, int count, String preText) {
|
||||
this(filter, StaticValue.get(count), preText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Target player sacrifices X permanents matching the filter
|
||||
*/
|
||||
public SacrificeEffect(FilterPermanent filter, DynamicValue count, String preText) {
|
||||
super(Outcome.Sacrifice);
|
||||
this.filter = filter;
|
||||
|
|
@ -49,26 +53,24 @@ public class SacrificeEffect extends OneShotEffect {
|
|||
boolean applied = false;
|
||||
for (UUID playerId : targetPointer.getTargets(game, source)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
FilterPermanent newFilter = filter.copy(); // filter can be static, so it's important to copy here
|
||||
newFilter.add(new ControllerIdPredicate(player.getId()));
|
||||
int amount = count.calculate(game, source, this);
|
||||
int realCount = game.getBattlefield().countAll(newFilter, player.getId(), game);
|
||||
amount = Math.min(amount, realCount);
|
||||
Target target = new TargetPermanent(amount, amount, newFilter, true);
|
||||
if (amount > 0 && target.canChoose(player.getId(), source, game)) {
|
||||
while (!target.isChosen()
|
||||
&& target.canChoose(player.getId(), source, game)
|
||||
&& player.canRespond()) {
|
||||
player.chooseTarget(Outcome.Sacrifice, target, source, game);
|
||||
}
|
||||
for (int idx = 0; idx < target.getTargets().size(); idx++) {
|
||||
Permanent permanent = game.getPermanent(target.getTargets().get(idx));
|
||||
if (permanent != null
|
||||
&& permanent.sacrifice(source, game)) {
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
int amount = Math.min(
|
||||
count.calculate(game, source, this),
|
||||
game.getBattlefield().count(TargetSacrifice.makeFilter(filter), player.getId(), source, game)
|
||||
);
|
||||
if (amount < 1) {
|
||||
continue;
|
||||
}
|
||||
TargetSacrifice target = new TargetSacrifice(amount, filter);
|
||||
while (!target.isChosen() && target.canChoose(player.getId(), source, game) && player.canRespond()) {
|
||||
player.choose(Outcome.Sacrifice, target, source, game);
|
||||
}
|
||||
for (UUID targetId : target.getTargets()) {
|
||||
Permanent permanent = game.getPermanent(targetId);
|
||||
if (permanent != null && permanent.sacrifice(source, game)) {
|
||||
applied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue