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

View file

@ -49,7 +49,6 @@ public final class ScoutsWarning extends CardImpl {
class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
private ScoutsWarningWatcher watcher;
private int zoneChangeCounter;
public ScoutsWarningAsThoughEffect() {
@ -59,13 +58,12 @@ class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
private ScoutsWarningAsThoughEffect(final ScoutsWarningAsThoughEffect effect) {
super(effect);
this.watcher = effect.watcher;
this.zoneChangeCounter = effect.zoneChangeCounter;
}
@Override
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());
if (watcher != null && card != null) {
zoneChangeCounter = card.getZoneChangeCounter(game);
@ -85,11 +83,12 @@ class ScoutsWarningAsThoughEffect extends AsThoughEffectImpl {
@Override
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);
if (card != null && card.isCreature(game) && source.isControlledBy(affectedControllerId)) {
return true;
}
return card != null
&& card.isCreature(game)
&& source.isControlledBy(affectedControllerId);
}
return false;
}

View file

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