mirror of
https://github.com/correl/mage.git
synced 2025-02-19 11:07:01 +00:00
CompoundAbility
This commit is contained in:
parent
d9e0590763
commit
1acf00a5da
2 changed files with 86 additions and 9 deletions
Mage/src/mage/abilities
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.SubLayer;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.CompoundAbility;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.filter.FilterPermanent;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilityControlledEffect> {
|
||||
|
||||
protected Ability ability;
|
||||
protected CompoundAbility ability;
|
||||
protected boolean excludeSource;
|
||||
protected FilterPermanent filter;
|
||||
|
||||
|
@ -52,11 +52,23 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
|||
this(ability, duration, new FilterPermanent());
|
||||
}
|
||||
|
||||
public GainAbilityControlledEffect(CompoundAbility ability, Duration duration) {
|
||||
this(ability, duration, new FilterPermanent());
|
||||
}
|
||||
|
||||
public GainAbilityControlledEffect(Ability ability, Duration duration, FilterPermanent filter) {
|
||||
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) {
|
||||
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);
|
||||
this.ability = ability;
|
||||
this.filter = filter;
|
||||
|
@ -75,7 +87,7 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
|||
public void init(Ability source, Game game) {
|
||||
super.init(source, game);
|
||||
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()))) {
|
||||
objects.add(perm.getId());
|
||||
}
|
||||
|
@ -90,25 +102,35 @@ public class GainAbilityControlledEffect extends ContinuousEffectImpl<GainAbilit
|
|||
|
||||
@Override
|
||||
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 (!(excludeSource && perm.getId().equals(source.getSourceId()))) {
|
||||
perm.addAbility(ability, game);
|
||||
for (Ability abilityToAdd : ability) {
|
||||
perm.addAbility(abilityToAdd, game);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setAbility(Ability ability) {
|
||||
this.ability = new CompoundAbility(ability);
|
||||
}
|
||||
|
||||
public Ability getFirstAbility() {
|
||||
return ability.get(0);
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (excludeSource)
|
||||
sb.append("Other ");
|
||||
sb.append(filter.getMessage()).append(" you control ");
|
||||
if (duration.equals(Duration.WhileOnBattlefield))
|
||||
sb.append("have ");
|
||||
else
|
||||
sb.append("gain ");
|
||||
if (duration.equals(Duration.WhileOnBattlefield))
|
||||
sb.append("have ");
|
||||
else
|
||||
sb.append("gain ");
|
||||
sb.append(ability.getRule()).append(" ").append(duration.toString());
|
||||
staticText = sb.toString();
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue