mirror of
https://github.com/magefree/mage.git
synced 2025-12-29 23:12:10 -08:00
Fix Clash effect causing NullPointerExceptions (#10742)
This commit is contained in:
parent
005f32cfff
commit
4d3b944b65
4 changed files with 24 additions and 16 deletions
|
|
@ -1,7 +1,6 @@
|
|||
|
||||
package mage.cards.c;
|
||||
|
||||
import java.util.UUID;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.BeginningOfYourEndStepTriggeredAbility;
|
||||
import mage.abilities.effects.ContinuousEffect;
|
||||
|
|
@ -13,9 +12,9 @@ import mage.abilities.keyword.EnchantAbility;
|
|||
import mage.cards.CardImpl;
|
||||
import mage.cards.CardSetInfo;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.SubType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubType;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.players.Player;
|
||||
|
|
@ -23,8 +22,9 @@ import mage.target.TargetPermanent;
|
|||
import mage.target.common.TargetCreaturePermanent;
|
||||
import mage.target.targetpointer.FixedTarget;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author jeffwadsworth
|
||||
*/
|
||||
public final class CaptivatingGlance extends CardImpl {
|
||||
|
|
@ -87,9 +87,9 @@ class CaptivatingGlanceEffect extends OneShotEffect {
|
|||
effect.setTargetPointer(new FixedTarget(enchantedCreature, game));
|
||||
game.addEffect(effect, source);
|
||||
} else {
|
||||
Object opponent = getValue("clashOpponent");
|
||||
if (opponent instanceof Player) {
|
||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, ((Player)opponent).getId());
|
||||
Player opponent = game.getPlayer((UUID) getValue("clashOpponent"));
|
||||
if (opponent != null) {
|
||||
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, opponent.getId());
|
||||
effect.setTargetPointer(new FixedTarget(enchantedCreature, game));
|
||||
game.addEffect(effect, source);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import mage.abilities.MageSingleton;
|
|||
import mage.abilities.Mode;
|
||||
import mage.constants.EffectType;
|
||||
import mage.constants.Outcome;
|
||||
import mage.players.Player;
|
||||
import mage.target.targetpointer.FirstTargetPointer;
|
||||
import mage.target.targetpointer.TargetPointer;
|
||||
|
||||
|
|
@ -104,6 +105,12 @@ public abstract class EffectImpl implements Effect {
|
|||
values = new HashMap<>();
|
||||
}
|
||||
}
|
||||
if (value instanceof Player) {
|
||||
// If Player are set as value, there might be PlayerImpl serialized in ClientMessage's GameView.
|
||||
// That does cause the message's data to not be unzippable, since the PlayerImpl class are not
|
||||
// client-side.
|
||||
throw new IllegalArgumentException("Players should not be set as value, set the UUID instead.");
|
||||
}
|
||||
values.put(key, value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@ public class ClashEffect extends OneShotEffect {
|
|||
if (cardOpponent != null) {
|
||||
opponent.moveCardToLibraryWithInfo(cardOpponent, source, game, Zone.LIBRARY, topOpponent, true);
|
||||
}
|
||||
|
||||
// fire CLASHED events with info about winner (flag is true if playerId won; other player is targetId)
|
||||
game.fireEvent(new GameEvent(
|
||||
GameEvent.EventType.CLASHED, opponent.getId(), source,
|
||||
|
|
@ -157,7 +158,7 @@ public class ClashEffect extends OneShotEffect {
|
|||
));
|
||||
|
||||
// set opponent to DoIfClashWonEffect
|
||||
source.getEffects().setValue("clashOpponent", opponent);
|
||||
source.getEffects().setValue("clashOpponent", opponent.getId());
|
||||
return cmcController > cmcOpponent;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,8 +14,9 @@ import mage.players.Player;
|
|||
import mage.target.targetpointer.FixedTarget;
|
||||
import mage.util.CardUtil;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
|
|
@ -31,7 +32,7 @@ public class DoIfClashWonEffect extends OneShotEffect {
|
|||
public DoIfClashWonEffect(Effect effect, boolean setTargetPointerToClashedOpponent, String chooseUseText) {
|
||||
super(Outcome.Benefit);
|
||||
this.executingEffect = effect;
|
||||
this.chooseUseText = chooseUseText;
|
||||
this.chooseUseText = chooseUseText;
|
||||
this.setTargetPointerToClashedOpponent = setTargetPointerToClashedOpponent;
|
||||
}
|
||||
|
||||
|
|
@ -52,21 +53,20 @@ public class DoIfClashWonEffect extends OneShotEffect {
|
|||
message = chooseUseText;
|
||||
message = CardUtil.replaceSourceName(message, mageObject.getLogName());
|
||||
}
|
||||
|
||||
|
||||
if (chooseUseText == null || player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
|
||||
if (new ClashEffect().apply(game, source)) {
|
||||
if (setTargetPointerToClashedOpponent) {
|
||||
Object opponent = getValue("clashOpponent");
|
||||
if (opponent instanceof Player) {
|
||||
executingEffect.setTargetPointer(new FixedTarget(((Player)opponent).getId()));
|
||||
}
|
||||
Player opponent = game.getPlayer((UUID) getValue("clashOpponent"));
|
||||
if (opponent != null) {
|
||||
executingEffect.setTargetPointer(new FixedTarget(opponent.getId()));
|
||||
}
|
||||
} else {
|
||||
executingEffect.setTargetPointer(this.targetPointer);
|
||||
}
|
||||
if (executingEffect instanceof OneShotEffect) {
|
||||
return executingEffect.apply(game, source);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
game.addEffect((ContinuousEffect) executingEffect, source);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue