Fixed NPE and triggered abilities not working for tokens.

This commit is contained in:
magenoxx 2011-07-30 10:52:41 +04:00
parent ccca6db6a9
commit ff32c1698b
3 changed files with 37 additions and 5 deletions

View file

@ -33,6 +33,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.MageObject;
import mage.ObjectColor; import mage.ObjectColor;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Rarity; import mage.Constants.Rarity;
@ -116,6 +117,32 @@ public class CardView implements Serializable {
} }
} }
public CardView(MageObject card) {
this.id = card.getId();
this.name = card.getName();
if (card instanceof Permanent) {
this.power = Integer.toString(card.getPower().getValue());
this.toughness = Integer.toString(card.getToughness().getValue());
this.loyalty = Integer.toString(((Permanent) card).getCounters().getCount(CounterType.LOYALTY));
} else {
this.power = card.getPower().toString();
this.toughness = card.getToughness().toString();
this.loyalty = "";
}
this.cardTypes = card.getCardType();
this.subTypes = card.getSubtype();
this.superTypes = card.getSupertype();
this.color = card.getColor();
this.manaCost = card.getManaCost().getSymbols();
this.convertedManaCost = card.getManaCost().convertedManaCost();
if (card instanceof PermanentToken) {
this.rarity = Rarity.COMMON;
this.expansionSetCode = ((PermanentToken)card).getExpansionSetCode();
this.rules = ((PermanentToken)card).getRules();
}
}
protected CardView() { protected CardView() {
} }

View file

@ -76,10 +76,14 @@ public class GameView implements Serializable {
if (stackObject instanceof StackAbility) { if (stackObject instanceof StackAbility) {
MageObject object = game.getObject(stackObject.getSourceId()); MageObject object = game.getObject(stackObject.getSourceId());
Card card = game.getCard(stackObject.getSourceId()); Card card = game.getCard(stackObject.getSourceId());
if (object != null) if (card != null) {
stack.put(stackObject.getId(), new StackAbilityView((StackAbility)stackObject, object.getName(), new CardView(card))); if (object != null)
else stack.put(stackObject.getId(), new StackAbilityView((StackAbility)stackObject, object.getName(), new CardView(card)));
stack.put(stackObject.getId(), new StackAbilityView((StackAbility)stackObject, "", new CardView(card))); else
stack.put(stackObject.getId(), new StackAbilityView((StackAbility)stackObject, "", new CardView(card)));
} else if (object != null) {
stack.put(stackObject.getId(), new CardView(object));
}
} }
else { else {
stack.put(stackObject.getId(), new CardView((Spell)stackObject)); stack.put(stackObject.getId(), new CardView((Spell)stackObject));

View file

@ -164,7 +164,8 @@ public abstract class AbilityImpl<T extends AbilityImpl<T>> implements Ability {
//20100716 - 601.2e //20100716 - 601.2e
if (game.getObject(sourceId) != null) { if (game.getObject(sourceId) != null) {
//game.getObject(sourceId).adjustCosts(this, game); //game.getObject(sourceId).adjustCosts(this, game);
game.getCard(sourceId).adjustCosts(this, game); if (game.getCard(sourceId) != null)
game.getCard(sourceId).adjustCosts(this, game);
} }
if (!useAlternativeCost(game)) { if (!useAlternativeCost(game)) {