* Added Celestial Convergence and some changes to game draw handling.

This commit is contained in:
LevelX2 2017-04-21 15:18:04 +02:00
parent 274e0f9052
commit e284922017
8 changed files with 278 additions and 31 deletions

View file

@ -0,0 +1,145 @@
/*
* 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.cards.c;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.EntersBattlefieldAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.abilities.effects.common.counter.RemoveCounterSourceEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.counters.Counter;
import mage.game.Game;
import mage.players.Player;
/**
*
* @author LevelX2
*/
public class CelestialConvergence extends CardImpl {
public CelestialConvergence(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{W}");
// Celestial Convergence enters the battlefield with seven omen counters on it.
Effect effect = new AddCountersSourceEffect(new Counter("omen", 2));
this.addAbility(new EntersBattlefieldAbility(effect, "with 2 omen counters"));
// At the beginning of your upkeep, remove an omen counter from Celestial Convergence. If there are no omen counters on Celestial Convergence, the player with the highest life total wins the game. If two or more players are tied for highest life total, the game is a draw.
Ability ability = new BeginningOfUpkeepTriggeredAbility(
Zone.BATTLEFIELD, new RemoveCounterSourceEffect(new Counter("omen")), TargetController.YOU, false);
ability.addEffect(new CelestialConvergenceEffect());
this.addAbility(ability);
}
public CelestialConvergence(final CelestialConvergence card) {
super(card);
}
@Override
public CelestialConvergence copy() {
return new CelestialConvergence(this);
}
}
class CelestialConvergenceEffect extends OneShotEffect {
public CelestialConvergenceEffect() {
super(Outcome.PutCreatureInPlay);
this.staticText = "If there are no omen counters on {this}, the player with the highest life total wins the game. If two or more players are tied for highest life total, the game is a draw";
}
public CelestialConvergenceEffect(final CelestialConvergenceEffect effect) {
super(effect);
}
@Override
public CelestialConvergenceEffect copy() {
return new CelestialConvergenceEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Card sourceObject = game.getCard(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (sourceObject != null
&& controller != null
&& sourceObject.getCounters(game).getCount("omen") == 0) {
/**
* 801.14. If an effect states that a player wins the game, all of
* that players opponents within his or her range of influence lose
* the game instead. #
*
* 801.15. If the effect of a spell or ability states that the game
* is a draw, the game is a draw for that spell or abilitys
* controller and all players within his or her range of influence.
* They leave the game. All remaining players continue to play the
* game.
*
*/
List<UUID> highestLifePlayers = new ArrayList<>();
int highLife = Integer.MIN_VALUE;
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLife() > highLife) {
highestLifePlayers.clear();
highestLifePlayers.add(player.getId());
} else if (player.getLife() == highLife) {
highestLifePlayers.add(player.getId());
}
}
}
if (highestLifePlayers.isEmpty()) {
return false;
}
if (highestLifePlayers.size() > 1) {
game.setDraw(controller.getId());
} else {
Player winner = game.getPlayer(highestLifePlayers.iterator().next());
if (winner != null) {
winner.won(game);
}
}
return true;
}
return false;
}
}

View file

@ -27,6 +27,8 @@
*/
package mage.cards.d;
import java.util.Objects;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
@ -49,9 +51,6 @@ import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
import java.util.Objects;
import java.util.UUID;
/**
*
* @author spjspj
@ -63,7 +62,7 @@ public class DivineIntervention extends CardImpl {
// Divine Intervention enters the battlefield with 2 intervention counters on it.
Effect effect = new AddCountersSourceEffect(CounterType.INTERVENTION.createInstance(2));
this.addAbility(new EntersBattlefieldAbility(effect, "enters with 2 intervention counters"));
this.addAbility(new EntersBattlefieldAbility(effect, "with 2 intervention counters"));
// At the beginning of your upkeep, remove an intervention counter from Divine Intervention.
this.addAbility(new BeginningOfUpkeepTriggeredAbility(new RemoveCounterSourceEffect(CounterType.INTERVENTION.createInstance()), TargetController.YOU, false));
@ -161,16 +160,9 @@ public class DivineIntervention extends CardImpl {
if (controller != null && sourcePermanent != null) {
if (game.getState().getZone(sourcePermanent.getId()) == Zone.BATTLEFIELD && sourcePermanent.getCounters(game).getCount(CounterType.INTERVENTION) == 0) {
game.setDraw(controller.getId());
for (UUID player : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(player);
if (opponent != null) {
game.setDraw(player);
}
}
return true;
}
}
return false;
}
}

View file

@ -0,0 +1,80 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.mage.test.game.ends;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import org.junit.Assert;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
*
* @author LevelX2
*/
public class GameIsADrawTest extends CardTestPlayerBase {
@Test
public void GameDrawByDamage() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
// Flame Rift deals 4 damage to each player.
addCard(Zone.HAND, playerA, "Flame Rift", 3); // Sorcery {1}{R}
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 4);
// Flame Rift deals 4 damage to each player.
addCard(Zone.HAND, playerB, "Flame Rift", 2); // Sorcery
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Flame Rift");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Rift");
castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Rift");
setStopAt(2, PhaseStep.BEGIN_COMBAT);
execute();
assertLife(playerA, 0);
assertLife(playerB, 0);
Assert.assertFalse("Player A has not won.", playerA.hasWon());
Assert.assertFalse("Player B has not won.", playerB.hasWon());
Assert.assertTrue("Game has ended.", currentGame.hasEnded());
Assert.assertTrue("Both players had 0 life, game has be de a draw.", currentGame.isADraw());
}
@Test
public void GameDrawByDivineIntervention() {
addCard(Zone.BATTLEFIELD, playerA, "Plains", 8);
// Divine Intervention enters the battlefield with two intervention counters on it.
// At the beginning of your upkeep, remove an intervention counter from Divine Intervention.
// When you remove the last intervention counter from Divine Intervention, the game is a draw.
addCard(Zone.HAND, playerA, "Divine Intervention", 1); // Enchantment {6}{W}{W}
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion", 1);
addCard(Zone.BATTLEFIELD, playerB, "Silvercoat Lion", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Divine Intervention");
setStopAt(5, PhaseStep.PRECOMBAT_MAIN);
execute();
assertLife(playerA, 20);
assertLife(playerB, 20);
Assert.assertFalse("Player A has not won.", playerA.hasWon());
Assert.assertFalse("Player B has not won.", playerB.hasWon());
Assert.assertTrue("Game has ended.", currentGame.hasEnded());
Assert.assertTrue("Both players had 0 life, game has be de a draw.", currentGame.isADraw());
}
}

View file

@ -29,7 +29,6 @@ package org.mage.test.player;
import java.io.Serializable;
import java.util.*;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Abilities;
@ -632,8 +631,7 @@ public class TestPlayer implements Player {
// If getMaxBlockedBy() == 0 it means any number of creatures can block this creature
if (attacker.getMaxBlockedBy() != 0 && blockers > attacker.getMaxBlockedBy()) {
throw new UnsupportedOperationException(attacker.getName() + " is blocked by " + blockers + " creature(s). It can only be blocked by " + attacker.getMaxBlockedBy() + " or less.");
}
else if(blockers < attacker.getMinBlockedBy()) {
} else if (blockers < attacker.getMinBlockedBy()) {
throw new UnsupportedOperationException(attacker.getName() + " is blocked by " + blockers + " creature(s). It has to be blocked by " + attacker.getMinBlockedBy() + " or more.");
}
}
@ -1676,6 +1674,16 @@ public class TestPlayer implements Player {
computerPlayer.lost(game);
}
@Override
public boolean hasDrew() {
return computerPlayer.hasDrew();
}
@Override
public void drew(Game game) {
computerPlayer.drew(game);
}
@Override
public void lostForced(Game game) {
computerPlayer.lostForced(game);

View file

@ -2813,7 +2813,7 @@ public abstract class GameImpl implements Game, Serializable {
for (UUID playerToSetId : getState().getPlayersInRange(playerId, this)) {
Player playerToDraw = getPlayer(playerToSetId);
if (playerToDraw != null) {
playerToDraw.lostForced(this);
playerToDraw.drew(this);
}
}
}

View file

@ -176,7 +176,7 @@ public class GameEvent implements Serializable {
data originalId of the mana producing ability
*/
MANA_PAID,
LOSES, LOST, WINS,
LOSES, LOST, WINS, DRAW_PLAYER,
TARGET, TARGETED,
/* TARGETS_VALID
targetId id of the spell or id of stack ability the targets were set to

View file

@ -212,6 +212,8 @@ public interface Player extends MageItem, Copyable<Player> {
boolean hasLost();
boolean hasDrew();
boolean hasWon();
boolean hasQuit();
@ -430,6 +432,8 @@ public interface Player extends MageItem, Copyable<Player> {
void lostForced(Game game);
void drew(Game game);
void won(Game game);
void leave();

View file

@ -107,6 +107,7 @@ public abstract class PlayerImpl implements Player, Serializable {
protected boolean human;
protected int life;
protected boolean wins;
protected boolean draws;
protected boolean loses;
protected Library library;
protected Cards sideboard;
@ -226,6 +227,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.human = player.human;
this.life = player.life;
this.wins = player.wins;
this.draws = player.draws;
this.loses = player.loses;
this.library = player.library.copy();
@ -391,6 +393,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.abilities.clear();
this.counters.clear();
this.wins = false;
this.draws = false;
this.loses = false;
this.left = false;
// reset is neccessary because in tournament player will be used for each round
@ -2190,6 +2193,16 @@ public abstract class PlayerImpl implements Player, Serializable {
}
}
@Override
public void drew(Game game) {
if (!hasLost()) {
this.draws = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DRAW_PLAYER, null, null, playerId));
game.informPlayers("For " + this.getLogName() + " the game is a draw.");
game.gameOver(playerId);
}
}
@Override
public boolean hasLost() {
return this.loses;
@ -2197,7 +2210,7 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean isInGame() {
return !hasQuit() && !hasLost() && !hasWon() && !hasLeft();
return !hasQuit() && !hasLost() && !hasWon() && !hasDrew() && !hasLeft();
}
@Override
@ -2210,6 +2223,11 @@ public abstract class PlayerImpl implements Player, Serializable {
return !this.loses && this.wins;
}
@Override
public boolean hasDrew() {
return this.draws;
}
@Override
public void declareAttacker(UUID attackerId, UUID defenderId, Game game, boolean allowUndo) {
if (allowUndo) {