mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Whims of the Fates - Implemented the card logic.
This commit is contained in:
parent
ce3728766d
commit
774a54ecb9
1 changed files with 101 additions and 28 deletions
|
|
@ -28,26 +28,26 @@
|
||||||
package mage.sets.bornofthegods;
|
package mage.sets.bornofthegods;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.effects.ContinuousEffect;
|
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
import mage.abilities.effects.common.continious.GainControlTargetEffect;
|
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.constants.CardType;
|
import mage.constants.CardType;
|
||||||
import mage.constants.Duration;
|
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.constants.Rarity;
|
import mage.constants.Rarity;
|
||||||
import mage.filter.common.FilterCreaturePermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
import mage.filter.predicate.permanent.ControllerIdPredicate;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.players.PlayerList;
|
import mage.players.PlayerList;
|
||||||
import mage.target.Target;
|
import mage.target.Target;
|
||||||
import mage.target.common.TargetCreaturePermanent;
|
import mage.target.TargetPermanent;
|
||||||
import mage.target.targetpointer.FixedTarget;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -77,6 +77,8 @@ public class WhimsOfTheFates extends CardImpl<WhimsOfTheFates> {
|
||||||
|
|
||||||
class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
||||||
|
|
||||||
|
protected static Random rnd = new Random();
|
||||||
|
|
||||||
public WhimsOfTheFateEffect() {
|
public WhimsOfTheFateEffect() {
|
||||||
super(Outcome.Detriment);
|
super(Outcome.Detriment);
|
||||||
this.staticText = "Starting with you, each player separates all permanents he or she controls into three piles. Then each player chooses one of his or her piles at random and sacrifices those permanents.";
|
this.staticText = "Starting with you, each player separates all permanents he or she controls into three piles. Then each player chooses one of his or her piles at random and sacrifices those permanents.";
|
||||||
|
|
@ -95,8 +97,10 @@ class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player controller = game.getPlayer(source.getControllerId());
|
Player controller = game.getPlayer(source.getControllerId());
|
||||||
if (controller != null) {
|
if (controller != null) {
|
||||||
Map<UUID, UUID> playerCreature = new HashMap<UUID,UUID>();
|
|
||||||
boolean left = source.getChoices().get(0).getChoice().equals("Left");
|
// Map of players and their piles (1,2,3) with values of UUID of the permanents
|
||||||
|
Map<UUID, Map<Integer, Set<UUID>>> playerPermanents = new LinkedHashMap<UUID, Map<Integer, Set<UUID>>>();
|
||||||
|
|
||||||
PlayerList playerList = game.getState().getPlayerList();
|
PlayerList playerList = game.getState().getPlayerList();
|
||||||
while (!playerList.get().equals(source.getControllerId()) && controller.isInGame()) {
|
while (!playerList.get().equals(source.getControllerId()) && controller.isInGame()) {
|
||||||
playerList.getNext();
|
playerList.getNext();
|
||||||
|
|
@ -105,7 +109,7 @@ class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
||||||
Player nextPlayer;
|
Player nextPlayer;
|
||||||
UUID firstNextPlayer = null;
|
UUID firstNextPlayer = null;
|
||||||
|
|
||||||
while (!getNextPlayerInDirection(left, playerList, game).equals(firstNextPlayer) && controller.isInGame()){
|
while (!getNextPlayerInDirection(true, playerList, game).equals(firstNextPlayer) && controller.isInGame()) {
|
||||||
nextPlayer = game.getPlayer(playerList.get());
|
nextPlayer = game.getPlayer(playerList.get());
|
||||||
if (nextPlayer == null) {
|
if (nextPlayer == null) {
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -113,36 +117,70 @@ class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
||||||
if (firstNextPlayer == null) {
|
if (firstNextPlayer == null) {
|
||||||
firstNextPlayer = nextPlayer.getId();
|
firstNextPlayer = nextPlayer.getId();
|
||||||
}
|
}
|
||||||
// if player is in range he chooses 3 piles
|
// if player is in range of controller he chooses 3 piles with all its permanents
|
||||||
if (currentPlayer != null && controller.getInRange().contains(currentPlayer.getId())) {
|
if (currentPlayer != null && controller.getInRange().contains(currentPlayer.getId())) {
|
||||||
|
Map<Integer, Set<UUID>> playerPiles = new HashMap<Integer, Set<UUID>>();
|
||||||
|
for (int i = 1; i < 4; i++) {
|
||||||
|
playerPiles.put(i, new LinkedHashSet<UUID>());
|
||||||
FilterCreaturePermanent filter = new FilterCreaturePermanent(new StringBuilder("creature controlled by ").append(nextPlayer.getName()).toString());
|
}
|
||||||
filter.add(new ControllerIdPredicate(nextPlayer.getId()));
|
playerPermanents.put(currentPlayer.getId(), playerPiles);
|
||||||
Target target = new TargetCreaturePermanent(filter, true);
|
for (int i = 1; i < 3; i++) {
|
||||||
target.setNotTarget(false);
|
FilterPermanent filter = new FilterPermanent(
|
||||||
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game)) {
|
new StringBuilder("the permanents for the ").append(i == 1 ? "first " : "second ").append("pile").toString());
|
||||||
if (currentPlayer.chooseTarget(outcome, target, source, game)) {
|
filter.add(new ControllerIdPredicate(currentPlayer.getId()));
|
||||||
playerCreature.put(currentPlayer.getId(), target.getFirstTarget());
|
Target target;
|
||||||
|
if (i == 1) {
|
||||||
|
target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
|
||||||
|
} else {
|
||||||
|
target = new TargetSecondPilePermanent(playerPiles.get(1), filter);
|
||||||
|
}
|
||||||
|
currentPlayer.chooseTarget(outcome, target, source, game);
|
||||||
|
StringBuilder message = new StringBuilder(currentPlayer.getName()).append(" pile ").append(i).append(": ");
|
||||||
|
if (target.getTargets().isEmpty()) {
|
||||||
|
message.append(" (empty)");
|
||||||
|
} else {
|
||||||
|
for (UUID permanentId : target.getTargets()) {
|
||||||
|
Permanent permanent = game.getPermanent(permanentId);
|
||||||
|
if (permanent != null) {
|
||||||
|
message.append(permanent.getName()).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
game.informPlayers(message.toString());
|
||||||
|
playerPiles.get(i).addAll(target.getTargets());
|
||||||
|
}
|
||||||
|
|
||||||
|
// add all permanents not targeted yet to the third pile
|
||||||
|
StringBuilder message = new StringBuilder(currentPlayer.getName()).append(" pile 3: ");
|
||||||
|
for (Permanent permanent : game.getState().getBattlefield().getAllActivePermanents(currentPlayer.getId())) {
|
||||||
|
if (!playerPiles.get(1).contains(permanent.getId()) && !playerPiles.get(2).contains(permanent.getId())) {
|
||||||
|
playerPiles.get(3).add(permanent.getId());
|
||||||
|
message.append(permanent.getName()).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (playerPiles.get(3).isEmpty()) {
|
||||||
|
message.append(" (empty)");
|
||||||
|
}
|
||||||
|
game.informPlayers(message.toString());
|
||||||
|
}
|
||||||
currentPlayer = nextPlayer;
|
currentPlayer = nextPlayer;
|
||||||
}
|
}
|
||||||
// change control of targets
|
// Sacrifice all permanents from a pile randomly selected
|
||||||
for (Map.Entry<UUID, UUID> entry : playerCreature.entrySet()) {
|
for (Map.Entry<UUID, Map<Integer, Set<UUID>>> playerPiles : playerPermanents.entrySet()) {
|
||||||
Player player = game.getPlayer(entry.getKey());
|
Player player = game.getPlayer(playerPiles.getKey());
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
Permanent creature = game.getPermanent(entry.getValue());
|
// decide which pile to sacrifice
|
||||||
if (creature != null) {
|
int sacrificePile = rnd.nextInt(3) + 1; // random number from 1 - 3
|
||||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfGame, player.getId());
|
game.informPlayers(new StringBuilder(player.getName()).append(" sacrifices pile number ").append(sacrificePile).toString());
|
||||||
effect.setTargetPointer(new FixedTarget(creature.getId()));
|
for (UUID permanentId : playerPiles.getValue().get(sacrificePile)) {
|
||||||
game.addEffect(effect, source);
|
Permanent permanent = game.getPermanent(permanentId);
|
||||||
game.informPlayers(new StringBuilder(player.getName()).append(" gains control of ").append(creature.getName()).toString());
|
if (permanent != null) {
|
||||||
|
permanent.sacrifice(source.getSourceId(), game);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -158,3 +196,38 @@ class WhimsOfTheFateEffect extends OneShotEffect<WhimsOfTheFateEffect> {
|
||||||
return nextPlayerId;
|
return nextPlayerId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class TargetSecondPilePermanent extends TargetPermanent {
|
||||||
|
|
||||||
|
protected Set<UUID> firstPile;
|
||||||
|
|
||||||
|
public TargetSecondPilePermanent(Set<UUID> firstPile, FilterPermanent filter) {
|
||||||
|
super(0, Integer.MAX_VALUE, filter, true);
|
||||||
|
this.firstPile = firstPile;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canTarget(UUID controllerId, UUID id, UUID sourceId, Game game, boolean flag) {
|
||||||
|
if (firstPile.contains(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.canTarget(controllerId, id, sourceId, game, flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
|
||||||
|
if (firstPile.contains(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.canTarget(controllerId, id, source, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canTarget(UUID id, Ability source, Game game) {
|
||||||
|
if (firstPile.contains(id)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return super.canTarget(id, source, game);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue