🐞 fix(gvg): 修复农田特殊种子加成逻辑
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user