mirror of
https://github.com/correl/mage.git
synced 2024-12-26 11:09:27 +00:00
can now add Abilities to players
This commit is contained in:
parent
9f922c6a2a
commit
6660c6eece
5 changed files with 65 additions and 48 deletions
|
@ -30,12 +30,12 @@ package mage.sets.magic2011;
|
|||
|
||||
import java.util.UUID;
|
||||
import mage.Constants.CardType;
|
||||
import mage.Constants.Duration;
|
||||
import mage.Constants.Rarity;
|
||||
import mage.Constants.TargetController;
|
||||
import mage.Constants.Zone;
|
||||
import mage.abilities.common.SimpleStaticAbility;
|
||||
import mage.abilities.effects.common.CantTargetControllerEffect;
|
||||
import mage.abilities.effects.common.continious.GainAbilityControllerEffect;
|
||||
import mage.abilities.keyword.HexproofAbility;
|
||||
import mage.abilities.keyword.LeylineAbility;
|
||||
import mage.cards.CardImpl;
|
||||
import mage.filter.FilterStackObject;
|
||||
|
@ -57,7 +57,7 @@ public class LeylineOfSanctity extends CardImpl<LeylineOfSanctity> {
|
|||
this.expansionSetCode = "M11";
|
||||
this.color.setWhite(true);
|
||||
this.addAbility(LeylineAbility.getInstance());
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new CantTargetControllerEffect(filter, Duration.WhileOnBattlefield)));
|
||||
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityControllerEffect(HexproofAbility.getInstance())));
|
||||
}
|
||||
|
||||
public LeylineOfSanctity(final LeylineOfSanctity card) {
|
||||
|
|
|
@ -329,6 +329,25 @@ public class ContinuousEffects implements Serializable {
|
|||
}
|
||||
}
|
||||
}
|
||||
//get all applicable Replacement effects on players
|
||||
for (Player player: game.getPlayers().values()) {
|
||||
for (Ability ability: player.getAbilities().getStaticAbilities(Zone.BATTLEFIELD)) {
|
||||
for (Effect effect: ability.getEffects(game, EffectType.REPLACEMENT)) {
|
||||
ReplacementEffect rEffect = (ReplacementEffect) effect;
|
||||
if (rEffect.applies(event, ability, game)) {
|
||||
replaceEffects.add(rEffect);
|
||||
abilityMap.put(rEffect.getId(), ability);
|
||||
}
|
||||
}
|
||||
for (Effect effect: ability.getEffects(game, EffectType.PREVENTION)) {
|
||||
ReplacementEffect rEffect = (ReplacementEffect) effect;
|
||||
if (rEffect.applies(event, ability, game)) {
|
||||
replaceEffects.add(rEffect);
|
||||
abilityMap.put(rEffect.getId(), ability);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//get all applicable transient Replacement effects
|
||||
for (ReplacementEffect effect: replacementEffects) {
|
||||
if (effect.getDuration() != Duration.OneUse || !effect.isUsed()) {
|
||||
|
|
|
@ -26,69 +26,57 @@
|
|||
* or implied, of BetaSteward_at_googlemail.com.
|
||||
*/
|
||||
|
||||
package mage.abilities.effects.common;
|
||||
package mage.abilities.effects.common.continious;
|
||||
|
||||
import mage.Constants.Duration;
|
||||
import mage.Constants.Layer;
|
||||
import mage.Constants.Outcome;
|
||||
import mage.Constants.SubLayer;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.effects.ReplacementEffectImpl;
|
||||
import mage.filter.FilterStackObject;
|
||||
import mage.abilities.effects.ContinuousEffectImpl;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.GameEvent.EventType;
|
||||
import mage.game.stack.StackObject;
|
||||
import mage.players.Player;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author BetaSteward_at_googlemail.com
|
||||
*/
|
||||
public class CantTargetControllerEffect extends ReplacementEffectImpl<CantTargetControllerEffect> {
|
||||
public class GainAbilityControllerEffect extends ContinuousEffectImpl<GainAbilityControllerEffect> {
|
||||
|
||||
private FilterStackObject filterSource;
|
||||
protected Ability ability;
|
||||
|
||||
public CantTargetControllerEffect(FilterStackObject filterSource, Duration duration) {
|
||||
super(duration, Outcome.Benefit);
|
||||
this.filterSource = filterSource;
|
||||
setText();
|
||||
/**
|
||||
* Add ability with Duration.WhileOnBattlefield
|
||||
* @param ability
|
||||
*/
|
||||
public GainAbilityControllerEffect(Ability ability) {
|
||||
this(ability, Duration.WhileOnBattlefield);
|
||||
}
|
||||
|
||||
public CantTargetControllerEffect(final CantTargetControllerEffect effect) {
|
||||
public GainAbilityControllerEffect(Ability ability, Duration duration) {
|
||||
super(duration, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
|
||||
this.ability = ability;
|
||||
staticText = "You have " + ability.getRule() + " " + duration.toString();
|
||||
}
|
||||
|
||||
public GainAbilityControllerEffect(final GainAbilityControllerEffect effect) {
|
||||
super(effect);
|
||||
this.filterSource = effect.filterSource.copy();
|
||||
this.ability = effect.ability.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CantTargetControllerEffect copy() {
|
||||
return new CantTargetControllerEffect(this);
|
||||
public GainAbilityControllerEffect copy() {
|
||||
return new GainAbilityControllerEffect(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||
if (event.getType() == EventType.TARGET && event.getTargetId().equals(source.getControllerId())) {
|
||||
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
|
||||
if (sourceObject != null && filterSource.match(sourceObject)) {
|
||||
return true;
|
||||
}
|
||||
Player player = game.getPlayer(source.getControllerId());
|
||||
if (player != null) {
|
||||
player.addAbility(ability);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void setText() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("You can't be the targets of ");
|
||||
sb.append(filterSource.getMessage());
|
||||
sb.append(" ").append(duration.toString());
|
||||
staticText = sb.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -80,6 +80,7 @@ public interface Player extends MageItem, Copyable<Player> {
|
|||
public Library getLibrary();
|
||||
public Cards getGraveyard();
|
||||
public Abilities<Ability> getAbilities();
|
||||
public void addAbility(Ability ability);
|
||||
public Counters getCounters();
|
||||
public int getLife();
|
||||
public void setLife(int life, Game game);
|
||||
|
|
|
@ -420,11 +420,14 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
@Override
|
||||
public boolean discard(Card card, Ability source, Game game) {
|
||||
//20100716 - 701.7
|
||||
removeFromHand(card, game);
|
||||
card.moveToZone(Zone.GRAVEYARD, source==null?null:source.getId(), game, false);
|
||||
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, card.getId(), source==null?null:source.getId(), playerId));
|
||||
return true;
|
||||
if (card != null) {
|
||||
removeFromHand(card, game);
|
||||
card.moveToZone(Zone.GRAVEYARD, source==null?null:source.getId(), game, false);
|
||||
|
||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, card.getId(), source==null?null:source.getId(), playerId));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -917,6 +920,12 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
public Abilities getAbilities() {
|
||||
return this.abilities;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAbility(Ability ability) {
|
||||
ability.setSourceId(playerId);
|
||||
this.abilities.add(ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLandsPerTurn() {
|
||||
|
@ -955,7 +964,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
|
|||
this.library = player.getLibrary();
|
||||
this.hand = player.getHand();
|
||||
this.graveyard = player.getGraveyard();
|
||||
this.abilities = player.getAbilities();
|
||||
// this.abilities = player.getAbilities();
|
||||
this.manaPool = player.getManaPool();
|
||||
this.life = player.getLife();
|
||||
this.counters = player.getCounters();
|
||||
|
|
Loading…
Reference in a new issue