mirror of
https://github.com/magefree/mage.git
synced 2026-01-09 20:32:06 -08:00
* Fixed some possible java exception causes.
This commit is contained in:
parent
b668209f7d
commit
c774e95335
5 changed files with 173 additions and 167 deletions
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* 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
|
||||
|
|
@ -20,14 +20,14 @@
|
|||
* 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.abilities.effects;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.constants.Duration;
|
||||
|
|
@ -42,7 +42,6 @@ import mage.game.stack.StackObject;
|
|||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
|
|
@ -68,10 +67,10 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
|
|||
public boolean checksEventType(GameEvent event, Game game) {
|
||||
return event.getType() == EventType.DAMAGE_PLAYER;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
DamageEvent damageEvent = (DamageEvent)event;
|
||||
DamageEvent damageEvent = (DamageEvent) event;
|
||||
UUID playerId = getSourceControllerId(event.getSourceId(), game);
|
||||
if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) {
|
||||
Player target = game.getPlayer(event.getTargetId());
|
||||
|
|
@ -81,9 +80,11 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
|
|||
if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", game)) {
|
||||
redirectTarget = new TargetPermanent(filter);
|
||||
if (numPlaneswalkers == 1) {
|
||||
redirectTarget.add(game.getBattlefield().getAllActivePermanents(filter, target.getId(), game).get(0).getId(), game);
|
||||
}
|
||||
else {
|
||||
List<Permanent> planeswalker = game.getBattlefield().getAllActivePermanents(filter, target.getId(), game);
|
||||
if (!planeswalker.isEmpty()) {
|
||||
redirectTarget.add(planeswalker.get(0).getId(), game);
|
||||
}
|
||||
} else {
|
||||
player.choose(Outcome.Damage, redirectTarget, null, game);
|
||||
}
|
||||
if (!game.isSimulation()) {
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
* 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;
|
||||
|
|
@ -57,10 +56,10 @@ import mage.watchers.common.CommanderInfoWatcher;
|
|||
public abstract class GameCommanderImpl extends GameImpl {
|
||||
|
||||
static boolean CHECK_COMMANDER_DAMAGE = true;
|
||||
|
||||
|
||||
private final Map<UUID, Cards> mulliganedCards = new HashMap<>();
|
||||
// private final Set<CommanderInfoWatcher> commanderCombatWatcher = new HashSet<>();
|
||||
|
||||
|
||||
protected boolean alsoHand; // replace commander going to hand
|
||||
protected boolean alsoLibrary; // replace commander going to library
|
||||
protected boolean startingPlayerSkipsDraw = true;
|
||||
|
|
@ -80,12 +79,12 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
protected void init(UUID choosingPlayerId) {
|
||||
Ability ability = new SimpleStaticAbility(Zone.COMMAND, new InfoEffect("Commander effects"));
|
||||
//Move commander to command zone
|
||||
for (UUID playerId: state.getPlayerList(startingPlayerId)) {
|
||||
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) {
|
||||
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);
|
||||
commander.getAbilities().setControllerId(player.getId());
|
||||
|
|
@ -107,7 +106,6 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
state.getTurnMods().add(new TurnMod(startingPlayerId, PhaseStep.DRAW));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//20130711
|
||||
/*903.8. The Commander variant uses an alternate mulligan rule.
|
||||
|
|
@ -123,12 +121,12 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
TargetCardInHand target = new TargetCardInHand(1, player.getHand().size(), new FilterCard("card to mulligan"));
|
||||
target.setNotTarget(true);
|
||||
target.setRequired(false);
|
||||
if (player.choose(Outcome.Exile, player.getHand(), target, this)){
|
||||
if (player.choose(Outcome.Exile, player.getHand(), target, this)) {
|
||||
int numCards = target.getTargets().size();
|
||||
for(UUID uuid : target.getTargets()){
|
||||
for (UUID uuid : target.getTargets()) {
|
||||
Card card = player.getHand().get(uuid, this);
|
||||
if(card != null){
|
||||
if(!mulliganedCards.containsKey(playerId)){
|
||||
if (card != null) {
|
||||
if (!mulliganedCards.containsKey(playerId)) {
|
||||
mulliganedCards.put(playerId, new CardsImpl());
|
||||
}
|
||||
card.moveToExile(null, "", null, this);
|
||||
|
|
@ -140,14 +138,15 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
if (freeMulligans > 0) {
|
||||
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
|
||||
int used = usedFreeMulligans.get(player.getId());
|
||||
if (used < freeMulligans ) {
|
||||
if (used < freeMulligans) {
|
||||
deduction = 0;
|
||||
usedFreeMulligans.put(player.getId(), used+1);
|
||||
usedFreeMulligans.put(player.getId(), used + 1);
|
||||
}
|
||||
} else {
|
||||
deduction = 0;{
|
||||
deduction = 0;
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
usedFreeMulligans.put(player.getId(), 1);
|
||||
}
|
||||
}
|
||||
|
|
@ -155,25 +154,25 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
fireInformEvent(new StringBuilder(player.getLogName())
|
||||
.append(" mulligans ")
|
||||
.append(numCards)
|
||||
.append(numCards == 1? " card":" cards")
|
||||
.append(deduction == 0 ? " for free and draws ":" down to ")
|
||||
.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());
|
||||
.append(player.getHand().size() <= 1 ? " card" : " cards").toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endMulligan(UUID playerId){
|
||||
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){
|
||||
if (player != null && mulliganedCards.containsKey(playerId)) {
|
||||
for (Card card : mulliganedCards.get(playerId).getCards(this)) {
|
||||
if (card != null) {
|
||||
card.moveToZone(Zone.LIBRARY, null, this, false);
|
||||
card.setFaceDown(false, this);
|
||||
}
|
||||
}
|
||||
if(mulliganedCards.get(playerId).size() > 0){
|
||||
if (mulliganedCards.get(playerId).size() > 0) {
|
||||
player.shuffleLibrary(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -186,12 +185,15 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
*/
|
||||
@Override
|
||||
protected boolean checkStateBasedActions() {
|
||||
for (Player player: getPlayers().values()) {
|
||||
for (Player player : getPlayers().values()) {
|
||||
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId());
|
||||
for(Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()){
|
||||
if (damageWatcher == null) {
|
||||
continue;
|
||||
}
|
||||
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
|
||||
if (entrySet.getValue() > 20) {
|
||||
Player opponent = getPlayer(entrySet.getKey());
|
||||
if (opponent != null && player.isInGame()){
|
||||
if (opponent != null && player.isInGame()) {
|
||||
opponent.lost(this);
|
||||
}
|
||||
}
|
||||
|
|
@ -203,7 +205,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
@Override
|
||||
public Set<UUID> getOpponents(UUID playerId) {
|
||||
Set<UUID> opponents = new HashSet<>();
|
||||
for (UUID opponentId: this.getPlayer(playerId).getInRange()) {
|
||||
for (UUID opponentId : this.getPlayer(playerId).getInRange()) {
|
||||
if (!opponentId.equals(playerId)) {
|
||||
opponents.add(opponentId);
|
||||
}
|
||||
|
|
@ -213,7 +215,7 @@ public abstract class GameCommanderImpl extends GameImpl {
|
|||
|
||||
@Override
|
||||
public boolean isOpponent(Player player, UUID playerToCheck) {
|
||||
return !player.getId().equals(playerToCheck);
|
||||
return !player.getId().equals(playerToCheck);
|
||||
}
|
||||
|
||||
public void setAlsoHand(boolean alsoHand) {
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*
|
||||
* Copyright 2011 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
|
||||
|
|
@ -20,7 +20,7 @@
|
|||
* 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.
|
||||
|
|
@ -43,15 +43,14 @@ import mage.watchers.Watcher;
|
|||
|
||||
/* 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.)
|
||||
* over the course of the game loses the game. (This is a state-based action. See rule 704.)
|
||||
*
|
||||
*
|
||||
* @author Plopman
|
||||
*/
|
||||
|
||||
public class CommanderInfoWatcher extends Watcher {
|
||||
|
||||
public Map<UUID, Integer> damageToPlayer = new HashMap<>();
|
||||
public final Map<UUID, Integer> damageToPlayer = new HashMap<>();
|
||||
public boolean checkCommanderDamage;
|
||||
|
||||
public CommanderInfoWatcher(UUID commander, boolean checkCommanderDamage) {
|
||||
|
|
@ -59,7 +58,6 @@ public class CommanderInfoWatcher extends Watcher {
|
|||
this.sourceId = commander;
|
||||
this.checkCommanderDamage = checkCommanderDamage;
|
||||
}
|
||||
|
||||
|
||||
public CommanderInfoWatcher(final CommanderInfoWatcher watcher) {
|
||||
super(watcher);
|
||||
|
|
@ -76,20 +74,21 @@ public class CommanderInfoWatcher extends Watcher {
|
|||
public void watch(GameEvent event, Game game) {
|
||||
if (checkCommanderDamage && event.getType() == EventType.DAMAGED_PLAYER && event instanceof DamagedPlayerEvent) {
|
||||
if (sourceId.equals(event.getSourceId())) {
|
||||
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event;
|
||||
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
|
||||
if (damageEvent.isCombatDamage()) {
|
||||
UUID playerUUID = event.getTargetId();
|
||||
Integer damage = damageToPlayer.get(playerUUID);
|
||||
if(damage == null){
|
||||
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){
|
||||
if (!game.isSimulation())
|
||||
if (player != null && commander != null) {
|
||||
if (!game.isSimulation()) {
|
||||
game.informPlayers(commander.getLogName() + " did " + damage + " combat damage to " + player.getLogName() + " during the game.");
|
||||
}
|
||||
this.addCardInfoToCommander(game);
|
||||
}
|
||||
}
|
||||
|
|
@ -109,18 +108,18 @@ public class CommanderInfoWatcher extends Watcher {
|
|||
if (object != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<b>Commander</b>");
|
||||
Integer castCount = (Integer)game.getState().getValue(sourceId + "_castCount");
|
||||
Integer castCount = (Integer) game.getState().getValue(sourceId + "_castCount");
|
||||
if (castCount != null) {
|
||||
sb.append(" ").append(castCount).append(castCount == 1 ? " time":" times").append(" casted from the command zone.");
|
||||
sb.append(" ").append(castCount).append(castCount == 1 ? " time" : " times").append(" casted from the command zone.");
|
||||
}
|
||||
this.addInfo(object, "Commander",sb.toString(), game);
|
||||
|
||||
this.addInfo(object, "Commander", sb.toString(), game);
|
||||
|
||||
if (checkCommanderDamage) {
|
||||
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.getLogName()).append(".");
|
||||
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(),sb.toString(), game);
|
||||
this.addInfo(object, new StringBuilder("Commander").append(entry.getKey()).toString(), sb.toString(), game);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -135,6 +134,6 @@ public class CommanderInfoWatcher extends Watcher {
|
|||
|
||||
public Map<UUID, Integer> getDamageToPlayer() {
|
||||
return damageToPlayer;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue