use of mage.target.TargetPermanent in project mage by magefree.
the class CruelRealityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player cursedPlayer = game.getPlayer(targetPointer.getFirst(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (cursedPlayer == null || controller == null) {
return false;
}
TargetPermanent target = new TargetPermanent(filter);
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), cursedPlayer.getId(), game) && cursedPlayer.choose(Outcome.Sacrifice, target, source.getId(), game)) {
Permanent objectToBeSacrificed = game.getPermanent(target.getFirstTarget());
if (objectToBeSacrificed != null) {
if (objectToBeSacrificed.sacrifice(source, game)) {
return true;
}
}
}
cursedPlayer.loseLife(5, game, source, false);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class CurseOfInertiaTapOrUntapTargetEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanent(this.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null && game.getCombat().getPlayerDefenders(game, false).contains(enchantment.getAttachedTo())) {
TargetPermanent target = new TargetPermanent();
target.setTargetController(game.getCombat().getAttackingPlayerId());
addTarget(target);
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class ExpropriateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
// Outcome.Detriment - AI will gain control all the time (Money choice)
// TODO: add AI hint logic in the choice method, see Tyrant's Choice as example
TwoChoiceVote vote = new TwoChoiceVote("Time (extra turn)", "Money (gain control)", Outcome.Detriment);
vote.doVotes(source, game);
// extra turn
int timeCount = vote.getVoteCount(true);
for (int i = 0; i < timeCount; i++) {
game.getState().getTurnMods().add(new TurnMod(source.getControllerId(), false));
}
// gain control
if (vote.getVoteCount(false) < 1) {
return true;
}
List<Permanent> toSteal = new ArrayList<>();
for (UUID playerId : vote.getVotedFor(false)) {
int moneyCount = vote.getVotes(playerId).stream().mapToInt(x -> x ? 0 : 1).sum();
FilterPermanent filter = new FilterPermanent();
filter.add(new ControllerIdPredicate(playerId));
moneyCount = Math.min(game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game), moneyCount);
if (moneyCount == 0) {
continue;
}
TargetPermanent target = new TargetPermanent(moneyCount, filter);
target.setNotTarget(true);
player.choose(Outcome.GainControl, target, source.getSourceId(), game);
target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(toSteal::add);
}
game.addEffect(new GainControlTargetEffect(Duration.Custom, true, source.getControllerId()).setTargetPointer(new FixedTargets(toSteal, game)), source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class GodEternalBontuEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
if (!player.choose(outcome, target, source.getSourceId(), game)) {
return false;
}
int counter = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.sacrifice(source, game)) {
counter++;
}
}
return player.drawCards(counter, source, game) > 0;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class HarmonyOfNatureEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetPermanent target = new TargetControlledPermanent(0, Integer.MAX_VALUE, HarmonyOfNature.filter, true);
controller.choose(outcome, target, source.getSourceId(), game);
if (target.getTargets().isEmpty()) {
return false;
}
int tappedAmount = 0;
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null && permanent.tap(source, game)) {
tappedAmount++;
}
}
if (tappedAmount > 0) {
controller.gainLife(tappedAmount * 4, game, source);
}
return true;
}
Aggregations