Search in sources :

Example 41 with SizeAdjustment

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

the class PreSizeTester method getTargetSizeInt.

private int getTargetSizeInt(String size) {
    AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
    SizeAdjustment sa = ref.silentlyGetConstructedCDOMObject(SizeAdjustment.class, size);
    return sa.get(IntegerKey.SIZEORDER);
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 42 with SizeAdjustment

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

the class WieldCategory method adjustForSize.

/**
	 * Get the WieldCategory adjusted for the size difference between the weapon
	 * and the PC. This uses the 3.5 equipment sizes.
	 * 
	 * @param pc
	 *            Player character to get the weild category for.
	 * @param eq
	 *            Equipment to get the weild category for.
	 * @return The ajusted WieldCategory
	 */
public WieldCategory adjustForSize(final PlayerCharacter pc, final Equipment eq) {
    if (pc == null || eq == null || eq.get(ObjectKey.WIELD) == null) {
        return this;
    }
    // Check if we have a bonus that changes the weapons effective size
    // for wield purposes.
    SizeAdjustment oldEqSa = eq.getSizeAdjustment();
    if (pc.sizeInt() != eq.sizeInt()) {
        int aBump = 0;
        aBump += (int) pc.getTotalBonusTo("WIELDCATEGORY", eq.getWieldName());
        aBump += (int) pc.getTotalBonusTo("WIELDCATEGORY", "ALL");
        // loops for each equipment type
        int modWield = 0;
        for (String eqType : eq.typeList()) {
            final StringBuilder sB = new StringBuilder("WEAPONPROF=TYPE.");
            sB.append(eqType);
            // get the type bonus (ex TYPE.MARTIAL)
            final int i = (int) pc.getTotalBonusTo(sB.toString(), "WIELDCATEGORY");
            // get the highest bonus
            if (i < modWield) {
                modWield = i;
            }
        }
        aBump += modWield;
        if (aBump != 0) {
            final int newSizeInt = eq.sizeInt() + aBump;
            AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
            SizeAdjustment sadj = ref.getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(newSizeInt);
            eq.put(ObjectKey.SIZE, CDOMDirectSingleRef.getRef(sadj));
        }
    }
    WieldCategory pcWCat = getSwitch(pc, eq);
    eq.put(ObjectKey.SIZE, CDOMDirectSingleRef.getRef(oldEqSa));
    return pcWCat;
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 43 with SizeAdjustment

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

the class SizeToken method process.

@Override
public boolean process(LoadContext context, PCTemplate template) {
    String value = template.get(StringKey.SIZEFORMULA);
    if (value == null) {
        return true;
    }
    SizeAdjustment size = context.getReferenceContext().silentlyGetConstructedCDOMObject(SizeAdjustment.class, value);
    Formula sizeFormula;
    if (size == null) {
        sizeFormula = FormulaFactory.getFormulaFor(value);
    } else {
        sizeFormula = new FixedSizeFormula(CDOMDirectSingleRef.getRef(size));
    }
    if (!sizeFormula.isValid()) {
        Logging.errorPrint("Size in " + getTokenName() + " was not valid: " + sizeFormula.toString(), context);
        return false;
    }
    context.getObjectContext().put(template, FormulaKey.SIZE, sizeFormula);
    return false;
}
Also used : FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula) Formula(pcgen.base.formula.Formula) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Aggregations

SizeAdjustment (pcgen.core.SizeAdjustment)43 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)14 Equipment (pcgen.core.Equipment)11 Race (pcgen.core.Race)10 LoadContext (pcgen.rules.context.LoadContext)10 PlayerCharacter (pcgen.core.PlayerCharacter)8 Before (org.junit.Before)7 WieldCategory (pcgen.core.character.WieldCategory)7 Formula (pcgen.base.formula.Formula)3 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)3 Campaign (pcgen.core.Campaign)3 Description (pcgen.core.Description)3 GameMode (pcgen.core.GameMode)3 PCClass (pcgen.core.PCClass)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2