Search in sources :

Example 1 with AbstractReferenceContext

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

the class Equipment method getDamage.

private String getDamage(PlayerCharacter apc, boolean bPrimary) {
    int headnum = bPrimary ? 1 : 2;
    EquipmentHead head = getEquipmentHeadReference(headnum);
    if (head == null) {
        return "";
    }
    String dam = head.get(StringKey.DAMAGE);
    if (!isWeapon() || (!bPrimary && !isDouble())) {
        return dam == null ? "" : dam;
    }
    if (bPrimary && dam == null) {
        // No need to grab reference, always exists due to if above
        EquipmentHead altHead = getEquipmentHead(2);
        dam = altHead.get(StringKey.DAMAGE);
    }
    String override = get(StringKey.DAMAGE_OVERRIDE);
    if (bPrimary && override != null) {
        // this overides the base damage
        dam = override;
    }
    if (dam == null) {
        dam = getWeaponInfo("DAMAGE", bPrimary);
    }
    final int iSize = sizeInt();
    int iMod = iSize + (int) bonusTo(apc, "EQMWEAPON", "DAMAGESIZE", bPrimary);
    iMod += (int) bonusTo(apc, "WEAPON", "DAMAGESIZE", bPrimary);
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    if (iMod < 0) {
        iMod = 0;
    } else {
        int maxIndex = ref.getConstructedObjectCount(SizeAdjustment.class) - 1;
        if (iMod > maxIndex) {
            iMod = maxIndex;
        }
    }
    SizeAdjustment sa = ref.getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(iMod);
    return adjustDamage(dam, sa);
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext)

Example 2 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 3 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 4 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 5 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)

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