use of pcgen.core.ArmorProf in project pcgen by PCGen.
the class ArmorProfToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
String armorProf;
// Do not initialize, null is significant!
Prerequisite prereq = null;
boolean isPre = false;
if (value.indexOf("[") == -1) {
// Supported version of PRExxx using |. Needs to be at the front of the
// Parsing code because many objects expect the pre to have been determined
// Ahead of time. Until deprecated code is removed, it will have to stay
// like this.
armorProf = value;
StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
while (tok.hasMoreTokens()) {
String token = tok.nextToken();
if (PreParserFactory.isPreReqString(token)) {
if (isPre) {
String errorText = "Invalid " + getTokenName() + ": " + value + " PRExxx must be at the END of the Token";
Logging.errorPrint(errorText);
return new ParseResult.Fail(errorText, context);
}
prereq = getPrerequisite(token);
if (prereq == null) {
return new ParseResult.Fail("Error generating Prerequisite " + prereq + " in " + getFullName(), context);
}
int preStart = value.indexOf(token) - 1;
armorProf = value.substring(0, preStart);
isPre = true;
}
}
} else {
return new ParseResult.Fail("Use of [] for Prerequisites has been removed. " + "Please use | based standard", context);
}
ParseResult pr = checkSeparatorsAndNonEmpty('|', armorProf);
if (!pr.passed()) {
return pr;
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(armorProf, Constants.PIPE);
List<CDOMReference<ArmorProf>> armorProfs = new ArrayList<>();
List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
while (tok.hasMoreTokens()) {
String aProf = tok.nextToken();
if (Constants.LST_PERCENT_LIST.equals(aProf)) {
foundOther = true;
ChooseSelectionActor<ArmorProf> cra;
if (prereq == null) {
cra = this;
} else {
ConditionalSelectionActor<ArmorProf> cca = new ConditionalSelectionActor<>(this);
cca.addPrerequisite(prereq);
cra = cca;
}
context.getObjectContext().addToList(obj, ListKey.NEW_CHOOSE_ACTOR, cra);
} else if (Constants.LST_ALL.equalsIgnoreCase(aProf)) {
foundAny = true;
armorProfs.add(context.getReferenceContext().getCDOMAllReference(ARMORPROF_CLASS));
} else if (aProf.startsWith("ARMORTYPE.") || aProf.startsWith("ARMORTYPE=")) {
foundOther = true;
CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "ARMOR." + aProf.substring(10));
if (ref == null) {
return ParseResult.INTERNAL_ERROR;
}
equipTypes.add(ref);
} else {
foundOther = true;
armorProfs.add(context.getReferenceContext().getCDOMReference(ARMORPROF_CLASS, aProf));
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
if (!armorProfs.isEmpty() || !equipTypes.isEmpty()) {
ArmorProfProvider pp = new ArmorProfProvider(armorProfs, equipTypes);
if (prereq != null) {
pp.addPrerequisite(prereq);
}
context.getObjectContext().addToList(obj, ListKey.AUTO_ARMORPROF, pp);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.ArmorProf in project pcgen by PCGen.
the class PreArmorProfTester 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;
final int number;
try {
number = Integer.parseInt(prereq.getOperand());
} catch (NumberFormatException exceptn) {
throw new PrerequisiteException(LanguageBundle.getFormattedString("Prereq.error", "PREARMOR", //$NON-NLS-1$ //$NON-NLS-2$
prereq.toString()));
}
final String aString = prereq.getKey();
Equipment keyEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, aString);
final boolean isType = aString.startsWith("TYPE") && aString.length() > 5;
final boolean isArmorType = aString.startsWith("ARMORTYPE") && aString.length() > 11;
String typeString = null;
if (isType) {
typeString = "ARMOR." + aString.substring(5);
} else if (isArmorType) {
typeString = "ARMOR." + aString.substring(10);
}
for (ProfProvider<ArmorProf> spp : display.getArmorProfList()) {
if (keyEquip != null && spp.providesProficiency(keyEquip.getArmorProf())) {
runningTotal++;
} else if (keyEquip != null && spp.providesEquipmentType(keyEquip.getType())) {
runningTotal++;
} else if (isType && spp.providesEquipmentType(typeString)) {
runningTotal++;
} else if (isArmorType && spp.providesEquipmentType(typeString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, number);
return countedTotal(prereq, runningTotal);
}
use of pcgen.core.ArmorProf in project pcgen by PCGen.
the class ProficiencyToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, Equipment eq, String value) {
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
return new ParseResult.Fail("Equipment Token PROFICIENCY syntax " + "without a Subtoken is invalid: PROFICIENCY:" + value, context);
}
if (pipeLoc != value.lastIndexOf(Constants.PIPE)) {
return new ParseResult.Fail(getTokenName() + " expecting only one '|', " + "format is: SubToken|ProfName value was: " + value, context);
}
String subtoken = value.substring(0, pipeLoc);
String prof = value.substring(pipeLoc + 1);
if (prof == null || prof.isEmpty()) {
return new ParseResult.Fail("PROFICIENCY cannot have " + "empty second argument: " + value, context);
}
if (subtoken.equals("WEAPON")) {
// This can be reactivated if .CLEAR is implemented, to allow .MOD to override the proficiency
// if (context.getObjectContext().getObject(eq, ObjectKey.WEAPON_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:WEAPON is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<WeaponProf> wp = context.getReferenceContext().getCDOMReference(WeaponProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.WEAPON_PROF, wp);
} else if (subtoken.equals("ARMOR")) {
// if (context.getObjectContext().getObject(eq, ObjectKey.ARMOR_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:ARMOR is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<ArmorProf> wp = context.getReferenceContext().getCDOMReference(ArmorProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.ARMOR_PROF, wp);
} else if (subtoken.equals("SHIELD")) {
// if (context.getObjectContext().getObject(eq, ObjectKey.SHIELD_PROF) != null)
// {
// return new ParseResult.Fail(
// "Only one PROFICIENCY:SHIELD is allowed per item. Token was PROFICIENCY:"
// + value, context);
// }
CDOMSingleRef<ShieldProf> wp = context.getReferenceContext().getCDOMReference(ShieldProf.class, prof);
context.getObjectContext().put(eq, ObjectKey.SHIELD_PROF, wp);
} else {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Unknown Subtoken for PROFICIENCY: " + subtoken);
cpr.addErrorMessage(" Subtoken must be " + "WEAPON, ARMOR or SHIELD");
return cpr;
}
return ParseResult.SUCCESS;
}
use of pcgen.core.ArmorProf in project pcgen by PCGen.
the class PreArmorProfTest method setUp.
/**
* @see pcgen.AbstractCharacterTestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
super.setUp();
Equipment chainmailArmor = new Equipment();
chainmailArmor.setName("Chainmail");
chainmailArmor.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
chainmailArmor.addToListFor(ListKey.TYPE, Type.getConstant("Medium"));
Globals.getContext().getReferenceContext().importObject(chainmailArmor);
Equipment breastplateArmor = new Equipment();
breastplateArmor.setName("Breastplate");
breastplateArmor.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
breastplateArmor.addToListFor(ListKey.TYPE, Type.getConstant("Medium"));
Globals.getContext().getReferenceContext().importObject(breastplateArmor);
Equipment leatherArmor = new Equipment();
leatherArmor.setName("Leather");
leatherArmor.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
leatherArmor.addToListFor(ListKey.TYPE, Type.getConstant("Light"));
Globals.getContext().getReferenceContext().importObject(leatherArmor);
Equipment fullPlateArmor = new Equipment();
fullPlateArmor.setName("Full Plate");
fullPlateArmor.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
fullPlateArmor.addToListFor(ListKey.TYPE, Type.getConstant("Heavy"));
Globals.getContext().getReferenceContext().importObject(fullPlateArmor);
ArmorProf leather = new ArmorProf();
leather.setName("Leather");
leather.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
leather.addToListFor(ListKey.TYPE, Type.getConstant("Light"));
Globals.getContext().getReferenceContext().importObject(leather);
ArmorProf chainmail = new ArmorProf();
chainmail.setName("Chainmail");
chainmail.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
chainmail.addToListFor(ListKey.TYPE, Type.getConstant("Medium"));
Globals.getContext().getReferenceContext().importObject(chainmail);
ArmorProf breastplate = new ArmorProf();
breastplate.setName("Breastplate");
breastplate.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
breastplate.addToListFor(ListKey.TYPE, Type.getConstant("Medium"));
Globals.getContext().getReferenceContext().importObject(breastplate);
ArmorProf fpprof = new ArmorProf();
fpprof.setName("Full Plate");
fpprof.addToListFor(ListKey.TYPE, Type.getConstant("Armor"));
fpprof.addToListFor(ListKey.TYPE, Type.getConstant("Heavy"));
Globals.getContext().getReferenceContext().importObject(fpprof);
}
use of pcgen.core.ArmorProf in project pcgen by PCGen.
the class EquipmentQualifierTokenTest method initializeObjects.
private void initializeObjects() {
wp1 = new WeaponProf();
wp1.setName("Eq1");
primaryContext.getReferenceContext().importObject(wp1);
eq1 = new Equipment();
eq1.setName("Eq1");
primaryContext.getReferenceContext().importObject(eq1);
primaryContext.unconditionallyProcess(eq1, "TYPE", "WEAPON");
primaryContext.unconditionallyProcess(eq1, "PROFICIENCY", "WEAPON|Eq1");
sp1 = new ShieldProf();
sp1.setName("Eq2");
primaryContext.getReferenceContext().importObject(sp1);
eq2 = new Equipment();
eq2.setName("Eq2");
primaryContext.getReferenceContext().importObject(eq2);
primaryContext.unconditionallyProcess(eq2, "TYPE", "SHIELD");
primaryContext.unconditionallyProcess(eq2, "PROFICIENCY", "SHIELD|Eq2");
ap1 = new ArmorProf();
ap1.setName("Eq3");
primaryContext.getReferenceContext().importObject(ap1);
eq3 = new Equipment();
eq3.setName("Eq3");
primaryContext.getReferenceContext().importObject(eq3);
primaryContext.unconditionallyProcess(eq3, "TYPE", "ARMOR.Masterful");
primaryContext.unconditionallyProcess(eq3, "PROFICIENCY", "ARMOR|Eq3");
wp2 = new WeaponProf();
wp2.setName("Wp2");
primaryContext.getReferenceContext().importObject(wp2);
eq4 = new Equipment();
eq4.setName("Eq4");
primaryContext.getReferenceContext().importObject(eq4);
primaryContext.unconditionallyProcess(eq4, "TYPE", "WEAPON.Masterful");
primaryContext.unconditionallyProcess(eq4, "PROFICIENCY", "WEAPON|Wp2");
}
Aggregations