Search in sources :

Example 11 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ListSkillCostFacet method dataAdded.

/**
	 * Adds the SkillCost objects granted by CDOMObjects, as applied directly to
	 * a ClassSkillList, when a CDOMObject is added to a Player Character.
	 * 
	 * Triggered when one of the Facets to which ListSkillCostFacet 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();
    CharID id = dfce.getCharID();
    for (CDOMReference ref : cdo.getModifiedLists()) {
        List<ClassSkillList> useList = new ArrayList<>();
        for (Object list : ref.getContainedObjects()) {
            if (list instanceof ClassSkillList) {
                useList.add((ClassSkillList) list);
            }
        }
        if (!useList.isEmpty()) {
            Collection<CDOMReference<Skill>> mods = cdo.getListMods(ref);
            for (CDOMReference<Skill> skRef : mods) {
                for (AssociatedPrereqObject apo : (Iterable<AssociatedPrereqObject>) cdo.getListAssociations(ref, skRef)) {
                    SkillCost sc = apo.getAssociation(AssociationKey.SKILL_COST);
                    for (ClassSkillList csl : useList) {
                        for (Skill skill : skRef.getContainedObjects()) {
                            add(id, csl, sc, skill, cdo);
                        }
                    }
                }
            }
        }
    }
}
Also used : SkillCost(pcgen.cdom.enumeration.SkillCost) ArrayList(java.util.ArrayList) CharID(pcgen.cdom.enumeration.CharID) ClassSkillList(pcgen.cdom.list.ClassSkillList) Skill(pcgen.core.Skill) CDOMObject(pcgen.cdom.base.CDOMObject) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 12 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class AvailableSpellInputFacet method dataAdded.

/**
	 * Triggered when one of the Facets to which ConditionallyKnownSpellFacet
	 * 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();
    Collection<CDOMReference<? extends CDOMList<?>>> listrefs = cdo.getModifiedLists();
    CharID id = dfce.getCharID();
    for (CDOMReference<? extends CDOMList<?>> ref : listrefs) {
        processListRef(id, cdo, ref);
    }
}
Also used : CDOMObject(pcgen.cdom.base.CDOMObject) CDOMList(pcgen.cdom.base.CDOMList) CharID(pcgen.cdom.enumeration.CharID) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 13 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class PlayerCharacter method processAbilityList.

private void processAbilityList(CDOMObject cdo, CDOMReference<AbilityList> ref) {
    Collection<CDOMReference<Ability>> mods = cdo.getListMods(ref);
    for (CDOMReference<Ability> objref : mods) {
        Collection<Ability> objs = objref.getContainedObjects();
        Collection<AssociatedPrereqObject> assoc = cdo.getListAssociations(ref, objref);
        for (Ability ab : objs) {
            if (ab == null) {
                Logging.log(Logging.LST_ERROR, "Missing object referenced in the ability list for '" + cdo + "' list is " + ref + ". Source " + cdo.getSourceURI());
                continue;
            }
            for (AssociatedPrereqObject apo : assoc) {
                Nature nature = apo.getAssociation(AssociationKey.NATURE);
                CDOMSingleRef<AbilityCategory> acRef = apo.getAssociation(AssociationKey.CATEGORY);
                AbilityCategory cat = acRef.get();
                if (ab.getSafe(ObjectKey.MULTIPLE_ALLOWED)) {
                    List<String> choices = apo.getAssociation(AssociationKey.ASSOC_CHOICES);
                    if (choices == null) {
                        //CHOOSE:NOCHOICE can be unconditionally applied (must be STACK:YES)
                        CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), "");
                        cas.addAllPrerequisites(apo.getPrerequisiteList());
                        applyAbility(cas, cdo);
                    } else {
                        for (final String choice : choices) {
                            CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab), choice);
                            cas.addAllPrerequisites(apo.getPrerequisiteList());
                            applyAbility(cas, cdo);
                        }
                    }
                } else {
                    CNAbilitySelection cas = new CNAbilitySelection(CNAbilityFactory.getCNAbility(cat, nature, ab));
                    cas.addAllPrerequisites(apo.getPrerequisiteList());
                    applyAbility(cas, cdo);
                }
            }
        }
    }
    cabFacet.update(id);
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Nature(pcgen.cdom.enumeration.Nature) CNAbilitySelection(pcgen.cdom.helper.CNAbilitySelection) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 14 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class ClassDataHandler method getSpellsIn.

/**
	 * Returns a List of Spell with following criteria:
	 *
	 * @param level      (optional, ignored if < 0),
	 * @param spellLists the lists of spells
	 * @param pc TODO
	 * @return a List of Spell
	 */
public static List<Spell> getSpellsIn(final int level, List<? extends CDOMList<Spell>> spellLists) {
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    ArrayList<CDOMReference<CDOMList<Spell>>> useLists = new ArrayList<>();
    for (CDOMReference ref : masterLists.getActiveLists()) {
        for (CDOMList<Spell> list : spellLists) {
            if (ref.contains(list)) {
                useLists.add(ref);
                break;
            }
        }
    }
    boolean allLevels = level == -1;
    Set<Spell> spellList = new HashSet<>();
    for (CDOMReference<CDOMList<Spell>> ref : useLists) {
        for (Spell spell : masterLists.getObjects(ref)) {
            Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(ref, spell);
            for (AssociatedPrereqObject apo : assoc) {
                // TODO Not sure if effect of null for PC
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), (PlayerCharacter) null, null)) {
                    int lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
                    if (allLevels || level == lvl) {
                        spellList.add(spell);
                        break;
                    }
                }
            }
        }
    }
    return new ArrayList<>(spellList);
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) MasterListInterface(pcgen.cdom.base.MasterListInterface) CDOMList(pcgen.cdom.base.CDOMList) CDOMReference(pcgen.cdom.base.CDOMReference) HashSet(java.util.HashSet) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 15 with CDOMReference

use of pcgen.cdom.base.CDOMReference in project pcgen by PCGen.

the class DeityToken method getToken.

/**
	 * @see pcgen.io.exporttoken.Token#getToken(java.lang.String, pcgen.core.PlayerCharacter, pcgen.io.ExportHandler)
	 */
@Override
public String getToken(String tokenSource, PlayerCharacter pc, ExportHandler eh) {
    String retString = "";
    CharacterDisplay display = pc.getDisplay();
    Deity deity = display.getDeity();
    if (deity != null) {
        StringTokenizer aTok = new StringTokenizer(tokenSource, ".", false);
        String subTag = "OUTPUTNAME";
        if (aTok.countTokens() > 1) {
            aTok.nextToken();
            subTag = aTok.nextToken();
        }
        if ("NAME".equals(subTag)) {
            if (!display.getSuppressBioField(BiographyField.DEITY)) {
                retString = deity.getDisplayName();
            }
        } else if ("OUTPUTNAME".equals(subTag)) {
            if (!display.getSuppressBioField(BiographyField.DEITY)) {
                retString = OutputNameFormatting.getOutputName(deity);
            }
        } else if ("DOMAINLIST".equals(subTag)) {
            retString = getDomainListToken(deity);
        } else if ("FOLLOWERALIGNMENT".equals(subTag)) {
            Logging.errorPrint("Output Sheet uses DEITY.FOLLOWERALIGN: " + "Function has been removed from PCGen");
        } else if ("ALIGNMENT".equals(subTag)) {
            CDOMSingleRef<PCAlignment> al = deity.get(ObjectKey.ALIGNMENT);
            retString = al == null ? "" : al.get().getKeyName();
        } else if ("APPEARANCE".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Appearance");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("DESCRIPTION".equals(subTag)) {
            retString = pc.getDescription(deity);
        } else if ("HOLYITEM".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Symbol");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("FAVOREDWEAPON".equals(subTag)) {
            List<CDOMReference<WeaponProf>> dwp = deity.getSafeListFor(ListKey.DEITYWEAPON);
            retString = ReferenceUtilities.joinLstFormat(dwp, Constants.PIPE, true);
        } else if ("PANTHEONLIST".equals(subTag)) {
            FactSetKey<String> fk = FactSetKey.valueOf("Pantheon");
            Set<String> pset = new TreeSet<>();
            for (Indirect<String> indirect : deity.getSafeSetFor(fk)) {
                pset.add(indirect.get());
            }
            retString = StringUtil.join(pset, ", ");
        } else if ("SOURCE".equals(subTag)) {
            retString = SourceFormat.getFormattedString(deity, Globals.getSourceDisplay(), true);
        } else if ("SA".equals(subTag)) {
            retString = getSAToken(deity, display);
        } else if ("TITLE".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Title");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        } else if ("WORSHIPPERS".equals(subTag)) {
            FactKey<String> fk = FactKey.valueOf("Worshippers");
            String str = deity.getResolved(fk);
            retString = (str == null) ? "" : str;
        }
    }
    return retString;
}
Also used : Deity(pcgen.core.Deity) TreeSet(java.util.TreeSet) Set(java.util.Set) CharacterDisplay(pcgen.core.display.CharacterDisplay) Indirect(pcgen.base.util.Indirect) FactKey(pcgen.cdom.enumeration.FactKey) StringTokenizer(java.util.StringTokenizer) PCAlignment(pcgen.core.PCAlignment) FactSetKey(pcgen.cdom.enumeration.FactSetKey) CDOMReference(pcgen.cdom.base.CDOMReference)

Aggregations

CDOMReference (pcgen.cdom.base.CDOMReference)125 ArrayList (java.util.ArrayList)57 StringTokenizer (java.util.StringTokenizer)40 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)35 ParseResult (pcgen.rules.persistence.token.ParseResult)30 Skill (pcgen.core.Skill)24 ChoiceSet (pcgen.cdom.base.ChoiceSet)22 ConcretePersistentTransitionChoice (pcgen.cdom.base.ConcretePersistentTransitionChoice)21 ReferenceChoiceSet (pcgen.cdom.choiceset.ReferenceChoiceSet)19 Prerequisite (pcgen.core.prereq.Prerequisite)18 Formula (pcgen.base.formula.Formula)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Spell (pcgen.core.spell.Spell)15 TreeSet (java.util.TreeSet)14 Test (org.junit.Test)14 ClassSkillChoiceActor (pcgen.cdom.helper.ClassSkillChoiceActor)12 CharID (pcgen.cdom.enumeration.CharID)11 ObjectMatchingReference (pcgen.cdom.reference.ObjectMatchingReference)11 ParsingSeparator (pcgen.base.text.ParsingSeparator)10 CDOMList (pcgen.cdom.base.CDOMList)10