use of mage.game.stack.Spell 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.Spell in project mage by magefree.
the class ArclightPhoenixWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell == null || !spell.isInstantOrSorcery(game)) {
return;
}
this.instantSorceryCount.putIfAbsent(spell.getControllerId(), 0);
this.instantSorceryCount.compute(spell.getControllerId(), (k, a) -> a + 1);
}
}
use of mage.game.stack.Spell in project mage by magefree.
the class ArchfiendsVesselEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
if (entersTheBattlefieldEvent.getTargetId().equals(getSourceId()) && entersTheBattlefieldEvent.getFromZone() == Zone.GRAVEYARD) {
return true;
} else {
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
List<Spell> spellsCastFromGraveyard = watcher.getSpellsCastFromGraveyardThisTurn(getControllerId());
if (spellsCastFromGraveyard != null) {
return spellsCastFromGraveyard.stream().anyMatch(spell -> spell.getMainCard().getId().equals((entersTheBattlefieldEvent.getTarget().getMainCard().getId())));
}
}
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class BingoCount method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
if (spell.getManaValue() > 9) {
return true;
}
MageObject mageObject = game.getObject(source.getSourceId());
if (mageObject != null) {
// Map<number, amount of counters>
Map<Integer, Integer> chipCounters = new HashMap<>();
if (game.getState().getValue(mageObject.getId() + "_chip") != null) {
chipCounters.putAll((Map<Integer, Integer>) game.getState().getValue(mageObject.getId() + "_chip"));
}
chipCounters.putIfAbsent(spell.getManaValue(), 0);
chipCounters.put(spell.getManaValue(), chipCounters.get(spell.getManaValue()) + 1);
game.getState().setValue(mageObject.getId() + "_chip", chipCounters);
if (mageObject instanceof Permanent) {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Map.Entry<Integer, Integer> entry : chipCounters.entrySet()) {
i++;
sb.append(entry.getKey());
if (i < chipCounters.size()) {
sb.append(", ");
}
}
((Permanent) mageObject).addInfo("chip counters", CardUtil.addToolTipMarkTags("Chip counters at: " + sb), game);
new AddCountersSourceEffect(CounterType.CHIP.createInstance()).apply(game, source);
}
return true;
}
}
return false;
}
use of mage.game.stack.Spell in project mage by magefree.
the class BrineboundGiftTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
switch(event.getType()) {
case ENTERS_THE_BATTLEFIELD:
return event.getTargetId().equals(getSourceId());
case TARGETED:
break;
default:
return false;
}
Permanent permanent = this.getSourcePermanentOrLKI(game);
if (permanent == null || !event.getTargetId().equals(permanent.getAttachedTo())) {
return false;
}
Spell spell = game.getSpell(event.getSourceId());
return spell != null && spell.hasSubtype(SubType.AURA, game);
}
Aggregations