Search in sources :

Example 6 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext 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 7 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext 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 8 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class SourceFileLoader method finishLoad.

private void finishLoad(final List<Campaign> aSelectedCampaignsList, LoadContext context) {
    createLangBonusObject(context);
    AbstractReferenceContext refContext = context.getReferenceContext();
    refContext.buildDeferredObjects();
    refContext.buildDerivedObjects();
    referenceAllCategories(context);
    context.resolveDeferredTokens();
    LoadValidator validator = new LoadValidator(aSelectedCampaignsList);
    refContext.validate(validator);
    refContext.resolveReferences(validator);
    context.resolvePostValidationTokens();
    context.resolvePostDeferredTokens();
    ReferenceContextUtilities.validateAssociations(refContext, validator);
    for (Equipment eq : refContext.getConstructedCDOMObjects(Equipment.class)) {
        eq.setToCustomSize(null);
        EqModAttachment.finishEquipment(eq);
    }
}
Also used : Equipment(pcgen.core.Equipment) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LoadValidator(pcgen.rules.context.LoadValidator)

Example 9 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class CodeControlLoader method parseLine.

@Override
public void parseLine(LoadContext context, String inputLine, URI sourceURI) throws PersistenceLayerException {
    int sepLoc = inputLine.indexOf('\t');
    if (sepLoc != -1) {
        Logging.errorPrint("Unsure what to do with line with multiple tokens: " + inputLine + " in file: " + sourceURI);
        return;
    }
    try {
        AbstractReferenceContext refContext = context.getReferenceContext();
        CodeControl controller = refContext.constructNowIfNecessary(CodeControl.class, "Controller");
        LstUtils.processToken(context, controller, sourceURI, inputLine);
    } catch (PersistenceLayerException ple) {
        Logging.errorPrint("Exception in Load: ", ple);
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) CodeControl(pcgen.cdom.inst.CodeControl) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext)

Example 10 with AbstractReferenceContext

use of pcgen.rules.context.AbstractReferenceContext in project pcgen by PCGen.

the class AbstractCharacterTestCase method setUp.

/**
	 * Sets up the absolute minimum amount of data to create a PlayerCharacter
	 * Object.
	 * @throws Exception
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    TestHelper.loadPlugins();
    Globals.setUseGUI(false);
    Globals.emptyLists();
    final GameMode gamemode = SettingsHandler.getGame();
    LoadContext context = Globals.getContext();
    str = BuildUtilities.createStat("Strength", "STR");
    str.put(VariableKey.getConstant("LOADSCORE"), FormulaFactory.getFormulaFor("STRSCORE"));
    str.put(VariableKey.getConstant("OFFHANDLIGHTBONUS"), FormulaFactory.getFormulaFor(2));
    str.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    str.put(VariableKey.getConstant("MAXLEVELSTAT=" + str.getKeyName()), FormulaFactory.getFormulaFor(str.getKeyName() + "SCORE-10"));
    dex = BuildUtilities.createStat("Dexterity", "DEX");
    dex.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    dex.put(VariableKey.getConstant("MAXLEVELSTAT=" + dex.getKeyName()), FormulaFactory.getFormulaFor(dex.getKeyName() + "SCORE-10"));
    PCStat con = BuildUtilities.createStat("Constitution", "CON");
    con.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    con.put(VariableKey.getConstant("MAXLEVELSTAT=" + con.getKeyName()), FormulaFactory.getFormulaFor(con.getKeyName() + "SCORE-10"));
    intel = BuildUtilities.createStat("Intelligence", "INT");
    intel.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    intel.put(VariableKey.getConstant("MAXLEVELSTAT=" + intel.getKeyName()), FormulaFactory.getFormulaFor(intel.getKeyName() + "SCORE-10"));
    wis = BuildUtilities.createStat("Wisdom", "WIS");
    wis.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    wis.put(VariableKey.getConstant("MAXLEVELSTAT=" + wis.getKeyName()), FormulaFactory.getFormulaFor(wis.getKeyName() + "SCORE-10"));
    cha = BuildUtilities.createStat("Charisma", "CHA");
    cha.put(FormulaKey.STAT_MOD, FormulaFactory.getFormulaFor("floor(SCORE/2)-5"));
    cha.put(VariableKey.getConstant("MAXLEVELSTAT=" + cha.getKeyName()), FormulaFactory.getFormulaFor(cha.getKeyName() + "SCORE-10"));
    gamemode.setBonusFeatLevels("3|3");
    SettingsHandler.setGame("3.5");
    AbstractReferenceContext ref = context.getReferenceContext();
    lg = BuildUtilities.createAlignment("Lawful Good", "LG");
    ref.importObject(lg);
    ln = BuildUtilities.createAlignment("Lawful Neutral", "LN");
    ref.importObject(ln);
    le = BuildUtilities.createAlignment("Lawful Evil", "LE");
    ref.importObject(le);
    ng = BuildUtilities.createAlignment("Neutral Good", "NG");
    ref.importObject(ng);
    tn = BuildUtilities.createAlignment("True Neutral", "TN");
    ref.importObject(tn);
    ne = BuildUtilities.createAlignment("Neutral Evil", "NE");
    ref.importObject(ne);
    cg = BuildUtilities.createAlignment("Chaotic Good", "CG");
    ref.importObject(cg);
    cn = BuildUtilities.createAlignment("Chaotic Neutral", "CN");
    ref.importObject(cn);
    ce = BuildUtilities.createAlignment("Chaotic Evil", "CE");
    ref.importObject(ce);
    ref.importObject(BuildUtilities.createAlignment("None", "NONE"));
    ref.importObject(BuildUtilities.createAlignment("Deity's", "Deity"));
    GameModeFileLoader.addDefaultWieldCategories(context);
    ref.importObject(str);
    ref.importObject(dex);
    ref.importObject(con);
    ref.importObject(intel);
    ref.importObject(wis);
    ref.importObject(cha);
    ref.constructCDOMObject(Language.class, "All Language For Test");
    BuildUtilities.createFact(context, "ClassType", PCClass.class);
    FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
    fd.setSelectable(true);
    SourceFileLoader.processFactDefinitions(context);
    fine = BuildUtilities.createSize("Fine", 0);
    diminutive = BuildUtilities.createSize("Diminutive", 1);
    tiny = BuildUtilities.createSize("Tiny", 2);
    small = BuildUtilities.createSize("Small", 3);
    medium = BuildUtilities.createSize("Medium", 4);
    medium.put(ObjectKey.IS_DEFAULT_SIZE, true);
    large = BuildUtilities.createSize("Large", 5);
    huge = BuildUtilities.createSize("Huge", 6);
    gargantuan = BuildUtilities.createSize("Gargantuan", 7);
    colossal = BuildUtilities.createSize("Colossal", 8);
    SourceFileLoader.createLangBonusObject(context);
    GameModeFileLoader.addDefaultUnitSet(SettingsHandler.getGame());
    SettingsHandler.getGame().selectDefaultUnitSet();
    ref.importObject(AbilityCategory.FEAT);
    additionalSetUp();
    context.getReferenceContext().buildDerivedObjects();
    context.resolveDeferredTokens();
    assertTrue(ref.resolveReferences(null));
    context.loadCampaignFacets();
    character = new PlayerCharacter();
}
Also used : GameMode(pcgen.core.GameMode) PlayerCharacter(pcgen.core.PlayerCharacter) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) LoadContext(pcgen.rules.context.LoadContext) PCStat(pcgen.core.PCStat)

Aggregations

AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)29 PCStat (pcgen.core.PCStat)7 GameMode (pcgen.core.GameMode)6 ArrayList (java.util.ArrayList)3 SizeAdjustment (pcgen.core.SizeAdjustment)3 LoadContext (pcgen.rules.context.LoadContext)3 CDOMObject (pcgen.cdom.base.CDOMObject)2 DirectAbilityFacet (pcgen.cdom.facet.DirectAbilityFacet)2 ActiveEqModFacet (pcgen.cdom.facet.model.ActiveEqModFacet)2 AlignmentFacet (pcgen.cdom.facet.model.AlignmentFacet)2 BioSetFacet (pcgen.cdom.facet.model.BioSetFacet)2 CheckFacet (pcgen.cdom.facet.model.CheckFacet)2 ClassFacet (pcgen.cdom.facet.model.ClassFacet)2 ClassLevelFacet (pcgen.cdom.facet.model.ClassLevelFacet)2 CompanionModFacet (pcgen.cdom.facet.model.CompanionModFacet)2 DeityFacet (pcgen.cdom.facet.model.DeityFacet)2 DomainFacet (pcgen.cdom.facet.model.DomainFacet)2 ExpandedCampaignFacet (pcgen.cdom.facet.model.ExpandedCampaignFacet)2 LanguageFacet (pcgen.cdom.facet.model.LanguageFacet)2 SizeFacet (pcgen.cdom.facet.model.SizeFacet)2