✨ feat(gvg): 动态
This commit is contained in:
@@ -95,4 +95,23 @@ export enum GVG_TECH_TYPE {
|
||||
BATTLE_REVIVE_GAP = 4, // 激战期复活间隔减少
|
||||
BATTLE_ITEM_CATAPULT = 5, // 成员获得投石车(箭塔)
|
||||
BATTLE_ITEM_KNIFE = 6, // 成员活动匕首(攻城车)
|
||||
}
|
||||
|
||||
// 动态类型
|
||||
export enum GVG_REC_TYPE {
|
||||
PREPARE = 1, // 备战期战报
|
||||
BATTLE_BY_ROLE = 2, // 个人战报
|
||||
BATTLE_BY_CITY = 3, // 城池战报
|
||||
BATTLE_BY_LEAGUE = 4, // 联军战报
|
||||
}
|
||||
|
||||
// 动态具体id
|
||||
export enum GVG_REC_ID {
|
||||
ADD_RESOURCE = 1, // 成员贡献粮食、铁矿、木材
|
||||
SETTLE_POINT = 2, // 成员成功占领驻扎点
|
||||
POINT_BE_GRAB = 3, // 成员占领的驻扎点被其他联军抢占
|
||||
SEND_ITEM = 4, // 战备道具发放
|
||||
VESTIGE_RANK = 5, // 联军每日的征战排名
|
||||
LEAGUE_JOIN_GUILD = 6, // 军团加入联军
|
||||
LEAGUE_QUIT_GUILD = 7, // 军团退出联军
|
||||
}
|
||||
@@ -32,6 +32,9 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
@prop({ required: true })
|
||||
lockRoleId: string; // 锁定的人
|
||||
|
||||
@prop({ required: true })
|
||||
lockRoleName: string;
|
||||
|
||||
@prop({ required: true })
|
||||
harvestTime: number; // 收获时间,农庄:种植下去后将时间更新,收获之后设为0,林场&矿场:小游戏结束时更新
|
||||
|
||||
@@ -85,13 +88,13 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
* @param lands [{fieldId: number, time: number, addType: number}] fieldId:田地id, time: 锁定时间 addType: 种子加成
|
||||
* @returns
|
||||
*/
|
||||
public static async lockFields(configId: number, leagueCode: string, farmId: number, roleId: string, lands: { fieldId: number, addType: number }[]) {
|
||||
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} }
|
||||
}));
|
||||
const result = await GVGLeagueFarmModel.bulkWrite(lands.map(({ fieldId, addType }) => {
|
||||
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 { 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;
|
||||
}
|
||||
@@ -114,7 +117,7 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
public static async harvest(configId: number, leagueCode: string, farmId: number, fieldIds: number[], roleId: string) {
|
||||
const batchCode = genCode(10);
|
||||
const result = await GVGLeagueFarmModel.bulkWrite(fieldIds.map(fieldId => {
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, lockRoleId: roleId, harvestTime: { $lt: nowSeconds() } }, update: { $set: { unlockTime: 0, harvestTime: 0, lockRoleId: '', batchCode }} } }
|
||||
return { updateOne: { filter: { configId, leagueCode, farmId, fieldId, lockRoleId: roleId, harvestTime: { $lt: nowSeconds() } }, update: { $set: { unlockTime: 0, harvestTime: 0, lockRoleId: '', lockRoleName: '', batchCode }} } }
|
||||
}));
|
||||
if(result.modifiedCount == 0) return [];
|
||||
const fieldResult: GVGLeagueFarmType[] = await GVGLeagueFarmModel.find({ batchCode }).sort({ fieldId: 1 }).select('-_id -createdAt -updatedAt -__v -configId -leagueCode').lean();
|
||||
@@ -124,12 +127,12 @@ export default class GVGLeagueFarm extends BaseModel {
|
||||
public static async helpHarvest(configId: number, leagueCode: string, farmId: number, fieldId: number) {
|
||||
const result: GVGLeagueFarmType = await GVGLeagueFarmModel.findOneAndUpdate(
|
||||
{ configId, leagueCode, farmId, fieldId, harvestTime: { $lt: nowSeconds() }, unlockTime: { $gt: nowSeconds() } },
|
||||
{ $set: { unlockTime: 0, harvestTime: 0, lockRoleId: '' }}, { new: true }).lean();
|
||||
{ $set: { unlockTime: 0, harvestTime: 0, lockRoleId: '', lockRoleName: '' }}, { new: true }).lean();
|
||||
return result
|
||||
}
|
||||
|
||||
public static async releaseLock(configId: number, leagueCode: string, farmId: number, roleId: string) {
|
||||
await GVGLeagueFarmModel.updateMany({ configId, leagueCode, farmId, lockRoleId: roleId }, { $set: { unlockTime: 0, lockRoleId: '' } });
|
||||
await GVGLeagueFarmModel.updateMany({ configId, leagueCode, farmId, lockRoleId: roleId }, { $set: { unlockTime: 0, lockRoleId: '', lockRoleName: '' } });
|
||||
}
|
||||
|
||||
public static async lockMineOrForestry(configId: number, leagueCode: string, farmId: number, type: number, roleId: string, fieldId: number, itemId: number) {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, } from '@typegoose/typegoose';
|
||||
import { GVG_REC_TYPE } from '../consts';
|
||||
|
||||
@index({ leagueCode: 1, guildCode: 1, configId: 1 })
|
||||
@index({ createTime: -1 })
|
||||
export default class GVGRec extends BaseModel {
|
||||
|
||||
@prop({ required: true, default: '' })
|
||||
leagueCode: string; // 联军id
|
||||
|
||||
@prop({ required: false, default: '' })
|
||||
roleId: string; // 玩家id
|
||||
|
||||
@prop({ required: false, default: '' })
|
||||
cityId: number; // 所处城池
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
configId: number; // 赛期
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
type: number; // 1-备战期联军动态 2-激战期我的战报 3-激战期城池战报 4-激战期军团战报
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
recId: number; // 配在动态策划表中的id
|
||||
|
||||
@prop({ required: true, default: [], type: String })
|
||||
params: string[]; // 显示的参数问题,替代%d的
|
||||
|
||||
@prop({ required: true, default: 0 })
|
||||
createTime: number; // 时间
|
||||
|
||||
public static async addRec(param: GVGRecUpdate) {
|
||||
await GVGRecModel.insertMany([param]);
|
||||
}
|
||||
|
||||
public static async addRecs(params: GVGRecUpdate[]) {
|
||||
await GVGRecModel.insertMany(params);
|
||||
}
|
||||
|
||||
public static async findByLeague(leagueCode: string, type: GVG_REC_TYPE) {
|
||||
const result: GVGRecType[] = await GVGRecModel.find({ leagueCode, type }, { _id: 0, recId: 1, params: 1, createTime: 1 }).sort({ createTime: -1 }).limit(50).lean();
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
export const GVGRecModel = getModelForClass(GVGRec);
|
||||
|
||||
export interface GVGRecType extends Pick<DocumentType<GVGRec>, keyof GVGRec> {
|
||||
id: number;
|
||||
};
|
||||
export type GVGRecUpdate = Partial<GVGRecType>; // 将所有字段变成可选项
|
||||
@@ -1122,7 +1122,6 @@ export function getGVGResourceBaseByTypeAndLv(type: number, lv: number) {
|
||||
return gameData.gvgResource.get(id);
|
||||
}
|
||||
|
||||
|
||||
// 获取农庄小游戏最多能有多少特殊加成田
|
||||
export function getFieldMaxAddType(farmId: number) {
|
||||
let add = new Map<number, number>();
|
||||
|
||||
@@ -5,21 +5,21 @@ import { readFileAndParse } from '../util'
|
||||
export interface DicGVGCityAdd {
|
||||
// 城池类型 1-大城 2-中城 3-小城
|
||||
cityType: number;
|
||||
// dic_zyz_GVGResourceBase的type
|
||||
resourceType: number;
|
||||
// 联盟币的加成
|
||||
coinAdd: number;
|
||||
// 产量加成
|
||||
outputAdd: number;
|
||||
// 粮食加成
|
||||
foodAdd: number;
|
||||
// 矿物加成
|
||||
mineralAdd: number;
|
||||
// 木头加成
|
||||
woodAdd: number;
|
||||
}
|
||||
|
||||
export const dicGVGCityAdd = new Map<string, DicGVGCityAdd>();
|
||||
export const dicGVGCityAdd = new Map<number, DicGVGCityAdd>();
|
||||
export function loadGVGCityAdd() {
|
||||
dicGVGCityAdd.clear();
|
||||
|
||||
let arr = readFileAndParse(FILENAME.DIC_GVG_CITY_ADD);
|
||||
arr.forEach(o => {
|
||||
dicGVGCityAdd.set(`${o.cityType}_${o.resourceType}`, o);
|
||||
dicGVGCityAdd.set(o.cityType, o);
|
||||
});
|
||||
arr = undefined;
|
||||
}
|
||||
@@ -1,8 +1,20 @@
|
||||
[
|
||||
{
|
||||
"cityType": 1,
|
||||
"resourceType": 1,
|
||||
"coinAdd": 0.1,
|
||||
"outputAdd": 0.1
|
||||
"foodAdd": 0.1,
|
||||
"mineralAdd": 0.1,
|
||||
"woodAdd": 0.1
|
||||
},
|
||||
{
|
||||
"cityType": 2,
|
||||
"foodAdd": 0.3,
|
||||
"mineralAdd": 0.3,
|
||||
"woodAdd": 0.3
|
||||
},
|
||||
{
|
||||
"cityType": 3,
|
||||
"foodAdd": 0.5,
|
||||
"mineralAdd": 0.5,
|
||||
"woodAdd": 0.5
|
||||
}
|
||||
]
|
||||
@@ -33,6 +33,6 @@
|
||||
"DEBUG_TIME": 1,
|
||||
"CHECK_WORD": 1,
|
||||
"CAN_PAY": 1,
|
||||
"SKIP_ENCODE": 1,
|
||||
"SKIP_ENCODE": 0,
|
||||
"NEED_REBATE": 0
|
||||
}
|
||||
Reference in New Issue
Block a user