Search in sources :

Example 6 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class HitPointFacet method getLevelHitDie.

/**
	 * Returns the HitDie for the given PCClass and level in the Player
	 * Character identified by the given CharID.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            HitDie of the given PCClass and level will be returned
	 * @param pcClass
	 *            The PCClass for which the HitDie will be returned
	 * @param classLevel
	 *            The level for which the HitDie will be returned
	 * @return The HitDie for the given PCClass and level in the Player
	 *         Character identified by the given CharID
	 */
public HitDie getLevelHitDie(CharID id, PCClass pcClass, int classLevel) {
    // Class Base Hit Die
    HitDie currDie = pcClass.getSafe(ObjectKey.LEVEL_HITDIE);
    Processor<HitDie> dieLock = raceFacet.get(id).get(ObjectKey.HITDIE);
    if (dieLock != null) {
        currDie = dieLock.applyProcessor(currDie, pcClass);
    }
    // Templates
    for (PCTemplate template : templateFacet.getSet(id)) {
        if (template != null) {
            Processor<HitDie> lock = template.get(ObjectKey.HITDIE);
            if (lock != null) {
                currDie = lock.applyProcessor(currDie, pcClass);
            }
        }
    }
    // Levels
    PCClassLevel cl = classFacet.getClassLevel(id, pcClass, classLevel);
    if (cl != null) {
        if (cl.get(ObjectKey.DONTADD_HITDIE) != null) {
            //null;
            currDie = HitDie.ZERO;
        } else {
            Processor<HitDie> lock = cl.get(ObjectKey.HITDIE);
            if (lock != null) {
                currDie = lock.applyProcessor(currDie, pcClass);
            }
        }
    }
    return currDie;
}
Also used : HitDie(pcgen.cdom.content.HitDie) PCTemplate(pcgen.core.PCTemplate) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 7 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class PCGVer2Parser method parseTempBonusLine.

/**
	 * ###############################################################
	 * Temporary Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String cTag = null;
    String tName = null;
    boolean active = true;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
            cTag = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
            tName = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
            active = element.getText().endsWith(IOConstants.VALUE_Y);
        }
    }
    if ((cTag == null) || (tName == null)) {
        warnings.add("Illegal TempBonus line ignored: " + line);
        return;
    }
    //$NON-NLS-1$
    final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
    if (aTok.countTokens() < 2) {
        return;
    }
    final String cType = aTok.nextToken();
    final String cKey = aTok.nextToken();
    Equipment aEq = null;
    if (!tName.equals(IOConstants.TAG_PC)) {
        // bonus is applied to an equipment item
        // so create a new one and add to PC
        final Equipment eq = thePC.getEquipmentNamed(tName);
        if (eq == null) {
            return;
        }
        aEq = eq.clone();
        //aEq.setWeight("0");
        aEq.resetTempBonusList();
    }
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        final String bonus;
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            bonus = EntityEncoder.decode(element.getText());
        } else {
            continue;
        }
        if ((bonus == null) || (bonus.length() <= 0)) {
            continue;
        }
        BonusObj newB = null;
        Object creator = null;
        LoadContext context = Globals.getContext();
        // type of object to set as the creator
        if (cType.equals(IOConstants.TAG_FEAT)) {
            for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
                Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
                if (a != null) {
                    newB = Bonus.newBonus(context, bonus);
                    creator = a;
                    break;
                }
            }
        } else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
            Equipment aEquip = thePC.getEquipmentNamed(cKey);
            if (aEquip == null) {
                aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
            }
            if (aEquip != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aEquip;
            }
        } else if (cType.equals(IOConstants.TAG_CLASS)) {
            final PCClass aClass = thePC.getClassKeyed(cKey);
            if (aClass == null) {
                continue;
            }
            int idx = bonus.indexOf('|');
            newB = Bonus.newBonus(context, bonus.substring(idx + 1));
            creator = aClass;
        } else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
            PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
            if (aTemplate != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aTemplate;
            }
        } else if (cType.equals(IOConstants.TAG_SKILL)) {
            Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
            if (aSkill != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSkill;
            }
        } else if (cType.equals(IOConstants.TAG_SPELL)) {
            final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
            if (aSpell != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSpell;
            }
        } else if (cType.equals(IOConstants.TAG_NAME)) {
            newB = Bonus.newBonus(context, bonus);
        //newB.setCreatorObject(thePC);
        }
        if (newB == null) {
            return;
        }
        TempBonusInfo tempBonusInfo;
        // Check to see if the target was the PC or an Item
        if (tName.equals(IOConstants.TAG_PC)) {
            thePC.setApplied(newB, true);
            tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
        } else {
            thePC.setApplied(newB, true);
            aEq.addTempBonus(newB);
            tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
        }
        if (!active) {
            String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
            thePC.setTempBonusFilter(bonusName);
        }
    }
    if (aEq != null) {
        aEq.setAppliedName(cKey);
        thePC.addTempBonusItemList(aEq);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) Equipment(pcgen.core.Equipment) LoadContext(pcgen.rules.context.LoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Example 8 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class PCGVer2Parser method parseTemplateLine.

/*
	 * ###############################################################
	 * Character Templates methods
	 * ###############################################################
	 */
private void parseTemplateLine(final String line) throws PCGParseException {
    if (line.charAt(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1) == '[') {
        final PCGTokenizer tokens;
        try {
            tokens = new PCGTokenizer(line);
        } catch (PCGParseException pcgpex) {
            final String message = "Illegal Template line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
            warnings.add(message);
            return;
        }
        PCTemplate aPCTemplate = null;
        Iterator<PCGElement> it = tokens.getElements().iterator();
        if (it.hasNext()) {
            final PCGElement element = it.next();
            String assoc = null;
            //Must deal with APPLIEDTO first (before item is added to the PC)
            for (final PCGElement child : element.getChildren()) {
                String childTag = child.getName();
                if (IOConstants.TAG_NAME.equals(childTag)) {
                    aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, EntityEncoder.decode(child.getText()));
                    if (aPCTemplate == null) {
                        break;
                    }
                } else if (IOConstants.TAG_APPLIEDTO.equals(childTag)) {
                    assoc = child.getText();
                }
            }
            for (final PCGElement child : element.getChildren()) {
                final String childTag = child.getName();
                if (IOConstants.TAG_NAME.equals(childTag)) {
                    if (aPCTemplate == null) {
                        break;
                    }
                    addKeyedTemplate(aPCTemplate, assoc);
                } else if (IOConstants.TAG_CHOSENFEAT.equals(childTag)) {
                    String mapKey = null;
                    String mapValue = null;
                    for (PCGElement subChild : child.getChildren()) {
                        final String subChildTag = subChild.getName();
                        if (IOConstants.TAG_MAPKEY.equals(subChildTag)) {
                            mapKey = subChild.getText();
                        } else if (IOConstants.TAG_MAPVALUE.equals(subChildTag)) {
                            mapValue = subChild.getText();
                        }
                    }
                    if ((mapKey != null) && (mapValue != null)) {
                        String feat = EntityEncoder.decode(mapValue);
                        PCTemplate subt = Compatibility.getTemplateFor(aPCTemplate, EntityEncoder.decode(mapKey), feat);
                        if (subt != null) {
                            CNAbilitySelection as = CNAbilitySelection.getAbilitySelectionFromPersistentFormat(feat);
                            thePC.addTemplateFeat(subt, as);
                        }
                    }
                } else if (IOConstants.TAG_CHOSENTEMPLATE.equals(childTag)) {
                    for (PCGElement subChild : child.getChildren()) {
                        final String subChildTag = subChild.getName();
                        if (IOConstants.TAG_NAME.equals(subChildTag)) {
                            final String ownedTemplateKey = EntityEncoder.decode(subChild.getText());
                            final PCTemplate ownedTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, ownedTemplateKey);
                            if (ownedTemplate != null) {
                                thePC.setTemplatesAdded(aPCTemplate, ownedTemplate);
                            }
                        }
                    }
                } else //Add handled below, AppliedTo handled in the first loop
                if (!IOConstants.TAG_ADDTOKEN.equals(childTag) && !IOConstants.TAG_APPLIEDTO.equals(childTag)) {
                    final String msg = LanguageBundle.getFormattedString(//$NON-NLS-1$
                    "Warnings.PCGenParser.UnknownTemplateInfo", childTag + ":" + child.getText());
                    warnings.add(msg);
                }
            }
        }
        //Must process ADD after Template is added to the PC
        for (PCGElement e : new PCGTokenizer(line).getElements()) {
            String tag = e.getName();
            if (tag.equals(IOConstants.TAG_ADDTOKEN)) {
                parseAddTokenInfo(e, aPCTemplate);
            }
        }
    } else {
        String key = EntityEncoder.decode(line.substring(IOConstants.TAG_TEMPLATESAPPLIED.length() + 1));
        PCTemplate aPCTemplate = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, key);
        addKeyedTemplate(aPCTemplate, null);
    }
}
Also used : CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) PCTemplate(pcgen.core.PCTemplate)

Example 9 with PCTemplate

use of pcgen.core.PCTemplate 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 10 with PCTemplate

use of pcgen.core.PCTemplate in project pcgen by PCGen.

the class PCGVer2Creator method appendWeaponProficiencyLines.

/*
	 * ###############################################################
	 * Character Weapon proficiencies methods
	 * ###############################################################
	 */
private void appendWeaponProficiencyLines(StringBuilder buffer) {
    final int size = charDisplay.getWeaponProfSet().size();
    if (size > 0) {
        /*
			 * since aPC.getWeaponProfList() returns a TreeSet,
			 * we have to put them into an array first.
			 * we do not use TreeSet's toArray()-method since it
			 * makes no guarantees on element order.
			 *
			 * author: Thomas Behr 08-09-02
			 */
        final String[] weaponProficiencies = new String[size];
        int j = 0;
        for (WeaponProf wp : charDisplay.getSortedWeaponProfs()) {
            weaponProficiencies[j++] = wp.getKeyName();
        }
        // as per Mynex's request do not write more than 10 weapons per line
        final int step = 10;
        final int times = (size / step) + (((size % step) > 0) ? 1 : 0);
        for (int k = 0; k < times; ++k) {
            buffer.append(IOConstants.TAG_WEAPONPROF).append(':');
            buffer.append('[');
            String del = Constants.EMPTY_STRING;
            int stop = Math.min(size, (k * step) + 10);
            for (int i = k * step; i < stop; ++i) {
                buffer.append(del);
                buffer.append(IOConstants.TAG_WEAPON).append(':');
                buffer.append(EntityEncoder.encode(weaponProficiencies[i]));
                //$NON-NLS-1$
                del = "|";
            }
            buffer.append(']');
            buffer.append(IOConstants.LINE_SEP);
        }
    }
    //
    // Save any selected racial bonus weapons
    //
    appendWeaponProficiencyLines(buffer, charDisplay.getRace());
    //
    for (PCTemplate pct : charDisplay.getTemplateSet()) {
        appendWeaponProficiencyLines(buffer, pct);
    }
    //
    for (final PCClass pcClass : charDisplay.getClassSet()) {
        appendWeaponProficiencyLines(buffer, pcClass);
    }
}
Also used : WeaponProf(pcgen.core.WeaponProf) PCTemplate(pcgen.core.PCTemplate) PCClass(pcgen.core.PCClass)

Aggregations

PCTemplate (pcgen.core.PCTemplate)215 Test (org.junit.Test)105 Race (pcgen.core.Race)66 PlayerCharacter (pcgen.core.PlayerCharacter)38 CDOMObject (pcgen.cdom.base.CDOMObject)31 ArrayList (java.util.ArrayList)19 CharID (pcgen.cdom.enumeration.CharID)18 ParseResult (pcgen.rules.persistence.token.ParseResult)14 SimpleAssociatedObject (pcgen.cdom.base.SimpleAssociatedObject)13 Vision (pcgen.core.Vision)12 LoadContext (pcgen.rules.context.LoadContext)12 PCClass (pcgen.core.PCClass)11 StringTokenizer (java.util.StringTokenizer)10 VariableKey (pcgen.cdom.enumeration.VariableKey)8 DataFacetChangeEvent (pcgen.cdom.facet.event.DataFacetChangeEvent)8 Ability (pcgen.core.Ability)8 Formula (pcgen.base.formula.Formula)6 Equipment (pcgen.core.Equipment)6 PCStat (pcgen.core.PCStat)6 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)6