活动:月卡权限

This commit is contained in:
luying
2022-03-09 19:47:20 +08:00
parent dafc77954b
commit f440ef2ebe
22 changed files with 295 additions and 220 deletions
+40 -80
View File
@@ -17,6 +17,7 @@ import { ComRoleStatusHero } from '../db/ComBattleTeam';
import { sendMailByContent } from './mailService';
import { DicTowerTask } from '../pubUtils/dictionary/DicTowerTask';
import * as dicParam from '../pubUtils/dicParam';
import { getVipHungupReward } from './activity/monthlyTicketService';
/**
* 获取当前镇念塔状态
@@ -53,26 +54,20 @@ export async function getTowerStatus(role: RoleType) {
* 获取镇念塔挂机收益
* @param roleId
*/
export async function getHungupRewards(roleId: string) {
const result = await calcuHangUpReward(roleId);
if(result.status == -1) {
return result;
}
let {timeReward, startTime, deltaTime} = result.data;
let {hangUpSpdUpCnt = 0, lastSpdUpTime} = await RoleModel.findByRoleId(roleId);
export async function getHungupRewards(roleId: string, role?: RoleType) {
if(!role) role = await RoleModel.findByRoleId(roleId);
const result = await calcuHangUpReward(role);
if(!result) return false;
let { hangUpSpdUpCnt = 0, lastSpdUpTime } = role;
let {timeReward, startTime, deltaTime} = result;
let curTime = new Date();
if (shouldRefresh(lastSpdUpTime, curTime)) {
hangUpSpdUpCnt = 0;
}
let nextCostGold = getManyHangSpdUpCostGold(hangUpSpdUpCnt, 1);
return {
status: 0,
resResult: null,
data: {
startTime, hangUpPassTime: Math.floor(deltaTime/1000), hangUpSpdUpCnt: dicParam.TOWER_BOOST.TOWER_BOOSTTIME - hangUpSpdUpCnt, nextCostGold, rewards: timeReward
}
}
return { startTime, hangUpPassTime: Math.floor(deltaTime/1000), hangUpSpdUpCnt: dicParam.TOWER_BOOST.TOWER_BOOSTTIME - hangUpSpdUpCnt, nextCostGold, rewards: timeReward }
}
/**
@@ -265,43 +260,21 @@ async function startHangUp(roleId: string, roleName: string) {
await HangUpRecordModel.initRecord(roleId, roleName);
}
export async function checkHangUpSpdUpCnt(roleId: string, cnt: number, curTime: Date) {
const role = await RoleModel.findByRoleId(roleId);
let { hangUpSpdUpCnt, gold, lastSpdUpTime } = role;
if (shouldRefresh(lastSpdUpTime, curTime)) {
hangUpSpdUpCnt = 0;
}
if (cnt + hangUpSpdUpCnt > dicParam.TOWER_BOOST.TOWER_BOOSTTIME) {
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);
export async function calcuHangUpReward(role: RoleType, speedUp = false, speedUpCnt = 1, curTime = new Date()) {
let { roleId, towerLv = 1, hangUpSpdUpCnt = 0, lastSpdUpTime, vipStartTime } = role;
if (towerLv - 1 < dicParam.TOWER_HANG_UP.TOWER_HANG_UP_ENABLE_LV) {
return { status: -1, resResult: resResult(STATUS.TOWER_HANG_UP_NOT_START) }
return false
}
let towerInfo = gameData.tower.get(towerLv - 1); // towerLv 是当前层,奖励计算按照已经通过的层,即上一层
let timeReward = []; // 奖励
let needReceiveGoods = []; // 由于小数,未能领取的奖励
let baseReward = towerInfo.rewardOfcollect;
let { startTime } = await HangUpRecordModel.getCurRec(roleId);
let endTime = curTime; // 挂机结束时间,现在到开始时间,经历了10的倍数的时间
let deltaTime = curTime.getTime() - startTime.getTime(); // 累计的挂机时间,受最大时间限制
if (deltaTime > HANG_UP_CONSTS.MAX_TIME) {
deltaTime = HANG_UP_CONSTS.MAX_TIME;
endTime = curTime; // 累积到超过24小时,那么结束时间和下一次开启时间就取整了
} else {
let multiReal = Math.floor(deltaTime / HANG_UP_CONSTS.UNIT_TIME);// 距开始挂机实际过去的时间单位
endTime = new Date(startTime.getTime() + multiReal * HANG_UP_CONSTS.UNIT_TIME)
}
if (speedUp) { // 加速,直接收取6小时收益,小数的累积和普通收取独立
if (hangUpSpdUpCnt + speedUpCnt <= dicParam.TOWER_BOOST.TOWER_BOOSTTIME || !lastSpdUpTime || shouldRefresh(lastSpdUpTime, new Date)) { // 可加速
let multi = Math.floor(HANG_UP_CONSTS.SPD_UP_REC_TIME / HANG_UP_CONSTS.UNIT_TIME);
let startTime = curTime;
let endTime = new Date(curTime.getTime() + HANG_UP_CONSTS.SPD_UP_REC_TIME);
let deltaTime = endTime.getTime() - startTime.getTime(); // 累计的挂机时间,受最大时间限制
let spdUpRec = await HangUpSpdUpRecModel.getSpdUpRec(roleId, towerLv - 1);
let goods = [];
if (spdUpRec) {
@@ -309,50 +282,37 @@ export async function calcuHangUpReward(roleId: string, speedUp = false, speedUp
let notReceivedGoods = notReceivedGoodsList.find(cur => cur.cnt == cnt);
goods = notReceivedGoods ? notReceivedGoods.goods : [];
}
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);
let roundCount = Math.floor(newCount);
if (newCount > roundCount) {
needReceiveGoods.push({ gid: id, count: cal.sub(newCount, roundCount) });
}
if (roundCount > 0) {
timeReward.push({ id, count: roundCount })
}
}
let { timeReward, needReceiveGoods } = getVipHungupReward(startTime.getTime(), endTime.getTime(), baseReward, goods, vipStartTime);
return {
endLv: towerLv, startTime, deltaTime, endTime, timeReward, needReceiveGoods
};
} else {
return false
}
} else {
let { startTime } = await HangUpRecordModel.getCurRec(roleId);
let endTime = curTime; // 挂机结束时间,现在到开始时间,经历了10的倍数的时间
let deltaTime = curTime.getTime() - startTime.getTime(); // 累计的挂机时间,受最大时间限制
if (deltaTime > HANG_UP_CONSTS.MAX_TIME) {
deltaTime = HANG_UP_CONSTS.MAX_TIME;
startTime = new Date(curTime.getTime() - deltaTime);
endTime = curTime; // 累积到超过24小时,那么结束时间和下一次开启时间就取整了
} else {
let multiReal = Math.floor(deltaTime / HANG_UP_CONSTS.UNIT_TIME);// 距开始挂机实际过去的时间单位
endTime = new Date(startTime.getTime() + multiReal * HANG_UP_CONSTS.UNIT_TIME)
}
let lastRec = await HangUpRecordModel.getLastRec(roleId);
let notReceivedGoods = lastRec ? lastRec.notReceivedGoods : [];
let multi = Math.floor(deltaTime / HANG_UP_CONSTS.UNIT_TIME); // 结算奖励的倍数,受最大时间限制
let { timeReward, needReceiveGoods } = getVipHungupReward(startTime.getTime(), endTime.getTime(), baseReward, notReceivedGoods, vipStartTime);
// console.log(deltaTime, multi, 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);
let roundCount = Math.floor(newCount);
if (newCount > roundCount) {
needReceiveGoods.push({ gid: id, count: cal.sub(newCount, roundCount) });
}
if (roundCount > 0) {
timeReward.push({ id, count: roundCount })
}
}
return {
endLv: towerLv, startTime, deltaTime, endTime, timeReward, needReceiveGoods
};
}
return {
status: 0,
data: {
endLv: towerLv - 1,
startTime,
deltaTime,
endTime,
timeReward,
needReceiveGoods
}
};
}
function checkCond(heroes: TaskHero[], type: number, param: number, cnt: number) {