use of pcgen.core.Skill in project pcgen by PCGen.
the class MoncskillToken method unparse.
@Override
public String[] unparse(LoadContext context, Race race) {
CDOMGroupRef<ClassSkillList> monsterList = context.getReferenceContext().getCDOMTypeReference(ClassSkillList.class, "Monster");
AssociatedChanges<CDOMReference<Skill>> changes = context.getListContext().getChangesInList(getTokenName(), race, monsterList);
Changes<ChooseSelectionActor<?>> listChanges = context.getObjectContext().getListChanges(race, ListKey.NEW_CHOOSE_ACTOR);
List<String> list = new ArrayList<>();
Collection<CDOMReference<Skill>> removedItems = changes.getRemoved();
if (removedItems != null && !removedItems.isEmpty()) {
if (changes.includesGlobalClear()) {
context.addWriteMessage("Non-sensical relationship in " + getTokenName() + ": global .CLEAR and local .CLEAR. performed");
return null;
}
list.add(Constants.LST_DOT_CLEAR_DOT + ReferenceUtilities.joinLstFormat(removedItems, "|.CLEAR."));
}
Collection<ChooseSelectionActor<?>> listRemoved = listChanges.getRemoved();
if (listRemoved != null && !listRemoved.isEmpty()) {
if (listRemoved.contains(this)) {
list.add(".CLEAR.LIST");
}
}
if (changes.includesGlobalClear()) {
list.add(Constants.LST_DOT_CLEAR);
}
MapToList<CDOMReference<Skill>, AssociatedPrereqObject> map = changes.getAddedAssociations();
if (map != null && !map.isEmpty()) {
Set<CDOMReference<Skill>> added = map.getKeySet();
for (CDOMReference<Skill> ab : added) {
for (AssociatedPrereqObject assoc : map.getListFor(ab)) {
if (!SkillCost.CLASS.equals(assoc.getAssociation(AssociationKey.SKILL_COST))) {
context.addWriteMessage("Skill Cost must be " + "CLASS for Token " + getTokenName());
return null;
}
}
}
list.add(ReferenceUtilities.joinLstFormat(added, Constants.PIPE));
}
Collection<ChooseSelectionActor<?>> listAdded = listChanges.getAdded();
if (listAdded != null && !listAdded.isEmpty()) {
for (ChooseSelectionActor<?> csa : listAdded) {
if (csa.getSource().equals(getTokenName())) {
try {
list.add(csa.getLstFormat());
} catch (PersistenceLayerException e) {
context.addWriteMessage("Error writing Prerequisite: " + e);
return null;
}
}
}
}
if (list.isEmpty()) {
// Zero indicates no add or clear
return null;
}
return list.toArray(new String[list.size()]);
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class PreCSkillTest method testCSkillServesAs.
public void testCSkillServesAs() throws Exception {
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, myClass, true);
myClass = character.getClassKeyed("My Class");
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
Skill bar = new Skill();
bar.setName("Bar");
bar.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(bar);
Skill foo = new Skill();
foo.setName("Foo");
foo.addToListFor(ListKey.SERVES_AS_SKILL, CDOMDirectSingleRef.getRef(bar));
foo.addToListFor(ListKey.TYPE, Type.getConstant("Foo"));
Globals.getContext().getReferenceContext().importObject(foo);
Skill baz = new Skill();
baz.setName("Baz");
baz.addToListFor(ListKey.TYPE, Type.getConstant("Baz"));
Globals.getContext().getReferenceContext().importObject(baz);
Skill fee = new Skill();
fee.setName("Fee");
fee.addToListFor(ListKey.TYPE, Type.getConstant("Bar"));
Globals.getContext().getReferenceContext().importObject(fee);
character.addLocalCost(myClass, fee, SkillCost.CLASS, myClass);
character.addLocalCost(myClass, foo, SkillCost.CLASS, myClass);
prereq = factory.parse("PRECSKILL:1,Bar");
assertTrue("Character has 1 Listen Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Bar,Fee");
assertTrue("Character has a Bar Skill and a Fee Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,Baz,Fee");
assertFalse("Character does not have both Baz and Fee Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:1,TYPE=Bar");
assertTrue("Character has 1 Bar Type Skill", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:2,TYPE=Bar");
assertTrue("Character has 2 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PRECSKILL:3,TYPE=Bar");
assertFalse("Character has less than 3 Bar Type Skills", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class PreCSkillTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
spot = new Skill();
spot.setName("Spot");
Globals.getContext().getReferenceContext().importObject(spot);
Skill listen = new Skill();
listen.setName("Listen");
Globals.getContext().getReferenceContext().importObject(listen);
spy1 = new Skill();
spy1.setName("Spy 1");
spy1.addToListFor(ListKey.TYPE, Type.getConstant("Spy"));
Globals.getContext().getReferenceContext().importObject(spy1);
spy2 = new Skill();
spy2.setName("Spy 2");
spy2.addToListFor(ListKey.TYPE, Type.getConstant("Spy"));
Globals.getContext().getReferenceContext().importObject(spy2);
spy3 = new Skill();
spy3.setName("Spy 3");
spy3.addToListFor(ListKey.TYPE, Type.getConstant("Spy"));
Globals.getContext().getReferenceContext().importObject(spy3);
Skill spy4 = new Skill();
spy4.setName("Spy 4");
spy4.addToListFor(ListKey.TYPE, Type.getConstant("Spy"));
Globals.getContext().getReferenceContext().importObject(spy4);
myClass.setName("My Class");
myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
Globals.getContext().getReferenceContext().importObject(myClass);
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class LocalSkillCostFacetTest method testAddBadSource.
@Test
public void testAddBadSource() {
Skill t1 = getObject();
PCClassLevel pcl = new PCClassLevel();
DataFacetChangeEvent<CharID, CDOMObject> dfce = new DataFacetChangeEvent<>(id, pcl, new Object(), DataFacetChangeEvent.DATA_ADDED);
ListKey<CDOMReference<Skill>> lk = ListKey.LOCALCSKILL;
pcl.addToListFor(lk, CDOMDirectSingleRef.getRef(t1));
try {
getFacet().dataAdded(dfce);
fail();
} catch (IllegalArgumentException e) {
// Yep!
}
}
use of pcgen.core.Skill in project pcgen by PCGen.
the class LocalSkillCostFacetTest method testCopyContentsOne.
@Test
public void testCopyContentsOne() {
Skill t1 = getObject();
Skill t2 = getAltObject();
assertFalse(getFacet().contains(id, class1, SkillCost.CLASS, t1));
addCost(id, class1, t1, SkillCost.CLASS);
assertFalse(getFacet().contains(id, class1, SkillCost.CLASS, t2));
assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t1));
addCost(id, class1, t2, SkillCost.CLASS);
assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t1));
assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t2));
assertFalse(getFacet().contains(id, class2, SkillCost.CLASS, t2));
addCost(id, class2, t2, SkillCost.CLASS);
assertTrue(getFacet().contains(id, class2, SkillCost.CLASS, t2));
getFacet().copyContents(id, altid);
//prove the copy
assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t1));
assertTrue(getFacet().contains(id, class1, SkillCost.CLASS, t2));
assertTrue(getFacet().contains(id, class2, SkillCost.CLASS, t2));
assertTrue(getFacet().contains(altid, class1, SkillCost.CLASS, t1));
assertTrue(getFacet().contains(altid, class1, SkillCost.CLASS, t2));
assertTrue(getFacet().contains(id, class2, SkillCost.CLASS, t2));
//prove independence (remove from id)
removeCosts(id, class1);
assertFalse(getFacet().contains(id, class1, SkillCost.CLASS, t1));
assertFalse(getFacet().contains(id, class1, SkillCost.CLASS, t2));
assertTrue(getFacet().contains(altid, class1, SkillCost.CLASS, t1));
assertTrue(getFacet().contains(altid, class1, SkillCost.CLASS, t2));
}
Aggregations