mirror of
https://github.com/magefree/mage.git
synced 2025-12-27 05:52:06 -08:00
Fixed some possible exceptions.
This commit is contained in:
parent
a505173854
commit
3d8494edb5
7 changed files with 72 additions and 58 deletions
|
|
@ -25,24 +25,27 @@
|
|||
* authors and should not be interpreted as representing official policies, either expressed
|
||||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.UUID;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.game.stack.StackObject;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
/**
|
||||
* A object reference that takes zone changes into account.
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class MageObjectReference implements Comparable<MageObjectReference>, Serializable {
|
||||
|
||||
private static final transient Logger logger = Logger.getLogger(MageObjectReference.class);
|
||||
|
||||
private final UUID sourceId;
|
||||
private final int zoneChangeCounter;
|
||||
|
||||
|
|
@ -50,20 +53,21 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
this.sourceId = mageObject.getId();
|
||||
this.zoneChangeCounter = mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
|
||||
/**
|
||||
* That values manually (can be used to let it reference to a Permanent
|
||||
* that is not yet on the battlefield.
|
||||
*
|
||||
* That values manually (can be used to let it reference to a Permanent that
|
||||
* is not yet on the battlefield.
|
||||
*
|
||||
* @param sourceId
|
||||
* @param zoneChangeCounter
|
||||
* @param game
|
||||
* @param game
|
||||
*/
|
||||
public MageObjectReference(UUID sourceId, int zoneChangeCounter, Game game) {
|
||||
this.sourceId = sourceId;
|
||||
this.zoneChangeCounter = zoneChangeCounter;
|
||||
}
|
||||
|
||||
public MageObjectReference(UUID sourceId, Game game) {
|
||||
public MageObjectReference(UUID sourceId, Game game) {
|
||||
this.sourceId = sourceId;
|
||||
MageObject mageObject = game.getObject(sourceId);
|
||||
if (mageObject != null) {
|
||||
|
|
@ -72,7 +76,18 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
if (game.getPlayerList().contains(sourceId)) {
|
||||
this.zoneChangeCounter = 0;
|
||||
} else {
|
||||
throw new IllegalArgumentException("The provided sourceId is not connected to an object in the game");
|
||||
logger.error("The provided sourceId is not connected to an object in the game id:" + sourceId);
|
||||
for (StackObject stackObject : game.getStack()) {
|
||||
logger.error("StackObject: " + stackObject.getId() + " sourceId" + stackObject.getSourceId() + " name" + stackObject.getName());
|
||||
}
|
||||
mageObject = game.getLastKnownInformation(sourceId, Zone.STACK);
|
||||
if (mageObject != null) {
|
||||
this.zoneChangeCounter = mageObject.getZoneChangeCounter(game);
|
||||
logger.error("SourceId found in LKI");
|
||||
} else {
|
||||
logger.error("SourceId NOT found in LKI");
|
||||
this.zoneChangeCounter = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -96,8 +111,8 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
@Override
|
||||
public boolean equals(Object v) {
|
||||
if (v instanceof MageObjectReference) {
|
||||
if (((MageObjectReference)v).getSourceId().equals(this.sourceId)) {
|
||||
return ((MageObjectReference)v).getZoneChangeCounter() == this.zoneChangeCounter;
|
||||
if (((MageObjectReference) v).getSourceId().equals(this.sourceId)) {
|
||||
return ((MageObjectReference) v).getZoneChangeCounter() == this.zoneChangeCounter;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
@ -117,7 +132,7 @@ public class MageObjectReference implements Comparable<MageObjectReference>, Ser
|
|||
public boolean refersTo(MageObject mageObject, Game game) {
|
||||
if (mageObject != null) {
|
||||
if (mageObject instanceof Spell) {
|
||||
return ((Spell)mageObject).getSourceId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
return ((Spell) mageObject).getSourceId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
return mageObject.getId().equals(sourceId) && this.zoneChangeCounter == mageObject.getZoneChangeCounter(game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ public enum CardRepository {
|
|||
// raise this if db structure was changed
|
||||
private static final long CARD_DB_VERSION = 41;
|
||||
// raise this if new cards were added to the server
|
||||
private static final long CARD_CONTENT_VERSION = 35;
|
||||
private static final long CARD_CONTENT_VERSION = 36;
|
||||
|
||||
private final Random random = new Random();
|
||||
private Dao<CardInfo, Object> cardDao;
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@ public class LandfallWatcher extends Watcher {
|
|||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
|
||||
Permanent permanent = game.getPermanent(event.getTargetId());
|
||||
if (permanent.getCardType().contains(CardType.LAND) && !playerPlayedLand.contains(event.getPlayerId())) {
|
||||
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||
if (permanent != null && permanent.getCardType().contains(CardType.LAND) && !playerPlayedLand.contains(event.getPlayerId())) {
|
||||
playerPlayedLand.add(event.getPlayerId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue