forked from External/mage
[ODY] Split Balancing Acts' effects into two effects to fix interactions with other cards. For #6761
This commit is contained in:
parent
513085bbcc
commit
f263fe2a09
1 changed files with 84 additions and 61 deletions
|
|
@ -15,6 +15,7 @@ import mage.players.Player;
|
|||
import mage.target.common.TargetCardInHand;
|
||||
import mage.target.common.TargetControlledPermanent;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
|
@ -25,8 +26,10 @@ public final class BalancingAct extends CardImpl {
|
|||
public BalancingAct(UUID ownerId, CardSetInfo setInfo) {
|
||||
super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{2}{W}{W}");
|
||||
|
||||
// Each player chooses a number of permanents they control equal to the number of permanents controlled by the player who controls the fewest, then sacrifices the rest. Each player discards cards the same way.
|
||||
this.getSpellAbility().addEffect(new BalancingActEffect());
|
||||
// Each player chooses a number of permanents they control equal to the number of permanents controlled by the player who controls the fewest, then sacrifices the rest.
|
||||
this.getSpellAbility().addEffect(new BalancingActSacrificeEffect());
|
||||
// Each player discards cards the same way.
|
||||
this.getSpellAbility().addEffect(new BalancingActDiscardEffect());
|
||||
}
|
||||
|
||||
private BalancingAct(final BalancingAct card) {
|
||||
|
|
@ -39,79 +42,99 @@ public final class BalancingAct extends CardImpl {
|
|||
}
|
||||
}
|
||||
|
||||
class BalancingActEffect extends OneShotEffect {
|
||||
class BalancingActSacrificeEffect extends OneShotEffect {
|
||||
|
||||
BalancingActEffect() {
|
||||
BalancingActSacrificeEffect() {
|
||||
super(Outcome.Sacrifice);
|
||||
staticText = "Each player chooses a number of permanents they control equal to the number of permanents controlled by the player who controls the fewest, then sacrifices the rest. Each player discards cards the same way";
|
||||
staticText = "Each player chooses a number of permanents they control equal to the number of permanents controlled by the player who controls the fewest, then sacrifices the rest.";
|
||||
}
|
||||
|
||||
private BalancingActEffect(final BalancingActEffect effect) {
|
||||
private BalancingActSacrificeEffect(final BalancingActSacrificeEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BalancingActEffect copy() {
|
||||
return new BalancingActEffect(this);
|
||||
public BalancingActSacrificeEffect copy() {
|
||||
return new BalancingActSacrificeEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller != null) {
|
||||
int minPermanent = Integer.MAX_VALUE, minCard = Integer.MAX_VALUE;
|
||||
// count minimal permanents
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
int count = game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source, game).size();
|
||||
if (count < minPermanent) {
|
||||
minPermanent = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// sacrifice permanents over the minimum
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
|
||||
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), source, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source, game)) {
|
||||
if (permanent != null && !target.getTargets().contains(permanent.getId())) {
|
||||
permanent.sacrifice(source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// count minimal cards in hand
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
int count = player.getHand().size();
|
||||
if (count < minCard) {
|
||||
minCard = count;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// discard cards over the minimum
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
|
||||
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), source, game)) {
|
||||
Cards cards = player.getHand().copy();
|
||||
cards.removeIf(target.getTargets()::contains);
|
||||
player.discard(cards, false, source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
int minPermanent = Integer.MAX_VALUE;
|
||||
// count minimal permanents
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
minPermanent = Math.min(minPermanent, game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source, game).size());
|
||||
}
|
||||
}
|
||||
// sacrifice permanents over the minimum
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
TargetControlledPermanent target = new TargetControlledPermanent(minPermanent, minPermanent, new FilterControlledPermanent(), true);
|
||||
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), source, game)) {
|
||||
for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledPermanent(), player.getId(), source, game)) {
|
||||
if (permanent != null && !target.getTargets().contains(permanent.getId())) {
|
||||
permanent.sacrifice(source, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
class BalancingActDiscardEffect extends OneShotEffect {
|
||||
|
||||
BalancingActDiscardEffect() {
|
||||
super(Outcome.Discard);
|
||||
staticText = "Each player discards cards the same way";
|
||||
}
|
||||
|
||||
private BalancingActDiscardEffect(final BalancingActDiscardEffect effect) {
|
||||
super(effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public BalancingActDiscardEffect copy() {
|
||||
return new BalancingActDiscardEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
Player controller = game.getPlayer(source.getControllerId());
|
||||
if (controller == null) {
|
||||
return false;
|
||||
}
|
||||
int minCard = Integer.MAX_VALUE;
|
||||
// count minimal cards in hand)
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player != null) {
|
||||
minCard = Math.min(minCard, player.getHand().size());
|
||||
}
|
||||
}
|
||||
|
||||
// discard cards over the minimum
|
||||
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
|
||||
Player player = game.getPlayer(playerId);
|
||||
if (player == null) {
|
||||
continue;
|
||||
}
|
||||
TargetCardInHand target = new TargetCardInHand(minCard, new FilterCard());
|
||||
if (target.choose(Outcome.Benefit, player.getId(), source.getSourceId(), source, game)) {
|
||||
Cards cards = player.getHand().copy();
|
||||
cards.removeIf(target.getTargets()::contains);
|
||||
player.discard(cards, false, source, game);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue