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

fix: correct inventory responses during incubation phases (#3756)

Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/3756 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>

b8063889
Sainan <63328889+Sainan@users.noreply.github.com>
提交于

代码差异

7 个文件 +37 -28
Modified src/controllers/api/adoptPetController.ts +9 -0
@@ -2,6 +2,7 @@ import { getJSONfromString } from "../../helpers/stringHelpers.ts";
2 2 import { getInventory } from "../../services/inventoryService.ts";
3 3 import { getAccountIdForRequest } from "../../services/loginService.ts";
4 4 import type { RequestHandler } from "express";
5 import { Status } from "../../types/equipmentTypes.ts";
5 6
6 7 export const adoptPetController: RequestHandler = async (req, res) => {
7 8 const accountId = await getAccountIdForRequest(req);
@@ -9,6 +10,14 @@ export const adoptPetController: RequestHandler = async (req, res) => {
9 10 const data = getJSONfromString<IAdoptPetRequest>(String(req.body));
10 11 const details = inventory.KubrowPets.id(data.petId)!.Details!;
11 12 details.Name = data.name;
13 let canSetActive = true;
14 for (const pet of inventory.KubrowPets) {
15 if (pet.Details!.Status == Status.StatusAvailable) {
16 canSetActive = false;
17 break;
18 }
19 }
20 details.Status = canSetActive ? Status.StatusAvailable : Status.StatusStasis;
12 21 await inventory.save();
13 22 res.json({
14 23 petId: data.petId,
Modified src/controllers/api/claimCompletedRecipeController.ts +2 -11
@@ -183,18 +183,9 @@ const claimCompletedRecipe = async (
183 183 }
184 184
185 185 if (recipe.secretIngredientAction == "SIA_CREATE_KUBROW") {
186 // This request is sent automatically once the pending recipe is completed.
186 187 const pet = inventory.KubrowPets.id(pendingRecipe.KubrowPet!)!;
187 if (pet.Details!.HatchDate!.getTime() > Date.now()) {
188 pet.Details!.HatchDate = new Date();
189 }
190 let canSetActive = true;
191 for (const pet of inventory.KubrowPets) {
192 if (pet.Details!.Status == Status.StatusAvailable) {
193 canSetActive = false;
194 break;
195 }
196 }
197 pet.Details!.Status = canSetActive ? Status.StatusAvailable : Status.StatusStasis;
188 pet.Details!.Status = Status.StatusIncubated;
198 189 } else if (recipe.secretIngredientAction == "SIA_DISTILL_PRINT") {
199 190 const pet = inventory.KubrowPets.id(pendingRecipe.KubrowPet!)!;
200 191 addKubrowPetPrint(
Modified src/models/inventoryModels/inventoryModel.ts +17 -11
@@ -1214,7 +1214,6 @@ const pendingRecipeSchema = new Schema<IPendingRecipeDatabase>(
1214 1214 {
1215 1215 ItemType: String,
1216 1216 CompletionDate: Date,
1217 TargetItemId: String,
1218 1217 TargetFingerprint: String,
1219 1218 LongGuns: { type: [EquipmentSchema], default: undefined },
1220 1219 Pistols: { type: [EquipmentSchema], default: undefined },
@@ -1231,16 +1230,23 @@ pendingRecipeSchema.virtual("ItemId").get(function () {
1231 1230
1232 1231 pendingRecipeSchema.set("toJSON", {
1233 1232 virtuals: true,
1234 transform(_document, returnedObject: Record<string, any>) {
1235 delete returnedObject._id;
1236 delete returnedObject.__v;
1237 delete returnedObject.LongGuns;
1238 delete returnedObject.Pistols;
1239 delete returnedObject.Melees;
1240 delete returnedObject.SuitToUnbrand;
1241 delete returnedObject.KubrowPet;
1242 (returnedObject as IPendingRecipeClient).CompletionDate = {
1243 $date: { $numberLong: (returnedObject as IPendingRecipeDatabase).CompletionDate.getTime().toString() }
1233 transform(_document, obj: Record<string, any>) {
1234 delete obj._id;
1235 delete obj.__v;
1236 delete obj.LongGuns;
1237 delete obj.Pistols;
1238 delete obj.Melees;
1239 delete obj.SuitToUnbrand;
1240
1241 const client = obj as IPendingRecipeClient;
1242 const db = obj as IPendingRecipeDatabase;
1243
1244 if (db.KubrowPet) {
1245 client.TargetItemId = db.KubrowPet.toString();
1246 delete obj.KubrowPet;
1247 }
1248 client.CompletionDate = {
1249 $date: { $numberLong: db.CompletionDate.getTime().toString() }
1244 1250 };
1245 1251 }
1246 1252 });
Modified src/services/importService.ts +4 -3
@@ -263,7 +263,8 @@ const convertPurchaseHistory = (client: IVendorPurchaseHistoryEntryClient): IVen
263 263 const convertPendingRecipe = (client: IPendingRecipeClient): IPendingRecipeDatabase => {
264 264 return {
265 265 ...client,
266 CompletionDate: convertDate(client.CompletionDate)
266 CompletionDate: convertDate(client.CompletionDate),
267 KubrowPet: client.TargetItemId ? new Types.ObjectId(client.TargetItemId) : undefined
267 268 };
268 269 };
269 270
@@ -578,8 +579,8 @@ export const importInventory = (db: TInventoryDatabaseDocument, client: Partial<
578 579 const recipe = getRecipe(pr.ItemType);
579 580 if (recipe?.secretIngredientAction == "SIA_CREATE_KUBROW" && !pr.KubrowPet) {
580 581 pr.KubrowPet = db.KubrowPets.find(x => x.Details!.Status == Status.StatusIncubating)?._id;
581 logger.debug(
582 `importing an incubating pet; associating pet ${pr.KubrowPet?.toString()} with recipe ${pr._id.toString()} (${pr.ItemType})`
582 logger.warn(
583 `imported recipe ${pr._id.toString()} (${pr.ItemType}) had no TargetItemId; best guess fixup is ${pr.KubrowPet?.toString()}`
583 584 );
584 585 }
585 586 }
Modified src/services/inventoryService.ts +1 -1
@@ -1579,7 +1579,7 @@ export const addKubrowPet = (
1579 1579 HasCollar: isCatbrow || questCompleted,
1580 1580 PrintsRemaining: !isPreU26 && isCatbrow ? 3 : 2,
1581 1581 Status: premiumPurchase ? Status.StatusStasis : Status.StatusIncubating,
1582 HatchDate: premiumPurchase ? new Date() : new Date(Date.now() + 10 * unixTimesInMs.hour), // On live, this seems to be somewhat randomised so that the pet hatches 9~11 hours after start.
1582 HatchDate: premiumPurchase ? new Date() : new Date(Date.now() + 10 * unixTimesInMs.hour), // On live, this seems to be somewhat randomised so that the pet hatches 9~11 hours after start. TOVERIFY: Although it might differ for the quest recipe?
1583 1583 IsMale: !!getRandomInt(0, 1),
1584 1584 Size: getRandomInt(70, 100) / 100,
1585 1585 DominantTraits: dominantTraits,
Modified src/types/equipmentTypes.ts +3 -1
@@ -136,9 +136,11 @@ export interface IKubrowPetDetailsClient extends Omit<IKubrowPetDetailsDatabase,
136 136 }
137 137
138 138 export enum Status {
139 StatusIncubating = "STATUS_INCUBATING",
140 StatusIncubated = "STATUS_INCUBATED",
139 141 StatusAvailable = "STATUS_AVAILABLE",
140 142 StatusStasis = "STATUS_STASIS",
141 StatusIncubating = "STATUS_INCUBATING"
143 StatusDistilling = "STATUS_DISTILLING" // TODO: We currently don't ever set this, but we probably should?
142 144 }
143 145
144 146 // inventory.CrewShips[0].Weapon
Modified src/types/inventoryTypes/inventoryTypes.ts +1 -1
@@ -949,7 +949,6 @@ export interface IPendingCouponClient {
949 949 export interface IPendingRecipeDatabase {
950 950 ItemType: string;
951 951 CompletionDate: Date;
952 TargetItemId?: string; // unsure what this is for
953 952 TargetFingerprint?: string;
954 953 LongGuns?: IEquipmentDatabase[];
955 954 Pistols?: IEquipmentDatabase[];
@@ -964,6 +963,7 @@ export interface IPendingRecipeClient extends Omit<
964 963 > {
965 964 ItemId: IOid;
966 965 CompletionDate: IMongoDate;
966 TargetItemId?: string;
967 967 }
968 968
969 969 export interface IAccolades {