use of mage.game.stack.StackObject in project mage by magefree.
the class LeylineOfCombustionTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
if (sourceObject == null) {
return false;
}
Player targetter = game.getPlayer(event.getPlayerId());
if (targetter == null || !targetter.hasOpponent(this.controllerId, game)) {
return false;
}
if (!event.getTargetId().equals(this.controllerId)) {
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (permanent == null || !permanent.isControlledBy(this.controllerId)) {
return false;
}
}
// If a spell targets you and/or a permanent you control multiple times,
// or if a spell targets you and one or more permanents you control,
// Leyline of Combustion’s triggered ability triggers once.
Set<UUID> sourceObjects = (Set<UUID>) game.getState().getValue("sourceObjects" + this.id);
if (sourceObjects == null) {
sourceObjects = new HashSet<>();
}
if (!sourceObjects.add(sourceObject.getId())) {
return false;
}
game.getState().setValue("sourceObjects" + this.id, sourceObjects);
this.getEffects().clear();
Effect effect = new DamageTargetEffect(2);
effect.setTargetPointer(new FixedTarget(event.getPlayerId(), game));
this.addEffect(effect);
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class OverrideEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject spell = game.getStack().getStackObject(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && spell != null) {
Player player = game.getPlayer(spell.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
if (player != null && controller != null) {
int amount = ArtifactYouControlCount.instance.calculate(game, source, this);
if (amount > 0) {
Cost cost = ManaUtil.createManaCost(amount, false);
if (!cost.pay(source, game, source, spell.getControllerId(), false)) {
game.informPlayers(sourceObject.getLogName() + ": cost wasn't payed - countering target spell.");
return game.getStack().counter(source.getFirstTarget(), source, game);
}
}
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SameCastingCostPredicate method apply.
@Override
public boolean apply(ObjectSourcePlayer<MageItem> input, Game game) {
StackObject source = game.getStack().getStackObject(input.getSourceId());
if (source != null) {
if (source.getStackAbility().getTargets().isEmpty() || source.getStackAbility().getTargets().get(0).getTargets().isEmpty()) {
return true;
}
Permanent firstTarget = game.getPermanent(source.getStackAbility().getTargets().get(0).getTargets().get(0));
Permanent inputPermanent = game.getPermanent(input.getObject().getId());
if (firstTarget != null && inputPermanent != null) {
return firstTarget.getManaValue() == inputPermanent.getManaValue();
}
}
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SkullscorchDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
StackObject spell = null;
for (StackObject object : game.getStack()) {
if (object instanceof Spell && object.getSourceId().equals(source.getSourceId())) {
spell = object;
}
}
if (spell != null) {
boolean discardCards = true;
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
if (player.chooseUse(Outcome.Detriment, "Have " + spell.getLogName() + " deal 4 damage to you?", source, game)) {
discardCards = false;
player.damage(4, source.getSourceId(), source, game);
game.informPlayers(player.getLogName() + " has " + spell.getLogName() + " deal 4 to them");
}
if (discardCards) {
player.discard(2, true, false, source, game);
}
}
return discardCards;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class SkophosMazeWardenTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
StackObject stackObject = game.getStack().getStackObject(event.getSourceId());
if (stackObject == null) {
return false;
}
Permanent permanent = game.getPermanent(stackObject.getSourceId());
if (permanent == null || !permanent.isControlledBy(getControllerId()) || !permanent.isLand(game) || !permanent.getName().equals("Labyrinth of Skophos")) {
return false;
}
Permanent creature = game.getPermanent(event.getTargetId());
if (creature == null || !creature.isCreature(game) || creature.getId().equals(getSourceId())) {
return false;
}
this.getEffects().clear();
this.addEffect(new FightTargetSourceEffect().setTargetPointer(new FixedTarget(creature, game)));
return true;
}
Aggregations