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);
}
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;
}
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;
}
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;
}
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);
}
Aggregations