mirror of
https://github.com/magefree/mage.git
synced 2026-01-26 21:29:17 -08:00
CompoundAbility
This commit is contained in:
parent
d9e0590763
commit
1acf00a5da
2 changed files with 86 additions and 9 deletions
55
Mage/src/mage/abilities/CompoundAbility.java
Normal file
55
Mage/src/mage/abilities/CompoundAbility.java
Normal file
|
|
@ -0,0 +1,55 @@
|
||||||
|
package mage.abilities;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noxx
|
||||||
|
*/
|
||||||
|
public class CompoundAbility extends AbilitiesImpl<Ability> {
|
||||||
|
|
||||||
|
private String ruleText;
|
||||||
|
|
||||||
|
public CompoundAbility(Ability... abilities) {
|
||||||
|
this(null, abilities);
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundAbility(String ruleText, Ability... abilities) {
|
||||||
|
for (Ability ability : abilities) {
|
||||||
|
add(ability);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public CompoundAbility(final CompoundAbility compoundAbility) {
|
||||||
|
for (Ability ability : compoundAbility) {
|
||||||
|
add(ability);
|
||||||
|
}
|
||||||
|
this.ruleText = compoundAbility.ruleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRule() {
|
||||||
|
if (ruleText != null) {
|
||||||
|
return ruleText;
|
||||||
|
}
|
||||||
|
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
List<String> rules = super.getRules(null);
|
||||||
|
for (int index = 0; index < rules.size(); index++) {
|
||||||
|
if (index > 0) {
|
||||||
|
if (index < rules.size() - 1) {
|
||||||
|
sb.append(", ");
|
||||||
|
} else {
|
||||||
|
sb.append(" and ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sb.append(rules.get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
// we can't simply cache it to this.ruleText as some cards may change abilities dynamically
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CompoundAbility copy() {
|
||||||
|
return new CompoundAbility(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -33,18 +33,18 @@ import mage.Constants.Layer;
|
||||||
import mage.Constants.Outcome;
|
import mage.Constants.Outcome;
|
||||||
import mage.Constants.SubLayer;
|
import mage.Constants.SubLayer;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
|
import mage.abilities.CompoundAbility;
|
||||||
import mage.abilities.effects.ContinuousEffectImpl;
|
import mage.abilities.effects.ContinuousEffectImpl;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
*/
|
*/
|
||||||
public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilityControlledEffect> {
|
public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilityControlledEffect> {
|
||||||
|
|
||||||
protected Ability ability;
|
protected CompoundAbility ability;
|
||||||
protected boolean excludeSource;
|
protected boolean excludeSource;
|
||||||
protected FilterPermanent filter;
|
protected FilterPermanent filter;
|
||||||
|
|
||||||
|
|
@ -52,11 +52,23 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
||||||
this(ability, duration, new FilterPermanent());
|
this(ability, duration, new FilterPermanent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GainAbilityControlledEffect(CompoundAbility ability, Duration duration) {
|
||||||
|
this(ability, duration, new FilterPermanent());
|
||||||
|
}
|
||||||
|
|
||||||
public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter) {
|
public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter) {
|
||||||
this(ability, duration, filter, false);
|
this(ability, duration, filter, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GainAbilityControlledEffect(CompoundAbility ability, Duration duration, FilterPermanent filter) {
|
||||||
|
this(ability, duration, filter, false);
|
||||||
|
}
|
||||||
|
|
||||||
public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter, boolean excludeSource) {
|
public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter, boolean excludeSource) {
|
||||||
|
this(new CompoundAbility(ability), duration, filter, excludeSource);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GainAbilityControlledEffect(CompoundAbility ability, Duration duration, FilterPermanent filter, boolean excludeSource) {
|
||||||
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||||
this.ability = ability;
|
this.ability = ability;
|
||||||
this.filter = filter;
|
this.filter = filter;
|
||||||
|
|
@ -75,7 +87,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
||||||
public void init(Ability source, Game game) {
|
public void init(Ability source, Game game) {
|
||||||
super.init(source, game);
|
super.init(source, game);
|
||||||
if (this.affectedObjectsSet) {
|
if (this.affectedObjectsSet) {
|
||||||
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
||||||
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
|
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
|
||||||
objects.add(perm.getId());
|
objects.add(perm.getId());
|
||||||
}
|
}
|
||||||
|
|
@ -90,16 +102,26 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
for (Permanent perm: game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
for (Permanent perm : game.getBattlefield().getAllActivePermanents(filter, source.getControllerId(), game)) {
|
||||||
if (!this.affectedObjectsSet || objects.contains(perm.getId())) {
|
if (!this.affectedObjectsSet || objects.contains(perm.getId())) {
|
||||||
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
|
if (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
|
||||||
perm.addAbility(ability, game);
|
for (Ability abilityToAdd : ability) {
|
||||||
|
perm.addAbility(abilityToAdd, game);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setAbility(Ability ability) {
|
||||||
|
this.ability = new CompoundAbility(ability);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ability getFirstAbility() {
|
||||||
|
return ability.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
private void setText() {
|
private void setText() {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
if (excludeSource)
|
if (excludeSource)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue