新增碎片&钻石
This commit is contained in:
@@ -86,6 +86,7 @@ exports.DeleteDeck = async(req, res) => {
|
||||
return res.status(200).send(upUser.decks);
|
||||
};
|
||||
|
||||
// 购买卡片
|
||||
exports.BuyCard = async (req, res) => {
|
||||
|
||||
const userId = req.jwt.userId;
|
||||
@@ -117,17 +118,17 @@ exports.BuyCard = async (req, res) => {
|
||||
var variant = await VariantModel.get(variantId);
|
||||
var factor = variant != null ? variant.cost_factor : 1;
|
||||
var cost = quantity * factor * card.cost;
|
||||
if(user.coins < cost)
|
||||
return res.status(400).send({ error: "Not enough coins" });
|
||||
if(user.cardfragments < cost)
|
||||
return res.status(400).send({ error: "Not enough cardfragments" });
|
||||
|
||||
user.coins -= cost;
|
||||
user.cardfragments -= cost;
|
||||
|
||||
var valid = await UserTool.addCards(user, [{tid: cardId, variant: variantId, quantity: quantity}]);
|
||||
if (!valid)
|
||||
return res.status(500).send({ error: "Error when adding cards" });
|
||||
|
||||
//Update the user array
|
||||
var updatedUser = await UserModel.save(user, ["coins", "cards"]);
|
||||
var updatedUser = await UserModel.save(user, ["cardfragments", "cards"]);
|
||||
if (!updatedUser) return res.status(500).send({ error: "Error updating user: " + userId });
|
||||
|
||||
// Activity Log -------------
|
||||
@@ -175,14 +176,14 @@ exports.SellCard = async (req, res) => {
|
||||
|
||||
var factor = variant != null ? variant.cost_factor : 1;
|
||||
var cost = quantity * Math.round(card.cost * factor * config.sell_ratio);
|
||||
user.coins += cost;
|
||||
user.cardfragments += cost;
|
||||
|
||||
var valid = await UserTool.addCards(user, [{tid: cardId, variant: variantId, quantity: -quantity}]);
|
||||
if (!valid)
|
||||
return res.status(500).send({ error: "Error when removing cards" });
|
||||
|
||||
//Update the user array
|
||||
var updatedUser = await UserModel.save(user, ["coins", "cards"]);
|
||||
var updatedUser = await UserModel.save(user, ["cardfragments", "cards"]);
|
||||
if (!updatedUser) return res.status(500).send({ error: "Error updating user: " + userId });
|
||||
|
||||
// Activity Log -------------
|
||||
@@ -224,7 +225,7 @@ exports.SellDuplicateCards = async (req, res) => {
|
||||
return res.status(404).send({ error: "Cant find cards" });
|
||||
|
||||
var cards_to_sell = [];
|
||||
var coins = 0;
|
||||
var cardfragments = 0;
|
||||
for(var i=0; i<user.cards.length; i++)
|
||||
{
|
||||
var card = user.cards[i];
|
||||
@@ -241,7 +242,7 @@ exports.SellDuplicateCards = async (req, res) => {
|
||||
var factor = variant != null ? variant.cost_factor : 1;
|
||||
var cost = quantity * Math.round(card_data.cost * factor * config.sell_ratio);
|
||||
cards_to_sell.push(sell);
|
||||
coins += cost;
|
||||
cardfragments += cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -250,14 +251,14 @@ exports.SellDuplicateCards = async (req, res) => {
|
||||
if(cards_to_sell.length == 0)
|
||||
return res.status(200).send();
|
||||
|
||||
user.coins += coins;
|
||||
user.cardfragments += cardfragments;
|
||||
|
||||
var valid = await UserTool.addCards(user, cards_to_sell);
|
||||
if (!valid)
|
||||
return res.status(500).send({ error: "Error when removing cards" });
|
||||
|
||||
//Update the user array
|
||||
var updatedUser = await UserModel.save(user, ["coins", "cards"]);
|
||||
var updatedUser = await UserModel.save(user, ["cardfragments", "cards"]);
|
||||
if (!updatedUser) return res.status(500).send({ error: "Error updating user: " + userId });
|
||||
|
||||
// Activity Log -------------
|
||||
@@ -269,6 +270,7 @@ exports.SellDuplicateCards = async (req, res) => {
|
||||
return res.status(200).send();
|
||||
};
|
||||
|
||||
// 购买卡包 TODO 金币&钻石
|
||||
exports.BuyPack = async (req, res) => {
|
||||
|
||||
const userId = req.jwt.userId;
|
||||
|
||||
Reference in New Issue
Block a user