整理代码结构,使用service
This commit is contained in:
@@ -68,57 +68,6 @@ const moment = require('moment');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// 获取物品
|
||||
export class Reward {
|
||||
roleId: string;
|
||||
roleName: string;
|
||||
rewards: Array<{type?: number, gid: number, count: number}>;
|
||||
|
||||
constructor(roleId: string, roleName: string, rewards: Array<{type?: number, gid: number, count: number}>) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.rewards = rewards;
|
||||
}
|
||||
|
||||
public async saveReward() {
|
||||
|
||||
let returnGoods = new Array();
|
||||
for(let goods of this.rewards) {
|
||||
let goodInfo = getGoodById(goods.gid);
|
||||
if(goodInfo.goodType == GOOD_TYPE.EQUIP) { // 装备
|
||||
let result = await this.rewardWeapons(goodInfo, {id: goods.gid, cnt: goods.count });
|
||||
for(let obj of result) {
|
||||
returnGoods.push({dropType: goods.type, ...obj})
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnGoods;
|
||||
}
|
||||
|
||||
private async rewardWeapons (dicGood: any, weapon: {id:number,cnt:number }) {
|
||||
|
||||
let weaponsData = [];
|
||||
let cnt = weapon.cnt;
|
||||
while (cnt > 0) {
|
||||
const seqId = await CounterModel.getNewCounter('eid');
|
||||
const equipInfo = {
|
||||
roleId: this.roleId,
|
||||
roleName: this.roleName,
|
||||
eid: weapon.id,
|
||||
eName: dicGood.name,
|
||||
seqId,
|
||||
quality: dicGood.lv,
|
||||
type: dicGood.goodType
|
||||
}
|
||||
const equip = await EquipModel.createEquip(equipInfo);
|
||||
cnt -= 1;
|
||||
weaponsData.push(equip);
|
||||
}
|
||||
return weaponsData;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将 | 分隔的字符串解析为数组,如:a|b|c 解析为[a, b, c]
|
||||
* @param str 要解析的字符串
|
||||
|
||||
Reference in New Issue
Block a user