use of mage.target.Target in project mage by magefree.
the class DescentOfTheDragonsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Map<UUID, Integer> playersWithTargets = new HashMap<>();
for (Target target : source.getTargets()) {
for (UUID permanentId : target.getTargets()) {
Permanent permanent = game.getPermanent(permanentId);
if (permanent != null) {
UUID controllerOfTargetId = permanent.getControllerId();
if (permanent.destroy(source, game, false)) {
int count = playersWithTargets.getOrDefault(controllerOfTargetId, 0);
playersWithTargets.put(controllerOfTargetId, count + 1);
}
}
}
}
DragonToken dragonToken = new DragonToken();
for (Map.Entry<UUID, Integer> amountTokensPerPlayer : playersWithTargets.entrySet()) {
dragonToken.putOntoBattlefield(amountTokensPerPlayer.getValue(), game, source, amountTokensPerPlayer.getKey());
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class EurekaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
PlayerList playerList = game.getState().getPlayerList().copy();
while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) {
playerList.getNext();
}
Player currentPlayer = game.getPlayer(playerList.get());
UUID firstInactivePlayer = null;
Target target = new TargetCardInHand(new FilterPermanentCard());
while (controller.canRespond()) {
if (firstInactivePlayer == null) {
firstInactivePlayer = currentPlayer.getId();
}
if (currentPlayer != null && currentPlayer.canRespond() && game.getState().getPlayersInRange(controller.getId(), game).contains(currentPlayer.getId())) {
target.clearChosen();
if (target.canChoose(source.getSourceId(), currentPlayer.getId(), game) && currentPlayer.chooseUse(outcome, "Put permanent from your hand to play?", source, game)) {
if (target.chooseTarget(outcome, currentPlayer.getId(), source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
currentPlayer.moveCards(card, Zone.BATTLEFIELD, source, game);
firstInactivePlayer = null;
}
}
}
}
// get next player
playerList.getNext();
currentPlayer = game.getPlayer(playerList.get());
// if all player since this player didn't put permanent in play finish the process
if (currentPlayer != null && currentPlayer.getId().equals(firstInactivePlayer)) {
break;
}
}
return true;
}
return false;
}
use of mage.target.Target in project mage by magefree.
the class EvolutionaryEscalationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Counter counter = CounterType.P1P1.createInstance(3);
boolean addedCounters = false;
for (Target target : source.getTargets()) {
Permanent targetPermanent = game.getPermanent(target.getFirstTarget());
if (targetPermanent != null) {
targetPermanent.addCounters(counter.copy(), source.getControllerId(), source, game);
addedCounters = true;
}
}
return addedCounters;
}
use of mage.target.Target in project mage by magefree.
the class FumbleEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getTargets().getFirstTarget());
Player player = game.getPlayer(source.getControllerId());
if (player == null || permanent == null) {
return false;
}
List<Permanent> attachments = new ArrayList<>();
for (UUID permId : permanent.getAttachments()) {
Permanent attachment = game.getPermanent(permId);
if (attachment != null) {
if (attachment.hasSubtype(SubType.AURA, game) || attachment.hasSubtype(SubType.EQUIPMENT, game)) {
attachments.add(attachment);
}
}
}
new ReturnToHandTargetEffect().apply(game, source);
if (!attachments.isEmpty()) {
Target target = new TargetCreaturePermanent(1, 1, StaticFilters.FILTER_PERMANENT_CREATURE, true);
Permanent newCreature = null;
if (player.choose(Outcome.BoostCreature, target, source.getSourceId(), game)) {
newCreature = game.getPermanent(target.getFirstTarget());
}
for (Permanent attachment : attachments) {
if (!attachment.hasSubtype(SubType.AURA, game) && !attachment.hasSubtype(SubType.EQUIPMENT, game)) {
continue;
}
ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, player.getId());
effect.setTargetPointer(new FixedTarget(attachment, game));
game.addEffect(effect, source);
if (newCreature != null) {
attachment.attachTo(newCreature.getId(), source, game);
}
}
}
return true;
}
use of mage.target.Target in project mage by magefree.
the class GoblinVandalTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent sourcePermanent = game.getPermanent(getSourceId());
if (sourcePermanent.isAttacking()) {
for (CombatGroup combatGroup : game.getCombat().getGroups()) {
if (combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(getSourceId())) {
UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(getSourceId(), game);
FilterPermanent filter = new FilterArtifactPermanent();
filter.add(new ControllerIdPredicate(defendingPlayerId));
Target target = new TargetPermanent(filter);
this.addTarget(target);
return true;
}
}
}
return false;
}
Aggregations