Search in sources :

Example 1 with Hint

use of mage.abilities.hint.Hint in project mage by magefree.

the class PermanentImpl method getRules.

/**
 * @param game can be null, e.g. for cards viewer
 * @return
 */
@Override
public List<String> getRules(Game game) {
    try {
        List<String> rules = getRules();
        // info
        if (info != null) {
            for (String data : info.values()) {
                rules.add(data);
            }
        }
        // ability hints
        List<String> abilityHints = new ArrayList<>();
        if (HintUtils.ABILITY_HINTS_ENABLE) {
            for (Ability ability : getAbilities(game)) {
                for (Hint hint : ability.getHints()) {
                    String s = hint.getText(game, ability);
                    if (s != null && !s.isEmpty()) {
                        abilityHints.add(s);
                    }
                }
            }
        }
        // restrict hints
        List<String> restrictHints = new ArrayList<>();
        if (game != null && HintUtils.RESTRICT_HINTS_ENABLE) {
            // restrict
            for (Map.Entry<RestrictionEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRestrictionEffects(this, game).entrySet()) {
                for (Ability ability : entry.getValue()) {
                    if (!entry.getKey().canAttack(game, false) || !entry.getKey().canAttack(this, null, ability, game, false)) {
                        restrictHints.add(HintUtils.prepareText("Can't attack" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT));
                    }
                    if (!entry.getKey().canBlock(null, this, ability, game, false)) {
                        restrictHints.add(HintUtils.prepareText("Can't block" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT));
                    }
                    if (!entry.getKey().canBeUntapped(this, ability, game, false)) {
                        restrictHints.add(HintUtils.prepareText("Can't untapped" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT));
                    }
                    if (!entry.getKey().canUseActivatedAbilities(this, ability, game, false)) {
                        restrictHints.add(HintUtils.prepareText("Can't use activated abilities" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT));
                    }
                    if (!entry.getKey().canTransform(this, ability, game, false)) {
                        restrictHints.add(HintUtils.prepareText("Can't transform" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_RESTRICT));
                    }
                }
            }
            // requirement
            for (Map.Entry<RequirementEffect, Set<Ability>> entry : game.getContinuousEffects().getApplicableRequirementEffects(this, false, game).entrySet()) {
                for (Ability ability : entry.getValue()) {
                    if (entry.getKey().mustAttack(game)) {
                        restrictHints.add(HintUtils.prepareText("Must attack" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    if (entry.getKey().mustBlock(game)) {
                        restrictHints.add(HintUtils.prepareText("Must block" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    if (entry.getKey().mustBlockAny(game)) {
                        restrictHints.add(HintUtils.prepareText("Must block any" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    if (entry.getKey().mustBlockAllAttackers(game)) {
                        restrictHints.add(HintUtils.prepareText("Must block all attackers" + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    MageObject object = game.getObject(entry.getKey().mustAttackDefender(ability, game));
                    if (object != null) {
                        restrictHints.add(HintUtils.prepareText("Must attack defender " + object.getLogName() + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    object = game.getObject(entry.getKey().mustBlockAttacker(ability, game));
                    if (object != null) {
                        restrictHints.add(HintUtils.prepareText("Must block attacker " + object.getLogName() + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                    object = game.getObject(entry.getKey().mustBlockAttackerIfElseUnblocked(ability, game));
                    if (object != null) {
                        restrictHints.add(HintUtils.prepareText("Must block attacker if able " + object.getLogName() + addSourceObjectName(game, ability), null, HintUtils.HINT_ICON_REQUIRE));
                    }
                }
            }
            restrictHints.sort(String::compareTo);
        }
        // total hints
        if (!abilityHints.isEmpty() || !restrictHints.isEmpty()) {
            rules.add(HintUtils.HINT_START_MARK);
            HintUtils.appendHints(rules, abilityHints);
            HintUtils.appendHints(rules, restrictHints);
        }
        return rules;
    } catch (Exception e) {
        return CardUtil.RULES_ERROR_INFO;
    }
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Hint(mage.abilities.hint.Hint) MageObject(mage.MageObject) RequirementEffect(mage.abilities.effects.RequirementEffect) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 2 with Hint

use of mage.abilities.hint.Hint in project mage by magefree.

the class CardUtil method getCardRulesWithAdditionalInfo.

/**
 * Prepare rules list from abilities
 *
 * @param rulesSource abilities list to show as rules
 * @param hintsSource abilities list to show as card hints only (you can add additional hints here; exameple: from second or transformed side)
 */
public static List<String> getCardRulesWithAdditionalInfo(Game game, UUID cardId, String cardName, Abilities<Ability> rulesSource, Abilities<Ability> hintsSource) {
    try {
        List<String> rules = rulesSource.getRules(cardName);
        if (game != null) {
            // debug state
            for (String data : game.getState().getCardState(cardId).getInfo().values()) {
                rules.add(data);
            }
            // ability hints
            List<String> abilityHints = new ArrayList<>();
            if (HintUtils.ABILITY_HINTS_ENABLE) {
                for (Ability ability : hintsSource) {
                    for (Hint hint : ability.getHints()) {
                        String s = hint.getText(game, ability);
                        if (s != null && !s.isEmpty()) {
                            abilityHints.add(s);
                        }
                    }
                }
            }
            // total hints
            if (!abilityHints.isEmpty()) {
                rules.add(HintUtils.HINT_START_MARK);
                HintUtils.appendHints(rules, abilityHints);
            }
        }
        return rules;
    } catch (Exception e) {
        logger.error("Exception in rules generation for card: " + cardName, e);
    }
    return RULES_ERROR_INFO;
}
Also used : SpellAbility(mage.abilities.SpellAbility) Ability(mage.abilities.Ability) Hint(mage.abilities.hint.Hint) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 3 with Hint

use of mage.abilities.hint.Hint in project mage by magefree.

the class StackAbilityView method updateTargets.

private void updateTargets(Game game, StackAbility ability) {
    List<String> names = new ArrayList<>();
    for (UUID modeId : ability.getModes().getSelectedModes()) {
        Mode mode = ability.getModes().get(modeId);
        if (!mode.getTargets().isEmpty()) {
            addTargets(mode.getTargets(), mode.getEffects(), ability, game);
        } else {
            List<UUID> targetList = new ArrayList<>();
            for (Effect effect : mode.getEffects()) {
                TargetPointer targetPointer = effect.getTargetPointer();
                if (targetPointer instanceof FixedTarget) {
                    targetList.add(((FixedTarget) targetPointer).getTarget());
                }
            }
            if (!targetList.isEmpty()) {
                overrideTargets(targetList);
                for (UUID uuid : targetList) {
                    MageObject mageObject = game.getObject(uuid);
                    if (mageObject != null) {
                        if ((mageObject instanceof Card) && ((Card) mageObject).isFaceDown(game)) {
                            continue;
                        }
                        String newName = GameLog.getColoredObjectIdNameForTooltip(mageObject);
                        if (!names.contains(newName)) {
                            names.add(newName);
                        }
                    }
                }
            }
        }
    }
    if (!names.isEmpty()) {
        getRules().add("<i>Related objects: " + names + "</i>");
    }
    // show for modal ability, which mode was choosen
    if (ability.isModal()) {
        Modes modes = ability.getModes();
        for (UUID modeId : modes.getSelectedModes()) {
            Mode mode = modes.get(modeId);
            this.rules.add("<span color='green'><i>Chosen mode: " + mode.getEffects().getText(mode) + "</i></span>");
        }
    }
    if (HintUtils.ABILITY_HINTS_ENABLE) {
        List<String> abilityHints = new ArrayList<>();
        for (Hint hint : ability.getHints()) {
            abilityHints.add(hint.getText(game, ability));
        }
        // total hints
        if (!abilityHints.isEmpty()) {
            rules.add(HintUtils.HINT_START_MARK);
            HintUtils.appendHints(rules, abilityHints);
        }
    }
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Modes(mage.abilities.Modes) Hint(mage.abilities.hint.Hint) Mode(mage.abilities.Mode) ArrayList(java.util.ArrayList) MageObject(mage.MageObject) Card(mage.cards.Card) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) TargetPointer(mage.target.targetpointer.TargetPointer)

Aggregations

Hint (mage.abilities.hint.Hint)3 MageObject (mage.MageObject)2 Ability (mage.abilities.Ability)2 SpellAbility (mage.abilities.SpellAbility)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 UUID (java.util.UUID)1 Mode (mage.abilities.Mode)1 Modes (mage.abilities.Modes)1 Effect (mage.abilities.effects.Effect)1 RequirementEffect (mage.abilities.effects.RequirementEffect)1 RestrictionEffect (mage.abilities.effects.RestrictionEffect)1 Card (mage.cards.Card)1 FixedTarget (mage.target.targetpointer.FixedTarget)1 TargetPointer (mage.target.targetpointer.TargetPointer)1