✨ feat(军团): 修改boss和城门血条逻辑

This commit is contained in:
luying
2023-09-19 20:14:04 +08:00
parent e8ba038bb5
commit 9797f41652
10 changed files with 330 additions and 89 deletions
+65 -32
View File
@@ -1,24 +1,25 @@
import { BossInstanceType, BossInstanceModel } from '../db/BossInstance';
import { lockData } from '../services/redLockService';
import { findIndex, pick } from 'underscore';
import { sismemberAsync, smembersAsync, saddAsync, delAsync, getRoleOnlineInfo } from '../services/redisService';
import { sismemberAsync, smembersAsync, saddAsync, delAsync, getRoleOnlineInfo, getServerCreateTime } from '../services/redisService';
import { pinus } from 'pinus';
import { STATUS } from '../consts/statusCode';
import { resResult, shouldRefresh } from '../pubUtils/util';
import { BattleRecordModel } from '../db/BattleRecord';
import { getArmyBossRank, gameData } from '../pubUtils/data';
import { getArmyBossRank, gameData, getBossHpRatio } from '../pubUtils/data';
import { sendMailToGuildByContent } from '../services/mailService';
import { MAIL_TYPE, AUCTION_SOURCE, ABI_TYPE, PUSH_ROUTE } from '../consts';
import { MAIL_TYPE, AUCTION_SOURCE, ABI_TYPE, PUSH_ROUTE, BOSS_HP_RATIO_TYPE } 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';
import { nowSeconds } from '../pubUtils/timeUtil';
import { getZeroPoint, getZeroPointOfTime, nowSeconds } from '../pubUtils/timeUtil';
import { GUILDACTIVITY } from '../pubUtils/dicParam';
import { ServerRecordModel } from '../db/ServerRecords';
import { GuildRecord, ServerRecordModel } from '../db/ServerRecords';
import { sendMessageToGuildWithSuc, sendMessageToUsersWithSuc } from './pushService';
import { AttributeCal } from '../domain/roleField/attribute';
import { saveGuildBossHpLog } from '../pubUtils/logUtil';
import { getHeroesAttributes } from './playerCeService';
/**
* 获得boss界面
@@ -196,33 +197,21 @@ export async function getBossHp(serverId: number, guildCode: string, dicBossBase
let serverRecord = await ServerRecordModel.findTodayData(serverId);
if(!serverRecord) return { ratio: 1, bossHp: zoomInDamage(minBossHp) };
let dicWar = gameData.war.get(warId);
let dicWarJson = gameData.warJson.get(dicWar.dispatchJsonId);
let actorId = gameData.heroIdByWar.get(warId);
let dicBoss = dicWarJson.find(cur => cur.actorId == actorId);
let attribute = dicBoss?.attribute||[];
let hp = attribute.find(cur => cur.id == ABI_TYPE.ABI_HP)?.val||0;
console.log(`getBossHp warId ${warId} hp ${hp}`);
let activeGuilds = serverRecord.activeGuilds||[];
let myGuild = activeGuilds.find(cur => cur.guildCode == guildCode);
let activeCe = 0, playerCnt = 0;
if(myGuild) {
let activePlayers = myGuild.players||[];
activePlayers.sort((a, b) => b.ce - a.ce);
for(let i = 0; i < 10; i++) {
if(!activePlayers[i]) break;
activeCe += activePlayers[i].topLineupCe;
playerCnt ++;
}
}
if(playerCnt == 0) return { ratio: 1, bossHp: zoomInDamage(minBossHp) };
let subCe = getBossSubAttrCe(actorId, dicWar.secondAttrLevel, bossLv)
console.log(`getBossHp activeCe ${activeCe} playerCnt ${playerCnt} subCe ${subCe}`);
let B = (activeCe/playerCnt/6 - subCe)/GUILDACTIVITY.GATEACTIVITY_ENEMYCE;
let bossBaseHp = B * hp;
let bossHp = Math.floor(bossBaseHp * bossHpRatio);
let playerAtkResult = await getPlayerAtkAvg(myGuild);
if (!playerAtkResult) return { ratio: 1, bossHp: zoomInDamage(minBossHp) };
// *军团的玩家人数=开启前一天军团内登录的玩家数
// *单个玩家的平均攻击力=军团前一天活跃玩家中最强6人排名前10的玩家的最强6人的攻击之和/10
let { playerAtkAvg, playerCnt, activeCe } = playerAtkResult;
// 倍数按开服天数变化
let ratio = await getBossHpRatioByServer(BOSS_HP_RATIO_TYPE.BOSS_RATIO, serverId);
// *单个玩家10回合造成的总伤害=单个玩家的平均攻击力*倍数*10
let player10Damage = playerAtkAvg * ratio * 10;
// boss血量=单个玩家10回合造成的总伤害*军团的玩家人数*2
let bossHp = Math.floor(player10Damage * playerCnt * 2);
let B = getB(warId, bossLv, activeCe, playerCnt);
if(B < 1) {
B = 1;
bossHp = minBossHp;
@@ -231,11 +220,55 @@ export async function getBossHp(serverId: number, guildCode: string, dicBossBase
B = 1;
bossHp = minBossHp;
}
console.log(`getBossHp B ${B}`);
saveGuildBossHpLog(serverId, warId, guildCode, { minBossHp, bossHpRatio, hp, activeCe, playerCnt, subCe, B, bossHp })
saveGuildBossHpLog(serverId, warId, guildCode, { minBossHp, bossHpRatio, ratio, playerAtkAvg, player10Damage, activeCe, playerCnt, B, bossHp })
return { ratio: B, bossHp: zoomInDamage(bossHp) };
}
function getB(warId: number, bossLv: number, activeCe: number, playerCnt: number) {
let dicWar = gameData.war.get(warId);
if (!dicWar) return 1;
let actorId = gameData.heroIdByWar.get(warId);
let subCe = getBossSubAttrCe(actorId, dicWar.secondAttrLevel, bossLv)
let B = (activeCe/playerCnt/6 - subCe)/GUILDACTIVITY.GATEACTIVITY_ENEMYCE;
return B;
}
async function getPlayerAtkAvg(myGuild: GuildRecord) {
if (!myGuild) return false;
let playerAtkSum = 0, playerCnt = 0, activeCe = 0;
if (myGuild) {
let activePlayers = myGuild.players || [];
activePlayers.sort((a, b) => b.ce - a.ce);
for (let i = 0; i < 10; i++) {
if (!activePlayers[i]) break;
let onePlayerAtkSum = 0, heroCnt = 0;
let { roleId, topLineup = [], topLineupCe = 0 } = activePlayers[i];
let attrByHid = await getHeroesAttributes(roleId);
for (let { hid } of topLineup) {
let atk = attrByHid.get(hid)?.getAtk() || 0;
onePlayerAtkSum += atk;
heroCnt++;
}
if (heroCnt == 0) continue; // 基本不可能,但是以防NaN
playerAtkSum += onePlayerAtkSum / heroCnt * 6;
playerCnt++;
activeCe += topLineupCe;
}
}
if (playerCnt == 0) return false;
let playerAtkAvg = playerAtkSum / playerCnt * 10;
return { playerAtkAvg, playerCnt, activeCe };
}
export async function getBossHpRatioByServer(type: BOSS_HP_RATIO_TYPE, serverId: number) {
let serverOpenTime = await getServerCreateTime(serverId);
let serverZeroPoint = getZeroPointOfTime(serverOpenTime);
let todayZeroPoint = getZeroPoint();
let n = Math.floor((todayZeroPoint - serverZeroPoint)/86400) + 1;
return getBossHpRatio(type, n);
}
export function zoomInDamage(damage: number, ratio = 100) {
return Math.floor(damage * ratio);
}