diff --git a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java index 4c462dbbeb4..311fa30f694 100644 --- a/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AI/src/main/java/mage/player/ai/ComputerPlayer.java @@ -1380,8 +1380,10 @@ public class ComputerPlayer extends PlayerImpl implements Player { for (Mana avail : available) { if (mana.enough(avail)) { SpellAbility ability = card.getSpellAbility(); + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability, playerId); + castEvent.setZone(game.getState().getZone(card.getMainCard().getId())); if (ability != null && ability.canActivate(playerId, game).canActivate() - && !game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), ability, playerId), ability, game, true)) { + && !game.getContinuousEffects().preventedByRuleModification(castEvent, ability, game, true)) { if (card.isInstant(game) || card.hasAbility(FlashAbility.getInstance(), game)) { playableInstant.add(card); diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 6816176332a..dceaba8b20a 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -302,9 +302,12 @@ public abstract class AbilityImpl implements Ability { String announceString = handleOtherXCosts(game, controller); // For effects from cards like Void Winnower x costs have to be set - if (this.getAbilityType() == AbilityType.SPELL - && game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, this.getId(), this, getControllerId()), this)) { - return false; + if (this.getAbilityType() == AbilityType.SPELL) { + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, this.getId(), this, getControllerId()); + castEvent.setZone(game.getState().getZone(CardUtil.getMainCardId(game, sourceId))); + if (game.replaceEvent(castEvent, this)) { + return false; + } } handlePhyrexianManaCosts(game, controller); diff --git a/Mage/src/main/java/mage/abilities/SpellAbility.java b/Mage/src/main/java/mage/abilities/SpellAbility.java index 4ab4c6cecf9..53db5121fc1 100644 --- a/Mage/src/main/java/mage/abilities/SpellAbility.java +++ b/Mage/src/main/java/mage/abilities/SpellAbility.java @@ -108,8 +108,11 @@ public class SpellAbility extends ActivatedAbilityImpl { // play restrict // Check if rule modifying events prevent to cast the spell in check playable mode if (game.inCheckPlayableState()) { + Card card = game.getCard(sourceId); + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this, playerId); + castEvent.setZone(card == null ? null : game.getState().getZone(card.getMainCard().getId())); if (game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this, playerId), this, game, true)) { + castEvent, this, game, true)) { return ActivationStatus.getFalse(); } } diff --git a/Mage/src/main/java/mage/game/events/GameEvent.java b/Mage/src/main/java/mage/game/events/GameEvent.java index 2c2554fe738..704d001fa14 100644 --- a/Mage/src/main/java/mage/game/events/GameEvent.java +++ b/Mage/src/main/java/mage/game/events/GameEvent.java @@ -156,10 +156,16 @@ public class GameEvent implements Serializable { amount X multiplier to change X value, default 1 */ CAST_SPELL, - /* SPELL_CAST - x-Costs are already defined - */ CAST_SPELL_LATE, + /* SPELL_CAST, CAST_SPELL_LATE + targetId id of the spell that's try to cast + sourceId sourceId of the spell that's try to cast + playerId player that try to cast the spell + amount not used for this event + flag not used for this event + zone zone the spell is cast from (main card) + */ + SPELL_CAST, /* SPELL_CAST targetId id of the spell that's cast sourceId sourceId of the spell that's cast @@ -168,7 +174,6 @@ public class GameEvent implements Serializable { flag not used for this event zone zone the spell is cast from */ - SPELL_CAST, ACTIVATE_ABILITY, ACTIVATED_ABILITY, /* ACTIVATE_ABILITY, ACTIVATED_ABILITY, targetId id of the ability to activate / use diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 8cb50fc1b39..9797958726f 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -1169,11 +1169,13 @@ public abstract class PlayerImpl implements Player, Serializable { } Card card = game.getCard(ability.getSourceId()); if (card != null) { - if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, - ability.getId(), ability, playerId, approvingObject), ability)) { + Zone fromZone = game.getState().getZone(card.getMainCard().getId()); + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, + ability.getId(), ability, playerId, approvingObject); + castEvent.setZone(fromZone); + if (!game.replaceEvent(castEvent, ability)) { int bookmark = game.bookmarkState(); setStoredBookmark(bookmark); // move global bookmark to current state (if you activated mana before then you can't rollback it) - Zone fromZone = game.getState().getZone(card.getMainCard().getId()); card.cast(game, fromZone, ability, playerId); Spell spell = game.getStack().getSpell(ability.getId()); if (spell == null) { @@ -1207,15 +1209,15 @@ public abstract class PlayerImpl implements Player, Serializable { } clearCastSourceIdManaCosts(); // TODO: test multiple alternative cost for different cards as same time - GameEvent event = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, + castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject); - event.setZone(fromZone); // why wasn't this set before?? - game.fireEvent(event); + castEvent.setZone(fromZone); + game.fireEvent(castEvent); if (spell.activate(game, noMana)) { - event = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, + GameEvent castedEvent = GameEvent.getEvent(GameEvent.EventType.SPELL_CAST, spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject); - event.setZone(fromZone); - game.fireEvent(event); + castedEvent.setZone(fromZone); + game.fireEvent(castedEvent); if (!game.isSimulation()) { game.informPlayers(getLogName() + spell.getActivatedMessage(game)); } @@ -3776,15 +3778,18 @@ public abstract class PlayerImpl implements Player, Serializable { continue; } // cast spell restrictions 1 + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getId(), ability, this.getId()); + castEvent.setZone(fromZone); if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), - ability, this.getId()), ability, game, true)) { + castEvent, ability, game, true)) { continue; } // cast spell restrictions 2 + GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, + ability.getId(), ability, this.getId()); + castLateEvent.setZone(fromZone); if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, ability.getSourceId(), - ability, this.getId()), ability, game, true)) { + castLateEvent, ability, game, true)) { continue; } @@ -3880,15 +3885,19 @@ public abstract class PlayerImpl implements Player, Serializable { continue; } // cast spell restrictions 1 + GameEvent castEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, + ability.getId(), ability, this.getId()); + castEvent.setZone(fromZone); if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), - ability, this.getId()), ability, game, true)) { + castEvent, ability, game, true)) { continue; } // cast spell restrictions 2 + GameEvent castLateEvent = GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, + ability.getId(), ability, this.getId()); + castLateEvent.setZone(fromZone); if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification( - GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, ability.getSourceId(), - ability, this.getId()), ability, game, true)) { + castLateEvent, ability, game, true)) { continue; }