use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class WojekApothecaryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
if (target != null) {
ObjectColor color = target.getColor(game);
for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (permanent.getColor(game).shares(color)) {
ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.ContinuousEffect 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.abilities.effects.ContinuousEffect in project mage by magefree.
the class DreadhordeArcanistReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
if (card != null && controller.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + '?', source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
ContinuousEffect effect = new DreadhordeArcanistReplacementEffect(card.getId());
effect.setTargetPointer(new FixedTarget(card.getId(), game.getState().getZoneChangeCounter(card.getId())));
game.addEffect(effect, source);
return true;
}
use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class DreamPillagerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
int amount = (Integer) getValue("damage");
if (amount > 0) {
Set<Card> cards = controller.getLibrary().getTopCards(game, amount);
if (!cards.isEmpty()) {
controller.moveCards(cards, Zone.EXILED, source, game);
Cards canBeCast = new CardsImpl();
for (Card card : cards) {
if (!card.isLand(game)) {
canBeCast.add(card);
}
}
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, Duration.EndOfTurn);
effect.setTargetPointer(new FixedTargets(canBeCast, game));
game.addEffect(effect, source);
}
return true;
}
return true;
}
return false;
}
use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class ExhaustionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player != null) {
ContinuousEffect effect = new DontUntapInPlayersNextUntapStepAllEffect(filter);
effect.setTargetPointer(new FixedTarget(player.getId()));
game.addEffect(effect, source);
return true;
}
return false;
}
Aggregations