use of pcgen.core.SizeAdjustment in project pcgen by PCGen.
the class PreSizeParser method parse.
/**
* Parse the pre req list
*
* @param kind The kind of the prerequisite (less the "PRE" prefix)
* @param formula The body of the prerequisite.
* @param invertResult Whether the prerequisite should invert the result.
* @param overrideQualify
* if set true, this prerequisite will be enforced in spite
* of any "QUALIFY" tag that may be present.
* @return PreReq
* @throws PersistenceLayerException
*/
@Override
public Prerequisite parse(String kind, String formula, boolean invertResult, boolean overrideQualify) throws PersistenceLayerException {
Prerequisite prereq = super.parse(kind, formula, invertResult, overrideQualify);
try {
prereq.setKind("size");
// Get the comparator type SIZEGTEQ, BSIZE, SIZENEQ etc.
String compType = kind.substring(4);
if (compType.isEmpty()) {
compType = "gteq";
}
prereq.setOperator(compType);
String abb = formula.substring(0, 1);
LoadContext context = Globals.getContext();
CDOMSingleRef<SizeAdjustment> ref = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, abb);
context.forgetMeNot(ref);
prereq.setOperand(formula);
if (invertResult) {
prereq.setOperator(prereq.getOperator().invert());
}
} catch (PrerequisiteException pe) {
throw new PersistenceLayerException("Unable to parse the prerequisite :'" + kind + ':' + formula + "'. " + pe.getLocalizedMessage());
}
return prereq;
}
use of pcgen.core.SizeAdjustment in project pcgen by PCGen.
the class CharacterUtils method selectClothes.
public static void selectClothes(final PlayerCharacter aPC) {
if (Globals.checkRule(RuleConstants.FREECLOTHES) && //$NON-NLS-1$
((aPC.getDisplay().totalNonMonsterLevels()) == 1)) {
//
// See what the PC is already carrying
//
List<Equipment> clothes = aPC.getEquipmentOfType("Clothing.Resizable", //$NON-NLS-1$ //$NON-NLS-2$
3);
//
// Check to see if any of the clothing the PC
// is carrying will actually fit and
// has a zero price attached
//
boolean hasClothes = false;
SizeAdjustment pcSizeAdj = aPC.getDisplay().getSizeAdjustment();
if (!clothes.isEmpty()) {
for (Equipment eq : clothes) {
if (!eq.isType("Magic") && (CoreUtility.doublesEqual(eq.getCost(aPC).doubleValue(), 0.0)) && pcSizeAdj.equals(eq.getSafe(ObjectKey.SIZE))) {
hasClothes = true;
break;
}
}
}
//
if (!hasClothes) {
clothes = EquipmentList.getEquipmentOfType("Clothing.Resizable.Starting", "Magic.Custom.Auto_Gen");
if (clothes.isEmpty()) {
clothes = EquipmentList.getEquipmentOfType("Clothing.Resizable", "Magic.Custom.Auto_Gen");
}
List<Equipment> selectedClothes = new ArrayList<>();
selectedClothes = Globals.getChoiceFromList(//$NON-NLS-1$
LanguageBundle.getString("in_sumSelectAFreeSetOfClothing"), clothes, selectedClothes, 1, aPC);
if (!selectedClothes.isEmpty()) {
Equipment eq = selectedClothes.get(0);
if (eq != null) {
eq = eq.clone();
eq.setQty(new Float(1));
//
if (!pcSizeAdj.equals(eq.getSafe(ObjectKey.SIZE))) {
eq.resizeItem(aPC, pcSizeAdj);
}
// make cost 0
eq.setCostMod('-' + eq.getCost(aPC).toString());
if (aPC.getEquipmentNamed(eq.nameItemFromModifiers(aPC)) == null) {
aPC.addEquipment(eq);
} else {
Logging.errorPrint(//$NON-NLS-1$
"Cannot add duplicate equipment to PC");
}
}
}
}
}
}
use of pcgen.core.SizeAdjustment in project pcgen by PCGen.
the class CharacterFacadeImpl method getEquipmentSizedForCharacter.
/**
* @see pcgen.core.facade.CharacterFacade#getEquipmentSizedForCharacter(pcgen.core.facade.EquipmentFacade)
*/
@Override
public EquipmentFacade getEquipmentSizedForCharacter(EquipmentFacade equipment) {
final Equipment equip = (Equipment) equipment;
final SizeAdjustment newSize = charDisplay.getSizeAdjustment();
if (equip.getSizeAdjustment() == newSize || !Globals.canResizeHaveEffect(equip, null)) {
return equipment;
}
final String existingKey = equip.getKeyName();
final String newKey = equip.createKeyForAutoResize(newSize);
Equipment potential = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, newKey);
if (newKey.equals(existingKey)) {
return equipment;
}
// in place of the selected equipment.
if (potential != null) {
return potential;
}
final String newName = equip.createNameForAutoResize(newSize);
potential = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, newName);
if (potential != null) {
return potential;
}
final Equipment newEq = equip.clone();
if (!newEq.containsKey(ObjectKey.BASE_ITEM)) {
newEq.put(ObjectKey.BASE_ITEM, CDOMDirectSingleRef.getRef(equip));
}
newEq.setName(newName);
newEq.put(StringKey.OUTPUT_NAME, newName);
newEq.put(StringKey.KEY_NAME, newKey);
newEq.resizeItem(theCharacter, newSize);
newEq.removeType(Type.AUTO_GEN);
newEq.removeType(Type.STANDARD);
if (!newEq.isType(Constants.TYPE_CUSTOM)) {
newEq.addType(Type.CUSTOM);
}
Globals.getContext().getReferenceContext().importObject(newEq);
return newEq;
}
use of pcgen.core.SizeAdjustment in project pcgen by PCGen.
the class SizemultToken method parseTokenWithSeparator.
@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, LoadInfo info, String value) {
int pipeLoc = value.indexOf('|');
if (pipeLoc == -1) {
return new ParseResult.Fail(getTokenName() + " requires a pipe, found : " + value, context);
}
if (pipeLoc != value.lastIndexOf('|')) {
return new ParseResult.Fail(getTokenName() + " requires only one pipe, found : " + value, context);
}
String sizeName = value.substring(0, pipeLoc);
String multiplierString = value.substring(pipeLoc + 1);
CDOMSingleRef<SizeAdjustment> size = context.getReferenceContext().getCDOMReference(SizeAdjustment.class, sizeName);
/*
* TODO Any way to handle the situation of the sizeName being
* misspelled, etc? (old system did just first character)
*/
try {
BigDecimal multiplier = new BigDecimal(multiplierString);
if (multiplier.compareTo(BigDecimal.ZERO) <= 0) {
return new ParseResult.Fail(getTokenName() + " requires a positive multiplier : " + multiplierString + " in value: " + value, context);
}
info.addSizeAdjustment(size, multiplier);
} catch (NumberFormatException nfe) {
return new ParseResult.Fail(getTokenName() + " misunderstood multiplier : " + multiplierString + " in value: " + value, context);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.SizeAdjustment in project pcgen by PCGen.
the class PreHDTest method testClassLevels.
/**
* Tests using monster class levels
* @throws Exception
*/
public void testClassLevels() throws Exception {
monClass.setName("Humanoid");
monClass.put(ObjectKey.IS_MONSTER, true);
Globals.getContext().getReferenceContext().importObject(monClass);
race1.setName("Bugbear");
CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
race1.put(FormulaKey.SIZE, new FixedSizeFormula(largeRef));
race1.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(monClass), FormulaFactory.getFormulaFor(3)));
Globals.getContext().getReferenceContext().importObject(race1);
final PlayerCharacter character = new PlayerCharacter();
character.setRace(race1);
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREHD:MIN=4");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=3");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=3,MAX=6");
assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=4,MAX=7");
assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREHD:MIN=1,MAX=2");
assertFalse("Character doesn't have 2 or less HD", PrereqHandler.passes(prereq, character, null));
}
Aggregations