forked from External/mage
Fixed protector NPE on empty opponents
This commit is contained in:
parent
c061c7f436
commit
2e8f24edb3
1 changed files with 9 additions and 7 deletions
|
|
@ -1677,20 +1677,22 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
@Override
|
||||
public void chooseProtector(Game game, Ability source) {
|
||||
Set<UUID> opponents = game.getOpponents(this.getControllerId());
|
||||
UUID protectorId;
|
||||
Player newProtector;
|
||||
if (opponents.size() > 1) {
|
||||
TargetPlayer target = new TargetPlayer(new FilterOpponent("protector for " + getName()));
|
||||
target.setNotTarget(true);
|
||||
target.setRequired(true);
|
||||
game.getPlayer(getControllerId()).choose(Outcome.Neutral, target, source, game);
|
||||
protectorId = target.getFirstTarget();
|
||||
newProtector = game.getPlayer(target.getFirstTarget());
|
||||
} else {
|
||||
protectorId = RandomUtil.randomFromCollection(opponents);
|
||||
newProtector = game.getPlayer(opponents.iterator().next());
|
||||
}
|
||||
if (newProtector != null) {
|
||||
String protectorName = newProtector.getLogName();
|
||||
game.informPlayers(protectorName + " has been chosen to protect " + this.getLogName());
|
||||
this.addInfo("protector", "Protected by " + protectorName, game);
|
||||
this.setProtectorId(newProtector.getId());
|
||||
}
|
||||
String protectorName = game.getPlayer(protectorId).getLogName();
|
||||
game.informPlayers(protectorName + " has been chosen to protect " + this.getLogName());
|
||||
this.addInfo("protector", "Protected by " + protectorName, game);
|
||||
this.setProtectorId(protectorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue