Search in sources :

Example 1 with QualifiedObject

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

the class CoreUtils method getLoadID.

private static <T> String getLoadID(T obj) {
    if (obj instanceof Identified) {
        Identified l = (Identified) obj;
        String name = l.getDisplayName();
        String id = obj.getClass().getSimpleName() + ": " + name;
        if (!l.getKeyName().equals(name)) {
            id = id + " [" + l.getKeyName() + "]";
        }
        return id;
    } else if (obj instanceof QualifiedObject) {
        QualifiedObject<?> qo = (QualifiedObject<?>) obj;
        return getLoadID(qo.getRawObject());
    } else if (obj instanceof CDOMReference) {
        CDOMReference<?> ref = (CDOMReference<?>) obj;
        return ref.getReferenceClass().getSimpleName() + " Primitive: " + ref.getLSTformat(false);
    } else {
        return obj.getClass().getSimpleName() + ": " + obj.toString();
    }
}
Also used : Identified(pcgen.cdom.base.Identified) QualifiedObject(pcgen.core.QualifiedObject) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 2 with QualifiedObject

use of pcgen.core.QualifiedObject 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 3 with QualifiedObject

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

the class VisionFacet method getActiveVision.

/**
	 * Returns a non-null copy of the Collection of Vision objects which are
	 * active on the Player Character identified by the given CharID.
	 * 
	 * This method is value-semantic in that ownership of the returned
	 * Collection is transferred to the class calling this method. Modification
	 * of the returned Collection will not modify this VisionFacet and
	 * modification of this VisionFacet will not modify the returned Collection.
	 * Modifications to the returned Collection will also not modify any future
	 * or previous objects returned by this (or other) methods on VisionFacet.
	 * If you wish to modify the information stored in this VisionFacet, you
	 * must use the add*() and remove*() methods of VisionFacet.
	 * 
	 * @param id
	 *            The CharID identifying the Player Character for which the
	 *            active Vision objects is to be returned
	 * @return a non-null copy of the Collection of Vision objects which are
	 *         active on the Player Character identified by the given CharID
	 */
public Collection<Vision> getActiveVision(CharID id) {
    Map<QualifiedObject<Vision>, Set<Object>> componentMap = getCachedMap(id);
    if (componentMap == null) {
        return Collections.emptyList();
    }
    Map<VisionType, Integer> map = new HashMap<>();
    for (Map.Entry<QualifiedObject<Vision>, Set<Object>> me : componentMap.entrySet()) {
        QualifiedObject<Vision> qo = me.getKey();
        for (Object source : me.getValue()) {
            if (prerequisiteFacet.qualifies(id, qo, source)) {
                String sourceString = (source instanceof CDOMObject) ? ((CDOMObject) source).getQualifiedKey() : "";
                Vision v = qo.getRawObject();
                Formula distance = v.getDistance();
                int a = formulaResolvingFacet.resolve(id, distance, sourceString).intValue();
                VisionType visType = v.getType();
                Integer current = map.get(visType);
                if (current == null || current < a) {
                    map.put(visType, a);
                }
            }
        }
    }
    /*
		 * parse through the global list of vision tags and see if this PC has
		 * any BONUS:VISION tags which will create a new visionMap entry, and
		 * add any BONUS to existing entries in the map
		 */
    for (VisionType vType : VisionType.getAllVisionTypes()) {
        int aVal = (int) bonusCheckingFacet.getBonus(id, "VISION", vType.toString());
        if (aVal > 0) {
            Integer current = map.get(vType);
            map.put(vType, aVal + (current == null ? 0 : current));
        }
    }
    TreeSet<Vision> returnSet = new TreeSet<>();
    for (Map.Entry<VisionType, Integer> me : map.entrySet()) {
        returnSet.add(new Vision(me.getKey(), FormulaFactory.getFormulaFor(me.getValue())));
    }
    return returnSet;
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashMap(java.util.HashMap) VisionType(pcgen.util.enumeration.VisionType) Formula(pcgen.base.formula.Formula) QualifiedObject(pcgen.core.QualifiedObject) Vision(pcgen.core.Vision) CDOMObject(pcgen.cdom.base.CDOMObject) TreeSet(java.util.TreeSet) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with QualifiedObject

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

the class AutoEquipmentFacet method dataAdded.

/**
	 * Adds Equipment granted to a Player Character by AUTO:EQUIP.
	 * 
	 * Triggered when one of the Facets to which AutoEquipmentFacet 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();
    List<QualifiedObject<CDOMReference<Equipment>>> list = cdo.getSafeListFor(ListKey.EQUIPMENT);
    if (list != null) {
        addAll(dfce.getCharID(), list, cdo);
    }
}
Also used : Equipment(pcgen.core.Equipment) QualifiedObject(pcgen.core.QualifiedObject) CDOMObject(pcgen.cdom.base.CDOMObject)

Example 5 with QualifiedObject

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

the class DomainToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, PCClass pcc, String value) {
    StringTokenizer pipeTok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;
    String tok = pipeTok.nextToken();
    if (looksLikeAPrerequisite(tok)) {
        return new ParseResult.Fail("Cannot have only PRExxx subtoken in " + getTokenName() + ": " + value, context);
    }
    List<QualifiedObject<CDOMSingleRef<Domain>>> toAdd = new ArrayList<>();
    boolean foundClear = false;
    while (true) {
        if (Constants.LST_DOT_CLEAR.equals(tok)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item", context);
            }
            context.getObjectContext().removeList(pcc, ListKey.DOMAIN);
            foundClear = true;
        } else {
            CDOMSingleRef<Domain> domain = context.getReferenceContext().getCDOMReference(DOMAIN_CLASS, tok);
            QualifiedObject<CDOMSingleRef<Domain>> qo = new QualifiedObject<>(domain);
            toAdd.add(qo);
            context.getObjectContext().addToList(pcc, ListKey.DOMAIN, qo);
        }
        first = false;
        if (!pipeTok.hasMoreTokens()) {
            // No prereqs, so we're done
            return ParseResult.SUCCESS;
        }
        tok = pipeTok.nextToken();
        if (looksLikeAPrerequisite(tok)) {
            break;
        }
    }
    if (foundClear) {
        return new ParseResult.Fail("Cannot use PREREQs when using .CLEAR in " + getTokenName(), context);
    }
    while (true) {
        Prerequisite prereq = getPrerequisite(tok);
        if (prereq == null) {
            return new ParseResult.Fail("   (Did you put feats after the " + "PRExxx tags in " + getTokenName() + ":?)", context);
        }
        for (PrereqObject pro : toAdd) {
            pro.addPrerequisite(prereq);
        }
        if (!pipeTok.hasMoreTokens()) {
            break;
        }
        tok = pipeTok.nextToken();
    }
    return ParseResult.SUCCESS;
}
Also used : ArrayList(java.util.ArrayList) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) PrereqObject(pcgen.cdom.base.PrereqObject) StringTokenizer(java.util.StringTokenizer) QualifiedObject(pcgen.core.QualifiedObject) Domain(pcgen.core.Domain) Prerequisite(pcgen.core.prereq.Prerequisite)

Aggregations

QualifiedObject (pcgen.core.QualifiedObject)17 Prerequisite (pcgen.core.prereq.Prerequisite)10 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)9 StringTokenizer (java.util.StringTokenizer)6 Domain (pcgen.core.Domain)6 CDOMObject (pcgen.cdom.base.CDOMObject)5 ArrayList (java.util.ArrayList)3 CDOMReference (pcgen.cdom.base.CDOMReference)3 Vision (pcgen.core.Vision)3 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)3 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)3 StringWriter (java.io.StringWriter)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 Test (org.junit.Test)2 Formula (pcgen.base.formula.Formula)2 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)2 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)2