🐞 fix(gvg): 修复农田特殊种子加成逻辑

This commit is contained in:
luying
2023-02-07 18:05:21 +08:00
parent eb5808dfb1
commit f21fd2dfa8
7 changed files with 78 additions and 75 deletions

View File

@@ -7,6 +7,13 @@ import { genCode } from '../pubUtils/util';
import { GVG } from '../pubUtils/dicParam';
import { GVG_RESOURCE_TYPE } from '../consts';
class AddType {
@prop({ required: true })
addType: number; // 加成类型
@prop({ required: true })
roleId: string; // 加成玩家
}
@index({ leagueCode: 1, configId: 1 })
@index({ fieldId: 1 })
@index({ batchCode: 1 })
@@ -43,7 +50,10 @@ export default class GVGLeagueFarm extends BaseModel {
seedType: number; // 仅农庄使用,实际种的种子类型
@prop({ required: true })
addType: number; // 仅农庄使用,种子加成
addType: number; // 仅农庄使用,当前种子加成
@prop({ required: true, type: AddType, _id: false })
addTypes: AddType[]; // 仅农庄使用,历史种子加成
@prop({ required: true })
batchCode: string; // 批量号
@@ -57,6 +67,9 @@ export default class GVGLeagueFarm extends BaseModel {
@prop({ required: true })
outputStr: string; // 产量计算公式
@prop({ required: true })
index: number; // 种植位置
public static async findByType(configId: number, leagueCode: string, type: number) {
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, type }).select('-_id').lean();
return result;
@@ -92,26 +105,30 @@ export default class GVGLeagueFarm extends BaseModel {
public static async lockFields(configId: number, leagueCode: string, farmId: number, roleId: string, roleName: string, lands: { fieldId: number, addType: number }[]) {
// 先创建
await GVGLeagueFarmModel.bulkWrite(lands.map(({ fieldId }) => {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId }, update: { $setOnInsert: { unlockTime: 0, harvestTime: 0, seedType: 0, addType: 0 } }, upsert: true} }
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId }, update: { $setOnInsert: { unlockTime: 0, harvestTime: 0, seedType: 0, addType: 0, addTypes: [] } }, upsert: true} }
}));
const result = await GVGLeagueFarmModel.bulkWrite(lands.map(({ fieldId, addType }) => {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, $or:[{ unlockTime: { $lt: nowSeconds() }}, {lockRoleId: roleId, lockRoleName: roleName} ] }, update: { $set: { addType, unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId } } } }
if(addType > 0) {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, $or:[{ unlockTime: { $lt: nowSeconds() }}, {lockRoleId: roleId, lockRoleName: roleName} ] }, update: { $set: { addType, unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId }, $push: { addTypes: { addType, roleId } } } } }
} else {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, $or:[{ unlockTime: { $lt: nowSeconds() }}, {lockRoleId: roleId, lockRoleName: roleName} ] }, update: { $set: { addType, unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId } } } }
}
}));
return result;
}
public static async findByFarmIdAndRoleId(configId: number, leagueCode: string, farmId: number, roleId: string) {
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, farmId, lockRoleId: roleId, unlockTime: { $gte: nowSeconds() } }).sort({ fieldId: 1 }).select('-_id -createdAt -updatedAt -__v -leagueCode -configId -roleId').lean();
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, farmId, lockRoleId: roleId, unlockTime: { $gte: nowSeconds() } }).sort({ index: -1, fieldId: 1 }).select('-_id -createdAt -updatedAt -__v -leagueCode -configId -roleId').lean();
return result;
}
public static async plant(configId: number, leagueCode: string, farmId: number, fields: { fieldId: number, seedType: number, time: number, output: number, outputStr: string }[], roleId: string) {
public static async plant(configId: number, leagueCode: string, farmId: number, fields: { fieldId: number, seedType: number, time: number, output: number, outputStr: string, index: number }[], roleId: string) {
const batchCode = genCode(10);
const result = await GVGLeagueFarmModel.bulkWrite(fields.map(({ fieldId, seedType, time, output, outputStr }) => {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, lockRoleId: roleId }, update: { $set: { seedType, unlockTime: getFutureTime(), harvestTime: nowSeconds() + time, batchCode, output, outputStr }} } }
const result = await GVGLeagueFarmModel.bulkWrite(fields.map(({ fieldId, seedType, time, output, outputStr, index }) => {
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, lockRoleId: roleId }, update: { $set: { seedType, unlockTime: getFutureTime(), harvestTime: nowSeconds() + time, batchCode, output, outputStr, index }} } }
}));
if(result.modifiedCount == 0) return [];
const fieldResult: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ batchCode }).sort({ fieldId: 1 }).select('-_id -createdAt -updatedAt -__v -configId -leagueCode').lean();
const fieldResult: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ batchCode }).sort({ fieldId: 1 }).select('-_id -createdAt -updatedAt -__v').lean();
return fieldResult;
}
@@ -133,7 +150,7 @@ export default class GVGLeagueFarm extends BaseModel {
}
public static async releaseLock(configId: number, leagueCode: string, farmId: number, roleId: string) {
await GVGLeagueFarmModel.updateMany({ configId, leagueCode, farmId, lockRoleId: roleId }, { $set: { unlockTime: 0, lockRoleId: '', lockRoleName: '' } });
await GVGLeagueFarmModel.updateMany({ configId, leagueCode, farmId, lockRoleId: roleId, index: 0 }, { $set: { unlockTime: 0, lockRoleId: '', lockRoleName: '' } });
}
public static async lockMineOrForestry(configId: number, leagueCode: string, farmId: number, type: number, roleId: string, fieldId: number, itemId: number) {

View File

@@ -3,6 +3,7 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, } from '@typegoose/typegoose';
import { GVGLeagueFarmType } from './GVGLeagueFarm';
import { GVG_RESOURCE_TYPE } from '../consts';
@index({ leagueCode: 1, configId: 1, farmId: 1, fieldId: 1 })
export default class GVGLeagueFarmRec extends BaseModel {
@@ -47,11 +48,11 @@ export default class GVGLeagueFarmRec extends BaseModel {
output: number; // 产量
@prop({ required: false })
outputStr: number; // 产量计算公式
outputStr: string; // 产量计算公式
public static async insertRecs(params: GVGLeagueFarmType[]) {
public static async insertRecs(type: GVG_RESOURCE_TYPE,params: GVGLeagueFarmType[]) {
let insertParams = params.map(field => {
return { ...field, startRoleId: field.lockRoleId, startTime: new Date() }
return { ...field, startRoleId: field.lockRoleId, startTime: new Date(), type }
})
await GVGLeagueFarmRecModel.insertMany(insertParams);
}

View File

@@ -317,7 +317,7 @@ export const gameData = {
gvgResourceBaseByType: dicGVGResourceBaseByType,
gvgResourceBaseByLv: dicGVGResourceBaseByLv,
gvgFieldAddType: new Map<number, number>(),
gvgSpFieldRatio: { min: 0, max: 0},
gvgPlayerFieldAddType: new Map<number, number>(),
gvgContributeBox: dicGVGContributeBox,
gvgArea: dicGVGArea,
gvgCity: dicGVGCity,
@@ -1151,12 +1151,10 @@ function parseGVGFieldAdd() {
for(let [type, ratio] of arr) {
gameData.gvgFieldAddType.set(parseInt(type), parseFloat(ratio));
}
}
function parseGVGSpFieldRatio() {
let arr = param.GVG.GVG_SP_FIELD_RATIO.split('&');
gameData.gvgSpFieldRatio.min = parseFloat(arr[0]);
gameData.gvgSpFieldRatio.max = parseFloat(arr[0]);
let arr2 = decodeArrayListStr(param.GVG.GVG_SP_FIELD_RATIO);
for(let [type, ratio] of arr2) {
gameData.gvgPlayerFieldAddType.set(parseInt(type), parseFloat(ratio));
}
}
export function getGVGTasksByType(taskType: number) {
@@ -1220,7 +1218,6 @@ function parseDicParam() {
parseComBattleRewardTime();
parseGVGActive();
parseGVGFieldAdd();
parseGVGSpFieldRatio();
parseGVGVestigeCnt();
}

View File

@@ -391,12 +391,14 @@ export const GVG = {
GVG_FARM_LOCK_TIME: 300, // 农田锁定时间(秒)
GVG_MINE_LOCK_TIME: 300, // 矿山锁定时间(秒)
GVG_FORESTRY_LOCK_TIME: 300, // 林场锁定时间(秒)
GVG_FIELD_TYPE_RATIO: '1&5%|2&10%|3&10%', // 全联盟的特殊格子上限百分比a%的格子为小麦这个1&a|2&b|3&c
GVG_SP_FIELD_RATIO: '10%&30%', // 分配给玩家的时候有多少特殊格子 min&max 填最大最小百分比即可
GVG_FIELD_TYPE_RATIO: '1&5%|2&10%|3&10%', // 全联盟的
GVG_SP_FIELD_RATIO: '1&5%|2&10%|3&10%', // 分配给玩家的时候特殊格子上限百分比a%的格子为小麦这个1&a|2&b|3&c
GVG_REFRESH_TIME: 5, // 0
GVG_ROBOT_NAME: '遗迹守卫', // 0
GVG_SINGLE_SERVICE_CITY: '1&2&3', // 单服城池
GVG_CROSS_SERVICE_CITY: '4&5&6&7&8&9&10&11&12&13', // 跨服城池
GVG_VESTIGE_PREPARE_COUNTDOWN: 120, // 遗迹准备界面倒计时(s)
GVG_VESTIGE_BATTLE_COUNTDOWN: 300, // 遗迹战斗界面倒计时(s)
GVG_VESTIGE_BGMAP_GKID: 80001, // GVG备战期遗迹防守阵容地图所用的关卡id
GVG_CITY_BGMAP_GKID: 85001, // GVG激战期防守阵容地图所用的关卡id
};