mirror of
https://github.com/correl/mage.git
synced 2024-11-28 19:19:55 +00:00
Fixed missing watchers on game start, added error on missing watcher;
This commit is contained in:
parent
1d8fbb3304
commit
b313ab3b7c
3 changed files with 50 additions and 55 deletions
|
@ -1,14 +1,7 @@
|
||||||
|
|
||||||
package mage.view;
|
package mage.view;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.costs.Cost;
|
import mage.abilities.costs.Cost;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
@ -32,8 +25,10 @@ import mage.players.Player;
|
||||||
import mage.watchers.common.CastSpellLastTurnWatcher;
|
import mage.watchers.common.CastSpellLastTurnWatcher;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class GameView implements Serializable {
|
public class GameView implements Serializable {
|
||||||
|
@ -90,7 +85,7 @@ public class GameView implements Serializable {
|
||||||
if (object != null) {
|
if (object != null) {
|
||||||
if (object instanceof Permanent) {
|
if (object instanceof Permanent) {
|
||||||
boolean controlled = ((Permanent) object).getControllerId().equals(createdForPlayerId);
|
boolean controlled = ((Permanent) object).getControllerId().equals(createdForPlayerId);
|
||||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, ((Permanent) object).getName(), new CardView(((Permanent) object), game, controlled, false, false)));
|
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, object.getName(), new CardView(((Permanent) object), game, controlled, false, false)));
|
||||||
} else {
|
} else {
|
||||||
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, card.getName(), new CardView(card, game, false, false, false)));
|
stack.put(stackObject.getId(), new StackAbilityView(game, (StackAbility) stackObject, card.getName(), new CardView(card, game, false, false, false)));
|
||||||
}
|
}
|
||||||
|
@ -109,14 +104,14 @@ public class GameView implements Serializable {
|
||||||
} else if (object instanceof Emblem) {
|
} else if (object instanceof Emblem) {
|
||||||
CardView cardView = new CardView(new EmblemView((Emblem) object));
|
CardView cardView = new CardView(new EmblemView((Emblem) object));
|
||||||
// Card sourceCard = (Card) ((Emblem) object).getSourceObject();
|
// Card sourceCard = (Card) ((Emblem) object).getSourceObject();
|
||||||
((StackAbility) stackObject).setName(((Emblem) object).getName());
|
stackObject.setName(object.getName());
|
||||||
// ((StackAbility) stackObject).setExpansionSetCode(sourceCard.getExpansionSetCode());
|
// ((StackAbility) stackObject).setExpansionSetCode(sourceCard.getExpansionSetCode());
|
||||||
stack.put(stackObject.getId(),
|
stack.put(stackObject.getId(),
|
||||||
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
|
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
|
||||||
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
||||||
} else if (object instanceof Plane) {
|
} else if (object instanceof Plane) {
|
||||||
CardView cardView = new CardView(new PlaneView((Plane) object));
|
CardView cardView = new CardView(new PlaneView((Plane) object));
|
||||||
((StackAbility) stackObject).setName(((Plane) object).getName());
|
stackObject.setName(object.getName());
|
||||||
stack.put(stackObject.getId(),
|
stack.put(stackObject.getId(),
|
||||||
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
|
new StackAbilityView(game, (StackAbility) stackObject, object.getName(), cardView));
|
||||||
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
||||||
|
@ -131,7 +126,7 @@ public class GameView implements Serializable {
|
||||||
} else if (object instanceof StackAbility) {
|
} else if (object instanceof StackAbility) {
|
||||||
StackAbility stackAbility = ((StackAbility) object);
|
StackAbility stackAbility = ((StackAbility) object);
|
||||||
stackAbility.newId();
|
stackAbility.newId();
|
||||||
stack.put(stackObject.getId(), new CardView(((StackAbility) stackObject)));
|
stack.put(stackObject.getId(), new CardView(stackObject));
|
||||||
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
checkPaid(stackObject.getId(), ((StackAbility) stackObject));
|
||||||
} else {
|
} else {
|
||||||
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
|
LOGGER.fatal("Object can't be cast to StackAbility: " + object.getName() + ' ' + object.toString() + ' ' + object.getClass().toString());
|
||||||
|
@ -182,7 +177,7 @@ public class GameView implements Serializable {
|
||||||
this.special = false;
|
this.special = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
CastSpellLastTurnWatcher watcher = (CastSpellLastTurnWatcher) game.getState().getWatchers().get(CastSpellLastTurnWatcher.class.getSimpleName());
|
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
spellsCastCurrentTurn = watcher.getAmountOfSpellsAllPlayersCastOnCurrentTurn();
|
spellsCastCurrentTurn = watcher.getAmountOfSpellsAllPlayersCastOnCurrentTurn();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,9 +1,5 @@
|
||||||
package mage.game;
|
package mage.game;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.MageObject;
|
import mage.MageObject;
|
||||||
import mage.abilities.*;
|
import mage.abilities.*;
|
||||||
|
@ -65,10 +61,14 @@ import mage.util.GameLog;
|
||||||
import mage.util.MessageToClient;
|
import mage.util.MessageToClient;
|
||||||
import mage.util.RandomUtil;
|
import mage.util.RandomUtil;
|
||||||
import mage.util.functions.ApplyToPermanent;
|
import mage.util.functions.ApplyToPermanent;
|
||||||
import mage.watchers.Watchers;
|
|
||||||
import mage.watchers.common.*;
|
import mage.watchers.common.*;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
public abstract class GameImpl implements Game, Serializable {
|
public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
private static final int ROLLBACK_TURNS_MAX = 4;
|
private static final int ROLLBACK_TURNS_MAX = 4;
|
||||||
|
@ -150,6 +150,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
this.state = new GameState();
|
this.state = new GameState();
|
||||||
this.startLife = startLife;
|
this.startLife = startLife;
|
||||||
this.executingRollback = false;
|
this.executingRollback = false;
|
||||||
|
initGameDefaultWatchers();
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameImpl(final GameImpl game) {
|
public GameImpl(final GameImpl game) {
|
||||||
|
@ -259,6 +260,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
public void addPlayer(Player player, Deck deck) {
|
public void addPlayer(Player player, Deck deck) {
|
||||||
player.useDeck(deck, this);
|
player.useDeck(deck, this);
|
||||||
state.addPlayer(player);
|
state.addPlayer(player);
|
||||||
|
initPlayerDefaultWatchers(player.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1012,20 +1014,6 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
getState().setChoosingPlayerId(null);
|
getState().setChoosingPlayerId(null);
|
||||||
state.resetWatchers(); // watcher objects from cards are reused during match so reset all card watchers already added
|
state.resetWatchers(); // watcher objects from cards are reused during match so reset all card watchers already added
|
||||||
// add default watchers
|
|
||||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
|
||||||
getState().addWatcher(new PlayerDamagedBySourceWatcher(playerId));
|
|
||||||
getState().addWatcher(new BloodthirstWatcher(playerId));
|
|
||||||
}
|
|
||||||
getState().addWatcher(new MorbidWatcher());
|
|
||||||
getState().addWatcher(new CastSpellLastTurnWatcher());
|
|
||||||
getState().addWatcher(new CastSpellYourLastTurnWatcher());
|
|
||||||
getState().addWatcher(new PlayerLostLifeWatcher());
|
|
||||||
getState().addWatcher(new PlayerLostLifeNonCombatWatcher());
|
|
||||||
getState().addWatcher(new BlockedAttackerWatcher());
|
|
||||||
getState().addWatcher(new DamageDoneWatcher());
|
|
||||||
getState().addWatcher(new PlanarRollWatcher());
|
|
||||||
getState().addWatcher(new PlayersAttackedThisTurnWatcher());
|
|
||||||
|
|
||||||
//20100716 - 103.5
|
//20100716 - 103.5
|
||||||
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
|
||||||
|
@ -1074,6 +1062,24 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void initGameDefaultWatchers() {
|
||||||
|
getState().addWatcher(new MorbidWatcher());
|
||||||
|
getState().addWatcher(new CastSpellLastTurnWatcher());
|
||||||
|
getState().addWatcher(new CastSpellYourLastTurnWatcher());
|
||||||
|
getState().addWatcher(new PlayerLostLifeWatcher());
|
||||||
|
getState().addWatcher(new PlayerLostLifeNonCombatWatcher());
|
||||||
|
getState().addWatcher(new BlockedAttackerWatcher());
|
||||||
|
getState().addWatcher(new DamageDoneWatcher());
|
||||||
|
getState().addWatcher(new PlanarRollWatcher());
|
||||||
|
getState().addWatcher(new PlayersAttackedThisTurnWatcher());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initPlayerDefaultWatchers(UUID playerId) {
|
||||||
|
getState().addWatcher(new PlayerDamagedBySourceWatcher(playerId));
|
||||||
|
getState().addWatcher(new BloodthirstWatcher(playerId));
|
||||||
|
}
|
||||||
|
|
||||||
protected void sendStartMessage(Player choosingPlayer, Player startingPlayer) {
|
protected void sendStartMessage(Player choosingPlayer, Player startingPlayer) {
|
||||||
StringBuilder message = new StringBuilder();
|
StringBuilder message = new StringBuilder();
|
||||||
if (choosingPlayer != null) {
|
if (choosingPlayer != null) {
|
||||||
|
@ -1205,7 +1211,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
fireInformEvent(new StringBuilder(player.getLogName())
|
fireInformEvent(new StringBuilder(player.getLogName())
|
||||||
.append(" mulligans")
|
.append(" mulligans")
|
||||||
.append(deduction == 0 ? " for free and draws " : " down to ")
|
.append(deduction == 0 ? " for free and draws " : " down to ")
|
||||||
.append(Integer.toString(numCards - deduction))
|
.append((numCards - deduction))
|
||||||
.append(numCards - deduction == 1 ? " card" : " cards").toString());
|
.append(numCards - deduction == 1 ? " card" : " cards").toString());
|
||||||
player.drawCards(numCards - deduction, this);
|
player.drawCards(numCards - deduction, this);
|
||||||
}
|
}
|
||||||
|
@ -1542,7 +1548,6 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param emblem
|
* @param emblem
|
||||||
* @param sourceObject
|
* @param sourceObject
|
||||||
* @param toPlayerId controller and owner of the emblem
|
* @param toPlayerId controller and owner of the emblem
|
||||||
|
@ -1561,7 +1566,6 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @param plane
|
* @param plane
|
||||||
* @param sourceObject
|
* @param sourceObject
|
||||||
* @param toPlayerId controller and owner of the plane (may only be one per
|
* @param toPlayerId controller and owner of the plane (may only be one per
|
||||||
|
@ -1979,7 +1983,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
if ((ability instanceof SpellAbility)
|
if ((ability instanceof SpellAbility)
|
||||||
&& SpellAbilityType.BASE_ALTERNATE == ((SpellAbility) ability).getSpellAbilityType()
|
&& SpellAbilityType.BASE_ALTERNATE == ((SpellAbility) ability).getSpellAbilityType()
|
||||||
&& !ability.getTargets().isEmpty()) {
|
&& !ability.getTargets().isEmpty()) {
|
||||||
spellAbility = (SpellAbility) ability;
|
spellAbility = ability;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2738,7 +2742,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
if (!game.isSimulation()) {
|
if (!game.isSimulation()) {
|
||||||
StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
|
StringBuilder message = new StringBuilder(preventionSource.getLogName()).append(": Prevented ");
|
||||||
message.append(Integer.toString(result.getPreventedDamage())).append(" damage from ").append(damageSource.getLogName());
|
message.append(result.getPreventedDamage()).append(" damage from ").append(damageSource.getLogName());
|
||||||
if (!targetName.isEmpty()) {
|
if (!targetName.isEmpty()) {
|
||||||
message.append(" to ").append(targetName);
|
message.append(" to ").append(targetName);
|
||||||
}
|
}
|
||||||
|
@ -2773,7 +2777,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
* Gets last known information about object in the zone. At the moment
|
* Gets last known information about object in the zone. At the moment
|
||||||
* doesn't take into account zone (it is expected that it doesn't really
|
* doesn't take into account zone (it is expected that it doesn't really
|
||||||
* matter, if not, then Map<UUID, Map<Zone, Card>> should be used instead).
|
* matter, if not, then Map<UUID, Map<Zone, Card>> should be used instead).
|
||||||
*
|
* <p>
|
||||||
* Can return null.
|
* Can return null.
|
||||||
*
|
*
|
||||||
* @param objectId
|
* @param objectId
|
||||||
|
@ -3128,7 +3132,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
public void saveRollBackGameState() {
|
public void saveRollBackGameState() {
|
||||||
if (gameOptions.rollbackTurnsAllowed) {
|
if (gameOptions.rollbackTurnsAllowed) {
|
||||||
int toDelete = getTurnNum() - ROLLBACK_TURNS_MAX;
|
int toDelete = getTurnNum() - ROLLBACK_TURNS_MAX;
|
||||||
if (toDelete > 0 && gameStatesRollBack.containsKey(toDelete)) {
|
if (toDelete > 0) {
|
||||||
gameStatesRollBack.remove(toDelete);
|
gameStatesRollBack.remove(toDelete);
|
||||||
}
|
}
|
||||||
gameStatesRollBack.put(getTurnNum(), state.copy());
|
gameStatesRollBack.put(getTurnNum(), state.copy());
|
||||||
|
@ -3180,9 +3184,7 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
@Override
|
@Override
|
||||||
public void setEnterWithCounters(UUID sourceId, Counters counters) {
|
public void setEnterWithCounters(UUID sourceId, Counters counters) {
|
||||||
if (counters == null) {
|
if (counters == null) {
|
||||||
if (enterWithCounters.containsKey(sourceId)) {
|
|
||||||
enterWithCounters.remove(sourceId);
|
enterWithCounters.remove(sourceId);
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
enterWithCounters.put(sourceId, counters);
|
enterWithCounters.put(sourceId, counters);
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
package mage.watchers;
|
package mage.watchers;
|
||||||
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
@ -7,7 +6,6 @@ import org.apache.log4j.LogManager;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -50,7 +48,7 @@ public class Watchers extends HashMap<String, Watcher> {
|
||||||
if (containsKey(key)) {
|
if (containsKey(key)) {
|
||||||
return super.get(key);
|
return super.get(key);
|
||||||
}
|
}
|
||||||
logger.info(key + " not found in watchers");
|
logger.error(key + " not found in watchers", new Throwable());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue