演武台:结构修改
This commit is contained in:
@@ -20,21 +20,30 @@ import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
* @param bossInstance
|
||||
* @param roleId
|
||||
*/
|
||||
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');
|
||||
export async function getBossInstanceInfo(userGuild: UserGuildType, guild?: GuildType) {
|
||||
let bossInstance = await BossInstanceModel.findBossInstance(userGuild.guildCode);
|
||||
|
||||
if(!bossInstance) {
|
||||
bossInstance = await BossInstanceModel.findLastOverBossInstance(userGuild.guildCode);
|
||||
}
|
||||
return await getBossInstanceInfoByData(bossInstance, userGuild, guild);
|
||||
}
|
||||
|
||||
export async function getBossInstanceInfoByData(bossInstance: BossInstanceType, userGuild: UserGuildType, guild?: GuildType) {
|
||||
if(!guild) guild = await GuildModel.findByCode(userGuild.guildCode, null, 'code refOpenBossTime openBossCnt');
|
||||
|
||||
let refObj = await getRefBossCnt(guild, userGuild); // 刷新次数
|
||||
let showParamObj = await getLastBossInstance(guildCode, roleId);
|
||||
let status = bossInstance? bossInstance.status: GUILD_BOSS_STATUS.WAIT_OPEN;
|
||||
if(status == GUILD_BOSS_STATUS.CLEAR) status = GUILD_BOSS_STATUS.WAIT_OPEN;
|
||||
let bossInfo = null;
|
||||
|
||||
if(bossInstance) {
|
||||
let { warId, ranks, bossHp, bossLv, status, encourageCnt } = bossInstance;
|
||||
let { warId, ranks, bossHp, bossLv, 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, ...refObj };
|
||||
let rankInfo = getRanks(ranks, userGuild.roleId);
|
||||
bossInfo = { warId, ...rankInfo, bossHp, bossLv, encourageCnt, encourageMax: dicBossBase.encourageSum };
|
||||
}
|
||||
return { status, bossInfo, ...refObj }
|
||||
}
|
||||
|
||||
async function getRefBossCnt(guild: GuildType, userGuild: UserGuildType) {
|
||||
@@ -83,68 +92,6 @@ export function getRanks(ranks: {roleId: string; score: number; time: number; jo
|
||||
return { ranks: lastRanks, myRank }
|
||||
}
|
||||
|
||||
export async function getLastBossInstance(guildCode: string, roleId: string) {
|
||||
|
||||
let lastBossInstance = await BossInstanceModel.findLastOverBossInstance(guildCode);
|
||||
if(lastBossInstance) {
|
||||
if(lastBossInstance.roleIdRecords.indexOf(roleId) == -1) {
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(lastBossInstance.code, roleId);
|
||||
let { warId } = lastBossInstance;
|
||||
return { status: GUILD_BOSS_STATUS.CLEAR, showParam: { winWarId: lastBossInstance.warId, winBossLv: lastBossInstance.bossLv }, warId }
|
||||
} else {
|
||||
return { status: GUILD_BOSS_STATUS.WAIT_OPEN }
|
||||
}
|
||||
} else {
|
||||
return { status: GUILD_BOSS_STATUS.WAIT_OPEN }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结算战斗
|
||||
* @param code
|
||||
* @param serverId
|
||||
* @param dataName
|
||||
* @param damage
|
||||
* @param roleId
|
||||
*/
|
||||
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 {status, ranks, warId, bossHp, bossLv } = await BossInstanceModel.findByCode(bossCode);//锁定关卡信息
|
||||
if (status == GUILD_BOSS_STATUS.CLEAR) { // 已经被打败了
|
||||
res.releaseCallback();//解锁
|
||||
await BossInstanceModel.recordRoleIdWhenCheck(bossCode, roleId);
|
||||
return true;
|
||||
}
|
||||
let index = findIndex(ranks, {roleId});
|
||||
if (index == -1) { // 没有调用过battleBoss
|
||||
res.releaseCallback();//解锁
|
||||
return false;
|
||||
}
|
||||
ranks[index].score += bossHp; // 可能会把hp扣成负的,然后排行榜多加了,这里矫正回来
|
||||
if (bossHp > damage) {//检查造成的伤害是否会让boss死亡
|
||||
res.releaseCallback();//解锁
|
||||
return true;
|
||||
}
|
||||
await BossInstanceModel.updateBossInstance(bossCode, { bossHp: 0, status: GUILD_BOSS_STATUS.CLEAR, ranks, roleIdRecords:[roleId], killTime: nowSeconds()}, );
|
||||
await pushBossHpMessage(guildCode, serverId, 0, true);
|
||||
res.releaseCallback();//数据修改解锁
|
||||
// 击杀奖励&伤害奖励
|
||||
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(guildCode, AUCTION_SOURCE.BOSS, bossCode, serverId, rewards);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/**
|
||||
* 获得排名区间奖励
|
||||
* @param rankLv
|
||||
|
||||
Reference in New Issue
Block a user