[MOM] Implement Zephyr Singer

This commit is contained in:
theelk801 2023-04-09 13:19:13 -04:00
parent 47fe90458f
commit 2c0486673f
7 changed files with 150 additions and 95 deletions

View file

@ -30,6 +30,7 @@ import mage.players.ManaPool;
import mage.players.Player;
import mage.target.Target;
import mage.target.common.TargetControlledCreaturePermanent;
import mage.watchers.common.ConvokeWatcher;
import java.util.ArrayList;
import java.util.List;
@ -79,6 +80,7 @@ public class ConvokeAbility extends SimpleStaticAbility implements AlternateMana
public ConvokeAbility() {
super(Zone.ALL, null); // all AlternateManaPaymentAbility must use ALL zone to calculate playable abilities
this.setRuleAtTheTop(true);
this.addWatcher(new ConvokeWatcher());
this.addHint(new ValueHint("Untapped creatures you control", new PermanentsOnBattlefieldCount(filterUntapped)));
}

View file

@ -0,0 +1,28 @@
package mage.filter.predicate.permanent;
import mage.MageObjectReference;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.watchers.common.ConvokeWatcher;
/**
* @author TheElk801
*/
public enum ConvokedSourcePredicate implements ObjectSourcePlayerPredicate<Permanent> {
PERMANENT(-1),
SPELL(0);
private final int offset;
ConvokedSourcePredicate(int offset) {
this.offset = offset;
}
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return ConvokeWatcher.checkConvoke(
new MageObjectReference(input.getSource(), offset), input.getObject(), game
);
}
}

View file

@ -16,11 +16,11 @@ import java.util.Set;
/**
* @author LevelX2
*/
public class EachCreatureThatConvokedSourceWatcher extends Watcher {
public class ConvokeWatcher extends Watcher {
private final Map<MageObjectReference, Set<MageObjectReference>> convokingCreatures = new HashMap<>();
public EachCreatureThatConvokedSourceWatcher() {
public ConvokeWatcher() {
super(WatcherScope.GAME);
}
@ -29,26 +29,28 @@ public class EachCreatureThatConvokedSourceWatcher extends Watcher {
if (event.getType() != GameEvent.EventType.CONVOKED) {
return;
}
Spell spell = game.getSpell(event.getSourceId());
Permanent tappedCreature = game.getPermanentOrLKIBattlefield(event.getTargetId());
if (spell == null || tappedCreature == null) {
return;
}
MageObjectReference convokedSpell = new MageObjectReference(spell.getSourceId(), game);
Set<MageObjectReference> creatures;
if (convokingCreatures.containsKey(convokedSpell)) {
creatures = convokingCreatures.get(convokedSpell);
} else {
creatures = new HashSet<>();
convokingCreatures.put(convokedSpell, creatures);
}
creatures.add(new MageObjectReference(tappedCreature, game));
convokingCreatures
.computeIfAbsent(new MageObjectReference(spell.getSourceId(), game), x -> new HashSet<>())
.add(new MageObjectReference(tappedCreature, game));
}
public Set<MageObjectReference> getConvokingCreatures(MageObjectReference mor) {
return convokingCreatures.get(mor);
public static Set<MageObjectReference> getConvokingCreatures(MageObjectReference mor, Game game) {
return game
.getState()
.getWatcher(ConvokeWatcher.class)
.convokingCreatures
.get(mor);
}
public static boolean checkConvoke(MageObjectReference mor, Permanent permanent, Game game) {
return getConvokingCreatures(mor, game)
.stream()
.anyMatch(m -> m.refersTo(permanent, game));
}
@Override