时间:整理时间方法

This commit is contained in:
luying
2021-05-08 19:13:44 +08:00
parent 6f03a96c51
commit 78e3c26a7a
51 changed files with 662 additions and 411 deletions
@@ -1,6 +1,6 @@
import { Application, BackendSession } from "pinus";
import { resResult, getRandEelmWithWeight, shouldRefresh, getRandSingleEelm } from "../../../pubUtils/util";
import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, REFRESH_HOUR } from "../../../consts";
import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, REFRESH_TIME, TIME_OUTPUT_TYPE } from "../../../consts";
import { gameData } from "../../../pubUtils/data";
import { GachaListReturn, GachaResult, GachaData } from "../../../domain/activityField/gachaField";
import { UserGachaModel } from "../../../db/UserGacha";
@@ -9,7 +9,7 @@ import { RoleModel } from "../../../db/Role";
import { HeroModel } from "../../../db/Hero";
import { RewardInter } from "../../../pubUtils/interface";
import { handleCost, createHeroes, addItems } from "../../../services/rewardService";
import { getAfterDateByDay, getTodayZeroDate } from "../../../pubUtils/timeUtil";
import { getZeroPointD, getTimeFun } from "../../../pubUtils/timeUtil";
import { UserGachaRecModel } from "../../../db/UserGachaRec";
import { ActivityModel } from "../../../db/Activity";
import { checkTask } from "../../../services/taskService";
@@ -133,7 +133,8 @@ export class GachaHandler {
let resultRefFreeTime = 0;
if (dicGacha.free.count > 0) {
resultRefFreeTime = getAfterDateByDay(refFreeTime, dicGacha.free.day);
let f = getTimeFun(userGacha.refFreeTime);
resultRefFreeTime = <number>f.getAfterDayWithHour(dicGacha.free.day);
}
return resResult(STATUS.SUCCESS, {
gachaId, activityId,
@@ -290,7 +291,7 @@ export class GachaHandler {
const roleId: string = session.get('roleId');
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
if (shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
if (shouldRefresh(refVisitedTime, new Date())) {
visitedHero = [];
}
@@ -317,9 +318,9 @@ export class GachaHandler {
let { pieceId } = dicHero;
let { visitedHero, refVisitedTime } = await UserGachaModel.findByRole(roleId, GACHA_ID.NORMAL, 0);
if (shouldRefresh(refVisitedTime, new Date(), REFRESH_HOUR)) {
if (shouldRefresh(refVisitedTime, new Date())) {
visitedHero = [];
refVisitedTime = getTodayZeroDate(REFRESH_HOUR);
refVisitedTime = getZeroPointD();
}
if (visitedHero.includes(hid)) {
return resResult(STATUS.GACHA_HAS_VISITED);
@@ -22,7 +22,7 @@ import { addUserToChannel, getSimpleRoleInfo } from '../../../services/roleServi
import { ChannelUser } from '../../../domain/ChannelUser';
import { pushComBtlTeamMsg, pushFriendTeamInviteMsg, pushNormalItemMsg, pushTeamInviteMsg } from '../../../services/chatService';
import { EXTERIOR } from '../../../pubUtils/dicParam';
import { getTodayZeroDate } from '../../../pubUtils/timeUtil';
import { getZeroPointD, getTimeFunD } from '../../../pubUtils/timeUtil';
import { FriendParams } from '../../../domain/roleField/friend';
import { checkTask, checkTaskWithGoods } from '../../../services/taskService';
import { gameData, getWarByBlueprtId } from '../../../pubUtils/data';
@@ -595,7 +595,8 @@ export class ComBattleHandler {
*/
async getTeamRec(msg: {}, session: BackendSession) {
let roleId = session.get('roleId');
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, null, new Date(new Date().setHours(0, 0, 0, 0) - 2 * 24 * 60 * 60 * 1000));
let timef = getTimeFunD();
let teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, null, <Date>timef.getBeforeDayWithHour(2));
if (!teams) return resResult(STATUS.COM_BATTLE_NO_RECENT_REC);
return resResult(STATUS.SUCCESS, {teamInfos: teams});
@@ -707,7 +708,7 @@ export class ComBattleHandler {
async getRecentTeammates(msg: { }, session: BackendSession) {
let roleId = session.get('roleId');
const teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, null, getTodayZeroDate());
const teams = await ComBattleTeamModel.getTeamByRoleAndTime(roleId, null, getZeroPointD());
let roleIdList = new Array<string>();
for(let { roleIds } of teams) {
for(let r of roleIds) {
@@ -19,7 +19,7 @@ export class DungeonBattleHandler {
let roleId = session.get('roleId');
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime, dungeonHeroes=[] } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
if(shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME)) {
if(shouldRefresh(dungeonRefTime, curTime)) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
@@ -41,7 +41,7 @@ export class DungeonBattleHandler {
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
let needRefresh = shouldRefresh(dungeonRefTime, curTime);
if(needRefresh) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
@@ -1,9 +1,9 @@
import { Application, BackendSession } from 'pinus';
import { resResult, genCode, getRandSingleEelm } from '../../../pubUtils/util';
import { STATUS, TASK_TYPE, AUCTION_SOURCE } from '../../../consts';
import { STATUS, TASK_TYPE } from '../../../consts';
import { BossInstanceModel } from '../../../db/BossInstance';
import { BattleRecordModel } from '../../../db/BattleRecord';
import { nowSeconds, getTodayZeroPoint } from '../../../pubUtils/timeUtil';
import { nowSeconds, getZeroPoint } from '../../../pubUtils/timeUtil';
import { getBossInstanceInfo, bossResult, checkBossBattleMemberExists, pushBossHpMessage, getBossInstanceWhenEnd, addBossInstance } from '../../../services/guildBossService';
import { findWhere } from 'underscore'
import { GUILD_STRUCTURE, GUILD_BOSS_STATUS, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
@@ -16,7 +16,6 @@ import { getBossByLv } from '../../../pubUtils/data';
import { lockData } from '../../../services/redLockService';
import { pushGuildBossSucMsg } from '../../../services/chatService';
import { checkTask } from '../../../services/taskService';
import { genAuction } from '../../../services/auctionService';
export default function (app: Application) {
return new GuildHandler(app);
@@ -75,7 +74,7 @@ export class GuildHandler {
if (!!res.err)
return resResult(STATUS.REDLOCK_ERR);
let bossInstance = await BossInstanceModel.findBossInstance(code);
if (!!bossInstance && ( bossInstance.bossHp > 0 || bossInstance.startTime >= getTodayZeroPoint() )) {
if (!!bossInstance && ( bossInstance.bossHp > 0 || bossInstance.startTime >= getZeroPoint() )) {
res.releaseCallback();
return resResult(STATUS.GUILD_SCRIPT_IS_OPENED_TODAY);
}
@@ -116,7 +115,7 @@ export class GuildHandler {
if (bossInstance.bossHp <= 0)
return resResult(STATUS.GUILD_SCRIPT_IS_COMPLETE);
let myRank = findWhere(bossInstance.ranks, {roleId});
if (!!myRank && myRank.time > getTodayZeroPoint())
if (!!myRank && myRank.time > getZeroPoint())
return resResult(STATUS.GUILD_SCRIPT_IS_BATTLED);
let { warId, ranks } = bossInstance;
const battleCode = genCode(8); // 关卡唯一值
@@ -1,5 +1,5 @@
import { Application, BackendSession, pinus, ChannelService } from 'pinus';
import { resResult, getRandEelm, getRefTime, shouldRefresh, sortArrRandom } from '../../../pubUtils/util';
import { Application, BackendSession, ChannelService } from 'pinus';
import { resResult, getRandEelm, shouldRefresh, sortArrRandom } from '../../../pubUtils/util';
import { STATUS, GUILD_OPERATE, GUILD_AUTH, GUILD_JOB, GUILD_APPLY_TYPE, GUILD_STRUCTURE, GUILD_REC_TYPE, GUILD_STRUCTURE_NAME, MAIL_TYPE, REDIS_KEY, GUILD_SELECT, USER_GUILD_SELECT, TASK_TYPE } from '../../../consts';
import { UserGuildModel } from '../../../db/UserGuild';
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly } from '../../../services/guildService';
@@ -8,9 +8,9 @@ import { RoleModel, RoleType } from '../../../db/Role';
import { ARMY } from '../../../pubUtils/dicParam';
import { handleCost, addItems } from '../../../services/rewardService';
import { getGoldObject } from '../../../pubUtils/itemUtils';
import { nowSeconds, getBeforeDaySeconds, getSeconds } from '../../../pubUtils/timeUtil';
import { nowSeconds, getTimeFun } from '../../../pubUtils/timeUtil';
import { GuildListInfo } from '../../../domain/battleField/guild';
import { GuildRankParam, GuildLeader } from '../../../domain/rank';
import { GuildLeader } from '../../../domain/rank';
import { UserGuildApplyModel } from '../../../db/UserGuildApply';
import { hasStructureConsume, getStructureConsume, gameData } from '../../../pubUtils/data';
import { GuildRecModel } from '../../../db/GuildRec';
@@ -420,13 +420,13 @@ export class GuildHandler {
let guild = await GuildModel.findByCode(myGuild.guildCode, serverId, GUILD_SELECT.INVITED_MEMBER);
let invitedMembers = guild.invitedMembers;
if(shouldRefresh(guild.inviteTime, new Date(), 0)) {
if(shouldRefresh(guild.inviteTime, new Date())) {
invitedMembers = [];
}
// 离线时间,三天内在线且尚未加入军团。按以下规则排序 离线时间 玩家等级 玩家战力
const day = getBeforeDaySeconds(3);
const day = <number>getTimeFun().getBeforeDay(3);
const { quitGuildTime: quitTime = 0 } = await RoleModel.findByRoleId(roleId);
let allList = await RoleModel.getInviteList(day, serverId);
@@ -472,7 +472,7 @@ export class GuildHandler {
}
}
}
await GuildModel.recordInvitedMember(code, serverId, roleIds, shouldRefresh(guild.inviteTime, new Date(), 0));
await GuildModel.recordInvitedMember(code, serverId, roleIds, shouldRefresh(guild.inviteTime, new Date()));
this.channelService.pushMessageByUids('onGuildInvite', resResult(STATUS.SUCCESS, { code }), uids);
return resResult(STATUS.SUCCESS, { roleIds: result });
@@ -717,7 +717,7 @@ export class GuildHandler {
// 离线72小时
const { roleName: oldRoleName, quitTime } = await RoleModel.findByRoleId(leaderRoleId);
if (quitTime > getBeforeDaySeconds(3)) {
if (quitTime > <number>getTimeFun().getBeforeDay(3)) {
return resResult(STATUS.GUILD_LEADER_LOGIN);
}
// 上周周功勋最高的人
@@ -830,9 +830,8 @@ export class GuildHandler {
const checkResult = await checkAuth(GUILD_OPERATE.GET_REC, roleId, code);
if (!checkResult) return resResult(STATUS.GUILD_AUTH_NOT_ENOUGH);
let startTime = getRefTime(new Date(), 0, -3);
// console.log(startTime)
const list = await GuildRecModel.getGuildRec(code, getSeconds(startTime));
const list = await GuildRecModel.getGuildRec(code, <number>getTimeFun().getBeforeDayWithHour(3));
return resResult(STATUS.SUCCESS, { list });
}
@@ -987,7 +986,7 @@ export class GuildHandler {
const serverId = session.get('serverId');
const guild = await GuildModel.findByCode(code, serverId);
const leader = <RoleType>guild.leader;
let threeDaysBefore = getBeforeDaySeconds(3);
let threeDaysBefore = <number>getTimeFun().getBeforeDay(3);
await RoleModel.updateRoleInfo(leader.roleId, { quitTime: threeDaysBefore } );
return resResult(STATUS.SUCCESS, { code });
@@ -3,11 +3,11 @@ import { resResult, genCode, getRandSingleEelm } from '../../../pubUtils/util';
import { STATUS, TASK_TYPE } from '../../../consts';
import { GuildTrainModel } from '../../../db/GuildTrain';
import { BattleRecordModel } from '../../../db/BattleRecord';
import { nowSeconds, getHourPoint, getCurHourPoint } from '../../../pubUtils/timeUtil';
import { nowSeconds, getTimeFun, getZeroPoint } from '../../../pubUtils/timeUtil';
import { getUserGuild, getGuildTrainInfo, unlockTrain, getGuildTrainRewards } from '../../../services/guildTrainService';
import { findIndex, findWhere } from 'underscore'
import { lockData } from '../../../services/redLockService';
import { REFRESH_HOUR, GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
import { GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
import { UserGuildModel } from '../../../db/UserGuild';
import { GuildModel } from '../../../db/Guild';
import { getArmyTrainJuDian, getTrainSoloReward, getTrainBaseByLv } from '../../../pubUtils/data';
@@ -171,10 +171,11 @@ export class GuildTrainHandler {
return resResult(STATUS.WRONG_PARMS);
}
if (time < getCurHourPoint(REFRESH_HOUR) && nowSeconds() > getCurHourPoint(REFRESH_HOUR)) {
let todayRef = <number>getTimeFun().getTimeWithHour(); // 今天的5点
if (time < todayRef && nowSeconds() > todayRef) {
return resResult(STATUS.GUILD_TRAIN_IS_RESETED);//重置前进入战斗,重置后回调该接口
}
if (time > getHourPoint(REFRESH_HOUR)) {
if (time > getZeroPoint()) { // 刷新时间,如果是4点算前一天的5点
userGuild = await UserGuildModel.updateInfo(roleId, {}, { trainCount: -1 });//扣除一次挑战次数
}
await BattleRecordModel.updateBattleRecordByCode(battleCode, {
@@ -86,7 +86,7 @@ export class TowerBattleHandler {
let {timeReward, startTime, deltaTime} = result.data;
let {hangUpSpdUpCnt, lastSpdUpTime} = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && hangUpSpdUpCnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime) && hangUpSpdUpCnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
hangUpSpdUpCnt = HANG_UP_CONSTS.MAX_SPD_UP_CNT;
}
let num = HANG_UP_CONSTS.MAX_SPD_UP_CNT - hangUpSpdUpCnt + 1;
@@ -167,7 +167,7 @@ export class TowerBattleHandler {
let { towerLv, towerTaskRefTime, towerTaskReCnt = 0 } = await RoleModel.findByRoleId(roleId);
let curTasks = await TowerTaskRecModel.getCurTasks(roleId); // 当前显示中的任务
const needRefresh = shouldRefresh(towerTaskRefTime, curTime, TOWER_TASK_CONST.REFRESH_TIME);
const needRefresh = shouldRefresh(towerTaskRefTime, curTime);
if(needRefresh) {
const batchCode = genCode(8);
@@ -12,7 +12,7 @@ import { getAp } from '../../../services/actionPointService';
import { ItemModel } from '../../../db/Item';
import { chackFunOpenWhenLogin } from '../../../services/funcSwitchService';
import { loginRefresh } from '../../../services/playerEventService';
import { nowSeconds, getCurWeekTime } from '../../../pubUtils/timeUtil';
import { nowSeconds } from '../../../pubUtils/timeUtil';
import { rmRoleFromQueue, roleLeave, getRoleOnlineInfo, roleLogin } from '../../../services/redisService';
import { UserGuildModel } from '../../../db/UserGuild';
import { GuildModel } from '../../../db/Guild';
@@ -8,7 +8,7 @@ import { UserGuildActivityRecModel } from "../../../db/UserGuildActivityRec";
import { leaveCityChannel, addRoleToCityChannel, getCityChannelSid } from "../../../services/chatService";
import { UserGuildModel } from "../../../db/UserGuild";
import { GuildActivityRecordModel } from "../../../db/GuildActivityRec";
import { nowSeconds, getBeforeSeconds, getNextHourPoint } from "../../../pubUtils/timeUtil";
import { nowSeconds, getTimeFun } from "../../../pubUtils/timeUtil";
import { getGoldObject } from "../../../pubUtils/itemUtils";
import { GUILDACTIVITY } from "../../../pubUtils/dicParam";
import { handleCost } from "../../../services/rewardService";
@@ -233,14 +233,15 @@ export class CityActivityHandler {
let pushResult = await UserGuildActivityRecModel.pushCityRecord(code, { round, hid, damage });
if (!pushResult) return resResult(STATUS.WRONG_PARMS);
let tomorrow = <number>getTimeFun().getAfterDayWithHour();
// 更新redis数据
let myR = new Rank(REDIS_KEY.USER_CITY_ACTIVITY, { serverId, guildCode });
let myScore = await myR.setRankWithRoleInfo(roleId, damage, Date.now(), null, true);
await myR.setExpire(getNextHourPoint(5));
await myR.setExpire(tomorrow);
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
let guildScore = await r.setRankWithGuildInfo(guildCode, damage, Date.now(), null, true);
await r.setExpire(getNextHourPoint(5));
await r.setExpire(tomorrow);
gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp, -1 * damage);
if (gateHp <= 0) {
@@ -278,7 +279,7 @@ export class CityActivityHandler {
if (!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
// 更新userGuildActivityRecord
let challengeTime = getBeforeSeconds(-1 * GUILDACTIVITY.CITYACTIVITY_CHALLENGE_CD);
let challengeTime = <number>getTimeFun().getBeforeSeconds(-1 * GUILDACTIVITY.CITYACTIVITY_CHALLENGE_CD);
let myGuildActivityRec = await UserGuildActivityRecModel.updateInfo(code, { isSuccess, isCompleted: true, cityId, challengeTime });
if (!myGuildActivityRec) return resResult(STATUS.INTERNAL_ERR);
@@ -13,7 +13,7 @@ import { getGuildChannelSid } from "../../../services/chatService";
import { UserGuildModel } from "../../../db/UserGuild";
import { GuildActivityCityModel } from "../../../db/GuildActivityCity";
import { Rank } from "../../../services/rankService";
import { getNextHourPoint } from "../../../pubUtils/timeUtil";
import { getTimeFun } from "../../../pubUtils/timeUtil";
import { checkTask } from "../../../services/taskService";
import { accomplishTask } from "../../../pubUtils/taskUtil";
@@ -139,14 +139,15 @@ export class GateActivityHandler {
let { score, newRecords, memberRecord: newMemberRecord } = scoreResult;
obj.setMemberRecord(code, newMemberRecord);
let tomorrow = <number>getTimeFun().getAfterDayWithHour();
// 更新redis数据
let myR = new Rank(REDIS_KEY.USER_GATE_ACTIVITY, { serverId, guildCode }, false);
let myScore = await myR.setRankWithRoleInfo(roleId, score, Date.now(), null, true);
await myR.setExpire(getNextHourPoint(5));
await myR.setExpire(tomorrow);
let r = new Rank(REDIS_KEY.GATE_ACTIVITY, { serverId }, true);
let guildScore = await r.setRankWithGuildInfo(guildCode, score, Date.now(), null, true);
await r.setExpire(getNextHourPoint(5));
await r.setExpire(tomorrow);
// 更新数据库
let rec = await UserGuildActivityRecModel.pushRecord(code, newRecords, round);
@@ -1,8 +1,8 @@
import { Application, BackendSession, ChannelService } from "pinus";
import { resResult, getRandEelm, getResStr, shouldRefresh, getRefTime, sortArrRandom } from "../../../pubUtils/util";
import { resResult, getRandEelm, getResStr, shouldRefresh, sortArrRandom } from "../../../pubUtils/util";
import { STATUS, ROLE_SELECT, FRIEND_DROP_TYPE, FRIEND_RELATION_TYPE, POPULATE_TYPE, BLOCK_OPEATE, CONSUME_TYPE, ITID, HERO_SELECT, EQUIP_SELECT, REDIS_KEY, MSG_SOURCE, MSG_TYPE, TASK_TYPE } from "../../../consts";
import Role, { RoleModel, RoleType } from "../../../db/Role";
import { getBeforeHourSeconds } from "../../../pubUtils/timeUtil";
import { RoleModel, RoleType } from "../../../db/Role";
import { getTimeFun, getZeroPointD } from "../../../pubUtils/timeUtil";
import { FriendApplyModel } from "../../../db/FriendApply";
import { FriendApplyParams, FriendListParam, FriendRecommendParams, BlackListParam, FriendValueListParam } from "../../../domain/roleField/friend";
import { FriendShipModel, FriendShipType } from "../../../db/FriendShip";
@@ -40,13 +40,13 @@ export class FriendHandler {
public async getRecommend(msg: { }, session: BackendSession) {
let roleId: string = session.get('roleId');
const day = getBeforeHourSeconds(FRIEND.FRIEND_RECONMMEND_ACTIVETIME);
const day = <number>getTimeFun().getBeforeHour(FRIEND.FRIEND_RECONMMEND_ACTIVETIME);
const { lv, serverId: myServerId, userInfo: { serverType: myServerType } } = await RoleModel.findByRoleId(roleId, ROLE_SELECT.GET_MY_SERVER);
let allList = await RoleModel.getRecommedList(lv - FRIEND.FRIEND_RECONMMEND_LEVEL, lv + FRIEND.FRIEND_RECONMMEND_LEVEL, day);
// 筛掉自己今天申请过的人
let applyList = await FriendApplyModel.getSentApplyList(roleId, getRefTime(new Date(), 0));
let applyList = await FriendApplyModel.getSentApplyList(roleId, getZeroPointD());
allList = allList.filter(cur => {
return !applyList.find(ccur => ccur.roleId == cur.roleId);
});
@@ -294,7 +294,7 @@ export class FriendHandler {
if(!friendRole || !friendShip) continue;
let fs = <FriendShipType>friend.friendShip;
let ref = shouldRefresh(fs.refTime, new Date(), 0);
let ref = shouldRefresh(fs.refTime, new Date());
if(ref) {
friendShip = await FriendShipModel.refreshSendAndReceive(roleId, friendRole.roleId);
}
@@ -525,7 +525,7 @@ export class FriendHandler {
if(todaySendCnt + FRIEND.FRIEND_FRIENDPOINT_ADD > max) break;
let fs = <FriendShipType>relation.friendShip;
let ref = shouldRefresh(fs.refTime, new Date(), 0);
let ref = shouldRefresh(fs.refTime, new Date());
let sendHeartRec = await FriendShipModel.sendHeart(roleId, relation.roleId, 1, FRIEND.FRIEND_RECEIVE_SINGLE, ref);
if(!sendHeartRec) continue;
@@ -592,7 +592,7 @@ export class FriendHandler {
// 收取爱心
let fs = <FriendShipType>relation.friendShip;
let ref = shouldRefresh(fs.refTime, new Date(), 0);
let ref = shouldRefresh(fs.refTime, new Date());
let receiveHeartRec = await FriendShipModel.receiveHeart(roleId, relation.roleId, 1, relation.beSentHeart, ref);
if(!receiveHeartRec) continue;
@@ -1,11 +1,11 @@
import { Application, BackendSession, pinus } from "pinus";
import { resResult, parseGoodStr, getRandSingleEelm } from "../../../pubUtils/util";
import { STATUS, TASK_FUN_TYPE } from "../../../consts";
import { STATUS, TASK_FUN_TYPE, SHOP_REFRESH_TYPE } from "../../../consts";
import { gameData } from "../../../pubUtils/data";
import { UserTaskRecModel } from "../../../db/UserTaskRec";
import { addItems } from "../../../services/rewardService";
import { UserTaskModel } from "../../../db/UserTask";
import { getCurWeekDate, nowSeconds } from "../../../pubUtils/timeUtil";
import { nowSeconds, getZeroPointD } from "../../../pubUtils/timeUtil";
import { DicDailyTask, DicAchievement, DicMainTask } from "../../../pubUtils/dictionary/DicTask";
import { getMainTask, refDailyTaskBox, removeHistoryTask, getCurTask, checkTask } from "../../../services/taskService";
import { TASK } from "../../../pubUtils/dicParam";
@@ -41,7 +41,7 @@ export class ShopHandler {
if(type == TASK_FUN_TYPE.DAILY) { // 增加积分
let userTask = await UserTaskModel.findByRole(roleId);
let dic = <DicDailyTask>dicTask;
let curWeek = getCurWeekDate(1, 5);
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
if(curWeek > userTask.dailyTaskRefWeekly) {
userTask = await UserTaskModel.resetDailyScore(roleId, dic.point, curWeek);
} else {
@@ -139,7 +139,7 @@ export class ShopHandler {
let point = 0, weeklyPoint = 0, box: number[] = [];
// 每日、成就增加积分
if(type == TASK_FUN_TYPE.DAILY) { // 增加积分
let curWeek = getCurWeekDate(1, 5);
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
let shouldRefresh = false;
let { dailyTaskPointWeekly, dailyTaskBox, dailyTaskRefWeekly } = userTask;
@@ -263,7 +263,7 @@ export class ShopHandler {
let point = 0, weeklyPoint = 0;
if(type == TASK_FUN_TYPE.DAILY) { // 增加积分
let userTask = await UserTaskModel.findByRole(roleId);
let curWeek = getCurWeekDate(1, 5);
let curWeek = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
if(curWeek > userTask.dailyTaskRefWeekly) {
userTask = await UserTaskModel.resetDailyScore(roleId, incPoint, curWeek);
} else {
+10 -10
View File
@@ -4,7 +4,7 @@ import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_
import { DividendRec, ItemReward } from "../domain/dbGeneral";
import { genCode, resResult } from '../pubUtils/util';
import { LotModel, LotParam } from '../db/Lot';
import { getNextTime, getTodayZeroDate, getZeroDateByDeltaDay } from '../pubUtils/timeUtil';
import { getZeroPointD, getTimeFunD } from '../pubUtils/timeUtil';
import { gameData, getGoodById } from '../pubUtils/data';
import { DividendParam, DividendType } from '../db/Dividend';
import { pushMail } from '../pubUtils/interface';
@@ -53,31 +53,31 @@ export async function officialAuctionLots(session: BackendSession, begin: Date)
}
export function auctionBegin() {
return getNextTime(new Date(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
return <Date>getTimeFunD().getAfterDayWithHour(0, AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
}
export function guildAuctionEnd() {
return getNextTime(new Date(), AUCTION_TIME.GUILD_END_HOUR, AUCTION_TIME.GUILD_END_MIN);
return <Date>getTimeFunD().getAfterDayWithHour(0, AUCTION_TIME.GUILD_END_HOUR, AUCTION_TIME.GUILD_END_MIN);
}
export function auctionEnd() {
return getNextTime(new Date(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
export function auctionEnd() {
return <Date>getTimeFunD().getAfterDayWithHour(0, AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
}
export function todayGuildBegin() {
return getNextTime(getTodayZeroDate(), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
return <Date>getTimeFunD(getZeroPointD()).getAfterDayWithHour(0, AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
}
export function yestodayGuildBegin() {
return getNextTime(getZeroDateByDeltaDay(-1), AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
export function yestodayGuildBegin() {
return <Date>getTimeFunD(getZeroPointD()).getAfterDayWithHour(-1, AUCTION_TIME.GUILD_BEGIN_HOUR, AUCTION_TIME.GUILD_BEGIN_MIN);
}
export function todayWorldBegin() {
return getNextTime(getTodayZeroDate(), AUCTION_TIME.WORLD_BEGIN_HOUR, AUCTION_TIME.WORLD_BEGIN_MIN);
return <Date>getTimeFunD(getZeroPointD()).getAfterDayWithHour(0, AUCTION_TIME.WORLD_BEGIN_HOUR, AUCTION_TIME.WORLD_BEGIN_MIN);
}
export function todayWorldEnd() {
return getNextTime(getTodayZeroDate(), AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
return <Date>getTimeFunD(getZeroPointD()).getAfterDayWithHour(0, AUCTION_TIME.WORLD_END_HOUR, AUCTION_TIME.WORLD_END_MIN);
}
/**
+7 -6
View File
@@ -1,11 +1,11 @@
import { HeroModel } from './../db/Hero';
import { HangUpRecordModel } from './../db/HangUpRecord';
import { pinus } from 'pinus';
import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY, TASK_TYPE } from './../consts';
import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY, TASK_TYPE, TIME_OUTPUT_TYPE } from './../consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
import { RoleModel } from './../db/Role';
import { shouldRefresh, resResult, cal, getRandEelmWithWeight, getRefTime } from '../pubUtils/util';
import { shouldRefresh, resResult, cal, getRandEelmWithWeight } from '../pubUtils/util';
import { STATUS } from '../consts/statusCode';
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
import { TowerTaskRecModel } from '../db/TowerTaskRec';
@@ -14,6 +14,7 @@ import { Rank } from './rankService';
import { checkTask } from './taskService';
import { getRandExpedition, gameData } from '../pubUtils/data';
import { ItemInter, RewardInter } from '../pubUtils/interface';
import { getTimeFunM } from '../pubUtils/timeUtil';
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
let { towerLv } = await RoleModel.findByRoleId(roleId);
@@ -113,7 +114,7 @@ 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;
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime, HANG_UP_CONSTS.REFRESH_TIME, 1) && hangUpSpdUpCnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
if (!lastSpdUpTime || (shouldRefresh(lastSpdUpTime, curTime) && hangUpSpdUpCnt <= HANG_UP_CONSTS.MAX_SPD_UP_CNT)) {
hangUpSpdUpCnt = HANG_UP_CONSTS.MAX_SPD_UP_CNT;
}
if (cnt > hangUpSpdUpCnt) {
@@ -145,7 +146,7 @@ export async function calcuHangUpReward(roleId: string, speedUp = false, speedUp
}
if (speedUp) { // 加速,直接收取6小时收益,小数的累积和普通收取独立
if (hangUpSpdUpCnt >= speedUpCnt || !lastSpdUpTime || shouldRefresh(lastSpdUpTime, new Date, HANG_UP_CONSTS.REFRESH_TIME, 1)) { // 可加速
if (hangUpSpdUpCnt >= speedUpCnt || !lastSpdUpTime || shouldRefresh(lastSpdUpTime, new Date)) { // 可加速
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 = [];
@@ -293,8 +294,8 @@ export async function createCurTasks(towerLv: number, batchCode: string, roleId:
}
export function getRemainTime(curTime: Date) {
let nextTime = getRefTime(curTime, TOWER_TASK_CONST.REFRESH_TIME, 1);
return Math.floor((nextTime.getTime() - curTime.getTime())/1000);
let nextTime = <number>getTimeFunM(curTime).getAfterDayWithHour(1);
return Math.floor((nextTime - curTime.getTime())/1000);
}
export function treatTask(recs: Array<any>, curTime: Date) {
+2 -1
View File
@@ -24,6 +24,7 @@ import { checkTaskInComBattleEnd } from './taskService';
import { getRewardByBlueprtId, gameData, comBtlRangeByLv, getBossHpByBlueprtId } from '../pubUtils/data';
import { getFriendPointObject } from '../pubUtils/itemUtils';
import { DicWar } from '../pubUtils/dictionary/DicWar';
import { getZeroPointD } from '../pubUtils/timeUtil';
/**
* 在给定的品质列表中随机返回一定数量的藏宝图Id
@@ -170,7 +171,7 @@ export async function getRealReward(blueprtId: number, roleSt: RoleStatus) {
}
export async function getAssistTimesByQuality(roleId: string, qualityArr?: number[]) {
let teams = await ComBattleTeamModel.getAssistTeamsByTime(roleId, qualityArr, new Date(new Date().setHours(0, 0, 0, 0)), true);
let teams = await ComBattleTeamModel.getAssistTeamsByTime(roleId, qualityArr, getZeroPointD(), true);
let cntMap = new Map<number, number>();
teams.forEach(team => {
if (team && team.quality && team.roleStatus) {
+2 -2
View File
@@ -1,6 +1,6 @@
import { DonationModel } from '../db/Donation';
import { getTodayZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
import { getZeroPoint, nowSeconds } from '../pubUtils/timeUtil';
import { GuildModel } from '../db/Guild';
import { findWhere } from 'underscore';
import { GUILD_STRUCTURE } from '../consts/constModules/guildConst';
@@ -14,7 +14,7 @@ export async function getDonation(code: string, serverId: number) {
if (!donation) {
donation = await createDonation(code, serverId);
}
if (donation.refTime < getTodayZeroPoint()) {
if (donation.refTime < getZeroPoint()) {
let { structure } = await GuildModel.findGuild(code, serverId, 'structure');
let { lv } = findWhere(structure, {id: GUILD_STRUCTURE.DONATE});
donation = await DonationModel.updateDonation(code, { donateFund:0, reports:[], refTime: nowSeconds(), donationLv: lv});
+2 -2
View File
@@ -11,7 +11,7 @@ import { DUNGEON_CONST } from '../consts';
export async function checkDungeonNum(roleId: string, inc: number) {
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
let needRefresh = shouldRefresh(dungeonRefTime, curTime);
if(needRefresh) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
@@ -38,7 +38,7 @@ export async function checkDungeonAndIncrease(roleId: string, inc: number, isRef
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime } = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let needRefresh = isRef && shouldRefresh(dungeonRefTime, curTime, DUNGEON_CONST.REFRESH_TIME);
let needRefresh = isRef && shouldRefresh(dungeonRefTime, curTime);
if(needRefresh) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
@@ -9,6 +9,7 @@ import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
import { HeroType } from '../db/Hero';
import { gameData } from '../pubUtils/data';
import { getPlayerAttribute, getRobotAttribute } from './pvpService';
import { getTimeFunD } from '../pubUtils/timeUtil';
/**
* 根据存下的战力获取当前远征关卡的对手
@@ -167,9 +168,8 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
export async function getCEScaleAndRange(roleId: string, curDicExpedition: any) {
// 匹配,判断是不是新手期
const role = await RoleModel.findByRoleId(roleId);
let now = new Date();
let today = now.setHours(0, 0, 0, 0);;
let isNew = today - role.createdAt.getTime() <= 3*24*60*60*1000;
let timef = getTimeFunD(role.createdAt)
let isNew = timef.getDayGap() <= 3;
let scale = isNew?curDicExpedition.CEScaleNew:curDicExpedition.CEScale;
let range = isNew?curDicExpedition.CERangeNew:curDicExpedition.CERange;
return {scale, range, lv: role.lv}
@@ -206,7 +206,7 @@ export async function getResetRemainCnt(curTime: Date, roleId: string, role?: Ro
}
let { expeditionResetCnt, expeditionResetRefTime } = role;
let needRefresh = !expeditionResetRefTime || shouldRefresh(expeditionResetRefTime, curTime, EXPEDITION_CONST.REFRESH_TIME);
let needRefresh = !expeditionResetRefTime || shouldRefresh(expeditionResetRefTime, curTime);
if(needRefresh) {
expeditionResetCnt = 0; expeditionResetRefTime = curTime;
}
+6 -6
View File
@@ -3,8 +3,8 @@ import { ActivityModel } from "../db/Activity";
import { DicGacha } from "../pubUtils/dictionary/DicGacha";
import { UserGachaType, UserGachaModel } from "../db/UserGacha";
import { shouldRefresh, getRandEelm, getRandEelmWithWeight } from "../pubUtils/util";
import { REFRESH_HOUR, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR } from "../consts";
import { getNextDayByGap, getTodayZeroDate } from "../pubUtils/timeUtil";
import { REFRESH_TIME, GACHA_TO_FLOOR, GACHA_FLOOR_TYPE, GACHA_CONTENT_TYPE, HERO_QUALITY_TYPE, GACHA_OCCUPY_HID, IT_TYPE, ITID, CONSUME_TYPE, SPECIAL_ATTR, TIME_OUTPUT_TYPE } from "../consts";
import { getTimeFunD, getZeroPointD } from "../pubUtils/timeUtil";
import { gameData, getDicGachaFloor } from "../pubUtils/data";
/**
@@ -38,13 +38,13 @@ export async function refreshGacha(dicGacha: DicGacha, userGacha: UserGachaType)
}
let { roleId, gachaId, refFreeTime, refHopeTime, hope } = userGacha;
if(shouldRefresh(refFreeTime, new Date(), REFRESH_HOUR, day)) {
let ref = getNextDayByGap(refFreeTime, new Date(), day);
if(shouldRefresh(refFreeTime, new Date(), REFRESH_TIME, day)) {
let ref = <Date>getTimeFunD().getAfterDayByGap(refFreeTime, day);
userGacha = await UserGachaModel.refreshFreeCount(roleId, gachaId, 0, ref);
}
if(shouldRefresh(refHopeTime, new Date(), REFRESH_HOUR)) {
if(shouldRefresh(refHopeTime, new Date(), REFRESH_TIME)) {
hope = hope.map(cur => { return { ...cur, hasGet: false}});
let ref = getTodayZeroDate(REFRESH_HOUR);
let ref = getZeroPointD();
userGacha = await UserGachaModel.refreshHopeCount(roleId, gachaId, 0, hope, ref);
}
return userGacha
@@ -12,7 +12,7 @@ import { getGuildChannelSid } from "./chatService";
import { pinus } from "pinus";
import { getRandEelm, sortArrRandom, resResult } from "../pubUtils/util";
import { Rank } from "./rankService";
import { getNextHourPoint } from "../pubUtils/timeUtil";
import { getTimeFun } from "../pubUtils/timeUtil";
export class GateActivityObject {
private gateHp: Map<string, number> = new Map(); // 城门血条,每个军团有一条血条 guildCode => hp
@@ -268,7 +268,8 @@ export class RaceActivityObject {
if(woodenHorse.status == 1 || woodenHorse.status == 2) { // 更新距离 // TODO 写进const表
let r = new Rank(REDIS_KEY.RACE_ACTIVITY, { serverId }, true, 5);
await r.setRank({guildCode}, Math.floor(woodenHorse.distance * 1000), woodenHorse.time - woodenHorse.startTime, false);
await r.setExpire(getNextHourPoint(5));
let tomorrow = <number>getTimeFun().getAfterDayWithHour();
await r.setExpire(tomorrow);
if (needSendEnd) { // 抵达后发送奖励,发送消息,结算
await sendSingleRaceActEndMsg(guildCode, woodenHorse);
}
@@ -3,7 +3,7 @@ import { RoleModel } from "../db/Role";
import { reduceCe } from "../pubUtils/util";
import { GUILDACTIVITY } from "../pubUtils/dicParam";
import { gameData, getGuildAuctionRewards, getCityActivityRewards } from "../pubUtils/data";
import { getCurHourPoint, getCurDay, nowSeconds } from "../pubUtils/timeUtil";
import { getCurDay, nowSeconds, getTimeFun } from "../pubUtils/timeUtil";
import { GUILD_ACTIVITY_STATUS, GET_POINT_WAYS, GUILD_ACTIVITY_TYPE, REDIS_KEY, AUCTION_SOURCE, MAIL_TYPE, CITY_STATUS } from "../consts";
import { Record, UserGuildActivityRecModel } from "../db/UserGuildActivityRec";
import { GateMembersRec, CityParam, Member, WoodenHorse } from "../domain/battleField/guildActivity";
@@ -92,8 +92,9 @@ export function getGuildActivityStatus(id: number) {
}
export function getGuildActivityByDic(dicGuildActivity: DicGuildActivity) {
let startTime = getCurHourPoint(dicGuildActivity.startTime, dicGuildActivity.startMinute, dicGuildActivity.startSeconds);
let countdownTime = getCurHourPoint(dicGuildActivity.countDown);
let t = getTimeFun();
let startTime = <number>t.getTimeWithHour(dicGuildActivity.startTime, dicGuildActivity.startMinute, dicGuildActivity.startSeconds);
let countdownTime = <number>t.getTimeWithHour(dicGuildActivity.countDown);
let { duringTime, openDay } = dicGuildActivity;
let endTime = startTime + duringTime;
+5 -5
View File
@@ -1,5 +1,5 @@
import { BossInstanceType, BossInstanceModel } from '../db/BossInstance';
import { getTodayZeroPoint } from '../pubUtils/timeUtil';
import { getZeroPoint } from '../pubUtils/timeUtil';
import { lockData } from '../services/redLockService';
import { findIndex } from 'underscore';
import { MailModel, MailType } from '../db/Mail';
@@ -25,14 +25,14 @@ export async function getBossInstanceInfo(bossInstance: BossInstanceType, roleId
return b.score - a.score + a.time - b.time;
});
let result:any = {};
if (!!winWarId && winTime > getTodayZeroPoint() && roleIdRecords.indexOf(roleId) == -1) {
if (!!winWarId && winTime > getZeroPoint() && roleIdRecords.indexOf(roleId) == -1) {
//今日通关过,且首次点开boss界面,提示某某boss已通关
result = { showParam: { winWarId, winBossLv } };
await BossInstanceModel.recordRoleIdWhenCheck(guildCode, roleId);
}
if ( bossHp <= 0 ) {
result = { warId };
if (startTime < getTodayZeroPoint()) {
if (startTime < getZeroPoint()) {
//今日未开启过boss,等待开启
result.status = GUILD_BOSS_STATUS.WAIT_OPEN;
return result;
@@ -47,7 +47,7 @@ export async function getBossInstanceInfo(bossInstance: BossInstanceType, roleId
let lastRanks = ranks.map(({roleId: battleRoleId, score, time}, index) => {
if (roleId == battleRoleId) {
myRank = { roleId, score, rankLv: index + 1 };
if (time >= getTodayZeroPoint())
if (time >= getZeroPoint())
isBattled = true;
}
return {roleId, score, rankLv: index + 1};
@@ -80,7 +80,7 @@ export async function getBossInstanceWhenEnd(bossInstance: BossInstanceType, rol
pushRanks.forEach(({roleId: battleRoleId, score, time}, index) => {
if (roleId == battleRoleId) {
myRank = {roleId, score, rankLv: index + 1};
if (time >= getTodayZeroPoint())
if (time >= getZeroPoint())
isBattled = true;
}
return {roleId, score, rankLv: index + 1};
+2 -2
View File
@@ -119,7 +119,7 @@ export async function getGuildWithRefActive(guildCode: string, serverId: number)
const now = new Date();
let { activeDaily, refTimeDaily } = guild;
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
let isRefDaily = shouldRefresh(refTimeDaily, now);
if (isRefDaily) {
activeDaily = 0; refTimeDaily = now;
guild = await GuildModel.updateInfoWithLeader(guildCode, { activeDaily, refTimeDaily }, {});
@@ -198,7 +198,7 @@ export async function getUserGuildWithRefActive(roleId: string, select: string,
let { receivedActive, refTimeDaily, activeDaily, activeRecord, wishGoods } = userGuild;
const now = new Date();
let isRefDaily = shouldRefresh(refTimeDaily, now, 0);
let isRefDaily = shouldRefresh(refTimeDaily, now);
if (isRefDaily) {
let mails = new Array<MailType>();
let pushMessage = new Array<pushMail>();
@@ -1,7 +1,7 @@
import { UserGuildModel } from '../db/UserGuild';
import { getArmyTrainJuDian, getTrainBaseByLv } from '../pubUtils/data';
import { nowSeconds, getHourPoint } from '../pubUtils/timeUtil';
import { REFRESH_HOUR, GUILD_STRUCTURE } from '../consts/constModules/guildConst';
import { nowSeconds, getZeroPoint } from '../pubUtils/timeUtil';
import { GUILD_STRUCTURE } from '../consts';
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
import { GuildModel } from '../db/Guild';
import { findWhere } from 'underscore';
@@ -26,7 +26,7 @@ export async function getUserGuild(roleId: string, serverId: number) {
return;
let { trainCount, trainTime, buyTrainCount, guildCode} = userGuild;
await resetTrain(guildCode, serverId);//检查重置练兵场
if (trainTime < getHourPoint(REFRESH_HOUR)) {//重置挑战次数和购买次数
if (trainTime < getZeroPoint()) {//重置挑战次数和购买次数
trainCount = ARMY.ARMY_TRAIN_BUYTIMES;
buyTrainCount = 0;
userGuild = await UserGuildModel.updateInfo(roleId, {trainCount, trainTime: nowSeconds(), buyTrainCount}, {});
+4 -4
View File
@@ -4,12 +4,12 @@ import { RoleType } from '../db/Role';
import { PVP_HERO_POS, REDIS_KEY, PVP_CONST } from '../consts';
import { setPvpDefResult } from '../services/timeTaskService';
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
import { getRandSingleIndex, genCode, shouldRefresh, reduceCe, getChineseName } from '../pubUtils/util';
import { getRandSingleIndex, genCode, shouldRefresh, getChineseName } from '../pubUtils/util';
import { oppPlayersInter, pvpEndParamInter } from '../pubUtils/interface';
import { gameData, getPLvByScore } from "../pubUtils/data";
import { PVP } from '../pubUtils/dicParam';
import { SystemConfigModel } from '../db/SystemConfig'
import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil';
import { nowSeconds, getTimeFun } from '../pubUtils/timeUtil';
import { HeroesRecord } from '../db/PvpRecord';
import { HeroModel } from '../db/Hero';
import { MainAttrNumber, Attribute, CeAttrData, CeAttrDataRole } from '../domain/roleField/attribute';
@@ -405,7 +405,7 @@ export function refresh(challengeCnt: number, challengeRefTime: number, seasonEn
return {challengeCnt, challengeRefTime};
}
let period = PVP.PVP_CHALLENGE_NORMALTIMES * 60;
if (checkTodayTime(seasonEndTime)) {
if (getTimeFun(seasonEndTime).checkDay()) {
period = PVP.PVP_CHALLENGE_FINALTIMES * 60;
}
let time = nowSeconds();
@@ -452,7 +452,7 @@ export async function findPvpDefByRoleId(roleId: string) {
// 获取刷新对手次数及消耗
export function getRefOppCnt(refOppCnt: number, refOppTime: Date) {
let curTime = new Date();
let shouldRefOpp = shouldRefresh(refOppTime, curTime, PVP_CONST.REFRESH_TIME);
let shouldRefOpp = shouldRefresh(refOppTime, curTime);
if(shouldRefOpp) {
refOppCnt = 0; refOppTime = curTime;
}
+2 -3
View File
@@ -5,7 +5,6 @@ import { resResult, shouldRefresh, shouldRefreshWeek } from '../pubUtils/util';
import { nowSeconds } from "../pubUtils/timeUtil";
import { RoleModel } from '../db/Role';
import { refDailyTask, refDailyTaskBox } from './taskService'
import { REFRESH_HOUR } from "../consts";
/**
* 刷新
@@ -37,14 +36,14 @@ export async function refreshDaily(session: FrontendOrBackendSession) {
if(session.get('roleId')) {
let refDaily: number = session.get('refDaily'); // 10位时间戳,每天每人更新一次
let refWeekly: number = session.get('refWeekly'); // 10位时间戳,每天每人更新一次
if(!refDaily || shouldRefresh(new Date(refDaily * 1000), new Date(), REFRESH_HOUR)) {
if(!refDaily || shouldRefresh(new Date(refDaily * 1000), new Date())) {
refDaily = nowSeconds();
session.set('refDaily', refDaily);
session.push('refDaily', () => {});
await refDailyTask(session.get('roleId'), session.get('sid'));
}
if(!refWeekly || shouldRefreshWeek(new Date(refWeekly * 1000), new Date(), 1, REFRESH_HOUR)) {
if(!refWeekly || shouldRefreshWeek(new Date(refWeekly * 1000), new Date())) {
refWeekly = nowSeconds();
session.set('refWeekly', refWeekly);
session.push('refWeekly', () => {});
+5 -5
View File
@@ -2,7 +2,7 @@ import * as taskUtil from '../pubUtils/taskUtil';
import { RoleType } from '../db/Role';
import { pinus, FrontendOrBackendSession } from 'pinus';
import { resResult, shouldRefresh } from '../pubUtils/util';
import { STATUS, TASK_TYPE, TASK_FUN_TYPE } from '../consts';
import { STATUS, TASK_TYPE, TASK_FUN_TYPE, SHOP_REFRESH_TYPE } from '../consts';
import { TaskParam, TaskListReturn } from '../domain/roleField/task';
import { HeroType } from '../db/Hero';
import { EquipType } from '../db/Equip';
@@ -13,7 +13,7 @@ import { UserTaskModel, UserTaskType } from '../db/UserTask';
import { UserTaskRecModel } from '../db/UserTaskRec';
import { UserTaskHistoryModel } from '../db/UserTaskHistory';
import { gameData, getGoodById } from '../pubUtils/data';
import { getCurWeekDate, getSeconds } from '../pubUtils/timeUtil';
import { getSeconds, getZeroPointD } from '../pubUtils/timeUtil';
import { RoleStatus } from '../db/ComBattleTeam';
export async function checkTaskWithRoles(roleId: string, sid: string, funcs: number[], taskType: number, roles: RoleType[]) {
@@ -125,14 +125,14 @@ export async function getCurTask(roleId: string, session: FrontendOrBackendSessi
let userTask = await UserTaskModel.findByRole(roleId);
let { dailyTaskRefWeekly, dailyTaskRef } = userTask;
let curWeekStart = getCurWeekDate(1, 5);
let curWeekStart = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
if (dailyTaskRefWeekly < curWeekStart) { // 刷新周宝箱
dailyTaskRefWeekly = curWeekStart;
}
session.set('refWeekly', getSeconds(dailyTaskRefWeekly));
session.push('refWeekly', () => { });
if (shouldRefresh(dailyTaskRef, new Date(), 5)) {
if (shouldRefresh(dailyTaskRef, new Date())) {
dailyTaskRef = new Date();
userTask = await UserTaskModel.updateInfo(roleId, { dailyTaskRef });
await removeHistoryTask(roleId, TASK_FUN_TYPE.DAILY);
@@ -168,7 +168,7 @@ export async function getMainTask(roleId: string, userTask: UserTaskType) {
export async function getDailyTask(roleId: string, userTask: UserTaskType) {
let type = TASK_FUN_TYPE.DAILY;
let { dailyTaskPoint: point, dailyTaskRefWeekly, dailyTaskPointWeekly: weeklyPoint, dailyTaskBox: box } = userTask;
let curWeekStart = getCurWeekDate(1, 5);
let curWeekStart = getZeroPointD(SHOP_REFRESH_TYPE.WEEKLY);
if (dailyTaskRefWeekly < curWeekStart) { // 刷新
dailyTaskRefWeekly = curWeekStart;
weeklyPoint = 0;
+7 -7
View File
@@ -3,12 +3,12 @@ import { scheduleJob, Job } from 'node-schedule';
import { SystemConfigModel } from '../db/SystemConfig';
import PvpDefenseType,{ PvpDefenseModel } from '../db/PvpDefense';
import { PVP } from '../pubUtils/dicParam';
import { nowSeconds, getTodayZeroPoint, getAge } from '../pubUtils/timeUtil';
import { nowSeconds, getAge, getTimeFun } from '../pubUtils/timeUtil';
import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank, getTodayGuildActivity } from '../pubUtils/data';
import { deepCopy, resResult, getRandSingleEelm } from '../pubUtils/util';
import { getLvByScore } from './pvpService';
import { getAllOnlineRoles, getAllServers, initSingleRank, delGuildActivityRank } from './redisService';
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE } from '../consts';
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE, GUILD_ACTIVITY_STATUS, GUILD_ACTIVITY_TYPE, TASK_TYPE, TIME_OUTPUT_TYPE, REFRESH_TIME } from '../consts';
import { RoleModel } from '../db/Role';
import { MailModel, MailType } from '../db/Mail';
import { pinus } from 'pinus';
@@ -48,12 +48,12 @@ export async function init() {
console.log('create season seasonNum = '+ systemConfig?.seasonNum);
let warIds = getPvpGkWarIds();
let warId = warIds[0];
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS);
systemConfig = await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
} else {
seasonEndTime = systemConfig.seasonEndTime;
if (systemConfig.seasonEndTime - SETTLE_DIFF <= nowSeconds()) {//服务器启动时,检查当前时间是否大于实际结算的时间,若大于则重新开启定时任务,若小于则按照结束时间开启定时任务
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS);
console.log('update season seasonNum = '+ systemConfig.seasonNum);
systemConfig.seasonNum++;//赛季值增加1
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum: systemConfig.seasonNum, oldSeasonEndTime: systemConfig.seasonEndTime});
@@ -241,7 +241,7 @@ async function setNextPvpTime(notSetNext: boolean) {
return { seasonEndTime, seasonNum , oldSeasonEndTime: 0};
}
let oldSeasonEndTime = seasonEndTime;
seasonEndTime = (PVP.PVP_SEASON_DAYS + 1) * PER_DAY + getTodayZeroPoint();
seasonEndTime = <number>getTimeFun().getAfterDay(PVP.PVP_SEASON_DAYS + 1);
await SystemConfigModel.updateSeason(seasonEndTime, oldSeasonEndTime);
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);
@@ -273,10 +273,10 @@ export async function resetPvpSeasonTime(hour: number) {
if (!systemConfig) {
let warIds = getPvpGkWarIds();
let warId = warIds[0];
seasonEndTime = hour * 60 * 60 + getTodayZeroPoint();
seasonEndTime = <number>getTimeFun().getTimeWithHour(REFRESH_TIME - hour);
systemConfig = await SystemConfigModel.createSystemConfig( seasonEndTime, warId );
} else {
seasonEndTime = hour * 60 * 60 + getTodayZeroPoint();
seasonEndTime = <number>getTimeFun().getTimeWithHour(REFRESH_TIME - hour);
seasonNum = systemConfig.seasonNum + 1;
await SystemConfigModel.updateSystemConfig({ seasonEndTime, seasonNum, oldSeasonEndTime: 0});
await setPvpSeasonResult({name: 'simpleJobExample' + systemConfig.seasonNum, notSetNext: true });
+3 -2
View File
@@ -4,7 +4,7 @@
*/
import { BattleDropModel } from '../db/BattleDrop';
import { getRefTime, getRandEelmWithWeight, getRandSingleEelm } from '../pubUtils/util';
import { getRandEelmWithWeight, getRandSingleEelm } from '../pubUtils/util';
import { BATTLE_REWARD_TYPE, BLUEPRT_CONST } from '../consts';
import { addItems } from './rewardService';
import { BattleBlueprtDropModel } from '../db/BattleBlueprtDrop'
@@ -12,6 +12,7 @@ import { RoleModel } from '../db/Role';
import { gameData } from '../pubUtils/data';
import { DicWar } from '../pubUtils/dictionary/DicWar';
import { RewardInter } from '../pubUtils/interface';
import { getZeroPointD } from '../pubUtils/timeUtil';
export class WarReward {
private roleId: string;
@@ -117,7 +118,7 @@ export class WarReward {
}
private async handlerBlueprtReward(num: number) {
const refTime = getRefTime(new Date(), BLUEPRT_CONST.REFRESH_TIME);
const refTime = getZeroPointD();
const battleBlueprtDrop = await BattleBlueprtDropModel.findByTime(this.roleId, refTime);
if(battleBlueprtDrop) {
let { getNum = 0, curCostAp = 0, getSum = 0, costAp = 0 } = battleBlueprtDrop;
+4 -3
View File
@@ -1,6 +1,7 @@
import 'mocha';
import { expect } from 'chai';
import { getNextTime } from '../app/pubUtils/timeUtil';
import { getTimeFunD } from '../app/pubUtils/timeUtil';
import { TIME_OUTPUT_TYPE } from '../app/consts';
const millisecondsPerDay = 24 * 60 * 60 * 1000;
@@ -15,7 +16,7 @@ describe('测试时间工具方法', function () {
const baseDate = new Date();
const newHour = 9, newMin = 9, newSec = 9;
baseDate.setHours(newHour - 1, 0, 0);
const newDate = getNextTime(baseDate, newHour, newMin, newSec);
const newDate = <Date>getTimeFunD(baseDate).getAfterDayWithHour(0, newHour, newMin, newSec);
checkTime(newDate, newHour, newMin, newSec);
expect(newDate.getDate()).to.be.equal(baseDate.getDate());
});
@@ -24,7 +25,7 @@ describe('测试时间工具方法', function () {
const baseDate = new Date();
const newHour = 9, newMin = 9, newSec = 9;
baseDate.setHours(newHour + 1, 0, 0);
const newDate = getNextTime(baseDate, newHour, newMin, newSec);
const newDate = <Date>getTimeFunD(baseDate).getAfterDayWithHour(0, newHour, newMin, newSec);
checkTime(newDate, newHour, newMin, newSec);
expect(newDate.getDate()).to.be.equal(new Date(baseDate.getTime() + millisecondsPerDay).getDate());
});