use of mage.game.permanent.Permanent in project mage by magefree.
the class BattleForBretagardTarget method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> possibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<String> names = this.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
names.removeIf(Objects::isNull);
names.removeIf(String::isEmpty);
possibleTargets.removeIf(uuid -> {
Permanent permanent = game.getPermanent(uuid);
return permanent == null || names.contains(permanent.getName());
});
return possibleTargets;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BattleForBretagardTarget method canTarget.
@Override
public boolean canTarget(UUID playerId, UUID id, Ability ability, Game game) {
if (!super.canTarget(playerId, id, ability, game)) {
return false;
}
Set<String> names = this.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
names.removeIf(Objects::isNull);
names.removeIf(String::isEmpty);
Permanent permanent = game.getPermanent(id);
return permanent != null && !names.contains(permanent.getName());
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BarrinsSpiteEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = source.getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
if (permanents.isEmpty()) {
return false;
}
if (permanents.size() == 1) {
permanents.get(0).sacrifice(source, game);
return true;
}
if (permanents.size() > 2) {
throw new IllegalStateException("Too many permanents in list, shouldn't be possible");
}
Player player = game.getPlayer(permanents.get(0).getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player == null || controller == null) {
return false;
}
Permanent perm1 = permanents.get(0);
Permanent perm2 = permanents.get(1);
if (player.chooseUse(outcome, "Choose which permanent to sacrifice", "The other will be returned to your hand", perm1.getIdName(), perm2.getIdName(), source, game)) {
perm1.sacrifice(source, game);
controller.moveCards(perm2, Zone.HAND, source, game);
return true;
}
perm2.sacrifice(source, game);
controller.moveCards(perm1, Zone.HAND, source, game);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BeamsplitterMageApplier method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Spell spell = (Spell) getValue("spellCast");
if (player == null || spell == null) {
return false;
}
FilterPermanent filter = new FilterControlledCreaturePermanent("a creature you control that can be targeted by " + spell.getName());
filter.add(AnotherPredicate.instance);
filter.add(new BeamsplitterMagePredicate(spell));
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
player.choose(outcome, target, source.getSourceId(), game);
Permanent permanent = game.getPermanent(target.getFirstTarget());
if (permanent == null) {
return false;
}
spell.createCopyOnStack(game, source, player.getId(), false, 1, new BeamsplitterMageApplier(permanent, game));
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class BazaarTraderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
Permanent permanent = targetPermanentReference.getPermanent(game);
if (player != null && permanent != null) {
return permanent.changeControllerId(player.getId(), game, source);
} else {
discard();
}
return false;
}
Aggregations