Search in sources :

Example 6 with Type

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

the class ClassDataHandler method startElement.

/**
	 * @throws SAXException
	 * @throws IllegalArgumentException if the file being processed is not the
	 * same GameMode as requested.
	 *  
	 * @see org.xml.sax.helpers.DefaultHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
	 */
@Override
public void startElement(final String uri, final String localName, final String aName, final Attributes anAttrs) throws SAXException {
    if (//$NON-NLS-1$
    theState == ParserState.INIT && "class_data".equals(aName)) {
        if (anAttrs != null) {
            //$NON-NLS-1$
            final String gm = anAttrs.getValue("game_mode");
            if (!SystemCollections.getGameModeNamed(gm).equals(theGameMode)) {
                //$NON-NLS-1$
                throw new IllegalArgumentException("Incorrect game mode");
            }
            theValidFlag = true;
        }
        return;
    }
    if (!theValidFlag) {
        //$NON-NLS-1$
        throw new SAXException("NPCGen.Options.InvalidFileFormat");
    }
    if (theState == ParserState.INIT) {
        if (//$NON-NLS-1$
        "class".equals(aName)) {
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String classKey = anAttrs.getValue("key");
                final PCClass pcClass = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, classKey);
                if (pcClass == null) {
                    //$NON-NLS-1$
                    Logging.errorPrintLocalised("Exceptions.PCGenParser.ClassNotFound", classKey);
                } else {
                    theCurrentData = new ClassData(pcClass);
                    theState = ParserState.CLASSDATA;
                }
            }
        }
    } else if (theState == ParserState.CLASSDATA) {
        if (//$NON-NLS-1$
        "stats".equals(aName)) {
            theState = ParserState.STATDATA;
        } else if (//$NON-NLS-1$
        "skills".equals(aName)) {
            theState = ParserState.SKILLDATA;
        } else if (//$NON-NLS-1$
        "abilities".equals(aName)) {
            theState = ParserState.ABILITYDATA;
            theCurrentCategory = AbilityCategory.FEAT;
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String catName = anAttrs.getValue("category");
                if (catName != null) {
                    theCurrentCategory = SettingsHandler.getGame().getAbilityCategory(catName);
                }
            }
        } else if (//$NON-NLS-1$
        "spells".equals(aName)) {
            theState = ParserState.SPELLDATA;
            theCurrentSpellType = SpellType.KNOWN;
            if (anAttrs != null) {
                //$NON-NLS-1$
                final String bookName = anAttrs.getValue("type");
                if (bookName != null) {
                    if (//$NON-NLS-1$
                    "Prepared Spells".equals(bookName)) {
                        theCurrentSpellType = SpellType.PREPARED;
                    }
                }
            }
        } else if (//$NON-NLS-1$
        "subclasses".equals(aName)) {
            theState = ParserState.SUBCLASSDATA;
        }
    } else if (theState == ParserState.STATDATA) {
        if (//$NON-NLS-1$
        "stat".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String statAbbr = anAttrs.getValue("value");
                if (statAbbr != null) {
                    PCStat stat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(PCStat.class, statAbbr);
                    theCurrentData.addStat(stat, weight);
                }
            }
        }
    } else if (theState == ParserState.SKILLDATA) {
        if (//$NON-NLS-1$
        "skill".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String key = anAttrs.getValue("value");
                if (key != null) {
                    if (//$NON-NLS-1$
                    "*".equals(key)) {
                        remainingWeight = weight;
                    } else if (//$NON-NLS-1$
                    key.startsWith("TYPE")) {
                        final List<Skill> skillsOfType = Globals.getPObjectsOfType(Globals.getContext().getReferenceContext().getConstructedCDOMObjects(Skill.class), key.substring(5));
                        if (skillsOfType.isEmpty()) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("NPCGenerator: No skills of type found (" + key + ")");
                        }
                    } else {
                        final Skill skill = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, key);
                        if (skill == null) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("NPCGenerator: Skill not found (" + key + ")");
                        }
                    }
                    if (//$NON-NLS-1$
                    weight > 0 && !key.equals("*")) {
                        theCurrentData.addSkill(key, weight);
                    } else {
                        removeList.add(key);
                    }
                }
            }
        }
    } else if (theState == ParserState.ABILITYDATA) {
        if (//$NON-NLS-1$
        "ability".equals(aName)) {
            if (anAttrs != null) {
                final int weight = getWeight(anAttrs);
                //$NON-NLS-1$
                final String key = anAttrs.getValue("value");
                if (key != null) {
                    if (//$NON-NLS-1$
                    "*".equals(key)) {
                        remainingWeight = weight;
                    } else if (//$NON-NLS-1$
                    key.startsWith("TYPE")) {
                        Type type = Type.getConstant(key.substring(5));
                        for (final Ability ability : Globals.getContext().getReferenceContext().getManufacturer(Ability.class, theCurrentCategory).getAllObjects()) {
                            if (!ability.containsInList(ListKey.TYPE, type)) {
                                continue;
                            }
                            if (ability.getSafe(ObjectKey.VISIBILITY) == Visibility.DEFAULT) {
                                if (weight > 0) {
                                    theCurrentData.addAbility(theCurrentCategory, ability, weight);
                                } else {
                                    // We have to remove any feats of this
                                    // type.
                                    // TODO - This is a little goofy.  We
                                    // already have the feat but we will 
                                    // store the key and reretrieve it.
                                    removeList.add(ability.getKeyName());
                                }
                            }
                        }
                    } else {
                        final Ability ability = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, theCurrentCategory, key);
                        if (ability == null) {
                            //$NON-NLS-1$ //$NON-NLS-2$
                            Logging.debugPrint("Ability (" + key + ") not found");
                        } else if (weight > 0) {
                            theCurrentData.addAbility(theCurrentCategory, ability, weight);
                        } else {
                            // We have to remove any feats of this
                            // type.
                            // TODO - This is a little goofy.  We
                            // already have the feat but we will 
                            // store the key and reretrieve it.
                            removeList.add(ability.getKeyName());
                        }
                    }
                }
            }
        }
    } else if (theState == ParserState.SPELLDATA) {
        if (//$NON-NLS-1$
        "level".equals(aName) && anAttrs != null) {
            //$NON-NLS-1$
            final String lvlStr = anAttrs.getValue("id");
            if (lvlStr != null) {
                theCurrentLevel = Integer.parseInt(lvlStr);
                theState = ParserState.SPELLLEVELDATA;
            }
        }
    } else if (theState == ParserState.SPELLLEVELDATA) {
        if (//$NON-NLS-1$
        "spell".equals(aName) && anAttrs != null) {
            final int weight = getWeight(anAttrs);
            //$NON-NLS-1$
            final String key = anAttrs.getValue("name");
            if (key != null) {
                if (//$NON-NLS-1$
                "*".equals(key)) {
                    remainingWeight = weight;
                } else if (//$NON-NLS-1$
                key.startsWith("SCHOOL")) {
                // Not sure how to do this yet
                } else {
                    final Spell spell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, key);
                    if (spell != null) {
                        if (theCurrentSpellType == SpellType.KNOWN) {
                            theCurrentData.addKnownSpell(theCurrentLevel, spell, weight);
                        } else if (theCurrentSpellType == SpellType.PREPARED) {
                            theCurrentData.addPreparedSpell(theCurrentLevel, spell, weight);
                        }
                    } else {
                        Logging.errorPrint("Spell \"" + key + "\" not found.");
                    }
                }
            }
        }
    } else if (theState == ParserState.SUBCLASSDATA) {
        if (//$NON-NLS-1$
        "subclass".equals(aName) && anAttrs != null) {
            final int weight = getWeight(anAttrs);
            //$NON-NLS-1$
            final String key = anAttrs.getValue("value");
            theCurrentData.addSubClass(key, weight);
        }
    }
}
Also used : Ability(pcgen.core.Ability) Skill(pcgen.core.Skill) Type(pcgen.cdom.enumeration.Type) PCClass(pcgen.core.PCClass) PCStat(pcgen.core.PCStat) Spell(pcgen.core.spell.Spell) SAXException(org.xml.sax.SAXException)

Example 7 with Type

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

the class DataSet method initLists.

private void initLists() {
    List<Race> raceList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(Race.class));
    raceList.sort(new RaceComparator());
    for (Race race : raceList) {
        if (race.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            races.addElement(race);
        }
    }
    List<PCClass> classList = new ArrayList<>(context.getReferenceContext().getConstructedCDOMObjects(PCClass.class));
    classList.sort(new PCClassComparator());
    for (PCClass pcClass : classList) {
        if (pcClass.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            classes.addElement(pcClass);
        }
    }
    for (Skill skill : context.getReferenceContext().getConstructedCDOMObjects(Skill.class)) {
        if (skill.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            skills.addElement(skill);
        }
    }
    for (Deity deity : context.getReferenceContext().getConstructedCDOMObjects(Deity.class)) {
        deities.addElement(deity);
    }
    for (PCTemplate template : context.getReferenceContext().getConstructedCDOMObjects(PCTemplate.class)) {
        if (template.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            templates.addElement(template);
        }
    }
    for (Kit kit : context.getReferenceContext().getConstructedCDOMObjects(Kit.class)) {
        kits.addElement(kit);
    }
    for (PCAlignment alignment : context.getReferenceContext().getOrderSortedCDOMObjects(PCAlignment.class)) {
        alignments.addElement(alignment);
    }
    for (PCStat stat : context.getReferenceContext().getOrderSortedCDOMObjects(PCStat.class)) {
        stats.addElement(stat);
    }
    //			new AbilityCategoryComparator());
    for (AbilityCategory category : gameMode.getAllAbilityCategories()) {
        if (category.isVisibleTo(View.VISIBLE_DISPLAY)) {
            //				categories.addElement(category);
            List<Ability> abList = new ArrayList<>(Globals.getContext().getReferenceContext().getManufacturer(Ability.class, category).getAllObjects());
            Globals.sortPObjectListByName(abList);
            DefaultListFacade<AbilityFacade> abilityList = new DefaultListFacade<>(abList);
            for (Iterator<AbilityFacade> iterator = abilityList.iterator(); iterator.hasNext(); ) {
                AbilityFacade facade = iterator.next();
                if (facade instanceof Ability) {
                    Ability ability = (Ability) facade;
                    if (!(ability.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY))) {
                        iterator.remove();
                    }
                }
            }
            abilityMap.put(category, abilityList);
        }
    }
    Map<String, BodyStructure> structMap = new HashMap<>(SystemCollections.getUnmodifiableBodyStructureList().size() + 3);
    for (String name : SystemCollections.getUnmodifiableBodyStructureList()) {
        // TODO i18n the display name and correct the DataSetTest
        String displayName = name.substring(0, 1).toUpperCase() + name.substring(1).toLowerCase();
        final BodyStructure bodyStructure = new BodyStructure(displayName);
        bodyStructures.addElement(bodyStructure);
        structMap.put(name, bodyStructure);
    }
    Set<Type> typesWithDesignatedSlots = buildSlottedTypeList();
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_EQUIPPED, true, typesWithDesignatedSlots));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_CARRIED, true));
    bodyStructures.addElement(new BodyStructure(Constants.EQUIP_LOCATION_NOTCARRIED, true));
    for (EquipSlot es : SystemCollections.getUnmodifiableEquipSlotList()) {
        if (structMap.containsKey(es.getBodyStructureName())) {
            structMap.get(es.getBodyStructureName()).addEquipSlot(es);
        }
    }
    for (Equipment eq : context.getReferenceContext().getConstructedCDOMObjects(Equipment.class)) {
        if (eq.getSafe(ObjectKey.VISIBILITY).isVisibleTo(View.VISIBLE_DISPLAY)) {
            equipment.addElement(eq);
        }
    }
    for (String xpTableName : gameMode.getXPTableNames()) {
        xpTableNames.addElement(xpTableName);
    }
    for (String characterType : gameMode.getCharacterTypeList()) {
        characterTypes.addElement(characterType);
    }
    for (SizeAdjustment size : context.getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER)) {
        sizes.addElement(size);
    }
    createGearBuySellSchemes();
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) EquipSlot(pcgen.core.character.EquipSlot) Type(pcgen.cdom.enumeration.Type) AbilityFacade(pcgen.facade.core.AbilityFacade) DefaultListFacade(pcgen.facade.util.DefaultListFacade)

Example 8 with Type

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

the class Ability method getTypes.

/* (non-Javadoc)
	 * @see pcgen.core.facade.AbilityFacade#getTypes()
	 */
@Override
public List<String> getTypes() {
    List<Type> trueTypeList = getTrueTypeList(true);
    List<String> typeNames = new ArrayList<>();
    for (Type type : trueTypeList) {
        typeNames.add(type.toString());
    }
    return typeNames;
}
Also used : Type(pcgen.cdom.enumeration.Type) MessageType(pcgen.core.utils.MessageType) ArrayList(java.util.ArrayList)

Example 9 with Type

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

the class PreSkillMultTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) {
    CharacterDisplay display = character.getDisplay();
    int runningTotal = 0;
    final int requiredRanks = Integer.parseInt(prereq.getOperand());
    String requiredSkillKey = prereq.getKey().toUpperCase();
    final boolean isType = //$NON-NLS-1$ //$NON-NLS-2$
    (requiredSkillKey.startsWith("TYPE.") || requiredSkillKey.startsWith("TYPE="));
    if (isType) {
        requiredSkillKey = requiredSkillKey.substring(5);
    }
    final String skillKey = requiredSkillKey;
    final int percentageSignPosition = skillKey.lastIndexOf('%');
    boolean foundMatch = false;
    for (Skill aSkill : display.getSkillSet()) {
        final String aSkillKey = aSkill.getKeyName().toUpperCase();
        if (isType) {
            if (percentageSignPosition >= 0) {
                for (Type type : aSkill.getTrueTypeList(false)) {
                    if (type.toString().toUpperCase().startsWith(skillKey.substring(0, percentageSignPosition))) {
                        foundMatch = true;
                        break;
                    }
                }
            } else if (aSkill.isType(skillKey)) {
                foundMatch = true;
            }
            if (foundMatch) {
                final int result = prereq.getOperator().compare(SkillRankControl.getTotalRank(character, aSkill).intValue(), requiredRanks);
                if (result == 0) {
                    foundMatch = false;
                } else {
                    runningTotal = result;
                }
            }
        } else if (aSkillKey.equals(skillKey) || ((percentageSignPosition >= 0) && aSkillKey.startsWith(skillKey.substring(0, percentageSignPosition)))) {
            final int result = prereq.getOperator().compare(SkillRankControl.getTotalRank(character, aSkill).intValue(), requiredRanks);
            if (result > 0) {
                foundMatch = true;
                runningTotal = result;
            }
        }
        if (foundMatch) {
            break;
        }
    }
    return countedTotal(prereq, runningTotal);
}
Also used : Skill(pcgen.core.Skill) Type(pcgen.cdom.enumeration.Type) CharacterDisplay(pcgen.core.display.CharacterDisplay)

Example 10 with Type

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

the class NaturalattacksLst method unparse.

@Override
public String[] unparse(LoadContext context, CDOMObject obj) {
    Changes<Equipment> changes = context.getObjectContext().getListChanges(obj, ListKey.NATURAL_WEAPON);
    Collection<Equipment> eqadded = changes.getAdded();
    if (eqadded == null || eqadded.isEmpty()) {
        return null;
    }
    StringBuilder sb = new StringBuilder();
    boolean first = true;
    for (Equipment lstw : eqadded) {
        if (!first) {
            sb.append(Constants.PIPE);
        }
        Equipment eq = Equipment.class.cast(lstw);
        String name = eq.getDisplayName();
        // TODO objcontext.getString(eq, StringKey.NAME);
        if (name == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a name");
            return null;
        }
        sb.append(name).append(Constants.COMMA);
        List<Type> type = eq.getListFor(ListKey.TYPE);
        if (type == null || type.isEmpty()) {
            context.addWriteMessage(getTokenName() + " expected Equipment to have a type");
            return null;
        }
        sb.append(StringUtil.join(type, Constants.DOT));
        sb.append(Constants.COMMA);
        Boolean attProgress = eq.get(ObjectKey.ATTACKS_PROGRESS);
        if (attProgress == null) {
            context.addWriteMessage(getTokenName() + " expected Equipment to know ATTACKS_PROGRESS state");
            return null;
        } else if (!attProgress.booleanValue()) {
            sb.append(Constants.CHAR_ASTERISK);
        }
        List<BonusObj> bonuses = eq.getListFor(ListKey.BONUS);
        if (bonuses == null || bonuses.isEmpty()) {
            sb.append('1');
        } else {
            if (bonuses.size() != 1) {
                context.addWriteMessage(getTokenName() + " expected only one BONUS on Equipment: " + bonuses);
                return null;
            }
            // TODO Validate BONUS type?
            BonusObj extraAttacks = bonuses.iterator().next();
            sb.append(Integer.parseInt(extraAttacks.getValue()) + 1);
        }
        sb.append(Constants.COMMA);
        EquipmentHead head = eq.getEquipmentHeadReference(1);
        if (head == null) {
            context.addWriteMessage(getTokenName() + " expected an EquipmentHead on Equipment");
            return null;
        }
        String damage = head.get(StringKey.DAMAGE);
        if (damage == null) {
            context.addWriteMessage(getTokenName() + " expected a Damage on EquipmentHead");
            return null;
        }
        sb.append(damage);
        Integer hands = eq.get(IntegerKey.SLOTS);
        if (hands != null && hands != 0) {
            sb.append(',').append(hands);
        }
        List<SpecialProperty> spropList = eq.getSafeListFor(ListKey.SPECIAL_PROPERTIES);
        for (SpecialProperty sprop : spropList) {
            sb.append(",SPROP=").append(sprop.toString());
        }
        first = false;
    }
    return new String[] { sb.toString() };
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) EquipmentHead(pcgen.cdom.inst.EquipmentHead) Type(pcgen.cdom.enumeration.Type) Equipment(pcgen.core.Equipment) SpecialProperty(pcgen.core.SpecialProperty)

Aggregations

Type (pcgen.cdom.enumeration.Type)27 ArrayList (java.util.ArrayList)6 MessageType (pcgen.core.utils.MessageType)6 EquipmentHead (pcgen.cdom.inst.EquipmentHead)4 Skill (pcgen.core.Skill)4 StringTokenizer (java.util.StringTokenizer)3 PCStat (pcgen.core.PCStat)3 BonusObj (pcgen.core.bonus.BonusObj)3 AttackType (pcgen.util.enumeration.AttackType)3 HashMap (java.util.HashMap)2 ClassSource (pcgen.cdom.helper.ClassSource)2 SpellSchool (pcgen.cdom.identifier.SpellSchool)2 ChangeArmorType (pcgen.cdom.processor.ChangeArmorType)2 ClassType (pcgen.core.ClassType)2 Equipment (pcgen.core.Equipment)2 WeaponProf (pcgen.core.WeaponProf)2 CharacterDisplay (pcgen.core.display.CharacterDisplay)2 ParseResult (pcgen.rules.persistence.token.ParseResult)2 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1