Search in sources :

Example 1 with SkillFilter

use of pcgen.cdom.enumeration.SkillFilter in project pcgen by PCGen.

the class PlayerCharacter method getSkillFilter.

/**
	 * @return The selected skill display filter.
	 */
public SkillFilter getSkillFilter() {
    SkillFilter filter = skillFilterFacet.get(id);
    if (filter == null) {
        filter = SkillFilter.getByValue(PCGenSettings.OPTIONS_CONTEXT.initInt(PCGenSettings.OPTION_SKILL_FILTER, SkillFilter.Usable.getValue()));
        if (filter == SkillFilter.SkillsTab) {
            filter = SkillFilter.Usable;
        }
        setSkillFilter(filter);
    }
    return filter;
}
Also used : SkillFilter(pcgen.cdom.enumeration.SkillFilter)

Example 2 with SkillFilter

use of pcgen.cdom.enumeration.SkillFilter in project pcgen by PCGen.

the class SkillToken method getSkill.

/**
	 * Select the target skill based on the supplied critieria. Uses the
	 * id in the details object to either retrieve a skill by name or by
	 * position in the skill list.
	 *
	 * @param pc The character being processed.
	 * @param details The parsed details of the token.
	 * @param eh The ExportHandler
	 * @return The matching skill, or null if none match.
	 */
private Skill getSkill(PlayerCharacter pc, SkillDetails details, ExportHandler eh) {
    Skill skill = null;
    try {
        final int i = Integer.parseInt(details.getSkillId());
        final List<Skill> pcSkills = new ArrayList<>(getSkillList(pc));
        SkillFilter filter = details.getSkillFilter();
        if (filter == null || filter == SkillFilter.Selected) {
            filter = pc.getSkillFilter();
        }
        Iterator<Skill> iter = pcSkills.iterator();
        while (iter.hasNext()) {
            Skill sk = iter.next();
            if (!pc.includeSkill(sk, filter) || !sk.qualifies(pc, null)) {
                iter.remove();
            }
        }
        if ((i >= (pcSkills.size() - 1)) && eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
        if (i < pcSkills.size()) {
            skill = pcSkills.get(i);
        }
    } catch (NumberFormatException exc) {
        //Allowing SKILL.Spot.<subtoken>
        skill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, details.getSkillId());
    }
    return skill;
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) SkillFilter(pcgen.cdom.enumeration.SkillFilter)

Example 3 with SkillFilter

use of pcgen.cdom.enumeration.SkillFilter in project pcgen by PCGen.

the class PCCountSkillsTermEvaluator method resolve.

@Override
public Float resolve(PlayerCharacter pc) {
    int count = 0;
    //TODO This is a bug, it assumes export
    final List<Skill> skills = pc.getDisplay().getPartialSkillList(View.VISIBLE_EXPORT);
    SkillFilter filter = SkillFilter.getByToken(filterToken);
    if (filter == null || filter == SkillFilter.Selected) {
        filter = pc.getSkillFilter();
    }
    for (Skill sk : skills) {
        if (pc.includeSkill(sk, filter) && sk.qualifies(pc, null)) {
            count++;
        }
    }
    return (float) count;
}
Also used : Skill(pcgen.core.Skill) SkillFilter(pcgen.cdom.enumeration.SkillFilter)

Example 4 with SkillFilter

use of pcgen.cdom.enumeration.SkillFilter in project pcgen by PCGen.

the class SkillToken method buildSkillDetails.

/**
	 * Given the source of the token, split it up into its skill id and
	 * properties. The token itself is ignopred as this has already been
	 * processed elsewhere. The expected format is token.skillid.property...
	 *
	 * @param tokenSource The source of the token.
	 * @return A SkillDetails containing the details of the token.
	 */
public static SkillDetails buildSkillDetails(String tokenSource) {
    final StringTokenizer aTok = new StringTokenizer(tokenSource, ".");
    SkillFilter filter = null;
    List<String> properties = new ArrayList<>();
    // Split out the parts of the source
    String skillId = "";
    for (int i = 0; aTok.hasMoreTokens(); ++i) {
        String token = aTok.nextToken();
        if (i == 0) {
        // Ignore
        } else if (i == 1) {
            skillId = token;
        } else {
            filter = SkillFilter.getByToken(token);
            if (filter != null) {
                if (aTok.hasMoreTokens()) {
                    token = aTok.nextToken();
                } else {
                    token = "NAME";
                }
            }
            properties.add(token);
        }
    }
    // Create and return the SkillDetails object.
    return new SkillDetails(skillId, properties, filter);
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) SkillFilter(pcgen.cdom.enumeration.SkillFilter)

Example 5 with SkillFilter

use of pcgen.cdom.enumeration.SkillFilter in project pcgen by PCGen.

the class SkillSitToken method getSkill.

/**
	 * Select the target skill based on the supplied criteria. Uses the
	 * id in the details object to either retrieve a skill by name or by
	 * position in the skill list.
	 *
	 * @param pc The character being processed.
	 * @param details The parsed details of the token.
	 * @param eh The ExportHandler
	 * @return The matching skill, or null if none match.
	 */
private Object getSkill(PlayerCharacter pc, SkillDetails details, ExportHandler eh) {
    Object skill = null;
    try {
        int i = Integer.parseInt(details.getSkillId());
        final List<Skill> pcSkills = new ArrayList<>(getSkillList(pc));
        SkillFilter filter = details.getSkillFilter();
        if (filter == null || filter == SkillFilter.Selected) {
            filter = pc.getSkillFilter();
        }
        Iterator<Skill> iter = pcSkills.iterator();
        while (iter.hasNext()) {
            Skill sk = iter.next();
            if (!pc.includeSkill(sk, filter) || !sk.qualifies(pc, null)) {
                iter.remove();
            }
        }
        if ((i >= (pcSkills.size() - 1)) && eh != null && eh.getExistsOnly()) {
            eh.setNoMoreItems(true);
        }
        for (iter = pcSkills.iterator(); i >= 0; ) {
            Skill sk = iter.next();
            if (i == 0) {
                return sk;
            }
            //wasn't the base skill
            i--;
            List<String> situations = new ArrayList<>(sk.getUniqueListFor(ListKey.SITUATION));
            if (situations != null) {
                int numSits = situations.size();
                if (i < numSits) {
                    Collections.sort(situations);
                }
                for (String situation : situations) {
                    double bonus = pc.getTotalBonusTo("SITUATION", sk.getKeyName() + '=' + situation);
                    if (bonus > 0.01 || bonus < -0.01) {
                        if (i == 0) {
                            return new SkillSituation(sk, situation, bonus);
                        }
                        //Wasn't this situation
                        i--;
                    }
                }
            }
        }
    } catch (NumberFormatException exc) {
        String skillName = details.getSkillId();
        int equalLoc = skillName.indexOf("=");
        if (equalLoc == -1) {
            //Allowing SKILL.Spot.<subtoken>
            skill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillName);
        } else {
            //Allowing SKILL.Spot=Situation.<subtoken>
            String situation = skillName.substring(equalLoc + 1);
            Skill sk = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, skillName.substring(0, equalLoc));
            double bonus = pc.getTotalBonusTo("SITUATION", sk.getKeyName() + '=' + situation);
            return new SkillSituation(sk, situation, bonus);
        }
    }
    return skill;
}
Also used : Skill(pcgen.core.Skill) ArrayList(java.util.ArrayList) SkillFilter(pcgen.cdom.enumeration.SkillFilter) SkillSituation(pcgen.cdom.helper.SkillSituation)

Aggregations

SkillFilter (pcgen.cdom.enumeration.SkillFilter)5 ArrayList (java.util.ArrayList)3 Skill (pcgen.core.Skill)3 StringTokenizer (java.util.StringTokenizer)1 SkillSituation (pcgen.cdom.helper.SkillSituation)1