Initial commit
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
const ItemBoughtPacket = require("../Packets/ItemBought");
|
||||
const packet_57 = require("../Packets/packet_57");
|
||||
|
||||
const BASE_SHOP = require("../Data/shop");
|
||||
const { SHOP, SHOP_ENTRIES_BUY } = BASE_SHOP;
|
||||
|
||||
module.exports = async function (ws, message, player) {
|
||||
const categoryID = message.getUint8(1);
|
||||
const itemID = message.getUint8(2);
|
||||
const rawAmount = message.getUint32(3);
|
||||
|
||||
let bought = {
|
||||
categoryID,
|
||||
id: itemID,
|
||||
amount: 0
|
||||
};
|
||||
|
||||
const itemToBuy = SHOP.find(entry => entry.categoryID === categoryID && entry.itemID === itemID);
|
||||
console.info(categoryID, itemID, SHOP)
|
||||
if (!itemToBuy) {
|
||||
const boughtItemConfirmationPacket = ItemBoughtPacket(bought);
|
||||
return player.map.registerIndividualNetworkPacket(player.id, boughtItemConfirmationPacket);
|
||||
};
|
||||
|
||||
const isItemAvailable = itemToBuy.isAvailable(player);
|
||||
if (!isItemAvailable) return;
|
||||
|
||||
if (SHOP_ENTRIES_BUY[player.id] && SHOP_ENTRIES_BUY[player.id]?.[categoryID]?.[itemID] >= itemToBuy.maximumPlayerAmount) {
|
||||
bought = {
|
||||
categoryID,
|
||||
id: itemID,
|
||||
amount: 0
|
||||
};
|
||||
|
||||
const boughtItemConfirmationPacket = ItemBoughtPacket(bought);
|
||||
return player.map.registerIndividualNetworkPacket(player.id, boughtItemConfirmationPacket);
|
||||
};
|
||||
|
||||
const amount = rawAmount; // Math.min(rawAmount, (itemToBuy.maximumPlayerAmount || Infinity) - alreadyBoughtAmount)
|
||||
bought.amount = amount;
|
||||
|
||||
player.rewardCallback({
|
||||
isRegular: true,
|
||||
authorID: player.id,
|
||||
source: {},
|
||||
rewards: [{
|
||||
categoryID,
|
||||
id: itemID,
|
||||
amount
|
||||
}]
|
||||
});
|
||||
|
||||
player.inventory.refreshSingle({
|
||||
categoryID: 1,
|
||||
id: itemToBuy.currencyType,
|
||||
amount: itemToBuy.currencyAmount * amount * -1
|
||||
});
|
||||
|
||||
const packets = [];
|
||||
const boughtItemConfirmationPacket = ItemBoughtPacket(bought);
|
||||
packets.push(boughtItemConfirmationPacket);
|
||||
|
||||
console.info("bought", bought);
|
||||
|
||||
if (false && alreadyBoughtAmount + amount >= itemToBuy.maximumPlayerAmount) {
|
||||
const removeShopEntryPacket = packet_57({
|
||||
id: itemID,
|
||||
shopCategoryID: itemToBuy.shopCategoryID
|
||||
});
|
||||
|
||||
packets.push(removeShopEntryPacket);
|
||||
};
|
||||
|
||||
player.map.registerIndividualNetworkPacket(player.id, packets);
|
||||
};
|
||||
Reference in New Issue
Block a user