Search in sources :

Example 31 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class SpellsToken method unparse.

@Override
public String[] unparse(LoadContext context, KitSpells kitSpell) {
    StringBuilder sb = new StringBuilder();
    String spellBook = kitSpell.getSpellBook();
    String globalSpellbook = Globals.getDefaultSpellBook();
    if (spellBook != null && !globalSpellbook.equals(spellBook)) {
        sb.append("SPELLBOOK=").append(spellBook);
    }
    CDOMSingleRef<PCClass> castingClass = kitSpell.getCastingClass();
    if (castingClass != null) {
        if (sb.length() != 0) {
            sb.append(Constants.PIPE);
        }
        sb.append(Constants.LST_CLASS_EQUAL).append(castingClass.getLSTformat(false));
    }
    Collection<KnownSpellIdentifier> spells = kitSpell.getSpells();
    if (spells != null) {
        boolean needPipe = sb.length() > 0;
        for (KnownSpellIdentifier ksi : spells) {
            if (needPipe) {
                sb.append(Constants.PIPE);
            }
            needPipe = true;
            Collection<List<CDOMSingleRef<Ability>>> abilities = kitSpell.getAbilities(ksi);
            for (List<CDOMSingleRef<Ability>> abils : abilities) {
                StringBuilder spell = new StringBuilder();
                spell.append(StringUtil.replaceAll(ksi.getLSTformat(), Constants.LST_TYPE_EQUAL, Constants.LST_TYPE_DOT));
                if (abils != null && !abils.isEmpty()) {
                    spell.append('[');
                    spell.append(ReferenceUtilities.joinLstFormat(abils, "]["));
                    spell.append(']');
                }
                Integer count = kitSpell.getSpellCount(ksi, abils);
                if (count != 1) {
                    spell.append('=').append(count);
                }
                sb.append(spell);
            }
        }
    }
    if (sb.length() == 0) {
        return null;
    }
    return new String[] { sb.toString() };
}
Also used : Ability(pcgen.core.Ability) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) PCClass(pcgen.core.PCClass) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) ArrayList(java.util.ArrayList) List(java.util.List)

Example 32 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class SpellsToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, KitSpells kitSpell, String value) {
    StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
    ComplexParseResult pr = new ComplexParseResult();
    while (aTok.hasMoreTokens()) {
        String field = aTok.nextToken();
        if (field.startsWith("SPELLBOOK=")) {
            if (kitSpell.getSpellBook() != null) {
                return new ParseResult.Fail("Cannot reset SPELLBOOK in SPELLS: " + value, context);
            }
            String spellBook = field.substring(10);
            if (spellBook.isEmpty()) {
                return new ParseResult.Fail("Cannot set SPELLBOOK " + "to empty value in SPELLS: " + value, context);
            }
            kitSpell.setSpellBook(spellBook);
        } else if (field.startsWith(Constants.LST_CLASS_EQUAL)) {
            if (kitSpell.getCastingClass() != null) {
                return new ParseResult.Fail("Cannot reset CLASS" + " in SPELLS: " + value, context);
            }
            String className = field.substring(6);
            if (className.isEmpty()) {
                return new ParseResult.Fail("Cannot set CLASS " + "to empty value in SPELLS: " + value, context);
            } else if (className.equalsIgnoreCase("Default")) {
                pr.addWarningMessage("Use of Default for CLASS= in KIT " + "SPELLS line is unnecessary: Ignoring");
            } else {
                kitSpell.setCastingClass(context.getReferenceContext().getCDOMReference(PCClass.class, className));
            }
        } else {
            int count = 1;
            int equalLoc = field.indexOf(Constants.EQUALS);
            if (equalLoc != -1) {
                String countStr = field.substring(equalLoc + 1);
                try {
                    count = Integer.parseInt(countStr);
                } catch (NumberFormatException e) {
                    return new ParseResult.Fail("Expected an Integer COUNT," + " but found: " + countStr + " in " + value, context);
                }
                field = field.substring(0, equalLoc);
            }
            if (field.isEmpty()) {
                return new ParseResult.Fail("Expected an Spell in SPELLS" + " but found: " + value, context);
            }
            StringTokenizer subTok = new StringTokenizer(field, "[]");
            String filterString = subTok.nextToken();
            // must satisfy all elements in a comma delimited list
            CDOMReference<Spell> sp = null;
            sp = TokenUtilities.getTypeOrPrimitive(context, SPELL_CLASS, filterString);
            if (sp == null) {
                return new ParseResult.Fail("  encountered Invalid limit in " + getTokenName() + ": " + value, context);
            }
            KnownSpellIdentifier ksi = new KnownSpellIdentifier(sp, null);
            ArrayList<CDOMSingleRef<Ability>> featList = new ArrayList<>();
            while (subTok.hasMoreTokens()) {
                String featName = subTok.nextToken();
                CDOMSingleRef<Ability> feat = context.getReferenceContext().getCDOMReference(ABILITY_CLASS, AbilityCategory.FEAT, featName);
                featList.add(feat);
            }
            kitSpell.addSpell(ksi, featList, count);
        }
    }
    if (kitSpell.getSpellBook() == null) {
        kitSpell.setSpellBook(Globals.getDefaultSpellBook());
    }
    return pr;
}
Also used : Ability(pcgen.core.Ability) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) ParseResult(pcgen.rules.persistence.token.ParseResult) KnownSpellIdentifier(pcgen.cdom.content.KnownSpellIdentifier) ArrayList(java.util.ArrayList) ComplexParseResult(pcgen.rules.persistence.token.ComplexParseResult) PCClass(pcgen.core.PCClass) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) StringTokenizer(java.util.StringTokenizer) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 33 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class NonStatToStatFacet method dataAdded.

/**
	 * Adds a PCStat to this facet if the PCStat was set to a non stat by a CDOMObject
	 * which has been added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NonStatToStatFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    List<CDOMSingleRef<PCStat>> locks = cdo.getListFor(ListKey.NONSTAT_TO_STAT_STATS);
    if (locks != null) {
        CharID charID = dfce.getCharID();
        for (CDOMSingleRef<PCStat> ref : locks) {
            add(charID, ref.get(), cdo);
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) PCStat(pcgen.core.PCStat) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CharID(pcgen.cdom.enumeration.CharID)

Example 34 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class NonStatStatFacet method dataAdded.

/**
	 * Adds a PCStat to this facet if the PCStat was set to a non stat by a CDOMObject
	 * which has been added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NonStatStatFacet listens fires a
	 * DataFacetChangeEvent to indicate a CDOMObject was added to a Player
	 * Character.
	 * 
	 * @param dfce
	 *            The DataFacetChangeEvent containing the information about the
	 *            change
	 * 
	 * @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
	 */
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
    CDOMObject cdo = dfce.getCDOMObject();
    List<CDOMSingleRef<PCStat>> locks = cdo.getListFor(ListKey.NONSTAT_STATS);
    if (locks != null) {
        CharID charID = dfce.getCharID();
        for (CDOMSingleRef<PCStat> ref : locks) {
            add(charID, ref.get(), cdo);
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) PCStat(pcgen.core.PCStat) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CharID(pcgen.cdom.enumeration.CharID)

Example 35 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class WeaponProfToken method parseNonEmptyToken.

@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
    String weaponProfs;
    // Do not initialize, null is significant!
    Prerequisite prereq = null;
    boolean isPre = false;
    if (value.indexOf("[") == -1) {
        // Supported version of PRExxx using |.  Needs to be at the front of the
        // Parsing code because many objects expect the pre to have been determined
        // Ahead of time.  Until deprecated code is removed, it will have to stay
        // like this.
        weaponProfs = value;
        StringTokenizer tok = new StringTokenizer(weaponProfs, Constants.PIPE);
        while (tok.hasMoreTokens()) {
            String token = tok.nextToken();
            if (PreParserFactory.isPreReqString(token)) {
                if (isPre) {
                    String errorText = "Invalid " + getTokenName() + ": " + value + "  PRExxx must be at the END of the Token";
                    Logging.errorPrint(errorText);
                    return new ParseResult.Fail(errorText, context);
                }
                prereq = getPrerequisite(token);
                if (prereq == null) {
                    return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
                }
                int preStart = value.indexOf(token) - 1;
                weaponProfs = value.substring(0, preStart);
                isPre = true;
                ParseResult fail = checkForLoopPrereqs(prereq, context);
                if (fail != null) {
                    return fail;
                }
            }
        }
    } else {
        return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
    }
    ParseResult pr = checkForIllegalSeparator('|', weaponProfs);
    if (!pr.passed()) {
        return pr;
    }
    boolean foundAny = false;
    boolean foundOther = false;
    StringTokenizer tok = new StringTokenizer(weaponProfs, Constants.PIPE);
    WeaponProfProvider wpp = new WeaponProfProvider();
    while (tok.hasMoreTokens()) {
        String token = tok.nextToken();
        if (Constants.LST_PERCENT_LIST.equals(token)) {
            foundOther = true;
            ChooseSelectionActor<WeaponProf> cra;
            if (prereq == null) {
                cra = this;
            } else {
                ConditionalSelectionActor<WeaponProf> cca = new ConditionalSelectionActor<>(this);
                cca.addPrerequisite(prereq);
                cra = cca;
            }
            context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
        } else if ("DEITYWEAPONS".equals(token)) {
            foundOther = true;
            context.getObjectContext().put(obj, ObjectKey.HAS_DEITY_WEAPONPROF, new QualifiedObject<>(Boolean.TRUE, prereq));
        } else {
            if (Constants.LST_ALL.equalsIgnoreCase(token)) {
                foundAny = true;
                CDOMGroupRef<WeaponProf> allRef = context.getReferenceContext().getCDOMAllReference(WEAPONPROF_CLASS);
                wpp.addWeaponProfAll(allRef);
            } else {
                foundOther = true;
                if (token.startsWith(Constants.LST_TYPE_DOT) || token.startsWith(Constants.LST_TYPE_EQUAL)) {
                    CDOMGroupRef<WeaponProf> rr = TokenUtilities.getTypeReference(context, WEAPONPROF_CLASS, token.substring(5));
                    if (rr == null) {
                        return ParseResult.INTERNAL_ERROR;
                    }
                    wpp.addWeaponProfType(rr);
                } else {
                    CDOMSingleRef<WeaponProf> ref = context.getReferenceContext().getCDOMReference(WEAPONPROF_CLASS, token);
                    wpp.addWeaponProf(ref);
                }
            }
        }
    }
    if (foundAny && foundOther) {
        return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
    }
    if (!wpp.isEmpty()) {
        if (prereq != null) {
            wpp.addPrerequisite(prereq);
        }
        context.getObjectContext().addToList(obj, ListKey.WEAPONPROF, wpp);
    }
    return ParseResult.SUCCESS;
}
Also used : ParseResult(pcgen.rules.persistence.token.ParseResult) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) StringTokenizer(java.util.StringTokenizer) ConditionalSelectionActor(pcgen.cdom.content.ConditionalSelectionActor) QualifiedObject(pcgen.core.QualifiedObject) CDOMGroupRef(pcgen.cdom.reference.CDOMGroupRef) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)38 ArrayList (java.util.ArrayList)13 Ability (pcgen.core.Ability)10 Domain (pcgen.core.Domain)10 Prerequisite (pcgen.core.prereq.Prerequisite)10 StringTokenizer (java.util.StringTokenizer)9 QualifiedObject (pcgen.core.QualifiedObject)9 PCStat (pcgen.core.PCStat)6 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)4 CharID (pcgen.cdom.enumeration.CharID)4 AbilityCategory (pcgen.core.AbilityCategory)4 PCClass (pcgen.core.PCClass)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 HashMap (java.util.HashMap)3 Formula (pcgen.base.formula.Formula)3