Search in sources :

Example 6 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PCGVer2Parser method parseTempBonusLine.

/**
	 * ###############################################################
	 * Temporary Bonuses
	 * ###############################################################
	 * @param line
	 **/
private void parseTempBonusLine(final String line) {
    PCGTokenizer tokens;
    try {
        tokens = new PCGTokenizer(line);
    } catch (PCGParseException pcgpex) {
        final String message = "Illegal TempBonus line ignored: " + line + Constants.LINE_SEPARATOR + "Error: " + pcgpex.getMessage();
        warnings.add(message);
        return;
    }
    String cTag = null;
    String tName = null;
    boolean active = true;
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        if (IOConstants.TAG_TEMPBONUS.equals(tag)) {
            cTag = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSTARGET.equals(tag)) {
            tName = EntityEncoder.decode(element.getText());
        } else if (IOConstants.TAG_TEMPBONUSACTIVE.equals(tag)) {
            active = element.getText().endsWith(IOConstants.VALUE_Y);
        }
    }
    if ((cTag == null) || (tName == null)) {
        warnings.add("Illegal TempBonus line ignored: " + line);
        return;
    }
    //$NON-NLS-1$
    final StringTokenizer aTok = new StringTokenizer(cTag, "=", false);
    if (aTok.countTokens() < 2) {
        return;
    }
    final String cType = aTok.nextToken();
    final String cKey = aTok.nextToken();
    Equipment aEq = null;
    if (!tName.equals(IOConstants.TAG_PC)) {
        // bonus is applied to an equipment item
        // so create a new one and add to PC
        final Equipment eq = thePC.getEquipmentNamed(tName);
        if (eq == null) {
            return;
        }
        aEq = eq.clone();
        //aEq.setWeight("0");
        aEq.resetTempBonusList();
    }
    for (PCGElement element : tokens.getElements()) {
        final String tag = element.getName();
        final String bonus;
        if (IOConstants.TAG_TEMPBONUSBONUS.equals(tag)) {
            bonus = EntityEncoder.decode(element.getText());
        } else {
            continue;
        }
        if ((bonus == null) || (bonus.length() <= 0)) {
            continue;
        }
        BonusObj newB = null;
        Object creator = null;
        LoadContext context = Globals.getContext();
        // type of object to set as the creator
        if (cType.equals(IOConstants.TAG_FEAT)) {
            for (AbilityCategory aCat : SettingsHandler.getGame().getAllAbilityCategories()) {
                Ability a = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Ability.class, aCat, cKey);
                if (a != null) {
                    newB = Bonus.newBonus(context, bonus);
                    creator = a;
                    break;
                }
            }
        } else if (cType.equals(IOConstants.TAG_EQUIPMENT)) {
            Equipment aEquip = thePC.getEquipmentNamed(cKey);
            if (aEquip == null) {
                aEquip = context.getReferenceContext().silentlyGetConstructedCDOMObject(Equipment.class, cKey);
            }
            if (aEquip != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aEquip;
            }
        } else if (cType.equals(IOConstants.TAG_CLASS)) {
            final PCClass aClass = thePC.getClassKeyed(cKey);
            if (aClass == null) {
                continue;
            }
            int idx = bonus.indexOf('|');
            newB = Bonus.newBonus(context, bonus.substring(idx + 1));
            creator = aClass;
        } else if (cType.equals(IOConstants.TAG_TEMPLATE)) {
            PCTemplate aTemplate = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, cKey);
            if (aTemplate != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aTemplate;
            }
        } else if (cType.equals(IOConstants.TAG_SKILL)) {
            Skill aSkill = context.getReferenceContext().silentlyGetConstructedCDOMObject(Skill.class, cKey);
            if (aSkill != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSkill;
            }
        } else if (cType.equals(IOConstants.TAG_SPELL)) {
            final Spell aSpell = context.getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, cKey);
            if (aSpell != null) {
                newB = Bonus.newBonus(context, bonus);
                creator = aSpell;
            }
        } else if (cType.equals(IOConstants.TAG_NAME)) {
            newB = Bonus.newBonus(context, bonus);
        //newB.setCreatorObject(thePC);
        }
        if (newB == null) {
            return;
        }
        TempBonusInfo tempBonusInfo;
        // Check to see if the target was the PC or an Item
        if (tName.equals(IOConstants.TAG_PC)) {
            thePC.setApplied(newB, true);
            tempBonusInfo = thePC.addTempBonus(newB, creator, thePC);
        } else {
            thePC.setApplied(newB, true);
            aEq.addTempBonus(newB);
            tempBonusInfo = thePC.addTempBonus(newB, creator, aEq);
        }
        if (!active) {
            String bonusName = BonusDisplay.getBonusDisplayName(tempBonusInfo);
            thePC.setTempBonusFilter(bonusName);
        }
    }
    if (aEq != null) {
        aEq.setAppliedName(cKey);
        thePC.addTempBonusItemList(aEq);
    }
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) Ability(pcgen.core.Ability) SpecialAbility(pcgen.core.SpecialAbility) BonusObj(pcgen.core.bonus.BonusObj) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) TempBonusInfo(pcgen.core.BonusManager.TempBonusInfo) StringTokenizer(java.util.StringTokenizer) Skill(pcgen.core.Skill) Equipment(pcgen.core.Equipment) LoadContext(pcgen.rules.context.LoadContext) CDOMObject(pcgen.cdom.base.CDOMObject) AssociatedPrereqObject(pcgen.cdom.base.AssociatedPrereqObject) PObject(pcgen.core.PObject) PCTemplate(pcgen.core.PCTemplate) AbilityCategory(pcgen.core.AbilityCategory)

Example 7 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PCGVer2Creator method appendSpellLines.

/*
	 * ###############################################################
	 * Character Spells Information methods
	 * ###############################################################
	 */
/*
	 * #Character Spells Information
	 * CLASS:Wizard|CANCASTPERDAY:2,4(Totals the levels all up + includes attribute bonuses)
	 * SPELLNAME:Blah|SCHOOL:blah|SUBSCHOOL:blah|Etc
	 *
	 * completely changed due to new Spell API
	 */
private void appendSpellLines(StringBuilder buffer) {
    for (PCClass pcClass : charDisplay.getClassSet()) {
        Collection<? extends CharacterSpell> sp = charDisplay.getCharacterSpells(pcClass);
        List<CharacterSpell> classSpells = new ArrayList<>(sp);
        // Add in the spells granted by objects
        thePC.addBonusKnownSpellsToList(pcClass, classSpells);
        Collections.sort(classSpells);
        for (CharacterSpell cSpell : classSpells) {
            for (SpellInfo spellInfo : cSpell.getInfoList()) {
                CDOMObject owner = cSpell.getOwner();
                List<? extends CDOMList<Spell>> lists = charDisplay.getSpellLists(owner);
                if (SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC) < 0) {
                    Logging.errorPrint("Ignoring unqualified spell " + cSpell.getSpell() + " in list for class " + pcClass + ".");
                    continue;
                }
                if (spellInfo.getBook().equals(Globals.getDefaultSpellBook()) && thePC.getSpellSupport(pcClass).isAutoKnownSpell(cSpell.getSpell(), SpellLevel.getFirstLevelForKey(cSpell.getSpell(), lists, thePC), false, thePC) && thePC.getAutoSpells()) {
                    continue;
                }
                buffer.append(IOConstants.TAG_SPELLNAME).append(':');
                buffer.append(EntityEncoder.encode(cSpell.getSpell().getKeyName()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_TIMES).append(':');
                buffer.append(spellInfo.getTimes());
                buffer.append('|');
                buffer.append(IOConstants.TAG_CLASS).append(':');
                buffer.append(EntityEncoder.encode(pcClass.getKeyName()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_SPELL_BOOK).append(':');
                buffer.append(EntityEncoder.encode(spellInfo.getBook()));
                buffer.append('|');
                buffer.append(IOConstants.TAG_SPELLLEVEL).append(':');
                buffer.append(spellInfo.getActualLevel());
                if (spellInfo.getNumPages() > 0) {
                    buffer.append('|');
                    buffer.append(IOConstants.TAG_SPELLNUMPAGES).append(':');
                    buffer.append(spellInfo.getNumPages());
                }
                final List<Ability> metaFeats = spellInfo.getFeatList();
                if ((metaFeats != null) && (!metaFeats.isEmpty())) {
                    buffer.append('|');
                    buffer.append(IOConstants.TAG_FEATLIST).append(':');
                    buffer.append('[');
                    String del = Constants.EMPTY_STRING;
                    for (Ability feat : metaFeats) {
                        buffer.append(del);
                        buffer.append(IOConstants.TAG_FEAT).append(':');
                        buffer.append(EntityEncoder.encode(feat.getKeyName()));
                        //$NON-NLS-1$
                        del = "|";
                    }
                    buffer.append(']');
                }
                buffer.append('|');
                appendSourceInTaggedFormat(buffer, StringPClassUtil.getStringFor(owner.getClass()) + "|" + owner.getKeyName());
                buffer.append(IOConstants.LINE_SEP);
            }
        }
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) SpecialAbility(pcgen.core.SpecialAbility) CDOMObject(pcgen.cdom.base.CDOMObject) ArrayList(java.util.ArrayList) CharacterSpell(pcgen.core.character.CharacterSpell) PCClass(pcgen.core.PCClass) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) SpellInfo(pcgen.core.character.SpellInfo)

Example 8 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class PlayerCharacter method calculateKnownSpellsForClassLevel.

public void calculateKnownSpellsForClassLevel(PCClass pcc) {
    if (!pcc.containsListFor(ListKey.KNOWN_SPELLS) || importing || !autoKnownSpells) {
        return;
    }
    // If this class has at least one entry in the "Known spells" tag
    // And we are set up to automatically assign known spells...
    List<? extends CDOMList<Spell>> spellLists = getSpellLists(pcc);
    SpellSupportForPCClass spellSupport = getSpellSupport(pcc);
    // Recalculate the number of spells per day of each level
    // that this chracter can cast in this class.
    spellSupport.calcCastPerDayMapForLevel(this);
    // Get the maximum spell level that this character can cast.
    final int maxCastableLevel = spellSupport.getMaxCastLevel();
    for (CDOMList<Spell> list : spellLists) {
        for (int spellLevel : availSpellFacet.getScopes2(id, list)) {
            if (spellLevel <= maxCastableLevel) {
                for (Spell spell : availSpellFacet.getSet(id, list, spellLevel)) {
                    if (spellSupport.isAutoKnownSpell(spell, spellLevel, true, this)) {
                        CharacterSpell cs = getCharacterSpellForSpell(pcc, spell, pcc);
                        if (cs == null) {
                            // Create a new character spell for this level.
                            cs = new CharacterSpell(pcc, spell);
                            cs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
                            addCharacterSpell(pcc, cs);
                        } else {
                            if (cs.getSpellInfoFor(Globals.getDefaultSpellBook(), spellLevel) == null) {
                                cs.addInfo(spellLevel, 1, Globals.getDefaultSpellBook());
                            } else {
                            // already know this one
                            }
                        }
                    }
                }
            }
        }
    }
    for (Domain d : getDomainSet()) {
        if (pcc.getKeyName().equals(getDomainSource(d).getPcclass().getKeyName())) {
            DomainApplication.addSpellsToClassForLevels(this, d, pcc, 0, maxCastableLevel);
        }
    }
}
Also used : CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 9 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class DomainApplication method removeDomain.

/**
	 * Remove a domain from the character.
	 * @param pc The character
	 * @param domain The domain.
	 */
public static void removeDomain(PlayerCharacter pc, Domain domain) {
    ClassSource source = pc.getDomainSource(domain);
    PCClass aClass = pc.getClassKeyed(source.getPcclass().getKeyName());
    if (aClass != null) {
        int maxLevel;
        for (maxLevel = 0; maxLevel < 10; maxLevel++) {
            if (pc.getSpellSupport(aClass).getCastForLevel(maxLevel, pc) == 0) {
                break;
            }
        }
        if (maxLevel > 0) {
            removeSpellsFromClassForLevels(pc, domain, aClass);
        }
        if ((maxLevel > 1) && (aClass.getSafe(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY) == 0)) {
            DomainSpellList domainSpellList = domain.get(ObjectKey.DOMAIN_SPELLLIST);
            final List<Spell> aList = pc.getAllSpellsInLists(Collections.singletonList(domainSpellList));
            for (Spell gcs : aList) {
                if (SpellLevel.getFirstLvlForKey(gcs, domainSpellList, pc) < maxLevel) {
                    pc.removeDomainSpellCount(aClass);
                    break;
                }
            }
        }
    }
    if (!pc.isImporting()) {
        BonusActivation.deactivateBonuses(domain, pc);
    }
}
Also used : DomainSpellList(pcgen.cdom.list.DomainSpellList) PCClass(pcgen.core.PCClass) ClassSource(pcgen.cdom.helper.ClassSource) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 10 with Spell

use of pcgen.core.spell.Spell in project pcgen by PCGen.

the class EqModCost method replaceCostSpellXPCost.

private static String replaceCostSpellXPCost(String costFormula, final String listEntry) {
    String modChoice = "";
    while (costFormula.contains("%SPELLXPCOST")) {
        final int idx = costFormula.indexOf("%SPELLXPCOST");
        if (modChoice.isEmpty()) {
            final String spellName = EqModSpellInfo.getSpellInfoString(listEntry, "SPELLNAME");
            final Spell aSpell = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(Spell.class, spellName);
            if (aSpell != null) {
                modChoice = Integer.toString(aSpell.getSafe(IntegerKey.XP_COST));
            }
        }
        costFormula = costFormula.substring(0, idx) + modChoice + costFormula.substring(idx + 12);
    }
    return costFormula;
}
Also used : Spell(pcgen.core.spell.Spell)

Aggregations

Spell (pcgen.core.spell.Spell)87 CharacterSpell (pcgen.core.character.CharacterSpell)35 ArrayList (java.util.ArrayList)25 PCClass (pcgen.core.PCClass)24 AssociatedPrereqObject (pcgen.cdom.base.AssociatedPrereqObject)16 CDOMReference (pcgen.cdom.base.CDOMReference)15 Ability (pcgen.core.Ability)15 LoadContext (pcgen.rules.context.LoadContext)13 CDOMList (pcgen.cdom.base.CDOMList)12 CDOMObject (pcgen.cdom.base.CDOMObject)11 Test (org.junit.Test)10 KnownSpellIdentifier (pcgen.cdom.content.KnownSpellIdentifier)9 AvailableSpell (pcgen.cdom.helper.AvailableSpell)8 StringTokenizer (java.util.StringTokenizer)7 CNAbility (pcgen.cdom.content.CNAbility)7 ClassSpellList (pcgen.cdom.list.ClassSpellList)7 DomainSpellList (pcgen.cdom.list.DomainSpellList)7 Formula (pcgen.base.formula.Formula)6 Domain (pcgen.core.Domain)6 PObject (pcgen.core.PObject)6