mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08: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:
parent
ebb71b7dd7
commit
05cbd90fe2
16 changed files with 521 additions and 196 deletions
|
|
@ -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;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
219
Mage/src/mage/game/GameCommanderImpl.java
Normal file
219
Mage/src/mage/game/GameCommanderImpl.java
Normal 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 that’s 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 that’s 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() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue