use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCClassTest method testGetKnownForLevelSpellstatOther.
public void testGetKnownForLevelSpellstatOther() {
LoadContext context = Globals.getContext();
PCClass megaCasterClass = new PCClass();
megaCasterClass.setName("MegaCasterOther");
BuildUtilities.setFact(megaCasterClass, "SpellType", "Arcane");
context.unconditionallyProcess(megaCasterClass, "SPELLSTAT", "OTHER");
megaCasterClass.put(ObjectKey.SPELLBOOK, false);
megaCasterClass.put(ObjectKey.MEMORIZE_SPELLS, false);
context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(1), "KNOWN", "4,2,2,3,4,5,0");
context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(1), "CAST", "3,1,2,3,4,5,0,0");
context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(2), "KNOWN", "4,2,2,3,4,5,6,7,8,9,10");
context.unconditionallyProcess(megaCasterClass.getOriginalClassLevel(2), "CAST", "3,1,2,3,4,5,6,7,8,9,10");
Globals.getContext().getReferenceContext().importObject(megaCasterClass);
context.getReferenceContext().buildDerivedObjects();
context.loadCampaignFacets();
final PlayerCharacter character = getCharacter();
// Test retrieval for a non-spell casting class.
character.incrementClassLevel(1, nqClass);
PCClass charClass = character.getClassKeyed(nqClass.getKeyName());
assertEquals("Known 0th level for non spell casting class", 0, character.getSpellSupport(charClass).getKnownForLevel(0, character));
// Test retrieval for a spell casting class.
character.incrementClassLevel(1, megaCasterClass);
charClass = character.getClassKeyed(megaCasterClass.getKeyName());
setPCStat(character, cha, 10);
assertEquals("Known 0th level for character's class", 4, character.getSpellSupport(charClass).getKnownForLevel(0, character));
character.calcActiveBonuses();
assertEquals("Known 1st level where stat is high enough, but no bonus", 2, character.getSpellSupport(charClass).getKnownForLevel(1, character));
RuleCheck bonusKnownRule = new RuleCheck();
bonusKnownRule.setName(RuleConstants.BONUSSPELLKNOWN);
bonusKnownRule.setDefault(true);
GameMode gameMode = SettingsHandler.getGame();
gameMode.getModeContext().getReferenceContext().importObject(bonusKnownRule);
BonusSpellInfo bsi = new BonusSpellInfo();
bsi.setName("1");
bsi.setStatScore(12);
bsi.setStatRange(8);
context.getReferenceContext().importObject(bsi);
bsi = new BonusSpellInfo();
bsi.setName("5");
bsi.setStatScore(20);
bsi.setStatRange(8);
assertEquals("Known 1st level where stat would give bonus and active", 2, character.getSpellSupport(charClass).getKnownForLevel(1, character));
assertEquals("Known 2nd level for character's class", 2, character.getSpellSupport(charClass).getKnownForLevel(2, character));
assertEquals("Known 3rd level for character's class", 3, character.getSpellSupport(charClass).getKnownForLevel(3, character));
assertEquals("Known 4th level for character's class", 4, character.getSpellSupport(charClass).getKnownForLevel(4, character));
charClass.put(IntegerKey.KNOWN_SPELLS_FROM_SPECIALTY, 1);
assertEquals("Known 5th level for character's class", 6, character.getSpellSupport(charClass).getKnownForLevel(5, character));
assertEquals("Known 6th level for character's class", 0, character.getSpellSupport(charClass).getKnownForLevel(6, character));
assertEquals("Known 7th level for character's class", 0, character.getSpellSupport(charClass).getKnownForLevel(7, character));
// Add spell bonus for level above known max
bsi = new BonusSpellInfo();
bsi.setName("7");
bsi.setStatScore(12);
bsi.setStatRange(8);
assertEquals("Known 7th level for character's class", 0, character.getSpellSupport(charClass).getKnownForLevel(7, character));
assertEquals("Known 8th level for character's class", 0, character.getSpellSupport(charClass).getKnownForLevel(8, character));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusManagerTest method testStackingPositiveFirst.
/**
* Validate that the setActiveBonusStack method will correctly calculate the value of
* a positive bonus followed by a negative bonus to a non-stackable value.
*/
@Test
public void testStackingPositiveFirst() {
PCTemplate testObj = TestHelper.makeTemplate("PostiveFirst");
LoadContext context = Globals.getContext();
final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, posBonus);
final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, negBonus);
PlayerCharacter pc = getCharacter();
pc.addTemplate(testObj);
// Run the check a few times to ensure no randomness issues
for (int i = 0; i < 10; i++) {
pc.calcActiveBonuses();
assertEquals("Incorrect bonus total", 3.0, pc.getTotalBonusTo("COMBAT", "AC"), 0.0001);
}
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class BonusManagerTest method testStackingPosNegPos.
/**
* Validate that the setActiveBonusStack method will correctly calculate the value of
* a positive bonus, then a negative bonus followed by a positive bonus to a
* non-stackable value.
*/
@Test
public void testStackingPosNegPos() {
PCTemplate testObj = TestHelper.makeTemplate("PosNegPos");
LoadContext context = Globals.getContext();
final BonusObj posBonus = Bonus.newBonus(context, "COMBAT|AC|5|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, posBonus);
final BonusObj negBonus = Bonus.newBonus(context, "COMBAT|AC|-2|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, negBonus);
final BonusObj posBonus2 = Bonus.newBonus(context, "COMBAT|AC|4|TYPE=Armor");
testObj.addToListFor(ListKey.BONUS, posBonus2);
PlayerCharacter pc = getCharacter();
pc.addTemplate(testObj);
// Run the check a few times to ensure no randomness issues
for (int i = 0; i < 10; i++) {
pc.calcActiveBonuses();
assertEquals("Incorrect bonus total", 3.0, pc.getTotalBonusTo("COMBAT", "AC"), 0.0001);
}
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class ChallengeRatingPathfinderTest method additionalSetUp.
@Override
protected void additionalSetUp() throws Exception {
SettingsHandler.getGame().setCRSteps("1/2|1/3|1/4|1/6|1/8");
SettingsHandler.getGame().setCRThreshold("BASECR");
SettingsHandler.getGame().setMonsterRoleList(new ArrayList<>(Arrays.asList("Combat", "Skill", "Druid")));
SettingsHandler.getGame().addClassType("PC CRFORMULA:CL ISMONSTER:NO CRMOD:-1 CRMODPRIORITY:1");
SettingsHandler.getGame().addClassType("NPC CRFORMULA:CL ISMONSTER:NO CRMOD:-2 CRMODPRIORITY:2");
SettingsHandler.getGame().addClassType("Monster CRFORMULA:0 ISMONSTER:YES");
SettingsHandler.getGame().addClassType("Companion CRFORMULA:NONE ISMONSTER:YES");
LoadContext context = Globals.getContext();
BuildUtilities.createFact(context, "ClassType", PCClass.class);
SourceFileLoader.processFactDefinitions(context);
CampaignSourceEntry source = TestHelper.createSource(getClass());
GenericLoader<Race> raceLoader = new GenericLoader<>(Race.class);
PCClassLoader classLoader = new PCClassLoader();
final String standardRaceLine = "Standard Race";
raceLoader.parseLine(context, null, standardRaceLine, source);
standardRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Standard Race");
final String koboldRaceLine = "Kobold CRMOD:NPC|-3";
raceLoader.parseLine(context, null, koboldRaceLine, source);
koboldRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Kobold");
final String drowNobleLine = "Drow Noble CRMOD:PC.NPC|0";
raceLoader.parseLine(context, null, drowNobleLine, source);
drowNobleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Drow Noble");
final String babauLine = "Babau MONSTERCLASS:TestMonsterClass:7 CR:6 ROLE:Combat.Skill";
raceLoader.parseLine(context, null, babauLine, source);
babauRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Babau");
final String dryadLine = "Dryad MONSTERCLASS:TestMonsterClass:8 CR:7 ROLE:Druid";
raceLoader.parseLine(context, null, dryadLine, source);
dryadRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dryad");
final String companionLine = "TestCompanion MONSTERCLASS:TestCompanionClass:4";
raceLoader.parseLine(context, null, companionLine, source);
companionRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "TestCompanion");
final String zombieLine = "Zombie MONSTERCLASS:TestMonsterClass:1 CR:1/2 ROLE:Combat";
raceLoader.parseLine(context, null, zombieLine, source);
zombieRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Zombie");
final String direRatLine = "Dire Rat MONSTERCLASS:TestMonsterClass:1 CR:1/3 ROLE:Combat";
raceLoader.parseLine(context, null, direRatLine, source);
direRatRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Dire rat");
final String miteLine = "Mite MONSTERCLASS:TestMonsterClass:1 CR:1/4 ROLE:Combat";
raceLoader.parseLine(context, null, miteLine, source);
miteRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Mite");
final String beetleLine = "Beetle MONSTERCLASS:TestMonsterClass:1 CR:1/6 ROLE:Combat";
raceLoader.parseLine(context, null, beetleLine, source);
beetleRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Beetle");
final String centipedeLine = "Centipede MONSTERCLASS:TestMonsterClass:1 CR:1/8 Centipede";
raceLoader.parseLine(context, null, centipedeLine, source);
centipedeRace = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Centipede");
final String pcClassLine = "CLASS:TestPCClass TYPE:PC ROLE:Combat";
pcClass = classLoader.parseLine(context, null, pcClassLine, source);
context.getReferenceContext().importObject(pcClass);
final String pcClassLine2 = "CLASS:TestPCClass2 TYPE:PC ROLE:Druid";
pcClass2 = classLoader.parseLine(context, null, pcClassLine2, source);
context.getReferenceContext().importObject(pcClass2);
final String npcClassLine = "CLASS:TestNPCClass2 TYPE:NPC";
npcClass = classLoader.parseLine(context, null, npcClassLine, source);
context.getReferenceContext().importObject(npcClass);
final String npcClassLine2 = "CLASS:TestNPCClass2 TYPE:NPC";
npcClass2 = classLoader.parseLine(context, null, npcClassLine2, source);
context.getReferenceContext().importObject(npcClass2);
final String monsterClassLine = "CLASS:TestMonsterClass HD:8 CLASSTYPE:Monster";
monsterClass = classLoader.parseLine(context, null, monsterClassLine, source);
context.getReferenceContext().importObject(monsterClass);
final String companionClassLine = "CLASS:TestCompanionClass HD:8 CLASSTYPE:Companion";
companionClass = classLoader.parseLine(context, null, companionClassLine, source);
context.getReferenceContext().importObject(companionClass);
context.commit();
BuildUtilities.createFact(context, "ClassType", PCClass.class);
FactDefinition<?, String> fd = BuildUtilities.createFact(context, "SpellType", PCClass.class);
fd.setSelectable(true);
SourceFileLoader.processFactDefinitions(context);
context.getReferenceContext().buildDerivedObjects();
context.resolveDeferredTokens();
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class EquipmentModifierTest method test885958A.
/**
* Test +13
*/
public void test885958A() {
LoadContext context = Globals.getContext();
final EquipmentModifier eqMod = new EquipmentModifier();
final BonusObj aBonus = Bonus.newBonus(context, "WEAPON|DAMAGE|((%CHOICE)MIN(STR))");
eqMod.addToListFor(ListKey.BONUS, aBonus);
final Equipment e = new Equipment();
e.addAssociation(eqMod, "+13");
for (BonusObj bonusObj : eqMod.getBonusList(e)) {
assertEquals("((+13)MIN(STR))", bonusObj.getValue());
}
assertEquals("((%CHOICE)MIN(STR))", aBonus.getValue());
}
Aggregations