红点:修改推送方式
This commit is contained in:
@@ -4,7 +4,7 @@ import { STATUS, GACHA_ID, HERO_QUALITY_TYPE, TASK_TYPE, REFRESH_TIME, TIME_OUTP
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { GachaListReturn, GachaResult, GachaData } from "../../../domain/activityField/gachaField";
|
||||
import { UserGachaModel } from "../../../db/UserGacha";
|
||||
import { refreshGacha, getFloorResult, getResultFromContentId } from "../../../services/gachaService";
|
||||
import { refreshGacha, getFloorResult, getResultFromContentId, getGachaList } from "../../../services/gachaService";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
@@ -35,18 +35,7 @@ export class GachaHandler {
|
||||
async getGachaList(msg: {}, session: BackendSession) {
|
||||
const { } = msg;
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
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);
|
||||
}
|
||||
const list = await getGachaList(roleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { AUCTION_STAGE, DEBUG_MAGIC_WORD, STATUS, OFFER_RATIO, CURRENCY_BY_TYPE,
|
||||
import { LotModel } from "../../../db/Lot";
|
||||
import { ItemReward } from "../../../domain/dbGeneral";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus } from "../../../services/auctionService";
|
||||
import { auctionStage, calculateDividend, genAuction, sendUngotDividend, startGuildAuction, startWorldAuction, stopAuction, todayGuildBegin, getBasePrice, debugAuctionLots, officialAuctionLots, auctionBidStatus, getMaxPrice, guildBidStatus, getAuction } from "../../../services/auctionService";
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { getSimpleRoleInfo } from '../../../services/roleService';
|
||||
import { getRoleOnlineInfo } from '../../../services/redisService';
|
||||
@@ -25,11 +25,9 @@ export class AuctionHandler {
|
||||
|
||||
const guildCode = session.get('guildCode');
|
||||
if (!guildCode) return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
const begin = todayGuildBegin();
|
||||
let lots = magicWord === DEBUG_MAGIC_WORD ? await debugAuctionLots(session, begin) : await officialAuctionLots(session, begin);
|
||||
let result = await getAuction(guildCode, session, magicWord);
|
||||
|
||||
const dividends = await DividendModel.findGuildDividendsByBegin(guildCode, begin);
|
||||
return resResult(STATUS.SUCCESS, { lots, dividends });
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async offer(msg: { code: string, max: boolean }, session: BackendSession) {
|
||||
@@ -76,8 +74,11 @@ export class AuctionHandler {
|
||||
|
||||
if (curBuyer) {
|
||||
const { roleName: buyerName } = await getSimpleRoleInfo(curBuyer);
|
||||
const { sid: buyerSid } = await getRoleOnlineInfo(buyerName);
|
||||
const { isOnline, sid: buyerSid } = await getRoleOnlineInfo(curBuyer);
|
||||
await addItems(curBuyer, buyerName, buyerSid, [{ id: CURRENCY_BY_TYPE.get(CURRENCY_TYPE.GOLD), count: curPrice }]);
|
||||
if(isOnline) {
|
||||
this.channelService.pushMessageByUids('onAuctionOver', resResult(STATUS.SUCCESS, { code }), [{ uid: curBuyer, sid: buyerSid }]);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxFlag) {
|
||||
|
||||
@@ -15,7 +15,7 @@ import { RoleStatus, ComBattleTeamModel, ComBattleTeamType, BossHp } from '../..
|
||||
import { ItemModel, ItemType } from '../../../db/Item';
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { checkRoleInQueue, rmRoleFromQueue, setTeamSearchReq } from '../../../services/redisService';
|
||||
import { getRandBlueprtId, clearComBtlTimer, getAssistTimesByQuality, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress, getComBattleFriendAdd, teammateInBlackList, blueprtIdValid, createComTeamData, hasEnoughBlueprt, addRoleToTeam, addRoleStToTeam, addValidSearchingRoles, validToJoin, addRobotsToTeam, addRobotsLater, teamIsFullToStart, oneTeamNotInBlack } from '../../../services/comBattleService';
|
||||
import { getRandBlueprtId, clearComBtlTimer, getFrd, updateRobotHurtByTime, comBtlLvInvalid, clearRobotHurtTimer, setDismissTimer, dismissTeam, incEquipPrintDrop, randEquipPrintId, handleComBtlProgress, getComBattleFriendAdd, teammateInBlackList, blueprtIdValid, createComTeamData, hasEnoughBlueprt, addRoleToTeam, addRoleStToTeam, addValidSearchingRoles, validToJoin, addRobotsToTeam, addRobotsLater, teamIsFullToStart, oneTeamNotInBlack, getAllAssistCnt } from '../../../services/comBattleService';
|
||||
import { setAp } from '../../../services/actionPointService';
|
||||
import { roleLevelup } from '../../../services/normalBattleService';
|
||||
import { addUserToChannel, getSimpleRoleInfo } from '../../../services/roleService';
|
||||
@@ -630,11 +630,7 @@ export class ComBattleHandler {
|
||||
*/
|
||||
async getAssistCnt(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let cntMap = await getAssistTimesByQuality(roleId);
|
||||
let cnt = [];
|
||||
for (let i = 0; i < COM_BTL_QUALITY.length; ++i) {
|
||||
cnt[i] = cntMap.get(i + 1) || 0;
|
||||
}
|
||||
let cnt = await getAllAssistCnt(roleId);
|
||||
return resResult(STATUS.SUCCESS, {cnt});
|
||||
}
|
||||
/**
|
||||
@@ -646,11 +642,7 @@ export class ComBattleHandler {
|
||||
*/
|
||||
async getComBtlCnt(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let cntMap = await getAssistTimesByQuality(roleId);
|
||||
let cnt: number[] = [];
|
||||
for (let i = 0; i < COM_BTL_QUALITY.length; ++i) {
|
||||
cnt[i] = cntMap.get(i + 1) || 0;
|
||||
}
|
||||
let cnt = await getAllAssistCnt(roleId);
|
||||
const blueprts = await ItemModel.findByRoleAndType(roleId, CONSUME_TYPE.BLUEPRT);
|
||||
return resResult(STATUS.SUCCESS, { blueprts, assistCnt: cnt });
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { GOLD_COST_RATIO } from '../../../consts';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult, calculateNum } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getDailyNum } from '../../../services/dailyBattleService';
|
||||
import { getDailyNum, getDailyBattleList } from '../../../services/dailyBattleService';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
@@ -21,42 +21,8 @@ export class DailyBattleHandler {
|
||||
async getData(msg: { }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
let {warStar} = await RoleModel.findByRoleId(roleId);
|
||||
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
|
||||
});
|
||||
}
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let result = await getDailyBattleList(role);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { list: result });
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import { resResult, calculateNum, shouldRefresh } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { handleCost } from '../../../services/rewardService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { getDungeonData } from '../../../services/dungeonService';
|
||||
|
||||
export default function(app: Application) {
|
||||
return new DungeonBattleHandler(app);
|
||||
@@ -17,19 +18,9 @@ export class DungeonBattleHandler {
|
||||
// 获取关卡列表
|
||||
async getData(msg: { }, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let { dungeonCnt = 0, dungeonBuyCnt = 0, dungeonRefTime, dungeonHeroes=[] } = await RoleModel.findByRoleId(roleId);
|
||||
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 resResult(STATUS.SUCCESS, {
|
||||
nextCostGold,
|
||||
dungeonHeroes,
|
||||
battleCount: DUNGEON_CONST.MAX_CNT + dungeonBuyCnt - dungeonCnt,
|
||||
buyCount: DUNGEON_CONST.MAX_BUY_CNT - dungeonBuyCnt
|
||||
});
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let res = await getDungeonData(role);
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
}
|
||||
|
||||
// 购买每日次数
|
||||
|
||||
@@ -5,7 +5,7 @@ import { ExpeditionWarRecordModel } from '../../../db/ExpeditionWarRecord';
|
||||
import { ExpeditionPointModel } from '../../../db/ExpeditionPoint';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { calculateSumCE, genCode } from '../../../pubUtils/util';
|
||||
import { getPointRewardStatus, getResetRemainCnt, findOrCreateEnemies } from '../../../services/expeditionService';
|
||||
import { getPointRewardStatus, getResetRemainCnt, findOrCreateEnemies, getExpeditionStatus } from '../../../services/expeditionService';
|
||||
import { EXPEDITION_CONST, EXPEDITION_WAR_RECORD_STATUS, LINEUP_NUM, TASK_TYPE } from '../../../consts';
|
||||
import { WarReward } from '../../../services/warRewardService';
|
||||
import { addItems } from '../../../services/rewardService';
|
||||
@@ -32,41 +32,9 @@ export class ExpeditionBattleHandler {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
|
||||
// 获取远征关卡状态
|
||||
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 res = await getExpeditionStatus(roleId, roleName);
|
||||
|
||||
// 每一关的挑战状态
|
||||
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 resResult(STATUS.SUCCESS, {
|
||||
expeditionCode,
|
||||
curLv,
|
||||
expeditionWarRecord,
|
||||
pointRewards,
|
||||
heroes: heroes.map(cur => { return { "dataId": cur.seqId, "hp": cur.hp, "ap": cur.ap } }),
|
||||
resetCnt
|
||||
});
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { Application, BackendSession, pinus } from 'pinus';
|
||||
import { resResult, genCode, getRandSingleEelm } from '../../../pubUtils/util';
|
||||
import { STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { BossInstanceModel } from '../../../db/BossInstance';
|
||||
@@ -14,7 +14,7 @@ import { checkAuth, addActive } from '../../../services/guildService';
|
||||
import { GuildModel } from '../../../db/Guild';
|
||||
import { getBossByLv } from '../../../pubUtils/data';
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { pushGuildBossSucMsg } from '../../../services/chatService';
|
||||
import { pushGuildBossSucMsg, getGuildChannelSid } from '../../../services/chatService';
|
||||
import { checkTask } from '../../../services/taskService';
|
||||
|
||||
export default function (app: Application) {
|
||||
@@ -99,6 +99,10 @@ export class GuildHandler {
|
||||
await BossInstanceModel.openBossInstance(code, bossHp, warId, bossBase.bossLevel);
|
||||
res.releaseCallback();
|
||||
let result = {warId, ranks: [], myRank: {}, bossHp, status: 3, bossLv: bossBase.bossLevel, isBattled: false};
|
||||
|
||||
let chatSid = await getGuildChannelSid(code);
|
||||
pinus.app.rpc.chat.guildRemote.pushBossOpen.toServer(chatSid, code, warId, bossHp, result.status);
|
||||
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ 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';
|
||||
import { checkAuth, joinGuild, getGuildWithRefActive, getUserGuildWithRefActive, addActive, settleGuildWeekly, getMyGuildInfo } from '../../../services/guildService';
|
||||
import { GuildModel, GuildType } from '../../../db/Guild';
|
||||
import { RoleModel, RoleType } from '../../../db/Role';
|
||||
import { ARMY } from '../../../pubUtils/dicParam';
|
||||
@@ -272,22 +272,7 @@ export class GuildHandler {
|
||||
return resResult(STATUS.GUILD_NOT_FOUND);
|
||||
}
|
||||
|
||||
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 });
|
||||
|
||||
// 返回
|
||||
const result = { hasGuild: true, ...guild, leader: { ...leader, isOnline: leaderIsOnline }, rank, myInfo: {...userGuild }};
|
||||
let result = await getMyGuildInfo(roleId, sid, userGuild, guild, serverId, session);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import { STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { GuildTrainModel } from '../../../db/GuildTrain';
|
||||
import { BattleRecordModel } from '../../../db/BattleRecord';
|
||||
import { nowSeconds, getTimeFun, getZeroPoint } from '../../../pubUtils/timeUtil';
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, getGuildTrainRewards } from '../../../services/guildTrainService';
|
||||
import { getUserGuild, getGuildTrainInfo, unlockTrain, getGuildTrainRewards, getGuildTrainInstance } from '../../../services/guildTrainService';
|
||||
import { findIndex, findWhere } from 'underscore'
|
||||
import { lockData } from '../../../services/redLockService';
|
||||
import { GUILD_REPORT_NUM, GUILD_POINT_WAYS } from '../../../consts/constModules/guildConst';
|
||||
@@ -37,15 +37,8 @@ export class GuildTrainHandler {
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
const { guildCode: code } = userGuild;
|
||||
let { trainId, trainLv } = await GuildModel.findGuild(code, serverId, 'trainId trainLv');
|
||||
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;
|
||||
let guild = await GuildModel.findGuild(code, serverId, 'trainId trainLv');
|
||||
let result = await getGuildTrainInstance(roleId, guild, userGuild);
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
//获得试炼战报
|
||||
|
||||
@@ -12,7 +12,7 @@ import { STATUS } from '../../../consts/statusCode';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { RScriptRecordModel } from '../../../db/RScriptRecord';
|
||||
import { updateWarStar, checkBattleHeroes, roleLevelup } from '../../../services/normalBattleService';
|
||||
import { updateWarStar, checkBattleHeroes, roleLevelup, getBattleList } from '../../../services/normalBattleService';
|
||||
import { checkDungeonNum, checkDungeonAndIncrease } from '../../../services/dungeonService';
|
||||
import { switchOnFunc } from '../../../services/funcSwitchService';
|
||||
import { gameData } from '../../../pubUtils/data';
|
||||
@@ -110,40 +110,7 @@ export class NormalBattleHandler {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let { 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 });
|
||||
|
||||
let result = await getBattleList(role, type);
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
list: result
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ import { RoleModel } from './../../../db/Role';
|
||||
import { TowerRecordModel } from './../../../db/TowerRecord';
|
||||
import { Application, BackendSession } from 'pinus';
|
||||
import { resResult, shouldRefresh, calculateNum, genCode } from '../../../pubUtils/util';
|
||||
import { calcuHangUpReward, checkTaskConditions, checkHangUpSpdUpCnt, createCurTasks, treatTask, getRemainTime, getDoingOrWaitingTasks } from '../../../services/battleService';
|
||||
import { calcuHangUpReward, checkTaskConditions, checkHangUpSpdUpCnt, createCurTasks, treatTask, getRemainTime, getDoingOrWaitingTasks, getTowerStatus, getHungupRewards, getTasks } from '../../../services/battleService';
|
||||
import { addItems, handleCost } from '../../../services/rewardService';
|
||||
import { checkBattleHeroes } from '../../../services/normalBattleService';
|
||||
import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
@@ -30,32 +30,9 @@ export class TowerBattleHandler {
|
||||
async getStatus(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let serverId = session.get('serverId');
|
||||
let { towerLv } = await RoleModel.findByRoleId(roleId);
|
||||
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: '天梯记录异常' };
|
||||
}
|
||||
const data = {
|
||||
canHungUp: towerLv >= HANG_UP_CONSTS.ENABLE_LV,
|
||||
hungUpEnableLv: HANG_UP_CONSTS.ENABLE_LV,
|
||||
canSendTask: true,
|
||||
curLv: towerLv,
|
||||
usedHeroes: towerRec.heroes,
|
||||
progress: towerRec.warStatus
|
||||
};
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let data = await getTowerStatus(role);
|
||||
|
||||
return resResult(STATUS.SUCCESS, data);
|
||||
}
|
||||
|
||||
@@ -79,20 +56,11 @@ export class TowerBattleHandler {
|
||||
|
||||
async checkHangUpRewards(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
const result = await calcuHangUpReward(roleId);
|
||||
let result = await getHungupRewards(roleId);
|
||||
if(result.status == -1) {
|
||||
return result.resResult
|
||||
return result.resResult;
|
||||
}
|
||||
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 resResult(STATUS.SUCCESS, {startTime, hangUpPassTime: Math.floor(deltaTime/1000), hangUpSpdUpCnt, nextCostGold, rewards: timeReward});
|
||||
return resResult(STATUS.SUCCESS, result.data);
|
||||
}
|
||||
|
||||
async recHangUpRewards(msg: {}, session: BackendSession) {
|
||||
@@ -162,30 +130,11 @@ export class TowerBattleHandler {
|
||||
async getTasks(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
let roleName = session.get('roleName');
|
||||
let curTime = new Date();
|
||||
|
||||
let { towerLv, towerTaskRefTime, towerTaskReCnt = 0 } = await RoleModel.findByRoleId(roleId);
|
||||
let curTasks = await TowerTaskRecModel.getCurTasks(roleId); // 当前显示中的任务
|
||||
let role = await RoleModel.findByRoleId(roleId);
|
||||
let result = await getTasks(role);
|
||||
|
||||
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 resResult(STATUS.SUCCESS, { curTasks: treatTask(curTasks, curTime), refRemainTime, nextCostGold });
|
||||
return resResult(STATUS.SUCCESS, result);
|
||||
}
|
||||
|
||||
async refreshTasks(msg: {}, session: BackendSession) {
|
||||
|
||||
@@ -8,7 +8,7 @@ import { getArmyWishPoolBaseByLv, getGoodById } from '../../../pubUtils/data';
|
||||
import { addItems, checkGoods } from '../../../services/rewardService';
|
||||
import { IT_TYPE } from '../../../consts/constModules/itemConst';
|
||||
import { GUILD_STRUCTURE } from '../../../consts/constModules/guildConst';
|
||||
import { getUserGuildWithRefActive } from '../../../services/guildService';
|
||||
import { getUserGuildWithRefActive, getWishPool } from '../../../services/guildService';
|
||||
import { findIndex, findWhere } from 'underscore';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { getRoleOnlineInfo } from '../../../services/redisService';
|
||||
@@ -27,15 +27,8 @@ export class WishPoolHandler {
|
||||
let userGuild = await getUserGuildWithRefActive(roleId, 'wishDntCnt wishGoods guildCode');
|
||||
if (!userGuild)
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
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 resResult(STATUS.SUCCESS, { list, wishDntCnt:wishDntCnt||0, wishGoods });
|
||||
let res = await getWishPool(userGuild);
|
||||
return resResult(STATUS.SUCCESS, );
|
||||
}
|
||||
|
||||
// 许愿
|
||||
|
||||
@@ -2,7 +2,7 @@ import { CHANNEL_PREFIX, MSG_SOURCE, CHANNEL_TYPE } from './../../../consts/cons
|
||||
import {Application, BackendSession} from 'pinus';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { DEFAULT_MSG_PER_PAGE, STATUS, TASK_TYPE } from '../../../consts';
|
||||
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo, recentPrivateChatInfos } from '../../../services/chatService';
|
||||
import { createAccuseData, createGroupMsg, createPrivateMsg, getPrivateMessages, pushGroupMsgToRoom, pushMsgToRole, updatePrivateMsgReadInfo, recentPrivateChatInfos, recentWorldMsgs, recentSysMsgs, recentGuildMsgs } from '../../../services/chatService';
|
||||
import { getSimpleRoleInfo } from '../../../services/roleService';
|
||||
import { checkTaskWithArgs } from '../../../services/taskService';
|
||||
|
||||
@@ -148,6 +148,21 @@ export class ChatHandler {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取群组聊天记录
|
||||
* @param {{}} msg
|
||||
* @param session
|
||||
*/
|
||||
async getGroupMessages(msg: {}, session: BackendSession) {
|
||||
const serverId: number = session.get('serverId');
|
||||
const guildCode: string = session.get('guildCode');
|
||||
|
||||
const worldMsgs = await recentWorldMsgs(serverId);
|
||||
const sysMsgs = await recentSysMsgs(serverId);
|
||||
const guildMsgs = await recentGuildMsgs(guildCode);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { worldMsgs, sysMsgs, guildMsgs })
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 获取私聊历史消息
|
||||
|
||||
@@ -25,6 +25,7 @@ export class GuildRemote {
|
||||
private DEMOTION = 'onDemotion';
|
||||
private PROMOTION = 'onPromotion';
|
||||
private GUILD_REC_ADD = 'onGuildRecAdd';
|
||||
private GUILD_BOSS_OPEN = 'onGuildBossOpen';
|
||||
private GATE_ACT_RANK = 'onGuildGateRankUpdate'; // 军团活动排行榜
|
||||
private CITY_ACT_RANK = 'onGuildCityRankUpdate'; // 军团活动排行榜
|
||||
private GUILD_GATE_ACT_HP = 'onGuildGateHpUpdate'; // 军团活动蛮夷入侵排行榜
|
||||
@@ -271,4 +272,14 @@ export class GuildRemote {
|
||||
this.pushMessage(guildCode, this.GUILD_RACE_EVENT, { timestamp: Date.now(), events });
|
||||
}
|
||||
|
||||
/**
|
||||
* @description 当团长开启演武台时
|
||||
* @param guildCode
|
||||
* @param warId
|
||||
* @param bossHp
|
||||
* @param status
|
||||
*/
|
||||
public async pushBossOpen(guildCode: string, warId: number, bossHp: number, status: number) {
|
||||
this.pushMessage(guildCode, this.GUILD_BOSS_OPEN, { guildCode, warId, bossHp, status });
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { STATUS } from './../../../consts/statusCode';
|
||||
import { EquipModel } from './../../../db/Equip';
|
||||
import { RoleModel } from './../../../db/Role';
|
||||
import { RoleModel, RoleType } from './../../../db/Role';
|
||||
import { UserModel } from '../../../db/User';
|
||||
import { GMUserModel } from '../../../db/GMUser';
|
||||
import { Application } from 'pinus';
|
||||
@@ -61,6 +61,53 @@ export class EntryHandler {
|
||||
}
|
||||
let serverName = this.app.getServerId();
|
||||
await roleLogin(role.roleId, user.userCode, serverName, user.pkgName, role.funcs || []); // 保存在线用户
|
||||
await this.addSession(role, session);
|
||||
|
||||
let channelService = self.app.get('channelService');
|
||||
let channel = channelService.getChannel(role.roleId, true);
|
||||
if (channel.getMembers().indexOf(role.roleId) === -1) {
|
||||
channel.add(role.roleId, self.app.get('serverId'));
|
||||
}
|
||||
|
||||
// put user into channel
|
||||
// console.log(JSON.stringify(self.app.rpc.battle))
|
||||
// await self.app.rpc.battle.battleRemote.add.route(session)(role.roleId, self.app.get('serverId'), role.serverId, true);
|
||||
addRoleToSysChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||
addRoleToWorldChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||
await self.app.rpc.chat.chatRemote.addWorldChannel.route(session)(role.roleId, serverId, self.app.get('serverId'));
|
||||
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
await chackFunOpenWhenLogin(role, session);
|
||||
if (role.hasInit) await loginRefresh(role.roleId);
|
||||
reportOneOnline(role.roleId, user.userCode, self.app.get('serverId'), user.pkgName);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
r.setRankWithRoleInfo(role.roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
let r2 = new Rank(REDIS_KEY.SUM_CE_RANK, { serverId });
|
||||
r2.setRankWithRoleInfo(role.roleId, role.lv, role.updatedAt.getTime(), role);
|
||||
|
||||
// 任务
|
||||
checkTaskWithRole(serverId, role.roleId, self.app.get('serverId'), role.funcs, TASK_TYPE.LOGIN_SUM, role);
|
||||
checkTaskWithRole(serverId, role.roleId, self.app.get('serverId'), role.funcs, TASK_TYPE.LOGIN_SERIES, role);
|
||||
// 推送数据
|
||||
pushData(role, session);
|
||||
|
||||
role['heros'] = heros;
|
||||
role['equips'] = equips;
|
||||
role['consumeGoods'] = items;
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
role.heads = role.heads.filter(cur => cur.status);
|
||||
role.frames = role.frames.filter(cur => cur.status);
|
||||
role.spines = role.spines.filter(cur => cur.status);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { role });
|
||||
}
|
||||
|
||||
async addSession(role: RoleType, session: FrontendSession) {
|
||||
const self = this;
|
||||
await session.abind(role.roleId);
|
||||
session.set('uid', role.roleId);
|
||||
session.set('roleId', role.roleId);
|
||||
@@ -87,82 +134,6 @@ export class EntryHandler {
|
||||
// }
|
||||
// });
|
||||
session.on('closed', this.onUserLeave.bind(this));
|
||||
|
||||
let channelService = self.app.get('channelService');
|
||||
let channel = channelService.getChannel(role.roleId, true);
|
||||
if (channel.getMembers().indexOf(role.roleId) === -1) {
|
||||
channel.add(role.roleId, self.app.get('serverId'));
|
||||
}
|
||||
|
||||
// put user into channel
|
||||
// console.log(JSON.stringify(self.app.rpc.battle))
|
||||
// await self.app.rpc.battle.battleRemote.add.route(session)(role.roleId, self.app.get('serverId'), role.serverId, true);
|
||||
addRoleToSysChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||
addRoleToWorldChannel(role.roleId, self.app.get('serverId'), role.serverId);
|
||||
await self.app.rpc.chat.chatRemote.addWorldChannel.route(session)(role.roleId, serverId, self.app.get('serverId'));
|
||||
let heros = await HeroModel.findByRole(role.roleId, [], HERO_SELECT.ENTRY, true);
|
||||
let equips = await EquipModel.findbyRole(role.roleId);
|
||||
let items = await ItemModel.findbyRole(role.roleId);
|
||||
let mails = await getMails(role.roleId, serverId)
|
||||
await chackFunOpenWhenLogin(role, session);
|
||||
if (role.hasInit) await loginRefresh(role.roleId);
|
||||
reportOneOnline(role.roleId, user.userCode, self.app.get('serverId'), user.pkgName);
|
||||
|
||||
let r = new Rank(REDIS_KEY.HERO_NUM_RANK, { serverId });
|
||||
r.setRankWithRoleInfo(role.roleId, role.heroNum, role.heroNumUpdatedAt, role);
|
||||
let r2 = new Rank(REDIS_KEY.SUM_CE_RANK, { serverId });
|
||||
r2.setRankWithRoleInfo(role.roleId, role.lv, role.updatedAt.getTime(), role);
|
||||
|
||||
// 任务
|
||||
checkTaskWithRole(serverId, role.roleId, self.app.get('serverId'), role.funcs, TASK_TYPE.LOGIN_SUM, role);
|
||||
checkTaskWithRole(serverId, role.roleId, self.app.get('serverId'), role.funcs, TASK_TYPE.LOGIN_SERIES, role);
|
||||
// 推送数据
|
||||
pushData(role, session);
|
||||
|
||||
role['heros'] = heros;
|
||||
role['equips'] = equips;
|
||||
role['consumeGoods'] = items;
|
||||
let apJson = await getAp(Date.now(), role.roleId);
|
||||
role['apJson'] = apJson;
|
||||
role['mails'] = mails;
|
||||
if (!role.showLineup) role.showLineup = role.topLineup.map(cur => cur.hid);
|
||||
role.heads = role.heads.filter(cur => cur.status);
|
||||
role.frames = role.frames.filter(cur => cur.status);
|
||||
role.spines = role.spines.filter(cur => cur.status);
|
||||
|
||||
const recentPrivateChats = await recentPrivateChatInfos(role.roleId, role.roleName);
|
||||
if (recentPrivateChats) {
|
||||
role['recentPrivateChats'] = recentPrivateChats;
|
||||
}
|
||||
role['worldMsgs'] = await recentWorldMsgs(role.serverId);
|
||||
role['sysMsgs'] = await recentSysMsgs(role.serverId);
|
||||
|
||||
if (role.hasGuild) {
|
||||
let userGuild = await UserGuildModel.getMyGuild(role.roleId, USER_GUILD_SELECT.ENTRY);
|
||||
if (userGuild) {
|
||||
let guild = await GuildModel.findGuild(userGuild.guildCode, role.serverId, GUILD_SELECT.ENTRY);
|
||||
if (guild) {
|
||||
addRoleToGuildChannel(role.roleId, self.app.get('serverId'), userGuild.guildCode);
|
||||
role['guildMsgs'] = await recentGuildMsgs(userGuild.guildCode);
|
||||
role['guildAuth'] = userGuild.auth;
|
||||
role['guildCode'] = userGuild.guildCode;
|
||||
let { lv: guildLv, memberCnt } = guild;
|
||||
let dicGuild = gameData.centerBase.get(guildLv);
|
||||
if (dicGuild && memberCnt >= dicGuild.peopleNum) {
|
||||
role['guildMemberMax'] = true;
|
||||
} else {
|
||||
role['guildMemberMax'] = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 任务
|
||||
let { mainTask, dailyTask, achievement } = await getCurTask(role.roleId, session);
|
||||
role['mainTask'] = mainTask;
|
||||
role['dailyTask'] = dailyTask;
|
||||
role['achievement'] = achievement;
|
||||
|
||||
return resResult(STATUS.SUCCESS, { role });
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,12 +3,10 @@ import { MailModel } from '../../../db/Mail';
|
||||
import { GroupMailModel } from '../../../db/GroupMail';
|
||||
import { resResult } from '../../../pubUtils/util';
|
||||
import { STATUS } from '../../../consts/statusCode';
|
||||
import { findWhere } from 'underscore';
|
||||
import { MAIL_STATUS, MAIL_TEM_TYPE, MAIL_TYPE } from '../../../consts/constModules/mailConst';
|
||||
import { handleCost, addItems } from '../../../services/rewardService';
|
||||
import { mongoose } from '@typegoose/typegoose';
|
||||
const { ObjectId } = mongoose.Types;
|
||||
import { addItems } from '../../../services/rewardService';
|
||||
import { nowSeconds } from '../../../pubUtils/timeUtil';
|
||||
import { getMails } from '../../../services/mailService';
|
||||
export default function(app: Application) {
|
||||
return new MailHandler(app);
|
||||
}
|
||||
@@ -18,6 +16,14 @@ export class MailHandler {
|
||||
|
||||
}
|
||||
|
||||
public async getMails(msg:{}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const serverId: number = session.get('serverId');
|
||||
|
||||
const list = await getMails(roleId, serverId);
|
||||
return resResult(STATUS.SUCCESS, { list });
|
||||
}
|
||||
|
||||
public async refrshMails(msg:{}) {
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { Application, BackendSession } from "pinus";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, REDIS_KEY, RANK_TYPE_TO_KEY, ROLE_SELECT, RANK_TYPE, HERO_SELECT, GUILD_SELECT } from "../../../consts";
|
||||
import { STATUS, RANK_TYPE_TO_KEY, ROLE_SELECT, RANK_TYPE, HERO_SELECT, GUILD_SELECT } from "../../../consts";
|
||||
import { RoleModel } from "../../../db/Role";
|
||||
import { UserGuildModel } from "../../../db/UserGuild";
|
||||
import { GuildModel } from "../../../db/Guild";
|
||||
import { UserModel } from "../../../db/User";
|
||||
import { Rank } from "../../../services/rankService";
|
||||
import { Rank, getGeneralRank } from "../../../services/rankService";
|
||||
import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
import { GeneralRankParamRole, GeneralRankParamBattle, RoleRankInfo } from "../../../domain/rank";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { addItems } from "../../../services/rewardService";
|
||||
import { HeroModel, HeroUpdate } from "../../../db/Hero";
|
||||
@@ -29,39 +27,7 @@ export class RoleHandler {
|
||||
let role = await RoleModel.findByRoleId(roleId, 'rankReceived');
|
||||
if(!role) return resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let res = await getGeneralRank(role, serverId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import { getAtrrNameById } from '../../../consts/constModules/abilityConst'
|
||||
import { findIndex } from 'underscore';
|
||||
import { SclResultInter, SclPosInter } from '../../../pubUtils/interface';
|
||||
import { SchoolModel } from '../../../db/School';
|
||||
import { checkTeraphMaterialEnough } from '../../../services/roleService'
|
||||
import { checkTeraphMaterialEnough, getSchoolList } from '../../../services/roleService'
|
||||
import { calPlayerCeAndSave, calAllHeroCe } from '../../../services/playerCeService';
|
||||
import { HERO_SYSTEM_TYPE, LINEUP_NUM, ROLE_SELECT, REDIS_KEY, TASK_TYPE, DEFAULT_HEROES, DEFAULT_HERO_LV, DEFAULT_ITEMS, DEFAULT_EQUIPS, DEFAULT_GOLD, DEFAULT_COIN } from '../../../consts';
|
||||
import { checkBattleHeroesByHid } from '../../../services/normalBattleService';
|
||||
@@ -189,38 +189,7 @@ export class RoleHandler {
|
||||
// 获得百家学宫
|
||||
async getSchoolList(msg: {}, session: BackendSession) {
|
||||
let roleId = session.get('roleId');
|
||||
|
||||
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
|
||||
});
|
||||
});
|
||||
let school = await getSchoolList(roleId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, { school });
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ import { gameData } from "../../../pubUtils/data";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GUILD_STRUCTURE, ITID, CONSUME_TYPE, HERO_QUALITY_TYPE, HERO_GROW_MAX } from "../../../consts";
|
||||
import { DicShopListModel } from "../../../db/DicShopList";
|
||||
import { ShopItem } from "../../../domain/dbGeneral";
|
||||
import { ShopItemListParam } from '../../../domain/roleField/shop';
|
||||
import { UserShopModel } from "../../../db/UserShop";
|
||||
import { handleCost, addItems } from "../../../services/rewardService";
|
||||
import { GuildModel } from "../../../db/Guild";
|
||||
import { SHOP } from "../../../pubUtils/dicParam";
|
||||
import { getHonourObject } from "../../../pubUtils/itemUtils";
|
||||
import { HeroModel } from "../../../db/Hero";
|
||||
import { getShopListById } from "../../../services/shopService";
|
||||
|
||||
export default function(app: Application) {
|
||||
return new ShopHandler(app);
|
||||
@@ -29,46 +28,7 @@ export class ShopHandler {
|
||||
return resResult(STATUS.WRONG_PARMS);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
const shopItemList = await getShopListById(shopId, roleId);
|
||||
return resResult(STATUS.SUCCESS, { shopItemList });
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,13 @@ export class ShopHandler {
|
||||
constructor(private app: Application) {
|
||||
}
|
||||
|
||||
public async getTaskList(msg:{}, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
const res = await getCurTask(roleId, session);
|
||||
return resResult(STATUS.SUCCESS, res);
|
||||
}
|
||||
|
||||
// 领取主线任务、每日任务、成就单条任务
|
||||
async receiveTask(msg: { type: number, id: number }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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 }
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据存下的战力获取当前远征关卡的对手
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活动页签里的限时卡池
|
||||
*
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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人阵容
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
58
game-server/app/services/shopService.ts
Normal file
58
game-server/app/services/shopService.ts
Normal 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;
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
export enum ROLE_SELECT {
|
||||
// 初始登录数据
|
||||
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineup topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spines spine guildCode frdCnt showLineup updatedAt heroNum heroNumUpdatedAt loginTime hasInit',
|
||||
ENTRY = 'serverId userInfo.uid userInfo.tel userInfo.serverType ce topLineup topLineupCe teraphs roleId roleName tili lv exp gold coin vLv title hasGuild funcs eventStatus heads head frames frame spines spine guildCode frdCnt showLineup updatedAt heroNum heroNumUpdatedAt loginTime hasInit rankReceived',
|
||||
// 玩家列表显示基础数据
|
||||
SHOW_SIMPLE = 'roleId roleName ce head frame spine lv title job quitTime loginTime vLv guildName serverId userInfo.serverType',
|
||||
// 显示申请需要的信息
|
||||
|
||||
@@ -83,7 +83,8 @@ export default class Activity_Pop_Up_Shop extends BaseModel {
|
||||
}
|
||||
|
||||
//删除活动领取记录
|
||||
public static async deleteActivity(_serverId: number, activityId: number, roleId: string, id: number) {
|
||||
public static async deleteActivity(serverId: number, activityId: number, roleId: string, id: number) {
|
||||
console.log(serverId)
|
||||
let nowDate = new Date();
|
||||
await ActivityPopUpShopModel.deleteMany({
|
||||
roleId, activityId, id,
|
||||
|
||||
Reference in New Issue
Block a user