Search in sources :

Example 41 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class NaturalWeaponProfFacet method dataAdded.

/**
	 * Adds the implied (by NATURALATTACKS: token) weapon proficiencies to a
	 * Player Character when a CDOMObject which grants natural attacks is added
	 * to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NaturalWeaponProfFacet 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();
    // Natural Weapon Proficiencies
    List<CDOMSingleRef<WeaponProf>> iwp = cdo.getListFor(ListKey.IMPLIED_WEAPONPROF);
    if (iwp != null) {
        CharID id = dfce.getCharID();
        for (CDOMSingleRef<WeaponProf> ref : iwp) {
            add(id, ref.get(), cdo);
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CharID(pcgen.cdom.enumeration.CharID)

Example 42 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class EquipmentLoader method process.

@Override
public List<CDOMObject> process(StringBuilder sb, int line, String lineString, ConversionDecider decider) throws PersistenceLayerException, InterruptedException {
    String[] tokens = lineString.split(FIELD_SEPARATOR);
    if (tokens.length == 0) {
        return null;
    }
    String objectName = tokens[0];
    sb.append(objectName);
    List<CDOMObject> list = new ArrayList<>();
    for (int tok = 1; tok < tokens.length; tok++) {
        String token = tokens[tok];
        sb.append(FIELD_SEPARATOR);
        if (token.isEmpty()) {
            continue;
        }
        Equipment obj = context.getReferenceContext().constructCDOMObject(EQUIPMENT_CLASS, line + "Test" + tok + " " + token);
        obj.put(StringKey.CONVERT_NAME, tokens[0]);
        List<CDOMObject> injected = processToken(sb, objectName, obj, token, decider, line);
        if (injected != null) {
            list.addAll(injected);
        }
        EquipmentHead h1 = obj.getEquipmentHeadReference(1);
        if (h1 != null) {
            context.purge(h1);
        }
        EquipmentHead h2 = obj.getEquipmentHeadReference(1);
        if (h2 != null) {
            context.purge(h2);
        }
        context.purge(obj);
        TokenConverter.clearConstants();
    }
    return list;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList)

Example 43 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class LSTConverter method load.

private String load(URI uri, Loader loader) throws InterruptedException, PersistenceLayerException {
    StringBuilder dataBuffer;
    context.setSourceURI(uri);
    context.setExtractURI(uri);
    try {
        dataBuffer = LstFileLoader.readFromURI(uri);
    } catch (PersistenceLayerException ple) {
        String message = LanguageBundle.getFormattedString(//$NON-NLS-1$
        "Errors.LstFileLoader.LoadError", uri, ple.getMessage());
        Logging.errorPrint(message);
        return null;
    }
    StringBuilder resultBuffer = new StringBuilder(dataBuffer.length());
    final String aString = dataBuffer.toString();
    String[] fileLines = aString.split(LstFileLoader.LINE_SEPARATOR_REGEXP);
    for (int line = 0; line < fileLines.length; line++) {
        String lineString = fileLines[line];
        if ((lineString.isEmpty()) || (lineString.charAt(0) == LstFileLoader.LINE_COMMENT_CHAR) || lineString.startsWith("SOURCE")) {
            resultBuffer.append(lineString);
        } else {
            List<CDOMObject> newObj = loader.process(resultBuffer, line, lineString, decider);
            if (newObj != null) {
                for (CDOMObject cdo : newObj) {
                    injected.addToListFor(loader, uri, cdo);
                }
            }
        }
        resultBuffer.append("\n");
    }
    return resultBuffer.toString();
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 44 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class PCGVer2Parser method parseWeaponProficienciesLine.

/*
	 * ###############################################################
	 * Character Weapon proficiencies methods
	 * ###############################################################
	 */
private void parseWeaponProficienciesLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Weapon proficiencies line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    CDOMObject source = null;
    boolean hadSource = false;
    for (PCGElement element : tokens.getElements()) {
        if (IOConstants.TAG_SOURCE.equals(element.getName())) {
            hadSource = true;
            String type = Constants.EMPTY_STRING;
            String key = Constants.EMPTY_STRING;
            for (final PCGElement child : element.getChildren()) {
                final String tag = child.getName();
                if (IOConstants.TAG_TYPE.equals(tag)) {
                    type = child.getText().toUpperCase();
                } else if (IOConstants.TAG_NAME.equals(tag)) {
                    key = child.getText();
                }
            }
            if (Constants.EMPTY_STRING.equals(type) || Constants.EMPTY_STRING.equals(key)) {
                final String message = "Illegal Weapon proficiencies line ignored: " + line;
                warnings.add(message);
                return;
            }
            if (IOConstants.TAG_RACE.equals(type)) {
                source = thePC.getRace();
            } else if (TAG_PCTEMPLATE.equals(type)) {
                PCTemplate template = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
                if (thePC.hasTemplate(template)) {
                    source = template;
                } else {
                    warnings.add("PC does not have Template: " + key);
                }
            } else if (IOConstants.TAG_PCCLASS.equals(type)) {
                source = thePC.getClassKeyed(key);
            }
            if (source == null) {
                final String message = "Invalid source specification: " + line;
                warnings.add(message);
            }
            break;
        }
    }
    final PCGElement element = tokens.getElements().get(0);
    boolean processed = false;
    if (source != null) {
        List<PersistentTransitionChoice<?>> adds = source.getListFor(ListKey.ADD);
        if (adds != null) {
            for (PersistentTransitionChoice<?> ptc : adds) {
                if (ptc.getChoiceClass().equals(WeaponProf.class)) {
                    for (PCGElement child : element.getChildren()) {
                        WeaponProf wp = getWeaponProf(child.getText());
                        Set c = Collections.singleton(wp);
                        ptc.act(c, source, thePC);
                    }
                    processed = true;
                    break;
                }
            }
        }
    }
    if (hadSource && !processed) {
        final String message = "Unable to apply WeaponProfs: " + line;
        warnings.add(message);
    }
}
Also used : EquipSet(pcgen.core.character.EquipSet) Set(java.util.Set) SelectableSet(pcgen.cdom.base.SelectableSet) HashSet(java.util.HashSet) CDOMObject(pcgen.cdom.base.CDOMObject) PersistentTransitionChoice(pcgen.cdom.base.PersistentTransitionChoice) WeaponProf(pcgen.core.WeaponProf) PCTemplate(pcgen.core.PCTemplate)

Example 45 with CDOMObject

use of pcgen.cdom.base.CDOMObject in project pcgen by PCGen.

the class PCGVer2Creator method appendSpellLines.

/*
	 * ###############################################################
	 * Character Spells Information methods
	 * ###############################################################
	 */
/*
	 * #Character Spells Information
	 * CLASS:Wizard|CANCASTPERDAY:2,4(Totals the levels all up + includes attribute bonuses)
	 * SPELLNAME:Blah|SCHOOL:blah|SUBSCHOOL:blah|Etc
	 *
	 * completely changed due to new Spell API
	 */
private void appendSpellLines(StringBuilder buffer) {
    for (PCClass pcClass : charDisplay.getClassSet()) {
        Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pcClass);
        List<CharacterSpell> classSpells = new ArrayList<>(sp);
        // Add in the spells granted by objects
        thePC.addBonusKnownSpellsToList(pcClass, classSpells);
        Collections.sort(classSpells);
        for (CharacterSpell cSpell : classSpells) {
            for (SpellInfo spellInfo : cSpell.getInfoList()) {
                CDOMObject owner = cSpell.getOwner();
                List<? extends CDOMList<Spell>> lists = charDisplay.getSpellLists(owner);
                if (SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC) < 0) {
                    Logging.errorPrint("Ignoring unqualified spell " + cSpell.getSpell() + " in list for class " + pcClass + ".");
                    continue;
                }
                if (spellInfo.getBook().equals(Globals.getDefaultSpellBook()) && thePC.getSpellSupport(pcClass).isAutoKnownSpell(cSpell.getSpell(), SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC), false, thePC) && thePC.getAutoSpells()) {
                    continue;
                }
                buffer.append(IOConstants.TAG_SPELLNAME).append(':');
                buffer.append(EntityEncoder.encode(cSpell.getSpell().getKeyName()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_TIMES).append(':');
                buffer.append(spellInfo.getTimes());
                buffer.append('|');
                buffer.append(IOConstants.TAG_CLASS).append(':');
                buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_SPELL_BOOK).append(':');
                buffer.append(EntityEncoder.encode(spellInfo.getBook()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_SPELLLEVEL).append(':');
                buffer.append(spellInfo.getActualLevel());
                if (spellInfo.getNumPages() > 0) {
                    buffer.append('|');
                    buffer.append(IOConstants.TAG_SPELLNUMPAGES).append(':');
                    buffer.append(spellInfo.getNumPages());
                }
                final List<Ability> metaFeats = spellInfo.getFeatList();
                if ((metaFeats != null) && (!metaFeats.isEmpty())) {
                    buffer.append('|');
                    buffer.append(IOConstants.TAG_FEATLIST).append(':');
                    buffer.append('[');
                    String del = Constants.EMPTY_STRING;
                    for (Ability feat : metaFeats) {
                        buffer.append(del);
                        buffer.append(IOConstants.TAG_FEAT).append(':');
                        buffer.append(EntityEncoder.encode(feat.getKeyName()));
                        //$NON-NLS-1$
                        del = "|";
                    }
                    buffer.append(']');
                }
                buffer.append('|');
                appendSourceInTaggedFormat(buffer, StringPClassUtil.getStringFor(owner.getClass()) + "|" + owner.getKeyName());
                buffer.append(IOConstants.LINE_SEP);
            }
        }
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) SpecialAbility(pcgen.core.SpecialAbility) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Aggregations

CDOMObject (pcgen.cdom.base.CDOMObject)235 Test (org.junit.Test)68 CharID (pcgen.cdom.enumeration.CharID)53 PCTemplate (pcgen.core.PCTemplate)30 ArrayList (java.util.ArrayList)22 PCClass (pcgen.core.PCClass)18 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)17 Race (pcgen.core.Race)17 Equipment (pcgen.core.Equipment)15 PlayerCharacter (pcgen.core.PlayerCharacter)15 Map (java.util.Map)14 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)14 CDOMReference (pcgen.cdom.base.CDOMReference)14 BonusObj (pcgen.core.bonus.BonusObj)14 IdentityHashMap (java.util.IdentityHashMap)12 Set (java.util.Set)12 VariableKey (pcgen.cdom.enumeration.VariableKey)11 HashMap (java.util.HashMap)10 CNAbility (pcgen.cdom.content.CNAbility)10 Spell (pcgen.core.spell.Spell)9