use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class PlayerImpl method restore.
@Override
public void restore(Player player) {
this.name = player.getName();
this.human = player.isHuman();
this.life = player.getLife();
this.passed = player.isPassed();
// Don't restore more global states. If restored they are probably cause for unintended draws (https://github.com/magefree/mage/issues/1205).
// this.wins = player.hasWon();
// this.loses = player.hasLost();
// this.left = player.hasLeft();
// this.quit = player.hasQuit();
// Makes no sense to restore
// this.priorityTimeLeft = player.getPriorityTimeLeft();
// this.idleTimeout = player.hasIdleTimeout();
// this.timerTimeout = player.hasTimerTimeout();
// can't change so no need to restore
// this.isTestMode = player.isTestMode();
// This is meta data and should'nt be restored by rollback
// this.userData = player.getUserData();
this.library = player.getLibrary().copy();
this.sideboard = player.getSideboard().copy();
this.hand = player.getHand().copy();
this.graveyard = player.getGraveyard().copy();
// noinspection deprecation - it's ok to use it in inner methods
this.commandersIds = new HashSet<>(player.getCommandersIds());
this.abilities = player.getAbilities().copy();
this.counters = player.getCounters().copy();
this.landsPlayed = player.getLandsPlayed();
this.landsPerTurn = player.getLandsPerTurn();
this.loyaltyUsePerTurn = player.getLoyaltyUsePerTurn();
this.maxHandSize = player.getMaxHandSize();
this.maxAttackedBy = player.getMaxAttackedBy();
this.manaPool = player.getManaPool().copy();
// Restore user specific settings in case changed since state save
this.manaPool.setAutoPayment(this.getUserData().isManaPoolAutomatic());
this.manaPool.setAutoPaymentRestricted(this.getUserData().isManaPoolAutomaticRestricted());
this.turns = player.getTurns();
this.range = player.getRange();
this.canGainLife = player.isCanGainLife();
this.canLoseLife = player.isCanLoseLife();
this.attachments.clear();
this.attachments.addAll(player.getAttachments());
this.inRange.clear();
this.inRange.addAll(player.getInRange());
this.canPayLifeCost = player.getCanPayLifeCost();
this.sacrificeCostFilter = player.getSacrificeCostFilter() != null ? player.getSacrificeCostFilter().copy() : null;
this.loseByZeroOrLessLife = player.canLoseByZeroOrLessLife();
this.canPlayCardsFromGraveyard = player.canPlayCardsFromGraveyard();
this.drawsOnOpponentsTurn = player.isDrawsOnOpponentsTurn();
this.alternativeSourceCosts.clear();
this.alternativeSourceCosts.addAll(player.getAlternativeSourceCosts());
this.topCardRevealed = player.isTopCardRevealed();
this.playersUnderYourControl.clear();
this.playersUnderYourControl.addAll(player.getPlayersUnderYourControl());
this.isGameUnderControl = player.isGameUnderControl();
this.turnController = player.getTurnControlledBy();
this.turnControllers.clear();
this.turnControllers.addAll(player.getTurnControllers());
this.reachedNextTurnAfterLeaving = player.hasReachedNextTurnAfterLeaving();
this.clearCastSourceIdManaCosts();
this.castSourceIdWithAlternateMana.clear();
this.castSourceIdWithAlternateMana.addAll(player.getCastSourceIdWithAlternateMana());
for (Entry<UUID, ManaCosts<ManaCost>> entry : player.getCastSourceIdManaCosts().entrySet()) {
this.castSourceIdManaCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
}
for (Entry<UUID, Costs<Cost>> entry : player.getCastSourceIdCosts().entrySet()) {
this.castSourceIdCosts.put(entry.getKey(), (entry.getValue() == null ? null : entry.getValue().copy()));
}
this.phyrexianColors = player.getPhyrexianColors() != null ? player.getPhyrexianColors().copy() : null;
this.designations.clear();
for (Designation object : player.getDesignations()) {
this.designations.add(object.copy());
}
// Don't restore!
// this.storedBookmark
// this.usersAllowedToSeeHandCards
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class NumaJoragaChieftainEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
ManaCosts cost = new ManaCostsImpl("{X}{X}");
if (!player.chooseUse(Outcome.BoostCreature, "Pay " + cost.getText() + "?", source, game)) {
return false;
}
int costX = player.announceXMana(0, Integer.MAX_VALUE, "Announce the value for {X}", game, source);
cost.add(new GenericManaCost(2 * costX));
if (!cost.pay(source, game, source, source.getControllerId(), false, null)) {
return false;
}
ReflexiveTriggeredAbility ability = new ReflexiveTriggeredAbility(new DistributeCountersEffect(CounterType.P1P1, costX, false, ""), false, "distribute " + costX + " +1/+1 counters among any number of target Elves");
ability.addTarget(new TargetCreaturePermanentAmount(costX, filter));
game.fireReflexiveTriggeredAbility(ability, source);
return true;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class ElectropotenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID creatureId = (UUID) getValue("damageSource");
Permanent creature = game.getPermanentOrLKIBattlefield(creatureId);
Player controller = game.getPlayer(source.getControllerId());
if (creature != null && controller != null) {
if (controller.chooseUse(Outcome.Damage, "Pay {2}{R} to do the damage?", source, game)) {
// if (controller.chooseUse(Outcome.Damage, "Pay {2}{R}? If you do, " + creature.getName() + " deals damage equal to its power to any target.", game)) {
ManaCosts manaCosts = new ManaCostsImpl("{2}{R}");
if (manaCosts.pay(source, game, source, controller.getId(), false, null)) {
int amount = creature.getPower().getValue();
UUID target = source.getTargets().getFirstTarget();
Permanent targetCreature = game.getPermanent(target);
if (targetCreature != null) {
targetCreature.damage(amount, creature.getId(), source, game, false, true);
} else {
Player player = game.getPlayer(target);
if (player != null) {
player.damage(amount, creature.getId(), source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class JeskaiInfiltratorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Set<Card> cardsToManifest = new HashSet<>();
cardsToManifest.add(source.getSourcePermanentIfItStillExists(game));
cardsToManifest.add(controller.getLibrary().getFromTop(game));
UUID exileId = UUID.randomUUID();
controller.moveCardsToExile(cardsToManifest, source, game, false, exileId, "");
ExileZone exileZone = game.getExile().getExileZone(exileId);
for (Card card : exileZone.getCards(game)) {
card.setFaceDown(true, game);
}
// removes Jeskai Infiltrator from Battlefield, so Jeskai Infiltrator returns as a fresh permanent to the battlefield with new position
game.fireUpdatePlayersEvent();
Ability newSource = source.copy();
newSource.setWorksFaceDown(true);
// the Set will mimic the Shuffling
exileZone.getCards(game).forEach(card -> {
ManaCosts manaCosts = null;
if (card.isCreature(game)) {
manaCosts = card.getSpellAbility().getManaCosts();
if (manaCosts == null) {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
});
controller.moveCards(exileZone.getCards(game), Zone.BATTLEFIELD, source, game, false, true, false, null);
return true;
}
return false;
}
use of mage.abilities.costs.mana.ManaCosts in project mage by magefree.
the class ScrollOfFateEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || controller.getHand().isEmpty()) {
return false;
}
TargetCardInHand targetCard = new TargetCardInHand();
if (!controller.chooseTarget(Outcome.PutCardInPlay, controller.getHand(), targetCard, source, game)) {
return false;
}
Ability newSource = source.copy();
newSource.setWorksFaceDown(true);
Set<Card> cards = targetCard.getTargets().stream().map(game::getCard).filter(Objects::nonNull).collect(Collectors.toSet());
cards.stream().forEach(card -> {
ManaCosts manaCosts = null;
if (card.isCreature(game)) {
manaCosts = card.getSpellAbility() != null ? card.getSpellAbility().getManaCosts() : null;
if (manaCosts == null) {
manaCosts = new ManaCostsImpl("{0}");
}
}
MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, BecomesFaceDownCreatureEffect.FaceDownType.MANIFESTED), newSource);
});
controller.moveCards(cards, Zone.BATTLEFIELD, source, game, false, true, false, null);
cards.stream().map(Card::getId).map(game::getPermanent).filter(permanent -> permanent != null).forEach(permanent -> permanent.setManifested(true));
return true;
}
Aggregations