领取奇遇事件
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
|
||||
import { getWarById, getGoodById } from './gamedata';
|
||||
import { CounterModel } from '../db/Counter';
|
||||
import { EquipModel } from '../db/Equip';
|
||||
import { GOOD_TYPE } from '../consts/consts';
|
||||
|
||||
export function genCode(len) {
|
||||
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
@@ -11,29 +15,96 @@
|
||||
}
|
||||
|
||||
export function decodeStr(type, str) {
|
||||
if(str == '&') {
|
||||
if(str == '&'|| !str) {
|
||||
return []
|
||||
} else {
|
||||
return str.split('|').map(cur => {
|
||||
let arr = cur.split('&');
|
||||
let result = {};
|
||||
switch (type) {
|
||||
case 'fixReward': {
|
||||
let [gid, count] = arr;
|
||||
result = { gid: parseInt(gid), count: parseInt(count)};
|
||||
break;
|
||||
}
|
||||
case 'conditionReward': {
|
||||
let [gid, count, condition] = arr;
|
||||
result = { gid: parseInt(gid), count: parseInt(count), condition: parseInt(condition) };
|
||||
break;
|
||||
}
|
||||
case 'randomReward': {
|
||||
let [gid, count, frequency] = arr;
|
||||
result = { gid: parseInt(gid), count: parseInt(count), frequency: parseInt(frequency) };
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return decodeStrSingle(type,cur);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
export function decodeStrSingle(type, str) { //单层,返回对象而不是数组
|
||||
if(str == '&'|| !str) {
|
||||
return {}
|
||||
} else {
|
||||
let arr = str.split('&');
|
||||
let result = {};
|
||||
switch (type) {
|
||||
case 'fixReward': {
|
||||
let [gid, count] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
result = { gid: parseInt(gid), count: parseInt(count)};
|
||||
break;
|
||||
}
|
||||
case 'conditionReward': {
|
||||
let [gid, count, condition] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
result = { gid: parseInt(gid), count: parseInt(count), condition: parseInt(condition) };
|
||||
break;
|
||||
}
|
||||
case 'randomReward': {
|
||||
let [gid, count, frequency] = arr;
|
||||
if(isNaN(gid) || isNaN(count)) throw new Error('格式错误');
|
||||
result = { gid: parseInt(gid), count: parseInt(count), frequency: parseInt(frequency) };
|
||||
}
|
||||
case 'eventSuitLevel': {
|
||||
let [min, max] = arr;
|
||||
if(isNaN(min) || isNaN(max)) throw new Error('格式错误');
|
||||
result = { min: parseInt(min), max: parseInt(max) };
|
||||
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
// 获取物品
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user