From 40871874fc5788dc01044c09f5d62df287d90114 Mon Sep 17 00:00:00 2001 From: Zordon1337 Date: Fri, 2 Aug 2024 15:40:26 +0200 Subject: [PATCH] added champion upgrading --- Utils/Logic.js | 5 +++++ index.js | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 Utils/Logic.js diff --git a/Utils/Logic.js b/Utils/Logic.js new file mode 100644 index 0000000..31298f1 --- /dev/null +++ b/Utils/Logic.js @@ -0,0 +1,5 @@ +function CalculateShards(level) { + let baseCosts = [25, 50, 100, 250, 500, 1000, 2000,4000,5000,8000]; + return baseCosts[level] +} +module.exports = {CalculateShards} \ No newline at end of file diff --git a/index.js b/index.js index ffd826b..5f69456 100644 --- a/index.js +++ b/index.js @@ -6,6 +6,7 @@ const app = express(); var buffer = require('buffer/').Buffer; const database = require("./db.js") const BoxesUtil = require("./Utils/Boxes.js") +const ShardsUtil = require("./Utils/Logic.js") app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' })); function calculateTrophies(placement, trophiesForFirstPlace, trophiesForFourteenthPlace, totalPlaces) { @@ -222,7 +223,7 @@ app.post("/v4710_rankRoad/claimRoadReward", (req, res) => { let claimedReward = {}; if (rewardID.includes("lolbox")) { // handle box opening - if(rewardID != "lol.1v1.lolbox.mystery_champion_rank_bronze_1") + if(!rewardID.includes("lol.1v1.lolbox.mystery_champion")) { claimedReward = BoxesUtil.RandomBox(rewardID,data) } else { @@ -288,5 +289,39 @@ app.post("/v4710_player/nickname", (req, res) => { }); }); }); - +app.post("/v4710_champions/upgrade",(req,res)=>{ + var champion = req.body.championId + var levelsToAdd = req.body.levelsToAdd + 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; + } + // too bad, need to check if player actually has the champion + var level = data.Champions.OwnedChampions[champion].Level; + if(level == 0) + { + log(`${data.GeneralData.Nickname} upgraded ${champion} to level ${level + 1} which costs 25 shards`) + data.Champions.OwnedChampions[champion].Level++; + data.Champions.ChampionShards[champion]-=(level+1) * 25; + } else { + console.log(levelsToAdd) + for(let i = 1; i <= levelsToAdd; i++) + { + log(`${data.GeneralData.Nickname} upgraded ${champion} to level ${level+1} which costs ${(ShardsUtil.CalculateShards(level))} shards`) + data.Champions.OwnedChampions[champion].Level++; + data.Champions.ChampionShards[champion]-=(ShardsUtil.CalculateShards(level)); + level = data.Champions.OwnedChampions[champion].Level; + } + } + database.updateUserData(token, data, (err) => { + if (err) { + res.status(500).send({ error: 'Failed to update data' }); + return; + } + res.send('true'); + }); + }) +}) app.listen(80); \ No newline at end of file