Fixed regression where sellchance because NaN due to a divide by 0 error
This commit is contained in:
parent
e65b75261f
commit
2a750a9989
@ -503,10 +503,10 @@ export class ItemHelper
|
||||
/**
|
||||
* Calcualte the average quality of an item and its children
|
||||
* @param items An offers item to process
|
||||
* @param nonQualityItemsReturnNegative Treat items without a quality property as non-existant
|
||||
* @param skipArmorItemsWithoutDurability Skip over armor items without durability
|
||||
* @returns % quality modifer between 0 and 1
|
||||
*/
|
||||
public getItemQualityModifierForItems(items: Item[], nonQualityItemsReturnNegative = false): number
|
||||
public getItemQualityModifierForItems(items: Item[], skipArmorItemsWithoutDurability?: boolean): number
|
||||
{
|
||||
if (this.isOfBaseclass(items[0]._tpl, BaseClasses.WEAPON))
|
||||
{
|
||||
@ -517,7 +517,7 @@ export class ItemHelper
|
||||
let itemsWithQualityCount = 0;
|
||||
for (const item of items)
|
||||
{
|
||||
const result = this.getItemQualityModifier(item, nonQualityItemsReturnNegative);
|
||||
const result = this.getItemQualityModifier(item, skipArmorItemsWithoutDurability);
|
||||
if (result === -1)
|
||||
{
|
||||
continue;
|
||||
@ -532,14 +532,25 @@ export class ItemHelper
|
||||
|
||||
/**
|
||||
* get normalized value (0-1) based on item condition
|
||||
* Will return -1 for base armor items with 0 durability
|
||||
* @param item
|
||||
* @returns number between 0 and 1
|
||||
* @param skipArmorItemsWithoutDurability return -1 for armor items that have maxdurability of 0
|
||||
* @returns Number between 0 and 1
|
||||
*/
|
||||
public getItemQualityModifier(item: Item, nonQualityItemsReturnNegative = false): number
|
||||
public getItemQualityModifier(item: Item, skipArmorItemsWithoutDurability?: boolean): number
|
||||
{
|
||||
// Default to 100%
|
||||
let result = 1;
|
||||
|
||||
// Is armor and has 0 max durability
|
||||
const itemDetails = this.getItem(item._tpl)[1];
|
||||
if (skipArmorItemsWithoutDurability
|
||||
&& this.isOfBaseclass(item._tpl, BaseClasses.ARMOR)
|
||||
&& itemDetails._props.MaxDurability === 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (item.upd)
|
||||
{
|
||||
const medkit = item.upd.MedKit ? item.upd.MedKit : undefined;
|
||||
@ -549,8 +560,6 @@ export class ItemHelper
|
||||
const resource = item.upd.Resource ? item.upd.Resource : undefined;
|
||||
const repairKit = item.upd.RepairKit ? item.upd.RepairKit : undefined;
|
||||
|
||||
const itemDetails = this.getItem(item._tpl)[1];
|
||||
|
||||
if (medkit)
|
||||
{
|
||||
// Meds
|
||||
@ -582,12 +591,6 @@ export class ItemHelper
|
||||
result = repairKit.Resource / itemDetails._props.MaxRepairResource;
|
||||
}
|
||||
|
||||
// Not handled by any of the above + default value
|
||||
if (nonQualityItemsReturnNegative && result === 1)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (result === 0)
|
||||
{
|
||||
// make item non-zero but still very low
|
||||
|
Loading…
Reference in New Issue
Block a user