use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class LoxodonPeacekeeperEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null) {
int lowLife = Integer.MAX_VALUE;
Set<UUID> tiedPlayers = new HashSet<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLife() < lowLife) {
lowLife = player.getLife();
}
}
}
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
if (player.getLife() == lowLife) {
tiedPlayers.add(playerId);
}
}
}
if (tiedPlayers.size() > 0) {
UUID newControllerId = null;
if (tiedPlayers.size() > 1) {
FilterPlayer filter = new FilterPlayer("a player tied for lowest life total");
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (!tiedPlayers.contains(playerId)) {
filter.add(Predicates.not(new PlayerIdPredicate(playerId)));
}
}
TargetPlayer target = new TargetPlayer(1, 1, true, filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
} else {
return false;
}
newControllerId = game.getPlayer(target.getFirstTarget()).getId();
} else {
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
if (tiedPlayers.contains(playerId)) {
newControllerId = playerId;
break;
}
}
}
if (newControllerId != null) {
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, newControllerId);
effect.setTargetPointer(new FixedTarget(sourcePermanent, game));
game.addEffect(effect, source);
game.informPlayers(game.getPlayer(newControllerId).getLogName() + " has gained control of " + sourcePermanent.getLogName());
return true;
}
}
}
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class MurderousSpoilsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent target = game.getPermanent(source.getFirstTarget());
if (target != null) {
List<Permanent> attachments = new ArrayList<>();
for (UUID uuid : target.getAttachments()) {
Permanent attached = game.getBattlefield().getPermanent(uuid);
if (attached.hasSubtype(SubType.EQUIPMENT, game)) {
attachments.add(attached);
}
}
for (Permanent p : attachments) {
ContinuousEffect gainControl = new GainControlTargetEffect(Duration.Custom);
gainControl.setTargetPointer(new FixedTarget(p, game));
game.addEffect(gainControl, source);
}
target.destroy(source, game, true);
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class AwakenElementalToken method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = null;
for (Target target : source.getTargets()) {
targetId = target.getFirstTarget();
}
if (targetId != null) {
FixedTarget fixedTarget = new FixedTarget(targetId, game);
ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.EndOfGame);
continuousEffect.setTargetPointer(fixedTarget);
game.addEffect(continuousEffect, source);
Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(3));
effect.setTargetPointer(fixedTarget);
return effect.apply(game, source);
}
return true;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class NullstoneGargoyleTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getSpell(event.getTargetId());
if (spell.isCreature(game)) {
return false;
}
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher != null && watcher.getNumberOfNonCreatureSpells() == 1) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
return false;
}
use of mage.target.targetpointer.FixedTarget in project mage by magefree.
the class NorrittDelayedDestroyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
DestroyTargetEffect effect = new DestroyTargetEffect();
effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY, new InvertCondition(TargetAttackedThisTurnCondition.instance));
delayedAbility.getDuration();
delayedAbility.getTargets().addAll(source.getTargets());
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
Aggregations