Search in sources :

Example 1 with WieldCategory

use of pcgen.core.character.WieldCategory in project pcgen by PCGen.

the class PreEquippedTester method passesPreEquipHandleTokens.

/**
	 * Process the tokens and return the number that is not passed.
	 *
	 * @param prereq
	 * @param character The pc to use.
	 * @param equippedType The equipped type to look for (e.g. Equipment.EQUIPPED_TWO_HANDS)
	 *
	 * @return the number that did not pass
	 * @throws PrerequisiteException
	 */
public int passesPreEquipHandleTokens(final Prerequisite prereq, final PlayerCharacter character, final EquipmentLocation equippedType) throws PrerequisiteException {
    // TODO refactor this code with PreEquipTester
    boolean isEquipped = false;
    if (character.hasEquipment()) {
        String aString = prereq.getKey();
        for (Equipment eq : character.getDisplay().getEquippedEquipmentSet()) {
            //
            if (eq.getLocation() != equippedType) {
                continue;
            }
            if (aString.startsWith("WIELDCATEGORY=") || aString.startsWith("WIELDCATEGORY.")) {
                final WieldCategory wCat = eq.getEffectiveWieldCategory(character);
                if ((wCat != null) && wCat.getKeyName().equalsIgnoreCase(aString.substring(14))) {
                    isEquipped = true;
                    break;
                }
            } else if (//$NON-NLS-1$ //$NON-NLS-2$
            aString.startsWith("TYPE=") || aString.startsWith("TYPE.")) {
                isEquipped = eq.isType(aString);
                break;
            } else //not a TYPE string
            {
                String eqName;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                aString.startsWith("BASEITEM=")) {
                    eqName = eq.getBaseItemName();
                    aString = aString.substring(aString.indexOf(Constants.EQUALS) + 1);
                } else {
                    eqName = eq.getName();
                }
                if (aString.indexOf('%') >= 0) {
                    //handle wildcards (always assume they
                    // end the line)
                    final int percentPos = aString.indexOf('%');
                    if (eqName.regionMatches(true, 0, aString, 0, percentPos)) {
                        isEquipped = true;
                        break;
                    }
                } else if (eqName.equalsIgnoreCase(aString)) {
                    //just a straight String compare
                    isEquipped = true;
                    break;
                }
            }
        }
    }
    final PrerequisiteOperator operator = prereq.getOperator();
    int runningTotal;
    if (operator.equals(PrerequisiteOperator.EQ) || operator.equals(PrerequisiteOperator.GTEQ)) {
        runningTotal = isEquipped ? 1 : 0;
    } else if (operator.equals(PrerequisiteOperator.NEQ) || operator.equals(PrerequisiteOperator.LT)) {
        runningTotal = isEquipped ? 0 : 1;
    } else {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreEquipped.error.invalid_comparison", //$NON-NLS-1$
        prereq.toString()));
    }
    return countedTotal(prereq, runningTotal);
}
Also used : Equipment(pcgen.core.Equipment) WieldCategory(pcgen.core.character.WieldCategory)

Example 2 with WieldCategory

use of pcgen.core.character.WieldCategory in project pcgen by PCGen.

the class GameModeFileLoader method addDefaultWieldCategories.

public static void addDefaultWieldCategories(LoadContext context) throws PersistenceLayerException {
    PreParserFactory prereqParser;
    try {
        prereqParser = PreParserFactory.getInstance();
    } catch (final PersistenceLayerException ple) {
        Logging.errorPrint("Error Initializing PreParserFactory");
        Logging.errorPrint("  " + ple.getMessage(), ple);
        throw new UnreachableError(ple);
    }
    AbstractReferenceContext refContext = context.getReferenceContext();
    Collection<WieldCategory> categories = refContext.getConstructedCDOMObjects(WieldCategory.class);
    WieldCategory light = null;
    WieldCategory twoHanded = null;
    WieldCategory oneHanded = null;
    WieldCategory tooLarge = null;
    WieldCategory tooSmall = null;
    for (final WieldCategory wc : categories) {
        String name = wc.getKeyName();
        if ("Light".equalsIgnoreCase(name)) {
            light = wc;
        }
        if ("TwoHanded".equalsIgnoreCase(name)) {
            twoHanded = wc;
        }
        if ("OneHanded".equalsIgnoreCase(name)) {
            oneHanded = wc;
        }
        if ("TooLarge".equalsIgnoreCase(name)) {
            tooLarge = wc;
        }
        if ("TooSmall".equalsIgnoreCase(name)) {
            tooSmall = wc;
        }
    }
    boolean buildLight = false;
    if (light == null) {
        light = new WieldCategory();
        light.setName("Light");
        refContext.importObject(light);
        buildLight = true;
    }
    boolean buildTwoHanded = false;
    if (twoHanded == null) {
        twoHanded = new WieldCategory();
        twoHanded.setName("TwoHanded");
        refContext.importObject(twoHanded);
        buildTwoHanded = true;
    }
    boolean buildOneHanded = false;
    if (oneHanded == null) {
        oneHanded = new WieldCategory();
        oneHanded.setName("OneHanded");
        refContext.importObject(oneHanded);
        buildOneHanded = true;
    }
    boolean buildTooLarge = false;
    if (tooLarge == null) {
        tooLarge = new WieldCategory();
        tooLarge.setName("TooLarge");
        refContext.importObject(tooLarge);
        buildTooLarge = true;
    }
    boolean buildTooSmall = false;
    if (tooSmall == null) {
        tooSmall = new WieldCategory();
        tooSmall.setName("TooSmall");
        refContext.importObject(tooSmall);
        buildTooSmall = true;
    }
    CDOMDirectSingleRef<WieldCategory> tooSmallRef = CDOMDirectSingleRef.getRef(tooSmall);
    CDOMDirectSingleRef<WieldCategory> lightRef = CDOMDirectSingleRef.getRef(light);
    CDOMDirectSingleRef<WieldCategory> oneHandedRef = CDOMDirectSingleRef.getRef(oneHanded);
    CDOMDirectSingleRef<WieldCategory> twoHandedRef = CDOMDirectSingleRef.getRef(twoHanded);
    CDOMDirectSingleRef<WieldCategory> tooLargeRef = CDOMDirectSingleRef.getRef(tooLarge);
    if (buildLight) {
        light.setHandsRequired(1);
        light.setFinessable(true);
        light.addDamageMult(1, 1.0f);
        light.addDamageMult(2, 1.0f);
        Prerequisite p = prereqParser.parse("PREVARLTEQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+2");
        qo = new QualifiedObject<>(twoHandedRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+3");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        light.addCategorySwitch(qo);
        light.setWieldCategoryStep(1, oneHandedRef);
        light.setWieldCategoryStep(2, twoHandedRef);
    }
    if (buildTwoHanded) {
        twoHanded.setFinessable(false);
        twoHanded.setHandsRequired(2);
        twoHanded.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-3");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        twoHanded.addCategorySwitch(qo);
        twoHanded.setWieldCategoryStep(-2, lightRef);
        twoHanded.setWieldCategoryStep(-1, oneHandedRef);
    }
    if (buildOneHanded) {
        oneHanded.setHandsRequired(1);
        oneHanded.setFinessable(false);
        oneHanded.addDamageMult(1, 1.0f);
        oneHanded.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(twoHandedRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+2");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        oneHanded.addCategorySwitch(qo);
        oneHanded.setWieldCategoryStep(-1, lightRef);
        oneHanded.setWieldCategoryStep(1, twoHandedRef);
    }
    if (buildTooLarge) {
        tooLarge.setFinessable(false);
        tooLarge.setHandsRequired(999);
        tooLarge.setWieldCategoryStep(-3, lightRef);
        tooLarge.setWieldCategoryStep(-2, oneHandedRef);
        tooLarge.setWieldCategoryStep(-1, twoHandedRef);
        tooLarge.setWieldCategoryStep(0, twoHandedRef);
    }
    if (buildTooSmall) {
        tooSmall.setFinessable(false);
        tooSmall.setHandsRequired(2);
        tooSmall.addDamageMult(2, 1.5f);
        Prerequisite p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-3");
        QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(tooSmallRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-2");
        qo = new QualifiedObject<>(lightRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVAREQ:EQUIP.SIZE.INT,PC.SIZE.INT-1");
        qo = new QualifiedObject<>(oneHandedRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        p = prereqParser.parse("PREVARGTEQ:EQUIP.SIZE.INT,PC.SIZE.INT+1");
        qo = new QualifiedObject<>(tooLargeRef);
        qo.addPrerequisite(p);
        tooSmall.addCategorySwitch(qo);
        tooSmall.setWieldCategoryStep(-2, lightRef);
        tooSmall.setWieldCategoryStep(-1, oneHandedRef);
    }
}
Also used : PreParserFactory(pcgen.persistence.lst.prereq.PreParserFactory) AbstractReferenceContext(pcgen.rules.context.AbstractReferenceContext) UnreachableError(pcgen.base.lang.UnreachableError) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef) QualifiedObject(pcgen.core.QualifiedObject) WieldCategory(pcgen.core.character.WieldCategory) Prerequisite(pcgen.core.prereq.Prerequisite)

Example 3 with WieldCategory

use of pcgen.core.character.WieldCategory 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 4 with WieldCategory

use of pcgen.core.character.WieldCategory in project pcgen by PCGen.

the class WeaponTokenTest method setUp.

/*
	 * @see TestCase#setUp()
	 */
@Override
protected void setUp() throws Exception {
    super.setUp();
    PlayerCharacter character = getCharacter();
    LoadContext context = Globals.getContext();
    //Stats
    setPCStat(character, str, 15);
    setPCStat(character, dex, 16);
    setPCStat(character, intel, 17);
    BonusObj aBonus = Bonus.newBonus(context, "COMBAT|TOHIT.Melee|STR|TYPE=Ability");
    if (aBonus != null) {
        str.addToListFor(ListKey.BONUS, aBonus);
    }
    aBonus = Bonus.newBonus(context, "COMBAT|DAMAGE.Melee,DAMAGE.Thrown|STR");
    if (aBonus != null) {
        str.addToListFor(ListKey.BONUS, aBonus);
    }
    aBonus = Bonus.newBonus(context, "COMBAT|DAMAGEMULT:0|0.5*(STR>=0)");
    if (aBonus != null) {
        str.addToListFor(ListKey.BONUS, aBonus);
    }
    aBonus = Bonus.newBonus(context, "COMBAT|DAMAGEMULT:1|1");
    if (aBonus != null) {
        str.addToListFor(ListKey.BONUS, aBonus);
    }
    aBonus = Bonus.newBonus(context, "COMBAT|DAMAGEMULT:2|1.5*(STR>=0)");
    if (aBonus != null) {
        str.addToListFor(ListKey.BONUS, aBonus);
    }
    aBonus = Bonus.newBonus(context, "MODSKILLPOINTS|NUMBER|INT");
    if (aBonus != null) {
        intel.addToListFor(ListKey.BONUS, aBonus);
    }
    // Race
    Race testRace = new Race();
    testRace.setName("TestRace");
    testRace.put(StringKey.KEY_NAME, "KEY_TEST_RACE");
    CDOMDirectSingleRef<SizeAdjustment> mediumRef = CDOMDirectSingleRef.getRef(medium);
    CDOMDirectSingleRef<SizeAdjustment> largeRef = CDOMDirectSingleRef.getRef(large);
    testRace.put(FormulaKey.SIZE, new FixedSizeFormula(mediumRef));
    character.setRace(testRace);
    // Class
    PCClass myClass = new PCClass();
    myClass.setName("My Class");
    myClass.put(StringKey.KEY_NAME, "KEY_MY_CLASS");
    myClass.put(FormulaKey.START_SKILL_POINTS, FormulaFactory.getFormulaFor(3));
    final BonusObj babClassBonus = Bonus.newBonus(context, "COMBAT|BASEAB|CL+15");
    myClass.getOriginalClassLevel(1).addToListFor(ListKey.BONUS, babClassBonus);
    context.getReferenceContext().importObject(myClass);
    character.incrementClassLevel(1, myClass, true);
    character.calcActiveBonuses();
    dblWpn = new Equipment();
    dblWpn.setName("DoubleWpn");
    dblWpn.put(StringKey.KEY_NAME, "KEY_DOUBLE_WPN");
    TestHelper.addType(dblWpn, "Weapon.Melee.Martial.Double.Standard.Bludgeoning.Flail");
    dblWpn.getEquipmentHead(1).put(StringKey.DAMAGE, "1d10");
    dblWpn.getEquipmentHead(2).put(StringKey.DAMAGE, "1d6");
    dblWpn.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    dblWpn.getEquipmentHead(2).put(IntegerKey.CRIT_MULT, 2);
    dblWpn.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 1);
    dblWpn.getEquipmentHead(2).put(IntegerKey.CRIT_RANGE, 1);
    dblWpn.put(IntegerKey.SLOTS, 2);
    dblWpn.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    dblWpn.put(ObjectKey.SIZE, mediumRef);
    dblWpn.put(ObjectKey.BASESIZE, mediumRef);
    character.addEquipment(dblWpn);
    EquipSet def = new EquipSet("0.1", "Default");
    character.addEquipSet(def);
    EquipSet es = new EquipSet("0.1.1", "Double Weapon", dblWpn.getKeyName(), dblWpn);
    character.addEquipSet(es);
    character.setCalcEquipmentList();
    WeaponProf wp = new WeaponProf();
    wp.setName("DoubleWpn");
    wp.put(IntegerKey.HANDS, Constants.HANDS_SIZE_DEPENDENT);
    context.getReferenceContext().importObject(wp);
    wp = new WeaponProf();
    wp.setName("Sword (Bastard)");
    wp.put(StringKey.KEY_NAME, "KEY_Sword (Bastard)");
    TestHelper.addType(wp, "MARTIAL.EXOTIC");
    context.getReferenceContext().importObject(wp);
    bastardSword = new Equipment();
    bastardSword.setName("Sword, Bastard");
    bastardSword.put(StringKey.KEY_NAME, "BASTARD_SWORD");
    bastardSword.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(wp));
    TestHelper.addType(bastardSword, "Weapon.Melee.Martial.Exotic.Standard.Slashing.Sword");
    bastardSword.getEquipmentHead(1).put(StringKey.DAMAGE, "1d10");
    bastardSword.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    bastardSword.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 2);
    bastardSword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    bastardSword.put(ObjectKey.SIZE, mediumRef);
    bastardSword.put(ObjectKey.BASESIZE, mediumRef);
    wp = new WeaponProf();
    wp.setName("Longsword");
    wp.put(StringKey.KEY_NAME, "KEY_LONGSWORD");
    wp.addToListFor(ListKey.TYPE, Type.getConstant("MARTIAL"));
    context.getReferenceContext().importObject(wp);
    largeSword = new Equipment();
    largeSword.setName("Longsword (Large)");
    largeSword.put(StringKey.KEY_NAME, "KEY_LONGSWORD_LARGE");
    largeSword.put(StringKey.OUTPUT_NAME, "Longsword (Large)");
    largeSword.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(wp));
    TestHelper.addType(largeSword, "Weapon.Melee.Martial.Standard.Slashing.Sword");
    largeSword.getEquipmentHead(1).put(StringKey.DAMAGE, "1d10");
    largeSword.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    largeSword.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 2);
    largeSword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    largeSword.put(ObjectKey.SIZE, largeRef);
    largeSword.put(ObjectKey.BASESIZE, largeRef);
    fineSword = new Equipment();
    fineSword.setName("Longsword (Fine)");
    fineSword.put(StringKey.KEY_NAME, "KEY_LONGSWORD_FINE");
    fineSword.put(StringKey.OUTPUT_NAME, "Longsword (Fine)");
    fineSword.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(wp));
    TestHelper.addType(fineSword, "Weapon.Melee.Martial.Standard.Slashing.Sword.Finesseable");
    fineSword.getEquipmentHead(1).put(StringKey.DAMAGE, "1d10");
    fineSword.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    fineSword.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 2);
    fineSword.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    fineSword.put(ObjectKey.SIZE, mediumRef);
    fineSword.put(ObjectKey.BASESIZE, mediumRef);
    WeaponProf spearwp = new WeaponProf();
    spearwp.setName("Spear");
    spearwp.put(StringKey.KEY_NAME, "KEY_SPEAR");
    spearwp.addToListFor(ListKey.TYPE, Type.getConstant("MARTIAL"));
    context.getReferenceContext().importObject(spearwp);
    longSpear = new Equipment();
    longSpear.setName("Longspear");
    longSpear.put(StringKey.KEY_NAME, "KEY_LONGSPEAR");
    longSpear.put(StringKey.OUTPUT_NAME, "Longspear");
    longSpear.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(spearwp));
    TestHelper.addType(longSpear, "Weapon.Melee.Martial.Standard.Piercing.Spear");
    longSpear.getEquipmentHead(1).put(StringKey.DAMAGE, "1d6");
    longSpear.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    longSpear.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 1);
    longSpear.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded"));
    longSpear.put(ObjectKey.SIZE, mediumRef);
    longSpear.put(ObjectKey.BASESIZE, mediumRef);
    longSpear.put(IntegerKey.REACH, 10);
    GameMode gm = SettingsHandler.getGame();
    RuleCheck rc = new RuleCheck();
    rc.setName("SIZECAT");
    gm.getModeContext().getReferenceContext().importObject(rc);
    SettingsHandler.setRuleCheck("SIZECAT", true);
    gm.setWCStepsFormula("EQUIP.SIZE.INT-PC.SIZE.INT");
    gm.setWeaponReachFormula("(RACEREACH+(max(0,REACH-5)))*REACHMULT");
    wp = new WeaponProf();
    wp.setName("Silly Bite");
    wp.put(StringKey.KEY_NAME, "SillyBite");
    //wp.setTypeInfo("Weapon.Natural.Melee.Finesseable.Bludgeoning.Piercing.Slashing");
    wp.addToListFor(ListKey.TYPE, Type.NATURAL);
    context.getReferenceContext().importObject(wp);
    bite = new Equipment();
    bite.setName("Silly Bite");
    bite.put(StringKey.KEY_NAME, "SillyBite");
    bite.put(StringKey.OUTPUT_NAME, "Silly Bite (For Test)");
    TestHelper.addType(bite, "Weapon.Natural.Melee.Finesseable.Bludgeoning.Piercing.Slashing");
    bite.put(ObjectKey.WEIGHT, BigDecimal.ZERO);
    bite.put(ObjectKey.SIZE, mediumRef);
    bite.put(ObjectKey.BASESIZE, mediumRef);
    aBonus = Bonus.newBonus(context, "WEAPON|ATTACKS|" + 7);
    if (aBonus != null) {
        bite.addToListFor(ListKey.BONUS, aBonus);
    }
    bite.put(IntegerKey.SLOTS, 0);
    bite.setQty(Float.valueOf(1));
    bite.setNumberCarried(1.0f);
    bite.put(ObjectKey.ATTACKS_PROGRESS, false);
    bite.getEquipmentHead(1).put(StringKey.DAMAGE, "1d10");
    bite.getEquipmentHead(1).put(IntegerKey.CRIT_MULT, 2);
    bite.getEquipmentHead(1).put(IntegerKey.CRIT_RANGE, 2);
    bite.put(ObjectKey.WIELD, context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded"));
    bite.put(ObjectKey.WEAPON_PROF, new CDOMDirectSingleRef<>(wp));
    longbow = new Equipment();
    longbow.setName("Longbow");
    TestHelper.addType(longbow, "Weapon.Martial.Ranged.Standard.Piercing.Container.Projectile.Bow.Longbow");
    longbow.put(ObjectKey.TOTAL_CAPACITY, Capacity.ANY);
    longbow.put(ObjectKey.CONTAINER_WEIGHT_CAPACITY, BigDecimal.ONE);
    longbow.addToListFor(ListKey.CAPACITY, new Capacity("Arrow", BigDecimal.ONE));
    longbow.setQty(Float.valueOf(1));
    longbow.setNumberCarried(1.0f);
    arrow = new Equipment();
    arrow.setName("Arrow");
    TestHelper.addType(arrow, "Ammunition.Standard.Arrow.Individual");
    // Weild categories
    WieldCategory twoHanded = context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded");
    twoHanded.setSizeDifference(1);
    // Equip mods
    EquipmentModifier eqMod = new EquipmentModifier();
    eqMod.setName("Plus 1 Enhancement");
    eqMod.put(StringKey.KEY_NAME, "PLUS1W");
    TestHelper.addType(eqMod, "Ammunition.Weapon");
    eqMod.put(IntegerKey.PLUS, 1);
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Enhancement");
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Magic");
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Plus1");
    aBonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|1|TYPE=Enhancement");
    if (aBonus != null) {
        eqMod.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(eqMod);
    eqMod = new EquipmentModifier();
    eqMod.setName("Plus 2 Enhancement");
    eqMod.put(StringKey.KEY_NAME, "PLUS2W");
    TestHelper.addType(eqMod, "Ammunition.Weapon");
    eqMod.put(IntegerKey.PLUS, 2);
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Enhancement");
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Magic");
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Plus2");
    aBonus = Bonus.newBonus(context, "WEAPON|DAMAGE,TOHIT|2|TYPE=Enhancement");
    if (aBonus != null) {
        eqMod.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(eqMod);
    eqMod = new EquipmentModifier();
    eqMod.setName("Masterwork");
    eqMod.put(StringKey.KEY_NAME, "MWORKW");
    TestHelper.addType(eqMod, "Ammunition.Weapon");
    eqMod.addToListFor(ListKey.ITEM_TYPES, "Masterwork");
    aBonus = Bonus.newBonus(context, "WEAPON|TOHIT|1|TYPE=Enhancement");
    if (aBonus != null) {
        eqMod.addToListFor(ListKey.BONUS, aBonus);
    }
    context.getReferenceContext().importObject(eqMod);
    PCTemplate pct = new PCTemplate();
    context.unconditionallyProcess(pct, "AUTO", "WEAPONPROF|KEY_Sword (Bastard)|KEY_LONGSWORD|SillyBite");
    character.addTemplate(pct);
    wpnBonusPct = new PCTemplate();
    context.unconditionallyProcess(wpnBonusPct, "BONUS", "WEAPONPROF=DoubleWpn|DAMAGE|3");
    context.unconditionallyProcess(wpnBonusPct, "BONUS", "WEAPONPROF=DoubleWpn|TOHIT|4");
    wpnBonusAbility = TestHelper.makeAbility("FEAT_BONUS", AbilityCategory.FEAT, "General");
    context.unconditionallyProcess(wpnBonusAbility, "BONUS", "WEAPONPROF=DoubleWpn|DAMAGE|1");
    context.unconditionallyProcess(wpnBonusAbility, "BONUS", "WEAPONPROF=DoubleWpn|TOHIT|2");
    assertTrue(context.getReferenceContext().resolveReferences(null));
}
Also used : BonusObj(pcgen.core.bonus.BonusObj) EquipSet(pcgen.core.character.EquipSet) WeaponProf(pcgen.core.WeaponProf) PCClass(pcgen.core.PCClass) FixedSizeFormula(pcgen.cdom.formula.FixedSizeFormula) GameMode(pcgen.core.GameMode) EquipmentModifier(pcgen.core.EquipmentModifier) PlayerCharacter(pcgen.core.PlayerCharacter) Equipment(pcgen.core.Equipment) Capacity(pcgen.cdom.helper.Capacity) Race(pcgen.core.Race) LoadContext(pcgen.rules.context.LoadContext) WieldCategory(pcgen.core.character.WieldCategory) RuleCheck(pcgen.core.RuleCheck) PCTemplate(pcgen.core.PCTemplate) SizeAdjustment(pcgen.core.SizeAdjustment)

Example 5 with WieldCategory

use of pcgen.core.character.WieldCategory in project pcgen by PCGen.

the class PreEquipBothTest 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_BOTH);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equipboth");
    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)

Aggregations

WieldCategory (pcgen.core.character.WieldCategory)16 Equipment (pcgen.core.Equipment)9 SizeAdjustment (pcgen.core.SizeAdjustment)7 LoadContext (pcgen.rules.context.LoadContext)7 FixedSizeFormula (pcgen.cdom.formula.FixedSizeFormula)6 PlayerCharacter (pcgen.core.PlayerCharacter)6 Race (pcgen.core.Race)6 StringTokenizer (java.util.StringTokenizer)4 CDOMSingleRef (pcgen.cdom.reference.CDOMSingleRef)2 QualifiedObject (pcgen.core.QualifiedObject)2 WeaponProf (pcgen.core.WeaponProf)2 File (java.io.File)1 BigDecimal (java.math.BigDecimal)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 UnreachableError (pcgen.base.lang.UnreachableError)1 Capacity (pcgen.cdom.helper.Capacity)1 EquipmentHead (pcgen.cdom.inst.EquipmentHead)1 EquipmentModifier (pcgen.core.EquipmentModifier)1