Search in sources :

Example 66 with BonusObj

use of pcgen.core.bonus.BonusObj 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 67 with BonusObj

use of pcgen.core.bonus.BonusObj 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 68 with BonusObj

use of pcgen.core.bonus.BonusObj 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 69 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class BonusToken method unparse.

@Override
public String[] unparse(LoadContext context, EquipmentModifier mod) {
    Changes<BonusObj> changes = context.getObjectContext().getListChanges(mod, ListKey.BONUS);
    if (changes == null || changes.isEmpty()) {
        // Empty indicates no token present
        return null;
    }
    // CONSIDER need to deal with removed...
    Collection<BonusObj> added = changes.getAdded();
    String tokenName = getTokenName();
    Set<String> bonusSet = new TreeSet<>();
    for (BonusObj bonus : added) {
        if (tokenName.equals(bonus.getTokenSource())) {
            String bonusString = bonus.getLSTformat();
            bonusSet.add(bonusString);
        }
    }
    if (bonusSet.isEmpty()) {
        // This is okay - just no BONUSes from this token
        return null;
    }
    return bonusSet.toArray(new String[bonusSet.size()]);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) TreeSet(java.util.TreeSet)

Example 70 with BonusObj

use of pcgen.core.bonus.BonusObj in project pcgen by PCGen.

the class BonusToken method parseToken.

@Override
public ParseResult parseToken(LoadContext context, EquipmentModifier mod, String value) {
    BonusObj bon = Bonus.newBonus(context, value);
    if (bon == null) {
        return new ParseResult.Fail(getTokenName() + " was given invalid bonus: " + value, context);
    }
    bon.setTokenSource(getTokenName());
    context.getObjectContext().addToList(mod, ListKey.BONUS, bon);
    return ParseResult.SUCCESS;
}
Also used : BonusObj(pcgen.core.bonus.BonusObj)

Aggregations

BonusObj (pcgen.core.bonus.BonusObj)126 LoadContext (pcgen.rules.context.LoadContext)48 PlayerCharacter (pcgen.core.PlayerCharacter)29 ArrayList (java.util.ArrayList)22 CDOMObject (pcgen.cdom.base.CDOMObject)18 PCClass (pcgen.core.PCClass)14 Prerequisite (pcgen.core.prereq.Prerequisite)13 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)13 EquipSet (pcgen.core.character.EquipSet)11 IdentityHashMap (java.util.IdentityHashMap)10 Map (java.util.Map)10 TreeSet (java.util.TreeSet)10 Ability (pcgen.core.Ability)10 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)8 TempBonusInfo (pcgen.core.BonusManager.TempBonusInfo)8 Equipment (pcgen.core.Equipment)8 HashMap (java.util.HashMap)7 Race (pcgen.core.Race)7 StringTokenizer (java.util.StringTokenizer)6 CNAbility (pcgen.cdom.content.CNAbility)6