diff --git a/.luarc.json b/.luarc.json new file mode 100644 index 00000000000..440870ada6a --- /dev/null +++ b/.luarc.json @@ -0,0 +1,3 @@ +{ + "workspace.maxPreload": 10000 +} \ No newline at end of file diff --git a/data/modules/scripts/gamestore/init.lua b/data/modules/scripts/gamestore/init.lua index 44a95897fd9..d879b1ca6cb 100644 --- a/data/modules/scripts/gamestore/init.lua +++ b/data/modules/scripts/gamestore/init.lua @@ -2,7 +2,7 @@ GameStore = { ModuleName = "GameStore", Developers = { "Cjaker", "metabob", "Rick" }, Version = "1.1", - LastUpdated = "25-07-2020 11:52AM" + LastUpdated = "25-07-2020 11:52AM", } --== Enums ==-- @@ -34,7 +34,6 @@ GameStore.OfferTypes = { OFFER_TYPE_HIRELING_OUTFIT = 24, OFFER_TYPE_HUNTINGSLOT = 25, OFFER_TYPE_ITEM_BED = 26, - OFFER_TYPE_ITEM_UNIQUE = 27, } GameStore.SubActions = { @@ -53,7 +52,7 @@ GameStore.SubActions = { BLESSING_ALL_PVP = 12, CHARM_EXPANSION = 13, TASKHUNTING_THIRDSLOT = 14, - PREY_THIRDSLOT_REDIRECT = 15 + PREY_THIRDSLOT_REDIRECT = 15, } GameStore.ActionType = { @@ -71,7 +70,7 @@ GameStore.CoinType = { } GameStore.Storages = { - expBoostCount = 51052 + expBoostCount = 51052, } GameStore.ConverType = { @@ -79,12 +78,12 @@ GameStore.ConverType = { SHOW_MOUNT = 1, SHOW_OUTFIT = 2, SHOW_ITEM = 3, - SHOW_HIRELING = 4 + SHOW_HIRELING = 4, } GameStore.ConfigureOffers = { SHOW_NORMAL = 0, - SHOW_CONFIGURE = 1 + SHOW_CONFIGURE = 1, } function convertType(type) @@ -98,7 +97,6 @@ function convertType(type) [GameStore.OfferTypes.OFFER_TYPE_CHARGES] = GameStore.ConverType.SHOW_ITEM, [GameStore.OfferTypes.OFFER_TYPE_HIRELING] = GameStore.ConverType.SHOW_HIRELING, [GameStore.OfferTypes.OFFER_TYPE_ITEM_BED] = GameStore.ConverType.SHOW_NONE, - [GameStore.OfferTypes.OFFER_TYPE_ITEM_UNIQUE] = GameStore.ConverType.SHOW_ITEM, } if not types[type] then @@ -113,7 +111,7 @@ function useOfferConfigure(type) [GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE] = GameStore.ConfigureOffers.SHOW_CONFIGURE, [GameStore.OfferTypes.OFFER_TYPE_HIRELING] = GameStore.ConfigureOffers.SHOW_CONFIGURE, [GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE] = GameStore.ConfigureOffers.SHOW_CONFIGURE, - [GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE] = GameStore.ConfigureOffers.SHOW_CONFIGURE + [GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE] = GameStore.ConfigureOffers.SHOW_CONFIGURE, } if not types[type] then @@ -132,14 +130,14 @@ GameStore.ClientOfferTypes = { GameStore.HistoryTypes = { HISTORY_TYPE_NONE = 0, HISTORY_TYPE_GIFT = 1, - HISTORY_TYPE_REFUND = 2 + HISTORY_TYPE_REFUND = 2, } GameStore.States = { STATE_NONE = 0, STATE_NEW = 1, STATE_SALE = 2, - STATE_TIMED = 3 + STATE_TIMED = 3, } GameStore.StoreErrors = { @@ -147,14 +145,14 @@ GameStore.StoreErrors = { STORE_ERROR_NETWORK = 1, STORE_ERROR_HISTORY = 2, STORE_ERROR_TRANSFER = 3, - STORE_ERROR_INFORMATION = 4 + STORE_ERROR_INFORMATION = 4, } GameStore.ServiceTypes = { SERVICE_STANDERD = 0, SERVICE_OUTFITS = 3, SERVICE_MOUNTS = 4, - SERVICE_BLESSINGS = 5 + SERVICE_BLESSINGS = 5, } GameStore.SendingPackets = { @@ -165,7 +163,7 @@ GameStore.SendingPackets = { S_OpenStore = 0xFB, -- 251 S_StoreOffers = 0xFC, -- 252 S_OpenTransactionHistory = 0xFD, -- 253 - S_CompletePurchase = 0xFE -- 254 + S_CompletePurchase = 0xFE, -- 254 } GameStore.RecivedPackets = { @@ -184,29 +182,26 @@ GameStore.ExpBoostValues = { [2] = 45, [3] = 90, [4] = 180, - [5] = 360 + [5] = 360, } GameStore.DefaultValues = { - DEFAULT_VALUE_ENTRIES_PER_PAGE = 26 + DEFAULT_VALUE_ENTRIES_PER_PAGE = 26, } GameStore.DefaultDescriptions = { - OUTFIT = { "This outfit looks nice. Only high-class people are able to wear it!", - "An outfit that was created to suit you. We are sure you'll like it.", - "Legend says only smart people should wear it, otherwise you will burn!" }, - MOUNT = { "This is a fantastic mount that helps to become faster, try it!", - "The first rider of this mount became the leader of his country! legends say that." }, - NAMECHANGE = { "Are you hunted? Tired of that? Get a new name, a new life!", - "A new name to suit your needs!" }, + OUTFIT = { "This outfit looks nice. Only high-class people are able to wear it!", "An outfit that was created to suit you. We are sure you'll like it.", "Legend says only smart people should wear it, otherwise you will burn!" }, + MOUNT = { "This is a fantastic mount that helps to become faster, try it!", "The first rider of this mount became the leader of his country! legends say that." }, + NAMECHANGE = { "Are you hunted? Tired of that? Get a new name, a new life!", "A new name to suit your needs!" }, SEXCHANGE = { "Bored of your character's sex? Get a new sex for him now!!" }, EXPBOOST = { "Are you tired of leveling slow? try it!" }, PREYSLOT = { - "It's hunting season! Activate a prey to gain a bonus when hunting a certain monster. Every character can purchase one Permanent Prey Slot, which enables the activation of an additional prey. \nIf you activate a prey, you can select one monster out of nine. The bonus for your prey will be selected randomly from one of the following: damage boost, damage reduction, bonus XP, improved loot. The bonus value may range from 5% to 50%. Your prey will be active for 2 hours hunting time: the duration of an active prey will only be reduced while you are hunting." }, + "It's hunting season! Activate a prey to gain a bonus when hunting a certain monster. Every character can purchase one Permanent Prey Slot, which enables the activation of an additional prey. \nIf you activate a prey, you can select one monster out of nine. The bonus for your prey will be selected randomly from one of the following: damage boost, damage reduction, bonus XP, improved loot. The bonus value may range from 5% to 50%. Your prey will be active for 2 hours hunting time: the duration of an active prey will only be reduced while you are hunting.", + }, PREYBONUS = { - "You activated a prey but do not like the randomly selected bonus? Roll for a new one! Here you can purchase five Prey Bonus Rerolls! \nA Bonus Reroll allows you to get a bonus with a higher value (max. 50%). The bonus for your prey will be selected randomly from one of the following: damage boost, damage reduction, bonus XP, improved loot. The 2 hours hunting time will start anew once you have rolled for a new bonus. Your prey monster will stay the same." }, - 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." } + "You activated a prey but do not like the randomly selected bonus? Roll for a new one! Here you can purchase five Prey Bonus Rerolls! \nA Bonus Reroll allows you to get a bonus with a higher value (max. 50%). The bonus for your prey will be selected randomly from one of the following: damage boost, damage reduction, bonus XP, improved loot. The 2 hours hunting time will start anew once you have rolled for a new bonus. Your prey monster will stay the same.", + }, + 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." }, } --==Parsing==-- @@ -239,7 +234,9 @@ local function queueSendStoreAlertToUser(message, delay, playerId, storeErrorCod end function onRecvbyte(player, msg, byte) - if not configManager.getBoolean(STOREMODULES) then return true end + if not configManager.getBoolean(STOREMODULES) then + return true + end if player:getVocation():getId() == 0 and not GameStore.haveCategoryRook() then return player:sendCancelMessage("Store don't have offers for rookgaard citizen.") end @@ -322,15 +319,14 @@ function parseRequestStoreOffers(playerId, msg) local actionType = msg:getByte() local oldProtocol = player:getClient().version < 1200 + local categoryName = msg:getString() if oldProtocol then - local categoryName = msg:getString() - local category = GameStore.getCategoryByName(categoryName, player) + local category = GameStore.getCategoryByName(categoryName) if category then addPlayerEvent(sendShowStoreOffersOnOldProtocol, 350, playerId, category) end elseif actionType == GameStore.ActionType.OPEN_CATEGORY then - local categoryName = msg:getString() local category = GameStore.getCategoryByName(categoryName) if category then addPlayerEvent(sendShowStoreOffers, 50, playerId, category) @@ -383,7 +379,7 @@ function parseRequestStoreOffers(playerId, msg) local searchString = msg:getString() local results = GameStore.fuzzySearchOffer(searchString) if not results or #results == 0 then - return addPlayerEvent(sendStoreError, 250, playerId, GameStore.StoreErrors.STORE_ERROR_INFORMATION, "No results found for \"" .. searchString .. "\".") + return addPlayerEvent(sendStoreError, 250, playerId, GameStore.StoreErrors.STORE_ERROR_INFORMATION, 'No results found for "' .. searchString .. '".') end local searchResultsCategory = { @@ -400,27 +396,34 @@ function parseBuyStoreOffer(playerId, msg) local id = msg:getU32() local offer = GameStore.getOfferById(id) local productType = msg:getByte() + if not offer then + return false + end -- All guarding conditions under which the offer should not be processed must be included here - if (table.contains(GameStore.OfferTypes, offer.type) == false) -- we've got an invalid offer type - or (not player) -- player not found + if + (table.contains(GameStore.OfferTypes, offer.type) == false) -- 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) -- we could not find the 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_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_POUCH 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 + 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_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_POUCH + 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 @@ -461,7 +464,8 @@ function parseBuyStoreOffer(playerId, msg) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_MOUNT then GameStore.processMountPurchase(player, offer.id) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_NAMECHANGE then - local newName = msg:getString(); GameStore.processNameChangePurchase(player, offer, productType, newName) + local newName = msg:getString() + GameStore.processNameChangePurchase(player, offer, productType, newName) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE then GameStore.processSexChangePurchase(player) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then @@ -477,9 +481,12 @@ function parseBuyStoreOffer(playerId, msg) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_CHARGES then GameStore.processChargesPurchase(player, offer.itemtype, offer.name, offer.charges, offer.moveable) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING then - local hirelingName = msg:getString(); local sex = msg:getByte(); GameStore.processHirelingPurchase(player, offer, productType, hirelingName, sex) + local hirelingName = msg:getString() + local sex = msg:getByte() + GameStore.processHirelingPurchase(player, offer, productType, hirelingName, sex) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING_NAMECHANGE then - local hirelingName = msg:getString(); GameStore.processHirelingChangeNamePurchase(player, offer, productType, hirelingName) + local hirelingName = msg:getString() + GameStore.processHirelingChangeNamePurchase(player, offer, productType, hirelingName) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING_SEXCHANGE then GameStore.processHirelingChangeSexPurchase(player, offer) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL then @@ -533,7 +540,7 @@ end local function getCategoriesRook() local tmpTable, count = {}, 0 for i, v in pairs(GameStore.Categories) do - if (v.rookgaard) then + if v.rookgaard then tmpTable[#tmpTable+1] = v count = count + 1 end @@ -561,7 +568,7 @@ function openStore(playerId) end local GameStoreCategories, GameStoreCount = nil, 0 - if (player:getVocation():getId() == 0) then + if player:getVocation():getId() == 0 then GameStoreCategories, GameStoreCount = getCategoriesRook() else GameStoreCategories, GameStoreCount = GameStore.Categories, #GameStore.Categories @@ -589,7 +596,7 @@ function openStore(playerId) end end - if (GameStoreCategories) then + if GameStoreCategories then msg:addU16(GameStoreCount) for _, category in ipairs(GameStoreCategories) do addCategory(category) @@ -614,16 +621,18 @@ function Player.canBuyOffer(self, offer) disabled = 1 end - 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_PREYBONUS and - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE and - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE and - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_POUCH and - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL and - offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT and - not offer.id then + 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_PREYBONUS + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_TEMPLE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_POUCH + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_SKILL + and offer.type ~= GameStore.OfferTypes.OFFER_TYPE_HIRELING_OUTFIT + and not offer.id + then disabled = 1 end @@ -637,7 +646,7 @@ function Player.canBuyOffer(self, offer) local pounch = self:getItemById(23721, true) if pounch then disabled = 1 - disabledReason = "You already have a " .. item:getName() .. "." + disabledReason = "You already have Loot Pouch." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_BLESSINGS then if self:getBlessingCount(offer.blessid) >= 5 then @@ -716,7 +725,7 @@ function Player.canBuyOffer(self, offer) disabled = 1 disabledReason = "You can't buy XP Boost for today." end - if (remainingBoost > 0) then + if remainingBoost > 0 then disabled = 1 disabledReason = "You already have an active XP boost." end @@ -783,7 +792,7 @@ function sendShowStoreOffers(playerId, category, redirectId) categoryLimit = 0 end - if not (oldProtocol) then + if not oldProtocol then msg:addU32(redirectId or 0) msg:addByte(0) -- Window Type msg:addByte(0) -- Collections Size @@ -821,14 +830,14 @@ function sendShowStoreOffers(playerId, category, redirectId) end local canBuy = player:canBuyOffer(offer) - if (canBuy.disabled == 1) then + if canBuy.disabled == 1 then for index, disableTable in ipairs(disableReasons) do - if (canBuy.disabledReason == disableTable.reason) then + if canBuy.disabledReason == disableTable.reason then offer.disabledReadonIndex = index end end - if (offer.disabledReadonIndex == nil) then + if offer.disabledReadonIndex == nil then offer.disabledReadonIndex = #disableReasons table.insert(disableReasons, canBuy.disabledReason) end @@ -865,16 +874,16 @@ function sendShowStoreOffers(playerId, category, redirectId) msg:addByte(off.coinType or 0x00) msg:addByte((off.disabledReadonIndex ~= nil) and 1 or 0) - if (off.disabledReadonIndex ~= nil) then - msg:addByte(0x01); + if off.disabledReadonIndex ~= nil then + msg:addByte(0x01) msg:addU16(off.disabledReadonIndex) off.disabledReadonIndex = nil -- Reseting the table to nil disable reason end - if (off.state) then - if (off.state == GameStore.States.STATE_SALE) then + if off.state then + if off.state == GameStore.States.STATE_SALE then local daySub = off.validUntil - os.date("*t").day - if (daySub >= 0) then + if daySub >= 0 then msg:addByte(off.state) msg:addU32(os.time() + daySub * 86400) msg:addU32(off.basePrice) @@ -893,7 +902,7 @@ function sendShowStoreOffers(playerId, category, redirectId) local tryOnType = 0 local type = convertType(offer.type) - msg:addByte(type); + msg:addByte(type) if type == GameStore.ConverType.SHOW_NONE then msg:addString(offer.icons[1]) elseif type == GameStore.ConverType.SHOW_MOUNT then @@ -963,7 +972,7 @@ function sendShowStoreOffersOnOldProtocol(playerId, category) msg:addByte(GameStore.SendingPackets.S_StoreOffers) msg:addString(category.name) - if not (category.offers) then + if not category.offers then msg:addU16(0) msg:sendToPlayer(player) player:sendButtonIndication(haveSaleOffer, 1) @@ -975,7 +984,7 @@ function sendShowStoreOffersOnOldProtocol(playerId, category) for _, offer in ipairs(category.offers) do if limit > 0 then -- Blocking offers that are not on coin currency. On old protocol we cannot change or validate any currency instead the default (Coin) - if (not (offer.coinType) or offer.coinType == GameStore.CoinType.Coin) then + if not offer.coinType or offer.coinType == GameStore.CoinType.Coin then count = count + 1 end limit = limit - 1 @@ -984,7 +993,7 @@ function sendShowStoreOffersOnOldProtocol(playerId, category) msg:addU16(count) for _, offer in ipairs(category.offers) do - if (count > 0 and offer.coinType == GameStore.CoinType.Coin) then + if count > 0 and offer.coinType == GameStore.CoinType.Coin then count = count - 1 local name = "" if offer.type == GameStore.OfferTypes.OFFER_TYPE_ITEM and offer.count then @@ -997,9 +1006,9 @@ function sendShowStoreOffersOnOldProtocol(playerId, category) name = name .. (offer.name or "Something Special") local newPrice = nil - if (offer.state == GameStore.States.STATE_SALE) then + if offer.state == GameStore.States.STATE_SALE then local daySub = offer.validUntil - os.sdate("*t").day - if (daySub < 0) then + if daySub < 0 then newPrice = offer.basePrice end end @@ -1010,10 +1019,10 @@ function sendShowStoreOffersOnOldProtocol(playerId, category) msg:addString(name) msg:addString(offer.description or GameStore.getDefaultDescription(offer.type, offer.count)) msg:addU32(offerPrice) - if (offer.state) then - if (offer.state == GameStore.States.STATE_SALE) then + if offer.state then + if offer.state == GameStore.States.STATE_SALE then local daySub = offer.validUntil - os.sdate("*t").day - if (daySub >= 0) then + if daySub >= 0 then msg:addByte(offer.state) msg:addU32(os.stime() + daySub * 86400) msg:addU32(offer.basePrice) @@ -1075,7 +1084,7 @@ function sendStoreTransactionHistory(playerId, page, entriesPerPage) msg:addByte(#entries) for k, entry in ipairs(entries) do - if not (oldProtocol) then + if not oldProtocol then msg:addU32(0) end msg:addU32(entry.time) @@ -1085,7 +1094,7 @@ function sendStoreTransactionHistory(playerId, page, entriesPerPage) msg:addByte(0x0) -- 0 = transferable tibia coin, 1 = normal tibia coin end msg:addString(entry.description) - if not (oldProtocol) then + if not oldProtocol then msg:addByte(0) -- details end end @@ -1359,7 +1368,7 @@ end GameStore.canUseHirelingName = function(name) local result = { - ability = false + ability = false, } if name:len() < 3 or name:len() > 14 then result.reason = "The length of the hireling name must be between 3 and 14 characters." @@ -1373,18 +1382,18 @@ GameStore.canUseHirelingName = function(name) end local matchtwo = name:match("^%s+") - if (matchtwo) then + if matchtwo then result.reason = "The hireling name can't have whitespace at begin." return result end local matchthree = name:match("[^a-zA-Z ]") - if (matchthree) then + if matchthree then result.reason = "The hireling name has invalid characters" return result end - if (count > 1) then + if count > 1 then result.reason = "The hireling name have more than 1 whitespace." return result end @@ -1395,7 +1404,7 @@ GameStore.canUseHirelingName = function(name) for k, word in ipairs(words) do for k, nameWord in ipairs(split) do if nameWord:lower() == word then - result.reason = "You can't use word \"" .. word .. "\" in your hireling name." + result.reason = "You can't use word \"" .. word .. '" in your hireling name.' return result end end @@ -1403,8 +1412,8 @@ GameStore.canUseHirelingName = function(name) local tmpName = name:gsub("%s+", "") for i = 1, #words do - if (tmpName:lower():find(words[i])) then - result.reason = "You can't use word \"" .. words[i] .. "\" with whitespace in your hireling name." + if tmpName:lower():find(words[i]) then + result.reason = "You can't use word \"" .. words[i] .. '" with whitespace in your hireling name.' return result end end @@ -1415,7 +1424,7 @@ end GameStore.canChangeToName = function(name) local result = { - ability = false + ability = false, } if name:len() < 3 or name:len() > 14 then result.reason = "The length of your new name must be between 3 and 14 characters." @@ -1429,12 +1438,12 @@ GameStore.canChangeToName = function(name) end local matchtwo = name:match("^%s+") - if (matchtwo) then + if matchtwo then result.reason = "Your new name can't have whitespace at begin." return result end - if (count > 1) then + if count > 1 then result.reason = "Your new name have more than 1 whitespace." return result end @@ -1445,7 +1454,7 @@ GameStore.canChangeToName = function(name) for k, word in ipairs(words) do for k, nameWord in ipairs(split) do if nameWord:lower() == word then - result.reason = "You can't use word \"" .. word .. "\" in your new name." + result.reason = "You can't use word \"" .. word .. '" in your new name.' return result end end @@ -1453,17 +1462,17 @@ GameStore.canChangeToName = function(name) local tmpName = name:gsub("%s+", "") for i = 1, #words do - if (tmpName:lower():find(words[i])) then - result.reason = "You can't use word \"" .. words[i] .. "\" with whitespace in your new name." + if tmpName:lower():find(words[i]) then + result.reason = "You can't use word \"" .. words[i] .. '" with whitespace in your new name.' return result end end if MonsterType(name) then - result.reason = "Your new name \"" .. name .. "\" can't be a monster's name." + result.reason = 'Your new name "' .. name .. "\" can't be a monster's name." return result elseif Npc(name) then - result.reason = "Your new name \"" .. name .. "\" can't be a npc's name." + result.reason = 'Your new name "' .. name .. "\" can't be a npc's name." return result end @@ -1473,7 +1482,7 @@ GameStore.canChangeToName = function(name) for i = 1, name:len() do local m = name:sub(i, i) if m == c then - result.reason = "You can't use this letter \"" .. c .. "\" in your new name." + result.reason = "You can't use this letter \"" .. c .. '" in your new name.' return result end end @@ -1576,14 +1585,14 @@ function GameStore.processStackablePurchase(player, offerId, offerCount, offerNa if inbox and inbox:getEmptySlots() > 0 then if (isKeg and offerCount > 500) or offerCount > 100 then local parcel = inbox:addItem(PARCEL_ID, 1) - parcel:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()); + parcel:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) if parcel then - parcel:setAttribute(ITEM_ATTRIBUTE_NAME, '' .. offerCount .. 'x ' .. offerName .. ' package.') + parcel:setAttribute(ITEM_ATTRIBUTE_NAME, "" .. offerCount .. "x " .. offerName .. " package.") local pendingCount = offerCount local limit = isKeg and 500 or 100 - while (pendingCount > 0) do + while pendingCount > 0 do local pack - if (pendingCount > limit) then + if pendingCount > limit then pack = limit else pack = pendingCount @@ -1620,9 +1629,7 @@ end function GameStore.processHouseRelatedPurchase(player, offer) local function isCaskItem(itemId) - return (itemId >= ITEM_HEALTH_CASK_START and itemId <= ITEM_HEALTH_CASK_END) or - (itemId >= ITEM_MANA_CASK_START and itemId <= ITEM_MANA_CASK_END) or - (itemId >= ITEM_SPIRIT_CASK_START and itemId <= ITEM_SPIRIT_CASK_END) + return (itemId >= ITEM_HEALTH_CASK_START and itemId <= ITEM_HEALTH_CASK_END) or (itemId >= ITEM_MANA_CASK_START and itemId <= ITEM_MANA_CASK_END) or (itemId >= ITEM_SPIRIT_CASK_START and itemId <= ITEM_SPIRIT_CASK_END) end local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX) @@ -1667,7 +1674,8 @@ 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 + 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) then @@ -1692,8 +1700,8 @@ function GameStore.processNameChangePurchase(player, offer, productType, newName if productType == GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE then local tile = Tile(player:getPosition()) - if (tile) then - if (not tile:hasFlag(TILESTATE_PROTECTIONZONE)) then + if tile then + if not tile:hasFlag(TILESTATE_PROTECTIONZONE) then return error({ code = 1, message = "You can change name only in Protection Zone." }) end end @@ -1713,7 +1721,9 @@ function GameStore.processNameChangePurchase(player, offer, productType, newName local message = string.format("You have purchased %s for %d coins.", offer.name, offer.price) addPlayerEvent(sendStorePurchaseSuccessful, 500, playerId, message) - newName = newName:lower():gsub("(%l)(%w*)", function(a, b) return string.upper(a) .. b end) + newName = newName:lower():gsub("(%l)(%w*)", function(a, b) + return string.upper(a) .. b + end) db.query("UPDATE `players` SET `name` = " .. db.escapeString(newName) .. " WHERE `id` = " .. player:getGuid()) message = "You have successfully changed you name, relogin!" addEvent(function() @@ -1741,7 +1751,7 @@ function GameStore.processExpBoostPuchase(player) player:setStoreXpBoost(50) player:setExpBoostStamina(currentExpBoostTime + 3600) - if (player:getStorageValue(GameStore.Storages.expBoostCount) == -1 or expBoostCount == 6) then + if player:getStorageValue(GameStore.Storages.expBoostCount) == -1 or expBoostCount == 6 then player:setStorageValue(GameStore.Storages.expBoostCount, 1) end @@ -1776,7 +1786,7 @@ function GameStore.processTempleTeleportPurchase(player) player:teleportTo(player:getTown():getTemplePosition()) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have been teleported to your hometown.') + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have been teleported to your hometown.") end function GameStore.processHirelingPurchase(player, offer, productType, hirelingName, chosenSex) @@ -1793,7 +1803,9 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN return error({ code = 1, message = result.reason }) end - hirelingName = hirelingName:lower():gsub("(%l)(%w*)", function(a, b) return string.upper(a) .. b end) + hirelingName = hirelingName:lower():gsub("(%l)(%w*)", function(a, b) + return string.upper(a) .. b + end) local hireling = player:addNewHireling(hirelingName, chosenSex) if not hireling then @@ -1828,9 +1840,11 @@ function GameStore.processHirelingChangeNamePurchase(player, offer, productType, return error({ code = 1, message = result.reason }) end - newHirelingName = newHirelingName:lower():gsub("(%l)(%w*)", function(a, b) return string.upper(a) .. b end) + newHirelingName = newHirelingName:lower():gsub("(%l)(%w*)", function(a, b) + return string.upper(a) .. b + end) - local message = 'Close the store window to select which hireling should be renamed to ' .. newHirelingName + local message = "Close the store window to select which hireling should be renamed to " .. newHirelingName addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) addPlayerEvent(HandleHirelingNameChange, 550, playerId, offer, newHirelingName) @@ -1846,7 +1860,7 @@ function GameStore.processHirelingChangeSexPurchase(player, offer) return error({ code = 1, message = "You cannot buy hireling change sex on client 10, please relog on client 12 and try again." }) end - local message = 'Close the store window to select which hireling should have the sex changed.' + local message = "Close the store window to select which hireling should have the sex changed." addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) addPlayerEvent(HandleHirelingSexChange, 550, playerId, offer) @@ -1860,7 +1874,7 @@ function GameStore.processHirelingSkillPurchase(player, offer) player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) local skill = offer.id - HIRELING_STORAGE.SKILL player:enableHirelingSkill(skill) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'A new hireling skill has been added to all your hirelings') + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A new hireling skill has been added to all your hirelings") end function GameStore.processHirelingOutfitPurchase(player, offer) @@ -1871,7 +1885,7 @@ function GameStore.processHirelingOutfitPurchase(player, offer) player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) local outfit = offer.id - HIRELING_STORAGE.OUTFIT player:enableHirelingOutfit(outfit) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'A new hireling outfit has been added to all your hirelings') + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "A new hireling outfit has been added to all your hirelings") end --==Player==-- @@ -1963,7 +1977,7 @@ function Player.makeCoinTransaction(self, offer, desc) local op = true if desc then - desc = offer.name .. ' (' .. desc .. ')' + desc = offer.name .. " (" .. desc .. ")" else desc = offer.name end @@ -1981,7 +1995,7 @@ function Player.makeCoinTransaction(self, offer, desc) -- When the transaction is suscessfull add to the history if op then - GameStore.insertHistory(self:getAccountId(), GameStore.HistoryTypes.HISTORY_TYPE_NONE, desc, (offer.price) * -1, offer.coinType) + GameStore.insertHistory(self:getAccountId(), GameStore.HistoryTypes.HISTORY_TYPE_NONE, desc, offer.price * -1, offer.coinType) end return op @@ -2038,12 +2052,14 @@ end local function getHomeOffers(playerId) local player = Player(playerId) - if not player then return {} end + if not player then + return {} + end local GameStoreCategories = GameStore.Categories local offers = {} - if (GameStoreCategories) then + if GameStoreCategories then for k, category in ipairs(GameStoreCategories) do if category.offers then for _, offer in ipairs(category.offers) do @@ -2077,14 +2093,14 @@ function sendHomePage(playerId) local homeOffers = getHomeOffers(player:getId()) for p, offer in pairs(homeOffers) do local canBuy = player:canBuyOffer(offer) - if (canBuy.disabled == 1) then + if canBuy.disabled == 1 then for index, disableTable in ipairs(disableReasons) do - if (canBuy.disabledReason == disableTable.reason) then + if canBuy.disabledReason == disableTable.reason then offer.disabledReadonIndex = index end end - if (offer.disabledReadonIndex == nil) then + if offer.disabledReadonIndex == nil then offer.disabledReadonIndex = #disableReasons table.insert(disableReasons, canBuy.disabledReason) end @@ -2107,8 +2123,8 @@ function sendHomePage(playerId) msg:addByte(offer.coinType or 0x00) msg:addByte((offer.disabledReadonIndex ~= nil) and 1 or 0) - if (offer.disabledReadonIndex ~= nil) then - msg:addByte(0x01); + if offer.disabledReadonIndex ~= nil then + msg:addByte(0x01) msg:addU16(offer.disabledReadonIndex) offer.disabledReadonIndex = nil -- Reseting the table to nil disable reason end @@ -2117,7 +2133,7 @@ function sendHomePage(playerId) local type = convertType(offer.type) - msg:addByte(type); + msg:addByte(type) if type == GameStore.ConverType.SHOW_NONE then msg:addString(offer.icons[1]) elseif type == GameStore.ConverType.SHOW_MOUNT then @@ -2178,12 +2194,12 @@ end -- Hireling Helpers function HandleHirelingNameChange(playerId, offer, newHirelingName) - local player = Player(playerId); + local player = Player(playerId) local cb = function(playerId, data, hireling) local offer = data.offer local newHirelingName = data.newHirelingName - local player = Player(playerId); + local player = Player(playerId) if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end @@ -2195,7 +2211,7 @@ function HandleHirelingNameChange(playerId, offer, newHirelingName) local oldName = hireling.name hireling.name = newHirelingName - if not player:makeCoinTransaction(data.offer, oldName .. ' to ' .. newHirelingName) then + if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then return player:showInfoModal("Error", "Transaction error") end @@ -2203,18 +2219,18 @@ function HandleHirelingNameChange(playerId, offer, newHirelingName) if lamp then lamp:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "This mysterious lamp summons your very own personal hireling.\nThis item cannot be traded.\nThis magic lamp is the home of " .. hireling:getName() .. ".") end - logger.debug('{} has been renamed to {}', oldName, newHirelingName) + logger.debug("{} has been renamed to {}", oldName, newHirelingName) sendUpdatedStoreBalances(playerId) end - player:sendHirelingSelectionModal('Choose a Hireling', 'Select a hireling below', cb, { offer = offer, newHirelingName = newHirelingName }) + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer, newHirelingName = newHirelingName }) end function HandleHirelingSexChange(playerId, offer) - local player = Player(playerId); + local player = Player(playerId) local cb = function(playerId, data, hireling) - local player = Player(playerId); + local player = Player(playerId) if not hireling then return player:showInfoModal("Error", "Your must select a hireling.") end @@ -2230,20 +2246,20 @@ function HandleHirelingSexChange(playerId, offer) local changeTo, sexString, lookType if hireling.sex == HIRELING_SEX.FEMALE then changeTo = HIRELING_SEX.MALE - sexString = 'male' + sexString = "male" lookType = HIRELING_OUTFIT_DEFAULT.male else changeTo = HIRELING_SEX.FEMALE - sexString = 'female' + sexString = "female" lookType = HIRELING_OUTFIT_DEFAULT.female end hireling.sex = changeTo hireling.looktype = lookType - logger.debug('{} sex was changed to {}', hireling:getName(), sexString) + logger.debug("{} sex was changed to {}", hireling:getName(), sexString) sendUpdatedStoreBalances(playerId) end - player:sendHirelingSelectionModal('Choose a Hireling', 'Select a hireling below', cb, { offer = offer }) + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer }) end