演武台:鼓舞,次数限制,掉落修改,结构修改
This commit is contained in:
@@ -1,94 +1,101 @@
|
||||
import { BossInstanceType, BossInstanceModel } from '../db/BossInstance';
|
||||
import { getZeroPoint } from '../pubUtils/timeUtil';
|
||||
import { lockData } from '../services/redLockService';
|
||||
import { findIndex } from 'underscore';
|
||||
import { MailType } from '../db/Mail';
|
||||
import { sismemberAsync, smembersAsync, saddAsync, delAsync, getRoleOnlineInfo } from '../services/redisService';
|
||||
import { pinus } from 'pinus';
|
||||
import { STATUS } from '../consts/statusCode';
|
||||
import { deepCopy, resResult } from '../pubUtils/util';
|
||||
import { resResult, shouldRefresh } from '../pubUtils/util';
|
||||
import { BattleRecordModel } from '../db/BattleRecord';
|
||||
import { getArmyBossRank, gameData, getAuctionRewardByPoolId } from '../pubUtils/data';
|
||||
import { sendMailByContent } from '../services/mailService';
|
||||
import { pushMail } from '../pubUtils/interface';
|
||||
import { sendMailToGuildByContent } from '../services/mailService';
|
||||
import { MAIL_TYPE, AUCTION_SOURCE } from '../consts';
|
||||
import { GUILD_BOSS_STATUS } from '../consts/constModules/guildConst';
|
||||
import { genAuction } from './auctionService';
|
||||
import { GuildModel, GuildType } from '../db/Guild';
|
||||
import { UserGuildModel, UserGuildType } from '../db/UserGuild';
|
||||
|
||||
/**
|
||||
* 获得boss界面
|
||||
* @param bossInstance
|
||||
* @param roleId
|
||||
*/
|
||||
export async function getBossInstanceInfo(bossInstance: BossInstanceType, roleId:string) {
|
||||
let { warId, ranks, bossHp, bossLv, winWarId, winTime, roleIdRecords, guildCode, startTime, winBossLv } = bossInstance;
|
||||
export async function getBossInstanceInfo(guildCode: string, roleId:string, userGuild: UserGuildType, guild?: GuildType) {
|
||||
let bossInstance = await BossInstanceModel.findBossInstance(guildCode);
|
||||
if(!guild) guild = await GuildModel.findByCode(guildCode, null, 'code refOpenBossTime openBossCnt');
|
||||
|
||||
let refObj = await getRefBossCnt(guild, userGuild); // 刷新次数
|
||||
let showParamObj = await getLastBossInstance(bossInstance, guildCode, roleId);
|
||||
if(bossInstance) {
|
||||
let { warId, ranks, bossHp, bossLv, status, encourageCnt } = bossInstance;
|
||||
let dicBossBase = gameData.bossBaseByBossLv.get(bossLv);
|
||||
let rankInfo = getRanks(ranks, roleId);
|
||||
// 此处showParamObj一定要放在最前
|
||||
return { ...showParamObj, warId, ...rankInfo, bossHp, status, bossLv, encourageCnt, encourageMax: dicBossBase.encourageSum,...refObj };
|
||||
} else {
|
||||
return showParamObj;
|
||||
}
|
||||
}
|
||||
|
||||
async function getRefBossCnt(guild: GuildType, userGuild: UserGuildType) {
|
||||
let guildCnt = await refreshGuildOfBoss(guild);
|
||||
let userGuildCnt = await refreshUserGuildOfBoss(userGuild);
|
||||
return { ...guildCnt, ...userGuildCnt }
|
||||
}
|
||||
|
||||
export async function refreshGuildOfBoss(guild: GuildType, inc: number = 0) {
|
||||
let { refOpenBossTime, openBossCnt } = guild;
|
||||
if(shouldRefresh(refOpenBossTime, new Date())) {
|
||||
openBossCnt = 0;
|
||||
}
|
||||
if(inc != 0) {
|
||||
guild = await GuildModel.updateInfo(guild.code, { refOpenBossTime: new Date(), openBossCnt: openBossCnt + inc });
|
||||
openBossCnt = guild.openBossCnt;
|
||||
}
|
||||
return { leaderOpenCnt: openBossCnt }
|
||||
}
|
||||
export async function refreshUserGuildOfBoss(userGuild: UserGuildType, incEncourage = 0, incChallenge = 0) {
|
||||
let { refBossTime, encourageCnt, bossChallengeCnt } = userGuild;
|
||||
if(shouldRefresh(refBossTime, new Date())) {
|
||||
encourageCnt = 0, bossChallengeCnt = 0;
|
||||
}
|
||||
if(incEncourage != 0 || incChallenge != 0) {
|
||||
userGuild = await UserGuildModel.updateInfo(userGuild.roleId, { refBossTime: new Date(), encourageCnt: encourageCnt + incEncourage, bossChallengeCnt: bossChallengeCnt + incChallenge }, {});
|
||||
encourageCnt = userGuild.encourageCnt;
|
||||
bossChallengeCnt = userGuild.bossChallengeCnt;
|
||||
}
|
||||
return { myChallengeCnt: bossChallengeCnt, myEncourageCnt: encourageCnt }
|
||||
|
||||
}
|
||||
|
||||
export function getRanks(ranks: {roleId: string; score: number; time: number; job: number;}[], roleId: string ) {
|
||||
ranks.sort(function(a, b) {
|
||||
return b.score - a.score + a.time - b.time;
|
||||
});
|
||||
let result:any = {};
|
||||
if (!!winWarId && winTime > getZeroPoint() && roleIdRecords.indexOf(roleId) == -1) {
|
||||
//今日通关过,且首次点开boss界面,提示某某boss已通关
|
||||
result = { showParam: { winWarId, winBossLv } };
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(guildCode, roleId);
|
||||
}
|
||||
if ( bossHp <= 0 ) {
|
||||
result = { warId };
|
||||
if (startTime < getZeroPoint()) {
|
||||
//今日未开启过boss,等待开启
|
||||
result.status = GUILD_BOSS_STATUS.WAIT_OPEN;
|
||||
return result;
|
||||
} else {
|
||||
//今日已开启,且boss通关
|
||||
result.status = GUILD_BOSS_STATUS.OPENED;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
let isBattled = false;
|
||||
|
||||
let myRank = {};
|
||||
let lastRanks = ranks.map(({roleId: battleRoleId, score, time}, index) => {
|
||||
let lastRanks = ranks.map(({roleId: battleRoleId, score }, index) => {
|
||||
if (roleId == battleRoleId) {
|
||||
myRank = { roleId, score, rankLv: index + 1 };
|
||||
if (time >= getZeroPoint())
|
||||
isBattled = true;
|
||||
}
|
||||
return {roleId, score, rankLv: index + 1};
|
||||
});
|
||||
return { warId, ranks: lastRanks, myRank, bossHp, status: GUILD_BOSS_STATUS.OPEN, isBattled, bossLv };
|
||||
return { ranks: lastRanks, myRank }
|
||||
}
|
||||
/**
|
||||
* 战斗结束返回
|
||||
* @param bossInstance
|
||||
* @param roleId
|
||||
* @param battleNum
|
||||
*/
|
||||
export async function getBossInstanceWhenEnd(bossInstance: BossInstanceType, roleId:string, battleNum:number) {
|
||||
let { warId, ranks, bossHp, winWarId, guildCode, recordRanks, winNum, bossLv, winBossLv } = bossInstance;
|
||||
let pushRanks;
|
||||
let result:any = {};
|
||||
if (battleNum == winNum) { //检查当前战斗回调是否是上一次战斗的回调,若是返回上次排名的结果
|
||||
pushRanks = deepCopy(recordRanks);
|
||||
result = {warId: winWarId, bossHp: 0, bossLv: winBossLv, status: GUILD_BOSS_STATUS.OPEN};
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(guildCode, roleId);
|
||||
} else {
|
||||
pushRanks = deepCopy(ranks);
|
||||
result = {warId, bossHp, bossLv, status: GUILD_BOSS_STATUS.OPEN};
|
||||
}
|
||||
pushRanks.sort(function(a, b) {
|
||||
return b.score - a.score + a.time - b.time;
|
||||
});
|
||||
let isBattled = false;
|
||||
let myRank = {};
|
||||
pushRanks.forEach(({roleId: battleRoleId, score, time}, index) => {
|
||||
if (roleId == battleRoleId) {
|
||||
myRank = {roleId, score, rankLv: index + 1};
|
||||
if (time >= getZeroPoint())
|
||||
isBattled = true;
|
||||
|
||||
export async function getLastBossInstance(bossInstance: BossInstanceType, guildCode: string, roleId: string) {
|
||||
if(bossInstance && bossInstance.status == GUILD_BOSS_STATUS.OPEN) return {}
|
||||
|
||||
let lastBossInstance = await BossInstanceModel.findLastOverBossInstance(guildCode);
|
||||
if(lastBossInstance) {
|
||||
if(lastBossInstance.roleIdRecords.indexOf(roleId) == -1) {
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(lastBossInstance.code, roleId);
|
||||
return { status: GUILD_BOSS_STATUS.CLEAR, showParam: { winWarId: lastBossInstance.warId, winBossLv: lastBossInstance.bossLv } }
|
||||
} else {
|
||||
return { status: GUILD_BOSS_STATUS.CLEAR }
|
||||
}
|
||||
return {roleId, score, rankLv: index + 1};
|
||||
});
|
||||
result.myRank = myRank;
|
||||
result.ranks = pushRanks;
|
||||
result.isBattled = isBattled;
|
||||
return result;
|
||||
} else {
|
||||
return { status: GUILD_BOSS_STATUS.WAIT_OPEN }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,47 +106,40 @@ export async function getBossInstanceWhenEnd(bossInstance: BossInstanceType, rol
|
||||
* @param damage
|
||||
* @param roleId
|
||||
*/
|
||||
export async function bossResult(code: string, serverId: number, dataName: string, roleId: string, damage: number) {
|
||||
let res:any = await lockData(serverId, dataName, code);//加锁
|
||||
export async function checkBossResult(bossCode: string, guildCode: string, serverId: number, dataName: string, roleId: string, damage: number) {
|
||||
let res:any = await lockData(serverId, dataName, guildCode);//加锁
|
||||
if (!!res.err)
|
||||
return true;
|
||||
let {winSettled, ranks, num, warId, bossHp, bossLv, code: bossCode } = await BossInstanceModel.findBossInstance(code);//锁定关卡信息
|
||||
if (winSettled) {
|
||||
let {status, ranks, warId, bossHp, bossLv } = await BossInstanceModel.findByCode(bossCode);//锁定关卡信息
|
||||
if (status == GUILD_BOSS_STATUS.CLEAR) { // 已经被打败了
|
||||
res.releaseCallback();//解锁
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(code, roleId);
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(bossCode, roleId);
|
||||
return true;
|
||||
}
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index == -1) {
|
||||
if (index == -1) { // 没有调用过battleBoss
|
||||
res.releaseCallback();//解锁
|
||||
return false;
|
||||
}
|
||||
ranks[index].score += bossHp;
|
||||
ranks[index].score += bossHp; // 可能会把hp扣成负的,然后排行榜多加了,这里矫正回来
|
||||
if (bossHp > damage) {//检查造成的伤害是否会让boss死亡
|
||||
res.releaseCallback();//解锁
|
||||
return true;
|
||||
}
|
||||
let { recordRanks } = await BossInstanceModel.updateBossInstance(code, { bossHp: 0, winSettled: true, ranks, recordRanks: ranks, winNum: num, winWarId: warId, winBossLv: bossLv, roleIdRecords:[roleId]}, );
|
||||
await pushBossHpMessage(code, serverId, 0, true);
|
||||
await BossInstanceModel.updateBossInstance(bossCode, { bossHp: 0, status: GUILD_BOSS_STATUS.CLEAR, ranks, roleIdRecords:[roleId]}, );
|
||||
await pushBossHpMessage(guildCode, serverId, 0, true);
|
||||
res.releaseCallback();//数据修改解锁
|
||||
recordRanks.sort(function(a, b) {
|
||||
return b.score - a.score + a.time - b.time;
|
||||
});
|
||||
//下发邮件奖励
|
||||
recordRanks.forEach(async function({ roleId }, index){
|
||||
let rankLv = index + 1;
|
||||
let goods = getArmyBossRankReward(rankLv);
|
||||
if (!goods || !goods.length)
|
||||
return;
|
||||
await sendMailByContent(MAIL_TYPE.GUILD_BOSS_REWARD, roleId, {
|
||||
params: [JSON.stringify(rankLv)], goods
|
||||
})
|
||||
});
|
||||
// 加入拍卖行
|
||||
// 击杀奖励&伤害奖励
|
||||
let dicBossBase = gameData.bossBaseByBossLv.get(bossLv);
|
||||
let dicWar = gameData.war.get(warId);
|
||||
await sendMailToGuildByContent(MAIL_TYPE.GUILD_BOSS_REWARD, roleId, {
|
||||
params: [`${dicWar.gk_name}`], goods: dicBossBase.killReward
|
||||
});
|
||||
|
||||
// 加入拍卖行
|
||||
if(dicBossBase) {
|
||||
let rewards = getAuctionRewardByPoolId(dicBossBase.rewards);
|
||||
await genAuction(code, AUCTION_SOURCE.BOSS, bossCode, serverId, rewards);
|
||||
await genAuction(guildCode, AUCTION_SOURCE.BOSS, bossCode, serverId, rewards);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user