✨ 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);
|
||||
}
|
||||
|
||||
// 科技树加成 叠加
|
||||
|
||||
Reference in New Issue
Block a user