foul-magics/Mage/src/main/java/mage/abilities/effects/common/CopyTokenEffect.java
Evan Kranzler dacf30f4b9
Refactoring subtypes to make Maskwood Nexus work (ready for review) (#7432)
* removed and renamed SubTypeList

* updated subtype test

* refactored Changeling to be an ability that actually does something

* moved isAllCreatureTypes into SubTypes class

* renamed copyTo method to copyFrom

* added removeAllCreatureTypes where usable

* replaced some subtype methods

* replaced some more subtype methods

* replaced subtype mass add/remove methods

* updated more subtype methods

* fixed some errors

* made common shared creature type predicate

* refactored another card involving subtypes

* Added usage of object attribute in subTypes's write operations;

* Refactor: use same param styles in subtype methods

* Refactor: simplified usage of copy appliers;

* Refactor: fixed code usage in CopyApplier

Co-authored-by: Oleg Agafonov <jaydi85@gmail.com>
2021-01-26 08:52:35 -05:00

57 lines
1.9 KiB
Java

package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.constants.*;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.permanent.token.Token;
public class CopyTokenEffect extends ContinuousEffectImpl {
protected Token token;
public CopyTokenEffect(Token token) {
super(Duration.WhileOnBattlefield, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature);
this.token = token.copy();
staticText = "You may have {this} enter the battlefield as a copy of " + token.getDescription() + " on the battlefield";
}
public CopyTokenEffect(final CopyTokenEffect effect) {
super(effect);
this.token = effect.token.copy();
}
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId());
permanent.setName(token.getName());
permanent.getColor(game).setColor(token.getColor(game));
permanent.getCardType().clear();
for (CardType type : token.getCardType()) {
permanent.addCardType(type);
}
permanent.removeAllSubTypes(game);
permanent.copySubTypesFrom(game, token);
permanent.getSuperType().clear();
for (SuperType type : token.getSuperType()) {
permanent.addSuperType(type);
}
permanent.getAbilities().clear();
for (Ability ability : token.getAbilities()) {
permanent.addAbility(ability, source.getSourceId(), game);
}
permanent.getPower().setValue(token.getPower().getValue());
permanent.getToughness().setValue(token.getToughness().getValue());
//permanent.getLoyalty().setValue(card.getLoyalty().getValue());
return true;
}
@Override
public CopyTokenEffect copy() {
return new CopyTokenEffect(this);
}
}