use of mage.game.events.EntersTheBattlefieldEvent in project mage by magefree.
the class VigorMortisReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
if (creature != null) {
creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game, event.getAppliedEffects());
discard();
}
return false;
}
use of mage.game.events.EntersTheBattlefieldEvent in project mage by magefree.
the class DevourEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
Player controller = game.getPlayer(source.getControllerId());
if (creature == null || controller == null) {
return false;
}
Target target = new TargetControlledPermanent(1, Integer.MAX_VALUE, devourFactor.getFilter(), true);
target.setRequired(false);
if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
return false;
}
if (!controller.chooseUse(Outcome.Detriment, "Devour " + devourFactor.getCardType().toString().toLowerCase() + "s?", source, game)) {
return false;
}
controller.chooseTarget(Outcome.Detriment, target, source, game);
if (target.getTargets().isEmpty()) {
return false;
}
List<Permanent> creaturesDevoured = new ArrayList<>();
int devouredCreatures = 0;
for (UUID targetId : target.getTargets()) {
Permanent targetCreature = game.getPermanent(targetId);
if (targetCreature != null && targetCreature.sacrifice(source, game)) {
creaturesDevoured.add(targetCreature);
devouredCreatures++;
}
}
if (!game.isSimulation()) {
game.informPlayers(creature.getLogName() + " devours " + devouredCreatures + " " + devourFactor.getCardType().toString().toLowerCase() + "s");
}
// need for multistep effects
game.getState().processAction(game);
int amountCounters;
if (devourFactor == DevourFactor.DevourX) {
amountCounters = devouredCreatures * devouredCreatures;
} else {
amountCounters = devouredCreatures * devourFactor.getFactor();
}
creature.addCounters(CounterType.P1P1.createInstance(amountCounters), source.getControllerId(), source, game);
game.getState().setValue(creature.getId().toString() + "devoured", creaturesDevoured);
return false;
}
use of mage.game.events.EntersTheBattlefieldEvent in project mage by magefree.
the class InfiniteReflectionEntersBattlefieldEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
MageObject toCopyToObject = ((EntersTheBattlefieldEvent) event).getTarget();
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (sourcePermanent != null && toCopyToObject != null && sourcePermanent.getAttachedTo() != null) {
Permanent toCopyFromPermanent = game.getPermanent(sourcePermanent.getAttachedTo());
if (toCopyFromPermanent != null) {
game.copyPermanent(toCopyFromPermanent, toCopyToObject.getId(), source, new EmptyCopyApplier());
}
}
return false;
}
use of mage.game.events.EntersTheBattlefieldEvent in project mage by magefree.
the class UphillBattleTapEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent target = ((EntersTheBattlefieldEvent) event).getTarget();
CreatureWasCastWatcher creatureSpellWatcher = game.getState().getWatcher(CreatureWasCastWatcher.class);
PlayCreatureLandWatcher landWatcher = game.getState().getWatcher(PlayCreatureLandWatcher.class);
if (target != null && ((creatureSpellWatcher != null && creatureSpellWatcher.wasCreatureCastThisTurn(target.getId())) || (landWatcher != null && landWatcher.wasLandPlayed(target.getId())))) {
target.setTapped(true);
}
return false;
}
use of mage.game.events.EntersTheBattlefieldEvent in project mage by magefree.
the class NecromanticSummoningReplacementEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
if (creature != null) {
creature.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game, event.getAppliedEffects());
discard();
}
return false;
}
Aggregations