mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
[MH2] Implemented Recalibrate
This commit is contained in:
parent
2bcb06775b
commit
acb8070d6b
6 changed files with 140 additions and 45 deletions
|
|
@ -0,0 +1,18 @@
|
|||
package mage.abilities.condition.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.Condition;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.DiscardedCardWatcher;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum ControllerDiscardedThisTurnCondition implements Condition {
|
||||
instance;
|
||||
|
||||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
return DiscardedCardWatcher.checkPlayerDiscarded(source.getControllerId(), game);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package mage.abilities.hint.common;
|
||||
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.condition.common.ControllerDiscardedThisTurnCondition;
|
||||
import mage.abilities.hint.ConditionHint;
|
||||
import mage.abilities.hint.Hint;
|
||||
import mage.game.Game;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public enum ControllerDiscardedHint implements Hint {
|
||||
instance;
|
||||
|
||||
private static final Hint hint = new ConditionHint(
|
||||
ControllerDiscardedThisTurnCondition.instance, "You discarded a card this turn"
|
||||
);
|
||||
|
||||
@Override
|
||||
public String getText(Game game, Ability ability) {
|
||||
return hint.getText(game, ability);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ControllerDiscardedHint copy() {
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
package mage.watchers.common;
|
||||
|
||||
import mage.constants.WatcherScope;
|
||||
import mage.game.Game;
|
||||
import mage.game.events.GameEvent;
|
||||
import mage.watchers.Watcher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* @author TheElk801
|
||||
*/
|
||||
public class DiscardedCardWatcher extends Watcher {
|
||||
|
||||
private final Map<UUID, Integer> playerMap = new HashMap<>();
|
||||
|
||||
public DiscardedCardWatcher() {
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
if (event.getType() == GameEvent.EventType.DISCARDED_CARD) {
|
||||
playerMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
playerMap.clear();
|
||||
super.reset();
|
||||
}
|
||||
|
||||
public static boolean checkPlayerDiscarded(UUID playerId, Game game) {
|
||||
DiscardedCardWatcher watcher = game.getState().getWatcher(DiscardedCardWatcher.class);
|
||||
return watcher != null && watcher.playerMap.getOrDefault(playerId, 0) > 0;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue