use of mage.abilities.PlayLandAbility in project mage by magefree.
the class WordOfCommandTestFlashEffect method checkPlayability.
private boolean checkPlayability(Card card, Player targetPlayer, Game game, Ability source) {
// check for card playability
boolean canPlay = false;
if (card.isLand(game)) {
// we can't use getPlayableObjects(game) in here because it disallows playing lands outside the main step // TODO: replace to getPlayable() checks with disable step condition?
if (targetPlayer.canPlayLand() && game.getActivePlayerId().equals(targetPlayer.getId())) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof PlayLandAbility) {
if (!game.getContinuousEffects().preventedByRuleModification(GameEvent.getEvent(GameEvent.EventType.PLAY_LAND, ability.getSourceId(), ability, targetPlayer.getId()), ability, game, true)) {
canPlay = true;
}
}
}
}
} else {
// Word of Command allows the chosen card to be played "as if it had flash" so we need to invoke such effect to bypass the check
AsThoughEffectImpl effect2 = new WordOfCommandTestFlashEffect();
game.addEffect(effect2, source);
if (targetPlayer.getPlayableObjects(game, Zone.HAND).containsObject(card.getId())) {
canPlay = true;
}
for (AsThoughEffect eff : game.getContinuousEffects().getApplicableAsThoughEffects(AsThoughEffectType.CAST_AS_INSTANT, game)) {
if (eff instanceof WordOfCommandTestFlashEffect) {
eff.discard();
break;
}
}
}
return canPlay;
}
use of mage.abilities.PlayLandAbility in project mage by magefree.
the class PlayFromNotOwnHandZoneTargetEffect method applies.
@Override
public boolean applies(UUID objectId, Ability affectedAbility, Ability source, Game game, UUID playerId) {
if (affectedAbility == null) {
// AsThough effect types in one conditional effect
throw new IllegalArgumentException("ERROR, can't call applies method on empty affectedAbility");
}
// invalid targets
List<UUID> targets = getTargetPointer().getTargets(game, source);
if (targets.isEmpty()) {
this.discard();
return false;
}
// invalid zone
if (!game.getState().getZone(objectId).match(fromZone)) {
return false;
}
// invalid caster
switch(allowedCaster) {
case YOU:
if (playerId != source.getControllerId()) {
return false;
}
break;
case OPPONENT:
if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
return false;
}
break;
case OWNER:
if (playerId != game.getCard(objectId).getOwnerId()) {
return false;
}
break;
case ANY:
break;
}
// targets goes to main card all the time
UUID objectIdToCast = CardUtil.getMainCardId(game, objectId);
if (!targets.contains(objectIdToCast)) {
return false;
}
// if can't play lands
if (!affectedAbility.getAbilityType().isPlayCardAbility() || onlyCastAllowed && affectedAbility instanceof PlayLandAbility) {
return false;
}
// OK, allow to play
if (withoutMana) {
allowCardToPlayWithoutMana(objectId, source, playerId, game);
}
return true;
}
use of mage.abilities.PlayLandAbility in project mage by magefree.
the class PlayableObjectRecord method load.
public void load(List<ActivatedAbility> activatedAbilities) {
this.basicManaAbilities.clear();
this.basicPlayAbilities.clear();
this.basicCastAbilities.clear();
this.other.clear();
// split abilities to types (it allows to enable or disable playable icon)
for (ActivatedAbility ability : activatedAbilities) {
List<PlayableObjectRecord> dest;
if (ability instanceof BasicManaAbility) {
dest = this.basicManaAbilities;
} else if (ability instanceof PlayLandAbility) {
dest = this.basicPlayAbilities;
} else if (ability instanceof SpellAbility && (((SpellAbility) ability).getSpellAbilityType() == SpellAbilityType.BASE)) {
dest = this.basicCastAbilities;
} else {
dest = this.other;
}
// collect info about abilities for card icons popup, must be simple online text (html symbols are possible)
// some long html tags can be miss (example: ability extra hint) -- that's ok
String shortInfo = ability.toString();
if (shortInfo.length() > 50) {
shortInfo = shortInfo.substring(0, 50 - 1) + "...";
}
shortInfo = shortInfo.replace("<br>", " ");
shortInfo = shortInfo.replace("\n", " ");
dest.add(new PlayableObjectRecord(ability.getId(), shortInfo));
}
}
Aggregations