Search in sources :

Example 1 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class Equipment method addEqModifier.

/**
	 * Adds a feature to the EqModifier attribute of the Equipment object. If a
	 * non-null selectedChoice is supplied, this method will not be interactive,
	 * and will not show a dialog if a choice is required. Instead, the provided
	 * value will be used.
	 * 
	 * @param eqMod
	 *            The feature to be added to the EqModifier attribute
	 * @param bPrimary
	 *            The feature to be added to the EqModifier attribute
	 * @param aPC
	 *            The PC that the modifier is being added for.
	 * @param selectedChoice
	 *            The choice to be used instead of asking the user, should a
	 *            choice be required.
	 * @param equipChoice
	 *            The details of the choice to be made. Used when there are
	 *            secondary options.
	 */
public void addEqModifier(final EquipmentModifier eqMod, final boolean bPrimary, final PlayerCharacter aPC, final String selectedChoice, final EquipmentChoice equipChoice) {
    boolean bImporting = false;
    if ((aPC != null) && aPC.isImporting()) {
        bImporting = true;
    }
    if (!bImporting && !canAddModifier(aPC, eqMod, bPrimary)) {
        return;
    }
    List<CDOMSingleRef<EquipmentModifier>> replaces = eqMod.getListFor(ListKey.REPLACED_KEYS);
    EquipmentHead head = getEquipmentHead(bPrimary ? 1 : 2);
    if (replaces != null) {
        //
        for (CDOMSingleRef<EquipmentModifier> ref : replaces) {
            EquipmentModifier mod = ref.get();
            String key = mod.getKeyName();
            for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
                if (key.equalsIgnoreCase(aMod.getKeyName())) {
                    head.removeFromListFor(ListKey.EQMOD, aMod);
                    head.removeVarModifiers(aPC.getCharID(), aMod);
                    if (bPrimary) {
                        usePrimaryCache = false;
                    } else {
                        useSecondaryCache = false;
                    }
                    setDirty(true);
                }
            }
        }
    }
    if (eqMod.isType("BaseMaterial")) {
        for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
            if (aMod.isType("BaseMaterial")) {
                head.removeFromListFor(ListKey.EQMOD, aMod);
                head.removeVarModifiers(aPC.getCharID(), aMod);
                if (bPrimary) {
                    usePrimaryCache = false;
                } else {
                    useSecondaryCache = false;
                }
                setDirty(true);
            }
        }
    } else if (eqMod.isType("MagicalEnhancement")) {
        for (EquipmentModifier aMod : head.getSafeListFor(ListKey.EQMOD)) {
            if (aMod.isType("MagicalEnhancement")) {
                head.removeFromListFor(ListKey.EQMOD, aMod);
                head.removeVarModifiers(aPC.getCharID(), aMod);
                if (bPrimary) {
                    usePrimaryCache = false;
                } else {
                    useSecondaryCache = false;
                }
            }
        }
    }
    //
    // Add the modifier if it's not already there
    //
    EquipmentModifier aMod = getEqModifierKeyed(eqMod.getKeyName(), bPrimary);
    if (aMod == null) {
        //
        if (!eqMod.getSafe(StringKey.CHOICE_STRING).isEmpty()) {
            aMod = eqMod.clone();
            if (aMod == null) {
                return;
            }
        } else {
            aMod = eqMod;
        }
        head.addToListFor(ListKey.EQMOD, aMod);
        head.addVarModifiers(aPC.getCharID(), aMod);
        if (bPrimary) {
            usePrimaryCache = false;
        } else {
            useSecondaryCache = false;
        }
    }
    //
    if (!bImporting) {
        boolean allRemoved = false;
        if (selectedChoice != null && !selectedChoice.isEmpty()) {
            if (!eqMod.getSafe(StringKey.CHOICE_STRING).startsWith("EQBUILDER.")) {
                EquipmentChoiceDriver.setChoice(this, aMod, selectedChoice, equipChoice);
                allRemoved = !hasAssociations(aMod);
            }
        } else if (!EquipmentChoiceDriver.getChoice(1, this, aMod, true, aPC)) {
            allRemoved = true;
        }
        if (allRemoved) {
            head.removeFromListFor(ListKey.EQMOD, aMod);
            head.removeVarModifiers(aPC.getCharID(), aMod);
            if (bPrimary) {
                usePrimaryCache = false;
            } else {
                useSecondaryCache = false;
            }
        }
    }
    setBase();
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 2 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef 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 CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class NaturalWeaponProfFacet method dataAdded.

/**
	 * Adds the implied (by NATURALATTACKS: token) weapon proficiencies to a
	 * Player Character when a CDOMObject which grants natural attacks is added
	 * to a Player Character.
	 * 
	 * Triggered when one of the Facets to which NaturalWeaponProfFacet 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();
    // Natural Weapon Proficiencies
    List<CDOMSingleRef<WeaponProf>> iwp = cdo.getListFor(ListKey.IMPLIED_WEAPONPROF);
    if (iwp != null) {
        CharID id = dfce.getCharID();
        for (CDOMSingleRef<WeaponProf> ref : iwp) {
            add(id, ref.get(), cdo);
        }
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) WeaponProf(pcgen.core.WeaponProf) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) CharID(pcgen.cdom.enumeration.CharID)

Example 4 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class PlayerCharacter method getEffectiveCompanionLevel.

/**
	 * This method returns the effective level of this character for purposes of
	 * applying companion mods to a companion of the specified type.
	 * <p>
	 * <b>Note</b>: This whole structure is kind of messed up since nothing
	 * enforces that a companion mod of a given type always looks at the same
	 * variable (either Class or Variable).  Note it seems that this used to
	 * be driven off types but now it's driven from a list of companion mods
	 * but the java doc has not been updated.
	 *
	 * @param compList
	 *            A list of companionMods to get level for
	 * @return The effective level for this companion type
	 */
public int getEffectiveCompanionLevel(final CompanionList compList) {
    for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, compList).getAllObjects()) {
        Map<String, Integer> varmap = cMod.getMapFor(MapKey.APPLIED_VARIABLE);
        for (final String varName : varmap.keySet()) {
            final int lvl = this.getVariableValue(varName, Constants.EMPTY_STRING).intValue();
            if (lvl > 0) {
                return lvl;
            }
        }
        Map<CDOMSingleRef<? extends PCClass>, Integer> ac = cMod.getMapFor(MapKey.APPLIED_CLASS);
        for (Map.Entry<CDOMSingleRef<? extends PCClass>, Integer> me : ac.entrySet()) {
            PCClass pcclass = me.getKey().get();
            String key = pcclass.getKeyName();
            int lvl = getLevel(getClassKeyed(key));
            if (lvl > 0) {
                return lvl;
            }
        }
    }
    return 0;
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Map(java.util.Map) HashMap(java.util.HashMap) CompanionMod(pcgen.core.character.CompanionMod)

Example 5 with CDOMSingleRef

use of pcgen.cdom.reference.CDOMSingleRef in project pcgen by PCGen.

the class PlayerCharacter method getOldFollowerLimit.

private int getOldFollowerLimit(CompanionList cList) {
    // they can take unlimited number of them.
    for (CompanionMod cMod : Globals.getContext().getReferenceContext().getManufacturer(CompanionMod.class, cList).getAllObjects()) {
        Map<String, Integer> varmap = cMod.getMapFor(MapKey.APPLIED_VARIABLE);
        for (String varName : varmap.keySet()) {
            if (this.getVariableValue(varName, Constants.EMPTY_STRING).intValue() > 0) {
                return -1;
            }
        }
        Map<CDOMSingleRef<? extends PCClass>, Integer> ac = cMod.getMapFor(MapKey.APPLIED_CLASS);
        for (Map.Entry<CDOMSingleRef<? extends PCClass>, Integer> me : ac.entrySet()) {
            PCClass pcclass = me.getKey().get();
            String key = pcclass.getKeyName();
            for (PCClass pcClass : getClassSet()) {
                if (pcClass.getKeyName().equals(key)) {
                    return me.getValue();
                }
            }
        }
    }
    return 0;
}
Also used : CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) Map(java.util.Map) HashMap(java.util.HashMap) CompanionMod(pcgen.core.character.CompanionMod)

Aggregations

CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)38 ArrayList (java.util.ArrayList)13 Ability (pcgen.core.Ability)10 Domain (pcgen.core.Domain)10 Prerequisite (pcgen.core.prereq.Prerequisite)10 StringTokenizer (java.util.StringTokenizer)9 QualifiedObject (pcgen.core.QualifiedObject)9 PCStat (pcgen.core.PCStat)6 List (java.util.List)4 Map (java.util.Map)4 TreeSet (java.util.TreeSet)4 CDOMObject (pcgen.cdom.base.CDOMObject)4 CDOMReference (pcgen.cdom.base.CDOMReference)4 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)4 CharID (pcgen.cdom.enumeration.CharID)4 AbilityCategory (pcgen.core.AbilityCategory)4 PCClass (pcgen.core.PCClass)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 HashMap (java.util.HashMap)3 Formula (pcgen.base.formula.Formula)3