MCPcopy Create free account
hub / github.com/PCGen/pcgen / getCostFromPluses

Method getCostFromPluses

code/src/java/pcgen/core/Equipment.java:3951–4012  ·  view source on GitHub ↗

Tack on the cost of the magical enhancement(s). @param iPlus the Pluses of the primary head @param altPlus the Pluses of the secondary head @return cost from pluses

(final int iPlus, final int altPlus)

Source from the content-addressed store, hash-verified

3949 * @return cost from pluses
3950 */
3951 private BigDecimal getCostFromPluses(final int iPlus, final int altPlus)
3952 {
3953
3954 if (((iPlus != 0) || (altPlus != 0)) && (JEPResourceChecker.getMissingResourceCount() == 0))
3955 {
3956 PJEP myParser = null;
3957 try
3958 {
3959 myParser = PjepPool.getInstance().aquire();
3960 myParser.addVariable("PLUS", iPlus);
3961 myParser.addVariable("ALTPLUS", altPlus);
3962 myParser.addVariable("BASECOST", getSafe(ObjectKey.COST).doubleValue());
3963
3964 if (isAmmunition())
3965 {
3966 myParser.addVariable("BASEQTY", getSafe(IntegerKey.BASE_QUANTITY));
3967 }
3968
3969 // Look for an expression for all of this item's types
3970 // If there is more than 1, use the most expensive.
3971 String costExpr;
3972 BigDecimal maxCost = null;
3973 final List<String> itemTypes = typeList();
3974
3975 for (String typeMatched : itemTypes)
3976 {
3977 costExpr = SettingsHandler.getGameAsProperty().get().getPlusCalculation(Type.getConstant(typeMatched));
3978
3979 if (costExpr != null)
3980 {
3981 final BigDecimal thisCost = evaluateCost(myParser, costExpr);
3982
3983 if ((maxCost == null) || (thisCost.compareTo(maxCost) > 1))
3984 {
3985 maxCost = thisCost;
3986 }
3987 }
3988 }
3989
3990 if (maxCost != null)
3991 {
3992 return maxCost;
3993 }
3994
3995 //
3996 // No cost formula found, check for catch-all definition
3997 //
3998 costExpr = SettingsHandler.getGameAsProperty().get().getPlusCalculation(Type.ANY);
3999
4000 if (costExpr != null)
4001 {
4002 return evaluateCost(myParser, costExpr);
4003 }
4004 }
4005 finally
4006 {
4007 PjepPool.getInstance().release(myParser);
4008 }

Callers 1

getCostMethod · 0.95

Calls 15

getInstanceMethod · 0.95
isAmmunitionMethod · 0.95
typeListMethod · 0.95
getGameAsPropertyMethod · 0.95
getConstantMethod · 0.95
evaluateCostMethod · 0.95
aquireMethod · 0.80
doubleValueMethod · 0.80
getSafeMethod · 0.80
getPlusCalculationMethod · 0.80
releaseMethod · 0.80

Tested by

no test coverage detected