From a0a7b462d2418ef8176d9bc6f79f56b147636d1b Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Mon, 11 Mar 2024 15:16:35 -0300 Subject: [PATCH 01/10] gamestore: set CoinType Transferable as default and created limit consts. --- data/modules/scripts/gamestore/gamestore.lua | 2 +- data/modules/scripts/gamestore/init.lua | 29 +++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/data/modules/scripts/gamestore/gamestore.lua b/data/modules/scripts/gamestore/gamestore.lua index 852bd4d4405..f000c4079af 100644 --- a/data/modules/scripts/gamestore/gamestore.lua +++ b/data/modules/scripts/gamestore/gamestore.lua @@ -6770,7 +6770,7 @@ for k, category in ipairs(GameStore.Categories) do offer.type = GameStore.OfferTypes.OFFER_TYPE_NONE end if not offer.coinType then - offer.coinType = GameStore.CoinType.Coin + offer.coinType = GameStore.CoinType.Transferable end end end diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 6146f562307..7feeffa8783 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -206,6 +206,13 @@ GameStore.DefaultDescriptions = { TEMPLE = { "Need a quick way home? Buy this transportation service to get instantly teleported to your home temple. \n\nNote, you cannot use this service while having a battle sign or a protection zone block. Further, the service will not work in no-logout zones or close to your home temple." }, } +GameStore.ItemLimit = { + PREY_WILDCARD = 50, + INSTANT_REWARD_ACCESS = 90, + EXPBOOST = 6, + HIRELING = 10, +} + --==Parsing==-- GameStore.isItsPacket = function(byte) for k, v in pairs(GameStore.RecivedPackets) do @@ -697,12 +704,12 @@ function Player.canBuyOffer(self, offer) disabledReason = "You already have this mount." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS then - if self:getCollectionTokens() >= 90 then + if self:getCollectionTokens() >= GameStore.ItemLimit.INSTANT_REWARD_ACCESS then disabled = 1 disabledReason = "You already have maximum of reward tokens." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYBONUS then - if self:getPreyCards() >= 50 then + if self:getPreyCards() >= GameStore.ItemLimit.PREY_WILDCARD then disabled = 1 disabledReason = "You already have maximum of prey wildcards." end @@ -722,7 +729,7 @@ function Player.canBuyOffer(self, offer) disabledReason = "You already have 3 slots released." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then - if self:getStorageValue(GameStore.Storages.expBoostCount) == 6 then + if self:getStorageValue(GameStore.Storages.expBoostCount) == GameStore.ItemLimit.EXPBOOST then disabled = 1 disabledReason = "You can't buy XP Boost for today." end @@ -731,7 +738,7 @@ function Player.canBuyOffer(self, offer) disabledReason = "You already have an active XP boost." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING then - if self:getHirelingsCount() >= 10 then + if self:getHirelingsCount() >= GameStore.ItemLimit.HIRELING then disabled = 1 disabledReason = "You already have bought the maximum number of allowed hirelings." end @@ -1565,8 +1572,9 @@ function GameStore.processAllBlessingsPurchase(player, count) end function GameStore.processInstantRewardAccess(player, offerCount) - if player:getCollectionTokens() + offerCount >= 91 then - return error({ code = 1, message = "You cannot own more than 90 reward tokens." }) + local limit = GameStore.ItemLimit.INSTANT_REWARD_ACCESS + if player:getCollectionTokens() + offerCount >= limit + 1 then + return error({ code = 1, message = "You cannot own more than " .. limit .. " reward tokens." }) end player:setCollectionTokens(player:getCollectionTokens() + offerCount) end @@ -1769,8 +1777,9 @@ function GameStore.processTaskHuntingThirdSlot(player) end function GameStore.processPreyBonusReroll(player, offerCount) - if player:getPreyCards() + offerCount >= 51 then - return error({ code = 1, message = "You cannot own more than 50 prey wildcards." }) + local limit = GameStore.ItemLimit.PREY_WILDCARD + if player:getPreyCards() + offerCount >= limit + 1 then + return error({ code = 1, message = "You cannot own more than " .. limit .. " prey wildcards." }) end player:addPreyCards(offerCount) end @@ -1812,8 +1821,8 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN return addPlayerEvent(sendStorePurchaseSuccessful, 650, player:getId(), message) -- If not, we ask him to do! else - if player:getHirelingsCount() >= 10 then - return error({ code = 1, message = "You cannot have more than 10 hirelings." }) + if player:getHirelingsCount() >= GameStore.ItemLimit.HIRELING then + return error({ code = 1, message = "You cannot have more than " .. GameStore.ItemLimit.HIRELING .. " hirelings." }) end -- TODO: Use the correct dialog (byte 0xDB) on client 1205+ -- for compatibility, request name using the change name dialog From a8db0c375a199dc34b54277d5a3f5d4e7dcbc980 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Mon, 11 Mar 2024 15:18:08 -0300 Subject: [PATCH 02/10] .gitignore: fixes on gitignore, maintain only files necessary, update vcproj and added exclude files. --- .gitignore | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d233ae17409..a73a8c3022c 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,9 @@ bld/ [Ll]og/ build/ vcproj/ +!vcproj/canary.sln +!vcproj/canary.vcxproj +!vcproj/settings.props # Visual Studio 2015/2017 cache/options directory .vs/ @@ -372,9 +375,7 @@ config.lua config_canary.lua client_assertions.txt .env -otservbr.otbm -canary.otbm -otservbr-custom.otbm +data-otservbr-global/world/otservbr.otbm # Extensions *.ini @@ -382,9 +383,6 @@ otservbr-custom.otbm *.exe *.manifest *.rar -*-house.xml -*-monster.xml -*-npc.xml monster_count.txt # SFTP for Sublime @@ -398,4 +396,4 @@ canary.old vcpkg_installed # CLION -cmake-build-debug* +cmake-build-* From 93416a5295d3baa0d8d05faf1bf43c7d5db73b77 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Mon, 11 Mar 2024 17:50:53 -0300 Subject: [PATCH 03/10] vcpkg: update builtin-baseline version. --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index dda054f3774..ad742354699 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -32,5 +32,5 @@ "platform": "windows" } ], - "builtin-baseline": "095ee06e7f60dceef7d713e3f8b1c2eb10d650d7" + "builtin-baseline": "9765877106f7c179995e8010bb7427a865a6bd1d" } From f865793f52243c7f37f8ccb63fe7161e7e9a7a6f Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Tue, 12 Mar 2024 17:51:16 -0300 Subject: [PATCH 04/10] items.xml: fix level of sanguine coil. --- data/items/items.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data/items/items.xml b/data/items/items.xml index 765c6e9db51..0bc1c782452 100644 --- a/data/items/items.xml +++ b/data/items/items.xml @@ -75427,7 +75427,7 @@ Granted by TibiaGoals.com"/> - + @@ -75455,7 +75455,7 @@ Granted by TibiaGoals.com"/> - + From 6fa242145062a7cfbb00734362cb642d99cda5c5 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Wed, 27 Mar 2024 12:31:47 -0300 Subject: [PATCH 05/10] Checking msg is not empty to avoid empties broadcasts. --- src/game/game.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/game/game.cpp b/src/game/game.cpp index cac0b596ebf..b45f60551b2 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -7836,9 +7836,11 @@ void Game::addBestiaryList(uint16_t raceid, std::string name) { } void Game::broadcastMessage(const std::string &text, MessageClasses type) const { - g_logger().info("Broadcasted message: {}", text); - for (const auto &it : players) { - it.second->sendTextMessage(type, text); + if (!text.empty()) { + g_logger().info("Broadcasted message: {}", text); + for (const auto &it : players) { + it.second->sendTextMessage(type, text); + } } } From 9dd863965aae8ebc13c4f82cf3ccad784f03224c Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Thu, 18 Apr 2024 11:06:20 -0300 Subject: [PATCH 06/10] gamestore improvements. fix `player:sendUpdateContainer(inbox)` to be called just one time. --- data/modules/scripts/gamestore/init.lua | 53 +++++++++++-------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 7feeffa8783..476c7c20887 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -408,28 +408,25 @@ function parseBuyStoreOffer(playerId, msg) end -- All guarding conditions under which the offer should not be processed must be included here - if - not table.contains(GameStore.OfferTypes, offer.type) -- we've got an invalid offer type + if not table.contains(GameStore.OfferTypes, offer.type) -- we've got an invalid offer type or not player or (player:getVocation():getId() == 0) and (not GameStore.haveOfferRook(id)) -- we don't have such offer or not offer or (offer.type == GameStore.OfferTypes.OFFER_TYPE_NONE) -- offer is disabled - or ( - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYBONUS - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT - and not offer.id - ) + or (offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYBONUS + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT + and not offer.id) then return queueSendStoreAlertToUser("This offer is unavailable [1]", 350, playerId, GameStore.StoreErrors.STORE_ERROR_INFORMATION) end @@ -514,7 +511,8 @@ function parseBuyStoreOffer(playerId, msg) if not pcallOk then local alertMessage = pcallError.code and pcallError.message or "Something went wrong. Your purchase has been cancelled." - if not pcallError.code then -- unhandled error + if not pcallError.code then + -- unhandled error -- log some debugging info logger.warn("[parseBuyStoreOffer] - Purchase failed due to an unhandled script error. Stacktrace: {}", pcallError) end @@ -625,14 +623,12 @@ function sendOfferDescription(player, offerId, description) end function Player.canBuyOffer(self, offer) - local playerId = self:getId() local disabled, disabledReason = 0, "" if offer.disabled or not offer.type then disabled = 1 end - if - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE + if offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT @@ -1649,7 +1645,6 @@ function GameStore.processHouseRelatedPurchase(player, offer) decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end end - player:sendUpdateContainer(inbox) else for i = 1, offer.count do local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1) @@ -1661,10 +1656,10 @@ function GameStore.processHouseRelatedPurchase(player, offer) decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end end - player:sendUpdateContainer(inbox) end end end + player:sendUpdateContainer(inbox) end end @@ -1685,10 +1680,9 @@ function GameStore.processOutfitPurchase(player, offerSexIdTable, addon) elseif player:hasOutfit(looktype, _addon) then return error({ code = 0, message = "You already own this outfit." }) else - if - not (player:addOutfitAddon(looktype, _addon)) -- TFS call failed - or (not player:hasOutfit(looktype, _addon)) -- Additional check; if the looktype doesn't match player sex for example, - -- then the TFS check will still pass... bug? (TODO) + -- TFS call failed and Additional check; if the looktype doesn't match player sex for example, + if not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) + -- then the TFS check will still pass... bug? (TODO) then error({ code = 0, message = "There has been an issue with your outfit purchase. Your purchase has been cancelled." }) else @@ -2228,7 +2222,8 @@ function sendHomePage(playerId) msg:sendToPlayer(player) end -function Player:openStore(serviceName) --exporting the method so other scripts can use to open store +--exporting the method so other scripts can use to open store +function Player:openStore(serviceName) local playerId = self:getId() openStore(playerId) From 7c6999862e4387c6dcea30e30e9aee3c6c08b99c Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 18 Apr 2024 14:07:02 +0000 Subject: [PATCH 07/10] Lua code format - (Stylua) --- data/modules/scripts/gamestore/init.lua | 41 ++++++++++++++----------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 476c7c20887..b9511e769da 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -408,25 +408,28 @@ function parseBuyStoreOffer(playerId, msg) end -- All guarding conditions under which the offer should not be processed must be included here - if not table.contains(GameStore.OfferTypes, offer.type) -- we've got an invalid offer type + if + not table.contains(GameStore.OfferTypes, offer.type) -- we've got an invalid offer type or not player or (player:getVocation():getId() == 0) and (not GameStore.haveOfferRook(id)) -- we don't have such offer or not offer or (offer.type == GameStore.OfferTypes.OFFER_TYPE_NONE) -- offer is disabled - or (offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYBONUS - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL - and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT - and not offer.id) + or ( + offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYBONUS + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_INSTANT_REWARD_ACCESS + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT + and not offer.id + ) then return queueSendStoreAlertToUser("This offer is unavailable [1]", 350, playerId, GameStore.StoreErrors.STORE_ERROR_INFORMATION) end @@ -628,7 +631,8 @@ function Player.canBuyOffer(self, offer) disabled = 1 end - if offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE + if + offer.type ~= GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_EXPBOOST and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_PREYSLOT and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT @@ -1681,8 +1685,9 @@ function GameStore.processOutfitPurchase(player, offerSexIdTable, addon) return error({ code = 0, message = "You already own this outfit." }) else -- TFS call failed and Additional check; if the looktype doesn't match player sex for example, - if not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) - -- then the TFS check will still pass... bug? (TODO) + if + not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) + -- then the TFS check will still pass... bug? (TODO) then error({ code = 0, message = "There has been an issue with your outfit purchase. Your purchase has been cancelled." }) else From b998ac999105fad77585a326ae523ad1b3d89c40 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Thu, 18 Apr 2024 11:18:54 -0300 Subject: [PATCH 08/10] vcpkg: update builtin-baseline with last commit. --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index ad742354699..5eb71177edb 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -32,5 +32,5 @@ "platform": "windows" } ], - "builtin-baseline": "9765877106f7c179995e8010bb7427a865a6bd1d" + "builtin-baseline": "501cb01e517ee5689577bb01ba8bd1b4c1041a53" } From da98856c2b61ad2f4376bccc29357d38e4f4b624 Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Sat, 20 Apr 2024 21:33:15 -0300 Subject: [PATCH 09/10] some adjusts. --- data/modules/scripts/gamestore/init.lua | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index b9511e769da..e53bab813f0 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -514,9 +514,8 @@ function parseBuyStoreOffer(playerId, msg) if not pcallOk then local alertMessage = pcallError.code and pcallError.message or "Something went wrong. Your purchase has been cancelled." + -- unhandled error if not pcallError.code then - -- unhandled error - -- log some debugging info logger.warn("[parseBuyStoreOffer] - Purchase failed due to an unhandled script error. Stacktrace: {}", pcallError) end @@ -1684,11 +1683,7 @@ function GameStore.processOutfitPurchase(player, offerSexIdTable, addon) elseif player:hasOutfit(looktype, _addon) then return error({ code = 0, message = "You already own this outfit." }) else - -- TFS call failed and Additional check; if the looktype doesn't match player sex for example, - if - not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) - -- then the TFS check will still pass... bug? (TODO) - then + if not player:addOutfitAddon(looktype, _addon) or not player:hasOutfit(looktype, _addon) then error({ code = 0, message = "There has been an issue with your outfit purchase. Your purchase has been cancelled." }) else player:addOutfitAddon(offerSexIdTable.male, _addon) From efe784ea3a6d611ae58c81abf695e3ac48016fad Mon Sep 17 00:00:00 2001 From: Elson Costa Date: Tue, 23 Apr 2024 08:48:21 -0300 Subject: [PATCH 10/10] vcpkg: remove changes on builtin-baseline. --- vcpkg.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg.json b/vcpkg.json index 5eb71177edb..dda054f3774 100644 --- a/vcpkg.json +++ b/vcpkg.json @@ -32,5 +32,5 @@ "platform": "windows" } ], - "builtin-baseline": "501cb01e517ee5689577bb01ba8bd1b4c1041a53" + "builtin-baseline": "095ee06e7f60dceef7d713e3f8b1c2eb10d650d7" }