Search in sources :

Example 6 with AssociatedPrereqObject

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

the class KnownSpellInputFacet method processList.

private void processList(CharID id, CDOMList<Spell> spelllist, CDOMReference<? extends CDOMList<?>> listref, CDOMObject cdo) {
    for (CDOMReference<Spell> objref : cdo.getListMods((CDOMReference<? extends CDOMList<Spell>>) listref)) {
        for (AssociatedPrereqObject apo : cdo.getListAssociations(listref, objref)) {
            Boolean known = apo.getAssociation(AssociationKey.KNOWN);
            if ((known == null) || !known.booleanValue()) {
                continue;
            }
            Collection<Spell> spells = objref.getContainedObjects();
            Integer lvl = apo.getAssociation(AssociationKey.SPELL_LEVEL);
            if (apo.hasPrerequisites()) {
                List<Prerequisite> prereqs = apo.getPrerequisiteList();
                for (Spell spell : spells) {
                    AvailableSpell as = new AvailableSpell(spelllist, spell, lvl);
                    as.addAllPrerequisites(prereqs);
                    conditionallyKnownSpellFacet.add(id, as, cdo);
                }
            } else {
                for (Spell spell : spells) {
                    knownSpellFacet.add(id, spelllist, lvl, spell, cdo);
                }
            }
        }
    }
}
Also used : AvailableSpell(pcgen.cdom.helper.AvailableSpell) AvailableSpell(pcgen.cdom.helper.AvailableSpell) Spell(pcgen.core.spell.Spell) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 7 with AssociatedPrereqObject

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

the class PCGVer2Parser method parseSpellLine.

/*
	 * ###############################################################
	 * Character Spells Information methods
	 * ###############################################################
	 */
private void parseSpellLine(final String line) {
    final PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal Spell line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    Spell aSpell = null;
    PCClass aPCClass = null;
    PObject source = null;
    String spellBook = null;
    int times = 1;
    int spellLevel = 0;
    int numPages = 0;
    final List<Ability> metaFeats = new ArrayList<>();
    int ppCost = -1;
    for (final PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_SPELLNAME.equals(tag)) {
            String spellName = EntityEncoder.decode(element.getText());
            spellName = SpellMigration.getNewSpellKey(spellName, pcgenVersion, SettingsHandler.getGame().getName());
            // either NULL (no spell) a Spell instance,
            aSpell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, spellName);
            if (aSpell == null) {
                final String message = "Could not find spell named: " + spellName;
                warnings.add(message);
                return;
            }
        } else if (IOConstants.TAG_TIMES.equals(tag)) {
            try {
                times = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // nothing we can do about it
            }
        } else if (IOConstants.TAG_CLASS.equals(tag)) {
            final String classKey = EntityEncoder.decode(element.getText());
            aPCClass = thePC.getClassKeyed(classKey);
            if (aPCClass == null) {
                final String message = "Invalid class specification: " + classKey;
                warnings.add(message);
                return;
            }
        } else if (IOConstants.TAG_SPELL_BOOK.equals(tag)) {
            spellBook = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_SPELLLEVEL.equals(tag)) {
            try {
                spellLevel = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // nothing we can do about it
            }
        } else if (IOConstants.TAG_SPELLPPCOST.equals(tag)) {
            try {
                ppCost = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // nothing we can do about it
            }
        } else if (IOConstants.TAG_SPELLNUMPAGES.equals(tag)) {
            try {
                numPages = Integer.parseInt(element.getText());
            } catch (NumberFormatException nfe) {
            // nothing we can do about it
            }
        } else if (IOConstants.TAG_SOURCE.equals(tag)) {
            String typeName = Constants.EMPTY_STRING;
            String objectKey = Constants.EMPTY_STRING;
            for (final PCGElement child : element.getChildren()) {
                final String childTag = child.getName();
                if (IOConstants.TAG_TYPE.equals(childTag)) {
                    typeName = child.getText().toUpperCase();
                } else if (IOConstants.TAG_NAME.equals(childTag)) {
                    objectKey = child.getText();
                }
            }
            if (IOConstants.TAG_DOMAIN.equals(typeName)) {
                Domain domain = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(DOMAIN_CLASS, objectKey);
                ClassSource cs = thePC.getDomainSource(domain);
                if (cs == null) {
                    final String message = "Could not find domain: " + objectKey;
                    warnings.add(message);
                    return;
                }
                source = domain;
            } else {
                // it's either the class, sub-class or a cast-as class
                // first see if it's the class
                ClassSpellList csl = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(ClassSpellList.class, objectKey);
                if (((aPCClass != null) && objectKey.equals(aPCClass.getKeyName())) || (aPCClass != null && thePC.getSpellLists(aPCClass).contains(csl))) {
                    source = aPCClass;
                } else {
                    // see if PC has the class
                    source = thePC.getClassKeyed(objectKey);
                }
            }
        } else if (IOConstants.TAG_FEATLIST.equals(tag)) {
            for (PCGElement child : element.getChildren()) {
                final String featKey = EntityEncoder.decode(child.getText());
                final Ability anAbility = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, AbilityCategory.FEAT, featKey);
                if (anAbility != null) {
                    metaFeats.add(anAbility);
                }
            }
        }
    }
    if ((aPCClass == null) || (spellBook == null)) {
        final String message = "Illegal Spell line ignored: " + line;
        warnings.add(message);
        return;
    }
    /*
		 * this can only happen if the source type was NOT DOMAIN!
		 */
    if (source == null) {
        source = aPCClass;
    }
    //		if (obj instanceof List)
    //		{
    //			// find the instance of Spell in this class
    //			// best suited to this spell
    //			for (final Spell spell : (ArrayList<Spell>) obj)
    //			{
    //				// valid spell has a non-negative spell level
    //				if ((spell != null)
    //					&& (SpellLevel.getFirstLevelForKey(spell,
    //						thePC.getSpellLists(source), thePC) >= 0))
    //				{
    //					aSpell = spell;
    //					break;
    //				}
    //			}
    //			if (aSpell == null)
    //			{
    //				Logging.errorPrint("Could not resolve spell " + obj.toString());
    //			}
    //		}
    //		if (aSpell == null)
    //		{
    //			final String message =
    //					"Could not find spell named: " + String.valueOf(obj);
    //			warnings.add(message);
    //
    //			return;
    //		}
    // just to make sure the spellbook is present
    thePC.addSpellBook(spellBook);
    final SpellBook book = thePC.getSpellBookByName(spellBook);
    thePC.calculateKnownSpellsForClassLevel(aPCClass);
    final Integer[] spellLevels = SpellLevel.levelForKey(aSpell, thePC.getSpellLists(source), thePC);
    boolean found = false;
    for (int sindex = 0; sindex < spellLevels.length; ++sindex) {
        final int level = spellLevels[sindex];
        final int metmagicLevels = totalAddedLevelsFromMetamagic(metaFeats);
        if (spellLevel > 0 && spellLevel != (level + metmagicLevels)) {
            // Skip spell in class lists that does not match level the character knows it.
            continue;
        }
        if (level < 0) {
            Collection<CDOMReference<Spell>> mods = source.getListMods(Spell.SPELLS);
            if (mods == null) {
                continue;
            }
            for (CDOMReference<Spell> ref : mods) {
                Collection<Spell> refSpells = ref.getContainedObjects();
                Collection<AssociatedPrereqObject> assocs = source.getListAssociations(Spell.SPELLS, ref);
                for (Spell sp : refSpells) {
                    if (aSpell.getKeyName().equals(sp.getKeyName())) {
                        for (AssociatedPrereqObject apo : assocs) {
                            String sb = apo.getAssociation(AssociationKey.SPELLBOOK);
                            if (spellBook.equals(sb)) {
                                found = true;
                                break;
                            }
                        }
                    }
                }
            }
            continue;
        }
        found = true;
        // do not load auto knownspells into default spellbook
        if (spellBook.equals(Globals.getDefaultSpellBook()) && thePC.getSpellSupport(aPCClass).isAutoKnownSpell(aSpell, level, false, thePC) && thePC.getAutoSpells()) {
            continue;
        }
        CharacterSpell aCharacterSpell = thePC.getCharacterSpellForSpell(aPCClass, aSpell, source);
        // so we'll need to add it to the list
        if (aCharacterSpell == null) {
            aCharacterSpell = new CharacterSpell(source, aSpell);
            aCharacterSpell.addInfo(level, times, spellBook);
            thePC.addCharacterSpell(aPCClass, aCharacterSpell);
        }
        SpellInfo aSpellInfo = null;
        if (source.getKeyName().equals(aPCClass.getKeyName()) || !spellBook.equals(Globals.getDefaultSpellBook())) {
            aSpellInfo = aCharacterSpell.getSpellInfoFor(spellBook, spellLevel);
            // metaFeats list have to do with this?
            if ((aSpellInfo == null) || !metaFeats.isEmpty()) {
                aSpellInfo = aCharacterSpell.addInfo(spellLevel, times, spellBook);
            }
        }
        if (aSpellInfo != null) {
            if (!metaFeats.isEmpty()) {
                aSpellInfo.addFeatsToList(metaFeats);
            }
            aSpellInfo.setActualPPCost(ppCost);
            aSpellInfo.setNumPages(numPages);
            book.setNumPagesUsed(book.getNumPagesUsed() + numPages);
            book.setNumSpells(book.getNumSpells() + 1);
        }
    }
    if (!found) {
        final String message = "Could not find spell " + aSpell.getDisplayName() + " in " + shortClassName(source) + " " + source.getDisplayName();
        warnings.add(message);
    }
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) ClassSource(pcgen.cdom.helper.ClassSource) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) ClassSpellList(pcgen.cdom.list.ClassSpellList) PCClass(pcgen.core.PCClass) SpellBook(pcgen.core.character.SpellBook) PObject(pcgen.core.PObject) CharacterSpell(pcgen.core.character.CharacterSpell) Domain(pcgen.core.Domain) CDOMReference(pcgen.cdom.base.CDOMReference) SpellInfo(pcgen.core.character.SpellInfo)

Example 8 with AssociatedPrereqObject

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

the class PCClass method inheritAttributesFrom.

/*
	 * REFACTOR Some derivative of this method will be in PCClass only as part
	 * of the factory creation of a PCClassLevel... or perhaps in PCClassLevel
	 * so it can steal some information from other PCClassLevels of that
	 * PCClass. Either way, this will be far from its current form in the final
	 * solution.
	 */
/*
	 * CONSIDER Why does this not inherit classSkillChoices?
	 */
public void inheritAttributesFrom(final PCClass otherClass) {
    Boolean hbss = otherClass.get(ObjectKey.HAS_BONUS_SPELL_STAT);
    if (hbss != null) {
        put(ObjectKey.HAS_BONUS_SPELL_STAT, hbss);
        CDOMSingleRef<PCStat> bss = otherClass.get(ObjectKey.BONUS_SPELL_STAT);
        if (bss != null) {
            put(ObjectKey.BONUS_SPELL_STAT, bss);
        }
    }
    Boolean usbs = otherClass.get(ObjectKey.USE_SPELL_SPELL_STAT);
    if (usbs != null) {
        put(ObjectKey.USE_SPELL_SPELL_STAT, usbs);
    }
    Boolean cwss = otherClass.get(ObjectKey.CASTER_WITHOUT_SPELL_STAT);
    if (cwss != null) {
        put(ObjectKey.CASTER_WITHOUT_SPELL_STAT, cwss);
    }
    CDOMSingleRef<PCStat> ss = otherClass.get(ObjectKey.SPELL_STAT);
    if (ss != null) {
        put(ObjectKey.SPELL_STAT, ss);
    }
    TransitionChoice<CDOMListObject<Spell>> slc = otherClass.get(ObjectKey.SPELLLIST_CHOICE);
    if (slc != null) {
        put(ObjectKey.SPELLLIST_CHOICE, slc);
    }
    List<QualifiedObject<CDOMReference<Equipment>>> e = otherClass.getListFor(ListKey.EQUIPMENT);
    if (e != null) {
        addAllToListFor(ListKey.EQUIPMENT, e);
    }
    List<WeaponProfProvider> wp = otherClass.getListFor(ListKey.WEAPONPROF);
    if (wp != null) {
        addAllToListFor(ListKey.WEAPONPROF, wp);
    }
    QualifiedObject<Boolean> otherWP = otherClass.get(ObjectKey.HAS_DEITY_WEAPONPROF);
    if (otherWP != null) {
        put(ObjectKey.HAS_DEITY_WEAPONPROF, otherWP);
    }
    List<ArmorProfProvider> ap = otherClass.getListFor(ListKey.AUTO_ARMORPROF);
    if (ap != null) {
        addAllToListFor(ListKey.AUTO_ARMORPROF, ap);
    }
    List<ShieldProfProvider> sp = otherClass.getListFor(ListKey.AUTO_SHIELDPROF);
    if (sp != null) {
        addAllToListFor(ListKey.AUTO_SHIELDPROF, sp);
    }
    List<BonusObj> bonusList = otherClass.getListFor(ListKey.BONUS);
    if (bonusList != null) {
        addAllToListFor(ListKey.BONUS, bonusList);
    }
    try {
        ownBonuses(this);
    } catch (CloneNotSupportedException ce) {
        // TODO Auto-generated catch block
        ce.printStackTrace();
    }
    for (VariableKey vk : otherClass.getVariableKeys()) {
        put(vk, otherClass.get(vk));
    }
    if (otherClass.containsListFor(ListKey.CSKILL)) {
        removeListFor(ListKey.CSKILL);
        addAllToListFor(ListKey.CSKILL, otherClass.getListFor(ListKey.CSKILL));
    }
    if (otherClass.containsListFor(ListKey.LOCALCCSKILL)) {
        removeListFor(ListKey.LOCALCCSKILL);
        addAllToListFor(ListKey.LOCALCCSKILL, otherClass.getListFor(ListKey.LOCALCCSKILL));
    }
    removeListFor(ListKey.KIT_CHOICE);
    addAllToListFor(ListKey.KIT_CHOICE, otherClass.getSafeListFor(ListKey.KIT_CHOICE));
    remove(ObjectKey.REGION_CHOICE);
    if (otherClass.containsKey(ObjectKey.REGION_CHOICE)) {
        put(ObjectKey.REGION_CHOICE, otherClass.get(ObjectKey.REGION_CHOICE));
    }
    removeListFor(ListKey.SAB);
    addAllToListFor(ListKey.SAB, otherClass.getSafeListFor(ListKey.SAB));
    /*
		 * TODO Does this need to have things from the Class Level objects?
		 * I don't think so based on deferred processing of levels...
		 */
    addAllToListFor(ListKey.DAMAGE_REDUCTION, otherClass.getListFor(ListKey.DAMAGE_REDUCTION));
    for (CDOMReference<Vision> ref : otherClass.getSafeListMods(Vision.VISIONLIST)) {
        for (AssociatedPrereqObject apo : otherClass.getListAssociations(Vision.VISIONLIST, ref)) {
            putToList(Vision.VISIONLIST, ref, apo);
        }
    }
    /*
		 * TODO This is a clone problem, but works for now - thpr 10/3/08
		 */
    if (otherClass instanceof SubClass) {
        levelMap.clear();
        copyLevelsFrom(otherClass);
    }
    addAllToListFor(ListKey.NATURAL_WEAPON, otherClass.getListFor(ListKey.NATURAL_WEAPON));
    put(ObjectKey.LEVEL_HITDIE, otherClass.get(ObjectKey.LEVEL_HITDIE));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) CDOMListObject(pcgen.cdom.base.CDOMListObject) WeaponProfProvider(pcgen.cdom.helper.WeaponProfProvider) ArmorProfProvider(pcgen.cdom.helper.ArmorProfProvider) VariableKey(pcgen.cdom.enumeration.VariableKey) ShieldProfProvider(pcgen.cdom.helper.ShieldProfProvider) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject)

Example 9 with AssociatedPrereqObject

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

the class CharacterFacadeImpl method buildAvailableDomainsList.

/**
	 * This method returns all available domains, without filtering.
	 */
private void buildAvailableDomainsList() {
    List<DomainFacadeImpl> availDomainList = new ArrayList<>();
    List<DomainFacadeImpl> selDomainList = new ArrayList<>();
    Deity pcDeity = charDisplay.getDeity();
    if (pcDeity != null) {
        for (CDOMReference<Domain> domainRef : pcDeity.getSafeListMods(Deity.DOMAINLIST)) {
            Collection<AssociatedPrereqObject> assoc = pcDeity.getListAssociations(Deity.DOMAINLIST, domainRef);
            for (AssociatedPrereqObject apo : assoc) {
                for (Domain d : domainRef.getContainedObjects()) {
                    if (!isDomainInList(availDomainList, d)) {
                        availDomainList.add(new DomainFacadeImpl(d, apo.getPrerequisiteList()));
                    }
                }
            }
        }
    }
    // Loop through the available prestige domains
    for (PCClass aClass : charDisplay.getClassList()) {
        /*
			 * Need to do for the class, for compatibility, since level 0 is
			 * loaded into the class itself
			 */
        processDomainList(aClass, availDomainList);
        processAddDomains(aClass, availDomainList);
        for (int lvl = 0; lvl <= charDisplay.getLevel(aClass); lvl++) {
            PCClassLevel cl = charDisplay.getActiveClassLevel(aClass, lvl);
            processAddDomains(cl, availDomainList);
            processDomainList(cl, availDomainList);
        }
    }
    // Loop through the character's selected domains
    for (Domain d : charDisplay.getDomainSet()) {
        DomainFacadeImpl domainFI = new DomainFacadeImpl(d);
        boolean found = false;
        for (DomainFacadeImpl row : availDomainList) {
            if (d.equals(row.getRawObject())) {
                domainFI = row;
                found = true;
                break;
            }
        }
        if (!found) {
            availDomainList.add(domainFI);
        }
        if (!isDomainInList(selDomainList, d)) {
            selDomainList.add(domainFI);
        }
    }
    availDomains.updateContents(availDomainList);
    domains.updateContents(selDomainList);
    maxDomains.set(theCharacter.getMaxCharacterDomains());
    remainingDomains.set(theCharacter.getMaxCharacterDomains() - charDisplay.getDomainCount());
    updateDomainTodo();
}
Also used : Deity(pcgen.core.Deity) ArrayList(java.util.ArrayList) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PCClassLevel(pcgen.cdom.inst.PCClassLevel)

Example 10 with AssociatedPrereqObject

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

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