红点:修改推送方式

This commit is contained in:
luying
2021-05-31 13:29:58 +08:00
parent 44d9e80640
commit a8eebc200c
38 changed files with 805 additions and 605 deletions

View File

@@ -1,6 +1,6 @@
import { MailModel, MailType } from './../db/Mail';
import { DividendModel } from './../db/Dividend';
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS, MAIL_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, STATUS, DIVIDENDWEEKENDRATE, DIVIDENDMAXRATIO, DIVIDENDPOSITIONMAXRATIO, ROLE_RECEIVE_STATUS, AUCTION_BID_STATUS } from './../consts';
import { LOT_CODE_LEN, AUCTION_STAGE, AUCTION_TIME, DIVIDEND_CODE_LEN, DIVIDEND_STATUS, LOT_STATUS, MAIL_TYPE, CURRENCY_BY_TYPE, CURRENCY_TYPE, STATUS, DIVIDENDWEEKENDRATE, DIVIDENDMAXRATIO, DIVIDENDPOSITIONMAXRATIO, ROLE_RECEIVE_STATUS, AUCTION_BID_STATUS, DEBUG_MAGIC_WORD } from './../consts';
import { DividendRec, ItemReward } from "../domain/dbGeneral";
import { genCode, resResult } from '../pubUtils/util';
import { LotModel, LotParam } from '../db/Lot';
@@ -9,7 +9,7 @@ import { gameData, getGoodById } from '../pubUtils/data';
import { DividendParam, DividendType } from '../db/Dividend';
import { pushMail } from '../pubUtils/interface';
import { getMailContent } from './mailService';
import { pinus, BackendSession } from 'pinus';
import { pinus, BackendSession, FrontendOrBackendSession } from 'pinus';
import { participants } from './guildActivityService';
import { Member } from '../domain/battleField/guildActivity';
@@ -33,13 +33,13 @@ export function auctionStage() {
if (curTime > todayWorldEnd().getTime()) return AUCTION_STAGE.END;
}
export async function debugAuctionLots(session: BackendSession, begin: Date) {
export async function debugAuctionLots(session: FrontendOrBackendSession, begin: Date) {
const serverId = session.get('serverId');
const lots = await LotModel.findWorldLotsByBegin(serverId, begin);
return lots;
}
export async function officialAuctionLots(session: BackendSession, begin: Date) {
export async function officialAuctionLots(session: FrontendOrBackendSession, begin: Date) {
const serverId = session.get('serverId');
const guildCode = session.get('guildCode');
const stage = auctionStage();
@@ -278,3 +278,17 @@ export async function sendUngotDividend(debug = false) {
return false;
}
}
/**
* 获取拍卖行数据
* @param guildCode
* @param session
* @param magicWord
*/
export async function getAuction(guildCode: string, session: FrontendOrBackendSession, magicWord?: string) {
const begin = todayGuildBegin();
let lots = magicWord === DEBUG_MAGIC_WORD ? await debugAuctionLots(session, begin) : await officialAuctionLots(session, begin);
const dividends = await DividendModel.findGuildDividendsByBegin(guildCode, begin);
return { lots, dividends };
}

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, TIME_OUTPUT_TYPE } from './../consts';
import { HANG_UP_CONSTS, TOWER_TASK_CONST, REDIS_KEY, TASK_TYPE, TIME_OUTPUT_TYPE, GOLD_COST_RATIO } from './../consts';
import { BattleRecordModel } from './../db/BattleRecord';
import { TowerRecordModel } from './../db/TowerRecord';
import { RoleModel } from './../db/Role';
import { shouldRefresh, resResult, cal, getRandEelmWithWeight } from '../pubUtils/util';
import { RoleModel, RoleType } from './../db/Role';
import { shouldRefresh, resResult, cal, getRandEelmWithWeight, calculateNum, genCode } from '../pubUtils/util';
import { STATUS } from '../consts/statusCode';
import { HangUpSpdUpRecModel } from '../db/HangUpSpdUpRec';
import { TowerTaskRecModel } from '../db/TowerTaskRec';
@@ -16,6 +16,96 @@ import { getRandExpedition, gameData } from '../pubUtils/data';
import { ItemInter, RewardInter } from '../pubUtils/interface';
import { getTimeFunM } from '../pubUtils/timeUtil';
/**
* 获取当前镇念塔状态
* @param role
*/
export async function getTowerStatus(role: RoleType) {
let { towerLv, roleId, serverId } = role;
if (!towerLv) {
towerLv = 1;
let role = await RoleModel.towerLvUp(roleId);
// 更新redis
let r = new Rank(REDIS_KEY.TOWER_RANK, { serverId });
await r.setRankWithRoleInfo(roleId, towerLv, role.towerUpTime.getTime(), role);
}
let towerRec = await TowerRecordModel.getRecordByLv(roleId, towerLv);
if (!towerRec) {
const towerInfo = gameData.tower.get(towerLv);
const { warArray } = towerInfo;
const sts = warArray.map(id => {
return {warId: id, status: false};
});
towerRec = await TowerRecordModel.createRecord({roleId, lv: towerLv, warStatus: sts});
// return { code: 201, data: '天梯记录异常' };
}
return {
canHungUp: towerLv >= HANG_UP_CONSTS.ENABLE_LV,
hungUpEnableLv: HANG_UP_CONSTS.ENABLE_LV,
canSendTask: true,
curLv: towerLv,
usedHeroes: towerRec.heroes,
progress: towerRec.warStatus
};
}
/**
* 获取镇念塔挂机收益
* @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, lastSpdUpTime} = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
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;
let nextCostGold = calculateNum(GOLD_COST_RATIO.TOWER_HANG_SPDUP, {num}, 50);
return {
status: 0,
resResult: null,
data: {
startTime, hangUpPassTime: Math.floor(deltaTime/1000), hangUpSpdUpCnt, nextCostGold, rewards: timeReward
}
}
}
/**
* 获取派遣任务列表
* @param role
*/
export async function getTasks(role: RoleType) {
let { roleId, roleName, towerLv, towerTaskRefTime, towerTaskReCnt = 0 } = role;
let curTime = new Date();
let curTasks = await TowerTaskRecModel.getCurTasks(roleId); // 当前显示中的任务
const needRefresh = shouldRefresh(towerTaskRefTime, curTime);
if(needRefresh) {
const batchCode = genCode(8);
let {waitingTaskCode, doingTaskCode, doingIds} = getDoingOrWaitingTasks(curTasks, curTime);
await TowerTaskRecModel.hideTask(roleId, waitingTaskCode); // 隐藏没有在做的任务
await TowerTaskRecModel.updateBatchCode(roleId, doingTaskCode, batchCode); // 更新留下来的旧任务的batchCode
await createCurTasks(towerLv, batchCode, roleId, roleName, doingTaskCode.length, TOWER_TASK_CONST.RAND_CNT-doingTaskCode.length, doingIds); // 新建任务
curTasks = await TowerTaskRecModel.getCurTasks(roleId);
// 重置派遣次数
const role = await RoleModel.resetTowerCnt(roleId, curTime);
towerTaskReCnt = role.towerTaskReCnt;
}
let refRemainTime = getRemainTime(curTime);
let nextCostGold = calculateNum(GOLD_COST_RATIO.TOWER_TASK_REF, {num: towerTaskReCnt + 1}, 50);
return {curTasks: treatTask(curTasks, curTime), refRemainTime, nextCostGold}
}
export async function checkTowerWar(roleId: string, battleId: number, heroes: Array<number>) {
let { towerLv } = await RoleModel.findByRoleId(roleId);
const towerInfo = gameData.tower.get(towerLv);

View File

@@ -223,6 +223,7 @@ export async function recentSysMsgs(serverId: number, count?: number) {
* @returns
*/
export async function recentGuildMsgs(guildCode: string, count?: number) {
if(!guildCode) return [];
const result = await recentGroupMsgs(groupRoomId(CHANNEL_PREFIX.GUILD, guildCode), count);
return result;
}

View File

@@ -170,6 +170,15 @@ export async function getRealReward(blueprtId: number, roleSt: RoleStatus) {
return fixReward;
}
export async function getAllAssistCnt(roleId: string) {
let cntMap = await getAssistTimesByQuality(roleId);
let cnt = [];
for (let i = 0; i < COM_BTL_QUALITY.length; ++i) {
cnt[i] = cntMap.get(i + 1) || 0;
}
return cnt;
}
export async function getAssistTimesByQuality(roleId: string, qualityArr?: number[]) {
let teams = await ComBattleTeamModel.getAssistTeamsByTime(roleId, qualityArr, getZeroPointD(), true);
let cntMap = new Map<number, number>();

View File

@@ -9,26 +9,26 @@ import { RoleType } from '../db/Role';
import { FrontendOrBackendSession, pinus } from 'pinus';
import { resResult } from '../pubUtils/util';
import { STATUS, USER_GUILD_SELECT, GUILD_SELECT } from '../consts';
// import { getAllShopList } from './shopService';
// import { getGeneralRank } from './rankService';
import { getAllShopList } from './shopService';
import { getGeneralRank } from './rankService';
import { getFriendList, getApplyList } from './friendService';
// import { getDailyBattleList } from './dailyBattleService';
// import { getExpeditionStatus } from './expeditionService';
// import { getTowerStatus, getHungupRewards, getTasks } from './battleService';
// import { getAllAssistCnt } from './comBattleService';
// import { getDungeonData } from './dungeonService';
// import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
import { getDailyBattleList } from './dailyBattleService';
import { getExpeditionStatus } from './expeditionService';
import { getTowerStatus, getHungupRewards, getTasks } from './battleService';
import { getAllAssistCnt } from './comBattleService';
import { getDungeonData } from './dungeonService';
import { PvpSeasonResultModel } from '../db/PvpSeasonResult';
import { nowSeconds } from '../pubUtils/timeUtil';
// import { getGachaList } from './gachaService';
// import { getSchoolList } from './roleService';
// import { addRoleToGuildChannel } from './chatChannelService';
// import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool } from './guildService';
// import { getAuction } from './auctionService';
// import { getGuildTrainInstance } from './guildTrainService';
// import { BossInstanceModel } from '../db/BossInstance';
// import { getBossInstanceInfo } from './guildBossService';
// import { getEvent } from './eventSercive';
// import { getBattleListOfMain } from './normalBattleService';
import { getGachaList } from './gachaService';
import { getSchoolList } from './roleService';
import { addRoleToGuildChannel } from './chatChannelService';
import { getMyGuildInfo, getGuildWithRefActive, getUserGuildWithRefActive, getWishPool } from './guildService';
import { getAuction } from './auctionService';
import { getGuildTrainInstance } from './guildTrainService';
import { BossInstanceModel } from '../db/BossInstance';
import { getBossInstanceInfo } from './guildBossService';
import { getEvent } from './eventSercive';
import { getBattleListOfMain } from './normalBattleService';
export async function pushData(role: RoleType, session: FrontendOrBackendSession) {
try{
@@ -37,78 +37,78 @@ export async function pushData(role: RoleType, session: FrontendOrBackendSession
pushEntryStart(roleId, sid);
// // 商店
// const shop = await getAllShopList(roleId);
// pushEntryData('shop', roleId, sid, shop);
// // 排行榜
// const rank = await getGeneralRank(role, serverId);
// pushEntryData('rank', roleId, sid, rank);
// // 邮件
// const mails = await getMails(roleId, serverId);
// pushEntryData('mail', roleId, sid, mails);
// 商店
const shop = await getAllShopList(roleId);
pushEntryData('shop', roleId, sid, shop);
// 排行榜
const rank = await getGeneralRank(role, serverId);
pushEntryData('rank', roleId, sid, rank);
// 邮件
const mails = await getMails(roleId, serverId);
pushEntryData('mail', roleId, sid, mails);
// 好友
const friendList = await getFriendList(role);
const applyList = await getApplyList(roleId);
pushEntryData('friend', roleId, sid, { friendList, applyList });
// // 每日关卡
// const daily = await getDailyBattleList(role);
// pushEntryData('daily', roleId, sid, daily);
// // 远征
// const expedition = await getExpeditionStatus(roleId, roleName);
// pushEntryData('expedition', roleId, sid, expedition);
// // 镇念塔
// const tower = await getTowerEntryData(role);
// pushEntryData('tower', roleId, sid, tower);
// // 寻宝
// const assistCnt = await getAllAssistCnt(roleId);
// pushEntryData('comBattle', roleId, sid, { assistCnt })
// // 秘境
// const dungeon = await getDungeonData(role);
// pushEntryData('dungeon', roleId, sid, dungeon);
// // PVP
// const hasSeasonReward = await getPvpEntryData(roleId);
// pushEntryData('pvp', roleId, sid, { hasSeasonReward });
// // 招募
// const gacha = await getGachaList(roleId);
// pushEntryData('gacha', roleId, sid, gacha);
// // 百家学宫
// const school = await getSchoolList(roleId);
// pushEntryData('school', roleId, sid, school);
// // 军团
// const { hasGuild, guild, userGuild, guildResult } = await getGuildEntryData(role, sid, session);
// if(hasGuild) {
// pushEntryData('guild', roleId, sid, guildResult);
// // 拍卖
// const auction = await getAuction(guildCode, session);
// pushEntryData('auction', roleId, sid, auction);
// // 练兵场
// const train = await getGuildTrainInstance(roleId, guild, userGuild);
// pushEntryData('train', roleId, sid, train);
// // 演武台boss
// const bossInstance = await BossInstanceModel.findBossInstance(guild.code);
// if(bossInstance) {
// const boss = await getBossInstanceInfo(bossInstance, roleId);
// pushEntryData('boss', roleId, sid, boss);
// }
// // 许愿池
// const wishPool = await getWishPool(userGuild);
// pushEntryData('wishPool', roleId, sid, wishPool);
// }
// // 任务
// const { mainTask, dailyTask, achievement } = await getCurTask(role.roleId, session);
// pushEntryData('task', roleId, sid, { mainTask, dailyTask, achievement });
// // 聊天
// const worldMsgs = await recentWorldMsgs(serverId);
// const sysMsgs = await recentSysMsgs(serverId);
// const guildMsgs = await recentGuildMsgs(guildCode);
// const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName);
// pushEntryData('chat', roleId, sid, { worldMsgs, sysMsgs, guildMsgs, recentPrivateChats });
// // 奇遇
// const event = await getEvent(role.eventStatus, roleId, roleName);
// pushEntryData('event', roleId, sid, event);
// // 主线关卡列表
// const battle = await getBattleListOfMain(role);
// pushEntryData('battle', roleId, sid, battle);
// 每日关卡
const daily = await getDailyBattleList(role);
pushEntryData('daily', roleId, sid, daily);
// 远征
const expedition = await getExpeditionStatus(roleId, roleName);
pushEntryData('expedition', roleId, sid, expedition);
// 镇念塔
const tower = await getTowerEntryData(role);
pushEntryData('tower', roleId, sid, tower);
// 寻宝
const assistCnt = await getAllAssistCnt(roleId);
pushEntryData('comBattle', roleId, sid, { assistCnt })
// 秘境
const dungeon = await getDungeonData(role);
pushEntryData('dungeon', roleId, sid, dungeon);
// PVP
const hasSeasonReward = await getPvpEntryData(roleId);
pushEntryData('pvp', roleId, sid, { hasSeasonReward });
// 招募
const gacha = await getGachaList(roleId);
pushEntryData('gacha', roleId, sid, gacha);
// 百家学宫
const school = await getSchoolList(roleId);
pushEntryData('school', roleId, sid, school);
// 军团
const { hasGuild, guild, userGuild, guildResult } = await getGuildEntryData(role, sid, session);
if(hasGuild) {
pushEntryData('guild', roleId, sid, guildResult);
// 拍卖
const auction = await getAuction(guildCode, session);
pushEntryData('auction', roleId, sid, auction);
// 练兵场
const train = await getGuildTrainInstance(roleId, guild, userGuild);
pushEntryData('train', roleId, sid, train);
// 演武台boss
const bossInstance = await BossInstanceModel.findBossInstance(guild.code);
if(bossInstance) {
const boss = await getBossInstanceInfo(bossInstance, roleId);
pushEntryData('boss', roleId, sid, boss);
}
// 许愿池
const wishPool = await getWishPool(userGuild);
pushEntryData('wishPool', roleId, sid, wishPool);
}
// 任务
const { mainTask, dailyTask, achievement } = await getCurTask(role.roleId, session);
pushEntryData('task', roleId, sid, { mainTask, dailyTask, achievement });
// 聊天
const worldMsgs = await recentWorldMsgs(serverId);
const sysMsgs = await recentSysMsgs(serverId);
const guildMsgs = await recentGuildMsgs(guildCode);
const recentPrivateChats = await recentPrivateChatInfos(roleId, roleName);
pushEntryData('chat', roleId, sid, { worldMsgs, sysMsgs, guildMsgs, recentPrivateChats });
// 奇遇
const event = await getEvent(role.eventStatus, roleId, roleName);
pushEntryData('event', roleId, sid, event);
// 主线关卡列表
const battle = await getBattleListOfMain(role);
pushEntryData('battle', roleId, sid, battle);
pushEntryEnd(roleId, sid);
}catch(e) {
@@ -133,54 +133,55 @@ function pushEntryEnd(roleId: string, sid: string) {
pinus.app.channelService.pushMessageByUids('onEntryDataEnd', resResult(STATUS.SUCCESS), uids);//通知在线玩家练兵场重置,
}
// /**
// * 镇念塔初始数据
// * @param role
// */
// async function getTowerEntryData(role: RoleType) {
// const { roleId } = role;
// const status = await getTowerStatus(role);
// const hungUp = await getHungupRewards(roleId);
// const tasks = await getTasks(role);
// if(hungUp.status == -1) {
// return { status, hungUp: {}, tasks }
// } else {
// return { status, hungUp: hungUp.data, tasks }
// }
// }
// /**
// * 获取是否存在pvp赛季奖励
// * @param roleId
// */
// async function getPvpEntryData(roleId: string) {
// let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
// if(!pvpSeasonResult) return false;
/**
* 镇念塔初始数据
* @param role
*/
async function getTowerEntryData(role: RoleType) {
const { roleId } = role;
const status = await getTowerStatus(role);
const hungUp = await getHungupRewards(roleId);
const tasks = await getTasks(role);
if(hungUp.status == -1) {
return { status, hungUp: {}, tasks }
} else {
return { status, hungUp: hungUp.data, tasks }
}
}
// let { oldSeasonData, show} = pvpSeasonResult;
// // 旧赛季结算的时候会在pvpSeasonResult表中存上一赛季的时间并更新show字段
// return oldSeasonData.seasonEndTime <= nowSeconds() && show;
// }
/**
* 获取是否存在pvp赛季奖励
* @param roleId
*/
async function getPvpEntryData(roleId: string) {
let pvpSeasonResult = await PvpSeasonResultModel.getPvpSeasonResult(roleId);
if(!pvpSeasonResult) return false;
// /**
// * 获取军团信息,并加入军团频道
// * @param role
// * @param sid
// * @param session
// */
// async function getGuildEntryData(role: RoleType, sid: string, session: FrontendOrBackendSession) {
let { oldSeasonData, show} = pvpSeasonResult;
// 旧赛季结算的时候会在pvpSeasonResult表中存上一赛季的时间并更新show字段
return oldSeasonData.seasonEndTime <= nowSeconds() && show;
}
// if (role.hasGuild) {
// let userGuild = await getUserGuildWithRefActive(role.roleId, 'job auth guildCode receivedActive activeRecord activeDaily activeWeekly wishDntCnt wishGoods');
// if (userGuild) {
// let guild = await getGuildWithRefActive(userGuild.guildCode, role.serverId);
// if (guild) {
// addRoleToGuildChannel(role.roleId, sid, userGuild.guildCode);
/**
* 获取军团信息,并加入军团频道
* @param role
* @param sid
* @param session
*/
async function getGuildEntryData(role: RoleType, sid: string, session: FrontendOrBackendSession) {
if (role.hasGuild) {
let userGuild = await getUserGuildWithRefActive(role.roleId, 'job auth guildCode receivedActive activeRecord activeDaily activeWeekly wishDntCnt wishGoods');
if (userGuild) {
let guild = await getGuildWithRefActive(userGuild.guildCode, role.serverId);
if (guild) {
addRoleToGuildChannel(role.roleId, sid, userGuild.guildCode);
// let result = await getMyGuildInfo(role.roleId, sid, userGuild, guild, role.serverId, session);
// return { hasGuild: true, guild, userGuild, guildResult: result};
// }
// }
// }
// return { hasGuild: false }
// }
let result = await getMyGuildInfo(role.roleId, sid, userGuild, guild, role.serverId, session);
return { hasGuild: true, guild, userGuild, guildResult: result};
}
}
}
return { hasGuild: false }
}

View File

@@ -5,9 +5,53 @@
import DailyRecord, { DailyRecordModel } from '../db/DailyRecord';
import { resResult } from '../pubUtils/util';
import { STATUS } from '../consts/statusCode';
import { RoleModel } from '../db/Role';
import { RoleModel, RoleType } from '../db/Role';
import { gameData } from '../pubUtils/data';
/**
* 获取全部每日关卡列表
* @param role
*/
export async function getDailyBattleList(role: RoleType) {
let { roleId, warStar } = role;
let dicDaily = gameData.daily;
let result = new Array();
for(let {dailyType: type, name, timesPerDay, timesCanBuy } of dicDaily) {
let refreshResult = await DailyRecordModel.refreshRecord(roleId, type);
let wars: {battleId: number, cost: number, star: number, status: number, name: string}[] = new Array();
let dicDailyWar = gameData.dailyWarByType.get(type);
for(let {war_id, cost, gk_name, previousGk } of dicDailyWar) {
let status = 0, star = 0;
let curBattle = warStar.find(cur => cur.id == war_id);
if(curBattle) {
status = 2;
star = curBattle.star;
} else {
if (previousGk) {
let preBattleRecord = warStar.find(cur => cur.id == previousGk);
if(preBattleRecord) {
status = 1;
} else {
status = 0;
}
} else {
status = 1;
}
}
wars.push({
battleId: war_id, cost, star, status, name: gk_name
});
}
let checkDailyResult = await getDailyNum(refreshResult, timesPerDay, timesCanBuy);
result.push({
type, name, ...checkDailyResult,
wars
});
}
return result;
}
// 检查每日本次数checkBattle使用
export async function checkDaily(roleId: string, battleId: number, inc: number) {
let dailyWar = gameData.war.get(battleId);

View File

@@ -2,10 +2,30 @@
* 每日本相关
*/
import { resResult, shouldRefresh } from '../pubUtils/util';
import { resResult, shouldRefresh, calculateNum } from '../pubUtils/util';
import { STATUS } from '../consts/statusCode';
import { RoleModel } from '../db/Role';
import { DUNGEON_CONST } from '../consts';
import { RoleModel, RoleType } from '../db/Role';
import { DUNGEON_CONST, GOLD_COST_RATIO } from '../consts';
/**
* 获取秘境本数据
* @param role
*/
export async function getDungeonData(role: RoleType) {
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime, dungeonHeroes=[] } = role;
let curTime = new Date();
if(shouldRefresh(dungeonRefTime, curTime)) {
dungeonCnt = 0; dungeonBuyCnt = 0;
}
let nextCostGold = calculateNum(GOLD_COST_RATIO.DUNGRON_BUY_NUM, {num: dungeonBuyCnt + 1 }, 50);
return {
nextCostGold,
dungeonHeroes,
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt,
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt
}
}
// 检查秘境本次数checkBattle使用
export async function checkDungeonNum(roleId: string, inc: number) {

View File

@@ -3,13 +3,56 @@ import { ExpeditionPointModel } from '../db/ExpeditionPoint';
import Role, { RoleModel, RoleType } from '../db/Role';
import { PvpDefenseModel } from '../db/PvpDefense';
import { shouldRefresh } from '../pubUtils/util';
import { EXPEDITION_CONST } from '../consts';
import { shouldRefresh, calculateSumCE } from '../pubUtils/util';
import { EXPEDITION_CONST, LINEUP_NUM, EXPEDITION_WAR_RECORD_STATUS } from '../consts';
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';
import { ExpeditionRecordModel } from '../db/ExpeditionRecord';
/**
* 获取远征关卡列表
* @param roleId
* @param roleName
*/
export async function getExpeditionStatus(roleId: string, roleName: string) {
// 获取远征关卡状态
let expeditionRecord = await ExpeditionRecordModel.getCurRecord(roleId);
if (!expeditionRecord) { // 首次新建一条记录
// 我方战力
let myCe = await calculateSumCE(roleId, 1, { num: LINEUP_NUM });
expeditionRecord = await ExpeditionRecordModel.createRecord({
roleId, roleName, heroes: [], myCe
});
await findOrCreateEnemies(roleId, myCe, expeditionRecord.expeditionCode, 1, EXPEDITION_WAR_RECORD_STATUS.WAITING);
}
// 每一关的挑战状态
let { expeditionCode, heroes } = expeditionRecord;
let expeditionWarRecord = await ExpeditionWarRecordModel.getRecordByCode(expeditionCode);
let curLv = 0;
if (expeditionWarRecord.length > 0) {
curLv = expeditionWarRecord[expeditionWarRecord.length - 1].expeditionId;
}
// 重置次数
let role = await RoleModel.findByRoleId(roleId);
let curTime = new Date();
let { resetCnt } = await getResetRemainCnt(curTime, roleId, role);
// 点数,和宝箱领取状态
let pointRewards = await getPointRewardStatus(roleId, role);
return {
expeditionCode,
curLv,
expeditionWarRecord,
pointRewards,
heroes: heroes.map(cur => { return { "dataId": cur.seqId, "hp": cur.hp, "ap": cur.ap } }),
resetCnt
}
}
/**
* 根据存下的战力获取当前远征关卡的对手

View File

@@ -1,12 +1,31 @@
import { GachaData, Floor, GachaResult, Hope } from "../domain/activityField/gachaField";;
import { GachaData, Floor, GachaResult, Hope, GachaListReturn } from "../domain/activityField/gachaField";;
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_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 { 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, GACHA_ID } from "../consts";
import { getTimeFunD, getZeroPointD } from "../pubUtils/timeUtil";
import { gameData, getDicGachaFloor } from "../pubUtils/data";
/**
* 获取招募列表
* @param roleId
*/
export async function getGachaList(roleId: string) {
let userGachaList = await UserGachaModel.findAllByRole(roleId);
let list: GachaListReturn[] = [];
for (let [id, dicGacha] of gameData.gacha) {
if (id == GACHA_ID.TIMELIMIT) continue; // 不包括限时
let userGacha = userGachaList.find(cur => cur.gachaId == id);
if (userGacha)
userGacha = await refreshGacha(dicGacha, userGacha);
let param = new GachaListReturn(dicGacha, userGacha);
list.push(param);
}
return list;
}
/**
* 获取活动页签里的限时卡池
*

View File

@@ -1,16 +1,16 @@
import { gameData, getGuildActiveWeekReward, getGuildActiveByIdAndType, getGoodById } from "../pubUtils/data";
import { GuildModel } from "../db/Guild";
import { GuildModel, GuildType } from "../db/Guild";
import { resResult, shouldRefresh } from "../pubUtils/util";
import { STATUS, MAIL_TYPE, GUILD_AUTH, GUILD_JOB, REDIS_KEY, CHAT_SERVER, TASK_TYPE } from "../consts";
import { RoleModel } from "../db/Role";
import { RoleModel, RoleType } from "../db/Role";
import { UserGuildModel, UserGuildType } from "../db/UserGuild";
import { UserGuildApplyModel } from "../db/UserGuildApply";
import { SystemConfigModel } from "../db/SystemConfig";
import { nowSeconds } from "../pubUtils/timeUtil";
import { pinus, BackendSession } from "pinus";
import { pinus, BackendSession, FrontendOrBackendSession } from "pinus";
import { ARMY } from "../pubUtils/dicParam";
import { sendMail } from "./mailService";
import { initSingleRank, getRoleOnlineInfo, updateUserInfo } from "./redisService";
import { initSingleRank, getRoleOnlineInfo, updateUserInfo, isRoleOnline } from "./redisService";
import { GuildRankParam, GuildLeader } from "../domain/rank";
import { lockData, lockDataNoRetry } from '../services/redLockService';
import { ErrLogModel } from '../db/ErrLog';
@@ -22,6 +22,30 @@ import { addRoleToGuildChannel } from "./chatService";
import { Rank } from "./rankService";
import { checkActivityTask, checkTask } from "./taskService";
export async function getMyGuildInfo(roleId: string, sid: string, userGuild: UserGuildType, guild: GuildType, serverId: number, session: FrontendOrBackendSession) {
let leader = <RoleType>guild.leader;
let leaderIsOnline = await isRoleOnline(leader.roleId);
// 打开公会页面加入channel
if(userGuild.guildCode) {
addRoleToGuildChannel(roleId, sid, guild.code);
session.set('guildCode', guild.code);
session.push('guildCode', () => {});
}
// 获取排行榜
let r = new Rank(REDIS_KEY.GUILD_ACTIVE_RANK, { serverId });
const rank = await r.getMyRank({ guildCode: guild.code });
let { lv: guildLv, memberCnt } = guild;
let dicGuild = gameData.centerBase.get(guildLv);
let guildMemberMax = dicGuild && memberCnt >= dicGuild.peopleNum;
// 返回
return { hasGuild: true, guildMemberMax, ...guild, leader: { ...leader, isOnline: leaderIsOnline }, rank, myInfo: {...userGuild }};
}
/**
* @description 检查该玩家是否有权限做操作
* @param func 操作id
@@ -292,3 +316,17 @@ export async function settleGuildWeekly() {
await SystemConfigModel.updateSystemConfig({ settleGuildWeeklyTime: nowSeconds() }); // 记录一下
console.log('————— settleGuildWeekly结束 —————');
}
export async function getWishPool(userGuild: UserGuildType) {
const { guildCode: code, wishDntCnt, wishGoods } = userGuild;
let userGuilds = await UserGuildModel.getWishPoolGoods(code, ' wishDntCnt wishGoods roleId');
let list = [];
userGuilds.map(({ wishGoods, roleId })=>{
wishGoods.map(({ type, goodId, count, receiveCnt, drawCnt, id })=>{
list.push({ type, goodId, count, receiveCnt, drawCnt, id, roleId })
});
});
return { list, wishDntCnt:wishDntCnt||0, wishGoods };
}

View File

@@ -1,9 +1,9 @@
import { UserGuildModel } from '../db/UserGuild';
import { UserGuildModel, UserGuildType } from '../db/UserGuild';
import { getArmyTrainJuDian, getTrainBaseByLv } from '../pubUtils/data';
import { nowSeconds, getZeroPoint } from '../pubUtils/timeUtil';
import { GUILD_STRUCTURE } from '../consts';
import { GuildTrainType, GuildTrainModel, TrainInstance } from '../db/GuildTrain';
import { GuildModel } from '../db/Guild';
import { GuildModel, GuildType } from '../db/Guild';
import { findWhere } from 'underscore';
import { ARMY } from '../pubUtils/dicParam';
import { lockData } from './redLockService';
@@ -184,4 +184,23 @@ export async function checkResetTrain(roleId: string, serverId: number) {
*/
export async function removeTrainRank(guildCode: string, roleId: string, trainId: number) {
await GuildTrainModel.removeTrainRank(guildCode, roleId, trainId);
}
/**
* 获取军团练兵场
* @param roleId
* @param guild
* @param userGuild
*/
export async function getGuildTrainInstance(roleId: string, guild: GuildType, userGuild: UserGuildType) {
let { trainId, trainLv, code } = guild;
let guildTrain = await GuildTrainModel.findTrainByTrainIdNotLock(code, trainId);
if (!guildTrain) {
guildTrain = await unlockTrain(code, trainId);
}
let { trainCount, trainRewards, buyTrainCount } = userGuild;
let result: any = getGuildTrainInfo(guildTrain, roleId, trainCount, trainRewards);
result.buyTrainCount = buyTrainCount || 0;
result.trainLv = trainLv;
return result;
}

View File

@@ -1,14 +1,16 @@
import { HeroModel } from '../db/Hero';
import Role, { RoleModel } from '../db/Role'
import Role, { RoleModel, RoleType } from '../db/Role'
import { getLvByExp, getExpByLv, gameData } from '../pubUtils/data';
import { updateUserInfo } from './redisService';
import { switchOnFunc } from './funcSwitchService';
import { FUNC_OPT_TYPE, TASK_TYPE } from '../consts';
import { FUNC_OPT_TYPE, TASK_TYPE, WAR_TYPE } from '../consts';
import { BackendSession } from 'pinus';
import { REDIS_KEY } from '../consts';
import { Rank } from './rankService';
import { checkActivityTask, checkTask } from './taskService';
import { accomplishTask } from '../pubUtils/taskUtil';
import { RScriptRecordModel } from '../db/RScriptRecord';
export async function roleLevelup(roleId: string, kingExp: number, session: BackendSession) {
const serverId = session.get('serverId');
@@ -103,4 +105,51 @@ export async function updateWarStar(roleId: string, battleId: number, warType: n
result = await RoleModel.pushWarStar(roleId, battleId, warType, star);
}
return result
}
export async function getBattleListOfMain(role: RoleType) {
let types = [ WAR_TYPE.NORMAL, WAR_TYPE.VESTIGE, WAR_TYPE.MAIN_ELITE ];
let result = [];
for(let type of types) {
let list = await getBattleList(role, type);
result.push({ type, list });
}
return result
}
export async function getBattleList(role: RoleType, type: number) {
let { roleId, warStar } = role;
let scripts = await RScriptRecordModel.findbyRole(roleId, type);
let result = []; // 去重
for (let { battleId, scriptBefore = '', scriptAfter = '' } of scripts) {
result.push({
battleId,
status: 0,
star: 0,
scriptBefore,
scriptAfter
});
}
for (let { id, star, warType } of warStar) {
if (warType == type) {
let curResult = result.find(cur => cur.battleId == id);
if (curResult) {
curResult.status = 1;
curResult.star = star;
} else {
result.push({
battleId: id,
status: 1,
star,
scriptBefore: '',
scriptAfter: ''
});
}
}
}
result = result.sort((a, b) => { return a.battleId - b.battleId });
return result;
}

View File

@@ -20,6 +20,11 @@ import { pinus } from 'pinus';
import { PvpHistoryOppModel, PvpHistoryOppType } from '../db/PvpHistoryOpp';
import { Rank } from './rankService';
export async function getPvpData() {
}
export async function initPvpInfo(role: RoleType) {
let heroes: Array<Heroes> = [];
//初始化最强5人阵容

View File

@@ -1,9 +1,9 @@
import { KeyName, KeyNameParam, RankParam, GuildRankParam, RoleRankInfo, GuildRankInfo, GuildLeader, LineupParam, myIdInter } from "../domain/rank";
import { REDIS_RANK_TO_INFO, ROLE_SELECT, GUILD_SELECT, REDIS_KEY, REDIS_RANK_TO_EXTRA, HERO_SELECT, COMPOSE_FIELD_TYPE, KEY_TO_COMPOSE_FIELD, RANK_TYPE } from "../consts";
import { KeyName, KeyNameParam, RankParam, GuildRankParam, RoleRankInfo, GuildRankInfo, GuildLeader, LineupParam, myIdInter, GeneralRankParamRole, GeneralRankParamBattle } from "../domain/rank";
import { REDIS_RANK_TO_INFO, ROLE_SELECT, GUILD_SELECT, REDIS_KEY, REDIS_RANK_TO_EXTRA, HERO_SELECT, COMPOSE_FIELD_TYPE, KEY_TO_COMPOSE_FIELD, RANK_TYPE_TO_KEY } from "../consts";
import { redisClient, setUserInfo } from "./redisService";
import { RoleType, RoleModel } from "../db/Role";
import { GuildType, GuildModel } from "../db/Guild";
import { HeroModel, HeroType } from "../db/Hero";
import { HeroModel, HeroType, HeroUpdate } from "../db/Hero";
import { SystemConfigModel } from "../db/SystemConfig";
import { PvpDefenseModel } from "../db/PvpDefense";
import { gameData } from "../pubUtils/data";
@@ -793,4 +793,46 @@ export async function setRankRedisFromDb(type: string, args?: {serverId?: number
}
}
}
}
/**
* 获取排行榜总览
* @param role 玩家数据
* @param serverId 所在服务器
*/
export async function getGeneralRank(role: RoleType&{rankReceived: number[]}, serverId: number) {
let { rankReceived = []} = role;
let res = {
role: new Array<GeneralRankParamRole>(),
battle: new Array<GeneralRankParamBattle>()
};
for(let { id, general } of gameData.rank) {
let redisKey = RANK_TYPE_TO_KEY.get(id);
if(redisKey) {
let received = rankReceived.filter(rewardId => {
let dic = gameData.generalRankReward.get(rewardId);
return dic && dic.rankId == id;
});
if(general == 1) {
let r = new Rank(redisKey, { serverId }, false, 1);
let ranks = <RoleRankInfo[]> await r.getRankByRange();
if(ranks.length > 0) {
let param = new GeneralRankParamRole(id, ranks[0]||new RoleRankInfo({}, false), received);
res.role.push(param);
}
} else if (general = 2) {
let r = new Rank(redisKey, { serverId }, false, 1);
let ranks = <RoleRankInfo[]> await r.getRankByRange();
let hero: HeroUpdate;
if(ranks.length > 0) {
hero = await HeroModel.getMyTopHero(ranks[0].roleId, 'hid skins');
let param = new GeneralRankParamBattle(id, ranks[0]||new RoleRankInfo({}, false), hero, received);
res.battle.push(param);
}
}
}
}
return res;
}

View File

@@ -1,10 +1,14 @@
import { ChannelUser } from './../domain/ChannelUser';
import { Channel } from 'pinus';
import { getRandValueByMinMax, getRandEelm } from '../pubUtils/util';
import { getRandValueByMinMax, getRandEelm, decodeIdCntArrayStr } from '../pubUtils/util';
import { TERAPH_RANDOM } from "../consts";
import { DicTeraph } from '../pubUtils/dictionary/DicTeraph';
import { Teraph, RoleModel } from '../db/Role';
import { ROLE_SELECT } from '../consts';
import { SCHOOL } from '../pubUtils/dicParam';
import { gameData } from '../pubUtils/data';
import { SchoolModel } from '../db/School';
import { SclResultInter, SclPosInter } from '../pubUtils/interface';
const TERAPH_STRENGTHEN = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
/**
* 计算强化次数和消耗
@@ -98,3 +102,43 @@ export async function getSimpleRoleInfos(roleIds: string[]) {
let roles = await RoleModel.findRoleByField('roleId', roleIds, ROLE_SELECT.SHOW_SIMPLE, true);
return roles;
}
/**
* 百家学宫
* @param roleId
*/
export async function getSchoolList(roleId: string) {
const dicPosition = decodeIdCntArrayStr(SCHOOL.SCHOOL_POSITION, 1); // id=>isOpen
const userSchoolList = await SchoolModel.findByRoleId(roleId);
let school = new Array<SclResultInter>();
gameData.school.forEach((dicSchool) => {
let position = new Array<SclPosInter>();
dicPosition.forEach((isOpen, dicId) => {
let id = parseInt(dicId);
let userSchool = userSchoolList.find(cur => cur.schoolId == dicSchool.id && cur.positionId == id);
if (userSchool) {
position.push({
id,
hid: userSchool.hid,
isOpen: userSchool.isOpen
});
} else {
position.push({
id,
hid: 0,
isOpen: !!isOpen
});
}
});
school.push({
id: dicSchool.id,
position
});
});
return school;
}

View File

@@ -0,0 +1,58 @@
import { gameData } from "../pubUtils/data";
import { DicShopListModel } from "../db/DicShopList";
import { ShopItem } from "../domain/dbGeneral";
import { ShopItemListParam } from '../domain/roleField/shop';
import { UserShopModel } from "../db/UserShop";
export async function getShopListById(shopId: number, roleId: string) {
let shopItemList = new Array<ShopItemListParam>(); // 返回
let dbDicShop = await DicShopListModel.findByShopId(shopId);
let userShopRecs = await UserShopModel.findMapByShopId(roleId, shopId);
// console.log(JSON.stringify([...userShopRecs]))
if(!dbDicShop || dbDicShop.useJson) { // 完全使用json中配置的商品数据库只做排序用数据库内没有的排到最后
let items = dbDicShop?.items||[];
let map = new Map<number, ShopItem>();
for(let item of items) {
map.set(item.id, item);
}
let dicShop = gameData.shop.get(shopId)||[];
for(let { id, type } of dicShop) {
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
if(map.has(id)) {
let item = map.get(id);
let param = new ShopItemListParam(id, item.discount, type, buyCount, item.order);
shopItemList.push(param);
} else {
let param = new ShopItemListParam(id, 1, type, buyCount, 0);
shopItemList.push(param);
}
}
} else { // 只返回数据库内的商品
let items = dbDicShop?.items||[];
for(let item of items) {
let { id, order, discount } = item;
let buyCount = userShopRecs.has(id)?userShopRecs.get(id).count: 0;
let dicShop = gameData.shopItem.get(id);
if(dicShop) {
let param = new ShopItemListParam(id, discount, dicShop.type, buyCount, order);
shopItemList.push(param);
}
}
}
shopItemList = shopItemList.sort((a, b) => b.order - a.order);
return shopItemList;
}
export async function getAllShopList(roleId: string) {
let shopLists: {shopId: number, shopItemList: ShopItemListParam[]}[] = [];
for(let [ shopId ] of gameData.shopList) {
let shopItemList = await getShopListById(shopId, roleId);
shopLists.push({ shopId, shopItemList });
}
return shopLists;
}