From f683c06c38adabe8f539b22ac98495a7647091ff Mon Sep 17 00:00:00 2001 From: ZackRhodes <30397274+ZackRhodes@users.noreply.github.com> Date: Sun, 11 Dec 2022 16:51:10 -0500 Subject: [PATCH] Add Cosmetic Purchasing --- .../core/secret-formula/shop-purchases.js | 4 +- public/Steam/steam.js | 60 ++++++++++++++++--- src/components/tabs/shop/ShopButton.vue | 8 ++- 3 files changed, 58 insertions(+), 14 deletions(-) diff --git a/javascripts/core/secret-formula/shop-purchases.js b/javascripts/core/secret-formula/shop-purchases.js index f3d77a591..69ff9c033 100644 --- a/javascripts/core/secret-formula/shop-purchases.js +++ b/javascripts/core/secret-formula/shop-purchases.js @@ -65,7 +65,7 @@ GameDatabase.shopPurchases = { shop.purchaseLongerTimeSkip(); } }, - /*singleCosmeticSet: { + singleCosmeticSet: { key: "singleCosmeticSet", cost: 20, description: "Unlock a Glyph cosmetic set of your choice", @@ -78,7 +78,7 @@ GameDatabase.shopPurchases = { GlyphAppearanceHandler.chosenFromModal = null; GlyphAppearanceHandler.applyNotification(); } - }, + },/* allCosmeticSets: { key: "allCosmeticSets", cost: () => { diff --git a/public/Steam/steam.js b/public/Steam/steam.js index f6a93b247..c71285a7e 100644 --- a/public/Steam/steam.js +++ b/public/Steam/steam.js @@ -123,21 +123,21 @@ const SteamFunctions = { }); }, ConfirmSteamPurchase(OrderIdentifier) { - console.log(OrderIdentifier); + //console.log(OrderIdentifier); PlayFab.ClientApi.ConfirmPurchase({ OrderId: OrderIdentifier }, (result, error) => { if (result !== null && result.data.Items != null) { - console.log(result); + //console.log(result); const PurchaseName = result.data.Items[0].ItemId; const PurchaseInstance = result.data.Items[0].ItemInstanceId; PlayFab.ClientApi.ConsumeItem({ ItemInstanceId: PurchaseInstance, ConsumeCount: 1 }, (consumeResult, consumeError) => { if (consumeResult !== null) { - console.log(consumeResult); + //console.log(consumeResult); const stdsBought = Number(PurchaseName.replace("STD", "")); const currencyAddRequest = {Amount: stdsBought,VirtualCurrency: "ST"} PlayFab.ClientApi.AddUserVirtualCurrency(currencyAddRequest, (result, error) => { if (result !== null) { - console.log(result); + //console.log(result); SteamFunctions.SyncPlayFabSTD() } else if (error !== null) { console.log(error); @@ -150,7 +150,7 @@ const SteamFunctions = { } }); } else if (error !== null) { - console.log(error); + console.log("Awaiting Payment Confirmation"); } }); }, @@ -164,7 +164,7 @@ const SteamFunctions = { SyncPlayFabSTD(){ PlayFab.ClientApi.GetUserInventory({PlayFabId: PlayFab.PlayFabId}, (result, error) => { if (result !== null) { - console.log(result); + //console.log(result); const CurrentSTD = result.data.VirtualCurrency.ST const Inventory = result.data.Inventory ShopPurchaseData.totalSTD = CurrentSTD @@ -174,28 +174,70 @@ const SteamFunctions = { ); for (const key of Object.keys(GameDatabase.shopPurchases)) ShopPurchaseData[key] = inventoryData[key] ?? 0; GameUI.update(); + SteamFunctions.GetCosmetics() } else if (error !== null) { console.log(error); } }) }, PurchaseShopItem(itemCost,itemKey,itemConfig,chosenSet){ - console.log(itemCost,itemKey,itemConfig,chosenSet) + //console.log(itemCost,itemKey,itemConfig,chosenSet) const itemPurchaseRequest = { ItemId: itemKey, Price: typeof itemCost === "function" ? itemCost() : itemCost, VirtualCurrency: "ST" } - console.log(itemPurchaseRequest) + //console.log(itemPurchaseRequest) PlayFab.ClientApi.PurchaseItem(itemPurchaseRequest, (result, error) => { if (result !== null) { - console.log(result); + //console.log(result); if (itemConfig.instantPurchase) itemConfig.onPurchase(); + if (itemKey === "singleCosmeticSet") this.StoreCosmetics(chosenSet) SteamFunctions.SyncPlayFabSTD(); } else if (error !== null) { console.log(error); GameUI.notify.error(error.errorMessage) } }) + }, + StoreCosmetics(Cosmetic){ + const CosmeticID = Object.entries(GameDatabase.reality.glyphCosmeticSets).filter(item => item[1]["name"]===Cosmetic)[0][0] + var CosmeticList = [CosmeticID] + PlayFab.ClientApi.GetUserData({PlayFabId: PlayFab.PlayFabId}, (result, error) => { + if (result !== null) { + if(result.data.Data["Cosmetics"]){ + CosmeticList = CosmeticList.concat(result.data.Data["Cosmetics"].Value.split(",")) + } + const updatedCosmetics = [...new Set(CosmeticList)] + const UpdateRequest = { + Data: { + Cosmetics: updatedCosmetics.join(",") + } + } + //console.log(UpdateRequest) + PlayFab.ClientApi.UpdateUserData(UpdateRequest, (result, error) => { + if (result !== null) { + console.log("Cosmetics Updated on Server"); + ShopPurchaseData.unlockedCosmetics = updatedCosmetics + GameUI.update(); + } else if (error !== null) { + console.log(error); + } + }) + } else if (error !== null) { + console.log("Error Getting User Data"); + } + }) + }, + GetCosmetics(){ + PlayFab.ClientApi.GetUserData({PlayFabId: PlayFab.PlayFabId}, (result, error) => { + if (result !== null) { + const currentCosmetics = result.data.Data["Cosmetics"] ? result.data.Data["Cosmetics"].Value.split(",") : [] + ShopPurchaseData.unlockedCosmetics = currentCosmetics + GameUI.update(); + } else if (error !== null) { + console.log(error); + } + }) } }; \ No newline at end of file diff --git a/src/components/tabs/shop/ShopButton.vue b/src/components/tabs/shop/ShopButton.vue index caad164e5..655b7ed7a 100644 --- a/src/components/tabs/shop/ShopButton.vue +++ b/src/components/tabs/shop/ShopButton.vue @@ -45,8 +45,10 @@ export default { openSelectionModal() { Modal.cosmeticSetChoice.show(); }, - TestPurchase(){ - SteamFunctions.PurchaseShopItem(this.purchase.cost,this.purchase.config.key,this.purchase.config,this.chosenSet) + SteamPurchase(){ + if(!this.isSingleCosmeticSet || this.hasChosen){ + SteamFunctions.PurchaseShopItem(this.purchase.cost,this.purchase.config.key,this.purchase.config,this.chosenSet) + } }, purchaseButtonObject() { return { @@ -94,7 +96,7 @@ export default {