fix: prioritize non-stock/non-decorated items

Changed schema lookups to prioritize non-stock/non-decorated item defindexes when names collide
Modified unit tests to include example (stock Flame Thrower)
This commit is contained in:
xenticore
2025-03-27 15:32:45 -04:00
parent b24cda98ad
commit 967a32fc83
3 changed files with 35 additions and 20 deletions

View File

@@ -16,10 +16,13 @@ function isDateAfterOneDay(date1: Date, date2: Date): boolean {
export class ItemSchema { [key: string]: {name: string, tradable: Boolean}; }
export function getItemIndexByName(schema: ItemSchema, name: string) {
export function getItemIndexByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated: Boolean = true) {
for (const [defindex, value] of Object.entries(schema)) {
if (value['name'] == name) {
return parseInt(defindex)
const index = parseInt(defindex)
if(excludeStock && index <= 30) continue
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
return index
}
}
return null
@@ -29,9 +32,12 @@ export function getTradableStatusByDefindex(schema: ItemSchema, defindex: number
return schema[defindex.toString()].tradable
}
export function getTradableStatusByName(schema: ItemSchema, name: string) {
export function getTradableStatusByName(schema: ItemSchema, name: string, excludeStock: Boolean = true, excludeDecorated = true,) {
for (const [defindex, value] of Object.entries(schema)) {
if (value['name'] == name) {
const index = parseInt(defindex)
if(excludeStock && index <= 30) continue
if(excludeDecorated && (index >= 15000 && index < 16000)) continue
return value.tradable
}
}