mirror of
https://github.com/correl/mage.git
synced 2025-03-17 01:06:26 -09:00
[CMR] fixed Belbe, Corrupted Observer - wrong life lose watcher, added card's hint (#7198);
This commit is contained in:
parent
c548b3fd1d
commit
c13716d1c5
1 changed files with 47 additions and 15 deletions
|
@ -4,7 +4,11 @@ import mage.MageInt;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.BeginningOfPostCombatMainTriggeredAbility;
|
import mage.abilities.common.BeginningOfPostCombatMainTriggeredAbility;
|
||||||
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
|
import mage.abilities.effects.Effect;
|
||||||
import mage.abilities.effects.OneShotEffect;
|
import mage.abilities.effects.OneShotEffect;
|
||||||
|
import mage.abilities.hint.Hint;
|
||||||
|
import mage.abilities.hint.ValueHint;
|
||||||
import mage.cards.CardImpl;
|
import mage.cards.CardImpl;
|
||||||
import mage.cards.CardSetInfo;
|
import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
|
@ -20,6 +24,8 @@ import java.util.*;
|
||||||
*/
|
*/
|
||||||
public final class BelbeCorruptedObserver extends CardImpl {
|
public final class BelbeCorruptedObserver extends CardImpl {
|
||||||
|
|
||||||
|
private static final Hint hint = new ValueHint("Opponents who lost life that turn", BelbeCorruptedObserverDynamicValue.instance);
|
||||||
|
|
||||||
public BelbeCorruptedObserver(UUID ownerId, CardSetInfo setInfo) {
|
public BelbeCorruptedObserver(UUID ownerId, CardSetInfo setInfo) {
|
||||||
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{B}{G}");
|
super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{B}{G}");
|
||||||
|
|
||||||
|
@ -32,7 +38,7 @@ public final class BelbeCorruptedObserver extends CardImpl {
|
||||||
// At the beginning of each player's postcombat main phase, that player adds {C}{C} for each of your opponents who lost life this turn.
|
// At the beginning of each player's postcombat main phase, that player adds {C}{C} for each of your opponents who lost life this turn.
|
||||||
this.addAbility(new BeginningOfPostCombatMainTriggeredAbility(
|
this.addAbility(new BeginningOfPostCombatMainTriggeredAbility(
|
||||||
new BelbeCorruptedObserverEffect(), TargetController.ANY, false
|
new BelbeCorruptedObserverEffect(), TargetController.ANY, false
|
||||||
), new BelbeCorruptedObserverWatcher());
|
).addHint(hint), new BelbeCorruptedObserverWatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
private BelbeCorruptedObserver(final BelbeCorruptedObserver card) {
|
private BelbeCorruptedObserver(final BelbeCorruptedObserver card) {
|
||||||
|
@ -64,19 +70,22 @@ class BelbeCorruptedObserverEffect extends OneShotEffect {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Game game, Ability source) {
|
public boolean apply(Game game, Ability source) {
|
||||||
Player player = game.getPlayer(game.getActivePlayerId());
|
Player player = game.getPlayer(game.getActivePlayerId());
|
||||||
BelbeCorruptedObserverWatcher watcher = game.getState().getWatcher(BelbeCorruptedObserverWatcher.class);
|
if (player == null) {
|
||||||
if (player == null || watcher == null) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
int playerCount = watcher.getOpponentCount(source.getControllerId());
|
|
||||||
player.getManaPool().addMana(Mana.ColorlessMana(2 * playerCount), game, source);
|
int playerCount = BelbeCorruptedObserverDynamicValue.instance.calculate(game, source, this);
|
||||||
return true;
|
if (playerCount > 0) {
|
||||||
|
player.getManaPool().addMana(Mana.ColorlessMana(2 * playerCount), game, source);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class BelbeCorruptedObserverWatcher extends Watcher {
|
class BelbeCorruptedObserverWatcher extends Watcher {
|
||||||
|
|
||||||
private final Map<UUID, Set<UUID>> playerMap = new HashMap<>();
|
private final Map<UUID, Set<UUID>> opponentsWhoLostLife = new HashMap<>();
|
||||||
|
|
||||||
BelbeCorruptedObserverWatcher() {
|
BelbeCorruptedObserverWatcher() {
|
||||||
super(WatcherScope.GAME);
|
super(WatcherScope.GAME);
|
||||||
|
@ -87,20 +96,43 @@ class BelbeCorruptedObserverWatcher extends Watcher {
|
||||||
if (event.getType() != GameEvent.EventType.LOST_LIFE) {
|
if (event.getType() != GameEvent.EventType.LOST_LIFE) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
game.getOpponents(event.getPlayerId())
|
game.getOpponents(event.getPlayerId()).forEach(uuid -> {
|
||||||
.stream()
|
opponentsWhoLostLife
|
||||||
.map(uuid -> playerMap
|
.computeIfAbsent(uuid, x -> new HashSet<>())
|
||||||
.computeIfAbsent(uuid, x -> new HashSet<>())
|
.add(event.getPlayerId());
|
||||||
.add(event.getPlayerId()));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
playerMap.clear();
|
opponentsWhoLostLife.clear();
|
||||||
super.reset();
|
super.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
int getOpponentCount(UUID playerId) {
|
int getOpponentCount(UUID controllerId) {
|
||||||
return playerMap.computeIfAbsent(playerId, x -> new HashSet<>()).size();
|
return opponentsWhoLostLife.computeIfAbsent(controllerId, x -> new HashSet<>()).size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum BelbeCorruptedObserverDynamicValue implements DynamicValue {
|
||||||
|
instance;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||||
|
BelbeCorruptedObserverWatcher watcher = game.getState().getWatcher(BelbeCorruptedObserverWatcher.class);
|
||||||
|
if (watcher != null) {
|
||||||
|
return watcher.getOpponentCount(sourceAbility.getControllerId());
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DynamicValue copy() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getMessage() {
|
||||||
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue