use of mage.target.TargetPlayer in project mage by magefree.
the class PsychicSpiralEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (controller != null && targetPlayer != null) {
int cardsInGraveyard = controller.getGraveyard().size();
controller.shuffleCardsToLibrary(controller.getGraveyard(), game, source);
if (cardsInGraveyard > 0) {
targetPlayer.millCards(cardsInGraveyard, source, game);
}
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class SupremeInquisitorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player != null && targetPlayer != null) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 5, filter);
if (player.searchLibrary(target, source, game, targetPlayer.getId())) {
List<UUID> targetId = target.getTargets();
for (UUID targetCard : targetId) {
Card card = targetPlayer.getLibrary().remove(targetCard, game);
if (card != null) {
player.moveCardToExileWithInfo(card, null, null, source, game, Zone.LIBRARY, true);
}
}
}
targetPlayer.shuffleLibrary(source, game);
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class TormentedThoughtsDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetPlayer != null) {
int power = 0;
COSTS: for (Cost cost : source.getCosts()) {
if (cost instanceof SacrificeTargetCost) {
SacrificeTargetCost sacCost = (SacrificeTargetCost) cost;
for (Permanent permanent : sacCost.getPermanents()) {
power = permanent.getPower().getValue();
break COSTS;
}
}
}
if (power > 0) {
targetPlayer.discard(power, false, false, source, game);
}
return true;
}
return false;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class TsabosDecreeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (player == null) {
return false;
}
if (sourceObject == null) {
return false;
}
Choice typeChoice = new ChoiceCreatureType(sourceObject);
if (!player.choose(outcome, typeChoice, game)) {
return false;
}
game.informPlayers(sourceObject.getLogName() + " chosen type: " + typeChoice.getChoice());
targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
FilterCard filterCard = new FilterCard();
filterCard.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
targetPlayer.discard(new CardsImpl(targetPlayer.getHand().getCards(filterCard, game)), false, source, game);
FilterCreaturePermanent filterCreaturePermanent = new FilterCreaturePermanent();
filterCreaturePermanent.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
for (Permanent creature : game.getBattlefield().getActivePermanents(filterCreaturePermanent, source.getSourceId(), game)) {
if (creature.isControlledBy(targetPlayer.getId())) {
creature.destroy(source, game, true);
}
}
return true;
}
use of mage.target.TargetPlayer in project mage by magefree.
the class DrainPowerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
if (targetPlayer != null) {
List<Permanent> ignorePermanents = new ArrayList<>();
Map<Permanent, List<ActivatedManaAbilityImpl>> manaAbilitiesMap = new HashMap<>();
TargetPermanent target = null;
while (true) {
targetPlayer.setPayManaMode(true);
manaAbilitiesMap.clear();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, targetPlayer.getId(), game)) {
if (!ignorePermanents.contains(permanent)) {
List<ActivatedManaAbilityImpl> manaAbilities = new ArrayList<>();
abilitySearch: for (Ability ability : permanent.getAbilities()) {
if (ability instanceof ActivatedAbility && ability.getAbilityType() == AbilityType.MANA) {
ActivatedManaAbilityImpl manaAbility = (ActivatedManaAbilityImpl) ability;
if (manaAbility.canActivate(targetPlayer.getId(), game).canActivate()) {
// so it's necessary to filter them out manually - might be buggy in some fringe cases
for (ManaCost manaCost : manaAbility.getManaCosts()) {
if (!targetPlayer.getManaPool().getMana().includesMana(manaCost.getMana())) {
continue abilitySearch;
}
}
manaAbilities.add(manaAbility);
}
}
}
if (!manaAbilities.isEmpty()) {
manaAbilitiesMap.put(permanent, manaAbilities);
}
}
}
if (manaAbilitiesMap.isEmpty()) {
break;
}
List<Permanent> permList = new ArrayList<>(manaAbilitiesMap.keySet());
Permanent permanent;
if (permList.size() > 1 || target != null) {
FilterLandPermanent filter2 = new FilterLandPermanent("land you control to tap for mana (remaining: " + permList.size() + ')');
filter2.add(new PermanentInListPredicate(permList));
target = new TargetPermanent(1, 1, filter2, true);
while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
targetPlayer.chooseTarget(Outcome.Neutral, target, source, game);
}
permanent = game.getPermanent(target.getFirstTarget());
} else {
permanent = permList.get(0);
}
if (permanent != null) {
int i = 0;
for (ActivatedManaAbilityImpl manaAbility : manaAbilitiesMap.get(permanent)) {
i++;
if (manaAbilitiesMap.get(permanent).size() <= i || targetPlayer.chooseUse(Outcome.Neutral, "Activate mana ability \"" + manaAbility.getRule() + "\" of " + permanent.getLogName() + "? (Choose \"no\" to activate next mana ability)", source, game)) {
boolean originalCanUndo = manaAbility.isUndoPossible();
// prevents being able to undo Drain Power
manaAbility.setUndoPossible(false);
if (targetPlayer.activateAbility(manaAbility, game)) {
ignorePermanents.add(permanent);
}
// resets undoPossible to its original state
manaAbility.setUndoPossible(originalCanUndo);
break;
}
}
}
}
targetPlayer.setPayManaMode(false);
// 106.12. One card (Drain Power) causes one player to lose unspent mana and another to add “the mana lost this way.” (Note that these may be the same player.)
// This empties the former player's mana pool and causes the mana emptied this way to be put into the latter player's mana pool. Which permanents, spells, and/or
// abilities produced that mana are unchanged, as are any restrictions or additional effects associated with any of that mana.
List<ManaPoolItem> manaItems = targetPlayer.getManaPool().getManaItems();
targetPlayer.getManaPool().emptyPool(game);
for (ManaPoolItem manaPoolItem : manaItems) {
controller.getManaPool().addMana(manaPoolItem.isConditional() ? manaPoolItem.getConditionalMana() : manaPoolItem.getMana(), game, source, Duration.EndOfTurn.equals(manaPoolItem.getDuration()));
}
return true;
}
return false;
}
Aggregations