add CopiableValues object

This commit is contained in:
theelk801 2023-04-27 19:54:42 -04:00
parent f86cf176d7
commit 6094545343
7 changed files with 100 additions and 6 deletions

View file

@ -4,10 +4,6 @@ import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.CompoundAbility;
import mage.abilities.MageSingleton;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.dynamicvalue.common.DomainValue;
import mage.abilities.dynamicvalue.common.SignInversionDynamicValue;
import mage.abilities.dynamicvalue.common.StaticValue;
import mage.abilities.keyword.ChangelingAbility;
import mage.constants.*;
import mage.filter.Filter;

View file

@ -24,7 +24,6 @@ import mage.game.stack.Spell;
import mage.players.ManaPoolItem;
import mage.players.Player;
import mage.target.common.TargetCardInHand;
import mage.util.CardUtil;
import mage.util.trace.TraceInfo;
import org.apache.log4j.Logger;
@ -1002,6 +1001,10 @@ public class ContinuousEffects implements Serializable {
activeLayerEffects = getLayeredEffects(game, "layer_1");
}
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
permanent.saveCopiableValues(game);
}
layer = filterLayeredEffects(activeLayerEffects, Layer.ControlChangingEffects_2);
// apply control changing effects multiple times if it's needed
// for cases when control over permanents with change control abilities is changed

View file

@ -0,0 +1,78 @@
package mage.game.permanent;
import mage.MageObject;
import mage.abilities.Abilities;
import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.constants.CardType;
import mage.game.Game;
import mage.util.SubTypes;
import java.util.List;
/**
* @author TheElk801
*/
public class CopiableValues extends PermanentImpl {
CopiableValues() {
super(null, null, "");
}
private CopiableValues(final CopiableValues permanent) {
super(permanent);
}
@Override
public MageObject getBasicMageObject(Game game) {
return this;
}
@Override
public CopiableValues copy() {
return new CopiableValues(this);
}
void copyFrom(Permanent permanent, Game game) {
this.name = "" + permanent.getName();
this.manaCost = permanent.getManaCost().copy();
this.color = permanent.getColor(game).copy();
this.cardType.clear();
this.cardType.addAll(permanent.getCardType(game));
this.subtype.copyFrom(permanent.getSubtype(game));
this.supertype.clear();
this.supertype.addAll(permanent.getSuperType());
this.abilities = permanent.getAbilities(game).copy();
this.power = permanent.getPower().copy();
this.toughness = permanent.getToughness().copy();
this.startingLoyalty = permanent.getStartingLoyalty();
this.startingDefense = permanent.getStartingDefense();
this.expansionSetCode = permanent.getExpansionSetCode();
}
@Override
public String getName() {
return name;
}
@Override
public ManaCosts<ManaCost> getManaCost() {
return manaCost;
}
@Override
public List<CardType> getCardType(Game game) {
return cardType;
}
@Override
public SubTypes getSubtype(Game game) {
return subtype;
}
@Override
public Abilities<Ability> getAbilities(Game game) {
return super.getAbilities(null);
}
}

View file

@ -441,4 +441,8 @@ public interface Permanent extends Card, Controllable {
this.getPower().setBoostedValue(this.getToughness().getValue());
this.getToughness().setBoostedValue(power);
}
void saveCopiableValues(Game game);
Permanent getCopiableValues();
}

View file

@ -64,6 +64,7 @@ public class PermanentCard extends PermanentImpl {
startingLoyalty = card.getStartingLoyalty();
startingDefense = card.getStartingDefense();
copyFromCard(card, game);
saveCopiableValues(game);
// if temporary added abilities to the spell/card exist, you need to add it to the permanent derived from that card
Abilities<Ability> otherAbilities = game.getState().getAllOtherAbilities(card.getId());
if (otherAbilities != null) {

View file

@ -37,7 +37,6 @@ import mage.players.Player;
import mage.target.TargetPlayer;
import mage.util.CardUtil;
import mage.util.GameLog;
import mage.util.RandomUtil;
import mage.util.ThreadLocalStringBuilder;
import org.apache.log4j.Logger;
@ -110,6 +109,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
protected Map<String, String> info;
protected int createOrder;
protected boolean legendRuleApplies = true;
private final CopiableValues copiableValues = new CopiableValues();
private static final List<UUID> emptyList = Collections.unmodifiableList(new ArrayList<UUID>());
@ -182,6 +182,7 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.morphed = permanent.morphed;
this.manifested = permanent.manifested;
this.createOrder = permanent.createOrder;
this.copiableValues.copyFrom(permanent.copiableValues, null);
}
@Override
@ -223,6 +224,16 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
this.legendRuleApplies = true;
}
@Override
public void saveCopiableValues(Game game) {
this.copiableValues.copyFrom(this, game);
}
@Override
public Permanent getCopiableValues() {
return copiableValues;
}
@Override
public String getName() {
if (name.isEmpty()) {

View file

@ -29,6 +29,7 @@ public class PermanentToken extends PermanentImpl {
this.power = new MageInt(token.getPower().getModifiedBaseValue());
this.toughness = new MageInt(token.getToughness().getModifiedBaseValue());
this.copyFromToken(this.token, game, false); // needed to have at this time (e.g. for subtypes for entersTheBattlefield replacement effects)
this.saveCopiableValues(game);
if (this.token.isEntersTransformed()) {
TransformAbility.transformPermanent(this, this.token.getBackFace(), game, null);
}