✨ feat(gvg): 矿场
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// 每个农庄/每个田一条记录,这个田被其他人用了之后会覆盖
|
||||
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, } from '@typegoose/typegoose';
|
||||
import { getFutureTime, nowSeconds } from '../pubUtils/timeUtil';
|
||||
@@ -25,23 +27,32 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
fieldId: number; // 农庄id
|
||||
|
||||
@prop({ required: true })
|
||||
unlockTime: number; // 解锁时间,打开界面时预锁定一批填,种下去之后锁定时间延长到收获时间
|
||||
unlockTime: number; // 解锁时间,农场:打开界面时预锁定一批填,种下去之后锁定时间延长到收获时间,林场&矿场:开始小游戏时锁定时间
|
||||
|
||||
@prop({ required: true })
|
||||
lockRoleId: string; // 锁定的人
|
||||
|
||||
@prop({ required: true })
|
||||
harvestTime: number; // 收获时间,种植下去后将时间更新,收获之后设为0
|
||||
harvestTime: number; // 收获时间,农庄:种植下去后将时间更新,收获之后设为0,林场&矿场:小游戏结束时更新
|
||||
|
||||
@prop({ required: true })
|
||||
seedType: number; // 实际种的种子类型
|
||||
seedType: number; // 仅农庄使用,实际种的种子类型
|
||||
|
||||
@prop({ required: true })
|
||||
addType: number; // 种子加成
|
||||
addType: number; // 仅农庄使用,种子加成
|
||||
|
||||
@prop({ required: true })
|
||||
batchCode: string; // 批量号
|
||||
|
||||
@prop({ required: true })
|
||||
itemId: number; // 仅矿山使用,使用的铲子id
|
||||
|
||||
@prop({ required: true })
|
||||
output: number; // 产量,农庄:种下去时可以预估产量,林场&矿场:小游戏结束时根据结果更新
|
||||
|
||||
@prop({ required: true })
|
||||
outputStr: string; // 产量计算公式
|
||||
|
||||
public static async findByType(configId: number, leagueCode: string, type: number) {
|
||||
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, type }).select('-_id').lean();
|
||||
return result;
|
||||
@@ -57,12 +68,16 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static async findPlantedByFarmId(configId: number, leagueCode: string, farmId: number) {
|
||||
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, farmId, unlockTime: { $gte: nowSeconds() }, harvestTime: { $gte: nowSeconds() }}).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findByFieldIds(configId: number, leagueCode: string, farmId: number, fieldIds: number[]) {
|
||||
const result: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ configId, leagueCode, farmId, fieldId: { $in: fieldIds } }).select('-_id').lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 首次打开页面时锁定田
|
||||
* @param configId
|
||||
@@ -76,7 +91,7 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId }, update: { $setOnInsert: { unlockTime: 0, harvestTime: 0, seedType: 0, addType: 0 } }, upsert: true} }
|
||||
}));
|
||||
const result = await GVGLeagueFarmModel.bulkWrite(lands.map(({ fieldId, addType }) => {
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, unlockTime: { $lt: nowSeconds() } }, update: { $set: { addType, unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId } } } }
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, $or:[{ unlockTime: { $lt: nowSeconds() }}, {lockRoleId: roleId} ] }, update: { $set: { addType, unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId } } } }
|
||||
}));
|
||||
return result;
|
||||
}
|
||||
@@ -86,10 +101,10 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async plant(configId: number, leagueCode: string, farmId: number, fields: { fieldId: number, seedType: number, time: number }[], roleId: string) {
|
||||
public static async plant(configId: number, leagueCode: string, farmId: number, fields: { fieldId: number, seedType: number, time: number, output: number, outputStr: string }[], roleId: string) {
|
||||
const batchCode = genCode(10);
|
||||
const result = await GVGLeagueFarmModel.bulkWrite(fields.map(({ fieldId, seedType, time }) => {
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, lockRoleId: roleId }, update: { $set: { seedType, unlockTime: getFutureTime(), harvestTime: nowSeconds() + time, batchCode }} } }
|
||||
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 }} } }
|
||||
}));
|
||||
if(result.modifiedCount == 0) return [];
|
||||
const fieldResult: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ batchCode }).sort({ fieldId: 1 }).select('-_id -createdAt -updatedAt -__v -configId -leagueCode').lean();
|
||||
@@ -116,6 +131,29 @@ 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: '' } });
|
||||
}
|
||||
|
||||
public static async lockMineOrForestry(configId: number, leagueCode: string, farmId: number, type: number, roleId: string, fieldId: number, itemId: number) {
|
||||
// 先创建
|
||||
await GVGLeagueFarmModel.findOneAndUpdate({ configId, leagueCode, farmId, fieldId }, { $setOnInsert: { unlockTime: 0, itemId: 0, type } }, { upsert: true });
|
||||
const result: GVGLeagueFarmType = await GVGLeagueFarmModel.findOneAndUpdate(
|
||||
{ configId, leagueCode, farmId, fieldId, $or:[{ unlockTime: { $lt: nowSeconds() } }, {lockRoleId: roleId}] },
|
||||
{ $set: { unlockTime: nowSeconds() + GVG.GVG_FARM_LOCK_TIME, lockRoleId: roleId, itemId } },
|
||||
{ new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async findByField(configId: number, leagueCode: string, farmId: number, fieldId: number) {
|
||||
const result: GVGLeagueFarmType = await GVGLeagueFarmModel.findOne({ configId, leagueCode, farmId, fieldId }).lean();
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async mineOrForestryEnd(configId: number, leagueCode: string, farmId: number, roleId: string, fieldId: number, output: number, outputStr: string) {
|
||||
const result: GVGLeagueFarmType = await GVGLeagueFarmModel.findOneAndUpdate(
|
||||
{ configId, leagueCode, farmId, fieldId, lockRoleId: roleId,unlockTime: { $gte: nowSeconds() } },
|
||||
{ $set: { output, outputStr, unlockTime: getFutureTime(), harvestTime: nowSeconds() } },
|
||||
{ new: true }).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GVGLeagueFarmModel = getModelForClass(GVGLeagueFarm);
|
||||
|
||||
Reference in New Issue
Block a user