mirror of
https://github.com/correl/mage.git
synced 2024-12-26 03:00:11 +00:00
[KHM] Fixed Battle Mammoth triggering too many times
This commit is contained in:
parent
c4750ff6c9
commit
cd4b93a71a
2 changed files with 31 additions and 6 deletions
|
@ -13,9 +13,10 @@ import mage.constants.Zone;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
|
import mage.game.stack.StackObject;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author TheElk801
|
* @author TheElk801
|
||||||
|
@ -71,13 +72,38 @@ class BattleMammothTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkTrigger(GameEvent event, Game game) {
|
public boolean checkTrigger(GameEvent event, Game game) {
|
||||||
|
StackObject sourceObject = game.getStack().getStackObject(event.getSourceId());
|
||||||
|
if (sourceObject == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Player targetter = game.getPlayer(event.getPlayerId());
|
||||||
|
if (targetter == null || !targetter.hasOpponent(this.controllerId, game)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
Permanent permanent = game.getPermanentOrLKIBattlefield(event.getTargetId());
|
||||||
if (permanent == null || !permanent.isControlledBy(this.getControllerId())) {
|
if (permanent == null || !permanent.isControlledBy(this.getControllerId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Player targetter = game.getPlayer(event.getPlayerId());
|
// If a spell or ability an opponent controls targets a single permanent you control more than once,
|
||||||
Object object = game.getObject(event.getSourceId());
|
// Battle Mammoth’s triggered ability will trigger only once.
|
||||||
return object != null && targetter != null && targetter.hasOpponent(this.getControllerId(), game);
|
// However, if a spell or ability an opponent controls targets multiple permanents you control,
|
||||||
|
// Battle Mammoth’s triggered ability will trigger once for each of those permanents.
|
||||||
|
|
||||||
|
// targetMap - key - targetId, value - Set of stackObject Ids
|
||||||
|
Map<UUID, Set<UUID>> targetMap = (Map<UUID, Set<UUID>>) game.getState().getValue("targetMap" + this.id);
|
||||||
|
if (targetMap == null) {
|
||||||
|
targetMap = new HashMap<>();
|
||||||
|
}
|
||||||
|
Set<UUID> sourceObjects = targetMap.get(event.getTargetId());
|
||||||
|
if (sourceObjects == null) {
|
||||||
|
sourceObjects = new HashSet<>();
|
||||||
|
}
|
||||||
|
if (!sourceObjects.add(sourceObject.getId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
targetMap.put(event.getTargetId(), sourceObjects);
|
||||||
|
game.getState().setValue("targetMap" + this.id, targetMap);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -87,10 +87,9 @@ class LeylineOfCombustionTriggeredAbility extends TriggeredAbilityImpl {
|
||||||
if (sourceObjects == null) {
|
if (sourceObjects == null) {
|
||||||
sourceObjects = new HashSet<>();
|
sourceObjects = new HashSet<>();
|
||||||
}
|
}
|
||||||
if (sourceObjects.contains(sourceObject.getId())) {
|
if (!sourceObjects.add(sourceObject.getId())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
sourceObjects.add(sourceObject.getId());
|
|
||||||
game.getState().setValue("sourceObjects" + this.id, sourceObjects);
|
game.getState().setValue("sourceObjects" + this.id, sourceObjects);
|
||||||
this.getEffects().clear();
|
this.getEffects().clear();
|
||||||
Effect effect = new DamageTargetEffect(2);
|
Effect effect = new DamageTargetEffect(2);
|
||||||
|
|
Loading…
Reference in a new issue