use of mage.game.stack.StackObject in project mage by magefree.
the class KheruSpellsnatcherEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
StackObject stackObject = game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (stackObject != null && sourceObject != null && game.getStack().counter(targetPointer.getFirst(game, source), source, game, Zone.EXILED, false, ZoneDetail.NONE)) {
if (!stackObject.isCopy()) {
MageObject card = game.getObject(stackObject.getSourceId());
if (card instanceof Card) {
return PlayFromNotOwnHandZoneTargetEffect.exileAndPlayFromExile(game, source, (Card) card, TargetController.YOU, Duration.Custom, true, false, true);
}
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class KeeperOfTheDeadEffect method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject object = game.getObject(sourceId);
for (StackObject item : game.getState().getStack()) {
if (item.getId().equals(sourceId)) {
object = item;
}
if (item.getSourceId().equals(sourceId)) {
object = item;
}
}
if (object instanceof StackObject) {
UUID playerId = ((StackObject) object).getStackAbility().getFirstTarget();
for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && StaticFilters.FILTER_PERMANENT_CREATURE_NON_BLACK.match(permanent, game) && permanent.isControlledBy(playerId)) {
possibleTargets.add(targetId);
}
}
}
return possibleTargets;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class OupheVandalsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
UUID targetId = source.getFirstTarget();
StackObject stackObject = game.getStack().getStackObject(targetId);
if (targetId != null && game.getStack().counter(targetId, source, game)) {
UUID permanentId = stackObject.getSourceId();
if (permanentId != null) {
Permanent usedPermanent = game.getPermanent(permanentId);
if (usedPermanent != null) {
usedPermanent.destroy(source, game, false);
}
}
return true;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class PsychicBattleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null) {
Map<Player, Integer> manacostMap = new HashMap<>();
for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null && player.getLibrary().hasCards()) {
Card card = player.getLibrary().getFromTop(game);
player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', new CardsImpl(card), game);
manacostMap.put(player, card.getManaValue());
}
}
Player highestCostPlayer = null;
int maxValue = Collections.max(manacostMap.values());
boolean tie = false;
for (Map.Entry<Player, Integer> entry : manacostMap.entrySet()) {
if (entry.getValue() == maxValue) {
if (highestCostPlayer != null) {
// the result is tied, so nobody changes the targets
tie = true;
break;
} else {
highestCostPlayer = entry.getKey();
}
}
}
if (highestCostPlayer != null && !tie) {
StackObject stackObject = game.getStack().getStackObject(this.getTargetPointer().getFirst(game, source));
if (stackObject != null) {
// this makes the new target "invisible" for the Psychic Battle ability
stackObject.setTargetChanged(true);
stackObject.chooseNewTargets(game, highestCostPlayer.getId(), false, false, null);
}
return true;
}
return tie;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class RavagerOfTheFellsTarget method possibleTargets.
@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
Set<UUID> availablePossibleTargets = super.possibleTargets(sourceId, sourceControllerId, game);
Set<UUID> possibleTargets = new HashSet<>();
MageObject object = game.getObject(sourceId);
for (StackObject item : game.getState().getStack()) {
if (item.getId().equals(sourceId)) {
object = item;
}
if (item.getSourceId().equals(sourceId)) {
object = item;
}
}
if (object instanceof StackObject) {
UUID playerId = ((StackObject) object).getStackAbility().getFirstTarget();
Player player = game.getPlayerOrPlaneswalkerController(playerId);
if (player != null) {
for (UUID targetId : availablePossibleTargets) {
Permanent permanent = game.getPermanent(targetId);
if (permanent != null && permanent.isControlledBy(player.getId())) {
possibleTargets.add(targetId);
}
}
}
}
return possibleTargets;
}
Aggregations