Search in sources :

Example 6 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class GameModeFileLoader method addDefaultWieldCategories.

public static void addDefaultWieldCategories(LoadContext context) throws PersistenceLayerException {
    PreParserFactory prereqParser;
    try {
        prereqParser = PreParserFactory.getInstance();
    } catch (final PersistenceLayerException ple) {
        Logging.errorPrint("Error Initializing PreParserFactory");
        Logging.errorPrint("  " + ple.getMessage(), ple);
        throw new UnreachableError(ple);
    }
    AbstractReferenceContext refContext = context.getReferenceContext();
    Collection<WieldCategory> categories = refContext.getConstructedCDOMObjects(WieldCategory.class);
    WieldCategory light = null;
    WieldCategory twoHanded = null;
    WieldCategory oneHanded = null;
    WieldCategory tooLarge = null;
    WieldCategory tooSmall = null;
    for (final WieldCategory wc : categories) {
        String name = wc.getKeyName();
        if ("Light".equalsIgnoreCase(name)) {
            light = wc;
        }
        if ("TwoHanded".equalsIgnoreCase(name)) {
            twoHanded = wc;
        }
        if ("OneHanded".equalsIgnoreCase(name)) {
            oneHanded = wc;
        }
        if ("TooLarge".equalsIgnoreCase(name)) {
            tooLarge = wc;
        }
        if ("TooSmall".equalsIgnoreCase(name)) {
            tooSmall = wc;
        }
    }
    boolean buildLight = false;
    if (light == null) {
        light = new WieldCategory();
        light.setName("Light");
        refContext.importObject(light);
        buildLight = true;
    }
    boolean buildTwoHanded = false;
    if (twoHanded == null) {
        twoHanded = new WieldCategory();
        twoHanded.setName("TwoHanded");
        refContext.importObject(twoHanded);
        buildTwoHanded = true;
    }
    boolean buildOneHanded = false;
    if (oneHanded == null) {
        oneHanded = new WieldCategory();
        oneHanded.setName("OneHanded");
        refContext.importObject(oneHanded);
        buildOneHanded = true;
    }
    boolean buildTooLarge = false;
    if (tooLarge == null) {
        tooLarge = new WieldCategory();
        tooLarge.setName("TooLarge");
        refContext.importObject(tooLarge);
        buildTooLarge = true;
    }
    boolean buildTooSmall = false;
    if (tooSmall == null) {
        tooSmall = new WieldCategory();
        tooSmall.setName("TooSmall");
        refContext.importObject(tooSmall);
        buildTooSmall = true;
    }
    CDOMDirectSingleRef<WieldCategory> tooSmallRef = CDOMDirectSingleRef.getRef(tooSmall);
    CDOMDirectSingleRef<WieldCategory> lightRef = CDOMDirectSingleRef.getRef(light);
    CDOMDirectSingleRef<WieldCategory> oneHandedRef = CDOMDirectSingleRef.getRef(oneHanded);
    CDOMDirectSingleRef<WieldCategory> twoHandedRef = CDOMDirectSingleRef.getRef(twoHanded);
    CDOMDirectSingleRef<WieldCategory> tooLargeRef = CDOMDirectSingleRef.getRef(tooLarge);
    if (buildLight) {
        light.setHandsRequired(1);
        light.setFinessable(true);
        light.addDamageMult(1, 1.0f);
        light.addDamageMult(2, 1.0f);
        Prerequisite p = prereqParser.parse("PREVARLTEQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+2");
        qo = new QualifiedObject<>(twoHandedRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+3");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        light.setWieldCategoryStep(1, oneHandedRef);
        light.setWieldCategoryStep(2, twoHandedRef);
    }
    if (buildTwoHanded) {
        twoHanded.setFinessable(false);
        twoHanded.setHandsRequired(2);
        twoHanded.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-3");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        twoHanded.setWieldCategoryStep(-2, lightRef);
        twoHanded.setWieldCategoryStep(-1, oneHandedRef);
    }
    if (buildOneHanded) {
        oneHanded.setHandsRequired(1);
        oneHanded.setFinessable(false);
        oneHanded.addDamageMult(1, 1.0f);
        oneHanded.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(twoHandedRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+2");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        oneHanded.setWieldCategoryStep(-1, lightRef);
        oneHanded.setWieldCategoryStep(1, twoHandedRef);
    }
    if (buildTooLarge) {
        tooLarge.setFinessable(false);
        tooLarge.setHandsRequired(999);
        tooLarge.setWieldCategoryStep(-3, lightRef);
        tooLarge.setWieldCategoryStep(-2, oneHandedRef);
        tooLarge.setWieldCategoryStep(-1, twoHandedRef);
        tooLarge.setWieldCategoryStep(0, twoHandedRef);
    }
    if (buildTooSmall) {
        tooSmall.setFinessable(false);
        tooSmall.setHandsRequired(2);
        tooSmall.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-3");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        tooSmall.setWieldCategoryStep(-2, lightRef);
        tooSmall.setWieldCategoryStep(-1, oneHandedRef);
    }
}
Also used : PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) UnreachableError(pcgen.base.lang.UnreachableError) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) QualifiedObject(pcgen.core.QualifiedObject) WieldCategory(pcgen.core.character.WieldCategory) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 7 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class MigrationLoader method parseFirstToken.

/**
	 * Parse the leading token and value to produce a starting MigrationRule object.
	 * 
	 * @param firstToken The first token and value.
	 * @param lstLine The full line it came form, for error reporting purposes only.
	 * @param sourceURI The source path, for error reporting purposes only.
	 * @return A new MigrationRule, or null if the token could nto be parsed.
	 */
MigrationRule parseFirstToken(String firstToken, String lstLine, URI sourceURI) {
    final int idxColon = firstToken.indexOf(':');
    if (idxColon <= 0 || idxColon == firstToken.length() - 1) {
        // Missing colon or missing key or value
        Logging.errorPrint("Illegal migration rule '" + lstLine + "' in " + sourceURI.toString());
        return null;
    }
    String objTypeKey = "";
    try {
        objTypeKey = firstToken.substring(0, idxColon);
    } catch (StringIndexOutOfBoundsException e) {
        throw new UnreachableError(e);
    }
    MigrationRule.ObjectType objType;
    try {
        objType = ObjectType.valueOf(objTypeKey);
    } catch (IllegalArgumentException e) {
        Logging.errorPrint("Unknown object type for migration rule '" + lstLine + "' in " + sourceURI.toString());
        return null;
    }
    String key = "";
    try {
        key = firstToken.substring(idxColon + 1);
    } catch (StringIndexOutOfBoundsException e) {
        throw new UnreachableError(e);
    }
    MigrationRule rule;
    if (objType.isCategorized()) {
        if (key.endsWith("|")) {
            // Extra |
            Logging.errorPrint("Invalid category|key of '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        String[] keyParts = key.split("\\|");
        if (keyParts.length < 2) {
            // No | so missing a category
            Logging.errorPrint("Missing category in '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        if (keyParts.length > 2) {
            // Extra |
            Logging.errorPrint("Invalid category|key of '" + firstToken + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        if (StringUtils.isBlank(keyParts[0]) || keyParts[0].matches(invalidKeyPattern)) {
            Logging.errorPrint("Invalid category of '" + keyParts[0] + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        if (StringUtils.isBlank(keyParts[1]) || keyParts[1].matches(invalidKeyPattern)) {
            Logging.errorPrint("Invalid key of '" + keyParts[1] + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        rule = new MigrationRule(objType, keyParts[0], keyParts[1]);
    } else {
        String invalidKeyPat = objType == ObjectType.SOURCE ? invalidSourceKeyPattern : invalidKeyPattern;
        if (StringUtils.isBlank(key) || key.matches(invalidKeyPat)) {
            Logging.errorPrint("Invalid key of '" + key + "' of migration rule '" + lstLine + "' in " + sourceURI.toString());
            return null;
        }
        rule = new MigrationRule(objType, key);
    }
    return rule;
}
Also used : ObjectType(pcgen.core.system.MigrationRule.ObjectType) UnreachableError(pcgen.base.lang.UnreachableError) MigrationRule(pcgen.core.system.MigrationRule)

Example 8 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class GenericLoader method parseLine.

/**
	 * @see pcgen.persistence.lst.LstObjectFileLoader#parseLine(LoadContext, CDOMObject, String, SourceEntry)
	 */
@Override
public final T parseLine(LoadContext context, T object, String lstLine, SourceEntry source) throws PersistenceLayerException {
    T po;
    boolean isnew = false;
    if (object == null) {
        try {
            po = baseClass.newInstance();
            newConstructionActions(context, po);
        } catch (InstantiationException | IllegalAccessException e) {
            throw new UnreachableError(e);
        }
        isnew = true;
    } else {
        po = object;
    }
    final StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
    if (colToken.hasMoreTokens()) {
        po.setName(colToken.nextToken().intern());
        po.put(ObjectKey.SOURCE_CAMPAIGN, source.getCampaign());
        po.setSourceURI(source.getURI());
        if (isnew) {
            context.addStatefulInformation(po);
            context.getReferenceContext().importObject(po);
        }
    }
    while (colToken.hasMoreTokens()) {
        LstUtils.processToken(context, po, source, colToken.nextToken());
    }
    // One line each; finish the object and return null
    completeObject(context, source, po);
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) UnreachableError(pcgen.base.lang.UnreachableError)

Example 9 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class FacetBehavior method buildMap.

private static void buildMap() {
    map = new CaseInsensitiveMap<>();
    Field[] fields = FacetBehavior.class.getDeclaredFields();
    for (Field field : fields) {
        int mod = field.getModifiers();
        if (Modifier.isStatic(mod) && Modifier.isFinal(mod) && Modifier.isPublic(mod)) {
            try {
                Object obj = field.get(null);
                if (obj instanceof FacetBehavior) {
                    map.put(field.getName(), (FacetBehavior) obj);
                }
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new UnreachableError(e);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) UnreachableError(pcgen.base.lang.UnreachableError)

Example 10 with UnreachableError

use of pcgen.base.lang.UnreachableError in project pcgen by PCGen.

the class PluginManager method getLogName.

private String getLogName(Class<?> clazz, InteractivePlugin pl) {
    String logName = null;
    try {
        Field f = clazz.getField("LOG_NAME");
        logName = (String) f.get(pl);
    } catch (SecurityException e) {
        throw new UnreachableError("Access to Class " + clazz + " should not be prohibited", e);
    } catch (IllegalAccessException e) {
        throw new UnreachableError("Access to Method LOG_NAME in Class " + clazz + " should not be prohibited", e);
    } catch (NoSuchFieldException e) {
        Logging.errorPrint(clazz.getName() + " does not have LOG_NAME defined, " + "Plugin class implemented improperly");
    } catch (IllegalArgumentException e) {
        Logging.errorPrint(clazz.getName() + " does not have LOG_NAME defined to " + "take a Plugin as the argument, " + "Plugin class implemented improperly");
    }
    return logName;
}
Also used : Field(java.lang.reflect.Field) UnreachableError(pcgen.base.lang.UnreachableError)

Aggregations

UnreachableError (pcgen.base.lang.UnreachableError)39 URI (java.net.URI)23 URISyntaxException (java.net.URISyntaxException)23 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)19 LoadContext (pcgen.rules.context.LoadContext)14 Field (java.lang.reflect.Field)9 Ability (pcgen.core.Ability)9 Campaign (pcgen.core.Campaign)9 CDOMReference (pcgen.cdom.base.CDOMReference)7 AbilityList (pcgen.cdom.list.AbilityList)6 CNAbility (pcgen.cdom.content.CNAbility)5 PlayerCharacter (pcgen.core.PlayerCharacter)4 FeatLoader (pcgen.persistence.lst.FeatLoader)4 ArrayList (java.util.ArrayList)3 PCClass (pcgen.core.PCClass)3 PCTemplate (pcgen.core.PCTemplate)3 QualifiedObject (pcgen.core.QualifiedObject)3 AbilityLoader (pcgen.persistence.lst.AbilityLoader)3 GenericLoader (pcgen.persistence.lst.GenericLoader)3 PCClassLoader (pcgen.persistence.lst.PCClassLoader)3