Search in sources :

Example 46 with Skill

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()]);
}
Also used : ChooseSelectionActor(pcgen.cdom.base.ChooseSelectionActor) ArrayList(java.util.ArrayList) ClassSkillList(pcgen.cdom.list.ClassSkillList) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) Skill(pcgen.core.Skill) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 47 with Skill

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));
}
Also used : Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Example 48 with Skill

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);
}
Also used : Skill(pcgen.core.Skill)

Example 49 with Skill

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!
    }
}
Also used : DataFacetChangeEvent(pcgen.cdom.facet.event.DataFacetChangeEvent) Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference) PCClassLevel(pcgen.cdom.inst.PCClassLevel) Test(org.junit.Test)

Example 50 with Skill

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));
}
Also used : Skill(pcgen.core.Skill) Test(org.junit.Test)

Aggregations

Skill (pcgen.core.Skill)165 Test (org.junit.Test)60 PCClass (pcgen.core.PCClass)55 ArrayList (java.util.ArrayList)29 CDOMReference (pcgen.cdom.base.CDOMReference)24 CharID (pcgen.cdom.enumeration.CharID)23 SkillCost (pcgen.cdom.enumeration.SkillCost)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 PlayerCharacter (pcgen.core.PlayerCharacter)14 ChoiceSet (pcgen.cdom.base.ChoiceSet)13 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)13 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)13 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)13 StringTokenizer (java.util.StringTokenizer)10 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)10 Ability (pcgen.core.Ability)10 LoadContext (pcgen.rules.context.LoadContext)9 ClassSkillList (pcgen.cdom.list.ClassSkillList)8 HashSet (java.util.HashSet)7 CNAbility (pcgen.cdom.content.CNAbility)7