feat: handle client setting InfestationDate on equipment (#1927)
Closes #1919 Reviewed-on: OpenWF/SpaceNinjaServer#1927 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									660768b53b
								
							
						
					
					
						commit
						3d6c880c96
					
				@ -1,4 +1,4 @@
 | 
				
			|||||||
import { addGearExpByCategory, getInventory } from "@/src/services/inventoryService";
 | 
					import { applyClientEquipmentUpdates, getInventory } from "@/src/services/inventoryService";
 | 
				
			||||||
import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
					import { getAccountIdForRequest } from "@/src/services/loginService";
 | 
				
			||||||
import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
					import { IEquipmentClient } from "@/src/types/inventoryTypes/commonInventoryTypes";
 | 
				
			||||||
import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
					import { TEquipmentKey } from "@/src/types/inventoryTypes/inventoryTypes";
 | 
				
			||||||
@ -20,7 +20,7 @@ export const addXpController: RequestHandler = async (req, res) => {
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        addGearExpByCategory(inventory, gear, category as TEquipmentKey);
 | 
					        applyClientEquipmentUpdates(inventory, gear, category as TEquipmentKey);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    await inventory.save();
 | 
					    await inventory.save();
 | 
				
			||||||
    res.end();
 | 
					    res.end();
 | 
				
			||||||
 | 
				
			|||||||
@ -10,6 +10,10 @@ export const toMongoDate = (date: Date): IMongoDate => {
 | 
				
			|||||||
    return { $date: { $numberLong: date.getTime().toString() } };
 | 
					    return { $date: { $numberLong: date.getTime().toString() } };
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export const fromMongoData = (date: IMongoDate): Date => {
 | 
				
			||||||
 | 
					    return new Date(parseInt(date.$date.$numberLong));
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export const kubrowWeights: Record<TRarity, number> = {
 | 
					export const kubrowWeights: Record<TRarity, number> = {
 | 
				
			||||||
    COMMON: 6,
 | 
					    COMMON: 6,
 | 
				
			||||||
    UNCOMMON: 4,
 | 
					    UNCOMMON: 4,
 | 
				
			||||||
 | 
				
			|||||||
@ -69,6 +69,7 @@ import {
 | 
				
			|||||||
import { createShip } from "./shipService";
 | 
					import { createShip } from "./shipService";
 | 
				
			||||||
import {
 | 
					import {
 | 
				
			||||||
    catbrowDetails,
 | 
					    catbrowDetails,
 | 
				
			||||||
 | 
					    fromMongoData,
 | 
				
			||||||
    kubrowDetails,
 | 
					    kubrowDetails,
 | 
				
			||||||
    kubrowFurPatternsWeights,
 | 
					    kubrowFurPatternsWeights,
 | 
				
			||||||
    kubrowWeights,
 | 
					    kubrowWeights,
 | 
				
			||||||
@ -1475,21 +1476,20 @@ export const addEmailItem = async (
 | 
				
			|||||||
    return inventoryChanges;
 | 
					    return inventoryChanges;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
//TODO: wrong id is not erroring
 | 
					export const applyClientEquipmentUpdates = (
 | 
				
			||||||
export const addGearExpByCategory = (
 | 
					 | 
				
			||||||
    inventory: TInventoryDatabaseDocument,
 | 
					    inventory: TInventoryDatabaseDocument,
 | 
				
			||||||
    gearArray: IEquipmentClient[],
 | 
					    gearArray: IEquipmentClient[],
 | 
				
			||||||
    categoryName: TEquipmentKey
 | 
					    categoryName: TEquipmentKey
 | 
				
			||||||
): void => {
 | 
					): void => {
 | 
				
			||||||
    const category = inventory[categoryName];
 | 
					    const category = inventory[categoryName];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    gearArray.forEach(({ ItemId, XP }) => {
 | 
					    gearArray.forEach(({ ItemId, XP, InfestationDate }) => {
 | 
				
			||||||
        if (!XP) {
 | 
					        const item = category.id(ItemId.$oid);
 | 
				
			||||||
            return;
 | 
					        if (!item) {
 | 
				
			||||||
 | 
					            throw new Error(`No item with id ${ItemId.$oid} in ${categoryName}`);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        const item = category.id(ItemId.$oid);
 | 
					        if (XP) {
 | 
				
			||||||
        if (item) {
 | 
					 | 
				
			||||||
            item.XP ??= 0;
 | 
					            item.XP ??= 0;
 | 
				
			||||||
            item.XP += XP;
 | 
					            item.XP += XP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1504,6 +1504,10 @@ export const addGearExpByCategory = (
 | 
				
			|||||||
                });
 | 
					                });
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (InfestationDate) {
 | 
				
			||||||
 | 
					            item.InfestationDate = fromMongoData(InfestationDate);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,7 +21,6 @@ import {
 | 
				
			|||||||
    addFocusXpIncreases,
 | 
					    addFocusXpIncreases,
 | 
				
			||||||
    addFusionPoints,
 | 
					    addFusionPoints,
 | 
				
			||||||
    addFusionTreasures,
 | 
					    addFusionTreasures,
 | 
				
			||||||
    addGearExpByCategory,
 | 
					 | 
				
			||||||
    addItem,
 | 
					    addItem,
 | 
				
			||||||
    addLevelKeys,
 | 
					    addLevelKeys,
 | 
				
			||||||
    addLoreFragmentScans,
 | 
					    addLoreFragmentScans,
 | 
				
			||||||
@ -32,6 +31,7 @@ import {
 | 
				
			|||||||
    addShipDecorations,
 | 
					    addShipDecorations,
 | 
				
			||||||
    addSkin,
 | 
					    addSkin,
 | 
				
			||||||
    addStanding,
 | 
					    addStanding,
 | 
				
			||||||
 | 
					    applyClientEquipmentUpdates,
 | 
				
			||||||
    combineInventoryChanges,
 | 
					    combineInventoryChanges,
 | 
				
			||||||
    generateRewardSeed,
 | 
					    generateRewardSeed,
 | 
				
			||||||
    getCalendarProgress,
 | 
					    getCalendarProgress,
 | 
				
			||||||
@ -660,9 +660,8 @@ export const addMissionInventoryUpdates = async (
 | 
				
			|||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            default:
 | 
					            default:
 | 
				
			||||||
                // Equipment XP updates
 | 
					 | 
				
			||||||
                if (equipmentKeys.includes(key as TEquipmentKey)) {
 | 
					                if (equipmentKeys.includes(key as TEquipmentKey)) {
 | 
				
			||||||
                    addGearExpByCategory(inventory, value as IEquipmentClient[], key as TEquipmentKey);
 | 
					                    applyClientEquipmentUpdates(inventory, value as IEquipmentClient[], key as TEquipmentKey);
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                break;
 | 
					                break;
 | 
				
			||||||
            // if (
 | 
					            // if (
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user