XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFESpaceNinjaServer

A simple server for a small space ninja game

公开
关注 0 Fork 0 Star 0
返回提交历史

XFEstudio/XFESpaceNinjaServer

feat: track TechChanges in clan log (#1160)

Re #1152 Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/1160

073eddc0
Sainan <sainan@calamity.inc>
提交于

代码差异

4 个文件 +78 -19
Modified src/controllers/api/getGuildLogController.ts +7 -0
@@ -18,6 +18,13 @@ export const getGuildLogController: RequestHandler = async (req, res) => {
18 18 StandingsUpdates: [],
19 19 ClassChanges: []
20 20 };
21 guild.TechChanges?.forEach(entry => {
22 log.TechChanges.push({
23 dateTime: toMongoDate(entry.dateTime),
24 entryType: entry.entryType,
25 details: entry.details
26 });
27 });
21 28 guild.ClassChanges?.forEach(entry => {
22 29 log.ClassChanges.push({
23 30 dateTime: toMongoDate(entry.dateTime),
Modified src/controllers/api/guildTechController.ts +52 -5
@@ -13,8 +13,9 @@ import {
13 13 import { IMiscItem } from "@/src/types/inventoryTypes/inventoryTypes";
14 14 import { IInventoryChanges } from "@/src/types/purchaseTypes";
15 15 import { config } from "@/src/services/configService";
16 import { ITechProjectDatabase } from "@/src/types/guildTypes";
16 import { ITechProjectClient, ITechProjectDatabase } from "@/src/types/guildTypes";
17 17 import { TGuildDatabaseDocument } from "@/src/models/guildModel";
18 import { toMongoDate } from "@/src/helpers/inventoryHelpers";
18 19
19 20 export const guildTechController: RequestHandler = async (req, res) => {
20 21 const accountId = await getAccountIdForRequest(req);
@@ -23,9 +24,29 @@ export const guildTechController: RequestHandler = async (req, res) => {
23 24 const data = JSON.parse(String(req.body)) as TGuildTechRequest;
24 25 const action = data.Action.split(",")[0];
25 26 if (action == "Sync") {
26 res.json({
27 TechProjects: guild.toJSON().TechProjects
28 });
27 let needSave = false;
28 const techProjects: ITechProjectClient[] = [];
29 if (guild.TechProjects) {
30 for (const project of guild.TechProjects) {
31 const techProject: ITechProjectClient = {
32 ItemType: project.ItemType,
33 ReqCredits: project.ReqCredits,
34 ReqItems: project.ReqItems,
35 State: project.State
36 };
37 if (project.CompletionDate) {
38 techProject.CompletionDate = toMongoDate(project.CompletionDate);
39 if (Date.now() >= project.CompletionDate.getTime()) {
40 needSave ||= setTechLogState(guild, project.ItemType, 4, project.CompletionDate);
41 }
42 }
43 techProjects.push(techProject);
44 }
45 }
46 if (needSave) {
47 await guild.save();
48 }
49 res.json({ TechProjects: techProjects });
29 50 } else if (action == "Start") {
30 51 const recipe = ExportDojoRecipes.research[data.RecipeType!];
31 52 guild.TechProjects ??= [];
@@ -42,6 +63,7 @@ export const guildTechController: RequestHandler = async (req, res) => {
42 63 State: 0
43 64 }) - 1
44 65 ];
66 setTechLogState(guild, techProject.ItemType, 5);
45 67 if (config.noDojoResearchCosts) {
46 68 processFundedProject(guild, techProject, recipe);
47 69 }
@@ -159,10 +181,35 @@ const processFundedProject = (
159 181 recipe: IDojoResearch
160 182 ): void => {
161 183 techProject.State = 1;
162 techProject.CompletionDate = new Date(new Date().getTime() + (config.noDojoResearchTime ? 0 : recipe.time) * 1000);
184 techProject.CompletionDate = new Date(Date.now() + (config.noDojoResearchTime ? 0 : recipe.time) * 1000);
163 185 if (recipe.guildXpValue) {
164 186 guild.XP += recipe.guildXpValue;
165 187 }
188 setTechLogState(guild, techProject.ItemType, config.noDojoResearchTime ? 4 : 3, techProject.CompletionDate);
189 };
190
191 const setTechLogState = (
192 guild: TGuildDatabaseDocument,
193 type: string,
194 state: number,
195 dateTime: Date | undefined = undefined
196 ): boolean => {
197 guild.TechChanges ??= [];
198 const entry = guild.TechChanges.find(x => x.details == type);
199 if (entry) {
200 if (entry.entryType == state) {
201 return false;
202 }
203 entry.dateTime = dateTime ?? new Date();
204 entry.entryType = state;
205 } else {
206 guild.TechChanges.push({
207 dateTime: dateTime ?? new Date(),
208 entryType: state,
209 details: type
210 });
211 }
212 return true;
166 213 };
167 214
168 215 type TGuildTechRequest =
Modified src/models/guildModel.ts +12 -14
@@ -2,15 +2,14 @@ import {
2 2 IGuildDatabase,
3 3 IDojoComponentDatabase,
4 4 ITechProjectDatabase,
5 ITechProjectClient,
6 5 IDojoDecoDatabase,
7 6 ILongMOTD,
8 7 IGuildMemberDatabase,
9 IGuildLogClassChange
8 IGuildLogClassChange,
9 IGuildLogTechChange
10 10 } from "@/src/types/guildTypes";
11 11 import { Document, Model, model, Schema, Types } from "mongoose";
12 12 import { fusionTreasuresSchema, typeCountSchema } from "./inventoryModels/inventoryModel";
13 import { toMongoDate } from "../helpers/inventoryHelpers";
14 13
15 14 const dojoDecoSchema = new Schema<IDojoDecoDatabase>({
16 15 Type: String,
@@ -51,17 +50,6 @@ const techProjectSchema = new Schema<ITechProjectDatabase>(
51 50 { _id: false }
52 51 );
53 52
54 techProjectSchema.set("toJSON", {
55 virtuals: true,
56 transform(_doc, obj) {
57 const db = obj as ITechProjectDatabase;
58 const client = obj as ITechProjectClient;
59 if (db.CompletionDate) {
60 client.CompletionDate = toMongoDate(db.CompletionDate);
61 }
62 }
63 });
64
65 53 const longMOTDSchema = new Schema<ILongMOTD>(
66 54 {
67 55 message: String,
@@ -70,6 +58,15 @@ const longMOTDSchema = new Schema<ILongMOTD>(
70 58 { _id: false }
71 59 );
72 60
61 const guildLogTechChangeSchema = new Schema<IGuildLogTechChange>(
62 {
63 dateTime: Date,
64 entryType: Number,
65 details: String
66 },
67 { _id: false }
68 );
69
73 70 const guildLogClassChangeSchema = new Schema<IGuildLogClassChange>(
74 71 {
75 72 dateTime: Date,
@@ -100,6 +97,7 @@ const guildSchema = new Schema<IGuildDatabase>(
100 97 CeremonyContributors: { type: [Types.ObjectId], default: undefined },
101 98 CeremonyResetDate: Date,
102 99 CeremonyEndo: Number,
100 TechChanges: { type: [guildLogTechChangeSchema], default: undefined },
103 101 ClassChanges: { type: [guildLogClassChangeSchema], default: undefined }
104 102 },
105 103 { id: false }
Modified src/types/guildTypes.ts +7 -0
@@ -47,6 +47,7 @@ export interface IGuildDatabase {
47 47 CeremonyContributors?: Types.ObjectId[];
48 48 CeremonyResetDate?: Date;
49 49
50 TechChanges?: IGuildLogTechChange[];
50 51 ClassChanges?: IGuildLogClassChange[];
51 52 }
52 53
@@ -163,6 +164,12 @@ export interface ITechProjectDatabase extends Omit<ITechProjectClient, "Completi
163 164 CompletionDate?: Date;
164 165 }
165 166
167 export interface IGuildLogTechChange {
168 dateTime: Date;
169 entryType: number;
170 details: string;
171 }
172
166 173 export interface IGuildLogClassChange {
167 174 dateTime: Date;
168 175 entryType: number;