forked from OpenWF/SpaceNinjaServer
chore: use SubdocumentArray.id in some more places (#1400)
Reviewed-on: OpenWF/SpaceNinjaServer#1400 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
b0f0b61d49
commit
04d39ed973
@ -17,7 +17,7 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
|
|||||||
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
|
recipe.ingredients.map(x => ({ ItemType: x.ItemType, ItemCount: x.ItemCount * -1 }))
|
||||||
);
|
);
|
||||||
|
|
||||||
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
|
const item = inventory[payload.Category].id(req.query.ItemId as string)!;
|
||||||
item.Features ??= 0;
|
item.Features ??= 0;
|
||||||
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
|
item.Features |= EquipmentFeatures.INCARNON_GENESIS;
|
||||||
|
|
||||||
@ -39,7 +39,7 @@ export const evolveWeaponController: RequestHandler = async (req, res) => {
|
|||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const item = inventory[payload.Category].find(item => item._id.toString() == (req.query.ItemId as string))!;
|
const item = inventory[payload.Category].id(req.query.ItemId as string)!;
|
||||||
item.Features! &= ~EquipmentFeatures.INCARNON_GENESIS;
|
item.Features! &= ~EquipmentFeatures.INCARNON_GENESIS;
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`unexpected evolve weapon action: ${payload.Action}`);
|
throw new Error(`unexpected evolve weapon action: ${payload.Action}`);
|
||||||
|
@ -18,17 +18,15 @@ export const focusController: RequestHandler = async (req, res) => {
|
|||||||
case FocusOperation.InstallLens: {
|
case FocusOperation.InstallLens: {
|
||||||
const request = JSON.parse(String(req.body)) as ILensInstallRequest;
|
const request = JSON.parse(String(req.body)) as ILensInstallRequest;
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
for (const item of inventory[request.Category]) {
|
const item = inventory[request.Category].id(request.WeaponId);
|
||||||
if (item._id.toString() == request.WeaponId) {
|
if (item) {
|
||||||
item.FocusLens = request.LensType;
|
item.FocusLens = request.LensType;
|
||||||
addMiscItems(inventory, [
|
addMiscItems(inventory, [
|
||||||
{
|
{
|
||||||
ItemType: request.LensType,
|
ItemType: request.LensType,
|
||||||
ItemCount: -1
|
ItemCount: -1
|
||||||
} satisfies IMiscItem
|
} satisfies IMiscItem
|
||||||
]);
|
]);
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
res.json({
|
res.json({
|
||||||
|
@ -28,7 +28,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
|
|||||||
// shard installation
|
// shard installation
|
||||||
const request = getJSONfromString<IShardInstallRequest>(String(req.body));
|
const request = getJSONfromString<IShardInstallRequest>(String(req.body));
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const suit = inventory.Suits.find(suit => suit._id.toString() == request.SuitId.$oid)!;
|
const suit = inventory.Suits.id(request.SuitId.$oid)!;
|
||||||
if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
|
if (!suit.ArchonCrystalUpgrades || suit.ArchonCrystalUpgrades.length != 5) {
|
||||||
suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
|
suit.ArchonCrystalUpgrades = [{}, {}, {}, {}, {}];
|
||||||
}
|
}
|
||||||
@ -56,7 +56,7 @@ export const infestedFoundryController: RequestHandler = async (req, res) => {
|
|||||||
// shard removal
|
// shard removal
|
||||||
const request = getJSONfromString<IShardUninstallRequest>(String(req.body));
|
const request = getJSONfromString<IShardUninstallRequest>(String(req.body));
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const suit = inventory.Suits.find(suit => suit._id.toString() == request.SuitId.$oid)!;
|
const suit = inventory.Suits.id(request.SuitId.$oid)!;
|
||||||
|
|
||||||
const miscItemChanges: IMiscItem[] = [];
|
const miscItemChanges: IMiscItem[] = [];
|
||||||
if (suit.ArchonCrystalUpgrades![request.Slot].Color) {
|
if (suit.ArchonCrystalUpgrades![request.Slot].Color) {
|
||||||
|
@ -12,9 +12,7 @@ export const nameWeaponController: RequestHandler = async (req, res) => {
|
|||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const body = getJSONfromString<INameWeaponRequest>(String(req.body));
|
const body = getJSONfromString<INameWeaponRequest>(String(req.body));
|
||||||
const item = inventory[req.query.Category as string as TEquipmentKey].find(
|
const item = inventory[req.query.Category as string as TEquipmentKey].id(req.query.ItemId as string)!;
|
||||||
item => item._id.toString() == (req.query.ItemId as string)
|
|
||||||
)!;
|
|
||||||
if (body.ItemName != "") {
|
if (body.ItemName != "") {
|
||||||
item.ItemName = body.ItemName;
|
item.ItemName = body.ItemName;
|
||||||
} else {
|
} else {
|
||||||
|
@ -6,12 +6,10 @@ import { WeaponTypeInternal } from "@/src/services/itemDataService";
|
|||||||
|
|
||||||
export const setWeaponSkillTreeController: RequestHandler = async (req, res) => {
|
export const setWeaponSkillTreeController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId, req.query.Category as string);
|
||||||
const payload = getJSONfromString<ISetWeaponSkillTreeRequest>(String(req.body));
|
const payload = getJSONfromString<ISetWeaponSkillTreeRequest>(String(req.body));
|
||||||
|
|
||||||
const item = inventory[req.query.Category as WeaponTypeInternal].find(
|
const item = inventory[req.query.Category as WeaponTypeInternal].id(req.query.ItemId as string)!;
|
||||||
item => item._id.toString() == (req.query.ItemId as string)
|
|
||||||
)!;
|
|
||||||
item.SkillTree = payload.SkillTree;
|
item.SkillTree = payload.SkillTree;
|
||||||
|
|
||||||
await inventory.save();
|
await inventory.save();
|
||||||
|
@ -5,7 +5,7 @@ import { getInventory } from "@/src/services/inventoryService";
|
|||||||
export const popArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
|
export const popArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const suit = inventory.Suits.find(suit => suit._id.toString() == (req.query.oid as string));
|
const suit = inventory.Suits.id(req.query.oid as string);
|
||||||
if (suit && suit.ArchonCrystalUpgrades) {
|
if (suit && suit.ArchonCrystalUpgrades) {
|
||||||
suit.ArchonCrystalUpgrades = suit.ArchonCrystalUpgrades.filter(
|
suit.ArchonCrystalUpgrades = suit.ArchonCrystalUpgrades.filter(
|
||||||
x => x.UpgradeType != (req.query.type as string)
|
x => x.UpgradeType != (req.query.type as string)
|
||||||
|
@ -5,7 +5,7 @@ import { getInventory } from "@/src/services/inventoryService";
|
|||||||
export const pushArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
|
export const pushArchonCrystalUpgradeController: RequestHandler = async (req, res) => {
|
||||||
const accountId = await getAccountIdForRequest(req);
|
const accountId = await getAccountIdForRequest(req);
|
||||||
const inventory = await getInventory(accountId);
|
const inventory = await getInventory(accountId);
|
||||||
const suit = inventory.Suits.find(suit => suit._id.toString() == (req.query.oid as string));
|
const suit = inventory.Suits.id(req.query.oid as string);
|
||||||
if (suit) {
|
if (suit) {
|
||||||
suit.ArchonCrystalUpgrades ??= [];
|
suit.ArchonCrystalUpgrades ??= [];
|
||||||
const count = (req.query.count as number | undefined) ?? 1;
|
const count = (req.query.count as number | undefined) ?? 1;
|
||||||
|
@ -84,9 +84,7 @@ export const handleInventoryItemConfigChange = async (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const oldLoadoutConfig = loadout[loadoutSlot].find(
|
const oldLoadoutConfig = loadout[loadoutSlot].id(loadoutId);
|
||||||
loadout => loadout._id.toString() === loadoutId
|
|
||||||
);
|
|
||||||
|
|
||||||
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
|
const { ItemId, ...loadoutConfigItemIdRemoved } = loadoutConfig;
|
||||||
const loadoutConfigDatabase: ILoadoutConfigDatabase = {
|
const loadoutConfigDatabase: ILoadoutConfigDatabase = {
|
||||||
|
@ -61,19 +61,17 @@ export const handleSetShipDecorations = async (
|
|||||||
if (placedDecoration.MoveId) {
|
if (placedDecoration.MoveId) {
|
||||||
//moved within the same room
|
//moved within the same room
|
||||||
if (placedDecoration.OldRoom === placedDecoration.Room) {
|
if (placedDecoration.OldRoom === placedDecoration.Room) {
|
||||||
const existingDecorationIndex = roomToPlaceIn.PlacedDecos.findIndex(
|
const existingDecoration = roomToPlaceIn.PlacedDecos.id(placedDecoration.MoveId);
|
||||||
deco => deco._id.toString() === placedDecoration.MoveId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (existingDecorationIndex === -1) {
|
if (!existingDecoration) {
|
||||||
throw new Error("decoration to be moved not found");
|
throw new Error("decoration to be moved not found");
|
||||||
}
|
}
|
||||||
|
|
||||||
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Pos = placedDecoration.Pos;
|
existingDecoration.Pos = placedDecoration.Pos;
|
||||||
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Rot = placedDecoration.Rot;
|
existingDecoration.Rot = placedDecoration.Rot;
|
||||||
|
|
||||||
if (placedDecoration.Scale) {
|
if (placedDecoration.Scale) {
|
||||||
roomToPlaceIn.PlacedDecos[existingDecorationIndex].Scale = placedDecoration.Scale;
|
existingDecoration.Scale = placedDecoration.Scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
await personalRooms.save();
|
await personalRooms.save();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user