Search in sources :

Example 1 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class BonusManager method getBonusContext.

public String getBonusContext(BonusObj bo, boolean shortForm) {
    final StringBuilder sb = new StringBuilder(50);
    boolean bEmpty = true;
    sb.append('[');
    if (bo.hasPrerequisites()) {
        for (Prerequisite p : bo.getPrerequisiteList()) {
            if (!bEmpty) {
                sb.append(',');
            }
            sb.append(p.getDescription(shortForm));
            bEmpty = false;
        }
    }
    String type = bo.getTypeString();
    if (!type.isEmpty()) {
        if (!shortForm) {
            if (!bEmpty) {
                sb.append('|');
            }
            sb.append("TYPE=");
            bEmpty = false;
        }
        if (!shortForm || sb.charAt(sb.length() - 1) == '[') {
            sb.append(type);
            bEmpty = false;
        }
    }
    //
    if (!bEmpty) {
        sb.append('|');
    }
    sb.append(getSourceString(bo));
    sb.append(']');
    return sb.toString();
}
Also used : Prerequisite(pcgen.core.prereq.Prerequisite)

Example 2 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class Equipment method resizeItem.

/**
	 * Change the size of an item
	 * 
	 * @param pc
	 *            The PC carrying the item
	 * @param newSize
	 *            The new size for the item
	 */
public void resizeItem(final PlayerCharacter pc, SizeAdjustment newSize) {
    setBase();
    final int iOldSize = sizeInt();
    int iNewSize = newSize.get(IntegerKey.SIZEORDER);
    if (iNewSize != iOldSize) {
        put(ObjectKey.SIZE, CDOMDirectSingleRef.getRef(newSize));
        CDOMSingleRef<Equipment> baseItem = get(ObjectKey.BASE_ITEM);
        Equipment eq;
        if (baseItem == null) {
            eq = this;
        } else {
            eq = baseItem.get();
        }
        put(ObjectKey.CURRENT_COST, eq.getCostAdjustedForSize(pc, newSize));
        put(ObjectKey.WEIGHT, eq.getWeightAdjustedForSize(pc, newSize));
        adjustACForSize(pc, eq, newSize);
        String dam = eq.getDamageAdjustedForSize(newSize, true);
        if (dam != null && !dam.isEmpty()) {
            getEquipmentHead(1).put(StringKey.DAMAGE, dam);
        }
        String adam = eq.getDamageAdjustedForSize(newSize, false);
        if (adam != null && !adam.isEmpty()) {
            getEquipmentHead(2).put(StringKey.DAMAGE, adam);
        }
        //
        // Adjust the capacity of the container (if it is one)
        //
        BigDecimal weightCap = get(ObjectKey.CONTAINER_WEIGHT_CAPACITY);
        if (weightCap != null) {
            double mult = 1.0;
            if (newSize != null && pc != null) {
                mult = pc.getSizeBonusTo(newSize, "ITEMCAPACITY", eq.typeList(), 1.0);
            }
            BigDecimal multbd = new BigDecimal(mult);
            if (!Capacity.UNLIMITED.equals(weightCap)) {
                // CONSIDER ICK, ICK, direct access bad
                put(ObjectKey.CONTAINER_WEIGHT_CAPACITY, weightCap.multiply(multbd));
            }
            List<Capacity> capacity = removeListFor(ListKey.CAPACITY);
            if (capacity != null) {
                for (Capacity cap : capacity) {
                    BigDecimal content = cap.getCapacity();
                    if (!Capacity.UNLIMITED.equals(content)) {
                        content = content.multiply(multbd);
                    }
                    // CONSIDER ICK, ICK, direct access bad
                    addToListFor(ListKey.CAPACITY, new Capacity(cap.getType(), content));
                }
            }
            updateContainerCapacityString();
        }
    }
    //
    if (hasPrerequisites()) {
        AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
        int maxIndex = ref.getConstructedObjectCount(SizeAdjustment.class);
        for (Prerequisite aBonus : getPrerequisiteList()) {
            if ("SIZE".equalsIgnoreCase(aBonus.getKind())) {
                SizeAdjustment sa = ref.silentlyGetConstructedCDOMObject(SizeAdjustment.class, aBonus.getOperand());
                final int iOldPre = sa.get(IntegerKey.SIZEORDER);
                iNewSize += (iOldPre - iOldSize);
                if ((iNewSize >= 0) && (iNewSize <= maxIndex)) {
                    // Note: This actually impacts the Prereq in this
                    // Equipment, since it is returned
                    // by reference from the get above ... thus no need to
                    // perform a set
                    SizeAdjustment size = ref.getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(iNewSize);
                    aBonus.setOperand(size.getKeyName());
                }
            }
        }
    }
}
Also used : Capacity(pcgen.cdom.helper.Capacity) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) BigDecimal(java.math.BigDecimal) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with Prerequisite

use of pcgen.core.prereq.Prerequisite 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 4 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class CampaignSourceEntry method validatePrereqs.

/**
	 * Check that all prerequisites specified in the PCC file are 
	 * supported. Any unsupported prereqs will be reported as LST 
	 * errors. This is a recursive function allowing it to 
	 * check nested prereqs.
	 * 
	 * @param prereqList The prerequisites to be checked.
	 */
private static void validatePrereqs(List<Prerequisite> prereqList, URI sourceUri) {
    if (prereqList == null || prereqList.isEmpty()) {
        return;
    }
    for (Prerequisite prereq : prereqList) {
        if (prereq.isCharacterRequired()) {
            final PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
            ArrayList<Prerequisite> displayList = new ArrayList<>();
            displayList.add(prereq);
            String lstString = prereqWriter.getPrerequisiteString(displayList, Constants.TAB);
            Logging.log(Logging.LST_ERROR, "Prereq '" + prereq.getKind() + "' is not supported in PCC files. Prereq was '" + lstString + "' in " + sourceUri + ". Prereq will be ignored.");
        } else {
            validatePrereqs(prereq.getPrerequisites(), sourceUri);
        }
    }
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) ArrayList(java.util.ArrayList) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 5 with Prerequisite

use of pcgen.core.prereq.Prerequisite in project pcgen by PCGen.

the class CampaignSourceEntry method getNewCSE.

public static CampaignSourceEntry getNewCSE(Campaign campaign2, URI sourceUri, String value) {
    if (value == null || value.isEmpty()) {
        Logging.errorPrint("Cannot build CampaignSourceEntry for empty value in " + sourceUri);
        return null;
    }
    // Check if include/exclude items were present
    int pipePos = value.indexOf("|");
    CampaignSourceEntry cse;
    if (pipePos == -1) {
        if (value.startsWith("(")) {
            Logging.errorPrint("Invalid Campaign File, cannot start with (:" + value);
            return null;
        }
        URIEntry uri = URIEntry.getURIEntry(campaign2.getDisplayName(), sourceUri, value);
        cse = new CampaignSourceEntry(campaign2, uri);
    } else {
        URIEntry uri = URIEntry.getURIEntry(campaign2.getDisplayName(), sourceUri, value.substring(0, pipePos));
        cse = new CampaignSourceEntry(campaign2, uri);
        // Get the include/exclude item string
        String inExString = value.substring(pipePos + 1);
        List<String> tagList = parseSuffix(inExString, sourceUri, value);
        for (String tagString : tagList) {
            // Check for surrounding parens
            if (tagString.startsWith("((")) {
                Logging.errorPrint("Found Suffix in Campaign Source with multiple parenthesis: " + "Single set of parens required around INCLUDE/EXCLUDE");
                Logging.errorPrint("Found: '" + tagString + "' in " + value);
                return null;
            }
            // Update the include or exclude items list, as appropriate
            if (tagString.startsWith("(INCLUDE:")) {
                // assume matching parens
                tagString = inExString.substring(1, tagString.length() - 1);
                List<String> splitIncExc = cse.splitInExString(tagString);
                if (splitIncExc == null) {
                    //Error
                    return null;
                }
                cse.includeItems = splitIncExc;
            } else if (tagString.startsWith("(EXCLUDE:")) {
                // assume matching parens
                tagString = inExString.substring(1, tagString.length() - 1);
                List<String> splitIncExc = cse.splitInExString(tagString);
                if (splitIncExc == null) {
                    //Error
                    return null;
                }
                cse.excludeItems = splitIncExc;
            } else if (PreParserFactory.isPreReqString(tagString)) {
                Prerequisite prereq;
                try {
                    prereq = PreParserFactory.getInstance().parse(tagString);
                } catch (PersistenceLayerException e) {
                    Logging.errorPrint("Error Initializing PreParserFactory.", e);
                    return null;
                }
                if (prereq == null) {
                    Logging.errorPrint("Found invalid prerequisite in Campaign Source: '" + tagString + "' in " + value);
                    return null;
                }
                cse.prerequisites.add(prereq);
            } else {
                Logging.errorPrint("Invalid Suffix (must have " + "'(INCLUDE' '(EXCLUDE' or a PRExxx immediately " + "following the pipe (no spaces).  Found: '" + inExString + "' on Campaign Source: '" + value + "' in " + sourceUri);
                return null;
            }
        }
        validatePrereqs(cse.getPrerequisites(), sourceUri);
    }
    return cse;
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) ArrayList(java.util.ArrayList) List(java.util.List) HashMapToList(pcgen.base.util.HashMapToList) MapToList(pcgen.base.util.MapToList) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

Prerequisite (pcgen.core.prereq.Prerequisite)267 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)62 Test (org.junit.Test)61 PrerequisiteOperator (pcgen.core.prereq.PrerequisiteOperator)50 StringTokenizer (java.util.StringTokenizer)36 ArrayList (java.util.ArrayList)35 StringWriter (java.io.StringWriter)19 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)19 CDOMReference (pcgen.cdom.base.CDOMReference)18 ParseResult (pcgen.rules.persistence.token.ParseResult)18 BonusObj (pcgen.core.bonus.BonusObj)13 TreeSet (java.util.TreeSet)12 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)12 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)10 Domain (pcgen.core.Domain)10 QualifiedObject (pcgen.core.QualifiedObject)10 PrerequisiteWriterInterface (pcgen.persistence.lst.output.prereq.PrerequisiteWriterInterface)10 PrerequisiteWriter (pcgen.persistence.lst.output.prereq.PrerequisiteWriter)9 Ungranted (pcgen.cdom.base.Ungranted)8 PrerequisiteException (pcgen.core.prereq.PrerequisiteException)8