添加主线关卡和每日关卡
This commit is contained in:
166
game-server/app/servers/battle/handler/battleUtils.ts
Normal file
166
game-server/app/servers/battle/handler/battleUtils.ts
Normal file
@@ -0,0 +1,166 @@
|
||||
|
||||
import { ActionPointModel } from '../../../db/ActionPoint';
|
||||
import { BattleDropModel } from '../../../db/BattleDrop';
|
||||
import { CounterModel } from '../../../db/Counter';
|
||||
import { EquipModel } from '../../../db/Equip';
|
||||
|
||||
import { getWarById, getGoodById } from '../../../util/gamedata';
|
||||
import { decodeStr } from '../../../util/util';
|
||||
import { ACTION_POIN, BATTLE_REWARD_TYPE, GOOD_TYPE } from '../../../consts/consts';
|
||||
|
||||
export async function getAp(now: number, roleId: string) {
|
||||
let dataAp = await ActionPointModel.getAp(roleId);
|
||||
const maxAp = ACTION_POIN.MAX; // 最大体力值
|
||||
const per = ACTION_POIN.PER; // 恢复时间(ms)
|
||||
let {ap, refTime} = dataAp;
|
||||
if(ap >= maxAp) {
|
||||
// 体力溢出不需要做时间的处理
|
||||
return { ap, maxAp, refTime: now, apRemainTime:0, isOver: true }
|
||||
} else {
|
||||
if(refTime > now) refTime = now; // refTime:每次记录时候最近的一个整的时间点,绝对不会大于now
|
||||
let n = Math.floor((now - refTime)/per); // 上次记录到现在可以增长多少体力
|
||||
ap += n; // 增加上
|
||||
if(ap >= maxAp) { // 加上后溢出了
|
||||
ap = maxAp;
|
||||
return { ap, maxAp, refTime: now, apRemainTime:0, isOver: true }
|
||||
} else {
|
||||
refTime += n * per; // 更新refTime到离现在最近的一个整的时间点
|
||||
let apRemainTime = Math.floor((refTime + per - now)/1000); // 恢复下一点需要多少时间
|
||||
|
||||
return { ap, maxAp, refTime, apRemainTime, isOver: false }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function setAp(now: number, roleId: string, changeAp: number) {
|
||||
let ApResult = await getAp(now, roleId);
|
||||
let { ap, maxAp, refTime, apRemainTime, isOver } = ApResult; // 更新ap
|
||||
ap += changeAp;
|
||||
if(ap >= maxAp) { // 溢出
|
||||
refTime = now;
|
||||
apRemainTime = 0;
|
||||
}
|
||||
if(ap < 0) return null // 体力不足
|
||||
await ActionPointModel.saveAp(roleId, ap, refTime);
|
||||
|
||||
if(isOver && ap < maxAp) apRemainTime = Math.floor(ACTION_POIN.PER / 1000); // 特殊处理
|
||||
return {ap, maxAp, refTime, apRemainTime}
|
||||
}
|
||||
|
||||
export class WarReward {
|
||||
roleId: string;
|
||||
roleName: string;
|
||||
battleId: number;
|
||||
condition: Map<number, boolean>;
|
||||
warInfo: any;
|
||||
isSuccess: boolean;
|
||||
rewards: Array<{type: number, gid: number, count: number}>;
|
||||
|
||||
constructor(roleId: string, roleName: string, battleId: number, isSuccess: boolean) {
|
||||
this.roleId = roleId;
|
||||
this.roleName = roleName;
|
||||
this.battleId = battleId;
|
||||
this.condition = new Map();
|
||||
this.warInfo = getWarById(battleId);
|
||||
this.isSuccess = isSuccess;
|
||||
}
|
||||
|
||||
public setCondition(id: number, isOk: boolean) {
|
||||
this.condition.set(id, isOk);
|
||||
}
|
||||
|
||||
private handleFixReward(num: number) {
|
||||
if(this.isSuccess) { // 成功了才给固定奖励
|
||||
let {fixReward} = this.warInfo;
|
||||
let reward = decodeStr('fixReward', fixReward);
|
||||
for(let obj of reward) this.rewards.push({type: BATTLE_REWARD_TYPE.FIX_REWARD, ...obj, count: obj.count * num});
|
||||
}
|
||||
}
|
||||
private handleConditionReward(num: number) {
|
||||
if(this.isSuccess) {
|
||||
let {conditionReward} = this.warInfo;
|
||||
let reward = decodeStr('conditionReward', conditionReward);
|
||||
for(let obj of reward) {
|
||||
if(this.condition.get(obj.condition)) {
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.CONDITION_REWARD, ...obj, count: obj.count * num});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async handleRandomReward(num: number) {
|
||||
if(this.isSuccess) {
|
||||
let {randomReward} = this.warInfo;
|
||||
let reward = decodeStr('randomReward', randomReward);
|
||||
for(let obj of reward) {
|
||||
let { gid, frequency } = obj;
|
||||
let dropHistory = await BattleDropModel.findByGid(this.roleId, this.battleId, gid);
|
||||
let { getNum = 0, allNum = 0, getSum = 0, allSum = 0 } = dropHistory;
|
||||
for(let i = 0; i < num; i ++) {
|
||||
let flag = false; // 是否可以获得
|
||||
if(allNum + 1 > frequency) {
|
||||
allNum = 0; getNum = 0;
|
||||
}
|
||||
allNum++; allSum++;
|
||||
if(getNum == 0) {
|
||||
let r = Math.random();
|
||||
if(r <= 1/frequency*allNum || (allNum >= frequency) ) {
|
||||
flag = true; // 独立概率随机
|
||||
}
|
||||
}
|
||||
if(flag) {
|
||||
getNum ++; getSum++;
|
||||
this.rewards.push({type: BATTLE_REWARD_TYPE.RANDOM_REWARD, ...obj});
|
||||
}
|
||||
}
|
||||
await BattleDropModel.updateByGid(this.roleId, this.battleId, gid, {
|
||||
getNum, allNum, getSum, allSum
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async saveReward(num: number) {
|
||||
this.rewards = new Array();
|
||||
await this.handleFixReward(num);
|
||||
await this.handleConditionReward(num);
|
||||
await this.handleRandomReward(num);
|
||||
|
||||
let returnGoods = new Array();
|
||||
for(let goods of this.rewards) {
|
||||
let goodInfo = getGoodById(goods.gid);
|
||||
if(goodInfo.good_type == 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.good_type
|
||||
}
|
||||
const equip = await EquipModel.createEquip(equipInfo);
|
||||
cnt -= 1;
|
||||
weaponsData.push(equip);
|
||||
}
|
||||
return weaponsData;
|
||||
}
|
||||
|
||||
}
|
||||
107
game-server/app/servers/battle/handler/dailyBattleHandler.ts
Normal file
107
game-server/app/servers/battle/handler/dailyBattleHandler.ts
Normal file
@@ -0,0 +1,107 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { DailyRecordModel } from '../../../db/DailyRecord';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { getGamedata } from '../../../util/gamedata';
|
||||
import { WAR_TYPE } from '../../../consts/consts';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DailyBattleHandler(app);
|
||||
}
|
||||
|
||||
export class DailyBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
// 获取关卡列表
|
||||
async getData(msg: { }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleList(roleId, WAR_TYPE.DAILY);
|
||||
|
||||
let dicDaily = getGamedata('dic_daily');
|
||||
let dicDailyWar = getGamedata('dic_daily_war');
|
||||
|
||||
let result = new Array();
|
||||
for(let {type, name, sum} of dicDaily) {
|
||||
let refreshResult = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let {count} = refreshResult;
|
||||
let wars = new Array();
|
||||
for(let {war_id, daily_type, difficulty, cost, gk_name, previousGk } of dicDailyWar) {
|
||||
if(daily_type == type) {
|
||||
let status = 0, star = 0;
|
||||
let curBattle = BattleRecord.find(cur => cur.battleId == war_id);
|
||||
if(curBattle) {
|
||||
status = 2;
|
||||
star = curBattle.star;
|
||||
} else {
|
||||
if (previousGk) {
|
||||
let preBattleRecord = BattleRecord.find(cur => cur.battleId == previousGk);
|
||||
if(preBattleRecord) {
|
||||
status = 1;
|
||||
} else {
|
||||
status = 0;
|
||||
}
|
||||
} else {
|
||||
status = 1;
|
||||
}
|
||||
}
|
||||
wars.push({
|
||||
battleId: war_id, difficulty, cost, star, status, name: gk_name
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
result.push({
|
||||
type, count, sum, name,
|
||||
wars
|
||||
});
|
||||
}
|
||||
|
||||
return { code: 200, data: result }
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// 检查每日本次数checkBattle使用
|
||||
export async function checkDaily(roleId: string, battleId: number, inc: number) {
|
||||
let dicDaily = getGamedata('dic_daily');
|
||||
let dicDailyWar = getGamedata('dic_daily_war');
|
||||
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
||||
if(!dailyWar) return { status: -1, msg: '未找到该关卡' };
|
||||
let type = dailyWar.daily_type;
|
||||
|
||||
let curDaily = dicDaily.find(cur => cur.type == type);
|
||||
if(!curDaily) return { status: -1, msg: '未找到该类型' };
|
||||
let dailyRecord = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let { count } = dailyRecord;
|
||||
if(count + inc > curDaily.sum ) {
|
||||
return { status: -1, msg: '次数不足' }
|
||||
}
|
||||
return {status: 1, type, count, sum: curDaily.sum};
|
||||
}
|
||||
|
||||
// 检查每日本次数warEnd和warSweep使用
|
||||
export async function checkDailyAndIncrease(roleId: string, battleId: number, inc: number, isRef: boolean) {
|
||||
let dicDaily = getGamedata('dic_daily');
|
||||
let dicDailyWar = getGamedata('dic_daily_war');
|
||||
let dailyWar = dicDailyWar.find(cur => cur.war_id == battleId);
|
||||
if(!dailyWar) return { status: -1, msg: '未找到该关卡' };
|
||||
let type = dailyWar.daily_type;
|
||||
|
||||
let curDaily = dicDaily.find(cur => cur.type == type);
|
||||
if(!curDaily) return { status: -1, msg: '未找到该类型' };
|
||||
|
||||
let dailyRecord;
|
||||
if(isRef) {
|
||||
dailyRecord = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
} else {
|
||||
dailyRecord = await DailyRecordModel.getDailyRecordById(roleId, type);
|
||||
}
|
||||
let { count } = dailyRecord;
|
||||
if(count + inc > curDaily.sum ) {
|
||||
return { status: -1, msg: '次数不足' }
|
||||
}
|
||||
let result = await DailyRecordModel.increseDailyCount(roleId, type, inc);
|
||||
return {status: 1, type, count: result.count, sum: curDaily.sum};
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { BattleSweepRecordModel } from '../../../db/BattleSweepRecord';
|
||||
import { getWarById, getGoodById } from '../../../util/gamedata';
|
||||
import { CounterModel } from '../../../db/Counter';
|
||||
import { HeroModel } from '../../../db/Hero';
|
||||
import { EquipModel } from '../../../db/Equip';
|
||||
import { genCode } from '../../../util/util';
|
||||
import { getAp, setAp, WarReward } from './battleUtils';
|
||||
import { WAR_TYPE } from '../../../consts/consts';
|
||||
import { checkDaily, checkDailyAndIncrease } from './dailyBattleHandler';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new NormalBattleHandler(app);
|
||||
@@ -14,25 +15,44 @@ export class NormalBattleHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
// 进入关卡前,记录信息,生成唯一标识
|
||||
// 获取关卡列表
|
||||
async checkBattle(msg: {battleId: number, heroes: Array<any> }, session: BackendSession) {
|
||||
const { battleId, heroes } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return {
|
||||
code: 202,
|
||||
data: "缺少关卡信息"
|
||||
}
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
}
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
}
|
||||
|
||||
let apJson = await getAp(Date.now(), roleId);
|
||||
let {ap} = apJson;
|
||||
if(ap < warInfo.cost) {
|
||||
return { code: 202, data: "体力不足" }
|
||||
}
|
||||
|
||||
// 前置关卡是否挑战过
|
||||
let previousGk = warInfo.previousGk;
|
||||
if(previousGk) {
|
||||
let preBattle = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, previousGk, 1);
|
||||
if(!preBattle) return {code: 202, data: '需要完成上一关才可以挑战'};
|
||||
}
|
||||
|
||||
let dailyNum = {};
|
||||
if(warInfo.war_type == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDaily(roleId, battleId, 1);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
}
|
||||
const battleCode = genCode(8);
|
||||
const BattleRecord = await BattleRecordModel.updateBattleRecordByCode(battleCode, {
|
||||
$set: {
|
||||
roleId,
|
||||
roleName,
|
||||
battleId,
|
||||
roleId, roleName, battleId,
|
||||
status: 0,
|
||||
warName: warInfo.gk_name,
|
||||
warType: warInfo.war_type,
|
||||
@@ -42,28 +62,49 @@ export class NormalBattleHandler {
|
||||
|
||||
let {status} = BattleRecord;
|
||||
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
battleId, battleCode, status
|
||||
battleId, battleCode, status, apJson, dailyNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 关卡结算,记录使用的武将,获得奖励
|
||||
async battleEnd(msg: {battleCode: string, battleId: number, isSuccess: boolean, heroes: Array<any>, }, session: BackendSession) {
|
||||
// 关卡列表
|
||||
async getBattleList(msg: {type: number }, session: BackendSession) {
|
||||
const { type } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
const { battleCode, battleId, isSuccess, heroes } = msg;
|
||||
const BattleRecord = await BattleRecordModel.getBattleList(roleId, type);
|
||||
let result = []; // 去重
|
||||
for(let br of BattleRecord) {
|
||||
let index = result.findIndex(cur => cur.battleId == br.battleId);
|
||||
if(index == -1) {
|
||||
result.push(br);
|
||||
}
|
||||
}
|
||||
|
||||
return { code: 200, data: result }
|
||||
}
|
||||
|
||||
// 关卡结算,记录使用的武将,获得奖励
|
||||
async battleEnd(msg: {battleCode: string, battleId: number, isSuccess: boolean, star: number, heroes: Array<any>, }, session: BackendSession) {
|
||||
|
||||
const { battleCode, battleId, isSuccess, heroes, star } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
}
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
}
|
||||
|
||||
const BattleRecord = await BattleRecordModel.getBattleRecordByCode(battleCode, true);
|
||||
if(!BattleRecord || BattleRecord.status != 0) {
|
||||
return {
|
||||
code: 202,
|
||||
data: '关卡状态错误'
|
||||
}
|
||||
return { code: 202, data: '关卡状态错误' }
|
||||
}
|
||||
|
||||
let flag = 1; // 对比hero信息
|
||||
@@ -72,21 +113,44 @@ export class NormalBattleHandler {
|
||||
if(dbHeroes.indexOf(hid) == -1) flag = 0;
|
||||
}
|
||||
if(!flag) {
|
||||
return {
|
||||
code: 202,
|
||||
data: '关卡信息不同'
|
||||
}
|
||||
return { code: 202, data: '关卡信息不同' }
|
||||
}
|
||||
|
||||
let params = {}, reward: Array<any>;
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost); // 扣除体力
|
||||
if(!apJson) {
|
||||
return { code: 202, data: '体力不足' }
|
||||
}
|
||||
|
||||
let dailyNum = {};
|
||||
if(warInfo.war_type == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, 1, false);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
}
|
||||
|
||||
let warReward = new WarReward(roleId, roleName, battleId, isSuccess);
|
||||
let params = {};
|
||||
if(isSuccess) { // 挑战胜利
|
||||
params = {
|
||||
$set: {
|
||||
status: 1,
|
||||
star,
|
||||
record: { heroes }
|
||||
}
|
||||
}
|
||||
reward = await this.handleReward(roleId, roleName, warInfo.reward);
|
||||
|
||||
// 是否首通
|
||||
let condition1 = await BattleRecordModel.getBattleRecordByIdAndStatus(roleId, battleId, 1);
|
||||
if(!condition1) warReward.setCondition(0, true);
|
||||
// 是否首次3星
|
||||
if(star == 3) {
|
||||
let condition2 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
|
||||
if(!condition2) warReward.setCondition(1, true);
|
||||
}
|
||||
|
||||
} else { // 挑战失败
|
||||
params = {
|
||||
$set: {
|
||||
@@ -94,9 +158,10 @@ export class NormalBattleHandler {
|
||||
record: { heroes }
|
||||
}
|
||||
}
|
||||
reward = [];
|
||||
}
|
||||
|
||||
let reward = await warReward.saveReward(1);
|
||||
|
||||
const updateResult = await BattleRecordModel.updateBattleRecordByCode(battleCode, params, true);
|
||||
let { status } = updateResult;
|
||||
|
||||
@@ -104,78 +169,71 @@ export class NormalBattleHandler {
|
||||
code: 200,
|
||||
data: {
|
||||
battleCode, battleId, status,
|
||||
goods: reward
|
||||
goods: reward,
|
||||
apJson,
|
||||
dailyNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async handleReward(roleId: string, roleName: string, rewardStr:string) {
|
||||
let {weapons, armors, items, souls} = this.decodeReward(rewardStr);
|
||||
let addWeapons = await this.rewardWeapons(roleId, roleName, weapons);
|
||||
// 暂时只处理装备
|
||||
// let addArmors = await this.rewardArmors(roleId, roleName, armors);
|
||||
// let addItems = await this.rewardItems(roleId, roleName, items);
|
||||
// let addSouls = await this.rewardSouls(roleId, roleName, souls);
|
||||
|
||||
let result = [].concat(addWeapons);
|
||||
return result;
|
||||
}
|
||||
|
||||
private async rewardWeapons (roleId: string, roleName:string, weapons: Array<{id:number,cnt:number, type: number}>) {
|
||||
|
||||
let weaponsData = [];
|
||||
for (let weapon of weapons) {
|
||||
let cnt = weapon.cnt;
|
||||
let g = getGoodById(weapon.id);
|
||||
while (cnt > 0) {
|
||||
const seqId = await CounterModel.getNewCounter('eid');
|
||||
const equipInfo = {
|
||||
roleId,
|
||||
roleName,
|
||||
eid: weapon.id,
|
||||
eName: g.name,
|
||||
seqId,
|
||||
type: weapon.type,
|
||||
lv: g.lv
|
||||
}
|
||||
const equip = await EquipModel.createEquip(equipInfo);
|
||||
cnt -= 1;
|
||||
weaponsData.push(equip);
|
||||
}
|
||||
async battleSweep(msg: {battleId: number, count: number }, session: BackendSession) {
|
||||
|
||||
const { battleId, count } = msg;
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let warInfo = getWarById(battleId);
|
||||
if(!warInfo) {
|
||||
return { code: 202, data: "缺少关卡信息" }
|
||||
}
|
||||
// 校验是否三星通关过
|
||||
let condition1 = await BattleRecordModel.getBattleRecordByIdAndStar(roleId, battleId, 3);
|
||||
if(!condition1) {
|
||||
return { code: 202, data: "需要3星通过关卡才可以扫荡" }
|
||||
}
|
||||
return weaponsData;
|
||||
}
|
||||
|
||||
private decodeReward(rewardStr: string, multiple=1) {
|
||||
let weapons = [];
|
||||
let armors = [];
|
||||
let items = [];
|
||||
let souls = [];
|
||||
rewardStr.split('|').forEach((rStr) => {
|
||||
// r[0]: type, r[1]: id, r[2]: count
|
||||
let r = rStr.split('&');
|
||||
let type = parseInt(r[0] || '')||0;
|
||||
let id = parseInt(r[1] || '') || 0;
|
||||
let cnt = (parseInt(r[2] || '') || 0) * multiple;
|
||||
if (id !== 0 && cnt !== 0) {
|
||||
switch (r[0]) {
|
||||
case '0':
|
||||
items.push({id, cnt, type});
|
||||
break;
|
||||
case '1':
|
||||
weapons.push({id, cnt, type});
|
||||
break;
|
||||
case '2':
|
||||
armors.push({id, cnt, type});
|
||||
break;
|
||||
case '3':
|
||||
souls.push({id, cnt, type});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// 扣体力
|
||||
if(!warInfo.hasOwnProperty('cost')) {
|
||||
warInfo['cost'] = 0;
|
||||
}
|
||||
const now = Date.now(); // 当前时间戳
|
||||
let apJson = await setAp(now, roleId, -1 * warInfo.cost * count); // 扣除体力
|
||||
if(!apJson) {
|
||||
return { code: 202, data: '体力不足' }
|
||||
}
|
||||
|
||||
// 扫荡次数
|
||||
let dailyNum = {};
|
||||
if(warInfo.war_type == WAR_TYPE.DAILY) {
|
||||
let checkResult = await checkDailyAndIncrease(roleId, battleId, count, true);
|
||||
if(checkResult.status == -1) {
|
||||
return {code: 202, data: checkResult.msg}
|
||||
}
|
||||
dailyNum = { type: checkResult.type, count: checkResult.count, sum: checkResult.sum };
|
||||
}
|
||||
|
||||
// 发奖励
|
||||
let warReward = new WarReward(roleId, roleName, battleId, true);
|
||||
let result = await warReward.saveReward(count);
|
||||
|
||||
// 扫荡记录
|
||||
await BattleSweepRecordModel.saveBattleSweepRecordById(roleId, battleId, {
|
||||
$set: {
|
||||
roleName,
|
||||
warName: warInfo.gk_name,
|
||||
warType: warInfo.war_type
|
||||
},
|
||||
$inc: { count }
|
||||
});
|
||||
return {weapons, armors, items, souls};
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: {
|
||||
battleId, count,
|
||||
goods: result,
|
||||
apJson,
|
||||
dailyNum
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,15 +29,23 @@ export function getGamedata(key) {
|
||||
}
|
||||
|
||||
export function getWarById(warid) {
|
||||
let warInfo = gamedata['dic_zyz_gk']||[];
|
||||
return warInfo.find(cur => {
|
||||
return cur.war_id == warid
|
||||
});
|
||||
const wars = ['dic_zyz_gk', 'dic_daily_war', 'dic_event_war']; // 关卡相关的表
|
||||
let result;
|
||||
for(let filename of wars) {
|
||||
let warInfo = gamedata[filename]||[];
|
||||
for(let war of warInfo) {
|
||||
if(war.war_id == warid) {
|
||||
result = war; break;
|
||||
}
|
||||
}
|
||||
if(result) break;
|
||||
}
|
||||
return result||[];
|
||||
}
|
||||
|
||||
export function getGoodById(gid) {
|
||||
console.log(gid)
|
||||
let goodsInfo = gamedata['goods']||[];
|
||||
let goodsInfo = gamedata['dic_goods']||[];
|
||||
return goodsInfo.find(cur => {
|
||||
return cur.good_id == gid
|
||||
});
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
|
||||
export function genCode(len) {
|
||||
const chars = '123456789ABCDEFGHJKLMNPQRSTWXYZabcdefghijklmnopqrstuvwxyz';
|
||||
const charArr = chars.split('');
|
||||
@@ -7,4 +8,29 @@
|
||||
code += charArr[Math.floor(Math.random() * charArr.length)];
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
export function decodeStr(type, str) {
|
||||
if(str == '&') str = '';
|
||||
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;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user