[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
public boolean applies(GameEvent event, Ability source, Game game) {
if (!game.getOpponents(game.getControllerId(event.getSourceId())).contains(source.getControllerId())) {
return false;
}
switch (event.getType()) {
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);
case DAMAGE_CREATURE:
case DAMAGE_PLANESWALKER:
isOpponent = game.getOpponents(game.getControllerId(event.getSourceId())).contains(source.getControllerId());
Permanent permanent = game.getPermanent(event.getTargetId());
return permanent != null
return isOpponent
&& permanent != null
&& permanent.isControlledBy(source.getControllerId())
&& super.applies(event, source, game);
}

View file

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