/** * select items, which improve AC but are not type ARMOR * * @param item * @param subtype * @param property * @param equipped * @param merge * @param aPC * @param eh The ExportHandler to advise if there are no more items. * @return int */ private static String _replaceTokenArmorItem( int item, String subtype, String property, int equipped, int merge, PlayerCharacter aPC, ExportHandler eh) { // select all pieces of equipment of status==equipped // filter all AC relevant stuff final List<Equipment> aArrayList = new ArrayList<>(); for (Equipment eq : aPC.getEquipmentListInOutputOrder(merge)) { if (("".equals(subtype) || eq.isType(subtype)) && ((equipped == 3) || ((equipped == 2) && !eq.isEquipped()) || ((equipped == 1) && eq.isEquipped()))) { if (eq.altersAC(aPC) && !eq.isArmor() && !eq.isShield()) { aArrayList.add(eq); } } } if (item < aArrayList.size()) { final Equipment eq = aArrayList.get(item); return _writeArmorProperty(eq, property, aPC); } eh.setNoMoreItems(true); return ""; }
/** * Update the stored spellbook details in response to a spellbook item of equipment changing. * Changes to equipment other than spellbooks will be ignored. * * @param equip The equipment item that changed. */ private void updateSpellBooks(Equipment equip) { if (equip == null || equip.isType("SPELLBOOK")) { buildKnownPreparedNodes(); for (Iterator<SpellNode> iterator = bookSpellNodes.iterator(); iterator.hasNext(); ) { SpellNode spell = iterator.next(); if (!spellBookNames.containsElement(spell.getRootNode().getName())) { iterator.remove(); } } } }
private static String _writeArmorProperty(Equipment eq, String property, PlayerCharacter aPC) { CharacterDisplay display = aPC.getDisplay(); StringBuilder ret = new StringBuilder(); if (property.startsWith("NAME")) { if (eq.isEquipped() && !property.equals("NAMENOSTAR")) { ret.append("*"); } ret.append(OutputNameFormatting.parseOutputName(eq, aPC)); ret.append(eq.getAppliedName()); } else if (property.startsWith("OUTPUTNAME")) { // TODO this appears to be the same as above. Should be refactored if (eq.isEquipped()) { ret.append("*"); } ret.append(OutputNameFormatting.parseOutputName(eq, aPC)); ret.append(eq.getAppliedName()); } else if (property.startsWith("TOTALAC") || property.startsWith("ACBONUS")) { // adjustments for new equipment modifier // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT // FileAccess.write(output, Delta.toString(eq.getACMod())); String acMod = aPC.getControl(CControl.EQACMOD); if (acMod != null) { Object o = aPC.getLocal(eq, acMod); int intValue = ((Number) o).intValue(); ret.append(Delta.toString(intValue)); } else { ret.append(Delta.toString((int) eq.bonusTo(aPC, "COMBAT", "AC", true))); } } else if (property.startsWith("BASEAC")) { // adjustments for new equipment modifier // EQMARMOR|AC|x|TYPE=ENHANCEMENT changed to COMBAT|AC|x|TYPE=Armor.ENHANCEMENT // FileAccess.write(output, Delta.toString(eq.getACMod())); String baseMod = aPC.getControl(CControl.EQBASEACMOD); if (baseMod != null) { Object o = aPC.getLocal(eq, baseMod); int intValue = ((Number) o).intValue(); ret.append(Delta.toString(intValue)); } else { ret.append(Delta.toString((int) BonusCalc.charBonusTo(eq, "COMBAT", "AC", aPC))); } } else if (property.startsWith("MAXDEX")) { final int iMax = EqToken.getMaxDexTokenInt(aPC, eq); if (iMax != Constants.MAX_MAXDEX) { ret.append(Delta.toString(iMax)); } } else if (property.startsWith("ACCHECK")) { ret.append(Delta.toString(EqToken.getAcCheckTokenInt(aPC, eq))); } else if (property.startsWith("EDR")) { ret.append(Delta.toString(EqToken.getEdrTokenInt(aPC, eq))); } else if (property.startsWith("ISTYPE")) { if (eq.isType(property.substring(property.indexOf(".") + 1))) { ret.append("TRUE"); } else { ret.append("FALSE"); } } else if (property.startsWith("SPELLFAIL")) { ret.append(EqToken.getSpellFailureTokenInt(aPC, eq)); } else if (property.startsWith("MOVE")) { final StringTokenizer aTok = new StringTokenizer(eq.moveString(), ",", false); String tempString = ""; if (("M".equals(display.getSize()) || "S".equals(display.getSize())) && (aTok.countTokens() > 0)) { tempString = aTok.nextToken(); if ("S".equals(display.getSize()) && (aTok.countTokens() > 1)) { tempString = aTok.nextToken(); } } ret.append(tempString); } else if (property.startsWith("SPROP")) { ret.append(eq.getSpecialProperties(aPC)); } else if (property.startsWith("TYPE")) { String typeString = ""; if (eq.isLight()) { typeString = "Light"; } else if (eq.isMedium()) { typeString = "Medium"; } else if (eq.isHeavy()) { typeString = "Heavy"; } else if (eq.isShield()) { typeString = "Shield"; } else if (eq.isExtra()) { typeString = "Extra"; } ret.append(typeString); } else if (property.startsWith("WT")) { ret.append(BigDecimalHelper.trimZeros(eq.getWeight(aPC).toString())); } return ret.toString(); }
// TODO Refactor this with all the equipment tests. @Override public int passes(final Prerequisite prereq, final CharacterDisplay display, CDOMObject source) throws PrerequisiteException { final int number; try { number = Integer.parseInt(prereq.getOperand()); } catch (NumberFormatException e) { throw new PrerequisiteException( LanguageBundle.getFormattedString( "PreItem.error.bad_operand", prereq.toString())); // $NON-NLS-1$ } int runningTotal = 0; if (display.hasEquipment()) { // Work out exactlywhat we are going to test. final String aString = prereq.getKey(); List<String> typeList = null; if (aString.startsWith(Constants.LST_TYPE_EQUAL) || aString.startsWith(Constants.LST_TYPE_DOT)) { String stripped = aString.substring(Constants.SUBSTRING_LENGTH_FIVE); typeList = CoreUtility.split(stripped, '.'); } for (Equipment eq : display.getEquipmentSet()) { if (typeList != null) { // Check to see if the equipment matches // all of the types in the requested list; boolean bMatches = true; for (int i = 0, x = typeList.size(); i < x; ++i) { if (!eq.isType(typeList.get(i))) { bMatches = false; break; } } if (bMatches) { runningTotal++; } } else { // not a TYPE string final String eqName = eq.getName().toUpperCase(); if (aString.indexOf('%') >= 0) { // handle wildcards (always assume // they end the line) final int percentPos = aString.indexOf('%'); final String substring = aString.substring(0, percentPos).toUpperCase(); if ((eqName.startsWith(substring))) { ++runningTotal; break; } } else if (eqName.equalsIgnoreCase(aString)) { // just a straight String compare ++runningTotal; break; } } } } runningTotal = prereq.getOperator().compare(runningTotal, number); return countedTotal(prereq, runningTotal); }