Search in sources :

Example 11 with AssociatedPrereqObject

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

the class SpellLevel method isLevel.

/**
	 * isLevel(int aLevel)
	 *
	 * @param aLevel
	 *            level of the spell
	 * @param aPC
	 * @return true if the spell is of the given level in any spell list
	 */
public static boolean isLevel(Spell sp, int aLevel, PlayerCharacter aPC) {
    Integer levelKey = aLevel;
    MasterListInterface masterLists = SettingsHandler.getGame().getMasterLists();
    for (PCClass pcc : aPC.getClassSet()) {
        ClassSpellList csl = pcc.get(ObjectKey.CLASS_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(csl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    for (Domain domain : aPC.getDomainSet()) {
        DomainSpellList dsl = domain.get(ObjectKey.DOMAIN_SPELLLIST);
        Collection<AssociatedPrereqObject> assoc = masterLists.getAssociations(dsl, sp);
        if (assoc != null) {
            for (AssociatedPrereqObject apo : assoc) {
                if (PrereqHandler.passesAll(apo.getPrerequisiteList(), aPC, sp)) {
                    if (levelKey.equals(apo.getAssociation(AssociationKey.SPELL_LEVEL))) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) MasterListInterface(pcgen.cdom.base.MasterListInterface) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) Domain(pcgen.core.Domain) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 12 with AssociatedPrereqObject

use of pcgen.cdom.base.AssociatedPrereqObject 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 13 with AssociatedPrereqObject

use of pcgen.cdom.base.AssociatedPrereqObject 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 14 with AssociatedPrereqObject

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

the class AdddomainsToken method unparse.

@Override
public String[] unparse(LoadContext context, PCClass pcc) {
    AssociatedChanges<CDOMReference<Domain>> changes = context.getListContext().getChangesInList(getTokenName(), pcc, PCClass.ALLOWED_DOMAINS);
    Collection<CDOMReference<Domain>> removedItems = changes.getRemoved();
    if (removedItems != null && !removedItems.isEmpty() || changes.includesGlobalClear()) {
        context.addWriteMessage(getTokenName() + " does not support .CLEAR");
        return null;
    }
    MapToList<CDOMReference<Domain>, AssociatedPrereqObject> mtl = changes.getAddedAssociations();
    if (mtl == null || mtl.isEmpty()) {
        return null;
    }
    PrerequisiteWriter prereqWriter = new PrerequisiteWriter();
    Set<String> set = new TreeSet<>();
    Set<String> noPrereqSet = new TreeSet<>();
    for (CDOMReference<Domain> domain : mtl.getKeySet()) {
        for (AssociatedPrereqObject assoc : mtl.getListFor(domain)) {
            StringBuilder sb = new StringBuilder(domain.getLSTformat(false));
            List<Prerequisite> prereqs = assoc.getPrerequisiteList();
            if (prereqs == null || prereqs.isEmpty()) {
                noPrereqSet.add(sb.toString());
                continue;
            }
            for (Prerequisite prereq : prereqs) {
                sb.append(Constants.PIPE);
                StringWriter swriter = new StringWriter();
                try {
                    prereqWriter.write(swriter, prereq);
                } catch (PersistenceLayerException e) {
                    context.addWriteMessage("Error writing Prerequisite: " + e);
                    return null;
                }
                sb.append(swriter.toString());
            }
            set.add(sb.toString());
        }
    }
    if (!noPrereqSet.isEmpty()) {
        set.add(StringUtil.join(noPrereqSet, Constants.PIPE));
    }
    return set.toArray(new String[set.size()]);
}
Also used : PrerequisiteWriter(pcgen.persistence.lst.output.prereq.PrerequisiteWriter) PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringWriter(java.io.StringWriter) TreeSet(java.util.TreeSet) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 15 with AssociatedPrereqObject

use of pcgen.cdom.base.AssociatedPrereqObject 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

AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)50 CDOMReference (pcgen.cdom.base.CDOMReference)34 ArrayList (java.util.ArrayList)18 Prerequisite (pcgen.core.prereq.Prerequisite)18 Spell (pcgen.core.spell.Spell)14 StringTokenizer (java.util.StringTokenizer)11 TreeSet (java.util.TreeSet)10 Domain (pcgen.core.Domain)8 CDOMObject (pcgen.cdom.base.CDOMObject)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 CDOMList (pcgen.cdom.base.CDOMList)6 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)6 ParseResult (pcgen.rules.persistence.token.ParseResult)6 HashSet (java.util.HashSet)5 MasterListInterface (pcgen.cdom.base.MasterListInterface)5 AssociationKey (pcgen.cdom.enumeration.AssociationKey)5 ClassSkillList (pcgen.cdom.list.ClassSkillList)5 DomainSpellList (pcgen.cdom.list.DomainSpellList)5 StringWriter (java.io.StringWriter)4 PCClass (pcgen.core.PCClass)4