|
|
|
@@ -11,7 +11,7 @@ import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
|
|
|
|
|
import { TowerTaskRecModel } from '../db/TowerTaskRec';
|
|
|
|
|
import { cloneDeep } from 'lodash';
|
|
|
|
|
import { Rank } from './rankService';
|
|
|
|
|
import { checkTask } from './taskService';
|
|
|
|
|
import { checkActivityTask, checkTask } from './taskService';
|
|
|
|
|
import { getRandExpedition, gameData } from '../pubUtils/data';
|
|
|
|
|
import { ItemInter, RewardInter } from '../pubUtils/interface';
|
|
|
|
|
import { getTimeFunM } from '../pubUtils/timeUtil';
|
|
|
|
@@ -30,7 +30,7 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const tower = await TowerRecordModel.getRecordByLv(roleId, towerLv);
|
|
|
|
|
if(!tower) {
|
|
|
|
|
if (!tower) {
|
|
|
|
|
return { status: -1, resResult: resResult(STATUS.TOWER_NOT_FOUND) };
|
|
|
|
|
}
|
|
|
|
|
let { heroes: recHeroes = [], warStatus = [] } = tower;
|
|
|
|
@@ -44,9 +44,11 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
|
|
|
|
|
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_CHALLENGE) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return { status: 0, data: {
|
|
|
|
|
heroes: recHeroes, warStatus: curWarStatus
|
|
|
|
|
}};
|
|
|
|
|
return {
|
|
|
|
|
status: 0, data: {
|
|
|
|
|
heroes: recHeroes, warStatus: curWarStatus
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function towerBattleEnd(sid: string, funcs: number[], roleId: string, serverId: number, battleCode: string, battleId: number, succeed: boolean, heroes: Array<number>) {
|
|
|
|
@@ -81,20 +83,21 @@ export async function towerBattleEnd(sid: string, funcs: number[], roleId: strin
|
|
|
|
|
if (nextTowerInfo) {
|
|
|
|
|
const { warArray } = nextTowerInfo;
|
|
|
|
|
const sts = warArray.map(id => {
|
|
|
|
|
return {warId: id, status: false};
|
|
|
|
|
return { warId: id, status: false };
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await TowerRecordModel.createRecord({roleId, lv: towerLv + 1, warStatus: sts});
|
|
|
|
|
await TowerRecordModel.createRecord({ roleId, lv: towerLv + 1, warStatus: sts });
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const { reward } = gameData.tower.get(towerLv);
|
|
|
|
|
if (reward) towerReward = reward;
|
|
|
|
|
if (towerLv + 1 == HANG_UP_CONSTS.ENABLE_LV) {
|
|
|
|
|
await startHangUp(roleId, roleName);
|
|
|
|
|
pinus.app.get('channelService').pushMessageByUids('hangUpEnable', resResult(STATUS.SUCCESS, {enable: true}), [{uid: roleId, sid}]);
|
|
|
|
|
pinus.app.get('channelService').pushMessageByUids('hangUpEnable', resResult(STATUS.SUCCESS, { enable: true }), [{ uid: roleId, sid }]);
|
|
|
|
|
}
|
|
|
|
|
// 任务
|
|
|
|
|
await checkTask(roleId, sid, funcs, TASK_TYPE.BATTLE_TOWER_LV, role.towerLv, false, {});
|
|
|
|
|
await checkActivityTask(serverId, sid, funcs, roleId, TASK_TYPE.BATTLE_TOWER_LV, 1, { towerLv: role.towerLv });
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
status: 0,
|
|
|
|
@@ -113,20 +116,20 @@ async function startHangUp(roleId: string, roleName: string) {
|
|
|
|
|
|
|
|
|
|
export async function checkHangUpSpdUpCnt(roleId: string, cnt: number, curTime: Date) {
|
|
|
|
|
const role = await RoleModel.findByRoleId(roleId);
|
|
|
|
|
let {hangUpSpdUpCnt, gold, lastSpdUpTime} = role;
|
|
|
|
|
let { hangUpSpdUpCnt, gold, lastSpdUpTime } = role;
|
|
|
|
|
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime) && hangUpSpdUpCnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
|
|
|
|
|
hangUpSpdUpCnt = HANG_UP_CONSTS.MAX_SPD_UP_CNT;
|
|
|
|
|
}
|
|
|
|
|
if (cnt > hangUpSpdUpCnt) {
|
|
|
|
|
return {status: -1, resResult:resResult(STATUS.TOWER_NOT_ENOUGH_HANG_UP_TIME)}
|
|
|
|
|
}
|
|
|
|
|
return {status: 0, data: {hangUpSpdUpCnt, gold, lastSpdUpTime}}
|
|
|
|
|
if (cnt > hangUpSpdUpCnt) {
|
|
|
|
|
return { status: -1, resResult: resResult(STATUS.TOWER_NOT_ENOUGH_HANG_UP_TIME) }
|
|
|
|
|
}
|
|
|
|
|
return { status: 0, data: { hangUpSpdUpCnt, gold, lastSpdUpTime } }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)}
|
|
|
|
|
if (towerLv < HANG_UP_CONSTS.ENABLE_LV) {
|
|
|
|
|
return { status: -1, resResult: resResult(STATUS.TOWER_HANG_UP_NOT_START) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let towerInfo = gameData.tower.get(towerLv - 1); // towerLv 是当前层,奖励计算按照已经通过的层,即上一层
|
|
|
|
@@ -150,41 +153,41 @@ export async function calcuHangUpReward(roleId: string, speedUp = false, speedUp
|
|
|
|
|
let multi = Math.floor(HANG_UP_CONSTS.SPD_UP_REC_TIME / HANG_UP_CONSTS.UNIT_TIME);
|
|
|
|
|
let spdUpRec = await HangUpSpdUpRecModel.getSpdUpRec(roleId, towerLv - 1);
|
|
|
|
|
let goods = [];
|
|
|
|
|
if(spdUpRec) {
|
|
|
|
|
if (spdUpRec) {
|
|
|
|
|
let { notReceivedGoodsList = [], cnt } = spdUpRec;
|
|
|
|
|
let notReceivedGoods = notReceivedGoodsList.find(cur => cur.cnt == cnt );
|
|
|
|
|
goods = notReceivedGoods?notReceivedGoods.goods:[];
|
|
|
|
|
let notReceivedGoods = notReceivedGoodsList.find(cur => cur.cnt == cnt);
|
|
|
|
|
goods = notReceivedGoods ? notReceivedGoods.goods : [];
|
|
|
|
|
}
|
|
|
|
|
for(let {id, count} of baseReward) {
|
|
|
|
|
for (let { id, count } of baseReward) {
|
|
|
|
|
let newCount = cal.mul(count, multi);
|
|
|
|
|
let oldGoods = goods.find(cur => cur.gid == id);
|
|
|
|
|
if(oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
|
|
|
|
if (oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
|
|
|
|
let roundCount = Math.floor(newCount);
|
|
|
|
|
if(newCount > roundCount) {
|
|
|
|
|
needReceiveGoods.push({gid: id, count: cal.sub(newCount, roundCount)});
|
|
|
|
|
if (newCount > roundCount) {
|
|
|
|
|
needReceiveGoods.push({ gid: id, count: cal.sub(newCount, roundCount) });
|
|
|
|
|
}
|
|
|
|
|
if(roundCount > 0) {
|
|
|
|
|
timeReward.push({id, count: roundCount})
|
|
|
|
|
if (roundCount > 0) {
|
|
|
|
|
timeReward.push({ id, count: roundCount })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let lastRec = await HangUpRecordModel.getLastRec(roleId);
|
|
|
|
|
let notReceivedGoods = lastRec?lastRec.notReceivedGoods: [];
|
|
|
|
|
let notReceivedGoods = lastRec ? lastRec.notReceivedGoods : [];
|
|
|
|
|
|
|
|
|
|
let multi = Math.floor(deltaTime / HANG_UP_CONSTS.UNIT_TIME); // 结算奖励的倍数,受最大时间限制
|
|
|
|
|
|
|
|
|
|
// console.log(deltaTime, multi, baseReward);
|
|
|
|
|
for(let {id, count} of baseReward) {
|
|
|
|
|
for (let { id, count } of baseReward) {
|
|
|
|
|
let newCount = cal.mul(count, multi);
|
|
|
|
|
let oldGoods = notReceivedGoods.find(cur => cur.gid == id);
|
|
|
|
|
if(oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
|
|
|
|
if (oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
|
|
|
|
let roundCount = Math.floor(newCount);
|
|
|
|
|
if(newCount > roundCount) {
|
|
|
|
|
needReceiveGoods.push({gid: id, count: cal.sub(newCount, roundCount)});
|
|
|
|
|
if (newCount > roundCount) {
|
|
|
|
|
needReceiveGoods.push({ gid: id, count: cal.sub(newCount, roundCount) });
|
|
|
|
|
}
|
|
|
|
|
if(roundCount > 0) {
|
|
|
|
|
timeReward.push({id, count: roundCount})
|
|
|
|
|
if (roundCount > 0) {
|
|
|
|
|
timeReward.push({ id, count: roundCount })
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -207,16 +210,16 @@ async function checkCond(roleId: string, heroes, type: number, param: number, cn
|
|
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
|
case 1:
|
|
|
|
|
for(let seqId of heroes) {
|
|
|
|
|
const {star, colorStar} = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
for (let seqId of heroes) {
|
|
|
|
|
const { star, colorStar } = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
if (star + colorStar >= param) {
|
|
|
|
|
heroCnt++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
for(let seqId of heroes) {
|
|
|
|
|
let {hid} = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
for (let seqId of heroes) {
|
|
|
|
|
let { hid } = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
const hInfo = gameData.hero.get(hid);
|
|
|
|
|
if (hInfo.camp === param) {
|
|
|
|
|
heroCnt++;
|
|
|
|
@@ -224,8 +227,8 @@ async function checkCond(roleId: string, heroes, type: number, param: number, cn
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
for(let seqId of heroes) {
|
|
|
|
|
let {hid} = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
for (let seqId of heroes) {
|
|
|
|
|
let { hid } = await HeroModel.findBySeqIdAndRole(seqId, roleId);
|
|
|
|
|
const hInfo = gameData.hero.get(hid);
|
|
|
|
|
if (gameData.job.get(hInfo.jobid).job_class === param) {
|
|
|
|
|
heroCnt++;
|
|
|
|
@@ -244,7 +247,7 @@ async function checkCond(roleId: string, heroes, type: number, param: number, cn
|
|
|
|
|
export async function checkTaskConditions(roleId: string, heroes: number[], condition: { type: number, param: number, count: number }[]) {
|
|
|
|
|
|
|
|
|
|
let res = true;
|
|
|
|
|
for (let {type, param, count} of condition) {
|
|
|
|
|
for (let { type, param, count } of condition) {
|
|
|
|
|
const checkRes = await checkCond(roleId, heroes, type, param, count);
|
|
|
|
|
if (!checkRes) {
|
|
|
|
|
res = false;
|
|
|
|
@@ -264,28 +267,28 @@ export async function checkTaskConditions(roleId: string, heroes: number[], cond
|
|
|
|
|
export async function createCurTasks(towerLv: number, batchCode: string, roleId: string, roleName: string, hideNum: number, showNum: number, rids: Array<number>) {
|
|
|
|
|
let randomList = [];
|
|
|
|
|
let dicTask = gameData.towerTask;
|
|
|
|
|
for(let [ _id, task] of dicTask) {
|
|
|
|
|
let {suitFloor: {min, max} } = task;
|
|
|
|
|
let flag = max?(towerLv >= min && towerLv <= max): (towerLv >= min);
|
|
|
|
|
if(flag) {
|
|
|
|
|
for (let [_id, task] of dicTask) {
|
|
|
|
|
let { suitFloor: { min, max } } = task;
|
|
|
|
|
let flag = max ? (towerLv >= min && towerLv <= max) : (towerLv >= min);
|
|
|
|
|
if (flag) {
|
|
|
|
|
randomList.push(task);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
let returnTasks = new Array();
|
|
|
|
|
const arr = [{refreshStatus: 0, num: hideNum}, {refreshStatus: 1, num: showNum}];
|
|
|
|
|
for(let {refreshStatus, num} of arr) {
|
|
|
|
|
const arr = [{ refreshStatus: 0, num: hideNum }, { refreshStatus: 1, num: showNum }];
|
|
|
|
|
for (let { refreshStatus, num } of arr) {
|
|
|
|
|
let taskIds = [];
|
|
|
|
|
for(let i = 0; i < num; i++) {
|
|
|
|
|
for (let i = 0; i < num; i++) {
|
|
|
|
|
let list = randomList.filter(cur => !rids.includes(cur.taskId));
|
|
|
|
|
let {dic: tmp} = getRandEelmWithWeight(list);
|
|
|
|
|
if(tmp) {
|
|
|
|
|
let { dic: tmp } = getRandEelmWithWeight(list);
|
|
|
|
|
if (tmp) {
|
|
|
|
|
taskIds.push(tmp.taskId);
|
|
|
|
|
rids.push(tmp.taskId)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const curTasks = await TowerTaskRecModel.createTasks(roleId, roleName, batchCode, taskIds, refreshStatus);
|
|
|
|
|
|
|
|
|
|
if(refreshStatus == 1) {
|
|
|
|
|
if (refreshStatus == 1) {
|
|
|
|
|
returnTasks = curTasks;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -295,56 +298,56 @@ export async function createCurTasks(towerLv: number, batchCode: string, roleId:
|
|
|
|
|
|
|
|
|
|
export function getRemainTime(curTime: Date) {
|
|
|
|
|
let nextTime = <number>getTimeFunM(curTime).getAfterDayWithHour(1);
|
|
|
|
|
return Math.floor((nextTime - curTime.getTime())/1000);
|
|
|
|
|
return Math.floor((nextTime - curTime.getTime()) / 1000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function treatTask(recs: Array<any>, curTime: Date) {
|
|
|
|
|
return recs.map(cur => {
|
|
|
|
|
let { heroes, batchCode, taskId, taskCode, status, completeTime} = cur;
|
|
|
|
|
let { heroes, batchCode, taskId, taskCode, status, completeTime } = cur;
|
|
|
|
|
|
|
|
|
|
let getStatusResult = getTaskStatus(status, completeTime, curTime);
|
|
|
|
|
return { heroes, batchCode, taskId, taskCode, completeTime, ...getStatusResult }
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 刷新任务,正在进行中的部分保留,没有进行中的刷掉
|
|
|
|
|
export function getDoingOrWaitingTasks (taskList: Array<any>, curTime: Date) {
|
|
|
|
|
export function getDoingOrWaitingTasks(taskList: Array<any>, curTime: Date) {
|
|
|
|
|
let doingTaskCode = new Array<string>(), waitingTaskCode = new Array<string>(), doingIds = new Array<number>();
|
|
|
|
|
for(let task of taskList) {
|
|
|
|
|
let {status} = getTaskStatus(task.status, task.completeTime, curTime);
|
|
|
|
|
if(status == 1||status == 2) {
|
|
|
|
|
for (let task of taskList) {
|
|
|
|
|
let { status } = getTaskStatus(task.status, task.completeTime, curTime);
|
|
|
|
|
if (status == 1 || status == 2) {
|
|
|
|
|
doingTaskCode.push(task.taskCode);
|
|
|
|
|
doingIds.push(task.taskId);
|
|
|
|
|
} else if(status == 0|| status == 3) {
|
|
|
|
|
} else if (status == 0 || status == 3) {
|
|
|
|
|
waitingTaskCode.push(task.taskCode);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return {doingTaskCode, waitingTaskCode, doingIds}
|
|
|
|
|
return { doingTaskCode, waitingTaskCode, doingIds }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getTaskStatus(status: number, completeTime: Date, curTime: Date) {
|
|
|
|
|
let remainTime = 0;
|
|
|
|
|
if(status == 1) {
|
|
|
|
|
if (status == 1) {
|
|
|
|
|
// console.log(curTime.getTime(), completeTime.getTime())
|
|
|
|
|
remainTime = Math.floor((completeTime.getTime() - curTime.getTime())/1000);
|
|
|
|
|
if(remainTime < 0) {
|
|
|
|
|
status = 2; remainTime = 0;
|
|
|
|
|
}
|
|
|
|
|
remainTime = Math.floor((completeTime.getTime() - curTime.getTime()) / 1000);
|
|
|
|
|
if (remainTime < 0) {
|
|
|
|
|
status = 2; remainTime = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {status, remainTime}
|
|
|
|
|
return { status, remainTime }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function getTasksReward(roleId: string, curTime: Date) {
|
|
|
|
|
let oldTasks = await TowerTaskRecModel.getCurTasks(roleId);
|
|
|
|
|
let goods: ItemInter[] = [];
|
|
|
|
|
for(let task of oldTasks) {
|
|
|
|
|
let {completeTime, reward, termsForAdd, additionalReward} = gameData.towerTask.get(task.taskId);
|
|
|
|
|
for (let task of oldTasks) {
|
|
|
|
|
let { completeTime, reward, termsForAdd, additionalReward } = gameData.towerTask.get(task.taskId);
|
|
|
|
|
if (task.sendTime && task.sendTime.getTime() + completeTime * 1000 < curTime.getTime()) {
|
|
|
|
|
goods = goods.concat(reward);
|
|
|
|
|
if(termsForAdd) {
|
|
|
|
|
if (termsForAdd) {
|
|
|
|
|
const result = checkTaskConditions(roleId, task.heroes, termsForAdd);
|
|
|
|
|
if(result) {
|
|
|
|
|
if (result) {
|
|
|
|
|
goods = goods.concat(additionalReward);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@@ -369,7 +372,7 @@ export function getRandRobot(cnt = 1, withAttr = false) {
|
|
|
|
|
if (!warInfo || !warInfo.length) continue;
|
|
|
|
|
|
|
|
|
|
let heroes = [];
|
|
|
|
|
for(let hero of warInfo) {
|
|
|
|
|
for (let hero of warInfo) {
|
|
|
|
|
if (hero && hero.relation === 2 && hero.actorId) {
|
|
|
|
|
heroes.push(hero.actorId);
|
|
|
|
|
}
|
|
|
|
@@ -383,11 +386,11 @@ export function getRandRobot(cnt = 1, withAttr = false) {
|
|
|
|
|
* 拷贝敌军数组并添加当前血量字段
|
|
|
|
|
* @param source 原敌军数组,不包含当前血量字段
|
|
|
|
|
*/
|
|
|
|
|
export function transBossHpArr(source: Array<{dataId: number, hp: number, actorId: number}>): Array<{dataId: number, hp: number, curHp: number, actorId: number}> {
|
|
|
|
|
export function transBossHpArr(source: Array<{ dataId: number, hp: number, actorId: number }>): Array<{ dataId: number, hp: number, curHp: number, actorId: number }> {
|
|
|
|
|
let desArr = [];
|
|
|
|
|
source.forEach(elem => {
|
|
|
|
|
let { hp } = elem;
|
|
|
|
|
desArr.push(Object.assign(elem, {curHp: hp}));
|
|
|
|
|
desArr.push(Object.assign(elem, { curHp: hp }));
|
|
|
|
|
});
|
|
|
|
|
return cloneDeep(desArr);
|
|
|
|
|
}
|
|
|
|
|