[C14] Added 6 blue cards.

This commit is contained in:
LevelX2 2014-11-28 17:39:47 +01:00
parent 07b509684a
commit c673fbfae1
18 changed files with 1006 additions and 8 deletions

View file

@ -120,4 +120,12 @@ public class MageObjectReference implements Comparable<MageObjectReference> {
return mageObject.getId().equals(sourceId);
}
public Permanent getPermanent(Game game) {
Permanent permanent = game.getPermanent(sourceId);
if (permanent != null && permanent.getZoneChangeCounter() == zoneChangeCounter) {
return permanent;
}
return null;
}
}

View file

@ -56,8 +56,7 @@ public class BlocksIfAbleTargetEffect extends RequirementEffect {
@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
Permanent creature = game.getPermanent(source.getFirstTarget());
return creature != null && creature.getId().equals(permanent.getId());
return getTargetPointer().getTargets(game, source).contains(permanent.getId());
}
@Override

View file

@ -0,0 +1,175 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.abilities.effects.common.continious;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.MageObjectReference;
import mage.ObjectColor;
import mage.abilities.Ability;
import mage.abilities.common.TurnFaceUpAbility;
import mage.abilities.effects.ContinuousEffectImpl;
import mage.abilities.keyword.MorphAbility;
import mage.cards.Card;
import mage.constants.CardType;
import mage.constants.Duration;
import mage.constants.Layer;
import static mage.constants.Layer.AbilityAddingRemovingEffects_6;
import static mage.constants.Layer.ColorChangingEffects_5;
import static mage.constants.Layer.PTChangingEffects_7;
import static mage.constants.Layer.TypeChangingEffects_4;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author LevelX2
*/
public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl implements SourceEffect {
protected Map<UUID,Ability> turnFaceUpAbilityMap = new HashMap<>();
protected FilterPermanent filter;
protected ArrayList<MageObjectReference> objectList = new ArrayList<>();
public BecomesFaceDownCreatureAllEffect(FilterPermanent filter) {
super(Duration.EndOfGame, Outcome.BecomeCreature);
this.filter = filter;
staticText = "turn all " + filter.getMessage() + " face down. (They're 2/2 creatures.)";
}
public BecomesFaceDownCreatureAllEffect(final BecomesFaceDownCreatureAllEffect effect) {
super(effect);
this.objectList.addAll(effect.objectList);
for (Map.Entry<UUID,Ability> entry: effect.turnFaceUpAbilityMap.entrySet()) {
this.turnFaceUpAbilityMap.put(entry.getKey(), entry.getValue());
}
this.filter = effect.filter.copy();
}
@Override
public BecomesFaceDownCreatureAllEffect copy() {
return new BecomesFaceDownCreatureAllEffect(this);
}
@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()) {
objectList.add(new MageObjectReference(perm));
perm.setFaceDown(true);
// check for Morph
Card card = game.getCard(perm.getId());
if (card != null) {
for (Ability ability: card.getAbilities()) {
if (ability instanceof MorphAbility) {
this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility)ability).getMorphCosts()));
}
}
}
}
}
}
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
boolean targetExists = false;
for (MageObjectReference mor: objectList) {
Permanent permanent = mor.getPermanent(game);
if (permanent != null && permanent.isFaceDown()) {
targetExists = true;
switch (layer) {
case TypeChangingEffects_4:
permanent.setName("");
permanent.getSupertype().clear();
permanent.getCardType().clear();
permanent.getCardType().add(CardType.CREATURE);
permanent.getSubtype().clear();
permanent.getManaCost().clear();
break;
case ColorChangingEffects_5:
permanent.getColor().setColor(new ObjectColor());
break;
case AbilityAddingRemovingEffects_6:
Card card = game.getCard(permanent.getId()); //
List<Ability> abilities = new ArrayList<>();
for (Ability ability : permanent.getAbilities()) {
if (card != null && !card.getAbilities().contains(ability)) {
// gained abilities from other sources won't be removed
continue;
}
// TODO: Add flag "works also face down" to ability and use it to control ability removement instead of instanceof check
if (ability.getWorksFaceDown()) {
ability.setRuleVisible(false);
continue;
}
if (!ability.getRuleVisible() && !ability.getEffects().isEmpty()) {
if (ability.getEffects().get(0) instanceof BecomesFaceDownCreatureAllEffect) {
continue;
}
}
abilities.add(ability);
}
permanent.getAbilities().removeAll(abilities);
if (turnFaceUpAbilityMap.containsKey(permanent.getId())) {
permanent.addAbility(turnFaceUpAbilityMap.get(permanent.getId()), game);
}
break;
case PTChangingEffects_7:
if (sublayer == SubLayer.SetPT_7b) {
permanent.getPower().setValue(2);
permanent.getToughness().setValue(2);
}
}
}
}
if (!targetExists) {
discard();
}
return true;
}
@Override
public boolean apply(Game game, Ability source) {
return false;
}
@Override
public boolean hasLayer(Layer layer) {
return layer == Layer.PTChangingEffects_7 || layer == Layer.AbilityAddingRemovingEffects_6 || layer == Layer.ColorChangingEffects_5 || layer == Layer.TypeChangingEffects_4;
}
}

View file

@ -39,6 +39,8 @@ import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.Target;
import mage.util.CardUtil;
/**
*
@ -100,7 +102,7 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
boolean targetStillExists = false;
for (UUID permanentId: this.getTargetPointer().getTargets(game, source)) {
for (UUID permanentId: getTargetPointer().getTargets(game, source)) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
targetStillExists = true;
@ -113,7 +115,7 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
}
if (!targetStillExists) {
// no valid target exists, effect can be discarded
this.discard();
discard();
}
return true;
}
@ -125,9 +127,17 @@ public class GainControlTargetEffect extends ContinuousEffectImpl {
if (!staticText.isEmpty()) {
return staticText;
}
Target target = mode.getTargets().get(0);
StringBuilder sb = new StringBuilder("Gain control of ");
if (!mode.getTargets().get(0).getTargetName().startsWith("another")) {
sb.append("target ");
if (target.getMaxNumberOfTargets() > 1){
if (target.getNumberOfTargets() < target.getMaxNumberOfTargets()) {
sb.append("up to ");
}
sb.append(CardUtil.numberToText(target.getMaxNumberOfTargets())).append(" target ");
} else {
if (!target.getTargetName().startsWith("another")) {
sb.append("target ");
}
}
sb.append(mode.getTargets().get(0).getTargetName());
if (!duration.toString().isEmpty()) {

View file

@ -105,7 +105,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
protected static final String REMINDER_TEXT = "<i>(You may cast this card face down as a 2/2 creature for {3}. Turn it face up any time for its morph cost.)</i>";
protected String ruleText;
protected AlternativeCost2Impl alternateCosts = new AlternativeCost2Impl(ABILITY_KEYWORD, REMINDER_TEXT, new GenericManaCost(3));
protected Costs<Cost> morphCosts;
// needed to check activation status, if card changes zone after casting it
private int zoneChangeCounter = 0;
@ -115,6 +115,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
public MorphAbility(Card card, Costs<Cost> morphCosts) {
super(Zone.HAND, null);
this.morphCosts = morphCosts;
card.setMorphCard(true);
this.setWorksFaceDown(true);
name = ABILITY_KEYWORD;
@ -141,6 +142,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
this.zoneChangeCounter = ability.zoneChangeCounter;
this.ruleText = ability.ruleText;
this.alternateCosts = ability.alternateCosts.copy();
this.morphCosts = ability.morphCosts; // can't be changed
}
private static Costs<Cost> createCosts(Cost cost) {
@ -159,6 +161,10 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
zoneChangeCounter = 0;
}
public Costs<Cost> getMorphCosts() {
return morphCosts;
}
@Override
public boolean isActivated(Ability ability, Game game) {
Card card = game.getCard(sourceId);
@ -267,7 +273,7 @@ public class MorphAbility extends StaticAbility implements AlternativeSourceCost
/**
* This effect lets the creature always be a 2/2 face-down creature, with no text,
* no name, no subtypes, and no mana cost, if it's fac down on the battlefield.
* no name, no subtypes, and no mana cost, if it's face down on the battlefield.
* And it adds the MorphTurnFaceUpAbility ability.
* TODO: Check if it's better to create this effect always as a creature on the battelfield turns face down or
* a creature enters the battlefield face down. Then the effect could be removed as the permanent turns face up.