Search in sources :

Example 6 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class ClassSkillListFacet method levelChanged.

@Override
public void levelChanged(ClassLevelChangeEvent lce) {
    if ((lce.getOldLevel() == 0) && (lce.getNewLevel() > 0)) {
        PCClass cl = lce.getPCClass();
        CharID id = lce.getCharID();
        TransitionChoice<ClassSkillList> csc = cl.get(ObjectKey.SKILLLIST_CHOICE);
        if (csc == null) {
            ClassSkillList l = cl.get(ObjectKey.CLASS_SKILLLIST);
            if (l != null) {
                defaultClassSkillListFacet.add(id, cl, l, cl);
            }
        } else {
            PlayerCharacter pc = trackingFacet.getPC(id);
            for (ClassSkillList st : csc.driveChoice(pc)) {
                add(id, cl, st, cl);
            }
        }
    } else if ((lce.getOldLevel() > 0) && (lce.getNewLevel() == 0)) {
        removeAllFromSource(lce.getCharID(), lce.getPCClass());
    }
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) PCClass(pcgen.core.PCClass) CharID(pcgen.cdom.enumeration.CharID) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 7 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class ClassSkillListFacet method dataAdded.

@Override
public void dataAdded(ScopeFacetChangeEvent<CharID, PCClass, String> dfce) {
    PCClass cl = dfce.getScope();
    String subClassKey = dfce.getCDOMObject();
    SubClass subclass = cl.getSubClassKeyed(subClassKey);
    if (subclass != null) {
        ClassSkillList scl = subclass.get(ObjectKey.CLASS_SKILLLIST);
        defaultClassSkillListFacet.add(dfce.getCharID(), cl, scl, subclass);
    }
}
Also used : SubClass(pcgen.core.SubClass) PCClass(pcgen.core.PCClass) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 8 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class ClassSkillListFacet method dataRemoved.

@Override
public void dataRemoved(ScopeFacetChangeEvent<CharID, PCClass, String> dfce) {
    PCClass cl = dfce.getScope();
    String subClassKey = dfce.getCDOMObject();
    SubClass subclass = cl.getSubClassKeyed(subClassKey);
    if (subclass != null) {
        ClassSkillList scl = subclass.get(ObjectKey.CLASS_SKILLLIST);
        defaultClassSkillListFacet.add(dfce.getCharID(), cl, scl, subclass);
    }
}
Also used : SubClass(pcgen.core.SubClass) PCClass(pcgen.core.PCClass) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 9 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList in project pcgen by PCGen.

the class AbstractReferenceContext method buildDerivedObjects.

public void buildDerivedObjects() {
    Collection<Domain> domains = getConstructedCDOMObjects(Domain.class);
    for (Domain d : domains) {
        DomainSpellList dsl = constructCDOMObject(DOMAINSPELLLIST_CLASS, d.getKeyName());
        dsl.addType(Type.DIVINE);
        d.put(ObjectKey.DOMAIN_SPELLLIST, dsl);
    }
    Collection<PCClass> classes = getConstructedCDOMObjects(PCClass.class);
    for (PCClass pcc : classes) {
        String key = pcc.getKeyName();
        ClassSkillList skl = constructCDOMObject(CLASSSKILLLIST_CLASS, key);
        boolean isMonster = pcc.isMonster();
        if (isMonster) {
            skl.addType(Type.MONSTER);
        }
        pcc.put(ObjectKey.CLASS_SKILLLIST, skl);
        /*
			 * TODO Need to limit which are built to only spellcasters... If you
			 * do that, please see TO-DO in SpellListFacet
			 */
        ClassSpellList csl = constructCDOMObject(CLASSSPELLLIST_CLASS, key);
        FactKey<String> fk = FactKey.valueOf("SpellType");
        String spelltype = pcc.getResolved(fk);
        if (spelltype != null) {
            csl.addType(Type.getConstant(spelltype));
        }
        pcc.put(ObjectKey.CLASS_SPELLLIST, csl);
        // for (CDOMSubClass subcl : subclasses)
        if (pcc.containsListFor(ListKey.SUB_CLASS)) {
            SubClassCategory cat = SubClassCategory.getConstant(key);
            boolean needSelf = pcc.getSafe(ObjectKey.ALLOWBASECLASS).booleanValue();
            for (SubClass subcl : pcc.getListFor(ListKey.SUB_CLASS)) {
                String subKey = subcl.getKeyName();
                if (subKey.equalsIgnoreCase(key)) {
                    //Now an error to explicitly create this match, see CODE-1928
                    Logging.errorPrint("Cannot explicitly create a SUBCLASS that matches the parent class.  " + "Use ALLOWBASECLASS.  " + "Tokens on the offending SUBCLASS line will be ignored");
                    pcc.removeFromListFor(ListKey.SUB_CLASS, subcl);
                    continue;
                }
                skl = constructCDOMObject(CLASSSKILLLIST_CLASS, subKey);
                if (isMonster) {
                    skl.addType(Type.MONSTER);
                }
                subcl.put(ObjectKey.CLASS_SKILLLIST, skl);
                // TODO Need to limit which are built to only
                // spellcasters...
                csl = constructCDOMObject(CLASSSPELLLIST_CLASS, subKey);
                if (spelltype != null) {
                    csl.addType(Type.getConstant(spelltype));
                }
                subcl.put(ObjectKey.CLASS_SPELLLIST, csl);
                // constructCDOMObject(SPELLPROGRESSION_CLASS, subKey);
                /*
					 * CONSIDER For right now, this is easiest to do here, though
					 * doing this 'live' may be more appropriate in the end.
					 */
                subcl.setCDOMCategory(cat);
                importObject(subcl);
            }
            if (needSelf) {
                SubClass self = constructCDOMObject(SUBCLASS_CLASS, key);
                reassociateCategory(SUBCLASS_CLASS, self, null, cat);
            }
        }
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) SubClassCategory(pcgen.cdom.enumeration.SubClassCategory) SubClass(pcgen.core.SubClass) ClassSpellList(pcgen.cdom.list.ClassSpellList) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) ClassSkillList(pcgen.cdom.list.ClassSkillList)

Example 10 with ClassSkillList

use of pcgen.cdom.list.ClassSkillList 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)

Aggregations

ClassSkillList (pcgen.cdom.list.ClassSkillList)25 CDOMReference (pcgen.cdom.base.CDOMReference)8 PCClass (pcgen.core.PCClass)8 Skill (pcgen.core.Skill)8 Test (org.junit.Test)6 CharID (pcgen.cdom.enumeration.CharID)6 ArrayList (java.util.ArrayList)5 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)5 StringTokenizer (java.util.StringTokenizer)4 ParseResult (pcgen.rules.persistence.token.ParseResult)4 SkillCost (pcgen.cdom.enumeration.SkillCost)3 SubClass (pcgen.core.SubClass)3 Formula (pcgen.base.formula.Formula)2 ChoiceSet (pcgen.cdom.base.ChoiceSet)2 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)2 Race (pcgen.core.Race)2 AbstractTokenModelTest (tokenmodel.testsupport.AbstractTokenModelTest)2 CDOMObject (pcgen.cdom.base.CDOMObject)1 ChooseSelectionActor (pcgen.cdom.base.ChooseSelectionActor)1 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)1