/** * Creates a string from text + cardId and the zoneChangeCounter of the card * (from cardId). This string can be used to save and get values that must * be specific to a permanent instance. So they won't match, if a permanent * was e.g. exiled and came back immediately. * * @param text short value to describe the value * @param cardId id of the card * @param game the game * @return */ public static String getCardZoneString(String text, UUID cardId, Game game) { return getCardZoneString(text, cardId, game, false); }
/** * Checks if the current object with sourceId has damaged the player during the current turn. * The zoneChangeCounter will be taken into account. * * @param sourceId * @param game * @return */ public boolean hasSourceDoneDamage(UUID sourceId, Game game) { return damageSourceIds.contains(CardUtil.getCardZoneString(null, sourceId, game)); }
public static UUID getCardExileZoneId(Game game, UUID sourceId, boolean previous) { return getExileZoneId(getCardZoneString(SOURCE_EXILE_ZONE_TEXT, sourceId, game, previous), game); }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == EventType.DAMAGED_PLAYER) { if (event.getTargetId().equals(controllerId)) { damageSourceIds.add(CardUtil.getCardZoneString(null, event.getSourceId(), game)); } } }
protected void setActivationInfo(ActivationInfo activationInfo, Game game) { game.getState().setValue(CardUtil .getCardZoneString("activationsTurn" + originalId, sourceId, game), activationInfo.turnNum); game.getState().setValue(CardUtil .getCardZoneString("activationsCount" + originalId, sourceId, game), activationInfo.activationCounter); } }
protected ActivationInfo getActivationInfo(Game game) { Integer turnNum = (Integer) game.getState() .getValue(CardUtil.getCardZoneString("activationsTurn" + originalId, sourceId, game)); Integer activationCount = (Integer) game.getState() .getValue(CardUtil.getCardZoneString("activationsCount" + originalId, sourceId, game)); if (turnNum == null || activationCount == null) { return null; } return new ActivationInfo(turnNum, activationCount); }
private void saveAttackingCreature(UUID attackerId, Integer zoneChangeCounter, Game game) { Set<String> attackers; Map<Integer, Set<String>> attackerMap; Object object = game.getState().getValue("blockedAttackers" + getSourceId()); if (object instanceof Map) { attackerMap = (Map<Integer, Set<String>>) object; } else { attackerMap = new HashMap<>(); } attackers = attackerMap.computeIfAbsent(zoneChangeCounter, k -> new HashSet<>()); attackers.add(CardUtil.getCardZoneString(null, attackerId, game)); game.getState().setValue("blockedAttackers" + getSourceId().toString(), attackerMap); }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (super.checkTrigger(event, game)) { for (Effect effect : this.getEffects()) { if (effect instanceof DualNatureExileEffect) { ((DualNatureExileEffect) effect).setCardZoneString(CardUtil.getCardZoneString("_tokensCreated", this.getSourceId(), game, true)); } } return true; } return false; }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (super.checkTrigger(event, game)) { for (Effect effect : this.getEffects()) { if (effect instanceof SaprolingBurstDestroyEffect) { ((SaprolingBurstDestroyEffect) effect).setCardZoneString(CardUtil.getCardZoneString("_tokensCreated", this.getSourceId(), game, true)); } } return true; } return false; }
@Override public void watch(GameEvent event, Game game) { if (event.getType() == GameEvent.EventType.BLOCKER_DECLARED) { Map<Integer, Set<String>> targetMap; Object object = game.getState().getValue("targets" + this.getSourceId().toString()); if (object instanceof Map) { Permanent blocker = game.getPermanent(event.getSourceId()); if (blocker != null) { targetMap = (Map<Integer, Set<String>>) object; for (Map.Entry<Integer, Set<String>> entry : targetMap.entrySet()) { if (entry.getValue().contains(CardUtil.getCardZoneString("", blocker.getId(), game))) { // save the attacking creature that was blocked by a creature effected by Triton Tactics saveAttackingCreature(event.getTargetId(), entry.getKey(), game); } } } } } }
@Override public void adjustCosts(Ability ability, Game game) { Player player = game.getPlayer(ability.getFirstTarget()); if (player != null) { String key = CardUtil.getCardZoneString("targetPlayer", this.getSourceId(), game); game.getState().setValue(key, player.getId()); } } }
@Override public void adjustCosts(Ability ability, Game game) { Player player = game.getPlayer(ability.getFirstTarget()); if (player != null) { String key = CardUtil.getCardZoneString("targetPlayer", this.getSourceId(), game); game.getState().setValue(key, player.getId()); } } }
@Override public boolean apply(Game game, Ability source) { Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game, true)); if (object != null) { Set<UUID> tokensCreated = (Set<UUID>) object; for (UUID tokenId : tokensCreated) { Permanent token = game.getPermanent(tokenId); if (token != null) { token.destroy(source.getSourceId(), game, true); } } } return true; } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (super.checkTrigger(event, game)) { String key = CardUtil.getCardZoneString("targetPlayer", this.getSourceId(), game, true); Object object = game.getState().getValue(key); if (object instanceof UUID) { this.getEffects().setTargetPointer(new FixedTarget((UUID) object)); return true; } } return false; }
@Override @SuppressWarnings("unchecked") public boolean apply(Game game, Ability source) { Token token = new SaprolingBurstToken(new MageObjectReference(source.getSourceObject(game), game)); token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId()); Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { Object object = game.getState().getValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game)); Set<UUID> tokensCreated; if (object != null) { tokensCreated = (Set<UUID>) object; } else { tokensCreated = new HashSet<>(); } for (UUID tokenId : token.getLastAddedTokenIds()) { tokensCreated.add(tokenId); } game.getState().setValue(CardUtil.getCardZoneString("_tokensCreated", source.getSourceId(), game), tokensCreated); } return true; } }
@Override public boolean checkTrigger(GameEvent event, Game game) { if (super.checkTrigger(event, game)) { String key = CardUtil.getCardZoneString("targetPlayer", this.getSourceId(), game, true); Object object = game.getState().getValue(key); if (object instanceof UUID) { for (Effect effect : this.getEffects()) { effect.setTargetPointer(new FixedTarget((UUID) object)); } return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { FilterPermanent filter = new FilterControlledLandPermanent("any number of " + sweepSubtype + "s you control"); filter.add(new SubtypePredicate(sweepSubtype)); Target target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true); if (controller.chooseTarget(outcome, target, source, game)) { game.getState().setValue(CardUtil.getCardZoneString("sweep", source.getSourceId(), game), target.getTargets().size()); controller.moveCards(new CardsImpl(target.getTargets()), Zone.HAND, source, game); } return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { String key = CardUtil.getCardZoneString("lifePaid", source.getSourceId(), game, true); Object object = game.getState().getValue(key); if (object instanceof Integer) { int lifePaid = (int) object; MinionToken token = new MinionToken(); token.getPower().modifyBaseValue(lifePaid); token.getToughness().modifyBaseValue(lifePaid); token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId()); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { Cards cards = new CardsImpl(source.getTargets().get(0).getTargets()); game.getState().setValue(CardUtil.getCardZoneString("ParadoxicalOutcomeEffect", source.getSourceId(), game), cards.size()); controller.moveCards(new CardsImpl(source.getTargets().get(0).getTargets()), Zone.HAND, source, game); return true; } return false; } }
@Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanentEntering(source.getSourceId()); if (controller == null || permanent == null) { return false; } int payAmount = controller.getAmount(0, controller.getLife(), "Pay any amount of life", game); Cost cost = new PayLifeCost(payAmount); if (!cost.pay(source, game, source.getSourceId(), source.getControllerId(), true)) { return false; } Card sourceCard = game.getCard(source.getSourceId()); game.informPlayers((sourceCard != null ? sourceCard.getName() : "") + ": " + controller.getLogName() + " pays " + payAmount + " life."); String key = CardUtil.getCardZoneString("lifePaid", source.getSourceId(), game); game.getState().setValue(key, payAmount); permanent.addInfo("life paid", CardUtil.addToolTipMarkTags("Life paid: " + payAmount), game); return true; } }