Search in sources :

Example 46 with Spell

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

the class PlayerCharacterTest method testMaxValue.

/**
	 * Test the processing of the MAX function with respect to character stats.
	 */
public void testMaxValue() {
    readyToRun();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(pc, str, 8);
    setPCStat(pc, dex, 14);
    pc.setUseTempMods(true);
    assertEquals("STR", -1.0, pc.getVariableValue("STR", ""), 0.1);
    assertEquals("DEX", 2.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)", 2.0, pc.getVariableValue("max(STR,DEX)", ""), 0.1);
    StatToken statTok = new StatToken();
    assertEquals("Total stat.", "14", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "14", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Equip stat.", "14", statTok.getToken("STAT.1.NOTEMP", pc, null));
    assertEquals("No equip/temp stat.", "14", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("Base stat.", "14", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    final BonusObj raceBonus = Bonus.newBonus(context, "STAT|DEX|-2");
    giantClass.addToListFor(ListKey.BONUS, raceBonus);
    pc.setRace(giantRace);
    pc.incrementClassLevel(4, giantClass, true);
    assertEquals("Total stat.", "12", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "12", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Base stat.", "12", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("DEX", 1.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)", 1.0, pc.getVariableValue("max(STR,DEX)", ""), 0.1);
    Spell spell2 = new Spell();
    spell2.setName("Concrete Boots");
    final BonusObj aBonus = Bonus.newBonus(context, "STAT|DEX|-2");
    if (aBonus != null) {
        spell2.addToListFor(ListKey.BONUS, aBonus);
    }
    BonusObj penalty = spell2.getRawBonusList(pc).get(0);
    pc.addTempBonus(penalty, spell2, pc);
    pc.calcActiveBonuses();
    assertEquals("Total stat.", "10", statTok.getToken("STAT.1", pc, null));
    assertEquals("Temp stat.", "10", statTok.getToken("STAT.1.NOEQUIP", pc, null));
    assertEquals("Base stat.", "12", statTok.getToken("STAT.1.NOEQUIP.NOTEMP", pc, null));
    assertEquals("DEX", 0.0, pc.getVariableValue("DEX", ""), 0.1);
    assertEquals("max(STR,DEX)-STR", 1.0, pc.getVariableValue("max(STR,DEX)-STR", ""), 0.1);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell) StatToken(pcgen.io.exporttoken.StatToken)

Example 47 with Spell

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

the class PlayerCharacterTest method testAddSpells.

/**
	 * Tests adding a spell.
	 */
public void testAddSpells() {
    readyToRun();
    final PlayerCharacter character = new PlayerCharacter();
    character.setRace(human);
    character.incrementClassLevel(1, pcClass, true);
    final List<Ability> none = Collections.emptyList();
    String response = character.addSpell(null, none, pcClass.getKeyName(), null, 1, 1);
    assertEquals("Add spell should be rejected due to no spell", "Invalid parameter to add spell", response);
    Spell spell = new Spell();
    spell.setName("test spell 1");
    CharacterSpell charSpell = new CharacterSpell(pcClass, spell);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), null, 1, 1);
    assertEquals("Add spell should be rejected due to no book", "Invalid spell list/book name.", response);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), "", 1, 1);
    assertEquals("Add spell should be rejected due to no book", "Invalid spell list/book name.", response);
    // Add a non existant spell to a non existent spellbook
    String spellBookName = "Test book";
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to book not existing", "Could not find spell list/book Test book", response);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no levels.", "You can only prepare 0 spells for level 1 \nand there are no higher-level slots available.", response);
    response = character.addSpell(charSpell, none, "noclass", spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no matching class", "No class keyed noclass", response);
    SpellBook book = character.getSpellBookByName(spellBookName);
    book.setType(SpellBook.TYPE_PREPARED_LIST);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to no levels.", "You can only prepare 0 spells for level 1 \nand there are no higher-level slots available.", response);
    book.setType(SpellBook.TYPE_SPELL_BOOK);
    book.setPageFormula(FormulaFactory.getFormulaFor("SPELLLEVEL"));
    book.setNumPages(3);
    character.addSpellBook(spellBookName);
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    // Add a second time to cover multiples
    response = character.addSpell(charSpell, none, pcClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    response = character.addSpell(charSpell, none, giantClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should not be rejected.", "", response);
    response = character.addSpell(charSpell, none, giantClass.getKeyName(), spellBookName, 1, 1);
    assertEquals("Add spell should be rejected due to the book being full.", "There are not enough pages left to add this spell to the spell book.", response);
    PCClass c = character.getClassKeyed(pcClass.getKeyName());
    List<CharacterSpell> aList = character.getCharacterSpells(c, null, spellBookName, 1);
    CharacterSpell addedSpell = aList.get(0);
    response = character.delSpell(addedSpell.getSpellInfoFor(spellBookName, 1, none), pcClass, spellBookName);
    assertEquals("Delete spell should not be rejected.", "", response);
    aList = character.getCharacterSpells(giantClass, null, spellBookName, 1);
    addedSpell = aList.get(0);
    response = character.delSpell(addedSpell.getSpellInfoFor(spellBookName, 1), giantClass, spellBookName);
    assertEquals("Delete spell should not be rejected.", "", response);
}
Also used : SpellBook(pcgen.core.character.SpellBook) CharacterSpell(pcgen.core.character.CharacterSpell) Spell(pcgen.core.spell.Spell) CharacterSpell(pcgen.core.character.CharacterSpell)

Example 48 with Spell

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

the class TempBonusTest method testPCTemporaryBonus.

public void testPCTemporaryBonus() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    BonusObj bonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
    Spell spell = context.getReferenceContext().constructNowIfNecessary(Spell.class, "PCTempBonusItem");
    spell.addToListFor(ListKey.BONUS_PC, bonus);
    assertFalse(TempBonusHelper.hasAnyPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasPCTempBonus(spell));
    assertFalse(TempBonusHelper.hasNonPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasCharacterTempBonus(spell));
    assertFalse(TempBonusHelper.hasEquipmentTempBonus(spell));
    try {
        assertTrue(TempBonusHelper.getEquipmentApplyString(spell).isEmpty());
    } catch (NullPointerException e) {
    //This is appropriate too
    }
}
Also used : LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell)

Example 49 with Spell

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

the class TempBonusTest method testEquipmentTemporaryBonus.

public void testEquipmentTemporaryBonus() throws PersistenceLayerException {
    PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    BonusObj bonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
    EquipBonus tb = new EquipBonus(bonus, "MARTIAL;SIMPLE;EXOTIC");
    Spell spell = context.getReferenceContext().constructNowIfNecessary(Spell.class, "PCTempBonusItem");
    spell.addToListFor(ListKey.BONUS_EQUIP, tb);
    assertFalse(TempBonusHelper.hasAnyPCTempBonus(spell));
    assertFalse(TempBonusHelper.hasPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasNonPCTempBonus(spell));
    assertFalse(TempBonusHelper.hasCharacterTempBonus(spell));
    assertTrue(TempBonusHelper.hasEquipmentTempBonus(spell));
    Set<String> eaStringSet = TempBonusHelper.getEquipmentApplyString(spell);
    assertFalse(eaStringSet.isEmpty());
    assertEquals(1, eaStringSet.size());
    assertEquals("MARTIAL;SIMPLE;EXOTIC", eaStringSet.iterator().next());
    Equipment dagger = context.getReferenceContext().constructNowIfNecessary(Equipment.class, "Dagger");
    dagger.addToListFor(ListKey.TYPE, Type.WEAPON);
    dagger.addToListFor(ListKey.TYPE, Type.getConstant("Martial"));
    character.addEquipment(dagger);
    List<InfoFacade> eList = TempBonusHelper.getListOfApplicableEquipment(spell, character);
    assertEquals(1, eList.size());
    assertEquals("Dagger", eList.iterator().next().getKeyName());
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) InfoFacade(pcgen.facade.core.InfoFacade) LoadContext(pcgen.rules.context.LoadContext) Spell(pcgen.core.spell.Spell)

Example 50 with Spell

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

the class TempBonusTest method testANYPCTemporaryBonus.

public void testANYPCTemporaryBonus() throws PersistenceLayerException {
    LoadContext context = Globals.getContext();
    BonusObj bonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
    Spell spell = context.getReferenceContext().constructNowIfNecessary(Spell.class, "PCTempBonusItem");
    spell.addToListFor(ListKey.BONUS_ANYPC, bonus);
    assertTrue(TempBonusHelper.hasAnyPCTempBonus(spell));
    assertFalse(TempBonusHelper.hasPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasNonPCTempBonus(spell));
    assertTrue(TempBonusHelper.hasCharacterTempBonus(spell));
    assertFalse(TempBonusHelper.hasEquipmentTempBonus(spell));
    try {
        assertTrue(TempBonusHelper.getEquipmentApplyString(spell).isEmpty());
    } catch (NullPointerException e) {
    //This is appropriate too
    }
}
Also used : LoadContext(pcgen.rules.context.LoadContext) 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