fix 联调时遇到的问题

This commit is contained in:
luying
2020-11-05 19:33:39 +08:00
parent ff6b8bcdca
commit bd93d9dc1c
12 changed files with 598 additions and 119 deletions

View File

@@ -1,15 +1,17 @@
import { HeroModel } from './../db/Hero';
import { HangUpRecordModel } from './../db/HangUpRecord';
import { ChannelService } from 'pinus';
import { HANG_UP_CONSTS } from './../consts/consts';
import { HANG_UP_CONSTS, TOWER_TASK_CONST } from './../consts/consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
import { RoleModel } from './../db/Role';
import { getHeroInfoById, getJobInfoById, getTowerDataByLv } from "../pubUtils/gamedata"
import { decodeArrayStr, shouldRefresh, resResult, decodeStr, cal } from '../pubUtils/util';
import { getHeroInfoById, getJobInfoById, getTowerDataByLv, getTaskById, getTaskIdByFloor } from "../pubUtils/gamedata"
import { decodeArrayStr, shouldRefresh, resResult, decodeStr, cal, getRandomWithWeight, getRefTime } from '../pubUtils/util';
import { handleFixedReward } from './rewardService';
import { STATUS } from '../consts/statusCode';
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
import TowerTaskRec, { TowerTaskRecModel } from '../db/TowerTaskRec';
import { PvpDefenseModel } from '../db/PvpDefense';
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
const battleIdStr = `${battleId}`;
@@ -114,6 +116,9 @@ export async function checkHangUpSpdUpCnt(roleId: string, cnt: number, curTime:
export async function calcuHangUpReward(roleId: string, speedUp = false, speedUpCnt = 1, curTime = new Date()) {
let { towerLv = 1, hangUpSpdUpCnt = 0, lastSpdUpTime } = await RoleModel.findByRoleId(roleId);
if(towerLv < HANG_UP_CONSTS.ENABLE_LV) {
return {status: -1, resResult: resResult(STATUS.TOWER_HANG_UP_NOT_START)}
}
let towerInfo = getTowerDataByLv(towerLv - 1); // towerLv 是当前层,奖励计算按照已经通过的层,即上一层
let timeReward = []; // 奖励
@@ -175,12 +180,15 @@ export async function calcuHangUpReward(roleId: string, speedUp = false, speedUp
}
}
return {
endLv: towerLv - 1,
startTime,
deltaTime,
endTime,
timeReward,
needReceiveGoods
status: 0,
data: {
endLv: towerLv - 1,
startTime,
deltaTime,
endTime,
timeReward,
needReceiveGoods
}
};
}
@@ -236,3 +244,45 @@ export async function checkTaskConditions(roleId: string, heroes: Array<number>,
return res;
}
/**
* 创建新的派遣任务
* @param towerLv 玩家层数
* @param roleId 玩家id
* @param roleName 玩家名
*/
export async function createCurTasks(towerLv: number, roleId: string, roleName: string) {
let taskIds = [];
const taskList = getTaskIdByFloor(towerLv)||[];
const randomList = taskList.map(taskId => getTaskById(taskId));
for(let i = 0; i < TOWER_TASK_CONST.RAND_CNT; i++) {
let list = randomList.filter(cur => !taskIds.includes(cur.taskId));
let {dic: tmp} = getRandomWithWeight(list);
if(tmp) {
taskIds.push(tmp.taskId);
}
}
const curTasks = await TowerTaskRecModel.createTasks(roleId, roleName, taskIds);
return curTasks
}
export function getRemainTime(curTime: Date) {
let nextTime = getRefTime(curTime, TOWER_TASK_CONST.REFRESH_TIME, 1);
return Math.floor((nextTime.getTime() - curTime.getTime())/1000);
}
export function treatTask(recs: Array<any>, curTime: Date) {
return recs.map(cur => {
let { heroes, batchCode, taskId, taskCode, status, completeTime} = cur;
let remainTime = 0;
if(status == 1) {
console.log(curTime.getTime(), completeTime.getTime())
remainTime = Math.floor((completeTime.getTime() - curTime.getTime())/1000);
if(remainTime < 0) {
status = 2; remainTime = 0;
}
}
return { heroes, batchCode, taskId, taskCode, status, completeTime, remainTime }
});
}

View File

@@ -23,7 +23,7 @@ export async function checkDaily(roleId: string, battleId: number, inc: number)
if(count + inc > curDaily.timesPerDay + buyCount ) {
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
}
let checkDailyResult = getDailyNum(curDaily, curDaily.timesPerDay, curDaily.timesCanBuy);
let checkDailyResult = await getDailyNum(dailyRecord, curDaily.timesPerDay, curDaily.timesCanBuy);
return {status: 1, data: {type, ...checkDailyResult}};
}
@@ -56,7 +56,7 @@ export async function checkDailyAndIncrease(roleId: string, battleId: number, in
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
}
let result = await DailyRecordModel.increseDailyCount(roleId, type, inc);
let checkDailyResult = getDailyNum(result, curDaily.timesPerDay, curDaily.timesCanBuy);
let checkDailyResult = await getDailyNum(result, curDaily.timesPerDay, curDaily.timesCanBuy);
return {status: 1, data: {type, ...checkDailyResult}};
}