use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class PCClassTest method testAddAbility.
/**
* Test the definition and application of abilities.
* @throws PersistenceLayerException
*/
public void testAddAbility() throws PersistenceLayerException {
LoadContext context = Globals.getContext();
// Create some abilities to be added
AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
Ability ab1 = new Ability();
ab1.setName("Ability1");
ab1.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
Ability ab2 = new Ability();
ab2.setName("Ability2");
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab2);
// Link them to a template
CampaignSourceEntry source;
try {
source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
} catch (URISyntaxException e) {
throw new UnreachableError(e);
}
String classPCCText = "CLASS:Cleric HD:8 CLASSTYPE:PC TYPE:Base.PC ABB:Clr ABILITY:TestCat|AUTOMATIC|Ability1\n" + "CLASS:Cleric STARTSKILLPTS:2\n" + "2 ABILITY:TestCat|AUTOMATIC|Ability2";
PCClass pcclass = parsePCClassText(classPCCText, source);
ab1.setCDOMCategory(cat);
ab2.setCDOMCategory(cat);
context.getReferenceContext().importObject(ab1);
context.getReferenceContext().importObject(ab2);
CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
assertTrue(context.getReferenceContext().resolveReferences(null));
CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
Collection<CDOMReference<Ability>> mods = pcclass.getListMods(autoList);
assertEquals(1, mods.size());
CDOMReference<Ability> ref = mods.iterator().next();
Collection<Ability> abilities = ref.getContainedObjects();
assertEquals(1, abilities.size());
assertEquals(ab1, abilities.iterator().next());
Collection<AssociatedPrereqObject> assocs = pcclass.getListAssociations(autoList, ref);
assertEquals(1, assocs.size());
PCClassLevel level = pcclass.getOriginalClassLevel(2);
mods = level.getListMods(autoList);
assertEquals(1, mods.size());
ref = mods.iterator().next();
abilities = ref.getContainedObjects();
assertEquals(1, abilities.size());
assertEquals(ab2, abilities.iterator().next());
assocs = level.getListAssociations(autoList, ref);
assertEquals(1, assocs.size());
// Add the class to the character
PlayerCharacter pc = getCharacter();
pc.incrementClassLevel(1, pcclass, true);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertFalse("Character should not have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
pc.incrementClassLevel(1, pcclass, true);
assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class ClassFacet method setClassLevel.
/**
* Sets the PCClassLevel object associated with the given PCClass for the Player
* Character represented by the given CharID. Returns true if the set is successful.
* The set will be successful if the given PCClass is possessed by the given
* PlayerCharacter; false otherwise.
*
* The (numeric) class level for which the given PCClassLevel should be applied is
* determined by the level value set in the PCClassLevel.
*
* @param id
* The CharID representing the Player Character for which the given
* PCClassLevel should be set
* @param pcc
* The PCClass object for which the PCClassLevel object is set as the
* PCClass
* @param pcl
* The PCClassLevel object to be associated with the given PCClass and
* Player Character represented by the given CharID
* @return true if the set is successful; false otherwise.
* @throws CloneNotSupportedException
* if the class level cannot be thrown
*/
public boolean setClassLevel(CharID id, PCClass pcc, PCClassLevel pcl) throws CloneNotSupportedException {
if (pcc == null) {
throw new IllegalArgumentException("Class cannot be null in setClassLevel");
}
if (pcl == null) {
throw new IllegalArgumentException("Class Level cannot be null in setClassLevel");
}
ClassInfo info = getClassInfo(id);
if (info == null) {
return false;
}
PCClassLevel old = info.getClassLevel(pcc, pcl.get(IntegerKey.LEVEL));
boolean returnVal = info.setClassLevel(pcc, pcl);
support.fireClassLevelObjectChangeEvent(id, pcc, old, pcl);
return returnVal;
}
use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class UnarmedDamageFacet method dataAdded.
/**
* Stores in this facet any Unarmed Damage information from a CDOMObject
* which has been added to a Player Character.
*
* Triggered when one of the Facets to which UnarmedDamageFacet listens
* fires a DataFacetChangeEvent to indicate a CDOMObject was added to a
* Player Character.
*
* @param dfce
* The DataFacetChangeEvent containing the information about the
* change
*
* @see pcgen.cdom.facet.event.DataFacetChangeListener#dataAdded(pcgen.cdom.facet.event.DataFacetChangeEvent)
*/
@Override
public void dataAdded(DataFacetChangeEvent<CharID, CDOMObject> dfce) {
CDOMObject cdo = dfce.getCDOMObject();
if (cdo instanceof PCClass || cdo instanceof PCClassLevel) {
return;
}
List<String> damage = cdo.getListFor(ListKey.UNARMED_DAMAGE);
if (damage != null) {
add(dfce.getCharID(), damage, cdo);
}
}
use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class AddLst method parseNonEmptyToken.
@Override
protected ParseResult parseNonEmptyToken(LoadContext context, CDOMObject obj, String value) {
if (obj instanceof Ungranted) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Ungranted object type: " + obj.getClass().getSimpleName(), context);
}
if (obj instanceof NonInteractive) {
return new ParseResult.Fail("Cannot use " + getTokenName() + " on an Non-Interactive object type: " + obj.getClass().getSimpleName(), context);
}
int pipeLoc = value.indexOf(Constants.PIPE);
if (pipeLoc == -1) {
if (Constants.LST_DOT_CLEAR.equals(value)) {
if (obj instanceof PCClassLevel) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A non-level limited .CLEAR was " + "used in a Class Level line in " + obj.getKeyName());
return cpr;
}
} else if (value.startsWith(".CLEAR.LEVEL")) {
if (!(obj instanceof PCClassLevel)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was not used in a Class Level line in " + obj.getClass().getSimpleName() + ' ' + obj.getKeyName());
return cpr;
}
String levelString = value.substring(12);
try {
int level = Integer.parseInt(levelString);
if (level != obj.get(IntegerKey.LEVEL)) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid " + ".CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But was asked to clear a " + "different Class Level ( " + level + " ) than the Class Level Line it appeared on: " + obj.getKeyName());
return cpr;
}
} catch (NumberFormatException e) {
ComplexParseResult cpr = new ComplexParseResult();
cpr.addErrorMessage("Warning: You performed an invalid .CLEAR in a ADD: Token");
cpr.addErrorMessage(" A level limited .CLEAR ( " + value + " ) was used in a Class Level line");
cpr.addErrorMessage(" But the level ( " + levelString + " ) was not an integer in: " + obj.getKeyName());
return cpr;
}
} else {
return new ParseResult.Fail(getTokenName() + " requires a SubToken and argument, found: " + value, context);
}
context.getObjectContext().removeList(obj, ListKey.ADD);
return ParseResult.SUCCESS;
}
return context.processSubToken(obj, getTokenName(), value.substring(0, pipeLoc), value.substring(pipeLoc + 1));
}
use of pcgen.cdom.inst.PCClassLevel in project pcgen by PCGen.
the class PCClassTest method testFireNameChangedVariable.
/**
* Test name change
*/
public void testFireNameChangedVariable() {
final PCClass myClass = new PCClass();
myClass.setName("myClass");
myClass.put(StringKey.KEY_NAME, "KEY_myClass");
PCClassLevel cl2 = myClass.getOriginalClassLevel(2);
cl2.put(VariableKey.getConstant("someVar"), FormulaFactory.getFormulaFor("(CL=KEY_myClass/2) + CL=KEY_myClass"));
assertEquals(1, cl2.getVariableKeys().size());
assertEquals("someVar", cl2.getVariableKeys().iterator().next().toString());
assertNotNull(cl2.get(VariableKey.getConstant("someVar")));
assertEquals("(CL=KEY_myClass/2) + CL=KEY_myClass", cl2.get(VariableKey.getConstant("someVar")).toString());
myClass.setName("someOtherClass");
PCClassKeyChange.changeReferences("myClass", myClass);
assertEquals(1, cl2.getVariableKeys().size());
assertEquals("someVar", cl2.getVariableKeys().iterator().next().toString());
assertEquals("(CL=KEY_myClass/2) + CL=KEY_myClass", cl2.get(VariableKey.getConstant("someVar")).toString());
PCClassKeyChange.changeReferences("KEY_myClass", myClass);
assertEquals(1, cl2.getVariableKeys().size());
assertEquals("someVar", cl2.getVariableKeys().iterator().next().toString());
assertEquals("(CL=someOtherClass/2) + CL=someOtherClass", cl2.get(VariableKey.getConstant("someVar")).toString());
}
Aggregations