card_info_svr/src/logic/ItemCtrl.ts
2021-01-21 19:08:25 +08:00

95 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { DropItemCfg } from "cfg/parsers/DropItemCfg";
import { ItemCardCfg } from "cfg/parsers/ItemCardCfg";
import { ZError } from "common/ZError";
import { BaseConst } from "constants/BaseConst";
let ItemMan = {
// 卡牌按品质分
_card_lvs: new Map(),
// 卡牌按子类型分
_card_types: new Map(),
_items: new Map(),
useItem(itemid: number, itemcount: number = 1) {
let obj: DropItemCfg = global.$cfg.get(BaseConst.DROPITEM).get(itemid);
if(!obj){
throw new ZError(1001, 'not find item!');
}
return [{ itemid: 10001, itemnum: 1, itemtype: 1 }];
},
/**
* useItem使用物品主要指礼包类物品
* @param itemid : 物品卡id
* @param itemcount :物品卡数量
*/
useItemPackage(itemid: number, itemcount: number = 1) {
let obj: DropItemCfg = global.$cfg.get(BaseConst.DROPITEM).get(itemid);
if(!obj){
throw new ZError(1001, 'not find item!');
}
return [{ itemid: 10001, itemnum: 1 }];
},
/**
* decomposeItemCard分解卡片
* @param itemid : 物品卡id
* @param itemcount :物品卡数量
*/
decomposeItemCard(itemid: number, itemcount: number = 1){
},
initItems(){
this._items.clear();
this.initDropItems();
this.initCardItems();
this.handleItems();
},
initDropItems(){
let map: Map<number, DropItemCfg> = global.$cfg.get(BaseConst.DROPITEM);
map.forEach((v: DropItemCfg, k: number) => {
});
},
initCardItems(){
this._card_lvs.clear();
this._card_types.clear();
let map: Map<number, ItemCardCfg> = 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);
}
});
},
handleItems(){
}
};
export default ItemMan;