Search in sources :

Example 6 with WieldCategory

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

the class DownToken method parseTokenWithSeparator.

@Override
protected ParseResult parseTokenWithSeparator(LoadContext context, WieldCategory wc, String value) {
    StringTokenizer st = new StringTokenizer(value, Constants.PIPE);
    int count = -1;
    while (st.hasMoreTokens()) {
        CDOMSingleRef<WieldCategory> stepCat = context.getReferenceContext().getCDOMReference(WIELD_CATEGORY_CLASS, st.nextToken());
        wc.setWieldCategoryStep(count--, stepCat);
    }
    return ParseResult.SUCCESS;
}
Also used : StringTokenizer(java.util.StringTokenizer) WieldCategory(pcgen.core.character.WieldCategory)

Example 7 with WieldCategory

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

the class Equipment method getEffectiveWieldCategory.

/**
	 * Gets the minimum WieldCategory this weapon can be used at. Accounts for
	 * all modifiers that affect WieldCategory. 3.0 weapon sizes are mapped to
	 * appropriate WieldCategories.
	 * 
	 * @param aPC The PlayerCharacter using the weapon
	 * @return The minimum WieldCategory required to use the weapon.
	 */
public WieldCategory getEffectiveWieldCategory(final PlayerCharacter aPC) {
    CDOMSingleRef<WeaponProf> ref = get(ObjectKey.WEAPON_PROF);
    WeaponProf wp = ref == null ? null : ref.get();
    WieldCategory wCat = get(ObjectKey.WIELD);
    if (wCat != null && !Globals.checkRule(RuleConstants.SIZEOBJ)) {
        // Get the starting effective wield category
        wCat = wCat.adjustForSize(aPC, this);
    } else {
        int pcSize = aPC.sizeInt();
        if (wp != null) {
            pcSize += aPC.getTotalBonusTo("WEAPONPROF=" + wp.getKeyName(), "PCSIZE");
        }
        int sizeDiff;
        if (wCat != null && Globals.checkRule(RuleConstants.SIZEOBJ)) {
            // In this case we have a 3.5 style equipments size.
            // We need to map to a 3.0 style
            sizeDiff = wCat.getObjectSizeInt(this) - pcSize;
        } else {
            sizeDiff = sizeInt() - pcSize;
        }
        if (sizeDiff > 1) {
            wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TooLarge");
        } else if (sizeDiff == 1) {
            wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "TwoHanded");
        } else if (sizeDiff == 0) {
            wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "OneHanded");
        } else {
            wCat = Globals.getContext().getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, "Light");
        }
    }
    int aBump = 0;
    // TODO Remove this code when support for this "feature" goes away
    if (wp != null) {
        int iHands = wp.getSafe(IntegerKey.HANDS);
        if (iHands == Constants.HANDS_SIZE_DEPENDENT) {
            if (aPC.sizeInt() > sizeInt()) {
                iHands = 1;
            } else {
                iHands = 2;
            }
        }
        while (wCat.getHandsRequired() < iHands) {
            wCat = wCat.getWieldCategoryStep(1);
        }
        // See if there is a bonus associated with just this weapon
        final String expProfName = wp.getKeyName();
        aBump += (int) aPC.getTotalBonusTo("WEAPONPROF=" + expProfName, "WIELDCATEGORY");
        // loops for each equipment type
        int modWield = 0;
        for (String eqType : typeList()) {
            final StringBuilder sB = new StringBuilder("WEAPONPROF=TYPE.");
            sB.append(eqType);
            // get the type bonus (ex TYPE.MARTIAL)
            final int i = (int) aPC.getTotalBonusTo(sB.toString(), "WIELDCATEGORY");
            // get the highest bonus
            if (i < modWield) {
                modWield = i;
            }
        }
        aBump += modWield;
    }
    // or a bonus from the weapon itself
    aBump += (int) bonusTo(aPC, "WEAPON", "WIELDCATEGORY", true);
    if (aBump == 0) {
        return wCat;
    }
    return wCat.getWieldCategoryStep(aBump);
}
Also used : WieldCategory(pcgen.core.character.WieldCategory)

Example 8 with WieldCategory

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

the class WieldCategoryLoader method parseLine.

/**
	 * Parse the WIELDCATEGORY line
	 * 
	 * @param gameMode
	 * @param lstLine
	 * @throws PersistenceLayerException
	 */
public void parseLine(GameMode gameMode, String lstLine, URI source) throws PersistenceLayerException {
    LoadContext context = gameMode.getModeContext();
    StringTokenizer colToken = new StringTokenizer(lstLine, SystemLoader.TAB_DELIM);
    WieldCategory cat = null;
    String preKey = null;
    CDOMSingleRef<WieldCategory> preVal = null;
    while (colToken.hasMoreTokens()) {
        final String colString = colToken.nextToken().trim();
        final int idxColon = colString.indexOf(':');
        String key = "";
        try {
            key = colString.substring(0, idxColon);
        } catch (StringIndexOutOfBoundsException e) {
        // TODO Deal with Exception
        }
        if (key.equals("WIELDCATEGORY")) {
            final String value = colString.substring(idxColon + 1).trim();
            cat = context.getReferenceContext().silentlyGetConstructedCDOMObject(WieldCategory.class, value);
            if (cat == null) {
                cat = new WieldCategory();
                cat.setName(value.intern());
                gameMode.addWieldCategory(cat);
            }
        } else if (colString.startsWith("PREVAR")) {
            //TODO ensure preKey is null
            // a PREVARxx formula used to switch
            // weapon categories based on size
            preKey = colString;
        } else if (key.equals("SWITCH")) {
            //TODO ensure preVal is null
            // If matches PRE, switch category to this
            preVal = context.getReferenceContext().getCDOMReference(WieldCategory.class, colString.substring(7));
        } else {
            final String value = colString.substring(idxColon + 1).trim();
            if (context.processToken(cat, key, value)) {
                context.commit();
            } else {
                context.rollback();
                Logging.replayParsedMessages();
            }
            Logging.clearParseMessages();
        }
    }
    //TODO Error checking if preVal w/o preKey, vice versa, etc.
    if ((cat != null) && (preVal != null) && (preKey != null)) {
        try {
            QualifiedObject<CDOMSingleRef<WieldCategory>> qo = new QualifiedObject<>(preVal);
            qo.addPrerequisite(prereqParser.parse(preKey));
            cat.addCategorySwitch(qo);
        } catch (PersistenceLayerException ple) {
            Logging.errorPrint("Error parsing Prerequisite in " + source + ": " + preKey + "\n  " + ple.getMessage());
        }
    }
}
Also used : PersistenceLayerException(pcgen.persistence.PersistenceLayerException) StringTokenizer(java.util.StringTokenizer) QualifiedObject(pcgen.core.QualifiedObject) LoadContext(pcgen.rules.context.LoadContext) WieldCategory(pcgen.core.character.WieldCategory) CDOMSingleRef(pcgen.cdom.reference.CDOMSingleRef)

Example 9 with WieldCategory

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

the class PreEquipPrimaryTest 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("Dagger");
    character.addEquipment(longsword);
    longsword.setIsEquipped(true, character);
    longsword.setLocation(EquipmentLocation.EQUIPPED_PRIMARY);
    character.doAfavorForAunitTestThatIgnoresEquippingRules();
    Prerequisite prereq = new Prerequisite();
    prereq.setKind("equipprimary");
    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 10 with WieldCategory

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

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