mirror of
https://github.com/opentibiabr/canary
synced 2026-08-16 06:26:09 -04:00
This refactors a comprehensive set of modules for the GameStore system, including constants, helpers, and parsers. The changes establish a robust foundation for handling store offers, user actions, and transactions in a modular and maintainable way. The most important changes are the addition of a detailed constants file, helper functions for offer handling, and a parser module that manages all store-related protocol events and purchase logic. **GameStore System Foundation** * Added a new `gamestore.constants.lua` file containing all core constants for the GameStore, such as offer types, sub-actions, action types, coin types, error codes, packet codes, default values, descriptions, and item limits. This centralizes configuration and improves maintainability. **Helper Functions** * Introduced `gamestore.helpers.lua` with utility functions for converting offer types to display types and determining if an offer requires configuration, improving code reuse and clarity in offer handling. **Store Event and Purchase Parsing** * Added `gamestore.parsers.lua` which handles all GameStore protocol events, including opening the store, searching offers, buying offers, transferring coins, and transaction history. This module coordinates with helpers and senders to process requests and responses, including error handling and purchase validation. These changes collectively lay out the structure for a feature-rich, extensible GameStore system, making future enhancements and debugging easier. --------- Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
99 lines
3 KiB
Lua
99 lines
3 KiB
Lua
local gamestoreLibPath = CORE_DIRECTORY .. "/libs/gamestore"
|
|
|
|
local function moduleLoader(name)
|
|
return dofile(gamestoreLibPath .. "/" .. name .. ".lua")
|
|
end
|
|
|
|
local modulesToPreload = {
|
|
["gamestore.constants"] = function()
|
|
return moduleLoader("constants")
|
|
end,
|
|
["gamestore.helpers"] = function()
|
|
return moduleLoader("helpers")
|
|
end,
|
|
["gamestore.store"] = function()
|
|
return moduleLoader("store")
|
|
end,
|
|
["gamestore.senders"] = function()
|
|
return moduleLoader("senders")
|
|
end,
|
|
["gamestore.purchases"] = function()
|
|
return moduleLoader("purchases")
|
|
end,
|
|
["gamestore.parsers"] = function()
|
|
return moduleLoader("parsers")
|
|
end,
|
|
["gamestore.player"] = function()
|
|
return moduleLoader("player")
|
|
end,
|
|
}
|
|
|
|
for name, loader in pairs(modulesToPreload) do
|
|
if not package.preload[name] then
|
|
package.preload[name] = loader
|
|
end
|
|
end
|
|
|
|
local constants = package.loaded["gamestore.constants"] or moduleLoader("constants")
|
|
package.loaded["gamestore.constants"] = constants
|
|
|
|
local helpers = package.loaded["gamestore.helpers"] or moduleLoader("helpers")
|
|
package.loaded["gamestore.helpers"] = helpers
|
|
|
|
GameStore = GameStore or {}
|
|
for key, value in pairs(constants) do
|
|
GameStore[key] = value
|
|
end
|
|
|
|
local convertType = helpers.convertType
|
|
local useOfferConfigure = helpers.useOfferConfigure
|
|
|
|
_G.convertType = convertType
|
|
_G.useOfferConfigure = useOfferConfigure
|
|
|
|
GameStore.convertType = convertType
|
|
GameStore.useOfferConfigure = useOfferConfigure
|
|
|
|
local storeLib = require("gamestore.store")
|
|
for key, value in pairs(storeLib) do
|
|
GameStore[key] = value
|
|
end
|
|
|
|
local senders = require("gamestore.senders")
|
|
local purchases = require("gamestore.purchases")
|
|
for key, value in pairs(purchases) do
|
|
GameStore[key] = value
|
|
end
|
|
|
|
local parsers = require("gamestore.parsers")
|
|
GameStore.isItsPacket = parsers.isItsPacket
|
|
GameStore.fuzzySearchOffer = parsers.fuzzySearchOffer
|
|
|
|
local playerLib = require("gamestore.player")
|
|
for key, value in pairs(playerLib) do
|
|
Player[key] = value
|
|
end
|
|
|
|
-- Expose senders and parsers functions for compatibility
|
|
openStore = senders.openStore
|
|
sendOfferDescription = senders.sendOfferDescription
|
|
sendShowStoreOffers = senders.sendShowStoreOffers
|
|
sendShowStoreOffersOnOldProtocol = senders.sendShowStoreOffersOnOldProtocol
|
|
sendStoreTransactionHistory = senders.sendStoreTransactionHistory
|
|
sendStorePurchaseSuccessful = senders.sendStorePurchaseSuccessful
|
|
sendStoreError = senders.sendStoreError
|
|
sendStoreBalanceUpdating = senders.sendStoreBalanceUpdating
|
|
sendUpdatedStoreBalances = senders.sendUpdatedStoreBalances
|
|
sendRequestPurchaseData = senders.sendRequestPurchaseData
|
|
sendHomePage = senders.sendHomePage
|
|
|
|
parseTransferableCoins = parsers.parseTransferableCoins
|
|
parseOpenStore = parsers.parseOpenStore
|
|
parseRequestStoreOffers = parsers.parseRequestStoreOffers
|
|
parseBuyStoreOffer = parsers.parseBuyStoreOffer
|
|
parseOpenTransactionHistory = parsers.parseOpenTransactionHistory
|
|
parseRequestTransactionHistory = parsers.parseRequestTransactionHistory
|
|
|
|
function onRecvbyte(player, msg, byte)
|
|
return parsers.onRecvbyte(player, msg, byte)
|
|
end
|