use of pcgen.core.ShieldProf in project pcgen by PCGen.
the class ShieldProfToken method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
String shieldProf;
// 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.
shieldProf = value;
StringTokenizer tok = new StringTokenizer(shieldProf, 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;
shieldProf = 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 = checkForIllegalSeparator('|', shieldProf);
if (!pr.passed()) {
return pr;
}
boolean foundAny = false;
boolean foundOther = false;
StringTokenizer tok = new StringTokenizer(shieldProf, Constants.PIPE);
List<CDOMReference<ShieldProf>> shieldProfs = 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<ShieldProf> cra;
if (prereq == null) {
cra = this;
} else {
ConditionalSelectionActor<ShieldProf> 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;
shieldProfs.add(context.getReferenceContext().getCDOMAllReference(SHIELDPROF_CLASS));
} else if (aProf.startsWith("SHIELDTYPE.") || aProf.startsWith("SHIELDTYPE=")) {
foundOther = true;
CDOMReference<Equipment> ref = TokenUtilities.getTypeReference(context, EQUIPMENT_CLASS, "SHIELD." + aProf.substring(11));
if (ref == null) {
return ParseResult.INTERNAL_ERROR;
}
equipTypes.add(ref);
} else {
foundOther = true;
shieldProfs.add(context.getReferenceContext().getCDOMReference(SHIELDPROF_CLASS, aProf));
}
}
if (foundAny && foundOther) {
return new ParseResult.Fail("Non-sensical " + getFullName() + ": Contains ANY and a specific reference: " + value, context);
}
if (!shieldProfs.isEmpty() || !equipTypes.isEmpty()) {
ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
if (prereq != null) {
pp.addPrerequisite(prereq);
}
context.getObjectContext().addToList(obj, ListKey.AUTO_SHIELDPROF, pp);
}
return ParseResult.SUCCESS;
}
use of pcgen.core.ShieldProf 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.ShieldProf 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");
}
use of pcgen.core.ShieldProf in project pcgen by PCGen.
the class ShieldProfTokenTest method loadAllReference.
@Override
protected void loadAllReference() {
List<CDOMReference<ShieldProf>> shieldProfs = new ArrayList<>();
List<CDOMReference<Equipment>> equipTypes = new ArrayList<>();
shieldProfs.add(primaryContext.getReferenceContext().getCDOMAllReference(ShieldProf.class));
ShieldProfProvider pp = new ShieldProfProvider(shieldProfs, equipTypes);
primaryProf.addToListFor(ListKey.AUTO_SHIELDPROF, pp);
}
use of pcgen.core.ShieldProf in project pcgen by PCGen.
the class PreShieldProfTester method passes.
/**
* @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
*/
@Override
public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) {
final int numberRequired = Integer.parseInt(prereq.getOperand());
int runningTotal = 0;
final String aString = prereq.getKey();
final boolean isType = aString.startsWith("TYPE") && aString.length() > 5;
final boolean isShieldType = aString.startsWith("SHIELDTYPE") && aString.length() > 11;
String typeString = null;
if (isType) {
typeString = "SHIELD." + aString.substring(5);
} else if (isShieldType) {
typeString = "SHIELD." + aString.substring(11);
}
Equipment keyEquip = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, aString);
for (ProfProvider<ShieldProf> spp : display.getShieldProfList()) {
if (keyEquip != null && spp.providesProficiency(keyEquip.getShieldProf())) {
runningTotal++;
} else if (keyEquip != null && spp.providesEquipmentType(keyEquip.getType())) {
runningTotal++;
} else if (isType && spp.providesEquipmentType(typeString)) {
runningTotal++;
} else if (isShieldType && spp.providesEquipmentType(typeString)) {
runningTotal++;
}
}
runningTotal = prereq.getOperator().compare(runningTotal, numberRequired);
return countedTotal(prereq, runningTotal);
}
Aggregations