From c8a9e89be7c8183c25b6f43fa4d3c3aa2342e871 Mon Sep 17 00:00:00 2001 From: yuexin Date: Thu, 21 Jan 2021 19:41:51 +0800 Subject: [PATCH] =?UTF-8?q?=E7=89=A9=E5=93=81=E5=A4=84=E7=90=86=E9=80=BB?= =?UTF-8?q?=E8=BE=91=EF=BC=88=E6=9C=AA=E5=AE=8C=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/logic/ItemCtrl.ts | 74 ++++++++++++++++++++++++++++++++----------- src/logic/ItemDef.ts | 23 +++++++++++--- 2 files changed, 74 insertions(+), 23 deletions(-) diff --git a/src/logic/ItemCtrl.ts b/src/logic/ItemCtrl.ts index d38eaf9..0725ea0 100644 --- a/src/logic/ItemCtrl.ts +++ b/src/logic/ItemCtrl.ts @@ -48,6 +48,16 @@ let ItemMan = { }, + /** + * 获取单个物品价格 + * @param itemid : 物品id + * @returns + */ + getItemPrice(itemid: number): ItemInfo{ + let item: CommonItem = this._items.get(itemid); + return item? item._priceinfo: new ItemInfo(); + }, + initItems(){ this._items.clear(); @@ -63,37 +73,63 @@ let ItemMan = { map.forEach((v: DropItemCfg, k: number) => { if(k != 0){ let item = new CommonItem(); - + item.loadDropItem(v); + this._items.set(k, item); } }); }, initCardItems(){ - this._card_lvs.clear(); - this._card_types.clear(); - let map: Map = global.$cfg.get(BaseConst.ITEMCARD); - map.forEach((v: ItemCardCfg, k: number) =>{ - let lst = this._card_lvs.get(v.gradeid); - if(!lst){ - lst = [v]; - this._card_lvs.set(v.gradeid, lst); - }else{ - lst.push(v); - } - - lst = this._card_types.get(v.typeid); - if(!lst){ - lst = [v]; - this._card_types.set(v.typeid, lst); - }else{ - lst.push(v); + map.forEach((v: ItemCardCfg, k: number) => { + if(k != 0){ + let item = new CommonItem(); + item.loadCardItem(v); + this._items.set(k, item); } }); }, handleItems(){ + this.handCardCaches(); + this.handRandWeights(); + }, + + handCardCaches(){ + this._card_lvs.clear(); + this._card_types.clear(); + + this._items.forEach((v: CommonItem, k: number) =>{ + let lst = this._card_lvs.get(v._grade); + if(!lst){ + lst = [v]; + this._card_lvs.set(v._grade, lst); + }else{ + lst.push(v); + } + + lst = this._card_types.get(v._type); + if(!lst){ + lst = [v]; + this._card_types.set(v._type, lst); + }else{ + lst.push(v); + } + + v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{ + let obj: CommonItem = this._items.get(item.id); + obj && (item.weight = obj._weight); + }); + }); + }, + + handRandWeights(){ + this._items.forEach((v: CommonItem, k: number) =>{ + if(v._randexitems || v._randsubgrade || v._randsubtype){ + + } + }); } }; diff --git a/src/logic/ItemDef.ts b/src/logic/ItemDef.ts index 0d817cc..562a921 100644 --- a/src/logic/ItemDef.ts +++ b/src/logic/ItemDef.ts @@ -42,10 +42,15 @@ export class ItemInfo{ id: number; count: number; weight: number = 0; - constructor(itemid: number, itemcount: number, itemweight: number = 0){ + constructor(itemid?: number, itemcount?: number, itemweight?: number){ + this.id = itemid? itemid: 0; + this.count = itemcount? itemcount: 0; + this.weight = itemweight? itemweight: 0; + }; + + loadData(itemid: number, itemcount: number){ this.id = itemid; this.count = itemcount; - this.weight = itemweight; } }; @@ -58,6 +63,7 @@ export class CommonItem{ public _isautoopen: boolean = false; public _weight: number = 0; + public _priceinfo: ItemInfo = null; public _randsubtype: number = 0; public _randsubgrade: number = 0; @@ -68,6 +74,10 @@ export class CommonItem{ public _randsubitems: ItemInfo[]; + constructor(){ + this._priceinfo = new ItemInfo(); + }; + public loadCardItem(aitem: ItemCardCfg){ this._id = aitem.id; this._type = COMMON_ITEM_TYPE.CARD; @@ -76,7 +86,7 @@ export class CommonItem{ this._isautoopen = false; this._weight = aitem.weight; - + let lst = aitem.decomposition_to_obtain.split('|'); lst.forEach((v: string) => { let l = v.split(':'); @@ -103,7 +113,12 @@ export class CommonItem{ this._randsubtype = aitem.candtypeid; this._randsubgrade = aitem.candgradeid; - let lst = aitem.drop.split('|'); + let lst = aitem.Price.split(':'); + if(lst.length >= 2){ + this._priceinfo.loadData(parseInt(lst[0]), parseInt(lst[1])); + } + + lst = aitem.drop.split('|'); lst.forEach((v: string) => { let l = v.split(':'); if(l.length >= 2){