镇念塔调整
This commit is contained in:
@@ -6,9 +6,10 @@ 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 } from '../pubUtils/util';
|
||||
import { decodeArrayStr, shouldRefresh, resResult, decodeStr, cal } from '../pubUtils/util';
|
||||
import { handleFixedReward } from './rewardService';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
|
||||
|
||||
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
|
||||
const battleIdStr = `${battleId}`;
|
||||
@@ -18,7 +19,8 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
|
||||
console.error(`天梯层数异常,lv ${towerLv} by ${roleId}`);
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_INFO_NOT_FOUND) };
|
||||
}
|
||||
const warIds = decodeArrayStr(towerInfo.warIds) || [];
|
||||
const warIds = decodeArrayStr(towerInfo.warArray, '&') || [];
|
||||
console.log(warIds, battleIdStr);
|
||||
if (warIds.indexOf(battleIdStr) === -1) {
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_WRONG_BATTLE_ID) };
|
||||
}
|
||||
@@ -30,7 +32,7 @@ export async function checkTowerWar(roleId: string, battleId: number, heroes: Ar
|
||||
}
|
||||
}
|
||||
const curWarStatus = warStatus.find(elem => elem.warId == battleId);
|
||||
if (curWarStatus.status) {
|
||||
if (curWarStatus && curWarStatus.status) {
|
||||
return { status: -1, resResult: resResult(STATUS.TOWER_DUPLICATE_CHALLENGE) };
|
||||
}
|
||||
|
||||
@@ -60,25 +62,22 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
}
|
||||
})
|
||||
let newRec = await TowerRecordModel.updateRecord(roleId, towerLv, battleCode, battleId, heroes, inc);
|
||||
let bonusReward = null;
|
||||
let towerReward = null;
|
||||
if (inc === 1) {
|
||||
await RoleModel.towerLvUp(roleId);
|
||||
const nextTowerInfo = getTowerDataByLv(towerLv + 1);
|
||||
if (nextTowerInfo) {
|
||||
const { warIds } = nextTowerInfo;
|
||||
const sts = decodeArrayStr(warIds).map(id => {
|
||||
const { warArray } = nextTowerInfo;
|
||||
const sts = decodeArrayStr(warArray, '&').map(id => {
|
||||
return {warId: parseInt(id), status: false};
|
||||
});
|
||||
|
||||
await TowerRecordModel.createRecord({roleId, lv: towerLv + 1, warStatus: sts});
|
||||
|
||||
}
|
||||
const { bonus, fixReward } = getTowerDataByLv(towerLv);
|
||||
if (bonus) {
|
||||
let result = await handleFixedReward(roleId, roleName, bonus, 1);
|
||||
bonusReward = result.goods;
|
||||
}
|
||||
if (fixReward) {
|
||||
let result = await handleFixedReward(roleId, roleName, fixReward, 1);
|
||||
const { reward } = getTowerDataByLv(towerLv);
|
||||
if (reward) {
|
||||
let result = await handleFixedReward(roleId, roleName, reward, 1);
|
||||
towerReward = result.goods;
|
||||
}
|
||||
if (towerLv + 1 >= HANG_UP_CONSTS.ENABLE_LV) {
|
||||
@@ -90,7 +89,7 @@ export async function towerBattleEnd(channelService: ChannelService, sid: string
|
||||
status: 0,
|
||||
data: {
|
||||
newRec,
|
||||
bonusReward, towerReward,
|
||||
towerReward,
|
||||
towerStatus: !!inc
|
||||
}
|
||||
};
|
||||
@@ -101,41 +100,99 @@ 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 (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && 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_HANG_UP_FAILED)}
|
||||
}
|
||||
return {status: 0, data: {hangUpSpdUpCnt, gold, lastSpdUpTime}}
|
||||
}
|
||||
|
||||
export async function calcuHangUpReward(roleId: string, speedUp = false, speedUpCnt = 1, curTime = new Date()) {
|
||||
let { towerLv, hangUpSpdUpCnt, lastSpdUpTime } = await RoleModel.findByRoleId(roleId);
|
||||
let { startTime} = await HangUpRecordModel.getCurRec(roleId);
|
||||
let { towerLv = 1, hangUpSpdUpCnt = 0, lastSpdUpTime } = await RoleModel.findByRoleId(roleId);
|
||||
|
||||
let towerInfo = getTowerDataByLv(towerLv - 1); // towerLv 是当前层,奖励计算按照已经通过的层,即上一层
|
||||
let multi = 1; // 结算奖励的倍数,受最大时间限制
|
||||
let multiReal = 1; // 距开始挂机实际过去的时间单位
|
||||
if (speedUp) {
|
||||
if (hangUpSpdUpCnt >= speedUpCnt || shouldRefresh(lastSpdUpTime, new Date, HANG_UP_CONSTS.REFRESH_TIME, 1)) {
|
||||
multi = speedUpCnt;
|
||||
} else {
|
||||
multi = 0;
|
||||
let timeReward = []; // 奖励
|
||||
let needReceiveGoods = []; // 由于小数,未能领取的奖励
|
||||
let baseReward = decodeStr('decimalReward', 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 || !lastSpdUpTime || shouldRefresh(lastSpdUpTime, new Date, HANG_UP_CONSTS.REFRESH_TIME, 1)) { // 可加速
|
||||
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) {
|
||||
let { notReceivedGoodsList = [], cnt } = spdUpRec;
|
||||
let notReceivedGoods = notReceivedGoodsList.find(cur => cur.cnt == cnt );
|
||||
goods = notReceivedGoods?notReceivedGoods.goods:[];
|
||||
}
|
||||
for(let {gid, count} of baseReward) {
|
||||
let newCount = cal.mul(count, multi);
|
||||
let oldGoods = goods.find(cur => cur.gid == gid);
|
||||
if(oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
||||
let roundCount = Math.floor(newCount);
|
||||
if(newCount > roundCount) {
|
||||
needReceiveGoods.push({gid, count: cal.sub(newCount, roundCount)});
|
||||
}
|
||||
if(roundCount > 0) {
|
||||
timeReward.push({gid, count: roundCount})
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
let deltaTime = curTime.getTime() - startTime.getTime();
|
||||
multiReal = Math.floor(deltaTime / HANG_UP_CONSTS.UNIT_TIME);
|
||||
if (deltaTime > HANG_UP_CONSTS.MAX_TIME) deltaTime = HANG_UP_CONSTS.MAX_TIME;
|
||||
multi = Math.floor(deltaTime / 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); // 结算奖励的倍数,受最大时间限制
|
||||
|
||||
console.log(deltaTime, multi, baseReward);
|
||||
for(let {gid, count} of baseReward) {
|
||||
let newCount = cal.mul(count, multi);
|
||||
let oldGoods = notReceivedGoods.find(cur => cur.gid == gid);
|
||||
if(oldGoods) newCount = cal.add(newCount, oldGoods.count);
|
||||
let roundCount = Math.floor(newCount);
|
||||
if(newCount > roundCount) {
|
||||
needReceiveGoods.push({gid, count: cal.sub(newCount, roundCount)});
|
||||
}
|
||||
if(roundCount > 0) {
|
||||
timeReward.push({gid, count: roundCount})
|
||||
}
|
||||
}
|
||||
}
|
||||
return {
|
||||
endLv: towerLv - 1,
|
||||
startTime,
|
||||
endTime: new Date(startTime.getTime() + multiReal * HANG_UP_CONSTS.UNIT_TIME),
|
||||
timeReward: towerInfo.timeReward,
|
||||
multi
|
||||
deltaTime,
|
||||
endTime,
|
||||
timeReward,
|
||||
needReceiveGoods
|
||||
};
|
||||
}
|
||||
|
||||
async function checkCond(roleId: string, heroes, type: number, parm: number, cnt: number) {
|
||||
async function checkCond(roleId: string, heroes, type: number, param: number, cnt: number) {
|
||||
let heroCnt = 0;
|
||||
|
||||
switch (type) {
|
||||
case 1:
|
||||
let field = param == 1?'star': 'rank';
|
||||
for(let hid of heroes) {
|
||||
const rec = await HeroModel.findByHidAndRole(hid, roleId);
|
||||
if (rec.star >= parm) {
|
||||
if (rec[field] >= param) {
|
||||
heroCnt++;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +200,7 @@ async function checkCond(roleId: string, heroes, type: number, parm: number, cnt
|
||||
case 2:
|
||||
for(let hid of heroes) {
|
||||
const hInfo = getHeroInfoById(hid);
|
||||
if (hInfo.camp === parm) {
|
||||
if (hInfo.camp === param) {
|
||||
heroCnt++;
|
||||
}
|
||||
}
|
||||
@@ -151,7 +208,7 @@ async function checkCond(roleId: string, heroes, type: number, parm: number, cnt
|
||||
case 3:
|
||||
for(let hid of heroes) {
|
||||
const hInfo = getHeroInfoById(hid);
|
||||
if (getJobInfoById(hInfo.jobid) === parm) {
|
||||
if (getJobInfoById(hInfo.jobid) === param) {
|
||||
heroCnt++;
|
||||
}
|
||||
}
|
||||
@@ -166,18 +223,14 @@ async function checkCond(roleId: string, heroes, type: number, parm: number, cnt
|
||||
}
|
||||
|
||||
export async function checkTaskConditions(roleId: string, heroes: Array<number>, conditionsStr: string) {
|
||||
const condArr = conditionsStr.split('|');
|
||||
if (condArr.length < 1) return false;
|
||||
let condition = decodeStr('towerTaskCondition', conditionsStr);
|
||||
|
||||
let res = true;
|
||||
for (let cond of condArr) {
|
||||
const condDetail = cond.split('&');
|
||||
if (condDetail && condDetail.length === 3) {
|
||||
const checkRes = await checkCond(roleId, heroes, parseInt(condDetail[0]), parseInt(condDetail[1]), parseInt(condDetail[2]))
|
||||
if (!checkRes) {
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
for (let {type, param, cnt} of condition) {
|
||||
const checkRes = await checkCond(roleId, heroes, type, param, cnt);
|
||||
if (!checkRes) {
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
@@ -207,7 +207,6 @@ export async function refreshEvent(num: number, roleId: string, roleName: string
|
||||
return ccur.eventId != cur.eventID;
|
||||
});
|
||||
});
|
||||
console.log(JSON.stringify(randomList));
|
||||
|
||||
let curPoint = new Array<number>();
|
||||
for(let i = 0; i < num; i++) {
|
||||
|
||||
Reference in New Issue
Block a user