Search in sources :

Example 51 with LoadContext

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

the class BonusTest method testVarBonus.

/**
	 * Test the processing of bonusing variables using both 
	 * abilities and equipment.
	 */
public void testVarBonus() {
    LoadContext context = Globals.getContext();
    Ability dummyFeat = new Ability();
    dummyFeat.setName("DummyFeat");
    dummyFeat.setCDOMCategory(AbilityCategory.FEAT);
    final PlayerCharacter pc = getCharacter();
    // Create a variable
    dummyFeat.put(VariableKey.getConstant("NegLevels"), FormulaFactory.ZERO);
    // Create a bonus to it
    Ability dummyFeat2 = new Ability();
    dummyFeat2.setName("DummyFeat2");
    dummyFeat2.setCDOMCategory(AbilityCategory.FEAT);
    BonusObj aBonus = Bonus.newBonus(context, "VAR|NegLevels|7");
    if (aBonus != null) {
        dummyFeat2.addToListFor(ListKey.BONUS, aBonus);
    }
    Equipment equip = new Equipment();
    equip.setName("DummyEquip");
    aBonus = Bonus.newBonus(context, "VAR|NegLevels|2");
    if (aBonus != null) {
        equip.addToListFor(ListKey.BONUS, aBonus);
    }
    assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    addAbility(AbilityCategory.FEAT, dummyFeat);
    assertEquals("Variable value", 0.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -0.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
    // Add a bonus to it
    addAbility(AbilityCategory.FEAT, dummyFeat2);
    assertEquals("Variable value", 7.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -7.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
    // Add the equipment that gives a bonus to NegLevels
    EquipSet def = new EquipSet("0.1", "Default");
    pc.addEquipSet(def);
    final EquipSet eqSet = new EquipSet("0.1.1", "Equipped", "Test", equip);
    pc.addEquipSet(eqSet);
    pc.setCalcEquipmentList();
    pc.calcActiveBonuses();
    BonusActivation.activateBonuses(dummyFeat, pc);
    assertEquals("Variable value", 9.0, pc.getVariableValue("NegLevels", "").doubleValue(), 0.05);
    assertEquals("Variable value", -9.0, pc.getVariableValue("-1*NegLevels", "").doubleValue(), 0.05);
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) LoadContext(pcgen.rules.context.LoadContext)

Example 52 with LoadContext

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

the class PlayerCharacterTest method testGetVariableValue1.

/**
	 * Tests getVariableValue
	 * @throws Exception
	 */
public void testGetVariableValue1() throws Exception {
    readyToRun();
    LoadContext context = Globals.getContext();
    //Logging.setDebugMode(true);
    Logging.debugPrint("\n\n\ntestGetVariableValue1()");
    giantRace.put(VariableKey.getConstant("GiantVar1"), FormulaFactory.ZERO);
    final BonusObj raceBonus = Bonus.newBonus(context, "VAR|GiantVar1|7+HD");
    giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, raceBonus);
    giantClass.getOriginalClassLevel(1).put(VariableKey.getConstant("GiantClass1"), FormulaFactory.ZERO);
    final BonusObj babClassBonus = Bonus.newBonus(context, "VAR|GiantClass1|CL=Giant");
    giantClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
    final PlayerCharacter character = new PlayerCharacter();
    // NOTE: This will add 4 levels of giantClass to the character 
    character.setRace(giantRace);
    character.incrementClassLevel(4, giantClass, true);
    assertEquals(new Float(15.0), character.getVariableValue("GiantVar1", "CLASS:Giant"));
    assertEquals(new Float(8.0), character.getVariableValue("GiantClass1", "CLASS:Giant"));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext)

Example 53 with LoadContext

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

the class PlayerCharacterTest method testCheckSkillModChangeWithBonus.

/**
	 * Validate the checkSkillModChange correctly handles SKILLPOOL bonuses
	 */
public void testCheckSkillModChangeWithBonus() {
    readyToRun();
    PlayerCharacter character = getCharacter();
    character.setRace(human);
    character.setStat(intel, 10);
    PCTemplate template = TestHelper.makeTemplate("grantsskills");
    LoadContext context = Globals.getContext();
    final BonusObj skillBonusLvl1 = Bonus.newBonus(context, "SKILLPOOL|CLASS=MyClass;LEVEL=1|2");
    assertNotNull("Failed to create bonus", skillBonusLvl1);
    template.addToListFor(ListKey.BONUS, skillBonusLvl1);
    character.addTemplate(template);
    character.incrementClassLevel(2, pcClass, true);
    List<PCLevelInfo> levelInfoList = new ArrayList<>(character.getLevelInfo());
    assertEquals("Level number lvl 1", 1, levelInfoList.get(0).getClassLevel());
    assertEquals("Level number lvl 2", 2, levelInfoList.get(1).getClassLevel());
    assertEquals("Skills gained lvl 1", 3, levelInfoList.get(0).getSkillPointsGained(character));
    assertEquals("Skills remaining lvl 1", 3, levelInfoList.get(0).getSkillPointsRemaining());
    assertEquals("Skills gained lvl 2", 1, levelInfoList.get(1).getSkillPointsGained(character));
    assertEquals("Skills remaining lvl 2", 1, levelInfoList.get(1).getSkillPointsRemaining());
    character.checkSkillModChange();
    character.checkSkillModChange();
    assertEquals("Skills gained lvl 1", 3, levelInfoList.get(0).getSkillPointsGained(character));
    assertEquals("Skills remaining lvl 1", 3, levelInfoList.get(0).getSkillPointsRemaining());
    assertEquals("Skills gained lvl 2", 1, levelInfoList.get(1).getSkillPointsGained(character));
    assertEquals("Skills remaining lvl 2", 1, levelInfoList.get(1).getSkillPointsRemaining());
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext) PCLevelInfo(pcgen.core.pclevelinfo.PCLevelInfo)

Example 54 with LoadContext

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

the class PlayerCharacterTest method testAdjustMoveRates.

/**
	 * Test the processing and order of operations of the adjustMoveRates method.
	 */
public void testAdjustMoveRates() {
    Ability quickFlySlowSwim = TestHelper.makeAbility("quickFlySlowSwim", AbilityCategory.FEAT.getKeyName(), "Foo");
    PCTemplate template = TestHelper.makeTemplate("slowFlyQuickSwim");
    PCTemplate template2 = TestHelper.makeTemplate("dig");
    LoadContext context = Globals.getContext();
    final BonusObj digBonus = Bonus.newBonus(context, "MOVEADD|TYPE.Dig|60");
    assertNotNull("Failed to create bonus", digBonus);
    template2.addToListFor(ListKey.BONUS, digBonus);
    //template.addm
    context.getReferenceContext().importObject(quickFlySlowSwim);
    context.getReferenceContext().importObject(template2);
    context.unconditionallyProcess(human, "MOVE", "Walk,30");
    context.unconditionallyProcess(quickFlySlowSwim, "MOVE", "Swim,10,Fly,30");
    context.unconditionallyProcess(template, "MOVE", "Swim,30,Fly,10");
    readyToRun();
    GameMode game = SettingsHandler.getGame();
    LoadInfo li = game.getModeContext().getReferenceContext().constructNowIfNecessary(LoadInfo.class, game.getName());
    li.addLoadScoreValue(0, new BigDecimal("100.0"));
    li.addLoadScoreValue(10, new BigDecimal("100.0"));
    li.addLoadMultiplier("LIGHT", new Float(100), "100", 0);
    PlayerCharacter pc = getCharacter();
    setPCStat(pc, str, 10);
    pc.setRace(human);
    pc.calcActiveBonuses();
    pc.adjustMoveRates();
    CharacterDisplay display = pc.getDisplay();
    assertEquals(0.0, display.movementOfType("Swim"), 0.1);
    assertEquals(0.0, display.movementOfType("Fly"), 0.1);
    addAbility(AbilityCategory.FEAT, quickFlySlowSwim);
    pc.calcActiveBonuses();
    pc.adjustMoveRates();
    assertEquals(10.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    pc.addTemplate(template);
    pc.adjustMoveRates();
    assertEquals(30.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    pc.addTemplate(template2);
    pc.adjustMoveRates();
    assertEquals(30.0, display.movementOfType("Swim"), 0.1);
    assertEquals(30.0, display.movementOfType("Fly"), 0.1);
    assertEquals(60.0, display.movementOfType("Dig"), 0.1);
}
Also used : LoadInfo(pcgen.core.system.LoadInfo) BonusObj(pcgen.core.bonus.BonusObj) CharacterDisplay(pcgen.core.display.CharacterDisplay) LoadContext(pcgen.rules.context.LoadContext) BigDecimal(java.math.BigDecimal)

Example 55 with LoadContext

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

the class BonusTest method testBonuswithLISTValueTwoAssocInfoList.

public void testBonuswithLISTValueTwoAssocInfoList() {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(character, intel, 18);
    setPCStat(character, str, 16);
    BonusObj bonus = Bonus.newBonus(context, "STAT|%LIST|%LIST+1");
    List<BonusObj> bonusList = new ArrayList<>();
    bonusList.add(bonus);
    Ability testBonus = new Ability();
    testBonus.setName("TB2AssocList");
    testBonus.setCDOMCategory(AbilityCategory.FEAT);
    Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
    Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
    testBonus.addToListFor(ListKey.BONUS, bonus);
    CNAbility cna = AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "INT");
    testBonus = cna.getAbility();
    AbstractCharacterTestCase.applyAbility(character, AbilityCategory.FEAT, testBonus, "STR");
    character.calcActiveBonuses();
    bonus = testBonus.getSafeListFor(ListKey.BONUS).get(0);
    List<BonusPair> bonusPairs = character.getStringListFromBonus(bonus);
    assertEquals(2, bonusPairs.size());
    for (BonusPair bp : bonusPairs) {
        if (bp.fullyQualifiedBonusType.equals("STAT.INT")) {
            assertEquals(5, bp.resolve(character).intValue());
        } else {
            assertEquals(4, bp.resolve(character).intValue());
        }
    }
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) CNAbility(pcgen.cdom.content.CNAbility) PlayerCharacter(pcgen.core.PlayerCharacter) ArrayList(java.util.ArrayList) LoadContext(pcgen.rules.context.LoadContext)

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