Search in sources :

Example 1 with SpellSchool

use of pcgen.cdom.identifier.SpellSchool in project pcgen by PCGen.

the class PlayerCharacter method getConcentration.

public int getConcentration(final Spell sp, final CharacterSpell aSpell, PCClass aClass, int spellLevel, int metaConcentration, CDOMObject ow) {
    String bonDomain = "";
    if (ow instanceof Domain) {
        bonDomain = "DOMAIN." + ow.getKeyName();
        ClassSource source = getDomainSource((Domain) ow);
        if (source != null) {
            aClass = getClassKeyed(source.getPcclass().getKeyName());
        }
    }
    boolean useStatFromSpell = false;
    String bonClass = "";
    String spellType = "";
    String classKey = "";
    if ((aClass != null) || (ow instanceof PCClass)) {
        if ((aClass == null) || (ow instanceof PCClass)) {
            aClass = (PCClass) ow;
        }
        bonClass = "CLASS." + aClass.getKeyName();
        classKey = "CLASS:" + aClass.getKeyName();
        spellType = aClass.getSpellType();
        useStatFromSpell = aClass.getSafe(ObjectKey.USE_SPELL_SPELL_STAT);
    }
    if (!(ow instanceof PCClass) && !(ow instanceof Domain)) {
        // get BASESPELLSTAT from spell itself
        useStatFromSpell = true;
    }
    // set the spell Level used in aPC.getVariableValue()
    // Explicitly should *not* set the dirty flag to true.
    spellLevelTemp = spellLevel;
    // must be done after spellLevel is set above
    int concentration = getVariableValue(aSpell, SettingsHandler.getGame().getSpellBaseConcentration(), classKey).intValue() + metaConcentration;
    concentration += (int) getTotalBonusTo("CONCENTRATION", "ALLSPELLS");
    if (useStatFromSpell) {
        // get the BASESPELLSTAT from the spell itself
        CDOMSingleRef<PCStat> stat = sp.get(ObjectKey.SPELL_STAT);
        if (stat != null) {
            concentration += this.getStatModFor(stat.get());
        }
    }
    if (!sp.getKeyName().isEmpty()) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", "SPELL." + sp.getKeyName());
    }
    // DOMAIN.name
    if (!bonDomain.isEmpty()) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", bonDomain);
    }
    // CLASS.name
    if (!bonClass.isEmpty()) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", bonClass);
    }
    concentration += (int) getTotalBonusTo("CONCENTRATION", "TYPE." + spellType);
    if (spellType.equals("ALL")) {
        for (Type aType : sp.getTrueTypeList(false)) {
            concentration += (int) getTotalBonusTo("CONCENTRATION", "TYPE." + aType);
        }
    }
    for (SpellSchool aType : sp.getSafeListFor(ListKey.SPELL_SCHOOL)) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", "SCHOOL." + aType.toString());
    }
    for (String aType : sp.getSafeListFor(ListKey.SPELL_SUBSCHOOL)) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", "SUBSCHOOL." + aType);
    }
    for (String aType : sp.getSafeListFor(ListKey.SPELL_DESCRIPTOR)) {
        concentration += (int) getTotalBonusTo("CONCENTRATION", "DESCRIPTOR." + aType);
    }
    // Explicitly should *not* set the dirty flag to true.
    spellLevelTemp = 0;
    return concentration;
}
Also used : SpellSchool(pcgen.cdom.identifier.SpellSchool) MessageType(pcgen.core.utils.MessageType) AttackType(pcgen.util.enumeration.AttackType) Type(pcgen.cdom.enumeration.Type) ClassSource(pcgen.cdom.helper.ClassSource)

Example 2 with SpellSchool

use of pcgen.cdom.identifier.SpellSchool in project pcgen by PCGen.

the class SchoolToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, Spell spell, String value) {
    StringTokenizer aTok = new StringTokenizer(value, Constants.PIPE);
    boolean first = true;
    while (aTok.hasMoreTokens()) {
        String tokString = aTok.nextToken();
        if (Constants.LST_DOT_CLEAR.equals(tokString)) {
            if (!first) {
                return new ParseResult.Fail("  Non-sensical " + getTokenName() + ": .CLEAR was not the first list item: " + value, context);
            }
            context.getObjectContext().removeList(spell, ListKey.SPELL_SCHOOL);
        } else if (Constants.LST_ALL.equals(tokString)) {
            return new ParseResult.Fail(getTokenName() + "used reserved word ALL: " + value, context);
        } else if (Constants.LST_ANY.equals(tokString)) {
            return new ParseResult.Fail(getTokenName() + "used reserved word ANY: " + value, context);
        } else {
            SpellSchool ss = context.getReferenceContext().constructNowIfNecessary(SpellSchool.class, tokString);
            context.getObjectContext().addToList(spell, ListKey.SPELL_SCHOOL, ss);
        }
        first = false;
    }
    return ParseResult.SUCCESS;
}
Also used : SpellSchool(pcgen.cdom.identifier.SpellSchool) StringTokenizer(java.util.StringTokenizer) ParseResult(pcgen.rules.persistence.token.ParseResult)

Example 3 with SpellSchool

use of pcgen.cdom.identifier.SpellSchool in project pcgen by PCGen.

the class SpellsTokenTest method testValidSchool.

/**
	 * Check that a School qualifier is parsed correctly.
	 * @throws PersistenceLayerException If an error occurs.
	 */
public void testValidSchool() throws PersistenceLayerException {
    TokenRegistration.register(new SchoolToken());
    SpellSchool schoolA = primaryContext.getReferenceContext().constructNowIfNecessary(SpellSchool.class, "Abjuration");
    SpellSchool schoolB = secondaryContext.getReferenceContext().constructNowIfNecessary(SpellSchool.class, "Abjuration");
    CDOMObject a = (CDOMObject) construct(primaryContext, "Endure Elements");
    a.addToListFor(ListKey.SPELL_SCHOOL, schoolA);
    CDOMObject c = (CDOMObject) construct(secondaryContext, "Remove Curse");
    c.addToListFor(ListKey.SPELL_SCHOOL, schoolB);
    runRoundRobin("SPELLS|SCHOOL=Abjuration");
}
Also used : SpellSchool(pcgen.cdom.identifier.SpellSchool) CDOMObject(pcgen.cdom.base.CDOMObject) SchoolToken(plugin.primitive.spell.SchoolToken) SubSchoolToken(plugin.primitive.spell.SubSchoolToken)

Example 4 with SpellSchool

use of pcgen.cdom.identifier.SpellSchool in project pcgen by PCGen.

the class PlayerCharacter method aggregateSpellList.

public List<Spell> aggregateSpellList(final String school, final String subschool, final String descriptor, final int minLevel, final int maxLevel) {
    final List<Spell> retList = new ArrayList<>();
    for (PObject pObj : getSpellClassList()) {
        for (int a = minLevel; a <= maxLevel; a++) {
            for (CharacterSpell cs : getCharacterSpells(pObj, a)) {
                final Spell aSpell = cs.getSpell();
                SpellSchool ss = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(SpellSchool.class, school);
                if ((school.isEmpty()) || (ss != null) && aSpell.containsInList(ListKey.SPELL_SCHOOL, ss) || (subschool.isEmpty()) || aSpell.containsInList(ListKey.SPELL_SUBSCHOOL, subschool) || (descriptor.isEmpty()) || aSpell.containsInList(ListKey.SPELL_DESCRIPTOR, descriptor)) {
                    retList.add(aSpell);
                }
            }
        }
    }
    return retList;
}
Also used : SpellSchool(pcgen.cdom.identifier.SpellSchool) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 5 with SpellSchool

use of pcgen.cdom.identifier.SpellSchool in project pcgen by PCGen.

the class PlayerCharacter method getTotalCasterLevelWithSpellBonus.

public int getTotalCasterLevelWithSpellBonus(CharacterSpell acs, final Spell aSpell, final String spellType, final String classOrRace, final int casterLev) {
    if (aSpell != null && acs.getFixedCasterLevel() != null) {
        return getVariableValue(acs.getFixedCasterLevel(), Constants.EMPTY_STRING).intValue();
    }
    int tBonus = casterLev;
    boolean replaceCasterLevel = false;
    String tType;
    String tStr;
    // final List<TypedBonus> bonuses = new ArrayList<TypedBonus>();
    final List<CasterLevelSpellBonus> bonuses = new ArrayList<>();
    if (classOrRace != null) {
        // bonuses.addAll(getBonusesTo("CASTERLEVEL", classOrRace));
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", classOrRace);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", classOrRace);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        // BONUS:CASTERLEVEL|CLASS.Sorcerer|1
        if (!classOrRace.startsWith("RACE.")) {
            tStr = "CLASS." + classOrRace;
            // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
            tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
            if (tBonus > 0) {
                tType = getSpellBonusType("CASTERLEVEL", tStr);
                bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
            }
        }
    }
    if (aSpell == null) {
        return tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
    }
    if (!spellType.equals(Constants.NONE)) {
        tStr = "TYPE." + spellType;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    tStr = "SPELL." + aSpell.getKeyName();
    // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
    tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
    if (tBonus > 0) {
        tType = getSpellBonusType("CASTERLEVEL", tStr);
        bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
    }
    tStr += ".RESET";
    // final List<TypedBonus> reset = getBonusesTo("CASTERLEVEL", tStr);
    // if ( reset.size() > 0 )
    // {
    // bonuses.addAll(reset);
    // replaceCasterLevel = true;
    // }
    tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
    if (tBonus > 0) {
        replaceCasterLevel = true;
        tType = getSpellBonusType("CASTERLEVEL", tStr);
        bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
    }
    /*
		 * This wraps in TreeSet because it looks to me like this is ordered
		 * (given .RESET)
		 */
    for (SpellSchool school : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SCHOOL))) {
        tStr = "SCHOOL." + school.toString();
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (// Allow negative bonus to casterlevel
        tBonus != 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    for (String subschool : new TreeSet<>(aSpell.getSafeListFor(ListKey.SPELL_SUBSCHOOL))) {
        tStr = "SUBSCHOOL." + subschool;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    //Not wrapped because it wasn't in 5.14
    for (String desc : aSpell.getSafeListFor(ListKey.SPELL_DESCRIPTOR)) {
        tStr = "DESCRIPTOR." + desc;
        // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
        tStr += ".RESET";
        // final List<TypedBonus> reset1 = getBonusesTo("CASTERLEVEL",
        // tStr);
        // if ( reset.size() > 0 )
        // {
        // bonuses.addAll(reset1);
        // replaceCasterLevel = true;
        // }
        tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
        if (tBonus > 0) {
            replaceCasterLevel = true;
            tType = getSpellBonusType("CASTERLEVEL", tStr);
            bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
        }
    }
    final HashMapToList<CDOMList<Spell>, Integer> domainMap = getSpellLevelInfo(aSpell);
    if (domainMap != null) {
        for (CDOMList<Spell> spellList : domainMap.getKeySet()) {
            if (spellList instanceof DomainSpellList) {
                tStr = "DOMAIN." + spellList.getKeyName();
                // bonuses.addAll( getBonusesTo("CASTERLEVEL", tStr) );
                tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
                if (tBonus > 0) {
                    tType = getSpellBonusType("CASTERLEVEL", tStr);
                    bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
                }
                tStr += ".RESET";
                // final List<TypedBonus> reset1 =
                // getBonusesTo("CASTERLEVEL", tStr);
                // if ( reset.size() > 0 )
                // {
                // bonuses.addAll(reset1);
                // replaceCasterLevel = true;
                // }
                tBonus = (int) getTotalBonusTo("CASTERLEVEL", tStr);
                if (tBonus > 0) {
                    replaceCasterLevel = true;
                    tType = getSpellBonusType("CASTERLEVEL", tStr);
                    bonuses.add(new CasterLevelSpellBonus(tBonus, tType));
                }
            }
        }
    }
    int result = tallyCasterlevelBonuses(casterLev, replaceCasterLevel, bonuses);
    return (result);
}
Also used : ArrayList(java.util.ArrayList) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) DomainSpellList(pcgen.cdom.list.DomainSpellList) SpellSchool(pcgen.cdom.identifier.SpellSchool) TreeSet(java.util.TreeSet) CDOMList(pcgen.cdom.base.CDOMList)

Aggregations

SpellSchool (pcgen.cdom.identifier.SpellSchool)7 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2 Type (pcgen.cdom.enumeration.Type)2 ClassSource (pcgen.cdom.helper.ClassSource)2 CharacterSpell (pcgen.core.character.CharacterSpell)2 Spell (pcgen.core.spell.Spell)2 MessageType (pcgen.core.utils.MessageType)2 AttackType (pcgen.util.enumeration.AttackType)2 TreeSet (java.util.TreeSet)1 CDOMList (pcgen.cdom.base.CDOMList)1 CDOMObject (pcgen.cdom.base.CDOMObject)1 DomainSpellList (pcgen.cdom.list.DomainSpellList)1 ParseResult (pcgen.rules.persistence.token.ParseResult)1 SchoolToken (plugin.primitive.spell.SchoolToken)1 SubSchoolToken (plugin.primitive.spell.SubSchoolToken)1