[M21] Fix castability and selectability of EnthrallingHold (#6773)

This commit is contained in:
htrajan 2020-07-02 20:16:31 -07:00 committed by GitHub
parent b6b7a9c0f9
commit 91571df264
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 77 deletions

View file

@ -0,0 +1,60 @@
package mage.target.common;
import mage.abilities.Ability;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.TargetPermanent;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;
public class TargetTappedPermanentAsYouCast extends TargetPermanent {
public TargetTappedPermanentAsYouCast() {}
public TargetTappedPermanentAsYouCast(FilterPermanent filter) {
this.filter = filter;
this.targetName = filter.getMessage();
}
private TargetTappedPermanentAsYouCast(TargetTappedPermanentAsYouCast target) {
super(target);
}
@Override
public TargetTappedPermanentAsYouCast copy() {
return new TargetTappedPermanentAsYouCast(this);
}
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
.filter(Permanent::isTapped)
.map(Permanent::getId)
.collect(Collectors.toSet());
}
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
return game.getBattlefield().getAllActivePermanents(getFilter(), game).stream()
.anyMatch(Permanent::isTapped);
}
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
if (super.canTarget(controllerId, id, source, game)) {
Permanent permanent = game.getPermanent(id);
return permanent != null && permanent.isTapped();
}
return false;
}
// See ruling: https://www.mtgsalvation.com/forums/magic-fundamentals/magic-rulings/magic-rulings-archives/253345-dream-leash
@Override
public boolean stillLegalTarget(UUID id, Ability source, Game game) {
Permanent permanent = game.getPermanent(id);
return permanent != null && getFilter().match(permanent, game);
}
}