UNPKG

@ginstone/nga-api

Version:

88 lines (87 loc) 2.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ItemTypeInfo = exports.ItemInfo = exports.ItemData = void 0; const TradeBit_1 = require("../../enums/TradeBit"); const ItemType_1 = require("../../enums/ItemType"); const Medal_1 = require("../field/Medal"); const Money_1 = require("../field/Money"); // 道具数据 class ItemData { constructor(raw) { this.page = raw.currentPage; this.hasNext = !!raw.morePage; this.data = new Array; // 类型信息Map const itemInfo = JSON.parse(raw.itemInfo.replace("/*$js$*/", "")); const map = ItemTypeInfo.parse(itemInfo); Object.keys(raw).filter(i => /^\d+$/.exec(i)).forEach(key => { const value = raw[key]; // 类型信息 const typeKey = value.type + "_" + value.sub_type; const info = new ItemInfo(value, map.get(typeKey)); this.data.push(info); }); } } exports.ItemData = ItemData; // 道具信息 class ItemInfo { constructor(raw, typeInfo) { if (raw.t_index) this.index = raw.t_index; if (raw.trade_bit !== undefined) this.tradeBit = raw.trade_bit; this.id = raw.id; this.uid = raw.uid; this.count = raw.count; this.time = new Date(raw.time * 1000); this.bit = raw.bit; this.type = raw.type; this.subType = raw.sub_type; this.typeInfo = typeInfo; if (raw.price) { const price = Math.floor(raw.price / 1000); if (this.tradeBit === TradeBit_1.TradeBit.COPPER) { this.price = new Money_1.Money(price); } if (this.tradeBit === TradeBit_1.TradeBit.N) { this.price = price + ' N币'; } } if (typeInfo) { if (raw.type === ItemType_1.ItemType.MEDAL) { this.url = Medal_1.Medal.URL_PREFIX + typeInfo.icon; } else { this.url = ItemInfo.URL_PREFIX + typeInfo.icon; } } } } ItemInfo.URL_PREFIX = "https://img4.nga.178.com/ngabbs/nga_classic/items/"; exports.ItemInfo = ItemInfo; // 道具类型信息 class ItemTypeInfo { constructor(raw) { this.name = raw.name; this.icon = raw.icon; this.description = raw.dscp; if (raw.permission_buy_store) this.permissionBuyStore = raw.permission_buy_store; if (raw.buff_id) this.buffId = raw.buff_id; if (raw.buff_value_0) this.buffValue0 = raw.buff_value_0; if (raw.buff_last) this.buffLast = raw.buff_last; } static parse(raw) { const map = new Map; Object.keys(raw).forEach(key => { const value = raw[key]; map.set(key, new ItemTypeInfo(value)); }); return map; } } exports.ItemTypeInfo = ItemTypeInfo;