Fixed some possible exceptions.

This commit is contained in:
LevelX2 2016-02-06 02:12:51 +01:00
parent e936f7dc0f
commit d2eb6151f1
20 changed files with 133 additions and 132 deletions

View file

@ -46,6 +46,7 @@ import mage.game.GameState;
import mage.game.combat.CombatGroup;
import mage.game.command.Emblem;
import mage.game.permanent.Permanent;
import mage.game.permanent.PermanentCard;
import mage.game.permanent.PermanentToken;
import mage.game.stack.Spell;
import mage.game.stack.StackAbility;
@ -62,7 +63,7 @@ public class GameView implements Serializable {
private static final long serialVersionUID = 1L;
private static final Logger logger = Logger.getLogger(GameView.class);
private static final Logger LOGGER = Logger.getLogger(GameView.class);
private final int priorityTime;
private final List<PlayerView> players = new ArrayList<>();
@ -101,6 +102,9 @@ public class GameView implements Serializable {
// Stack Ability
MageObject object = game.getObject(stackObject.getSourceId());
Card card = game.getCard(stackObject.getSourceId());
if (card == null && (object instanceof PermanentCard)) {
card = ((PermanentCard) object).getCard();
}
if (card != null) {
if (object != null) {
if (object instanceof Permanent) {
@ -139,19 +143,17 @@ public class GameView implements Serializable {
stack.put(stackObject.getId(),
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
} else {
if (object instanceof StackAbility) {
} else if (object instanceof StackAbility) {
StackAbility stackAbility = ((StackAbility) object);
stackAbility.newId();
stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject)));
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
} else {
logger.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString() + " " + object.getClass().toString());
}
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + " " + object.toString() + " " + object.getClass().toString());
}
} else {
// can happen if a player times out while ability is on the stack
logger.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule());
LOGGER.debug("Stack Object for stack ability not found: " + stackObject.getStackAbility().getRule());
}
} else {
// Spell
@ -186,7 +188,7 @@ public class GameView implements Serializable {
}
if (isPlayer) {
// has only to be set for active palyer with priority (e.g. pay mana by delve or Quenchable Fire special action)
if (createdForPlayer != null && createdForPlayerId.equals(state.getPriorityPlayerId())) {
if (createdForPlayer != null && createdForPlayerId != null && createdForPlayerId.equals(state.getPriorityPlayerId())) {
this.special = state.getSpecialActions().getControlledBy(state.getPriorityPlayerId(), createdForPlayer.isInPayManaMode()).size() > 0;
}
} else {

View file

@ -436,18 +436,17 @@ public class HumanPlayer extends PlayerImpl {
@Override
public boolean choose(Outcome outcome, Cards cards, TargetCard target, Game game) {
if (cards == null) {
return false;
}
updateGameStatePriority("choose(4)", game);
while (!abort) {
boolean required = target.isRequired();
// if there is no cards to select from, then add possibility to cancel choosing action
if (cards == null) {
required = false;
} else {
int count = cards.count(target.getFilter(), game);
if (count == 0) {
required = false;
}
}
if (target.getTargets().size() >= target.getNumberOfTargets()) {
required = false;
}
@ -1227,7 +1226,7 @@ public class HumanPlayer extends PlayerImpl {
updateGameStatePriority("activateAbility", game);
if (abilities.size() == 1 && suppressAbilityPicker(abilities.values().iterator().next())) {
ActivatedAbility ability = abilities.values().iterator().next();
if (ability.getTargets().size() != 0
if (!ability.getTargets().isEmpty()
|| !(ability.getCosts().size() == 1 && ability.getCosts().get(0) instanceof SacrificeSourceCost)
|| !(ability.getCosts().size() == 2 && ability.getCosts().get(0) instanceof TapSourceCost && ability.getCosts().get(0) instanceof SacrificeSourceCost)) {
activateAbility(ability, game);
@ -1236,7 +1235,7 @@ public class HumanPlayer extends PlayerImpl {
}
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values()));
waitForResponse(game);
if (response.getUUID() != null) {
if (response.getUUID() != null && isInGame()) {
if (abilities.containsKey(response.getUUID())) {
activateAbility(abilities.get(response.getUUID()), game);
}

View file

@ -188,11 +188,10 @@ public class UserManager {
public void handleException(Exception ex) {
if (ex != null) {
LOGGER.fatal("User manager exception " + (ex.getMessage() == null ? "null" : ex.getMessage()));
if (ex.getCause() != null) {
LOGGER.debug("- Cause: " + (ex.getCause().getMessage() == null ? "null" : ex.getCause().getMessage()));
LOGGER.fatal("User manager exception ", ex);
if (ex.getStackTrace() != null) {
LOGGER.fatal(ex.getStackTrace());
}
ex.printStackTrace();
} else {
LOGGER.fatal("User manager exception - null");
}

View file

@ -43,6 +43,7 @@ import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.WatcherScope;
import mage.filter.common.FilterInstantOrSorceryCard;
import mage.game.ExileZone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
@ -152,9 +153,11 @@ class JelevaNephaliasCastEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(outcome, "Cast an instant or sorcery from exile?", source, game)) {
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source));
if (exileZone != null && exileZone.count(new FilterInstantOrSorceryCard(), game) > 0) {
if (controller.chooseUse(outcome, "Cast an instant or sorcery card from exile?", source, game)) {
TargetCardInExile target = new TargetCardInExile(new FilterInstantOrSorceryCard(), CardUtil.getCardExileZoneId(game, source));
if (controller.choose(Outcome.PlayForFree, game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)), target, game)) {
if (controller.choose(Outcome.PlayForFree, exileZone, target, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getExile().removeCard(card, game);
@ -162,6 +165,7 @@ class JelevaNephaliasCastEffect extends OneShotEffect {
}
}
}
}
return true;
}
return false;

View file

@ -13,7 +13,6 @@ import mage.abilities.common.AsEntersBattlefieldAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.cost.CostModificationEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.choices.ChoiceImpl;
import mage.constants.CardType;
@ -24,6 +23,7 @@ import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.Spell;
import mage.players.Player;
import mage.util.CardUtil;
@ -125,10 +125,9 @@ class CloudKeyCostModificationEffect extends CostModificationEffectImpl {
@Override
public boolean applies(Ability abilityToModify, Ability source, Game game) {
if (abilityToModify instanceof SpellAbility && abilityToModify.getControllerId().equals(source.getControllerId())) {
Card card = game.getCard(abilityToModify.getSourceId());
if (card.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) {
Spell spell = game.getStack().getSpell(abilityToModify.getSourceId());
if (spell != null && spell.getCardType().toString().contains((String) game.getState().getValue(source.getSourceId().toString() + "_CloudKey"))) {
return true;
}
}

View file

@ -32,9 +32,7 @@ import mage.abilities.Ability;
import mage.abilities.common.DiesAttachedTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.PutPermanentOnBattlefieldEffect;
import mage.abilities.effects.common.continuous.BoostEquippedEffect;
import mage.abilities.keyword.EquipAbility;
import mage.cards.Card;
@ -45,9 +43,6 @@ import mage.constants.Rarity;
import mage.constants.Zone;
import mage.filter.FilterCard;
import mage.filter.common.FilterCreatureCard;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.other.AuraCardCanAttachToPermanentId;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -86,7 +81,7 @@ class DeathrenderEffect extends OneShotEffect {
DeathrenderEffect() {
super(Outcome.PutCardInPlay);
this.staticText = "you may put a creature card from your hand onto the battlefield and attach {this} to it.";
this.staticText = "you may put a creature card from your hand onto the battlefield and attach {this} to it";
}
DeathrenderEffect(final DeathrenderEffect effect) {
@ -102,14 +97,13 @@ class DeathrenderEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null) {
if (controller != null && sourcePermanent != null) {
FilterCard filter = new FilterCreatureCard();
TargetCardInHand target = new TargetCardInHand(0, 1, filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card creatureInHand = game.getCard(target.getFirstTarget());
if (creatureInHand != null) {
game.getState().setValue("attachTo:" + sourcePermanent.getId(), game.getPermanent(creatureInHand.getId()));
if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game) && sourcePermanent != null) {
if (controller.moveCards(creatureInHand, Zone.BATTLEFIELD, source, game)) {
game.getPermanent(creatureInHand.getId()).addAttachment(sourcePermanent.getId(), game);
}
}

View file

@ -28,16 +28,11 @@
package mage.sets.magic2010;
import java.util.UUID;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DrawCardOpponentTriggeredAbility;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.targetpointer.FixedTarget;
/**
*
@ -49,7 +44,6 @@ public class UnderworldDreams extends CardImpl {
super(ownerId, 115, "Underworld Dreams", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{B}{B}{B}");
this.expansionSetCode = "M10";
// Whenever an opponent draws a card, Underworld Dreams deals 1 damage to him or her.
this.addAbility(new DrawCardOpponentTriggeredAbility(new DamageTargetEffect(1, true, "him or her"), false, true));
}

View file

@ -75,6 +75,7 @@ public class HamletbackGoliath extends CardImpl {
}
class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl {
HamletbackGoliathTriggeredAbility() {
super(Zone.BATTLEFIELD, new HamletbackGoliathEffect(), true);
}
@ -109,11 +110,12 @@ class HamletbackGoliathTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "Whenever another creature enters the battlefield, you may put X +1/+1 counters on Hamletback Goliath, where X is that creature's power.";
return "Whenever another creature enters the battlefield, you may put X +1/+1 counters on {this}, where X is that creature's power.";
}
}
class HamletbackGoliathEffect extends OneShotEffect {
HamletbackGoliathEffect() {
super(Outcome.BoostCreature);
}
@ -125,15 +127,14 @@ class HamletbackGoliathEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
Permanent creature = game.getPermanent(targetPointer.getFirst(game, source));
Permanent HamletbackGoliath = game.getPermanent(source.getSourceId());
Permanent sourceObject = game.getPermanent(source.getSourceId());
if (creature == null) {
creature = (Permanent) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.BATTLEFIELD);
}
if (creature != null) {
HamletbackGoliath.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game);
return true;
if (creature != null && sourceObject != null) {
sourceObject.addCounters(CounterType.P1P1.createInstance(creature.getPower().getValue()), game);
}
return false;
return true;
}
@Override

View file

@ -63,7 +63,6 @@ public class ErayoSoratamiAscendant extends CardImpl {
this.flipCard = true;
this.flipCardName = "Erayo's Essence";
// Flying
this.addAbility(FlyingAbility.getInstance());
// Whenever the fourth spell of a turn is cast, flip Erayo, Soratami Ascendant.
@ -121,7 +120,7 @@ class ErayoSoratamiAscendantTriggeredAbility extends TriggeredAbilityImpl {
class ErayosEssence extends Token {
ErayosEssence () {
ErayosEssence() {
super("Erayo's Essence", "");
supertype.add("Legendary");
cardType.add(CardType.ENCHANTMENT);
@ -129,13 +128,16 @@ class ErayosEssence extends Token {
color.setBlue(true);
// Whenever an opponent casts a spell for the first time in a turn, counter that spell.
this.addAbility(new ErayosEssenceTriggeredAbility());
Effect effect = new CounterTargetEffect();
effect.setText("counter that spell");
this.addAbility(new ErayosEssenceTriggeredAbility(effect));
}
}
class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl {
public ErayosEssenceTriggeredAbility() {
super(Zone.BATTLEFIELD, new CounterTargetEffect(), false);
public ErayosEssenceTriggeredAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
}
public ErayosEssenceTriggeredAbility(final ErayosEssenceTriggeredAbility ability) {
@ -163,7 +165,7 @@ class ErayosEssenceTriggeredAbility extends TriggeredAbilityImpl {
@Override
public String getRule() {
return "Whenever an opponent casts a spell for the first time each turn, counter that spell.";
return "Whenever an opponent casts a spell for the first time each turn, " + super.getRule();
}
@Override

View file

@ -78,10 +78,10 @@ public class EternalDominion extends CardImpl {
class EternalDominionEffect extends OneShotEffect {
private static final FilterCard filter = new FilterCard("an artifact, creature, enchantment, or land card");
private static final FilterCard FILTER = new FilterCard("an artifact, creature, enchantment, or land card");
static {
filter.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT),
FILTER.add(Predicates.or(new CardTypePredicate(CardType.ARTIFACT),
new CardTypePredicate(CardType.CREATURE),
new CardTypePredicate(CardType.ENCHANTMENT),
new CardTypePredicate(CardType.LAND)));
@ -102,7 +102,7 @@ class EternalDominionEffect extends OneShotEffect {
Player opponent = game.getPlayer(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (opponent != null && controller != null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
TargetCardInLibrary target = new TargetCardInLibrary(FILTER);
controller.searchLibrary(target, game, opponent.getId());
Card targetCard = game.getCard(target.getFirstTarget());
if (targetCard != null) {

View file

@ -32,12 +32,12 @@ import java.util.UUID;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.CardType;
import mage.constants.Rarity;
import mage.cards.CardImpl;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.Rarity;
import mage.constants.SubLayer;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
@ -50,7 +50,6 @@ import mage.target.common.TargetControlledCreaturePermanent;
*/
public class SigilBlessing extends CardImpl {
public SigilBlessing(UUID ownerId) {
super(ownerId, 195, "Sigil Blessing", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{G}{W}");
this.expansionSetCode = "ALA";
@ -71,6 +70,7 @@ public class SigilBlessing extends CardImpl {
}
class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl {
public SigilBlessingBoostControlledEffect() {
super(Duration.EndOfTurn, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, Outcome.BoostCreature);
staticText = "Until end of turn, target creature you control gets +3/+3 and other creatures you control get +1/+1";
@ -99,7 +99,7 @@ class SigilBlessingBoostControlledEffect extends ContinuousEffectImpl {
Permanent permanent = it.next().getPermanent(game);
if (permanent != null) {
int boost = 1;
if (getTargetPointer().getFirst(game, source).equals(permanent.getId())) {
if (permanent.getId().equals(getTargetPointer().getFirst(game, source))) {
boost = 3;
}
permanent.addPower(boost);

View file

@ -24,12 +24,10 @@
* 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.costs.common;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.costs.Cost;
import mage.abilities.costs.CostImpl;
@ -67,7 +65,7 @@ public class PayLoyaltyCost extends CostImpl {
@Override
public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) {
Permanent planeswalker = game.getPermanent(sourceId);
if (planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
if (planeswalker != null && planeswalker.getCounters().getCount(CounterType.LOYALTY) + amount >= 0 && planeswalker.canLoyaltyBeUsed(game)) {
if (amount > 0) {
planeswalker.getCounters().addCounter(CounterType.LOYALTY.createInstance(amount));
} else if (amount < 0) {

View file

@ -43,6 +43,7 @@ import java.util.Set;
import java.util.UUID;
import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.MageSingleton;
import mage.abilities.SpellAbility;
import mage.abilities.StaticAbility;
@ -743,6 +744,9 @@ public class ContinuousEffects implements Serializable {
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
effect.setValue("targetAbility", targetAbility);
if (effect.applies(event, sourceAbility, game)) {
if (targetAbility instanceof ActivatedAbility && ((ActivatedAbility) targetAbility).isCheckPlayableMode()) {
checkPlayableMode = true;
}
if (!checkPlayableMode) {
String message = effect.getInfoMessage(sourceAbility, event, game);
if (message != null && !message.isEmpty()) {

View file

@ -88,10 +88,10 @@ public class PlaneswalkerRedirectionEffect extends RedirectionEffect {
player.choose(Outcome.Damage, redirectTarget, null, game);
}
if (!game.isSimulation()) {
game.informPlayers(new StringBuilder(player.getLogName()).append(" redirects ")
.append(event.getAmount())
.append(" damage to ")
.append(game.getPermanent(redirectTarget.getFirstTarget()).getLogName()).toString());
Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget());
if (redirectTo != null) {
game.informPlayers(player.getLogName() + " redirects " + event.getAmount() + " damage to " + redirectTo.getLogName());
}
}
return true;
}

View file

@ -69,6 +69,6 @@ public class CounterTargetEffect extends OneShotEffect {
if (staticText != null && !staticText.isEmpty()) {
return staticText;
}
return "counter target " + mode.getTargets().get(0).getTargetName();
return "counter target " + (mode.getTargets().get(0) != null ? mode.getTargets().get(0).getTargetName() : "spell");
}
}

View file

@ -34,7 +34,7 @@ import mage.players.Player;
*/
public class EpicEffect extends OneShotEffect {
final String rule = "<br><br/>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)";
final String rule = "<br>Epic <i>(For the rest of the game, you can't cast spells. At the beginning of each of your upkeeps for the rest of the game, copy this spell except for its epic ability. If the spell has targets, you may choose new targets for the copy)";
public EpicEffect() {
super(Outcome.Benefit);

View file

@ -553,7 +553,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override
public int getSourceObjectZoneChangeCounter() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported.");
}
@Override
@ -563,7 +563,7 @@ public class StackAbility extends StackObjImpl implements Ability {
@Override
public int getZoneChangeCounter(Game game) {
throw new UnsupportedOperationException("Not supported.");
return game.getState().getZoneChangeCounter(getSourceId());
}
@Override

View file

@ -209,12 +209,15 @@ public abstract class StackObjImpl implements StackObject {
} else {
again = true;
}
} else {
// if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition
} else // if possible add the alternate Target - it may not be included in the old definition nor in the already selected targets of the new definition
if (newTarget.getTargets().contains(tempTarget.getFirstTarget()) || target.getTargets().contains(tempTarget.getFirstTarget())) {
if (targetController.isHuman()) {
game.informPlayer(targetController, "This target was already selected from origin spell. You can only keep this target!");
if (targetController.chooseUse(Outcome.Benefit, "This target was already selected from origin spell. Reset to original target?", ability, game)) {
// use previous target no target was selected
newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false);
} else {
again = true;
}
} else {
newTarget.addTarget(targetId, target.getTargetAmount(targetId), ability, game, false);
}
@ -236,7 +239,6 @@ public abstract class StackObjImpl implements StackObject {
// valid target was selected, add it to the new target definition
newTarget.addTarget(tempTarget.getFirstTarget(), target.getTargetAmount(targetId), ability, game, false);
}
}
} while (again && targetController.canRespond());
}
} // keep the target

View file

@ -898,7 +898,7 @@ public abstract class PlayerImpl implements Player, Serializable {
*/
@Override
public boolean putCardsOnTopOfLibrary(Cards cardsToLibrary, Game game, Ability source, boolean anyOrder) {
if (!cardsToLibrary.isEmpty()) {
if (cardsToLibrary != null && !cardsToLibrary.isEmpty()) {
Cards cards = new CardsImpl(cardsToLibrary); // prevent possible ConcurrentModificationException
UUID sourceId = (source == null ? null : source.getSourceId());
if (!anyOrder) {
@ -982,6 +982,9 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public boolean cast(SpellAbility ability, Game game, boolean noMana) {
if (game == null || ability == null) {
return false;
}
if (!ability.getSpellAbilityType().equals(SpellAbilityType.BASE)) {
ability = chooseSpellAbilityForCast(ability, game, noMana);
}