Search in sources :

Example 11 with WieldCategory

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

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

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

the class UpToken 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 14 with WieldCategory

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

the class PreEquipTester method passes.

/*
	 * (non-Javadoc)
	 *
	 * @see pcgen.core.prereq.PrerequisiteTest#passes(pcgen.core.PlayerCharacter)
	 */
@Override
public int passes(final Prerequisite prereq, final PlayerCharacter character, CDOMObject source) throws PrerequisiteException {
    int runningTotal = 0;
    final int number;
    try {
        number = Integer.parseInt(prereq.getOperand());
    } catch (NumberFormatException exceptn) {
        throw new PrerequisiteException(LanguageBundle.getFormattedString("PreFeat.error", //$NON-NLS-1$
        prereq.toString()));
    }
    CharacterDisplay display = character.getDisplay();
    if (display.hasEquipment()) {
        String targetEquip = prereq.getKey();
        for (Equipment eq : display.getEquippedEquipmentSet()) {
            if (targetEquip.startsWith("WIELDCATEGORY=") || targetEquip.startsWith("WIELDCATEGORY.")) {
                final WieldCategory wCat = eq.getEffectiveWieldCategory(character);
                if ((wCat != null) && wCat.getKeyName().equalsIgnoreCase(targetEquip.substring(14))) {
                    ++runningTotal;
                    break;
                }
            } else if (//$NON-NLS-1$ //$NON-NLS-2$
            targetEquip.startsWith("TYPE=") || targetEquip.startsWith("TYPE.")) {
                StringTokenizer tok = new StringTokenizer(targetEquip.substring(5).toUpperCase(), ".");
                boolean match = false;
                if (tok.hasMoreTokens()) {
                    match = true;
                }
                //
                while (tok.hasMoreTokens()) {
                    final String type = tok.nextToken();
                    if (!eq.isType(type)) {
                        match = false;
                        break;
                    }
                }
                if (match) {
                    ++runningTotal;
                    break;
                }
            } else //not a TYPE string
            {
                String eqName;
                if (//$NON-NLS-1$ //$NON-NLS-2$
                targetEquip.startsWith("BASEITEM=")) {
                    eqName = eq.getBaseItemName().toUpperCase();
                    targetEquip = targetEquip.substring(targetEquip.indexOf(Constants.EQUALS) + 1);
                } else {
                    eqName = eq.getName().toUpperCase();
                }
                if (targetEquip.indexOf('%') >= 0) {
                    //handle wildcards (always assume
                    // they end the line)
                    final int percentPos = targetEquip.indexOf('%');
                    final String substring = targetEquip.substring(0, percentPos).toUpperCase();
                    if ((eqName.startsWith(substring))) {
                        ++runningTotal;
                        break;
                    }
                } else if (eqName.equalsIgnoreCase(targetEquip)) {
                    //just a straight String compare
                    ++runningTotal;
                    break;
                }
            }
        }
    }
    runningTotal = prereq.getOperator().compare(runningTotal, number);
    return countedTotal(prereq, runningTotal);
}
Also used : PrerequisiteException(pcgen.core.prereq.PrerequisiteException) StringTokenizer(java.util.StringTokenizer) Equipment(pcgen.core.Equipment) CharacterDisplay(pcgen.core.display.CharacterDisplay) WieldCategory(pcgen.core.character.WieldCategory)

Example 15 with WieldCategory

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

the class Gui2InfoFactory method getEquipmentHtmlInfo.

private HtmlInfoBuilder getEquipmentHtmlInfo(Equipment equip) {
    final StringBuilder title = new StringBuilder(50);
    title.append(OutputNameFormatting.piString(equip, false));
    if (!equip.longName().equals(equip.getName())) {
        title.append("(").append(equip.longName()).append(")");
    }
    final HtmlInfoBuilder b = new HtmlInfoBuilder(null, false);
    File icon = equip.getIcon();
    if (icon != null) {
        b.appendIconElement(icon.toURI().toString());
    }
    b.appendTitleElement(title.toString());
    b.appendLineBreak();
    String baseName = equip.getBaseItemName();
    if (StringUtils.isNotEmpty(baseName) && !baseName.equals(equip.getName())) {
        //$NON-NLS-1$
        b.appendI18nElement(//$NON-NLS-1$
        "in_igInfoLabelTextBaseItem", baseName);
        b.appendLineBreak();
    }
    //$NON-NLS-1$
    b.appendI18nElement(//$NON-NLS-1$
    "in_igInfoLabelTextType", StringUtil.join(equip.getTrueTypeList(true), ". "));
    appendFacts(b, equip);
    //
    if (equip.isWeapon() || equip.get(ObjectKey.WIELD) != null) {
        b.appendLineBreak();
        final WieldCategory wCat = equip.getEffectiveWieldCategory(pc);
        if (wCat != null) {
            //$NON-NLS-1$
            b.appendI18nElement(//$NON-NLS-1$
            "in_igInfoLabelTextWield", wCat.getDisplayName());
        }
    }
    //
    if (equip.isWeapon() || equip.isArmor() || equip.isShield()) {
        b.appendLineBreak();
        final String value = (pc.isProficientWith(equip) && equip.meetsPreReqs(pc)) ? //$NON-NLS-1$
        LanguageBundle.getString("in_igInfoLabelTextYes") : (SettingsHandler.getPrereqFailColorAsHtmlStart() + //$NON-NLS-1$
        LanguageBundle.getString("in_igInfoLabelTextNo") + SettingsHandler.getPrereqFailColorAsHtmlEnd());
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextProficient", value);
    }
    final String cString = PrerequisiteUtilities.preReqHTMLStringsForList(pc, null, equip.getPrerequisiteList(), false);
    if (!cString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextReq", cString);
    }
    BigDecimal cost = equip.getCost(pc);
    if (cost != BigDecimal.ZERO) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igEqModelColCost", COST_FMT.format(cost.doubleValue()));
        b.append(" ");
        b.append(SettingsHandler.getGame().getCurrencyDisplay());
    }
    String bString = Globals.getGameModeUnitSet().displayWeightInUnitSet(equip.getWeight(pc).doubleValue());
    if (!bString.isEmpty()) {
        b.appendLineBreak();
        bString += Globals.getGameModeUnitSet().getWeightUnit();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextWeight", bString);
    }
    Integer a = EqToken.getMaxDexTokenInt(pc, equip);
    if (a.intValue() != Constants.MAX_MAXDEX) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextMaxDex", a.toString());
    }
    a = EqToken.getAcCheckTokenInt(pc, equip);
    if (equip.isArmor() || equip.isShield() || (a.intValue() != 0)) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextAcCheck", a.toString());
    }
    if (!SettingsHandler.getGame().getACText().isEmpty()) {
        a = equip.getACMod(pc);
        if (equip.isArmor() || equip.isShield() || (a.intValue() != 0)) {
            b.appendSpacer();
            b.appendElement(LanguageBundle.getFormattedString(//$NON-NLS-1$
            "in_igInfoLabelTextAcBonus", SettingsHandler.getGame().getACText()), a.toString());
        }
    }
    if (SettingsHandler.getGame().getTabShown(Tab.SPELLS)) {
        a = EqToken.getSpellFailureTokenInt(pc, equip);
        if (equip.isArmor() || equip.isShield() || (a.intValue() != 0)) {
            b.appendSpacer();
            b.appendI18nElement("in_igInfoLabelTextArcaneFailure", //$NON-NLS-1$
            a.toString());
        }
    }
    bString = SettingsHandler.getGame().getDamageResistanceText();
    if (!bString.isEmpty()) {
        a = EqToken.getEdrTokenInt(pc, equip);
        if (equip.isArmor() || equip.isShield() || (a.intValue() != 0)) {
            b.appendSpacer();
            b.appendElement(bString, a.toString());
        }
    }
    bString = equip.moveString();
    if (!bString.isEmpty()) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextMove", bString);
    }
    bString = equip.getSize();
    if (!bString.isEmpty()) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextSize", bString);
    }
    bString = equip.getDamage(pc);
    if (!bString.isEmpty()) {
        if (equip.isDouble()) {
            //$NON-NLS-1$
            bString += "/" + equip.getAltDamage(pc);
        }
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextDamage", bString);
    }
    String critRangeVar = ControlUtilities.getControlToken(Globals.getContext(), CControl.CRITRANGE);
    if (critRangeVar == null) {
        int critrange = EqToken.getOldBonusedCritRange(pc, equip, true);
        int altcritrange = EqToken.getOldBonusedCritRange(pc, equip, false);
        bString = critrange == 0 ? EMPTY_STRING : Integer.toString(critrange);
        if (equip.isDouble() && critrange != altcritrange) {
            bString += //$NON-NLS-1$
            "/" + (altcritrange == 0 ? EMPTY_STRING : Integer.toString(altcritrange));
        }
    } else {
        bString = WeaponToken.getNewCritRangeString(pc, equip, critRangeVar);
    }
    if (!bString.isEmpty()) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_ieInfoLabelTextCritRange", bString);
    }
    String critMultVar = ControlUtilities.getControlToken(Globals.getContext(), CControl.CRITMULT);
    if (critMultVar == null) {
        bString = EqToken.multAsString(equip.getCritMultiplier());
        if (equip.isDouble() && !(equip.getCritMultiplier() == equip.getAltCritMultiplier())) {
            //$NON-NLS-1$
            bString += "/" + EqToken.multAsString(equip.getAltCritMultiplier());
        }
    } else {
        bString = WeaponToken.getNewCritMultString(pc, equip, critMultVar);
    }
    if (!bString.isEmpty()) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextCritMult", bString);
    }
    if (equip.isWeapon()) {
        bString = Globals.getGameModeUnitSet().displayDistanceInUnitSet(EqToken.getRange(pc, equip).intValue());
        if (!bString.isEmpty()) {
            b.appendSpacer();
            b.appendI18nElement("in_igInfoLabelTextRange", //$NON-NLS-1$
            bString + Globals.getGameModeUnitSet().getDistanceUnit());
        }
    }
    bString = equip.getContainerCapacityString();
    if (!bString.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextContainer", bString);
    }
    bString = equip.getContainerContentsString();
    if (!bString.isEmpty()) {
        b.appendSpacer();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextCurrentlyContains", bString);
    }
    final int charges = equip.getRemainingCharges();
    if (charges >= 0) {
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextCharges", //$NON-NLS-1$
        Integer.valueOf(charges).toString());
    }
    Map<String, String> qualityMap = equip.getMapFor(MapKey.QUALITY);
    if (qualityMap != null && !qualityMap.isEmpty()) {
        Set<String> qualities = new TreeSet<>();
        for (Map.Entry<String, String> me : qualityMap.entrySet()) {
            qualities.add(new StringBuilder(50).append(me.getKey()).append(": ").append(me.getValue()).toString());
        }
        b.appendLineBreak();
        b.appendI18nElement("in_igInfoLabelTextQualities", //$NON-NLS-1$
        StringUtil.join(qualities, //$NON-NLS-2$
        ", "));
    }
    //Description
    String desc = pc.getDescription(equip);
    if (!desc.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nFormattedElement(//$NON-NLS-1$
        "in_InfoDescription", DescriptionFormatting.piWrapDesc(equip, desc, false));
    }
    String IDS = equip.getInterestingDisplayString(pc);
    if (!IDS.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextProp", IDS);
    }
    String note = equip.getNote();
    if (!note.isEmpty()) {
        b.appendLineBreak();
        //$NON-NLS-1$
        b.appendI18nElement("in_igInfoLabelTextNote", note);
    }
    return b;
}
Also used : BigDecimal(java.math.BigDecimal) TreeSet(java.util.TreeSet) HtmlInfoBuilder(pcgen.gui2.util.HtmlInfoBuilder) WieldCategory(pcgen.core.character.WieldCategory) File(java.io.File) Map(java.util.Map) TreeMap(java.util.TreeMap)

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