use of mage.game.permanent.Permanent in project mage by magefree.
the class ImpromptuRaidEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Card card = controller.getLibrary().getFromTop(game);
if (card != null) {
Cards cards = new CardsImpl();
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (filterPutInGraveyard.match(card, source.getSourceId(), source.getControllerId(), game)) {
controller.moveCards(card, Zone.GRAVEYARD, source, game);
return true;
}
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("", source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
return true;
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class ImpelledGiantBoostEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent impelledGiant = game.getPermanent(source.getSourceId());
Permanent tappedCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (tappedCreature != null && impelledGiant != null) {
int amount = tappedCreature.getPower().getValue();
game.addEffect(new BoostSourceEffect(amount, 0, Duration.EndOfTurn), source);
}
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class ImmovableRodAttackBlockTargetEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game);
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (sourcePermanent == null || !sourcePermanent.isTapped() || permanent == null) {
discard();
return false;
}
permanent.removeAllAbilities(source.getSourceId(), game);
return true;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class ImprisonUnblockEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent enchantment = game.getPermanent(source.getSourceId());
if (enchantment != null && enchantment.getAttachedTo() != null) {
Permanent permanent = game.getPermanent(enchantment.getAttachedTo());
if (permanent != null) {
if (permanent.isCreature(game)) {
// Tap the creature
permanent.tap(source, game);
// Remove it from combat
Effect effect = new RemoveFromCombatTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));
effect.apply(game, source);
// Make blocked creatures unblocked
BlockedByOnlyOneCreatureThisCombatWatcher watcher = game.getState().getWatcher(BlockedByOnlyOneCreatureThisCombatWatcher.class);
if (watcher != null) {
Set<CombatGroup> combatGroups = watcher.getBlockedOnlyByCreature(permanent.getId());
if (combatGroups != null) {
for (CombatGroup combatGroup : combatGroups) {
if (combatGroup != null) {
combatGroup.setBlocked(false, game);
}
}
}
}
return true;
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class JusticeEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
MageObject sourceObject = game.getObject(event.getSourceId());
if (sourceObject != null && sourceObject.getColor(game).isRed()) {
if (sourceObject instanceof Permanent && sourceObject.isCreature(game) || sourceObject instanceof Spell) {
this.getEffects().get(0).setValue("damageAmount", event.getAmount());
this.getEffects().get(0).setTargetPointer(new FixedTarget(game.getControllerId(sourceObject.getId())));
return true;
}
}
return false;
}
Aggregations