use of mage.game.permanent.Permanent in project mage by magefree.
the class HazeFrogEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
if (!game.replaceEvent(preventEvent)) {
int damage = event.getAmount();
Permanent permanent = game.getPermanent(event.getSourceId());
StringBuilder message = new StringBuilder();
if (permanent != null) {
message.append(" from ").append(permanent.getName());
}
message.insert(0, "Damage").append(" has been prevented: ").append(damage);
event.setAmount(0);
game.informPlayers(message.toString());
game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HazduhrTheAbbotRedirectDamageEffect method applies.
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
Permanent permanent = game.getBattlefield().getPermanent(source.getSourceId());
if (permanent != null) {
if (filter.match(permanent, permanent.getId(), permanent.getControllerId(), game)) {
if (event.getTargetId().equals(getTargetPointer().getFirst(game, source))) {
if (event.getTargetId() != null) {
TargetPermanent target = new TargetPermanent();
target.add(source.getSourceId(), game);
redirectTarget = target;
return true;
}
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class HeartPiercerBowAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
Permanent equipment = game.getPermanent(getSourceId());
if (equipment != null && equipment.getAttachedTo() != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
UUID defenderId = game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game);
if (defenderId != null) {
filter.add(new ControllerIdPredicate(defenderId));
this.getTargets().clear();
TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
this.addTarget(target);
return true;
}
}
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class IncandescentSoulstokeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
FilterCard filter = new FilterCreatureCard();
filter.add(SubType.ELEMENTAL.getPredicate());
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
}
}
}
}
return true;
}
return false;
}
use of mage.game.permanent.Permanent in project mage by magefree.
the class IncreasingSavageryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int amount = 5;
Spell spell = (Spell) game.getStack().getStackObject(source.getSourceId());
if (spell != null) {
if (spell.getFromZone() == Zone.GRAVEYARD) {
amount = 10;
}
Permanent permanent = game.getPermanent(targetPointer.getFirst(game, source));
if (permanent != null) {
permanent.addCounters(CounterType.P1P1.createInstance(amount), source.getControllerId(), source, game);
}
return true;
}
return false;
}
Aggregations