Search in sources :

Example 46 with LoadContext

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

the class PCTemplateTest method testAddFeatAbility.

/**
	 * Test the definition and application of abilities of category FEAT. 
	 * @throws PersistenceLayerException 
	 * @throws MalformedURLException 
	 */
public void testAddFeatAbility() throws PersistenceLayerException, MalformedURLException {
    LoadContext context = Globals.getContext();
    // Create some abilities to be added
    Ability ab1 = new Ability();
    ab1.setName("Ability1");
    ab1.setCDOMCategory(AbilityCategory.FEAT);
    context.getReferenceContext().importObject(ab1);
    Ability ab2 = new Ability();
    ab2.setName("Ability2");
    ab2.setCDOMCategory(AbilityCategory.FEAT);
    context.getReferenceContext().importObject(ab2);
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    loader.parseLine(context, null, "Template1	ABILITY:FEAT|AUTOMATIC|Ability1	ABILITY:FEAT|AUTOMATIC|Ability2", source);
    PCTemplate template = context.getReferenceContext().silentlyGetConstructedCDOMObject(PCTemplate.class, "Template1");
    context.getReferenceContext().importObject(ab1);
    context.getReferenceContext().importObject(ab2);
    CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "Feat");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
    Collection<CDOMReference<Ability>> listMods = template.getListMods(autoList);
    assertEquals(2, listMods.size());
    Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
    CDOMReference<Ability> ref1 = iterator.next();
    CDOMReference<Ability> ref2 = iterator.next();
    Collection<Ability> contained1 = ref1.getContainedObjects();
    Collection<Ability> contained2 = ref2.getContainedObjects();
    assertEquals(1, contained1.size());
    assertEquals(1, contained2.size());
    assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
    assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
    // Add the template to the character
    PlayerCharacter pc = getCharacter();
    pc.addTemplate(template);
    // Need to do this to populate the ability list
    //pc.getAutomaticAbilityList(AbilityCategory.FEAT);
    assertTrue("Character should have ability1.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, AbilityCategory.FEAT, Nature.AUTOMATIC, ab2));
}
Also used : AbilityList(pcgen.cdom.list.AbilityList) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 47 with LoadContext

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

the class PObjectTest method testAddAbility.

/**
	 * Test the definition and application of abilities. 
	 * @throws PersistenceLayerException 
	 */
public void testAddAbility() throws PersistenceLayerException {
    // Create some abilities to be added
    LoadContext context = Globals.getContext();
    AbilityCategory cat = context.getReferenceContext().constructCDOMObject(AbilityCategory.class, "TestCat");
    new AbilityCategoryLoader().parseLine(context, "TestCat\tCATEGORY:TestCat", null);
    Ability ab1 = new Ability();
    ab1.setName("Ability1");
    ab1.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
    Ability ab2 = new Ability();
    ab2.setName("Ability2");
    ab2.setCDOMCategory(SettingsHandler.getGame().getAbilityCategory("TestCat"));
    context.getReferenceContext().importObject(ab1);
    context.getReferenceContext().importObject(ab2);
    // Link them to a template
    Race race = new Race();
    CampaignSourceEntry source;
    try {
        source = new CampaignSourceEntry(new Campaign(), new URI("file:/" + getClass().getName() + ".java"));
    } catch (URISyntaxException e) {
        throw new UnreachableError(e);
    }
    GenericLoader<Race> loader = new GenericLoader<>(Race.class);
    loader.parseLine(context, race, "Race1	ABILITY:TestCat|AUTOMATIC|Ability1	ABILITY:TestCat|AUTOMATIC|Ability2", source);
    context.getReferenceContext().importObject(ab1);
    context.getReferenceContext().importObject(ab2);
    CDOMSingleRef<AbilityCategory> acRef = context.getReferenceContext().getCDOMReference(AbilityCategory.class, "TestCat");
    assertTrue(context.getReferenceContext().resolveReferences(null));
    CDOMReference<AbilityList> autoList = AbilityList.getAbilityListReference(acRef, Nature.AUTOMATIC);
    Collection<CDOMReference<Ability>> listMods = race.getListMods(autoList);
    assertEquals(2, listMods.size());
    Iterator<CDOMReference<Ability>> iterator = listMods.iterator();
    CDOMReference<Ability> ref1 = iterator.next();
    CDOMReference<Ability> ref2 = iterator.next();
    Collection<Ability> contained1 = ref1.getContainedObjects();
    Collection<Ability> contained2 = ref2.getContainedObjects();
    assertEquals(1, contained1.size());
    assertEquals(1, contained2.size());
    assertTrue(contained1.contains(ab1) || contained2.contains(ab1));
    assertTrue(contained1.contains(ab2) || contained2.contains(ab2));
    // Add the template to the character
    PlayerCharacter pc = getCharacter();
    pc.setRace(race);
    assertTrue("Character should have ability1.", hasAbility(pc, cat, Nature.AUTOMATIC, ab1));
    assertTrue("Character should have ability2.", hasAbility(pc, cat, Nature.AUTOMATIC, ab2));
}
Also used : CNAbility(pcgen.cdom.content.CNAbility) AbilityList(pcgen.cdom.list.AbilityList) GenericLoader(pcgen.persistence.lst.GenericLoader) URISyntaxException(java.net.URISyntaxException) UnreachableError(pcgen.base.lang.UnreachableError) URI(java.net.URI) CampaignSourceEntry(pcgen.persistence.lst.CampaignSourceEntry) LoadContext(pcgen.rules.context.LoadContext) AbilityCategoryLoader(pcgen.persistence.lst.AbilityCategoryLoader) CDOMReference(pcgen.cdom.base.CDOMReference)

Example 48 with LoadContext

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

the class StatListTest method setUp.

/**
	 * @see pcgen.AbstractCharacterTestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    PlayerCharacter pc = getCharacter();
    LoadContext context = Globals.getContext();
    locker = new PCTemplate();
    locker.setName("locker");
    CDOMDirectSingleRef<PCStat> strRef = CDOMDirectSingleRef.getRef(str);
    locker.addToListFor(ListKey.STAT_LOCKS, new StatLock(strRef, FormulaFactory.getFormulaFor(12)));
    unlocker = new PCTemplate();
    unlocker.setName("unlocker");
    unlocker.addToListFor(ListKey.UNLOCKED_STATS, strRef);
    bonus = TestHelper.makeAbility("Bonus", AbilityCategory.FEAT, "General.Fighter");
    BonusObj aBonus = Bonus.newBonus(context, "STAT|STR|7|TYPE=Enhancement");
    if (aBonus != null) {
        bonus.addToListFor(ListKey.BONUS, aBonus);
    }
    lockedBonus = TestHelper.makeAbility("LockedBonus", AbilityCategory.FEAT, "General.Fighter");
    aBonus = Bonus.newBonus(context, "LOCKEDSTAT|STR|3|TYPE=Morale");
    if (aBonus != null) {
        lockedBonus.addToListFor(ListKey.BONUS, aBonus);
    }
    setPCStat(pc, str, 6);
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) LoadContext(pcgen.rules.context.LoadContext) StatLock(pcgen.cdom.helper.StatLock)

Example 49 with LoadContext

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

the class BonusTest method testSkillPrereq.

/**
	 * Test the skill pre reqs
	 * @throws Exception
	 */
public void testSkillPrereq() throws Exception {
    LoadContext context = Globals.getContext();
    final Skill rideSkill = new Skill();
    rideSkill.setName("Ride");
    rideSkill.put(StringKey.KEY_NAME, "Ride");
    rideSkill.addToListFor(ListKey.TYPE, Type.getConstant("DEX"));
    final Ability skillFocus = new Ability();
    skillFocus.setName("Skill Focus");
    skillFocus.put(StringKey.KEY_NAME, "Skill Focus");
    final BonusObj saddleBonus = Bonus.newBonus(context, "SKILL|Ride|-5|!PREITEM:1,TYPE.Saddle");
    rideSkill.addToListFor(ListKey.BONUS, saddleBonus);
    final Equipment saddle = new Equipment();
    saddle.setName("Saddle, Test");
    saddle.addToListFor(ListKey.TYPE, Type.getConstant("SADDLE"));
    final PlayerCharacter pc = getCharacter();
    BonusActivation.activateBonuses(rideSkill, pc);
    double iBonus = saddleBonus.resolve(pc, "").doubleValue();
    assertEquals("Bonus value", -5.0, iBonus, 0.05);
    assertTrue("No saddle, should have a penalty", pc.isApplied(saddleBonus));
    pc.addEquipment(saddle);
    final EquipSet eqSet = new EquipSet("Test", "Test", "", saddle);
    pc.addEquipSet(eqSet);
    pc.calcActiveBonuses();
    BonusActivation.activateBonuses(rideSkill, pc);
    assertFalse("Saddle, should not have a penalty", pc.isApplied(saddleBonus));
}
Also used : Ability(pcgen.core.Ability) CNAbility(pcgen.cdom.content.CNAbility) Skill(pcgen.core.Skill) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) EquipSet(pcgen.core.character.EquipSet) LoadContext(pcgen.rules.context.LoadContext)

Example 50 with LoadContext

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

the class BonusTest method testBonuswithLISTValueTwoAssoc.

public void testBonuswithLISTValueTwoAssoc() {
    final PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    setPCStat(character, intel, 18);
    setPCStat(character, str, 16);
    BonusObj bonus = Bonus.newBonus(context, "VISION|Darkvision|%LIST+10|TYPE=Magical Boon");
    List<BonusObj> bonusList = new ArrayList<>();
    bonusList.add(bonus);
    Ability testBonus = new Ability();
    testBonus.setName("TB2Assoc");
    testBonus.setCDOMCategory(AbilityCategory.FEAT);
    testBonus.addToListFor(ListKey.BONUS, bonus);
    Globals.getContext().unconditionallyProcess(testBonus, "CHOOSE", "PCSTAT|ALL");
    Globals.getContext().unconditionallyProcess(testBonus, "MULT", "YES");
    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());
    int totalBonus = 0;
    BonusPair bp = bonusPairs.get(0);
    assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
    totalBonus += bp.resolve(character).intValue();
    bp = bonusPairs.get(1);
    assertEquals("VISION.DARKVISION:MAGICAL BOON", bp.fullyQualifiedBonusType);
    totalBonus += bp.resolve(character).intValue();
    assertEquals(27, totalBonus);
}
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