|
|
|
|
@@ -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) {
|
|
|
|
|
|