use of mage.watchers.common.CreatureAttackedWhichPlayerWatcher in project mage by magefree.
the class NacatlWarPrideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent origNactalWarPride = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (origNactalWarPride == null) {
return false;
}
CreatureAttackedWhichPlayerWatcher PlayerAttackedWatcher = game.getState().getWatcher(CreatureAttackedWhichPlayerWatcher.class);
// Count the number of creatures attacked opponent controls
UUID defenderId = PlayerAttackedWatcher.getPlayerAttackedThisTurnByCreature(source.getSourceId());
int count = 0;
if (defenderId != null) {
count = game.getBattlefield().countAll(new FilterControlledCreaturePermanent(), defenderId, game);
}
if (count == 0) {
return false;
}
List<Permanent> copies = new ArrayList<>();
Player controller = game.getPlayer(source.getControllerId());
CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, count, true, true);
effect.setTargetPointer(new FixedTarget(origNactalWarPride, game));
effect.apply(game, source);
copies.addAll(effect.getAddedPermanents());
if (!copies.isEmpty()) {
FixedTargets fixedTargets = new FixedTargets(copies, game);
ExileTargetEffect exileEffect = new ExileTargetEffect();
exileEffect.setTargetPointer(fixedTargets).setText("exile the tokens");
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
return true;
}
return false;
}
Aggregations