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) {
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);

View file

@ -302,10 +302,13 @@ 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)) {
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);

View file

@ -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();
}
}

View file

@ -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

View file

@ -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;
}