1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-03 17:00:16 -09:00

[AFR] Fixed Pack Tactics not triggering correctly ()

This commit is contained in:
Daniel Bomar 2021-07-04 09:07:38 -05:00 committed by GitHub
parent 27a55529a9
commit fc5e096ebf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,15 +3,11 @@ package mage.abilities.keyword;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.effects.Effect;
import mage.constants.AbilityWord;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
@ -21,7 +17,6 @@ public class PackTacticsAbility extends TriggeredAbilityImpl {
public PackTacticsAbility(Effect effect) {
super(Zone.BATTLEFIELD, effect, false);
this.addWatcher(new PackTacticsAbilityWatcher());
}
private PackTacticsAbility(final PackTacticsAbility ability) {
@ -35,12 +30,17 @@ public class PackTacticsAbility extends TriggeredAbilityImpl {
@Override
public boolean checkTrigger(GameEvent event, Game game) {
return getSourceId().equals(event.getSourceId());
}
@Override
public boolean checkInterveningIfClause(Game game) {
return PackTacticsAbilityWatcher.checkPlayer(getControllerId(), game);
if (getSourceId().equals(event.getSourceId())) {
int power = 0;
for (UUID attackerId : game.getCombat().getAttackers()) {
Permanent attacker = game.getPermanent(attackerId);
if (attacker != null) {
power += attacker.getPower().getValue();
}
}
return power >= 6;
}
return false;
}
@Override
@ -55,37 +55,3 @@ public class PackTacticsAbility extends TriggeredAbilityImpl {
"with total power 6 or greater this combat, " + super.getRule();
}
}
class PackTacticsAbilityWatcher extends Watcher {
private final Map<UUID, Integer> playerMap = new HashMap<>();
PackTacticsAbilityWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
switch (event.getType()) {
case BEGIN_COMBAT_STEP_PRE:
playerMap.clear();
return;
case ATTACKER_DECLARED:
Permanent permanent = game.getPermanent(event.getSourceId());
if (permanent == null) {
return;
}
playerMap.compute(
permanent.getControllerId(),
(u, i) -> i == null ?
permanent.getPower().getValue() :
Integer.sum(permanent.getPower().getValue(), i)
);
}
}
static boolean checkPlayer(UUID playerId, Game game) {
PackTacticsAbilityWatcher watcher = game.getState().getWatcher(PackTacticsAbilityWatcher.class);
return watcher != null && watcher.playerMap.getOrDefault(playerId, 0) >= 6;
}
}