use of mage.game.stack.StackAbility in project mage by magefree.
the class RepeatedReverberationEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getPlayerId().equals(this.getControllerId())) {
return false;
}
// activated ability
if (event.getType() == GameEvent.EventType.ACTIVATED_ABILITY) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility != null && stackAbility.getStackAbility() instanceof LoyaltyAbility) {
this.getEffects().clear();
this.addEffect(new RepeatedReverberationEffect().setTargetPointer(new FixedTarget(event.getTargetId(), game)));
return true;
}
}
// spell
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.isInstantOrSorcery(game)) {
this.getEffects().clear();
this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
this.addEffect(new CopyTargetSpellEffect(true).setTargetPointer(new FixedTarget(event.getTargetId(), game)));
return true;
}
}
return false;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class UnboundFlourishingCopyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (player != null && controller != null) {
Object needObject = game.getState().getValue(source.getSourceId() + UnboundFlourishing.needPrefix);
// copy ability
if (needObject instanceof StackAbility) {
StackAbility stackAbility = (StackAbility) needObject;
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
// copy spell
if (needObject instanceof Spell) {
Spell spell = (Spell) needObject;
spell.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
}
return false;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class WeaverOfHarmonyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(targetPointer.getFirst(game, source));
if (stackAbility == null) {
return false;
}
stackAbility.createCopyOnStack(game, source, source.getControllerId(), true);
return true;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class GoblinArtisansTarget method canTarget.
@Override
public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) {
if (!super.canTarget(controllerId, id, source, game)) {
return false;
}
MageObjectReference sourceRef = new MageObjectReference(source.getSourceObject(game), game);
Spell spell = game.getSpell(id);
if (spell == null) {
return false;
}
for (StackObject stackObject : game.getStack()) {
if (!(stackObject instanceof StackAbility)) {
continue;
}
Permanent permanent = ((StackAbility) stackObject).getSourcePermanentOrLKI(game);
if (permanent != null && !sourceRef.refersTo(permanent, game) && permanent.isCreature(game) && "Goblin Artisans".equals(permanent.getName()) && stackObject.getStackAbility().getTargets().stream().map(Target::getTargets).flatMap(Collection::stream).anyMatch(id::equals)) {
return false;
}
}
return true;
}
use of mage.game.stack.StackAbility in project mage by magefree.
the class RingsOfBrighthearthTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getPlayerId().equals(getControllerId())) {
return false;
}
StackAbility stackAbility = (StackAbility) game.getStack().getStackObject(event.getSourceId());
if (stackAbility == null || stackAbility.getStackAbility() instanceof ActivatedManaAbilityImpl) {
return false;
}
this.getEffects().setValue("stackAbility", stackAbility);
return true;
}
Aggregations