mirror of
https://github.com/correl/mage.git
synced 2024-11-25 03:00:11 +00:00
fix melee ability counting planeswalkers
This commit is contained in:
parent
7259fa9af1
commit
2d2438ba66
1 changed files with 26 additions and 42 deletions
|
@ -1,7 +1,5 @@
|
||||||
package mage.abilities.keyword;
|
package mage.abilities.keyword;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.abilities.common.AttacksTriggeredAbility;
|
import mage.abilities.common.AttacksTriggeredAbility;
|
||||||
import mage.abilities.dynamicvalue.DynamicValue;
|
import mage.abilities.dynamicvalue.DynamicValue;
|
||||||
|
@ -11,17 +9,17 @@ import mage.constants.Duration;
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.GameEvent.EventType;
|
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
* @author emerald000
|
* @author emerald000
|
||||||
*/
|
*/
|
||||||
public class MeleeAbility extends AttacksTriggeredAbility {
|
public class MeleeAbility extends AttacksTriggeredAbility {
|
||||||
|
|
||||||
public MeleeAbility() {
|
public MeleeAbility() {
|
||||||
super(new BoostSourceEffect(new MeleeDynamicValue(), new MeleeDynamicValue(), Duration.EndOfTurn), false);
|
super(new BoostSourceEffect(MeleeDynamicValue.instance, MeleeDynamicValue.instance, Duration.EndOfTurn), false);
|
||||||
this.addWatcher(new MeleeWatcher());
|
this.addWatcher(new MeleeWatcher());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +40,7 @@ public class MeleeAbility extends AttacksTriggeredAbility {
|
||||||
|
|
||||||
class MeleeWatcher extends Watcher {
|
class MeleeWatcher extends Watcher {
|
||||||
|
|
||||||
private Map<UUID, Set<UUID>> playersAttacked = new HashMap<>(0);
|
private final Map<UUID, Set<UUID>> playersAttacked = new HashMap<>(0);
|
||||||
|
|
||||||
public MeleeWatcher() {
|
public MeleeWatcher() {
|
||||||
super(WatcherScope.GAME);
|
super(WatcherScope.GAME);
|
||||||
|
@ -50,55 +48,41 @@ class MeleeWatcher extends Watcher {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
if (event.getType() == GameEvent.EventType.BEGIN_COMBAT_STEP_PRE) {
|
switch (event.getType()) {
|
||||||
this.playersAttacked.clear();
|
case BEGIN_COMBAT_STEP_PRE:
|
||||||
}
|
this.playersAttacked.clear();
|
||||||
else if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED) {
|
return;
|
||||||
Set<UUID> attackedPlayers = this.playersAttacked.getOrDefault(event.getPlayerId(), new HashSet<>(1));
|
case ATTACKER_DECLARED:
|
||||||
attackedPlayers.add(event.getTargetId());
|
if (game.getPlayer(event.getTargetId()) == null) {
|
||||||
this.playersAttacked.put(event.getPlayerId(), attackedPlayers);
|
return;
|
||||||
|
}
|
||||||
|
this.playersAttacked
|
||||||
|
.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>())
|
||||||
|
.add(event.getTargetId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfAttackedPlayers(UUID attackerId) {
|
public static int getNumberOfAttackedPlayers(UUID attackerId, Game game) {
|
||||||
if (this.playersAttacked.get(attackerId) != null) {
|
return game
|
||||||
return this.playersAttacked.get(attackerId).size();
|
.getState()
|
||||||
}
|
.getWatcher(MeleeWatcher.class)
|
||||||
return 0;
|
.playersAttacked
|
||||||
|
.getOrDefault(attackerId, Collections.emptySet())
|
||||||
|
.size();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MeleeDynamicValue implements DynamicValue {
|
enum MeleeDynamicValue implements DynamicValue {
|
||||||
|
instance;
|
||||||
private boolean valueChecked;
|
|
||||||
private int lockedInValue;
|
|
||||||
|
|
||||||
public MeleeDynamicValue() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected MeleeDynamicValue(final MeleeDynamicValue dynamicValue) {
|
|
||||||
super();
|
|
||||||
valueChecked = dynamicValue.valueChecked;
|
|
||||||
lockedInValue = dynamicValue.lockedInValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||||
MeleeWatcher watcher = game.getState().getWatcher(MeleeWatcher.class);
|
return MeleeWatcher.getNumberOfAttackedPlayers(sourceAbility.getSourceId(), game);
|
||||||
if (watcher != null) {
|
|
||||||
if (!valueChecked) {
|
|
||||||
this.lockedInValue = watcher.getNumberOfAttackedPlayers(sourceAbility.getControllerId());
|
|
||||||
valueChecked = true;
|
|
||||||
}
|
|
||||||
return this.lockedInValue;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MeleeDynamicValue copy() {
|
public MeleeDynamicValue copy() {
|
||||||
return new MeleeDynamicValue(this);
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue