mirror of
https://github.com/magefree/mage.git
synced 2026-01-10 04:42:07 -08:00
[LCI] Implement Subterranean Schooner
This commit is contained in:
parent
0e3c31ca7b
commit
e4ae0f6df5
5 changed files with 141 additions and 97 deletions
|
|
@ -0,0 +1,26 @@
|
|||
package mage.filter.predicate.permanent;
|
||||
|
||||
import mage.filter.predicate.ObjectSourcePlayer;
|
||||
import mage.filter.predicate.ObjectSourcePlayerPredicate;
|
||||
import mage.game.Game;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.watchers.common.CrewedVehicleWatcher;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum CrewedSourceThisTurnPredicate implements ObjectSourcePlayerPredicate<Permanent> {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
|
||||
return CrewedVehicleWatcher.checkIfCrewedThisTurn(
|
||||
input.getObject(), input.getSource().getSourcePermanentOrLKI(game), game
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "crewed {this} this turn";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,46 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.MageObjectReference;
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class CrewedVehicleWatcher extends Watcher {
|
||||
|
||||
private final Map<MageObjectReference, Set<MageObjectReference>> crewMap = new HashMap<>();
|
||||
|
||||
public CrewedVehicleWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.CREWED_VEHICLE) {
|
||||
crewMap.computeIfAbsent(new MageObjectReference(event.getSourceId(), game), x -> new HashSet<>())
|
||||
.add(new MageObjectReference(event.getTargetId(), game));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
crewMap.clear();
|
||||
}
|
||||
|
||||
public static boolean checkIfCrewedThisTurn(Permanent crewer, Permanent crewed, Game game) {
|
||||
return game
|
||||
.getState()
|
||||
.getWatcher(CrewedVehicleWatcher.class)
|
||||
.crewMap
|
||||
.getOrDefault(new MageObjectReference(crewed, game), Collections.emptySet())
|
||||
.stream()
|
||||
.anyMatch(mor -> mor.refersTo(crewer, game));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue