mirror of
https://github.com/magefree/mage.git
synced 2025-12-20 02:30:08 -08:00
[TLE] Implement Tale of Momo
This commit is contained in:
parent
ebf82309fc
commit
36c6210cee
5 changed files with 141 additions and 45 deletions
|
|
@ -0,0 +1,30 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.abilities.hint.ConditionHint;
|
||||
import mage.abilities.hint.Hint;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.CreatureLeftBattlefieldWatcher;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum CreatureLeftThisTurnCondition implements Condition {
|
||||
instance;
|
||||
private static final Hint hint = new ConditionHint(instance);
|
||||
|
||||
public static Hint getHint() {
|
||||
return hint;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return CreatureLeftBattlefieldWatcher.getNumberCreatureLeft(source.getControllerId(), game) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "a creature left the battlefield under your control this turn";
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.game.events.ZoneChangeEvent;
|
||||
import mage.util.CardUtil;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author Susucr
|
||||
*/
|
||||
public class CreatureLeftBattlefieldWatcher extends Watcher {
|
||||
|
||||
// player -> number of creatures that left the battlefield under that player's control this turn
|
||||
private final Map<UUID, Integer> mapCreaturesLeft = new HashMap<>();
|
||||
|
||||
public CreatureLeftBattlefieldWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() != GameEvent.EventType.ZONE_CHANGE) {
|
||||
return;
|
||||
}
|
||||
ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
|
||||
if (Zone.BATTLEFIELD.match(zEvent.getFromZone()) && zEvent.getTarget().isCreature(game)) {
|
||||
mapCreaturesLeft.compute(zEvent.getTarget().getControllerId(), CardUtil::setOrIncrementValue);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
mapCreaturesLeft.clear();
|
||||
}
|
||||
|
||||
public static int getNumberCreatureLeft(UUID playerId, Game game) {
|
||||
return game
|
||||
.getState()
|
||||
.getWatcher(CreatureLeftBattlefieldWatcher.class)
|
||||
.mapCreaturesLeft
|
||||
.getOrDefault(playerId, 0);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue