mirror of
https://github.com/correl/mage.git
synced 2024-11-15 19:19:33 +00:00
other fixes
This commit is contained in:
parent
90c7079bfa
commit
bf9e25fc34
6 changed files with 56 additions and 12 deletions
|
@ -1,6 +1,7 @@
|
|||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.Constants;
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.counters.CounterType;
|
||||
|
@ -23,7 +24,9 @@ public class CountersCount implements DynamicValue {
|
|||
Permanent p = game.getPermanent(sourceAbility.getSourceId());
|
||||
// if permanent already leaves the battlefield, try to find counters count via last known information
|
||||
if (p == null) {
|
||||
p = (Permanent) game.getLastKnownInformation(sourceAbility.getSourceId(), Constants.Zone.BATTLEFIELD);
|
||||
MageObject o = game.getLastKnownInformation(sourceAbility.getSourceId(), Constants.Zone.BATTLEFIELD);
|
||||
if (o instanceof Permanent)
|
||||
p = (Permanent) o;
|
||||
}
|
||||
if (p != null) {
|
||||
return p.getCounters().getCount(counter);
|
||||
|
|
|
@ -202,6 +202,8 @@ public class ContinuousEffects implements Serializable {
|
|||
|
||||
private boolean isInactive(ContinuousEffect effect, Game game) {
|
||||
Ability ability = abilityMap.get(effect.getId());
|
||||
if (ability == null)
|
||||
return true;
|
||||
switch(effect.getDuration()) {
|
||||
case WhileOnBattlefield:
|
||||
if (game.getObject(ability.getSourceId()) == null)
|
||||
|
|
|
@ -229,15 +229,15 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
|
|||
state.setZone(objectId, Zone.BATTLEFIELD);
|
||||
return object;
|
||||
}
|
||||
object = getCard(objectId);
|
||||
if (object != null)
|
||||
return object;
|
||||
for (StackObject item: state.getStack()) {
|
||||
if (item.getId().equals(objectId)) {
|
||||
state.setZone(objectId, Zone.STACK);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
object = getCard(objectId);
|
||||
if (object != null)
|
||||
return object;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -87,10 +87,10 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
public void reset(Game game) {
|
||||
// when the permanent is reset copy all original values from the card
|
||||
// must copy card each reset so that the original values don't get modified
|
||||
copyFromCard(card);
|
||||
copyFromCard(card, game);
|
||||
super.reset(game);
|
||||
}
|
||||
|
||||
|
||||
protected void copyFromCard(Card card) {
|
||||
this.name = card.getName();
|
||||
this.abilities.clear();
|
||||
|
@ -130,6 +130,45 @@ public class PermanentCard extends PermanentImpl<PermanentCard> {
|
|||
}
|
||||
}
|
||||
|
||||
protected void copyFromCard(Card card, Game game) {
|
||||
this.name = card.getName();
|
||||
this.abilities.clear();
|
||||
this.abilities.addAll(card.getAbilities());
|
||||
this.abilities.setControllerId(this.controllerId);
|
||||
this.cardType.clear();
|
||||
this.cardType.addAll(card.getCardType());
|
||||
this.color = card.getColor().copy();
|
||||
this.manaCost = card.getManaCost().copy();
|
||||
this.power = card.getPower().copy();
|
||||
this.toughness = card.getToughness().copy();
|
||||
if (card instanceof LevelerCard) {
|
||||
LevelAbility level = ((LevelerCard) card).getLevel(this.getCounters().getCount(CounterType.LEVEL));
|
||||
if (level != null) {
|
||||
this.power.setValue(level.getPower());
|
||||
this.toughness.setValue(level.getToughness());
|
||||
for (Ability ability : level.getAbilities()) {
|
||||
this.addAbility(ability, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (card instanceof PermanentCard) {
|
||||
this.maxLevelCounters = ((PermanentCard) card).maxLevelCounters;
|
||||
}
|
||||
this.subtype.clear();
|
||||
this.subtype.addAll(card.getSubtype());
|
||||
this.supertype.clear();
|
||||
this.supertype.addAll(card.getSupertype());
|
||||
this.expansionSetCode = card.getExpansionSetCode();
|
||||
this.rarity = card.getRarity();
|
||||
this.cardNumber = card.getCardNumber();
|
||||
|
||||
canTransform = card.canTransform();
|
||||
if (canTransform) {
|
||||
secondSideCard = card.getSecondCardFace();
|
||||
nightCard = card.isNightCard();
|
||||
}
|
||||
}
|
||||
|
||||
// public void checkPermanentOnlyTriggers(ZoneChangeEvent event, Game game) {
|
||||
// // we only want to trigger abilities that are not on the underlying card ie. have been added by another effect
|
||||
// // or we want to trigger abilities that only trigger on leaving the battlefield
|
||||
|
|
|
@ -159,14 +159,15 @@ public abstract class PermanentImpl<T extends PermanentImpl<T>> extends CardImpl
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public void addAbility(Ability ability) {
|
||||
throw new UnsupportedOperationException("Unsupported operation: use addAbility(Ability ability, Game game) instead");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbility(Ability ability, Game game) {
|
||||
Ability copy = ability.copy();
|
||||
if (!abilities.containsKey(copy.getId())) {
|
||||
if (!abilities.containsKey(ability.getId())) {
|
||||
Ability copy = ability.copy();
|
||||
copy.setControllerId(controllerId);
|
||||
copy.setSourceId(objectId);
|
||||
game.getState().addAbility(copy);
|
||||
|
|
|
@ -49,7 +49,6 @@ public class PermanentToken extends PermanentImpl<PermanentToken> {
|
|||
super(controllerId, controllerId, token.getName());
|
||||
this.token = token;
|
||||
this.expansionSetCode = expansionSetCode;
|
||||
copyFromToken(token);
|
||||
}
|
||||
|
||||
public PermanentToken(final PermanentToken permanent) {
|
||||
|
@ -61,15 +60,15 @@ public class PermanentToken extends PermanentImpl<PermanentToken> {
|
|||
@Override
|
||||
public void reset(Game game) {
|
||||
Token copy = token.copy();
|
||||
copyFromToken(copy);
|
||||
copyFromToken(copy, game);
|
||||
super.reset(game);
|
||||
}
|
||||
|
||||
protected void copyFromToken(Token token) {
|
||||
protected void copyFromToken(Token token, Game game) {
|
||||
this.name = token.getName();
|
||||
this.abilities.clear();
|
||||
for (Ability ability: token.getAbilities()) {
|
||||
this.addAbility(ability);
|
||||
this.addAbility(ability, game);
|
||||
}
|
||||
this.cardType = token.getCardType();
|
||||
this.color = token.getColor();
|
||||
|
|
Loading…
Reference in a new issue