mirror of
https://github.com/correl/mage.git
synced 2025-01-14 03:00:10 +00:00
Added effect type and logic to handle multiple untap restriction effects.
This commit is contained in:
parent
ae44981cfa
commit
0cf7ca3fca
5 changed files with 298 additions and 9 deletions
|
@ -67,6 +67,7 @@ public class ContinuousEffects implements Serializable {
|
||||||
private ContinuousEffectsList<PreventionEffect> preventionEffects = new ContinuousEffectsList<PreventionEffect>();
|
private ContinuousEffectsList<PreventionEffect> preventionEffects = new ContinuousEffectsList<PreventionEffect>();
|
||||||
private ContinuousEffectsList<RequirementEffect> requirementEffects = new ContinuousEffectsList<RequirementEffect>();
|
private ContinuousEffectsList<RequirementEffect> requirementEffects = new ContinuousEffectsList<RequirementEffect>();
|
||||||
private ContinuousEffectsList<RestrictionEffect> restrictionEffects = new ContinuousEffectsList<RestrictionEffect>();
|
private ContinuousEffectsList<RestrictionEffect> restrictionEffects = new ContinuousEffectsList<RestrictionEffect>();
|
||||||
|
private ContinuousEffectsList<RestrictionUntapNotMoreThanEffect> restrictionUntapNotMoreThanEffects = new ContinuousEffectsList<RestrictionUntapNotMoreThanEffect>();
|
||||||
private ContinuousEffectsList<AsThoughEffect> asThoughEffects = new ContinuousEffectsList<AsThoughEffect>();
|
private ContinuousEffectsList<AsThoughEffect> asThoughEffects = new ContinuousEffectsList<AsThoughEffect>();
|
||||||
private ContinuousEffectsList<CostModificationEffect> costModificationEffects = new ContinuousEffectsList<CostModificationEffect>();
|
private ContinuousEffectsList<CostModificationEffect> costModificationEffects = new ContinuousEffectsList<CostModificationEffect>();
|
||||||
private ContinuousEffectsList<SpliceCardEffect> spliceCardEffects = new ContinuousEffectsList<SpliceCardEffect>();
|
private ContinuousEffectsList<SpliceCardEffect> spliceCardEffects = new ContinuousEffectsList<SpliceCardEffect>();
|
||||||
|
@ -98,6 +99,7 @@ public class ContinuousEffects implements Serializable {
|
||||||
preventionEffects = effect.preventionEffects.copy();
|
preventionEffects = effect.preventionEffects.copy();
|
||||||
requirementEffects = effect.requirementEffects.copy();
|
requirementEffects = effect.requirementEffects.copy();
|
||||||
restrictionEffects = effect.restrictionEffects.copy();
|
restrictionEffects = effect.restrictionEffects.copy();
|
||||||
|
restrictionUntapNotMoreThanEffects = effect.restrictionUntapNotMoreThanEffects.copy();
|
||||||
asThoughEffects = effect.asThoughEffects.copy();
|
asThoughEffects = effect.asThoughEffects.copy();
|
||||||
costModificationEffects = effect.costModificationEffects.copy();
|
costModificationEffects = effect.costModificationEffects.copy();
|
||||||
spliceCardEffects = effect.spliceCardEffects.copy();
|
spliceCardEffects = effect.spliceCardEffects.copy();
|
||||||
|
@ -114,6 +116,7 @@ public class ContinuousEffects implements Serializable {
|
||||||
allEffectsLists.add(preventionEffects);
|
allEffectsLists.add(preventionEffects);
|
||||||
allEffectsLists.add(requirementEffects);
|
allEffectsLists.add(requirementEffects);
|
||||||
allEffectsLists.add(restrictionEffects);
|
allEffectsLists.add(restrictionEffects);
|
||||||
|
allEffectsLists.add(restrictionUntapNotMoreThanEffects);
|
||||||
allEffectsLists.add(asThoughEffects);
|
allEffectsLists.add(asThoughEffects);
|
||||||
allEffectsLists.add(costModificationEffects);
|
allEffectsLists.add(costModificationEffects);
|
||||||
allEffectsLists.add(spliceCardEffects);
|
allEffectsLists.add(spliceCardEffects);
|
||||||
|
@ -159,6 +162,7 @@ public class ContinuousEffects implements Serializable {
|
||||||
preventionEffects.removeInactiveEffects(game);
|
preventionEffects.removeInactiveEffects(game);
|
||||||
requirementEffects.removeInactiveEffects(game);
|
requirementEffects.removeInactiveEffects(game);
|
||||||
restrictionEffects.removeInactiveEffects(game);
|
restrictionEffects.removeInactiveEffects(game);
|
||||||
|
restrictionUntapNotMoreThanEffects.removeInactiveEffects(game);
|
||||||
asThoughEffects.removeInactiveEffects(game);
|
asThoughEffects.removeInactiveEffects(game);
|
||||||
costModificationEffects.removeInactiveEffects(game);
|
costModificationEffects.removeInactiveEffects(game);
|
||||||
spliceCardEffects.removeInactiveEffects(game);
|
spliceCardEffects.removeInactiveEffects(game);
|
||||||
|
@ -251,7 +255,7 @@ public class ContinuousEffects implements Serializable {
|
||||||
HashSet<Ability> abilities = restrictionEffects.getAbility(effect.getId());
|
HashSet<Ability> abilities = restrictionEffects.getAbility(effect.getId());
|
||||||
HashSet<Ability> applicableAbilities = new HashSet<Ability>();
|
HashSet<Ability> applicableAbilities = new HashSet<Ability>();
|
||||||
for (Ability ability : abilities) {
|
for (Ability ability : abilities) {
|
||||||
if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, permanent, false)) {
|
if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, false)) {
|
||||||
if (effect.applies(permanent, ability, game)) {
|
if (effect.applies(permanent, ability, game)) {
|
||||||
applicableAbilities.add(ability);
|
applicableAbilities.add(ability);
|
||||||
}
|
}
|
||||||
|
@ -264,6 +268,25 @@ public class ContinuousEffects implements Serializable {
|
||||||
return effects;
|
return effects;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HashMap<RestrictionUntapNotMoreThanEffect, HashSet<Ability>> getApplicableRestrictionUntapNotMoreThanEffects(Player player, Game game) {
|
||||||
|
HashMap<RestrictionUntapNotMoreThanEffect, HashSet<Ability>> effects = new HashMap<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>();
|
||||||
|
for (RestrictionUntapNotMoreThanEffect effect: restrictionUntapNotMoreThanEffects) {
|
||||||
|
HashSet<Ability> abilities = restrictionUntapNotMoreThanEffects.getAbility(effect.getId());
|
||||||
|
HashSet<Ability> applicableAbilities = new HashSet<Ability>();
|
||||||
|
for (Ability ability : abilities) {
|
||||||
|
if (!(ability instanceof StaticAbility) || ability.isInUseableZone(game, null, false)) {
|
||||||
|
if (effect.applies(player, ability, game)) {
|
||||||
|
applicableAbilities.add(ability);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!applicableAbilities.isEmpty()) {
|
||||||
|
effects.put(effect, abilities);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return effects;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param event
|
* @param event
|
||||||
|
@ -708,6 +731,10 @@ public class ContinuousEffects implements Serializable {
|
||||||
RestrictionEffect newRestrictionEffect = (RestrictionEffect)effect;
|
RestrictionEffect newRestrictionEffect = (RestrictionEffect)effect;
|
||||||
restrictionEffects.addEffect(newRestrictionEffect, source);
|
restrictionEffects.addEffect(newRestrictionEffect, source);
|
||||||
break;
|
break;
|
||||||
|
case RESTRICTION_UNTAP_NOT_MORE_THAN:
|
||||||
|
RestrictionUntapNotMoreThanEffect newRestrictionUntapNotMoreThanEffect = (RestrictionUntapNotMoreThanEffect)effect;
|
||||||
|
restrictionUntapNotMoreThanEffects.addEffect(newRestrictionUntapNotMoreThanEffect, source);
|
||||||
|
break;
|
||||||
case REQUIREMENT:
|
case REQUIREMENT:
|
||||||
RequirementEffect newRequirementEffect = (RequirementEffect)effect;
|
RequirementEffect newRequirementEffect = (RequirementEffect)effect;
|
||||||
requirementEffects.addEffect(newRequirementEffect, source);
|
requirementEffects.addEffect(newRequirementEffect, source);
|
||||||
|
|
|
@ -28,12 +28,14 @@
|
||||||
|
|
||||||
package mage.abilities.effects;
|
package mage.abilities.effects;
|
||||||
|
|
||||||
|
import mage.abilities.Ability;
|
||||||
import mage.constants.Duration;
|
import mage.constants.Duration;
|
||||||
import mage.constants.EffectType;
|
import mage.constants.EffectType;
|
||||||
import mage.constants.Outcome;
|
import mage.constants.Outcome;
|
||||||
import mage.abilities.Ability;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.players.Player;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -41,13 +43,28 @@ import mage.game.permanent.Permanent;
|
||||||
*/
|
*/
|
||||||
public abstract class RestrictionEffect<T extends RestrictionEffect<T>> extends ContinuousEffectImpl<T> {
|
public abstract class RestrictionEffect<T extends RestrictionEffect<T>> extends ContinuousEffectImpl<T> {
|
||||||
|
|
||||||
|
private boolean notMoreThanRestriction;
|
||||||
|
private int notMoreThanNumber;
|
||||||
|
private FilterPermanent notMoreThanNumberFilter;
|
||||||
|
|
||||||
public RestrictionEffect(Duration duration) {
|
public RestrictionEffect(Duration duration) {
|
||||||
|
this(duration, false, 0, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RestrictionEffect(Duration duration, boolean notMoreThanRestriction, int notMoreThanNumber, FilterPermanent notMoreThanNumberFilter) {
|
||||||
super(duration, Outcome.Detriment);
|
super(duration, Outcome.Detriment);
|
||||||
this.effectType = EffectType.RESTRICTION;
|
this.effectType = EffectType.RESTRICTION;
|
||||||
|
this.notMoreThanRestriction = notMoreThanRestriction;
|
||||||
|
this.notMoreThanNumber = notMoreThanNumber;
|
||||||
|
this.notMoreThanNumberFilter = notMoreThanNumberFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RestrictionEffect(final RestrictionEffect effect) {
|
public RestrictionEffect(final RestrictionEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
|
this.notMoreThanRestriction = effect.notMoreThanRestriction;
|
||||||
|
if (this.notMoreThanNumberFilter != null) {
|
||||||
|
this.notMoreThanNumberFilter = effect.notMoreThanNumberFilter.copy();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +74,15 @@ public abstract class RestrictionEffect<T extends RestrictionEffect<T>> extends
|
||||||
|
|
||||||
public abstract boolean applies(Permanent permanent, Ability source, Game game);
|
public abstract boolean applies(Permanent permanent, Ability source, Game game);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* only used for the notMoreThanRestrictions, called to check if the effect shall be applied for a player
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public boolean appliesNotMoreThan(Player player, Ability source, Game game) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canAttack(Game game) {
|
public boolean canAttack(Game game) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -77,5 +103,16 @@ public abstract class RestrictionEffect<T extends RestrictionEffect<T>> extends
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isNotMoreThanRestriction() {
|
||||||
|
return notMoreThanRestriction;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNotMoreThanNumber() {
|
||||||
|
return notMoreThanNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilterPermanent getNotMoreThanNumberFilter() {
|
||||||
|