[WOE] Implement Ash, Party Crasher (add Celebration Condition) (#10818)

* implement Ash, Party Crasher (add Celebration Condition)

* test Celebration with Ash
This commit is contained in:
Susucre 2023-08-16 14:31:02 +02:00 committed by GitHub
parent 853400ef46
commit cbec9ead63
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 281 additions and 0 deletions

View file

@ -0,0 +1,25 @@
package mage.abilities.condition.common;
import mage.abilities.Ability;
import mage.abilities.condition.Condition;
import mage.game.Game;
import mage.watchers.common.CelebrationWatcher;
/**
* @author Susucr
*/
public enum CelebrationCondition implements Condition {
instance;
@Override
public boolean apply(Game game, Ability source) {
CelebrationWatcher watcher = game.getState().getWatcher(CelebrationWatcher.class);
return watcher != null && watcher.celebrationActive(source.getControllerId());
}
@Override
public String toString() {
return "two or more nonland permanents entered the battlefield under your control this turn";
}
}

View file

@ -12,6 +12,7 @@ public enum AbilityWord {
ALLIANCE("Alliance"),
BATTALION("Battalion"),
BLOODRUSH("Bloodrush"),
CELEBRATION("Celebration"),
CHANNEL("Channel"),
CHROMA("Chroma"),
COHORT("Cohort"),

View file

@ -0,0 +1,47 @@
package mage.watchers.common;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.util.CardUtil;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author Susucr
*/
public class CelebrationWatcher extends Watcher {
// playerId -> number of nonland permanents entered the battlefield this turn under that player's control.
private final Map<UUID, Integer> celebrationCounts = new HashMap<>();
public CelebrationWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
return;
}
Permanent permanent = game.getPermanent(event.getTargetId());
if (permanent != null && !permanent.isLand(game)) {
celebrationCounts.compute(permanent.getControllerId(), CardUtil::setOrIncrementValue);
}
}
public boolean celebrationActive(UUID playerId) {
return celebrationCounts.getOrDefault(playerId, 0) >= 2;
}
@Override
public void reset() {
super.reset();
celebrationCounts.clear();
}
}