use of mage.game.stack.StackObject in project mage by magefree.
the class SourceTargetsPermanentCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject sourceSpell = game.getStack().getStackObject(source.getSourceId());
if (sourceSpell == null) {
return false;
}
Iterator<Target> targets = sourceSpell.getStackAbility().getTargets().iterator();
while (targets.hasNext()) {
Permanent permanent = game.getPermanentOrLKIBattlefield(targets.next().getFirstTarget());
if (filter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
return true;
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class ReplicateCopyEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.sourceId)) {
StackObject spell = game.getStack().getStackObject(this.sourceId);
if (spell instanceof Spell) {
Card card = ((Spell) spell).getCard();
if (card != null) {
for (Ability ability : card.getAbilities(game)) {
if (ability instanceof ReplicateAbility) {
if (ability.isActivated()) {
for (Effect effect : this.getEffects()) {
effect.setValue("ReplicateSpell", spell);
effect.setValue("ReplicateCount", ((ReplicateAbility) ability).getActivateCount());
}
return true;
}
}
}
}
}
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class DomriChaosBringerTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (!event.getSourceId().equals(spellId)) {
return false;
}
if (game.getTurnNum() != turnNumber) {
return false;
}
MageObject mo = game.getObject(event.getTargetId());
if (mo == null || !mo.isCreature(game)) {
return false;
}
StackObject stackObject = game.getStack().getStackObject(event.getTargetId());
if (stackObject == null) {
return false;
}
this.getEffects().clear();
FilterCard filter = new FilterCard();
filter.add(new CardIdPredicate(stackObject.getSourceId()));
this.addEffect(new GainAbilityControlledSpellsEffect(new RiotAbility(), filter));
return true;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class GripOfChaosEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(this.getTargetPointer().getFirst(game, source));
if (stackObject != null) {
for (UUID modeId : stackObject.getStackAbility().getModes().getSelectedModes()) {
Mode mode = stackObject.getStackAbility().getModes().get(modeId);
for (Target target : mode.getTargets()) {
UUID oldTargetId = target.getFirstTarget();
Set<UUID> possibleTargets = target.possibleTargets(stackObject.getSourceId(), stackObject.getControllerId(), game);
if (possibleTargets.contains(stackObject.getId())) {
// The stackObject can't target itself
possibleTargets.remove(stackObject.getId());
}
if (!possibleTargets.isEmpty()) {
int i = 0;
int rnd = RandomUtil.nextInt(possibleTargets.size());
Iterator<UUID> it = possibleTargets.iterator();
while (i < rnd) {
it.next();
i++;
}
UUID newTargetId = it.next();
target.remove(oldTargetId);
target.add(newTargetId, game);
}
}
}
return true;
}
return false;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class MaelstromNexusGainCascadeFirstSpellEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (StackObject stackObject : game.getStack()) {
// only spells cast, so no copies of spells
if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.isControlledBy(source.getControllerId())) {
Spell spell = (Spell) stackObject;
FirstSpellCastThisTurnWatcher watcher = game.getState().getWatcher(FirstSpellCastThisTurnWatcher.class);
if (watcher != null && spell.getId().equals(watcher.getIdOfFirstCastSpell(source.getControllerId()))) {
game.getState().addOtherAbility(spell.getCard(), cascadeAbility);
}
}
}
return true;
}
return false;
}
Aggregations