Search in sources :

Example 11 with SizeAdjustment

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

the class SizeTokenTest method setUp.

@Override
@Before
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    ps = BuildUtilities.createSize("Small", 0);
    primaryContext.getReferenceContext().importObject(ps);
    SizeAdjustment pm = BuildUtilities.createSize("Medium", 1);
    primaryContext.getReferenceContext().importObject(pm);
    SizeAdjustment ss = BuildUtilities.createSize("Small", 0);
    secondaryContext.getReferenceContext().importObject(ss);
    SizeAdjustment sm = BuildUtilities.createSize("Medium", 1);
    secondaryContext.getReferenceContext().importObject(sm);
}
Also used : SizeAdjustment(pcgen.core.SizeAdjustment) Before(org.junit.Before)

Example 12 with SizeAdjustment

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

the class NaturalattacksLst method process.

@Override
public boolean process(LoadContext context, CDOMObject obj) {
    List<Equipment> natWeapons = obj.getListFor(ListKey.NATURAL_WEAPON);
    if (natWeapons != null) {
        Formula sizeFormula = obj.getSafe(FormulaKey.SIZE);
        // If the size was just a default, check for a size prereq and use that instead.
        if (obj.get(FormulaKey.SIZE) == null && obj.hasPreReqTypeOf("SIZE")) {
            Integer requiredSize = getRequiredSize(obj);
            if (requiredSize != null) {
                sizeFormula = FormulaFactory.getFormulaFor(requiredSize);
            }
        }
        if (sizeFormula.isStatic()) {
            int isize = sizeFormula.resolveStatic().intValue();
            SizeAdjustment size = context.getReferenceContext().getSortedList(SizeAdjustment.class, IntegerKey.SIZEORDER).get(isize);
            for (Equipment e : natWeapons) {
                CDOMDirectSingleRef<SizeAdjustment> sizeRef = CDOMDirectSingleRef.getRef(size);
                e.put(ObjectKey.BASESIZE, sizeRef);
                e.put(ObjectKey.SIZE, sizeRef);
            }
        } else {
            Logging.errorPrint("SIZE in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName() + " must not be a variable " + "if it contains a NATURALATTACKS token");
        }
    }
    return true;
}
Also used : Formula(pcgen.base.formula.Formula) Equipment(pcgen.core.Equipment) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 13 with SizeAdjustment

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

the class NaturalattacksLst method getRequiredSize.

/**
	 * Retrieve the required size (i.e. PRESIZE) for the object defining the attack. Will
	 * only return a value if there is a single size. 
	 * @param obj The defining object. 
	 * @return The size integer, or null if none (or multiple) specified.
	 */
private Integer getRequiredSize(CDOMObject obj) {
    Set<Prerequisite> sizePrereqs = new HashSet<>();
    for (Prerequisite prereq : obj.getPrerequisiteList()) {
        sizePrereqs.addAll(PrerequisiteUtilities.getPreReqsOfKind(prereq, "SIZE"));
    }
    Integer requiredSize = null;
    for (Prerequisite prereq : sizePrereqs) {
        SizeAdjustment sa = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(SizeAdjustment.class, prereq.getOperand());
        final int targetSize = sa.get(IntegerKey.SIZEORDER);
        if (requiredSize != null && requiredSize != targetSize) {
            return null;
        }
        requiredSize = targetSize;
    }
    return requiredSize;
}
Also used : SizeAdjustment(pcgen.core.SizeAdjustment) HashSet(java.util.HashSet) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 14 with SizeAdjustment

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

the class SizeNumToken method process.

@Override
public boolean process(LoadContext context, Collection<? extends SizeAdjustment> obj) {
    boolean returnValue = true;
    Collection<SizeAdjustment> ordered;
    boolean hasAny = false;
    //First loop to detect deprecated case, remove in 6.7
    for (SizeAdjustment sa : obj) {
        if (sa.get(IntegerKey.SIZENUM) != null) {
            hasAny = true;
        }
    }
    if (hasAny) {
        Map<Integer, SizeAdjustment> map = new TreeMap<>();
        for (SizeAdjustment sa : obj) {
            Integer sizenum = sa.get(IntegerKey.SIZENUM);
            if (sizenum == null) {
                Logging.errorPrint("Size: " + sa.getKeyName() + " did not have a SIZENUM (cannot be assumed)");
                returnValue = false;
                continue;
            }
            SizeAdjustment previous = map.put(sizenum, sa);
            if (previous != null) {
                Logging.errorPrint("Size: " + sa.getKeyName() + " and size: " + previous.getKeyName() + " had identical SIZENUM: " + sizenum);
                returnValue = false;
            }
        }
        ordered = map.values();
    } else {
        //Provide a fall back to avoid immediate failure
        Logging.deprecationPrint("SizeAdjustment items must have a SIZENUM", context);
        ordered = context.getReferenceContext().getOrderSortedCDOMObjects(SizeAdjustment.class);
    }
    int order = 0;
    for (SizeAdjustment sa : ordered) {
        sa.put(IntegerKey.SIZEORDER, order++);
    }
    return returnValue;
}
Also used : TreeMap(java.util.TreeMap) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 15 with SizeAdjustment

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

the class PreBaseSizeTester method passes.

/**
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException {
    int runningTotal = 0;
    if ((display.getRace() != null) && !display.getRace().equals(Globals.s_EMPTYRACE)) {
        AbstractReferenceContext ref = Globals.getContext().getReferenceContext();
        SizeAdjustment sa = ref.silentlyGetConstructedCDOMObject(SizeAdjustment.class, prereq.getOperand());
        int targetSize = sa.get(IntegerKey.SIZEORDER);
        runningTotal = prereq.getOperator().compare(display.racialSizeInt(), targetSize);
    }
    return countedTotal(prereq, runningTotal);
}
Also used : AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) SizeAdjustment(pcgen.core.SizeAdjustment)

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