[KHM] fixed Reidane, God of the Worthy - rollback error on some events check without sourceId;

This commit is contained in:
Oleg Agafonov 2021-02-06 13:04:20 +04:00
parent f692a1f097
commit 9416c6140a
2 changed files with 10 additions and 5 deletions

View file

@ -169,17 +169,18 @@ class ValkmiraProtectorsShieldPreventionEffect extends PreventionEffectImpl {
@Override @Override
public boolean applies(GameEvent event, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
if (!game.getOpponents(game.getControllerId(event.getSourceId())).contains(source.getControllerId())) {
return false;
}
switch (event.getType()) { switch (event.getType()) {
case DAMAGE_PLAYER: case DAMAGE_PLAYER:
return source.isControlledBy(event.getTargetId()) boolean isOpponent = game.getOpponents(game.getControllerId(event.getSourceId())).contains(source.getControllerId());
return isOpponent
&& source.isControlledBy(event.getTargetId())
&& super.applies(event, source, game); && super.applies(event, source, game);
case DAMAGE_CREATURE: case DAMAGE_CREATURE:
case DAMAGE_PLANESWALKER: case DAMAGE_PLANESWALKER:
isOpponent = game.getOpponents(game.getControllerId(event.getSourceId())).contains(source.getControllerId());
Permanent permanent = game.getPermanent(event.getTargetId()); Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null return isOpponent
&& permanent != null
&& permanent.isControlledBy(source.getControllerId()) && permanent.isControlledBy(source.getControllerId())
&& super.applies(event, source, game); && super.applies(event, source, game);
} }

View file

@ -135,6 +135,10 @@ public interface Game extends MageItem, Serializable {
*/ */
default Set<UUID> getOpponents(UUID playerId) { default Set<UUID> getOpponents(UUID playerId) {
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
if (player == null) {
return new HashSet<>();
}
return player.getInRange().stream() return player.getInRange().stream()
.filter(opponentId -> !opponentId.equals(playerId)) .filter(opponentId -> !opponentId.equals(playerId))
.collect(Collectors.toSet()); .collect(Collectors.toSet());