add method Game.isActivePlayer(UUID playerId)

This commit is contained in:
igoudt 2018-06-29 14:59:11 +02:00
parent 2b78716a1b
commit ca1ebeb55e
16 changed files with 33 additions and 31 deletions

View file

@ -31,7 +31,7 @@ public class PlayLandAbility extends ActivatedAbilityImpl {
return ActivationStatus.getFalse();
}
//20091005 - 114.2a
return new ActivationStatus(game.getActivePlayerId().equals(playerId) && game.getPlayer(playerId).canPlayLand() && game.canPlaySorcery(playerId), permittingObject);
return new ActivationStatus(game.isActivePlayer(playerId) && game.getPlayer(playerId).canPlayLand() && game.canPlaySorcery(playerId), permittingObject);
}
@Override

View file

@ -51,7 +51,7 @@ public class HideawayPlayEffect extends OneShotEffect {
*/
if (card.isLand()) {
UUID playerId = controller.getId();
if (!game.getActivePlayerId().equals(playerId) || !game.getPlayer(playerId).canPlayLand()) {
if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
return false;
}
}

View file

@ -154,7 +154,7 @@ public class ManaOptions extends ArrayList<Mana> {
}
}
}
} else if (abilities.size() > 1) {
} else {
//perform a union of all existing options and the new options
List<Mana> copy = copy();
this.clear();
@ -227,7 +227,7 @@ public class ManaOptions extends ArrayList<Mana> {
if (options.size() == 1) {
//if there is only one mana option available add it to all the existing options
addMana(options.get(0));
} else if (options.size() > 1) {
} else {
//perform a union of all existing options and the new options
List<Mana> copy = copy();
this.clear();

View file

@ -3,6 +3,8 @@ package mage.game;
import java.io.Serializable;
import java.util.*;
import java.util.stream.Collectors;
import mage.MageItem;
import mage.MageObject;
import mage.abilities.Ability;
@ -119,15 +121,17 @@ public interface Game extends MageItem, Serializable {
* @param playerId
* @return
*/
default public Set<UUID> getOpponents(UUID playerId) {
Set<UUID> opponents = new HashSet<>();
default Set<UUID> getOpponents(UUID playerId) {
Player player = getPlayer(playerId);
for (UUID opponentId : player.getInRange()) {
if (!opponentId.equals(playerId)) {
opponents.add(opponentId);
}
}
return opponents;
return player.getInRange().stream()
.filter(opponentId -> !opponentId.equals(playerId))
.collect(Collectors.toSet());
}
default boolean isActivePlayer(UUID playerId){
return getActivePlayerId().equals(playerId);
}
/**
@ -141,7 +145,7 @@ public interface Game extends MageItem, Serializable {
* @param playerToCheckId
* @return
*/
default public boolean isOpponent(Player player, UUID playerToCheckId) {
default boolean isOpponent(Player player, UUID playerToCheckId) {
return !player.getId().equals(playerToCheckId);
}

View file

@ -2450,7 +2450,7 @@ public abstract class GameImpl implements Game, Serializable {
@Override
public boolean canPlaySorcery(UUID playerId) {
return isMainPhase() && getActivePlayerId().equals(playerId) && getStack().isEmpty();
return isMainPhase() && isActivePlayer(playerId) && getStack().isEmpty();
}
/**
@ -2594,7 +2594,7 @@ public abstract class GameImpl implements Game, Serializable {
// If the current monarch leaves the game. When that happens, the player whose turn it is becomes the monarch.
// If the monarch leaves the game on their turn, the next player in turn order becomes the monarch.
if (playerId.equals(getMonarchId())) {
if (!getActivePlayerId().equals(playerId)) {
if (!isActivePlayer(playerId)) {
setMonarchId(null, getActivePlayerId());
} else {
Player nextPlayer = getPlayerList().getNext(this);

View file

@ -2956,9 +2956,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// Other activated abilities
LinkedHashMap<UUID, ActivatedAbility> useable = new LinkedHashMap<>();
getOtherUseableActivatedAbilities(card, Zone.GRAVEYARD, game, useable);
for (Ability ability : useable.values()) {
playable.add(ability);
}
playable.addAll(useable.values());
}
for (ExileZone exile : game.getExile().getExileZones()) {
for (Card card : exile.getCards(game)) {

View file

@ -76,7 +76,7 @@ public class PermanentsEnteredBattlefieldYourLastTurnWatcher extends Watcher {
}
public List<Permanent> getPermanentsEnteringOnPlayersLastTurn(Game game, UUID playerId) {
if (game.getActivePlayerId().equals(playerId)) {
if (game.isActivePlayer(playerId)) {
return enteringBattlefield.get(playerId);
}
return enteringBattlefieldLastTurn.get(playerId);