✨ feat(军团): 修改boss和城门血条逻辑
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { ServerlistModel, ServerlistType } from "../../db/Serverlist";
|
||||
import { RoleModel } from "../../db/Role";
|
||||
import { GUILDACTIVITY } from "../../pubUtils/dicParam";
|
||||
import { gameData, getCityActivityRewards } from "../../pubUtils/data";
|
||||
import { getCurDay, nowSeconds, getTimeFun, getZeroPoint } from "../../pubUtils/timeUtil";
|
||||
import { GUILD_ACTIVITY_STATUS, GET_POINT_WAYS, GUILD_ACTIVITY_TYPE, REDIS_KEY, AUCTION_SOURCE, MAIL_TYPE, CITY_STATUS, DEBUG_MAGIC_WORD, GUILD_POINT_WAYS, TASK_TYPE, AUCTION_TIME, CITY_ACTIVITY_DOOR, ABI_TYPE, PUSH_ROUTE, RACE_ACTIVITY_STATUS, SHOP_REFRESH_TYPE, COUNTER, RACE_EVENT_TYPE } from "../../consts";
|
||||
import { gameData, getBossHpRatio, getCityActivityRewards } from "../../pubUtils/data";
|
||||
import { getCurDay, nowSeconds, getTimeFun, getZeroPoint, getZeroPointOfTime } from "../../pubUtils/timeUtil";
|
||||
import { GUILD_ACTIVITY_STATUS, GET_POINT_WAYS, GUILD_ACTIVITY_TYPE, REDIS_KEY, AUCTION_SOURCE, MAIL_TYPE, CITY_STATUS, DEBUG_MAGIC_WORD, GUILD_POINT_WAYS, TASK_TYPE, AUCTION_TIME, CITY_ACTIVITY_DOOR, ABI_TYPE, PUSH_ROUTE, RACE_ACTIVITY_STATUS, SHOP_REFRESH_TYPE, COUNTER, RACE_EVENT_TYPE, BOSS_HP_RATIO_TYPE } from "../../consts";
|
||||
import { Record, UserGuildActivityRecModel } from "../../db/UserGuildActivityRec";
|
||||
import { GateMembersRec, CityParam, WoodenHorse, RaceActivityRankParam } from "../../domain/battleField/guildActivity";
|
||||
import { DicGuildActivity } from "../../pubUtils/dictionary/DicGuildActivity";
|
||||
import { getAllServers, getRoleOnlineInfo, redisClient } from "../redisService";
|
||||
import { getAllServers, getRoleOnlineInfo, getServerCreateTime, redisClient } from "../redisService";
|
||||
import { SimpleGuildRankParam, SimpleRoleRankParam, GuildRankInfo, RoleRankInfo } from "../../domain/rank";
|
||||
import { pinus } from "pinus";
|
||||
import { GuildActivityRecordModel } from "../../db/GuildActivityRec";
|
||||
@@ -30,6 +30,8 @@ import { setInterval } from "timers";
|
||||
import { dispatch } from "../../pubUtils/dispatcher";
|
||||
import { GuildModel } from "../../db/Guild";
|
||||
import { getCityActivityObj, getGateActivityObj, getRaceActivityObj } from "../memoryCache/guildActivityData";
|
||||
import { getBossHpRatioByServer } from "../guildBossService";
|
||||
import { getHeroesAttributes } from "../playerCeService";
|
||||
|
||||
|
||||
/**
|
||||
@@ -730,49 +732,89 @@ function formatTime(date: Date) {
|
||||
}
|
||||
|
||||
export async function getCityActivityGateHp(serverId: number, cityId: number) {
|
||||
console.log(`getCityActivityGateHp: serverId ${serverId}, cityId ${cityId}`);
|
||||
let dicCityActivity = gameData.cityActivity.get(cityId);
|
||||
let playerResult = await getPlayerCnt(serverId);
|
||||
if (!playerResult) return dicCityActivity.hp
|
||||
let { activePlayerCnt, activeGuildCnt, activePlayerCe, activeTopPlayerCnt, activePlayers } = playerResult;
|
||||
|
||||
// 倍数按开服天数变化
|
||||
let ratio = await getBossHpRatioByServer(BOSS_HP_RATIO_TYPE.CITY_RATIO, serverId);
|
||||
// 单个玩家的平均攻击力
|
||||
let playerAtkResult = await getPlayerAtkAvg(activePlayers);
|
||||
if (!playerAtkResult) return dicCityActivity.hp;
|
||||
let { playerAtkAvg } = playerAtkResult;
|
||||
|
||||
// *单个玩家5回合造成的总伤害=单个玩家的平均攻击力*倍数*5(综合技能次级属性算出的倍数)
|
||||
let player5Damage = playerAtkAvg * ratio * 5;
|
||||
|
||||
// *平均一个军团的玩家人数=前一天参与军团活动的玩家/前一天参与军团活动的军团数量,
|
||||
let guildPlayerCntAvg = await getGuildPlayerCntAvg(serverId, activePlayerCnt, activeGuildCnt);
|
||||
|
||||
// 城池倍数
|
||||
let cityRatio = Math.max(Math.floor(activeGuildCnt/6), dicCityActivity.hpN);
|
||||
|
||||
// 城门血量=单个玩家5回合造成的总伤害*平均一个军团的玩家人数*城池倍数
|
||||
let gateHp = Math.floor(player5Damage * guildPlayerCntAvg * cityRatio);
|
||||
if(gateHp <= dicCityActivity.hp) {
|
||||
gateHp = dicCityActivity.hp;
|
||||
}
|
||||
|
||||
saveGuildGateHpLog(serverId, cityId, { activePlayerCnt, activePlayerCe, activeTopPlayerCnt, activeGuildCnt, ratio, playerAtkAvg, player5Damage, guildPlayerCntAvg, cityRatio, gateHp });
|
||||
|
||||
return gateHp;
|
||||
}
|
||||
|
||||
// *单个玩家的平均攻击力=本服活跃玩家中最强6人排名前10的玩家的最强6人的攻击之和/10
|
||||
async function getPlayerAtkAvg(activePlayers: ActivePlayer[]) {
|
||||
if (!activePlayers || activePlayers.length <= 0) return false;
|
||||
let playerAtkSum = 0, playerCnt = 0;
|
||||
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 = [] } = 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++;
|
||||
}
|
||||
if (playerCnt == 0) return false;
|
||||
let playerAtkAvg = playerAtkSum / playerCnt * 10;
|
||||
return { playerAtkAvg, playerCnt };
|
||||
}
|
||||
|
||||
async function getGuildPlayerCntAvg (serverId: number, activePlayerCnt: number, activeGuildCnt: number) {
|
||||
let minRatio = await getBossHpRatioByServer(BOSS_HP_RATIO_TYPE.CITY_PLAYER_RATIO, serverId);
|
||||
let guildPlayerCntAvg = Math.floor(activePlayerCnt / activeGuildCnt);
|
||||
if (guildPlayerCntAvg < minRatio) return minRatio;
|
||||
return guildPlayerCntAvg
|
||||
}
|
||||
|
||||
async function getPlayerCnt(serverId: number) {
|
||||
|
||||
let serverRecord = await ServerRecordModel.findTodayData(serverId);
|
||||
if(!serverRecord) return dicCityActivity.hp;
|
||||
if(!serverRecord) return false;
|
||||
|
||||
let activePlayerCnt = 50; // 前一天参与军团活动的玩家
|
||||
let activeGuildCnt = 5; // 前一天参与军团活动的军团
|
||||
let activePlayerCe = 0; // 前一天前十玩家的最强战力和
|
||||
let activeTopPlayerCnt = 1; // 前一天最强玩家数量
|
||||
let activePlayers: ActivePlayer[] = [];
|
||||
if(serverRecord) {
|
||||
if(serverRecord.activePlayerCe > 0) activePlayerCe = serverRecord.activePlayerCe;
|
||||
if(serverRecord.activePlayers?.length > 0) activeTopPlayerCnt = serverRecord.activePlayers?.length;
|
||||
if(serverRecord.activePlayers?.length > 0) {
|
||||
activeTopPlayerCnt = serverRecord.activePlayers?.length;
|
||||
activePlayers = serverRecord.activePlayers||[];
|
||||
}
|
||||
if(serverRecord.activeGuildCodes?.length > 0) activeGuildCnt = serverRecord.activeGuildCodes?.length;
|
||||
if(serverRecord.activeGuildMembers?.length > 0) activePlayerCnt = serverRecord.activeGuildMembers?.length;
|
||||
}
|
||||
console.log(`getCityActivityGateHp: activePlayerCnt ${activePlayerCnt}, activePlayerCe ${activePlayerCe}, activeTopPlayerCnt ${activeTopPlayerCnt} activeGuildCnt ${activeGuildCnt}`);
|
||||
|
||||
let atk = dicCityActivity.atkTemplate||0;
|
||||
console.log(`getCityActivityGateHp: atk ${atk}`);
|
||||
|
||||
let A = activePlayerCe/activeTopPlayerCnt/6/GUILDACTIVITY.GATEACTIVITY_ENEMYCE;
|
||||
if(A < 1) A = 1;
|
||||
console.log(`getCityActivityGateHp: A ${A}`);
|
||||
|
||||
let gateHpBase = A * atk;
|
||||
let N = dicCityActivity.hpN;
|
||||
|
||||
console.log(`getCityActivityGateHp: gateHpBase ${gateHpBase}, N ${N}`);
|
||||
|
||||
let playerGuildRatio = activePlayerCnt/activeGuildCnt;
|
||||
if(playerGuildRatio < dicCityActivity.playerCount) playerGuildRatio = dicCityActivity.playerCount;
|
||||
|
||||
let gateHp = Math.floor(gateHpBase * playerGuildRatio * N);
|
||||
console.log(`getCityActivityGateHp: gateHp ${gateHp}`);
|
||||
|
||||
|
||||
saveGuildGateHpLog(serverId, cityId, { activePlayerCnt, activePlayerCe, activeTopPlayerCnt, activeGuildCnt, atk, A, hpBase: gateHpBase, N, gateHp, playerGuildRatio });
|
||||
|
||||
if(gateHp <= dicCityActivity.hp) {
|
||||
gateHp = dicCityActivity.hp;
|
||||
}
|
||||
return gateHp;
|
||||
return { activePlayerCnt, activeGuildCnt, activePlayerCe, activeTopPlayerCnt, activePlayers }
|
||||
}
|
||||
|
||||
export async function declareCity(serverId: number, roleId: string, guildCode: string, cityId: number, isAutoDeclare: boolean, declareIndex: number) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user