use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class WeaponTokenTest method testWpnFinesse.
/**
* Test the processing of a finesseable weapon both with and without weapon finesse
* and temporary bonuses.
*/
public void testWpnFinesse() {
PlayerCharacter character = getCharacter();
assertEquals("Prof should be longsword", "KEY_LONGSWORD", fineSword.get(ObjectKey.WEAPON_PROF).get().getKeyName());
LoadContext context = Globals.getContext();
character.addEquipment(fineSword);
EquipSet es = new EquipSet("0.1.3", "Longsword (Fine)", fineSword.getName(), fineSword);
character.addEquipSet(es);
character.setCalcEquipmentList();
// Test weapon profs effects on large weapons
WeaponToken token = new WeaponToken();
assertEquals("Fine sword", "+18/+13/+8/+3", token.getToken("WEAPON.3.BASEHIT", character, null));
// Now apply weapon finess and check dex is used rather than str
Ability wpnFinesse = new Ability();
wpnFinesse.setName("Weapon Finesse");
wpnFinesse.setCDOMCategory(AbilityCategory.FEAT);
wpnFinesse.put(StringKey.KEY_NAME, "Weapon Finesse");
final BonusObj wfBonus = Bonus.newBonus(context, "COMBAT|TOHIT.Finesseable|((max(STR,DEX)-STR)+SHIELDACCHECK)|TYPE=NotRanged");
wpnFinesse.addToListFor(ListKey.BONUS, wfBonus);
addAbility(AbilityCategory.FEAT, wpnFinesse);
assertEquals("Fine sword", "+19/+14/+9/+4", token.getToken("WEAPON.3.BASEHIT", character, null));
// Add a temp penalty to dex and check that it is applied
character.setUseTempMods(true);
Spell spell2 = new Spell();
spell2.setName("Concrete Boots");
final BonusObj aBonus = Bonus.newBonus(context, "STAT|DEX|-4");
if (aBonus != null) {
spell2.addToListFor(ListKey.BONUS, aBonus);
}
BonusObj penalty = spell2.getRawBonusList(character).get(0);
character.addTempBonus(penalty, spell2, character);
character.calcActiveBonuses();
assertEquals("Fine sword", "+18/+13/+8/+3", token.getToken("WEAPON.3.BASEHIT", character, null));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PCGVer2ParserCharacterTest method testRaceAddSpellcaster.
/**
* Check that a racial ADD:SPELLCASTER happens exactly once on character
* load. Duplication of the association has occurred a couple of times in
* the past.
* @throws Exception
*/
public void testRaceAddSpellcaster() throws Exception {
LoadContext context = Globals.getContext();
Race rakshasha = context.getReferenceContext().silentlyGetConstructedCDOMObject(Race.class, "Rakshasa");
PlayerCharacter pc = getCharacter();
pc.setImporting(true);
PCGVer2Parser pcgParser = new PCGVer2Parser(pc);
String[] pcgLines = { "RACE:Rakshasa|ADD:[SPELLCASTER:Sorcerer|CHOICE:Sorcerer]" };
pcgParser.parsePCG(pcgLines);
PersistentTransitionChoice<?> tc = rakshasha.getListFor(ListKey.ADD).get(0);
List<Object> assocList = pc.getAssocList(tc, AssociationListKey.ADD);
assertEquals("Number of associations for ADD " + assocList, 1, assocList.size());
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class AbstractPreRoundRobin method runSimpleRoundRobin.
public static void runSimpleRoundRobin(String s, String d) {
try {
Prerequisite p = PreParserFactory.getInstance().parse(s);
PrerequisiteWriterInterface writer = PrerequisiteWriterFactory.getInstance().getWriter(p.getKind());
if (writer == null) {
fail("Could not find Writer for: " + p.getKind());
}
StringWriter w = new StringWriter();
writer.write(w, p);
assertEquals(d, w.toString());
/*
* Now try new system
*/
LoadContext context = new EditorLoadContext();
CDOMObject obj = new ObjectCache();
int colonLoc = s.indexOf(':');
String key = s.substring(0, colonLoc);
String value = s.substring(colonLoc + 1);
if (context.processToken(obj, key, value)) {
context.commit();
} else {
context.rollback();
Logging.replayParsedMessages();
fail();
}
Logging.clearParseMessages();
Collection<String> output = context.unparse(obj);
if (output == null || output.isEmpty()) {
// Uh Oh
fail("Unable to unparse: " + key + ":" + value);
}
assertEquals(1, output.size());
assertEquals(d, output.iterator().next());
} catch (PersistenceLayerException e) {
e.printStackTrace();
fail(e.getLocalizedMessage());
}
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PreBaseSizeTest method testBaseSizePlusMod.
/**
* Tests to make sure the base size does not includ SIZEMOD adjustments
* @throws Exception
*/
public void testBaseSizePlusMod() throws Exception {
final PlayerCharacter character = getCharacter();
LoadContext context = Globals.getContext();
character.setRace(race);
final BonusObj sizeBonus = Bonus.newBonus(context, "SIZEMOD|NUMBER|1");
race.addToListFor(ListKey.BONUS, sizeBonus);
character.calcActiveBonuses();
Prerequisite prereq;
final PreParserFactory factory = PreParserFactory.getInstance();
prereq = factory.parse("PREBASESIZEEQ:Medium");
assertTrue("Character's base size should be equal to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELTEQ:Medium");
assertTrue("Character's base size should be <= to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGTEQ:Medium");
assertTrue("Character's base size should be >= to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:Small");
assertTrue("Character's base size should be > to Small", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:Large");
assertTrue("Character's base size should be < to Large", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZELT:Medium");
assertFalse("Character's base size should not be < to Medium", PrereqHandler.passes(prereq, character, null));
prereq = factory.parse("PREBASESIZEGT:Medium");
assertFalse("Character's base size should not be > to Medium", PrereqHandler.passes(prereq, character, null));
}
use of pcgen.rules.context.LoadContext in project pcgen by PCGen.
the class PreClassTest method testSpellcasterTypeWrongCasePass.
/**
* Test to ensure that a spellcaster type check is case insensitive
* @throws Exception
*/
public void testSpellcasterTypeWrongCasePass() throws Exception {
LoadContext context = Globals.getContext();
final PCClass pcClass = context.getReferenceContext().constructCDOMObject(PCClass.class, "MyClass");
BuildUtilities.setFact(pcClass, "SpellType", "Arcane");
context.unconditionallyProcess(pcClass.getOriginalClassLevel(1), "CAST", "5,4");
context.unconditionallyProcess(pcClass, "SPELLSTAT", "CHA");
context.getReferenceContext().buildDerivedObjects();
context.getReferenceContext().resolveReferences(null);
context.loadCampaignFacets();
final PlayerCharacter character = getCharacter();
character.incrementClassLevel(1, pcClass);
setPCStat(character, cha, 12);
final Prerequisite prereq = new Prerequisite();
prereq.setKind("class");
prereq.setKey("Spellcaster.Arcane");
prereq.setOperand("1");
prereq.setOperator(PrerequisiteOperator.GTEQ);
final PreClassTester test = new PreClassTester();
final int passes = test.passes(prereq, character, null);
assertEquals(1, passes);
}
Aggregations