Merge branch 'master' of git.kingsome.cn:node/card_info_svr
This commit is contained in:
commit
fbd3761b78
@ -7,7 +7,7 @@ import { DropItemCfg } from '../cfg/parsers/DropItemCfg'
|
||||
import { ItemCardCfg } from '../cfg/parsers/ItemCardCfg'
|
||||
import { MatchCfg } from '../cfg/parsers/MatchCfg'
|
||||
import { ItemFuncCfg } from '../cfg/parsers/ItemFuncCfg'
|
||||
import ItemCtrl from "logic/ItemCtrl";
|
||||
import ItemCtrl from "../logic/ItemCtrl";
|
||||
|
||||
|
||||
export function initData() {
|
||||
|
@ -131,10 +131,10 @@ export default class AccountController extends BaseController {
|
||||
for (let obj of data) {
|
||||
let item = (await BagItem.findOrCreate({
|
||||
accountid,
|
||||
itemid: obj.itemid,
|
||||
itemtype: ItemType.UNKNOW
|
||||
itemid: obj.id,
|
||||
itemtype: obj.type
|
||||
})).doc
|
||||
item.count += obj.itemnum
|
||||
item.count += obj.count
|
||||
await item.save()
|
||||
}
|
||||
await record.save()
|
||||
|
@ -1,8 +1,9 @@
|
||||
import { DropItemCfg } from "cfg/parsers/DropItemCfg";
|
||||
import { ItemCardCfg } from "cfg/parsers/ItemCardCfg";
|
||||
import { ZError } from "common/ZError";
|
||||
import { BaseConst } from "constants/BaseConst";
|
||||
import { CommonItem, COMMON_ITEM_TYPE, ItemInfo } from "./ItemDef";
|
||||
import { DropItemCfg } from "../cfg/parsers/DropItemCfg";
|
||||
import { ItemCardCfg } from "../cfg/parsers/ItemCardCfg";
|
||||
import { ZError } from "../common/ZError";
|
||||
import { BaseConst } from "../constants/BaseConst";
|
||||
import { CIC, CommonItem, COMMON_ITEM_TYPE, ItemInfo } from "./ItemDef";
|
||||
import {calcWeight} from "./LogicUtil";
|
||||
|
||||
let ItemMan = {
|
||||
// 物品按品质分
|
||||
@ -14,31 +15,29 @@ let ItemMan = {
|
||||
|
||||
_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 :物品卡数量
|
||||
* 使用物品
|
||||
* @param itemid :物品id
|
||||
* @param itemcount :物品数量
|
||||
*/
|
||||
useItemPackage(itemid: number, itemcount: number = 1) {
|
||||
let obj: DropItemCfg = global.$cfg.get(BaseConst.DROPITEM).get(itemid);
|
||||
useItem(itemid: number, itemcount: number = 1) {
|
||||
let obj: CommonItem = this.findItem(itemid);
|
||||
if(!obj){
|
||||
throw new ZError(1001, 'not find item!');
|
||||
throw new ZError(1001, 'not find item cfg!');
|
||||
}
|
||||
|
||||
|
||||
let lst: CIC[] = [];
|
||||
let reslst:ItemInfo[] = [];
|
||||
|
||||
return [{ itemid: 10001, itemnum: 1 }];
|
||||
return reslst;
|
||||
|
||||
this._useItem(obj, itemcount, false, lst);
|
||||
|
||||
lst.forEach((item: CIC) => {
|
||||
reslst.push(item.info);
|
||||
});
|
||||
|
||||
return reslst;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -47,7 +46,25 @@ let ItemMan = {
|
||||
* @param itemcount :物品卡数量
|
||||
*/
|
||||
decomposeItemCard(itemid: number, itemcount: number = 1){
|
||||
let obj: CommonItem = this.findItem(itemid);
|
||||
if(!obj){
|
||||
throw new ZError(1001, 'not find item cfg!');
|
||||
}
|
||||
|
||||
if(!obj.isCard()){
|
||||
throw new ZError(1001, 'this item is not card!');
|
||||
}
|
||||
|
||||
let lst: CIC[] = [];
|
||||
|
||||
this._useItem(obj, itemcount, true, lst);
|
||||
|
||||
let reslst:ItemInfo[] = [];
|
||||
lst.forEach((item: CIC) => {
|
||||
reslst.push(item.info);
|
||||
});
|
||||
|
||||
return reslst;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -60,8 +77,58 @@ let ItemMan = {
|
||||
return item? item._priceinfo: new ItemInfo();
|
||||
},
|
||||
|
||||
/**
|
||||
* findItem
|
||||
*/
|
||||
findItem(itemid: number): CommonItem {
|
||||
return this._items.get(itemid);
|
||||
},
|
||||
|
||||
/**
|
||||
* 是否是物品包
|
||||
* @param itemid : 物品id
|
||||
*/
|
||||
isItemPackage(itemid: number): boolean{
|
||||
let item = this.findItem(itemid);
|
||||
return item? item.isPackage(): false;
|
||||
},
|
||||
|
||||
_useItem(item: CommonItem, count: number, dpcard: boolean, reslst: CIC[]){
|
||||
if(item.isPackage() && item._isautoopen){
|
||||
this._openItemPkg(item, count, false, reslst);
|
||||
}else if(dpcard && item.isCard()){
|
||||
this._openItemPkg(item, count, true, reslst);
|
||||
}else{
|
||||
reslst.push(new CIC(item, count));
|
||||
}
|
||||
},
|
||||
|
||||
_openItemPkg(pkg: CommonItem, count: number, dpcard: boolean, reslst: CIC[]){
|
||||
if(pkg._solidsubitems){
|
||||
pkg._solidsubitems.forEach((item: ItemInfo) => {
|
||||
let obj = this._items.get(item.id);
|
||||
this._useItem(obj, item.count * count, false, reslst);
|
||||
});
|
||||
}
|
||||
if(pkg._randsubitems){
|
||||
for(let i = 0; i < count; i++){
|
||||
let n = calcWeight(pkg._randsubitems, pkg._randsubtotalwh);
|
||||
let info = pkg._randsubitems[n];
|
||||
if(!info){
|
||||
//todo:
|
||||
continue;
|
||||
}
|
||||
let obj = this._items.get(info.id);
|
||||
if(!obj){
|
||||
//todo:
|
||||
continue;
|
||||
}
|
||||
this._useItem(obj, info.count, false, reslst);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
initItems(){
|
||||
return;
|
||||
this._items.clear();
|
||||
|
||||
// 默认id都唯一
|
||||
@ -142,16 +209,37 @@ let ItemMan = {
|
||||
if(v._randexitems || v._randsubgrade || v._randsubtype){
|
||||
if(!v._randsubitems){
|
||||
v._randsubitems = [];
|
||||
}else{
|
||||
v._randsubitems.length = 0;
|
||||
}
|
||||
|
||||
v._randsubtotalwh = 0;
|
||||
|
||||
let lst = [];
|
||||
if(v._randsubtype == COMMON_ITEM_TYPE.CARD && v._randsubgrade){
|
||||
lst = this._card_types.get(v._randsubgrade);
|
||||
}else{
|
||||
console.log('is card random:', v._randsubtype, v._randsubgrade);
|
||||
console.log([this._item_grades.keys()]);
|
||||
lst = this._item_grades.get(v._randsubgrade);
|
||||
}else if(v._randsubtype != COMMON_ITEM_TYPE.NONE){
|
||||
console.log('is not card random:', v._randsubtype);
|
||||
lst = this._item_types.get(v._randsubtype);
|
||||
}
|
||||
|
||||
lst.forEach((element: CommonItem) => {
|
||||
|
||||
lst && lst.forEach((element: CommonItem) => {
|
||||
v._randsubitems.push(new ItemInfo(element._id, 1, element._weight));
|
||||
v._randsubtotalwh += element._weight;
|
||||
});
|
||||
|
||||
v._randexitems && v._randexitems.forEach((item: ItemInfo) =>{
|
||||
let obj = v._randsubitems.find((v: ItemInfo) => {
|
||||
return v.id == item.id;
|
||||
});
|
||||
if(obj){
|
||||
obj.weight += item.weight;
|
||||
}else{
|
||||
v._randsubitems.push(item);
|
||||
v._randsubtotalwh += item.weight;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1,5 +1,7 @@
|
||||
import { DropItemCfg } from "cfg/parsers/DropItemCfg";
|
||||
import { ItemCardCfg } from "cfg/parsers/ItemCardCfg";
|
||||
import { count } from "console";
|
||||
import { timeBeforeDay } from "utils/time.util";
|
||||
|
||||
/**
|
||||
* 1.杂物
|
||||
@ -18,6 +20,7 @@ export const enum COMMON_ITEM_TYPE{
|
||||
CARD_PKG = 4,
|
||||
SKILL = 5,
|
||||
SKILL_PKG = 6,
|
||||
MONEY = 7,
|
||||
};
|
||||
|
||||
/**
|
||||
@ -41,11 +44,12 @@ export const enum COMMON_ITEM_GRADE{
|
||||
export class ItemInfo{
|
||||
id: number;
|
||||
count: number;
|
||||
weight: number = 0;
|
||||
constructor(itemid?: number, itemcount?: number, itemweight?: number){
|
||||
weight: number;
|
||||
type: number = 0;
|
||||
constructor(itemid?: number, itemcount: number = 1, itemweight: number = 0){
|
||||
this.id = itemid? itemid: 0;
|
||||
this.count = itemcount? itemcount: 0;
|
||||
this.weight = itemweight? itemweight: 0;
|
||||
this.count = itemcount;
|
||||
this.weight = itemweight;
|
||||
};
|
||||
|
||||
loadData(itemid: number, itemcount: number){
|
||||
@ -68,6 +72,8 @@ export class CommonItem{
|
||||
public _randsubtype: number = 0;
|
||||
public _randsubgrade: number = 0;
|
||||
|
||||
public _randsubtotalwh: number = 0;
|
||||
|
||||
public _solidsubitems: ItemInfo[];
|
||||
|
||||
public _randexitems: ItemInfo[];
|
||||
@ -133,7 +139,7 @@ export class CommonItem{
|
||||
|
||||
lst = aitem.additionalcandidates.split('|');
|
||||
lst.forEach((v: string) => {
|
||||
let item = new ItemInfo(parseInt(v), 1);
|
||||
let item = new ItemInfo(parseInt(v));
|
||||
if(!this._randexitems){
|
||||
this._randexitems = [item];
|
||||
}else{
|
||||
@ -142,4 +148,22 @@ export class CommonItem{
|
||||
});
|
||||
};
|
||||
|
||||
};
|
||||
isPackage(){
|
||||
return this._type == COMMON_ITEM_TYPE.CARD_PKG ||
|
||||
this._type == COMMON_ITEM_TYPE.NORMAL_PKG ||
|
||||
this._type == COMMON_ITEM_TYPE.SKILL_PKG;
|
||||
};
|
||||
|
||||
isCard(){
|
||||
return this._type == COMMON_ITEM_TYPE.CARD;
|
||||
}
|
||||
};
|
||||
|
||||
export class CIC{
|
||||
public item: CommonItem;
|
||||
public info: ItemInfo;
|
||||
constructor(aitem: CommonItem, acount: number = 1){
|
||||
this.item = aitem;
|
||||
this.info = new ItemInfo(aitem? aitem._id: 0, acount, aitem? aitem._weight: 0);
|
||||
};
|
||||
}
|
21
src/logic/LogicUtil.ts
Normal file
21
src/logic/LogicUtil.ts
Normal file
@ -0,0 +1,21 @@
|
||||
//[{weight}]
|
||||
/**
|
||||
* [计算权重]
|
||||
* @param {[array]} obj_vec [对象数组,对象中要有权重变量weight]
|
||||
* @return {[number]} [obj_vec数组索引]
|
||||
*/
|
||||
export function calcWeight(obj_vec: any[], all_weight: number) {
|
||||
if (all_weight <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let ret = 0;
|
||||
let rand = Math.random() * all_weight;
|
||||
for (let i = 0; i < obj_vec.length; i++) {
|
||||
if (rand < obj_vec[i].weight) {
|
||||
ret = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user