mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
- Fixed #6031
This commit is contained in:
parent
8b8d21d4ad
commit
4468a1abc6
1 changed files with 32 additions and 13 deletions
|
@ -1,5 +1,6 @@
|
||||||
package mage.cards.d;
|
package mage.cards.d;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.SimpleStaticAbility;
|
import mage.abilities.common.SimpleStaticAbility;
|
||||||
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
import mage.abilities.effects.ContinuousRuleModifyingEffectImpl;
|
||||||
|
@ -15,8 +16,7 @@ import mage.game.events.GameEvent;
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,13 +45,18 @@ class DeafeningSilenceEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
|
|
||||||
DeafeningSilenceEffect() {
|
DeafeningSilenceEffect() {
|
||||||
super(Duration.WhileOnBattlefield, Outcome.Detriment);
|
super(Duration.WhileOnBattlefield, Outcome.Detriment);
|
||||||
staticText = "each player can't cast more than one noncreature spell each turn";
|
staticText = "Each player can't cast more than one noncreature spell each turn";
|
||||||
}
|
}
|
||||||
|
|
||||||
private DeafeningSilenceEffect(final DeafeningSilenceEffect effect) {
|
private DeafeningSilenceEffect(final DeafeningSilenceEffect effect) {
|
||||||
super(effect);
|
super(effect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getInfoMessage(Ability source, GameEvent event, Game game) {
|
||||||
|
return "Each player can't cast more than one noncreature spell each turn";
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeafeningSilenceEffect copy() {
|
public DeafeningSilenceEffect copy() {
|
||||||
return new DeafeningSilenceEffect(this);
|
return new DeafeningSilenceEffect(this);
|
||||||
|
@ -69,18 +74,20 @@ class DeafeningSilenceEffect extends ContinuousRuleModifyingEffectImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean applies(GameEvent event, Ability source, Game game) {
|
public boolean applies(GameEvent event, Ability source, Game game) {
|
||||||
Card card = game.getCard(event.getTargetId());
|
Card card = game.getCard(event.getSourceId());
|
||||||
if (card == null || card.isCreature()) {
|
if (card == null
|
||||||
|
|| card.isCreature()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
DeafeningSilenceWatcher watcher = game.getState().getWatcher(DeafeningSilenceWatcher.class);
|
DeafeningSilenceWatcher watcher = game.getState().getWatcher(DeafeningSilenceWatcher.class);
|
||||||
return watcher != null && watcher.castSpell(event.getPlayerId());
|
return watcher != null
|
||||||
|
&& watcher.spellsCastByPlayerThisTurnNonCreature(event.getPlayerId()) > 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DeafeningSilenceWatcher extends Watcher {
|
class DeafeningSilenceWatcher extends Watcher {
|
||||||
|
|
||||||
private final Set<UUID> castSpell = new HashSet<>();
|
private final Map<UUID, Integer> spellsCastByPlayerThisTurnNonCreature = new HashMap<>();
|
||||||
|
|
||||||
DeafeningSilenceWatcher() {
|
DeafeningSilenceWatcher() {
|
||||||
super(WatcherScope.GAME);
|
super(WatcherScope.GAME);
|
||||||
|
@ -88,7 +95,9 @@ class DeafeningSilenceWatcher extends Watcher {
|
||||||
|
|
||||||
private DeafeningSilenceWatcher(final DeafeningSilenceWatcher watcher) {
|
private DeafeningSilenceWatcher(final DeafeningSilenceWatcher watcher) {
|
||||||
super(watcher);
|
super(watcher);
|
||||||
this.castSpell.addAll(watcher.castSpell);
|
for (Map.Entry<UUID, Integer> entry : watcher.spellsCastByPlayerThisTurnNonCreature.entrySet()) {
|
||||||
|
spellsCastByPlayerThisTurnNonCreature.put(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -97,19 +106,29 @@ class DeafeningSilenceWatcher extends Watcher {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Spell spell = game.getSpell(event.getTargetId());
|
Spell spell = game.getSpell(event.getTargetId());
|
||||||
if (spell == null || spell.isCreature()) {
|
if (spell == null
|
||||||
|
|| spell.isCreature()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
castSpell.add(event.getPlayerId());
|
UUID playerId = event.getPlayerId();
|
||||||
|
if (playerId != null) {
|
||||||
|
spellsCastByPlayerThisTurnNonCreature.putIfAbsent(playerId, 0);
|
||||||
|
spellsCastByPlayerThisTurnNonCreature.compute(playerId, (k, v) -> v + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() {
|
public void reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
castSpell.clear();
|
spellsCastByPlayerThisTurnNonCreature.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean castSpell(UUID playerId) {
|
public int spellsCastByPlayerThisTurnNonCreature(UUID playerId) {
|
||||||
return castSpell.contains(playerId);
|
return spellsCastByPlayerThisTurnNonCreature.getOrDefault(playerId, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeafeningSilenceWatcher copy() {
|
||||||
|
return new DeafeningSilenceWatcher(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue