Added can cast cards from graveyard flag to player.

This commit is contained in:
LevelX2 2014-05-31 22:15:52 +02:00
parent 86a6251997
commit ab721bc1c2
4 changed files with 47 additions and 1 deletions

View file

@ -35,6 +35,7 @@ import mage.constants.Zone;
import mage.abilities.keyword.ProtectionAbility;
import mage.abilities.mana.ManaAbility;
import mage.game.Game;
import mage.players.Player;
/**
* Represents a collection of {@link Ability Abilities}. This is the top most
@ -71,6 +72,16 @@ public interface Abilities<T extends Ability> extends List<T>, Serializable {
*/
Abilities<ActivatedAbility> getActivatedAbilities(Zone zone);
/**
* Retrieves all playable abilities for the given {@link Zone}.
*
* @param zone The {@link Zone} for which abilities should be retrieved.
* @return All abilities for the given {@link Zone}
*
* @see mage.cards.CardImpl#getSpellAbility()
*/
Abilities<ActivatedAbility> getPlayableAbilities(Zone zone);
/**
* Retrieves all {@link ManaAbility mana abilities} in the given {@link Zone}.
*

View file

@ -129,6 +129,18 @@ public class AbilitiesImpl<T extends Ability> extends ArrayList<T> implements Ab
return zonedAbilities;
}
@Override
public Abilities<ActivatedAbility> getPlayableAbilities(Zone zone) {
Abilities<ActivatedAbility> zonedAbilities = new AbilitiesImpl<>();
for (T ability: this) {
if (((ability instanceof SpellAbility) || (ability instanceof PlayLandAbility))
&& ability.getZone().match(zone)) {
zonedAbilities.add((ActivatedAbility)ability);
}
}
return zonedAbilities;
}
@Override
public Abilities<ManaAbility> getManaAbilities(Zone zone) {
Abilities<ManaAbility> abilities = new AbilitiesImpl<>();

View file

@ -102,8 +102,10 @@ public interface Player extends MageItem, Copyable<Player> {
boolean canPaySacrificeCost();
void setLifeTotalCanChange(boolean lifeTotalCanChange);
boolean isLifeTotalCanChange();
void setLoseByZeroOrLessLife(boolean LoseByZeroOrLessLife);
void setLoseByZeroOrLessLife(boolean loseByZeroOrLessLife);
boolean canLoseByZeroOrLessLife();
void setPlayCardsFromGraveyard(boolean playCardsFromGraveyard);
boolean canPlayCardsFromGraveyard();
/**
* Returns alternative casting costs a player can cast spells for

View file

@ -179,6 +179,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
protected boolean canPayLifeCost = true;
protected boolean canPaySacrificeCost = true;
protected boolean loseByZeroOrLessLife = true;
protected boolean canPlayCardsFromGraveyard = true;
protected final List<AlternativeSourceCosts> alternativeSourceCosts = new ArrayList<>();
@ -249,6 +250,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.canGainLife = player.canGainLife;
this.canLoseLife = player.canLoseLife;
this.loseByZeroOrLessLife = player.loseByZeroOrLessLife;
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard;
this.attachments.addAll(player.attachments);
@ -313,6 +315,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.canPayLifeCost = player.canPayLifeCost();
this.canPaySacrificeCost = player.canPaySacrificeCost();
this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts());
this.storedBookmark = player.getStoredBookmark();
@ -388,6 +391,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.canPayLifeCost = true;
this.canPaySacrificeCost = true;
this.loseByZeroOrLessLife = true;
this.canPlayCardsFromGraveyard = false;
this.topCardRevealed = false;
this.alternativeSourceCosts.clear();
}
@ -967,6 +971,13 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
}
}
if (zone != Zone.HAND) {
if (Zone.GRAVEYARD.equals(zone) && canPlayCardsFromGraveyard()) {
for (ActivatedAbility ability: object.getAbilities().getPlayableAbilities(Zone.HAND)) {
if (ability.canActivate(playerId, game)) {
useable.put(ability.getId(), ability);
}
}
}
if (zone != Zone.BATTLEFIELD && game.getContinuousEffects().asThough(object.getId(), AsThoughEffectType.CAST, this.getId(), game)) {
for (Ability ability: object.getAbilities()) {
ability.setControllerId(this.getId());
@ -2117,6 +2128,16 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
this.loseByZeroOrLessLife = loseByZeroOrLessLife;
}
@Override
public boolean canPlayCardsFromGraveyard() {
return canPlayCardsFromGraveyard;
}
@Override
public void setPlayCardsFromGraveyard(boolean playCardsFromGraveyard) {
this.canPlayCardsFromGraveyard = playCardsFromGraveyard;
}
@Override
public boolean autoLoseGame() {
return false;