Search in sources :

Example 36 with PCClass

use of pcgen.core.PCClass 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 37 with PCClass

use of pcgen.core.PCClass in project pcgen by PCGen.

the class TemplateTargetSaveRestoreTest method testTemplateFavoredClass.

@Test
public void testTemplateFavoredClass() {
    PCClass monclass = create(PCClass.class, "MonClass");
    new TypeLst().parseToken(context, monclass, "Monster");
    PCTemplate monster = create(PCTemplate.class, "Monster");
    create(PCClass.class, "MyClass");
    new FavoredclassToken().parseToken(context, monster, "%LIST");
    new ClassToken().parseToken(context, monster, "MonClass|MyClass");
    finishLoad();
    pc.addTemplate(monster);
    runRoundRobin(getPreEqualityCleanup());
    assertTrue(pc.getDisplay().getFavoredClasses().contains(monclass));
    assertTrue(reloadedPC.getDisplay().getFavoredClasses().contains(monclass));
    reloadedPC.removeTemplate(monster);
    reloadedPC.setDirty(true);
    assertFalse(reloadedPC.getDisplay().getFavoredClasses().contains(monclass));
}
Also used : FavoredclassToken(plugin.lsttokens.template.FavoredclassToken) ClassToken(plugin.lsttokens.choose.ClassToken) PCClass(pcgen.core.PCClass) TypeLst(plugin.lsttokens.TypeLst) PCTemplate(pcgen.core.PCTemplate) AbstractGlobalTargetedSaveRestoreTest(pcgen.io.testsupport.AbstractGlobalTargetedSaveRestoreTest) Test(org.junit.Test)

Example 38 with PCClass

use of pcgen.core.PCClass in project pcgen by PCGen.

the class AbstractGlobalTargetedSaveRestoreTest method testGlobalCSkillList.

@Test
public void testGlobalCSkillList() {
    PCClass monclass = create(PCClass.class, "MonClass");
    new HdToken().parseToken(context, monclass, "8");
    new TypeLst().parseToken(context, monclass, "Monster");
    Skill granted = create(Skill.class, "Granted");
    new ExclusiveToken().parseToken(context, granted, "Yes");
    T target = create(getObjectClass(), "Target");
    Skill skill = create(Skill.class, "MySkill");
    new ExclusiveToken().parseToken(context, skill, "Yes");
    new CskillLst().parseToken(context, target, "LIST");
    new SkillToken().parseToken(context, target, "Granted|MySkill");
    additionalChooseSet(target);
    Object o = prepare(target);
    finishLoad();
    pc.incrementClassLevel(1, monclass);
    pc.setHP(pc.getActiveClassLevel(monclass, 0), 3);
    assertEquals(SkillCost.EXCLUSIVE, pc.getSkillCostForClass(granted, monclass));
    applyObject(target);
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, monclass));
    final Runnable cleanup = getPreEqualityCleanup();
    Runnable fullcleanup = new Runnable() {

        public void run() {
            if (cleanup != null) {
                cleanup.run();
            }
            //TODO need this to create the spell support :/
            PCClass cl = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, "MonClass");
            reloadedPC.getSpellSupport(cl);
        }
    };
    runRoundRobin(fullcleanup);
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, monclass));
    assertEquals(SkillCost.CLASS, reloadedPC.getSkillCostForClass(granted, monclass));
    remove(o);
    reloadedPC.setDirty(true);
    if (isSymmetric()) {
        assertEquals(SkillCost.EXCLUSIVE, reloadedPC.getSkillCostForClass(granted, monclass));
    }
}
Also used : Skill(pcgen.core.Skill) CskillLst(plugin.lsttokens.CskillLst) HdToken(plugin.lsttokens.pcclass.HdToken) CDOMObject(pcgen.cdom.base.CDOMObject) PCClass(pcgen.core.PCClass) TypeLst(plugin.lsttokens.TypeLst) ExclusiveToken(plugin.lsttokens.skill.ExclusiveToken) SkillToken(plugin.lsttokens.choose.SkillToken) Test(org.junit.Test)

Example 39 with PCClass

use of pcgen.core.PCClass in project pcgen by PCGen.

the class DomainTargetSaveRestoreTest method testDomainCSkill.

@Test
public void testDomainCSkill() {
    Skill granted = create(Skill.class, "Granted");
    new ExclusiveToken().parseToken(context, granted, "Yes");
    Domain target = create(getObjectClass(), "Target");
    create(Skill.class, "MySkill");
    new CskillToken().parseToken(context, target, "LIST");
    new SkillToken().parseToken(context, target, "Granted|MySkill");
    Object o = prepare(target);
    finishLoad();
    applyObject(target);
    PCClass myclass = pc.getClassKeyed("MyClass");
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, myclass));
    runRoundRobin(getPreEqualityCleanup());
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(granted, myclass));
    myclass = reloadedPC.getClassKeyed("MyClass");
    assertEquals(SkillCost.CLASS, reloadedPC.getSkillCostForClass(granted, myclass));
    remove(o);
    reloadedPC.setDirty(true);
    assertEquals(SkillCost.EXCLUSIVE, reloadedPC.getSkillCostForClass(granted, myclass));
}
Also used : Skill(pcgen.core.Skill) CskillToken(plugin.lsttokens.domain.CskillToken) ExclusiveToken(plugin.lsttokens.skill.ExclusiveToken) Domain(pcgen.core.Domain) PCClass(pcgen.core.PCClass) SkillToken(plugin.lsttokens.choose.SkillToken) AbstractGlobalTargetedSaveRestoreTest(pcgen.io.testsupport.AbstractGlobalTargetedSaveRestoreTest) Test(org.junit.Test)

Example 40 with PCClass

use of pcgen.core.PCClass in project pcgen by PCGen.

the class RaceTargetSaveRestoreTest method testRaceMonCSkill.

@Test
public void testRaceMonCSkill() {
    PCClass monclass = create(PCClass.class, "MonClass");
    new TypeLst().parseToken(context, monclass, "Monster");
    new HdToken().parseToken(context, monclass, "8");
    new IsmonsterToken().parseToken(context, monclass, "YES");
    Skill monskill = create(Skill.class, "MonSkill");
    new ExclusiveToken().parseToken(context, monskill, "Yes");
    Race monster = create(Race.class, "Monster");
    Race other = create(Race.class, "Other");
    Skill skill = create(Skill.class, "MySkill");
    new ExclusiveToken().parseToken(context, skill, "Yes");
    new MoncskillToken().parseToken(context, monster, "LIST");
    new SkillToken().parseToken(context, monster, "MonSkill|MySkill");
    finishLoad();
    pc.setRace(monster);
    pc.incrementClassLevel(1, monclass);
    pc.setHP(pc.getActiveClassLevel(monclass, 0), 3);
    final Runnable cleanup = getPreEqualityCleanup();
    Runnable fullcleanup = new Runnable() {

        public void run() {
            if (cleanup != null) {
                cleanup.run();
            }
            //TODO need this to create the spell support :/
            PCClass cl = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCClass.class, "MonClass");
            reloadedPC.getSpellSupport(cl);
        }
    };
    runRoundRobin(fullcleanup);
    assertEquals(SkillCost.CLASS, pc.getSkillCostForClass(monskill, monclass));
    assertEquals(SkillCost.CLASS, reloadedPC.getSkillCostForClass(monskill, monclass));
    reloadedPC.setRace(other);
    reloadedPC.setDirty(true);
    assertEquals(SkillCost.EXCLUSIVE, reloadedPC.getSkillCostForClass(monskill, monclass));
}
Also used : MoncskillToken(plugin.lsttokens.race.MoncskillToken) Skill(pcgen.core.Skill) HdToken(plugin.lsttokens.pcclass.HdToken) IsmonsterToken(plugin.lsttokens.pcclass.IsmonsterToken) Race(pcgen.core.Race) PCClass(pcgen.core.PCClass) TypeLst(plugin.lsttokens.TypeLst) ExclusiveToken(plugin.lsttokens.skill.ExclusiveToken) SkillToken(plugin.lsttokens.choose.SkillToken) Test(org.junit.Test) AbstractGlobalTargetedSaveRestoreTest(pcgen.io.testsupport.AbstractGlobalTargetedSaveRestoreTest)

Aggregations

PCClass (pcgen.core.PCClass)359 Test (org.junit.Test)96 PlayerCharacter (pcgen.core.PlayerCharacter)61 Skill (pcgen.core.Skill)55 ArrayList (java.util.ArrayList)35 Domain (pcgen.core.Domain)30 LoadContext (pcgen.rules.context.LoadContext)28 PCClassLevel (pcgen.cdom.inst.PCClassLevel)26 CDOMObject (pcgen.cdom.base.CDOMObject)23 CharacterSpell (pcgen.core.character.CharacterSpell)20 Spell (pcgen.core.spell.Spell)20 StringTokenizer (java.util.StringTokenizer)19 CharID (pcgen.cdom.enumeration.CharID)19 ClassSource (pcgen.cdom.helper.ClassSource)19 PreClassTester (plugin.pretokens.test.PreClassTester)16 SkillCost (pcgen.cdom.enumeration.SkillCost)15 ParseResult (pcgen.rules.persistence.token.ParseResult)15 Ability (pcgen.core.Ability)14 Race (pcgen.core.Race)14 BonusObj (pcgen.core.bonus.BonusObj)14