Search in sources :

Example 46 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreEquipTest method testPassesPrerequisitePlayerCharacter.

/*
	 * Class under test for int passes(Prerequisite, PlayerCharacter)
	 */
public void testPassesPrerequisitePlayerCharacter() {
    final PlayerCharacter character = getCharacter();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("equip");
    prereq.setKey("LONGSWORD");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(passes);
    longsword.setName("Longsword (Masterwork)");
    assertFalse("Should be an exact match only", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("LONGSWORD%");
    assertTrue("Should be allow wildcard match", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 47 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreEquipTwoWeaponTest method testPassesPrerequisitePlayerCharacter.

/*
	 * Class under test for int passes(Prerequisite, PlayerCharacter)
	 */
public void testPassesPrerequisitePlayerCharacter() {
    final PlayerCharacter character = getCharacter();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_TWO_HANDS);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    final Prerequisite prereq = new Prerequisite();
    prereq.setKind("equiptwoweapon");
    prereq.setKey("LONGSWORD");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    final boolean passes = PrereqHandler.passes(prereq, character, null);
    assertTrue(passes);
    longsword.setName("Longsword (Large/Masterwork)");
    assertFalse("Should be an exact match only", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("LONGSWORD (LARGE%");
    assertTrue("Should allow wildcard match", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 48 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreEquipTwoWeaponTest method testWield.

/**
	 * Test wield category tests
	 * @throws Exception
	 */
public void testWield() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Race race = new Race();
    race.setName("Test Race");
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    character.setRace(race);
    LoadContext context = Globals.getContext();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_TWO_HANDS);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equiptwoweapon");
    prereq.setKey("WIELDCATEGORY=OneHanded");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    // Test 3.0 Style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    assertTrue("Weapon is M therefore OneHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.SIZE, largeRef);
    longsword.put(ObjectKey.BASESIZE, largeRef);
    assertFalse("Weapon is L therefore TwoHanded", PrereqHandler.passes(prereq, character, null));
    // Test 3.5 style
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    assertFalse("Weapon is TwoHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    assertTrue("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) WieldCategory(pcgen.core.character.WieldCategory) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 49 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreEquipTwoWeaponTest method testType.

/**
	 * Test equipment type tests
	 * @throws Exception
	 */
public void testType() throws Exception {
    final PlayerCharacter character = getCharacter();
    final Equipment longsword = new Equipment();
    longsword.setName("Longsword");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_TWO_HANDS);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equiptwoweapon");
    prereq.setKey("TYPE=Weapon");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    assertFalse("Equipment has no type", PrereqHandler.passes(prereq, character, null));
    longsword.addType(Type.WEAPON);
    assertTrue("Equipment is weapon", PrereqHandler.passes(prereq, character, null));
    prereq.setKey("TYPE.Armor");
    assertFalse("Equipment is not armor", PrereqHandler.passes(prereq, character, null));
}
Also used : PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment)

Example 50 with PlayerCharacter

use of pcgen.core.PlayerCharacter in project pcgen by PCGen.

the class PreFactSetTest method testFact.

/**
	 * Test the PREFACT code
	 * @throws Exception
	 */
public void testFact() throws Exception {
    final PlayerCharacter character = getCharacter();
    Deity deity = new Deity();
    BuildUtilities.addToFactSet(deity, "PANTHEON", "Greek");
    BuildUtilities.addToFactSet(deity, "PANTHEON", "War");
    deity.setName("Ares");
    character.setDeity(deity);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=Roman");
    assertFalse("Character's deity should not match requirement", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=War");
    assertTrue("Character's deity should match pantheon", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREFACTSET:1,DEITY,PANTHEON=Greek");
    assertTrue("Character's deity should match pantheon", PrereqHandler.passes(prereq, character, null));
}
Also used : Deity(pcgen.core.Deity) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory)

Aggregations

PlayerCharacter (pcgen.core.PlayerCharacter)438 PreParserFactory (pcgen.persistence.lst.prereq.PreParserFactory)89 PCClass (pcgen.core.PCClass)61 LoadContext (pcgen.rules.context.LoadContext)58 Ability (pcgen.core.Ability)54 Equipment (pcgen.core.Equipment)41 PCTemplate (pcgen.core.PCTemplate)38 EquipSet (pcgen.core.character.EquipSet)32 BonusObj (pcgen.core.bonus.BonusObj)29 Race (pcgen.core.Race)28 CharID (pcgen.cdom.enumeration.CharID)25 ExportHandler (pcgen.io.ExportHandler)24 Test (org.junit.Test)20 ArrayList (java.util.ArrayList)16 PreClassTester (plugin.pretokens.test.PreClassTester)16 CDOMObject (pcgen.cdom.base.CDOMObject)15 Skill (pcgen.core.Skill)14 CNAbility (pcgen.cdom.content.CNAbility)13 URI (java.net.URI)11 URISyntaxException (java.net.URISyntaxException)11