use of mage.players.Player in project mage by magefree.
the class FracturingGustDestroyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int destroyedPermanents = 0;
for (Permanent permanent : game.getState().getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
if (permanent.destroy(source, game, false)) {
++destroyedPermanents;
}
}
// needed in case a destroyed permanent did prevent life gain
game.getState().processAction(game);
if (destroyedPermanents > 0) {
controller.gainLife(2 * destroyedPermanents, game, source);
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class GlyphOfReincarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent targetWall = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (controller != null && targetWall != null) {
BlockedAttackerWatcher watcher = game.getState().getWatcher(BlockedAttackerWatcher.class);
if (watcher != null) {
Map<UUID, Player> destroyed = new HashMap<>();
for (Permanent creature : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
if (!creature.getId().equals(targetWall.getId())) {
if (watcher.creatureHasBlockedAttacker(new MageObjectReference(creature, game), new MageObjectReference(targetWall, game), game)) {
if (creature.destroy(source, game, true) && game.getState().getZone(creature.getId()) == Zone.GRAVEYARD) {
// If a commander is replaced to command zone, the creature does not die
Player permController = game.getPlayer(creature.getControllerId());
if (permController != null) {
destroyed.put(creature.getId(), permController);
}
}
}
}
}
// onto the battlefield under its owner’s control
for (Map.Entry<UUID, Player> entry : destroyed.entrySet()) {
Permanent permanent = (Permanent) game.getLastKnownInformation(entry.getKey(), Zone.BATTLEFIELD);
Player player = entry.getValue();
if (permanent != null && player != null) {
FilterCreatureCard filter = new FilterCreatureCard("a creature card from " + player.getName() + "'s graveyard");
filter.add(new OwnerIdPredicate(player.getId()));
Target targetCreature = new TargetCardInGraveyard(filter);
targetCreature.setNotTarget(true);
if (targetCreature.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, targetCreature, source, game)) {
Card card = game.getCard(targetCreature.getFirstTarget());
if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
}
}
return true;
}
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class GlowsporeShamanEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Target target = new TargetCardInYourGraveyard(0, 1, filter, true);
if (player.chooseUse(outcome, "Put a land card on top of your library?", source, game) && player.choose(outcome, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return player.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
}
}
return true;
}
use of mage.players.Player in project mage by magefree.
the class GoblinArchaeologistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (player != null && permanent != null) {
if (!player.flipCoin(source, game, true)) {
permanent.sacrifice(source, game);
} else {
Permanent targetArtifact = game.getPermanent(source.getFirstTarget());
targetArtifact.destroy(source, game, true);
permanent.untap(game);
}
return true;
}
return false;
}
use of mage.players.Player in project mage by magefree.
the class GoblinAssassinTriggeredEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> perms = new ArrayList<>();
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 && !player.flipCoin(source, game, false)) {
TargetControlledCreaturePermanent target = new TargetControlledCreaturePermanent();
target.setNotTarget(true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {
player.chooseTarget(Outcome.Sacrifice, target, source, game);
perms.addAll(target.getTargets());
}
}
}
for (UUID permID : perms) {
Permanent permanent = game.getPermanent(permID);
if (permanent != null) {
permanent.sacrifice(source, game);
}
}
return true;
}
return false;
}
Aggregations