Search in sources :

Example 91 with LoadContext

use of pcgen.rules.context.LoadContext 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 92 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PlayerCharacterTest method testGetAggregateAbilityList.

public void testGetAggregateAbilityList() {
    Ability resToAcid = TestHelper.makeAbility("Swelter", AbilityCategory.FEAT.getKeyName(), "Foo");
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(resToAcid, "MULT", "YES");
    context.unconditionallyProcess(resToAcid, "STACK", "YES");
    context.unconditionallyProcess(resToAcid, "CHOOSE", "NOCHOICE");
    PCTemplate template = TestHelper.makeTemplate("TemplateVirt");
    PCTemplate templateNorm = TestHelper.makeTemplate("TemplateNorm");
    context.getReferenceContext().importObject(resToAcid);
    context.unconditionallyProcess(human, "ABILITY", "FEAT|AUTOMATIC|KEY_Swelter");
    context.unconditionallyProcess(template, "ABILITY", "FEAT|VIRTUAL|KEY_Swelter");
    context.unconditionallyProcess(templateNorm, "ABILITY", "FEAT|NORMAL|KEY_Swelter");
    readyToRun();
    PlayerCharacter pc = getCharacter();
    List<Ability> abList = pc.getAggregateAbilityListNoDuplicates(AbilityCategory.FEAT);
    assertEquals(0, abList.size());
    pc.setRace(human);
    abList = pc.getAggregateAbilityListNoDuplicates(AbilityCategory.FEAT);
    assertEquals(1, abList.size());
    pc.addTemplate(template);
    abList = pc.getAggregateAbilityListNoDuplicates(AbilityCategory.FEAT);
    assertEquals(1, abList.size());
    pc.addTemplate(templateNorm);
    abList = pc.getAggregateAbilityListNoDuplicates(AbilityCategory.FEAT);
    assertEquals(1, abList.size());
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 93 with LoadContext

use of pcgen.rules.context.LoadContext in project pcgen by PCGen.

the class PlayerCharacterTest method testSkillsVisibility.

/**
	 * Test the skills visibility functionality. We want to ensure that
	 * each call retrieves the right set of skills.
	 */
public void testSkillsVisibility() {
    readyToRun();
    PlayerCharacter pc = getCharacter();
    Skill guiSkill = new Skill();
    Skill outputSkill = new Skill();
    Skill defaultSkill = new Skill();
    LoadContext context = Globals.getContext();
    context.unconditionallyProcess(guiSkill, "CLASSES", "MyClass");
    guiSkill.setName("GUI");
    guiSkill.addToListFor(ListKey.TYPE, Type.getConstant("INT"));
    guiSkill.put(ObjectKey.VISIBILITY, Visibility.DISPLAY_ONLY);
    SkillRankControl.modRanks(1.0, pcClass, true, pc, guiSkill);
    context.unconditionallyProcess(outputSkill, "CLASSES", "MyClass");
    outputSkill.setName("Output");
    outputSkill.addToListFor(ListKey.TYPE, Type.getConstant("INT"));
    outputSkill.put(ObjectKey.VISIBILITY, Visibility.OUTPUT_ONLY);
    SkillRankControl.modRanks(1.0, pcClass, true, pc, outputSkill);
    context.unconditionallyProcess(defaultSkill, "CLASSES", "MyClass");
    defaultSkill.setName("Default");
    defaultSkill.addToListFor(ListKey.TYPE, Type.getConstant("INT"));
    defaultSkill.put(ObjectKey.VISIBILITY, Visibility.DEFAULT);
    SkillRankControl.modRanks(1.0, pcClass, true, pc, defaultSkill);
    // Test retrieved list
    Collection<Skill> skillList = pc.getSkillSet();
    assertEquals("Full skill list should have all 3 skills", 3, skillList.size());
    skillList = pc.getDisplay().getPartialSkillList(View.VISIBLE_DISPLAY);
    assertEquals("GUI skill list should have 2 skills", 2, skillList.size());
    skillList = pc.getDisplay().getPartialSkillList(View.VISIBLE_EXPORT);
    assertEquals("Output skill list should have 2 skills", 2, skillList.size());
    skillList = pc.getDisplay().getPartialSkillList(View.ALL);
    assertEquals("Full skill list should have 3 skills", 3, skillList.size());
}
Also used : LoadContext(pcgen.rules.context.LoadContext)

Example 94 with LoadContext

use of pcgen.rules.context.LoadContext 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 95 with LoadContext

use of pcgen.rules.context.LoadContext 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)

Aggregations

LoadContext (pcgen.rules.context.LoadContext)141 PlayerCharacter (pcgen.core.PlayerCharacter)58 BonusObj (pcgen.core.bonus.BonusObj)48 PCClass (pcgen.core.PCClass)32 URI (java.net.URI)25 CampaignSourceEntry (pcgen.persistence.lst.CampaignSourceEntry)25 URISyntaxException (java.net.URISyntaxException)20 Campaign (pcgen.core.Campaign)16 Race (pcgen.core.Race)16 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)16 Equipment (pcgen.core.Equipment)15 UnreachableError (pcgen.base.lang.UnreachableError)14 PersistenceLayerException (pcgen.persistence.PersistenceLayerException)14 PCClassLoader (pcgen.persistence.lst.PCClassLoader)14 Spell (pcgen.core.spell.Spell)13 Ability (pcgen.core.Ability)12 PCTemplate (pcgen.core.PCTemplate)12 SizeAdjustment (pcgen.core.SizeAdjustment)10 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)9 Skill (pcgen.core.Skill)9