use of mage.players.ManaPool in project mage by magefree.
the class UpwellingRuleEffect method apply.
@Override
public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) {
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) {
ManaPool pool = player.getManaPool();
pool.addDoNotEmptyManaType(ManaType.WHITE);
pool.addDoNotEmptyManaType(ManaType.GREEN);
pool.addDoNotEmptyManaType(ManaType.BLUE);
pool.addDoNotEmptyManaType(ManaType.RED);
pool.addDoNotEmptyManaType(ManaType.BLACK);
pool.addDoNotEmptyManaType(ManaType.COLORLESS);
}
}
return true;
}
return false;
}
use of mage.players.ManaPool in project mage by magefree.
the class WordOfCommandTestFlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player sourceController = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
MageObject sourceObject = game.getObject(source.getSourceId());
Card card = null;
if (sourceController != null && targetPlayer != null && sourceObject != null) {
Player controller = null;
Spell wordOfCommand = game.getSpell(source.getSourceId());
if (wordOfCommand != null) {
if (wordOfCommand.getCommandedBy() != null) {
controller = game.getPlayer(wordOfCommand.getCommandedBy());
} else {
controller = game.getPlayer(sourceController.getTurnControlledBy());
}
}
if (controller == null) {
// reset the controller to avoid NPE
controller = sourceController;
}
// Look at target opponent's hand and choose a card from it
TargetCard targetCard = new TargetCard(Zone.HAND, new FilterCard());
if (controller.choose(Outcome.Discard, targetPlayer.getHand(), targetCard, game)) {
card = game.getCard(targetCard.getFirstTarget());
}
// You control that player until Word of Command finishes resolving
CardUtil.takeControlUnderPlayerStart(game, controller, targetPlayer, true);
// The player plays that card if able
if (card != null) {
// While doing so, the player can activate mana abilities only if they're from lands that player controls
RestrictionEffect effect = new WordOfCommandCantActivateEffect();
effect.setTargetPointer(new FixedTarget(targetPlayer.getId()));
game.addEffect(effect, source);
// and only if mana they produce is spent to activate other mana abilities of lands they control and/or play that card
ManaPool manaPool = targetPlayer.getManaPool();
manaPool.setForcedToPay(true);
manaPool.storeMana();
int bookmark = game.bookmarkState();
boolean canPlay = checkPlayability(card, targetPlayer, game, source);
while (canPlay && targetPlayer.canRespond() && !targetPlayer.playCard(card, game, false, new ApprovingObject(source, game))) {
SpellAbility spellAbility = card.getSpellAbility();
if (spellAbility != null) {
spellAbility.getManaCostsToPay().clear();
spellAbility.getManaCostsToPay().addAll(spellAbility.getManaCosts());
// force rollback if card was deemed playable
((ManaCostsImpl) spellAbility.getManaCostsToPay()).forceManaRollback(game, manaPool);
canPlay = checkPlayability(card, targetPlayer, game, source);
} else {
break;
}
}
if (!canPlay) {
game.informPlayers(targetPlayer.getLogName() + " didn't play " + card.getLogName() + " (card can't be played)");
}
// duplicate in case of a new mana pool existing - probably not necessary, but just in case
manaPool.setForcedToPay(false);
// a rollback creates a new mana pool for the player, so it's necessary to find it again
manaPool = targetPlayer.getManaPool();
manaPool.setForcedToPay(false);
game.removeBookmark(bookmark);
targetPlayer.resetStoredBookmark(game);
for (RestrictionEffect eff : game.getContinuousEffects().getRestrictionEffects()) {
if (eff instanceof WordOfCommandCantActivateEffect) {
eff.discard();
break;
}
}
game.getContinuousEffects().removeInactiveEffects(game);
Spell spell = game.getSpell(card.getId());
if (spell != null) {
// If the chosen card is cast as a spell, you control the player while that spell is resolving
spell.setCommandedBy(controller.getId());
}
}
wordOfCommand = game.getSpell(source.getSourceId());
if (wordOfCommand != null) {
// You control the player until Word of Command finishes resolving
wordOfCommand.setCommandedBy(controller.getId());
} else {
CardUtil.takeControlUnderPlayerEnd(game, controller, targetPlayer);
}
return true;
}
return false;
}
use of mage.players.ManaPool in project mage by magefree.
the class AssistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
Spell spell = game.getStack().getSpell(source.getSourceId());
if (controller != null && spell != null && targetPlayer != null) {
// AI can't assist other players, maybe for teammates only (but tests must work as normal)
int amountToPay = 0;
if (!targetPlayer.isComputer()) {
amountToPay = targetPlayer.announceXMana(0, unpaid.getMana().getGeneric(), "How much mana to pay as assist for " + controller.getName() + "?", game, source);
}
if (amountToPay > 0) {
Cost cost = ManaUtil.createManaCost(amountToPay, false);
if (cost.pay(source, game, source, targetPlayer.getId(), false)) {
ManaPool manaPool = controller.getManaPool();
manaPool.addMana(Mana.ColorlessMana(amountToPay), game, source);
// it's unlock mana for one use/click, but it can gives more
manaPool.unlockManaType(ManaType.COLORLESS);
game.informPlayers(targetPlayer.getLogName() + " paid {" + amountToPay + "} for " + controller.getLogName());
game.getState().setValue(source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()) + "_assisted", true);
}
// assist must be used before activating mana abilities, so no need to switch step after usage
// (mana and other special abilities can be used after assist)
// spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.NORMAL);
}
return true;
}
return false;
}
Aggregations