feat(gvg): 添加贡献等接口

This commit is contained in:
luying
2023-01-06 21:15:06 +08:00
parent 6cc38053e7
commit 0530f931bc
17 changed files with 301 additions and 49 deletions

View File

@@ -0,0 +1,5 @@
export function calProduce(obj: { food: number, mineral: number, wood: number }) {
let { food = 0, mineral = 0, wood = 0 } = obj||{};
return food + mineral + wood;
}

View File

@@ -16,11 +16,15 @@ import { GuildType } from "../../db/Guild";
export async function createNewGVGConfig() {
let { teamTime, prepareTime, battleTime, scheduleTime } = getPeriodTime();
const config = await GVGConfigModel.createNewConfig(teamTime, prepareTime, battleTime, scheduleTime);
setGVGConfigToRemote(config);
try {
await pinus.app.rpc.guild.guildRemote.setGVGConfig.broadcast(config);
await pinus.app.rpc.guild.guildRemote.setGVGServerGroup.broadcast();
await pinus.app.rpc.chat.chatRemote.setGVGServerGroup.broadcast();
await pinus.app.rpc.connector.connectorRemote.setGVGServerGroup.broadcast();
} catch(e) {
console.log('remote未初始完');
}
// TODO 每周自动解散一些联军
await pinus.app.rpc.guild.guildRemote.setGVGServerGroup.broadcast();
await pinus.app.rpc.chat.chatRemote.setGVGServerGroup.broadcast();
await pinus.app.rpc.connector.connectorRemote.setGVGServerGroup.broadcast();
return config;
}
@@ -53,13 +57,11 @@ export async function getGVGConfigFromRemote() {
return await pinus.app.rpc.guild.guildRemote.getGVGConfig.toServer(server.id);
}
export function setGVGConfigToRemote(config: GVGConfigType) {
if(!config) return null
pinus.app.rpc.guild.guildRemote.setGVGConfig.broadcast(config);
}
export function setGVGConfig(config: GVGConfigType) {
if(!config) return null
export async function setGVGConfig(config?: GVGConfigType) {
if(!config) {
config = await GVGConfigModel.findConfig();
}
console.log('##### setGVGConfig', config)
pinus.app.set('gvgConfigId', config.configId);
pinus.app.set('gvgTeamTime', config.teamTime);
pinus.app.set('gvgPrepareTime', config.prepareTime);
@@ -100,6 +102,7 @@ export async function getGVGServerType(serverId: number) {
export function getGVGPeriodData() {
let { configId, teamTime, prepareTime, battleTime, scheduleTime } = getGVGConfig();
console.log('#### getGVGPeriodData', configId, teamTime, prepareTime, battleTime, scheduleTime)
let period = getCurPeriod();
let countdownTime = teamTime;
switch(period) {
@@ -129,11 +132,11 @@ export function getCurPeriod() {
}
export async function initLeaguePrepare() {
const { configId } = getGVGConfig();
const config = await GVGConfigModel.findConfig();
if(!config) return;
const leagues = await GVGLeagueModel.findAllLeague();
for(let { leagueCode, memberCnt } of leagues) {
await GVGLeaguePrepareModel.initData(configId, leagueCode, memberCnt);
await GVGLeaguePrepareModel.initData(config.configId, leagueCode, memberCnt);
}
}
@@ -159,6 +162,7 @@ export async function getServersOfSameGroup(type: GVG_SERVER_TYPE, id: number) {
if(type == GVG_SERVER_TYPE.SINGLE) return [id];
let groupId = await getGroupIdOfServer(id);
console.log('###### getServersOfSameGroup', type, groupId, id);
return await getServersByGroupId(groupId);
}