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: gifting bonus (#2036)

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

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

代码差异

1 个文件 +22 -9
Modified src/controllers/api/giftingController.ts +22 -9
@@ -2,12 +2,13 @@ import { getJSONfromString } from "@/src/helpers/stringHelpers";
2 2 import { Account } from "@/src/models/loginModel";
3 3 import { areFriends } from "@/src/services/friendService";
4 4 import { createMessage } from "@/src/services/inboxService";
5 import { getInventory, updateCurrency } from "@/src/services/inventoryService";
5 import { combineInventoryChanges, getInventory, updateCurrency } from "@/src/services/inventoryService";
6 6 import { getAccountForRequest, getSuffixedName } from "@/src/services/loginService";
7 import { handleStoreItemAcquisition } from "@/src/services/purchaseService";
7 8 import { IOid } from "@/src/types/commonTypes";
8 import { IPurchaseParams } from "@/src/types/purchaseTypes";
9 import { IInventoryChanges, IPurchaseParams } from "@/src/types/purchaseTypes";
9 10 import { RequestHandler } from "express";
10 import { ExportFlavour } from "warframe-public-export-plus";
11 import { ExportBundles, ExportFlavour } from "warframe-public-export-plus";
11 12
12 13 export const giftingController: RequestHandler = async (req, res) => {
13 14 const data = getJSONfromString<IGiftingRequest>(String(req.body));
@@ -44,10 +45,7 @@ export const giftingController: RequestHandler = async (req, res) => {
44 45 // TODO: Cannot gift archwing items to players that have not completed the archwing quest. (Code 7)
45 46 // TODO: Cannot gift necramechs to players that have not completed heart of deimos. (Code 20)
46 47
47 const senderInventory = await getInventory(
48 senderAccount._id.toString(),
49 "PremiumCredits PremiumCreditsFree ActiveAvatarImageType GiftsRemaining"
50 );
48 const senderInventory = await getInventory(senderAccount._id.toString());
51 49
52 50 if (senderInventory.GiftsRemaining == 0) {
53 51 res.status(400).send("10").end();
@@ -55,7 +53,20 @@ export const giftingController: RequestHandler = async (req, res) => {
55 53 }
56 54 senderInventory.GiftsRemaining -= 1;
57 55
58 updateCurrency(senderInventory, data.PurchaseParams.ExpectedPrice, true);
56 const inventoryChanges: IInventoryChanges = updateCurrency(
57 senderInventory,
58 data.PurchaseParams.ExpectedPrice,
59 true
60 );
61 if (data.PurchaseParams.StoreItem in ExportBundles) {
62 const bundle = ExportBundles[data.PurchaseParams.StoreItem];
63 if (bundle.giftingBonus) {
64 combineInventoryChanges(
65 inventoryChanges,
66 (await handleStoreItemAcquisition(bundle.giftingBonus, senderInventory)).InventoryChanges
67 );
68 }
69 }
59 70 await senderInventory.save();
60 71
61 72 const senderName = getSuffixedName(senderAccount);
@@ -83,7 +94,9 @@ export const giftingController: RequestHandler = async (req, res) => {
83 94 }
84 95 ]);
85 96
86 res.end();
97 res.json({
98 InventoryChanges: inventoryChanges
99 });
87 100 };
88 101
89 102 interface IGiftingRequest {