public static int getTappedScore(final Permanent permanent) { if (permanent.getCardType().contains(CardType.CREATURE)) { return -100; } else if (permanent.getCardType().contains(CardType.LAND)) { return -20; // means probably no mana available (should be greater than passivity penalty } else { return -2; } }
/** * Returns all {@link Permanent} on the battlefield that match the specified * {@link CardType}. This method ignores the range of influence. * * @param type * @return a list of {@link Permanent} * @see Permanent */ public List<Permanent> getAllActivePermanents(CardType type) { return field.values() .stream() .filter(perm -> perm.isPhasedIn() && perm.getCardType().contains(type)) .collect(Collectors.toList()); }
@Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { Permanent permanent = affectedObjectList.get(0).getPermanent(game); if (permanent != null) { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { permanent.getCardType().clear(); permanent.getSubtype(game).clear(); if (!permanent.getCardType().contains(CardType.ENCHANTMENT)) { permanent.getCardType().add(CardType.ENCHANTMENT); } } break; } return true; } this.discard(); return false; }
@Override public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { Set<CardType> cardTypes = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); if(targetSource != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { for (CardType cardType : permanent.getCardType()) { if (cardTypes.contains(cardType)) { return true; } } cardTypes.addAll(permanent.getCardType()); } } } return false; }
@Override public boolean apply(Permanent input, Game game) { if (input.getAttachedTo() != null) { Permanent attachedTo = game.getPermanent(input.getAttachedTo()); if (attachedTo != null && attachedTo.getCardType().contains(cardType)) { return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, game)) { if (permanent != null && !permanent.getCardType().contains(addedCardType)) { permanent.addCardType(addedCardType); } } return true; }
public static int getFixedPermanentScore(final Game game, final Permanent permanent) { //TODO: cache it inside Card int score = getCardDefinitionScore(game, permanent); score += PERMANENT_SCORE; if (permanent.getCardType().contains(CardType.CREATURE)) { // TODO: implement in the mage core //score + =cardDefinition.getActivations().size()*50; //score += cardDefinition.getManaActivations().size()*80; } else { if (permanent.getSubtype(game).contains(SubType.EQUIPMENT)) { score += 100; } } return score; }
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { Player controller = game.getPlayer(sourceControllerId); EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class); if (controller != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) { if (controller.hasOpponent(permanent.getControllerId(), game)) { cardTypes.addAll(permanent.getCardType()); } } } return cardTypes; } }
@Override public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { if (super.canTarget(controllerId, id, source, game)) { Set<CardType> cardTypes = getOpponentPermanentCardTypes(source.getSourceId(), controllerId, game); Permanent permanent = game.getPermanent(id); for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { return true; } } } return false; }
@Override public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { if (super.canTarget(controllerId, id, source, game)) { Set<CardType> cardTypes = getOpponentPermanentCardTypes(source.getSourceId(), controllerId, game); Permanent permanent = game.getPermanent(id); for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { return true; } } } return false; }
private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) { Player controller = game.getPlayer(sourceControllerId); EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class); if (controller != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) { if (controller.hasOpponent(permanent.getControllerId(), game)) { cardTypes.addAll(permanent.getCardType()); } } } return cardTypes; } }
private static boolean canTap(Permanent permanent) { return !permanent.isTapped() && (!permanent.hasSummoningSickness() || !permanent.getCardType().contains(CardType.CREATURE) || permanent.getAbilities().contains(HasteAbility.getInstance())); }
@Override public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { // get all cardtypes from opponents permanents Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game); Set<UUID> possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); if (targetSource != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { possibleTargets.add(permanent.getId()); break; } } } } } return possibleTargets; }
@Override public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { // get all cardtypes from opponents permanents Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game); Set<UUID> possibleTargets = new HashSet<>(); MageObject targetSource = game.getObject(sourceId); if (targetSource != null) { for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { for (CardType type : permanent.getCardType()) { if (cardTypes.contains(type)) { possibleTargets.add(permanent.getId()); break; } } } } } return possibleTargets; }
public int evaluate(Permanent permanent, Game game) { if (!values.containsKey(permanent.getId())) { int value = 0; if (permanent.getCardType().contains(CardType.CREATURE)) { value += combat.evaluate(permanent, game); } value += permanent.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD).size(); value += permanent.getAbilities().getActivatedAbilities(Zone.BATTLEFIELD).size(); values.put(permanent.getId(), value); } return values.get(permanent.getId()); }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null && affectedObjectList.contains(new MageObjectReference(permanent, game))) { for (CardType cardType : addedCardTypes) { if (!permanent.getCardType().contains(cardType)) { permanent.addCardType(cardType); } } return true; } else if (this.getDuration() == Duration.Custom) { this.discard(); } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent equipment = game.getPermanent(source.getSourceId()); if (equipment != null && equipment.getAttachedTo() != null) { Permanent target = game.getPermanent(equipment.getAttachedTo()); if (target != null && !target.getCardType().contains(addedCardType)) { target.addCardType(addedCardType); } } return true; }
@Override public boolean apply(Game game, Ability source) { boolean result = false; for (UUID targetId : targetPointer.getTargets(game, source)) { Permanent target = game.getPermanent(targetId); if (target != null) { for (CardType cardType : addedCardTypes) { if (!target.getCardType().contains(cardType)) { target.addCardType(cardType); } } result = true; } } if (!result) { if (this.getDuration() == Duration.Custom) { this.discard(); } } return result; }
@Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { switch (layer) { case TypeChangingEffects_4: permanent.getCardType().clear(); permanent.addCardType(CardType.LAND); permanent.getSubtype(game).clear(); break; } return true; } return false; }
@Override public boolean apply(Layer layer, SubLayer sublayer, Ability source, Game game) { if (dynamicValue.calculate(game, source, this) >= lessThan) { return false; } Permanent permanent = game.getPermanent(source.getSourceId()); if (permanent != null) { switch (layer) { case TypeChangingEffects_4: if (sublayer == SubLayer.NA) { permanent.getCardType().remove(CardType.CREATURE); permanent.getSubtype(game).retainAll(SubType.getLandTypes(false)); if (permanent.isAttacking() || permanent.getBlocking() > 0) { permanent.removeFromCombat(game); } } break; } return true; } return false; }