card_info_svr/src/logic/ItemDef.ts
2021-01-22 02:59:03 +08:00

169 lines
4.1 KiB
TypeScript

import { DropItemCfg } from "cfg/parsers/DropItemCfg";
import { ItemCardCfg } from "cfg/parsers/ItemCardCfg";
import { count } from "console";
import { timeBeforeDay } from "utils/time.util";
/**
* 1.杂物
* 2.杂物包
* 3.卡牌
* 4.卡牌包
* 5.镶宝技能
* 6.镶宝技能包
*/
export const enum COMMON_ITEM_TYPE{
NONE = 0,
NORMAL = 1,
NORMAL_PKG = 2,
CARD = 3,
CARD_PKG = 4,
SKILL = 5,
SKILL_PKG = 6,
MONEY = 7,
};
/**
* 1.基础(暂时不用)
* 2.普通
* 3.稀有
* 4.史诗
* 5.传奇
* 6.神话(暂时不用)
*/
export const enum COMMON_ITEM_GRADE{
NONE = 0,
BASE = 1,
NORMAL = 2,
RARE = 3,
EPIC = 4,
LEGEND = 5,
MYTH = 6,
};
export class ItemInfo{
id: number;
count: number;
weight: number;
type: number = 0;
constructor(itemid?: number, itemcount: number = 1, itemweight: number = 0){
this.id = itemid? itemid: 0;
this.count = itemcount;
this.weight = itemweight;
};
loadData(itemid: number, itemcount: number){
this.id = itemid;
this.count = itemcount;
}
};
export class CommonItem{
public _id: number = 0;
public _type: number = 0;
public _subtype: number = 0;
public _grade: number = 0;
public _isautoopen: boolean = false;
public _weight: number = 0;
public _priceinfo: ItemInfo = null;
public _randsubtype: number = 0;
public _randsubgrade: number = 0;
public _randsubtotalwh: number = 0;
public _solidsubitems: ItemInfo[];
public _randexitems: ItemInfo[];
public _randsubitems: ItemInfo[];
constructor(){
this._priceinfo = new ItemInfo();
};
public loadCardItem(aitem: ItemCardCfg){
this._id = aitem.id;
this._type = COMMON_ITEM_TYPE.CARD;
this._subtype = aitem.typeid;
this._grade = aitem.gradeid;
this._isautoopen = false;
this._weight = aitem.weight;
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]));
if(!this._solidsubitems){
this._solidsubitems = [item];
}else{
this._solidsubitems.push(item);
}
}
});
};
public loadDropItem(aitem: DropItemCfg){
this._id = aitem.id;
this._type = aitem.itemtypeid;
this._subtype = COMMON_ITEM_TYPE.NONE;
this._grade = COMMON_ITEM_GRADE.BASE;
this._isautoopen = aitem.autopen == 1;
this._weight = aitem.weight;
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]));
}
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]));
if(!this._solidsubitems){
this._solidsubitems = [item];
}else{
this._solidsubitems.push(item);
}
}
});
lst = aitem.additionalcandidates.split('|');
lst.forEach((v: string) => {
let item = new ItemInfo(parseInt(v));
if(!this._randexitems){
this._randexitems = [item];
}else{
this._randexitems.push(item);
}
});
};
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);
};
}