use of mage.game.stack.StackObject in project mage by magefree.
the class ValiantRescuerWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ACTIVATED_ABILITY || game.getState().getStack().isEmpty()) {
return;
}
StackObject item = game.getState().getStack().getFirst();
if (item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility) {
playerMap.computeIfAbsent(event.getPlayerId(), u -> new HashMap<>());
playerMap.get(event.getPlayerId()).compute(event.getSourceId(), CardUtil::setOrIncrementValue);
}
}
use of mage.game.stack.StackObject in project mage by magefree.
the class ValiantRescuerWatcher method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
ValiantRescuerWatcher watcher = game.getState().getWatcher(ValiantRescuerWatcher.class);
if (watcher == null || !watcher.checkSpell(event.getPlayerId(), event.getSourceId()) || game.getState().getStack().isEmpty() || !event.getPlayerId().equals(this.getControllerId()) || event.getSourceId().equals(this.getSourceId())) {
return false;
}
StackObject item = game.getState().getStack().getFirst();
return item instanceof StackAbility && item.getStackAbility() instanceof CyclingAbility;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class BecomesTargetControlledPermanentTriggeredAbility method checkTrigger.
@Override
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());
if (permanent == null || !permanent.isControlledBy(this.getControllerId())) {
return false;
}
// If a spell or ability an opponent controls targets a single permanent you control more than once,
// Battle Mammoth’s triggered ability will trigger only once.
// 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;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class VariableCostImpl method announceXValue.
@Override
public int announceXValue(Ability source, Game game) {
int xValue = 0;
Player controller = game.getPlayer(source.getControllerId());
StackObject stackObject = game.getStack().getStackObject(source.getId());
if (controller != null && (source instanceof ManaAbility || stackObject != null)) {
xValue = controller.announceXCost(getMinValue(source, game), getMaxValue(source, game), "Announce the number of " + actionText, game, source, this);
}
return xValue;
}
use of mage.game.stack.StackObject in project mage by magefree.
the class GravestormEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getSourceId().equals(this.getSourceId())) {
StackObject spell = game.getStack().getStackObject(this.getSourceId());
if (spell instanceof Spell) {
for (Effect effect : this.getEffects()) {
effect.setValue("GravestormSpell", spell);
effect.setValue("GravestormSpellRef", new MageObjectReference(spell.getId(), game));
}
return true;
}
}
return false;
}
Aggregations