From 2dc7521c14235fff5249509cb15419df3a0ab120 Mon Sep 17 00:00:00 2001 From: Zordon1337 Date: Fri, 2 Aug 2024 18:59:01 +0200 Subject: [PATCH] Added handler for shop cases but can't get it to work for now --- Utils/Boxes.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++---- index.js | 24 ++++++++++++++++++ 2 files changed, 85 insertions(+), 5 deletions(-) diff --git a/Utils/Boxes.js b/Utils/Boxes.js index 0411547..58bfe83 100644 --- a/Utils/Boxes.js +++ b/Utils/Boxes.js @@ -3,16 +3,22 @@ function CalculateChance(boxType) { if(boxType.includes("lolbox.ultra")) { - return 0.75; + return 0.65; } if(boxType.includes("lolbox.mega")) { - return 0.50; + return 0.35; } if(boxType.includes("lolbox.lite")) { - return 0.25; + return 0.01; } + if(boxType.includes("lolbox.cosmic")) + return 0.80; + if(boxType.includes("lolbox.supreme")) + return 0.50; + if(boxType.includes("lolbox.massive")) + return 0.25; return 0.0; } function CalculateCards(boxType) @@ -29,6 +35,56 @@ function CalculateCards(boxType) { return 4; } + if(boxType.includes("lolbox.cosmic")) + return 10; + if(boxType.includes("lolbox.supreme")) + return 8; + if(boxType.includes("lolbox.massive")) + return 6; + return 4; +} +function CalculateGold(boxType) +{ + if(boxType.includes("lolbox.ultra")) + { + return 15000; + } + if(boxType.includes("lolbox.mega")) + { + return 1500; + } + if(boxType.includes("lolbox.lite")) + { + return 4000; + } + if(boxType.includes("lolbox.cosmic")) + return 40000; + if(boxType.includes("lolbox.supreme")) + return 15000; + if(boxType.includes("lolbox.massive")) + return 5000; + return 4; +} +function CalculateShards(boxType) +{ + if(boxType.includes("lolbox.ultra")) + { + return 5000; + } + if(boxType.includes("lolbox.mega")) + { + return 2500; + } + if(boxType.includes("lolbox.lite")) + { + return 750; + } + if(boxType.includes("lolbox.cosmic")) + return 7000; + if(boxType.includes("lolbox.supreme")) + return 3000; + if(boxType.includes("lolbox.massive")) + return 1000; return 4; } function RandomBox(boxType, data) @@ -38,14 +94,14 @@ function RandomBox(boxType, data) const WeaponSkins = JSON.parse(fs.readFileSync("./Helpers/WeaponSkins.json", "utf-8")); BoxContainer = [ { - "Amount": Math.floor(Math.random() * 20000), + "Amount": Math.floor(Math.random() * CalculateGold(boxType)), "RewardType": "LOLCoins" } ]; for (let i = 0; i < CalculateCards(boxType); i++) { let rand = Math.floor(Math.random() * ChampionsJson.length); if (data.Champions.OwnedChampions[ChampionsJson[rand]] != null) { - let shards = Math.floor(Math.random() * 200); + let shards = Math.floor(Math.random() * CalculateShards(boxType)); BoxContainer.push({ "ProductID": ChampionsJson[rand], "RewardType": "Blueprints", "Amount": shards }); data.Champions.ChampionShards[ChampionsJson[rand]] += shards; } else { diff --git a/index.js b/index.js index 5f69456..d9dea6f 100644 --- a/index.js +++ b/index.js @@ -324,4 +324,28 @@ app.post("/v4710_champions/upgrade",(req,res)=>{ }); }) }) +app.post("/v4710_product/coinPurchase",(req,res)=>{ + const token = buffer.from((req.headers['x-forwarded-for'] || req.socket.remoteAddress)+req.headers['Host']).toString('base64');; + database.getUserData(token, (err, data) => { + if (err) { + res.status(500).send({ error: 'Failed to retrieve user data' }); + return; + } + let cost = req.body.cost + let id = req.body.id + let currency = req.body.currencyType; + if(currency == "LT") // gems aka LOL Tokens + { + data.GeneralData.LoLTokens-=cost; + } + database.updateUserData(token, data, (err) => { + if (err) { + res.status(500).send({ error: 'Failed to update rewards' }); + return; + } + log(`User ${data.GeneralData.Nickname} bought ${id} for ${cost} LOL Tokens`); + res.json(BoxesUtil.RandomBox(id,data)) + }); + }) +}) app.listen(80); \ No newline at end of file