use of mage.util.functions.CopyApplier in project mage by magefree.
the class WallOfStolenIdentityCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanentEntering(source.getSourceId());
}
final Permanent sourcePermanent = permanent;
if (controller == null || sourcePermanent == null) {
return false;
}
Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
target.setRequired(true);
if (source instanceof SimpleStaticAbility) {
target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
target.setRequired(false);
target.setNotTarget(true);
}
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent == null) {
return false;
}
game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.addSubType(SubType.WALL);
blueprint.getAbilities().add(DefenderAbility.getInstance());
return true;
}
});
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new TapTargetEffect(), false, "tap the copied creature " + "and it doesn't untap during its controller's untap step for as long as you control {this}");
ability.addEffect(new DontUntapInControllersUntapStepTargetEffect(Duration.WhileControlled));
ability.getEffects().setTargetPointer(new FixedTarget(copyFromPermanent, game));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.util.functions.CopyApplier in project mage by magefree.
the class VesuvanDoppelgangerCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null) {
permanent = game.getPermanentEntering(source.getSourceId());
}
final Permanent sourcePermanent = permanent;
if (controller != null && sourcePermanent != null) {
Target target = new TargetPermanent(new FilterCreaturePermanent("target creature (you copy from)"));
target.setRequired(true);
if (source instanceof SimpleStaticAbility) {
target = new TargetPermanent(new FilterCreaturePermanent("creature (you copy from)"));
target.setRequired(false);
target.setNotTarget(true);
}
if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
Permanent copyFromPermanent = game.getPermanent(target.getFirstTarget());
if (copyFromPermanent != null) {
game.copyPermanent(copyFromPermanent, sourcePermanent.getId(), source, new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
blueprint.getColor().setColor(sourcePermanent.getColor(game));
blueprint.getAbilities().add(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new VesuvanDoppelgangerCopyEffect(), TargetController.YOU, true, false, rule2));
return true;
}
});
return true;
}
}
}
return false;
}
use of mage.util.functions.CopyApplier in project mage by magefree.
the class CreateTokenCopyTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId;
if (getTargetPointer() instanceof FixedTarget) {
targetId = ((FixedTarget) getTargetPointer()).getTarget();
} else {
targetId = getTargetPointer().getFirst(game, source);
}
Permanent permanent;
if (savedPermanent != null) {
permanent = savedPermanent;
} else if (useLKI) {
permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
} else {
permanent = game.getPermanentOrLKIBattlefield(targetId);
}
// can target card or permanent
Card copyFrom;
CopyApplier applier = new EmptyCopyApplier();
if (permanent != null) {
// handle copies of copies
Permanent copyFromPermanent = permanent;
for (ContinuousEffect effect : game.getState().getContinuousEffects().getLayeredEffects(game)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that our targetPermanent copies stats from
if (copyEffect.getSourceId().equals(permanent.getId())) {
MageObject object = ((CopyEffect) effect).getTarget();
if (object instanceof Permanent) {
copyFromPermanent = (Permanent) object;
if (copyEffect.getApplier() != null) {
applier = copyEffect.getApplier();
}
}
}
}
}
copyFrom = copyFromPermanent;
} else {
copyFrom = game.getCard(getTargetPointer().getFirst(game, source));
}
if (copyFrom == null) {
return false;
}
// create token and modify all attributes permanently (without game usage)
EmptyToken token = new EmptyToken();
// needed so that entersBattlefied triggered abilities see the attributes (e.g. Master Biomancer)
CardUtil.copyTo(token).from(copyFrom, game);
applier.apply(game, token, source, targetId);
if (becomesArtifact) {
token.addCardType(CardType.ARTIFACT);
}
if (isntLegendary) {
token.getSuperType().remove(SuperType.LEGENDARY);
}
if (startingLoyalty != -1) {
token.setStartingLoyalty(startingLoyalty);
}
if (additionalCardType != null) {
token.addCardType(additionalCardType);
}
if (hasHaste) {
token.addAbility(HasteAbility.getInstance());
}
if (gainsFlying) {
token.addAbility(FlyingAbility.getInstance());
}
if (tokenPower != Integer.MIN_VALUE) {
token.removePTCDA();
token.getPower().modifyBaseValue(tokenPower);
}
if (tokenToughness != Integer.MIN_VALUE) {
token.removePTCDA();
token.getToughness().modifyBaseValue(tokenToughness);
}
if (onlySubType != null) {
token.removeAllCreatureTypes();
token.addSubType(onlySubType);
}
if (additionalSubType != null) {
token.addSubType(additionalSubType);
}
if (color != null) {
token.getColor().setColor(color);
}
additionalAbilities.stream().forEach(token::addAbility);
if (!this.abilityClazzesToRemove.isEmpty()) {
List<Ability> abilitiesToRemoveTmp = new ArrayList<>();
// Find the ones to remove
for (Ability ability : token.getAbilities()) {
if (this.abilityClazzesToRemove.contains(ability.getClass())) {
abilitiesToRemoveTmp.add(ability);
}
}
// Remove them
for (Ability ability : abilitiesToRemoveTmp) {
// Remove subabilities
token.removeAbilities(ability.getSubAbilities());
// Remove the ability
token.removeAbility(ability);
}
}
token.putOntoBattlefield(number, game, source, playerId == null ? source.getControllerId() : playerId, tapped, attacking, attackedPlayer);
for (UUID tokenId : token.getLastAddedTokenIds()) {
// by cards like Doubling Season multiple tokens can be added to the battlefield
Permanent tokenPermanent = game.getPermanent(tokenId);
if (tokenPermanent != null) {
addedTokenPermanents.add(tokenPermanent);
// add counters if necessary ie Ochre Jelly
if (counter != null && numberOfCounters > 0) {
tokenPermanent.addCounters(counter.createInstance(numberOfCounters), source.getControllerId(), source, game);
}
}
}
return true;
}
use of mage.util.functions.CopyApplier in project mage by magefree.
the class CryptoplasmEffect method apply.
@Override
public boolean apply(Game game, final Ability source) {
Permanent creatureToCopy = game.getPermanent(getTargetPointer().getFirst(game, source));
if (creatureToCopy != null) {
CopyApplier applier = new CopyApplier() {
@Override
public boolean apply(Game game, MageObject blueprint, Ability source, UUID copyToObjectId) {
Ability upkeepAbility = new BeginningOfUpkeepTriggeredAbility(new CryptoplasmEffect(), TargetController.YOU, true);
upkeepAbility.addTarget(new TargetCreaturePermanent());
blueprint.getAbilities().add(upkeepAbility);
return true;
}
};
game.copyPermanent(creatureToCopy, source.getSourceId(), source, applier);
}
return true;
}
use of mage.util.functions.CopyApplier in project mage by magefree.
the class OlagLudevicsHubrisCopyApplier method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Cards cards = new CardsImpl(game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)));
cards.removeIf(uuid -> !game.getCard(uuid).isCreature(game));
if (cards.isEmpty()) {
return false;
}
Card copyFromCard = getCard(cards, source, game);
if (copyFromCard == null) {
return false;
}
Permanent newBluePrint = new PermanentCard(copyFromCard, source.getControllerId(), game);
newBluePrint.assignNewId();
CopyApplier applier = new OlagLudevicsHubrisCopyApplier();
applier.apply(game, newBluePrint, source, source.getSourceId());
CopyEffect copyEffect = new CopyEffect(Duration.Custom, newBluePrint, source.getSourceId());
copyEffect.newId();
copyEffect.setApplier(applier);
Ability newAbility = source.copy();
copyEffect.init(newAbility, game);
game.addEffect(copyEffect, newAbility);
return false;
}
Aggregations