fixed few errors like NPE

This commit is contained in:
Oleg Agafonov 2023-12-15 16:51:12 +04:00
parent d03ebad794
commit 595b0e0070
3 changed files with 10 additions and 9 deletions

View file

@ -103,6 +103,7 @@ class ExtraordinaryJourneyEffect extends OneShotEffect {
if(!effect.apply(game, source)) { if(!effect.apply(game, source)) {
return false; return false;
} }
game.getState().applyEffects(game);
Set<Card> cards = permanents Set<Card> cards = permanents
.stream() .stream()
@ -118,7 +119,6 @@ class ExtraordinaryJourneyEffect extends OneShotEffect {
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// For each of those cards, its owner may play it for as long as it remains exiled.
for (Player owner : owners) { for (Player owner : owners) {
String exileZoneName = "Exile — Can be played by " + owner.getName(); String exileZoneName = "Exile — Can be played by " + owner.getName();
UUID exileZoneId = CardUtil.getExileZoneId( UUID exileZoneId = CardUtil.getExileZoneId(
@ -127,7 +127,6 @@ class ExtraordinaryJourneyEffect extends OneShotEffect {
); );
ExileZone zone = game.getState().getExile().createZone(exileZoneId, exileZoneName); ExileZone zone = game.getState().getExile().createZone(exileZoneId, exileZoneName);
for(Card card : cards) { for(Card card : cards) {
if (card.getOwnerId().equals(owner.getId())) { if (card.getOwnerId().equals(owner.getId())) {
game.getExile().moveToAnotherZone(card, game, zone); game.getExile().moveToAnotherZone(card, game, zone);

View file

@ -49,7 +49,6 @@ public final class ScoutsWarning extends CardImpl {
class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl { class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
private ScoutsWarningWatcher watcher;
private int zoneChangeCounter; private int zoneChangeCounter;
public ScoutsWarningAsThoughEffect() { public ScoutsWarningAsThoughEffect() {
@ -59,13 +58,12 @@ class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
private ScoutsWarningAsThoughEffect(final ScoutsWarningAsThoughEffect effect) { private ScoutsWarningAsThoughEffect(final ScoutsWarningAsThoughEffect effect) {
super(effect); super(effect);
this.watcher = effect.watcher;
this.zoneChangeCounter = effect.zoneChangeCounter; this.zoneChangeCounter = effect.zoneChangeCounter;
} }
@Override @Override
public void init(Ability source, Game game) { public void init(Ability source, Game game) {
watcher = game.getState().getWatcher(ScoutsWarningWatcher.class, source.getControllerId()); ScoutsWarningWatcher watcher = game.getState().getWatcher(ScoutsWarningWatcher.class, source.getControllerId());
Card card = game.getCard(source.getSourceId()); Card card = game.getCard(source.getSourceId());
if (watcher != null && card != null) { if (watcher != null && card != null) {
zoneChangeCounter = card.getZoneChangeCounter(game); zoneChangeCounter = card.getZoneChangeCounter(game);
@ -85,11 +83,12 @@ class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
@Override @Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) { public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (watcher.isScoutsWarningSpellActive(source.getSourceId(), zoneChangeCounter)) { ScoutsWarningWatcher watcher = game.getState().getWatcher(ScoutsWarningWatcher.class, source.getControllerId());
if (watcher != null && watcher.isScoutsWarningSpellActive(source.getSourceId(), zoneChangeCounter)) {
Card card = game.getCard(sourceId); Card card = game.getCard(sourceId);
if (card != null && card.isCreature(game) && source.isControlledBy(affectedControllerId)) { return card != null
return true; && card.isCreature(game)
} && source.isControlledBy(affectedControllerId);
} }
return false; return false;
} }

View file

@ -32,6 +32,9 @@ public class AttachedToMatchesFilterCondition implements Condition {
if (attachedTo == null) { if (attachedTo == null) {
attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD); attachedTo = (Permanent) game.getLastKnownInformation(permanent.getAttachedTo(), Zone.BATTLEFIELD);
} }
if (attachedTo == null) {
return false;
}
if (filter.match(attachedTo, attachedTo.getControllerId(), source, game)) { if (filter.match(attachedTo, attachedTo.getControllerId(), source, game)) {
return true; return true;
} }