use of mage.MageObject in project mage by magefree.
the class JuxtaposeEffect method init.
@Override
public void init(Ability source, Game game) {
Player you = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (you != null && targetPlayer != null) {
Permanent permanent1 = chooseOnePermanentsWithTheHighestCMC(game, you, filter);
Permanent permanent2 = chooseOnePermanentsWithTheHighestCMC(game, targetPlayer, filter);
if (permanent1 != null && permanent2 != null) {
// exchange works only for two different controllers
if (permanent1.isControlledBy(permanent2.getControllerId())) {
// discard effect if controller of both permanents is the same
discard();
return;
}
this.lockedControllers.put(permanent1.getId(), permanent2.getControllerId());
this.zoneChangeCounter.put(permanent1.getId(), permanent1.getZoneChangeCounter(game));
this.lockedControllers.put(permanent2.getId(), permanent1.getControllerId());
this.zoneChangeCounter.put(permanent2.getId(), permanent2.getZoneChangeCounter(game));
permanent1.changeControllerId(targetPlayer.getId(), game, source);
permanent2.changeControllerId(you.getId(), game, source);
MageObject sourceObject = game.getCard(source.getSourceId());
game.informPlayers((sourceObject != null ? sourceObject.getLogName() : "") + ": " + you.getLogName() + " and " + targetPlayer.getLogName() + " exchange control of " + permanent1.getLogName() + " and " + permanent2.getName());
} else {
// discard if there are less than 2 permanents
discard();
}
}
}
use of mage.MageObject in project mage by magefree.
the class MedomaisProphecyLookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourcePermanentOrLKI(game);
if (controller == null || sourceObject == null) {
return false;
}
game.getState().getPlayersInRange(source.getControllerId(), game).stream().map(game::getPlayer).forEachOrdered(player -> controller.lookAtCards(sourceObject.getIdName() + " " + player.getName(), player.getLibrary().getFromTop(game), game));
return true;
}
use of mage.MageObject in project mage by magefree.
the class MutinyFirstTarget method canChoose.
@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
if (super.canChoose(sourceId, sourceControllerId, game)) {
UUID controllingPlayerId = game.getControllerId(sourceId);
for (UUID playerId : game.getOpponents(controllingPlayerId)) {
int possibleTargets = 0;
MageObject sourceObject = game.getObject(sourceId);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, playerId, game)) {
if (permanent.canBeTargetedBy(sourceObject, controllingPlayerId, game)) {
possibleTargets++;
}
}
if (possibleTargets > 1) {
return true;
}
}
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class MutinyFirstTarget method canTarget.
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
if (super.canTarget(controllerId, id, source, game)) {
// can only target, if the controller has at least two targetable creatures
UUID controllingPlayerId = game.getControllerId(id);
int possibleTargets = 0;
MageObject sourceObject = game.getObject(source.getId());
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controllingPlayerId, game)) {
if (permanent.canBeTargetedBy(sourceObject, controllerId, game)) {
possibleTargets++;
}
}
return possibleTargets > 1;
}
return false;
}
use of mage.MageObject in project mage by magefree.
the class MurmursFromBeyondEffect 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) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
if (!cards.isEmpty()) {
controller.revealCards(staticText, cards, game);
Card cardToGraveyard;
if (cards.size() == 1) {
cardToGraveyard = cards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, target, source, game);
opponent = game.getPlayer(target.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
opponent.chooseTarget(outcome, cards, target, source, game);
cardToGraveyard = game.getCard(target.getFirstTarget());
}
if (cardToGraveyard != null) {
controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
cards.remove(cardToGraveyard);
}
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
return false;
}
Aggregations