Merge branch 'feature/login'

Conflicts:
	game-server/app/servers/role/handler/heroHandler.ts
	game-server/app/services/redisService.ts
	shared/consts/index.ts
	shared/resource/jsons/dic_zyz_gk_main.json
This commit is contained in:
luying
2021-03-08 11:04:09 +08:00
79 changed files with 3766 additions and 2442 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
import { HeroModel } from './../db/Hero';
import { HangUpRecordModel } from './../db/HangUpRecord';
import { ChannelService, pinus } from 'pinus';
import { pinus } from 'pinus';
import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY } from './../consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
+10 -12
View File
@@ -1,4 +1,4 @@
import { mergeSameGoods } from '../pubUtils/util';
import { mergeSameGoods, deepCopy } from '../pubUtils/util';
import { EquipModel } from "../db/Equip";
import { HeroModel, EPlace, HeroType } from "../db/Hero";
import { getHeroJob, getGoodById, gameData, getJewelById, getHeroEquipByClassId } from "../pubUtils/data";
@@ -77,7 +77,7 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
return res;
}
} else if (!!hero) {//从穿戴装备的武将上卸下装备
await takeOffEquipAndCalPlayerCe(roleId, sid, seqId, hero, id);//卸下装备并重算战力
await takeOffEquipAndCalPlayerCe(roleId, sid, hero, equip, id);//卸下装备并重算战力
}
}
/**
@@ -88,15 +88,12 @@ export async function changeEquip(roleId: string, sid: string, equip: EquipType,
* @param hero
* @param id
*/
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, seqId: number, hero:HeroType, id: number ) {
let index = findIndex(hero.ePlace, { id });
if (index < 0)
return;
await EquipModel.updateEquipInfo(seqId, { hid: 0 });
hero.ePlace[index].equip = null;
export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, hero:HeroType, equip: EquipType, id: number ) {
let args = calEquipSeids(hero);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
return { seqId, hid: 0};
hero = await HeroModel.removeEquip(roleId, hero.hid, id, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
return { seqId: equip.seqId, hid: 0};
}
/**
* 穿戴装备并重算战力
@@ -106,9 +103,10 @@ export async function takeOffEquipAndCalPlayerCe(roleId: string, sid: string, se
* @param equip
*/
export async function dressEquip(roleId: string, sid: string, hero:HeroType, equip: EquipType) {
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
let args = calEquipSeids(hero);
await calPlayerCeAndSave(sid, roleId, [hero], HERO_SYSTEM_TYPE.EQUIP, args);
hero = await HeroModel.addEquip(roleId, hero.hid, equip.ePlaceId, equip._id);
await calPlayerCeAndSave(HERO_SYSTEM_TYPE.EQUIP, sid, roleId, hero, {}, args);
return { seqId: equip.seqId, hid: hero.hid };
}
/**
+7 -25
View File
@@ -3,9 +3,9 @@ import { ExpeditionPointModel } from '../db/ExpeditionPoint';
import Role, { RoleModel, RoleType } from '../db/Role';
import { PvpDefenseModel } from '../db/PvpDefense';
import { getWarJsons, getGamedata, getExpeditionById } from '../pubUtils/gamedata';
import { decodeStr, resResult, shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST, HERO_CE_RATIO, getAttrCeRatio } from '../consts';
import { getWarJsons, getGamedata } from '../pubUtils/gamedata';
import { decodeStr, shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST, HERO_CE_RATIO } from '../consts';
import { getAtrrNameById} from '../consts';
import { ExpeditionWarRecordModel } from '../db/ExpeditionWarRecord';
import { HeroType } from '../db/Hero';
@@ -75,7 +75,7 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
let result = resultRange[index];
let {roleId, heroes, defCe } = result;
let role = <RoleType>result.role;
let { globalCeAttr } = role;
let { attr: roleAttrs } = role;
enemyObj.enemyFrom = 1;
enemyObj.enemyId = roleId;
@@ -87,9 +87,9 @@ export async function matchPlayers(roleId: string, scale: number, range: number,
let hero = heroes[heroIndex];
if(hero) {
let h = <HeroType>hero.hero;
let { star, lv, ceAttr } = h;
let { star, lv, attr: heroAttrs } = h;
let dicHero = gameData.hero.get(hero.actorId);
let newAttribute = getPlayerAttribute(ceAttr, globalCeAttr);
let newAttribute = getPlayerAttribute(heroAttrs, roleAttrs);
let heroInfo = {
actorId: hero.actorId,
actorName: dicHero.name,
@@ -127,10 +127,7 @@ export async function matchRobots(scale: number, myCe: number, robotCe: number,
const { attribute } = json;
let newAttribute = getRobotAttribute(attribute, myCe, robotCe, scale);
let ce = 0;
for(let attrName in newAttribute) {
ce += newAttribute[attrName] * getAttrCeRatio(attrName)||0;
}
let ce = newAttribute.calCelAndReduce();
enemyObj.enemies.push({...json, attribute: newAttribute, lv});
allCe += ce;
}
@@ -156,21 +153,6 @@ export async function getCEScaleAndRange(roleId: string, curDicExpedition: any)
return {scale, range, lv: role.lv}
}
// 远征表属性解码
export function decodeWarJsonAttribute(attribute: string) {
let arr = decodeStr('attribute', attribute);
// 初始化
let obj = {hp: 0, atk: 0, matk: 0, def: 0, mdef: 0, speed: 0, agi: 0, luk: 0, hit: 0, cri: 0, flee: 0, antCri: 0, damageIncrease: 0, damageDecrease: 0, defIngnore: 0, bloodSuck: 0}
for(let {id, value} of arr) {
let field = getAtrrNameById(id);
if(field) {
obj[field] = value;
}
}
return obj
}
// 远征累计点数获取
export async function getPointRewardStatus(roleId: string, role?: Role) {
if(!role) {
+13 -9
View File
@@ -7,22 +7,26 @@ import { STATUS } from '../consts/statusCode';
import { resResult, reduceCe } from '../pubUtils/util';
import { calPlayerCeAndSave as pubCalPlayerCeAndSave, reCalAllHeroCe } from '../pubUtils/playerCe';
import { HeroType } from '../db/Hero';
import Hero, { HeroType, HeroUpdate } from '../db/Hero';
import { defaultHeroes } from './pvpService';
import { RoleUpdate } from '../db/Role';
//修改并下发战力
export async function calPlayerCeAndSave(sid: string, roleId: string, heros: Array<HeroType>, type?: number, args?: Array<number>) {
let {role, pushHeros, topLineupCe} = await pubCalPlayerCeAndSave(roleId, heros, type, args);
export async function calPlayerCeAndSave(type: number, sid: string, roleId: string, originHero: HeroType, update: HeroUpdate, args?: Array<number>) {
let {role, pushHeros, topLineupCe, hero} = await pubCalPlayerCeAndSave(type, roleId, originHero, update, args);
console.log(JSON.stringify(pushHeros))
//下发战力
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(role.ce) , heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids);
defaultHeroes(role);
return heros;
return hero;
}
export async function calAllHeroCe(sid: string, roleId: string, type?:number, args?:Array<number>) {
let {ce, pushHeros, topLineupCe }= await reCalAllHeroCe(roleId, type, args);
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids);
return {ce: reduceCe(ce)};
export async function calAllHeroCe(type:number, sid: string, roleId: string, update: RoleUpdate, args?:Array<number>) {
let {role, ce, pushHeros, topLineupCe } = await reCalAllHeroCe(type, roleId, update, args);
if(pushHeros.length > 0) {
let uids = [{ uid: roleId, sid }];
pinus.app.get('channelService').pushMessageByUids('onPlayerCeUpdate', resResult(STATUS.SUCCESS, { ce: reduceCe(ce), heros: pushHeros, topLineupCe: reduceCe(topLineupCe) }), uids);
}
return role;
}
+15 -24
View File
@@ -5,7 +5,7 @@ import { PVP_HERO_POS, ROBOT_NAME, REDIS_KEY, PVP_CONST, HERO_CE_RATIO } from '.
import { setPvpDefResult } from '../services/timeTaskService';
import { dicPvpOpponent, DicPvpOpponent } from "../pubUtils/dictionary/DicPvpOpponent";
import { getRandomIndexByLen, genCode, getRandomByLen, shouldRefresh, reduceCe, getChineseName } from '../pubUtils/util';
import { oppPlayersInter, pvpEndParamInter, Attributes } from '../pubUtils/interface';
import { oppPlayersInter, pvpEndParamInter } from '../pubUtils/interface';
import { RankParam } from '../domain/rank';
import { gameData, getPLvByScore } from "../pubUtils/data";
import { PVP } from '../pubUtils/dicParam';
@@ -14,7 +14,7 @@ import { setRank, getMyRank, getFieldByRank } from './redisService';
import { nowSeconds, checkTodayTime } from '../pubUtils/timeUtil';
import { HeroesRecord } from '../db/PvpRecord';
import { HeroModel, HeroType } from '../db/Hero';
import { CeAttrNumber, CeAttr, CeAttrRole, MainAttrNumber } from '../domain/roleField/attribute';
import { MainAttrNumber, Attribute, CeAttrData, CeAttrDataRole } from '../domain/roleField/attribute';
import { PvpEnemies, PvpHeroInfo, PvpOtherHeroes } from '../domain/dbGeneral';
import { DicWarJson } from '../pubUtils/dictionary/DicWarJson';
import { findWhere, findIndex } from 'underscore';
@@ -213,7 +213,7 @@ async function generPlayerOppHis(pvpdefense: PvpDefenseType, mapWarJson: DicWarJ
let heroInfo = new PvpHeroInfo();
heroInfo.setHeroInfo(dbHero);
heroInfo.setOutIndex(h.order);
let attribute = getPlayerAttribute(dbHero.ceAttr, role.globalCeAttr);
let attribute = getPlayerAttribute(dbHero.attr, role.attr);
heroInfo.setAttribute(attribute);
let enemy = new PvpEnemies(warJson, heroInfo, hs?hs.score: 0);
heroes.push(enemy);
@@ -491,16 +491,13 @@ export async function findPvpDefAllByRoleId(roleId: string) {
* @param enemyCe 出兵表对手战力
* @param ratio 系数
*/
export function getRobotAttribute(attribute: Attributes, ce: number, enemyCe: number, ratio: number) {
export function getRobotAttribute(attribute: {id: number, val: number}[], ce: number, enemyCe: number, ratio: number) {
let newAttribute = new CeAttrNumber();
for(let attrName in newAttribute) {
newAttribute[attrName] = Math.floor(attribute[attrName] * ce / enemyCe * ratio);
}
newAttribute['speed'] = 0;
newAttribute['ap'] = 0;
let newAttribute = new Attribute();
newAttribute.setByWarJson(attribute, ce / enemyCe * ratio);
let attrJson = newAttribute.getReduceAttributes();
return newAttribute;
return attrJson;
}
/**
@@ -508,18 +505,12 @@ export function getRobotAttribute(attribute: Attributes, ce: number, enemyCe: nu
* @param ceAttr hero表的ceAttr
* @param globalCeAttr role表中的globalCeAttr
*/
export function getPlayerAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
let newAttribute = new CeAttrNumber();
for(let attrName in newAttribute) {
let { base, ratioUp, fixUp, equipUp } = ceAttr[attrName];
let { ratioUp: ratioUp2, fixUp: fixUp2 } = globalCeAttr[attrName];
let result = base * ( HERO_CE_RATIO + ratioUp + ratioUp2) + (fixUp + fixUp2 + equipUp) * HERO_CE_RATIO;
newAttribute[attrName] += reduceCe(result);
}
newAttribute['speed'] = 0;
newAttribute['ap'] = 0;
export function getPlayerAttribute(heroAttrs: CeAttrData[] = [], roleAttrs: CeAttrDataRole[] = []) {
let newAttribute = new Attribute();
newAttribute.setByDbData(roleAttrs, heroAttrs);
let attrJson = newAttribute.getReduceAttributes();
return newAttribute;
return attrJson;
}
/**
@@ -527,8 +518,8 @@ export function getPlayerAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
* @param ceAttr
* @param globalCeAttr
*/
export function getPlayerMainAttribute(ceAttr: CeAttr, globalCeAttr: CeAttrRole) {
let attribute = getPlayerAttribute(ceAttr, globalCeAttr);
export function getPlayerMainAttribute(heroAttrs: CeAttrData[], roleAttrs: CeAttrDataRole[]) {
let attribute = getPlayerAttribute(heroAttrs, roleAttrs);
let mainAttributes = new MainAttrNumber(attribute);
return mainAttributes;
+18 -4
View File
@@ -10,6 +10,7 @@ import { SystemConfigModel } from '../db/SystemConfig';
import { GuildRankParam, GuildLeader, RankParam } from '../domain/rank';
import { GuildModel } from '../db/Guild';
import { comBtlRanges } from '../pubUtils/gamedata';
import { stringify } from 'querystring';
/**
* 在服务重新启动时,将信息存入redis
*/
@@ -366,8 +367,8 @@ export async function clearChannelServers() {
* @param userCode user表唯一字符串标识
* @param sid connector服的那个sid
*/
export async function roleLogin(roleId: string, userCode: string, sid: string) {
let param = { userCode, sid };
export async function roleLogin(roleId: string, userCode: string, sid: string, pkgName: string) {
let param = { userCode, sid, pkgName };
return await redisClient().hsetAsync(REDIS_KEY.ONLINE_USERS, roleId, JSON.stringify(param));
}
@@ -400,7 +401,8 @@ export async function getRoleOnlineInfo(roleId: string) {
return {
isOnline: true,
userCode: result.userCode,
sid: result.sid
sid: result.sid,
pkgName: result.pkgName
}
} catch(e) {
return { isOnline: false }
@@ -414,8 +416,20 @@ export async function getRoleOnlineInfo(roleId: string) {
* 获得所有在线的玩家
*/
export async function getAllOnlineRoles() {
const client: Redis.RedisClient = pinus.app.get('redis');
let allRoles = await redisClient().hgetallAsync(REDIS_KEY.ONLINE_USERS);
return allRoles;
let result = new Array<{roleId: string, userCode: string, sid: string, pkgName: string}>();
for(let roleId in allRoles) {
try{
let param = JSON.parse(allRoles[roleId]);
if(param) {
result.push({ roleId, userCode: param.userCode, sid: param.sid, pkgName: param.pkgName });
}
} catch(e) {
continue;
}
}
return result;
}
export async function resetPvpRanks() {
@@ -9,7 +9,7 @@ interface UserCache {
var userCacheMap = new Map<string, UserCache>();
export function init() {
scheduleJob("0/5 * * * * *", clearDirtyData, {name:'clearDirtyData'});//每个5秒钟,释放redis锁
scheduleJob('clearDirtyData', "0/5 * * * * *", clearDirtyData);//每个5秒钟,释放redis锁
}
/**
* 释放锁
+1 -1
View File
@@ -156,7 +156,7 @@ export async function addItems(roleId: string, roleName: string, sid: string, go
}
}
if (!!skinInfos.length) {
calAllHeroCe(sid, roleId, HERO_SYSTEM_TYPE.ADD_SKIN, addSkinIds)
calAllHeroCe(HERO_SYSTEM_TYPE.ADD_SKIN, sid, roleId, {}, addSkinIds);
pinus.app.get('channelService').pushMessageByUids('onHeroSkinChange', resResult(STATUS.SUCCESS, {skinInfos}), uids);
}
return showItems;
+32 -26
View File
@@ -3,44 +3,47 @@ import { Channel } from 'pinus';
import { getRandNum, getRandomArr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts/consts";
import { indexOf } from 'underscore';
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph } from '../db/Role';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* 计算强化次数和消耗
* @param count 强化次数
* @param attrNames 可以强化的属性名字
* @param attrs 可以强化的属性名字
* @param teraphInfo 字典表对应的神像信息
* @param teraph
* @param teraph 数据库内单个神像信息
*/
export function checkTeraphMaterialEnough(count: number, attrNames:Array<any>, teraphInfo: any, teraph: any) {
let res = {};
export function checkTeraphMaterialEnough(count: number, attrs:number[], teraphInfo: DicTeraph, teraph: Teraph) {
let consumes = [];
let times = 0;
if (count < 10) {
for (let i = 0; i < count; i++) {
if (!attrNames.length) {
if (!attrs.length) {
break;
}
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX);
let arr = getRandomArr(attrNames, num)
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX); // 强化时随机增加 2-4 属性
let arr: number[] = getRandomArr(attrs, num); // 随机出的属性id
let critical = getRandNum(0, 100);//属性暴击率
let criEffect = 1;
let criEffect = 1; // 暴击效果
if (critical <= teraphInfo.criRate)
criEffect = teraphInfo.criEffect;
for (let attrName of arr) {
let attrNameMax = attrName+'Max';
res[attrName] = teraphInfo[attrName] * criEffect;
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = indexOf(attrNames, attrName);
attrNames.splice(attrIndex, 1);
for (let attrId of arr) {
let val = teraph.attr.get(attrId); // 已有的强化值
val += teraphInfo.mainAttrUp.get(attrId) * criEffect;
let max = teraphInfo.mainAttrMax.get(attrId);
if(val > max) {
val = max;
let attrIndex = attrs.indexOf(attrId);
attrs.splice(attrIndex, 1);
}
teraph.attr.set(attrId, val);
}
times++;
}
} else if (count == 10){
let criticalArrTimes = getRandomArr(TERAPH_STRENGTHEN, 2);//10次中随机2次发生暴击
for (let item of TERAPH_STRENGTHEN) {
if (!attrNames.length) {
if (!attrs.length) {
break;
}
let criEffect = 1;
@@ -49,24 +52,27 @@ export function checkTeraphMaterialEnough(count: number, attrNames:Array<any>, t
criEffect = teraphInfo.criEffect;//本次是暴击 item 在 criticalArrTimes 中
}
let num = getRandNum(TERAPH_RANDOM.MIN, TERAPH_RANDOM.MAX);
let arr = getRandomArr(attrNames, num);
for (let attrName of arr) {
res[attrName] = (res[attrName]||0) + teraphInfo[attrName] * criEffect;
let attrNameMax = attrName+'Max';
if (teraph[attrName] + res[attrName] > teraphInfo[attrNameMax]) {
res[attrName] = teraphInfo[attrNameMax] - teraph[attrName];
let attrIndex = indexOf(attrNames, attrName);
attrNames.splice(attrIndex, 1);
let arr: number[] = getRandomArr(attrs, num);
for (let attrId of arr) {
let val = teraph.attr.get(attrId); // 已有的强化值
val += teraphInfo.mainAttrUp.get(attrId) * criEffect;
let max = teraphInfo.mainAttrMax.get(attrId);
if(val > max) {
val = max;
let attrIndex = attrs.indexOf(attrId);
attrs.splice(attrIndex, 1);
}
teraph.attr.set(attrId, val);
}
times++;
}
}
//计算消耗
for (let {id, count} of teraphInfo.upMaterial) {
consumes.push({ id, count: count*times});
consumes.push({ id, count: count * times});
}
return {attr: res, consumes};
return { consumes};
}
/**
*
+65 -12
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 } from '../pubUtils/timeUtil';
import { nowSeconds, getTodayZeroPoint, getAge } from '../pubUtils/timeUtil';
import { getPvpGkWarIds, getPvpRankRewards, getPvpHeroRewards, getResultMaxRank } from '../pubUtils/data';
import { deepCopy, getRandomArr, resResult } from '../pubUtils/util';
import { deepCopy, getRandomArr, resResult, shouldRefresh } from '../pubUtils/util';
import { getLvByScore } from './pvpService';
import { getMyRank, setRank, resetPvpRanks } from './redisService';
import { MAIL_TYPE, REDIS_KEY } from '../consts';
import { getMyRank, setRank, resetPvpRanks, getAllOnlineRoles } from './redisService';
import { MAIL_TYPE, REDIS_KEY, ADULT_AGE, GUEST_MAX_TIME, ADDICTION_PREVENTION_CODE } from '../consts';
import { RankParam } from '../domain/rank';
import { RoleModel } from '../db/Role';
import { MailModel, MailType } from '../db/Mail';
@@ -18,6 +18,8 @@ import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
import { settleGuildWeekly } from './guildService';
import { STATUS } from '../consts/statusCode';
import { getMailContent, sendMail } from './mailService';
import { reportOnline } from '../pubUtils/httpUtil';
import User, { UserModel } from '../db/User';
const PER_SECOND = 1 * 1000;
const PER_DAY = 24 * 60 * 60;
const SETTLE_DIFF = 29 * 60;
@@ -34,7 +36,7 @@ export async function init() {
let seasonEndTime = 0;
let systemConfig = await SystemConfigModel.findSystemConfig();//系统全局参数表
if (!systemConfig) {
console.log('create season seasonNum = '+ systemConfig.seasonNum);
console.log('create season seasonNum = '+ systemConfig?.seasonNum);
let warIds = getPvpGkWarIds();
let warId = warIds[0];
seasonEndTime = PVP.PVP_SEASON_DAYS * PER_DAY + getTodayZeroPoint();
@@ -50,21 +52,27 @@ export async function init() {
}
}
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult, { name: 'setPvpSeasonResult' });//设置实际赛季结算时间
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);//设置实际赛季结算时间
seasonEndTimeJobId = scheduleJob(seasonEndTime* PER_SECOND, resetPvpRanks, { name: 'resetRank' });//由于24之后,才展示结算之后的信息,为保排行榜信息一致性,设置实际重置排行榜的时间为12点
seasonEndTimeJobId = scheduleJob('resetRank', seasonEndTime * PER_SECOND, resetPvpRanks);//由于24之后,才展示结算之后的信息,为保排行榜信息一致性,设置实际重置排行榜的时间为12点
warJobId = scheduleJob("0 0 0 * * 1", resetPvpWarId);//每周1零点重置地图
await resetPvpRanks();//服务器重启,重置排行榜的信息
// 周功勋结算任务
guildWeeklyJobId = scheduleJob('0 0 0 * * 1', settleGuildWeekly, { name: 'settleGuildWeekly' });
guildWeeklyJobId = scheduleJob('settleGuildWeekly', '0 0 0 * * 1', settleGuildWeekly);
scheduleJob('reportOnline', '0 0/5 * * * *', reportOnlineSchedule)
}
function setPvpSeasonSchdule() {
setPvpSeasonResult();
}
/**
* pvp定时任务赛季结算
* @param obj
*/
export async function setPvpSeasonResult(obj:{ name:string, notSetNext?: boolean, notPush?: boolean }) {
export async function setPvpSeasonResult(obj?:{ name:string, notSetNext?: boolean, notPush?: boolean }) {
console.log('exce setPvpSeasonResult'+ obj?.name);
let { seasonNum, seasonEndTime, oldSeasonEndTime } = await setNextPvpTime(obj?.notSetNext);//设置下个结算任务
let resultMaxRank = getResultMaxRank();//根据排行榜的奖励表,获得最大排名挡位的最小值,其余不在结算中结算的玩家按照最大排名挡位在登录或进入pvp时结算
@@ -214,8 +222,8 @@ async function setNextPvpTime(notSetNext: boolean) {
seasonEndTime = (PVP.PVP_SEASON_DAYS + 1) * PER_DAY + getTodayZeroPoint();
await SystemConfigModel.updateSeason(seasonEndTime, oldSeasonEndTime);
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult, { name: 'setPvpSeasonResult' });
seasonEndTimeJobId = scheduleJob(seasonEndTime* PER_SECOND, resetPvpRanks, { name: 'resetRank' });
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);
seasonEndTimeJobId = scheduleJob('resetRank', seasonEndTime* PER_SECOND, resetPvpRanks);
return { seasonEndTime, seasonNum: seasonNum + 1, oldSeasonEndTime };
}
@@ -254,6 +262,51 @@ export async function resetPvpSeasonTime(hour: number) {
}
let settleTime = (seasonEndTime - SETTLE_DIFF)* PER_SECOND;
console.log('settleTime = ' + settleTime)
seasonJobId = scheduleJob(settleTime, setPvpSeasonResult, { name: 'setPvpSeasonResult' });
seasonJobId = scheduleJob('setPvpSeasonResult', settleTime, setPvpSeasonSchdule);
return { seasonEndTime, seasonNum };
}
export async function reportOnlineSchedule() {
let allRoles = await getAllOnlineRoles();
console.log('reportOnlineSchedule all roles count: ', allRoles.length)
for(let { roleId, userCode, sid, pkgName } of allRoles) {
let result = await reportOnline(userCode, pkgName); // 连接sdk
if(!result || result.code == -1) continue;
let user = await UserModel.findUserByUserCode(userCode);
if(!user) continue;
let { reportTime = new Date(), lastLoginTime = new Date(), guestTime, isGuest, hasAuthenticated, birthday } = user;
let age = getAge(birthday);
let isAdult = age >= ADULT_AGE;
if(result.code != ADDICTION_PREVENTION_CODE.SUCCESS) { // 未成年人防沉迷
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
isGuest,
guestTime, // 游客已体验时间
hasAuthenticated, // 是否进行过实名认证
isAdult, // 是否已成年
todayPlayTime: result.total, // 今天已游戏时长
type: result.code
} ), [{uid: roleId, sid: sid}]);
} else {
let lastTime = lastLoginTime > reportTime? lastLoginTime.getTime(): reportTime.getTime();
let guestTimeInc = Math.floor((Date.now() - lastTime)/1000);
user = await UserModel.updatePlayTime(userCode, guestTimeInc, result.total); // 记录时间
guestTime = user.guestTime;
if (isGuest && guestTime > GUEST_MAX_TIME) {
pinus.app.channelService.pushMessageByUids('onPlayTime', resResult(STATUS.SUCCESS, {
isGuest,
guestTime, // 游客已体验时间
hasAuthenticated, // 是否进行过实名认证
isAdult, // 是否已成年
todayPlayTime: result.total, // 今天已游戏时长
type: ADDICTION_PREVENTION_CODE.GUEST,
} ), [{uid: roleId, sid: sid}]);
}
}
}
}