use of mage.ObjectColor in project mage by magefree.
the class BecomesFaceDownCreatureAllEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
boolean targetExists = false;
for (MageObjectReference mor : affectedObjectList) {
Permanent permanent = mor.getPermanent(game);
if (permanent != null && permanent.isFaceDown(game)) {
targetExists = true;
switch(layer) {
case TypeChangingEffects_4:
permanent.setName("");
permanent.getSuperType().clear();
permanent.removeAllCardTypes(game);
permanent.addCardType(game, CardType.CREATURE);
permanent.removeAllSubTypes(game);
permanent.getManaCost().clear();
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 BecomesFaceDownCreatureAllEffect) {
continue;
}
}
abilitiesToRemove.add(ability);
}
permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
if (turnFaceUpAbilityMap.containsKey(permanent.getId())) {
permanent.addAbility(turnFaceUpAbilityMap.get(permanent.getId()), source.getSourceId(), game);
}
break;
case PTChangingEffects_7:
if (sublayer == SubLayer.SetPT_7b) {
permanent.getPower().setValue(2);
permanent.getToughness().setValue(2);
}
}
}
}
if (!targetExists) {
discard();
}
return true;
}
use of mage.ObjectColor 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;
}
use of mage.ObjectColor in project mage by magefree.
the class MorphAbility method askToActivateAlternativeCosts.
@Override
public boolean askToActivateAlternativeCosts(Ability ability, Game game) {
if (ability.getAbilityType() == AbilityType.SPELL) {
Player player = game.getPlayer(ability.getControllerId());
Spell spell = game.getStack().getSpell(ability.getId());
if (player != null && spell != null) {
this.resetMorph();
// so only the back is visible
spell.setFaceDown(true, game);
if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
game.getState().setValue("MorphAbility" + ability.getSourceId(), // Gift of Doom
"activated");
activateMorph(game);
// change mana costs
ability.getManaCostsToPay().clear();
ability.getCosts().clear();
for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCost) {
ability.getManaCostsToPay().add((ManaCost) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
// change spell colors and subtype *TODO probably this needs to be done by continuous effect (while on the stack)
ObjectColor spellColor = spell.getColor(game);
spellColor.setBlack(false);
spellColor.setRed(false);
spellColor.setGreen(false);
spellColor.setWhite(false);
spellColor.setBlue(false);
game.getState().getCreateMageObjectAttribute(spell.getCard(), game).getSubtype().clear();
} else {
spell.setFaceDown(false, game);
}
}
}
}
if (ability.getAbilityType() == AbilityType.PLAY_LAND) {
Player player = game.getPlayer(ability.getControllerId());
if (player != null) {
this.resetMorph();
if (alternateCosts.canPay(ability, this, ability.getControllerId(), game)) {
if (player.chooseUse(Outcome.Benefit, "Cast this card as a 2/2 " + "face-down creature for " + getCosts().getText() + " ?", ability, game)) {
activateMorph(game);
// change mana costs
ability.getManaCostsToPay().clear();
ability.getCosts().clear();
for (Iterator it = this.alternateCosts.iterator(); it.hasNext(); ) {
Cost cost = (Cost) it.next();
if (cost instanceof ManaCost) {
ability.getManaCostsToPay().add((ManaCost) cost.copy());
} else {
ability.getCosts().add(cost.copy());
}
}
}
}
}
}
return isActivated(ability, game);
}
use of mage.ObjectColor in project mage by magefree.
the class TargetControlledCreatureEachColor method makeFilter.
private static final FilterControlledPermanent makeFilter(String colors) {
List<ObjectColor> objectColors = Arrays.stream(colors.split("")).map(ObjectColor::new).collect(Collectors.toList());
FilterControlledPermanent filter = new FilterControlledCreaturePermanent(CardUtil.concatWithAnd(objectColors.stream().map(ObjectColor::getDescription).map(s -> CardUtil.addArticle(s) + " creature").collect(Collectors.toList())));
filter.add(Predicates.or(objectColors.stream().map(ColorPredicate::new).collect(Collectors.toList())));
return filter;
}
use of mage.ObjectColor in project mage by magefree.
the class CardView method fillEmpty.
private void fillEmpty(Card card, boolean controlled) {
this.name = "Face Down";
this.displayName = name;
this.displayFullName = name;
this.rules = new ArrayList<>();
this.power = "";
this.toughness = "";
this.loyalty = "";
this.startingLoyalty = "";
this.cardTypes = new ArrayList<>();
this.subTypes = new SubTypes();
this.superTypes = EnumSet.noneOf(SuperType.class);
this.color = new ObjectColor();
this.frameColor = new ObjectColor();
this.frameStyle = FrameStyle.M15_NORMAL;
this.manaCostLeftStr = "";
this.manaCostRightStr = "";
this.manaValue = 0;
// the controller can see more information (e.g. enlarged image) than other players for face down cards (e.g. Morph played face down)
if (!controlled) {
this.rarity = Rarity.COMMON;
this.expansionSetCode = "";
this.cardNumber = "0";
} else {
this.rarity = card.getRarity();
}
if (card != null) {
if (card instanceof Permanent) {
this.mageObjectType = MageObjectType.PERMANENT;
} else if (card.isCopy()) {
this.mageObjectType = MageObjectType.COPY_CARD;
} else {
this.mageObjectType = MageObjectType.CARD;
}
if (card instanceof PermanentToken) {
this.mageObjectType = MageObjectType.TOKEN;
}
if (card instanceof Spell) {
this.mageObjectType = MageObjectType.SPELL;
}
}
}
Aggregations