Fixed wrong targetId in CAST_SPELL, fixed miss code from 7b7bbcadd69dd717d980e1981031cb29d7c7b891;

This commit is contained in:
Oleg Agafonov 2021-09-04 03:01:20 +04:00
parent a0e046bf70
commit 261f32d9b9
5 changed files with 48 additions and 26 deletions

View file

@ -1380,8 +1380,10 @@ public class ComputerPlayer extends PlayerImpl implements Player {
for (Mana avail : available) { for (Mana avail : available) {
if (mana.enough(avail)) { if (mana.enough(avail)) {
SpellAbility ability = card.getSpellAbility(); 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() 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) if (card.isInstant(game)
|| card.hasAbility(FlashAbility.getInstance(), game)) { || card.hasAbility(FlashAbility.getInstance(), game)) {
playableInstant.add(card); playableInstant.add(card);

View file

@ -302,10 +302,13 @@ public abstract class AbilityImpl implements Ability {
String announceString = handleOtherXCosts(game, controller); String announceString = handleOtherXCosts(game, controller);
// For effects from cards like Void Winnower x costs have to be set // For effects from cards like Void Winnower x costs have to be set
if (this.getAbilityType() == AbilityType.SPELL if (this.getAbilityType() == AbilityType.SPELL) {
&& game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, this.getId(), this, getControllerId()), this)) { 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; return false;
} }
}
handlePhyrexianManaCosts(game, controller); handlePhyrexianManaCosts(game, controller);

View file

@ -108,8 +108,11 @@ public class SpellAbility extends ActivatedAbilityImpl {
// play restrict // play restrict
// Check if rule modifying events prevent to cast the spell in check playable mode // Check if rule modifying events prevent to cast the spell in check playable mode
if (game.inCheckPlayableState()) { 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( if (game.getContinuousEffects().preventedByRuleModification(
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, this.getId(), this, playerId), this, game, true)) { castEvent, this, game, true)) {
return ActivationStatus.getFalse(); return ActivationStatus.getFalse();
} }
} }

View file

@ -156,10 +156,16 @@ public class GameEvent implements Serializable {
amount X multiplier to change X value, default 1 amount X multiplier to change X value, default 1
*/ */
CAST_SPELL, CAST_SPELL,
/* SPELL_CAST
x-Costs are already defined
*/
CAST_SPELL_LATE, 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 /* SPELL_CAST
targetId id of the spell that's cast targetId id of the spell that's cast
sourceId sourceId 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 flag not used for this event
zone zone the spell is cast from zone zone the spell is cast from
*/ */
SPELL_CAST,
ACTIVATE_ABILITY, ACTIVATED_ABILITY, ACTIVATE_ABILITY, ACTIVATED_ABILITY,
/* ACTIVATE_ABILITY, ACTIVATED_ABILITY, /* ACTIVATE_ABILITY, ACTIVATED_ABILITY,
targetId id of the ability to activate / use targetId id of the ability to activate / use

View file

@ -1169,11 +1169,13 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
Card card = game.getCard(ability.getSourceId()); Card card = game.getCard(ability.getSourceId());
if (card != null) { if (card != null) {
if (!game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, Zone fromZone = game.getState().getZone(card.getMainCard().getId());
ability.getId(), ability, playerId, approvingObject), ability)) { 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(); int bookmark = game.bookmarkState();
setStoredBookmark(bookmark); // move global bookmark to current state (if you activated mana before then you can't rollback it) 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); card.cast(game, fromZone, ability, playerId);
Spell spell = game.getStack().getSpell(ability.getId()); Spell spell = game.getStack().getSpell(ability.getId());
if (spell == null) { 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 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); spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
event.setZone(fromZone); // why wasn't this set before?? castEvent.setZone(fromZone);
game.fireEvent(event); game.fireEvent(castEvent);
if (spell.activate(game, noMana)) { 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); spell.getSpellAbility().getId(), spell.getSpellAbility(), playerId, approvingObject);
event.setZone(fromZone); castedEvent.setZone(fromZone);
game.fireEvent(event); game.fireEvent(castedEvent);
if (!game.isSimulation()) { if (!game.isSimulation()) {
game.informPlayers(getLogName() + spell.getActivatedMessage(game)); game.informPlayers(getLogName() + spell.getActivatedMessage(game));
} }
@ -3776,15 +3778,18 @@ public abstract class PlayerImpl implements Player, Serializable {
continue; continue;
} }
// cast spell restrictions 1 // 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( if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), castEvent, ability, game, true)) {
ability, this.getId()), ability, game, true)) {
continue; continue;
} }
// cast spell restrictions 2 // 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( if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, ability.getSourceId(), castLateEvent, ability, game, true)) {
ability, this.getId()), ability, game, true)) {
continue; continue;
} }
@ -3880,15 +3885,19 @@ public abstract class PlayerImpl implements Player, Serializable {
continue; continue;
} }
// cast spell restrictions 1 // 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( if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL, ability.getSourceId(), castEvent, ability, game, true)) {
ability, this.getId()), ability, game, true)) {
continue; continue;
} }
// cast spell restrictions 2 // 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( if (isPlaySpell && game.getContinuousEffects().preventedByRuleModification(
GameEvent.getEvent(GameEvent.EventType.CAST_SPELL_LATE, ability.getSourceId(), castLateEvent, ability, game, true)) {
ability, this.getId()), ability, game, true)) {
continue; continue;
} }