Skip to content

Commit

Permalink
added champion upgrading
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordon1337 committed Aug 2, 2024
1 parent a2970bf commit 4087187
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions Utils/Logic.js
Original file line number Diff line number Diff line change
@@ -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}
39 changes: 37 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);

0 comments on commit 4087187

Please sign in to comment.