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

SpaceNinjaServer

A simple server for a small space ninja game

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

XFEstudio/SpaceNinjaServer

feat: personal deco capacity costs (#2329)

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

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

代码差异

3 个文件 +37 -22
Modified src/controllers/api/placeDecoInComponentController.ts +5 -1
@@ -57,7 +57,11 @@ export const placeDecoInComponentController: RequestHandler = async (req, res) =
57 57 component.DecoCapacity -= meta.capacityCost;
58 58 }
59 59 } else {
60 const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)![0];
60 const [itemType, meta] = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)!;
61 if (!itemType || meta.dojoCapacityCost === undefined) {
62 throw new Error(`unknown deco type: ${deco.Type}`);
63 }
64 component.DecoCapacity -= meta.dojoCapacityCost;
61 65 if (deco.Sockets !== undefined) {
62 66 guild.VaultFusionTreasures!.find(x => x.ItemType == itemType && x.Sockets == deco.Sockets)!.ItemCount -=
63 67 1;
Modified src/services/guildService.ts +2 -1
@@ -349,7 +349,8 @@ export const removeDojoDeco = (
349 349 component.DecoCapacity! += meta.capacityCost;
350 350 }
351 351 } else {
352 const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)![0];
352 const [itemType, meta] = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)!;
353 component.DecoCapacity! += meta.dojoCapacityCost!;
353 354 if (deco.Sockets !== undefined) {
354 355 addVaultFusionTreasures(guild, [
355 356 {
Modified src/services/shipCustomizationsService.ts +30 -20
@@ -59,7 +59,12 @@ export const handleSetShipDecorations = async (
59 59 const roomToPlaceIn = rooms.find(room => room.Name === placedDecoration.Room);
60 60
61 61 if (!roomToPlaceIn) {
62 throw new Error("room not found");
62 throw new Error(`unknown room: ${placedDecoration.Room}`);
63 }
64
65 const [itemType, meta] = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)!;
66 if (!itemType || meta.capacityCost === undefined) {
67 throw new Error(`unknown deco type: ${placedDecoration.Type}`);
63 68 }
64 69
65 70 if (placedDecoration.MoveId) {
@@ -83,7 +88,7 @@ export const handleSetShipDecorations = async (
83 88 OldRoom: placedDecoration.OldRoom,
84 89 NewRoom: placedDecoration.Room,
85 90 IsApartment: placedDecoration.IsApartment,
86 MaxCapacityIncrease: 0 // TODO: calculate capacity change upon removal
91 MaxCapacityIncrease: 0
87 92 };
88 93 }
89 94
@@ -96,6 +101,7 @@ export const handleSetShipDecorations = async (
96 101 }
97 102
98 103 oldRoom.PlacedDecos.pull({ _id: placedDecoration.MoveId });
104 oldRoom.MaxCapacity += meta.capacityCost;
99 105
100 106 const newDecoration = {
101 107 Type: placedDecoration.Type,
@@ -108,12 +114,14 @@ export const handleSetShipDecorations = async (
108 114
109 115 //the new room is still roomToPlaceIn
110 116 roomToPlaceIn.PlacedDecos.push(newDecoration);
117 roomToPlaceIn.MaxCapacity -= meta.capacityCost;
118
111 119 await personalRooms.save();
112 120 return {
113 121 OldRoom: placedDecoration.OldRoom,
114 122 NewRoom: placedDecoration.Room,
115 123 IsApartment: placedDecoration.IsApartment,
116 MaxCapacityIncrease: 0 // TODO: calculate capacity change upon removal
124 MaxCapacityIncrease: -meta.capacityCost
117 125 };
118 126 }
119 127
@@ -121,11 +129,11 @@ export const handleSetShipDecorations = async (
121 129 const decoIndex = roomToPlaceIn.PlacedDecos.findIndex(x => x._id.equals(placedDecoration.RemoveId));
122 130 const deco = roomToPlaceIn.PlacedDecos[decoIndex];
123 131 roomToPlaceIn.PlacedDecos.splice(decoIndex, 1);
132 roomToPlaceIn.MaxCapacity += meta.capacityCost;
124 133 await personalRooms.save();
125 134
126 135 if (!config.unlockAllShipDecorations) {
127 136 const inventory = await getInventory(accountId);
128 const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == deco.Type)![0];
129 137 if (deco.Sockets !== undefined) {
130 138 addFusionTreasures(inventory, [{ ItemType: itemType, Sockets: deco.Sockets, ItemCount: 1 }]);
131 139 } else {
@@ -138,24 +146,20 @@ export const handleSetShipDecorations = async (
138 146 DecoId: placedDecoration.RemoveId,
139 147 Room: placedDecoration.Room,
140 148 IsApartment: placedDecoration.IsApartment,
141 MaxCapacityIncrease: 0
149 MaxCapacityIncrease: 0 // Client already implies the capacity being refunded.
142 150 };
143 } else {
144 if (!config.unlockAllShipDecorations) {
145 const inventory = await getInventory(accountId);
146 const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)![0];
147 if (placedDecoration.Sockets !== undefined) {
148 addFusionTreasures(inventory, [
149 { ItemType: itemType, Sockets: placedDecoration.Sockets, ItemCount: -1 }
150 ]);
151 } else {
152 addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: -1 }]);
153 }
154 await inventory.save();
155 }
156 151 }
157 152
158 // TODO: handle capacity
153 if (!config.unlockAllShipDecorations) {
154 const inventory = await getInventory(accountId);
155 const itemType = Object.entries(ExportResources).find(arr => arr[1].deco == placedDecoration.Type)![0];
156 if (placedDecoration.Sockets !== undefined) {
157 addFusionTreasures(inventory, [{ ItemType: itemType, Sockets: placedDecoration.Sockets, ItemCount: -1 }]);
158 } else {
159 addShipDecorations(inventory, [{ ItemType: itemType, ItemCount: -1 }]);
160 }
161 await inventory.save();
162 }
159 163
160 164 //place decoration
161 165 const decoId = new Types.ObjectId();
@@ -167,10 +171,16 @@ export const handleSetShipDecorations = async (
167 171 Sockets: placedDecoration.Sockets,
168 172 _id: decoId
169 173 });
174 roomToPlaceIn.MaxCapacity -= meta.capacityCost;
170 175
171 176 await personalRooms.save();
172 177
173 return { DecoId: decoId.toString(), Room: placedDecoration.Room, IsApartment: placedDecoration.IsApartment };
178 return {
179 DecoId: decoId.toString(),
180 Room: placedDecoration.Room,
181 IsApartment: placedDecoration.IsApartment,
182 MaxCapacityIncrease: -meta.capacityCost
183 };
174 184 };
175 185
176 186 export const handleSetPlacedDecoInfo = async (accountId: string, req: ISetPlacedDecoInfoRequest): Promise<void> => {