逻辑处理

This commit is contained in:
yuexin 2021-01-21 20:01:41 +08:00
parent c8a9e89be7
commit a0a26043d8
2 changed files with 38 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg' import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
import { MatchCfg } from '../cfg/parsers/MatchCfg' import { MatchCfg } from '../cfg/parsers/MatchCfg'
import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg' import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg'
import ItemCtrl from "logic/ItemCtrl";
export function initData() { export function initData() {
@ -19,6 +20,6 @@ export function initData() {
rP(BaseConst.MATCH, MatchCfg); rP(BaseConst.MATCH, MatchCfg);
rP(BaseConst.ITEMFUNC, ItemFuncCfg); rP(BaseConst.ITEMFUNC, ItemFuncCfg);
DataParser.loadAll(); DataParser.loadAll();
ItemCtrl.initItems();
} }

View File

@ -2,11 +2,13 @@ import { DropItemCfg } from "cfg/parsers/DropItemCfg";
import { ItemCardCfg } from "cfg/parsers/ItemCardCfg"; import { ItemCardCfg } from "cfg/parsers/ItemCardCfg";
import { ZError } from "common/ZError"; import { ZError } from "common/ZError";
import { BaseConst } from "constants/BaseConst"; import { BaseConst } from "constants/BaseConst";
import { CommonItem, ItemInfo } from "./ItemDef"; import { CommonItem, COMMON_ITEM_TYPE, ItemInfo } from "./ItemDef";
let ItemMan = { let ItemMan = {
// 卡牌按品质分 // 物品按品质分
_card_lvs: new Map(), _item_grades: new Map(),
// 物品按类型分
_item_types: new Map(),
// 卡牌按子类型分 // 卡牌按子类型分
_card_types: new Map(), _card_types: new Map(),
@ -59,6 +61,7 @@ let ItemMan = {
}, },
initItems(){ initItems(){
return;
this._items.clear(); this._items.clear();
// 默认id都唯一 // 默认id都唯一
@ -91,32 +94,42 @@ let ItemMan = {
}, },
handleItems(){ handleItems(){
this.handCardCaches(); this.handCaches();
this.handRandWeights(); this.handRandWeights();
}, },
handCardCaches(){ handCaches(){
this._card_lvs.clear(); this._item_grades.clear();
this._card_types.clear(); this._card_types.clear();
this._items.forEach((v: CommonItem, k: number) =>{ this._items.forEach((v: CommonItem, k: number) =>{
let lst = this._card_lvs.get(v._grade); let lst = this._item_grades.get(v._grade);
if(!lst){ if(!lst){
lst = [v]; lst = [v];
this._card_lvs.set(v._grade, lst); this._item_grades.set(v._grade, lst);
}else{ }else{
lst.push(v); lst.push(v);
} }
lst = this._card_types.get(v._type); lst = this._item_types.get(v._type);
if(!lst){ if(!lst){
lst = [v]; lst = [v];
this._card_types.set(v._type, lst); this._item_types.set(v._type, lst);
}else{ }else{
lst.push(v); lst.push(v);
} }
if(v._type == COMMON_ITEM_TYPE.CARD){
lst = this._card_types.get(v._subtype);
if(!lst){
lst = [v];
this._card_types.set(v._subtype, lst);
}else{
lst.push(v);
}
}
v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{ v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{
let obj: CommonItem = this._items.get(item.id); let obj: CommonItem = this._items.get(item.id);
obj && (item.weight = obj._weight); obj && (item.weight = obj._weight);
@ -127,7 +140,19 @@ let ItemMan = {
handRandWeights(){ handRandWeights(){
this._items.forEach((v: CommonItem, k: number) =>{ this._items.forEach((v: CommonItem, k: number) =>{
if(v._randexitems || v._randsubgrade || v._randsubtype){ if(v._randexitems || v._randsubgrade || v._randsubtype){
if(!v._randsubitems){
v._randsubitems = [];
}
let lst = [];
if(v._randsubtype == COMMON_ITEM_TYPE.CARD && v._randsubgrade){
lst = this._card_types.get(v._randsubgrade);
}else{
lst = this._item_types.get(v._randsubtype);
}
lst.forEach((element: CommonItem) => {
});
} }
}); });
} }