use of mage.abilities.Ability in project mage by magefree.
the class DependentEffectsTest method testYixlidJailerAndNecroticOozeLooseAll.
@Test
public void testYixlidJailerAndNecroticOozeLooseAll() {
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
// As long as Necrotic Ooze is on the battlefield, it has all activated abilities of all creature cards in all graveyards
addCard(Zone.BATTLEFIELD, playerA, "Necrotic Ooze", 1);
// {2}{1},{T}: Tap target creature.
addCard(Zone.GRAVEYARD, playerA, "Akroan Jailer", 1);
// {T}: Target attacking creature gets +1/+1 until end of turn.
addCard(Zone.GRAVEYARD, playerB, "Anointer of Champions", 1);
// Cards in graveyards lose all abilities.
// Creature - {1}{B}
addCard(Zone.HAND, playerA, "Yixlid Jailer", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Yixlid Jailer");
setStrictChooseMode(true);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, "Yixlid Jailer", 1);
Permanent necroticOoze = getPermanent("Necrotic Ooze", playerA);
int numberOfActivatedAbilities = 0;
for (Ability ability : necroticOoze.getAbilities(currentGame)) {
if (ability.getAbilityType() == AbilityType.ACTIVATED) {
numberOfActivatedAbilities++;
}
}
Assert.assertEquals("All abilities from cards in graveyard are removed - so no abilities for Necrotic Ooze", 0, numberOfActivatedAbilities);
}
use of mage.abilities.Ability in project mage by magefree.
the class LicidSpecialActionEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent licid = (Permanent) source.getSourceObjectIfItStillExists(game);
if (licid != null) {
switch(layer) {
case TypeChangingEffects_4:
licid.removeAllCardTypes(game);
licid.addCardType(game, CardType.ENCHANTMENT);
licid.removeAllSubTypes(game);
licid.addSubType(game, SubType.AURA);
break;
case AbilityAddingRemovingEffects_6:
List<Ability> toRemove = new ArrayList<>();
for (Ability ability : licid.getAbilities(game)) {
for (Effect effect : ability.getEffects()) {
if (effect instanceof LicidEffect) {
toRemove.add(ability);
break;
}
}
}
licid.removeAbilities(toRemove, source.getSourceId(), game);
Ability ability = new EnchantAbility("creature");
ability.setRuleAtTheTop(true);
licid.addAbility(ability, source.getSourceId(), game);
licid.getSpellAbility().getTargets().clear();
Target target = new TargetCreaturePermanent();
target.addTarget(this.getTargetPointer().getFirst(game, source), source, game);
licid.getSpellAbility().getTargets().add(target);
}
return true;
}
discard();
return false;
}
use of mage.abilities.Ability in project mage by magefree.
the class CopyEffect method copyToPermanent.
protected boolean copyToPermanent(Permanent permanent, Game game, Ability source) {
if (copyFromObject.getCopyFrom() != null) {
// copy from temp blueprints (they are already copies)
permanent.setCopy(true, copyFromObject.getCopyFrom());
} else {
// copy object to object
permanent.setCopy(true, copyFromObject);
}
permanent.setName(copyFromObject.getName());
permanent.getColor(game).setColor(copyFromObject.getColor(game));
permanent.getManaCost().clear();
permanent.getManaCost().add(copyFromObject.getManaCost().copy());
permanent.removeAllCardTypes(game);
for (CardType type : copyFromObject.getCardType(game)) {
permanent.addCardType(game, type);
}
permanent.removeAllSubTypes(game);
permanent.copySubTypesFrom(game, copyFromObject);
permanent.getSuperType().clear();
for (SuperType type : copyFromObject.getSuperType()) {
permanent.addSuperType(type);
}
permanent.removeAllAbilities(source.getSourceId(), game);
if (copyFromObject instanceof Permanent) {
for (Ability ability : ((Permanent) copyFromObject).getAbilities(game)) {
permanent.addAbility(ability, getSourceId(), game);
}
} else {
for (Ability ability : copyFromObject.getAbilities()) {
permanent.addAbility(ability, getSourceId(), game);
}
}
// Primal Clay example:
// If a creature that’s already on the battlefield becomes a copy of this creature, it copies the power, toughness,
// and abilities that were chosen for this creature as it entered the battlefield. (2018-03-16)
permanent.getPower().setValue(copyFromObject.getPower().getBaseValueModified());
permanent.getToughness().setValue(copyFromObject.getToughness().getBaseValueModified());
permanent.setStartingLoyalty(copyFromObject.getStartingLoyalty());
if (copyFromObject instanceof Permanent) {
Permanent targetPermanent = (Permanent) copyFromObject;
permanent.setTransformed(targetPermanent.isTransformed());
permanent.setSecondCardFace(targetPermanent.getSecondCardFace());
permanent.setFlipCard(targetPermanent.isFlipCard());
permanent.setFlipCardName(targetPermanent.getFlipCardName());
}
// to get the image of the copied permanent copy number und expansionCode
if (copyFromObject instanceof PermanentCard) {
permanent.setCardNumber(((PermanentCard) copyFromObject).getCard().getCardNumber());
permanent.setExpansionSetCode(((PermanentCard) copyFromObject).getCard().getExpansionSetCode());
} else if (copyFromObject instanceof PermanentToken || copyFromObject instanceof Card) {
permanent.setCardNumber(((Card) copyFromObject).getCardNumber());
permanent.setExpansionSetCode(((Card) copyFromObject).getExpansionSetCode());
}
return true;
}
use of mage.abilities.Ability 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.Ability in project mage by magefree.
the class CopyPermanentEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourcePermanent = game.getPermanentEntering(source.getSourceId());
if (sourcePermanent == null) {
sourcePermanent = game.getObject(source.getSourceId());
}
if (controller == null || sourcePermanent == null) {
return false;
}
Permanent copyFromPermanent = null;
if (useTargetOfAbility) {
copyFromPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
} else {
Target target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
controller.choose(Outcome.Copy, target, source.getSourceId(), game);
copyFromPermanent = game.getPermanent(target.getFirstTarget());
}
}
if (copyFromPermanent == null) {
return true;
}
bluePrintPermanent = game.copyPermanent(duration, copyFromPermanent, sourcePermanent.getId(), source, applier);
if (bluePrintPermanent == null) {
return false;
}
// if object is a copy of an aura, it needs to attach again for new target
if (!bluePrintPermanent.hasSubtype(SubType.AURA, game)) {
return true;
}
// copied from mage.cards.c.CopyEnchantment.java
// permanent can be attached (Estrid's Mask) or enchant (Utopia Sprawl)
// TODO: fix Animate Dead -- it's can't be copied (can't retarget)
Outcome auraOutcome = Outcome.BoostCreature;
Target auraTarget = null;
// attach - search effect in spell ability (example: cast Utopia Sprawl, cast Estrid's Invocation on it)
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof SpellAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
for (Effect effect : ability.getEffects()) {
if (!(effect instanceof AttachEffect)) {
continue;
}
if (bluePrintPermanent.getSpellAbility().getTargets().size() > 0) {
auraTarget = bluePrintPermanent.getSpellAbility().getTargets().get(0);
}
}
}
// enchant - search in all abilities (example: cast Estrid's Invocation on enchanted creature by Estrid, the Masked second ability, cast Estrid's Invocation on it)
if (auraTarget == null) {
for (Ability ability : bluePrintPermanent.getAbilities()) {
if (!(ability instanceof EnchantAbility)) {
continue;
}
auraOutcome = ability.getEffects().getOutcome(ability);
if (ability.getTargets().size() > 0) {
// Animate Dead don't have targets
auraTarget = ability.getTargets().get(0);
}
}
}
/* if this is a copy of a copy, the copy's target has been
* copied and needs to be cleared
*/
if (auraTarget == null) {
return true;
}
// clear selected target
if (auraTarget.getFirstTarget() != null) {
auraTarget.remove(auraTarget.getFirstTarget());
}
// select new target
auraTarget.setNotTarget(true);
if (!controller.choose(auraOutcome, auraTarget, source.getSourceId(), game)) {
return true;
}
UUID targetId = auraTarget.getFirstTarget();
Permanent targetPermanent = game.getPermanent(targetId);
Player targetPlayer = game.getPlayer(targetId);
if (targetPermanent != null) {
targetPermanent.addAttachment(sourcePermanent.getId(), source, game);
} else if (targetPlayer != null) {
targetPlayer.addAttachment(sourcePermanent.getId(), source, game);
} else {
return false;
}
return true;
}
Aggregations