✨ feat(gvg): 动态
This commit is contained in:
@@ -15,6 +15,7 @@ import { addGVGReward } from "./gvgItemService";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
import { getProduceCoinCnt } from "./gvgItemService";
|
||||
import { GVGLeagueFarmRecModel } from "../../db/GVGLeagueFarmRec";
|
||||
import { addResourceRecord } from "./gvgRecService";
|
||||
|
||||
export function checkPreTech(techId: number, activeQueue: number[], techQueue: Tech[]) {
|
||||
const dicTech = gameData.gvgTech.get(techId);
|
||||
@@ -106,7 +107,7 @@ export function getMyDistribute(userDailyData: GVGUserDailyDataType) {
|
||||
* @param count 数量
|
||||
* @returns
|
||||
*/
|
||||
export async function addResource(leagueCode: string, roleId: string, resourceType: GVG_RESOURCE_TYPE, count: number) {
|
||||
export async function addResource(leagueCode: string, roleId: string, roleName: string, resourceType: GVG_RESOURCE_TYPE, count: number) {
|
||||
let { configId } = getGVGConfig();
|
||||
let resources = getResourceCnt(resourceType, count);
|
||||
if(!resources) return false;
|
||||
@@ -123,6 +124,7 @@ export async function addResource(leagueCode: string, roleId: string, resourceTy
|
||||
let userDailyData = await GVGUserDailyDataModel.addResource(configId, leagueCode, roleId, food, mineral, wood);
|
||||
|
||||
let myDistribute = getMyDistribute(userDailyData);
|
||||
addResourceRecord(roleId, roleName, leagueCode, resourceType, count);
|
||||
|
||||
return { resource: league.resources, lv: league.lv, myDistribute }
|
||||
}
|
||||
@@ -138,7 +140,7 @@ function getResourceCnt(resourceType: GVG_RESOURCE_TYPE, count: number) {
|
||||
}
|
||||
}
|
||||
|
||||
export async function lockField(leagueCode: string, roleId: string, farmId: number) {
|
||||
export async function lockField(leagueCode: string, roleId: string, roleName: string, farmId: number) {
|
||||
let { configId } = getGVGConfig();
|
||||
const produceCoinCnt = await getLockFieldCnt(leagueCode, roleId);
|
||||
if(produceCoinCnt == 0) return
|
||||
@@ -162,7 +164,7 @@ export async function lockField(leagueCode: string, roleId: string, farmId: numb
|
||||
lands.push({ fieldId, addType });
|
||||
}
|
||||
// 更新田
|
||||
await GVGLeagueFarmModel.lockFields(configId, leagueCode, farmId, roleId, lands);
|
||||
await GVGLeagueFarmModel.lockFields(configId, leagueCode, farmId, roleId, roleName, lands);
|
||||
return await GVGLeagueFarmModel.findByFarmIdAndRoleId(configId, leagueCode, farmId, roleId);
|
||||
}
|
||||
|
||||
@@ -321,7 +323,7 @@ export function calFarmOutput(seedType: number, addType: number, farmId: number,
|
||||
let { value: foodBase } = dicGVGItem;
|
||||
let addRatio = seedType == addType? GVG.GVG_SP_FIELD_ADD: 0;
|
||||
let farmRatio = dicFarm.fieldAdd;
|
||||
let cityRatio = getCitiesAdd(cities);
|
||||
let cityRatio = getCitiesAdd(cities, GVG_RESOURCE_TYPE.FOOD);
|
||||
let techRatio = getTechAdd(activeTech);
|
||||
|
||||
return {
|
||||
@@ -371,7 +373,7 @@ export function calMineOutput(farmId: number, result: [{ type: number, count: nu
|
||||
output += dic.output * count;
|
||||
addStrArr.push(`${dic.output}*${count}`);
|
||||
}
|
||||
let cityRatio = getCitiesAdd(cities);
|
||||
let cityRatio = getCitiesAdd(cities, GVG_RESOURCE_TYPE.MINERAL);
|
||||
let techRatio = getTechAdd(activeTech);
|
||||
return {
|
||||
output: Math.floor(output * (1 + (cityRatio + techRatio)/100)),
|
||||
@@ -392,7 +394,7 @@ export function calForestryOutput(farmId: number, result: number, cities: number
|
||||
let dicForestry = gameData.gvgResource.get(farmId);
|
||||
if(!dicForestry) return { output: 0, outputStr: '' };
|
||||
let base = dicForestry.woodOutput;
|
||||
let cityRatio = getCitiesAdd(cities);
|
||||
let cityRatio = getCitiesAdd(cities, GVG_RESOURCE_TYPE.WOOD);
|
||||
let techRatio = getTechAdd(activeTech);
|
||||
return {
|
||||
output: Math.floor( base * (1 + (cityRatio + techRatio)/100) * result),
|
||||
@@ -401,9 +403,22 @@ export function calForestryOutput(farmId: number, result: number, cities: number
|
||||
|
||||
}
|
||||
|
||||
// TODO 城池加成,多城池取最大加成
|
||||
function getCitiesAdd(cities: number[]) {
|
||||
return 0
|
||||
// 城池加成,多城池取最大加成
|
||||
function getCitiesAdd(cities: number[], resourceType: number) {
|
||||
let outputAdds: number[] = [0];
|
||||
for(let cityId of cities) {
|
||||
let dicCity = gameData.gvgCity.get(cityId);
|
||||
let dicCityAdd = gameData.gvgCityAdd.get(dicCity?.cityType);
|
||||
if(!dicCity || !dicCityAdd) continue;
|
||||
if(resourceType == GVG_RESOURCE_TYPE.FOOD) {
|
||||
outputAdds.push(dicCityAdd.foodAdd);
|
||||
} else if (resourceType == GVG_RESOURCE_TYPE.MINERAL) {
|
||||
outputAdds.push(dicCityAdd.mineralAdd);
|
||||
} else if (resourceType == GVG_RESOURCE_TYPE.WOOD) {
|
||||
outputAdds.push(dicCityAdd.woodAdd);
|
||||
}
|
||||
}
|
||||
return Math.max(...outputAdds);
|
||||
}
|
||||
|
||||
// 科技树加成 叠加
|
||||
|
||||
37
game-server/app/services/gvg/gvgRecService.ts
Normal file
37
game-server/app/services/gvg/gvgRecService.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
// 动态
|
||||
import { GVG_REC_ID, GVG_REC_TYPE, GVG_RESOURCE_TYPE } from "../../consts";
|
||||
import { GVGRecModel } from "../../db/GVGRec";
|
||||
import { nowSeconds } from "../../pubUtils/timeUtil";
|
||||
import { getGVGConfig } from "./gvgService";
|
||||
|
||||
// 加入军团
|
||||
export async function guildJoinLeagueRecord(leagueCode: string, guildName: string) {
|
||||
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_JOIN_GUILD);
|
||||
}
|
||||
|
||||
// 退出军团
|
||||
export async function guildQuitLeagueRecord(leagueCode: string, guildName: string) {
|
||||
await leagueJoinOrQuitGuild(leagueCode, guildName, GVG_REC_ID.LEAGUE_QUIT_GUILD);
|
||||
}
|
||||
|
||||
async function leagueJoinOrQuitGuild(leagueCode: string, guildName: string, recId: GVG_REC_ID.LEAGUE_JOIN_GUILD|GVG_REC_ID.LEAGUE_QUIT_GUILD) {
|
||||
let { configId } = getGVGConfig();
|
||||
let params = [guildName];
|
||||
await GVGRecModel.addRec({ leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId, createTime: nowSeconds(), params })
|
||||
}
|
||||
|
||||
// 获得资源
|
||||
export async function addResourceRecord(roleId: string, roleName: string, leagueCode: string, resourceType: GVG_RESOURCE_TYPE, output: number) {
|
||||
let { configId } = getGVGConfig();
|
||||
let params = [roleName, getResourceNameByType(resourceType), `${output}`];
|
||||
await GVGRecModel.addRec({ roleId, leagueCode, configId, type: GVG_REC_TYPE.PREPARE, recId: GVG_REC_ID.ADD_RESOURCE, createTime: nowSeconds(), params })
|
||||
}
|
||||
|
||||
function getResourceNameByType(resourceType: GVG_RESOURCE_TYPE) {
|
||||
switch(resourceType) {
|
||||
case GVG_RESOURCE_TYPE.FOOD: return '粮食';
|
||||
case GVG_RESOURCE_TYPE.MINERAL: return '矿物';
|
||||
case GVG_RESOURCE_TYPE.WOOD: return '木堆';
|
||||
}
|
||||
}
|
||||
@@ -196,4 +196,4 @@ export async function calLeagueCe(league: GVGLeagueType) {
|
||||
const guildCodes = league?.guildCodes||[];
|
||||
const guilds = await GuildModel.findByCodes(guildCodes);
|
||||
return guilds.reduce((pre, guild) => pre + guild.guildCe, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { GVG } from "../../pubUtils/dicParam";
|
||||
import { getZeroPointD } from "../../pubUtils/timeUtil";
|
||||
import { resResult } from "../../pubUtils/util";
|
||||
import { sendMessageToUserWithSuc } from "../pushService";
|
||||
import { guildJoinLeagueRecord } from "./gvgRecService";
|
||||
import { calLeagueCe, getCurPeriod, getGVGConfig, getGVGPeriodData, getGVGServerType } from "./gvgService";
|
||||
|
||||
/**
|
||||
@@ -136,6 +137,7 @@ export async function joinGuildToLeague(league: GVGLeagueType, targetGuildCode:
|
||||
league = await GVGLeagueModel.joinGuild(league.leagueCode, targetGuild);
|
||||
|
||||
await GuildModel.joinLeague(targetGuildCode, league.leagueCode);
|
||||
guildJoinLeagueRecord(league.leagueCode, targetGuild.name);
|
||||
|
||||
return resResult(STATUS.SUCCESS, league);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user