军团活动:诸侯混战城门血量
This commit is contained in:
@@ -311,11 +311,12 @@ export class GuildRemote {
|
||||
* @param cityId 城池
|
||||
* @param gateHp 血条
|
||||
*/
|
||||
public async pushCityGateHp(cityId: number, gateHp: number) {
|
||||
public async pushCityGateHp(cityId: number, gateHp: number, maxHp: number) {
|
||||
try {
|
||||
this.pushMessageToCity(cityId, this.GUILD_CITY_ACT_HP, {
|
||||
cityId,
|
||||
gateHp
|
||||
gateHp,
|
||||
maxHp
|
||||
});
|
||||
} catch(e) {
|
||||
errlogger.error(`remote ${__filename} \n ${e.stack}`);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Application, ChannelService, BackendSession, pinus, HandlerService, } from "pinus";
|
||||
import { GUILD_ACTIVITY_TYPE, STATUS, REDIS_KEY, GUILD_POINT_WAYS, CITY_STATUS, TASK_TYPE, ITEM_CHANGE_REASON } from "../../../consts";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { getGuildActivityStatus, getCityActivityObj, getCityStatus as pubGetCityStatus, getCities, getCityActivityRank, sendSingleCityActEndMsg, getMedianCe } from "../../../services/guildActivity/guildActivityService";
|
||||
import { getGuildActivityStatus, getCityActivityObj, getCityStatus as pubGetCityStatus, getCities, getCityActivityRank, sendSingleCityActEndMsg, getPreDayActiveData } from "../../../services/guildActivity/guildActivityService";
|
||||
import { GuildActivityCityModel } from "../../../db/GuildActivityCity";
|
||||
import { gameData } from "../../../pubUtils/data";
|
||||
import { UserGuildActivityRecModel } from "../../../db/UserGuildActivityRec";
|
||||
@@ -17,6 +17,7 @@ import { Rank } from "../../../services/rankService";
|
||||
import { checkActivityTask, checkTask } from "../../../services/taskService";
|
||||
import { guildInter } from "../../../pubUtils/interface";
|
||||
import { dispatch } from "../../../pubUtils/dispatcher";
|
||||
import { ServerRecordModel } from "../../../db/ServerRecords";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -68,7 +69,7 @@ export class CityActivityHandler {
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if (!dicCity) return resResult(STATUS.DIC_DATA_NOT_FOUND);
|
||||
let obj = getCityActivityObj();
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
let {gateHp, maxHp} = await obj.getGateHpAndInc(serverId, cityId);
|
||||
|
||||
let guildActivityRec = await GuildActivityRecordModel.getRecord(guildCode, serverId, this.aid);
|
||||
if (!guildActivityRec) return resResult(STATUS.WRONG_PARMS);
|
||||
@@ -99,7 +100,7 @@ export class CityActivityHandler {
|
||||
cityId,
|
||||
...statusResult,
|
||||
cityStatus,
|
||||
gateHp,
|
||||
gateHp, maxHp,
|
||||
challengeTime,
|
||||
...ranks
|
||||
});
|
||||
@@ -112,8 +113,6 @@ export class CityActivityHandler {
|
||||
const serverId = session.get('serverId');
|
||||
const guildCode = session.get('guildCode');
|
||||
|
||||
//TODO 权限校验&时间校验
|
||||
|
||||
let { cityId } = msg;
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if (dicCity.preCity.length > 0) return resResult(STATUS.CAN_NOT_DECLARE);
|
||||
@@ -158,7 +157,7 @@ export class CityActivityHandler {
|
||||
|
||||
const dicCity = gameData.cityActivity.get(cityId);
|
||||
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
let { gateHp, maxHp } = await obj.getGateHpAndInc(serverId, cityId);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
@@ -188,6 +187,8 @@ export class CityActivityHandler {
|
||||
|
||||
const dbCities = await GuildActivityCityModel.getAllCities(serverId);
|
||||
let cityStatus = pubGetCityStatus(guildCode, cityId, dicCity, dbCities);
|
||||
// 全服活跃统计
|
||||
await ServerRecordModel.addActiveGuild(serverId, guildCode);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
@@ -195,14 +196,14 @@ export class CityActivityHandler {
|
||||
await checkActivityTask(serverId, sid, roleId, TASK_TYPE.GUILD_ACTIVITY, 1, { aid: this.aid })
|
||||
|
||||
// 前一天中位数战力
|
||||
let medianCe = await getMedianCe(serverId);
|
||||
let medianCe = await getPreDayActiveData(serverId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
code,
|
||||
cityId,
|
||||
cityStatus,
|
||||
...statusResult,
|
||||
gateHp,
|
||||
gateHp, maxHp,
|
||||
guildScore,
|
||||
myScore: 0,
|
||||
medianCe
|
||||
@@ -252,7 +253,7 @@ export class CityActivityHandler {
|
||||
|
||||
const dicCity = gameData.cityActivity.get(cityId);
|
||||
let obj = getCityActivityObj();
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
let { gateHp, maxHp } = await obj.getGateHpAndInc(serverId, cityId);
|
||||
if (gateHp <= 0) return resResult(STATUS.GATE_HP_IS_ZERO);
|
||||
|
||||
let statusResult = getGuildActivityStatus(this.aid);
|
||||
@@ -272,14 +273,14 @@ export class CityActivityHandler {
|
||||
let guildScore = await r.setRankWithGuildInfo(guildCode, damage, Date.now(), null, true);
|
||||
await r.setExpire(tomorrow);
|
||||
|
||||
gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp, -1 * damage);
|
||||
({gateHp, maxHp} = await obj.getGateHpAndInc(serverId, cityId, -1 * damage));
|
||||
if (gateHp <= 0) {
|
||||
// 推送 停止活动并结算奖励
|
||||
await sendSingleCityActEndMsg(cityId, serverId);
|
||||
}
|
||||
// 推送 城门血量
|
||||
let chatSid = await getCityChannelSid(cityId);
|
||||
pinus.app.rpc.chat.guildRemote.pushCityGateHp.toServer(chatSid, cityId, gateHp);
|
||||
pinus.app.rpc.chat.guildRemote.pushCityGateHp.toServer(chatSid, cityId, gateHp, maxHp);
|
||||
await pinus.app.rpc.guild.guildActivityRemote.sendRankToGuilds.broadcast(this.aid);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
@@ -326,7 +327,7 @@ export class CityActivityHandler {
|
||||
let myScore = await myR.getMyScore({ roleId });
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
let { gateHp, maxHp } = await obj.getGateHpAndInc(serverId, cityId);
|
||||
|
||||
return resResult(STATUS.SUCCESS, {
|
||||
isSuccess,
|
||||
@@ -335,6 +336,7 @@ export class CityActivityHandler {
|
||||
guildScore,
|
||||
myScore,
|
||||
gateHp,
|
||||
maxHp,
|
||||
challengeTime: myGuildActivityRec.challengeTime
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, ChannelService, pinus, HandlerService, } from "pinus";
|
||||
import { getMedianCe, getGuildActivityStatus, getRecordScore, getGateActivityObj, participants, getGateActivityRank, getCityActivityObj } from "../../../services/guildActivity/guildActivityService";
|
||||
import { getGuildActivityStatus, getRecordScore, getGateActivityObj, participants, getGateActivityRank, getCityActivityObj } from "../../../services/guildActivity/guildActivityService";
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
import { STATUS, GUILD_ACTIVITY_TYPE, GUILD_POINT_WAYS, ENEMIES_TYPE, GET_POINT_WAYS, TASK_TYPE } from "../../../consts";
|
||||
import { UserGuildActivityRecModel } from "../../../db/UserGuildActivityRec";
|
||||
@@ -16,6 +16,7 @@ import { Rank } from "../../../services/rankService";
|
||||
import { getTimeFun, getZeroPointD } from "../../../pubUtils/timeUtil";
|
||||
import { checkActivityTask, checkTask } from "../../../services/taskService";
|
||||
import { guildInter } from "../../../pubUtils/interface";
|
||||
import { ServerRecordModel } from "../../../db/ServerRecords";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -92,9 +93,8 @@ export class GateActivityHandler {
|
||||
// 返回当前军团总军功
|
||||
let r = new Rank(REDIS_KEY.GATE_ACTIVITY, { serverId }, true);
|
||||
let guildScore = await r.getMyScore({ guildCode });
|
||||
|
||||
// 前一天中位数战力
|
||||
let medianCe = await getMedianCe(serverId);
|
||||
// 全服活跃统计
|
||||
await ServerRecordModel.addActiveGuild(serverId, guildCode);
|
||||
|
||||
// 任务
|
||||
await checkTask(roleId, sid, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
@@ -107,7 +107,6 @@ export class GateActivityHandler {
|
||||
guildScore: guildScore || 0,
|
||||
myScore: 0,
|
||||
challengeCnt: GUILDACTIVITY.GATEACTIVITY_CHALLENGE_TIMES - challengeCnt,
|
||||
medianCe
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import { getGoldObject } from '../../../pubUtils/itemUtils';
|
||||
import { RoleModel } from '../../../db/Role';
|
||||
import { sendMailToGuildByContent } from '../../../services/mailService';
|
||||
import { genAuction } from '../../../services/auctionService';
|
||||
import { getMedianCe } from '../../../services/guildActivity/guildActivityService';
|
||||
import { getPreDayActiveData } from '../../../services/guildActivity/guildActivityService';
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -63,8 +63,9 @@ export class GuildHandler {
|
||||
}
|
||||
let bossBase = getBossByLv(curStructure.lv);
|
||||
let { bossHp: minBossHp, warId } = getRandSingleEelm(bossBase.wars);
|
||||
let medianCe = await getMedianCe(serverId);
|
||||
let bossHp = Math.ceil(medianCe * bossBase.ratio);
|
||||
let medianCe = await getPreDayActiveData(serverId);
|
||||
// let bossHp = Math.ceil(medianCe * bossBase.ratio);
|
||||
let bossHp = 10000;
|
||||
|
||||
console.log('******* openBossInstance', medianCe, bossHp, minBossHp)
|
||||
if(bossHp < minBossHp) bossHp = minBossHp;
|
||||
|
||||
@@ -10,6 +10,7 @@ import { Rank } from "../../../services/rankService";
|
||||
import { checkActivityTask, checkTask } from "../../../services/taskService";
|
||||
import { guildInter } from "../../../pubUtils/interface";
|
||||
import { getGuildChannelSid } from "../../../services/chatService";
|
||||
import { ServerRecordModel } from "../../../db/ServerRecords";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -89,7 +90,8 @@ export class RaceActivityHandler {
|
||||
let events = obj.getEvents(guildCode, woodenHorse.distance);
|
||||
let chatSid = await getGuildChannelSid(guildCode);
|
||||
this.app.rpc.chat.guildRemote.pushRaceHorseJoin.toServer(chatSid, guildCode, woodenHorse);
|
||||
|
||||
// 全服活跃统计
|
||||
await ServerRecordModel.addActiveGuild(serverId, guildCode);
|
||||
// 任务
|
||||
await checkTask(roleId, sid, TASK_TYPE.GUILD_ACTIVITY, 1, true, { aid: this.aid });
|
||||
//成长任务
|
||||
|
||||
@@ -31,7 +31,7 @@ import { getEvent } from './eventSercive';
|
||||
import { getBattleListOfMain } from './normalBattleService';
|
||||
import { GuildType } from '../db/Guild';
|
||||
import UserGuild, { UserGuildType } from '../db/UserGuild';
|
||||
import { setMedianCe, getAllGuildActivityStatus } from './guildActivity/guildActivityService';
|
||||
import { setPreDayActiveData, getAllGuildActivityStatus } from './guildActivity/guildActivityService';
|
||||
import { getAllOnlineRoles } from './redisService';
|
||||
import Item from '../db/Item';
|
||||
import { PvpDefenseModel } from '../db/PvpDefense';
|
||||
@@ -236,6 +236,11 @@ async function getGuildEntryData(role: RoleType, sid: string, session: FrontendO
|
||||
}
|
||||
|
||||
export async function everydayRefresh() {
|
||||
pushRefreshTime();
|
||||
setPreDayActiveData();
|
||||
}
|
||||
|
||||
async function pushRefreshTime() {
|
||||
let allOnlineUsers = await getAllOnlineRoles();
|
||||
let todayZeroPoint = getZeroPoint();
|
||||
let n = Math.ceil(allOnlineUsers.length / PUSH_BATCH); // 一共多少批
|
||||
@@ -252,8 +257,7 @@ export async function everydayRefresh() {
|
||||
} else {
|
||||
clearInterval(interval);
|
||||
}
|
||||
}, PUSH_INTERVAL)
|
||||
setMedianCe();
|
||||
}, PUSH_INTERVAL);
|
||||
}
|
||||
|
||||
export async function kickUser(app: Application, uid: string, message = STATUS.LOGIN_ERR) {
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// 军团活动蛮夷入侵城门血量等数据存储
|
||||
|
||||
import { Member } from "../../domain/battleField/guildActivity";
|
||||
import { getCityActivityGateHp } from "./guildActivityService";
|
||||
|
||||
// 军团诸侯混战等数据
|
||||
export class CityActivityObject {
|
||||
private gateHp: Map<string, number> = new Map(); // 城门血条,每个cityId有一条血条 serverId&cityId => gateHp
|
||||
private maxHp: Map<string, number> = new Map(); // 城门血条,每个cityId最大城门血量 serverId&cityId => gateHp
|
||||
private members: Map<string, Array<Member>> = new Map(); // 每个军团参与的成员 guildCode => [{roleId, job}]
|
||||
private cities: Map<string, string[]> = new Map(); // 各个城池参与的军团 serverId&cityId => [guildCode]
|
||||
private guilds: Map<string, number> = new Map(); // 军团所在的城池 guildCode => cityId
|
||||
@@ -27,6 +29,7 @@ export class CityActivityObject {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
return {
|
||||
gateHp: this.gateHp.get(key),
|
||||
maxHp: this.maxHp.get(key),
|
||||
members: this.members.get(guildCode),
|
||||
city: this.cities.get(key),
|
||||
guild: this.guilds.get(guildCode)
|
||||
@@ -55,18 +58,20 @@ export class CityActivityObject {
|
||||
return this.members.get(guildCode)||[];
|
||||
}
|
||||
|
||||
public getGateHpAndInc(serverId: number, cityId: number, maxHp: number, inc: number = 0) {
|
||||
public async getGateHpAndInc(serverId: number, cityId: number, inc: number = 0) {
|
||||
let key = this.getKey(serverId, cityId);
|
||||
let gateHp = this.gateHp.get(key);
|
||||
if(!this.gateHp.has(key)) {
|
||||
gateHp = maxHp;
|
||||
gateHp = await getCityActivityGateHp(serverId, cityId);
|
||||
this.gateHp.set(key, gateHp);
|
||||
this.maxHp.set(key, gateHp);
|
||||
}
|
||||
if(inc != 0) {
|
||||
gateHp += inc;
|
||||
this.gateHp.set(key, gateHp);
|
||||
}
|
||||
if(gateHp <= 0) gateHp = 0;
|
||||
return gateHp
|
||||
return { gateHp, maxHp: this.maxHp.get(key)||0 }
|
||||
}
|
||||
|
||||
public getHistoryCity(roleId: string) {
|
||||
|
||||
@@ -4,7 +4,7 @@ import { reduceCe } from "../../pubUtils/util";
|
||||
import { GUILDACTIVITY } from "../../pubUtils/dicParam";
|
||||
import { gameData, getGuildAuctionRewards, getCityActivityRewards } from "../../pubUtils/data";
|
||||
import { getCurDay, nowSeconds, getTimeFun } 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 } from "../../consts";
|
||||
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 } from "../../consts";
|
||||
import { Record, UserGuildActivityRecModel } from "../../db/UserGuildActivityRec";
|
||||
import { GateMembersRec, CityParam, Member, WoodenHorse } from "../../domain/battleField/guildActivity";
|
||||
import { DicGuildActivity } from "../../pubUtils/dictionary/DicGuildActivity";
|
||||
@@ -27,6 +27,8 @@ import { UserGuildModel } from "../../db/UserGuild";
|
||||
import { raceActivityEnd } from "../timeTaskService";
|
||||
import { addActive } from "../guildService";
|
||||
import { checkTask, checkActivityTask } from "../taskService";
|
||||
import { ActivePlayer, ServerRecordModel } from "../../db/ServerRecords";
|
||||
import { Attack } from "../../domain/battleField/pvp";
|
||||
|
||||
let gateActivityObj: GateActivityObject;
|
||||
let cityActivityObj: CityActivityObject;
|
||||
@@ -55,19 +57,19 @@ export function getRaceActivityObj() {
|
||||
/**
|
||||
* 定时任务,获得前一天的活跃玩家中位数武将战力
|
||||
*/
|
||||
export async function setMedianCe() {
|
||||
export async function setPreDayActiveData() {
|
||||
let servers = await ServerlistModel.findByEnv(pinus.app.get('env'));
|
||||
|
||||
for (let server of servers) {
|
||||
let medianRole = await RoleModel.getMedianRole(server.id);
|
||||
if (!medianRole) {
|
||||
await ServerlistModel.updateByServerId(server.id, { medianCe: GUILDACTIVITY.GATEACTIVITY_ENEMYCE });
|
||||
} else {
|
||||
let { topLineup } = medianRole;
|
||||
let topHero = topLineup.sort((a, b) => b.ce - a.ce);
|
||||
let medianCe = reduceCe(topHero[0].ce);
|
||||
await ServerlistModel.updateByServerId(server.id, { medianCe });
|
||||
}
|
||||
let roles = await RoleModel.getActivePlayers(server.id);
|
||||
let activePlayerCnt = roles.length;
|
||||
let activePlayerCe = 0, activePlayers: ActivePlayer[] = []
|
||||
for(let i = 0; i < 10; i++) {
|
||||
if(!roles[i]) break;
|
||||
activePlayerCe += roles[i].topLineupCe;
|
||||
activePlayers.push(new ActivePlayer(roles[i]));
|
||||
}
|
||||
await ServerRecordModel.updateData(server.id, { activePlayerCnt, activePlayerCe: reduceCe(activePlayerCe), activePlayers });
|
||||
}
|
||||
return servers;
|
||||
}
|
||||
@@ -77,12 +79,9 @@ export async function setMedianCe() {
|
||||
* 获得本服前一天活跃玩家中位数玩家的最强武将战力
|
||||
* @param serverId
|
||||
*/
|
||||
export async function getMedianCe(serverId: number) {
|
||||
let server = await ServerlistModel.findByServerId(serverId);
|
||||
if (server) {
|
||||
return server.medianCe;
|
||||
}
|
||||
return GUILDACTIVITY.GATEACTIVITY_ENEMYCE;
|
||||
export async function getPreDayActiveData(serverId: number) {
|
||||
let record = await ServerRecordModel.findTodayData(serverId);
|
||||
return record;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -303,9 +302,7 @@ export async function sendGuildActEndMsg(aid: number) {
|
||||
|
||||
if (aid == GUILD_ACTIVITY_TYPE.GATE_ACTIVITY) {
|
||||
let obj = getGateActivityObj();
|
||||
console.log('******** gateActivity', obj);
|
||||
let guilds = obj.getGuilds();
|
||||
console.log('******** guilds', guilds);
|
||||
for (let [serverId, guildCodes] of guilds) {
|
||||
// console.log('***** serverId', serverId, 'guildCodes', guildCodes);
|
||||
for (let guildCode of guildCodes) {
|
||||
@@ -447,7 +444,7 @@ export async function cityActivitySettleReward(cityId: number, serverId: number)
|
||||
|
||||
let dicCity = gameData.cityActivity.get(cityId);
|
||||
if (!dicCity) return;
|
||||
let gateHp = obj.getGateHpAndInc(serverId, cityId, dicCity.hp);
|
||||
let {gateHp} = await obj.getGateHpAndInc(serverId, cityId);
|
||||
let isSuccess = gateHp <= 0; // 血条未击破则没有占领军团
|
||||
|
||||
let r = new Rank(REDIS_KEY.CITY_ACTIVITY, { serverId, cityId }, true);
|
||||
@@ -791,4 +788,44 @@ export async function setDicAuctionTime(startTime: number, endActivity: number,
|
||||
|
||||
function formatTime(date: Date) {
|
||||
return { hour: date.getHours(), minute: date.getMinutes(), seconds: date.getSeconds() }
|
||||
}
|
||||
|
||||
export async function getCityActivityGateHp(serverId: number, cityId: number) {
|
||||
console.log(`getCityActivityGateHp: serverId ${serverId}, cityId ${cityId}`);
|
||||
let dicCityActivity = gameData.cityActivity.get(cityId);
|
||||
|
||||
let serverRecord = await ServerRecordModel.findTodayData(serverId);
|
||||
if(!serverRecord) return dicCityActivity.hp;
|
||||
|
||||
let activePlayerCnt = 1, activePlayerCe = 0, activeTopPlayerCnt = 1, activeGuildCnt = 1;
|
||||
if(serverRecord) {
|
||||
if(serverRecord.activePlayerCnt > 0) activePlayerCnt = serverRecord.activePlayerCnt;
|
||||
if(serverRecord.activePlayerCe > 0) activePlayerCe = serverRecord.activePlayerCe;
|
||||
if(serverRecord.activePlayers?.length > 0) activeTopPlayerCnt = serverRecord.activePlayers?.length;
|
||||
if(serverRecord.activeGuildCodes?.length > 0) activeGuildCnt = serverRecord.activeGuildCodes?.length;
|
||||
}
|
||||
|
||||
console.log(`getCityActivityGateHp: activePlayerCnt ${activePlayerCnt}, activePlayerCe ${activePlayerCe}, activeTopPlayerCnt ${activeTopPlayerCnt} activeGuildCnt ${activeGuildCnt}`);
|
||||
|
||||
let dicWarJson = gameData.warJson.get(dicCityActivity.warid);
|
||||
let dicDoor = dicWarJson.find(cur => cur.actorId == CITY_ACTIVITY_DOOR);
|
||||
let attribute = dicDoor.attribute.find(cur => cur.id == ABI_TYPE.ABI_ATK);
|
||||
let atk = attribute? attribute.val: 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 gateHp = Math.floor(gateHpBase * (activePlayerCnt/activeGuildCnt) * N);
|
||||
console.log(`getCityActivityGateHp: gateHp ${gateHp}`);
|
||||
|
||||
if(gateHp == 0) {
|
||||
gateHp = dicCityActivity.hp;
|
||||
}
|
||||
return gateHp;
|
||||
}
|
||||
@@ -310,4 +310,6 @@ export enum RACE_ACTIVITY_STATUS {
|
||||
WAITING = 0, // 未开始
|
||||
START = 1, // 已开始
|
||||
END = 2 // 已结束
|
||||
}
|
||||
}
|
||||
|
||||
export const CITY_ACTIVITY_DOOR = 1047;
|
||||
@@ -37,7 +37,7 @@ export class CeAttrDataRole {
|
||||
}
|
||||
}
|
||||
|
||||
class TopHero {
|
||||
export class TopHero {
|
||||
@prop({ required: true })
|
||||
hid: number; // 武将id
|
||||
@prop({ required: true })
|
||||
@@ -696,12 +696,12 @@ export default class Role extends BaseModel {
|
||||
}
|
||||
|
||||
// 获取战力在中位数的玩家
|
||||
public static async getMedianRole(serverId: number) {
|
||||
public static async getActivePlayers(serverId: number) {
|
||||
let yesterday = <Date>getTimeFunD().getBeforeDayWithHour(1);
|
||||
const roles: RoleType[] = await RoleModel.find({ serverId, updatedAt: { $gte: yesterday } })
|
||||
.select('topLineup')
|
||||
.select('topLineup topLineupCe')
|
||||
.sort({ ce: -1 }).lean();
|
||||
return roles[Math.floor(roles.length / 2)]
|
||||
return roles
|
||||
}
|
||||
|
||||
public static async receiveRankReward(roleId: string, ids: number[]) {
|
||||
|
||||
73
shared/db/ServerRecords.ts
Normal file
73
shared/db/ServerRecords.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { RoleType, TopHero } from './Role';
|
||||
import { getZeroPoint } from '../pubUtils/timeUtil';
|
||||
|
||||
export class ActivePlayer {
|
||||
@prop({ required: true })
|
||||
roleId: string;
|
||||
@prop({ required: true })
|
||||
topLineupCe: number;
|
||||
@prop({ required: true, type: TopHero, default: [], _id: false })
|
||||
topLineup: Array<TopHero>; // 总战力
|
||||
|
||||
constructor(role: RoleType) {
|
||||
this.roleId = role.roleId;
|
||||
this.topLineupCe = role.topLineupCe;
|
||||
this.topLineup = role.topLineup;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 游戏字段接口
|
||||
*/
|
||||
@index({ serverId: 1, date: 1 })
|
||||
@modelOptions({ schemaOptions: { id: false } })
|
||||
export default class ServerRecord extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
serverId: number; // 小区id
|
||||
|
||||
@prop({ required: true, default: 1 })
|
||||
today: number; // 天
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
activePlayerCe: number; // 前一天活跃玩家前十的最强6人战力和
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
activePlayerCnt: number; // 前一天活跃玩家人数
|
||||
|
||||
@prop({ required: true, type: ActivePlayer, _id: false })
|
||||
activePlayers: ActivePlayer[]; // 前一天的活跃玩家
|
||||
|
||||
@prop({ required: true, type: String, default: [] })
|
||||
activeGuildCodes: string[]; // 前一天参与军团活动的军团
|
||||
|
||||
public static async updateData(serverId: number, update: ServerRecordUpdate) {
|
||||
let today = getZeroPoint();
|
||||
const doc = new ServerRecordModel();
|
||||
let rec: ServerRecordType = await ServerRecordModel.findOneAndUpdate({ serverId, today }, { $set: { ...doc.toJSON(), ...update } }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async addActiveGuild(serverId: number, guildCode: string) {
|
||||
let tomorrow = getZeroPoint() + 86400;
|
||||
let rec: ServerRecordType = await ServerRecordModel.findOneAndUpdate({ serverId, today: tomorrow }, { $addToSet: [guildCode] }, { new: true, upsert: true }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
public static async findTodayData(serverId: number) {
|
||||
let today = getZeroPoint();
|
||||
let rec: ServerRecordType = await ServerRecordModel.findOne({ serverId, today }).lean();
|
||||
return rec;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const ServerRecordModel = getModelForClass(ServerRecord);
|
||||
|
||||
export interface ServerRecordType extends Pick<DocumentType<ServerRecord>, keyof ServerRecord> {
|
||||
id: number;
|
||||
};
|
||||
export type ServerRecordUpdate = Partial<ServerRecordType>; // 将所有字段变成可选项
|
||||
@@ -25,6 +25,7 @@ export class Maintenance {
|
||||
hasNotify: boolean; // 是否有维护通知
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 游戏字段接口
|
||||
*/
|
||||
@@ -86,9 +87,6 @@ export default class Serverlist extends BaseModel {
|
||||
@prop({ required: true, default: 0 })
|
||||
playerCnt: number; // 当前玩家人数
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
medianCe: number; // 中位数武将战力、缩小10000倍后的结果
|
||||
|
||||
@prop({ required: true, type: Maintenance, _id: false })
|
||||
maintenance: Maintenance
|
||||
|
||||
|
||||
@@ -16,10 +16,12 @@ export interface DicCityActivity {
|
||||
readonly difficult: number;
|
||||
// 相应的出兵表
|
||||
readonly warid: number;
|
||||
// 城门血条
|
||||
readonly hp: number;
|
||||
// 可开启星期
|
||||
readonly week: number[];
|
||||
// 保底血量
|
||||
readonly hp: number;
|
||||
// 城门倍率
|
||||
readonly hpN: number;
|
||||
}
|
||||
|
||||
export const dicCityActivity = new Map<number, DicCityActivity>();
|
||||
|
||||
@@ -223,5 +223,23 @@
|
||||
"template": "<color=#53e1fb>%d</color><color=#301B0C>正在招兵买马:</color><color=#c08834>%d</color><color=#2f9b00><on click=%d>[前往]</on></color>",
|
||||
"worldchat": "<outline color=#1c1613 width=1><color=#53e1fb>%d</color>正在招兵买马:%d<color=#2f9b00><on click=%d>[前往]</on></color></outline>",
|
||||
"comments": "1:%d(军团名);2:%d(军团招募内容)"
|
||||
},
|
||||
{
|
||||
"id": 25,
|
||||
"name": "EQUIP_STAR_UP",
|
||||
"mean": "装备升至12星",
|
||||
"type": "1&",
|
||||
"template": "<color=#301B0C>恭喜</color><color=#c08834>%d</color><color=#301B0C>,成功将</color><on click=%d>%d</on><color=#301B0C>升至满星</color>",
|
||||
"worldchat": "<outline color=#1c1613 width=1>恭喜<color=#c08834>%d</color>,成功将<on click=%d>%d</on>升至满星</outline>",
|
||||
"comments": "1:%d(玩家名);2:%d(装备名)"
|
||||
},
|
||||
{
|
||||
"id": 26,
|
||||
"name": "EQUIP_QUALITY_UP",
|
||||
"mean": "装备升至金色",
|
||||
"type": "1&",
|
||||
"template": "<color=#301B0C>恭喜</color><color=#c08834>%d</color><color=#301B0C>,成功将</color><on click=%d>%d</on><color=#301B0C>升至最高品质</color>",
|
||||
"worldchat": "<outline color=#1c1613 width=1>恭喜<color=#c08834>%d</color>,成功将<on click=%d>%d</on>升至最高品质</outline>",
|
||||
"comments": "1:%d(玩家名);2:%d(装备名)"
|
||||
}
|
||||
]
|
||||
@@ -8,7 +8,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
@@ -19,7 +20,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
@@ -30,7 +32,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 4,
|
||||
@@ -41,7 +44,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
@@ -52,7 +56,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 6,
|
||||
@@ -63,7 +68,8 @@
|
||||
"difficult": 90,
|
||||
"warid": 7002,
|
||||
"hp": 5000000,
|
||||
"week": "2&4&6"
|
||||
"week": "2&4&6",
|
||||
"hpN": 1
|
||||
},
|
||||
{
|
||||
"id": 7,
|
||||
@@ -74,7 +80,8 @@
|
||||
"difficult": 100,
|
||||
"warid": 7003,
|
||||
"hp": 10000000,
|
||||
"week": "4&6"
|
||||
"week": "4&6",
|
||||
"hpN": 2
|
||||
},
|
||||
{
|
||||
"id": 8,
|
||||
@@ -85,7 +92,8 @@
|
||||
"difficult": 100,
|
||||
"warid": 7003,
|
||||
"hp": 10000000,
|
||||
"week": "4&6"
|
||||
"week": "4&6",
|
||||
"hpN": 2
|
||||
},
|
||||
{
|
||||
"id": 9,
|
||||
@@ -96,7 +104,8 @@
|
||||
"difficult": 100,
|
||||
"warid": 7003,
|
||||
"hp": 10000000,
|
||||
"week": "4&6"
|
||||
"week": "4&6",
|
||||
"hpN": 2
|
||||
},
|
||||
{
|
||||
"id": 10,
|
||||
@@ -107,6 +116,7 @@
|
||||
"difficult": 110,
|
||||
"warid": 7004,
|
||||
"hp": 30000000,
|
||||
"week": "6&"
|
||||
"week": "6&",
|
||||
"hpN": 3
|
||||
}
|
||||
]
|
||||
@@ -169,7 +169,7 @@
|
||||
"lv": 1,
|
||||
"hide": 0,
|
||||
"initial_ai": 0,
|
||||
"attribute": "1&2000000|2&2000|4&2500|5&2500",
|
||||
"attribute": "1&1000000",
|
||||
"skill": 0,
|
||||
"seid": 0,
|
||||
"star": 0,
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
"lv": 40,
|
||||
"hide": 1,
|
||||
"initial_ai": 0,
|
||||
"attribute": "&",
|
||||
"attribute": "2&3000",
|
||||
"skill": 0,
|
||||
"seid": 0,
|
||||
"star": 0,
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
"lv": 45,
|
||||
"hide": 1,
|
||||
"initial_ai": 0,
|
||||
"attribute": "&",
|
||||
"attribute": "2&3000",
|
||||
"skill": 0,
|
||||
"seid": 0,
|
||||
"star": 0,
|
||||
@@ -254,8 +254,8 @@
|
||||
},
|
||||
{
|
||||
"warId": 7003,
|
||||
"actorName": "骑兵",
|
||||
"actorId": 1003,
|
||||
"actorName": "武道家",
|
||||
"actorId": 1005,
|
||||
"dataId": 2006,
|
||||
"relation": 2,
|
||||
"outIndex": 5,
|
||||
@@ -277,8 +277,8 @@
|
||||
},
|
||||
{
|
||||
"warId": 7003,
|
||||
"actorName": "骑兵",
|
||||
"actorId": 1003,
|
||||
"actorName": "武道家",
|
||||
"actorId": 1005,
|
||||
"dataId": 2007,
|
||||
"relation": 2,
|
||||
"outIndex": 6,
|
||||
|
||||
@@ -151,7 +151,7 @@
|
||||
"lv": 45,
|
||||
"hide": 1,
|
||||
"initial_ai": 0,
|
||||
"attribute": "&",
|
||||
"attribute": "2&3000",
|
||||
"skill": 0,
|
||||
"seid": 0,
|
||||
"star": 0,
|
||||
|
||||
Reference in New Issue
Block a user