活动:月卡权限
This commit is contained in:
@@ -66,11 +66,10 @@ export class RechargeMoneyHandler {
|
||||
await ActivityRechargeMoneyModel.addRecord(notGetRecord._id, item.id, `${item.gid}&${item.count}`);
|
||||
let goods = await addItems(roleId, roleName, sid, [{ id: item.gid, count: item.count }], ITEM_CHANGE_REASON.RECHARGE_REWARD)
|
||||
|
||||
item.setHasGet(true);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
param: { activityId },
|
||||
item: item
|
||||
item: item,
|
||||
ticketCnt: playerData.ticketCnt,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,13 +36,10 @@ export class DailyBattleHandler {
|
||||
|
||||
const curDaily = gameData.daily.find(cur => cur.dailyType == type);
|
||||
if(!curDaily) return resResult(STATUS.DAILY_TYPE_NOT_FOUND);
|
||||
let { timesPerDay, timesCanBuy } = curDaily;
|
||||
|
||||
let { buyCount = 0 } = await DailyRecordModel.refreshRecord(roleId, type);
|
||||
let { vLv } = await RoleModel.findByRoleId(roleId);
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
}
|
||||
if(buyCount + count > timesCanBuy ) {
|
||||
|
||||
if(buyCount + count > curDaily.timesCanBuy ) {
|
||||
return resResult(STATUS.DAILY_REFRESH_TIMES_LACK)
|
||||
}
|
||||
let buyCost = 0;
|
||||
@@ -50,15 +47,15 @@ export class DailyBattleHandler {
|
||||
let num = buyCount + i;
|
||||
buyCost += getDailyBuyCountCost(num);
|
||||
}
|
||||
let {gold} = await RoleModel.findByRoleId(roleId);
|
||||
if(buyCost > gold) {
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
if(buyCost > role.gold) {
|
||||
return resResult(STATUS.DAILY_REFRESH_GOLD_LACK);
|
||||
}
|
||||
|
||||
await handleCost(roleId, sid, [getGoldObject(buyCost)], ITEM_CHANGE_REASON.DAILY_BATTLE_BUY_CNT);
|
||||
let newDailyRecord = await DailyRecordModel.increseBuyCount(roleId, type, count);
|
||||
|
||||
let checkDailyResult = await getDailyNum(newDailyRecord, timesPerDay, timesCanBuy);
|
||||
let checkDailyResult = await getDailyNum(newDailyRecord, role);
|
||||
return resResult(STATUS.SUCCESS, { type, ...checkDailyResult, buyCost});
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import * as dicParam from '../../../pubUtils/dicParam';
|
||||
import { DungeonFirstModel } from '../../../db/DungeonFirst';
|
||||
import { DungeonResultParam } from '../../../domain/battleField/dungeon';
|
||||
import { DEBUG_MAGIC_WORD, ITEM_CHANGE_REASON } from '../../../consts';
|
||||
import { getVipDungeonCnt } from '../../../services/activity/monthlyTicketService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DungeonBattleHandler(app);
|
||||
@@ -41,10 +42,6 @@ export class DungeonBattleHandler {
|
||||
}
|
||||
|
||||
let timesCanBuy = dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY;
|
||||
let { vLv } = await RoleModel.findByRoleId(roleId);
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
}
|
||||
if(dungeonBuyCnt + count > timesCanBuy ) {
|
||||
return resResult(STATUS.DUNGEON_REFRESH_TIMES_LACK)
|
||||
}
|
||||
@@ -60,10 +57,11 @@ export class DungeonBattleHandler {
|
||||
await RoleModel.buyCnt(roleId, needRefresh, count, curTime);
|
||||
|
||||
let nextCostGold = getDungeonBuyCountCost(dungeonBuyCnt + count + 1);
|
||||
let freeCount = getVipDungeonCnt(session.get('vipStartTime'));
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
costGold: buyCost,
|
||||
nextCostGold,
|
||||
battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt + count - dungeonCnt,
|
||||
battleCount: freeCount + dungeonBuyCnt + count - dungeonCnt,
|
||||
buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt - count
|
||||
});
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export class PvpHandler {
|
||||
let update: pvpUpdateInter = { };
|
||||
let result = new PvpDataReturn(); // 返回对象
|
||||
// 刷新次数
|
||||
let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
if(refChallengeObj.hasChanged) {
|
||||
update = { ...update, ...refChallengeObj }
|
||||
}
|
||||
@@ -161,7 +161,7 @@ export class PvpHandler {
|
||||
// 检查挑战次数
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let seasonEndTime: number = this.app.get('pvpSeasonEndTime');
|
||||
let { challengeCnt, challengeRefTime } = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let { challengeCnt, challengeRefTime } = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, session.get('vipStartTime'));
|
||||
if (challengeCnt == 0) {
|
||||
return resResult(STATUS.PVP_CHALLENGE_TIMES_NOT_ENOUGH);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ export class PvpHandler {
|
||||
update.oppPlayers = oppPlayers;
|
||||
|
||||
// 减少挑战次数
|
||||
let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
refChallengeObj.challengeCnt--;
|
||||
update = {...update, ...refChallengeObj};
|
||||
|
||||
@@ -363,7 +363,7 @@ export class PvpHandler {
|
||||
|
||||
let seasonNum: number = this.app.get('pvpSeasonNum');
|
||||
let seasonEndTime: number = this.app.get('pvpSeasonEndTime');
|
||||
let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
// 更新挑战阵容
|
||||
let scores: number[] = [];
|
||||
for(let { actorId } of heroes) {
|
||||
@@ -400,7 +400,7 @@ export class PvpHandler {
|
||||
if(!pvpDefense) return resResult(STATUS.PVP_NOT_OPEN);
|
||||
// 刷新次数
|
||||
let seasonEndTime: number = this.app.get('pvpSeasonEndTime');
|
||||
let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
// 更新防守阵容
|
||||
let scores: number[] = [], heroIdMap = new Map<number, string>(), hids: number[] = [];
|
||||
for(let { actorId } of heroes) {
|
||||
@@ -532,7 +532,7 @@ export class PvpHandler {
|
||||
return resResult(STATUS.PVP_BOX_IS_GOT);
|
||||
}
|
||||
receivedBox.push(id);
|
||||
let { challengeCnt, challengeRefTime } = refChallengeCnt(lastChallengeCnt, lastChallengeRefTime, seasonEndTime);
|
||||
let { challengeCnt, challengeRefTime } = await refChallengeCnt(lastChallengeCnt, lastChallengeRefTime, seasonEndTime, roleId, session.get('vipStartTime'));
|
||||
await PvpDefenseModel.updateInfo(roleId, { receivedBox, challengeCnt, challengeRefTime });
|
||||
let result = await addItems(roleId, roleName, sid, pvpBox.reward, ITEM_CHANGE_REASON.PVP_BOX_REWARD);
|
||||
// 任务
|
||||
|
||||
@@ -6,13 +6,14 @@ import { HangUpRecordModel } from './../../../db/HangUpRecord';
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { TowerRecordModel } from './../../../db/TowerRecord';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult, genCode } from '../../../pubUtils/util';
|
||||
import { calcuHangUpReward, checkHangUpSpdUpCnt, refreshTasks, treatTask, getRemainTime, getTowerStatus, getHungupRewards, getTasks, checkTaskRewards, getTowerTaskCostGold, getHangSpdUpCostGold, getManyHangSpdUpCostGold, getTaskStatus } from '../../../services/battleService';
|
||||
import { resResult, genCode, shouldRefresh } from '../../../pubUtils/util';
|
||||
import { calcuHangUpReward, refreshTasks, treatTask, getRemainTime, getTowerStatus, getHungupRewards, getTasks, checkTaskRewards, getTowerTaskCostGold, getHangSpdUpCostGold, getManyHangSpdUpCostGold, getTaskStatus } from '../../../services/battleService';
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { checkBattleHeroes } from '../../../services/normalBattleService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
import * as dicParam from '../../../pubUtils/dicParam';
|
||||
import { isNumber } from 'underscore';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new TowerBattleHandler(app);
|
||||
@@ -56,21 +57,23 @@ export class TowerBattleHandler {
|
||||
async checkHangUpRewards(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let result = await getHungupRewards(roleId);
|
||||
if(result.status == -1) {
|
||||
return result.resResult;
|
||||
if(!result) {
|
||||
return resResult(STATUS.TOWER_HANG_UP_NOT_START);
|
||||
}
|
||||
return resResult(STATUS.SUCCESS, result.data);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async recHangUpRewards(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
const result = await calcuHangUpReward(roleId);
|
||||
if(result.status == -1) {
|
||||
return result.resResult
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
const result = await calcuHangUpReward(role);
|
||||
if(!result) {
|
||||
return resResult(STATUS.TOWER_HANG_UP_NOT_START);
|
||||
}
|
||||
let { timeReward, endLv, endTime, deltaTime, needReceiveGoods } = result.data;
|
||||
let { timeReward, endLv, endTime, deltaTime, needReceiveGoods } = result;
|
||||
|
||||
const goods = await addItems(roleId, roleName, sid, timeReward, ITEM_CHANGE_REASON.TOWER_HUNG_UP_REWARD);
|
||||
await HangUpRecordModel.updateRec(roleId, roleName, endLv, endTime, needReceiveGoods);
|
||||
@@ -82,19 +85,27 @@ export class TowerBattleHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let sid = session.get('sid');
|
||||
if (msg.speedUpCnt <= 0) {
|
||||
let { speedUpCnt } = msg;
|
||||
|
||||
if (!isNumber(speedUpCnt) || speedUpCnt <= 0) {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
const curTime = new Date();
|
||||
const calResult = await calcuHangUpReward(roleId, true, msg.speedUpCnt, curTime);
|
||||
if(calResult.status == -1) {
|
||||
return calResult.resResult;
|
||||
}
|
||||
let { timeReward, endLv, deltaTime, needReceiveGoods } = calResult.data;
|
||||
|
||||
let result = await checkHangUpSpdUpCnt(roleId, msg.speedUpCnt, curTime);
|
||||
if(result.status == -1) return result.resResult;
|
||||
let {data: {hangUpSpdUpCnt, gold}} = result;
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let { hangUpSpdUpCnt, gold, lastSpdUpTime } = role;
|
||||
if (shouldRefresh(lastSpdUpTime, curTime)) {
|
||||
hangUpSpdUpCnt = 0;
|
||||
}
|
||||
if (speedUpCnt + hangUpSpdUpCnt > dicParam.TOWER_BOOST.TOWER_BOOSTTIME) {
|
||||
return resResult(STATUS.TOWER_NOT_ENOUGH_HANG_UP_TIME)
|
||||
}
|
||||
|
||||
const calResult = await calcuHangUpReward(role, true, msg.speedUpCnt, curTime);
|
||||
if(!calResult) {
|
||||
return resResult(STATUS.TOWER_HANG_UP_FAILED);
|
||||
}
|
||||
let { timeReward, endLv, deltaTime, needReceiveGoods } = calResult;
|
||||
|
||||
const costGold = getManyHangSpdUpCostGold(hangUpSpdUpCnt, msg.speedUpCnt);
|
||||
if(costGold > gold) {
|
||||
|
||||
@@ -130,10 +130,7 @@ export class EntryHandler {
|
||||
|
||||
await session.abind(role.roleId);
|
||||
session.set('userid', role.userInfo.uid);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
let updatedMailAt = role.updatedMailAt ? role.updatedMailAt : 0;
|
||||
session.set('updatedMailAt', updatedMailAt);
|
||||
session.set('loginTime', nowSeconds());
|
||||
session.set('roleName', role.roleName);
|
||||
session.set('eventStatus', role.eventStatus);
|
||||
@@ -142,17 +139,18 @@ export class EntryHandler {
|
||||
session.set('serverId', role.serverId);
|
||||
session.set('guildCode', role.guildCode);
|
||||
session.set('ip', ip);
|
||||
session.set('vipStartTime', role.vipStartTime||0);
|
||||
session.push('userid', () => { });
|
||||
session.push('sid', () => { });
|
||||
session.push('roleId', () => { });
|
||||
session.push('roleName', () => { });
|
||||
session.push('eventStatus', () => { });
|
||||
session.push('serverId', () => { });
|
||||
session.push('updatedMailAt', () => { });
|
||||
session.push('loginTime', () => { });
|
||||
session.push('guildCode', () => { });
|
||||
session.push('blockType', () => { });
|
||||
session.push('ip', () => { });
|
||||
session.push('vipStartTime', () => { });
|
||||
// console.log(role.guildCode)
|
||||
// session.push('rid', function (err) {
|
||||
// if (err) {
|
||||
|
||||
@@ -15,6 +15,7 @@ import { addActive } from '../../../services/guildService'
|
||||
import { checkActivityTask, checkTask } from '../../../services/taskService';
|
||||
import { guildInter } from '../../../pubUtils/interface';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { getVipDonateConsume } from '../../../services/activity/monthlyTicketService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -84,7 +85,8 @@ export class DonationHandler {
|
||||
let { donationLv } = await getDonation(code, guild, serverId);
|
||||
let { donateReward } = getArmyDonateBaseByLv(donationLv);
|
||||
let { rewardGood, rewardFund, cosume } = donateReward.get(id);
|
||||
let result = await handleCost(roleId, sid, [cosume], ITEM_CHANGE_REASON.DONATE);
|
||||
let consumeResult = getVipDonateConsume(cosume, session.get('vipStartTime'));
|
||||
let result = await handleCost(roleId, sid, consumeResult, ITEM_CHANGE_REASON.DONATE);
|
||||
if (!result) {
|
||||
res.releaseCallback();
|
||||
return resResult(STATUS.ROLE_MATERIAL_NOT_ENOUGH);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { ACTIVITY_TYPE, ITEM_CHANGE_REASON, MAIL_TYPE, STATUS } from '../../consts';
|
||||
import { ACTIVITY_TYPE, HANG_UP_CONSTS, ITEM_CHANGE_REASON, MAIL_TYPE, STATUS } from '../../consts';
|
||||
import { ActivityModel, ActivityModelType } from '../../db/Activity';
|
||||
import { ActivityMonthlyTicketModel, ActivityMonthlyTicketModelType } from '../../db/ActivityMonthlyTicket';
|
||||
import { RewardParam } from '../../domain/activityField/rewardField';
|
||||
@@ -7,8 +7,12 @@ import { addReward, stringToRewardInter, stringToRewardParam } from './giftPacka
|
||||
import moment = require('moment');
|
||||
import { ServerlistModel } from '../../db/Serverlist';
|
||||
import { sendMailByContent } from './../mailService';
|
||||
import { RoleModel } from '../../db/Role';
|
||||
import { RoleModel, RoleType } from '../../db/Role';
|
||||
import { getActivityById } from './activityService';
|
||||
import { RewardInter } from '../../pubUtils/interface';
|
||||
import { getGoldId } from '../../pubUtils/itemUtils';
|
||||
import { DUNGEON_CONST, PVP, VIP } from '../../pubUtils/dicParam';
|
||||
import { cal } from '../../pubUtils/util';
|
||||
|
||||
/**
|
||||
* 获取活动数据
|
||||
@@ -115,10 +119,10 @@ export async function makeMonthlyTicketReward(roleId: string, roleName: string,
|
||||
let { createTime } = await RoleModel.findByRoleId(roleId);
|
||||
let playerData = new MonthlyTicketData(activityData, createTime);
|
||||
|
||||
let endTime = moment(new Date()).startOf('d').add(playerData.days, 'day').toDate();
|
||||
let endTime = playerData.isForever? moment(new Date()).startOf('d').add(playerData.days, 'day').toDate(): null;
|
||||
console.log('endTime', moment(new Date()).startOf('d'), endTime, playerData.days)
|
||||
await ActivityMonthlyTicketModel.buyMonthlyTicket(serverId, roleId, activityId, activityData.type, endTime)
|
||||
|
||||
await ActivityMonthlyTicketModel.buyMonthlyTicket(serverId, roleId, activityId, activityData.type, endTime, playerData.isForever)
|
||||
await RoleModel.buyForeverTicket(roleId);
|
||||
let firstReward = playerData.firstReward;
|
||||
let rewardParamArr: Array<RewardParam> = stringToRewardParam(firstReward);
|
||||
let result = await addReward(roleId, roleName, sid, serverId, rewardParamArr, ITEM_CHANGE_REASON.MONTHLY_TICKET_FIRST)
|
||||
@@ -127,3 +131,75 @@ export async function makeMonthlyTicketReward(roleId: string, roleName: string,
|
||||
data: Object.assign(result, { item: { isOpen: true, todayIndex: 1 }, activityId: activityData.activityId })
|
||||
}
|
||||
}
|
||||
|
||||
// 月卡权限
|
||||
|
||||
// 军团捐献消耗
|
||||
export function getVipDonateConsume(originConsume: RewardInter, vipStartTime: number) {
|
||||
if(vipStartTime > 0) {
|
||||
if(originConsume.id == getGoldId()) {
|
||||
return [{ id: originConsume.id, count: Math.floor(originConsume.count * VIP.VIP_GUILD_DONATE_COST_GOLD_RATIO) }];
|
||||
} else {
|
||||
return [originConsume];
|
||||
}
|
||||
} else {
|
||||
return [originConsume];
|
||||
}
|
||||
}
|
||||
|
||||
export function getVipHungupReward(startTime: number, endTime: number, baseReward: RewardInter[], notReceivedGoods: {gid: number, count: number}[], vipStartTime: number) {
|
||||
let multi = Math.floor((endTime - startTime) / HANG_UP_CONSTS.UNIT_TIME);
|
||||
if(vipStartTime > 0) {
|
||||
if(vipStartTime > startTime) { // 开始挂机之后买的月卡
|
||||
let isNotVipNum = Math.floor((vipStartTime - startTime) / HANG_UP_CONSTS.UNIT_TIME); // 不是vip的时间段数
|
||||
let isVipNum = multi - isNotVipNum; // 是vip的时间段数
|
||||
multi = cal.add(isNotVipNum, cal.mul(isVipNum, VIP.VIP_TOWER_HUNG_UP_RATIO));
|
||||
} else {
|
||||
multi = cal.mul(multi, VIP.VIP_TOWER_HUNG_UP_RATIO);
|
||||
}
|
||||
}
|
||||
|
||||
let needReceiveGoods: {gid: number, count: number}[] = [];// 由于小数,未能领取的奖励
|
||||
let timeReward: {id: number, count: number}[] = []; // 本次奖励
|
||||
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 { needReceiveGoods, timeReward }
|
||||
}
|
||||
|
||||
export async function getVipPvpChallengeMaxCnt(roleId: string, vipStartTime?: number) {
|
||||
if(vipStartTime == undefined) {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'vipStartTime');
|
||||
vipStartTime = role.vipStartTime;
|
||||
}
|
||||
let count = PVP.PVP_CHALLENGE_COUNTS;
|
||||
if(vipStartTime > 0) {
|
||||
count += VIP.VIP_PVP_CHALLENGE_COUNTS_ADD;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
export function getVipDailyCnt(timesPerDay: number, role: RoleType) {
|
||||
let vipStartTime = role.vipStartTime;
|
||||
if(vipStartTime > 0) {
|
||||
timesPerDay += VIP.VIP_DAILY_TIMERS_PER_DAY_ADD;
|
||||
}
|
||||
return timesPerDay
|
||||
}
|
||||
|
||||
export function getVipDungeonCnt(vipStartTime: number) {
|
||||
let count = DUNGEON_CONST.DUNGEON_CONST_FREE;
|
||||
if(vipStartTime > 0) {
|
||||
count += VIP.VIP_DUNGEON_CONST_FREE_ADD;
|
||||
}
|
||||
return count
|
||||
}
|
||||
@@ -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) {
|
||||
|
||||
@@ -187,10 +187,10 @@ async function getTowerEntryData(role: RoleType) {
|
||||
const status = await getTowerStatus(role);
|
||||
const hungUp = await getHungupRewards(roleId);
|
||||
const tasks = await getTasks(role);
|
||||
if (hungUp.status == -1) {
|
||||
if (!hungUp) {
|
||||
return { status, hungUp: {}, tasks }
|
||||
} else {
|
||||
return { status, hungUp: hungUp.data, tasks }
|
||||
return { status, hungUp: hungUp, tasks }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +202,7 @@ async function getPvpEntryData(roleId: string) {
|
||||
let pvpDefense = await PvpDefenseModel.findByRoleId(roleId);
|
||||
if (pvpDefense) {
|
||||
let seasonEndTime = pinus.app.get('pvpSeasonEndTime');
|
||||
let refChallengeObj = refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime);
|
||||
let refChallengeObj = await refChallengeCnt(pvpDefense.challengeCnt, pvpDefense.challengeRefTime, seasonEndTime, roleId);
|
||||
let { challengeCnt } = refChallengeObj;
|
||||
let { receivedBox, score, hisScore } = pvpDefense;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { DicWar } from '../pubUtils/dictionary/DicWar';
|
||||
import { WarStar } from '../domain/dbGeneral';
|
||||
import * as dicParam from '../pubUtils/dicParam';
|
||||
import { calculateWarStar } from './normalBattleService';
|
||||
import { getVipDailyCnt } from './activity/monthlyTicketService';
|
||||
|
||||
/**
|
||||
* 获取全部每日关卡列表
|
||||
@@ -29,7 +30,7 @@ export async function getDailyBattleList(role: RoleType) {
|
||||
let war = getDailyWarStatus(dic, warStar);
|
||||
wars.push(war);
|
||||
}
|
||||
let checkDailyResult = await getDailyNum(refreshResult, timesPerDay, timesCanBuy);
|
||||
let checkDailyResult = await getDailyNum(refreshResult, role);
|
||||
result.push({
|
||||
type, name, ...checkDailyResult,
|
||||
wars
|
||||
@@ -75,7 +76,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 = await getDailyNum(dailyRecord, curDaily.timesPerDay, curDaily.timesCanBuy);
|
||||
let checkDailyResult = await getDailyNum(dailyRecord);
|
||||
return {status: 1, data: {type, ...checkDailyResult }};
|
||||
}
|
||||
|
||||
@@ -109,21 +110,20 @@ export async function checkDailyAndIncrease(roleId: string, warStar: WarStar[],
|
||||
return { status: -1, resResult: resResult(STATUS.DAILY_TIMES_LACK) }
|
||||
}
|
||||
let result = await DailyRecordModel.increseDailyCount(roleId, type, inc);
|
||||
let checkDailyResult = await getDailyNum(result, curDaily.timesPerDay, curDaily.timesCanBuy);
|
||||
let checkDailyResult = await getDailyNum(result);
|
||||
return {status: 1, data: {type, ...checkDailyResult, war}};
|
||||
}
|
||||
|
||||
export async function getDailyNum(dailyRecord: DailyRecord, timesPerDay?: number, timesCanBuy?: number) {
|
||||
export async function getDailyNum(dailyRecord: DailyRecord, role?: RoleType) {
|
||||
let {roleId, type, count = 0, buyCount = 0} = dailyRecord;
|
||||
if(!timesPerDay || !timesCanBuy) {
|
||||
const curDaily = gameData.daily.find(cur => cur.dailyType == type);
|
||||
timesPerDay = curDaily.timesPerDay;
|
||||
timesCanBuy = curDaily.timesCanBuy;
|
||||
}
|
||||
let {vLv} = await RoleModel.findByRoleId(roleId);
|
||||
if(vLv > 0) {
|
||||
timesCanBuy += 0; // 暂留,用于处理vip等级增加最大购买次数
|
||||
const curDaily = gameData.daily.find(cur => cur.dailyType == type);
|
||||
let {timesPerDay, timesCanBuy} = curDaily;
|
||||
|
||||
if(!role) {
|
||||
role = await RoleModel.findByRoleId(roleId, 'vipStartTime');
|
||||
}
|
||||
timesPerDay = getVipDailyCnt(timesPerDay, role);
|
||||
|
||||
return {count: timesPerDay - count + buyCount, buyCount: timesCanBuy - buyCount}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import { BattleRecordType } from '../db/BattleRecord';
|
||||
import { gameData } from '../pubUtils/data';
|
||||
import { DungeonFirstModel } from '../db/DungeonFirst';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
import { getVipDungeonCnt } from './activity/monthlyTicketService';
|
||||
|
||||
/**
|
||||
* 获取秘境本数据
|
||||
@@ -24,29 +25,31 @@ export async function getDungeonData(role: RoleType) {
|
||||
}
|
||||
|
||||
let nextCostGold = getDungeonBuyCountCost(dungeonBuyCnt + 1);
|
||||
let freeCount = getVipDungeonCnt(role.vipStartTime);
|
||||
return {
|
||||
nextCostGold,
|
||||
dungeonHeroes,
|
||||
battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt,
|
||||
battleCount: freeCount + dungeonBuyCnt - dungeonCnt,
|
||||
buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt
|
||||
}
|
||||
}
|
||||
|
||||
// 检查秘境本次数checkBattle使用
|
||||
export async function checkDungeonNum(roleId: string, inc: number) {
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime, vipStartTime } = await RoleModel.findByRoleId(roleId);
|
||||
let curTime = new Date();
|
||||
let needRefresh = shouldRefresh(dungeonRefTime, curTime);
|
||||
if(needRefresh) {
|
||||
dungeonCnt = 0; dungeonBuyCnt = 0;
|
||||
}
|
||||
if(dungeonCnt + inc > dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt) {
|
||||
let freeCount = getVipDungeonCnt(vipStartTime);
|
||||
if(dungeonCnt + inc > freeCount + dungeonBuyCnt) {
|
||||
return {status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK)}
|
||||
}
|
||||
await RoleModel.increaseDungeonCnt(roleId, needRefresh, 0, curTime);
|
||||
|
||||
return { status: 0, data: {
|
||||
battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt,
|
||||
battleCount: freeCount + dungeonBuyCnt - dungeonCnt,
|
||||
buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt
|
||||
}};
|
||||
}
|
||||
@@ -60,21 +63,22 @@ export async function checkDungeonNum(roleId: string, inc: number) {
|
||||
|
||||
export async function checkDungeonAndIncrease(roleId: string, inc: number, isRef: boolean) {
|
||||
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime, vipStartTime } = await RoleModel.findByRoleId(roleId);
|
||||
let curTime = new Date();
|
||||
|
||||
let needRefresh = isRef && shouldRefresh(dungeonRefTime, curTime);
|
||||
if(needRefresh) {
|
||||
dungeonCnt = 0; dungeonBuyCnt = 0;
|
||||
}
|
||||
let freeCount = getVipDungeonCnt(vipStartTime);
|
||||
|
||||
if(dungeonCnt + inc > dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt ) {
|
||||
if(dungeonCnt + inc > freeCount + dungeonBuyCnt ) {
|
||||
return { status: -1, resResult: resResult(STATUS.DUNGEON_TIMES_LACK) }
|
||||
}
|
||||
// console.log('needRefresh', needRefresh);
|
||||
await RoleModel.increaseDungeonCnt(roleId, needRefresh, inc, curTime);
|
||||
return {status: 1, data: {
|
||||
battleCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_FREE + dungeonBuyCnt - dungeonCnt - inc,
|
||||
battleCount: freeCount + dungeonBuyCnt - dungeonCnt - inc,
|
||||
buyCount: dicParam.DUNGEON_CONST.DUNGEON_CONST_BUY - dungeonBuyCnt
|
||||
}};
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ import { checkTask } from '../services/taskService';
|
||||
import { sendMailByContent } from './mailService';
|
||||
import { RoleRankInfo } from '../domain/rank';
|
||||
import { reportTAEvent } from './sdkService';
|
||||
import { getVipPvpChallengeMaxCnt } from './activity/monthlyTicketService';
|
||||
|
||||
/**
|
||||
* 返回对手三人信息
|
||||
@@ -296,9 +297,10 @@ export function getLvByScore(heroScores: HeroScore[]) {
|
||||
return getPLvByScore(score);
|
||||
}
|
||||
|
||||
export function refChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number) {
|
||||
export async function refChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number, roleId: string, vipStartTime?: number) {
|
||||
let hasChanged = false;
|
||||
if (challengeCnt >= PVP.PVP_CHALLENGE_COUNTS) {
|
||||
let initCount = await getVipPvpChallengeMaxCnt(roleId, vipStartTime)
|
||||
if (challengeCnt >= initCount) {
|
||||
return { hasChanged, challengeCnt, challengeRefTime: nowSeconds() };
|
||||
}
|
||||
let period = PVP.PVP_CHALLENGE_NORMALTIMES * 60;
|
||||
@@ -312,20 +314,22 @@ export function refChallengeCnt(challengeCnt: number, challengeRefTime: number,
|
||||
challengeRefTime = challengeRefTime + period * num;
|
||||
hasChanged = true;
|
||||
}
|
||||
challengeCnt = challengeCnt > PVP.PVP_CHALLENGE_COUNTS ? PVP.PVP_CHALLENGE_COUNTS : challengeCnt;
|
||||
challengeCnt = challengeCnt > initCount ? initCount : challengeCnt;
|
||||
return { hasChanged, challengeCnt, challengeRefTime };
|
||||
}
|
||||
|
||||
export function comsumeChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number) {
|
||||
export async function comsumeChallengeCnt(challengeCnt: number, challengeRefTime: number, seasonEndTime: number, roleId: string) {
|
||||
let initCount = await getVipPvpChallengeMaxCnt(roleId)
|
||||
|
||||
challengeCnt--;
|
||||
if (challengeCnt >= PVP.PVP_CHALLENGE_COUNTS) {
|
||||
if (challengeCnt >= initCount) {
|
||||
return { challengeCnt, challengeRefTime };
|
||||
}
|
||||
if (challengeCnt == PVP.PVP_CHALLENGE_COUNTS - 1) {
|
||||
if (challengeCnt == initCount - 1) {
|
||||
challengeRefTime = nowSeconds();
|
||||
return { challengeCnt, challengeRefTime };
|
||||
}
|
||||
return refChallengeCnt(challengeCnt, challengeRefTime, seasonEndTime);
|
||||
return refChallengeCnt(challengeCnt, challengeRefTime, seasonEndTime, roleId);
|
||||
}
|
||||
|
||||
export async function sendLastSeasonRewardIfNotSent(pvpDefense: PvpDefenseType) {
|
||||
@@ -569,13 +573,14 @@ export async function sendPVPRewardToUser(pvpDefense: PvpDefenseType, seasonNum:
|
||||
async function resetPvpScores(pvpDefense: PvpDefenseType, seasonNum: number, pvpSeasonResult: PvpSeasonResultType) {
|
||||
let { roleId, attack, defense } = pvpDefense;
|
||||
let { newHeroScores, newScore } = pvpSeasonResult;
|
||||
let initCount = await getVipPvpChallengeMaxCnt(roleId)
|
||||
|
||||
let newAttack = <Attack>calLineupScore(attack, newHeroScores);
|
||||
let newDefense = <Defense>calLineupScore(defense, newHeroScores);
|
||||
|
||||
pvpDefense = await PvpDefenseModel.updateInfoAndInclude(roleId, {
|
||||
heroScores: newHeroScores, score: newScore, attack: newAttack, defense: newDefense,
|
||||
seasonNum, challengeCnt: PVP.PVP_CHALLENGE_COUNTS, challengeRefTime: 0, winStreakNum: 0, isFirstEntry: true
|
||||
seasonNum, challengeCnt: initCount, challengeRefTime: 0, winStreakNum: 0, isFirstEntry: true
|
||||
});
|
||||
return pvpDefense;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user