1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-12 01:01:04 -09:00

* Commander - Added commander multiplayer format. Fixed commander damage win condition to only counting combat damage. Added some info to tooltip text of commander.

This commit is contained in:
LevelX2 2013-12-23 17:14:56 +01:00
parent ebb71b7dd7
commit 05cbd90fe2
16 changed files with 521 additions and 196 deletions
Mage.Server.Plugins
Mage.Game.CommanderDuel/src/mage/game
Mage.Game.CommanderFreeForAll
pom.xml
Mage.Server
config
pom.xml
release/config
Mage.Sets/src/mage/sets/fifthedition
Mage/src/mage

View file

@ -28,36 +28,12 @@
package mage.game;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.EmptyEffect;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.continious.CommanderReplacementEffect;
import mage.abilities.effects.common.cost.CommanderCostModification;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.MultiplayerAttackOption;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.match.MatchType;
import mage.game.turn.TurnMod;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import mage.watchers.Watcher;
import mage.watchers.common.CommanderCombatDamageWatcher;
public class CommanderDuel extends GameImpl<CommanderDuel> {
private final Map<UUID, Cards> mulliganedCards = new HashMap<UUID, Cards>();
public class CommanderDuel extends GameCommanderImpl {
public CommanderDuel(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
super(attackOption, range, freeMulligans);
}
@ -76,159 +52,9 @@ public class CommanderDuel extends GameImpl<CommanderDuel> {
return 2;
}
// MTG Rules 20121001
// 903.7. Once the starting player has been determined, each player sets his or her life total to 40 and
// draws a hand of seven cards.
@Override
public int getLife() {
return 40;
}
@Override
protected void init(UUID choosingPlayerId, GameOptions gameOptions) {
super.init(choosingPlayerId, gameOptions);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new EmptyEffect("Commander effects"));
//Move commender to commande zone
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null){
if (player.getSideboard().size() > 0){
Card commander = getCard((UUID)player.getSideboard().toArray()[0]);
if (commander != null) {
player.setCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
ability.addEffect(new CommanderReplacementEffect(commander.getId()));
ability.addEffect(new CommanderCostModification(commander.getId()));
getState().setValue(commander.getId() + "_castCount", new Integer(0));
getState().getWatchers().add(new CommanderCombatDamageWatcher(commander.getId()));
}
}
}
}
this.getState().addAbility(ability, this.getId(), null);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
//20130711
/*903.8. The Commander variant uses an alternate mulligan rule.
* Each time a player takes a mulligan, rather than shuffling his or her entire hand of cards into his or her library, that player exiles any number of cards from his or her hand face down.
* Then the player draws a number of cards equal to one less than the number of cards he or she exiled this way.
* That player may look at all cards exiled this way while taking mulligans.
* Once a player keeps an opening hand, that player shuffles all cards he or she exiled this way into his or her library.
* */
//TODO implement may look at exile cards
@Override
public void mulligan(UUID playerId) {
Player player = getPlayer(playerId);
TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
target.setNotTarget(true);
//target.setRequired(true);
if(player.choose(Outcome.Exile, player.getHand(), target, this)){
int numCards = target.getTargets().size();
for(UUID uuid : target.getTargets()){
Card card = player.getHand().get(uuid, this);
if(card != null){
if(!mulliganedCards.containsKey(playerId)){
mulliganedCards.put(playerId, new CardsImpl());
}
card.setFaceDown(true);
card.moveToExile(null, "", null, this);
mulliganedCards.get(playerId).add(card);
}
}
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
if (used < freeMulligans ) {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(used+1));
}
} else {
deduction = 0;{
}
usedFreeMulligans.put(player.getId(), new Integer(1));
}
}
player.drawCards(numCards - deduction, this);
fireInformEvent(new StringBuilder(player.getName())
.append(" mulligans ")
.append(numCards)
.append(numCards == 1? " card":" cards")
.append(deduction == 0 ? " for free and draws ":" down to ")
.append(Integer.toString(player.getHand().size()))
.append(player.getHand().size() <= 1? " card":" cards").toString());
}
}
@Override
public void endMulligan(UUID playerId){
//return cards to
Player player = getPlayer(playerId);
if(player != null && mulliganedCards.containsKey(playerId)){
for(Card card : mulliganedCards.get(playerId).getCards(this)){
if(card != null){
card.setFaceDown(false);
card.moveToZone(Zone.LIBRARY, null, this, false);
}
}
if(mulliganedCards.get(playerId).size() > 0){
player.shuffleLibrary(this);
}
}
}
/* 20130711
*903.14a A player thats been dealt 21 or more combat damage by the same commander
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
*
*/
@Override
protected boolean checkStateBasedActions() {
for(Watcher watcher : getState().getWatchers().values()){
if(watcher instanceof CommanderCombatDamageWatcher){
CommanderCombatDamageWatcher damageWatcher = (CommanderCombatDamageWatcher)watcher;
for(UUID playerUUID : damageWatcher.getDamageToPlayer().keySet()){
Player player = getPlayer(playerUUID);
if(player != null && damageWatcher.getDamageToPlayer().get(playerUUID) >= 21){
player.lost(this);
}
}
}
}
return super.checkStateBasedActions();
}
@Override
public void quit(UUID playerId) {
super.quit(playerId);
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<UUID>();
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public void leave(UUID playerId) {
super.leave(playerId);
}
@Override
public CommanderDuel copy() {
return new CommanderDuel(this);
}
}

View file

@ -0,0 +1,49 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.mage</groupId>
<artifactId>mage-server-plugins</artifactId>
<version>1.2.0</version>
</parent>
<artifactId>mage-game-commanderfreeforall</artifactId>
<packaging>jar</packaging>
<name>Mage Game Commander Free For All</name>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mage</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
<finalName>mage-game-freeforall</finalName>
</build>
<properties/>
</project>

View file

@ -0,0 +1,71 @@
/*
* 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.game;
import mage.constants.MultiplayerAttackOption;
import mage.constants.RangeOfInfluence;
import mage.game.match.MatchType;
/**
*
* @author LevelX2
*/
public class CommanderFreeForAll extends GameCommanderImpl {
private int numPlayers;
public CommanderFreeForAll(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
super(attackOption, range, freeMulligans);
}
public CommanderFreeForAll(final CommanderFreeForAll game) {
super(game);
this.numPlayers = game.numPlayers;
}
@Override
public MatchType getGameType() {
return new CommanderFreeForAllType();
}
@Override
public int getNumPlayers() {
return numPlayers;
}
public void setNumPlayers(int numPlayers) {
this.numPlayers = numPlayers;
}
@Override
public CommanderFreeForAll copy() {
return new CommanderFreeForAll(this);
}
}

View file

@ -0,0 +1,52 @@
/*
* 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.game;
import mage.game.match.MatchImpl;
import mage.game.match.MatchOptions;
/**
*
* @author LevelX2
*/
public class CommanderFreeForAllMatch extends MatchImpl {
public CommanderFreeForAllMatch(MatchOptions options) {
super(options);
}
@Override
public void startGame() throws GameException {
CommanderFreeForAll game = new CommanderFreeForAll(options.getAttackOption(), options.getRange(), options.getFreeMulligans());
game.setStartMessage(this.createGameStartMessage());
initGame(game);
games.add(game);
}
}

View file

@ -0,0 +1,57 @@
/*
* 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.game;
import mage.game.match.MatchType;
/**
*
* @author LevelX2
*/
public class CommanderFreeForAllType extends MatchType<CommanderFreeForAllType> {
public CommanderFreeForAllType() {
this.name = "Commander Free For All";
this.maxPlayers = 10;
this.minPlayers = 3;
this.numTeams = 0;
this.useAttackOption = true;
this.useRange = true;
}
protected CommanderFreeForAllType(final CommanderFreeForAllType matchType) {
super(matchType);
}
@Override
public CommanderFreeForAllType copy() {
return new CommanderFreeForAllType(this);
}
}

View file

@ -17,7 +17,8 @@
<modules>
<module>Mage.Deck.Constructed</module>
<module>Mage.Deck.Limited</module>
<module>Mage.Game.CommanderDuel</module>
<module>Mage.Game.CommanderDuel</module>
<module>Mage.Game.CommanderFreeForAll</module>
<module>Mage.Game.FreeForAll</module>
<module>Mage.Game.TwoPlayerDuel</module>
<module>Mage.Player.AI</module>

View file

@ -22,6 +22,7 @@
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
<gameType name="Commander Two Player Duel" jar="mage-game-commanderduel.jar" className="mage.game.CommanderDuelMatch" typeName="mage.game.CommanderDuelType"/>
<gameType name="Commander Free For All" jar="mage-game-commanderfreeforall.jar" className="mage.game.CommanderFreeForAllMatch" typeName="mage.game.CommanderFreeForAllType"/>
</gameTypes>
<tournamentTypes>
<tournamentType name="Elimination Booster Draft" jar="mage-tournament-booster-draft.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>

View file

@ -69,6 +69,12 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mage-game-commanderfreeforall</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mage-game-freeforall</artifactId>

View file

@ -11,6 +11,7 @@
<gameType name="Two Player Duel" jar="mage-game-twoplayerduel-${project.version}.jar" className="mage.game.TwoPlayerMatch" typeName="mage.game.TwoPlayerDuelType"/>
<gameType name="Free For All" jar="mage-game-freeforall-${project.version}.jar" className="mage.game.FreeForAllMatch" typeName="mage.game.FreeForAllType"/>
<gameType name="Commander Two Player Duel" jar="mage-game-commanderduel-${project.version}.jar" className="mage.game.CommanderDuelMatch" typeName="mage.game.CommanderDuelType"/>
<gameType name="Commander Free For All" jar="mage-game-commanderfreeforall-${project.version}.jar" className="mage.game.CommanderFreeForAllMatch" typeName="mage.game.CommanderFreeForAllType"/>
</gameTypes>
<tournamentTypes>
<tournamentType name="Elimination Booster Draft" jar="mage-tournament-boosterdraft-${project.version}.jar" className="mage.tournament.BoosterDraftEliminationTournament" typeName="mage.tournament.BoosterDraftEliminationTournamentType"/>

View file

@ -125,4 +125,4 @@ class EvilEyeOfOrmsByGoreEffect extends ReplacementEffectImpl<EvilEyeOfOrmsByGor
}
return false;
}
}
}

View file

@ -34,6 +34,7 @@ import mage.constants.SpellAbilityType;
import mage.constants.TimingRule;
import mage.constants.Zone;
import mage.game.Game;
import mage.watchers.common.CommanderCombatDamageWatcher;
/**
*

View file

@ -37,6 +37,7 @@ import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.Target;
import mage.target.targetpointer.FirstTargetPointer;
import mage.util.CardUtil;
/**
*
@ -107,7 +108,7 @@ public class DestroyTargetEffect extends OneShotEffect<DestroyTargetEffect> {
} else if (mode.getTargets().get(0).getNumberOfTargets() == 1) {
sb.append("Destroy target ").append(mode.getTargets().get(0).getTargetName());
} else {
sb.append("Destroy ").append(mode.getTargets().get(0).getNumberOfTargets()).append(" target ").append(mode.getTargets().get(0).getTargetName());
sb.append("Destroy ").append(CardUtil.numberToText(mode.getTargets().get(0).getNumberOfTargets())).append(" target ").append(mode.getTargets().get(0).getTargetName());
}
if (noRegen) {
sb.append(". It can't be regenerated");

View file

@ -28,6 +28,7 @@
package mage.abilities.effects.common.continious;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.ReplacementEffectImpl;
import mage.cards.Card;
@ -39,6 +40,7 @@ import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.common.CommanderCombatDamageWatcher;
/**
*
@ -83,15 +85,18 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl<CommanderR
if (permanent != null) {
Player player = game.getPlayer(permanent.getOwnerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
return permanent.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
boolean result = permanent.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
return result;
}
}
} else {
Card card = game.getCard(event.getTargetId());
if (card != null) {
Player player = game.getPlayer(card.getOwnerId());
if (player != null && player.chooseUse(Outcome.Benefit, "Move commander to command zone?", game)){
return card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
boolean result = card.moveToZone(Zone.COMMAND, source.getSourceId(), game, false);
return result;
}
}
}

View file

@ -0,0 +1,219 @@
/*
* 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.game;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.EmptyEffect;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.common.continious.CommanderReplacementEffect;
import mage.abilities.effects.common.cost.CommanderCostModification;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.constants.MultiplayerAttackOption;
import mage.constants.Outcome;
import mage.constants.PhaseStep;
import mage.constants.RangeOfInfluence;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.game.turn.TurnMod;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import mage.watchers.Watcher;
import mage.watchers.common.CommanderCombatDamageWatcher;
public abstract class GameCommanderImpl extends GameImpl<GameCommanderImpl> {
private final Map<UUID, Cards> mulliganedCards = new HashMap<UUID, Cards>();
public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
super(attackOption, range, freeMulligans);
}
public GameCommanderImpl(final GameCommanderImpl game) {
super(game);
}
// MTG Rules 20121001
// 903.7. Once the starting player has been determined, each player sets his or her life total to 40 and
// draws a hand of seven cards.
@Override
public int getLife() {
return 40;
}
@Override
protected void init(UUID choosingPlayerId, GameOptions gameOptions) {
super.init(choosingPlayerId, gameOptions);
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new EmptyEffect("Commander effects"));
//Move commander to command zone
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null){
if (player.getSideboard().size() > 0){
Card commander = getCard((UUID)player.getSideboard().toArray()[0]);
if (commander != null) {
player.setCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
ability.addEffect(new CommanderReplacementEffect(commander.getId()));
ability.addEffect(new CommanderCostModification(commander.getId()));
getState().setValue(commander.getId() + "_castCount", new Integer(0));
CommanderCombatDamageWatcher watcher = new CommanderCombatDamageWatcher(commander.getId());
getState().getWatchers().add(watcher);
watcher.addCardInfoToCommander(this);
}
}
}
}
this.getState().addAbility(ability, this.getId(), null);
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
}
//20130711
/*903.8. The Commander variant uses an alternate mulligan rule.
* Each time a player takes a mulligan, rather than shuffling his or her entire hand of cards into his or her library, that player exiles any number of cards from his or her hand face down.
* Then the player draws a number of cards equal to one less than the number of cards he or she exiled this way.
* That player may look at all cards exiled this way while taking mulligans.
* Once a player keeps an opening hand, that player shuffles all cards he or she exiled this way into his or her library.
* */
//TODO implement may look at exile cards
@Override
public void mulligan(UUID playerId) {
Player player = getPlayer(playerId);
TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
target.setNotTarget(true);
//target.setRequired(true);
if(player.choose(Outcome.Exile, player.getHand(), target, this)){
int numCards = target.getTargets().size();
for(UUID uuid : target.getTargets()){
Card card = player.getHand().get(uuid, this);
if(card != null){
if(!mulliganedCards.containsKey(playerId)){
mulliganedCards.put(playerId, new CardsImpl());
}
card.setFaceDown(true);
card.moveToExile(null, "", null, this);
mulliganedCards.get(playerId).add(card);
}
}
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
if (used < freeMulligans ) {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(used+1));
}
} else {
deduction = 0;{
}
usedFreeMulligans.put(player.getId(), new Integer(1));
}
}
player.drawCards(numCards - deduction, this);
fireInformEvent(new StringBuilder(player.getName())
.append(" mulligans ")
.append(numCards)
.append(numCards == 1? " card":" cards")
.append(deduction == 0 ? " for free and draws ":" down to ")
.append(Integer.toString(player.getHand().size()))
.append(player.getHand().size() <= 1? " card":" cards").toString());
}
}
@Override
public void endMulligan(UUID playerId){
//return cards to
Player player = getPlayer(playerId);
if(player != null && mulliganedCards.containsKey(playerId)){
for(Card card : mulliganedCards.get(playerId).getCards(this)){
if(card != null){
card.setFaceDown(false);
card.moveToZone(Zone.LIBRARY, null, this, false);
}
}
if(mulliganedCards.get(playerId).size() > 0){
player.shuffleLibrary(this);
}
}
}
/* 20130711
*903.14a A player thats been dealt 21 or more combat damage by the same commander
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
*
*/
@Override
protected boolean checkStateBasedActions() {
for(Watcher watcher : getState().getWatchers().values()){
if(watcher instanceof CommanderCombatDamageWatcher){
CommanderCombatDamageWatcher damageWatcher = (CommanderCombatDamageWatcher)watcher;
for(UUID playerUUID : damageWatcher.getDamageToPlayer().keySet()){
Player player = getPlayer(playerUUID);
if(player != null && damageWatcher.getDamageToPlayer().get(playerUUID) >= 21){
player.lost(this);
}
}
}
}
return super.checkStateBasedActions();
}
@Override
public void quit(UUID playerId) {
super.quit(playerId);
}
@Override
public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<UUID>();
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
}
@Override
public void leave(UUID playerId) {
super.leave(playerId);
}
}

View file

@ -51,7 +51,6 @@ import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.DelayedTriggeredAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.common.CastCommanderAbility;
import mage.abilities.common.ChancellorAbility;
import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects;

View file

@ -31,11 +31,13 @@ import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import mage.MageObject;
import mage.cards.Card;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.DamagedPlayerEvent;
import mage.game.events.GameEvent;
import mage.game.events.GameEvent.EventType;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.watchers.WatcherImpl;
@ -43,9 +45,6 @@ import mage.watchers.WatcherImpl;
*903.14a A player thats been dealt 21 or more combat damage by the same commander
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
*
*/
/**
*
* @author Plopman
*/
@ -74,20 +73,57 @@ public class CommanderCombatDamageWatcher extends WatcherImpl<CommanderCombatDam
if (event.getType() == EventType.DAMAGED_PLAYER && event instanceof DamagedPlayerEvent) {
if (sourceId.equals(event.getSourceId())) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event;
UUID playerUUID = event.getTargetId();
Integer damage = damageToPlayer.get(playerUUID);
if(damage == null){
damage = 0;
}
damage += damageEvent.getAmount();
damageToPlayer.put(playerUUID, damage);
Player player = game.getPlayer(playerUUID);
MageObject commander = game.getObject(sourceId);
if (player != null && commander != null){
game.informPlayers(commander.getName() + " did " + damage + " damages to " + player.getName() + " during the game.");
if (damageEvent.isCombatDamage()) {
UUID playerUUID = event.getTargetId();
Integer damage = damageToPlayer.get(playerUUID);
if(damage == null){
damage = 0;
}
damage += damageEvent.getAmount();
damageToPlayer.put(playerUUID, damage);
Player player = game.getPlayer(playerUUID);
MageObject commander = game.getObject(sourceId);
if (player != null && commander != null){
game.informPlayers(commander.getName() + " did " + damage + " combat damage to " + player.getName() + " during the game.");
this.addCardInfoToCommander(game);
}
}
}
}
// Add card info to the commander
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && event.getTargetId().equals(sourceId)) {
this.addCardInfoToCommander(game);
}
}
public void addCardInfoToCommander(Game game) {
MageObject object = game.getPermanent(sourceId);
if (object == null) {
object = game.getCard(sourceId);
}
if (object != null) {
StringBuilder sb = new StringBuilder();
sb.append("<b>Commander</b>");
Integer castCount = (Integer)game.getState().getValue(sourceId + "_castCount");
if (castCount != null) {
sb.append(" was ").append(castCount).append(castCount.intValue() == 1 ? " time":" times").append(" casted from the command zone.");
}
this.addInfo(object, "Commander",sb.toString());
for (Map.Entry<UUID, Integer> entry : damageToPlayer.entrySet()) {
Player damagedPlayer = game.getPlayer(entry.getKey());
sb.setLength(0);
sb.append("<b>Commander</b> did ").append(entry.getValue()).append(" combat damage to player ").append(damagedPlayer.getName()).append(".");
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(),sb.toString());
}
}
}
private void addInfo(MageObject object, String key, String value) {
if (object instanceof Card) {
((Card) object).addInfo(key, value);
} else if (object instanceof Permanent) {
((Permanent) object).addInfo(key, value);
}
}
public Map<UUID, Integer> getDamageToPlayer() {