use of mage.target.TargetPermanent in project mage by magefree.
the class ResoluteStrikeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getFirstTarget());
if (player == null || permanent == null || !permanent.hasSubtype(SubType.WARRIOR, game) || game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) == 0 || !player.chooseUse(outcome, "Attach an equipment you control?", source, game)) {
return false;
}
TargetPermanent targetPermanent = new TargetPermanent(0, 1, filter, true);
player.choose(outcome, targetPermanent, source.getSourceId(), game);
return permanent.addAttachment(targetPermanent.getFirstTarget(), source, game);
}
use of mage.target.TargetPermanent in project mage by magefree.
the class SabaccGameEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent targetPermanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (targetPermanent != null) {
Player opponent = game.getPlayer(targetPermanent.getControllerId());
if (opponent != null) {
FilterPermanent filter = new FilterPermanent("permanent controlled by " + controller.getName());
filter.add(new ControllerIdPredicate(controller.getId()));
TargetPermanent target = new TargetPermanent(1, 1, filter, true);
Permanent chosenPermanent = null;
if (target.chooseTarget(outcome, opponent.getId(), source, game)) {
chosenPermanent = game.getPermanent(target.getFirstTarget());
}
boolean flipWin = controller.flipCoin(source, game, true);
if (flipWin) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, controller.getId());
effect.setTargetPointer(new FixedTarget(targetPermanent, game));
game.addEffect(effect, source);
} else if (chosenPermanent != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
effect.setTargetPointer(new FixedTarget(chosenPermanent, game));
game.addEffect(effect, source);
}
}
}
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class RustmouthOgreTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
if (damageEvent.isCombatDamage() && event.getSourceId().equals(this.getSourceId())) {
FilterArtifactPermanent filter = new FilterArtifactPermanent("artifact that player controls");
filter.add(new ControllerIdPredicate(event.getPlayerId()));
filter.setMessage("artifact controlled by " + game.getPlayer(event.getTargetId()).getLogName());
this.getTargets().clear();
this.addTarget(new TargetPermanent(filter));
return true;
}
return false;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class SigardasVanguardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetPermanent target = new TargetCreaturesWithDifferentPowers();
player.choose(outcome, target, source.getSourceId(), game);
if (target.getTargets().isEmpty()) {
return false;
}
game.addEffect(new GainAbilityTargetEffect(DoubleStrikeAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTargets(new CardsImpl(target.getTargets()), game)), source);
return true;
}
use of mage.target.TargetPermanent in project mage by magefree.
the class SlaughterTheStrongEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
boolean selectionDone = false;
Set<UUID> selectedCreatures = new HashSet<>();
while (player.canRespond() && selectionDone == false) {
int powerSum = 0;
for (UUID creatureId : selectedCreatures) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
powerSum += creature.getPower().getValue();
}
}
FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
if (!selectedCreatures.isEmpty()) {
for (UUID creatureId : selectedCreatures) {
alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
}
currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
} else {
currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
}
// human can de-select targets, but AI must choose only one time
Target target;
if (player.isComputer()) {
// AI settings
FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
selectedCreatures.stream().forEach(id -> {
strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
});
target = new TargetPermanent(0, 1, strictFilter, true);
} else {
// Human settings
target = new TargetPermanent(0, 1, currentFilter, true);
}
player.chooseTarget(Outcome.BoostCreature, target, source, game);
if (target.getFirstTarget() != null) {
if (selectedCreatures.contains(target.getFirstTarget())) {
selectedCreatures.remove(target.getFirstTarget());
} else {
selectedCreatures.add(target.getFirstTarget());
}
} else {
if (player.isComputer()) {
// AI stops
selectionDone = true;
} else {
// Human can continue
String selected = "Selected: ";
for (UUID creatureId : selectedCreatures) {
Permanent creature = game.getPermanent(creatureId);
if (creature != null) {
selected += creature.getLogName() + " ";
}
}
selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
}
}
}
for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
if (!selectedCreatures.contains(creature.getId())) {
creature.sacrifice(source, game);
}
}
}
}
return true;
}
return false;
}
Aggregations