Skip to content

Commit

Permalink
Added handler for shop cases but can't get it to work for now
Browse files Browse the repository at this point in the history
  • Loading branch information
Zordon1337 committed Aug 2, 2024
1 parent 4087187 commit 2dc7521
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 5 deletions.
66 changes: 61 additions & 5 deletions Utils/Boxes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
24 changes: 24 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 2dc7521

Please sign in to comment.