use of mage.abilities.common.TurnFaceUpAbility in project mage by magefree.
the class BecomesFaceDownCreatureAllEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
for (Permanent perm : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (!perm.isFaceDown(game) && !perm.isTransformable()) {
affectedObjectList.add(new MageObjectReference(perm, game));
perm.setFaceDown(true, game);
// check for Morph
Card card = game.getCard(perm.getId());
if (card != null) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof MorphAbility) {
this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility) ability).getMorphCosts()));
}
}
}
}
}
}
use of mage.abilities.common.TurnFaceUpAbility in project mage by magefree.
the class BecomesFaceDownCreatureEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
Permanent permanent;
if (objectReference != null) {
permanent = objectReference.getPermanent(game);
} else {
permanent = game.getPermanent(source.getSourceId());
}
if (permanent != null && permanent.isFaceDown(game)) {
if (!foundPermanent) {
foundPermanent = true;
switch(faceDownType) {
case MANIFESTED:
case // sets manifested image
MANUAL:
permanent.setManifested(true);
break;
case MORPHED:
case MEGAMORPHED:
permanent.setMorphed(true);
break;
}
}
switch(layer) {
case TypeChangingEffects_4:
permanent.setName("");
permanent.getSuperType().clear();
permanent.removeAllCardTypes(game);
permanent.addCardType(game, CardType.CREATURE);
permanent.removeAllSubTypes(game);
break;
case ColorChangingEffects_5:
permanent.getColor(game).setColor(new ObjectColor());
break;
case AbilityAddingRemovingEffects_6:
//
Card card = game.getCard(permanent.getId());
List<Ability> abilitiesToRemove = new ArrayList<>();
for (Ability ability : permanent.getAbilities()) {
// keep gained abilities from other sources, removes only own (card text)
if (card != null && !card.getAbilities().contains(ability)) {
continue;
}
// so keep all tune face up abilities and other face down compatible
if (ability.getWorksFaceDown()) {
ability.setRuleVisible(false);
continue;
}
if (!ability.getRuleVisible() && !ability.getEffects().isEmpty()) {
if (ability.getEffects().get(0) instanceof BecomesFaceDownCreatureEffect) {
continue;
}
}
abilitiesToRemove.add(ability);
}
permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
if (turnFaceUpAbility != null) {
permanent.addAbility(turnFaceUpAbility, source.getSourceId(), game);
}
break;
case PTChangingEffects_7:
if (sublayer == SubLayer.SetPT_7b) {
permanent.getPower().setValue(2);
permanent.getToughness().setValue(2);
}
}
} else if (duration == Duration.Custom && foundPermanent == true) {
discard();
}
return true;
}
Aggregations