Search in sources :

Example 36 with SizeAdjustment

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

the class PreEquipSecondaryTest 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> smallRef = CDOMDirectSingleRef.getRef(small);
    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_SECONDARY);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equipsecondary");
    prereq.setKey("WIELDCATEGORY=Light");
    prereq.setOperand("1");
    prereq.setOperator(PrerequisiteOperator.EQ);
    // Test 3.0 Style
    longsword.put(ObjectKey.SIZE, smallRef);
    longsword.put(ObjectKey.BASESIZE, smallRef);
    assertTrue("Weapon is S therefore Light", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.SIZE, mediumRef);
    longsword.put(ObjectKey.BASESIZE, mediumRef);
    assertFalse("Weapon is M therefore OneHanded", 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, "OneHanded"));
    assertFalse("Weapon is OneHanded", PrereqHandler.passes(prereq, character, null));
    longsword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light"));
    assertTrue("Weapon is Light", 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 37 with SizeAdjustment

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

the class PreEquipTest 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);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equip");
    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 38 with SizeAdjustment

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

the class PreHDTest method testHD.

/**
	 * Test the PREHD code
	 * @throws Exception
	 */
public void testHD() throws Exception {
    race.setName("Human");
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    race.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    Globals.getContext().getReferenceContext().importObject(race);
    PCClass raceClass = new PCClass();
    raceClass.setName("Race Class");
    raceClass.put(StringKey.KEY_NAME, "RaceClass");
    raceClass.put(ObjectKey.IS_MONSTER, true);
    Globals.getContext().getReferenceContext().importObject(raceClass);
    race.put(ObjectKey.MONSTER_CLASS, new LevelCommandFactory(CDOMDirectSingleRef.getRef(raceClass), FormulaFactory.getFormulaFor(3)));
    final PlayerCharacter character = getCharacter();
    character.setRace(race);
    Prerequisite prereq;
    final PreParserFactory factory = PreParserFactory.getInstance();
    prereq = factory.parse("PREHD:MIN=4");
    assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHD:MIN=3");
    assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHD:MIN=1,MAX=3");
    assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHD:MIN=3,MAX=6");
    assertTrue("Character has 3 HD", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHD:MIN=4,MAX=7");
    assertFalse("Character doesn't have 4 HD", PrereqHandler.passes(prereq, character, null));
    prereq = factory.parse("PREHD:MIN=1,MAX=2");
    assertFalse("Character doesn't have 2 or less HD", PrereqHandler.passes(prereq, character, null));
}
Also used : LevelCommandFactory(pcgen.cdom.content.LevelCommandFactory) PlayerCharacter(pcgen.core.PlayerCharacter) PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) PCClass(pcgen.core.PCClass) SizeAdjustment(pcgen.core.SizeAdjustment) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula)

Example 39 with SizeAdjustment

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

the class WeaponhToken method getWeaponEquipment.

/**
	 * Create a fake Unarmed Strike equipment so we don't need it in the .lst files anymore
	 *
	 * @param display The character used to generate the size.
	 * @return The Unarmed Strike equipment.
	 */
public static Equipment getWeaponEquipment(CharacterDisplay display) {
    // Creating a fake Unarmed Strike equipment so we
    // don't need it in the .lst files anymore
    WeaponProf wp = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WeaponProf.class, "Unarmed Strike");
    if (wp == null) {
        wp = new WeaponProf();
        wp.setName(LanguageBundle.getString("Equipment.UnarmedStrike"));
        wp.put(StringKey.KEY_NAME, "Unarmed Strike");
        wp.addToListFor(ListKey.TYPE, Type.SIMPLE);
        Globals.getContext().getReferenceContext().importObject(wp);
    }
    Equipment eq = new Equipment();
    eq.setName(LanguageBundle.getString("Equipment.UnarmedStrike"));
    eq.put(StringKey.KEY_NAME, "KEY_Unarmed Strike");
    eq.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(wp));
    eq.put(StringKey.OUTPUT_NAME, LanguageBundle.getString("Equipment.UnarmedStrike"));
    eq.addType(Type.WEAPON);
    eq.addType(Type.MELEE);
    eq.addType(Type.SIMPLE);
    eq.addType(Type.UNARMED);
    eq.addType(Type.SUBDUAL);
    eq.addType(Type.STANDARD);
    eq.addType(Type.MONK);
    eq.addType(Type.BLUDGEONING);
    WieldCategory lightWC = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light");
    if (lightWC == null) {
    // Error?
    } else {
        eq.put(ObjectKey.WIELD, lightWC);
    }
    eq.put(ObjectKey.COST, BigDecimal.ZERO);
    eq.put(ObjectKey.CURRENT_COST, BigDecimal.ZERO);
    eq.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
    EquipmentHead head = eq.getEquipmentHead(1);
    head.put(StringKey.DAMAGE, "1d1");
    head.put(IntegerKey.CRIT_MULT, 2);
    head.put(IntegerKey.CRIT_RANGE, 1);
    eq.put(ObjectKey.MOD_CONTROL, EqModControl.NO);
    SizeAdjustment sa = display.getSizeAdjustment();
    CDOMDirectSingleRef<SizeAdjustment> ref = CDOMDirectSingleRef.getRef(sa);
    eq.put(ObjectKey.SIZE, ref);
    eq.put(ObjectKey.BASESIZE, ref);
    return eq;
}
Also used : EquipmentHead(pcgen.cdom.inst.EquipmentHead) Equipment(pcgen.core.Equipment) WeaponProf(pcgen.core.WeaponProf) WieldCategory(pcgen.core.character.WieldCategory) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 40 with SizeAdjustment

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

the class SizeTokenTest method setUp.

@Override
@Before
public void setUp() throws PersistenceLayerException, URISyntaxException {
    super.setUp();
    SizeAdjustment ps = BuildUtilities.createSize("S", 0);
    primaryContext.getReferenceContext().importObject(ps);
    SizeAdjustment pm = BuildUtilities.createSize("M", 1);
    primaryContext.getReferenceContext().importObject(pm);
    SizeAdjustment ss = BuildUtilities.createSize("S", 0);
    secondaryContext.getReferenceContext().importObject(ss);
    SizeAdjustment sm = BuildUtilities.createSize("M", 1);
    secondaryContext.getReferenceContext().importObject(sm);
}
Also used : SizeAdjustment(pcgen.core.SizeAdjustment) Before(org.junit.Before)

Aggregations

SizeAdjustment (pcgen.core.SizeAdjustment)43 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)14 Equipment (pcgen.core.Equipment)11 Race (pcgen.core.Race)10 LoadContext (pcgen.rules.context.LoadContext)10 PlayerCharacter (pcgen.core.PlayerCharacter)8 Before (org.junit.Before)7 WieldCategory (pcgen.core.character.WieldCategory)7 Formula (pcgen.base.formula.Formula)3 LevelCommandFactory (pcgen.cdom.content.LevelCommandFactory)3 Campaign (pcgen.core.Campaign)3 Description (pcgen.core.Description)3 GameMode (pcgen.core.GameMode)3 PCClass (pcgen.core.PCClass)3 Prerequisite (pcgen.core.prereq.Prerequisite)3 AbstractReferenceContext (pcgen.rules.context.AbstractReferenceContext)3 BigDecimal (java.math.BigDecimal)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 StringTokenizer (java.util.StringTokenizer)2