use of mage.game.permanent.Permanent 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.game.permanent.Permanent in project mage by magefree.
the class JuxtaposeEffect method getPermanentsWithTheHighestCMC.
private List<Permanent> getPermanentsWithTheHighestCMC(Game game, UUID playerId, FilterPermanent filter) {
List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, playerId, game);
int highestCMC = -1;
for (Permanent permanent : permanents) {
if (highestCMC < permanent.getManaValue()) {
highestCMC = permanent.getManaValue();
}
}
List<Permanent> result = new ArrayList<>();
for (Permanent permanent : permanents) {
if (permanent.getManaValue() == highestCMC) {
result.add(permanent);
}
}
return result;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class KalainReclusivePainterEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
if (creature == null) {
return false;
}
int manaPaid = ManaPaidSourceWatcher.getTreasurePaid(creature.getId(), game);
if (manaPaid < 1) {
return false;
}
creature.addCounters(CounterType.P1P1.createInstance(manaPaid), source.getControllerId(), source, game, event.getAppliedEffects());
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class KaerveksPurgeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
// Destroy target creature with converted mana cost X.
Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
if (targetCreature != null && targetCreature.destroy(source, game, false)) {
game.getState().processAction(game);
if (targetCreature.getZoneChangeCounter(game) + 1 == game.getState().getZoneChangeCounter(targetCreature.getId()) && game.getState().getZone(targetCreature.getId()) != Zone.GRAVEYARD) {
// A replacement effect has moved the card to another zone as graveyard
return true;
}
// If that creature dies this way, Kaervek's Purge deals damage equal to the creature's power to the creature's controller
Player creatureController = game.getPlayer(targetCreature.getControllerId());
int power = targetCreature.getPower().getValue();
if (creatureController != null) {
creatureController.damage(power, source.getSourceId(), source, game);
}
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class KaaliaOfTheVastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, "Put an Angel, Demon, or Dragon creature card from your hand onto the battlefield tapped and attacking?", source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(outcome, controller.getId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
UUID cardId = target.getFirstTarget();
Card card = game.getCard(cardId);
if (card != null && game.getCombat() != null) {
UUID defenderId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
if (defenderId != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent creature = game.getPermanent(cardId);
if (creature != null) {
game.getCombat().addAttackerToCombat(card.getId(), defenderId, game);
return true;
}
}
}
}
}
return false;
}
Aggregations