mirror of
https://github.com/magefree/mage.git
synced 2025-12-24 12:31:59 -08:00
Ability refactor: face down;
This commit is contained in:
parent
eea808d2d6
commit
f3f1c29926
8 changed files with 137 additions and 47 deletions
|
|
@ -40,6 +40,7 @@ public class TurnFaceUpAbility extends SpecialAction {
|
|||
this.usesStack = false;
|
||||
this.abilityType = AbilityType.SPECIAL_ACTION;
|
||||
this.setRuleVisible(false); // will be made visible only to controller in CardView
|
||||
this.setWorksFaceDown(true);
|
||||
}
|
||||
|
||||
public TurnFaceUpAbility(final TurnFaceUpAbility ability) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,5 @@
|
|||
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
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;
|
||||
|
|
@ -13,23 +7,20 @@ 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 mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.constants.*;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
|
||||
public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl implements SourceEffect {
|
||||
|
||||
protected Map<UUID,Ability> turnFaceUpAbilityMap = new HashMap<>();
|
||||
protected Map<UUID, Ability> turnFaceUpAbilityMap = new HashMap<>();
|
||||
protected FilterPermanent filter;
|
||||
|
||||
public BecomesFaceDownCreatureAllEffect(FilterPermanent filter) {
|
||||
|
|
@ -40,7 +31,7 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple
|
|||
|
||||
public BecomesFaceDownCreatureAllEffect(final BecomesFaceDownCreatureAllEffect effect) {
|
||||
super(effect);
|
||||
for (Map.Entry<UUID,Ability> entry: effect.turnFaceUpAbilityMap.entrySet()) {
|
||||
for (Map.Entry<UUID, Ability> entry : effect.turnFaceUpAbilityMap.entrySet()) {
|
||||
this.turnFaceUpAbilityMap.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
this.filter = effect.filter.copy();
|
||||
|
|
@ -54,16 +45,16 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple
|
|||
@Override
|
||||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
for (Permanent perm: game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), 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()) {
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
if (ability instanceof MorphAbility) {
|
||||
this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility)ability).getMorphCosts()));
|
||||
this.turnFaceUpAbilityMap.put(card.getId(), new TurnFaceUpAbility(((MorphAbility) ability).getMorphCosts()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -74,7 +65,7 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple
|
|||
@Override
|
||||
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
|
||||
boolean targetExists = false;
|
||||
for (MageObjectReference mor: affectedObjectList) {
|
||||
for (MageObjectReference mor : affectedObjectList) {
|
||||
Permanent permanent = mor.getPermanent(game);
|
||||
if (permanent != null && permanent.isFaceDown(game)) {
|
||||
targetExists = true;
|
||||
|
|
@ -92,27 +83,35 @@ public class BecomesFaceDownCreatureAllEffect extends ContinuousEffectImpl imple
|
|||
break;
|
||||
case AbilityAddingRemovingEffects_6:
|
||||
Card card = game.getCard(permanent.getId()); //
|
||||
List<Ability> abilities = new ArrayList<>();
|
||||
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)) {
|
||||
// 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
|
||||
|
||||
// 701.33c
|
||||
// If a card with morph is manifested, its controller may turn that card face up using
|
||||
// either the procedure described in rule 702.36e to turn a face-down permanent with morph face up
|
||||
// or the procedure described above to turn a manifested permanent face up.
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
abilities.add(ability);
|
||||
abilitiesToRemove.add(ability);
|
||||
}
|
||||
permanent.getAbilities().removeAll(abilities);
|
||||
permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
|
||||
if (turnFaceUpAbilityMap.containsKey(permanent.getId())) {
|
||||
permanent.addAbility(turnFaceUpAbilityMap.get(permanent.getId()), game);
|
||||
permanent.addAbility(turnFaceUpAbilityMap.get(permanent.getId()), source.getSourceId(), game);
|
||||
}
|
||||
break;
|
||||
case PTChangingEffects_7:
|
||||
|
|
|
|||
|
|
@ -1,8 +1,5 @@
|
|||
|
||||
package mage.abilities.effects.common.continuous;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import mage.MageObjectReference;
|
||||
import mage.ObjectColor;
|
||||
import mage.abilities.Ability;
|
||||
|
|
@ -12,14 +9,13 @@ import mage.abilities.costs.Costs;
|
|||
import mage.abilities.costs.CostsImpl;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.cards.Card;
|
||||
import mage.constants.CardType;
|
||||
import mage.constants.Duration;
|
||||
import mage.constants.Layer;
|
||||
import mage.constants.Outcome;
|
||||
import mage.constants.SubLayer;
|
||||
import mage.constants.*;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This effect lets the card be a 2/2 face-down creature, with no text, no name,
|
||||
* no subtypes, and no mana cost, if it's face down on the battlefield. And it
|
||||
|
|
@ -149,21 +145,31 @@ public class BecomesFaceDownCreatureEffect extends ContinuousEffectImpl implemen
|
|||
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)) {
|
||||
// gained abilities from other sources won't be removed
|
||||
continue;
|
||||
}
|
||||
|
||||
// 701.33c
|
||||
// If a card with morph is manifested, its controller may turn that card face up using
|
||||
// either the procedure described in rule 702.36e to turn a face-down permanent with morph face up
|
||||
// or the procedure described above to turn a manifested permanent face up.
|
||||
//
|
||||
// so keep all tune face up abilities and other face down compatible
|
||||
if (ability.getWorksFaceDown()) {
|
||||
ability.setRuleVisible(false);
|
||||
continue;
|
||||
} else if (!ability.getRuleVisible() && !ability.getEffects().isEmpty()) {
|
||||
}
|
||||
|
||||
if (!ability.getRuleVisible() && !ability.getEffects().isEmpty()) {
|
||||
if (ability.getEffects().get(0) instanceof BecomesFaceDownCreatureEffect) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
abilitiesToRemove.add(ability);
|
||||
}
|
||||
permanent.getAbilities().removeAll(abilitiesToRemove);
|
||||
permanent.removeAbilities(abilitiesToRemove, source.getSourceId(), game);
|
||||
if (turnFaceUpAbility != null) {
|
||||
permanent.addAbility(turnFaceUpAbility, source.getSourceId(), game);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,6 +156,7 @@ public interface Permanent extends Card, Controllable {
|
|||
|
||||
void addAbility(Ability ability, UUID sourceId, Game game);
|
||||
|
||||
@Deprecated // use addAbility(Ability ability, UUID sourceId, Game game) instead
|
||||
void addAbility(Ability ability, UUID sourceId, Game game, boolean createNewId);
|
||||
|
||||
void removeAllAbilities(UUID sourceId, Game game);
|
||||
|
|
|
|||
|
|
@ -365,7 +365,6 @@ public abstract class PermanentImpl extends CardImpl implements Permanent {
|
|||
}
|
||||
|
||||
@Override
|
||||
@Deprecated // use addAbility(Ability ability, UUID sourceId, Game game) instead
|
||||
public void addAbility(Ability ability, UUID sourceId, Game game, boolean createNewId) {
|
||||
// singleton abilities -- only one instance
|
||||
// other abilities -- any amount of instances
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue