use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class ElvishBranchbenderToken method apply.
@Override
public boolean apply(Game game, Ability source) {
int xValue = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
// fix
ContinuousEffect effect = new BecomesCreatureTargetEffect(new ElvishBranchbenderToken(xValue), false, false, Duration.EndOfTurn);
effect.setTargetPointer(targetPointer);
game.addEffect(effect, source);
return false;
}
use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class IncandescentSoulstokeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
FilterCard filter = new FilterCreatureCard();
filter.add(SubType.ELEMENTAL.getPredicate());
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
}
}
}
}
return true;
}
return false;
}
use of mage.abilities.effects.ContinuousEffect in project mage by magefree.
the class ImpromptuRaidEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
Cards cards = new CardsImpl();
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (filterPutInGraveyard.match(card, source.getSourceId(), source.getControllerId(), game)) {
controller.moveCards(card, Zone.GRAVEYARD, source, game);
return true;
}
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("", source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
}
}
return false;
}
use of mage.abilities.effects.ContinuousEffect 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.abilities.effects.ContinuousEffect 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;
}
Aggregations