mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
fix to NPE from players leaving game.
Trigger handler should check all non-active players
This commit is contained in:
@@ -39,6 +39,7 @@ import forge.card.spellability.SpellAbility;
|
|||||||
import forge.card.spellability.SpellAbilityRestriction;
|
import forge.card.spellability.SpellAbilityRestriction;
|
||||||
import forge.card.spellability.Target;
|
import forge.card.spellability.Target;
|
||||||
import forge.control.input.Input;
|
import forge.control.input.Input;
|
||||||
|
import forge.game.GameState;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
//import forge.util.TextUtil;
|
//import forge.util.TextUtil;
|
||||||
import forge.game.player.ComputerUtil;
|
import forge.game.player.ComputerUtil;
|
||||||
@@ -270,8 +271,9 @@ public class TriggerHandler {
|
|||||||
if (this.suppressedModes.contains(mode)) {
|
if (this.suppressedModes.contains(mode)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
final GameState game = Singletons.getModel().getGame();
|
||||||
|
|
||||||
final Player playerAP = Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn();
|
final Player playerAP = game.getPhaseHandler().getPlayerTurn();
|
||||||
if (playerAP == null) {
|
if (playerAP == null) {
|
||||||
// This should only happen outside of games, so it's safe to just
|
// This should only happen outside of games, so it's safe to just
|
||||||
// abort.
|
// abort.
|
||||||
@@ -285,8 +287,8 @@ public class TriggerHandler {
|
|||||||
// This is done to allow the list of triggers to be modified while
|
// This is done to allow the list of triggers to be modified while
|
||||||
// triggers are running.
|
// triggers are running.
|
||||||
final ArrayList<Trigger> delayedTriggersWorkingCopy = new ArrayList<Trigger>(this.delayedTriggers);
|
final ArrayList<Trigger> delayedTriggersWorkingCopy = new ArrayList<Trigger>(this.delayedTriggers);
|
||||||
List<Card> allCards = Singletons.getModel().getGame().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
List<Card> allCards = game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
||||||
allCards.addAll(Singletons.getModel().getGame().getCardsIn(ZoneType.Stack));
|
allCards.addAll(game.getCardsIn(ZoneType.Stack));
|
||||||
boolean checkStatics = false;
|
boolean checkStatics = false;
|
||||||
|
|
||||||
// Static triggers
|
// Static triggers
|
||||||
@@ -301,23 +303,23 @@ public class TriggerHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (checkStatics) {
|
if (checkStatics) {
|
||||||
Singletons.getModel().getGame().getAction().checkStaticAbilities();
|
game.getAction().checkStaticAbilities();
|
||||||
} else if (runParams.containsKey("Destination")){
|
} else if (runParams.containsKey("Destination")){
|
||||||
// Check static abilities when a card enters the battlefield
|
// Check static abilities when a card enters the battlefield
|
||||||
String type = (String) runParams.get("Destination");
|
String type = (String) runParams.get("Destination");
|
||||||
if (type.equals("Battlefield")) {
|
if (type.equals("Battlefield")) {
|
||||||
Singletons.getModel().getGame().getAction().checkStaticAbilities();
|
game.getAction().checkStaticAbilities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AP
|
// AP
|
||||||
allCards = playerAP.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
allCards = playerAP.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
||||||
allCards.addAll(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsIn(ZoneType.Stack), playerAP));
|
allCards.addAll(CardLists.filterControlledBy(game.getCardsIn(ZoneType.Stack), playerAP));
|
||||||
// add cards that move to hidden zones
|
// add cards that move to hidden zones
|
||||||
if (runParams.containsKey("Destination") && runParams.containsKey("Card")) {
|
if (runParams.containsKey("Destination") && runParams.containsKey("Card")) {
|
||||||
Card card = (Card) runParams.get("Card");
|
Card card = (Card) runParams.get("Card");
|
||||||
if (playerAP.equals(card.getController()) && !allCards.contains(card)
|
if (playerAP.equals(card.getController()) && !allCards.contains(card)
|
||||||
&& (Singletons.getModel().getGame().getZoneOf(card) == null || Singletons.getModel().getGame().getZoneOf(card).getZoneType().isHidden())) {
|
&& (game.getZoneOf(card) == null || game.getZoneOf(card).getZoneType().isHidden())) {
|
||||||
allCards.add(card);
|
allCards.add(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -336,14 +338,19 @@ public class TriggerHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NAP
|
// NAPs
|
||||||
allCards = playerAP.getOpponent().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
|
||||||
allCards.addAll(CardLists.filterControlledBy(Singletons.getModel().getGame().getCardsIn(ZoneType.Stack), playerAP.getOpponent()));
|
for(Player nap: game.getPlayers() )
|
||||||
|
{
|
||||||
|
if ( nap.equals(playerAP) ) continue;
|
||||||
|
|
||||||
|
allCards = nap.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES);
|
||||||
|
allCards.addAll(CardLists.filterControlledBy(game.getCardsIn(ZoneType.Stack), nap));
|
||||||
// add cards that move to hidden zones
|
// add cards that move to hidden zones
|
||||||
if (runParams.containsKey("Destination") && runParams.containsKey("Card")) {
|
if (runParams.containsKey("Destination") && runParams.containsKey("Card")) {
|
||||||
Card card = (Card) runParams.get("Card");
|
Card card = (Card) runParams.get("Card");
|
||||||
if (!playerAP.equals(card.getController()) && !allCards.contains(card)
|
if (!playerAP.equals(card.getController()) && !allCards.contains(card)
|
||||||
&& (Singletons.getModel().getGame().getZoneOf(card) == null || Singletons.getModel().getGame().getZoneOf(card).getZoneType().isHidden())) {
|
&& (game.getZoneOf(card) == null || game.getZoneOf(card).getZoneType().isHidden())) {
|
||||||
allCards.add(card);
|
allCards.add(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -355,13 +362,14 @@ public class TriggerHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (Trigger deltrig : delayedTriggersWorkingCopy) {
|
for (Trigger deltrig : delayedTriggersWorkingCopy) {
|
||||||
if (deltrig.getHostCard().getController().equals(playerAP.getOpponent())) {
|
if (deltrig.getHostCard().getController().equals(nap)) {
|
||||||
if (this.runSingleTrigger(deltrig, mode, runParams)) {
|
if (this.runSingleTrigger(deltrig, mode, runParams)) {
|
||||||
this.delayedTriggers.remove(deltrig);
|
this.delayedTriggers.remove(deltrig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Checks if the conditions are right for a single trigger to go off, and
|
// Checks if the conditions are right for a single trigger to go off, and
|
||||||
// runs it if so.
|
// runs it if so.
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class MatchController {
|
|||||||
if ( !game.isGameOver() )
|
if ( !game.isGameOver() )
|
||||||
throw new RuntimeException("Game is not over yet.");
|
throw new RuntimeException("Game is not over yet.");
|
||||||
|
|
||||||
GameOutcome result = new GameOutcome(reason, game.getPlayers());
|
GameOutcome result = new GameOutcome(reason, game.getRegisteredPlayers());
|
||||||
result.setTurnsPlayed(game.getPhaseHandler().getTurn());
|
result.setTurnsPlayed(game.getPhaseHandler().getTurn());
|
||||||
gamesPlayed.add(result);
|
gamesPlayed.add(result);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user