use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class GrenzoHavocRaiserEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
this.damagedPlayerName = null;
this.getEffects().get(0).setText(GrenzoHavocRaiser.goadEffectName);
Player damagedPlayer = game.getPlayer(event.getPlayerId());
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getSourceId());
Permanent abilitySourcePermanent = this.getSourcePermanentIfItStillExists(game);
if (damagedPlayer == null || permanent == null || abilitySourcePermanent == null) {
return false;
}
if (((DamagedEvent) event).isCombatDamage() && isControlledBy(permanent.getControllerId())) {
this.damagedPlayerName = damagedPlayer.getLogName();
this.getEffects().get(0).setText(GrenzoHavocRaiser.goadEffectName + " (" + this.damagedPlayerName + ")");
game.informPlayers(abilitySourcePermanent.getLogName() + " triggered for damaged " + this.damagedPlayerName);
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + damagedPlayer.getLogName() + " controls");
filter.add(new ControllerIdPredicate(damagedPlayer.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
for (Effect effect : this.getAllEffects()) {
if (effect instanceof GrenzoHavocRaiserEffect) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
effect.setValue("damage", event.getAmount());
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class MordantDragonEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
Player opponent = game.getPlayer(event.getPlayerId());
if (!damageEvent.isCombatDamage() || !event.getSourceId().equals(this.getSourceId()) || opponent == null) {
return false;
}
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
filter.add(new ControllerIdPredicate(opponent.getId()));
this.getTargets().clear();
this.addTarget(new TargetCreaturePermanent(filter));
for (Effect effect : this.getAllEffects()) {
effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
effect.setValue("damage", event.getAmount());
}
return true;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SereneMasterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (controller != null && sourceCreature != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature it's blocking");
filter.add(new BlockedByIdPredicate((source.getSourceId())));
Target target = new TargetCreaturePermanent(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
if (controller.chooseTarget(outcome, target, source, game)) {
Permanent attackingCreature = game.getPermanent(target.getFirstTarget());
if (attackingCreature != null) {
int newSourcePower = attackingCreature.getPower().getValue();
int newAttackerPower = sourceCreature.getPower().getValue();
ContinuousEffect effect = new SetPowerToughnessTargetEffect(newSourcePower, sourceCreature.getToughness().getValue(), Duration.EndOfCombat);
effect.setTargetPointer(new FixedTarget(source.getSourceId(), game));
game.addEffect(effect, source);
effect = new SetPowerToughnessTargetEffect(newAttackerPower, attackingCreature.getToughness().getValue(), Duration.EndOfCombat);
effect.setTargetPointer(new FixedTarget(attackingCreature.getId(), game));
game.addEffect(effect, source);
return true;
}
}
}
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SpyNetworkFaceDownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
MageObject mageObject = game.getObject(source.getSourceId());
if (controller != null && player != null && mageObject != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("face down creature controlled by " + player.getLogName());
filter.add(FaceDownPredicate.instance);
filter.add(new ControllerIdPredicate(player.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(1, 1, filter, true);
if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
while (controller.chooseUse(outcome, "Look at a face down creature controlled by " + player.getLogName() + "?", source, game)) {
target.clearChosen();
while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
controller.chooseTarget(outcome, target, source, game);
}
Permanent faceDownCreature = game.getPermanent(target.getFirstTarget());
if (faceDownCreature != null) {
Permanent copyFaceDown = faceDownCreature.copy();
copyFaceDown.setFaceDown(false, game);
Cards cards = new CardsImpl(copyFaceDown);
controller.lookAtCards("face down card - " + mageObject.getName(), cards, game);
game.informPlayers(controller.getLogName() + " looks at a face down creature controlled by " + player.getLogName());
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCreaturePermanent in project mage by magefree.
the class SplitThePartyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
if (controller == null || targetPlayer == null) {
return false;
}
int numCreatures = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game);
if (numCreatures > 0) {
int halfCreatures = (numCreatures / 2) + (numCreatures % 2);
FilterCreaturePermanent filter = new FilterCreaturePermanent("creatures controlled by " + targetPlayer.getName());
filter.add(new ControllerIdPredicate(targetPlayer.getId()));
TargetCreaturePermanent target = new TargetCreaturePermanent(halfCreatures, halfCreatures, filter, true);
if (controller.chooseTarget(outcome, target, source, game)) {
Set<Card> cardsToHand = new HashSet<>();
for (UUID creatureId : target.getTargets()) {
Card card = game.getPermanent(creatureId);
if (card != null) {
cardsToHand.add(card);
}
}
controller.moveCards(cardsToHand, Zone.HAND, source, game);
}
}
return true;
}
Aggregations