mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
fix #8073, Vial Smasher will not target invalid opponents
This commit is contained in:
parent
3bb432a037
commit
b15e97fa6f
1 changed files with 26 additions and 23 deletions
|
@ -20,13 +20,13 @@ import mage.game.permanent.Permanent;
|
|||
import mage.game.stack.Spell;
|
||||
import mage.players.Player;
|
||||
import mage.target.TargetPermanent;
|
||||
import mage.util.RandomUtil;
|
||||
import mage.watchers.common.SpellsCastWatcher;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
@ -123,17 +123,20 @@ class VialSmasherTheFierceEffect extends OneShotEffect {
|
|||
if (controller != null) {
|
||||
int damage = (Integer) getValue("VialSmasherTheFierceCMC");
|
||||
if (damage > 0) {
|
||||
Set<UUID> opponents = game.getOpponents(source.getControllerId());
|
||||
int random = RandomUtil.nextInt(opponents.size());
|
||||
Iterator<UUID> iterator = opponents.iterator();
|
||||
for (int i = 0; i < random; i++) {
|
||||
iterator.next();
|
||||
List<Player> opponents = game.getOpponents(source.getControllerId())
|
||||
.stream()
|
||||
.map(game::getPlayer)
|
||||
.filter(Objects::nonNull)
|
||||
.filter(o -> !o.hasLost())
|
||||
.filter(o -> !o.hasLeft())
|
||||
.collect(Collectors.toList());
|
||||
if(opponents.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
UUID opponentId = iterator.next();
|
||||
Player opponent = game.getPlayer(opponentId);
|
||||
if (opponent != null) {
|
||||
Collections.shuffle(opponents);
|
||||
Player opponent = opponents.get(0);
|
||||
game.informPlayers(opponent.getLogName() + " was chosen at random.");
|
||||
if (game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), opponentId, game).size() > 0) {
|
||||
if (game.getBattlefield().getAllActivePermanents(new FilterPlaneswalkerPermanent(), opponent.getId(), game).size() > 0) {
|
||||
if (controller.chooseUse(Outcome.Damage, "Redirect to a planeswalker controlled by " + opponent.getLogName() + "?", source, game)) {
|
||||
FilterPlaneswalkerPermanent filter = new FilterPlaneswalkerPermanent("a planeswalker controlled by " + opponent.getLogName());
|
||||
filter.add(new ControllerIdPredicate(opponent.getId()));
|
||||
|
@ -147,7 +150,7 @@ class VialSmasherTheFierceEffect extends OneShotEffect {
|
|||
}
|
||||
}
|
||||
opponent.damage(damage, source.getSourceId(), source, game);
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue