From 55ae9859c2239938d624f4f4bfb65856679ca7f7 Mon Sep 17 00:00:00 2001 From: yuexin Date: Fri, 22 Jan 2021 12:32:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=8E=B7=E5=8F=96=E7=89=A9?= =?UTF-8?q?=E5=93=81=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/logic/ItemCtrl.ts | 22 +++++++++++++++++++++- src/logic/ItemDef.ts | 30 +++++++++++++++++++----------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/logic/ItemCtrl.ts b/src/logic/ItemCtrl.ts index 1b06506..a88a469 100644 --- a/src/logic/ItemCtrl.ts +++ b/src/logic/ItemCtrl.ts @@ -78,7 +78,7 @@ let ItemMan = { }, /** - * findItem + * findItem:根据物品id查找物品对象 */ findItem(itemid: number): CommonItem { return this._items.get(itemid); @@ -93,6 +93,26 @@ let ItemMan = { return item? item.isPackage(): false; }, + /** + * 根据字符串获取物品列表 + * @param infostr : id1:count1|id2:count2|... + * @returns 物品列表 + */ + getItemsByInfo(infostr: string): ItemInfo[]{ + let reslst: ItemInfo[] = []; + let lst = infostr.split('|'); + lst.forEach((v: string) =>{ + let item = new ItemInfo(); + if(item.loadInfo(v)){ + let obj = this.findItem(item.id); + obj && (item.type = obj._type); + reslst.push(item); + } + }); + + return reslst; + }, + _useItem(item: CommonItem, count: number, dpcard: boolean, reslst: CIC[]){ if(item.isPackage() && item._isautoopen){ this._openItemPkg(item, count, false, reslst); diff --git a/src/logic/ItemDef.ts b/src/logic/ItemDef.ts index 00b387f..2e9d4ee 100644 --- a/src/logic/ItemDef.ts +++ b/src/logic/ItemDef.ts @@ -55,6 +55,19 @@ export class ItemInfo{ loadData(itemid: number, itemcount: number){ this.id = itemid; this.count = itemcount; + }; + + loadInfo(infostr: string){ + if(!infostr){ + return false; + } + let l = infostr.split(':'); + if(l.length >= 2){ + this.id = parseInt(l[0]); + this.count = parseInt(l[1]); + return this.id > 0; + } + return false; } }; @@ -93,9 +106,8 @@ export class CommonItem{ let lst = aitem.decomposition_to_obtain.split('|'); lst.forEach((v: string) => { - let l = v.split(':'); - if(l.length >= 2){ - let item = new ItemInfo(parseInt(l[0]), parseInt(l[1])); + let item = new ItemInfo(); + if(item.loadInfo(v)){ if(!this._solidsubitems){ this._solidsubitems = [item]; }else{ @@ -117,16 +129,12 @@ export class CommonItem{ this._randsubtype = aitem.candtypeid; this._randsubgrade = aitem.candgradeid; - let lst = aitem.Price.split(':'); - if(lst.length >= 2){ - this._priceinfo.loadData(parseInt(lst[0]), parseInt(lst[1])); - } + this._priceinfo.loadInfo(aitem.Price); - lst = aitem.drop.split('|'); + let lst = aitem.drop.split('|'); lst.forEach((v: string) => { - let l = v.split(':'); - if(l.length >= 2){ - let item = new ItemInfo(parseInt(l[0]), parseInt(l[1])); + let item = new ItemInfo(); + if(item.loadInfo(v)){ if(!this._solidsubitems){ this._solidsubitems = [item]; }else{