[NEO] Implemented Flame Discharge

This commit is contained in:
Daniel Bomar 2022-02-05 15:11:53 -06:00
parent 9f83d9572f
commit dfb3f87bb3
No known key found for this signature in database
GPG key ID: C86C8658F4023918
4 changed files with 156 additions and 0 deletions

View file

@ -0,0 +1,31 @@
package mage.abilities.condition.common;
import mage.MageObject;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.watchers.common.ControlledModifiedCreatureAsSpellCastWatcher;
/**
*
* @author weirddan455
*/
public enum ControlledModifiedCreatureAsSpellCastCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = source.getSourceObject(game);
ControlledModifiedCreatureAsSpellCastWatcher watcher = game.getState().getWatcher(ControlledModifiedCreatureAsSpellCastWatcher.class);
if (sourceObject == null || watcher == null) {
return false;
}
return watcher.checkModifiedCondition(new MageObjectReference(sourceObject, game));
}
@Override
public String toString() {
return "you controlled a modified creature as you cast this spell";
}
}

View file

@ -0,0 +1,53 @@
package mage.watchers.common;
import mage.MageObjectReference;
import mage.constants.WatcherScope;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.ModifiedPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
import java.util.HashMap;
/**
*
* @author weirddan455
*/
public class ControlledModifiedCreatureAsSpellCastWatcher extends Watcher {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.add(ModifiedPredicate.instance);
}
public ControlledModifiedCreatureAsSpellCastWatcher() {
super(WatcherScope.GAME);
}
private final HashMap<MageObjectReference, Boolean> spellsCastCondition = new HashMap<>();
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
Spell spell = game.getSpell(event.getTargetId());
if (spell != null) {
MageObjectReference mor = new MageObjectReference(spell, game);
Boolean condition = !game.getBattlefield().getAllActivePermanents(filter, spell.getControllerId(), game).isEmpty();
spellsCastCondition.put(mor, condition);
}
}
}
@Override
public void reset() {
super.reset();
spellsCastCondition.clear();
}
public boolean checkModifiedCondition(MageObjectReference mor) {
return spellsCastCondition.getOrDefault(mor, false);
}
}