diff --git a/.github/workflows/build-ubuntu-dummy.yml b/.github/workflows/build-ubuntu-dummy.yml index 00c4efdef87..f4ebb00ff27 100644 --- a/.github/workflows/build-ubuntu-dummy.yml +++ b/.github/workflows/build-ubuntu-dummy.yml @@ -17,11 +17,9 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, ubuntu-22.04] + os: [ubuntu-22.04] buildtype: [linux-release, linux-debug] include: - - os: ubuntu-20.04 - triplet: x64-linux - os: ubuntu-22.04 triplet: x64-linux diff --git a/.github/workflows/build-ubuntu.yml b/.github/workflows/build-ubuntu.yml index cdc54dc33f2..2b369e34875 100644 --- a/.github/workflows/build-ubuntu.yml +++ b/.github/workflows/build-ubuntu.yml @@ -36,11 +36,9 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-20.04, ubuntu-22.04] + os: [ubuntu-22.04] buildtype: [linux-release, linux-debug] include: - - os: ubuntu-20.04 - triplet: x64-linux - os: ubuntu-22.04 triplet: x64-linux 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-* diff --git a/CMakeLists.txt b/CMakeLists.txt index e4093f4de2d..52c35a471f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,10 +86,9 @@ endif() # === IPO === -option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON) if(OPTIONS_ENABLE_IPO) - log_option_enabled("IPO/LTO") if(MSVC) + log_option_enabled("IPO/LTO") set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL") set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") @@ -97,6 +96,7 @@ if(OPTIONS_ENABLE_IPO) set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG") else() if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release") + log_option_enabled("IPO/LTO") include(CheckIPOSupported) check_ipo_supported(RESULT result OUTPUT output) if(result) diff --git a/cmake/modules/BaseConfig.cmake b/cmake/modules/BaseConfig.cmake index 7e3f6404b3f..a1980d0f604 100644 --- a/cmake/modules/BaseConfig.cmake +++ b/cmake/modules/BaseConfig.cmake @@ -121,7 +121,9 @@ if (MSVC) endforeach(type) add_compile_options(/MP /FS /Zf /EHsc) -endif (MSVC) +else() + add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra) +endif() ## Link compilation files to build/bin folder, else link to the main dir function(set_output_directory target_name) diff --git a/config.lua.dist b/config.lua.dist index a5bb3d73ca5..447a90647c2 100644 --- a/config.lua.dist +++ b/config.lua.dist @@ -52,7 +52,8 @@ cleanProtectionZones = false -- Connection Config -- NOTE: allowOldProtocol can allow login on 10x protocol. (11.00) -- NOTE: maxPlayers set to 0 means no limit --- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25 +-- NOTE: MaxPacketsPerSeconds if you change you will be subject to bugs by WPE, keep the default value of 25, +-- It's recommended to use a range like min 50 in this function, otherwise you will be disconnected after equipping two-handed distance weapons. ip = "127.0.0.1" allowOldProtocol = false bindOnlyGlobalAddress = false @@ -80,6 +81,17 @@ freeDepotLimit = 2000 premiumDepotLimit = 10000 depotBoxes = 20 +-- Augments System (Get more info in: https://github.com/opentibiabr/canary/pull/2602) +-- NOTE: the following values are for all weapons and equipments that have type of "increase damage", "powerful impact" and "strong impact". +-- To customize the percentage of a particular item with these augment types, please add to the item "augments" section on items.xml as the example above. +-- NOTE: The values represent percentage. +-- NOTE: augmentIncreasedDamagePercent = value between 1 and 100 (damage percent to increase. ex: 5 = 5%, 50 = 50%) +-- NOTE: augmentPowerfulImpactPercent = value between 1 and 100 (damage percent to increase. ex: 10 = 10%, 100 = 100%) +-- NOTE: augmentStrongImpactPercent = value between 1 and 100 (damage percent to increase. ex: 7 = 7%, 70 = 70%) +augmentIncreasedDamagePercent = 5 +augmentPowerfulImpactPercent = 7 +augmentStrongImpactPercent = 10 + -- Prey system -- NOTE: preyRerollPricePerLevel: Price multiplier in gold coin for rerolling prey list. -- NOTE: preySelectListPrice: Price to manually select creature on list and to lock prey slot. @@ -212,6 +224,8 @@ wheelAtelierRevealGreaterCost = 6000000 familiarTime = 30 partyAutoShareExperience = true +-- partyShareRangeMultiplier: the range of the party share experience, default 3/2 (1.5) +partyShareRangeMultiplier = 1.5 partyShareLootBoosts = false partyShareLootBoostsDimishingFactor = 0.7 @@ -239,6 +253,7 @@ onlyPremiumAccount = false -- NOTE: enablePlayerPutItemInAmmoSlot = true, will enable players to put any items on ammo slot, more used in custom shopping system -- NOTE: startStreakLevel will make a reward streak level for new players who never logged in -- NOTE: if showLootsInBestiary is true, will cause all loots to be shown in the bestiary even if the player has not reached the required number of kills +-- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers stashMoving = false depotChest = 4 autoLoot = false @@ -257,6 +272,7 @@ storeInboxMaxLimit = 2000 enablePlayerPutItemInAmmoSlot = false startStreakLevel = 0 showLootsInBestiary = false +minTownIdToBankTransfer = 3 -- Teleport summon -- Set to true will never remove the summon @@ -361,7 +377,10 @@ partyListMaxDistance = 30 toggleMapCustom = true -- Market +-- NOTE: marketRefreshPricesInterval (in minutes, minimum is 1 minute) +-- NOTE: set it to 0 for disable, is the time in which the task will run updating the prices of the items that will be sent to the client marketOfferDuration = 30 * 24 * 60 * 60 +marketRefreshPricesInterval = 30 premiumToCreateMarketOffer = true checkExpiredMarketOffersEachMinutes = 60 maxMarketOffersAtATimePerPlayer = 100 @@ -393,7 +412,6 @@ resetSessionsOnStartup = false -- Misc. -- NOTE: experienceDisplayRates: set to false to ignore exp rate or true to include exp rate -- NOTE: disableLegacyRaids: set to true to disable legacy XML raids --- NOTE: combatChainDelay: set to minimum 50 miliseconds allowChangeOutfit = true toggleMountInProtectionZone = false freePremium = false @@ -426,7 +444,8 @@ maxElementalResistance = 200 maxDamageReflection = 200 -- Chain system -toggleChainSystem = true +-- NOTE: combatChainDelay: set to minimum 50 miliseconds +toggleChainSystem = false combatChainDelay = 50 combatChainTargets = 5 combatChainSkillFormulaAxe = 0.9 diff --git a/data-otservbr-global/lib/core/quests.lua b/data-otservbr-global/lib/core/quests.lua index ef61ee2549b..a35dcb15dea 100644 --- a/data-otservbr-global/lib/core/quests.lua +++ b/data-otservbr-global/lib/core/quests.lua @@ -5592,7 +5592,7 @@ if not Quests then }, [41] = { name = "Adventurers Guild", - startStorageId = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, + startStorageId = Storage.AdventurersGuild.QuestLine, startStorageValue = 1, missions = { [1] = { @@ -5606,6 +5606,18 @@ if not Quests then But the dragon hoards might justify the risks. You killed %d/50 dragons and dragon lords."):format(math.max(player:getStorageValue(Storage.AdventurersGuild.GreatDragonHunt.DragonCounter), 0)) end, }, + [2] = { + name = "The Lost Brother", + storageId = Storage.AdventurersGuild.TheLostBrother, + missionId = 11000, + startValue = 1, + endValue = 3, + states = { + [1] = "At the Kha'zeel Mountains you met the merchant Tarun. His brother has gone missing and was last seen following a beautiful woman into a palace. Tarun fears this woman might have been a demon.", + [2] = "You found the remains of Tarun's brother containing a message. Go back to Tarun and report his brother's last words.", + [3] = "You told Tarun about his brother's sad fate. He was very downhearted but gave you his sincere thanks. The beautiful asuri have taken a young man's life and the happiness of another one.", + }, + }, }, }, [42] = { diff --git a/data-otservbr-global/lib/core/storages.lua b/data-otservbr-global/lib/core/storages.lua index 69f1d7f7948..fce8059f7d1 100644 --- a/data-otservbr-global/lib/core/storages.lua +++ b/data-otservbr-global/lib/core/storages.lua @@ -106,7 +106,6 @@ Storage = { -- unused ExerciseDummyExhaust = 30029, SamsOldBackpack = 30030, SamsOldBackpackDoor = 30031, - StrawberryCupcake = 30032, ChayenneReward = 30033, SwampDiggingTimeout = 30034, HydraEggQuest = 30035, @@ -125,8 +124,6 @@ Storage = { Navigator = 30048, DwarvenLegs = 30049, PrinceDrazzakTime = 30050, - LemonCupcake = 30052, - BlueberryCupcake = 30053, -- Reserved in Global.Storage.FamiliarSummonEvent10 = 30054 -- Reserved in Global.Storage.FamiliarSummonEvent60 = 30055 ChayenneKeyTime = 30056, @@ -1573,6 +1570,8 @@ Storage = { WarriorSkeleton = 52146, DragonCounter = 52147, }, + QuestLine = 52148, + TheLostBrother = 52149, }, DreamersChallenge = { -- Reserved storage from 52160 - 52199 @@ -2537,7 +2536,6 @@ Storage = { NightmareTeddy = {}, PoacherCavesMiniWorldChange = {}, TheGreatDragonHunt = {}, - TheLostBrother = {}, TheTaintedSouls = {}, }, U10_90 = { -- update 10.90 - Reserved Storages 45201 - 45350 diff --git a/data-otservbr-global/lib/quests/the_primal_ordeal.lua b/data-otservbr-global/lib/quests/the_primal_ordeal.lua index de708ee4de2..24324e1147b 100644 --- a/data-otservbr-global/lib/quests/the_primal_ordeal.lua +++ b/data-otservbr-global/lib/quests/the_primal_ordeal.lua @@ -6,12 +6,10 @@ function RegisterPrimalPackBeast(template) primalMonster.loot = {} primalMonster.name = "Primal Pack Beast" primalMonster.description = "a primal pack beast" - - primalMonster.health = primalMonster.health - primalMonster.maxHealth = primalMonster.maxHealth + primalMonster.maxHealth = primalMonster.maxHealth * 0.7 + primalMonster.health = primalMonster.maxHealth primalMonster.raceId = nil primalMonster.Bestiary = nil primalMonster.corpse = 0 - primal:register(primalMonster) end diff --git a/data-otservbr-global/migrations/43.lua b/data-otservbr-global/migrations/43.lua index 1464703c96e..6d3492a815a 100644 --- a/data-otservbr-global/migrations/43.lua +++ b/data-otservbr-global/migrations/43.lua @@ -1,5 +1,5 @@ function onUpdateDatabase() - logger.info("Updating database to version 43 (feat frags_limit, payment and duration_days in guild wars)") + logger.info("Updating database to version 44 (feat frags_limit, payment and duration_days in guild wars)") db.query([[ ALTER TABLE `guild_wars` diff --git a/data-otservbr-global/migrations/44.lua b/data-otservbr-global/migrations/44.lua index 86a6d8ffec1..c551fc79aeb 100644 --- a/data-otservbr-global/migrations/44.lua +++ b/data-otservbr-global/migrations/44.lua @@ -1,3 +1,11 @@ function onUpdateDatabase() - return false -- true = There are others migrations file | false = this is the last migration file + logger.info("Updating database to version 45 (fix: mana shield column size for more than 65k)") + + db.query([[ + ALTER TABLE `players` + MODIFY COLUMN `manashield` INT UNSIGNED NOT NULL DEFAULT '0', + MODIFY COLUMN `max_manashield` INT UNSIGNED NOT NULL DEFAULT '0'; + ]]) + + return true end diff --git a/data-otservbr-global/migrations/45.lua b/data-otservbr-global/migrations/45.lua new file mode 100644 index 00000000000..c606f18522e --- /dev/null +++ b/data-otservbr-global/migrations/45.lua @@ -0,0 +1,56 @@ +function onUpdateDatabase() + logger.info("Updating database to version 46 (feat: vip groups)") + + db.query([[ + CREATE TABLE IF NOT EXISTS `account_vipgroups` ( + `id` tinyint(3) UNSIGNED NOT NULL, + `account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is', + `name` varchar(128) NOT NULL, + `customizable` BOOLEAN NOT NULL DEFAULT '1', + CONSTRAINT `account_vipgroups_pk` PRIMARY KEY (`id`, `account_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + ]]) + + db.query([[ + CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0); + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0); + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0); + END; + ]]) + + db.query([[ + CREATE TABLE IF NOT EXISTS `account_vipgrouplist` ( + `account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is', + `player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry', + `vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs', + INDEX `account_id` (`account_id`), + INDEX `player_id` (`player_id`), + INDEX `vipgroup_id` (`vipgroup_id`), + CONSTRAINT `account_vipgrouplist_unique` UNIQUE (`account_id`, `player_id`, `vipgroup_id`), + CONSTRAINT `account_vipgrouplist_player_fk` + FOREIGN KEY (`player_id`) REFERENCES `players` (`id`) + ON DELETE CASCADE, + CONSTRAINT `account_vipgrouplist_vipgroup_fk` + FOREIGN KEY (`vipgroup_id`, `account_id`) REFERENCES `account_vipgroups` (`id`, `account_id`) + ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8; + ]]) + + db.query([[ + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) + SELECT 1, id, 'Friends', 0 FROM `accounts`; + ]]) + + db.query([[ + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) + SELECT 2, id, 'Enemies', 0 FROM `accounts`; + ]]) + + db.query([[ + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) + SELECT 3, id, 'Trading Partners', 0 FROM `accounts`; + ]]) + + return true +end diff --git a/data-otservbr-global/migrations/46.lua b/data-otservbr-global/migrations/46.lua new file mode 100644 index 00000000000..86a6d8ffec1 --- /dev/null +++ b/data-otservbr-global/migrations/46.lua @@ -0,0 +1,3 @@ +function onUpdateDatabase() + return false -- true = There are others migrations file | false = this is the last migration file +end diff --git a/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua b/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua index b0bc59364d6..7ad43b016c9 100644 --- a/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua +++ b/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua @@ -24,7 +24,6 @@ local thePrimalMenaceConfig = { CountGrowthPerHazard = 1.05, CountMax = 6, - HpRateOnSpawn = 0.7, MonsterPool = { "Emerald Tortoise (Primal)", "Gore Horn (Primal)", @@ -291,8 +290,6 @@ local function spawnMonster(monsterId, spawnPosition) MonsterId = primalMonster:getId(), Created = os.time(), } - local monsterMaxHealth = primalMonster:getMaxHealth() - primalMonster:setHealth(monsterMaxHealth * thePrimalMenaceConfig.MonsterConfig.HpRateOnSpawn) local primalBeasts = monster:getStorageValue(thePrimalMenaceConfig.Storage.PrimalBeasts) table.insert(primalBeasts, primalBeastEntry) diff --git a/data-otservbr-global/npc/alaistar.lua b/data-otservbr-global/npc/alaistar.lua index e893975b24b..68aaa75679a 100644 --- a/data-otservbr-global/npc/alaistar.lua +++ b/data-otservbr-global/npc/alaistar.lua @@ -36,13 +36,14 @@ local itemsTable = { { itemName = "strong health potion", clientId = 236, buy = 115 }, { itemName = "strong mana potion", clientId = 237, buy = 93 }, { itemName = "supreme health potion", clientId = 23375, buy = 625 }, - { itemName = "ultimate health potion", clientId = 7643, buy = 438 }, - { itemName = "ultimate mana potion", clientId = 23373, buy = 379 }, + { itemName = "ultimate health potion", clientId = 7643, buy = 379 }, + { itemName = "ultimate mana potion", clientId = 23373, buy = 438 }, { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, { itemName = "vial", clientId = 2874, sell = 5 }, }, ["creature products"] = { { itemName = "cowbell", clientId = 21204, sell = 210 }, + { itemName = "execowtioner mask", clientId = 21201, sell = 240 }, { itemName = "giant pacifier", clientId = 21199, sell = 170 }, { itemName = "glob of glooth", clientId = 21182, sell = 125 }, { itemName = "glooth injection tube", clientId = 21103, sell = 350 }, diff --git a/data-otservbr-global/npc/alexander.lua b/data-otservbr-global/npc/alexander.lua index 78f51e486c8..fda2799bf4d 100644 --- a/data-otservbr-global/npc/alexander.lua +++ b/data-otservbr-global/npc/alexander.lua @@ -30,6 +30,28 @@ npcConfig.voices = { } local itemsTable = { + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["creature products"] = { + { itemName = "crystal ball", clientId = 3076, buy = 530, sell = 190 }, + { itemName = "life crystal", clientId = 3061, sell = 83 }, + { itemName = "mind stone", clientId = 3062, sell = 170 }, + }, + ["shields"] = { + { itemName = "spellbook of enlightenment", clientId = 8072, sell = 4000 }, + { itemName = "spellbook of warding", clientId = 8073, sell = 8000 }, + { itemName = "spellbook of mind control", clientId = 8074, sell = 13000 }, + { itemName = "spellbook of lost souls", clientId = 8075, sell = 19000 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, ["runes"] = { { itemName = "animate dead rune", clientId = 3203, buy = 375 }, { itemName = "blank rune", clientId = 3147, buy = 10 }, diff --git a/data-otservbr-global/npc/an_idol.lua b/data-otservbr-global/npc/an_idol.lua new file mode 100644 index 00000000000..69977dc81ec --- /dev/null +++ b/data-otservbr-global/npc/an_idol.lua @@ -0,0 +1,68 @@ +local internalNpcName = "An Idol" +local npcType = Game.createNpcType(internalNpcName) +local npcConfig = {} + +npcConfig.name = internalNpcName +npcConfig.description = internalNpcName + +npcConfig.health = 100 +npcConfig.maxHealth = npcConfig.health +npcConfig.walkInterval = 0 +npcConfig.walkRadius = 2 + +npcConfig.outfit = { + lookTypeEx = 15894, +} + +npcConfig.flags = { + floorchange = false, +} + +local keywordHandler = KeywordHandler:new() +local npcHandler = NpcHandler:new(keywordHandler) + +npcType.onThink = function(npc, interval) + npcHandler:onThink(npc, interval) +end + +npcType.onAppear = function(npc, creature) + npcHandler:onAppear(npc, creature) +end + +npcType.onDisappear = function(npc, creature) + npcHandler:onDisappear(npc, creature) +end + +npcType.onMove = function(npc, creature, fromPosition, toPosition) + npcHandler:onMove(npc, creature, fromPosition, toPosition) +end + +npcType.onSay = function(npc, creature, type, message) + npcHandler:onSay(npc, creature, type, message) +end + +npcType.onCloseChannel = function(npc, creature) + npcHandler:onCloseChannel(npc, creature) +end + +local function creatureSayCallback(npc, creature, type, message) + local player = Player(creature) + + if not npcHandler:checkInteraction(npc, creature) then + return false + end + + if MsgContains(message, "VBOX") then + npcHandler:say("J-T B^C J^BXT°", npc, creature) + player:teleportTo(Position(32366, 32531, 8), false) + player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) + end + + return true +end + +npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) +npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, false) + +-- npcType registering the npcConfig table +npcType:register(npcConfig) diff --git a/data-otservbr-global/npc/asima.lua b/data-otservbr-global/npc/asima.lua index 645689c42d4..c3aca3fcd5e 100644 --- a/data-otservbr-global/npc/asima.lua +++ b/data-otservbr-global/npc/asima.lua @@ -24,6 +24,14 @@ npcConfig.flags = { } local itemsTable = { + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, ["potions"] = { { itemName = "empty potion flask", clientId = 283, sell = 5 }, { itemName = "empty potion flask", clientId = 284, sell = 5 }, @@ -41,6 +49,12 @@ local itemsTable = { { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, { itemName = "vial", clientId = 2874, sell = 5 }, }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, ["runes"] = { { itemName = "avalanche rune", clientId = 3161, buy = 57 }, { itemName = "blank rune", clientId = 3147, buy = 10 }, @@ -61,8 +75,27 @@ local itemsTable = { { itemName = "poison field rune", clientId = 3172, buy = 21 }, { itemName = "poison wall rune", clientId = 3176, buy = 52 }, { itemName = "sudden death rune", clientId = 3155, buy = 135 }, + { itemName = "stalagmite rune", clientId = 3179, buy = 12 }, { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, }, + ["wands"] = { + { itemName = "hailstorm rod", clientId = 3067, buy = 15000 }, + { itemName = "moonlight rod", clientId = 3070, buy = 1000 }, + { itemName = "necrotic rod", clientId = 3069, buy = 5000 }, + { itemName = "northwind rod", clientId = 8083, buy = 7500 }, + { itemName = "snakebite rod", clientId = 3066, buy = 500 }, + { itemName = "springsprout rod", clientId = 8084, buy = 18000 }, + { itemName = "terra rod", clientId = 3065, buy = 10000 }, + { itemName = "underworld rod", clientId = 8082, buy = 22000 }, + { itemName = "wand of cosmic energy", clientId = 3073, buy = 10000 }, + { itemName = "wand of decay", clientId = 3072, buy = 5000 }, + { itemName = "wand of draconia", clientId = 8093, buy = 7500 }, + { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, + { itemName = "wand of inferno", clientId = 3071, buy = 15000 }, + { itemName = "wand of starstorm", clientId = 8092, buy = 18000 }, + { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, + { itemName = "wand of vortex", clientId = 3074, buy = 500 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/asnarus.lua b/data-otservbr-global/npc/asnarus.lua index a733d90834b..3992d513e9b 100644 --- a/data-otservbr-global/npc/asnarus.lua +++ b/data-otservbr-global/npc/asnarus.lua @@ -56,7 +56,7 @@ npcConfig.shop = { { itemName = "animate dead rune", clientId = 3203, buy = 375 }, { itemName = "arrow", clientId = 3447, buy = 2 }, { itemName = "blue quiver", clientId = 35848, buy = 400 }, - { itemName = "bolt", clientId = 3483, buy = 4 }, + { itemName = "bolt", clientId = 3446, buy = 4 }, { itemName = "bow", clientId = 3350, buy = 400, sell = 100 }, { itemName = "bowl of terror sweat", clientId = 20204, sell = 500 }, { itemName = "broken visor", clientId = 20184, sell = 1900 }, diff --git a/data-otservbr-global/npc/briasol.lua b/data-otservbr-global/npc/briasol.lua index 6905011fee9..38dcd074159 100644 --- a/data-otservbr-global/npc/briasol.lua +++ b/data-otservbr-global/npc/briasol.lua @@ -113,7 +113,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/chantalle.lua b/data-otservbr-global/npc/chantalle.lua index 2615f6557da..3ed42984f5c 100644 --- a/data-otservbr-global/npc/chantalle.lua +++ b/data-otservbr-global/npc/chantalle.lua @@ -99,7 +99,7 @@ npcConfig.shop = { { itemName = "diamond", clientId = 32770, sell = 15000 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/chuckles.lua b/data-otservbr-global/npc/chuckles.lua index 51fb3f2add6..4eb06b6bb3d 100644 --- a/data-otservbr-global/npc/chuckles.lua +++ b/data-otservbr-global/npc/chuckles.lua @@ -59,6 +59,38 @@ local itemsTable = { { itemName = "sudden death rune", clientId = 3155, buy = 135 }, { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, }, + ["wands"] = { + { itemName = "hailstorm rod", clientId = 3067, buy = 15000 }, + { itemName = "moonlight rod", clientId = 3070, buy = 1000 }, + { itemName = "necrotic rod", clientId = 3069, buy = 5000 }, + { itemName = "northwind rod", clientId = 8083, buy = 7500 }, + { itemName = "snakebite rod", clientId = 3066, buy = 500 }, + { itemName = "springsprout rod", clientId = 8084, buy = 18000 }, + { itemName = "terra rod", clientId = 3065, buy = 10000 }, + { itemName = "underworld rod", clientId = 8082, buy = 22000 }, + { itemName = "wand of cosmic energy", clientId = 3073, buy = 10000 }, + { itemName = "wand of decay", clientId = 3072, buy = 5000 }, + { itemName = "wand of draconia", clientId = 8093, buy = 7500 }, + { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, + { itemName = "wand of inferno", clientId = 3071, buy = 15000 }, + { itemName = "wand of starstorm", clientId = 8092, buy = 18000 }, + { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, + { itemName = "wand of vortex", clientId = 3074, buy = 500 }, + }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/edmund.lua b/data-otservbr-global/npc/edmund.lua index d8635297949..c61a95bcd72 100644 --- a/data-otservbr-global/npc/edmund.lua +++ b/data-otservbr-global/npc/edmund.lua @@ -68,7 +68,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/fenech.lua b/data-otservbr-global/npc/fenech.lua index 7152c0ef9c5..f69dcafaa89 100644 --- a/data-otservbr-global/npc/fenech.lua +++ b/data-otservbr-global/npc/fenech.lua @@ -71,6 +71,20 @@ local itemsTable = { { itemName = "sudden death rune", clientId = 3155, buy = 135 }, { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/frans.lua b/data-otservbr-global/npc/frans.lua index 8761a7d89d6..a1b695adf14 100644 --- a/data-otservbr-global/npc/frans.lua +++ b/data-otservbr-global/npc/frans.lua @@ -58,6 +58,20 @@ local itemsTable = { { itemName = "sudden death rune", clientId = 3155, buy = 135 }, { itemName = "ultimate healing rune", clientId = 3160, buy = 175 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/frederik.lua b/data-otservbr-global/npc/frederik.lua index 9b33ccf9684..81ff1ec58b6 100644 --- a/data-otservbr-global/npc/frederik.lua +++ b/data-otservbr-global/npc/frederik.lua @@ -82,6 +82,20 @@ local itemsTable = { { itemName = "ultimate spirit potion", clientId = 23374, buy = 438 }, { itemName = "vial", clientId = 2874, sell = 5 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/gail.lua b/data-otservbr-global/npc/gail.lua index 80a9b54b3e5..de2a52dc7f4 100644 --- a/data-otservbr-global/npc/gail.lua +++ b/data-otservbr-global/npc/gail.lua @@ -109,7 +109,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/gnomegica.lua b/data-otservbr-global/npc/gnomegica.lua index 0805ca33ace..b860caf3962 100644 --- a/data-otservbr-global/npc/gnomegica.lua +++ b/data-otservbr-global/npc/gnomegica.lua @@ -78,6 +78,20 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/hanna.lua b/data-otservbr-global/npc/hanna.lua index 7fca4c908aa..dfea1547135 100644 --- a/data-otservbr-global/npc/hanna.lua +++ b/data-otservbr-global/npc/hanna.lua @@ -145,7 +145,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/hireling.lua b/data-otservbr-global/npc/hireling.lua index 145d846bd7e..aad7785079d 100644 --- a/data-otservbr-global/npc/hireling.lua +++ b/data-otservbr-global/npc/hireling.lua @@ -228,7 +228,7 @@ function createHirelingType(HirelingName) }, ["distance"] = { { itemName = "arrow", clientId = 3447, buy = 2 }, - { itemName = "bolt", clientId = 3483, buy = 4 }, + { itemName = "bolt", clientId = 3446, buy = 4 }, { itemName = "bow", clientId = 3350, buy = 400, sell = 100 }, { itemName = "crossbow", clientId = 3349, buy = 500, sell = 120 }, { itemName = "crystalline arrow", clientId = 15793, buy = 450 }, diff --git a/data-otservbr-global/npc/ishina.lua b/data-otservbr-global/npc/ishina.lua index 1fd61200c15..358ee2619a3 100644 --- a/data-otservbr-global/npc/ishina.lua +++ b/data-otservbr-global/npc/ishina.lua @@ -139,7 +139,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/iwan.lua b/data-otservbr-global/npc/iwan.lua index 2cc24843318..77689b12003 100644 --- a/data-otservbr-global/npc/iwan.lua +++ b/data-otservbr-global/npc/iwan.lua @@ -78,7 +78,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/jessica.lua b/data-otservbr-global/npc/jessica.lua index 37ac18ed54a..43b1839b3ee 100644 --- a/data-otservbr-global/npc/jessica.lua +++ b/data-otservbr-global/npc/jessica.lua @@ -98,7 +98,7 @@ npcConfig.shop = { { itemName = "diamond", clientId = 32770, sell = 15000 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/khanna.lua b/data-otservbr-global/npc/khanna.lua index 02fcee7b6d5..76b5c1e70da 100644 --- a/data-otservbr-global/npc/khanna.lua +++ b/data-otservbr-global/npc/khanna.lua @@ -34,7 +34,7 @@ local itemsTable = { ["runes"] = { { itemName = "animate dead rune", clientId = 3203, buy = 375 }, { itemName = "avalanche rune", clientId = 3161, buy = 57 }, - { itemName = "blank rune", clientId = 3147, buy = 10 }, + { itemName = "blank rune", clientId = 3147, buy = 20 }, { itemName = "chameleon rune", clientId = 3178, buy = 210 }, { itemName = "convince creature rune", clientId = 3177, buy = 80 }, { itemName = "cure poison rune", clientId = 3153, buy = 65 }, @@ -84,6 +84,46 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["creature products"] = { + { itemName = "bashmu fang", clientId = 36820, sell = 600 }, + { itemName = "bashmu feather", clientId = 36820, sell = 350 }, + { itemName = "bashmu tongue", clientId = 36820, sell = 400 }, + { itemName = "blue goanna scale", clientId = 31559, sell = 230 }, + { itemName = "crystal ball", clientId = 3076, buy = 650 }, + { itemName = "fafnar symbol", clientId = 31443, sell = 950 }, + { itemName = "goanna claw", clientId = 31561, sell = 950 }, + { itemName = "goanna meat", clientId = 31560, sell = 190 }, + { itemName = "lamassu hoof", clientId = 31441, sell = 330 }, + { itemName = "lamassu horn", clientId = 31442, sell = 240 }, + { itemName = "life crystal", clientId = 3061, sell = 85 }, + { itemName = "lizard heart", clientId = 31340, sell = 530 }, + { itemName = "manticore ear", clientId = 31440, sell = 310 }, + { itemName = "manticore tail", clientId = 31439, sell = 220 }, + { itemName = "mind stone", clientId = 3062, sell = 170 }, + { itemName = "old girtablilu carapace", clientId = 36972, sell = 570 }, + { itemName = "red goanna scale", clientId = 31558, sell = 270 }, + { itemName = "scorpion charm", clientId = 36822, sell = 620 }, + { itemName = "sphinx feather", clientId = 31437, sell = 470 }, + { itemName = "sphinx tiara", clientId = 31438, sell = 360 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + { itemName = "spellbook of enlightenment", clientId = 8072, sell = 4000 }, + { itemName = "spellbook of lost souls", clientId = 8075, sell = 19000 }, + { itemName = "spellbook of mind control", clientId = 8074, sell = 13000 }, + { itemName = "spellbook of warding", clientId = 8073, sell = 8000 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/mordecai.lua b/data-otservbr-global/npc/mordecai.lua index 60063a423ba..dc0e3c07a77 100644 --- a/data-otservbr-global/npc/mordecai.lua +++ b/data-otservbr-global/npc/mordecai.lua @@ -88,6 +88,17 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/nelly.lua b/data-otservbr-global/npc/nelly.lua index 8c3b123c47a..911464524c6 100644 --- a/data-otservbr-global/npc/nelly.lua +++ b/data-otservbr-global/npc/nelly.lua @@ -94,6 +94,20 @@ local itemsTable = { { itemName = "letter", clientId = 3505, buy = 8 }, { itemName = "parcel", clientId = 3503, buy = 15 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/nipuna.lua b/data-otservbr-global/npc/nipuna.lua index aa9d74cec52..ef3211bce42 100644 --- a/data-otservbr-global/npc/nipuna.lua +++ b/data-otservbr-global/npc/nipuna.lua @@ -101,6 +101,17 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/odemara.lua b/data-otservbr-global/npc/odemara.lua index bcfe94bf8eb..3e1986714c7 100644 --- a/data-otservbr-global/npc/odemara.lua +++ b/data-otservbr-global/npc/odemara.lua @@ -70,7 +70,7 @@ npcConfig.shop = { { itemName = "diamond", clientId = 32770, sell = 15000 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/oiriz.lua b/data-otservbr-global/npc/oiriz.lua index 3a5d3a6b411..4b731c015a2 100644 --- a/data-otservbr-global/npc/oiriz.lua +++ b/data-otservbr-global/npc/oiriz.lua @@ -68,7 +68,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/rabaz.lua b/data-otservbr-global/npc/rabaz.lua index 3e47da6a5ca..e532e7def66 100644 --- a/data-otservbr-global/npc/rabaz.lua +++ b/data-otservbr-global/npc/rabaz.lua @@ -82,6 +82,20 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/rachel.lua b/data-otservbr-global/npc/rachel.lua index 3206c99864a..057787692c9 100644 --- a/data-otservbr-global/npc/rachel.lua +++ b/data-otservbr-global/npc/rachel.lua @@ -71,6 +71,23 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["valuables"] = { + { itemName = "talon", clientId = 3034, sell = 320 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/romir.lua b/data-otservbr-global/npc/romir.lua index 11ea038d266..09ab62ab1a4 100644 --- a/data-otservbr-global/npc/romir.lua +++ b/data-otservbr-global/npc/romir.lua @@ -82,6 +82,20 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/shiriel.lua b/data-otservbr-global/npc/shiriel.lua index 546bb26447b..fd982f345b9 100644 --- a/data-otservbr-global/npc/shiriel.lua +++ b/data-otservbr-global/npc/shiriel.lua @@ -70,6 +70,20 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/sigurd.lua b/data-otservbr-global/npc/sigurd.lua index cca63a33e3e..e4d1b585307 100644 --- a/data-otservbr-global/npc/sigurd.lua +++ b/data-otservbr-global/npc/sigurd.lua @@ -72,6 +72,20 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/sundara.lua b/data-otservbr-global/npc/sundara.lua index c1364240fa9..95ff206f2ad 100644 --- a/data-otservbr-global/npc/sundara.lua +++ b/data-otservbr-global/npc/sundara.lua @@ -101,6 +101,17 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/tandros.lua b/data-otservbr-global/npc/tandros.lua index e25ba65f2a3..ae647b26127 100644 --- a/data-otservbr-global/npc/tandros.lua +++ b/data-otservbr-global/npc/tandros.lua @@ -88,6 +88,20 @@ local itemsTable = { { itemName = "wand of voodoo", clientId = 8094, buy = 22000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/tarun.lua b/data-otservbr-global/npc/tarun.lua index 31f56602f81..9f0b8be5883 100644 --- a/data-otservbr-global/npc/tarun.lua +++ b/data-otservbr-global/npc/tarun.lua @@ -51,6 +51,74 @@ npcType.onCloseChannel = function(npc, creature) npcHandler:onCloseChannel(npc, creature) end +local function creatureSayCallback(npc, creature, type, message) + local player = Player(creature) + if not player then + return false + end + local playerId = player:getId() + + if not npcHandler:checkInteraction(npc, creature) then + return false + end + + local theLostBrotherStorage = player:getStorageValue(Storage.AdventurersGuild.TheLostBrother) + if MsgContains(message, "mission") then + if theLostBrotherStorage < 1 then + npcHandler:say({ + "My brother is missing. I fear, he went to this evil palace north of here. A place of great beauty, certainly filled with riches and luxury. But in truth it is a threshold to hell and demonesses are after his blood. ...", + "He is my brother, and I am deeply ashamed to admit but I don't dare to go there. Perhaps your heart is more courageous than mine. Would you go to see this place and search for my brother?", + }, npc, creature) + npcHandler:setTopic(playerId, 1) + elseif theLostBrotherStorage == 1 then + npcHandler:say("I hope you will find my brother.", npc, creature) + npcHandler:setTopic(playerId, 0) + elseif theLostBrotherStorage == 2 then + npcHandler:say({ + "So, he is dead as I feared. I warned him not to go with this woman, but he gave in to temptation. My heart darkens and moans. But you have my sincere thanks. ...", + "Without your help I would have stayed in the dark about his fate. Please, take this as a little recompense.", + }, npc, creature) + player:addItem(3039, 1) + player:addExperience(3000, true) + player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 3) + npcHandler:setTopic(playerId, 0) + end + elseif npcHandler:getTopic(playerId) == 1 then + if MsgContains(message, "yes") then + npcHandler:say("I thank you! This is more than I could hope!", npc, creature) + if theLostBrotherStorage < 1 then + player:setStorageValue(Storage.AdventurersGuild.QuestLine, 1) + end + player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 1) + elseif MsgContains(message, "no") then + npcHandler:say("As you wish.", npc, creature) + end + npcHandler:setTopic(playerId, 0) + end + + return true +end + +local function onTradeRequest(npc, creature) + local player = Player(creature) + if not player then + return false + end + local playerId = player:getId() + + if player:getStorageValue(Storage.AdventurersGuild.TheLostBrother) ~= 3 then + return false + end + + return true +end + +npcHandler:setMessage(MESSAGE_GREET, "Greetings!") +npcHandler:setMessage(MESSAGE_FAREWELL, "Farewell.") +npcHandler:setMessage(MESSAGE_SENDTRADE, "Of course, just have a look.") +npcHandler:setCallback(CALLBACK_ON_TRADE_REQUEST, onTradeRequest) +npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback) +npcHandler:setMessage(MESSAGE_WALKAWAY, "Farewell.") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) npcConfig.shop = { diff --git a/data-otservbr-global/npc/tesha.lua b/data-otservbr-global/npc/tesha.lua index 95e31f97cb7..6a3c4b9fadb 100644 --- a/data-otservbr-global/npc/tesha.lua +++ b/data-otservbr-global/npc/tesha.lua @@ -98,7 +98,7 @@ npcConfig.shop = { { itemName = "diamond", clientId = 32770, sell = 15000 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/tezila.lua b/data-otservbr-global/npc/tezila.lua index dab92c807f5..fe667133ad7 100644 --- a/data-otservbr-global/npc/tezila.lua +++ b/data-otservbr-global/npc/tezila.lua @@ -67,7 +67,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/topsy.lua b/data-otservbr-global/npc/topsy.lua index 395fd23cbeb..66ea6f27e6a 100644 --- a/data-otservbr-global/npc/topsy.lua +++ b/data-otservbr-global/npc/topsy.lua @@ -78,6 +78,20 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/valindara.lua b/data-otservbr-global/npc/valindara.lua index 69655358dfe..cf9506fcdd5 100644 --- a/data-otservbr-global/npc/valindara.lua +++ b/data-otservbr-global/npc/valindara.lua @@ -111,7 +111,7 @@ npcConfig.shop = { { itemName = "fire wall rune", clientId = 3190, buy = 61 }, { itemName = "fireball rune", clientId = 3189, buy = 30 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/npc/xodet.lua b/data-otservbr-global/npc/xodet.lua index 2d8832bd964..f687b491e89 100644 --- a/data-otservbr-global/npc/xodet.lua +++ b/data-otservbr-global/npc/xodet.lua @@ -72,6 +72,20 @@ local itemsTable = { { itemName = "wand of dragonbreath", clientId = 3075, buy = 1000 }, { itemName = "wand of vortex", clientId = 3074, buy = 500 }, }, + ["exercise weapons"] = { + { itemName = "durable exercise rod", clientId = 35283, buy = 945000, count = 1800 }, + { itemName = "durable exercise wand", clientId = 35284, buy = 945000, count = 1800 }, + { itemName = "exercise rod", clientId = 28556, buy = 262500, count = 500 }, + { itemName = "exercise wand", clientId = 28557, buy = 262500, count = 500 }, + { itemName = "lasting exercise rod", clientId = 35289, buy = 7560000, count = 14400 }, + { itemName = "lasting exercise wand", clientId = 35290, buy = 7560000, count = 14400 }, + }, + ["others"] = { + { itemName = "spellwand", clientId = 651, sell = 299 }, + }, + ["shields"] = { + { itemName = "spellbook", clientId = 3059, buy = 150 }, + }, } npcConfig.shop = {} diff --git a/data-otservbr-global/npc/yasir.lua b/data-otservbr-global/npc/yasir.lua index d576b611e53..9c5cf3dbf69 100644 --- a/data-otservbr-global/npc/yasir.lua +++ b/data-otservbr-global/npc/yasir.lua @@ -60,6 +60,7 @@ npcConfig.shop = { { itemName = "ape fur", clientId = 5883, sell = 120 }, { itemName = "apron", clientId = 33933, sell = 1300 }, { itemName = "badger fur", clientId = 903, sell = 15 }, + { itemName = "bakragore's amalgamation", clientId = 43968, sell = 2000000 }, { itemName = "bamboo stick", clientId = 11445, sell = 30 }, { itemName = "banana sash", clientId = 11511, sell = 55 }, { itemName = "basalt fetish", clientId = 17856, sell = 210 }, @@ -75,6 +76,7 @@ npcConfig.shop = { { itemName = "black hood", clientId = 9645, sell = 190 }, { itemName = "black wool", clientId = 11448, sell = 300 }, { itemName = "blazing bone", clientId = 16131, sell = 610 }, + { itemName = "bloated maggot", clientId = 43856, sell = 5200 }, { itemName = "blood preservation", clientId = 11449, sell = 320 }, { itemName = "blood tincture in a vial", clientId = 18928, sell = 360 }, { itemName = "bloody dwarven beard", clientId = 17827, sell = 110 }, @@ -173,7 +175,11 @@ npcConfig.shop = { { itemName = "dandelion seeds", clientId = 25695, sell = 200 }, { itemName = "dangerous proto matter", clientId = 23515, sell = 300 }, { itemName = "dark bell", clientId = 32596, sell = 310000 }, + { itemName = "dark obsidian splinter", clientId = 43850, sell = 4400 }, { itemName = "dark rosary", clientId = 10303, sell = 48 }, + { itemName = "darklight core", clientId = 43853, sell = 4100 }, + { itemName = "darklight figurine", clientId = 43961, sell = 3400000 }, + { itemName = "darklight matter", clientId = 43851, sell = 5500 }, { itemName = "dead weight", clientId = 20202, sell = 450 }, { itemName = "deepling breaktime snack", clientId = 14011, sell = 90 }, { itemName = "deepling claw", clientId = 14044, sell = 430 }, @@ -229,6 +235,7 @@ npcConfig.shop = { { itemName = "falcon crest", clientId = 28823, sell = 650 }, { itemName = "fern", clientId = 3737, sell = 20 }, { itemName = "fiery heart", clientId = 9636, sell = 375 }, + { itemName = "fiery tear", clientId = 39040, sell = 1070000 }, { itemName = "fig leaf", clientId = 25742, sell = 200 }, { itemName = "figurine of cruelty", clientId = 34019, sell = 3100000 }, { itemName = "figurine of greed", clientId = 34021, sell = 2900000 }, @@ -480,6 +487,8 @@ npcConfig.shop = { { itemName = "rorc feather", clientId = 18993, sell = 70 }, { itemName = "rotten heart", clientId = 31589, sell = 74000 }, { itemName = "rotten piece of cloth", clientId = 10291, sell = 30 }, + { itemName = "rotten roots", clientId = 43849, sell = 3800 }, + { itemName = "rotten vermin ichor", clientId = 43847, sell = 4500 }, { itemName = "sabretooth", clientId = 10311, sell = 400 }, { itemName = "sabretooth fur", clientId = 39378, sell = 2500 }, { itemName = "safety pin", clientId = 11493, sell = 120 }, @@ -636,6 +645,7 @@ npcConfig.shop = { { itemName = "wolf paw", clientId = 5897, sell = 70 }, { itemName = "wood", clientId = 5901, sell = 5 }, { itemName = "wool", clientId = 10319, sell = 15 }, + { itemName = "worm sponge", clientId = 43848, sell = 4200 }, { itemName = "writhing brain", clientId = 32600, sell = 370000 }, { itemName = "writhing heart", clientId = 32599, sell = 185000 }, { itemName = "wyrm scale", clientId = 9665, sell = 400 }, diff --git a/data-otservbr-global/npc/yonan.lua b/data-otservbr-global/npc/yonan.lua index 44dbb8dd83c..69bddee5cb3 100644 --- a/data-otservbr-global/npc/yonan.lua +++ b/data-otservbr-global/npc/yonan.lua @@ -39,7 +39,7 @@ npcConfig.shop = { { itemName = "cyan crystal fragment", clientId = 16125, sell = 800 }, { itemName = "dragon figurine", clientId = 30053, sell = 45000 }, { itemName = "gemmed figurine", clientId = 24392, sell = 3500 }, - { itemName = "giant amethyst", clientId = 30061, sell = 60000 }, + { itemName = "giant amethyst", clientId = 32622, sell = 60000 }, { itemName = "giant emerald", clientId = 30060, sell = 90000 }, { itemName = "giant ruby", clientId = 30059, sell = 70000 }, { itemName = "giant sapphire", clientId = 30061, sell = 50000 }, diff --git a/data-otservbr-global/scripts/actions/other/cup_cakes.lua b/data-otservbr-global/scripts/actions/other/cup_cakes.lua deleted file mode 100644 index a9d94dbaacd..00000000000 --- a/data-otservbr-global/scripts/actions/other/cup_cakes.lua +++ /dev/null @@ -1,51 +0,0 @@ -local data = { - [28484] = { - Type = "mana", - ExhaustStor = Storage.BlueberryCupcake, - timestamp = 10, - }, - [28485] = { - Type = "health", - ExhaustStor = Storage.StrawberryCupcake, - timestamp = 10, - }, - [28486] = { - Type = "skill", - ExhaustStor = Storage.LemonCupcake, - timestamp = 10, - }, -} - -local lemon = Condition(CONDITION_ATTRIBUTES) -lemon:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000) -lemon:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 10) - -local cupCakes = Action() - -function cupCakes.onUse(player, item, fromPos, itemEx, toPos) - local foundItem = data[item.itemid] - if not foundItem then - return - end - if (player:getStorageValue(foundItem.ExhaustStor)) < os.time() then - if foundItem.Type == "mana" then - player:addMana(player:getMaxMana()) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your mana has been refilled.") - elseif foundItem.Type == "health" then - player:addHealth(player:getMaxHealth()) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your health has been refilled.") - elseif foundItem.Type == "skill" then - player:addCondition(lemon) - player:sendTextMessage(MESSAGE_FAILURE, "You feel more focused.") - end - player:say("Mmmm.", TALKTYPE_MONSTER_SAY) - item:remove(1) - player:setStorageValue(foundItem.ExhaustStor, os.time() + (foundItem.timestamp * 60)) - else - player:sendTextMessage(MESSAGE_FAILURE, "You need to wait before using it again.") - end - return true -end - -cupCakes:id(28484, 28485, 28486) -cupCakes:register() diff --git a/data-otservbr-global/scripts/actions/quests/adventurers_guild/warrior_skeleton.lua b/data-otservbr-global/scripts/actions/quests/adventurers_guild/warrior_skeleton.lua index a1aec80aaee..73a5d3f8acb 100644 --- a/data-otservbr-global/scripts/actions/quests/adventurers_guild/warrior_skeleton.lua +++ b/data-otservbr-global/scripts/actions/quests/adventurers_guild/warrior_skeleton.lua @@ -3,6 +3,11 @@ function adventurersWarriorSkeleton.onUse(player, item, fromPosition, target, to if player:getStorageValue(Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton) < 1 then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have discovered a deceased warrior's skeleton. It seems he tried to hunt the dragons around here - and failed.") player:addItem(5882, 1) -- red dragon scale + + if player:getStorageValue(Storage.AdventurersGuild.QuestLine) < 1 then + player:setStorageValue(Storage.AdventurersGuild.QuestLine, 1) + end + player:setStorageValue(Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, 1) player:setStorageValue(Storage.AdventurersGuild.GreatDragonHunt.DragonCounter, 0) else diff --git a/data-otservbr-global/scripts/actions/quests/adventures_of_galthen/galthens_tree.lua b/data-otservbr-global/scripts/actions/quests/adventures_of_galthen/galthens_tree.lua new file mode 100644 index 00000000000..441b91fa345 --- /dev/null +++ b/data-otservbr-global/scripts/actions/quests/adventures_of_galthen/galthens_tree.lua @@ -0,0 +1,19 @@ +local galthensTree = Action() +function galthensTree.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local hasExhaustion, message = player:kv():get("galthens-satchel") or 0, "Empty." + if hasExhaustion < os.time() then + local container = player:addItem(36813) + container:addItem(36810, 1) + player:kv():set("galthens-satchel", os.time() + 30 * 24 * 60 * 60) + message = "You have found a galthens satchel." + end + + player:teleportTo(Position(32396, 32520, 7)) + player:getPosition():sendMagicEffect(CONST_ME_WATERSPLASH) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message) + + return true +end + +galthensTree:position(Position(32366, 32542, 8)) +galthensTree:register() diff --git a/data-otservbr-global/scripts/actions/quests/feaster_of_souls/portal_brain_head.lua b/data-otservbr-global/scripts/actions/quests/feaster_of_souls/portal_brain_head.lua index 725359eb64a..aebc0b3ca7a 100644 --- a/data-otservbr-global/scripts/actions/quests/feaster_of_souls/portal_brain_head.lua +++ b/data-otservbr-global/scripts/actions/quests/feaster_of_souls/portal_brain_head.lua @@ -103,26 +103,26 @@ function teleportBoss.onStepIn(creature, item, position, fromPosition) end local player = creature if player:getLevel() < config.requiredLevel then - player:teleportTo(fromPosition, true) + player:teleportTo(config.exitPosition, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to be level " .. config.requiredLevel .. " or higher.") return true end if locked then - player:teleportTo(fromPosition, true) + player:teleportTo(config.exitPosition, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "There's already someone fighting with " .. config.bossName .. ".") return false end if zone:countPlayers(IgnoredByMonsters) >= 5 then - player:teleportTo(fromPosition, true) + player:teleportTo(config.exitPosition, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The boss room is full.") return false end local timeLeft = player:getBossCooldown(config.bossName) - os.time() if timeLeft > 0 then - player:teleportTo(fromPosition, true) + player:teleportTo(config.exitPosition, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have to wait " .. getTimeInWords(timeLeft) .. " to face " .. config.bossName .. " again!") player:getPosition():sendMagicEffect(CONST_ME_POFF) diff --git a/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua b/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua index ac8f4506c70..ad0e8d49b73 100644 --- a/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua +++ b/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua @@ -275,8 +275,10 @@ local questTable = { { storage = Storage.Quest.U11_40.ThreatenedDreams.QuestLine, storageValue = 1 }, { storage = Storage.Quest.U11_40.ThreatenedDreams.Mission01[1], storageValue = 16 }, { storage = Storage.Quest.U11_40.ThreatenedDreams.Mission02.KroazurAccess, storageValue = 1 }, + { storage = Storage.AdventurersGuild.QuestLine, storageValue = 1 }, { storage = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, storageValue = 1 }, { storage = Storage.AdventurersGuild.GreatDragonHunt.WarriorSkeleton, storageValue = 2 }, + { storage = Storage.AdventurersGuild.TheLostBrother, storageValue = 3 }, { storage = Storage.Quest.U10_55.Dawnport.Questline, storageValue = 1 }, { storage = Storage.Quest.U10_55.Dawnport.GoMain, storageValue = 1 }, { storage = Storage.ForgottenKnowledge.AccessDeath, storageValue = 1 }, diff --git a/data-otservbr-global/scripts/creaturescripts/quests/dark_trails/kill_the_ravager.lua b/data-otservbr-global/scripts/creaturescripts/quests/dark_trails/kill_the_ravager.lua index 97798dadfeb..f11bfa41efe 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/dark_trails/kill_the_ravager.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/dark_trails/kill_the_ravager.lua @@ -7,7 +7,7 @@ local function removeTeleport(position) end local theRavager = CreatureEvent("TheRavagerDeath") -function theRavager.onDeath(player, creature) +function theRavager.onDeath(creature) local position = creature:getPosition() position:sendMagicEffect(CONST_ME_TELEPORT) local item = Game.createItem(1949, 1, { x = 33496, y = 32070, z = 8 }) diff --git a/data-otservbr-global/scripts/creaturescripts/quests/killing_in_the_name_of/monster_kill.lua b/data-otservbr-global/scripts/creaturescripts/quests/killing_in_the_name_of/monster_kill.lua index b2ba681d251..f8f7ddc5c6b 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/killing_in_the_name_of/monster_kill.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/killing_in_the_name_of/monster_kill.lua @@ -57,7 +57,7 @@ function deathEvent.onDeath(creature, _corpse, _lastHitKiller, mostDamageKiller) end end -- Minotaurs - killCheck(player, targetName, Storage.KillingInTheNameOf.BudrikMinos, 0, tasks.Budrik[1].creatures, nil, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.MinotaurCount) + killCheck(player, targetName, Storage.KillingInTheNameOf.BudrikMinos, 0, tasks.Budrik[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.MinotaurCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.MinotaurCount) -- Necromancers and Priestesses killCheck(player, targetName, Storage.KillingInTheNameOf.LugriNecromancers, 0, tasks.Lugri[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.NecromancerCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.NecromancerCount) killCheck(player, targetName, Storage.KillingInTheNameOf.LugriNecromancers, 3, tasks.Lugri[1].creatures, Storage.Quest.U8_5.KillingInTheNameOf.AltKillCount.NecromancerCount, Storage.Quest.U8_5.KillingInTheNameOf.MonsterKillCount.NecromancerCount) diff --git a/data-otservbr-global/scripts/creaturescripts/quests/liquid_black/deepling_boss_kill.lua b/data-otservbr-global/scripts/creaturescripts/quests/liquid_black/deepling_boss_kill.lua index 6916f3dfa5a..49fb3e17c11 100644 --- a/data-otservbr-global/scripts/creaturescripts/quests/liquid_black/deepling_boss_kill.lua +++ b/data-otservbr-global/scripts/creaturescripts/quests/liquid_black/deepling_boss_kill.lua @@ -5,12 +5,11 @@ local bosses = { } local deeplingBosses = CreatureEvent("DeeplingBossDeath") -function deeplingBosses.onDeath(player, creature) +function deeplingBosses.onDeath(creature) local bossConfig = bosses[creature:getName():lower()] if not bossConfig then return true end - onDeathForDamagingPlayers(creature, function(creature, player) if player:getStorageValue(Storage.DeeplingBosses.DeeplingStatus) < bossConfig.status then player:setStorageValue(Storage.DeeplingBosses.DeeplingStatus, bossConfig.status) diff --git a/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua b/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua new file mode 100644 index 00000000000..a5cc9a123f4 --- /dev/null +++ b/data-otservbr-global/scripts/game_migrations/20241715984279_move_wheel_scrolls_from_storagename_to_kv.lua @@ -0,0 +1,24 @@ +local promotionScrolls = { + { oldScroll = "wheel.scroll.abridged", newScroll = "abridged" }, + { oldScroll = "wheel.scroll.basic", newScroll = "basic" }, + { oldScroll = "wheel.scroll.revised", newScroll = "revised" }, + { oldScroll = "wheel.scroll.extended", newScroll = "extended" }, + { oldScroll = "wheel.scroll.advanced", newScroll = "advanced" }, +} + +local function migrate(player) + for _, scrollTable in ipairs(promotionScrolls) do + local oldStorage = player:getStorageValueByName(scrollTable.oldScroll) + if oldStorage > 0 then + player:kv():scoped("wheel-of-destiny"):scoped("scrolls"):set(scrollTable.newScroll, true) + end + end +end + +local migration = Migration("20241715984279_move_wheel_scrolls_from_storagename_to_kv") + +function migration:onExecute() + self:forEachPlayer(migrate) +end + +migration:register() diff --git a/data-otservbr-global/scripts/quests/the_lost_brother/movement-find-remains.lua b/data-otservbr-global/scripts/quests/the_lost_brother/movement-find-remains.lua new file mode 100644 index 00000000000..c2ddb8efcb7 --- /dev/null +++ b/data-otservbr-global/scripts/quests/the_lost_brother/movement-find-remains.lua @@ -0,0 +1,19 @@ +local findRemains = MoveEvent() + +function findRemains.onStepIn(creature, item, position, fromPosition) + local player = creature:getPlayer() + if not player then + return true + end + + if player:getStorageValue(Storage.AdventurersGuild.TheLostBrother) == 1 then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You stumble over some old bones. Something is carved into the stone wall here: 'Tarun, my brother, you were right. She's evil.'") + player:setStorageValue(Storage.AdventurersGuild.TheLostBrother, 2) + player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) + end + + return true +end + +findRemains:position(Position(32959, 32674, 4)) +findRemains:register() diff --git a/data-otservbr-global/scripts/spells/monster/doctor_marrow_explosion.lua b/data-otservbr-global/scripts/spells/monster/doctor_marrow_explosion.lua index f616e8b8cee..491d9f2516d 100644 --- a/data-otservbr-global/scripts/spells/monster/doctor_marrow_explosion.lua +++ b/data-otservbr-global/scripts/spells/monster/doctor_marrow_explosion.lua @@ -21,7 +21,7 @@ end local spell = Spell("instant") function onTargetCreature(creature, target) - if not targetPos then + if not target then return true end local master = target:getMaster() @@ -29,7 +29,7 @@ function onTargetCreature(creature, target) return true end - local distance = math.floor(targetPos:getDistance(target:getPosition())) + local distance = math.floor(creature:getPosition():getDistance(target:getPosition())) local actualDamage = damage / (2 ^ distance) doTargetCombatHealth(0, target, COMBAT_EARTHDAMAGE, actualDamage, actualDamage, CONST_ME_NONE) if crit then @@ -63,21 +63,26 @@ function spell.onCastSpell(creature, var) end, i * 100, targetPos) end - addEvent(function(cid) + addEvent(function(cid, pos) local creature = Creature(cid) - creature:getPosition():sendMagicEffect(CONST_ME_ORANGE_ENERGY_SPARK) - targetPos:sendMagicEffect(CONST_ME_ORANGETELEPORT) - end, 2000, creature:getId()) + if creature then + creature:getPosition():sendMagicEffect(CONST_ME_ORANGE_ENERGY_SPARK) + pos:sendMagicEffect(CONST_ME_ORANGETELEPORT) + end + end, 2000, creature:getId(), targetPos) addEvent(function(cid, pos) - damage = -math.random(3500, 7000) - if math.random(1, 100) <= 10 then - crit = true - damage = damage * 1.5 - else - crit = false + local creature = Creature(cid) + if creature then + damage = -math.random(3500, 7000) + if math.random(1, 100) <= 10 then + crit = true + damage = damage * 1.5 + else + crit = false + end + spellCombat:execute(creature, Variant(pos)) end - spellCombat:execute(creature, Variant(pos)) end, totalDelay, creature:getId(), targetPos) return true end diff --git a/data-otservbr-global/scripts/weapons/scripts/diamond_arrow.lua b/data-otservbr-global/scripts/weapons/scripts/diamond_arrow.lua index 61984209287..36be8dc38b4 100644 --- a/data-otservbr-global/scripts/weapons/scripts/diamond_arrow.lua +++ b/data-otservbr-global/scripts/weapons/scripts/diamond_arrow.lua @@ -16,7 +16,7 @@ combat:setParameter(COMBAT_PARAM_BLOCKARMOR, true) function onGetFormulaValues(player, skill, attack, factor) local distanceSkill = player:getEffectiveSkillLevel(SKILL_DISTANCE) local min = (player:getLevel() / 5) - local max = (0.09 * factor) * distanceSkill * 37 + (player:getLevel() / 5) + local max = (0.09 * factor) * distanceSkill * attack + (player:getLevel() / 5) return -min, -max end diff --git a/data-otservbr-global/world/otservbr-monster.xml b/data-otservbr-global/world/otservbr-monster.xml index d3bbc69e858..974c2ea6809 100644 --- a/data-otservbr-global/world/otservbr-monster.xml +++ b/data-otservbr-global/world/otservbr-monster.xml @@ -4076,7 +4076,6 @@ - @@ -4122,9 +4121,6 @@ - - - @@ -6928,19 +6924,13 @@ - - - - - - @@ -6953,9 +6943,6 @@ - - - @@ -6963,7 +6950,6 @@ - @@ -6985,15 +6971,11 @@ - - - - @@ -7009,9 +6991,6 @@ - - - @@ -63284,9 +63263,6 @@ - - - @@ -63491,9 +63467,6 @@ - - - @@ -96125,15 +96098,15 @@ + + + - - - @@ -96718,6 +96691,9 @@ + + + @@ -96725,9 +96701,6 @@ - - - @@ -118889,12 +118862,12 @@ - - - + + + diff --git a/data-otservbr-global/world/otservbr-npc.xml b/data-otservbr-global/world/otservbr-npc.xml index 10772902341..f97bc118fdc 100644 --- a/data-otservbr-global/world/otservbr-npc.xml +++ b/data-otservbr-global/world/otservbr-npc.xml @@ -2994,5 +2994,8 @@ - + + + + diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 35e0bb17e7f..ec1a92f3528 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -140,8 +140,8 @@ local function useStaminaXpBoost(player) return false end - local staminaMinutes = player:getExpBoostStamina() / 60 - if staminaMinutes == 0 then + local xpBoostMinutes = player:getXpBoostTime() / 60 + if xpBoostMinutes == 0 then return end @@ -156,18 +156,26 @@ local function useStaminaXpBoost(player) return end + local xpBoostLeftMinutesByDailyReward = player:kv():get("daily-reward-xp-boost") or 0 if timePassed > 60 then - if staminaMinutes > 2 then - staminaMinutes = staminaMinutes - 2 + if xpBoostMinutes > 2 then + xpBoostMinutes = xpBoostMinutes - 2 + if xpBoostLeftMinutesByDailyReward > 2 then + player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 2) + end else - staminaMinutes = 0 + xpBoostMinutes = 0 + player:kv():remove("daily-reward-xp-boost") end _G.NextUseXpStamina[playerId] = currentTime + 120 else - staminaMinutes = staminaMinutes - 1 + xpBoostMinutes = xpBoostMinutes - 1 + if xpBoostLeftMinutesByDailyReward > 0 then + player:kv():set("daily-reward-xp-boost", xpBoostLeftMinutesByDailyReward - 1) + end _G.NextUseXpStamina[playerId] = currentTime + 60 end - player:setExpBoostStamina(staminaMinutes * 60) + player:setXpBoostTime(xpBoostMinutes * 60) end local function useConcoctionTime(player) @@ -519,14 +527,14 @@ function Player:onGainExperience(target, exp, rawExp) self:addCondition(soulCondition) end - -- Store Bonus - useStaminaXpBoost(self) -- Use store boost stamina + -- XP Boost Bonus + useStaminaXpBoost(self) -- Use stamina XP boost (store or daily reward) - local Boost = self:getExpBoostStamina() - local stillHasBoost = Boost > 0 - local storeXpBoostAmount = stillHasBoost and self:getStoreXpBoost() or 0 + local xpBoostTimeLeft = self:getXpBoostTime() + local stillHasXpBoost = xpBoostTimeLeft > 0 + local xpBoostPercent = stillHasXpBoost and self:getXpBoostPercent() or 0 - self:setStoreXpBoost(storeXpBoostAmount) + self:setXpBoostPercent(xpBoostPercent) -- Stamina Bonus local staminaBonusXp = 1 @@ -564,7 +572,7 @@ function Player:onGainExperience(target, exp, rawExp) local lowLevelBonuxExp = self:getFinalLowLevelBonus() local baseRate = self:getFinalBaseRateExperience() - return (exp + (exp * (storeXpBoostAmount / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate + return (exp + (exp * (xpBoostPercent / 100) + (exp * (lowLevelBonuxExp / 100)))) * staminaBonusXp * baseRate end function Player:onLoseExperience(exp) diff --git a/data/items/items.xml b/data/items/items.xml index 765c6e9db51..e7e73d9753b 100644 --- a/data/items/items.xml +++ b/data/items/items.xml @@ -53105,6 +53105,9 @@ hands of its owner. Granted by TibiaRoyal.com"/> + + + @@ -64463,8 +64466,8 @@ hands of its owner. Granted by TibiaRoyal.com"/> + - @@ -74870,11 +74873,14 @@ Granted by TibiaGoals.com"/> - + + + + @@ -74991,6 +74997,15 @@ Granted by TibiaGoals.com"/> + + + + + + + + + @@ -75006,6 +75021,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75029,6 +75047,12 @@ Granted by TibiaGoals.com"/> + + + + + + @@ -75052,6 +75076,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75075,6 +75102,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75098,6 +75128,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75121,6 +75154,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75146,6 +75182,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75170,6 +75209,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75194,6 +75236,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75218,6 +75263,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75242,6 +75290,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75266,6 +75317,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75282,6 +75336,14 @@ Granted by TibiaGoals.com"/> + + + + + + + + @@ -75308,6 +75370,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75335,6 +75400,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75362,6 +75430,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75389,6 +75460,9 @@ Granted by TibiaGoals.com"/> + + + @@ -75404,6 +75478,14 @@ Granted by TibiaGoals.com"/> + + + + + + + + @@ -75419,6 +75501,7 @@ Granted by TibiaGoals.com"/> + @@ -75426,8 +75509,12 @@ Granted by TibiaGoals.com"/> + + + + - + @@ -75446,6 +75533,7 @@ Granted by TibiaGoals.com"/> + @@ -75454,8 +75542,12 @@ Granted by TibiaGoals.com"/> + + + + - + @@ -75478,6 +75570,17 @@ Granted by TibiaGoals.com"/> + + + + + + + + + + + @@ -75489,6 +75592,7 @@ Granted by TibiaGoals.com"/> + @@ -75500,6 +75604,10 @@ Granted by TibiaGoals.com"/> + + + + @@ -75519,6 +75627,7 @@ Granted by TibiaGoals.com"/> + @@ -75528,6 +75637,10 @@ Granted by TibiaGoals.com"/> + + + + @@ -75552,6 +75665,17 @@ Granted by TibiaGoals.com"/> + + + + + + + + + + + diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 9eb1b0b57b5..c2349ce7fd6 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -67,17 +67,28 @@ end function getTimeInWords(secsParam) local secs = tonumber(secsParam) + local days = math.floor(secs / (24 * 3600)) + secs = secs - (days * 24 * 3600) local hours, minutes, seconds = getHours(secs), getMinutes(secs), getSeconds(secs) local timeStr = "" + if days > 0 then + timeStr = days .. (days > 1 and " days" or " day") + end + if hours > 0 then - timeStr = hours .. (hours > 1 and " hours" or " hour") + if timeStr ~= "" then + timeStr = timeStr .. ", " + end + + timeStr = timeStr .. hours .. (hours > 1 and " hours" or " hour") end if minutes > 0 then if timeStr ~= "" then timeStr = timeStr .. ", " end + timeStr = timeStr .. minutes .. (minutes > 1 and " minutes" or " minute") end @@ -85,9 +96,9 @@ function getTimeInWords(secsParam) if timeStr ~= "" then timeStr = timeStr .. " and " end + timeStr = timeStr .. seconds .. (seconds > 1 and " seconds" or " second") end - return timeStr end diff --git a/data/modules/scripts/daily_reward/daily_reward.lua b/data/modules/scripts/daily_reward/daily_reward.lua index 1f0e805704c..09b927cedda 100644 --- a/data/modules/scripts/daily_reward/daily_reward.lua +++ b/data/modules/scripts/daily_reward/daily_reward.lua @@ -476,8 +476,15 @@ function Player.selectDailyReward(self, msg) end dailyRewardMessage = "Picked items: " .. description elseif dailyTable.type == DAILY_REWARD_TYPE_XP_BOOST then - self:setExpBoostStamina(self:getExpBoostStamina() + (rewardCount * 60)) - self:setStoreXpBoost(50) + local rewardCountReviewed = rewardCount + local xpBoostLeftMinutes = self:kv():get("daily-reward-xp-boost") or 0 + if xpBoostLeftMinutes > 0 then + rewardCountReviewed = rewardCountReviewed - xpBoostLeftMinutes + end + + self:setXpBoostTime(self:getXpBoostTime() + (rewardCountReviewed * 60)) + self:kv():set("daily-reward-xp-boost", rewardCount) + self:setXpBoostPercent(50) dailyRewardMessage = "Picked reward: XP Bonus for " .. rewardCount .. " minutes." elseif dailyTable.type == DAILY_REWARD_TYPE_PREY_REROLL then self:addPreyCards(rewardCount) 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 a927715cd93..ba7398d9d3e 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 @@ -402,7 +409,7 @@ function parseBuyStoreOffer(playerId, msg) -- 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 + 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 @@ -472,7 +479,7 @@ function parseBuyStoreOffer(playerId, msg) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_SEXCHANGE then GameStore.processSexChangePurchase(player) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then - GameStore.processExpBoostPuchase(player) + GameStore.processExpBoostPurchase(player) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_HUNTINGSLOT then GameStore.processTaskHuntingThirdSlot(player) elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_PREYSLOT then @@ -507,8 +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." - if not pcallError.code then -- unhandled error - -- log some debugging info + -- unhandled error + if not pcallError.code then logger.warn("[parseBuyStoreOffer] - Purchase failed due to an unhandled script error. Stacktrace: {}", pcallError) end @@ -618,9 +625,8 @@ function sendOfferDescription(player, offerId, description) end function Player.canBuyOffer(self, offer) - local playerId = self:getId() local disabled, disabledReason = 0, "" - if offer.disabled == true or not offer.type then + if offer.disabled or not offer.type then disabled = 1 end @@ -692,18 +698,17 @@ function Player.canBuyOffer(self, offer) disabledReason = "The offer is fake." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_MOUNT then - local hasMount = self:hasMount(offer.id) - if hasMount == true then + if self:hasMount(offer.id) then disabled = 1 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 @@ -723,17 +728,16 @@ function Player.canBuyOffer(self, offer) disabledReason = "You already have 3 slots released." end elseif offer.type == GameStore.OfferTypes.OFFER_TYPE_EXPBOOST then - local remainingBoost = self:getExpBoostStamina() - 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 - if remainingBoost > 0 then + if self:getXpBoostTime() > 0 then disabled = 1 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 @@ -786,9 +790,9 @@ function Player.canReceiveStoreItems(self, offerId, offerCount) local inboxItems = inbox:getItems(true) local slotsOccupied = #inboxItems local maxCapacity = inbox:getMaxCapacity() - local slotsAvailable = maxCapacity - slotsOccupied if slotsOccupied + slotsNeeded > maxCapacity then + local slotsAvailable = maxCapacity - slotsOccupied return false, string.format("Not enough free slots in your store inbox. You need %d more slot(s). Currently occupied: %d/%d", slotsNeeded - slotsAvailable, slotsOccupied, maxCapacity) end @@ -1104,14 +1108,16 @@ function sendStoreTransactionHistory(playerId, page, entriesPerPage) if not player then return false end - local oldProtocol = player:getClient().version < 1200 - local totalEntries = GameStore.retrieveHistoryTotalPages(player:getAccountId()) - local totalPages = math.ceil(totalEntries / entriesPerPage) + local entries = GameStore.retrieveHistoryEntries(player:getAccountId(), page, entriesPerPage) -- this makes everything easy! if #entries == 0 then return addPlayerEvent(sendStoreError, 250, playerId, GameStore.StoreErrors.STORE_ERROR_HISTORY, "You don't have any entries yet.") end + local oldProtocol = player:getClient().version < 1200 + local totalEntries = GameStore.retrieveHistoryTotalPages(player:getAccountId()) + local totalPages = math.ceil(totalEntries / entriesPerPage) + local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_OpenTransactionHistory) msg:addU32(totalPages > 0 and page - 1 or 0x0) -- current page @@ -1165,10 +1171,8 @@ function sendStoreError(playerId, errorType, message) local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_StoreError) - msg:addByte(errorType) msg:addString(message, "sendStoreError - message") - msg:sendToPlayer(player) end @@ -1183,7 +1187,7 @@ function sendStoreBalanceUpdating(playerId, updating) msg:addByte(0x00) msg:sendToPlayer(player) - if updating == true then + if updating then sendUpdatedStoreBalances(playerId) end end @@ -1194,7 +1198,6 @@ function sendUpdatedStoreBalances(playerId) return false end - local oldProtocol = player:getClient().version < 1200 local msg = NetworkMessage() msg:addByte(GameStore.SendingPackets.S_CoinBalanceUpdating) msg:addByte(0x01) @@ -1205,6 +1208,8 @@ function sendUpdatedStoreBalances(playerId) -- Send total of coins (transferable and normal coin) msg:addU32(player:getTibiaCoins()) msg:addU32(player:getTransferableCoins()) -- How many are Transferable + + local oldProtocol = player:getClient().version < 1200 if not oldProtocol then -- How many are reserved for a Character Auction -- We currently do not have this system implemented, so we will send 0 @@ -1346,7 +1351,7 @@ end GameStore.retrieveHistoryTotalPages = function(accountId) local resultId = db.storeQuery("SELECT count(id) as total FROM store_history WHERE account_id = " .. accountId) - if resultId == false then + if not resultId then return 0 end @@ -1360,7 +1365,7 @@ GameStore.retrieveHistoryEntries = function(accountId, currentPage, entriesPerPa local offset = currentPage > 1 and entriesPerPage * (currentPage - 1) or 0 local resultId = db.storeQuery("SELECT * FROM `store_history` WHERE `account_id` = " .. accountId .. " ORDER BY `time` DESC LIMIT " .. offset .. ", " .. entriesPerPage .. ";") - if resultId ~= false then + if resultId then repeat local entry = { mode = Result.getNumber(resultId, "mode"), @@ -1566,8 +1571,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 @@ -1602,7 +1608,7 @@ function GameStore.processStackablePurchase(player, offerId, offerCount, offerNa local countToAdd = math.min(remainingCount, stackSize) local inboxItem = inbox:addItem(offerId, countToAdd) if inboxItem then - if movable ~= true then + if not movable then inboxItem:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end else @@ -1631,22 +1637,32 @@ function GameStore.processHouseRelatedPurchase(player, offer) local inbox = player:getStoreInbox() if inbox then for _, itemId in ipairs(itemIds) do - for i = 1, offer.count do + if isCaskItem(itemId) then local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1) if decoKit then decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a <" .. ItemType(itemId):getName() .. ">.") decoKit:setCustomAttribute("unWrapId", itemId) - if isCaskItem(itemId) then - decoKit:setAttribute(ITEM_ATTRIBUTE_DATE, offer.count) - end + decoKit:setAttribute(ITEM_ATTRIBUTE_DATE, offer.count) - if offer.movable ~= true then + if not offer.movable then decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) end end + else + for i = 1, offer.count do + local decoKit = inbox:addItem(ITEM_DECORATION_KIT, 1) + if decoKit then + decoKit:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, "You bought this item in the Store.\nUnwrap it in your own house to create a <" .. ItemType(itemId):getName() .. ">.") + decoKit:setCustomAttribute("unWrapId", itemId) + + if not offer.movable then + decoKit:setAttribute(ITEM_ATTRIBUTE_STORE, systemTime()) + end + end + end end - player:sendUpdateContainer(inbox) end + player:sendUpdateContainer(inbox) end end @@ -1667,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 - 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 + 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) @@ -1689,8 +1701,6 @@ function GameStore.processMountPurchase(player, offerId) end function GameStore.processNameChangePurchase(player, offer, productType, newName) - local playerId = player:getId() - if productType == GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE then local tile = Tile(player:getPosition()) if tile then @@ -1720,11 +1730,11 @@ function GameStore.processNameChangePurchase(player, offer, productType, newName else message = "Your character has been renamed successfully." end - addPlayerEvent(sendStorePurchaseSuccessful, 500, playerId, message) + addPlayerEvent(sendStorePurchaseSuccessful, 500, player:getId(), message) player:changeName(newName) else - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) end end @@ -1732,12 +1742,12 @@ function GameStore.processSexChangePurchase(player) player:toggleSex() end -function GameStore.processExpBoostPuchase(player) - local currentExpBoostTime = player:getExpBoostStamina() +function GameStore.processExpBoostPurchase(player) + local currentXpBoostTime = player:getXpBoostTime() local expBoostCount = player:getStorageValue(GameStore.Storages.expBoostCount) - player:setStoreXpBoost(50) - player:setExpBoostStamina(currentExpBoostTime + 3600) + player:setXpBoostPercent(50) + player:setXpBoostTime(currentXpBoostTime + 3600) if expBoostCount == -1 or expBoostCount == 6 then expBoostCount = 1 @@ -1761,8 +1771,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 @@ -1780,9 +1791,6 @@ function GameStore.processTempleTeleportPurchase(player) end function GameStore.processHirelingPurchase(player, offer, productType, hirelingName, chosenSex) - local playerId = player:getId() - local offerId = offer.id - if player:getClient().version < 1200 then return error({ code = 1, message = "You cannot buy hirelings on client 10, please relog on client 12 and try again." }) end @@ -1804,22 +1812,58 @@ function GameStore.processHirelingPurchase(player, offer, productType, hirelingN player:makeCoinTransaction(offer, hirelingName) local message = "You have successfully bought " .. hirelingName - return addPlayerEvent(sendStorePurchaseSuccessful, 650, playerId, message) + 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 - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offerId, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_HIRELING) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_HIRELING) end end -function GameStore.processHirelingChangeNamePurchase(player, offer, productType, newHirelingName) - local playerId = player:getId() - local offerId = offer.id +-- Hireling Helpers +local function HandleHirelingNameChange(playerId, offer, newHirelingName) + local player = Player(playerId) + if not player then + return + end + + local functionCallback = function(playerIdInFunction, data, hireling) + local playerInFunction = Player(playerIdInFunction) + if not playerInFunction then + return + end + if not hireling then + return playerInFunction:showInfoModal("Error", "Your must select a hireling.") + end + + if hireling.active > 0 then + return playerInFunction:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + end + + local oldName = hireling.name + hireling.name = data.newHirelingName + + if not playerInFunction:makeCoinTransaction(data.offer, oldName .. " to " .. hireling.name) then + return playerInFunction:showInfoModal("Error", "Transaction error") + end + + local lamp = playerInFunction:findHirelingLamp(hireling:getId()) + 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, hireling.name) + sendUpdatedStoreBalances(playerIdInFunction) + end + + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer, newHirelingName = newHirelingName }) +end + +function GameStore.processHirelingChangeNamePurchase(player, offer, productType, newHirelingName) if player:getClient().version < 1200 then return error({ code = 1, @@ -1838,17 +1882,60 @@ function GameStore.processHirelingChangeNamePurchase(player, offer, productType, end) local message = "Close the store window to select which hireling should be renamed to " .. newHirelingName + local playerId = player:getId() addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) - addPlayerEvent(HandleHirelingNameChange, 550, playerId, offer, newHirelingName) else - return addPlayerEvent(sendRequestPurchaseData, 250, playerId, offerId, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) + return addPlayerEvent(sendRequestPurchaseData, 250, player:getId(), offer.id, GameStore.ClientOfferTypes.CLIENT_STORE_OFFER_NAMECHANGE) end end -function GameStore.processHirelingChangeSexPurchase(player, offer) - local playerId = player:getId() +local function HandleHirelingSexChange(playerId, offer) + local player = Player(playerId) + if not player then + return + end + + local functionCallback = function(playerIdInFunction, data, hireling) + local playerInFunction = Player(playerIdInFunction) + if not playerInFunction then + return + end + + if not hireling then + return playerInFunction:showInfoModal("Error", "Your must select a hireling.") + end + + if hireling.active > 0 then + return playerInFunction:showInfoModal("Error", "Your hireling must be inside his/her lamp.") + end + + if not playerInFunction:makeCoinTransaction(data.offer, hireling:getName()) then + return playerInFunction:showInfoModal("Error", "Transaction error") + end + + local changeTo, sexString, lookType + if hireling.sex == HIRELING_SEX.FEMALE then + changeTo = HIRELING_SEX.MALE + sexString = "male" + lookType = HIRELING_OUTFIT_DEFAULT.male + else + changeTo = HIRELING_SEX.FEMALE + sexString = "female" + lookType = HIRELING_OUTFIT_DEFAULT.female + end + + hireling.sex = changeTo + hireling.looktype = lookType + + logger.debug("{} sex was changed to {}", hireling:getName(), sexString) + sendUpdatedStoreBalances(playerIdInFunction) + end + + player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", functionCallback, { offer = offer }) +end +function GameStore.processHirelingChangeSexPurchase(player, offer) if player:getClient().version < 1200 then return error({ code = 1, @@ -1857,8 +1944,8 @@ function GameStore.processHirelingChangeSexPurchase(player, offer) end local message = "Close the store window to select which hireling should have the sex changed." + local playerId = player:getId() addPlayerEvent(sendStorePurchaseSuccessful, 200, playerId, message) - addPlayerEvent(HandleHirelingSexChange, 550, playerId, offer) end @@ -2135,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) @@ -2154,75 +2242,3 @@ function Player:openStore(serviceName) --exporting the method so other scripts c addPlayerEvent(sendShowStoreOffers, 50, playerId, category) end end - --- Hireling Helpers -function HandleHirelingNameChange(playerId, offer, newHirelingName) - local player = Player(playerId) - - local cb = function(playerId, data, hireling) - local offer = data.offer - local newHirelingName = data.newHirelingName - local player = Player(playerId) - if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") - end - - if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") - end - - local oldName = hireling.name - hireling.name = newHirelingName - - if not player:makeCoinTransaction(data.offer, oldName .. " to " .. newHirelingName) then - return player:showInfoModal("Error", "Transaction error") - end - - local lamp = player:findHirelingLamp(hireling:getId()) - 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) - sendUpdatedStoreBalances(playerId) - end - - player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer, newHirelingName = newHirelingName }) -end - -function HandleHirelingSexChange(playerId, offer) - local player = Player(playerId) - - local cb = function(playerId, data, hireling) - local player = Player(playerId) - if not hireling then - return player:showInfoModal("Error", "Your must select a hireling.") - end - - if hireling.active > 0 then - return player:showInfoModal("Error", "Your hireling must be inside his/her lamp.") - end - - if not player:makeCoinTransaction(data.offer, hireling:getName()) then - return player:showInfoModal("Error", "Transaction error") - end - - local changeTo, sexString, lookType - if hireling.sex == HIRELING_SEX.FEMALE then - changeTo = HIRELING_SEX.MALE - sexString = "male" - lookType = HIRELING_OUTFIT_DEFAULT.male - else - changeTo = HIRELING_SEX.FEMALE - sexString = "female" - lookType = HIRELING_OUTFIT_DEFAULT.female - end - - hireling.sex = changeTo - hireling.looktype = lookType - - logger.debug("{} sex was changed to {}", hireling:getName(), sexString) - sendUpdatedStoreBalances(playerId) - end - - player:sendHirelingSelectionModal("Choose a Hireling", "Select a hireling below", cb, { offer = offer }) -end diff --git a/data/scripts/actions/items/blueberry_cupcake.lua b/data/scripts/actions/items/blueberry_cupcake.lua new file mode 100644 index 00000000000..f645e852101 --- /dev/null +++ b/data/scripts/actions/items/blueberry_cupcake.lua @@ -0,0 +1,18 @@ +local blueberryCupcake = Action() + +function blueberryCupcake.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if player:hasExhaustion("blueberry-cupcake-cooldown") then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to wait before using it again.") + return true + end + + player:addMana(player:getMaxMana()) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your mana has been refilled.") + player:say("Mmmm.", TALKTYPE_MONSTER_SAY) + player:setExhaustion("blueberry-cupcake-cooldown", 10 * 60) + item:remove(1) + return true +end + +blueberryCupcake:id(28484) +blueberryCupcake:register() diff --git a/data/scripts/actions/items/exercise_training_weapons.lua b/data/scripts/actions/items/exercise_training_weapons.lua index 4a72f19e5c8..3c62d7c1183 100644 --- a/data/scripts/actions/items/exercise_training_weapons.lua +++ b/data/scripts/actions/items/exercise_training_weapons.lua @@ -133,7 +133,7 @@ end local exerciseTraining = Action() function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target or not target:getId() then + if not target or type(target) == "table" or not target:getId() then return true end diff --git a/data/scripts/actions/items/lemon_cupcake.lua b/data/scripts/actions/items/lemon_cupcake.lua new file mode 100644 index 00000000000..3cf085d8ad8 --- /dev/null +++ b/data/scripts/actions/items/lemon_cupcake.lua @@ -0,0 +1,24 @@ +local distanceCondition = Condition(CONDITION_ATTRIBUTES) +distanceCondition:setParameter(CONDITION_PARAM_BUFF_SPELL, 1) +distanceCondition:setParameter(CONDITION_PARAM_TICKS, 60 * 60 * 1000) +distanceCondition:setParameter(CONDITION_PARAM_SKILL_DISTANCE, 10) +distanceCondition:setParameter(CONDITION_PARAM_FORCEUPDATE, true) + +local lemonCupcake = Action() + +function lemonCupcake.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if player:hasExhaustion("lemon-cupcake-cooldown") then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to wait before using it again.") + return true + end + + player:addCondition(distanceCondition) + player:sendTextMessage(MESSAGE_FAILURE, "You feel more focused.") + player:say("Mmmm.", TALKTYPE_MONSTER_SAY) + player:setExhaustion("lemon-cupcake-cooldown", 10 * 60) + item:remove(1) + return true +end + +lemonCupcake:id(28486) +lemonCupcake:register() diff --git a/data/scripts/actions/items/potions.lua b/data/scripts/actions/items/potions.lua index 02e92349363..473796d79df 100644 --- a/data/scripts/actions/items/potions.lua +++ b/data/scripts/actions/items/potions.lua @@ -89,10 +89,13 @@ function flaskPotion.onUse(player, item, fromPosition, target, toPosition, isHot local deactivatedFlasks = player:kv():get("talkaction.potions.flask") or false if not deactivatedFlasks then local container = Container(item:getParent().uid) - local inbox = player:getSlotItem(CONST_SLOT_STORE_INBOX) - - if fromPosition.x == CONTAINER_POSITION and container ~= inbox and container:getEmptySlots() ~= 0 then - container:addItem(potion.flask, 1) + if container then + local storeInbox = player:getSlotItem(CONST_SLOT_STORE_INBOX) + if fromPosition.x == CONTAINER_POSITION and container ~= storeInbox and container:getEmptySlots() ~= 0 then + container:addItem(potion.flask, 1) + else + player:addItem(potion.flask, 1) + end else Game.createItem(potion.flask, 1, fromPosition) end diff --git a/data/scripts/actions/items/strawberry_cupcake.lua b/data/scripts/actions/items/strawberry_cupcake.lua new file mode 100644 index 00000000000..7ee7ec75764 --- /dev/null +++ b/data/scripts/actions/items/strawberry_cupcake.lua @@ -0,0 +1,18 @@ +local strawberryCupcake = Action() + +function strawberryCupcake.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if player:hasExhaustion("strawberry-cupcake-cooldown") then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to wait before using it again.") + return true + end + + player:addHealth(player:getMaxHealth()) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your health has been refilled.") + player:say("Mmmm.", TALKTYPE_MONSTER_SAY) + player:setExhaustion("strawberry-cupcake-cooldown", 10 * 60) + item:remove(1) + return true +end + +strawberryCupcake:id(28485) +strawberryCupcake:register() diff --git a/data/scripts/actions/items/wheel_scrolls.lua b/data/scripts/actions/items/wheel_scrolls.lua index b42339a706e..61aaa6fe40a 100644 --- a/data/scripts/actions/items/wheel_scrolls.lua +++ b/data/scripts/actions/items/wheel_scrolls.lua @@ -1,9 +1,9 @@ local promotionScrolls = { - [43946] = { storageName = "wheel.scroll.abridged", points = 3, name = "abridged promotion scroll" }, - [43947] = { storageName = "wheel.scroll.basic", points = 5, name = "basic promotion scroll" }, - [43948] = { storageName = "wheel.scroll.revised", points = 9, name = "revised promotion scroll" }, - [43949] = { storageName = "wheel.scroll.extended", points = 13, name = "extended promotion scroll" }, - [43950] = { storageName = "wheel.scroll.advanced", points = 20, name = "advanced promotion scroll" }, + [43946] = { name = "abridged", points = 3, itemName = "abridged promotion scroll" }, + [43947] = { name = "basic", points = 5, itemName = "basic promotion scroll" }, + [43948] = { name = "revised", points = 9, itemName = "revised promotion scroll" }, + [43949] = { name = "extended", points = 13, itemName = "extended promotion scroll" }, + [43950] = { name = "advanced", points = 20, itemName = "advanced promotion scroll" }, } local scroll = Action() @@ -15,13 +15,14 @@ function scroll.onUse(player, item, fromPosition, target, toPosition, isHotkey) end local scrollData = promotionScrolls[item:getId()] - if player:getStorageValueByName(scrollData.storageName) == 1 then + local scrollKV = player:kv():scoped("wheel-of-destiny"):scoped("scrolls") + if scrollKV:get(scrollData.name) then player:sendTextMessage(MESSAGE_LOOK, "You have already deciphered this scroll.") return true end - player:setStorageValueByName(scrollData.storageName, 1) - player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.name .. ".") + scrollKV:set(scrollData.name, true) + player:sendTextMessage(MESSAGE_LOOK, "You have gained " .. scrollData.points .. " promotion points for the Wheel of Destiny by deciphering the " .. scrollData.itemName .. ".") item:remove(1) return true end diff --git a/data/scripts/creaturescripts/player/offline_training.lua b/data/scripts/creaturescripts/player/offline_training.lua index abfb0b94b3d..4466c6ee0e3 100644 --- a/data/scripts/creaturescripts/player/offline_training.lua +++ b/data/scripts/creaturescripts/player/offline_training.lua @@ -12,7 +12,7 @@ function offlineTraining.onLogin(player) player:setOfflineTrainingSkill(SKILL_NONE) if offlineTime < 600 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must be logged out for more than 10 minutes to start offline training.") + player:sendTextMessage(MESSAGE_OFFLINE_TRAINING, "You must be logged out for more than 10 minutes to start offline training.") return true end @@ -50,15 +50,15 @@ function offlineTraining.onLogin(player) end text = string.format("%s.", text) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, text) + player:sendTextMessage(MESSAGE_OFFLINE_TRAINING, text) local vocation = player:getVocation() local promotion = vocation:getPromotion() local topVocation = not promotion and vocation or promotion - local updateSkills = false + if table.contains({ SKILL_CLUB, SKILL_SWORD, SKILL_AXE, SKILL_DISTANCE }, offlineTrainingSkill) then - local modifier = topVocation:getBaseAttackSpeed() / 1000 + local modifier = topVocation:getBaseAttackSpeed() / 1000 / configManager.getFloat(configKeys.RATE_OFFLINE_TRAINING_SPEED) updateSkills = player:addOfflineTrainingTries(offlineTrainingSkill, (trainingTime / modifier) / (offlineTrainingSkill == SKILL_DISTANCE and 4 or 2)) elseif offlineTrainingSkill == SKILL_MAGLEVEL then local gainTicks = topVocation:getManaGainTicks() * 2 diff --git a/data/scripts/eventcallbacks/README.md b/data/scripts/eventcallbacks/README.md index bdafcb41b33..601653574bd 100644 --- a/data/scripts/eventcallbacks/README.md +++ b/data/scripts/eventcallbacks/README.md @@ -47,6 +47,7 @@ Event callbacks are available for several categories of game entities, such as ` - `(void)` `playerOnCombat` - `(void)` `playerOnInventoryUpdate` - `(bool)` `playerOnRotateItem` +- `(void)` `playerOnWalk` - `(void)` `monsterOnDropLoot` - `(void)` `monsterPostDropLoot` - `(void)` `monsterOnSpawn` diff --git a/data/scripts/lib/register_achievements.lua b/data/scripts/lib/register_achievements.lua index 18a2d6e41ef..23d4bbd93ca 100644 --- a/data/scripts/lib/register_achievements.lua +++ b/data/scripts/lib/register_achievements.lua @@ -58,7 +58,7 @@ ACHIEVEMENTS = { [57] = { name = "Annihilator", grade = 2, points = 5, description = "You've daringly jumped into the infamous Annihilator and survived - taking home fame, glory and your reward." }, [58] = { name = "Master of the Nexus", grade = 2, points = 6, description = "You were able to fight your way through the countless hordes in the Demon Forge. Once more you proved that nothing is impossible." }, [59] = { name = "Talented Dancer", grade = 1, points = 1, description = "You're a lord or lady of the dance - and not afraid to use your skills to impress tribal gods. One step to the left, one jump to the right, twist and shout!" }, - [60] = { name = "Ministrel", grade = 1, points = 2, secret = true, description = "You can handle any music instrument you're given - and actually manage to produce a pleasant sound with it. You're a welcome guest and entertainer in most taverns." }, + [60] = { name = "Allow Cookies?", grade = 1, points = 2, description = "With a perfectly harmless smile, you tricked all the funny guys into eating your exploding cookies. Next time you pull this prank, consider wearing a Boy Scout outfit to make it even better." }, [61] = { name = "Ruthless", grade = 2, points = 5, description = "You've touched all thrones of the Ruthless Seven and absorbed some of their evil spirit. It may have changed you forever." }, [62] = { name = "Champion of Chazorai", grade = 2, points = 4, description = "You won the merciless 2 vs. 2 team tournament on the Isle of Strife and wiped out wave after wave of fearsome opponents. Death or victory - you certainly chose the latter." }, [63] = { name = "Wayfarer", grade = 1, points = 3, secret = true, description = "Dragon dreams are golden." }, @@ -193,7 +193,7 @@ ACHIEVEMENTS = { [192] = { name = "I Like it Fancy", grade = 1, points = 1, secret = true, description = "You definitely know how to bring out the best in your furniture and decoration pieces. Beautiful." }, [193] = { name = "Skin-Deep", grade = 2, points = 4, secret = true, description = "You always carry your obsidian knife with you and won't hesitate to use it. You've skinned countless little - and bigger - critters and yeah: they usually don't get any more beautiful on the inside. It's rather blood and gore and all that..." }, [194] = { name = "Ashes to Dust", grade = 2, points = 4, secret = true, description = "Staking vampires and demons has almost turned into your profession. You make sure to gather even the tiniest amount of evil dust particles. Beware of silicosis." }, - [195] = { name = "Silent Pet", grade = 1, points = 1, secret = true, description = "Awww. Your very own little goldfish friend - he's cute, he's shiny and he can't complain should you forget to feed him. He'll definitely brighten up your day!" }, + -- [195] = Unknown/non-existent [196] = { name = "Safely Stored Away", grade = 1, points = 2, secret = true, description = "Don't worry, no one will be able to take it from you. Probably." }, [197] = { name = "Something's in There", grade = 1, points = 1, secret = true, description = "By the gods! What was that?" }, [198] = { name = "Silent Pet", grade = 1, points = 1, secret = true, description = "Awww. Your very own little goldfish friend - he's cute, he's shiny and he can't complain should you forget to feed him. He'll definitely brighten up your day!" }, @@ -218,7 +218,7 @@ ACHIEVEMENTS = { [217] = { name = "Doctor! Doctor!", grade = 1, points = 2, secret = true, description = "Did someone call a doctor? You delivered 100 medicine bags to Ottokar of the Venore poor house in times of dire need, well done!" }, [218] = { name = "Beak Doctor", grade = 2, points = 4, description = "You significantly helped the afflicted citizens of Venore in times of dire need. Somehow you still feel close to the victims of the fever outbreak. Your clothes make you one of them, one poor soul amongst the countless afflicted." }, [219] = { name = "Mystic Fabric Magic", grade = 2, points = 4, description = "You vanquished the mad mage, you subdued the raging mage - no spellweaving self-exposer can stand in your way. Yet you are quite absorbed in magical studies yourself. This very fabric reflects this personal approval of the magic arts." }, - [220] = { name = "Breaking the Ice", grade = 1, points = 1, description = "You almost made friends with Shardhead... before he died. Poor guy only seems to attract violence with his frosty attitude." }, + -- [220] = Unknown/non-existent [221] = { name = "Arachnoise", grade = 1, points = 1, description = "You've shattered each of Bloodweb's eight frozen legs. As they say: break a leg, and then some more." }, [222] = { name = "Rootless Behaviour", grade = 1, points = 1, description = "You've descended into the swampy depths of Deathbine's lair and made quick work of it." }, [223] = { name = "Twisted Mutation", grade = 1, points = 1, description = "You've slain Esmeralda, the most hideous and aggressive of the mutated rats. No one will know that you almost lost a finger in the process." }, @@ -248,7 +248,7 @@ ACHIEVEMENTS = { [247] = { name = "Torn Treasures", grade = 1, points = 1, secret = true, description = "Wyda seems to be really, really bored. You also found out that she doesn't really need all those blood herbs that adventurers brought her. Still, she was nice enough to take one from you and gave you something quite cool in exchange." }, [248] = { name = "Loyal Subject", grade = 1, points = 1, secret = true, description = "You joined the Kingsday festivities and payed King Tibianus your respects. Now, off to party!" }, [249] = { name = "Desert Fisher", grade = 1, points = 1, description = "You managed to catch a fish in a surrounding that usually doesn't even carry water. Everything is subject to change, probably..." }, - [250] = { name = "Gem Cutter", grade = 1, points = 1, secret = true, description = 'You cut your first gem - and it bears your own name! Now that would be a nice gift! This does not make it a "true" Heart of the Sea, however...' }, + -- [250] = Unknown/non-existent [251] = { name = "Dog Sitter", grade = 1, points = 1, description = "You showed Noodles the way home. How long will it take this time until he's on the loose again? That dog must be really bored in the throne room by now." }, [252] = { name = "Ice Harvester", grade = 1, points = 1, description = "You witnessed the thawing of Svargrond and harvested rare seeds from some strange icy plants. They must be good for something." }, [253] = { name = "Preservationist", grade = 1, points = 1, secret = true, description = "You are a pretty smart thinker and managed to create everlasting flowers. They might become a big hit with all the people who aren't blessed with a green thumb or just forgetful." }, @@ -273,7 +273,7 @@ ACHIEVEMENTS = { [272] = { name = "Headache", grade = 1, points = 2, description = "Even in the deepest structures of the hive, you began to strike against the mighty foe. Your actions probably already gave the hive a headache." }, [273] = { name = "Confusion", grade = 1, points = 3, description = "The destruction you have caused by now can be felt throughout the whole hive. The mayhem that follows your step caused significant confusion in the consciousness of the hive." }, [274] = { name = "Manic", grade = 2, points = 4, description = "You have destroyed a significant amount of the hive's vital nerve centers and caused massive destruction to the hive's awareness. You are probably causing the hive horrible nightmares." }, - [275] = { name = "Suppressor", grade = 2, points = 4, description = "A war is won by those who have the best supply of troops. The hive's troops have been dealt a significant blow by your actions. You interrupted the hive's replenishment of troops lastingly and severely." }, + -- [275] = Unknown/non-existent [276] = { name = "Navigational Error", grade = 2, points = 5, secret = true, description = "You confronted the Navigator." }, [277] = { name = "Si, Ariki!", grade = 1, points = 1, description = "You've found the oriental traveller Yasir and were able to trade with him - even if you didn't really understand his language." }, [278] = { name = "Guardian Downfall", grade = 2, points = 4, description = "You ended the life of over three hundred Deepling Guards. Not quite the guardian of the Deeplings, are you?" }, @@ -282,7 +282,7 @@ ACHIEVEMENTS = { [281] = { name = "Gem Cutter", grade = 1, points = 1, secret = true, description = 'You cut your first gem - and it bears your own name! Now that would be a nice gift! This does not make it a "true" Heart of the Sea, however...' }, [282] = { name = "Spolium Profundis", grade = 2, points = 4, description = "You travelled the depths of this very world. You entered the blackness of the deep sea to conquer the realm of the Deeplings. May this suit remind you of the strange beauty below." }, [283] = { name = "Bane of the Hive", grade = 1, points = 2, description = "Countless fights and never tiring effort in the war against the hive grant you the experience to finish your outfit with the last remaining part. Your chitin outfit is a testament of your skills and dedication for the cause." }, - [284] = { name = "King of the Ring", grade = 1, points = 2, description = "Bretzecutioner's body just got slammed away. You are a true king of the ring!" }, + -- [284] = Unknown/non-existent [285] = { name = "Hive War Veteran", grade = 1, points = 1, description = "Your invaluable experience in fighting the hive allows you to add another piece of armor to your chitin outfit to prove your dedication for the cause." }, [286] = { name = "Hive Fighter", grade = 1, points = 1, description = "You have participated that much in the hive war, that you are able to create some makeshift armor from the remains of dead hive born that can be found in the major hive, to show of your skill." }, [287] = { name = "Howly Silence", grade = 1, points = 1, description = "You muted the everlasting howling of Hemming." }, @@ -294,7 +294,7 @@ ACHIEVEMENTS = { [293] = { name = "King of the Ring", grade = 1, points = 2, description = "Bretzecutioner's body just got slammed away. You are a true king of the ring!" }, [294] = { name = "Back from the Dead", grade = 1, points = 2, description = "You overcame the undead Zanakeph and sent him back into the darkness that spawned him." }, [295] = { name = "Pwned All Fur", grade = 3, points = 8, secret = true, description = "You've faced and defeated each of the mighty bosses the Paw and Fur society sent you out to kill. All by yourself. What a hunt!" }, - [296] = { name = "Diplomatic Immunity", grade = 2, points = 4, secret = true, description = "You killed the ambassador of the abyss that often that they might consider sending another one. Perhaps that will one day stop further intrusions." }, + -- [296] = Unknown/non-existent [297] = { name = "Bibby's Bloodbath", grade = 1, points = 1, secret = true, description = "You lend a helping hand in defeating invading Orcs by destroying their warcamp along with their leader. Bibby's personal bloodbath..." }, [298] = { name = "Nestling", grade = 1, points = 1, description = "You cleansed the land from an eight legged nuisance by defeating Mamma Longlegs three times. She won't be back soon... or will she?" }, [299] = { name = "Becoming a Bigfoot", grade = 1, points = 1, description = "You did it! You convinced the reclusive gnomes to accept you as one of their Bigfoots. Now you are ready to help them. With big feet big missions seen to come." }, @@ -321,14 +321,14 @@ ACHIEVEMENTS = { [320] = { name = "Funghitastic", grade = 1, points = 3, description = "Finally your dream to become a walking mushroom has come true ... No, wait a minute!" }, [321] = { name = "Crystal Clear", grade = 1, points = 3, description = "If the gnomes had told you that crystal armor is see-through you had probably changed your underwear in time." }, [322] = { name = "Gnomish Art Of War", grade = 1, points = 3, description = "You have unleashed your inner gnome and slain some of the most fearsome threats that gnomekind has ever faced. Now you can come and go to the warzones as it pleases you. The enemies of gnomekind will never be safe again." }, - [323] = { name = "Never Surrender", grade = 1, points = 3, description = "You did not show any signs of surrender to any sight of... you get the picture. Even a hundred of them did not pose a threat to you." }, + -- [323] = Unknown/non-existent [324] = { name = "True Dedication", grade = 2, points = 5, secret = true, description = "You conquered the demon challenge and prevailed... now show off your success in style!" }, [325] = { name = "Task Manager", grade = 1, points = 2, secret = true, description = "Helping a poor, stupid goblin to feed his starving children and wifes feels good ... if you'd only get rid of the strange feeling that you're missing something." }, [326] = { name = "Gravedigger", grade = 1, points = 3, description = "Assisting Omrabas' sick plan to resurrect made you dig your way through the blood-soaked halls of Drefia. Maybe better he failed!" }, [327] = { name = "Repenter", grade = 1, points = 1, secret = true, description = "You cleansed your soul in serving the Repenter enclave and purified thine self in completing all tasks in a single day of labour." }, [328] = { name = "Umbral Swordsman", grade = 2, points = 6, description = "You managed to transform, improve and sacrify your blade into a master state and have proven yourself worthy in a nightmarish world." }, - [329] = { name = "Umbral Berserker", grade = 2, points = 6, description = "You managed to transform, improve and sacrify your hammer into a master state and have proven yourself worthy in a nightmarish world." }, - [330] = { name = "Umbral Bladelord", grade = 2, points = 6, description = "You managed to transform, improve and sacrify your slayer into a master state and have proven yourself worthy in a nightmarish world." }, + -- [329] = Unknown/non-existent + -- [330] = Unknown/non-existent [331] = { name = "Cave Completionist", grade = 1, points = 2, description = "You have helped the gnomes of the spike in securing the caves and explored enough of the lightles depths to earn you a complete cave explorers outfit. Well done!" }, [332] = { name = "Umbral Bladelord", grade = 2, points = 6, description = "You managed to transform, improve and sacrify your slayer into a master state and have proven yourself worthy in a nightmarish world." }, [333] = { name = "Umbral Headsman", grade = 2, points = 6, description = "You managed to transform, improve and sacrify your axe into a master state and have proven yourself worthy in a nightmarish world." }, @@ -367,7 +367,7 @@ ACHIEVEMENTS = { [366] = { name = "Publicity", grade = 1, points = 1, description = "You are a man of the public. Or of good publicity at least. Through your efforts in advertising the airtight cloth, Zeronex might yet be redeemed - and Rathleton might yet see its first working Gloud Ship." }, [367] = { name = "Snake Charmer", grade = 1, points = 1, description = "By restoring the Everhungry Altar, you charmed the Fire-Feathered Sea Serpent back into its fitful sleep, twenty miles beneath the sea." }, [368] = { name = "Hoard of the Dragon", grade = 1, points = 1, secret = true, description = "Your adventurous way through countless dragon lairs earned you a pretty treasure - and surely the enmity of many a dragon." }, - [369] = { name = "Icy Glare", grade = 1, points = 1, description = "Here's looking at you, kid. This ancient creature seems to size you up with its brilliant eyes and barely tolerates you riding it. Maybe it thinks you're the defrosted snack, after all?" }, + -- [369] = Unknown/non-existent [370] = { name = "Little Ball of Wool", grade = 1, points = 1, description = "You found a lost sheep and thus a steady source of black wool. But careful: don't get entangled." }, [371] = { name = "Luminous Kitty", grade = 1, points = 3, description = "You made some efforts to bring a little more light into the world. And what a nice present you got in return!" }, [372] = { name = "The Right Tone", grade = 1, points = 1, description = "By setting the right tone you convinced a crystal wolf to accompany you. Remember it is made of crystal, though, so be careful in a banshee's presence." }, @@ -404,10 +404,10 @@ ACHIEVEMENTS = { [403] = { name = "Icy Glare", grade = 1, points = 1, description = "Here's looking at you, kid. This ancient creature seems to size you up with its brilliant eyes and barely tolerates you riding it. Maybe it thinks you're the defrosted snack, after all?" }, [404] = { name = "Cartography 101", grade = 1, points = 2, description = "You succeeded in finding and charting several previously unexplored landmarks and locations for the Adventurer's Guild, you probably never need to ask anyone for the way - do you?" }, [405] = { name = "Lost Palace Raider", grade = 1, points = 2, secret = true, description = "Lifting the secrets of a fabulous palace and defeating a beautiful demon princess was a thrilling experience indeed. This site's marvels nearly matched its terrors. Nearly." }, - [406] = { name = "The More the Merrier", grade = 0, points = 0, secret = true, description = "It's dangerous to go alone... Take ten friends." }, - [407] = { name = "Contender", grade = 1, points = 3, description = "You have fully unlocked 10 medium monsters in the cyclopedia." }, + [406] = { name = "The More the Merrier", grade = 1, points = 0, secret = true, description = "It's dangerous to go alone... Take ten friends." }, + -- [407] = Unknown/non-existent [408] = { name = "Rift Warrior", grade = 1, points = 3, description = "You went through hell. Seven times. You defeated the demons. Countless times. You put an end to Ferumbras claims to ascendancy. Once and for all." }, - [409] = { name = "Duked It Out", grade = 1, points = 1, description = "You defeated the Duke of the Depths and destroyed his lava pump!" }, + -- [409] = Unknown/non-existent [410] = { name = "Hat Hunter", grade = 2, points = 5, description = "You sucessfully fought against all odds to protect your world from an ascending god! – You weren't there for the hat only after all?" }, [411] = { name = "Ogre Chef", grade = 1, points = 1, description = "You didn't manage to become an ogre chief. But at least you are, beyond doubt, a worthy ogre chef." }, [412] = { name = "The Call of the Wild", grade = 1, points = 2, description = "You opposed man-eating ogres and clumsy clomps. You grappled with hungry chieftains, desperate goblins and angry spirits. So you truly overcame the wild vastness of Krailos." }, @@ -421,13 +421,13 @@ ACHIEVEMENTS = { [420] = { name = "Toothfairy Assistant", grade = 1, points = 1, description = "You assisted a very prominent fae and you fought tooth and nail to earn this title." }, [421] = { name = "Fairy Teasing", grade = 1, points = 1, secret = true, description = "Teasing fairies is fun. They leave behind such pretty clouds of glittering dust when chased. Just hope they don't get you back for it." }, [422] = { name = "Corruption Contained", grade = 2, points = 5, description = "You have managed to stall the worst incursion of corruption. Still this is just one battle won in an all out war for your world." }, - [423] = { name = "Daraman's Footsteps", grade = 1, points = 1, description = "You journeyed through Darashia and the sea of sand around it, while fighting the perils of the desert." }, - [424] = { name = "Dwarven Mines", grade = 1, points = 1, description = "Vast mines, an orc fortress and the magnificence of Kazordoon - you really know every corner of North-Eastern Mainland now." }, - [425] = { name = "Elven Woods", grade = 1, points = 1, description = "Tall trees, deep forests and and the beauty of Ab'Dendriel - you really know every corner of the elven lands now." }, - [426] = { name = "Glooth Punk", grade = 1, points = 1, description = "Glooth is the substance that powers a whole continent and all its weird inhabitants, workshops and factories. You travelled this strange smorgasbord of curiosities in its entirety - just in time for tea." }, - [427] = { name = "High and Dry", grade = 1, points = 2, description = "You asked Captain Charles to take a shortcut quite a few times. Now you are all too familiar with desert islands all over Tibia." }, - [428] = { name = "Jewel in the Swamp", grade = 1, points = 1, description = "Damp swamps, a dry desert and the opulence of Venore - you really know every corner of Eastern Mainland now." }, - [429] = { name = "King of the Jungle", grade = 1, points = 1, description = "You have searched Port Hope and the jungle that thoroughly, that you are up to adoption by a friendly ape family." }, + -- [423] = Unknown/non-existent + -- [424] = Unknown/non-existent + -- [425] = Unknown/non-existent + -- [426] = Unknown/non-existent + -- [427] = Unknown/non-existent + -- [428] = Unknown/non-existent + -- [429] = Unknown/non-existent [430] = { name = "Little Adventure", grade = 1, points = 1, description = "You have fully unlocked 10 easy monsters in the cyclopedia." }, [431] = { name = "Little Big Adventure", grade = 1, points = 2, secret = true, description = "You have fully unlocked 100 easy monsters in the cyclopedia." }, [432] = { name = "Contender", grade = 1, points = 3, description = "You have fully unlocked 10 medium monsters in the cyclopedia." }, @@ -470,7 +470,7 @@ ACHIEVEMENTS = { [469] = { name = "Battle Mage", grade = 2, points = 6, description = "Wielding dangerous knowledge as well as the sword is your expertise. You have proven yourself versatile in all manner of situations." }, [470] = { name = "Widely Travelled", grade = 3, points = 7, description = "As a true globetrotter you can now show your colours proudly with this extraordinary outfit." }, [471] = { name = "Running the Rift", grade = 1, points = 3, description = "You don't just have a permission to ride a rift runner, you literally went through hell and earned it!" }, - [472] = { name = "Nothing but Hot Air", grade = 1, points = 2, description = "You have tamed the ghostly mists to do your bidding. For now ..." }, + -- [472] = Unknown/non-existent [473] = { name = "Exalted Battle Mage", grade = 1, points = 2, description = "Not only did you master the battlefield as a mage, you were also induced to the most inner secrets of the art of magical warfare and prevailed." }, [474] = { name = "Areas of Effect", grade = 1, points = 3, secret = true, description = "Wisely contributing your resources to areas, you pushed creatures to maximum effect, allowing improved respawn for everyone! Well done!" }, [475] = { name = "Tied the Knot", grade = 1, points = 1, secret = true, description = "You figured out the right order of spells in the buried cathedral, how enchanting!" }, @@ -483,7 +483,7 @@ ACHIEVEMENTS = { [482] = { name = "Dream Catcher", grade = 1, points = 3, description = "You are the slayer of the ancient nightmare beast and prevented the nightmare to spread its madness." }, [483] = { name = "Champion of Summer", grade = 1, points = 2, secret = true, description = "You have vanquished numerous arena champions in the name of the Summer Court." }, [484] = { name = "Champion of Winter", grade = 1, points = 2, secret = true, description = "You have vanquished numerous arena champions in the name of the Winter Court." }, - [485] = { name = "Allow Cookies?", grade = 2, points = 6, description = "With a perfectly harmless smile, you tricked all the funny guys into eating your exploding cookies. Next time you pull this prank, consider wearing a Boy Scout outfit to make it even better." }, + -- [485] = Unknown/non-existent [486] = { name = "Bewitcher", grade = 2, points = 5, secret = true, description = "You literally put everything in that cauldron except lilac and gooseberries." }, [487] = { name = "Gryphon Rider", grade = 1, points = 3, description = "Unmasking spies, killing demons, discovering omens, solving puzzles and fighting ogres, manticores and feral sphinxes. - Nobody said it was easy to become a gryphon rider." }, [488] = { name = "Sculptor Apprentice", grade = 1, points = 2, secret = true, description = "Granted, you didn't carve those lifelike animal figurines yourself. But helping a medusa to find proper objects and even watching her using her petrifying gaze is almost as rewarding." }, @@ -496,6 +496,7 @@ ACHIEVEMENTS = { [495] = { name = "Inquisition's Arm", grade = 1, points = 2, description = "Your special garb, solely awarded to a dedicated Hand of the Inquisition, is now complete." }, [496] = { name = "Traditionalist", grade = 2, points = 6, description = "You proudly wear the traditional Orcsoberfest garb, same as it ever was and as it always will be." }, [497] = { name = "Do a Barrel Roll!", grade = 1, points = 3, description = "Riding a traditional beer barrel from the Orcsoberfest is a once-in-a-lifetime experience. Beer sold separately." }, + -- [498] = Unknown/non-existent [499] = { name = "Orcsoberfest Welcome", grade = 1, points = 3, secret = true, description = 'The Orcsoberfest is not only known for its traditional food, beer and customs but also fun events and excitement! You took part in all of that and can now truly say: "I survived!"' }, [500] = { name = "Prospectre", grade = 1, points = 1, secret = true, description = "You made acquaintance with the Thaian. A strange contemporary with a dark history. No man but a derivate of greed and obsession." }, [501] = { name = "Nothing but Hot Air", grade = 1, points = 3, description = "You have tamed the ghostly mists to do your bidding. For now ..." }, @@ -506,19 +507,24 @@ ACHIEVEMENTS = { [506] = { name = "Falconer", grade = 1, points = 2, description = "A true beastmaster learns the language of his animal companions. Now you as well can bolster your unique bond with nature and help preserve the balance of life as a proud falconer." }, [507] = { name = "Steppe Elegance", grade = 1, points = 3, description = "Champion of the wildlands, a swift strider among the creatures of the wild. The elegant nature of the gallop, this envoy of speed has mastered, indicates the precise understanding of its terrain and environment." }, [508] = { name = "Beyonder", grade = 1, points = 3, description = "Adventurous beyond death, you travelled the Netherworld. Although you had just the ghost of a chance you survived and even came back from the realm of the dead." }, + -- [509] = Unknown/non-existent [510] = { name = "Drama in Darama", grade = 1, points = 3, description = "If a pride of lions and a pack of hyaenas feud, it is not called a catfight but a ... whatsoever. For sure, it caused a lot of drama in the Darama Desert." }, [511] = { name = "Malefitz", grade = 1, points = 1, secret = true, description = "Made acquaintance with three brothers Fitz." }, [512] = { name = "Lionheart", grade = 1, points = 3, description = "You bested the maleficent duo Drume and Fugue and restored order to the besieged town of Bounac. You conquered the exotic stronghold of the Order of the Cobra and bested the undead knights of the Order of the Falcon. A true knight in heart and mind." }, + [513] = { name = "Soul Mender", grade = 4, points = 10, description = "Brought back to the realm of the living this magnificent creature will carry you through death and everything that lays beyond." }, [514] = { name = "You Got Horse Power", grade = 3, points = 8, description = "Brought back to the realm of the living this magnificent creature will carry you through death and everything that lays beyond." }, [515] = { name = "Unleash the Beast", grade = 3, points = 8, description = "You defeated the manifestation of Goshnar's evil traits by fighting your way through beasts you didn't even want to imagine. It transformed you and now you can also look the part." }, [516] = { name = "Well Roared, Lion!", grade = 1, points = 1, description = "You helped Domizian and thus proved yourself worthy to enter the werelion sanctum underneath Lion's Rock. You faced the mighty werelions there and one of the rare white lions even chose to accompany you." }, + -- [517] = Unknown/non-existent [518] = { name = "Honorary Rascoohan", grade = 1, points = 2, description = "When in Rascacoon, do as the Rascoohans do!" }, [519] = { name = "Release the Kraken", grade = 1, points = 3, description = "Riding around on this squishy companion gives you the feeling of flying through the air... uhm... swimming through the seven seas!" }, + -- [520] = Unknown/non-existent [521] = { name = "Pied Piper", grade = 1, points = 3, secret = true, description = "You are not exactly the Pied Piper of Hamelin but at least you managed to fend off a decent amount of pirats and helped to keep them out of the cities." }, [522] = { name = "Woodcarver", grade = 1, points = 3, secret = true, description = "You defeated Megasylvan Yselda in the wake of the sleeping carnisylvan menace deep under Bounac." }, [523] = { name = "Bounacean Chivalry", grade = 1, points = 2, secret = true, description = "Yselda forever stands watch against the carnisylvan menace. Ever awake, waiting in the dark, her heart longs to be united with her king once again. Deep empathy let a hero to bring her Kesar's tulip as a token of his love. That hero was you." }, [524] = { name = "Knowledge Raider", grade = 1, points = 3, description = "Your thirst for knowledge is insatiable. In the task of helping your gnomish friends, flawless execution is just the icing on the cake." }, [525] = { name = "Citizen of Issavi", grade = 1, points = 2, description = "It was not the first time that you helped the Sapphire Blade or the Midnight Flame with a difficult task. You may now wear the Kilmareshian robes as well as the tagralt blade and the eye-embroidered veil of the seers as a sign of Issavi's gratitude." }, + [526] = { name = "King's Council", grade = 1, points = 0, description = "Your continued efforts in keeping Bounac and the people of Kesar the Younger safe, earned you a permanent place at the royal court as an advisor to the king." }, [527] = { name = "Hot on the Trail", grade = 1, points = 3, description = "Since it is fireproof, this flaming creature feels right at home in raging infernos. But remember: just because it doesn't burn, you still do!" }, [528] = { name = "Shell We Take a Ride", grade = 1, points = 3, description = "Equipped with the shell of a tortoise and claws of a lobster this insect like companion will help you through every hardship." }, [529] = { name = "Phantastic!", grade = 1, points = 3, description = "This mighty pachyderm will march into battle as if just taking its Sunday stroll. The cost of friendship was only a few drome points!" }, @@ -526,7 +532,22 @@ ACHIEVEMENTS = { [531] = { name = "First Achievement", grade = 1, points = 1, secret = true, description = "Congratulations to your very first achievement! ... Well, not really. But imagine, it is. Because at this point during your journey into Tibia's past, achievements have been introduced." }, [532] = { name = "Sharp Dressed", grade = 1, points = 2, description = "Just everyone will be crazy about you if you are wearing this formal dress. They will come running, promise!" }, [533] = { name = "Engine Driver", grade = 1, points = 3, description = "This glooth-driven locomotive will bring you to any party in the blink of an eye." }, + [534] = { name = "Friendly Fire", grade = 1, points = 2, description = "You mastered the fire and tamed a supervulcano!" }, + [535] = { name = "Wedding Planner", grade = 1, points = 3, description = "Alas! What could be more beautiful and satisfying than bringing two loving hearts together? So romantic!" }, + [536] = { name = "Beaver Away", grade = 1, points = 1, description = "You really were as busy as a beaver in order to help the nagas. Enjoy some eager company!" }, + [537] = { name = "Snake Pit", grade = 1, points = 1, description = "Mysterious nagas, a vibrant jungle and a sinking island - you really know every corner of Marapur now." }, + [538] = { name = "Royalty of Hazard", grade = 1, points = 1, description = "For some it can't be hazardous enough." }, + [539] = { name = "Measuring the World", grade = 1, points = 2, description = "Step by step you discovered many of the secrets hidden in the world, thus gaining the right to wear the Discoverer outfit and hat. Made-to-measure for a brave traveller of the Tibian wilds." }, [540] = { name = "Ripp-Ripp Hooray!", grade = 1, points = 3, description = "Don't get carried away by your success. Get carried away by your Ripptor." }, + [541] = { name = "Warrior of the Iks", grade = 1, points = 2, description = "Combining unabating courage in combat and respect for the traditions and culture of the ancient Iks earned you the honours of true Aucar." }, + [542] = { name = "Mutagenius", grade = 1, points = 2, description = "You accomplished the impossible and created 16 mutagens of corresponding colours." }, + [543] = { name = "Strangest Thing", grade = 1, points = 3, description = "Only its rider can love this abomination of a mount." }, + [544] = { name = "Fully Decayed", grade = 1, points = 2, description = "You defeated the embodiments of decay and live to tell the tale, wear the rotting attire of the unfaltering defender proudly." }, + [545] = { name = "Like Fox and Mouse", grade = 1, points = 3, description = "Sly as a fox, quiet as a mouse - the perfect mount for a stealthy foray." }, + [546] = { name = "The Spirit of Purity", grade = 1, points = 3, description = "Withstanding both filth and desolation of the rotten darkness that corrupted the very core of this world, you embodied the weapon of purity and light to defy all that was tainted. This spirit will continue guide you on all future paths." }, + [547] = { name = "Museum Goer", grade = 1, points = 2, description = "You unveiled the secret plot of the Mitmah who stole away an entire civilisation for their own entertainment. Let the death of their outpost vanguard be an eternal lesson to them." }, + [548] = { name = "Mystic Predator", grade = 1, points = 3, description = "Proving your true worth to a mystic creature like the jaguar, king of the hunt, granted you not only respect but also its heart." }, + [549] = { name = "The Rule of Raccool", grade = 1, points = 2, description = "You almost feel as cool as a raccoon. Now, where's the trash?" }, } --[[ diff --git a/data/scripts/lib/register_migrations.lua b/data/scripts/lib/register_migrations.lua index 5a2734dfc51..26b9a7b1a94 100644 --- a/data/scripts/lib/register_migrations.lua +++ b/data/scripts/lib/register_migrations.lua @@ -45,7 +45,7 @@ function Migration:register() return end if not self:_validateName() then - error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: _. Example: 20231128213149_add_new_monsters") + logger.error("Invalid migration name: " .. self.name .. ". Migration names must be in the format: _. Example: 20231128213149_add_new_monsters") end table.insert(Migration.registry, self) diff --git a/data/scripts/runes/destroy_field_rune.lua b/data/scripts/runes/destroy_field_rune.lua index 024dbc1bcd7..8752be7eb51 100644 --- a/data/scripts/runes/destroy_field_rune.lua +++ b/data/scripts/runes/destroy_field_rune.lua @@ -4,6 +4,13 @@ local fields = { 105, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126, 2132 local rune = Spell("rune") function rune.onCastSpell(creature, variant, isHotkey) + local inPz = creature:getTile():hasFlag(TILESTATE_PROTECTIONZONE) + if inPz then + creature:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + creature:getPosition():sendMagicEffect(CONST_ME_POFF) + return false + end + local position = Variant.getPosition(variant) local tile = Tile(position) local field = tile and tile:getItemByType(ITEM_TYPE_MAGICFIELD) diff --git a/data/scripts/spells/conjuring/conjure_diamond_arrow.lua b/data/scripts/spells/conjuring/conjure_diamond_arrow.lua deleted file mode 100644 index 2ab4bbe0647..00000000000 --- a/data/scripts/spells/conjuring/conjure_diamond_arrow.lua +++ /dev/null @@ -1,21 +0,0 @@ -local spell = Spell("instant") - -function spell.onCastSpell(creature, variant) - return creature:conjureItem(0, 25757, 100, CONST_ME_MAGIC_BLUE) -end - -spell:group("support") -spell:id(192) -spell:name("Conjure Diamond Arrow") -spell:words("exevo gran con hur") -spell:cooldown(2 * 1000) -spell:groupCooldown(2 * 1000) -spell:level(150) -spell:mana(1000) -spell:soul(0) -spell:isPremium(true) -spell:isSelfTarget(true) -spell:isAggressive(false) -spell:vocation("paladin;true", "royal paladin;true") -spell:needLearn(false) -spell:register() diff --git a/data/scripts/spells/conjuring/conjure_spectral_bolt.lua b/data/scripts/spells/conjuring/conjure_spectral_bolt.lua deleted file mode 100644 index 336eb423139..00000000000 --- a/data/scripts/spells/conjuring/conjure_spectral_bolt.lua +++ /dev/null @@ -1,21 +0,0 @@ -local spell = Spell("instant") - -function spell.onCastSpell(creature, variant) - return creature:conjureItem(0, 35902, 100, CONST_ME_MAGIC_BLUE) -end - -spell:group("support") -spell:id(193) -spell:name("Conjure Spectral Bolt") -spell:words("exevo gran con vis") -spell:cooldown(2 * 1000) -spell:groupCooldown(2 * 1000) -spell:level(150) -spell:mana(1000) -spell:soul(0) -spell:isPremium(true) -spell:isSelfTarget(true) -spell:isAggressive(false) -spell:vocation("paladin;true", "royal paladin;true") -spell:needLearn(false) -spell:register() diff --git a/data/scripts/spells/house/kick.lua b/data/scripts/spells/house/kick.lua index b4b583c1007..265ac48f796 100644 --- a/data/scripts/spells/house/kick.lua +++ b/data/scripts/spells/house/kick.lua @@ -4,6 +4,7 @@ function spell.onCastSpell(player, variant) local targetPlayer = Player(variant:getString()) or player local guest = targetPlayer:getTile():getHouse() local owner = player:getTile():getHouse() + -- Owner kick yourself from house if targetPlayer == player then player:getPosition():sendMagicEffect(CONST_ME_POFF) @@ -11,6 +12,13 @@ function spell.onCastSpell(player, variant) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) return true end + + if not owner:canEditAccessList(GUEST_LIST, player) then + player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) + player:getPosition():sendMagicEffect(CONST_ME_POFF) + return false + end + if not owner or not guest or not guest:kickPlayer(player, targetPlayer) then player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) player:getPosition():sendMagicEffect(CONST_ME_POFF) diff --git a/data/scripts/spells/support/avatar_of_light.lua b/data/scripts/spells/support/avatar_of_light.lua index edc25c4f66e..a84fd3b8c8e 100644 --- a/data/scripts/spells/support/avatar_of_light.lua +++ b/data/scripts/spells/support/avatar_of_light.lua @@ -15,20 +15,9 @@ function spell.onCastSpell(creature, variant) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 60 - elseif grade >= 2 then - cooldown = 90 - elseif grade >= 1 then - cooldown = 120 - end local duration = 15000 condition:setTicks(duration) - local conditionCooldown = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 265) - conditionCooldown:setTicks((cooldown * 1000 * 60) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - -- creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) - creature:addCondition(conditionCooldown) + creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) creature:addCondition(condition) creature:avatarTimer((os.time() * 1000) + duration) creature:reloadData() @@ -43,7 +32,7 @@ spell:words("uteta res sac") spell:level(300) spell:mana(1500) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(2 * 60 * 60 * 1000) -- Default cooldown = 2 hours spell:groupCooldown(2 * 1000) spell:vocation("paladin;true", "royal paladin;true") spell:hasParams(true) diff --git a/data/scripts/spells/support/avatar_of_nature.lua b/data/scripts/spells/support/avatar_of_nature.lua index 0bd1473c3ca..fa32dd6b821 100644 --- a/data/scripts/spells/support/avatar_of_nature.lua +++ b/data/scripts/spells/support/avatar_of_nature.lua @@ -15,20 +15,9 @@ function spell.onCastSpell(creature, variant) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 60 - elseif grade >= 2 then - cooldown = 90 - elseif grade >= 1 then - cooldown = 120 - end local duration = 15000 condition:setTicks(duration) - local conditionCooldown = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 267) - conditionCooldown:setTicks((cooldown * 1000 * 60) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - -- creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) - creature:addCondition(conditionCooldown) + creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) creature:addCondition(condition) creature:avatarTimer((os.time() * 1000) + duration) creature:reloadData() @@ -43,7 +32,7 @@ spell:words("uteta res dru") spell:level(300) spell:mana(2200) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(2 * 60 * 60 * 1000) -- Default cooldown = 2 hours spell:groupCooldown(2 * 1000) spell:vocation("druid;true", "elder druid;true") spell:hasParams(true) diff --git a/data/scripts/spells/support/avatar_of_steel.lua b/data/scripts/spells/support/avatar_of_steel.lua index 8380a524c6d..da71ff14f96 100644 --- a/data/scripts/spells/support/avatar_of_steel.lua +++ b/data/scripts/spells/support/avatar_of_steel.lua @@ -15,20 +15,9 @@ function spell.onCastSpell(creature, variant) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 60 - elseif grade >= 2 then - cooldown = 90 - elseif grade >= 1 then - cooldown = 120 - end local duration = 15000 condition:setTicks(duration) - local conditionCooldown = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 264) - conditionCooldown:setTicks((cooldown * 1000 * 60) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - -- creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) - creature:addCondition(conditionCooldown) + creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) creature:addCondition(condition) creature:avatarTimer((os.time() * 1000) + duration) creature:reloadData() @@ -43,7 +32,7 @@ spell:words("uteta res eq") spell:level(300) spell:mana(800) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(2 * 60 * 60 * 1000) -- Default cooldown = 2 hours spell:groupCooldown(2 * 1000) spell:vocation("knight;true", "elite knight;true") spell:hasParams(true) diff --git a/data/scripts/spells/support/avatar_of_storm.lua b/data/scripts/spells/support/avatar_of_storm.lua index 79bb4e3b37e..ad644de01ba 100644 --- a/data/scripts/spells/support/avatar_of_storm.lua +++ b/data/scripts/spells/support/avatar_of_storm.lua @@ -15,20 +15,9 @@ function spell.onCastSpell(creature, variant) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 60 - elseif grade >= 2 then - cooldown = 90 - elseif grade >= 1 then - cooldown = 120 - end local duration = 15000 condition:setTicks(duration) - local conditionCooldown = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 266) - conditionCooldown:setTicks((cooldown * 1000 * 60) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - -- creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) - creature:addCondition(conditionCooldown) + creature:getPosition():sendMagicEffect(CONST_ME_AVATAR_APPEAR) creature:addCondition(condition) creature:avatarTimer((os.time() * 1000) + duration) creature:reloadData() @@ -43,7 +32,7 @@ spell:words("uteta res ven") spell:level(300) spell:mana(2200) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(2 * 60 * 60 * 1000) -- Default cooldown = 2 hours spell:groupCooldown(2 * 1000) spell:vocation("sorcerer;true", "master sorcerer;true") spell:hasParams(true) diff --git a/data/scripts/talkactions/gm/afk.lua b/data/scripts/talkactions/gm/afk.lua new file mode 100644 index 00000000000..6167a2b6068 --- /dev/null +++ b/data/scripts/talkactions/gm/afk.lua @@ -0,0 +1,94 @@ +local afk = TalkAction("/afk") + +playersAFKs = {} + +local function checkIsAFK(id) + for index, item in pairs(playersAFKs) do + if id == item.id then + return { afk = true, index = index } + end + end + return { afk = false } +end + +local function showAfkMessage(playerPosition) + local spectators = Game.getSpectators(playerPosition, false, true, 8, 8, 8, 8) + if #spectators > 0 then + for _, spectator in ipairs(spectators) do + spectator:say("AFK !", TALKTYPE_MONSTER_SAY, false, spectator, playerPosition) + end + end +end + +function afk.onSay(player, words, param) + if param == "" then + player:sendCancelMessage("You need to specify on/off param.") + return true + end + + local id, playerPosition = player:getId(), player:getPosition() + local isAfk = checkIsAFK(id) + if param == "on" then + if isAfk.afk then + player:sendCancelMessage("You are already AFK!") + return true + end + + table.insert(playersAFKs, { id = id, position = playerPosition }) + if player:isInGhostMode() then + player:setGhostMode(false) + end + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are now AFK!") + playerPosition:sendMagicEffect(CONST_ME_REDSMOKE) + showAfkMessage(playerPosition) + elseif param == "off" then + if isAfk.afk then + table.remove(playersAFKs, isAfk.index) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer AFK!") + playerPosition:sendMagicEffect(CONST_ME_REDSMOKE) + end + end + + return true +end + +afk:separator(" ") +afk:groupType("gamemaster") +afk:register() + +------------------ AFK Effect Message ------------------ +local afkEffect = GlobalEvent("GodAfkEffect") +function afkEffect.onThink(interval) + for _, player in ipairs(playersAFKs) do + showAfkMessage(player.position) + end + return true +end + +afkEffect:interval(5000) +afkEffect:register() + +------------------ Stop AFK Message when moves ------------------ +local callback = EventCallback() +function callback.playerOnWalk(player, creature, creaturePos, toPos) + local isAfk = checkIsAFK(player:getId()) + if isAfk.afk then + table.remove(playersAFKs, isAfk.index) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are no longer AFK!") + end + return true +end + +callback:register() + +------------------ Player Logout ------------------ +local godAfkLogout = CreatureEvent("GodAfkLogout") +function godAfkLogout.onLogout(player) + local isAfk = checkIsAFK(player:getId()) + if isAfk.afk then + table.remove(playersAFKs, isAfk.index) + end + return true +end + +godAfkLogout:register() diff --git a/data/scripts/talkactions/god/add_skill.lua b/data/scripts/talkactions/god/add_skill.lua index f1c6244fba6..20644582325 100644 --- a/data/scripts/talkactions/god/add_skill.lua +++ b/data/scripts/talkactions/god/add_skill.lua @@ -44,8 +44,7 @@ function addSkill.onSay(player, words, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() local count = 1 if split[3] then diff --git a/data/scripts/talkactions/god/charms.lua b/data/scripts/talkactions/god/charms.lua index 14dde0a58d7..f06c17ac7e7 100644 --- a/data/scripts/talkactions/god/charms.lua +++ b/data/scripts/talkactions/god/charms.lua @@ -19,8 +19,8 @@ function addCharm.onSay(player, words, param) player:sendCancelMessage("A player with that name is not online.") return true end - --trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + + split[2] = split[2]:trimSpace() player:sendCancelMessage("Added " .. split[2] .. " charm points to character '" .. target:getName() .. "'.") target:sendCancelMessage("Received " .. split[2] .. " charm points!") @@ -133,8 +133,8 @@ function setBestiary.onSay(player, words, param) return true end - split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left - split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left + split[2] = split[2]:trimSpace() + split[3] = split[3]:trimSpace() local monsterName = split[2] local mType = MonsterType(monsterName) diff --git a/data/scripts/talkactions/god/create_monster.lua b/data/scripts/talkactions/god/create_monster.lua index 924a0d0906d..ce5869a2eee 100644 --- a/data/scripts/talkactions/god/create_monster.lua +++ b/data/scripts/talkactions/god/create_monster.lua @@ -73,20 +73,20 @@ function createMonster.onSay(player, words, param) local monsterName = split[1] local monsterCount = 0 if split[2] then - split[2] = split[2]:gsub("^%s*(.-)$", "%1") --Trim left + split[2] = split[2]:trimSpace() monsterCount = tonumber(split[2]) end local monsterForge = nil if split[3] then - split[3] = split[3]:gsub("^%s*(.-)$", "%1") --Trim left + split[3] = split[3]:trimSpace() monsterForge = split[3] end if monsterCount > 1 then local spawnRadius = 5 if split[4] then - split[4] = split[4]:gsub("^%s*(.-)$", "%1") --Trim left + split[4] = split[4]:trimSpace() spawnRadius = split[4] print(spawnRadius) end diff --git a/data/scripts/talkactions/god/manage_badge.lua b/data/scripts/talkactions/god/manage_badge.lua new file mode 100644 index 00000000000..310cce247b0 --- /dev/null +++ b/data/scripts/talkactions/god/manage_badge.lua @@ -0,0 +1,35 @@ +local addBadge = TalkAction("/addbadge") + +function addBadge.onSay(player, words, param) + -- create log + logCommand(player, words, param) + + if param == "" then + player:sendCancelMessage("Command param required.") + return true + end + + local split = param:split(",") + if not split[2] then + player:sendCancelMessage("Insufficient parameters. Usage: /addbadge playerName, badgeID") + return true + end + + local target = Player(split[1]) + if not target then + player:sendCancelMessage("A player with that name is not online.") + return true + end + + split[2] = split[2]:trimSpace() + local id = tonumber(split[2]) + if target:addBadge(id) then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You added a badge with ID "%i" to player "%s".', id, target:getName())) + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s added a badge to you.", player:getName())) + end + return true +end + +addBadge:separator(" ") +addBadge:groupType("god") +addBadge:register() diff --git a/data/scripts/talkactions/god/manage_storage.lua b/data/scripts/talkactions/god/manage_storage.lua index 929ef7b4417..e1973ebde00 100644 --- a/data/scripts/talkactions/god/manage_storage.lua +++ b/data/scripts/talkactions/god/manage_storage.lua @@ -18,8 +18,7 @@ function Player.getStorageValueTalkaction(self, param) return true end - -- Trim left - split[2] = split[2]:gsub("^%s*(.-)$", "%1") + split[2] = split[2]:trimSpace() -- Try to convert the second parameter to a number. If it's not a number, treat it as a storage name local storageKey = tonumber(split[2]) diff --git a/data/scripts/talkactions/god/manage_title.lua b/data/scripts/talkactions/god/manage_title.lua new file mode 100644 index 00000000000..d99adbe5dc0 --- /dev/null +++ b/data/scripts/talkactions/god/manage_title.lua @@ -0,0 +1,70 @@ +local addTitle = TalkAction("/addtitle") + +function addTitle.onSay(player, words, param) + -- create log + logCommand(player, words, param) + + if param == "" then + player:sendCancelMessage("Command param required.") + return true + end + + local split = param:split(",") + if not split[2] then + player:sendCancelMessage("Insufficient parameters. Usage: /addtitle playerName, badgeID") + return true + end + + local target = Player(split[1]) + if not target then + player:sendCancelMessage("A player with that name is not online.") + return true + end + + split[2] = split[2]:trimSpace() + local id = tonumber(split[2]) + if target:addTitle(id) then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format('You added a title with ID "%i" to player "%s".', id, target:getName())) + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s added a title to you.", player:getName())) + end + + return true +end + +addTitle:separator(" ") +addTitle:groupType("god") +addTitle:register() + +----------------------------------------- +local setTitle = TalkAction("/settitle") + +function setTitle.onSay(player, words, param) + -- create log + logCommand(player, words, param) + + if param == "" then + player:sendCancelMessage("Command param required.") + return true + end + + local split = param:split(",") + if not split[2] then + player:sendCancelMessage("Insufficient parameters. Usage: /settitle playerName, badgeID") + return true + end + + local target = Player(split[1]) + if not target then + player:sendCancelMessage("A player with that name is not online.") + return true + end + + split[2] = split[2]:trimSpace() + local id = tonumber(split[2]) + target:setCurrentTitle(id) + return true +end + +setTitle:separator(" ") +setTitle:groupType("god") +setTitle:register() diff --git a/data/scripts/talkactions/god/vip_manager.lua b/data/scripts/talkactions/god/manage_vip.lua similarity index 100% rename from data/scripts/talkactions/god/vip_manager.lua rename to data/scripts/talkactions/god/manage_vip.lua diff --git a/data/scripts/talkactions/god/reload.lua b/data/scripts/talkactions/god/reload.lua index 5bf72868320..20b9431dbba 100644 --- a/data/scripts/talkactions/god/reload.lua +++ b/data/scripts/talkactions/god/reload.lua @@ -30,6 +30,7 @@ local reloadTypes = { ["scripts"] = RELOAD_TYPE_SCRIPTS, ["stage"] = RELOAD_TYPE_CORE, ["stages"] = RELOAD_TYPE_CORE, + ["vocations"] = RELOAD_TYPE_VOCATIONS, } local reload = TalkAction("/reload") diff --git a/schema.sql b/schema.sql index 58e6ea216ce..7bbf6c86ac5 100644 --- a/schema.sql +++ b/schema.sql @@ -7,7 +7,7 @@ CREATE TABLE IF NOT EXISTS `server_config` ( CONSTRAINT `server_config_pk` PRIMARY KEY (`config`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '44'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0'); +INSERT INTO `server_config` (`config`, `value`) VALUES ('db_version', '46'), ('motd_hash', ''), ('motd_num', '0'), ('players_record', '0'); -- Table structure `accounts` CREATE TABLE IF NOT EXISTS `accounts` ( @@ -127,8 +127,8 @@ CREATE TABLE IF NOT EXISTS `players` ( `skill_lifeleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `skill_manaleech_chance` bigint(20) UNSIGNED NOT NULL DEFAULT '0', `skill_manaleech_amount` bigint(20) UNSIGNED NOT NULL DEFAULT '0', - `manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0', - `max_manashield` SMALLINT UNSIGNED NOT NULL DEFAULT '0', + `manashield` INT UNSIGNED NOT NULL DEFAULT '0', + `max_manashield` INT UNSIGNED NOT NULL DEFAULT '0', `xpboost_stamina` smallint(5) UNSIGNED DEFAULT NULL, `xpboost_value` tinyint(4) UNSIGNED DEFAULT NULL, `marriage_status` bigint(20) UNSIGNED NOT NULL DEFAULT '0', @@ -215,6 +215,44 @@ CREATE TABLE IF NOT EXISTS `account_viplist` ( ON DELETE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +-- Table structure `account_vipgroup` +CREATE TABLE IF NOT EXISTS `account_vipgroups` ( + `id` tinyint(3) UNSIGNED NOT NULL, + `account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose vip group entry it is', + `name` varchar(128) NOT NULL, + `customizable` BOOLEAN NOT NULL DEFAULT '1', + CONSTRAINT `account_vipgroups_pk` PRIMARY KEY (`id`, `account_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +-- +-- Trigger +-- +DELIMITER // +CREATE TRIGGER `oncreate_accounts` AFTER INSERT ON `accounts` FOR EACH ROW BEGIN + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (1, NEW.`id`, 'Enemies', 0); + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (2, NEW.`id`, 'Friends', 0); + INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES (3, NEW.`id`, 'Trading Partner', 0); +END +// +DELIMITER ; + +-- Table structure `account_vipgrouplist` +CREATE TABLE IF NOT EXISTS `account_vipgrouplist` ( + `account_id` int(11) UNSIGNED NOT NULL COMMENT 'id of account whose viplist entry it is', + `player_id` int(11) NOT NULL COMMENT 'id of target player of viplist entry', + `vipgroup_id` tinyint(3) UNSIGNED NOT NULL COMMENT 'id of vip group that player belongs', + INDEX `account_id` (`account_id`), + INDEX `player_id` (`player_id`), + INDEX `vipgroup_id` (`vipgroup_id`), + CONSTRAINT `account_vipgrouplist_unique` UNIQUE (`account_id`, `player_id`, `vipgroup_id`), + CONSTRAINT `account_vipgrouplist_player_fk` + FOREIGN KEY (`player_id`) REFERENCES `players` (`id`) + ON DELETE CASCADE, + CONSTRAINT `account_vipgrouplist_vipgroup_fk` + FOREIGN KEY (`vipgroup_id`, `account_id`) REFERENCES `account_vipgroups` (`id`, `account_id`) + ON DELETE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + -- Table structure `boosted_boss` CREATE TABLE IF NOT EXISTS `boosted_boss` ( `boostname` TEXT, @@ -372,9 +410,9 @@ CREATE TABLE IF NOT EXISTS `guild_ranks` ( -- DELIMITER // CREATE TRIGGER `oncreate_guilds` AFTER INSERT ON `guilds` FOR EACH ROW BEGIN - INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('The Leader', 3, NEW.`id`); - INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Vice-Leader', 2, NEW.`id`); - INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Member', 1, NEW.`id`); + INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('The Leader', 3, NEW.`id`); + INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Vice-Leader', 2, NEW.`id`); + INSERT INTO `guild_ranks` (`name`, `level`, `guild_id`) VALUES ('Member', 1, NEW.`id`); END // DELIMITER ; @@ -428,9 +466,8 @@ CREATE TABLE IF NOT EXISTS `houses` ( -- trigger -- DELIMITER // -CREATE TRIGGER `ondelete_players` BEFORE DELETE ON `players` - FOR EACH ROW BEGIN - UPDATE `houses` SET `owner` = 0 WHERE `owner` = OLD.`id`; +CREATE TRIGGER `ondelete_players` BEFORE DELETE ON `players` FOR EACH ROW BEGIN + UPDATE `houses` SET `owner` = 0 WHERE `owner` = OLD.`id`; END // DELIMITER ; @@ -815,3 +852,9 @@ INSERT INTO `players` (4, 'Paladin Sample', 1, 1, 8, 3, 185, 185, 4200, 113, 115, 95, 39, 129, 0, 90, 90, 0, 8, '', 470, 1, 10, 0, 10, 0, 10, 0, 10, 0), (5, 'Knight Sample', 1, 1, 8, 4, 185, 185, 4200, 113, 115, 95, 39, 129, 0, 90, 90, 0, 8, '', 470, 1, 10, 0, 10, 0, 10, 0, 10, 0), (6, 'GOD', 6, 1, 2, 0, 155, 155, 100, 113, 115, 95, 39, 75, 0, 60, 60, 0, 8, '', 410, 1, 10, 0, 10, 0, 10, 0, 10, 0); + +-- Create vip groups for GOD account +INSERT INTO `account_vipgroups` (`id`, `name`, `account_id`. `customizable`) VALUES +(1, 'Friends', 1, 0), +(2, 'Enemies', 1, 0), +(3, 'Trading Partners', 1, 0); diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 0961bc93fde..17a36ff3d23 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -327,7 +327,7 @@ void CanaryServer::loadModules() { // If "USE_ANY_DATAPACK_FOLDER" is set to true then you can choose any datapack folder for your server const auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER, __FUNCTION__); auto datapackName = g_configManager().getString(DATA_DIRECTORY, __FUNCTION__); - if (!useAnyDatapack && (datapackName != "data-canary" && datapackName != "data-otservbr-global" || datapackName != "data-otservbr-global" && datapackName != "data-canary")) { + if (!useAnyDatapack && datapackName != "data-canary" && datapackName != "data-otservbr-global") { throw FailedToInitializeCanary(fmt::format( "The datapack folder name '{}' is wrong, please select valid " "datapack name 'data-canary' or 'data-otservbr-global " @@ -376,6 +376,7 @@ void CanaryServer::loadModules() { g_game().loadBoostedCreature(); g_ioBosstiary().loadBoostedBoss(); g_ioprey().initializeTaskHuntOptions(); + g_game().logCyclopediaStats(); } void CanaryServer::modulesLoadHelper(bool loaded, std::string moduleName) { @@ -389,4 +390,5 @@ void CanaryServer::shutdown() { g_dispatcher().shutdown(); g_metrics().shutdown(); inject().shutdown(); + std::exit(0); } diff --git a/src/canary_server.hpp b/src/canary_server.hpp index bb22232b8e4..57c931cd133 100644 --- a/src/canary_server.hpp +++ b/src/canary_server.hpp @@ -46,8 +46,8 @@ class CanaryServer { FAILED }; - RSA &rsa; Logger &logger; + RSA &rsa; ServiceManager &serviceManager; std::atomic loaderStatus = LoaderStatus::LOADING; diff --git a/src/config/config_enums.hpp b/src/config/config_enums.hpp index b9b857f435c..22043f42525 100644 --- a/src/config/config_enums.hpp +++ b/src/config/config_enums.hpp @@ -17,6 +17,9 @@ enum ConfigKey_t : uint16_t { ALLOW_BLOCK_SPAWN, ALLOW_CHANGEOUTFIT, ALLOW_RELOAD, + AUGMENT_INCREASED_DAMAGE_PERCENT, + AUGMENT_POWERFUL_IMPACT_PERCENT, + AUGMENT_STRONG_IMPACT_PERCENT, AUTH_TYPE, AUTOBANK, AUTOLOOT, @@ -36,10 +39,10 @@ enum ConfigKey_t : uint16_t { CLASSIC_ATTACK_SPEED, CLEAN_PROTECTION_ZONES, COMBAT_CHAIN_DELAY, - COMBAT_CHAIN_TARGETS, COMBAT_CHAIN_SKILL_FORMULA_AXE, COMBAT_CHAIN_SKILL_FORMULA_CLUB, COMBAT_CHAIN_SKILL_FORMULA_SWORD, + COMBAT_CHAIN_TARGETS, COMPRESSION_LEVEL, CONVERT_UNSAFE_SCRIPTS, CORE_DIRECTORY, @@ -136,6 +139,7 @@ enum ConfigKey_t : uint16_t { MAP_DOWNLOAD_URL, MAP_NAME, MARKET_OFFER_DURATION, + MARKET_REFRESH_PRICES, MARKET_PREMIUM, MAX_ALLOWED_ON_A_DUMMY, MAX_CONTAINER_ITEM, @@ -155,6 +159,7 @@ enum ConfigKey_t : uint16_t { METRICS_PROMETHEUS_ADDRESS, MIN_DELAY_BETWEEN_CONDITIONS, MIN_ELEMENTAL_RESISTANCE, + MIN_TOWN_ID_TO_BANK_TRANSFER, MOMENTUM_CHANCE_FORMULA_A, MOMENTUM_CHANCE_FORMULA_B, MOMENTUM_CHANCE_FORMULA_C, @@ -178,6 +183,7 @@ enum ConfigKey_t : uint16_t { OWNER_NAME, PARALLELISM, PARTY_AUTO_SHARE_EXPERIENCE, + PARTY_SHARE_RANGE_MULTIPLIER, PARTY_LIST_MAX_DISTANCE, PARTY_SHARE_LOOT_BOOSTS_DIMINISHING_FACTOR, PARTY_SHARE_LOOT_BOOSTS, @@ -322,5 +328,5 @@ enum ConfigKey_t : uint16_t { WHEEL_POINTS_PER_LEVEL, WHITE_SKULL_TIME, WORLD_TYPE, - XP_DISPLAY_MODE, + XP_DISPLAY_MODE }; diff --git a/src/config/configmanager.cpp b/src/config/configmanager.cpp index c1702672e71..e1345bbac4b 100644 --- a/src/config/configmanager.cpp +++ b/src/config/configmanager.cpp @@ -11,7 +11,6 @@ #include "config/configmanager.hpp" #include "lib/di/container.hpp" -#include "declarations.hpp" #include "game/game.hpp" #include "server/network/webhook/webhook.hpp" @@ -62,6 +61,7 @@ bool ConfigManager::load() { loadIntConfig(L, GAME_PORT, "gameProtocolPort", 7172); loadIntConfig(L, LOGIN_PORT, "loginProtocolPort", 7171); loadIntConfig(L, MARKET_OFFER_DURATION, "marketOfferDuration", 30 * 24 * 60 * 60); + loadIntConfig(L, MARKET_REFRESH_PRICES, "marketRefreshPricesInterval", 30); loadIntConfig(L, PREMIUM_DEPOT_LIMIT, "premiumDepotLimit", 8000); loadIntConfig(L, SQL_PORT, "mysqlPort", 3306); loadIntConfig(L, STASH_ITEMS, "stashItemCount", 5000); @@ -166,6 +166,9 @@ bool ConfigManager::load() { loadBoolConfig(L, XP_DISPLAY_MODE, "experienceDisplayRates", true); loadFloatConfig(L, BESTIARY_RATE_CHARM_SHOP_PRICE, "bestiaryRateCharmShopPrice", 1.0); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_CLUB, "combatChainSkillFormulaClub", 0.7); + loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_SWORD, "combatChainSkillFormulaSword", 1.1); loadFloatConfig(L, FORGE_AMOUNT_MULTIPLIER, "forgeAmountMultiplier", 3.0); loadFloatConfig(L, HAZARD_EXP_BONUS_MULTIPLIER, "hazardExpBonusMultiplier", 2.0); loadFloatConfig(L, LOYALTY_BONUS_PERCENTAGE_MULTIPLIER, "loyaltyBonusPercentageMultiplier", 1.0); @@ -218,9 +221,6 @@ bool ConfigManager::load() { loadIntConfig(L, CHECK_EXPIRED_MARKET_OFFERS_EACH_MINUTES, "checkExpiredMarketOffersEachMinutes", 60); loadIntConfig(L, COMBAT_CHAIN_DELAY, "combatChainDelay", 50); loadIntConfig(L, COMBAT_CHAIN_TARGETS, "combatChainTargets", 5); - loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_AXE, "combatChainSkillFormulaAxe", 0.9); - loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_CLUB, "combatChainSkillFormulaClub", 0.7); - loadFloatConfig(L, COMBAT_CHAIN_SKILL_FORMULA_SWORD, "combatChainSkillFormulaSword", 1.1); loadIntConfig(L, COMPRESSION_LEVEL, "packetCompressionLevel", 6); loadIntConfig(L, CRITICALCHANCE, "criticalChance", 10); loadIntConfig(L, DAY_KILLS_TO_RED, "dayKillsToRedSkull", 3); @@ -287,6 +287,7 @@ bool ConfigManager::load() { loadIntConfig(L, METRICS_OSTREAM_INTERVAL, "metricsOstreamInterval", 1000); loadIntConfig(L, MIN_DELAY_BETWEEN_CONDITIONS, "minDelayBetweenConditions", 0); loadIntConfig(L, MIN_ELEMENTAL_RESISTANCE, "minElementalResistance", -200); + loadIntConfig(L, MIN_TOWN_ID_TO_BANK_TRANSFER, "minTownIdToBankTransfer", 3); loadIntConfig(L, MONTH_KILLS_TO_RED, "monthKillsToRedSkull", 10); loadIntConfig(L, MULTIPLIER_ATTACKONFIST, "multiplierSpeedOnFist", 5); loadIntConfig(L, ORANGE_SKULL_DURATION, "orangeSkullDuration", 7); @@ -317,6 +318,7 @@ bool ConfigManager::load() { loadIntConfig(L, STAMINA_PZ_GAIN, "staminaPzGain", 1); loadIntConfig(L, STAMINA_TRAINER_DELAY, "staminaTrainerDelay", 5); loadIntConfig(L, STAMINA_TRAINER_GAIN, "staminaTrainerGain", 1); + loadFloatConfig(L, PARTY_SHARE_RANGE_MULTIPLIER, "partyShareRangeMultiplier", 1.5f); loadIntConfig(L, START_STREAK_LEVEL, "startStreakLevel", 0); loadIntConfig(L, STATUSQUERY_TIMEOUT, "statusTimeout", 5000); loadIntConfig(L, STORE_COIN_PACKET, "coinPacketSize", 25); @@ -343,6 +345,9 @@ bool ConfigManager::load() { loadIntConfig(L, WHEEL_ATELIER_ROTATE_REGULAR_COST, "wheelAtelierRotateRegularCost", 250000); loadIntConfig(L, WHEEL_POINTS_PER_LEVEL, "wheelPointsPerLevel", 1); loadIntConfig(L, WHITE_SKULL_TIME, "whiteSkullTime", 15 * 60 * 1000); + loadIntConfig(L, AUGMENT_INCREASED_DAMAGE_PERCENT, "augmentIncreasedDamagePercent", 5); + loadIntConfig(L, AUGMENT_POWERFUL_IMPACT_PERCENT, "augmentPowerfulImpactPercent", 10); + loadIntConfig(L, AUGMENT_STRONG_IMPACT_PERCENT, "augmentStrongImpactPercent", 7); loadStringConfig(L, CORE_DIRECTORY, "coreDirectory", "data"); loadStringConfig(L, DATA_DIRECTORY, "dataPackDirectory", "data-otservbr-global"); diff --git a/src/creatures/CMakeLists.txt b/src/creatures/CMakeLists.txt index f3dedf3a8f3..af6ba129eac 100644 --- a/src/creatures/CMakeLists.txt +++ b/src/creatures/CMakeLists.txt @@ -22,7 +22,10 @@ target_sources(${PROJECT_NAME}_lib PRIVATE players/storages/storages.cpp players/player.cpp players/achievement/player_achievement.cpp + players/cyclopedia/player_badge.cpp + players/cyclopedia/player_title.cpp players/wheel/player_wheel.cpp players/wheel/wheel_gems.cpp players/vocations/vocation.cpp + players/vip/player_vip.cpp ) diff --git a/src/creatures/appearance/mounts/mounts.cpp b/src/creatures/appearance/mounts/mounts.cpp index dff0f02a451..7051d04ddb8 100644 --- a/src/creatures/appearance/mounts/mounts.cpp +++ b/src/creatures/appearance/mounts/mounts.cpp @@ -35,7 +35,7 @@ bool Mounts::loadFromXml() { continue; } - mounts.emplace_back(std::make_shared( + mounts.emplace(std::make_shared( static_cast(pugi::cast(mountNode.attribute("id").value())), lookType, mountNode.attribute("name").as_string(), @@ -44,12 +44,11 @@ bool Mounts::loadFromXml() { mountNode.attribute("type").as_string() )); } - mounts.shrink_to_fit(); return true; } std::shared_ptr Mounts::getMountByID(uint8_t id) { - auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr mount) { + auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr &mount) { return mount->id == id; // Note the use of -> operator to access the members of the Mount object }); @@ -58,7 +57,7 @@ std::shared_ptr Mounts::getMountByID(uint8_t id) { std::shared_ptr Mounts::getMountByName(const std::string &name) { auto mountName = name.c_str(); - auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr mount) { + auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr &mount) { return strcasecmp(mountName, mount->name.c_str()) == 0; }); @@ -66,7 +65,7 @@ std::shared_ptr Mounts::getMountByName(const std::string &name) { } std::shared_ptr Mounts::getMountByClientID(uint16_t clientId) { - auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr mount) { + auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr &mount) { return mount->clientId == clientId; // Note the use of -> operator to access the members of the Mount object }); diff --git a/src/creatures/appearance/mounts/mounts.hpp b/src/creatures/appearance/mounts/mounts.hpp index 05bd330a66b..ca4f969842a 100644 --- a/src/creatures/appearance/mounts/mounts.hpp +++ b/src/creatures/appearance/mounts/mounts.hpp @@ -11,8 +11,8 @@ struct Mount { Mount(uint8_t initId, uint16_t initClientId, std::string initName, int32_t initSpeed, bool initPremium, std::string initType) : - name(initName), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium), - type(initType) { } + name(std::move(initName)), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium), + type(std::move(initType)) { } std::string name; int32_t speed; @@ -30,10 +30,10 @@ class Mounts { std::shared_ptr getMountByName(const std::string &name); std::shared_ptr getMountByClientID(uint16_t clientId); - [[nodiscard]] const std::vector> &getMounts() const { + [[nodiscard]] const phmap::parallel_flat_hash_set> &getMounts() const { return mounts; } private: - std::vector> mounts; + phmap::parallel_flat_hash_set> mounts; }; diff --git a/src/creatures/appearance/outfit/outfit.cpp b/src/creatures/appearance/outfit/outfit.cpp index 6f0490339de..9e96c60e756 100644 --- a/src/creatures/appearance/outfit/outfit.cpp +++ b/src/creatures/appearance/outfit/outfit.cpp @@ -14,6 +14,13 @@ #include "utils/tools.hpp" #include "game/game.hpp" +bool Outfits::reload() { + for (auto &outfitsVector : outfits) { + outfitsVector.clear(); + } + return loadFromXml(); +} + bool Outfits::loadFromXml() { pugi::xml_document doc; auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/outfits.xml"; @@ -68,10 +75,12 @@ bool Outfits::loadFromXml() { } std::shared_ptr Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const { - for (const auto &outfit : outfits[sex]) { - if (outfit->lookType == lookType) { - return outfit; - } + auto it = std::ranges::find_if(outfits[sex], [&lookType](const auto &outfit) { + return outfit->lookType == lookType; + }); + + if (it != outfits[sex].end()) { + return *it; } return nullptr; } @@ -83,17 +92,7 @@ std::shared_ptr Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t l * @return const pointer to the outfit or nullptr if it could not be found. */ -std::shared_ptr Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) { +std::shared_ptr Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const { PlayerSex_t searchSex = (sex == PLAYERSEX_MALE) ? PLAYERSEX_FEMALE : PLAYERSEX_MALE; - - for (uint16_t i = 0; i < outfits[sex].size(); i++) { - if (outfits[sex].at(i)->lookType == lookType) { - if (outfits[searchSex].size() > i) { - return outfits[searchSex].at(i); - } else { // looktype found but the oposite sex array doesn't have this index. - return nullptr; - } - } - } - return nullptr; + return getOutfitByLookType(searchSex, lookType); } diff --git a/src/creatures/appearance/outfit/outfit.hpp b/src/creatures/appearance/outfit/outfit.hpp index e1a5143c673..30b84d1aca2 100644 --- a/src/creatures/appearance/outfit/outfit.hpp +++ b/src/creatures/appearance/outfit/outfit.hpp @@ -12,9 +12,17 @@ #include "declarations.hpp" #include "lib/di/container.hpp" +struct OutfitEntry { + constexpr OutfitEntry(uint16_t initLookType, uint8_t initAddons) : + lookType(initLookType), addons(initAddons) { } + + uint16_t lookType; + uint8_t addons; +}; + struct Outfit { Outfit(std::string initName, uint16_t initLookType, bool initPremium, bool initUnlocked, std::string initFrom) : - name(initName), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(initFrom) { } + name(std::move(initName)), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(std::move(initFrom)) { } std::string name; uint16_t lookType; @@ -38,9 +46,10 @@ class Outfits { return inject(); } - std::shared_ptr getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType); + std::shared_ptr getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const; bool loadFromXml(); + bool reload(); [[nodiscard]] std::shared_ptr getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const; [[nodiscard]] const std::vector> &getOutfits(PlayerSex_t sex) const { diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index cf98fcb6a7b..2aaadac4d61 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -98,7 +98,11 @@ CombatDamage Combat::getCombatDamage(std::shared_ptr creature, std::sh } } } + if (attackerPlayer && wheelSpell && wheelSpell->isInstant()) { + wheelSpell->getCombatDataAugment(attackerPlayer, damage); + } } + return damage; } @@ -283,7 +287,7 @@ bool Combat::isProtected(std::shared_ptr attacker, std::shared_ptrgetVocation()->canCombat() || !target->getVocation()->canCombat() && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) { + if ((!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat()) && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) { return true; } @@ -649,6 +653,10 @@ CombatDamage Combat::applyImbuementElementalDamage(std::shared_ptr attac continue; } + if (damage.primary.type != COMBAT_PHYSICALDAMAGE) { + break; + } + float damagePercent = imbuementInfo.imbuement->elementDamage / 100.0; damage.secondary.type = imbuementInfo.imbuement->combatType; @@ -699,7 +707,7 @@ bool Combat::checkFearConditionAffected(std::shared_ptr player) { auto affectedCount = (party->getMemberCount() + 5) / 5; g_logger().debug("[{}] Player is member of a party, {} members can be feared", __FUNCTION__, affectedCount); - for (const auto member : party->getMembers()) { + for (const auto &member : party->getMembers()) { if (member->hasCondition(CONDITION_FEARED)) { affectedCount -= 1; } @@ -751,7 +759,7 @@ void Combat::CombatConditionFunc(std::shared_ptr caster, std::shared_p } } - if (caster == target || target && !target->isImmune(condition->getType())) { + if (caster == target || (target && !target->isImmune(condition->getType()))) { auto conditionCopy = condition->clone(); if (caster) { conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID()); @@ -1022,10 +1030,10 @@ bool Combat::doCombatChain(std::shared_ptr caster, std::shared_ptrgetChainValues(caster, maxTargets, chainDistance, backtracking); - auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, backtracking, aggressive, target); + auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, aggressive, backtracking, std::move(target)); g_logger().debug("[{}] Chain targets: {}", __FUNCTION__, targets.size()); - if (targets.empty() || targets.size() == 1 && targets.begin()->second.empty()) { + if (targets.empty() || (targets.size() == 1 && targets.begin()->second.empty())) { return false; } @@ -1114,7 +1122,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin uint32_t maxY = 0; // calculate the max viewable range - for (std::shared_ptr tile : tileList) { + for (const std::shared_ptr &tile : tileList) { const Position &tilePos = tile->getPosition(); uint32_t diff = Position::getDistanceX(tilePos, pos); @@ -1132,7 +1140,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin const int32_t rangeY = maxY + MAP_MAX_VIEW_PORT_Y; int affected = 0; - for (std::shared_ptr tile : tileList) { + for (const std::shared_ptr &tile : tileList) { if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) { continue; } @@ -1187,7 +1195,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin uint8_t beamAffectedCurrent = 0; tmpDamage.affected = affected; - for (std::shared_ptr tile : tileList) { + for (const std::shared_ptr &tile : tileList) { if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) { continue; } @@ -1233,7 +1241,7 @@ void Combat::CombatFunc(std::shared_ptr caster, const Position &origin } void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptr target, CombatDamage &damage, const CombatParams ¶ms) { - doCombatHealth(caster, target, caster ? caster->getPosition() : Position(), damage, params); + doCombatHealth(caster, std::move(target), caster ? caster->getPosition() : Position(), damage, params); } void Combat::doCombatHealth(std::shared_ptr caster, std::shared_ptr target, const Position &origin, CombatDamage &damage, const CombatParams ¶ms) { @@ -1374,7 +1382,7 @@ void Combat::doCombatDispel(std::shared_ptr caster, std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms) { +[[maybe_unused]] void Combat::doCombatDefault(std::shared_ptr caster, std::shared_ptr target, const CombatParams ¶ms) { doCombatDefault(caster, target, caster ? caster->getPosition() : Position(), params); } @@ -2068,7 +2076,7 @@ void AreaCombat::setupExtArea(const std::list &list, uint32_t rows) { void MagicField::onStepInField(const std::shared_ptr &creature) { // remove magic walls/wild growth - if (!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE) { + if ((!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE) || id == ITEM_WILDGROWTH_SAFE) { if (!creature->isInGhostMode()) { g_game().internalRemoveItem(static_self_cast(), 1); } @@ -2083,7 +2091,7 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { if (ownerId) { bool harmfulField = true; auto itemTile = getTile(); - if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) { + if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || (itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE))) { auto ownerPlayer = g_game().getPlayerByGUID(ownerId); if (ownerPlayer) { harmfulField = false; diff --git a/src/creatures/combat/combat.hpp b/src/creatures/combat/combat.hpp index 6a79455c7c4..93b02502f25 100644 --- a/src/creatures/combat/combat.hpp +++ b/src/creatures/combat/combat.hpp @@ -72,8 +72,8 @@ class ChainCallback final : public CallBack { private: void onChainCombat(std::shared_ptr creature, uint8_t &chainTargets, uint8_t &chainDistance, bool &backtracking); - uint8_t m_chainTargets = 0; uint8_t m_chainDistance = 0; + uint8_t m_chainTargets = 0; bool m_backtracking = false; bool m_fromLua = false; }; @@ -125,7 +125,7 @@ class MatrixArea { data_[row] = new bool[cols]; for (uint32_t col = 0; col < cols; ++col) { - data_[row][col] = 0; + data_[row][col] = false; } } } @@ -324,7 +324,7 @@ class Combat { } void setPlayerCombatValues(formulaType_t formulaType, double mina, double minb, double maxa, double maxb); void postCombatEffects(std::shared_ptr caster, const Position &origin, const Position &pos) const { - postCombatEffects(caster, origin, pos, params); + postCombatEffects(std::move(caster), origin, pos, params); } void setOrigin(CombatOrigin origin) { @@ -393,7 +393,7 @@ class Combat { * @param damage The combat damage. * @return The calculated level formula. */ - int32_t getLevelFormula(std::shared_ptr player, const std::shared_ptr wheelSpell, const CombatDamage &damage) const; + int32_t getLevelFormula(std::shared_ptr player, std::shared_ptr wheelSpell, const CombatDamage &damage) const; CombatDamage getCombatDamage(std::shared_ptr creature, std::shared_ptr target) const; // configureable diff --git a/src/creatures/combat/condition.cpp b/src/creatures/combat/condition.cpp index 9d0f6962884..7f477f1d859 100644 --- a/src/creatures/combat/condition.cpp +++ b/src/creatures/combat/condition.cpp @@ -1308,7 +1308,7 @@ void ConditionManaShield::addCondition(std::shared_ptr creature, const bool ConditionManaShield::unserializeProp(ConditionAttr_t attr, PropStream &propStream) { if (attr == CONDITIONATTR_MANASHIELD) { - return propStream.read(manaShield); + return propStream.read(manaShield); } return Condition::unserializeProp(attr, propStream); } @@ -1317,7 +1317,7 @@ void ConditionManaShield::serialize(PropWriteStream &propWriteStream) { Condition::serialize(propWriteStream); propWriteStream.write(CONDITIONATTR_MANASHIELD); - propWriteStream.write(manaShield); + propWriteStream.write(manaShield); } bool ConditionManaShield::setParam(ConditionParam_t param, int32_t value) { @@ -1472,7 +1472,7 @@ bool ConditionDamage::unserializeProp(ConditionAttr_t attr, PropStream &propStre } else if (attr == CONDITIONATTR_OWNER) { return propStream.skip(4); } else if (attr == CONDITIONATTR_INTERVALDATA) { - IntervalInfo damageInfo; + IntervalInfo damageInfo {}; if (!propStream.read(damageInfo)) { return false; } @@ -1530,7 +1530,7 @@ bool ConditionDamage::addDamage(int32_t rounds, int32_t time, int32_t value) { // rounds, time, damage for (int32_t i = 0; i < rounds; ++i) { - IntervalInfo damageInfo; + IntervalInfo damageInfo {}; damageInfo.interval = time; damageInfo.timeLeft = time; damageInfo.value = value; @@ -1803,13 +1803,9 @@ void ConditionDamage::generateDamageList(int32_t amount, int32_t start, std::lis * ConditionFeared */ bool ConditionFeared::isStuck(std::shared_ptr creature, Position pos) const { - for (Direction dir : m_directionsVector) { - if (canWalkTo(creature, pos, dir)) { - return false; - } - } - - return true; + return std::ranges::all_of(m_directionsVector, [&](Direction dir) { + return !canWalkTo(creature, pos, dir); + }); } bool ConditionFeared::getRandomDirection(std::shared_ptr creature, Position pos) { @@ -1995,6 +1991,8 @@ bool ConditionFeared::getFleePath(std::shared_ptr creature, const Posi futurePos.y -= wsize; g_logger().debug("[{}] Trying to flee to NORTHWEST to {} [{}]", __FUNCTION__, futurePos.toString(), wsize); break; + case DIRECTION_NONE: + break; } found = creature->getPathTo(futurePos, dirList, 0, 30); diff --git a/src/creatures/combat/condition.hpp b/src/creatures/combat/condition.hpp index 1cffba99b50..07b31b42d15 100644 --- a/src/creatures/combat/condition.hpp +++ b/src/creatures/combat/condition.hpp @@ -27,7 +27,7 @@ class Condition : public SharedObject { virtual bool startCondition(std::shared_ptr creature); virtual bool executeCondition(std::shared_ptr creature, int32_t interval); virtual void endCondition(std::shared_ptr creature) = 0; - virtual void addCondition(std::shared_ptr creature, const std::shared_ptr condition) = 0; + virtual void addCondition(std::shared_ptr creature, std::shared_ptr condition) = 0; virtual uint32_t getIcons() const; ConditionId_t getId() const { return id; @@ -65,14 +65,14 @@ class Condition : public SharedObject { protected: uint8_t drainBodyStage = 0; - int64_t endTime; - uint32_t subId; - int32_t ticks; - ConditionType_t conditionType; - ConditionId_t id; - bool isBuff; + int64_t endTime {}; + uint32_t subId {}; + int32_t ticks {}; + ConditionType_t conditionType {}; + ConditionId_t id {}; + bool isBuff {}; - virtual bool updateCondition(const std::shared_ptr addCondition); + virtual bool updateCondition(std::shared_ptr addCondition); private: SoundEffect_t tickSound = SoundEffect_t::SILENCE; @@ -90,7 +90,7 @@ class ConditionGeneric : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; uint32_t getIcons() const override; std::shared_ptr clone() const override { @@ -106,7 +106,7 @@ class ConditionAttributes final : public ConditionGeneric { bool startCondition(std::shared_ptr creature) final; bool executeCondition(std::shared_ptr creature, int32_t interval) final; void endCondition(std::shared_ptr creature) final; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) final; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) final; bool setParam(ConditionParam_t param, int32_t value) final; @@ -172,7 +172,7 @@ class ConditionRegeneration final : public ConditionGeneric { bool startCondition(std::shared_ptr creature) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr addCondition) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -205,7 +205,7 @@ class ConditionManaShield final : public Condition { bool startCondition(std::shared_ptr creature) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr addCondition) override; uint32_t getIcons() const override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -219,7 +219,7 @@ class ConditionManaShield final : public Condition { bool unserializeProp(ConditionAttr_t attr, PropStream &propStream) override; private: - uint16_t manaShield = 0; + uint32_t manaShield = 0; }; class ConditionSoul final : public ConditionGeneric { @@ -227,7 +227,7 @@ class ConditionSoul final : public ConditionGeneric { ConditionSoul(ConditionId_t initId, ConditionType_t initType, int32_t iniTicks, bool initBuff = false, uint32_t initSubId = 0) : ConditionGeneric(initId, initType, iniTicks, initBuff, initSubId) { } - void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr addCondition) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; bool setParam(ConditionParam_t param, int32_t value) override; @@ -270,7 +270,7 @@ class ConditionDamage final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; uint32_t getIcons() const override; std::shared_ptr clone() const override { @@ -309,7 +309,7 @@ class ConditionDamage final : public Condition { bool getNextDamage(int32_t &damage); bool doDamage(std::shared_ptr creature, int32_t healthChange); - bool updateCondition(const std::shared_ptr addCondition) override; + bool updateCondition(std::shared_ptr addCondition) override; }; class ConditionFeared final : public Condition { @@ -321,7 +321,7 @@ class ConditionFeared final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; uint32_t getIcons() const override; std::shared_ptr clone() const override { @@ -360,7 +360,7 @@ class ConditionSpeed final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; uint32_t getIcons() const override; std::shared_ptr clone() const override { @@ -395,7 +395,7 @@ class ConditionOutfit final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; std::shared_ptr clone() const override { return std::make_shared(*this); @@ -421,7 +421,7 @@ class ConditionLight final : public Condition { bool startCondition(std::shared_ptr creature) override; bool executeCondition(std::shared_ptr creature, int32_t interval) override; void endCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr addCondition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr addCondition) override; std::shared_ptr clone() const override { return std::make_shared(*this); @@ -445,7 +445,7 @@ class ConditionSpellCooldown final : public ConditionGeneric { ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } bool startCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; std::shared_ptr clone() const override { return std::make_shared(*this); @@ -458,7 +458,7 @@ class ConditionSpellGroupCooldown final : public ConditionGeneric { ConditionGeneric(initId, initType, initTicks, initBuff, initSubId) { } bool startCondition(std::shared_ptr creature) override; - void addCondition(std::shared_ptr creature, const std::shared_ptr condition) override; + void addCondition(std::shared_ptr creature, std::shared_ptr condition) override; std::shared_ptr clone() const override { return std::make_shared(*this); diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 60cc5e7d2a9..dd4305de14e 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -630,6 +630,43 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr } } +void Spell::getCombatDataAugment(std::shared_ptr player, CombatDamage &damage) { + if (!(damage.instantSpellName).empty()) { + const auto equippedAugmentItems = player->getEquippedAugmentItems(); + for (const auto &item : equippedAugmentItems) { + const auto augments = item->getAugmentsBySpellName(damage.instantSpellName); + for (auto &augment : augments) { + if (augment->value == 0) { + continue; + } + if (augment->type == Augment_t::IncreasedDamage || augment->type == Augment_t::PowerfulImpact || augment->type == Augment_t::StrongImpact) { + const float augmentPercent = augment->value / 100.0; + damage.primary.value += static_cast(damage.primary.value * augmentPercent); + damage.secondary.value += static_cast(damage.secondary.value * augmentPercent); + } else if (augment->type != Augment_t::Cooldown) { + const int32_t augmentValue = augment->value * 100; + damage.lifeLeech += augment->type == Augment_t::LifeLeech ? augmentValue : 0; + damage.manaLeech += augment->type == Augment_t::ManaLeech ? augmentValue : 0; + damage.criticalDamage += augment->type == Augment_t::CriticalExtraDamage ? augmentValue : 0; + } + } + } + } +}; + +int32_t Spell::calculateAugmentSpellCooldownReduction(std::shared_ptr player) const { + int32_t spellCooldown = 0; + const auto equippedAugmentItems = player->getEquippedAugmentItemsByType(Augment_t::Cooldown); + for (const auto &item : equippedAugmentItems) { + const auto augments = item->getAugmentsBySpellNameAndType(getName(), Augment_t::Cooldown); + for (auto &augment : augments) { + spellCooldown += augment->value; + } + } + + return spellCooldown; +} + void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; @@ -644,8 +681,10 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { if (isUpgraded) { spellCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, spellGrade); } - g_logger().debug("[{}] spell name: {}, spellCooldown: {}, bonus: {}", __FUNCTION__, name, spellCooldown, player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN)); + int32_t augmentCooldownReduction = calculateAugmentSpellCooldownReduction(player); + g_logger().debug("[{}] spell name: {}, spellCooldown: {}, bonus: {}, augment {}", __FUNCTION__, name, spellCooldown, player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN), augmentCooldownReduction); spellCooldown -= player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN); + spellCooldown -= augmentCooldownReduction; if (spellCooldown > 0) { std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, m_spellId); player->addCondition(condition); @@ -727,7 +766,6 @@ uint32_t Spell::getManaCost(std::shared_ptr player) const { if (manaPercent != 0) { uint32_t maxMana = player->getMaxMana(); uint32_t manaCost = (maxMana * manaPercent) / 100; - WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); if (manaRedution > manaCost) { return 0; } @@ -750,7 +788,7 @@ bool InstantSpell::playerCastInstant(std::shared_ptr player, std::string var.type = VARIANT_NUMBER; var.number = player->getID(); } else if (needTarget || casterTargetOrDirection) { - std::shared_ptr target = nullptr; + std::shared_ptr target; bool useDirection = false; if (hasParam) { @@ -1046,7 +1084,7 @@ bool RuneSpell::castSpell(std::shared_ptr creature, std::shared_ptr creature, const LuaVariant &var, bool isHotkey) { bool result; if (isLoadedCallback()) { - result = executeCastSpell(creature, var, isHotkey); + result = executeCastSpell(std::move(creature), var, isHotkey); } else { result = false; } diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index cd1a7aaa623..fc23bbf9030 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -63,8 +63,8 @@ class Spells final : public Scripts { } void clear(); - bool registerInstantLuaEvent(const std::shared_ptr instant); - bool registerRuneLuaEvent(const std::shared_ptr rune); + bool registerInstantLuaEvent(std::shared_ptr instant); + bool registerRuneLuaEvent(std::shared_ptr rune); private: std::map> runes; @@ -92,7 +92,7 @@ class BaseSpell { class CombatSpell final : public Script, public BaseSpell, public std::enable_shared_from_this { public: // Constructor - CombatSpell(const std::shared_ptr newCombat, bool newNeedTarget, bool newNeedDirection); + CombatSpell(std::shared_ptr newCombat, bool newNeedTarget, bool newNeedDirection); // The copy constructor and the assignment operator have been deleted to prevent accidental copying. CombatSpell(const CombatSpell &) = delete; @@ -345,6 +345,9 @@ class Spell : public BaseSpell { m_separator = newSeparator.data(); } + void getCombatDataAugment(std::shared_ptr player, CombatDamage &damage); + int32_t calculateAugmentSpellCooldownReduction(std::shared_ptr player) const; + protected: void applyCooldownConditions(std::shared_ptr player) const; bool playerSpellCheck(std::shared_ptr player) const; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 6101ff0473d..7796863f066 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -125,7 +125,7 @@ void Creature::onThink(uint32_t interval) { auto onThink = [self = getCreature(), interval] { // scripting event - onThink const auto &thinkEvents = self->getCreatureEvents(CREATURE_EVENT_THINK); - for (const auto creatureEventPtr : thinkEvents) { + for (const auto &creatureEventPtr : thinkEvents) { creatureEventPtr->executeOnThink(self->static_self_cast(), interval); } }; @@ -299,7 +299,7 @@ void Creature::updateTileCache(std::shared_ptr upTile, const Position &pos if (pos.z == myPos.z) { int32_t dx = Position::getOffsetX(pos, myPos); int32_t dy = Position::getOffsetY(pos, myPos); - updateTileCache(upTile, dx, dy); + updateTileCache(std::move(upTile), dx, dy); } } @@ -332,7 +332,7 @@ int32_t Creature::getWalkCache(const Position &pos) { void Creature::onAddTileItem(std::shared_ptr tileItem, const Position &pos) { if (isMapLoaded && pos.z == getPosition().z) { - updateTileCache(tileItem, pos); + updateTileCache(std::move(tileItem), pos); } } @@ -343,7 +343,7 @@ void Creature::onUpdateTileItem(std::shared_ptr updateTile, const Position if (oldType.blockSolid || oldType.blockPathFind || newType.blockPathFind || newType.blockSolid) { if (pos.z == getPosition().z) { - updateTileCache(updateTile, pos); + updateTileCache(std::move(updateTile), pos); } } } @@ -355,7 +355,7 @@ void Creature::onRemoveTileItem(std::shared_ptr updateTile, const Position if (iType.blockSolid || iType.blockPathFind || iType.isGroundTile()) { if (pos.z == getPosition().z) { - updateTileCache(updateTile, pos); + updateTileCache(std::move(updateTile), pos); } } } @@ -439,7 +439,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { // Check if any of our summons is out of range (+/- 2 floors or 30 tiles away) bool checkRemoveDist = Position::getDistanceZ(newPos, pos) > 2 || (std::max(Position::getDistanceX(newPos, pos), Position::getDistanceY(newPos, pos)) > 30); - if (monster && monster->isFamiliar() && checkSummonDist || teleportSummon && !protectionZoneCheck && checkSummonDist) { + if ((monster && monster->isFamiliar() && checkSummonDist) || (teleportSummon && !protectionZoneCheck && checkSummonDist)) { const auto &creatureMaster = summon->getMaster(); if (!creatureMaster) { continue; @@ -709,7 +709,7 @@ void Creature::onDeath() { } } - bool killedByPlayer = mostDamageCreature && mostDamageCreature->getPlayer() || mostDamageCreatureMaster && mostDamageCreatureMaster->getPlayer(); + bool killedByPlayer = (mostDamageCreature && mostDamageCreature->getPlayer()) || (mostDamageCreatureMaster && mostDamageCreatureMaster->getPlayer()); if (getPlayer()) { g_metrics().addCounter( "player_death", @@ -761,7 +761,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared if (getMaster()) { // Scripting event onDeath const CreatureEventList &deathEvents = getCreatureEvents(CREATURE_EVENT_DEATH); - for (const auto deathEventPtr : deathEvents) { + for (const auto &deathEventPtr : deathEvents) { deathEventPtr->executeOnDeath(static_self_cast(), nullptr, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } } @@ -805,7 +805,8 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared auto monster = getMonster(); if (monster && !monster->isRewardBoss()) { std::ostringstream lootMessage; - lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(player->getProtocolVersion() < 1200) << "."; + auto collorMessage = player->getProtocolVersion() > 1200 && player->getOperatingSystem() < CLIENTOS_OTCLIENT_LINUX; + lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(collorMessage) << "."; auto suffix = corpseContainer->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); if (!suffix.empty()) { lootMessage << suffix; @@ -823,7 +824,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared auto isReachable = g_game().map.getPathMatching(player->getPosition(), dirList, FrozenPathingConditionCall(corpse->getPosition()), fpp); - if (player->checkAutoLoot(monster->isRewardBoss()) && corpseContainer && mostDamageCreature->getPlayer() && isReachable) { + if (player->checkAutoLoot(monster->isRewardBoss()) && isReachable) { g_dispatcher().addEvent([player, corpseContainer, corpsePosition = corpse->getPosition()] { g_game().playerQuickLootCorpse(player, corpseContainer, corpsePosition); }, @@ -833,7 +834,7 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared } // Scripting event onDeath - for (const auto deathEventPtr : getCreatureEvents(CREATURE_EVENT_DEATH)) { + for (const auto &deathEventPtr : getCreatureEvents(CREATURE_EVENT_DEATH)) { if (deathEventPtr) { deathEventPtr->executeOnDeath(static_self_cast(), corpse, lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); } @@ -1168,7 +1169,7 @@ double Creature::getDamageRatio(std::shared_ptr attacker) const { } uint64_t Creature::getGainedExperience(std::shared_ptr attacker) const { - return std::floor(getDamageRatio(attacker) * getLostExperience()); + return std::floor(getDamageRatio(std::move(attacker)) * getLostExperience()); } void Creature::addDamagePoints(std::shared_ptr attacker, int32_t damagePoints) { @@ -1180,7 +1181,7 @@ void Creature::addDamagePoints(std::shared_ptr attacker, int32_t damag auto it = damageMap.find(attackerId); if (it == damageMap.end()) { - CountBlock_t cb; + CountBlock_t cb {}; cb.ticks = OTSYS_TIME(); cb.total = damagePoints; damageMap[attackerId] = cb; @@ -1246,7 +1247,7 @@ void Creature::onTickCondition(ConditionType_t type, bool &bRemove) { } void Creature::onCombatRemoveCondition(std::shared_ptr condition) { - removeCondition(condition); + removeCondition(std::move(condition)); } void Creature::onAttacked() { @@ -1274,7 +1275,7 @@ bool Creature::deprecatedOnKilledCreature(std::shared_ptr target, bool // scripting event - onKill const CreatureEventList &killEvents = getCreatureEvents(CREATURE_EVENT_KILL); - for (const auto killEventPtr : killEvents) { + for (const auto &killEventPtr : killEvents) { killEventPtr->executeOnKill(static_self_cast(), target, lastHit); } return false; @@ -1292,7 +1293,7 @@ void Creature::onGainExperience(uint64_t gainExp, std::shared_ptr targ gainExp /= 2; } - master->onGainExperience(gainExp, target); + master->onGainExperience(gainExp, std::move(target)); if (!m->isFamiliar()) { auto spectators = Spectators().find(position); @@ -1573,7 +1574,7 @@ void Creature::setSpeed(int32_t varSpeedDelta) { } void Creature::setCreatureLight(LightInfo lightInfo) { - internalLight = std::move(lightInfo); + internalLight = lightInfo; } void Creature::setNormalCreatureLight() { @@ -1588,7 +1589,7 @@ bool Creature::registerCreatureEvent(const std::string &name) { CreatureEventType_t type = event->getEventType(); if (hasEventRegistered(type)) { - for (const auto creatureEventPtr : eventsList) { + for (const auto &creatureEventPtr : eventsList) { if (creatureEventPtr == event) { return false; } @@ -1641,7 +1642,7 @@ CreatureEventList Creature::getCreatureEvents(CreatureEventType_t type) { return tmpEventList; } - for (const auto creatureEventPtr : eventsList) { + for (const auto &creatureEventPtr : eventsList) { if (creatureEventPtr->getEventType() == type) { tmpEventList.push_back(creatureEventPtr); } @@ -1726,7 +1727,7 @@ bool FrozenPathingConditionCall::operator()(const Position &startPos, const Posi } bool Creature::isInvisible() const { - return std::find_if(conditions.begin(), conditions.end(), [](const std::shared_ptr condition) { + return std::find_if(conditions.begin(), conditions.end(), [](const std::shared_ptr &condition) { return condition->getType() == CONDITION_INVISIBLE; }) != conditions.end(); diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 4acbacb570a..670d5f3d688 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -209,19 +209,19 @@ class Creature : virtual public Thing, public SharedObject { return mana; } - uint16_t getManaShield() const { + uint32_t getManaShield() const { return manaShield; } - void setManaShield(uint16_t value) { + void setManaShield(uint32_t value) { manaShield = value; } - uint16_t getMaxManaShield() const { + uint32_t getMaxManaShield() const { return maxManaShield; } - void setMaxManaShield(uint16_t value) { + void setMaxManaShield(uint32_t value) { maxManaShield = value; } @@ -400,13 +400,13 @@ class Creature : virtual public Thing, public SharedObject { void executeConditions(uint32_t interval); bool hasCondition(ConditionType_t type, uint32_t subId = 0) const; - virtual bool isImmune(CombatType_t type) const { + virtual bool isImmune([[maybe_unused]] CombatType_t type) const { return false; } - virtual bool isImmune(ConditionType_t type) const { + virtual bool isImmune([[maybe_unused]] ConditionType_t type) const { return false; } - virtual bool isSuppress(ConditionType_t type, bool attackerPlayer) const { + virtual bool isSuppress([[maybe_unused]] ConditionType_t type, [[maybe_unused]] bool attackerPlayer) const { return false; }; @@ -424,7 +424,7 @@ class Creature : virtual public Thing, public SharedObject { virtual void drainHealth(std::shared_ptr attacker, int32_t damage); virtual void drainMana(std::shared_ptr attacker, int32_t manaLoss); - virtual bool challengeCreature(std::shared_ptr, int targetChangeCooldown) { + virtual bool challengeCreature(std::shared_ptr, [[maybe_unused]] int targetChangeCooldown) { return false; } @@ -448,10 +448,10 @@ class Creature : virtual public Thing, public SharedObject { * @deprecated -- This is here to trigger the deprecated onKill events in lua */ bool deprecatedOnKilledCreature(std::shared_ptr target, bool lastHit); - virtual bool onKilledPlayer(const std::shared_ptr &target, bool lastHit) { + virtual bool onKilledPlayer([[maybe_unused]] const std::shared_ptr &target, [[maybe_unused]] bool lastHit) { return false; }; - virtual bool onKilledMonster(const std::shared_ptr &target) { + virtual bool onKilledMonster([[maybe_unused]] const std::shared_ptr &target) { return false; }; virtual void onGainExperience(uint64_t gainExp, std::shared_ptr target); diff --git a/src/creatures/creatures_definitions.hpp b/src/creatures/creatures_definitions.hpp index 46fb5fe5979..33f62dbd2aa 100644 --- a/src/creatures/creatures_definitions.hpp +++ b/src/creatures/creatures_definitions.hpp @@ -124,7 +124,7 @@ enum ConditionType_t : uint8_t { // constexpr definiting suppressible conditions constexpr bool IsConditionSuppressible(ConditionType_t condition) { - constexpr ConditionType_t suppressibleConditions[] = { + constexpr std::array suppressibleConditions = { CONDITION_POISON, CONDITION_FIRE, CONDITION_ENERGY, @@ -135,13 +135,9 @@ constexpr bool IsConditionSuppressible(ConditionType_t condition) { CONDITION_CURSED, }; - for (const auto &suppressibleCondition : suppressibleConditions) { - if (condition == suppressibleCondition) { - return true; - } - } - - return false; + return std::ranges::any_of(suppressibleConditions, [condition](const auto &suppressibleCondition) { + return condition == suppressibleCondition; + }); } enum ConditionParam_t { @@ -718,11 +714,11 @@ enum ChannelEvent_t : uint8_t { CHANNELEVENT_EXCLUDE = 3, }; -enum VipStatus_t : uint8_t { - VIPSTATUS_OFFLINE = 0, - VIPSTATUS_ONLINE = 1, - VIPSTATUS_PENDING = 2, - VIPSTATUS_TRAINING = 3 +enum class VipStatus_t : uint8_t { + Offline = 0, + Online = 1, + Pending = 2, + Training = 3 }; enum Vocation_t : uint16_t { @@ -1401,32 +1397,29 @@ struct CreatureIcon { struct Position; struct VIPEntry { - VIPEntry(uint32_t initGuid, std::string initName, std::string initDescription, uint32_t initIcon, bool initNotify) : + VIPEntry(uint32_t initGuid, const std::string &initName, const std::string &initDescription, uint32_t initIcon, bool initNotify) : guid(initGuid), name(std::move(initName)), description(std::move(initDescription)), icon(initIcon), notify(initNotify) { } - uint32_t guid; - std::string name; - std::string description; - uint32_t icon; - bool notify; + uint32_t guid = 0; + std::string name = ""; + std::string description = ""; + uint32_t icon = 0; + bool notify = false; }; -struct OutfitEntry { - constexpr OutfitEntry(uint16_t initLookType, uint8_t initAddons) : - lookType(initLookType), addons(initAddons) { } - - uint16_t lookType; - uint8_t addons; -}; +struct VIPGroupEntry { + VIPGroupEntry(uint8_t initId, const std::string &initName, bool initCustomizable) : + id(initId), + name(std::move(initName)), + customizable(initCustomizable) { } -struct FamiliarEntry { - constexpr explicit FamiliarEntry(uint16_t initLookType) : - lookType(initLookType) { } - uint16_t lookType; + uint8_t id = 0; + std::string name = ""; + bool customizable = false; }; struct Skill { @@ -1539,19 +1532,6 @@ using ItemsTierCountList = std::map>; | ... */ -struct Familiar { - Familiar(std::string initName, uint16_t initLookType, bool initPremium, bool initUnlocked, std::string initType) : - name(initName), lookType(initLookType), - premium(initPremium), unlocked(initUnlocked), - type(initType) { } - - std::string name; - uint16_t lookType; - bool premium; - bool unlocked; - std::string type; -}; - struct ProtocolFamiliars { ProtocolFamiliars(const std::string &initName, uint16_t initLookType) : name(initName), lookType(initLookType) { } @@ -1654,18 +1634,11 @@ struct ShopBlock { int32_t itemStorageValue; std::vector childShop; - ShopBlock() { - itemId = 0; - itemName = ""; - itemSubType = 0; - itemBuyPrice = 0; - itemSellPrice = 0; - itemStorageKey = 0; - itemStorageValue = 0; - } + ShopBlock() : + itemId(0), itemName(""), itemSubType(0), itemBuyPrice(0), itemSellPrice(0), itemStorageKey(0), itemStorageValue(0) { } - explicit ShopBlock(uint16_t newItemId, int32_t newSubType = 0, uint32_t newBuyPrice = 0, uint32_t newSellPrice = 0, int32_t newStorageKey = 0, int32_t newStorageValue = 0, std::string newName = "") : - itemId(newItemId), itemSubType(newSubType), itemBuyPrice(newBuyPrice), itemSellPrice(newSellPrice), itemStorageKey(newStorageKey), itemStorageValue(newStorageValue), itemName(std::move(newName)) { } + explicit ShopBlock(uint16_t newItemId, std::string newName = "", int32_t newSubType = 0, uint32_t newBuyPrice = 0, uint32_t newSellPrice = 0, int32_t newStorageKey = 0, int32_t newStorageValue = 0) : + itemId(newItemId), itemName(std::move(newName)), itemSubType(newSubType), itemBuyPrice(newBuyPrice), itemSellPrice(newSellPrice), itemStorageKey(newStorageKey), itemStorageValue(newStorageValue) { } bool operator==(const ShopBlock &other) const { return itemId == other.itemId && itemName == other.itemName && itemSubType == other.itemSubType && itemBuyPrice == other.itemBuyPrice && itemSellPrice == other.itemSellPrice && itemStorageKey == other.itemStorageKey && itemStorageValue == other.itemStorageValue && childShop == other.childShop; diff --git a/src/creatures/interactions/chat.hpp b/src/creatures/interactions/chat.hpp index 022b3f540a1..3643086184c 100644 --- a/src/creatures/interactions/chat.hpp +++ b/src/creatures/interactions/chat.hpp @@ -71,7 +71,7 @@ class ChatChannel { int32_t onLeaveEvent = -1; int32_t onSpeakEvent = -1; - uint16_t id; + uint16_t id {}; bool publicChannel = false; friend class Chat; @@ -79,8 +79,8 @@ class ChatChannel { class PrivateChatChannel final : public ChatChannel { public: - PrivateChatChannel(uint16_t channelId, std::string channelName) : - ChatChannel(channelId, channelName) { } + PrivateChatChannel(uint16_t channelId, [[maybe_unused]] std::string channelName) : + ChatChannel(channelId, std::move(channelName)) { } uint32_t getOwner() const override { return owner; diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index f15616d6af5..fccc19b05e5 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -385,7 +385,7 @@ void Monster::onCreatureFound(std::shared_ptr creature, bool pushFront } void Monster::onCreatureEnter(std::shared_ptr creature) { - onCreatureFound(creature, true); + onCreatureFound(std::move(creature), true); } bool Monster::isFriend(const std::shared_ptr &creature) const { @@ -701,7 +701,7 @@ void Monster::updateIdleStatus() { isWalkingBack = true; } } else if (const auto &master = getMaster()) { - if ((!isSummon() && totalPlayersOnScreen == 0 || isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0) && getFaction() != FACTION_DEFAULT) { + if (((!isSummon() && totalPlayersOnScreen == 0) || (isSummon() && master->getMonster() && master->getMonster()->totalPlayersOnScreen == 0)) && getFaction() != FACTION_DEFAULT) { idle = true; } } @@ -838,7 +838,7 @@ void Monster::doAttacking(uint32_t interval) { for (const spellBlock_t &spellBlock : mType->info.attackSpells) { bool inRange = false; - if (spellBlock.spell == nullptr || spellBlock.isMelee && isFleeing()) { + if (spellBlock.spell == nullptr || (spellBlock.isMelee && isFleeing())) { continue; } diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index edf3874161d..bf9a39e4133 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -15,7 +15,6 @@ class Creature; class Game; -class Spawn; class Monster final : public Creature { public: @@ -23,7 +22,7 @@ class Monster final : public Creature { static int32_t despawnRange; static int32_t despawnRadius; - explicit Monster(const std::shared_ptr mType); + explicit Monster(std::shared_ptr mType); // non-copyable Monster(const Monster &) = delete; @@ -160,7 +159,7 @@ class Monster final : public Creature { } std::vector getIcons() const override { - const auto creatureIcons = Creature::getIcons(); + auto creatureIcons = Creature::getIcons(); if (!creatureIcons.empty()) { return creatureIcons; } @@ -324,7 +323,7 @@ class Monster final : public Creature { return timeToChangeFiendish; } - const std::shared_ptr getMonsterType() const { + std::shared_ptr getMonsterType() const { return mType; } diff --git a/src/creatures/monsters/monsters.cpp b/src/creatures/monsters/monsters.cpp index 190c14c76e5..3d457aa4d47 100644 --- a/src/creatures/monsters/monsters.cpp +++ b/src/creatures/monsters/monsters.cpp @@ -20,7 +20,7 @@ void MonsterType::loadLoot(const std::shared_ptr monsterType, LootB if (lootBlock.childLoot.empty()) { bool isContainer = Item::items[lootBlock.id].isContainer(); if (isContainer) { - for (LootBlock child : lootBlock.childLoot) { + for (const LootBlock &child : lootBlock.childLoot) { lootBlock.childLoot.push_back(child); } } @@ -74,7 +74,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell return true; } - std::shared_ptr combatSpell = nullptr; + std::shared_ptr combatSpell; auto combatPtr = std::make_shared(); @@ -156,7 +156,7 @@ bool Monsters::deserializeSpell(const std::shared_ptr spell, spell std::shared_ptr condition = Condition::createCondition(CONDITIONID_COMBAT, CONDITION_OUTFIT, duration, 0)->static_self_cast(); - if (spell->outfitMonster != "") { + if (!spell->outfitMonster.empty()) { condition->setLazyMonsterOutfit(spell->outfitMonster); } else if (spell->outfitItem > 0) { Outfit_t outfit; @@ -307,7 +307,7 @@ std::shared_ptr Monsters::getMonsterType(const std::string &name, b } std::shared_ptr Monsters::getMonsterTypeByRaceId(uint16_t raceId, bool isBoss /* = false*/) const { - const auto bossType = g_ioBosstiary().getMonsterTypeByBossRaceId(raceId); + auto bossType = g_ioBosstiary().getMonsterTypeByBossRaceId(raceId); if (isBoss && bossType) { return bossType; } diff --git a/src/creatures/monsters/monsters.hpp b/src/creatures/monsters/monsters.hpp index 0fa2a3d88db..518befd8a70 100644 --- a/src/creatures/monsters/monsters.hpp +++ b/src/creatures/monsters/monsters.hpp @@ -30,7 +30,7 @@ struct spellBlock_t { ~spellBlock_t() = default; spellBlock_t(const spellBlock_t &other) = delete; spellBlock_t &operator=(const spellBlock_t &other) = delete; - spellBlock_t(spellBlock_t &&other) : + spellBlock_t(spellBlock_t &&other) noexcept : spell(other.spell), chance(other.chance), speed(other.speed), @@ -57,7 +57,7 @@ struct spellBlock_t { class MonsterType { struct MonsterInfo { - LuaScriptInterface* scriptInterface; + LuaScriptInterface* scriptInterface {}; std::map elementMap; std::map reflectMap; @@ -201,7 +201,7 @@ class MonsterType { return !info.bosstiaryClass.empty(); } - void loadLoot(const std::shared_ptr monsterType, LootBlock lootblock); + void loadLoot(std::shared_ptr monsterType, LootBlock lootblock); bool canSpawn(const Position &pos); }; @@ -271,8 +271,8 @@ class Monsters { std::shared_ptr getMonsterType(const std::string &name, bool silent = false) const; std::shared_ptr getMonsterTypeByRaceId(uint16_t raceId, bool isBoss = false) const; - bool tryAddMonsterType(const std::string &name, const std::shared_ptr mType); - bool deserializeSpell(const std::shared_ptr spell, spellBlock_t &sb, const std::string &description = ""); + bool tryAddMonsterType(const std::string &name, std::shared_ptr mType); + bool deserializeSpell(std::shared_ptr spell, spellBlock_t &sb, const std::string &description = ""); std::unique_ptr scriptInterface; std::map> monsters; diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 21eab1a7c0b..ef5912c8052 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -39,7 +39,6 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) { this->filemonstername = filemonstername; loaded = true; - uint32_t eventschedule = g_eventsScheduler().getSpawnMonsterSchedule(); std::string boostedNameGet = g_game().getBoostedMonsterName(); for (auto spawnMonsterNode : doc.child("monsters").children()) { @@ -89,12 +88,6 @@ bool SpawnsMonster::loadFromXML(const std::string &filemonstername) { centerPos.z ); - int32_t boostedrate = 1; - - if (nameAttribute.value() == boostedNameGet) { - boostedrate = 2; - } - pugi::xml_attribute weightAttribute = childMonsterNode.attribute("weight"); uint32_t weight = 1; if (weightAttribute) { @@ -157,12 +150,9 @@ SpawnMonster::~SpawnMonster() { bool SpawnMonster::findPlayer(const Position &pos) { auto spectators = Spectators().find(pos); - for (const auto &spectator : spectators) { - if (!spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByMonsters)) { - return true; - } - } - return false; + return std::ranges::any_of(spectators, [](const auto &spectator) { + return !spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByMonsters); + }); } bool SpawnMonster::isInSpawnMonsterZone(const Position &pos) { @@ -299,7 +289,7 @@ void SpawnMonster::cleanup() { } bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Direction dir, uint32_t scheduleInterval, uint32_t weight /*= 1*/) { - std::string variant = ""; + std::string variant; for (const auto &zone : Zone::getZones(pos)) { if (!zone->getMonsterVariant().empty()) { variant = zone->getMonsterVariant() + "|"; @@ -343,7 +333,7 @@ bool SpawnMonster::addMonster(const std::string &name, const Position &pos, Dire g_logger().error("[SpawnMonster] Monster {} already exists in spawn block at {}", name, pos.toString()); return false; } - if (monsterType->isBoss() && sb->monsterTypes.size() > 0) { + if (monsterType->isBoss() && !sb->monsterTypes.empty()) { g_logger().error("[SpawnMonster] Boss monster {} has been added to spawn block with other monsters. This is not allowed.", name); return false; } @@ -436,10 +426,8 @@ std::shared_ptr spawnBlock_t::getMonsterType() const { } bool spawnBlock_t::hasBoss() const { - for (const auto &[monsterType, weight] : monsterTypes) { - if (monsterType->isBoss()) { - return true; - } - } - return false; + return std::ranges::any_of(monsterTypes, [](const auto &pair) { + const auto &[monsterType, weight] = pair; + return monsterType->isBoss(); + }); } diff --git a/src/creatures/monsters/spawns/spawn_monster.hpp b/src/creatures/monsters/spawns/spawn_monster.hpp index 800b36fda5a..35b856d23d4 100644 --- a/src/creatures/monsters/spawns/spawn_monster.hpp +++ b/src/creatures/monsters/spawns/spawn_monster.hpp @@ -29,7 +29,7 @@ struct spawnBlock_t { class SpawnMonster { public: SpawnMonster(Position initPos, int32_t initRadius) : - centerPos(std::move(initPos)), radius(initRadius) { } + centerPos(initPos), radius(initRadius) { } ~SpawnMonster(); // non-copyable @@ -71,9 +71,9 @@ class SpawnMonster { uint32_t checkSpawnMonsterEvent = 0; static bool findPlayer(const Position &pos); - bool spawnMonster(uint32_t spawnMonsterId, spawnBlock_t &sb, const std::shared_ptr monsterType, bool startup = false); + bool spawnMonster(uint32_t spawnMonsterId, spawnBlock_t &sb, std::shared_ptr monsterType, bool startup = false); void checkSpawnMonster(); - void scheduleSpawn(uint32_t spawnMonsterId, spawnBlock_t &sb, const std::shared_ptr monsterType, uint16_t interval, bool startup = false); + void scheduleSpawn(uint32_t spawnMonsterId, spawnBlock_t &sb, std::shared_ptr monsterType, uint16_t interval, bool startup = false); }; class SpawnsMonster { diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index d347ec6b66c..e445a58fcca 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -52,9 +52,6 @@ Npc::Npc(const std::shared_ptr &npcType) : } } -Npc::~Npc() { -} - void Npc::addList() { g_game().addNpc(static_self_cast()); } @@ -248,7 +245,7 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 uint32_t shoppingBagSlots = 20; const ItemType &itemType = Item::items[itemId]; if (std::shared_ptr tile = ignore ? player->getTile() : nullptr; tile) { - double slotsNedeed = 0; + double slotsNedeed; if (itemType.stackable) { slotsNedeed = inBackpacks ? std::ceil(std::ceil(static_cast(amount) / itemType.stackSize) / shoppingBagSlots) : std::ceil(static_cast(amount) / itemType.stackSize); } else { @@ -263,7 +260,7 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 uint32_t buyPrice = 0; const std::vector &shopVector = getShopItemVector(player->getGUID()); - for (ShopBlock shopBlock : shopVector) { + for (const ShopBlock &shopBlock : shopVector) { if (itemType.id == shopBlock.itemId && shopBlock.itemBuyPrice != 0) { buyPrice = shopBlock.itemBuyPrice; } @@ -308,7 +305,7 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint8_t subType, uint16_t amount, bool ignore) { uint64_t totalPrice = 0; - onPlayerSellItem(player, itemId, subType, amount, ignore, totalPrice); + onPlayerSellItem(std::move(player), itemId, subType, amount, ignore, totalPrice); } void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, uint64_t totalPrice) { @@ -324,7 +321,6 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u bool hasMore = false; uint64_t toSellCount = 0; phmap::flat_hash_map toSell; - int64_t start = OTSYS_TIME(); for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { if (toSellCount >= 500) { hasMore = true; @@ -341,8 +337,8 @@ void Npc::onPlayerSellAllLoot(uint32_t playerId, uint16_t itemId, bool ignore, u toSellCount += item->getItemAmount(); } } - for (auto &[itemId, amount] : toSell) { - onPlayerSellItem(player, itemId, 0, amount, ignore, totalPrice, container); + for (auto &[m_itemId, amount] : toSell) { + onPlayerSellItem(player, m_itemId, 0, amount, ignore, totalPrice, container); } auto ss = std::stringstream(); if (totalPrice == 0) { @@ -377,7 +373,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint uint32_t sellPrice = 0; const ItemType &itemType = Item::items[itemId]; const std::vector &shopVector = getShopItemVector(player->getGUID()); - for (ShopBlock shopBlock : shopVector) { + for (const ShopBlock &shopBlock : shopVector) { if (itemType.id == shopBlock.itemId && shopBlock.itemSellPrice != 0) { sellPrice = shopBlock.itemSellPrice; } @@ -387,7 +383,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint } auto toRemove = amount; - for (auto item : player->getInventoryItemsFromId(itemId, ignore)) { + for (const auto &item : player->getInventoryItemsFromId(itemId, ignore)) { if (!item || item->getTier() > 0 || item->hasImbuements()) { continue; } @@ -452,7 +448,6 @@ void Npc::onPlayerCheckItem(std::shared_ptr player, uint16_t itemId, uin return; } - const ItemType &itemType = Item::items[itemId]; // onPlayerCheckItem(self, player, itemId, subType) CreatureCallback callback = CreatureCallback(npcType->info.scriptInterface, getNpc()); if (callback.startScriptInterface(npcType->info.playerLookEvent)) { @@ -515,7 +510,7 @@ void Npc::onThinkWalk(uint32_t interval) { } // If talking, no walking - if (playerInteractions.size() > 0) { + if (!playerInteractions.empty()) { walkTicks = 0; eventWalk = 0; return; diff --git a/src/creatures/npcs/npc.hpp b/src/creatures/npcs/npc.hpp index 2d4e87ac7b8..7e8be84c7f1 100644 --- a/src/creatures/npcs/npc.hpp +++ b/src/creatures/npcs/npc.hpp @@ -27,7 +27,6 @@ class Npc final : public Creature { explicit Npc(const std::shared_ptr &npcType); Npc() = default; - ~Npc(); // Singleton - ensures we don't accidentally copy it Npc(const Npc &) = delete; @@ -68,7 +67,7 @@ class Npc final : public Creature { } void setName(std::string newName) { - npcType->name = newName; + npcType->name = std::move(newName); } CreatureType_t getType() const override { @@ -190,13 +189,13 @@ class Npc final : public Creature { std::shared_ptr npcType; std::shared_ptr spawnNpc; - uint8_t speechBubble; + uint8_t speechBubble {}; uint32_t yellTicks = 0; uint32_t walkTicks = 0; uint32_t soundTicks = 0; - bool ignoreHeight; + bool ignoreHeight {}; phmap::flat_hash_set> playerSpectators; Position masterPos; diff --git a/src/creatures/npcs/npcs.cpp b/src/creatures/npcs/npcs.cpp index ecfd2750a94..6fe7f0b8320 100644 --- a/src/creatures/npcs/npcs.cpp +++ b/src/creatures/npcs/npcs.cpp @@ -84,16 +84,16 @@ void NpcType::loadShop(const std::shared_ptr &npcType, ShopBlock shopBl } // Check if the item already exists in the shop vector and ignore it - for (auto shopIterator = npcType->info.shopItemVector.begin(); shopIterator != npcType->info.shopItemVector.end(); ++shopIterator) { - if (*shopIterator == shopBlock) { - return; - } + if (std::any_of(npcType->info.shopItemVector.begin(), npcType->info.shopItemVector.end(), [&shopBlock](const auto &shopIterator) { + return shopIterator == shopBlock; + })) { + return; } if (shopBlock.childShop.empty()) { bool isContainer = iType.isContainer(); if (isContainer) { - for (ShopBlock child : shopBlock.childShop) { + for (const ShopBlock &child : shopBlock.childShop) { shopBlock.childShop.push_back(child); } } diff --git a/src/creatures/npcs/npcs.hpp b/src/creatures/npcs/npcs.hpp index 1a984abf2e8..ab5e700caea 100644 --- a/src/creatures/npcs/npcs.hpp +++ b/src/creatures/npcs/npcs.hpp @@ -25,7 +25,7 @@ class Shop { class NpcType : public SharedObject { struct NpcInfo { - LuaScriptInterface* scriptInterface; + LuaScriptInterface* scriptInterface {}; Outfit_t outfit = {}; RespawnType respawnType = {}; diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index 968deca5331..a8be411dc6c 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -146,12 +146,9 @@ SpawnNpc::~SpawnNpc() { bool SpawnNpc::findPlayer(const Position &pos) { auto spectators = Spectators().find(pos); - for (const auto &spectator : spectators) { - if (!spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByNpcs)) { - return true; - } - } - return false; + return std::ranges::any_of(spectators, [](const auto &spectator) { + return !spectator->getPlayer()->hasFlag(PlayerFlags_t::IgnoredByNpcs); + }); } bool SpawnNpc::isInSpawnNpcZone(const Position &pos) { diff --git a/src/creatures/npcs/spawns/spawn_npc.hpp b/src/creatures/npcs/spawns/spawn_npc.hpp index d02a83e80c5..49eb3bc6f2b 100644 --- a/src/creatures/npcs/spawns/spawn_npc.hpp +++ b/src/creatures/npcs/spawns/spawn_npc.hpp @@ -26,7 +26,7 @@ struct spawnBlockNpc_t { class SpawnNpc : public SharedObject { public: SpawnNpc(Position initPos, int32_t initRadius) : - centerPos(std::move(initPos)), radius(initRadius) { } + centerPos(initPos), radius(initRadius) { } ~SpawnNpc(); // non-copyable @@ -91,7 +91,7 @@ class SpawnsNpc { } std::string setFileName(std::string setName) { - return fileName = setName; + return fileName = std::move(setName); } std::forward_list> &getSpawnNpcList() { diff --git a/src/creatures/players/achievement/player_achievement.hpp b/src/creatures/players/achievement/player_achievement.hpp index 7d141c96a16..d1073a9bf1e 100644 --- a/src/creatures/players/achievement/player_achievement.hpp +++ b/src/creatures/players/achievement/player_achievement.hpp @@ -13,7 +13,7 @@ class Player; class KV; struct Achievement { - Achievement() { } + Achievement() = default; std::string name; std::string description; diff --git a/src/creatures/players/cyclopedia/player_badge.cpp b/src/creatures/players/cyclopedia/player_badge.cpp new file mode 100644 index 00000000000..9b892a6164c --- /dev/null +++ b/src/creatures/players/cyclopedia/player_badge.cpp @@ -0,0 +1,156 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#include "pch.hpp" + +#include "player_badge.hpp" + +#include "creatures/players/player.hpp" +#include "game/game.hpp" +#include "kv/kv.hpp" + +PlayerBadge::PlayerBadge(Player &player) : + m_player(player) { } + +bool PlayerBadge::hasBadge(uint8_t id) const { + if (id == 0) { + return false; + } + + if (auto it = std::find_if(m_badgesUnlocked.begin(), m_badgesUnlocked.end(), [id](auto badge_it) { + return badge_it.first.m_id == id; + }); + it != m_badgesUnlocked.end()) { + return true; + } + + return false; +} + +bool PlayerBadge::add(uint8_t id, uint32_t timestamp /* = 0*/) { + if (hasBadge(id)) { + return false; + } + + const Badge &badge = g_game().getBadgeById(id); + if (badge.m_id == 0) { + return false; + } + + int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000); + getUnlockedKV()->set(badge.m_name, toSaveTimeStamp); + m_badgesUnlocked.emplace_back(badge, toSaveTimeStamp); + m_badgesUnlocked.shrink_to_fit(); + return true; +} + +void PlayerBadge::checkAndUpdateNewBadges() { + for (const auto &badge : g_game().getBadges()) { + switch (badge.m_type) { + case CyclopediaBadge_t::ACCOUNT_AGE: + if (accountAge(badge.m_amount)) { + add(badge.m_id); + } + break; + case CyclopediaBadge_t::LOYALTY: + if (loyalty(badge.m_amount)) { + add(badge.m_id); + } + break; + case CyclopediaBadge_t::ACCOUNT_ALL_LEVEL: + if (accountAllLevel(badge.m_amount)) { + add(badge.m_id); + } + break; + case CyclopediaBadge_t::ACCOUNT_ALL_VOCATIONS: + if (accountAllVocations(badge.m_amount)) { + add(badge.m_id); + } + break; + case CyclopediaBadge_t::TOURNAMENT_PARTICIPATION: + case CyclopediaBadge_t::TOURNAMENT_POINTS: + break; + } + } + + loadUnlockedBadges(); +} + +void PlayerBadge::loadUnlockedBadges() { + const auto &unlockedBadges = getUnlockedKV()->keys(); + g_logger().debug("[{}] - Loading unlocked badges: {}", __FUNCTION__, unlockedBadges.size()); + for (const auto &badgeName : unlockedBadges) { + const Badge &badge = g_game().getBadgeByName(badgeName); + if (badge.m_id == 0) { + g_logger().error("[{}] - Badge {} not found.", __FUNCTION__, badgeName); + continue; + } + + g_logger().debug("[{}] - Badge {} found for player {}.", __FUNCTION__, badge.m_name, m_player.getName()); + + m_badgesUnlocked.emplace_back(badge, getUnlockedKV()->get(badgeName)->getNumber()); + } +} + +const std::shared_ptr &PlayerBadge::getUnlockedKV() { + if (m_badgeUnlockedKV == nullptr) { + m_badgeUnlockedKV = m_player.kv()->scoped("badges")->scoped("unlocked"); + } + + return m_badgeUnlockedKV; +} + +// Badge Calculate Functions +bool PlayerBadge::accountAge(uint8_t amount) { + return std::floor(m_player.getLoyaltyPoints() / 365) >= amount; +} + +bool PlayerBadge::loyalty(uint8_t amount) { + return m_player.getLoyaltyPoints() >= amount; +} + +bool PlayerBadge::accountAllLevel(uint8_t amount) { + const auto &players = g_game().getPlayersByAccount(m_player.getAccount(), true); + uint16_t total = std::accumulate(players.begin(), players.end(), 0, [](uint16_t sum, const std::shared_ptr &player) { + return sum + player->getLevel(); + }); + return total >= amount; +} + +bool PlayerBadge::accountAllVocations(uint8_t amount) { + auto knight = false; + auto paladin = false; + auto druid = false; + auto sorcerer = false; + for (const auto &player : g_game().getPlayersByAccount(m_player.getAccount(), true)) { + if (player->getLevel() >= amount) { + auto vocationEnum = player->getPlayerVocationEnum(); + if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { + knight = true; + } else if (vocationEnum == Vocation_t::VOCATION_SORCERER_CIP) { + sorcerer = true; + } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { + paladin = true; + } else if (vocationEnum == Vocation_t::VOCATION_DRUID_CIP) { + druid = true; + } + } + } + return knight && paladin && druid && sorcerer; +} + +bool PlayerBadge::tournamentParticipation(uint8_t skill) { + // todo check if is used + return false; +} + +bool PlayerBadge::tournamentPoints(uint8_t race) { + // todo check if is used + return false; +} diff --git a/src/creatures/players/cyclopedia/player_badge.hpp b/src/creatures/players/cyclopedia/player_badge.hpp new file mode 100644 index 00000000000..7bf28c0c302 --- /dev/null +++ b/src/creatures/players/cyclopedia/player_badge.hpp @@ -0,0 +1,65 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#include "enums/player_cyclopedia.hpp" + +class Player; +class KV; + +struct Badge { + uint8_t m_id = 0; + CyclopediaBadge_t m_type; + std::string m_name; + uint16_t m_amount = 0; + + Badge() = default; + + Badge(uint8_t id, CyclopediaBadge_t type, std::string name, uint16_t amount) : + m_id(id), m_type(type), m_name(std::move(name)), m_amount(amount) { } + + bool operator==(const Badge &other) const { + return m_id == other.m_id; + } +}; + +namespace std { + template <> + struct hash { + std::size_t operator()(const Badge &b) const { + return hash()(b.m_id); + } + }; +} + +class PlayerBadge { +public: + explicit PlayerBadge(Player &player); + + [[nodiscard]] bool hasBadge(uint8_t id) const; + bool add(uint8_t id, uint32_t timestamp = 0); + void checkAndUpdateNewBadges(); + void loadUnlockedBadges(); + const std::shared_ptr &getUnlockedKV(); + + // Badge Calculate Functions + bool accountAge(uint8_t amount); + bool loyalty(uint8_t amount); + bool accountAllLevel(uint8_t amount); + bool accountAllVocations(uint8_t amount); + [[nodiscard]] bool tournamentParticipation(uint8_t skill); + [[nodiscard]] bool tournamentPoints(uint8_t race); + +private: + // {badge ID, time when it was unlocked} + std::shared_ptr m_badgeUnlockedKV; + std::vector> m_badgesUnlocked; + Player &m_player; +}; diff --git a/src/creatures/players/cyclopedia/player_title.cpp b/src/creatures/players/cyclopedia/player_title.cpp new file mode 100644 index 00000000000..624b0313457 --- /dev/null +++ b/src/creatures/players/cyclopedia/player_title.cpp @@ -0,0 +1,324 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#include "pch.hpp" + +#include "player_title.hpp" + +#include "creatures/players/player.hpp" +#include "game/game.hpp" +#include "kv/kv.hpp" + +PlayerTitle::PlayerTitle(Player &player) : + m_player(player) { } + +bool PlayerTitle::isTitleUnlocked(uint8_t id) const { + if (id == 0) { + return false; + } + + if (auto it = std::find_if(m_titlesUnlocked.begin(), m_titlesUnlocked.end(), [id](auto title_it) { + return title_it.first.m_id == id; + }); + it != m_titlesUnlocked.end()) { + return true; + } + + return false; +} + +bool PlayerTitle::manage(bool canAdd, uint8_t id, uint32_t timestamp /* = 0*/) { + const Title &title = g_game().getTitleById(id); + if (title.m_id == 0) { + return false; + } + + if (!canAdd) { + if (!title.m_permanent) { + remove(title); + } + return false; + } + + if (isTitleUnlocked(id)) { + return false; + } + + int toSaveTimeStamp = timestamp != 0 ? timestamp : (OTSYS_TIME() / 1000); + getUnlockedKV()->set(title.m_maleName, toSaveTimeStamp); + m_titlesUnlocked.emplace_back(title, toSaveTimeStamp); + m_titlesUnlocked.shrink_to_fit(); + g_logger().debug("[{}] - Added title: {}", __FUNCTION__, title.m_maleName); + + return true; +} + +void PlayerTitle::remove(const Title &title) { + auto id = title.m_id; + if (!isTitleUnlocked(id)) { + return; + } + + auto it = std::find_if(m_titlesUnlocked.begin(), m_titlesUnlocked.end(), [id](auto title_it) { + return title_it.first.m_id == id; + }); + + if (it == m_titlesUnlocked.end()) { + return; + } + + getUnlockedKV()->remove(title.m_maleName); + m_titlesUnlocked.erase(it); + m_titlesUnlocked.shrink_to_fit(); + g_logger().debug("[{}] - Removed title: {}", __FUNCTION__, title.m_maleName); +} + +const std::vector> &PlayerTitle::getUnlockedTitles() { + return m_titlesUnlocked; +} + +uint8_t PlayerTitle::getCurrentTitle() const { + return static_cast(m_player.kv()->scoped("titles")->get("current-title")->getNumber()); +} + +void PlayerTitle::setCurrentTitle(uint8_t id) { + m_player.kv()->scoped("titles")->set("current-title", id != 0 && isTitleUnlocked(id) ? id : 0); +} + +std::string PlayerTitle::getCurrentTitleName() { + auto currentTitle = getCurrentTitle(); + if (currentTitle == 0) { + return ""; + } + + auto title = g_game().getTitleById(currentTitle); + if (title.m_id == 0) { + return ""; + } + + return getNameBySex(m_player.getSex(), title.m_maleName, title.m_femaleName); +} + +const std::string &PlayerTitle::getNameBySex(PlayerSex_t sex, const std::string &male, const std::string &female) { + return sex == PLAYERSEX_FEMALE && !female.empty() ? female : male; +} + +void PlayerTitle::checkAndUpdateNewTitles() { + Benchmark bm_checkTitles; + for (const auto &title : g_game().getTitles()) { + switch (title.m_type) { + case CyclopediaTitle_t::NOTHING: + break; + case CyclopediaTitle_t::GOLD: + manage(checkGold(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::MOUNTS: + manage(checkMount(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::OUTFITS: + manage(checkOutfit(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::LEVEL: + manage(checkLevel(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::HIGHSCORES: + manage(checkHighscore(title.m_skill), title.m_id); + break; + case CyclopediaTitle_t::BESTIARY: + case CyclopediaTitle_t::BOSSTIARY: + manage(checkBestiary(title.m_maleName, title.m_race, title.m_type == CyclopediaTitle_t::BOSSTIARY, title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::DAILY_REWARD: + manage(checkLoginStreak(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::TASK: + manage(checkTask(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::MAP: + // manage(checkMap(title.m_amount), title.m_id); + break; + case CyclopediaTitle_t::OTHERS: + manage(checkOther(title.m_maleName), title.m_id); + break; + } + } + + g_logger().debug("Checking and updating titles of player {} took {} milliseconds.", m_player.getName(), bm_checkTitles.duration()); + + loadUnlockedTitles(); +} + +void PlayerTitle::loadUnlockedTitles() { + const auto &unlockedTitles = getUnlockedKV()->keys(); + g_logger().debug("[{}] - Loading unlocked titles: {}", __FUNCTION__, unlockedTitles.size()); + for (const auto &titleName : unlockedTitles) { + const Title &title = g_game().getTitleByName(titleName); + if (title.m_id == 0) { + g_logger().error("[{}] - Title {} not found.", __FUNCTION__, titleName); + continue; + } + + m_titlesUnlocked.emplace_back(title, getUnlockedKV()->get(titleName)->getNumber()); + } +} + +const std::shared_ptr &PlayerTitle::getUnlockedKV() { + if (m_titleUnlockedKV == nullptr) { + m_titleUnlockedKV = m_player.kv()->scoped("titles")->scoped("unlocked"); + } + + return m_titleUnlockedKV; +} + +// Title Calculate Functions +bool PlayerTitle::checkGold(uint32_t amount) { + return m_player.getBankBalance() >= amount; +} + +bool PlayerTitle::checkMount(uint32_t amount) { + uint8_t total = 0; + for (const auto &mount : g_game().mounts.getMounts()) { + if (m_player.hasMount(mount)) { + total++; + } + } + return total >= amount; +} + +bool PlayerTitle::checkOutfit(uint32_t amount) { + return m_player.outfits.size() >= amount; +} + +bool PlayerTitle::checkLevel(uint32_t amount) { + return m_player.getLevel() >= amount; +} + +bool PlayerTitle::checkHighscore(uint8_t skill) { + Database &db = Database::getInstance(); + std::string query; + std::string fieldCheck = "id"; + + switch (static_cast(skill)) { + case HighscoreCategories_t::CHARMS: + query = fmt::format( + "SELECT `pc`.`player_guid`, `pc`.`charm_points`, `p`.`group_id` FROM `player_charms` pc JOIN `players` p ON `pc`.`player_guid` = `p`.`id` WHERE `p`.`group_id` < {} ORDER BY `pc`.`charm_points` DESC LIMIT 1", + static_cast(GROUP_TYPE_GAMEMASTER) + ); + fieldCheck = "player_guid"; + break; + case HighscoreCategories_t::DROME: + // todo check if player is in the top 5 for the previous rota of the Tibiadrome. + return false; + case HighscoreCategories_t::GOSHNAR: + // todo check if player is the most killer of Goshnar and his aspects. + return false; + default: + std::string skillName = g_game().getSkillNameById(skill); + query = fmt::format( + "SELECT * FROM `players` WHERE `group_id` < {} AND `{}` > 10 ORDER BY `{}` DESC LIMIT 1", + static_cast(GROUP_TYPE_GAMEMASTER), skillName, skillName + ); + break; + } + + DBResult_ptr result = db.storeQuery(query); + if (!result) { + return false; + } + + auto resultValue = result->getNumber(fieldCheck); + g_logger().debug("top id: {}, player id: {}", resultValue, m_player.getGUID()); + + return resultValue == m_player.getGUID(); +} + +bool PlayerTitle::checkBestiary(const std::string &name, uint16_t race, bool isBoss /* = false*/, uint32_t amount) { + if (race == 0) { + if (name == "Executioner") { + // todo check if player has unlocked all bestiary + } else if (name == "Boss Executioner") { + // todo check if player has unlocked all bosses + } + return false; + } + if (isBoss && amount > 0) { + // todo check if this way, is calculating by boss race + return m_player.getBestiaryKillCount(race) >= amount; + } + return m_player.isCreatureUnlockedOnTaskHunting(g_monsters().getMonsterTypeByRaceId(race, isBoss)); +} + +bool PlayerTitle::checkLoginStreak(uint32_t amount) { + auto streakKV = m_player.kv()->scoped("daily-reward")->get("streak"); + return streakKV && streakKV.has_value() && static_cast(streakKV->getNumber()) >= amount; +} + +bool PlayerTitle::checkTask(uint32_t amount) { + return m_player.getTaskHuntingPoints() >= amount; +} + +bool PlayerTitle::checkMap(uint32_t amount) { + // todo cyclopledia + return false; +} + +bool PlayerTitle::checkOther(const std::string &name) { + if (name == "Guild Leader") { + auto rank = m_player.getGuildRank(); + return rank && rank->level == 3; + } else if (name == "Proconsul of Iksupan") { + // Win Ancient Aucar Outfits complete so fight with Atab and be teleported to the arena. + } else if (name == "Admirer of the Crown") { + // Complete the Royal Costume Outfits. + return m_player.canWear(1457, 3) && m_player.canWear(1456, 3); + } else if (name == "Big Spender") { + // Unlocked the full Golden Outfit. + return m_player.canWear(1211, 3) && m_player.canWear(1210, 3); + } else if (name == "Challenger of the Iks") { + // Defeat Ahau while equipping a Broken Iks Headpiece, a Broken Iks Cuirass, some Broken Iks Faulds and Broken Iks Sandals + return m_player.getBestiaryKillCount(2346) >= 1; + } else if (name == "Royal Bounacean Advisor") { + // Complete the Galthen and the Lost Queen quest line + // Win Royal Bounacean Outfit + return m_player.canWear(1437, 3) && m_player.canWear(1436, 3); + } else if (name == "Aeternal") { + // Unlocked by 10-year-old characters. + } else if (name == "Robinson Crusoe") { + // Visit Schrödinger's Island. + } else if (name == "Chompmeister") { + // Complete all Jean Pierre's dishes in Hot Cuisine Quest. + } else if (name == "Bringer of Rain") { + // Clear wave 100 in the Tibiadrome. + } else if (name == "Beastly") { + // Reached 2000 charm points + return m_player.getCharmPoints() >= 2000; + } else if (name == "Midnight Hunter") { + // Kill a certain amount of Midnight Panthers. + // (The exact number is yet to be confirmed but is at least 21 and at most 28 panthers.) + return m_player.getBestiaryKillCount(698) >= 25; + } else if (name == "Ratinator") { + // Kill 10,000 Cave Rats. + return m_player.getBestiaryKillCount(56) >= 10000; + } else if (name == "Doomsday Nemesis") { + // Kill Gaz'haragoth one time. + return m_player.getBestiaryKillCount(1003) >= 1; + } else if (name == "Hero of Bounac") { + // Complete The Order of the Lion Quest. + } else if (name == "King of Demon") { + // Defeat Morshabaal 5 times. + return m_player.getBestiaryKillCount(2118) >= 5; + } else if (name == "Planegazer") { + // Kill Planestrider in Opticording Sphere Quest. + } else if (name == "Time Traveller") { + // Complete 25 Years of Tibia Quest. + } else if (name == "Truly Boss") { + return m_player.getBossPoints() >= 15000; + } + return false; +} diff --git a/src/creatures/players/cyclopedia/player_title.hpp b/src/creatures/players/cyclopedia/player_title.hpp new file mode 100644 index 00000000000..0530fcc083d --- /dev/null +++ b/src/creatures/players/cyclopedia/player_title.hpp @@ -0,0 +1,105 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#include + +#include "creatures/creatures_definitions.hpp" +#include "enums/player_cyclopedia.hpp" +#include "enums/account_group_type.hpp" + +class Player; +class KV; + +struct Title { + uint8_t m_id = 0; + CyclopediaTitle_t m_type = CyclopediaTitle_t::NOTHING; + std::string m_maleName; + std::string m_femaleName; + std::string m_description; + uint32_t m_amount = 0; + bool m_permanent = false; + uint8_t m_skill = 0; + uint16_t m_race = 0; + + Title() = default; + + Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, uint32_t amount, bool permanent) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(), m_description(std::move(description)), + m_amount(amount), m_permanent(permanent), m_skill(0), m_race(0) { } + + Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, uint32_t amount, bool permanent, std::string femaleName) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)), + m_amount(amount), m_permanent(permanent), m_skill(0), m_race(0) { } + + Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string femaleName, std::string description, uint8_t skill) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)), + m_amount(0), m_permanent(false), m_skill(skill), m_race(0) { } + + Title(uint8_t id, CyclopediaTitle_t type, uint16_t race, std::string maleName, std::string femaleName, std::string description) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)), + m_amount(0), m_permanent(false), m_skill(0), m_race(race) { } + + Title(uint8_t id, CyclopediaTitle_t type, uint16_t race, std::string maleName, std::string femaleName, std::string description, uint32_t amount, bool permanent) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(std::move(femaleName)), m_description(std::move(description)), + m_amount(amount), m_permanent(permanent), m_skill(0), m_race(race) { } + + Title(uint8_t id, CyclopediaTitle_t type, std::string maleName, std::string description, bool permanent) : + m_id(id), m_type(type), m_maleName(std::move(maleName)), m_femaleName(), m_description(std::move(description)), + m_amount(0), m_permanent(permanent), m_skill(0), m_race(0) { } + + bool operator==(const Title &other) const { + return m_id == other.m_id; + } +}; + +namespace std { + template <> + struct hash { + std::size_t operator()(const Title &t) const { + return hash<uint8_t>()(t.m_id); + } + }; +} + +class PlayerTitle { +public: + explicit PlayerTitle(Player &player); + + [[nodiscard]] bool isTitleUnlocked(uint8_t id) const; + bool manage(bool canAdd, uint8_t id, uint32_t timestamp = 0); + void remove(const Title &title); + const std::vector<std::pair<Title, uint32_t>> &getUnlockedTitles(); + [[nodiscard]] uint8_t getCurrentTitle() const; + void setCurrentTitle(uint8_t id); + std::string getCurrentTitleName(); + static const std::string &getNameBySex(PlayerSex_t sex, const std::string &male, const std::string &female); + void checkAndUpdateNewTitles(); + void loadUnlockedTitles(); + const std::shared_ptr<KV> &getUnlockedKV(); + + // Title Calculate Functions + bool checkGold(uint32_t amount); + bool checkMount(uint32_t amount); + bool checkOutfit(uint32_t amount); + bool checkLevel(uint32_t amount); + bool checkHighscore(uint8_t skill); + bool checkBestiary(const std::string &name, uint16_t race, bool isBoss = false, uint32_t amount = 0); + bool checkLoginStreak(uint32_t amount); + bool checkTask(uint32_t amount); + bool checkMap(uint32_t amount); + bool checkOther(const std::string &name); + +private: + // {title ID, time when it was unlocked} + std::shared_ptr<KV> m_titleUnlockedKV; + std::vector<std::pair<Title, uint32_t>> m_titlesUnlocked; + Player &m_player; +}; diff --git a/src/creatures/players/grouping/familiars.cpp b/src/creatures/players/grouping/familiars.cpp index 538519685c3..a922013f19b 100644 --- a/src/creatures/players/grouping/familiars.cpp +++ b/src/creatures/players/grouping/familiars.cpp @@ -14,6 +14,13 @@ #include "utils/pugicast.hpp" #include "utils/tools.hpp" +bool Familiars::reload() { + for (auto &familiarsVector : familiars) { + familiarsVector.clear(); + } + return loadFromXml(); +} + bool Familiars::loadFromXml() { pugi::xml_document doc; auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/familiars.xml"; @@ -47,13 +54,13 @@ bool Familiars::loadFromXml() { continue; } - familiars[vocation].emplace_back( + familiars[vocation].emplace_back(std::make_shared<Familiar>( familiarsNode.attribute("name").as_string(), pugi::cast<uint16_t>(lookTypeAttribute.value()), familiarsNode.attribute("premium").as_bool(), familiarsNode.attribute("unlocked").as_bool(true), familiarsNode.attribute("type").as_string() - ); + )); } for (uint16_t vocation = VOCATION_NONE; vocation <= VOCATION_LAST; ++vocation) { familiars[vocation].shrink_to_fit(); @@ -61,11 +68,12 @@ bool Familiars::loadFromXml() { return true; } -const Familiar* Familiars::getFamiliarByLookType(uint16_t vocation, uint16_t lookType) const { - for (const Familiar &familiar : familiars[vocation]) { - if (familiar.lookType == lookType) { - return &familiar; - } +std::shared_ptr<Familiar> Familiars::getFamiliarByLookType(uint16_t vocation, uint16_t lookType) const { + if (auto it = std::find_if(familiars[vocation].begin(), familiars[vocation].end(), [lookType](auto familiar_it) { + return familiar_it->lookType == lookType; + }); + it != familiars[vocation].end()) { + return *it; } return nullptr; } diff --git a/src/creatures/players/grouping/familiars.hpp b/src/creatures/players/grouping/familiars.hpp index aae9b34e227..8f553af9fbe 100644 --- a/src/creatures/players/grouping/familiars.hpp +++ b/src/creatures/players/grouping/familiars.hpp @@ -9,20 +9,42 @@ #pragma once -#include "declarations.hpp" #include "lib/di/container.hpp" +struct FamiliarEntry { + constexpr explicit FamiliarEntry(uint16_t initLookType) : + lookType(initLookType) { } + uint16_t lookType; +}; + +struct Familiar { + Familiar(std::string initName, uint16_t initLookType, bool initPremium, bool initUnlocked, std::string initType) : + name(std::move(initName)), lookType(initLookType), + premium(initPremium), unlocked(initUnlocked), + type(std::move(initType)) { } + + std::string name; + uint16_t lookType; + bool premium; + bool unlocked; + std::string type; +}; + class Familiars { public: static Familiars &getInstance() { return inject<Familiars>(); } + bool loadFromXml(); - const std::vector<Familiar> &getFamiliars(uint16_t vocation) const { + bool reload(); + + std::vector<std::shared_ptr<Familiar>> &getFamiliars(uint16_t vocation) { return familiars[vocation]; } - const Familiar* getFamiliarByLookType(uint16_t vocation, uint16_t lookType) const; + + [[nodiscard]] std::shared_ptr<Familiar> getFamiliarByLookType(uint16_t vocation, uint16_t lookType) const; private: - std::vector<Familiar> familiars[VOCATION_LAST + 1]; + std::vector<std::shared_ptr<Familiar>> familiars[VOCATION_LAST + 1]; }; diff --git a/src/creatures/players/grouping/groups.cpp b/src/creatures/players/grouping/groups.cpp index 40dd13bc385..27ae68d9fd4 100644 --- a/src/creatures/players/grouping/groups.cpp +++ b/src/creatures/players/grouping/groups.cpp @@ -93,17 +93,18 @@ bool Groups::load() { // Parsing group flags parseGroupFlags(group, groupNode); - groups_vector.push_back(group); + groups_vector.emplace_back(std::make_shared<Group>(group)); } groups_vector.shrink_to_fit(); return true; } -Group* Groups::getGroup(uint16_t id) { - for (Group &group : groups_vector) { - if (group.id == id) { - return &group; - } +std::shared_ptr<Group> Groups::getGroup(uint16_t id) { + if (auto it = std::find_if(groups_vector.begin(), groups_vector.end(), [id](auto group_it) { + return group_it->id == id; + }); + it != groups_vector.end()) { + return *it; } return nullptr; } diff --git a/src/creatures/players/grouping/groups.hpp b/src/creatures/players/grouping/groups.hpp index 3d74564173d..d76914e2632 100644 --- a/src/creatures/players/grouping/groups.hpp +++ b/src/creatures/players/grouping/groups.hpp @@ -26,11 +26,11 @@ class Groups { static PlayerFlags_t getFlagFromNumber(uint8_t value); bool reload() const; bool load(); - Group* getGroup(uint16_t id); - std::vector<Group> &getGroups() { + std::shared_ptr<Group> getGroup(uint16_t id); + std::vector<std::shared_ptr<Group>> &getGroups() { return groups_vector; } private: - std::vector<Group> groups_vector; + std::vector<std::shared_ptr<Group>> groups_vector; }; diff --git a/src/creatures/players/grouping/guild.cpp b/src/creatures/players/grouping/guild.cpp index aca512f28e3..bbd662d1a1d 100644 --- a/src/creatures/players/grouping/guild.cpp +++ b/src/creatures/players/grouping/guild.cpp @@ -14,7 +14,7 @@ void Guild::addMember(const std::shared_ptr<Player> &player) { membersOnline.push_back(player); - for (auto member : getMembersOnline()) { + for (const auto &member : getMembersOnline()) { g_game().updatePlayerHelpers(member); } } diff --git a/src/creatures/players/grouping/guild.hpp b/src/creatures/players/grouping/guild.hpp index 834eb03252c..82b0a7367ea 100644 --- a/src/creatures/players/grouping/guild.hpp +++ b/src/creatures/players/grouping/guild.hpp @@ -32,9 +32,10 @@ class Guild : public Bankable { void addMember(const std::shared_ptr<Player> &player); void removeMember(const std::shared_ptr<Player> &player); - bool isGuild() { + bool isGuild() override { return true; } + void setOnline(bool value) override { online = value; } diff --git a/src/creatures/players/grouping/party.cpp b/src/creatures/players/grouping/party.cpp index 880fc77594f..76f1d955f10 100644 --- a/src/creatures/players/grouping/party.cpp +++ b/src/creatures/players/grouping/party.cpp @@ -7,6 +7,8 @@ * Website: https://docs.opentibiabr.com/ */ +#include <utility> + #include "pch.hpp" #include "creatures/players/grouping/party.hpp" @@ -47,23 +49,23 @@ void Party::disband() { currentLeader->sendCreatureSkull(currentLeader); currentLeader->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); - for (auto invitee : getInvitees()) { + for (const auto &invitee : getInvitees()) { invitee->removePartyInvitation(getParty()); currentLeader->sendCreatureShield(invitee); } inviteList.clear(); auto members = getMembers(); - for (auto member : members) { + for (const auto &member : members) { member->setParty(nullptr); member->sendClosePrivate(CHANNEL_PARTY); member->sendTextMessage(MESSAGE_PARTY_MANAGEMENT, "Your party has been disbanded."); } - for (auto member : members) { + for (const auto &member : members) { g_game().updatePlayerShield(member); - for (auto otherMember : members) { + for (const auto &otherMember : members) { otherMember->sendCreatureSkull(member); } @@ -132,7 +134,7 @@ bool Party::leaveParty(std::shared_ptr<Player> player) { g_game().updatePlayerShield(player); g_game().updatePlayerHelpers(player); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->sendCreatureSkull(player); player->sendPlayerPartyIcons(member); member->sendPartyCreatureUpdate(player); @@ -185,12 +187,12 @@ bool Party::passPartyLeadership(std::shared_ptr<Player> player) { updateSharedExperience(); updateTrackerAnalyzer(); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->sendPartyCreatureShield(oldLeader); member->sendPartyCreatureShield(player); } - for (auto invitee : getInvitees()) { + for (const auto &invitee : getInvitees()) { invitee->sendCreatureShield(oldLeader); invitee->sendCreatureShield(player); } @@ -231,7 +233,7 @@ bool Party::joinParty(const std::shared_ptr<Player> &player) { g_game().updatePlayerShield(player); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->sendCreatureSkull(player); member->sendPlayerPartyIcons(player); player->sendPlayerPartyIcons(member); @@ -282,7 +284,7 @@ bool Party::removeInvite(const std::shared_ptr<Player> &player, bool removeFromP if (empty()) { disband(); } else { - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { g_game().updatePlayerHelpers(member); } @@ -332,7 +334,7 @@ bool Party::invitePlayer(const std::shared_ptr<Player> &player) { inviteList.push_back(player); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { g_game().updatePlayerHelpers(member); } @@ -359,8 +361,8 @@ void Party::updateAllPartyIcons() { return; } auto members = getMembers(); - for (auto member : members) { - for (auto otherMember : members) { + for (const auto &member : members) { + for (const auto &otherMember : members) { member->sendPartyCreatureShield(otherMember); } @@ -376,14 +378,14 @@ void Party::broadcastPartyMessage(MessageClasses msgClass, const std::string &ms if (!leader) { return; } - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->sendTextMessage(msgClass, msg); } leader->sendTextMessage(msgClass, msg); if (sendToInvitations) { - for (auto invitee : getInvitees()) { + for (const auto &invitee : getInvitees()) { invitee->sendTextMessage(msgClass, msg); } } @@ -454,14 +456,14 @@ void Party::shareExperience(uint64_t experience, std::shared_ptr<Creature> targe g_events().eventPartyOnShareExperience(getParty(), shareExperience); g_callbacks().executeCallback(EventCallback_t::partyOnShareExperience, &EventCallback::partyOnShareExperience, getParty(), shareExperience); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->onGainSharedExperience(shareExperience, target); } leader->onGainSharedExperience(shareExperience, target); } bool Party::canUseSharedExperience(std::shared_ptr<Player> player) { - return getMemberSharedExperienceStatus(player) == SHAREDEXP_OK; + return getMemberSharedExperienceStatus(std::move(player)) == SHAREDEXP_OK; } SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr<Player> player) { @@ -473,7 +475,6 @@ SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr<Player> return SHAREDEXP_EMPTYPARTY; } - uint32_t highestLevel = getHighestLevel(); uint32_t minLevel = getMinLevel(); if (player->getLevel() < minLevel) { return SHAREDEXP_LEVELDIFFTOOLARGE; @@ -491,6 +492,10 @@ SharedExpStatus_t Party::getMemberSharedExperienceStatus(std::shared_ptr<Player> return SHAREDEXP_OK; } +float Party::shareRangeMultiplier() const { + return g_configManager().getFloat(PARTY_SHARE_RANGE_MULTIPLIER, __FUNCTION__); +} + uint32_t Party::getHighestLevel() { auto leader = getLeader(); if (!leader) { @@ -498,7 +503,7 @@ uint32_t Party::getHighestLevel() { } uint32_t highestLevel = leader->getLevel(); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { if (member->getLevel() > highestLevel) { highestLevel = member->getLevel(); } @@ -507,7 +512,7 @@ uint32_t Party::getHighestLevel() { } uint32_t Party::getMinLevel() { - return static_cast<uint32_t>(std::ceil((static_cast<float>(getHighestLevel()) * 2) / 3)); + return static_cast<uint32_t>(std::ceil(static_cast<float>(getHighestLevel()) / shareRangeMultiplier())); } uint32_t Party::getLowestLevel() { @@ -516,7 +521,7 @@ uint32_t Party::getLowestLevel() { return 0; } uint32_t lowestLevel = leader->getLevel(); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { if (member->getLevel() < lowestLevel) { lowestLevel = member->getLevel(); } @@ -525,7 +530,7 @@ uint32_t Party::getLowestLevel() { } uint32_t Party::getMaxLevel() { - return static_cast<uint32_t>(std::floor((static_cast<float>(getLowestLevel()) * 3) / 2)); + return static_cast<uint32_t>(std::floor(static_cast<float>(getLowestLevel()) * shareRangeMultiplier())); } bool Party::isPlayerActive(std::shared_ptr<Player> player) { @@ -533,7 +538,6 @@ bool Party::isPlayerActive(std::shared_ptr<Player> player) { if (it == ticksMap.end()) { return false; } - uint64_t timeDiff = OTSYS_TIME() - it->second; return timeDiff <= 2 * 60 * 1000; } @@ -548,7 +552,7 @@ SharedExpStatus_t Party::getSharedExperienceStatus() { return leaderStatus; } - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { SharedExpStatus_t memberStatus = getMemberSharedExperienceStatus(member); if (memberStatus != SHAREDEXP_OK) { return memberStatus; @@ -617,7 +621,7 @@ void Party::updatePlayerStatus(std::shared_ptr<Player> player) { } int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE, __FUNCTION__); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { showPlayerStatus(player, member, true); @@ -641,7 +645,7 @@ void Party::updatePlayerStatus(std::shared_ptr<Player> player, const Position &o int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE, __FUNCTION__); if (maxDistance != 0) { - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { bool condition1 = (Position::getDistanceX(oldPos, member->getPosition()) <= maxDistance && Position::getDistanceY(oldPos, member->getPosition()) <= maxDistance); bool condition2 = (Position::getDistanceX(newPos, member->getPosition()) <= maxDistance && Position::getDistanceY(newPos, member->getPosition()) <= maxDistance); if (condition1 && !condition2) { @@ -670,7 +674,7 @@ void Party::updatePlayerHealth(std::shared_ptr<Player> player, std::shared_ptr<C int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE, __FUNCTION__); auto playerPosition = player->getPosition(); auto leaderPosition = leader->getPosition(); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { auto memberPosition = member->getPosition(); bool condition = (maxDistance == 0 || (Position::getDistanceX(playerPosition, memberPosition) <= maxDistance && Position::getDistanceY(playerPosition, memberPosition) <= maxDistance)); if (condition) { @@ -690,7 +694,7 @@ void Party::updatePlayerMana(std::shared_ptr<Player> player, uint8_t manaPercent } int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE, __FUNCTION__); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerMana(player, manaPercent); @@ -709,7 +713,7 @@ void Party::updatePlayerVocation(std::shared_ptr<Player> player) { } int32_t maxDistance = g_configManager().getNumber(PARTY_LIST_MAX_DISTANCE, __FUNCTION__); - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { bool condition = (maxDistance == 0 || (Position::getDistanceX(player->getPosition(), member->getPosition()) <= maxDistance && Position::getDistanceY(player->getPosition(), member->getPosition()) <= maxDistance)); if (condition) { member->sendPartyPlayerVocation(player); @@ -727,7 +731,7 @@ void Party::updateTrackerAnalyzer() { return; } - for (auto member : getMembers()) { + for (const auto &member : getMembers()) { member->updatePartyTrackerAnalyzer(); } diff --git a/src/creatures/players/grouping/party.hpp b/src/creatures/players/grouping/party.hpp index a356d1a032b..10663a278bf 100644 --- a/src/creatures/players/grouping/party.hpp +++ b/src/creatures/players/grouping/party.hpp @@ -105,7 +105,7 @@ class Party : public SharedObject { void reloadPrices(); std::shared_ptr<PartyAnalyzer> getPlayerPartyAnalyzerStruct(uint32_t playerId) const { - if (auto it = std::find_if(membersData.begin(), membersData.end(), [playerId](const std::shared_ptr<PartyAnalyzer> preyIt) { + if (auto it = std::find_if(membersData.begin(), membersData.end(), [playerId](const std::shared_ptr<PartyAnalyzer> &preyIt) { return preyIt->id == playerId; }); it != membersData.end()) { @@ -133,6 +133,7 @@ class Party : public SharedObject { uint32_t getLowestLevel(); uint32_t getMinLevel(); uint32_t getMaxLevel(); + float shareRangeMultiplier() const; std::map<uint32_t, int64_t> ticksMap; diff --git a/src/creatures/players/grouping/team_finder.hpp b/src/creatures/players/grouping/team_finder.hpp index 123ce7c07d8..9fafbd03227 100644 --- a/src/creatures/players/grouping/team_finder.hpp +++ b/src/creatures/players/grouping/team_finder.hpp @@ -1,3 +1,5 @@ +#include <utility> + /** * Canary - A free and open-source MMORPG server emulator * Copyright (©) 2019-2024 OpenTibiaBR <opentibiabr@outlook.com> @@ -31,7 +33,7 @@ class TeamFinder { hunt_area(initHunt_area), questID(initQuestID), leaderGuid(initLeaderGuid), - membersMap(initMembersMap) { } + membersMap(std::move(initMembersMap)) { } virtual ~TeamFinder() = default; uint16_t minLevel = 0; diff --git a/src/creatures/players/highscore_category.hpp b/src/creatures/players/highscore_category.hpp index b387199f315..71da6b76ec6 100644 --- a/src/creatures/players/highscore_category.hpp +++ b/src/creatures/players/highscore_category.hpp @@ -10,8 +10,8 @@ #pragma once struct HighscoreCategory { - HighscoreCategory(const std::string &name, uint8_t id) : - m_name(name), + HighscoreCategory(std::string name, uint8_t id) : + m_name(std::move(name)), m_id(id) { } std::string m_name; diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 75e5b5ef2af..4109eb77472 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -16,6 +16,8 @@ #include "creatures/players/player.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" #include "creatures/players/storages/storages.hpp" #include "game/game.hpp" #include "game/modal_window/modal_window.hpp" @@ -47,12 +49,15 @@ Player::Player(ProtocolGame_ptr p) : lastPong(lastPing), inbox(std::make_shared<Inbox>(ITEM_INBOX)), client(std::move(p)) { + m_playerVIP = std::make_unique<PlayerVIP>(*this); m_wheelPlayer = std::make_unique<PlayerWheel>(*this); m_playerAchievement = std::make_unique<PlayerAchievement>(*this); + m_playerBadge = std::make_unique<PlayerBadge>(*this); + m_playerTitle = std::make_unique<PlayerTitle>(*this); } Player::~Player() { - for (std::shared_ptr<Item> item : inventory) { + for (const std::shared_ptr<Item> &item : inventory) { if (item) { item->resetParent(); item->stopDecaying(); @@ -72,7 +77,7 @@ Player::~Player() { } bool Player::setVocation(uint16_t vocId) { - Vocation* voc = g_vocations().getVocation(vocId); + const auto &voc = g_vocations().getVocation(vocId); if (!voc) { return false; } @@ -117,9 +122,10 @@ std::string Player::getDescription(int32_t lookDistance) { std::ostringstream s; std::string subjectPronoun = getSubjectPronoun(); capitalizeWords(subjectPronoun); + auto playerTitle = title()->getCurrentTitle() == 0 ? "" : (", " + title()->getCurrentTitleName()); if (lookDistance == -1) { - s << "yourself."; + s << "yourself" << playerTitle << "."; if (group->access) { s << " You are " << group->name << '.'; @@ -129,7 +135,7 @@ std::string Player::getDescription(int32_t lookDistance) { s << " You have no vocation."; } - if (loyaltyTitle.length() != 0) { + if (!loyaltyTitle.empty()) { s << " You are a " << loyaltyTitle << "."; } @@ -141,9 +147,8 @@ std::string Player::getDescription(int32_t lookDistance) { if (!group->access) { s << " (Level " << level << ')'; } - s << '.'; - s << " " << subjectPronoun; + s << playerTitle << ". " << subjectPronoun; if (group->access) { s << " " << getSubjectVerb() << " " << group->name << '.'; @@ -153,7 +158,7 @@ std::string Player::getDescription(int32_t lookDistance) { s << " has no vocation."; } - if (loyaltyTitle.length() != 0) { + if (!loyaltyTitle.empty()) { std::string article = "a"; if (loyaltyTitle[0] == 'A' || loyaltyTitle[0] == 'E' || loyaltyTitle[0] == 'I' || loyaltyTitle[0] == 'O' || loyaltyTitle[0] == 'U') { article = "an"; @@ -628,13 +633,27 @@ phmap::flat_hash_map<uint8_t, std::shared_ptr<Item>> Player::getAllSlotItems() c return itemMap; } +phmap::flat_hash_map<Blessings_t, std::string> Player::getBlessingNames() const { + static phmap::flat_hash_map<Blessings_t, std::string> blessingNames = { + { TWIST_OF_FATE, "Twist of Fate" }, + { WISDOM_OF_SOLITUDE, "The Wisdom of Solitude" }, + { SPARK_OF_THE_PHOENIX, "The Spark of the Phoenix" }, + { FIRE_OF_THE_SUNS, "The Fire of the Suns" }, + { SPIRITUAL_SHIELDING, "The Spiritual Shielding" }, + { EMBRACE_OF_TIBIA, "The Embrace of Tibia" }, + { BLOOD_OF_THE_MOUNTAIN, "Blood of the Mountain" }, + { HEARTH_OF_THE_MOUNTAIN, "Heart of the Mountain" }, + }; + return blessingNames; +} + void Player::setTraining(bool value) { for (const auto &[key, player] : g_game().getPlayers()) { if (!this->isInGhostMode() || player->isAccessPlayer()) { - player->notifyStatusChange(static_self_cast<Player>(), value ? VIPSTATUS_TRAINING : VIPSTATUS_ONLINE, false); + player->vip()->notifyStatusChange(static_self_cast<Player>(), value ? VipStatus_t::Training : VipStatus_t::Online, false); } } - this->statusVipList = VIPSTATUS_TRAINING; + vip()->setStatus(VipStatus_t::Training); setExerciseTraining(value); } @@ -1317,7 +1336,7 @@ void Player::getRewardList(std::vector<uint64_t> &rewards) const { std::vector<std::shared_ptr<Item>> Player::getRewardsFromContainer(std::shared_ptr<Container> container) const { std::vector<std::shared_ptr<Item>> rewardItemsVector; if (container) { - for (auto item : container->getItems(false)) { + for (const auto &item : container->getItems(false)) { if (item->getID() == ITEM_REWARD_CONTAINER) { auto items = getRewardsFromContainer(item->getContainer()); rewardItemsVector.insert(rewardItemsVector.end(), items.begin(), items.end()); @@ -1736,7 +1755,7 @@ void Player::onCreatureAppear(std::shared_ptr<Creature> creature, bool isLogin) offlineTime = 0; } - for (std::shared_ptr<Condition> condition : getMuteConditions()) { + for (const std::shared_ptr<Condition> &condition : getMuteConditions()) { condition->setTicks(condition->getTicks() - (offlineTime * 1000)); if (condition->getTicks() <= 0) { removeCondition(condition); @@ -1843,6 +1862,13 @@ void Player::onRemoveCreature(std::shared_ptr<Creature> creature, bool isLogout) Creature::onRemoveCreature(creature, isLogout); if (auto player = getPlayer(); player == creature) { + for (uint8_t slot = CONST_SLOT_FIRST; slot <= CONST_SLOT_LAST; ++slot) { + const auto item = inventory[slot]; + if (item) { + g_moveEvents().onPlayerDeEquip(getPlayer(), item, static_cast<Slots_t>(slot)); + } + } + if (isLogout) { if (m_party) { m_party->leaveParty(player); @@ -1925,7 +1951,8 @@ void Player::onWalk(Direction &dir) { Creature::onWalk(dir); setNextActionTask(nullptr); - setNextAction(OTSYS_TIME() + getStepDuration(dir)); + + g_callbacks().executeCallback(EventCallback_t::playerOnWalk, &EventCallback::playerOnWalk, getPlayer(), dir); } void Player::onCreatureMove(const std::shared_ptr<Creature> &creature, const std::shared_ptr<Tile> &newTile, const Position &newPos, const std::shared_ptr<Tile> &oldTile, const Position &oldPos, bool teleport) { @@ -2213,7 +2240,7 @@ uint32_t Player::isMuted() const { } int32_t muteTicks = 0; - for (std::shared_ptr<Condition> condition : conditions) { + for (const std::shared_ptr<Condition> &condition : conditions) { if (condition->getType() == CONDITION_MUTED && condition->getTicks() > muteTicks) { muteTicks = condition->getTicks(); } @@ -2382,7 +2409,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool if (!spectators.empty()) { message.type = MESSAGE_EXPERIENCE_OTHERS; message.text = getName() + " gained " + expString; - for (std::shared_ptr<Creature> spectator : spectators) { + for (const std::shared_ptr<Creature> &spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } @@ -2393,7 +2420,7 @@ void Player::addExperience(std::shared_ptr<Creature> target, uint64_t exp, bool ++level; // Player stats gain for vocations level <= 8 if (vocation->getId() != VOCATION_NONE && level <= 8) { - const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE); + const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE); healthMax += noneVocation->getHPGain(); health += noneVocation->getHPGain(); manaMax += noneVocation->getManaGain(); @@ -2475,7 +2502,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) { if (!spectators.empty()) { message.type = MESSAGE_EXPERIENCE_OTHERS; message.text = getName() + " lost " + expString; - for (std::shared_ptr<Creature> spectator : spectators) { + for (const std::shared_ptr<Creature> &spectator : spectators) { spectator->getPlayer()->sendTextMessage(message); } } @@ -2488,7 +2515,7 @@ void Player::removeExperience(uint64_t exp, bool sendText /* = false*/) { --level; // Player stats loss for vocations level <= 8 if (vocation->getId() != VOCATION_NONE && level <= 8) { - const Vocation* noneVocation = g_vocations().getVocation(VOCATION_NONE); + const auto &noneVocation = g_vocations().getVocation(VOCATION_NONE); healthMax = std::max<int32_t>(0, healthMax - noneVocation->getHPGain()); manaMax = std::max<int32_t>(0, manaMax - noneVocation->getManaGain()); capacity = std::max<int32_t>(0, capacity - noneVocation->getCapGain()); @@ -2918,6 +2945,7 @@ bool Player::spawn() { getParent()->postAddNotification(static_self_cast<Player>(), nullptr, 0); g_game().addCreatureCheck(static_self_cast<Player>()); g_game().addPlayer(static_self_cast<Player>()); + static_self_cast<Player>()->onChangeZone(static_self_cast<Player>()->getZoneType()); return true; } @@ -2965,7 +2993,7 @@ void Player::despawn() { // show player as pending for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(static_self_cast<Player>(), VIPSTATUS_PENDING, false); + player->vip()->notifyStatusChange(static_self_cast<Player>(), VipStatus_t::Pending, false); } setDead(true); @@ -3019,13 +3047,13 @@ void Player::removeList() { g_game().removePlayer(static_self_cast<Player>()); for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(static_self_cast<Player>(), VIPSTATUS_OFFLINE); + player->vip()->notifyStatusChange(static_self_cast<Player>(), VipStatus_t::Offline); } } void Player::addList() { for (const auto &[key, player] : g_game().getPlayers()) { - player->notifyStatusChange(static_self_cast<Player>(), this->statusVipList); + player->vip()->notifyStatusChange(static_self_cast<Player>(), vip()->getStatus()); } g_game().addPlayer(static_self_cast<Player>()); @@ -3040,82 +3068,6 @@ void Player::removePlayer(bool displayEffect, bool forced /*= true*/) { } } -void Player::notifyStatusChange(std::shared_ptr<Player> loginPlayer, VipStatus_t status, bool message) const { - if (!client) { - return; - } - - if (!VIPList.contains(loginPlayer->guid)) { - return; - } - - client->sendUpdatedVIPStatus(loginPlayer->guid, status); - - if (message) { - if (status == VIPSTATUS_ONLINE) { - client->sendTextMessage(TextMessage(MESSAGE_FAILURE, loginPlayer->getName() + " has logged in.")); - } else if (status == VIPSTATUS_OFFLINE) { - client->sendTextMessage(TextMessage(MESSAGE_FAILURE, loginPlayer->getName() + " has logged out.")); - } - } -} - -bool Player::removeVIP(uint32_t vipGuid) { - if (!VIPList.erase(vipGuid)) { - return false; - } - - VIPList.erase(vipGuid); - if (account) { - IOLoginData::removeVIPEntry(account->getID(), vipGuid); - } - - return true; -} - -bool Player::addVIP(uint32_t vipGuid, const std::string &vipName, VipStatus_t status) { - if (VIPList.size() >= getMaxVIPEntries() || VIPList.size() == 200) { // max number of buddies is 200 in 9.53 - sendTextMessage(MESSAGE_FAILURE, "You cannot add more buddies."); - return false; - } - - if (!VIPList.insert(vipGuid).second) { - sendTextMessage(MESSAGE_FAILURE, "This player is already in your list."); - return false; - } - - if (account) { - IOLoginData::addVIPEntry(account->getID(), vipGuid, "", 0, false); - } - - if (client) { - client->sendVIP(vipGuid, vipName, "", 0, false, status); - } - - return true; -} - -bool Player::addVIPInternal(uint32_t vipGuid) { - if (VIPList.size() >= getMaxVIPEntries() || VIPList.size() == 200) { // max number of buddies is 200 in 9.53 - return false; - } - - return VIPList.insert(vipGuid).second; -} - -bool Player::editVIP(uint32_t vipGuid, const std::string &description, uint32_t icon, bool notify) const { - auto it = VIPList.find(vipGuid); - if (it == VIPList.end()) { - return false; // player is not in VIP - } - - if (account) { - IOLoginData::editVIPEntry(account->getID(), vipGuid, description, icon, notify); - } - - return true; -} - // close container and its child containers void Player::autoCloseContainers(std::shared_ptr<Container> container) { std::vector<uint32_t> closeList; @@ -3271,13 +3223,6 @@ ReturnValue Player::queryAdd(int32_t index, const std::shared_ptr<Thing> &thing, case CONST_SLOT_LEFT: { if (item->isQuiver()) { ret = RETURNVALUE_CANNOTBEDRESSED; - } else if (slotPosition & SLOTP_LEFT) { - WeaponType_t type = item->getWeaponType(); - if (type == WEAPON_NONE || type == WEAPON_SHIELD || type == WEAPON_AMMO) { - ret = RETURNVALUE_CANNOTBEDRESSED; - } else { - ret = RETURNVALUE_NOERROR; - } } else if (slotPosition & SLOTP_TWO_HAND) { if (inventory[CONST_SLOT_RIGHT]) { WeaponType_t type = item->getWeaponType(); @@ -3290,6 +3235,13 @@ ReturnValue Player::queryAdd(int32_t index, const std::shared_ptr<Thing> &thing, } else { ret = RETURNVALUE_NOERROR; } + } else if (slotPosition & SLOTP_LEFT) { + WeaponType_t type = item->getWeaponType(); + if (type == WEAPON_NONE || type == WEAPON_SHIELD || type == WEAPON_AMMO) { + ret = RETURNVALUE_CANNOTBEDRESSED; + } else { + ret = RETURNVALUE_NOERROR; + } } else if (inventory[CONST_SLOT_RIGHT]) { std::shared_ptr<Item> rightItem = inventory[CONST_SLOT_RIGHT]; WeaponType_t type = item->getWeaponType(), rightType = rightItem->getWeaponType(); @@ -3533,7 +3485,7 @@ std::shared_ptr<Cylinder> Player::queryDestination(int32_t &index, const std::sh n--; } - for (std::shared_ptr<Item> tmpContainerItem : tmpContainer->getItemList()) { + for (const std::shared_ptr<Item> &tmpContainerItem : tmpContainer->getItemList()) { if (std::shared_ptr<Container> subContainer = tmpContainerItem->getContainer()) { containers.push_back(subContainer); } @@ -3544,7 +3496,7 @@ std::shared_ptr<Cylinder> Player::queryDestination(int32_t &index, const std::sh uint32_t n = 0; - for (std::shared_ptr<Item> tmpItem : tmpContainer->getItemList()) { + for (const std::shared_ptr<Item> &tmpItem : tmpContainer->getItemList()) { if (tmpItem == tradeItem) { continue; } @@ -3752,7 +3704,7 @@ uint32_t Player::getItemTypeCount(uint16_t itemId, int32_t subType /*= -1*/) con void Player::stashContainer(StashContainerList itemDict) { StashItemList stashItemDict; // ItemID - Count - for (auto it_dict : itemDict) { + for (const auto &it_dict : itemDict) { stashItemDict[(it_dict.first)->getID()] = it_dict.second; } @@ -3772,7 +3724,7 @@ void Player::stashContainer(StashContainerList itemDict) { uint32_t totalStowed = 0; std::ostringstream retString; uint16_t refreshDepotSearchOnItem = 0; - for (auto stashIterator : itemDict) { + for (const auto &stashIterator : itemDict) { uint16_t iteratorCID = (stashIterator.first)->getID(); if (g_game().internalRemoveItem(stashIterator.first, stashIterator.second) == RETURNVALUE_NOERROR) { addItemOnStash(iteratorCID, stashIterator.second); @@ -3858,7 +3810,7 @@ bool Player::removeItemOfType(uint16_t itemId, uint32_t amount, int32_t subType, bool Player::hasItemCountById(uint16_t itemId, uint32_t itemAmount, bool checkStash) const { uint32_t newCount = 0; // Check items from inventory - for (const auto item : getAllInventoryItems()) { + for (const auto &item : getAllInventoryItems()) { if (!item || item->getID() != itemId) { continue; } @@ -3889,7 +3841,7 @@ bool Player::removeItemCountById(uint16_t itemId, uint32_t itemAmount, bool remo uint32_t amountToRemove = itemAmount; // Check items from inventory - for (auto item : getAllInventoryItems()) { + for (const auto &item : getAllInventoryItems()) { if (!item || item->getID() != itemId) { continue; } @@ -3913,7 +3865,7 @@ bool Player::removeItemCountById(uint16_t itemId, uint32_t itemAmount, bool remo return false; } -ItemsTierCountList Player::getInventoryItemsId() const { +ItemsTierCountList Player::getInventoryItemsId(bool ignoreStoreInbox /* false */) const { ItemsTierCountList itemMap; for (int32_t i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; i++) { std::shared_ptr<Item> item = inventory[i]; @@ -3921,8 +3873,14 @@ ItemsTierCountList Player::getInventoryItemsId() const { continue; } - (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); - if (std::shared_ptr<Container> container = item->getContainer()) { + const bool isStoreInbox = item->getID() == ITEM_STORE_INBOX; + + if (!isStoreInbox) { + (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); + } + + const auto &container = item->getContainer(); + if (container && (!isStoreInbox || !ignoreStoreInbox)) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { auto containerItem = *it; (itemMap[containerItem->getID()])[containerItem->getTier()] += Item::countByType(containerItem, -1); @@ -4021,6 +3979,48 @@ double_t Player::calculateDamageReduction(double_t currentTotal, int16_t resista return (100 - currentTotal) / 100.0 * resistance + currentTotal; } +ItemsTierCountList Player::getStoreInboxItemsId() const { + ItemsTierCountList itemMap; + const auto &container = getStoreInbox(); + if (container) { + for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { + std::shared_ptr<Item> item = *it; + (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); + } + } + + return itemMap; +} + +ItemsTierCountList Player::getDepotChestItemsId() const { + ItemsTierCountList itemMap; + + for (const auto &[index, depot] : depotChests) { + const std::shared_ptr<Container> &container = depot->getContainer(); + for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { + std::shared_ptr<Item> item = *it; + (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); + } + } + + return itemMap; +} + +ItemsTierCountList Player::getDepotInboxItemsId() const { + ItemsTierCountList itemMap; + + const std::shared_ptr<Inbox> &inbox = getInbox(); + const std::shared_ptr<Container> &container = inbox->getContainer(); + if (container) { + for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { + const auto &item = *it; + (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); + } + } + + return itemMap; +} + std::vector<std::shared_ptr<Item>> Player::getAllInventoryItems(bool ignoreEquiped /*= false*/, bool ignoreItemWithTier /* false*/) const { std::vector<std::shared_ptr<Item>> itemVector; for (int i = CONST_SLOT_FIRST; i <= CONST_SLOT_LAST; ++i) { @@ -4047,6 +4047,35 @@ std::vector<std::shared_ptr<Item>> Player::getAllInventoryItems(bool ignoreEquip return itemVector; } +std::vector<std::shared_ptr<Item>> Player::getEquippedAugmentItemsByType(Augment_t augmentType) const { + std::vector<std::shared_ptr<Item>> equippedAugmentItemsByType; + const auto equippedAugmentItems = getEquippedItems(); + + for (const auto &item : equippedAugmentItems) { + for (auto &augment : item->getAugments()) { + if (augment->type == augmentType) { + equippedAugmentItemsByType.push_back(item); + } + } + } + + return equippedAugmentItemsByType; +} + +std::vector<std::shared_ptr<Item>> Player::getEquippedAugmentItems() const { + std::vector<std::shared_ptr<Item>> equippedAugmentItems; + const auto equippedItems = getEquippedItems(); + + for (const auto &item : equippedItems) { + if (item->getAugments().size() < 1) { + continue; + } + equippedAugmentItems.push_back(item); + } + + return equippedAugmentItems; +} + std::vector<std::shared_ptr<Item>> Player::getEquippedItems() const { std::vector<Slots_t> valid_slots { CONST_SLOT_HEAD, @@ -4074,14 +4103,14 @@ std::vector<std::shared_ptr<Item>> Player::getEquippedItems() const { } std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uint32_t> &countMap) const { - for (const auto item : getAllInventoryItems()) { + for (const auto &item : getAllInventoryItems()) { countMap[static_cast<uint32_t>(item->getID())] += Item::countByType(item, -1); } return countMap; } std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const { - for (const auto item : getAllInventoryItems(false, true)) { + for (const auto &item : getAllInventoryItems(false, true)) { countMap[item->getID()] += item->getItemCount(); } @@ -4089,7 +4118,7 @@ std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t } void Player::getAllItemTypeCountAndSubtype(std::map<uint32_t, uint32_t> &countMap) const { - for (const auto item : getAllInventoryItems()) { + for (const auto &item : getAllInventoryItems()) { uint16_t itemId = item->getID(); if (Item::items[itemId].isFluidContainer()) { countMap[static_cast<uint32_t>(itemId) | (item->getAttribute<uint32_t>(ItemAttribute_t::FLUIDTYPE)) << 16] += item->getItemCount(); @@ -4166,7 +4195,7 @@ void Player::postAddNotification(std::shared_ptr<Thing> thing, std::shared_ptr<C } } - for (std::shared_ptr<Container> container : containers) { + for (const std::shared_ptr<Container> &container : containers) { autoCloseContainers(container); } } @@ -4473,7 +4502,7 @@ void Player::updateItemsLight(bool internal /*=false*/) { LightInfo curLight = item->getLightInfo(); if (curLight.level > maxLight.level) { - maxLight = std::move(curLight); + maxLight = curLight; } } } @@ -4673,6 +4702,8 @@ void Player::onPlacedCreature() { removePlayer(true); } + this->onChangeZone(this->getZoneType()); + sendUnjustifiedPoints(); } @@ -5002,7 +5033,7 @@ bool Player::canFamiliar(uint16_t lookType) const { return true; } - const Familiar* familiar = Familiars::getInstance().getFamiliarByLookType(getVocationId(), lookType); + const auto &familiar = Familiars::getInstance().getFamiliarByLookType(getVocationId(), lookType); if (!familiar) { return false; } @@ -5043,24 +5074,24 @@ bool Player::removeFamiliar(uint16_t lookType) { return false; } -bool Player::getFamiliar(const Familiar &familiar) const { +bool Player::getFamiliar(const std::shared_ptr<Familiar> &familiar) const { if (group->access) { return true; } - if (familiar.premium && !isPremium()) { + if (familiar->premium && !isPremium()) { return false; } for (const FamiliarEntry &familiarEntry : familiars) { - if (familiarEntry.lookType != familiar.lookType) { + if (familiarEntry.lookType != familiar->lookType) { continue; } return true; } - if (!familiar.unlocked) { + if (!familiar->unlocked) { return false; } @@ -5367,6 +5398,7 @@ uint16_t Player::getSkillLevel(skills_t skill) const { } else if (skill == SKILL_MANA_LEECH_AMOUNT) { skillLevel += m_wheelPlayer->getStat(WheelStat_t::MANA_LEECH); } else if (skill == SKILL_CRITICAL_HIT_DAMAGE) { + skillLevel += m_wheelPlayer->getStat(WheelStat_t::CRITICAL_DAMAGE); skillLevel += m_wheelPlayer->getMajorStatConditional("Combat Mastery", WheelMajor_t::CRITICAL_DMG_2); skillLevel += m_wheelPlayer->getMajorStatConditional("Ballistic Mastery", WheelMajor_t::CRITICAL_DMG); skillLevel += m_wheelPlayer->checkAvatarSkill(WheelAvatarSkill_t::CRITICAL_DAMAGE); @@ -5414,7 +5446,7 @@ void Player::setTibiaCoins(int32_t v) { int32_t Player::getCleavePercent(bool useCharges) const { int32_t result = cleavePercent; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &it = Item::items[item->getID()]; if (!it.abilities) { continue; @@ -5440,7 +5472,7 @@ int32_t Player::getPerfectShotDamage(uint8_t range, bool useCharges) const { result = it->second; } - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5464,7 +5496,7 @@ int32_t Player::getPerfectShotDamage(uint8_t range, bool useCharges) const { int32_t Player::getSpecializedMagicLevel(CombatType_t combat, bool useCharges) const { int32_t result = specializedMagicLevel[combatTypeToIndex(combat)]; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5485,7 +5517,7 @@ int32_t Player::getSpecializedMagicLevel(CombatType_t combat, bool useCharges) c int32_t Player::getMagicShieldCapacityFlat(bool useCharges) const { int32_t result = magicShieldCapacityFlat; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5506,7 +5538,7 @@ int32_t Player::getMagicShieldCapacityFlat(bool useCharges) const { int32_t Player::getMagicShieldCapacityPercent(bool useCharges) const { int32_t result = magicShieldCapacityPercent; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5527,7 +5559,7 @@ int32_t Player::getMagicShieldCapacityPercent(bool useCharges) const { int32_t Player::getReflectPercent(CombatType_t combat, bool useCharges) const { int32_t result = reflectPercent[combatTypeToIndex(combat)]; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5548,7 +5580,7 @@ int32_t Player::getReflectPercent(CombatType_t combat, bool useCharges) const { int32_t Player::getReflectFlat(CombatType_t combat, bool useCharges) const { int32_t result = reflectFlat[combatTypeToIndex(combat)]; - for (const auto item : getEquippedItems()) { + for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { continue; @@ -5755,7 +5787,7 @@ void Player::setCurrentMount(uint8_t mount) { bool Player::hasAnyMount() const { const auto mounts = g_game().mounts.getMounts(); - for (const auto mount : mounts) { + for (const auto &mount : mounts) { if (hasMount(mount)) { return true; } @@ -5766,7 +5798,7 @@ bool Player::hasAnyMount() const { uint8_t Player::getRandomMountId() const { std::vector<uint8_t> playerMounts; const auto mounts = g_game().mounts.getMounts(); - for (const auto mount : mounts) { + for (const auto &mount : mounts) { if (hasMount(mount)) { playerMounts.push_back(mount->id); } @@ -6153,7 +6185,7 @@ uint64_t Player::getMoney() const { size_t i = 0; while (i < containers.size()) { std::shared_ptr<Container> container = containers[i++]; - for (std::shared_ptr<Item> item : container->getItemList()) { + for (const std::shared_ptr<Item> &item : container->getItemList()) { std::shared_ptr<Container> tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); @@ -6170,7 +6202,7 @@ std::pair<uint64_t, uint64_t> Player::getForgeSliversAndCores() const { uint64_t coreCount = 0; // Check items from inventory - for (const auto item : getAllInventoryItems()) { + for (const auto &item : getAllInventoryItems()) { if (!item) { continue; } @@ -6193,15 +6225,6 @@ std::pair<uint64_t, uint64_t> Player::getForgeSliversAndCores() const { return std::make_pair(sliverCount, coreCount); } -size_t Player::getMaxVIPEntries() const { - if (group->maxVipEntries != 0) { - return group->maxVipEntries; - } else if (isPremium()) { - return 100; - } - return 20; -} - size_t Player::getMaxDepotItems() const { if (group->maxDepotItems != 0) { return group->maxDepotItems; @@ -6213,7 +6236,7 @@ size_t Player::getMaxDepotItems() const { std::forward_list<std::shared_ptr<Condition>> Player::getMuteConditions() const { std::forward_list<std::shared_ptr<Condition>> muteConditions; - for (std::shared_ptr<Condition> condition : conditions) { + for (const std::shared_ptr<Condition> &condition : conditions) { if (condition->getTicks() <= 0) { continue; } @@ -6419,7 +6442,7 @@ void sendStowItems(const std::shared_ptr<Item> &item, const std::shared_ptr<Item } if (auto container = stowItem->getContainer()) { - for (auto stowable_it : container->getStowableItems()) { + for (const auto &stowable_it : container->getStowableItems()) { if ((stowable_it.first)->getID() == item->getID()) { itemDict.push_back(stowable_it); } @@ -6497,14 +6520,14 @@ void Player::openPlayerContainers() { if (itemContainer) { auto cid = item->getAttribute<int64_t>(ItemAttribute_t::OPENCONTAINER); if (cid > 0) { - openContainersList.emplace_back(std::make_pair(cid, itemContainer)); + openContainersList.emplace_back(cid, itemContainer); } for (ContainerIterator it = itemContainer->iterator(); it.hasNext(); it.advance()) { std::shared_ptr<Container> subContainer = (*it)->getContainer(); if (subContainer) { auto subcid = (*it)->getAttribute<uint8_t>(ItemAttribute_t::OPENCONTAINER); if (subcid > 0) { - openContainersList.emplace_back(std::make_pair(subcid, subContainer)); + openContainersList.emplace_back(subcid, subContainer); } } } @@ -6574,17 +6597,6 @@ void Player::initializeTaskHunting() { } std::string Player::getBlessingsName() const { - static const phmap::flat_hash_map<Blessings_t, std::string> BlessingNames = { - { TWIST_OF_FATE, "Twist of Fate" }, - { WISDOM_OF_SOLITUDE, "The Wisdom of Solitude" }, - { SPARK_OF_THE_PHOENIX, "The Spark of the Phoenix" }, - { FIRE_OF_THE_SUNS, "The Fire of the Suns" }, - { SPIRITUAL_SHIELDING, "The Spiritual Shielding" }, - { EMBRACE_OF_TIBIA, "The Embrace of Tibia" }, - { BLOOD_OF_THE_MOUNTAIN, "Blood of the Mountain" }, - { HEARTH_OF_THE_MOUNTAIN, "Heart of the Mountain" }, - }; - uint8_t count = 0; std::for_each(blessings.begin(), blessings.end(), [&count](uint8_t amount) { if (amount != 0) { @@ -6592,6 +6604,7 @@ std::string Player::getBlessingsName() const { } }); + auto BlessingNames = getBlessingNames(); std::ostringstream os; for (uint8_t i = 1; i <= 8; i++) { if (hasBlessing(i)) { @@ -6674,6 +6687,10 @@ void Player::clearCooldowns() { } void Player::triggerTranscendance() { + if (wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) > OTSYS_TIME()) { + return; + } + auto item = getInventoryItem(CONST_SLOT_LEGS); if (item == nullptr) { return; @@ -6688,12 +6705,30 @@ void Player::triggerTranscendance() { outfit.lookType = getVocation()->getAvatarLookType(); outfitCondition->setOutfit(outfit); addCondition(outfitCondition); - wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, OTSYS_TIME() + duration); + wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_FORGE, OTSYS_TIME() + duration); g_game().addMagicEffect(getPosition(), CONST_ME_AVATAR_APPEAR); - sendTextMessage(MESSAGE_ATTENTION, "Transcendance was triggered."); + sendSkills(); sendStats(); sendBasicData(); + + sendTextMessage(MESSAGE_ATTENTION, "Transcendance was triggered."); + + // Send player data after transcendance timer expire + const auto &task = createPlayerTask( + std::max<uint32_t>(SCHEDULER_MINTICKS, duration), + [playerId = getID()] { + auto player = g_game().getPlayerByID(playerId); + if (player) { + player->sendSkills(); + player->sendStats(); + player->sendBasicData(); + } + }, + "Player::triggerTranscendance" + ); + g_dispatcher().scheduleEvent(task); + wheel()->sendGiftOfLifeCooldown(); g_game().reloadCreature(getPlayer()); } @@ -6710,7 +6745,7 @@ void Player::requestDepotItems() { return; } - for (std::shared_ptr<Item> locker : depotLocker->getItemList()) { + for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) { std::shared_ptr<Container> c = locker->getContainer(); if (!c || c->empty()) { continue; @@ -6776,7 +6811,7 @@ void Player::requestDepotSearchItem(uint16_t itemId, uint8_t tier) { return; } - for (std::shared_ptr<Item> locker : depotLocker->getItemList()) { + for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) { std::shared_ptr<Container> c = locker->getContainer(); if (!c || c->empty()) { continue; @@ -6813,7 +6848,7 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool } std::vector<std::shared_ptr<Item>> itemsVector; - for (std::shared_ptr<Item> locker : depotLocker->getItemList()) { + for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) { std::shared_ptr<Container> c = locker->getContainer(); if (!c || c->empty() || // Retrieve from inbox. @@ -6836,7 +6871,7 @@ void Player::retrieveAllItemsFromDepotSearch(uint16_t itemId, uint8_t tier, bool } ReturnValue ret = RETURNVALUE_NOERROR; - for (std::shared_ptr<Item> item : itemsVector) { + for (const std::shared_ptr<Item> &item : itemsVector) { // First lets try to retrieve the item to the stash retrieve container. if (g_game().tryRetrieveStashItems(static_self_cast<Player>(), item)) { continue; @@ -6882,7 +6917,7 @@ std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Posi } uint8_t index = 0; - for (std::shared_ptr<Item> locker : depotLocker->getItemList()) { + for (const std::shared_ptr<Item> &locker : depotLocker->getItemList()) { std::shared_ptr<Container> c = locker->getContainer(); if (!c || c->empty() || (c->isInbox() && pos.y != 0x21) || // From inbox. (!c->isInbox() && pos.y != 0x20)) { // From depot. @@ -6905,8 +6940,9 @@ std::shared_ptr<Item> Player::getItemFromDepotSearch(uint16_t itemId, const Posi return nullptr; } -std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>> Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { - if (depotLocker == nullptr) { +std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_t, uint32_t>>> +Player::requestLockerItems(std::shared_ptr<DepotLocker> depotLocker, bool sendToClient /*= false*/, uint8_t tier /*= 0*/) const { + if (!depotLocker) { g_logger().error("{} - Depot locker is nullptr", __FUNCTION__); return {}; } @@ -6915,24 +6951,18 @@ std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_ std::vector<std::shared_ptr<Item>> itemVector; std::vector<std::shared_ptr<Container>> containers { depotLocker }; - size_t size = 0; - do { - std::shared_ptr<Container> container = containers[size]; - size++; + for (size_t i = 0; i < containers.size(); ++i) { + std::shared_ptr<Container> container = containers[i]; - for (std::shared_ptr<Item> item : container->getItemList()) { + for (const auto &item : container->getItemList()) { std::shared_ptr<Container> lockerContainers = item->getContainer(); if (lockerContainers && !lockerContainers->empty()) { containers.push_back(lockerContainers); continue; } - if (item->isStoreItem()) { - continue; - } - const ItemType &itemType = Item::items[item->getID()]; - if (itemType.wareId == 0) { + if (item->isStoreItem() || itemType.wareId == 0) { continue; } @@ -6940,44 +6970,31 @@ std::pair<std::vector<std::shared_ptr<Item>>, std::map<uint16_t, std::map<uint8_ continue; } - if (!item->hasMarketAttributes()) { - continue; - } - - if (!sendToClient && item->getTier() != tier) { + if (!item->hasMarketAttributes() || (!sendToClient && item->getTier() != tier)) { continue; } - (lockerItems[itemType.wareId])[item->getTier()] += Item::countByType(item, -1); + lockerItems[itemType.wareId][item->getTier()] += Item::countByType(item, -1); itemVector.push_back(item); } - } while (size < containers.size()); - StashItemList stashToSend = getStashItems(); - uint32_t countSize = 0; - for (auto [itemId, itemCount] : stashToSend) { - countSize += itemCount; } - do { - for (auto [itemId, itemCount] : stashToSend) { - const ItemType &itemType = Item::items[itemId]; - if (itemType.wareId == 0) { - continue; - } - - countSize = countSize - itemCount; - (lockerItems[itemType.wareId])[0] += itemCount; + StashItemList stashToSend = getStashItems(); + for (const auto &[itemId, itemCount] : stashToSend) { + const ItemType &itemType = Item::items[itemId]; + if (itemType.wareId != 0) { + lockerItems[itemType.wareId][0] += itemCount; } - } while (countSize > 0); + } - return std::make_pair(itemVector, lockerItems); + return { itemVector, lockerItems }; } std::pair<std::vector<std::shared_ptr<Item>>, uint16_t> Player::getLockerItemsAndCountById(const std::shared_ptr<DepotLocker> &depotLocker, uint8_t tier, uint16_t itemId) { std::vector<std::shared_ptr<Item>> lockerItems; auto [itemVector, itemMap] = requestLockerItems(depotLocker, false, tier); uint16_t totalCount = 0; - for (auto item : itemVector) { + for (const auto &item : itemVector) { if (!item || item->getID() != itemId) { continue; } @@ -7023,7 +7040,7 @@ bool Player::saySpell( int32_t valueEmote = 0; // Send to client - for (std::shared_ptr<Creature> spectator : spectators) { + for (const std::shared_ptr<Creature> &spectator : spectators) { if (std::shared_ptr<Player> tmpPlayer = spectator->getPlayer()) { if (g_configManager().getBoolean(EMOTE_SPELLS, __FUNCTION__)) { valueEmote = tmpPlayer->getStorageValue(STORAGEVALUE_EMOTE); @@ -7039,7 +7056,7 @@ bool Player::saySpell( } // Execute lua event method - for (std::shared_ptr<Creature> spectator : spectators) { + for (const std::shared_ptr<Creature> &spectator : spectators) { auto tmpPlayer = spectator->getPlayer(); if (!tmpPlayer) { continue; @@ -7683,7 +7700,7 @@ void Player::closeAllExternalContainers() { } } - for (std::shared_ptr<Container> container : containerToClose) { + for (const std::shared_ptr<Container> &container : containerToClose) { autoCloseContainers(container); } } @@ -7804,7 +7821,7 @@ bool Player::setAccount(uint32_t accountId) { } uint8_t Player::getAccountType() const { - return account ? account->getAccountType() : AccountType::ACCOUNT_TYPE_NORMAL; + return static_cast<uint8_t>(account ? account->getAccountType() : static_cast<uint8_t>(AccountType::ACCOUNT_TYPE_NORMAL)); } uint32_t Player::getAccountId() const { @@ -7847,7 +7864,7 @@ void Player::parseAttackRecvHazardSystem(CombatDamage &damage, std::shared_ptr<M auto points = getHazardSystemPoints(); if (m_party) { - for (const auto partyMember : m_party->getMembers()) { + for (const auto &partyMember : m_party->getMembers()) { if (partyMember && partyMember->getHazardSystemPoints() < points) { points = partyMember->getHazardSystemPoints(); } @@ -7906,7 +7923,7 @@ void Player::parseAttackDealtHazardSystem(CombatDamage &damage, std::shared_ptr< auto points = getHazardSystemPoints(); if (m_party) { - for (const auto partyMember : m_party->getMembers()) { + for (const auto &partyMember : m_party->getMembers()) { if (partyMember && partyMember->getHazardSystemPoints() < points) { points = partyMember->getHazardSystemPoints(); } @@ -7967,6 +7984,33 @@ const std::unique_ptr<PlayerAchievement> &Player::achiev() const { return m_playerAchievement; } +// Badge interface +std::unique_ptr<PlayerBadge> &Player::badge() { + return m_playerBadge; +} + +const std::unique_ptr<PlayerBadge> &Player::badge() const { + return m_playerBadge; +} + +// Title interface +std::unique_ptr<PlayerTitle> &Player::title() { + return m_playerTitle; +} + +const std::unique_ptr<PlayerTitle> &Player::title() const { + return m_playerTitle; +} + +// VIP interface +std::unique_ptr<PlayerVIP> &Player::vip() { + return m_playerVIP; +} + +const std::unique_ptr<PlayerVIP> &Player::vip() const { + return m_playerVIP; +} + void Player::sendLootMessage(const std::string &message) const { auto party = getParty(); if (!party) { @@ -7977,7 +8021,7 @@ void Player::sendLootMessage(const std::string &message) const { if (auto partyLeader = party->getLeader()) { partyLeader->sendTextMessage(MESSAGE_LOOT, message); } - for (const auto partyMember : party->getMembers()) { + for (const auto &partyMember : party->getMembers()) { if (partyMember) { partyMember->sendTextMessage(MESSAGE_LOOT, message); } @@ -8086,3 +8130,18 @@ bool Player::canSpeakWithHireling(uint8_t speechbubble) { return true; } + +uint16_t Player::getPlayerVocationEnum() const { + int cipTibiaId = getVocation()->getClientId(); + if (cipTibiaId == 1 || cipTibiaId == 11) { + return Vocation_t::VOCATION_KNIGHT_CIP; // Knight + } else if (cipTibiaId == 2 || cipTibiaId == 12) { + return Vocation_t::VOCATION_PALADIN_CIP; // Paladin + } else if (cipTibiaId == 3 || cipTibiaId == 13) { + return Vocation_t::VOCATION_SORCERER_CIP; // Sorcerer + } else if (cipTibiaId == 4 || cipTibiaId == 14) { + return Vocation_t::VOCATION_DRUID_CIP; // Druid + } + + return Vocation_t::VOCATION_NONE; +} diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 592db179071..58bebfb9f2f 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -34,6 +34,10 @@ #include "creatures/npcs/npc.hpp" #include "game/bank/bank.hpp" #include "enums/object_category.hpp" +#include "enums/player_cyclopedia.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" +#include "creatures/players/vip/player_vip.hpp" class House; class NetworkMessage; @@ -49,11 +53,17 @@ class TaskHuntingSlot; class Spell; class PlayerWheel; class PlayerAchievement; +class PlayerBadge; +class PlayerTitle; +class PlayerVIP; class Spectators; class Account; struct ModalWindow; struct Achievement; +struct Badge; +struct Title; +struct VIPGroup; struct ForgeHistory { ForgeAction_t actionType = ForgeAction_t::FUSION; @@ -334,7 +344,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool isBossOnBosstiaryTracker(const std::shared_ptr<MonsterType> &monsterType) const; - Vocation* getVocation() const { + std::shared_ptr<Vocation> getVocation() const { return vocation; } @@ -510,10 +520,10 @@ class Player final : public Creature, public Cylinder, public Bankable { void genReservedStorageRange(); - void setGroup(Group* newGroup) { + void setGroup(std::shared_ptr<Group> newGroup) { group = newGroup; } - Group* getGroup() const { + std::shared_ptr<Group> getGroup() const { return group; } @@ -657,6 +667,11 @@ class Player final : public Creature, public Cylinder, public Bankable { return loginPosition; } const Position &getTemplePosition() const { + if (!town) { + static auto emptyPosition = Position(); + return emptyPosition; + } + return town->getTemplePosition(); } std::shared_ptr<Town> getTown() const { @@ -730,6 +745,13 @@ class Player final : public Creature, public Cylinder, public Bankable { uint32_t getCapacity() const; + uint32_t getBonusCapacity() const { + if (hasFlag(PlayerFlags_t::CannotPickupItem) || hasFlag(PlayerFlags_t::HasInfiniteCapacity)) { + return std::numeric_limits<uint32_t>::max(); + } + return bonusCapacity; + } + uint32_t getFreeCapacity() const { if (hasFlag(PlayerFlags_t::CannotPickupItem)) { return 0; @@ -811,13 +833,6 @@ class Player final : public Creature, public Cylinder, public Bankable { return shopOwner; } - // V.I.P. functions - void notifyStatusChange(std::shared_ptr<Player> player, VipStatus_t status, bool message = true) const; - bool removeVIP(uint32_t vipGuid); - bool addVIP(uint32_t vipGuid, const std::string &vipName, VipStatus_t status); - bool addVIPInternal(uint32_t vipGuid); - bool editVIP(uint32_t vipGuid, const std::string &description, uint32_t icon, bool notify) const; - // follow functions bool setFollowCreature(std::shared_ptr<Creature> creature) override; void goToFollowCreature() override; @@ -1022,7 +1037,7 @@ class Player final : public Creature, public Cylinder, public Bankable { bool canFamiliar(uint16_t lookType) const; void addFamiliar(uint16_t lookType); bool removeFamiliar(uint16_t lookType); - bool getFamiliar(const Familiar &familiar) const; + bool getFamiliar(const std::shared_ptr<Familiar> &familiar) const; void setFamiliarLooktype(uint16_t familiarLooktype) { this->defaultOutfit.lookFamiliarsType = familiarLooktype; } @@ -1031,7 +1046,6 @@ class Player final : public Creature, public Cylinder, public Bankable { bool hasKilled(std::shared_ptr<Player> player) const; - size_t getMaxVIPEntries() const; size_t getMaxDepotItems() const; // tile @@ -1626,9 +1640,9 @@ class Player final : public Creature, public Cylinder, public Bankable { } } void sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, std::vector<std::pair<Achievement, uint32_t>> achievementsUnlocked); - void sendCyclopediaCharacterItemSummary() { + void sendCyclopediaCharacterItemSummary(const ItemsTierCountList &inventoryItems, const ItemsTierCountList &storeInboxItems, const StashItemList &supplyStashItems, const ItemsTierCountList &depotBoxItems, const ItemsTierCountList &inboxItems) { if (client) { - client->sendCyclopediaCharacterItemSummary(); + client->sendCyclopediaCharacterItemSummary(inventoryItems, storeInboxItems, supplyStashItems, depotBoxItems, inboxItems); } } void sendCyclopediaCharacterOutfitsMounts() { @@ -1802,11 +1816,11 @@ class Player final : public Creature, public Cylinder, public Bankable { void setGrindingXpBoost(uint16_t value) { grindingXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), value); } - uint16_t getStoreXpBoost() const { - return storeXpBoost; + uint16_t getXpBoostPercent() const { + return xpBoostPercent; } - void setStoreXpBoost(uint16_t exp) { - storeXpBoost = exp; + void setXpBoostPercent(uint16_t percent) { + xpBoostPercent = percent; } uint16_t getStaminaXpBoost() const { return staminaXpBoost; @@ -1815,17 +1829,17 @@ class Player final : public Creature, public Cylinder, public Bankable { staminaXpBoost = std::min<uint16_t>(std::numeric_limits<uint16_t>::max(), value); } - void setExpBoostStamina(uint16_t stamina) { - // only allow stamina boosts of 12 hours or less - if (stamina > 12 * 3600) { - expBoostStamina = 12 * 3600; + void setXpBoostTime(uint16_t timeLeft) { + // only allow time boosts of 12 hours or less + if (timeLeft > 12 * 3600) { + xpBoostTime = 12 * 3600; return; } - expBoostStamina = stamina; + xpBoostTime = timeLeft; } - uint16_t getExpBoostStamina() { - return expBoostStamina; + uint16_t getXpBoostTime() { + return xpBoostTime; } int32_t getIdleTime() const { @@ -2517,7 +2531,7 @@ class Player final : public Creature, public Cylinder, public Bankable { // Concoction system void updateConcoction(uint16_t itemId, uint16_t timeLeft) { - if (timeLeft < 0) { + if (timeLeft == 0) { activeConcoctions.erase(itemId); } else { activeConcoctions[itemId] = timeLeft; @@ -2566,12 +2580,28 @@ class Player final : public Creature, public Cylinder, public Bankable { // Get specific inventory item from itemid std::vector<std::shared_ptr<Item>> getInventoryItemsFromId(uint16_t itemId, bool ignore = true) const; + // this get all player store inbox items and return as ItemsTierCountList + ItemsTierCountList getStoreInboxItemsId() const; + // this get all player depot chest items and return as ItemsTierCountList + ItemsTierCountList getDepotChestItemsId() const; + // this get all player depot inbox items and return as ItemsTierCountList + ItemsTierCountList getDepotInboxItemsId() const; + // This get all player inventory items std::vector<std::shared_ptr<Item>> getAllInventoryItems(bool ignoreEquiped = false, bool ignoreItemWithTier = false) const; // This get all players slot items phmap::flat_hash_map<uint8_t, std::shared_ptr<Item>> getAllSlotItems() const; + // This get all blessings + phmap::flat_hash_map<Blessings_t, std::string> getBlessingNames() const; + + // Gets the equipped items with augment by type + std::vector<std::shared_ptr<Item>> getEquippedAugmentItemsByType(Augment_t augmentType) const; + + // Gets the equipped items with augment + std::vector<std::shared_ptr<Item>> getEquippedAugmentItems() const; + /** * @brief Get the equipped items of the player-> * @details This function returns a vector containing the items currently equipped by the player @@ -2587,6 +2617,18 @@ class Player final : public Creature, public Cylinder, public Bankable { std::unique_ptr<PlayerAchievement> &achiev(); const std::unique_ptr<PlayerAchievement> &achiev() const; + // Player badge interface + std::unique_ptr<PlayerBadge> &badge(); + const std::unique_ptr<PlayerBadge> &badge() const; + + // Player title interface + std::unique_ptr<PlayerTitle> &title(); + const std::unique_ptr<PlayerTitle> &title() const; + + // Player vip interface + std::unique_ptr<PlayerVIP> &vip(); + const std::unique_ptr<PlayerVIP> &vip() const; + void sendLootMessage(const std::string &message) const; std::shared_ptr<Container> getLootPouch(); @@ -2597,6 +2639,8 @@ class Player final : public Creature, public Cylinder, public Bankable { bool canSpeakWithHireling(uint8_t speechbubble); + uint16_t getPlayerVocationEnum() const; + private: friend class PlayerLock; std::mutex mutex; @@ -2653,7 +2697,7 @@ class Player final : public Creature, public Cylinder, public Bankable { size_t getLastIndex() const override; uint32_t getItemTypeCount(uint16_t itemId, int32_t subType = -1) const override; void stashContainer(StashContainerList itemDict); - ItemsTierCountList getInventoryItemsId() const; + ItemsTierCountList getInventoryItemsId(bool ignoreStoreInbox = false) const; // This function is a override function of base class std::map<uint32_t, uint32_t> &getAllItemTypeCount(std::map<uint32_t, uint32_t> &countMap) const override; @@ -2671,7 +2715,6 @@ class Player final : public Creature, public Cylinder, public Bankable { void addBosstiaryKill(const std::shared_ptr<MonsterType> &mType); phmap::flat_hash_set<uint32_t> attackedSet; - phmap::flat_hash_set<uint32_t> VIPList; std::map<uint8_t, OpenContainer> openContainers; std::map<uint32_t, std::shared_ptr<DepotLocker>> depotLockerMap; @@ -2755,7 +2798,7 @@ class Player final : public Creature, public Cylinder, public Bankable { std::shared_ptr<BedItem> bedItem = nullptr; std::shared_ptr<Guild> guild = nullptr; GuildRank_ptr guildRank; - Group* group = nullptr; + std::shared_ptr<Group> group = nullptr; std::shared_ptr<Inbox> inbox; std::shared_ptr<Item> imbuingItem = nullptr; std::shared_ptr<Item> tradeItem = nullptr; @@ -2768,7 +2811,7 @@ class Player final : public Creature, public Cylinder, public Bankable { ProtocolGame_ptr client; std::shared_ptr<Task> walkTask; std::shared_ptr<Town> town; - Vocation* vocation = nullptr; + std::shared_ptr<Vocation> vocation = nullptr; std::shared_ptr<RewardChest> rewardChest = nullptr; uint32_t inventoryWeight = 0; @@ -2806,7 +2849,7 @@ class Player final : public Creature, public Cylinder, public Bankable { int32_t m_deathTime = 0; uint32_t coinBalance = 0; uint32_t coinTransferableBalance = 0; - uint16_t expBoostStamina = 0; + uint16_t xpBoostTime = 0; uint8_t randomMount = 0; uint16_t lastStatsTrainingTime = 0; @@ -2816,7 +2859,7 @@ class Player final : public Creature, public Cylinder, public Bankable { uint16_t baseXpGain = 100; uint16_t voucherXpBoost = 0; uint16_t grindingXpBoost = 0; - uint16_t storeXpBoost = 0; + uint16_t xpBoostPercent = 0; uint16_t staminaXpBoost = 100; int16_t lastDepotId = -1; StashItemList stashItems; // [ItemID] = amount @@ -2866,7 +2909,6 @@ class Player final : public Creature, public Cylinder, public Bankable { FightMode_t fightMode = FIGHTMODE_ATTACK; Faction_t faction = FACTION_PLAYER; QuickLootFilter_t quickLootFilter; - VipStatus_t statusVipList = VIPSTATUS_ONLINE; PlayerPronoun_t pronoun = PLAYERPRONOUN_THEY; bool chaseMode = false; @@ -2979,9 +3021,15 @@ class Player final : public Creature, public Cylinder, public Bankable { friend class IOLoginDataLoad; friend class IOLoginDataSave; friend class PlayerAchievement; + friend class PlayerBadge; + friend class PlayerTitle; + friend class PlayerVIP; std::unique_ptr<PlayerWheel> m_wheelPlayer; std::unique_ptr<PlayerAchievement> m_playerAchievement; + std::unique_ptr<PlayerBadge> m_playerBadge; + std::unique_ptr<PlayerTitle> m_playerTitle; + std::unique_ptr<PlayerVIP> m_playerVIP; std::mutex quickLootMutex; diff --git a/src/creatures/players/vip/player_vip.cpp b/src/creatures/players/vip/player_vip.cpp new file mode 100644 index 00000000000..b4b1642ec69 --- /dev/null +++ b/src/creatures/players/vip/player_vip.cpp @@ -0,0 +1,247 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR <opentibiabr@outlook.com> + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#include "pch.hpp" + +#include "creatures/players/vip/player_vip.hpp" + +#include "io/iologindata.hpp" + +#include "game/game.hpp" +#include "creatures/players/player.hpp" + +const uint8_t PlayerVIP::firstID = 1; +const uint8_t PlayerVIP::lastID = 8; + +PlayerVIP::PlayerVIP(Player &player) : + m_player(player) { } + +size_t PlayerVIP::getMaxEntries() const { + if (m_player.group && m_player.group->maxVipEntries != 0) { + return m_player.group->maxVipEntries; + } else if (m_player.isPremium()) { + return 100; + } + return 20; +} + +uint8_t PlayerVIP::getMaxGroupEntries() const { + if (m_player.isPremium()) { + return 8; // max number of groups is 8 (5 custom and 3 default) + } + return 0; +} + +void PlayerVIP::notifyStatusChange(std::shared_ptr<Player> loginPlayer, VipStatus_t status, bool message) const { + if (!m_player.client) { + return; + } + + if (!vipGuids.contains(loginPlayer->getGUID())) { + return; + } + + m_player.client->sendUpdatedVIPStatus(loginPlayer->getGUID(), status); + + if (message) { + if (status == VipStatus_t::Online) { + m_player.sendTextMessage(TextMessage(MESSAGE_FAILURE, fmt::format("{} has logged in.", loginPlayer->getName()))); + } else if (status == VipStatus_t::Offline) { + m_player.sendTextMessage(TextMessage(MESSAGE_FAILURE, fmt::format("{} has logged out.", loginPlayer->getName()))); + } + } +} + +bool PlayerVIP::remove(uint32_t vipGuid) { + if (!vipGuids.erase(vipGuid)) { + return false; + } + + vipGuids.erase(vipGuid); + if (m_player.account) { + IOLoginData::removeVIPEntry(m_player.account->getID(), vipGuid); + } + + return true; +} + +bool PlayerVIP::add(uint32_t vipGuid, const std::string &vipName, VipStatus_t status) { + if (vipGuids.size() >= getMaxEntries() || vipGuids.size() == 200) { // max number of buddies is 200 in 9.53 + m_player.sendTextMessage(MESSAGE_FAILURE, "You cannot add more buddies."); + return false; + } + + if (!vipGuids.insert(vipGuid).second) { + m_player.sendTextMessage(MESSAGE_FAILURE, "This player is already in your list."); + return false; + } + + if (m_player.account) { + IOLoginData::addVIPEntry(m_player.account->getID(), vipGuid, "", 0, false); + } + + if (m_player.client) { + m_player.client->sendVIP(vipGuid, vipName, "", 0, false, status); + } + + return true; +} + +bool PlayerVIP::addInternal(uint32_t vipGuid) { + if (vipGuids.size() >= getMaxEntries() || vipGuids.size() == 200) { // max number of buddies is 200 in 9.53 + return false; + } + + return vipGuids.insert(vipGuid).second; +} + +bool PlayerVIP::edit(uint32_t vipGuid, const std::string &description, uint32_t icon, bool notify, std::vector<uint8_t> groupsId) const { + const auto it = vipGuids.find(vipGuid); + if (it == vipGuids.end()) { + return false; // player is not in VIP + } + + if (m_player.account) { + IOLoginData::editVIPEntry(m_player.account->getID(), vipGuid, description, icon, notify); + } + + IOLoginData::removeGuidVIPGroupEntry(m_player.account->getID(), vipGuid); + + for (const auto groupId : groupsId) { + const auto &group = getGroupByID(groupId); + if (group) { + group->vipGroupGuids.insert(vipGuid); + IOLoginData::addGuidVIPGroupEntry(group->id, m_player.account->getID(), vipGuid); + } + } + + return true; +} + +std::shared_ptr<VIPGroup> PlayerVIP::getGroupByID(uint8_t groupId) const { + auto it = std::find_if(vipGroups.begin(), vipGroups.end(), [groupId](const std::shared_ptr<VIPGroup> vipGroup) { + return vipGroup->id == groupId; + }); + + return it != vipGroups.end() ? *it : nullptr; +} + +std::shared_ptr<VIPGroup> PlayerVIP::getGroupByName(const std::string &name) const { + const auto groupName = name.c_str(); + auto it = std::find_if(vipGroups.begin(), vipGroups.end(), [groupName](const std::shared_ptr<VIPGroup> vipGroup) { + return strcmp(groupName, vipGroup->name.c_str()) == 0; + }); + + return it != vipGroups.end() ? *it : nullptr; +} + +void PlayerVIP::addGroupInternal(uint8_t groupId, const std::string &name, bool customizable) { + if (getGroupByName(name) != nullptr) { + g_logger().warn("{} - Group name already exists.", __FUNCTION__); + return; + } + + const auto freeId = getFreeId(); + if (freeId == 0) { + g_logger().warn("{} - No id available.", __FUNCTION__); + return; + } + + vipGroups.emplace_back(std::make_shared<VIPGroup>(freeId, name, customizable)); +} + +void PlayerVIP::removeGroup(uint8_t groupId) { + auto it = std::find_if(vipGroups.begin(), vipGroups.end(), [groupId](const std::shared_ptr<VIPGroup> vipGroup) { + return vipGroup->id == groupId; + }); + + if (it == vipGroups.end()) { + return; + } + + vipGroups.erase(it); + + if (m_player.account) { + IOLoginData::removeVIPGroupEntry(groupId, m_player.account->getID()); + } + + if (m_player.client) { + m_player.client->sendVIPGroups(); + } +} + +void PlayerVIP::addGroup(const std::string &name, bool customizable /*= true */) { + if (getGroupByName(name) != nullptr) { + m_player.sendCancelMessage("A group with this name already exists. Please choose another name."); + return; + } + + const auto freeId = getFreeId(); + if (freeId == 0) { + g_logger().warn("{} - No id available.", __FUNCTION__); + return; + } + + std::shared_ptr<VIPGroup> vipGroup = std::make_shared<VIPGroup>(freeId, name, customizable); + vipGroups.emplace_back(vipGroup); + + if (m_player.account) { + IOLoginData::addVIPGroupEntry(vipGroup->id, m_player.account->getID(), vipGroup->name, vipGroup->customizable); + } + + if (m_player.client) { + m_player.client->sendVIPGroups(); + } +} + +void PlayerVIP::editGroup(uint8_t groupId, const std::string &newName, bool customizable /*= true*/) { + if (getGroupByName(newName) != nullptr) { + m_player.sendCancelMessage("A group with this name already exists. Please choose another name."); + return; + } + + const auto &vipGroup = getGroupByID(groupId); + vipGroup->name = newName; + vipGroup->customizable = customizable; + + if (m_player.account) { + IOLoginData::editVIPGroupEntry(vipGroup->id, m_player.account->getID(), vipGroup->name, vipGroup->customizable); + } + + if (m_player.client) { + m_player.client->sendVIPGroups(); + } +} + +uint8_t PlayerVIP::getFreeId() const { + for (uint8_t i = firstID; i <= lastID; ++i) { + if (getGroupByID(i) == nullptr) { + return i; + } + } + + return 0; +} + +const std::vector<uint8_t> PlayerVIP::getGroupsIdGuidBelongs(uint32_t guid) { + std::vector<uint8_t> guidBelongs; + for (const auto &vipGroup : vipGroups) { + if (vipGroup->vipGroupGuids.contains(guid)) { + guidBelongs.emplace_back(vipGroup->id); + } + } + return guidBelongs; +} + +void PlayerVIP::addGuidToGroupInternal(uint8_t groupId, uint32_t guid) { + const auto &group = getGroupByID(groupId); + if (group) { + group->vipGroupGuids.insert(guid); + } +} diff --git a/src/creatures/players/vip/player_vip.hpp b/src/creatures/players/vip/player_vip.hpp new file mode 100644 index 00000000000..e9aeaf85326 --- /dev/null +++ b/src/creatures/players/vip/player_vip.hpp @@ -0,0 +1,74 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR <opentibiabr@outlook.com> + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#include "creatures/creatures_definitions.hpp" + +class Player; + +struct VIPGroup { + uint8_t id = 0; + std::string name = ""; + bool customizable = false; + phmap::flat_hash_set<uint32_t> vipGroupGuids; + + VIPGroup() = default; + VIPGroup(uint8_t id, const std::string &name, bool customizable) : + id(id), name(std::move(name)), customizable(customizable) { } +}; +class PlayerVIP { + +public: + explicit PlayerVIP(Player &player); + + static const uint8_t firstID; + static const uint8_t lastID; + + size_t getMaxEntries() const; + uint8_t getMaxGroupEntries() const; + + VipStatus_t getStatus() const { + return status; + } + void setStatus(VipStatus_t newStatus) { + status = newStatus; + } + + void notifyStatusChange(std::shared_ptr<Player> loginPlayer, VipStatus_t status, bool message = true) const; + bool remove(uint32_t vipGuid); + bool add(uint32_t vipGuid, const std::string &vipName, VipStatus_t status); + bool addInternal(uint32_t vipGuid); + bool edit(uint32_t vipGuid, const std::string &description, uint32_t icon, bool notify, std::vector<uint8_t> groupsId) const; + + // VIP Group + std::shared_ptr<VIPGroup> getGroupByID(uint8_t groupId) const; + std::shared_ptr<VIPGroup> getGroupByName(const std::string &name) const; + + void addGroupInternal(uint8_t groupId, const std::string &name, bool customizable); + void removeGroup(uint8_t groupId); + void addGroup(const std::string &name, bool customizable = true); + void editGroup(uint8_t groupId, const std::string &newName, bool customizable = true); + + void addGuidToGroupInternal(uint8_t groupId, uint32_t guid); + + uint8_t getFreeId() const; + const std::vector<uint8_t> getGroupsIdGuidBelongs(uint32_t guid); + + [[nodiscard]] const std::vector<std::shared_ptr<VIPGroup>> &getGroups() const { + return vipGroups; + } + +private: + Player &m_player; + + VipStatus_t status = VipStatus_t::Online; + std::vector<std::shared_ptr<VIPGroup>> vipGroups; + phmap::flat_hash_set<uint32_t> vipGuids; +}; diff --git a/src/creatures/players/vocations/vocation.cpp b/src/creatures/players/vocations/vocation.cpp index c9a276a641d..98dbaeb1bea 100644 --- a/src/creatures/players/vocations/vocation.cpp +++ b/src/creatures/players/vocations/vocation.cpp @@ -14,6 +14,11 @@ #include "utils/pugicast.hpp" #include "utils/tools.hpp" +bool Vocations::reload() { + vocationsMap.clear(); + return loadFromXml(); +} + bool Vocations::loadFromXml() { pugi::xml_document doc; auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/vocations.xml"; @@ -32,87 +37,87 @@ bool Vocations::loadFromXml() { uint16_t id = pugi::cast<uint16_t>(attr.value()); - auto res = vocationsMap.emplace(std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple(id)); - Vocation &voc = res.first->second; + auto res = vocationsMap.emplace(std::piecewise_construct, std::forward_as_tuple(id), std::forward_as_tuple(std::make_shared<Vocation>(id))); + auto voc = res.first->second; if ((attr = vocationNode.attribute("name"))) { - voc.name = attr.as_string(); + voc->name = attr.as_string(); } if ((attr = vocationNode.attribute("clientid"))) { - voc.clientId = pugi::cast<uint16_t>(attr.value()); + voc->clientId = pugi::cast<uint16_t>(attr.value()); } if ((attr = vocationNode.attribute("baseid"))) { - voc.baseId = pugi::cast<uint16_t>(attr.value()); + voc->baseId = pugi::cast<uint16_t>(attr.value()); } if ((attr = vocationNode.attribute("description"))) { - voc.description = attr.as_string(); + voc->description = attr.as_string(); } if ((attr = vocationNode.attribute("magicshield"))) { - voc.magicShield = attr.as_bool(); + voc->magicShield = attr.as_bool(); } if ((attr = vocationNode.attribute("gaincap"))) { - voc.gainCap = pugi::cast<uint32_t>(attr.value()) * 100; + voc->gainCap = pugi::cast<uint32_t>(attr.value()) * 100; } if ((attr = vocationNode.attribute("gainhp"))) { - voc.gainHP = pugi::cast<uint32_t>(attr.value()); + voc->gainHP = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("gainmana"))) { - voc.gainMana = pugi::cast<uint32_t>(attr.value()); + voc->gainMana = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("gainhpticks"))) { - voc.gainHealthTicks = pugi::cast<uint32_t>(attr.value()); + voc->gainHealthTicks = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("gainhpamount"))) { - voc.gainHealthAmount = pugi::cast<uint32_t>(attr.value()); + voc->gainHealthAmount = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("gainmanaticks"))) { - voc.gainManaTicks = pugi::cast<uint32_t>(attr.value()); + voc->gainManaTicks = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("gainmanaamount"))) { - voc.gainManaAmount = pugi::cast<uint32_t>(attr.value()); + voc->gainManaAmount = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("manamultiplier"))) { - voc.manaMultiplier = pugi::cast<float>(attr.value()); + voc->manaMultiplier = pugi::cast<float>(attr.value()); } if ((attr = vocationNode.attribute("attackspeed"))) { - voc.attackSpeed = pugi::cast<uint32_t>(attr.value()); + voc->attackSpeed = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("basespeed"))) { - voc.baseSpeed = pugi::cast<uint32_t>(attr.value()); + voc->baseSpeed = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("soulmax"))) { - voc.soulMax = pugi::cast<uint16_t>(attr.value()); + voc->soulMax = pugi::cast<uint16_t>(attr.value()); } if ((attr = vocationNode.attribute("gainsoulticks"))) { - voc.gainSoulTicks = pugi::cast<uint32_t>(attr.value()); + voc->gainSoulTicks = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("fromvoc"))) { - voc.fromVocation = pugi::cast<uint32_t>(attr.value()); + voc->fromVocation = pugi::cast<uint32_t>(attr.value()); } if ((attr = vocationNode.attribute("canCombat"))) { - voc.combat = attr.as_bool(); + voc->combat = attr.as_bool(); } if ((attr = vocationNode.attribute("avatarlooktype"))) { - voc.avatarLookType = pugi::cast<uint16_t>(attr.value()); + voc->avatarLookType = pugi::cast<uint16_t>(attr.value()); } for (auto childNode : vocationNode.children()) { @@ -121,75 +126,75 @@ bool Vocations::loadFromXml() { if (skillIdAttribute) { uint16_t skill_id = pugi::cast<uint16_t>(skillIdAttribute.value()); if (skill_id <= SKILL_LAST) { - voc.skillMultipliers[skill_id] = pugi::cast<float>(childNode.attribute("multiplier").value()); + voc->skillMultipliers[skill_id] = pugi::cast<float>(childNode.attribute("multiplier").value()); } else { g_logger().warn("[Vocations::loadFromXml] - " "No valid skill id: {} for vocation: {}", - skill_id, voc.id); + skill_id, voc->id); } } else { g_logger().warn("[Vocations::loadFromXml] - " "Missing skill id for vocation: {}", - voc.id); + voc->id); } } else if (strcasecmp(childNode.name(), "mitigation") == 0) { pugi::xml_attribute factorAttribute = childNode.attribute("multiplier"); if (factorAttribute) { - voc.mitigationFactor = pugi::cast<float>(factorAttribute.value()); + voc->mitigationFactor = pugi::cast<float>(factorAttribute.value()); } pugi::xml_attribute primaryShieldAttribute = childNode.attribute("primaryShield"); if (primaryShieldAttribute) { - voc.mitigationPrimaryShield = pugi::cast<float>(primaryShieldAttribute.value()); + voc->mitigationPrimaryShield = pugi::cast<float>(primaryShieldAttribute.value()); } pugi::xml_attribute secondaryShieldAttribute = childNode.attribute("secondaryShield"); if (secondaryShieldAttribute) { - voc.mitigationSecondaryShield = pugi::cast<float>(secondaryShieldAttribute.value()); + voc->mitigationSecondaryShield = pugi::cast<float>(secondaryShieldAttribute.value()); } } else if (strcasecmp(childNode.name(), "formula") == 0) { pugi::xml_attribute meleeDamageAttribute = childNode.attribute("meleeDamage"); if (meleeDamageAttribute) { - voc.meleeDamageMultiplier = pugi::cast<float>(meleeDamageAttribute.value()); + voc->meleeDamageMultiplier = pugi::cast<float>(meleeDamageAttribute.value()); } pugi::xml_attribute distDamageAttribute = childNode.attribute("distDamage"); if (distDamageAttribute) { - voc.distDamageMultiplier = pugi::cast<float>(distDamageAttribute.value()); + voc->distDamageMultiplier = pugi::cast<float>(distDamageAttribute.value()); } pugi::xml_attribute defenseAttribute = childNode.attribute("defense"); if (defenseAttribute) { - voc.defenseMultiplier = pugi::cast<float>(defenseAttribute.value()); + voc->defenseMultiplier = pugi::cast<float>(defenseAttribute.value()); } pugi::xml_attribute armorAttribute = childNode.attribute("armor"); if (armorAttribute) { - voc.armorMultiplier = pugi::cast<float>(armorAttribute.value()); + voc->armorMultiplier = pugi::cast<float>(armorAttribute.value()); } } else if (strcasecmp(childNode.name(), "pvp") == 0) { pugi::xml_attribute pvpDamageReceivedMultiplier = childNode.attribute("damageReceivedMultiplier"); if (pvpDamageReceivedMultiplier) { - voc.pvpDamageReceivedMultiplier = pugi::cast<float>(pvpDamageReceivedMultiplier.value()); + voc->pvpDamageReceivedMultiplier = pugi::cast<float>(pvpDamageReceivedMultiplier.value()); } pugi::xml_attribute pvpDamageDealtMultiplier = childNode.attribute("damageDealtMultiplier"); if (pvpDamageDealtMultiplier) { - voc.pvpDamageDealtMultiplier = pugi::cast<float>(pvpDamageDealtMultiplier.value()); + voc->pvpDamageDealtMultiplier = pugi::cast<float>(pvpDamageDealtMultiplier.value()); } } else if (strcasecmp(childNode.name(), "gem") == 0) { pugi::xml_attribute qualityAttr = childNode.attribute("quality"); pugi::xml_attribute nameAttr = childNode.attribute("name"); auto quality = pugi::cast<uint8_t>(qualityAttr.value()); auto name = nameAttr.as_string(); - voc.wheelGems[static_cast<WheelGemQuality_t>(quality)] = name; + voc->wheelGems[static_cast<WheelGemQuality_t>(quality)] = name; } } } return true; } -Vocation* Vocations::getVocation(uint16_t id) { +std::shared_ptr<Vocation> Vocations::getVocation(uint16_t id) { auto it = vocationsMap.find(id); if (it == vocationsMap.end()) { g_logger().warn("[Vocations::getVocation] - " @@ -197,12 +202,12 @@ Vocation* Vocations::getVocation(uint16_t id) { id); return nullptr; } - return &it->second; + return it->second; } uint16_t Vocations::getVocationId(const std::string &name) const { for (const auto &it : vocationsMap) { - if (strcasecmp(it.second.name.c_str(), name.c_str()) == 0) { + if (strcasecmp(it.second->name.c_str(), name.c_str()) == 0) { return it.first; } } @@ -211,7 +216,7 @@ uint16_t Vocations::getVocationId(const std::string &name) const { uint16_t Vocations::getPromotedVocation(uint16_t vocationId) const { for (const auto &it : vocationsMap) { - if (it.second.fromVocation == vocationId && it.first != vocationId) { + if (it.second->fromVocation == vocationId && it.first != vocationId) { return it.first; } } @@ -292,7 +297,7 @@ std::vector<WheelGemSupremeModifier_t> Vocation::getSupremeGemModifiers() { auto allModifiers = magic_enum::enum_entries<WheelGemSupremeModifier_t>(); g_logger().debug("Loading supreme gem modifiers for vocation: {}", vocationName); for (const auto &[value, modifierName] : allModifiers) { - std::string targetVocation(modifierName.substr(0, modifierName.find("_"))); + std::string targetVocation(modifierName.substr(0, modifierName.find('_'))); toLowerCaseString(targetVocation); g_logger().debug("Checking supreme gem modifier: {}, targetVocation: {}", modifierName, targetVocation); if (targetVocation == "general" || targetVocation.find(vocationName) != std::string::npos) { diff --git a/src/creatures/players/vocations/vocation.hpp b/src/creatures/players/vocations/vocation.hpp index a658e21ece7..0ad95ac0fc0 100644 --- a/src/creatures/players/vocations/vocation.hpp +++ b/src/creatures/players/vocations/vocation.hpp @@ -179,16 +179,17 @@ class Vocations { } bool loadFromXml(); + bool reload(); - Vocation* getVocation(uint16_t id); - const std::map<uint16_t, Vocation> &getVocations() const { + std::shared_ptr<Vocation> getVocation(uint16_t id); + const std::map<uint16_t, std::shared_ptr<Vocation>> &getVocations() const { return vocationsMap; } uint16_t getVocationId(const std::string &name) const; uint16_t getPromotedVocation(uint16_t vocationId) const; private: - std::map<uint16_t, Vocation> vocationsMap; + std::map<uint16_t, std::shared_ptr<Vocation>> vocationsMap; }; constexpr auto g_vocations = Vocations::getInstance; diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index 77a15f7cbf7..4c7a3dc52e0 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -130,16 +130,16 @@ namespace { struct PromotionScroll { uint16_t itemId; - std::string storageKey; + std::string name; uint8_t extraPoints; }; std::vector<PromotionScroll> WheelOfDestinyPromotionScrolls = { - { 43946, "wheel.scroll.abridged", 3 }, - { 43947, "wheel.scroll.basic", 5 }, - { 43948, "wheel.scroll.revised", 9 }, - { 43949, "wheel.scroll.extended", 13 }, - { 43950, "wheel.scroll.advanced", 20 }, + { 43946, "abridged", 3 }, + { 43947, "basic", 5 }, + { 43948, "revised", 9 }, + { 43949, "extended", 13 }, + { 43950, "advanced", 20 }, }; } // namespace @@ -283,7 +283,7 @@ bool PlayerWheel::canPlayerSelectPointOnSlot(WheelSlots_t slot, bool recursive) return true; } } else if (slot == WheelSlots_t::SLOT_GREEN_50) { - return recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot)) || true; + return (recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot))) || true; } // Red quadrant @@ -410,7 +410,7 @@ bool PlayerWheel::canPlayerSelectPointOnSlot(WheelSlots_t slot, bool recursive) return true; } } else if (slot == WheelSlots_t::SLOT_RED_50) { - return recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot)) || true; + return (recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot))) || true; } // Purple quadrant @@ -537,7 +537,7 @@ bool PlayerWheel::canPlayerSelectPointOnSlot(WheelSlots_t slot, bool recursive) return true; } } else if (slot == WheelSlots_t::SLOT_PURPLE_50) { - return recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot)) || true; + return (recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot))) || true; } // Blue quadrant @@ -664,7 +664,7 @@ bool PlayerWheel::canPlayerSelectPointOnSlot(WheelSlots_t slot, bool recursive) return true; } } else if (slot == WheelSlots_t::SLOT_BLUE_50) { - return recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot)) || true; + return (recursive && (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot))) || true; } return false; @@ -689,7 +689,7 @@ bool PlayerWheel::getSpellAdditionalArea(const std::string &spellName) const { return false; } - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellArea(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -709,7 +709,7 @@ int PlayerWheel::getSpellAdditionalTarget(const std::string &spellName) const { return 0; } - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalTarget(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -729,7 +729,7 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const return 0; } - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { return checkSpellAdditionalDuration(g_game().getIOWheel()->getWheelBonusData().spells.knight, spellName, stage); } else if (vocationEnum == Vocation_t::VOCATION_PALADIN_CIP) { @@ -744,18 +744,21 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const } void PlayerWheel::addPromotionScrolls(NetworkMessage &msg) const { - uint16_t count = 0; std::vector<uint16_t> unlockedScrolls; for (const auto &scroll : WheelOfDestinyPromotionScrolls) { - auto storageValue = m_player.getStorageValueByName(scroll.storageKey); - if (storageValue > 0) { - count++; + const auto &scrollKv = m_player.kv()->scoped("wheel-of-destiny")->scoped("scrolls"); + if (!scrollKv) { + continue; + } + + auto scrollOpt = scrollKv->get(scroll.name); + if (scrollOpt && scrollOpt->get<bool>()) { unlockedScrolls.push_back(scroll.itemId); } } - msg.add<uint16_t>(count); + msg.add<uint16_t>(unlockedScrolls.size()); for (const auto &itemId : unlockedScrolls) { msg.add<uint16_t>(itemId); } @@ -1016,7 +1019,7 @@ void PlayerWheel::sendOpenWheelWindow(NetworkMessage &msg, uint32_t ownerId) con } msg.addByte(getOptions(ownerId)); // Options - msg.addByte(getPlayerVocationEnum()); // Vocation id + msg.addByte(m_player.getPlayerVocationEnum()); // Vocation id msg.add<uint16_t>(getWheelPoints(false)); // Points (false param for not send extra points) msg.add<uint16_t>(getExtraPoints()); // Extra points @@ -1239,8 +1242,13 @@ uint16_t PlayerWheel::getExtraPoints() const { uint16_t totalBonus = 0; for (const auto &scroll : WheelOfDestinyPromotionScrolls) { - auto storageValue = m_player.getStorageValueByName(scroll.storageKey); - if (storageValue > 0) { + const auto &scrollKv = m_player.kv()->scoped("wheel-of-destiny")->scoped("scrolls"); + if (!scrollKv) { + continue; + } + + auto scrollKV = scrollKv->get(scroll.name); + if (scrollKV && scrollKV->get<bool>()) { totalBonus += scroll.extraPoints; } } @@ -1262,7 +1270,7 @@ uint16_t PlayerWheel::getWheelPoints(bool includeExtraPoints /* = true*/) const bool PlayerWheel::canOpenWheel() const { // Vocation check - if (getPlayerVocationEnum() == Vocation_t::VOCATION_NONE) { + if (m_player.getPlayerVocationEnum() == Vocation_t::VOCATION_NONE) { return false; } @@ -1304,21 +1312,6 @@ uint8_t PlayerWheel::getOptions(uint32_t ownerId) const { return 2; } -uint8_t PlayerWheel::getPlayerVocationEnum() const { - int cipTibiaId = m_player.getVocation()->getClientId(); - if (cipTibiaId == 1 || cipTibiaId == 11) { - return Vocation_t::VOCATION_KNIGHT_CIP; // Knight - } else if (cipTibiaId == 2 || cipTibiaId == 12) { - return Vocation_t::VOCATION_PALADIN_CIP; // Paladin - } else if (cipTibiaId == 3 || cipTibiaId == 13) { - return Vocation_t::VOCATION_SORCERER_CIP; // Sorcerer - } else if (cipTibiaId == 4 || cipTibiaId == 14) { - return Vocation_t::VOCATION_DRUID_CIP; // Druid - } - - return Vocation_t::VOCATION_NONE; -} - bool PlayerWheel::canSelectSlotFullOrPartial(WheelSlots_t slot) const { if (getPointsBySlotType(slot) == getMaxPointsPerSlot(slot)) { g_logger().debug("[{}] points on slot {}, max points {}", __FUNCTION__, getPointsBySlotType(slot), getMaxPointsPerSlot(slot)); @@ -1552,12 +1545,12 @@ void PlayerWheel::registerPlayerBonusData() { } if (m_playerBonusData.avatar.light >= 2) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 3 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Light", bonus); } if (m_playerBonusData.avatar.light >= 3) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 2 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Light", bonus); } } else { @@ -1570,12 +1563,12 @@ void PlayerWheel::registerPlayerBonusData() { } if (m_playerBonusData.avatar.nature >= 2) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 3 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Nature", bonus); } if (m_playerBonusData.avatar.nature >= 3) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 2 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Nature", bonus); } } else { @@ -1588,12 +1581,12 @@ void PlayerWheel::registerPlayerBonusData() { } if (m_playerBonusData.avatar.steel >= 2) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 3 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Steel", bonus); } if (m_playerBonusData.avatar.steel >= 3) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 2 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Steel", bonus); } } else { @@ -1606,19 +1599,19 @@ void PlayerWheel::registerPlayerBonusData() { } if (m_playerBonusData.avatar.storm >= 2) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 3 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Storm", bonus); } if (m_playerBonusData.avatar.storm >= 3) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 2 * 60 * 1000; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Storm", bonus); } } else { setSpellInstant("Avatar of Storm", false); } - for (const auto spell : m_playerBonusData.spells) { + for (const auto &spell : m_playerBonusData.spells) { upgradeSpell(spell); } @@ -1774,7 +1767,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus auto &spellsVector = bonusData.spells; if (!spellsVector.empty()) { g_logger().debug("Spells:"); - for (const auto spell : bonusData.spells) { + for (const auto &spell : bonusData.spells) { g_logger().debug(" {}", spell); } } @@ -1785,7 +1778,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus void PlayerWheel::loadDedicationAndConvictionPerks() { using VocationBonusFunction = std::function<void(const std::shared_ptr<Player> &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; auto wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); - auto vocationCipId = getPlayerVocationEnum(); + auto vocationCipId = m_player.getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { return; } @@ -1826,7 +1819,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto redStageValue = static_cast<uint8_t>(redStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_DRUID_CIP) { m_playerBonusData.stages.blessingOfTheGrove = redStageValue; } else if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { @@ -1854,7 +1847,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto purpleStage = static_cast<uint8_t>(purpleStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.avatar.steel = purpleStage; for (uint8_t i = 0; i < purpleStage; ++i) { @@ -1885,7 +1878,7 @@ void PlayerWheel::loadRevelationPerks() { m_playerBonusData.stats.healing += statsHealing; auto blueStage = static_cast<uint8_t>(blueStageEnum); - auto vocationEnum = getPlayerVocationEnum(); + auto vocationEnum = m_player.getPlayerVocationEnum(); if (vocationEnum == Vocation_t::VOCATION_KNIGHT_CIP) { m_playerBonusData.stages.combatMastery = blueStage; } else if (vocationEnum == Vocation_t::VOCATION_SORCERER_CIP) { @@ -2410,21 +2403,25 @@ int32_t PlayerWheel::checkBattleHealingAmount() const { } int32_t PlayerWheel::checkAvatarSkill(WheelAvatarSkill_t skill) const { - if (skill == WheelAvatarSkill_t::NONE || getOnThinkTimer(WheelOnThink_t::AVATAR) <= OTSYS_TIME()) { + if (skill == WheelAvatarSkill_t::NONE || (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) <= OTSYS_TIME() && getOnThinkTimer(WheelOnThink_t::AVATAR_FORGE) <= OTSYS_TIME())) { return 0; } uint8_t stage = 0; - if (getInstant("Avatar of Light")) { - stage = getStage(WheelStage_t::AVATAR_OF_LIGHT); - } else if (getInstant("Avatar of Steel")) { - stage = getStage(WheelStage_t::AVATAR_OF_STEEL); - } else if (getInstant("Avatar of Nature")) { - stage = getStage(WheelStage_t::AVATAR_OF_NATURE); - } else if (getInstant("Avatar of Storm")) { - stage = getStage(WheelStage_t::AVATAR_OF_STORM); + if (getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL) > OTSYS_TIME()) { + if (getInstant("Avatar of Light")) { + stage = getStage(WheelStage_t::AVATAR_OF_LIGHT); + } else if (getInstant("Avatar of Steel")) { + stage = getStage(WheelStage_t::AVATAR_OF_STEEL); + } else if (getInstant("Avatar of Nature")) { + stage = getStage(WheelStage_t::AVATAR_OF_NATURE); + } else if (getInstant("Avatar of Storm")) { + stage = getStage(WheelStage_t::AVATAR_OF_STORM); + } else { + return 0; + } } else { - return 0; + stage = 3; } if (skill == WheelAvatarSkill_t::DAMAGE_REDUCTION) { @@ -2534,7 +2531,7 @@ void PlayerWheel::reduceAllSpellsCooldownTimer(int32_t value) { } void PlayerWheel::resetUpgradedSpells() { - for (const auto spell : m_learnedSpellsSelected) { + for (const auto &spell : m_learnedSpellsSelected) { if (m_player.hasLearnedInstantSpell(spell)) { m_player.forgetInstantSpell(spell); } diff --git a/src/creatures/players/wheel/player_wheel.hpp b/src/creatures/players/wheel/player_wheel.hpp index 303063beb9b..14f922e9597 100644 --- a/src/creatures/players/wheel/player_wheel.hpp +++ b/src/creatures/players/wheel/player_wheel.hpp @@ -205,7 +205,6 @@ class PlayerWheel { * indicating that the player can increase points but cannot decrease the ID. */ uint8_t getOptions(uint32_t ownerId) const; - uint8_t getPlayerVocationEnum() const; std::shared_ptr<KV> gemsKV() const; diff --git a/src/creatures/players/wheel/wheel_definitions.hpp b/src/creatures/players/wheel/wheel_definitions.hpp index 8432e9dca21..c23d2adf53f 100644 --- a/src/creatures/players/wheel/wheel_definitions.hpp +++ b/src/creatures/players/wheel/wheel_definitions.hpp @@ -105,9 +105,10 @@ enum class WheelOnThink_t : uint8_t { FOCUS_MASTERY = 4, GIFT_OF_LIFE = 5, DIVINE_EMPOWERMENT = 6, - AVATAR = 7, + AVATAR_SPELL = 7, + AVATAR_FORGE = 8, - TOTAL_COUNT = 8 + TOTAL_COUNT = 9 }; enum class WheelStat_t : uint8_t { diff --git a/src/creatures/players/wheel/wheel_gems.hpp b/src/creatures/players/wheel/wheel_gems.hpp index 762684cb383..668d8fe05db 100644 --- a/src/creatures/players/wheel/wheel_gems.hpp +++ b/src/creatures/players/wheel/wheel_gems.hpp @@ -174,7 +174,7 @@ class GemModifierStrategy { public: explicit GemModifierStrategy(PlayerWheel &wheel) : m_wheel(wheel) { } - virtual ~GemModifierStrategy() { } + virtual ~GemModifierStrategy() = default; virtual void execute() = 0; protected: @@ -211,7 +211,7 @@ class GemModifierStatStrategy : public GemModifierStrategy { class GemModifierRevelationStrategy : public GemModifierStrategy { public: - explicit GemModifierRevelationStrategy(PlayerWheel &wheel, WheelGemAffinity_t affinity, uint16_t value) : + explicit GemModifierRevelationStrategy(PlayerWheel &wheel, WheelGemAffinity_t affinity, [[maybe_unused]] uint16_t value) : GemModifierStrategy(wheel), m_affinity(affinity) { } @@ -224,9 +224,9 @@ class GemModifierRevelationStrategy : public GemModifierStrategy { class GemModifierSpellBonusStrategy : public GemModifierStrategy { public: - explicit GemModifierSpellBonusStrategy(PlayerWheel &wheel, const std::string &spellName, WheelSpells::Bonus bonus) : + explicit GemModifierSpellBonusStrategy(PlayerWheel &wheel, std::string spellName, WheelSpells::Bonus bonus) : GemModifierStrategy(wheel), - m_spellName(spellName), + m_spellName(std::move(spellName)), m_bonus(bonus) { } void execute() override; @@ -256,7 +256,7 @@ class WheelModifierContext { Vocation_t m_vocation; }; -static int32_t getHealthValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { +[[maybe_unused]] static int32_t getHealthValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { static const std::unordered_map<WheelGemBasicModifier_t, std::unordered_map<Vocation_t, int32_t>> stats = { { WheelGemBasicModifier_t::Vocation_Health, @@ -333,7 +333,7 @@ static int32_t getHealthValue(Vocation_t vocation, WheelGemBasicModifier_t modif return 0; } -static int32_t getManaValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { +[[maybe_unused]] static int32_t getManaValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { static const std::unordered_map<WheelGemBasicModifier_t, std::unordered_map<Vocation_t, int32_t>> stats = { { WheelGemBasicModifier_t::Vocation_Mana_FireResistance, @@ -409,7 +409,7 @@ static int32_t getManaValue(Vocation_t vocation, WheelGemBasicModifier_t modifie return 0; } -static int32_t getCapacityValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { +[[maybe_unused]] static int32_t getCapacityValue(Vocation_t vocation, WheelGemBasicModifier_t modifier) { static const std::unordered_map<WheelGemBasicModifier_t, std::unordered_map<Vocation_t, int32_t>> stats = { { WheelGemBasicModifier_t::Vocation_Capacity_FireResistance, diff --git a/src/enums/item_attribute.hpp b/src/enums/item_attribute.hpp index adc49c11a19..be7b7445710 100644 --- a/src/enums/item_attribute.hpp +++ b/src/enums/item_attribute.hpp @@ -46,6 +46,7 @@ enum ItemAttribute_t : uint64_t { LOOTMESSAGE_SUFFIX = 33, STORE_INBOX_CATEGORY = 34, OBTAINCONTAINER = 35, + AUGMENTS = 36, }; enum ItemDecayState_t : uint8_t { diff --git a/src/enums/player_cyclopedia.hpp b/src/enums/player_cyclopedia.hpp new file mode 100644 index 00000000000..f0637011a19 --- /dev/null +++ b/src/enums/player_cyclopedia.hpp @@ -0,0 +1,38 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2024 OpenTibiaBR <opentibiabr@outlook.com> + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#ifndef USE_PRECOMPILED_HEADERS + #include <cstdint> +#endif + +enum CyclopediaBadge_t : uint8_t { + ACCOUNT_AGE = 1, + LOYALTY, + ACCOUNT_ALL_LEVEL, + ACCOUNT_ALL_VOCATIONS, + TOURNAMENT_PARTICIPATION, + TOURNAMENT_POINTS, +}; + +enum CyclopediaTitle_t : uint8_t { + NOTHING = 0, + GOLD, + MOUNTS, + OUTFITS, + LEVEL, + HIGHSCORES, + BESTIARY, + BOSSTIARY, + DAILY_REWARD, + TASK, + MAP, + OTHERS, +}; diff --git a/src/game/bank/bank.cpp b/src/game/bank/bank.cpp index 30345e0495b..d9a056396ce 100644 --- a/src/game/bank/bank.cpp +++ b/src/game/bank/bank.cpp @@ -80,18 +80,18 @@ const std::set<std::string> deniedNames = { "paladinsample" }; -const uint32_t minTownId = 3; - bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount) { if (!destination) { g_logger().error("Bank::transferTo: destination is nullptr"); return false; } + auto bankable = getBankable(); if (!bankable) { g_logger().error("Bank::transferTo: bankable is nullptr"); return false; } + auto destinationBankable = destination->getBankable(); if (!destinationBankable) { g_logger().error("Bank::transferTo: destinationBankable is nullptr"); @@ -102,11 +102,13 @@ bool Bank::transferTo(const std::shared_ptr<Bank> destination, uint64_t amount) if (destinationPlayer != nullptr) { auto name = asLowerCaseString(destinationPlayer->getName()); replaceString(name, " ", ""); + if (deniedNames.contains(name)) { g_logger().warn("Bank::transferTo: denied name: {}", name); return false; } - if (destinationPlayer->getTown()->getID() < minTownId) { + + if (destinationPlayer->getTown()->getID() < g_configManager().getNumber(MIN_TOWN_ID_TO_BANK_TRANSFER, __FUNCTION__)) { g_logger().warn("Bank::transferTo: denied town: {}", destinationPlayer->getTown()->getID()); return false; } diff --git a/src/game/functions/game_reload.cpp b/src/game/functions/game_reload.cpp index 887877bb1eb..0fc74bcee71 100644 --- a/src/game/functions/game_reload.cpp +++ b/src/game/functions/game_reload.cpp @@ -52,6 +52,8 @@ bool GameReload::init(Reload_t reloadTypes) const { return reloadScripts(); case Reload_t::RELOAD_TYPE_GROUPS: return reloadGroups(); + case Reload_t::RELOAD_TYPE_VOCATIONS: + return reloadVocations(); default: return false; } @@ -114,7 +116,6 @@ bool GameReload::reloadCore() const { const bool coreLoaded = g_luaEnvironment().loadFile(coreFolder + "/core.lua", "core.lua") == 0; if (coreLoaded) { - const auto &datapackFolder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__); const bool scriptsLoaded = g_scripts().loadScripts(coreFolder + "/scripts/lib", true, false); if (scriptsLoaded) { return true; @@ -201,3 +202,9 @@ bool GameReload::reloadGroups() const { logReloadStatus("Groups", result); return result; } + +bool GameReload::reloadVocations() const { + const bool result = g_vocations().reload(); + logReloadStatus("Vocations", result); + return result; +} diff --git a/src/game/functions/game_reload.hpp b/src/game/functions/game_reload.hpp index e2f3789cfde..45ff35c01a2 100644 --- a/src/game/functions/game_reload.hpp +++ b/src/game/functions/game_reload.hpp @@ -29,6 +29,7 @@ enum class Reload_t : uint8_t { RELOAD_TYPE_RAIDS, RELOAD_TYPE_SCRIPTS, RELOAD_TYPE_GROUPS, + RELOAD_TYPE_VOCATIONS, // Every is last RELOAD_TYPE_LAST @@ -65,6 +66,7 @@ class GameReload : public Game { bool reloadRaids() const; bool reloadScripts() const; bool reloadGroups() const; + bool reloadVocations() const; }; constexpr auto g_gameReload = GameReload::getInstance; diff --git a/src/game/game.cpp b/src/game/game.cpp index cac0b596ebf..621e3593816 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -37,6 +37,8 @@ #include "creatures/players/imbuements/imbuements.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" #include "creatures/npcs/npc.hpp" #include "server/network/webhook/webhook.hpp" #include "server/network/protocol/protocollogin.hpp" @@ -53,23 +55,6 @@ #include <appearances.pb.h> -enum class HighscoreCategories_t : uint8_t { - EXPERIENCE = 0, - FIST_FIGHTING = 1, - CLUB_FIGHTING = 2, - SWORD_FIGHTING = 3, - AXE_FIGHTING = 4, - DISTANCE_FIGHTING = 5, - SHIELDING = 6, - FISHING = 7, - MAGIC_LEVEL = 8, - LOYALTY = 9, - ACHIEVEMENTS = 10, - CHARMS = 11, - DROME = 12, - GOSHNAR = 13, -}; - namespace InternalGame { void sendBlockEffect(BlockType_t blockType, CombatType_t combatType, const Position &targetPos, std::shared_ptr<Creature> source) { if (blockType == BLOCK_DEFENSE) { @@ -109,7 +94,7 @@ namespace InternalGame { } if (blockType != BLOCK_NONE) { - g_game().sendSingleSoundEffect(targetPos, SoundEffect_t::NO_DAMAGE, source); + g_game().sendSingleSoundEffect(targetPos, SoundEffect_t::NO_DAMAGE, std::move(source)); } } @@ -209,14 +194,150 @@ Game::Game() { wildcardTree = std::make_shared<WildcardTreeNode>(false); + m_badges = { + Badge(1, CyclopediaBadge_t::ACCOUNT_AGE, "Fledegeling Hero", 1), + Badge(2, CyclopediaBadge_t::ACCOUNT_AGE, "Veteran Hero", 5), + Badge(3, CyclopediaBadge_t::ACCOUNT_AGE, "Senior Hero", 10), + Badge(4, CyclopediaBadge_t::ACCOUNT_AGE, "Ancient Hero", 15), + Badge(5, CyclopediaBadge_t::ACCOUNT_AGE, "Exalted Hero", 20), + + Badge(6, CyclopediaBadge_t::LOYALTY, "Tibia Loyalist (Grade 1)", 100), + Badge(7, CyclopediaBadge_t::LOYALTY, "Tibia Loyalist (Grade 2)", 1000), + Badge(8, CyclopediaBadge_t::LOYALTY, "Tibia Loyalist (Grade 3)", 5000), + + Badge(9, CyclopediaBadge_t::ACCOUNT_ALL_LEVEL, "Global Player (Grade 1)", 500), + Badge(10, CyclopediaBadge_t::ACCOUNT_ALL_LEVEL, "Global Player (Grade 2)", 1000), + Badge(11, CyclopediaBadge_t::ACCOUNT_ALL_LEVEL, "Global Player (Grade 3)", 2000), + + Badge(12, CyclopediaBadge_t::ACCOUNT_ALL_VOCATIONS, "Master Class (Grade 1)", 100), + Badge(13, CyclopediaBadge_t::ACCOUNT_ALL_VOCATIONS, "Master Class (Grade 2)", 250), + Badge(14, CyclopediaBadge_t::ACCOUNT_ALL_VOCATIONS, "Master Class (Grade 3)", 500), + + Badge(15, CyclopediaBadge_t::TOURNAMENT_PARTICIPATION, "Freshman of the Tournament", 1), + Badge(16, CyclopediaBadge_t::TOURNAMENT_PARTICIPATION, "Regular of the Tournament", 5), + Badge(17, CyclopediaBadge_t::TOURNAMENT_PARTICIPATION, "Hero of the Tournament", 10), + + Badge(18, CyclopediaBadge_t::TOURNAMENT_POINTS, "Tournament Competitor", 1000), + Badge(19, CyclopediaBadge_t::TOURNAMENT_POINTS, "Tournament Challenger", 2500), + Badge(20, CyclopediaBadge_t::TOURNAMENT_POINTS, "Tournament Master", 5000), + Badge(21, CyclopediaBadge_t::TOURNAMENT_POINTS, "Tournament Champion", 10000), + }; + + m_titles = { + Title(1, CyclopediaTitle_t::GOLD, "Gold Hoarder", "Earned at least 1,000,000 gold.", 1000000, false), + Title(2, CyclopediaTitle_t::GOLD, "Platinum Hoarder", "Earned at least 10,000,000 gold.", 10000000, false), + Title(3, CyclopediaTitle_t::GOLD, "Crystal Hoarder", "Earned at least 100,000,000 gold.", 100000000, false), + + Title(4, CyclopediaTitle_t::MOUNTS, "Beaststrider (Grade 1)", "Unlocked 10 or more Mounts.", 10, true), + Title(5, CyclopediaTitle_t::MOUNTS, "Beaststrider (Grade 2)", "Unlocked 20 or more Mounts.", 20, true), + Title(6, CyclopediaTitle_t::MOUNTS, "Beaststrider (Grade 3)", "Unlocked 30 or more Mounts.", 30, true), + Title(7, CyclopediaTitle_t::MOUNTS, "Beaststrider (Grade 4)", "Unlocked 40 or more Mounts.", 40, true), + Title(8, CyclopediaTitle_t::MOUNTS, "Beaststrider (Grade 5)", "Unlocked 50 or more Mounts.", 50, true), + + Title(9, CyclopediaTitle_t::OUTFITS, "Tibia's Topmodel (Grade 1)", "Unlocked 10 or more Outfits.", 10, true), + Title(10, CyclopediaTitle_t::OUTFITS, "Tibia's Topmodel (Grade 2)", "Unlocked 20 or more Outfits.", 20, true), + Title(11, CyclopediaTitle_t::OUTFITS, "Tibia's Topmodel (Grade 3)", "Unlocked 30 or more Outfits.", 30, true), + Title(12, CyclopediaTitle_t::OUTFITS, "Tibia's Topmodel (Grade 4)", "Unlocked 40 or more Outfits.", 40, true), + Title(13, CyclopediaTitle_t::OUTFITS, "Tibia's Topmodel (Grade 5)", "Unlocked 50 or more Outfits.", 50, true), + + Title(14, CyclopediaTitle_t::LEVEL, "Trolltrasher", "Reached level 50.", 50, false), + Title(15, CyclopediaTitle_t::LEVEL, "Cyclopscamper", "Reached level 100.", 100, false), + Title(16, CyclopediaTitle_t::LEVEL, "Dragondouser", "Reached level 200.", 200, false), + Title(17, CyclopediaTitle_t::LEVEL, "Demondoom", "Reached level 300.", 300, false), + Title(18, CyclopediaTitle_t::LEVEL, "Drakenbane", "Reached level 400.", 400, false), + Title(19, CyclopediaTitle_t::LEVEL, "Silencer", "Reached level 500.", 500, false), + Title(20, CyclopediaTitle_t::LEVEL, "Exalted", "Reached level 1000.", 1000, false), + + Title(21, CyclopediaTitle_t::HIGHSCORES, "Apex Predator", "", "Highest Level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::EXPERIENCE)), + Title(22, CyclopediaTitle_t::HIGHSCORES, "Big Boss", "", "Highest score of accumulated boss points on character's world.", static_cast<uint8_t>(HighscoreCategories_t::BOSS_POINTS)), + Title(23, CyclopediaTitle_t::HIGHSCORES, "Jack of all Taints", "", "Highest score for killing Goshnar and his aspects on character's world.", static_cast<uint8_t>(HighscoreCategories_t::GOSHNAR)), + Title(24, CyclopediaTitle_t::HIGHSCORES, "Legend of Fishing", "", "Highest fishing level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::FISHING)), + Title(25, CyclopediaTitle_t::HIGHSCORES, "Legend of Magic", "", "Highest magic level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::MAGIC_LEVEL)), + Title(26, CyclopediaTitle_t::HIGHSCORES, "Legend of Marksmanship", "", "Highest distance level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::DISTANCE_FIGHTING)), + Title(27, CyclopediaTitle_t::HIGHSCORES, "Legend of the Axe", "", "Highest axe level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::AXE_FIGHTING)), + Title(28, CyclopediaTitle_t::HIGHSCORES, "Legend of the Club", "", "Highest club level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::CLUB_FIGHTING)), + Title(29, CyclopediaTitle_t::HIGHSCORES, "Legend of the Fist", "", "Highest fist level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::FIST_FIGHTING)), + Title(30, CyclopediaTitle_t::HIGHSCORES, "Legend of the Shield", "", "Highest shielding level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::SHIELDING)), + Title(31, CyclopediaTitle_t::HIGHSCORES, "Legend of the Sword", "", "Highest sword level on character's world.", static_cast<uint8_t>(HighscoreCategories_t::SWORD_FIGHTING)), + Title(32, CyclopediaTitle_t::HIGHSCORES, "Prince Charming", "Princess Charming", "Highest score of accumulated charm points on character's world.", static_cast<uint8_t>(HighscoreCategories_t::CHARMS)), + Title(33, CyclopediaTitle_t::HIGHSCORES, "Reigning Drome Champion", "", "Finished most recent Tibiadrome rota ranked in the top 5.", static_cast<uint8_t>(HighscoreCategories_t::DROME)), + + Title(34, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_HUMANOID), "Bipedantic", "", "Unlocked All Humanoid Bestiary entries."), + Title(35, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_LYCANTHROPE), "Blood Moon Hunter", "Blood Moon Huntress", "Unlocked All Lycanthrope Bestiary entries."), + Title(36, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_AMPHIBIC), "Coldblooded", "", "Unlocked All Amphibic Bestiary entries."), + Title(37, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_BIRD), "Death from Below", "", "Unlocked all Bird Bestiary entries."), + Title(38, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_DEMON), "Demonator", "", "Unlocked all Demon Bestiary entries."), + Title(39, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_DRAGON), "Dragonslayer", "", "Unlocked all Dragon Bestiary entries."), + Title(40, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_ELEMENTAL), "Elementalist", "", "Unlocked all Elemental Bestiary entries."), + Title(41, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_VERMIN), "Exterminator", "", "Unlocked all Vermin Bestiary entries."), + Title(42, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_FEY), "Fey Swatter", "", "Unlocked all Fey Bestiary entries."), + Title(43, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_UNDEAD), "Ghosthunter", "Ghosthuntress", "Unlocked all Undead Bestiary entries."), + Title(44, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_CONSTRUCT), "Handyman", "Handywoman", "Unlocked all Construct Bestiary entries."), + Title(45, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_MAMMAL), "Huntsman", "Huntress", "Unlocked all Mammal Bestiary entries."), + Title(46, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_EXTRA_DIMENSIONAL), "Interdimensional Destroyer", "", "Unlocked all Extra Dimensional Bestiary entries."), + Title(47, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_HUMAN), "Manhunter", "Manhuntress", "Unlocked all Human Bestiary entries."), + Title(48, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_MAGICAL), "Master of Illusion", "Mistress of Illusion", "Unlocked all Magical Bestiary entries."), + Title(49, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_SLIME), "Ooze Blues", "", "Unlocked all Slime Bestiary entries."), + Title(50, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_AQUATIC), "Sea Bane", "", "Unlocked all Aquatic Bestiary entries."), + Title(51, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_REPTILE), "Snake Charmer", "", "Unlocked all Reptile Bestiary entries."), + Title(52, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_GIANT), "Tumbler", "", "Unlocked all Giant Bestiary entries."), + Title(53, CyclopediaTitle_t::BESTIARY, static_cast<uint16_t>(BestiaryType_t::BESTY_RACE_PLANT), "Weedkiller", "", "Unlocked all Plant Bestiary entries."), + Title(54, CyclopediaTitle_t::BESTIARY, 0, "Executioner", "", "Unlocked all Bestiary entries."), + + Title(55, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_NEMESIS), "Boss Annihilator", "", "Unlocked all Nemesis bosses.", 0, false), + Title(56, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_ARCHFOE), "Boss Destroyer", "", "Unlocked 10 or more Archfoe bosses.", 10, true), + Title(57, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_NEMESIS), "Boss Devastator", "", "Unlocked 10 or more Nemesis bosses.", 10, true), + Title(58, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_ARCHFOE), "Boss Eraser", "", "Unlocked all Archfoe bosses.", 0, false), + Title(59, CyclopediaTitle_t::BOSSTIARY, 0, "Boss Executioner", "", "Unlocked all bosses.", 0, false), + Title(60, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_BANE), "Boss Hunter", "", "Unlocked 10 or more Bane bosses.", 10, true), + Title(61, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_NEMESIS), "Boss Obliterator", "", "Unlocked 40 or more Nemesis bosses.", 40, true), + Title(62, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_BANE), "Boss Slayer", "", "Unlocked all Bane bosses.", 0, false), + Title(63, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_ARCHFOE), "Boss Smiter", "", "Unlocked 40 or more Archfoe bosses.", 40, true), + Title(64, CyclopediaTitle_t::BOSSTIARY, static_cast<uint16_t>(BosstiaryRarity_t::RARITY_BANE), "Boss Veteran", "", "Unlocked 40 or more Bane bosses.", 40, true), + + Title(65, CyclopediaTitle_t::DAILY_REWARD, "Creature of Habit (Grade 1)", "Reward Streak of at least 7 days of consecutive logins.", 7, true), + Title(66, CyclopediaTitle_t::DAILY_REWARD, "Creature of Habit (Grade 2)", "Reward Streak of at least 30 days of consecutive logins.", 30, true), + Title(67, CyclopediaTitle_t::DAILY_REWARD, "Creature of Habit (Grade 3)", "Reward Streak of at least 90 days of consecutive logins.", 90, true), + Title(68, CyclopediaTitle_t::DAILY_REWARD, "Creature of Habit (Grade 4)", "Reward Streak of at least 180 days of consecutive logins.", 180, true), + Title(69, CyclopediaTitle_t::DAILY_REWARD, "Creature of Habit (Grade 5)", "Reward Streak of at least 365 days of consecutive logins.", 365, true), + + Title(70, CyclopediaTitle_t::TASK, "Aspiring Huntsman", "Invested 160,000 tasks points.", 160000, true, "Aspiring Huntswoman"), + Title(71, CyclopediaTitle_t::TASK, "Competent Beastslayer", "Invested 320,000 tasks points.", 320000, true), + Title(72, CyclopediaTitle_t::TASK, "Feared Bountyhunter", "Invested 430,000 tasks points.", 430000, true), + + Title(73, CyclopediaTitle_t::MAP, "Dedicated Entrepreneur", "Explored 50% of all the map areas.", 50, false), + Title(74, CyclopediaTitle_t::MAP, "Globetrotter", "Explored all map areas.", 100, false), + + Title(75, CyclopediaTitle_t::OTHERS, "Guild Leader", "Leading a Guild.", false), + Title(76, CyclopediaTitle_t::OTHERS, "Proconsul of Iksupan", "Only a true devotee to the cause of the ancient Iks and their lost legacy may step up to the rank of proconsul.", true), + Title(77, CyclopediaTitle_t::OTHERS, "Admirer of the Crown", "Adjust your crown and handle it.", true), + Title(78, CyclopediaTitle_t::OTHERS, "Big Spender", "Unlocked the full Golden Outfit.", true), + Title(79, CyclopediaTitle_t::OTHERS, "Challenger of the Iks", "Challenged Ahau, guardian of Iksupan, in traditional Iks warrior attire.", true), + Title(80, CyclopediaTitle_t::OTHERS, "Royal Bounacean Advisor", "Called to the court of Bounac by Kesar the Younger himself.", true), + Title(81, CyclopediaTitle_t::OTHERS, "Aeternal", "Awarded exclusively to stalwart heroes keeping the faith under all circumstances.", true), + Title(82, CyclopediaTitle_t::OTHERS, "Robinson Crusoe", "Some discoveries are reserved to only the most experienced adventurers. Until the next frontier opens on the horizon.", true), + Title(83, CyclopediaTitle_t::OTHERS, "Chompmeister", "Awarded only to true connoisseurs undertaking even the most exotic culinary escapades.", true), + Title(84, CyclopediaTitle_t::OTHERS, "Bringer of Rain", "Forging through battle after battle like a true gladiator.", true), + Title(85, CyclopediaTitle_t::OTHERS, "Beastly", "Reached 2000 charm points. Quite beastly!", true), + Title(86, CyclopediaTitle_t::OTHERS, "Midnight Hunter", "When the hunter becomes the hunted, perseverance decides the game.", true), + Title(87, CyclopediaTitle_t::OTHERS, "Ratinator", "Killing some snarky cave rats is helpful, killing over ten thousand of them is a statement.", true), + Title(88, CyclopediaTitle_t::OTHERS, "Doomsday Nemesis", "Awarded for great help in the battle against Gaz'haragoth.", true), + Title(89, CyclopediaTitle_t::OTHERS, "Hero of Bounac", "You prevailed during the battle of Bounac and broke the siege that held Bounac's people in its firm grasp.", true), // Derrotar o boss Drume. + Title(90, CyclopediaTitle_t::OTHERS, "King of Demon", "Defeat Morshabaal 5 times.", 0, true, "Queen of Demon"), + Title(91, CyclopediaTitle_t::OTHERS, "Planegazer", "Followed the trail of the Planestrider to the end.", true), // Derrotar o boss Planestrider + Title(92, CyclopediaTitle_t::OTHERS, "Time Traveller", "Anywhere in time or space.", true), // Derrotar o boss Lord Retro + Title(93, CyclopediaTitle_t::OTHERS, "Truly Boss", "Reach 15,000 boss points.", true), + }; + m_highscoreCategoriesNames = { { static_cast<uint8_t>(HighscoreCategories_t::ACHIEVEMENTS), "Achievement Points" }, { static_cast<uint8_t>(HighscoreCategories_t::AXE_FIGHTING), "Axe Fighting" }, + { static_cast<uint8_t>(HighscoreCategories_t::BOSS_POINTS), "Boss Points" }, { static_cast<uint8_t>(HighscoreCategories_t::CHARMS), "Charm Points" }, { static_cast<uint8_t>(HighscoreCategories_t::CLUB_FIGHTING), "Club Fighting" }, - { static_cast<uint8_t>(HighscoreCategories_t::EXPERIENCE), "Experience Points" }, { static_cast<uint8_t>(HighscoreCategories_t::DISTANCE_FIGHTING), "Distance Fighting" }, { static_cast<uint8_t>(HighscoreCategories_t::DROME), "Drome Score" }, + { static_cast<uint8_t>(HighscoreCategories_t::EXPERIENCE), "Experience Points" }, { static_cast<uint8_t>(HighscoreCategories_t::FISHING), "Fishing" }, { static_cast<uint8_t>(HighscoreCategories_t::FIST_FIGHTING), "Fist Fighting" }, { static_cast<uint8_t>(HighscoreCategories_t::GOSHNAR), "Goshnar's Taint" }, @@ -284,15 +405,15 @@ void Game::loadBoostedCreature() { MonsterRace selectedMonster; if (!monsterlist.empty()) { - std::vector<MonsterRace> monsters; + std::vector<MonsterRace> m_monsters; for (const auto &[raceId, _name] : BestiaryList) { if (raceId != oldRace) { - monsters.emplace_back(raceId, _name); + m_monsters.emplace_back(raceId, _name); } } - if (!monsters.empty()) { - selectedMonster = monsters[normal_random(0, monsters.size() - 1)]; + if (!m_monsters.empty()) { + selectedMonster = m_monsters[normal_random(0, m_monsters.size() - 1)]; } } @@ -365,9 +486,16 @@ void Game::start(ServiceManager* manager) { g_dispatcher().cycleEvent( EVENT_LUA_GARBAGE_COLLECTION, [this] { g_luaEnvironment().collectGarbage(); }, "Calling GC" ); - g_dispatcher().cycleEvent( - EVENT_REFRESH_MARKET_PRICES, [this] { loadItemsPrice(); }, "Game::loadItemsPrice" - ); + auto marketItemsPriceIntervalMinutes = g_configManager().getNumber(MARKET_REFRESH_PRICES, __FUNCTION__); + if (marketItemsPriceIntervalMinutes > 0) { + auto marketItemsPriceIntervalMS = marketItemsPriceIntervalMinutes * 60000; + if (marketItemsPriceIntervalMS < 60000) { + marketItemsPriceIntervalMS = 60000; + } + g_dispatcher().cycleEvent( + marketItemsPriceIntervalMS, [this] { loadItemsPrice(); }, "Game::loadItemsPrice" + ); + } } GameState_t Game::getGameState() const { @@ -459,18 +587,11 @@ void Game::setGameState(GameState_t newState) { } } -bool Game::loadItemsPrice() { +void Game::loadItemsPrice() { IOMarket::getInstance().updateStatistics(); - std::ostringstream query, marketQuery; - query << "SELECT DISTINCT `itemtype` FROM `market_offers`;"; - - Database &db = Database::getInstance(); - DBResult_ptr result = db.storeQuery(query.str()); - if (!result) { - return false; - } - auto stats = IOMarket::getInstance().getPurchaseStatistics(); + // Update purchased offers (market_history) + const auto &stats = IOMarket::getInstance().getPurchaseStatistics(); for (const auto &[itemId, itemStats] : stats) { std::map<uint8_t, uint64_t> tierToPrice; for (const auto &[tier, tierStats] : itemStats) { @@ -479,12 +600,12 @@ bool Game::loadItemsPrice() { } itemsPriceMap[itemId] = tierToPrice; } + + // Update active buy offers (market_offers) auto offers = IOMarket::getInstance().getActiveOffers(MARKETACTION_BUY); for (const auto &offer : offers) { itemsPriceMap[offer.itemId][offer.tier] = std::max(itemsPriceMap[offer.itemId][offer.tier], offer.price); } - - return true; } void Game::loadMainMap(const std::string &filename) { @@ -505,7 +626,7 @@ void Game::loadCustomMaps(const std::filesystem::path &customMapPath) { int customMapIndex = 0; for (const auto &entry : fs::directory_iterator(customMapPath)) { - const auto realPath = entry.path(); + const auto &realPath = entry.path(); if (realPath.extension() != ".otbm") { continue; @@ -1012,7 +1133,7 @@ bool Game::removeCreature(std::shared_ptr<Creature> creature, bool isLogout /* = } // event method - for (auto spectator : spectators) { + for (const auto &spectator : spectators) { spectator->onRemoveCreature(creature, isLogout); } } @@ -1029,7 +1150,7 @@ bool Game::removeCreature(std::shared_ptr<Creature> creature, bool isLogout /* = removeCreatureCheck(creature); - for (auto summon : creature->getSummons()) { + for (const auto &summon : creature->getSummons()) { summon->setSkillLoss(false); removeCreature(summon); } @@ -1651,12 +1772,10 @@ void Game::playerMoveItem(std::shared_ptr<Player> player, const Position &fromPo player->stowItem(item, count, false); return; } - if (!item->isPushable() || item->hasAttribute(ItemAttribute_t::UNIQUEID)) { player->sendCancelMessage(RETURNVALUE_NOTMOVABLE); return; } - ReturnValue ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); @@ -1747,7 +1866,7 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr<Player> player, std::s } if (item->getContainer() && !item->isStoreItem()) { - for (std::shared_ptr<Item> containerItem : item->getContainer()->getItems(true)) { + for (const std::shared_ptr<Item> &containerItem : item->getContainer()->getItems(true)) { if (containerItem->isStoreItem() && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1763,7 +1882,7 @@ ReturnValue Game::checkMoveItemToCylinder(std::shared_ptr<Player> player, std::s } } if (item->getContainer() && !item->isStoreItem()) { - for (std::shared_ptr<Item> containerItem : item->getContainer()->getItems(true)) { + for (const std::shared_ptr<Item> &containerItem : item->getContainer()->getItems(true)) { if (containerItem->isStoreItem()) { return RETURNVALUE_NOTPOSSIBLE; } @@ -2034,7 +2153,7 @@ ReturnValue Game::internalMoveItem(std::shared_ptr<Cylinder> fromCylinder, std:: ReturnValue Game::internalAddItem(std::shared_ptr<Cylinder> toCylinder, std::shared_ptr<Item> item, int32_t index /*= INDEX_WHEREEVER*/, uint32_t flags /* = 0*/, bool test /* = false*/) { uint32_t remainderCount = 0; - return internalAddItem(toCylinder, item, index, flags, test, remainderCount); + return internalAddItem(std::move(toCylinder), std::move(item), index, flags, test, remainderCount); } ReturnValue Game::internalAddItem(std::shared_ptr<Cylinder> toCylinder, std::shared_ptr<Item> item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount) { @@ -2432,7 +2551,7 @@ bool Game::removeMoney(std::shared_ptr<Cylinder> cylinder, uint64_t money, uint3 size_t i = 0; while (i < containers.size()) { std::shared_ptr<Container> container = containers[i++]; - for (std::shared_ptr<Item> item : container->getItemList()) { + for (const std::shared_ptr<Item> &item : container->getItemList()) { std::shared_ptr<Container> tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); @@ -2727,7 +2846,7 @@ void Game::playerQuickLootCorpse(std::shared_ptr<Player> player, std::shared_ptr uint32_t totalLootedGold = 0; uint32_t totalLootedItems = 0; - for (std::shared_ptr<Item> item : itemList) { + for (const std::shared_ptr<Item> &item : itemList) { uint32_t worth = item->getWorth(); uint16_t baseCount = item->getItemCount(); ObjectCategory_t category = getObjectCategory(item); @@ -2978,7 +3097,7 @@ ReturnValue Game::collectRewardChestItems(std::shared_ptr<Player> player, uint32 auto rewardCount = rewardItemsVector.size(); uint32_t movedRewardItems = 0; std::string lootedItemsMessage; - for (auto item : rewardItemsVector) { + for (const auto &item : rewardItemsVector) { // Stop if player not have free capacity if (item && player->getCapacity() < item->getWeight()) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHCAPACITY); @@ -3199,7 +3318,13 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = } else { const int32_t &slotPosition = equipItem->getSlotPosition(); // Checks if a two-handed item is being equipped in the left slot when the right slot is already occupied and move to backpack - if (slotPosition & SLOTP_LEFT && rightItem && (slotPosition & SLOTP_TWO_HAND)) { + if ( + (slotPosition & SLOTP_LEFT) + && (slotPosition & SLOTP_TWO_HAND) + && rightItem + && !(it.weaponType == WEAPON_DISTANCE) + && !rightItem->isQuiver() + ) { ret = internalCollectManagedItems(player, rightItem, getObjectCategory(rightItem), false); } @@ -3744,6 +3869,19 @@ void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uin return; } } + + const std::shared_ptr<Monster> monster = creature->getMonster(); + if (monster && monster->isFamiliar() && creature->getMaster()->getPlayer() == player && (it.isRune() || it.type == ITEM_TYPE_POTION)) { + player->setNextPotionAction(OTSYS_TIME() + g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__)); + + if (it.isMultiUse()) { + player->sendUseItemCooldown(g_configManager().getNumber(EX_ACTIONS_DELAY_INTERVAL, __FUNCTION__)); + } + + player->sendCancelMessage(RETURNVALUE_CANNOTUSETHISOBJECT); + return; + } + Position toPos = creature->getPosition(); Position walkToPos = fromPos; ReturnValue ret = g_actions().canUse(player, fromPos); @@ -4331,7 +4469,7 @@ void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std:: return; } - for (auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_TEXTEDIT)) { + for (const auto &creatureEvent : player->getCreatureEvents(CREATURE_EVENT_TEXTEDIT)) { if (!creatureEvent->executeTextEdit(player, writeItem, text)) { player->setWriteItem(nullptr); return; @@ -4696,7 +4834,7 @@ void Game::playerRequestTrade(uint32_t playerId, const Position &pos, uint8_t st } if (tradeItemContainer) { - for (std::shared_ptr<Item> containerItem : tradeItemContainer->getItems(true)) { + for (const std::shared_ptr<Item> &containerItem : tradeItemContainer->getItems(true)) { if (containerItem->isStoreItem()) { player->sendTextMessage(MESSAGE_TRADE, "This item cannot be trade."); return; @@ -4927,7 +5065,7 @@ void Game::playerLookInTrade(uint32_t playerId, bool lookAtCounterOffer, uint8_t size_t i = 0; while (i < containers.size()) { std::shared_ptr<Container> container = containers[i++]; - for (std::shared_ptr<Item> item : container->getItemList()) { + for (const std::shared_ptr<Item> &item : container->getItemList()) { std::shared_ptr<Container> tmpContainer = item->getContainer(); if (tmpContainer) { containers.push_back(tmpContainer); @@ -5027,6 +5165,23 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint return; } + if (inBackpacks) { + uint32_t maxContainer = static_cast<uint32_t>(g_configManager().getNumber(MAX_CONTAINER, __FUNCTION__)); + auto backpack = player->getInventoryItem(CONST_SLOT_BACKPACK); + auto mainBackpack = backpack ? backpack->getContainer() : nullptr; + + if (mainBackpack && mainBackpack->getContainerHoldingCount() >= maxContainer) { + player->sendCancelMessage(RETURNVALUE_CONTAINERISFULL); + return; + } + + std::shared_ptr<Tile> tile = player->getTile(); + if (tile && tile->getItemCount() >= 20) { + player->sendCancelMessage(RETURNVALUE_CONTAINERISFULL); + return; + } + } + merchant->onPlayerBuyItem(player, it.id, count, amount, ignoreCap, inBackpacks); player->updateUIExhausted(); } @@ -5379,11 +5534,16 @@ void Game::playerSetManagedContainer(uint32_t playerId, ObjectCategory_t categor std::shared_ptr<Container> container = thing->getContainer(); auto allowConfig = g_configManager().getBoolean(TOGGLE_GOLD_POUCH_ALLOW_ANYTHING, __FUNCTION__) || g_configManager().getBoolean(TOGGLE_GOLD_POUCH_QUICKLOOT_ONLY, __FUNCTION__); - if (!container || (container->getID() == ITEM_GOLD_POUCH && category != OBJECTCATEGORY_GOLD) && !allowConfig) { + if (!container || ((container->getID() == ITEM_GOLD_POUCH && category != OBJECTCATEGORY_GOLD) && !allowConfig)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } + if (container->getID() == ITEM_GOLD_POUCH && !isLootContainer) { + player->sendTextMessage(MESSAGE_FAILURE, "You can only set the gold pouch as a loot container."); + return; + } + if (container->getHoldingPlayer() != player) { player->sendCancelMessage("You must be holding the container to set it as a loot container."); return; @@ -5613,21 +5773,21 @@ void Game::playerRequestAddVip(uint32_t playerId, const std::string &name) { } if (specialVip && !player->hasFlag(PlayerFlags_t::SpecialVIP)) { - player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player->"); + player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player"); return; } - player->addVIP(guid, formattedName, VIPSTATUS_OFFLINE); + player->vip()->add(guid, formattedName, VipStatus_t::Offline); } else { if (vipPlayer->hasFlag(PlayerFlags_t::SpecialVIP) && !player->hasFlag(PlayerFlags_t::SpecialVIP)) { - player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player->"); + player->sendTextMessage(MESSAGE_FAILURE, "You can not add this player"); return; } if (!vipPlayer->isInGhostMode() || player->isAccessPlayer()) { - player->addVIP(vipPlayer->getGUID(), vipPlayer->getName(), vipPlayer->statusVipList); + player->vip()->add(vipPlayer->getGUID(), vipPlayer->getName(), vipPlayer->vip()->getStatus()); } else { - player->addVIP(vipPlayer->getGUID(), vipPlayer->getName(), VIPSTATUS_OFFLINE); + player->vip()->add(vipPlayer->getGUID(), vipPlayer->getName(), VipStatus_t::Offline); } } } @@ -5638,16 +5798,16 @@ void Game::playerRequestRemoveVip(uint32_t playerId, uint32_t guid) { return; } - player->removeVIP(guid); + player->vip()->remove(guid); } -void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { +void Game::playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify, std::vector<uint8_t> vipGroupsId) { std::shared_ptr<Player> player = getPlayerByID(playerId); if (!player) { return; } - player->editVIP(guid, description, icon, notify); + player->vip()->edit(guid, description, icon, notify, vipGroupsId); } void Game::playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm) { @@ -5704,7 +5864,6 @@ void Game::playerCloseImbuementWindow(uint32_t playerid) { } player->setImbuingItem(nullptr); - return; } void Game::playerTurn(uint32_t playerId, Direction dir) { @@ -6012,7 +6171,7 @@ void Game::playerSpeakToNpc(std::shared_ptr<Player> player, const std::string &t } std::shared_ptr<Task> Game::createPlayerTask(uint32_t delay, std::function<void(void)> f, std::string context) const { - return Player::createPlayerTask(delay, f, context); + return Player::createPlayerTask(delay, std::move(f), std::move(context)); } //-- @@ -6351,9 +6510,10 @@ bool Game::combatBlockHit(CombatDamage &damage, std::shared_ptr<Creature> attack InternalGame::sendBlockEffect(primaryBlockType, damage.primary.type, target->getPosition(), attacker); // Damage reflection primary if (!damage.extension && attacker) { - if (targetPlayer && attacker->getMonster() && damage.primary.type != COMBAT_HEALING) { + std::shared_ptr<Monster> attackerMonster = attacker->getMonster(); + if (attackerMonster && targetPlayer && damage.primary.type != COMBAT_HEALING) { // Charm rune (target as player) - const auto mType = g_monsters().getMonsterType(attacker->getName()); + const auto &mType = attackerMonster->getMonsterType(); if (mType) { charmRune_t activeCharm = g_iobestiary().getCharmFromTarget(targetPlayer, mType); if (activeCharm == CHARM_PARRY) { @@ -6597,7 +6757,7 @@ void Game::handleHazardSystemAttack(CombatDamage &damage, std::shared_ptr<Player void Game::notifySpectators(const CreatureVector &spectators, const Position &targetPos, std::shared_ptr<Player> attackerPlayer, std::shared_ptr<Monster> targetMonster) { if (!spectators.empty()) { - for (auto spectator : spectators) { + for (const auto &spectator : spectators) { if (!spectator) { continue; } @@ -6767,7 +6927,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt if (damage.origin != ORIGIN_NONE) { const auto events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); if (!events.empty()) { - for (const auto creatureEvent : events) { + for (const auto &creatureEvent : events) { creatureEvent->executeHealthChange(target, attacker, damage); } damage.origin = ORIGIN_NONE; @@ -6971,7 +7131,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt if (target->hasCondition(CONDITION_MANASHIELD) && damage.primary.type != COMBAT_UNDEFINEDDAMAGE) { int32_t manaDamage = std::min<int32_t>(target->getMana(), healthChange); - uint16_t manaShield = target->getManaShield(); + uint32_t manaShield = target->getManaShield(); if (manaShield > 0) { if (manaShield > manaDamage) { target->setManaShield(manaShield - manaDamage); @@ -6986,7 +7146,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt if (damage.origin != ORIGIN_NONE) { const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { - for (const auto creatureEvent : events) { + for (const auto &creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); } healthChange = damage.primary.value + damage.secondary.value; @@ -7090,7 +7250,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt if (damage.origin != ORIGIN_NONE) { const auto events = target->getCreatureEvents(CREATURE_EVENT_HEALTHCHANGE); if (!events.empty()) { - for (const auto creatureEvent : events) { + for (const auto &creatureEvent : events) { creatureEvent->executeHealthChange(target, attacker, damage); } damage.origin = ORIGIN_NONE; @@ -7115,7 +7275,7 @@ bool Game::combatChangeHealth(std::shared_ptr<Creature> attacker, std::shared_pt if (realDamage == 0) { return true; } else if (realDamage >= targetHealth) { - for (const auto creatureEvent : target->getCreatureEvents(CREATURE_EVENT_PREPAREDEATH)) { + for (const auto &creatureEvent : target->getCreatureEvents(CREATURE_EVENT_PREPAREDEATH)) { if (!creatureEvent->executeOnPrepareDeath(target, attacker)) { return false; } @@ -7191,7 +7351,7 @@ void Game::sendDamageMessageAndEffects( sendEffects(target, damage, targetPos, message, spectators); if (shouldSendMessage(message)) { - sendMessages(attacker, target, damage, targetPos, attackerPlayer, targetPlayer, message, spectators, realDamage); + sendMessages(std::move(attacker), target, damage, targetPos, std::move(attackerPlayer), std::move(targetPlayer), message, spectators, realDamage); } } @@ -7230,7 +7390,7 @@ void Game::sendMessages( std::string spectatorMessage; - for (std::shared_ptr<Creature> spectator : spectators) { + for (const std::shared_ptr<Creature> &spectator : spectators) { std::shared_ptr<Player> tmpPlayer = spectator->getPlayer(); if (!tmpPlayer || tmpPlayer->getPosition().z != targetPos.z) { continue; @@ -7351,7 +7511,7 @@ void Game::applyCharmRune( int8_t chance = charm->id == CHARM_CRIPPLE ? charm->chance : charm->chance + attackerPlayer->getCharmChanceModifier(); g_logger().debug("charm chance: {}, base: {}, bonus: {}", chance, charm->chance, attackerPlayer->getCharmChanceModifier()); if (charm->type == CHARM_OFFENSIVE && (chance >= normal_random(0, 100))) { - g_iobestiary().parseCharmCombat(charm, attackerPlayer, target, realDamage); + g_iobestiary().parseCharmCombat(charm, attackerPlayer, std::move(target), realDamage); } } } @@ -7444,7 +7604,7 @@ bool Game::combatChangeMana(std::shared_ptr<Creature> attacker, std::shared_ptr< if (damage.origin != ORIGIN_NONE) { const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { - for (const auto creatureEvent : events) { + for (const auto &creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); } damage.origin = ORIGIN_NONE; @@ -7538,7 +7698,7 @@ bool Game::combatChangeMana(std::shared_ptr<Creature> attacker, std::shared_ptr< if (damage.origin != ORIGIN_NONE) { const auto events = target->getCreatureEvents(CREATURE_EVENT_MANACHANGE); if (!events.empty()) { - for (const auto creatureEvent : events) { + for (const auto &creatureEvent : events) { creatureEvent->executeManaChange(target, attacker, damage); } damage.origin = ORIGIN_NONE; @@ -7836,15 +7996,17 @@ 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); + } } } void Game::updateCreatureWalkthrough(std::shared_ptr<Creature> creature) { // Send to clients - for (const auto spectator : Spectators().find<Player>(creature->getPosition(), true)) { + for (const auto &spectator : Spectators().find<Player>(creature->getPosition(), true)) { const auto &tmpPlayer = spectator->getPlayer(); tmpPlayer->sendCreatureWalkthrough(creature, tmpPlayer->canWalkthroughEx(creature)); } @@ -8077,7 +8239,7 @@ void Game::playerLeaveParty(uint32_t playerId) { } std::shared_ptr<Party> party = player->getParty(); - if (!party || player->hasCondition(CONDITION_INFIGHT) && !player->getZoneType() == ZONE_PROTECTION) { + if (!party || (player->hasCondition(CONDITION_INFIGHT) && !player->getZoneType() == ZONE_PROTECTION)) { player->sendTextMessage(TextMessage(MESSAGE_FAILURE, "You cannot leave party, contact the administrator.")); return; } @@ -8121,6 +8283,15 @@ void Game::kickPlayer(uint32_t playerId, bool displayEffect) { player->removePlayer(displayEffect); } +void Game::playerFriendSystemAction(std::shared_ptr<Player> player, uint8_t type, uint8_t titleId) { + if (type == 0x0E) { + player->title()->setCurrentTitle(titleId); + player->sendCyclopediaCharacterBaseInformation(); + player->sendCyclopediaCharacterTitles(); + return; + } +} + void Game::playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page) { uint32_t playerGUID = player->getGUID(); if (characterID != playerGUID) { @@ -8145,7 +8316,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_ query << "SELECT `time`, `level`, `killed_by`, `mostdamage_by`, (select count(*) FROM `player_deaths` WHERE `player_id` = " << playerGUID << ") as `entries` FROM `player_deaths` WHERE `player_id` = " << playerGUID << " ORDER BY `time` DESC LIMIT " << offset << ", " << entriesPerPage; uint32_t playerID = player->getID(); - std::function<void(DBResult_ptr, bool)> callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { + std::function<void(DBResult_ptr, bool)> callback = [playerID, page, entriesPerPage](const DBResult_ptr &result, bool) { std::shared_ptr<Player> player = g_game().getPlayerByID(playerID); if (!player) { return; @@ -8210,7 +8381,7 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_ query << "SELECT `d`.`time`, `d`.`killed_by`, `d`.`mostdamage_by`, `d`.`unjustified`, `d`.`mostdamage_unjustified`, `p`.`name`, (select count(*) FROM `player_deaths` WHERE ((`killed_by` = " << escapedName << " AND `is_player` = 1) OR (`mostdamage_by` = " << escapedName << " AND `mostdamage_is_player` = 1))) as `entries` FROM `player_deaths` AS `d` INNER JOIN `players` AS `p` ON `d`.`player_id` = `p`.`id` WHERE ((`d`.`killed_by` = " << escapedName << " AND `d`.`is_player` = 1) OR (`d`.`mostdamage_by` = " << escapedName << " AND `d`.`mostdamage_is_player` = 1)) ORDER BY `time` DESC LIMIT " << offset << ", " << entriesPerPage; uint32_t playerID = player->getID(); - std::function<void(DBResult_ptr, bool)> callback = [playerID, page, entriesPerPage](DBResult_ptr result, bool) { + std::function<void(DBResult_ptr, bool)> callback = [playerID, page, entriesPerPage](const DBResult_ptr &result, bool) { std::shared_ptr<Player> player = g_game().getPlayerByID(playerID); if (!player) { return; @@ -8257,9 +8428,16 @@ void Game::playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_ case CYCLOPEDIA_CHARACTERINFO_ACHIEVEMENTS: player->achiev()->sendUnlockedSecretAchievements(); break; - case CYCLOPEDIA_CHARACTERINFO_ITEMSUMMARY: - player->sendCyclopediaCharacterItemSummary(); + case CYCLOPEDIA_CHARACTERINFO_ITEMSUMMARY: { + const ItemsTierCountList &inventoryItems = player->getInventoryItemsId(true); + const ItemsTierCountList &storeInboxItems = player->getStoreInboxItemsId(); + const StashItemList &supplyStashItems = player->getStashItems(); + const ItemsTierCountList &depotBoxItems = player->getDepotChestItemsId(); + const ItemsTierCountList &inboxItems = player->getDepotInboxItemsId(); + + player->sendCyclopediaCharacterItemSummary(inventoryItems, storeInboxItems, supplyStashItems, depotBoxItems, inboxItems); break; + } case CYCLOPEDIA_CHARACTERINFO_OUTFITSMOUNTS: player->sendCyclopediaCharacterOutfitsMounts(); break; @@ -8323,12 +8501,12 @@ std::string Game::generateVocationConditionHighscore(uint32_t vocation) { const auto vocationsMap = g_vocations().getVocations(); for (const auto &it : vocationsMap) { const auto &voc = it.second; - if (voc.getFromVocation() == vocation) { + if (voc->getFromVocation() == vocation) { if (firstVocation) { - queryPart << " WHERE `vocation` = " << voc.getId(); + queryPart << " WHERE `vocation` = " << voc->getId(); firstVocation = false; } else { - queryPart << " OR `vocation` = " << voc.getId(); + queryPart << " OR `vocation` = " << voc->getId(); } } } @@ -8372,14 +8550,10 @@ void Game::processHighscoreResults(DBResult_ptr result, uint32_t playerID, uint8 characters.reserve(result->countResults()); if (result) { do { - uint8_t characterVocation; const auto &voc = g_vocations().getVocation(result->getNumber<uint16_t>("vocation")); - if (voc) { - characterVocation = voc->getClientId(); - } else { - characterVocation = 0; - } - characters.emplace_back(std::move(result->getString("name")), result->getNumber<uint64_t>("points"), result->getNumber<uint32_t>("id"), result->getNumber<uint32_t>("rank"), result->getNumber<uint16_t>("level"), characterVocation); + uint8_t characterVocation = voc ? voc->getClientId() : 0; + std::string loyaltyTitle = ""; // todo get loyalty title from player + characters.emplace_back(std::move(result->getString("name")), result->getNumber<uint64_t>("points"), result->getNumber<uint32_t>("id"), result->getNumber<uint32_t>("rank"), result->getNumber<uint16_t>("level"), characterVocation, loyaltyTitle); } while (result->next()); } @@ -8434,39 +8608,7 @@ void Game::playerHighscores(std::shared_ptr<Player> player, HighscoreType_t type return; } - std::string categoryName; - const auto &categoryType = static_cast<HighscoreCategories_t>(category); - switch (categoryType) { - case HighscoreCategories_t::FIST_FIGHTING: - categoryName = "skill_fist"; - break; - case HighscoreCategories_t::CLUB_FIGHTING: - categoryName = "skill_club"; - break; - case HighscoreCategories_t::SWORD_FIGHTING: - categoryName = "skill_sword"; - break; - case HighscoreCategories_t::AXE_FIGHTING: - categoryName = "skill_axe"; - break; - case HighscoreCategories_t::DISTANCE_FIGHTING: - categoryName = "skill_dist"; - break; - case HighscoreCategories_t::SHIELDING: - categoryName = "skill_shielding"; - break; - case HighscoreCategories_t::FISHING: - categoryName = "skill_fishing"; - break; - case HighscoreCategories_t::MAGIC_LEVEL: - categoryName = "maglevel"; - break; - default: { - category = static_cast<uint8_t>(HighscoreCategories_t::EXPERIENCE); - categoryName = "experience"; - break; - } - } + std::string categoryName = getSkillNameById(category); std::string query; if (type == HIGHSCORE_GETENTRIES) { @@ -8484,6 +8626,32 @@ void Game::playerHighscores(std::shared_ptr<Player> player, HighscoreType_t type player->addAsyncOngoingTask(PlayerAsyncTask_Highscore); } +std::string Game::getSkillNameById(uint8_t &skill) { + switch (static_cast<HighscoreCategories_t>(skill)) { + case HighscoreCategories_t::FIST_FIGHTING: + return "skill_fist"; + case HighscoreCategories_t::CLUB_FIGHTING: + return "skill_club"; + case HighscoreCategories_t::SWORD_FIGHTING: + return "skill_sword"; + case HighscoreCategories_t::AXE_FIGHTING: + return "skill_axe"; + case HighscoreCategories_t::DISTANCE_FIGHTING: + return "skill_dist"; + case HighscoreCategories_t::SHIELDING: + return "skill_shielding"; + case HighscoreCategories_t::FISHING: + return "skill_fishing"; + case HighscoreCategories_t::MAGIC_LEVEL: + return "maglevel"; + case HighscoreCategories_t::BOSS_POINTS: + return "boss_points"; + default: + skill = static_cast<uint8_t>(HighscoreCategories_t::EXPERIENCE); + return "experience"; + } +} + void Game::playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation) { std::shared_ptr<Player> player = getPlayerByID(playerId); if (!player) { @@ -8658,13 +8826,13 @@ namespace { auto [itemVector, totalCount] = player->getLockerItemsAndCountById(depotLocker, tier, itemType.id); if (removeAmount > 0) { - if (totalCount == 0 || itemVector.size() == 0) { + if (totalCount == 0 || itemVector.empty()) { offerStatus << "Player " << player->getName() << " not have item for create offer"; return false; } uint32_t count = 0; - for (auto item : itemVector) { + for (const auto &item : itemVector) { if (!item) { continue; } @@ -8750,7 +8918,7 @@ bool checkCanInitCreateMarketOffer(std::shared_ptr<Player> player, uint8_t type, return false; } - if (amount == 0 || !it.stackable && amount > 2000 || it.stackable && amount > 64000) { + if (amount == 0 || (!it.stackable && amount > 2000) || (it.stackable && amount > 64000)) { offerStatus << "Failed to load amount " << amount << " for player " << player->getName(); return false; } @@ -8969,7 +9137,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } - if (amount == 0 || !it.stackable && amount > 2000 || it.stackable && amount > 64000 || amount > offer.amount) { + if (amount == 0 || (!it.stackable && amount > 2000) || (it.stackable && amount > 64000) || amount > offer.amount) { offerStatus << "Invalid offer amount " << amount << " for player " << player->getName(); return; } @@ -9218,7 +9386,7 @@ void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const st return; } - for (const auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_EXTENDED_OPCODE)) { + for (const auto &creatureEvent : player->getCreatureEvents(CREATURE_EVENT_EXTENDED_OPCODE)) { creatureEvent->executeExtendedOpcode(player, opcode, buffer); } } @@ -9270,7 +9438,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui player->setBedItem(nullptr); } else { - for (const auto creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) { + for (const auto &creatureEvent : player->getCreatureEvents(CREATURE_EVENT_MODALWINDOW)) { creatureEvent->executeModalWindow(player, modalWindowId, button, choice); } } @@ -9540,7 +9708,7 @@ void Game::playerRotatePodium(uint32_t playerId, const Position &pos, uint8_t st bool isPodiumOfRenown = itemId == ITEM_PODIUM_OF_RENOWN1 || itemId == ITEM_PODIUM_OF_RENOWN2; if (!isPodiumOfRenown) { auto lookTypeExAttribute = item->getCustomAttribute("LookTypeEx"); - if (!isMonsterVisible || podiumRaceId == 0 || lookTypeExAttribute && lookTypeExAttribute->getInteger() == 39003) { + if (!isMonsterVisible || podiumRaceId == 0 || (lookTypeExAttribute && lookTypeExAttribute->getInteger() == 39003)) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); return; } @@ -9756,7 +9924,7 @@ void Game::removeGuild(uint32_t guildId) { void Game::internalRemoveItems(const std::vector<std::shared_ptr<Item>> &itemVector, uint32_t amount, bool stackable) { if (stackable) { - for (std::shared_ptr<Item> item : itemVector) { + for (const std::shared_ptr<Item> &item : itemVector) { if (item->getItemCount() > amount) { internalRemoveItem(item, amount); break; @@ -9766,7 +9934,7 @@ void Game::internalRemoveItems(const std::vector<std::shared_ptr<Item>> &itemVec } } } else { - for (std::shared_ptr<Item> item : itemVector) { + for (const std::shared_ptr<Item> &item : itemVector) { internalRemoveItem(item); } } @@ -9781,7 +9949,7 @@ std::shared_ptr<BedItem> Game::getBedBySleeper(uint32_t guid) const { } void Game::setBedSleeper(std::shared_ptr<BedItem> bed, uint32_t guid) { - bedSleepersMap[guid] = bed; + bedSleepersMap[guid] = std::move(bed); } void Game::removeBedSleeper(uint32_t guid) { @@ -10335,7 +10503,7 @@ void Game::playerRewardChestCollect(uint32_t playerId, const Position &pos, uint bool Game::tryRetrieveStashItems(std::shared_ptr<Player> player, std::shared_ptr<Item> item) { ObjectCategory_t category = getObjectCategory(item); - return internalCollectManagedItems(player, item, category, false) == RETURNVALUE_NOERROR; + return internalCollectManagedItems(std::move(player), item, category, false) == RETURNVALUE_NOERROR; } std::unique_ptr<IOWheel> &Game::getIOWheel() { @@ -10467,7 +10635,7 @@ void Game::registerAchievement(uint16_t id, std::string name, std::string descri m_achievements[id] = Achievement(); m_achievements[id].id = id; m_achievements[id].name = name; - m_achievements[id].description = description; + m_achievements[id].description = std::move(description); m_achievements[id].secret = secret; m_achievements[id].grade = grade; m_achievements[id].points = points; @@ -10512,3 +10680,68 @@ std::vector<Achievement> Game::getPublicAchievements() { std::map<uint16_t, Achievement> Game::getAchievements() { return m_achievements; } + +void Game::logCyclopediaStats() { + g_logger().info("Loaded {} badges from Badge System", m_badges.size()); + g_logger().info("Loaded {} titles from Title system", m_titles.size()); +} + +std::unordered_set<Badge> Game::getBadges() { + return m_badges; +} + +Badge Game::getBadgeById(uint8_t id) { + if (id == 0) { + return {}; + } + auto it = std::find_if(m_badges.begin(), m_badges.end(), [id](const Badge &b) { + return b.m_id == id; + }); + if (it != m_badges.end()) { + return *it; + } + return {}; +} + +Badge Game::getBadgeByName(const std::string &name) { + if (name.empty()) { + return {}; + } + auto it = std::find_if(m_badges.begin(), m_badges.end(), [name](const Badge &b) { + return b.m_name == name; + }); + if (it != m_badges.end()) { + return *it; + } + return {}; +} + +std::unordered_set<Title> Game::getTitles() { + return m_titles; +} + +Title Game::getTitleById(uint8_t id) { + if (id == 0) { + return {}; + } + auto it = std::find_if(m_titles.begin(), m_titles.end(), [id](const Title &t) { + return t.m_id == id; + }); + if (it != m_titles.end()) { + return *it; + } + return {}; +} + +Title Game::getTitleByName(const std::string &name) { + if (name.empty()) { + return {}; + } + auto it = std::find_if(m_titles.begin(), m_titles.end(), [name](const Title &t) { + return t.m_maleName == name; + }); + if (it != m_titles.end()) { + return *it; + } + return {}; +} diff --git a/src/game/game.hpp b/src/game/game.hpp index 708aa4b1782..3a199254259 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -50,6 +50,8 @@ class Spectators; struct Achievement; struct HighscoreCategory; +struct Badge; +struct Title; static constexpr uint16_t SERVER_BEAT = 0x32; static constexpr int32_t EVENT_MS = 10000; @@ -58,7 +60,6 @@ static constexpr int32_t EVENT_DECAYINTERVAL = 250; static constexpr int32_t EVENT_DECAY_BUCKETS = 4; static constexpr int32_t EVENT_FORGEABLEMONSTERCHECKINTERVAL = 300000; static constexpr int32_t EVENT_LUA_GARBAGE_COLLECTION = 60000 * 10; // 10min -static constexpr int32_t EVENT_REFRESH_MARKET_PRICES = 60000; // 1min static constexpr std::chrono::minutes CACHE_EXPIRATION_TIME { 10 }; // 10min static constexpr std::chrono::minutes HIGHSCORE_CACHE_EXPIRATION_TIME { 10 }; // 10min @@ -98,6 +99,8 @@ class Game { void forceRemoveCondition(uint32_t creatureId, ConditionType_t type, ConditionId_t conditionId); + void logCyclopediaStats(); + /** * Load the main map * \param filename Is the map custom name (Example: "map".otbm, not is necessary add extension .otbm) @@ -305,9 +308,12 @@ class Game { void playerReportRuleViolationReport(uint32_t playerId, const std::string &targetName, uint8_t reportType, uint8_t reportReason, const std::string &comment, const std::string &translation); + void playerFriendSystemAction(std::shared_ptr<Player> player, uint8_t type, uint8_t titleId); + void playerCyclopediaCharacterInfo(std::shared_ptr<Player> player, uint32_t characterID, CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); void playerHighscores(std::shared_ptr<Player> player, HighscoreType_t type, uint8_t category, uint32_t vocation, const std::string &worldName, uint16_t page, uint8_t entriesPerPage); + static std::string getSkillNameById(uint8_t &skill); void updatePlayerSaleItems(uint32_t playerId); @@ -387,7 +393,7 @@ class Game { void playerRequestAddVip(uint32_t playerId, const std::string &name); void playerRequestRemoveVip(uint32_t playerId, uint32_t guid); - void playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify); + void playerRequestEditVip(uint32_t playerId, uint32_t guid, const std::string &description, uint32_t icon, bool notify, std::vector<uint8_t> vipGroupsId); void playerApplyImbuement(uint32_t playerId, uint16_t imbuementid, uint8_t slot, bool protectionCharm); void playerClearImbuement(uint32_t playerid, uint8_t slot); void playerCloseImbuementWindow(uint32_t playerid); @@ -510,7 +516,7 @@ class Game { return lightHour; } - bool loadItemsPrice(); + void loadItemsPrice(); void loadMotdNum(); void saveMotdNum() const; @@ -717,10 +723,21 @@ class Game { std::vector<Achievement> getPublicAchievements(); std::map<uint16_t, Achievement> getAchievements(); + std::unordered_set<Badge> getBadges(); + Badge getBadgeById(uint8_t id); + Badge getBadgeByName(const std::string &name); + + std::unordered_set<Title> getTitles(); + Title getTitleById(uint8_t id); + Title getTitleByName(const std::string &name); + private: std::map<uint16_t, Achievement> m_achievements; std::map<std::string, uint16_t> m_achievementsNameToId; + std::unordered_set<Badge> m_badges; + std::unordered_set<Title> m_titles; + std::vector<HighscoreCategory> m_highscoreCategories; std::unordered_map<uint8_t, std::string> m_highscoreCategoriesNames; diff --git a/src/game/game_definitions.hpp b/src/game/game_definitions.hpp index 2dadcbbd87c..a6ce6e7eaa8 100644 --- a/src/game/game_definitions.hpp +++ b/src/game/game_definitions.hpp @@ -84,6 +84,24 @@ enum CyclopediaCharacterInfo_RecentKillStatus_t : uint8_t { CYCLOPEDIA_CHARACTERINFO_RECENTKILLSTATUS_ARENA = 4 }; +enum class HighscoreCategories_t : uint8_t { + EXPERIENCE = 0, + FIST_FIGHTING = 1, + CLUB_FIGHTING = 2, + SWORD_FIGHTING = 3, + AXE_FIGHTING = 4, + DISTANCE_FIGHTING = 5, + SHIELDING = 6, + FISHING = 7, + MAGIC_LEVEL = 8, + LOYALTY = 9, + ACHIEVEMENTS = 10, + CHARMS = 11, + DROME = 12, + GOSHNAR = 13, + BOSS_POINTS = 14, +}; + enum HighscoreType_t : uint8_t { HIGHSCORE_GETENTRIES = 0, HIGHSCORE_OURRANK = 1 diff --git a/src/game/scheduling/events_scheduler.cpp b/src/game/scheduling/events_scheduler.cpp index c57f84b667c..a86254fa35c 100644 --- a/src/game/scheduling/events_scheduler.cpp +++ b/src/game/scheduling/events_scheduler.cpp @@ -27,7 +27,6 @@ bool EventsScheduler::loadScheduleEventFromXml() { int daysMath = ((timePtr->tm_year + 1900) * 365) + ((timePtr->tm_mon + 1) * 30) + (timePtr->tm_mday); // Keep track of loaded scripts to check for duplicates - int count = 0; phmap::flat_hash_set<std::string_view> loadedScripts; std::map<std::string, EventRates> eventsOnSameDay; for (const auto &eventNode : doc.child("events").children()) { diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index d4a4f33774d..6273f8fefbb 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -66,7 +66,7 @@ bool IOLoginDataLoad::preLoadPlayer(std::shared_ptr<Player> player, const std::s } player->setGUID(result->getNumber<uint32_t>("id")); - Group* group = g_game().groups.getGroup(result->getNumber<uint16_t>("group_id")); + std::shared_ptr<Group> group = g_game().groups.getGroup(result->getNumber<uint16_t>("group_id")); if (!group) { g_logger().error("Player {} has group id {} which doesn't exist", player->name, result->getNumber<uint16_t>("group_id")); return false; @@ -118,7 +118,7 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p player->setAccount(result->getNumber<uint32_t>("account_id")); } - Group* group = g_game().groups.getGroup(result->getNumber<uint16_t>("group_id")); + std::shared_ptr<Group> group = g_game().groups.getGroup(result->getNumber<uint16_t>("group_id")); if (!group) { g_logger().error("Player {} has group id {} which doesn't exist", player->name, result->getNumber<uint16_t>("group_id")); return false; @@ -177,11 +177,11 @@ bool IOLoginDataLoad::loadPlayerFirst(std::shared_ptr<Player> player, DBResult_p } player->staminaMinutes = result->getNumber<uint16_t>("stamina"); - player->setStoreXpBoost(result->getNumber<uint16_t>("xpboost_value")); - player->setExpBoostStamina(result->getNumber<uint16_t>("xpboost_stamina")); + player->setXpBoostPercent(result->getNumber<uint16_t>("xpboost_value")); + player->setXpBoostTime(result->getNumber<uint16_t>("xpboost_stamina")); - player->setManaShield(result->getNumber<uint16_t>("manashield")); - player->setMaxManaShield(result->getNumber<uint16_t>("max_manashield")); + player->setManaShield(result->getNumber<uint32_t>("manashield")); + player->setMaxManaShield(result->getNumber<uint32_t>("max_manashield")); return true; } @@ -678,12 +678,34 @@ void IOLoginDataLoad::loadPlayerVip(std::shared_ptr<Player> player, DBResult_ptr return; } + uint32_t accountId = player->getAccountId(); + Database &db = Database::getInstance(); - std::ostringstream query; - query << "SELECT `player_id` FROM `account_viplist` WHERE `account_id` = " << player->getAccountId(); - if ((result = db.storeQuery(query.str()))) { + std::string query = fmt::format("SELECT `player_id` FROM `account_viplist` WHERE `account_id` = {}", accountId); + if ((result = db.storeQuery(query))) { + do { + player->vip()->addInternal(result->getNumber<uint32_t>("player_id")); + } while (result->next()); + } + + query = fmt::format("SELECT `id`, `name`, `customizable` FROM `account_vipgroups` WHERE `account_id` = {}", accountId); + if ((result = db.storeQuery(query))) { + do { + player->vip()->addGroupInternal( + result->getNumber<uint8_t>("id"), + result->getString("name"), + result->getNumber<uint8_t>("customizable") == 0 ? false : true + ); + } while (result->next()); + } + + query = fmt::format("SELECT `player_id`, `vipgroup_id` FROM `account_vipgrouplist` WHERE `account_id` = {}", accountId); + if ((result = db.storeQuery(query))) { do { - player->addVIPInternal(result->getNumber<uint32_t>("player_id")); + player->vip()->addGuidToGroupInternal( + result->getNumber<uint8_t>("vipgroup_id"), + result->getNumber<uint32_t>("player_id") + ); } while (result->next()); } } @@ -889,6 +911,8 @@ void IOLoginDataLoad::loadPlayerInitializeSystem(std::shared_ptr<Player> player) player->wheel()->initializePlayerData(); player->achiev()->loadUnlockedAchievements(); + player->badge()->checkAndUpdateNewBadges(); + player->title()->checkAndUpdateNewTitles(); player->initializePrey(); player->initializeTaskHunting(); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index 7bc1b34c864..eccb88c8229 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -292,8 +292,8 @@ bool IOLoginDataSave::savePlayerFirst(std::shared_ptr<Player> player) { query << "`skill_mana_leech_amount_tries` = " << player->skills[SKILL_MANA_LEECH_AMOUNT].tries << ","; query << "`manashield` = " << player->getManaShield() << ","; query << "`max_manashield` = " << player->getMaxManaShield() << ","; - query << "`xpboost_value` = " << player->getStoreXpBoost() << ","; - query << "`xpboost_stamina` = " << player->getExpBoostStamina() << ","; + query << "`xpboost_value` = " << player->getXpBoostPercent() << ","; + query << "`xpboost_stamina` = " << player->getXpBoostTime() << ","; query << "`quickloot_fallback` = " << (player->quickLootFallbackToMainContainer ? 1 : 0) << ","; if (!player->isOffline()) { @@ -436,7 +436,7 @@ bool IOLoginDataSave::savePlayerBestiarySystem(std::shared_ptr<Player> player) { query << "`UnlockedRunesBit` = " << player->UnlockedRunesBit << ","; PropWriteStream propBestiaryStream; - for (const auto trackedType : player->getCyclopediaMonsterTrackerSet(false)) { + for (const auto &trackedType : player->getCyclopediaMonsterTrackerSet(false)) { propBestiaryStream.write<uint16_t>(trackedType->info.raceid); } size_t trackerSize; @@ -737,7 +737,7 @@ bool IOLoginDataSave::savePlayerBosstiary(std::shared_ptr<Player> player) { // Bosstiary tracker PropWriteStream stream; - for (const auto monsterType : player->getCyclopediaMonsterTrackerSet(true)) { + for (const auto &monsterType : player->getCyclopediaMonsterTrackerSet(true)) { if (!monsterType) { continue; } diff --git a/src/io/iobestiary.cpp b/src/io/iobestiary.cpp index f7305d8503c..c544021367e 100644 --- a/src/io/iobestiary.cpp +++ b/src/io/iobestiary.cpp @@ -97,7 +97,7 @@ bool IOBestiary::parseCharmCombat(const std::shared_ptr<Charm> charm, std::share std::shared_ptr<Charm> IOBestiary::getBestiaryCharm(charmRune_t activeCharm, bool force /*= false*/) const { const auto charmInternal = g_game().getCharmList(); - for (const auto tmpCharm : charmInternal) { + for (const auto &tmpCharm : charmInternal) { if (tmpCharm->id == activeCharm) { return tmpCharm; } @@ -169,7 +169,7 @@ void IOBestiary::setCharmRuneCreature(std::shared_ptr<Player> player, const std: std::list<charmRune_t> IOBestiary::getCharmUsedRuneBitAll(std::shared_ptr<Player> player) { int32_t input = player->getUsedRunesBit(); - ; + int8_t i = 0; std::list<charmRune_t> rtn; while (input != 0) { @@ -191,7 +191,7 @@ uint16_t IOBestiary::getBestiaryRaceUnlocked(std::shared_ptr<Player> player, Bes uint16_t count = 0; std::map<uint16_t, std::string> besty_l = g_game().getBestiaryList(); - for (auto it : besty_l) { + for (const auto &it : besty_l) { const auto mtype = g_monsters().getMonsterType(it.second); if (mtype && mtype->info.bestiaryRace == race && player->getBestiaryKillCount(mtype->info.raceid) > 0) { count++; @@ -271,7 +271,7 @@ int32_t IOBestiary::bitToggle(int32_t input, const std::shared_ptr<Charm> charm, return CHARM_NONE; } - int32_t returnToggle = 0; + int32_t returnToggle; int32_t binary = charm->binary; if (on) { returnToggle = input | binary; @@ -307,7 +307,7 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr<Player> player, charmRune_t ru player->setUnlockedRunesBit(value); } else if (action == 1) { std::list<charmRune_t> usedRunes = getCharmUsedRuneBitAll(player); - uint16_t limitRunes = 0; + uint16_t limitRunes; if (player->isPremium()) { if (player->hasCharmExpansion()) { @@ -343,7 +343,6 @@ void IOBestiary::sendBuyCharmRune(std::shared_ptr<Player> player, charmRune_t ru player->sendFYIBox("You don't have enough gold."); } player->BestiarysendCharms(); - return; } std::map<uint8_t, int16_t> IOBestiary::getMonsterElements(const std::shared_ptr<MonsterType> mtype) const { diff --git a/src/io/iobestiary.hpp b/src/io/iobestiary.hpp index 9cb2ef2fe55..a521ce68852 100644 --- a/src/io/iobestiary.hpp +++ b/src/io/iobestiary.hpp @@ -20,16 +20,18 @@ class Charm { public: Charm() = default; Charm(std::string initname, charmRune_t initcharmRune_t, std::string initdescription, charm_t inittype, uint16_t initpoints, int32_t initbinary) : - name(initname), id(initcharmRune_t), description(initdescription), type(inittype), points(initpoints), binary(initbinary) { } + name(std::move(initname)), id(initcharmRune_t), description(std::move(initdescription)), type(inittype), points(initpoints), binary(initbinary) { } virtual ~Charm() = default; std::string name; + charmRune_t id = CHARM_NONE; + std::string description; + charm_t type; + uint16_t points = 0; + int32_t binary = 0; std::string cancelMsg; std::string logMsg; - std::string description; - charm_t type; - charmRune_t id = CHARM_NONE; CombatType_t dmgtype = COMBAT_NONE; uint16_t effect = CONST_ME_NONE; @@ -38,8 +40,6 @@ class Charm { uint16_t percent = 0; int8_t chance = 0; - uint16_t points = 0; - int32_t binary = 0; }; class IOBestiary { diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index 4c6b95dc32e..122ade42c72 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -72,7 +72,7 @@ uint8_t IOLoginData::getAccountType(uint32_t accountId) { void IOLoginData::updateOnlineStatus(uint32_t guid, bool login) { static phmap::flat_hash_map<uint32_t, bool> updateOnline; - if (login && updateOnline.find(guid) != updateOnline.end() || guid <= 0) { + if ((login && updateOnline.find(guid) != updateOnline.end()) || guid <= 0) { return; } @@ -352,10 +352,9 @@ bool IOLoginData::hasBiddedOnHouse(uint32_t guid) { std::forward_list<VIPEntry> IOLoginData::getVIPEntries(uint32_t accountId) { std::forward_list<VIPEntry> entries; - std::ostringstream query; - query << "SELECT `player_id`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `name`, `description`, `icon`, `notify` FROM `account_viplist` WHERE `account_id` = " << accountId; + std::string query = fmt::format("SELECT `player_id`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `name`, `description`, `icon`, `notify` FROM `account_viplist` WHERE `account_id` = {}", accountId); - DBResult_ptr result = Database::getInstance().storeQuery(query.str()); + DBResult_ptr result = Database::getInstance().storeQuery(query); if (result) { do { entries.emplace_front( @@ -371,27 +370,69 @@ std::forward_list<VIPEntry> IOLoginData::getVIPEntries(uint32_t accountId) { } void IOLoginData::addVIPEntry(uint32_t accountId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { - Database &db = Database::getInstance(); - - std::ostringstream query; - query << "INSERT INTO `account_viplist` (`account_id`, `player_id`, `description`, `icon`, `notify`) VALUES (" << accountId << ',' << guid << ',' << db.escapeString(description) << ',' << icon << ',' << notify << ')'; - if (!db.executeQuery(query.str())) { - g_logger().error("Failed to add VIP entry for account %u. QUERY: %s", accountId, query.str().c_str()); + std::string query = fmt::format("INSERT INTO `account_viplist` (`account_id`, `player_id`, `description`, `icon`, `notify`) VALUES ({}, {}, {}, {}, {})", accountId, guid, g_database().escapeString(description), icon, notify); + if (!g_database().executeQuery(query)) { + g_logger().error("Failed to add VIP entry for account {}. QUERY: {}", accountId, query.c_str()); } } void IOLoginData::editVIPEntry(uint32_t accountId, uint32_t guid, const std::string &description, uint32_t icon, bool notify) { - Database &db = Database::getInstance(); - - std::ostringstream query; - query << "UPDATE `account_viplist` SET `description` = " << db.escapeString(description) << ", `icon` = " << icon << ", `notify` = " << notify << " WHERE `account_id` = " << accountId << " AND `player_id` = " << guid; - if (!db.executeQuery(query.str())) { - g_logger().error("Failed to edit VIP entry for account %u. QUERY: %s", accountId, query.str().c_str()); + std::string query = fmt::format("UPDATE `account_viplist` SET `description` = {}, `icon` = {}, `notify` = {} WHERE `account_id` = {} AND `player_id` = {}", g_database().escapeString(description), icon, notify, accountId, guid); + if (!g_database().executeQuery(query)) { + g_logger().error("Failed to edit VIP entry for account {}. QUERY: {}", accountId, query.c_str()); } } void IOLoginData::removeVIPEntry(uint32_t accountId, uint32_t guid) { - std::ostringstream query; - query << "DELETE FROM `account_viplist` WHERE `account_id` = " << accountId << " AND `player_id` = " << guid; - Database::getInstance().executeQuery(query.str()); + std::string query = fmt::format("DELETE FROM `account_viplist` WHERE `account_id` = {} AND `player_id` = {}", accountId, guid); + g_database().executeQuery(query); +} + +std::forward_list<VIPGroupEntry> IOLoginData::getVIPGroupEntries(uint32_t accountId, uint32_t guid) { + std::forward_list<VIPGroupEntry> entries; + + std::string query = fmt::format("SELECT `id`, `name`, `customizable` FROM `account_vipgroups` WHERE `account_id` = {}", accountId); + + DBResult_ptr result = g_database().storeQuery(query); + if (result) { + do { + entries.emplace_front( + result->getNumber<uint8_t>("id"), + result->getString("name"), + result->getNumber<uint8_t>("customizable") == 0 ? false : true + ); + } while (result->next()); + } + return entries; +} + +void IOLoginData::addVIPGroupEntry(uint8_t groupId, uint32_t accountId, const std::string &groupName, bool customizable) { + std::string query = fmt::format("INSERT INTO `account_vipgroups` (`id`, `account_id`, `name`, `customizable`) VALUES ({}, {}, {}, {})", groupId, accountId, g_database().escapeString(groupName), customizable); + if (!g_database().executeQuery(query)) { + g_logger().error("Failed to add VIP Group entry for account {} and group {}. QUERY: {}", accountId, groupId, query.c_str()); + } +} + +void IOLoginData::editVIPGroupEntry(uint8_t groupId, uint32_t accountId, const std::string &groupName, bool customizable) { + std::string query = fmt::format("UPDATE `account_vipgroups` SET `name` = {}, `customizable` = {} WHERE `id` = {} AND `account_id` = {}", g_database().escapeString(groupName), customizable, groupId, accountId); + if (!g_database().executeQuery(query)) { + g_logger().error("Failed to update VIP Group entry for account {} and group {}. QUERY: {}", accountId, groupId, query.c_str()); + } +} + +void IOLoginData::removeVIPGroupEntry(uint8_t groupId, uint32_t accountId) { + std::string query = fmt::format("DELETE FROM `account_vipgroups` WHERE `id` = {} AND `account_id` = {}", groupId, accountId); + g_database().executeQuery(query); +} + +void IOLoginData::addGuidVIPGroupEntry(uint8_t groupId, uint32_t accountId, uint32_t guid) { + std::string query = fmt::format("INSERT INTO `account_vipgrouplist` (`account_id`, `player_id`, `vipgroup_id`) VALUES ({}, {}, {})", accountId, guid, groupId); + if (!g_database().executeQuery(query)) { + g_logger().error("Failed to add guid VIP Group entry for account {}, player {} and group {}. QUERY: {}", accountId, guid, groupId, query.c_str()); + } +} + +void IOLoginData::removeGuidVIPGroupEntry(uint32_t accountId, uint32_t guid) { + std::string query = fmt::format("DELETE FROM `account_vipgrouplist` WHERE `account_id` = {} AND `player_id` = {}", accountId, guid); + g_database().executeQuery(query); } diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index b9fcc124ea0..be414739837 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -36,6 +36,13 @@ class IOLoginData { static void editVIPEntry(uint32_t accountId, uint32_t guid, const std::string &description, uint32_t icon, bool notify); static void removeVIPEntry(uint32_t accountId, uint32_t guid); + static std::forward_list<VIPGroupEntry> getVIPGroupEntries(uint32_t accountId, uint32_t guid); + static void addVIPGroupEntry(uint8_t groupId, uint32_t accountId, const std::string &groupName, bool customizable); + static void editVIPGroupEntry(uint8_t groupId, uint32_t accountId, const std::string &groupName, bool customizable); + static void removeVIPGroupEntry(uint8_t groupId, uint32_t accountId); + static void addGuidVIPGroupEntry(uint8_t groupId, uint32_t accountId, uint32_t guid); + static void removeGuidVIPGroupEntry(uint32_t accountId, uint32_t guid); + private: static bool savePlayerGuard(std::shared_ptr<Player> player); }; diff --git a/src/io/iomap.cpp b/src/io/iomap.cpp index 4edfefa66d1..d50d9b2804f 100644 --- a/src/io/iomap.cpp +++ b/src/io/iomap.cpp @@ -122,8 +122,6 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { const uint16_t base_y = stream.getU16(); const uint8_t base_z = stream.getU8(); - bool tileIsStatic = false; - while (stream.startNode()) { const uint8_t tileType = stream.getU8(); if (tileType != OTBM_HOUSETILE && tileType != OTBM_TILE) { @@ -166,9 +164,6 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { const auto &iType = Item::items[id]; if (!tile->isHouse() || (!iType.isBed() && !iType.isTrashHolder())) { - if (iType.blockSolid) { - tileIsStatic = true; - } const auto item = std::make_shared<BasicItem>(); item->id = id; @@ -194,10 +189,6 @@ void IOMap::parseTileArea(FileStream &stream, Map &map, const Position &pos) { const auto &iType = Item::items[id]; - if (iType.blockSolid) { - tileIsStatic = true; - } - const auto item = std::make_shared<BasicItem>(); item->id = id; diff --git a/src/io/iomarket.cpp b/src/io/iomarket.cpp index ca1bdb209d2..a0253e2ea01 100644 --- a/src/io/iomarket.cpp +++ b/src/io/iomarket.cpp @@ -29,10 +29,14 @@ uint8_t IOMarket::getTierFromDatabaseTable(const std::string &string) { MarketOfferList IOMarket::getActiveOffers(MarketAction_t action) { MarketOfferList offerList; - std::ostringstream query; - query << "SELECT `id`, `amount`, `price`, `tier`, `created`, `anonymous`, (SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `player_name` FROM `market_offers` WHERE `sale` = " << action; + std::string query = fmt::format( + "SELECT `id`, `itemtype`, `amount`, `price`, `tier`, `created`, `anonymous`, " + "(SELECT `name` FROM `players` WHERE `id` = `player_id`) AS `player_name` " + "FROM `market_offers` WHERE `sale` = {}", + action + ); - DBResult_ptr result = Database::getInstance().storeQuery(query.str()); + DBResult_ptr result = g_database().storeQuery(query); if (!result) { return offerList; } @@ -41,6 +45,7 @@ MarketOfferList IOMarket::getActiveOffers(MarketAction_t action) { do { MarketOffer offer; + offer.itemId = result->getNumber<uint16_t>("itemtype"); offer.amount = result->getNumber<uint16_t>("amount"); offer.price = result->getNumber<uint64_t>("price"); offer.timestamp = result->getNumber<uint32_t>("created") + marketOfferDuration; @@ -71,6 +76,7 @@ MarketOfferList IOMarket::getActiveOffers(MarketAction_t action, uint16_t itemId do { MarketOffer offer; + offer.itemId = itemId; offer.amount = result->getNumber<uint16_t>("amount"); offer.price = result->getNumber<uint64_t>("price"); offer.timestamp = result->getNumber<uint32_t>("created") + marketOfferDuration; @@ -333,9 +339,15 @@ bool IOMarket::moveOfferToHistory(uint32_t offerId, MarketOfferState_t state) { } void IOMarket::updateStatistics() { - std::ostringstream query; - query << "SELECT `sale` AS `sale`, `itemtype` AS `itemtype`, COUNT(`price`) AS `num`, MIN(`price`) AS `min`, MAX(`price`) AS `max`, SUM(`price`) AS `sum`, `tier` AS `tier` FROM `market_history` WHERE `state` = " << OFFERSTATE_ACCEPTED << " GROUP BY `itemtype`, `sale`, `tier`"; - DBResult_ptr result = Database::getInstance().storeQuery(query.str()); + auto query = fmt::format( + "SELECT sale, itemtype, COUNT(price) AS num, MIN(price) AS min, MAX(price) AS max, SUM(price) AS sum, tier " + "FROM market_history " + "WHERE state = '{}' " + "GROUP BY itemtype, sale, tier", + OFFERSTATE_ACCEPTED + ); + + DBResult_ptr result = g_database().storeQuery(query); if (!result) { return; } diff --git a/src/io/iomarket.hpp b/src/io/iomarket.hpp index 33180053584..4292651fb47 100644 --- a/src/io/iomarket.hpp +++ b/src/io/iomarket.hpp @@ -14,8 +14,6 @@ #include "lib/di/container.hpp" class IOMarket { - using StatisticsMap = std::map<uint16_t, std::map<uint8_t, MarketStatistics>>; - public: IOMarket() = default; @@ -43,10 +41,11 @@ class IOMarket { void updateStatistics(); - StatisticsMap getPurchaseStatistics() const { + using StatisticsMap = std::map<uint16_t, std::map<uint8_t, MarketStatistics>>; + const StatisticsMap &getPurchaseStatistics() const { return purchaseStatistics; } - StatisticsMap getSaleStatistics() const { + const StatisticsMap &getSaleStatistics() const { return saleStatistics; } diff --git a/src/items/bed.cpp b/src/items/bed.cpp index d093dcc5fd9..4b38be3b474 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -94,12 +94,7 @@ bool BedItem::canUse(std::shared_ptr<Player> player) { return false; } - auto partName = itemType.name; - auto nextPartname = nextBedItem->getName(); - auto firstPart = keepFirstWordOnly(partName); - auto nextPartOf = keepFirstWordOnly(nextPartname); - g_logger().debug("First bed part name {}, second part name {}", firstPart, nextPartOf); - if (!isMovable() || !nextBedItem->isMovable() || firstPart != nextPartOf) { + if (!isMovable() || !nextBedItem->isMovable() || !isBedComplete(nextBedItem)) { return false; } @@ -122,6 +117,23 @@ bool BedItem::canUse(std::shared_ptr<Player> player) { return true; } +bool BedItem::isBedComplete(std::shared_ptr<BedItem> nextBedItem) { + const ItemType &it = Item::items[id]; + + if (nextBedItem == nullptr) { + return false; + } + + auto partName = it.name; + auto nextPartname = nextBedItem->getName(); + auto firstPart = keepFirstWordOnly(partName); + auto nextPartOf = keepFirstWordOnly(nextPartname); + + g_logger().debug("First bed part id {} name {}, second part id {} name {}", it.id, firstPart, nextBedItem->getID(), nextPartOf); + + return it.bedPartOf == nextBedItem->getID(); +} + bool BedItem::trySleep(std::shared_ptr<Player> player) { if (!house || player->isRemoved()) { return false; diff --git a/src/items/bed.hpp b/src/items/bed.hpp index 59c0c66f68c..2aeb6e38e5b 100644 --- a/src/items/bed.hpp +++ b/src/items/bed.hpp @@ -39,6 +39,8 @@ class BedItem final : public Item { bool canUse(std::shared_ptr<Player> player); + bool isBedComplete(std::shared_ptr<BedItem> nextBedItem); + bool trySleep(std::shared_ptr<Player> player); bool sleep(std::shared_ptr<Player> player); void wakeUp(std::shared_ptr<Player> player); diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 7bd7dcef2c9..63ce657741a 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -218,7 +218,7 @@ std::string Container::getContentDescription(bool oldProtocol) { return getContentDescription(os, oldProtocol).str(); } -std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool oldProtocol) { +std::ostringstream &Container::getContentDescription(std::ostringstream &os, bool sendColoredMessage) { bool firstitem = true; for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { std::shared_ptr<Item> item = *it; @@ -234,10 +234,10 @@ std::ostringstream &Container::getContentDescription(std::ostringstream &os, boo os << ", "; } - if (oldProtocol) { - os << item->getNameDescription(); - } else { + if (sendColoredMessage) { os << "{" << item->getID() << "|" << item->getNameDescription() << "}"; + } else { + os << item->getNameDescription(); } } @@ -383,7 +383,7 @@ bool Container::isInsideContainerWithId(const uint16_t id) { } bool Container::isAnyKindOfRewardChest() { - return getID() == ITEM_REWARD_CHEST || getID() == ITEM_REWARD_CONTAINER && getParent() && getParent()->getContainer() && getParent()->getContainer()->getID() == ITEM_REWARD_CHEST || isBrowseFieldAndHoldsRewardChest(); + return getID() == ITEM_REWARD_CHEST || (getID() == ITEM_REWARD_CONTAINER && getParent() && getParent()->getContainer() && getParent()->getContainer()->getID() == ITEM_REWARD_CHEST) || isBrowseFieldAndHoldsRewardChest(); } bool Container::isAnyKindOfRewardContainer() { diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index 2d1ba9301c5..1f247b611bc 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -68,6 +68,7 @@ void ItemParse::initParse(const std::string &tmpStrValue, pugi::xml_node attribu ItemParse::parseWalk(tmpStrValue, valueAttribute, itemType); ItemParse::parseAllowDistanceRead(tmpStrValue, valueAttribute, itemType); ItemParse::parseImbuement(tmpStrValue, attributeNode, valueAttribute, itemType); + ItemParse::parseAugment(tmpStrValue, attributeNode, valueAttribute, itemType); ItemParse::parseStackSize(tmpStrValue, valueAttribute, itemType); ItemParse::parseSpecializedMagicLevelPoint(tmpStrValue, valueAttribute, itemType); ItemParse::parseMagicShieldCapacity(tmpStrValue, valueAttribute, itemType); @@ -870,6 +871,58 @@ void ItemParse::parseImbuement(const std::string &tmpStrValue, pugi::xml_node at } } +void ItemParse::parseAugment(const std::string &tmpStrValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType) { + if (tmpStrValue != "augments") { + return; + } + + // Check if the augments value is 1 or 0 (1 = enable - 0 = disable) + if (valueAttribute.as_bool()) { + for (const auto subAttributeNode : attributeNode.children()) { + const pugi::xml_attribute subKeyAttribute = subAttributeNode.attribute("key"); + if (!subKeyAttribute) { + continue; + } + + const pugi::xml_attribute subValueAttribute = subAttributeNode.attribute("value"); + if (!subValueAttribute) { + continue; + } + + const auto &augmentEnum = magic_enum::enum_cast<Augment_t>(toPascalCase(subValueAttribute.as_string())); + if (augmentEnum.has_value()) { + const Augment_t augmentType = augmentEnum.value(); + g_logger().trace("[ParseAugment::initParseAugment] - Item '{}' has an augment '{}'", itemType.name, subValueAttribute.as_string()); + int32_t augmentValue = 0; + const bool hasValueDescrition = isAugmentWithoutValueDescription(augmentType); + + if (hasValueDescrition) { + const auto it = AugmentWithoutValueDescriptionDefaultKeys.find(augmentType); + if (it != AugmentWithoutValueDescriptionDefaultKeys.end()) { + augmentValue = g_configManager().getNumber(it->second, __FUNCTION__); + } + } + + const auto augmentName = asLowerCaseString(subKeyAttribute.as_string()); + const pugi::xml_object_range<pugi::xml_node_iterator> augmentValueAttributeNode = subAttributeNode.children(); + if (!augmentValueAttributeNode.empty()) { + const pugi::xml_node augmentValueNode = *augmentValueAttributeNode.begin(); + const pugi::xml_attribute augmentValueAttribute = augmentValueNode.attribute("value"); + augmentValue = augmentValueAttribute ? pugi::cast<int32_t>(augmentValueAttribute.value()) : augmentValue; + } else if (!hasValueDescrition) { + g_logger().warn("[{}] - Item '{}' has an augment '{}' without a value", __FUNCTION__, itemType.name, augmentName); + } + + if (augmentType != Augment_t::None) { + itemType.addAugment(augmentName, augmentType, augmentValue); + } + } else { + g_logger().warn("[{}] - Unknown type '{}'", __FUNCTION__, subValueAttribute.as_string()); + } + } + } +} + void ItemParse::parseStackSize(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType) { std::string stringValue = tmpStrValue; if (stringValue == "stacksize") { diff --git a/src/items/functions/item/item_parse.hpp b/src/items/functions/item/item_parse.hpp index 7859a77fe9c..f63b6bc0689 100644 --- a/src/items/functions/item/item_parse.hpp +++ b/src/items/functions/item/item_parse.hpp @@ -158,6 +158,7 @@ const phmap::flat_hash_map<std::string, ItemParseAttributes_t> ItemParseAttribut { "primarytype", ITEM_PARSE_PRIMARYTYPE }, { "usedbyhouseguests", ITEM_PARSE_USEDBYGUESTS }, { "script", ITEM_PARSE_SCRIPT }, + { "augments", ITEM_PARSE_AUGMENT } }; const phmap::flat_hash_map<std::string, ItemTypes_t> ItemTypesMap = { @@ -247,6 +248,12 @@ const phmap::flat_hash_map<std::string, ImbuementTypes_t> ImbuementsTypeMap = { { "increase capacity", IMBUEMENT_INCREASE_CAPACITY } }; +const phmap::flat_hash_map<Augment_t, ConfigKey_t> AugmentWithoutValueDescriptionDefaultKeys = { + { Augment_t::IncreasedDamage, AUGMENT_INCREASED_DAMAGE_PERCENT }, + { Augment_t::PowerfulImpact, AUGMENT_POWERFUL_IMPACT_PERCENT }, + { Augment_t::StrongImpact, AUGMENT_STRONG_IMPACT_PERCENT }, +}; + class ItemParse : public Items { public: static void initParse(const std::string &tmpStrValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType); @@ -304,6 +311,7 @@ class ItemParse : public Items { static void parseWalk(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType); static void parseAllowDistanceRead(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType); static void parseImbuement(const std::string &tmpStrValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType); + static void parseAugment(const std::string &tmpStrValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType); static void parseStackSize(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType); static void parseSpecializedMagicLevelPoint(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType); static void parseMagicShieldCapacity(const std::string &tmpStrValue, pugi::xml_attribute valueAttribute, ItemType &itemType); diff --git a/src/items/item.cpp b/src/items/item.cpp index b51c076d80b..823eb13b393 100644 --- a/src/items/item.cpp +++ b/src/items/item.cpp @@ -1147,6 +1147,10 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr descriptions.emplace_back("Description", it.description); } + if (item->getContainer()) { + descriptions.emplace_back("Capacity", std::to_string(item->getContainer()->capacity())); + } + if (it.showCharges) { auto charges = item->getAttribute<int32_t>(ItemAttribute_t::CHARGES); if (charges != 0) { @@ -1403,10 +1407,6 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr descriptions.emplace_back("Tier", std::to_string(item->getTier())); } - if (item->getContainer()) { - descriptions.emplace_back("Capacity", std::to_string(item->getContainer()->capacity())); - } - std::string slotName; if (item->getImbuementSlot() > 0) { for (uint8_t i = 0; i < item->getImbuementSlot(); ++i) { @@ -1437,6 +1437,11 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr } } + std::string augmentsDescription = parseAugmentDescription(item, true); + if (!augmentsDescription.empty()) { + descriptions.emplace_back("Augments", augmentsDescription); + } + if (it.isKey()) { ss.str(""); ss << fmt::format("{:04}", item->getAttribute<uint16_t>(ItemAttribute_t::ACTIONID)); @@ -1562,6 +1567,10 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr descriptions.emplace_back("Description", it.description); } + if (it.isContainer()) { + descriptions.emplace_back("Capacity", std::to_string(it.maxItems)); + } + int32_t attack = it.attack; if (it.isRanged()) { bool separator = false; @@ -1781,14 +1790,15 @@ Item::getDescriptions(const ItemType &it, std::shared_ptr<Item> item /*= nullptr } } - if (it.isContainer()) { - descriptions.emplace_back("Capacity", std::to_string(it.maxItems)); - } - if (it.imbuementSlot > 0) { descriptions.emplace_back("Imbuement Slots", std::to_string(it.imbuementSlot)); } + std::string augmentsDescription = it.parseAugmentDescription(true); + if (!augmentsDescription.empty()) { + descriptions.emplace_back("Augments", augmentsDescription); + } + if (it.isKey()) { ss.str(""); ss << fmt::format("{:04}", 0); @@ -2075,13 +2085,18 @@ std::string Item::parseShowDuration(std::shared_ptr<Item> item) { std::string Item::parseShowAttributesDescription(std::shared_ptr<Item> item, const uint16_t itemId) { std::ostringstream itemDescription; const ItemType &itemType = Item::items[itemId]; + if (itemType.armor != 0 || (item && item->getArmor() != 0) || itemType.showAttributes) { - bool begin = true; + bool begin = itemType.isQuiver() ? false : true; int32_t armor = (item ? item->getArmor() : itemType.armor); if (armor != 0) { - itemDescription << " (Arm:" << armor; - begin = false; + if (begin) { + itemDescription << " (Arm:" << armor; + begin = false; + } else { + itemDescription << ", Arm:" << armor; + } } if (itemType.abilities) { @@ -2167,7 +2182,7 @@ std::string Item::parseShowAttributesDescription(std::shared_ptr<Item> item, con itemDescription << ", "; } - itemDescription << "Perfect Shot " << std::showpos << itemType.abilities->perfectShotDamage << std::noshowpos << " at range " << unsigned(itemType.abilities->perfectShotRange); + itemDescription << "perfect shot " << std::showpos << itemType.abilities->perfectShotDamage << std::noshowpos << " at range " << unsigned(itemType.abilities->perfectShotRange); } if (itemType.abilities->reflectFlat[0] != 0) { @@ -2315,7 +2330,7 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: s << " (\"" << it.runeSpellName << "\"). " << (it.stackable && tmpSubType > 1 ? "They" : "It") << " can only be used by "; const VocSpellMap &vocMap = rune->getVocMap(); - std::vector<Vocation*> showVocMap; + std::vector<std::shared_ptr<Vocation>> showVocMap; // vocations are usually listed with the unpromoted and promoted version, the latter being // hidden from description, so `total / 2` is most likely the amount of vocations to be shown. @@ -2869,8 +2884,10 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: } } - if (volume != 0) { + if (volume != 0 && !it.isQuiver()) { s << " (Vol:" << volume << ')'; + } else if (volume != 0 && it.isQuiver()) { + s << " (Vol:" << volume; } } else { bool found = true; @@ -3010,6 +3027,8 @@ std::string Item::getDescription(const ItemType &it, int32_t lookDistance, std:: s << '.'; } + s << parseAugmentDescription(item); + s << parseImbuementDescription(item); s << parseClassificationDescription(item); @@ -3218,7 +3237,7 @@ std::shared_ptr<Item> Item::transform(uint16_t itemId, uint16_t itemCount /*= -1 } std::shared_ptr<Item> newItem; - if (itemCount == -1) { + if (itemCount == 0) { newItem = Item::CreateItem(itemId, 1); } else { newItem = Item::CreateItem(itemId, itemCount); diff --git a/src/items/item.hpp b/src/items/item.hpp index 9ff0d3d15aa..a9774c902cd 100644 --- a/src/items/item.hpp +++ b/src/items/item.hpp @@ -291,6 +291,12 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { return isStoreItem() || hasOwner(); } + static std::string parseAugmentDescription(std::shared_ptr<Item> item, bool inspect = false) { + if (!item) { + return ""; + } + return items[item->getID()].parseAugmentDescription(inspect); + } static std::string parseImbuementDescription(std::shared_ptr<Item> item); static std::string parseShowDurationSpeed(int32_t speed, bool &begin); static std::string parseShowDuration(std::shared_ptr<Item> item); @@ -419,6 +425,29 @@ class Item : virtual public Thing, public ItemProperties, public SharedObject { } return items[id].extraDefense; } + std::vector<std::shared_ptr<AugmentInfo>> getAugments() const { + return items[id].augments; + } + std::vector<std::shared_ptr<AugmentInfo>> getAugmentsBySpellNameAndType(std::string spellName, Augment_t augmentType) const { + std::vector<std::shared_ptr<AugmentInfo>> augments; + for (auto &augment : items[id].augments) { + if (strcasecmp(augment->spellName.c_str(), spellName.c_str()) == 0 && augment->type == augmentType) { + augments.push_back(augment); + } + } + + return augments; + } + std::vector<std::shared_ptr<AugmentInfo>> getAugmentsBySpellName(std::string spellName) const { + std::vector<std::shared_ptr<AugmentInfo>> augments; + for (auto &augment : items[id].augments) { + if (strcasecmp(augment->spellName.c_str(), spellName.c_str()) == 0) { + augments.push_back(augment); + } + } + + return augments; + } uint8_t getImbuementSlot() const { if (hasAttribute(ItemAttribute_t::IMBUEMENT_SLOT)) { return getAttribute<uint8_t>(ItemAttribute_t::IMBUEMENT_SLOT); diff --git a/src/items/items.cpp b/src/items/items.cpp index 9e31f5f105f..7d8ff0cf7c0 100644 --- a/src/items/items.cpp +++ b/src/items/items.cpp @@ -67,6 +67,47 @@ ItemTypes_t Items::getLootType(const std::string &strValue) { return ITEM_TYPE_NONE; } +const std::string Items::getAugmentNameByType(Augment_t augmentType) { + std::string augmentTypeName = magic_enum::enum_name(augmentType).data(); + augmentTypeName = toStartCaseWithSpace(augmentTypeName); + if (!isAugmentWithoutValueDescription(augmentType)) { + toLowerCaseString(augmentTypeName); + } + return augmentTypeName; +} + +std::string ItemType::parseAugmentDescription(bool inspect /*= false*/) const { + if (augments.empty()) { + return ""; + } + + std::vector<std::string> descriptions; + for (const auto &augment : augments) { + descriptions.push_back(getFormattedAugmentDescription(augment)); + } + + if (inspect) { + return fmt::format("{}.", fmt::join(descriptions.begin(), descriptions.end(), ", ")); + } else { + return fmt::format("\nAugments: ({}).", fmt::join(descriptions.begin(), descriptions.end(), ", ")); + } +} + +std::string ItemType::getFormattedAugmentDescription(const std::shared_ptr<AugmentInfo> &augmentInfo) const { + const std::string augmentName = Items::getAugmentNameByType(augmentInfo->type); + std::string augmentSpellNameCapitalized = augmentInfo->spellName; + capitalizeWordsIgnoringString(augmentSpellNameCapitalized, " of "); + + char signal = augmentInfo->value > 0 ? '-' : '+'; + + if (Items::isAugmentWithoutValueDescription(augmentInfo->type)) { + return fmt::format("{} -> {}", augmentSpellNameCapitalized, augmentName); + } else if (augmentInfo->type == Augment_t::Cooldown) { + return fmt::format("{} -> {}{}s {}", augmentSpellNameCapitalized, signal, augmentInfo->value / 1000, augmentName); + } + return fmt::format("{} -> {:+}% {}", augmentSpellNameCapitalized, augmentInfo->value, augmentName); +} + bool Items::reload() { clear(); loadFromProtobuf(); diff --git a/src/items/items.hpp b/src/items/items.hpp index f9e48ae1032..e56678af6f3 100644 --- a/src/items/items.hpp +++ b/src/items/items.hpp @@ -252,6 +252,14 @@ class ItemType { return str; } + std::string parseAugmentDescription(bool inspect = false) const; + std::string getFormattedAugmentDescription(const std::shared_ptr<AugmentInfo> &augmentInfo) const; + + void addAugment(std::string spellName, Augment_t augmentType, int32_t value) { + auto augmentInfo = std::make_shared<AugmentInfo>(spellName, augmentType, value); + augments.emplace_back(augmentInfo); + } + void setImbuementType(ImbuementTypes_t imbuementType, uint16_t slotMaxTier) { imbuementTypes[imbuementType] = std::min<uint16_t>(IMBUEMENT_MAX_TIER, slotMaxTier); } @@ -331,6 +339,8 @@ class ItemType { int8_t hitChance = 0; + std::vector<std::shared_ptr<AugmentInfo>> augments; + // 12.90 bool wearOut = false; bool clockExpire = false; @@ -435,6 +445,18 @@ class Items { return dummys; } + static const std::string getAugmentNameByType(Augment_t augmentType); + + static bool isAugmentWithoutValueDescription(Augment_t augmentType) { + static std::vector<Augment_t> vector = { + Augment_t::IncreasedDamage, + Augment_t::PowerfulImpact, + Augment_t::StrongImpact, + }; + + return std::find(vector.begin(), vector.end(), augmentType) != vector.end(); + } + private: std::vector<ItemType> items; std::vector<uint16_t> ladders; diff --git a/src/items/items_definitions.hpp b/src/items/items_definitions.hpp index f044d4b5248..badac532951 100644 --- a/src/items/items_definitions.hpp +++ b/src/items/items_definitions.hpp @@ -270,6 +270,17 @@ enum ImbuementTypes_t : int64_t { IMBUEMENT_INCREASE_CAPACITY = 17 }; +enum class Augment_t : uint8_t { + None, + PowerfulImpact, + StrongImpact, + IncreasedDamage, + Cooldown, + CriticalExtraDamage, + LifeLeech, + ManaLeech +}; + enum class ContainerCategory_t : uint8_t { All, Ammunition, @@ -606,9 +617,19 @@ enum ItemParseAttributes_t { ITEM_PARSE_PRIMARYTYPE, ITEM_PARSE_USEDBYGUESTS, ITEM_PARSE_SCRIPT, + ITEM_PARSE_AUGMENT, }; struct ImbuementInfo { Imbuement* imbuement; uint32_t duration = 0; }; + +struct AugmentInfo { + AugmentInfo(std::string spellName, Augment_t type, int32_t value) : + spellName(std::move(spellName)), type(type), value(value) { } + + std::string spellName; + Augment_t type; + int32_t value; +}; diff --git a/src/items/tile.cpp b/src/items/tile.cpp index ca354700f22..f2006f627e1 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -791,7 +791,7 @@ ReturnValue Tile::queryAdd(int32_t, const std::shared_ptr<Thing> &thing, uint32_ if (ground) { const ItemType &iiType = Item::items[ground->getID()]; if (iiType.blockSolid) { - if (!iiType.pickupable && iiType.type != ITEM_TYPE_TRASHHOLDER || item->isMagicField() || item->isBlocking()) { + if ((!iiType.pickupable && iiType.type != ITEM_TYPE_TRASHHOLDER) || item->isMagicField() || item->isBlocking()) { if (!item->isPickupable() && !item->isCarpet()) { return RETURNVALUE_NOTENOUGHROOM; } @@ -1272,7 +1272,7 @@ void Tile::removeThing(std::shared_ptr<Thing> thing, uint32_t count) { } void Tile::removeCreature(std::shared_ptr<Creature> creature) { - g_game().map.getQTNode(tilePos.x, tilePos.y)->removeCreature(creature); + g_game().map.getMapSector(tilePos.x, tilePos.y)->removeCreature(creature); removeThing(creature, 0); } @@ -1575,7 +1575,7 @@ void Tile::internalAddThing(uint32_t, std::shared_ptr<Thing> thing) { if (!thing) { return; } - for (const auto zone : getZones()) { + for (const auto &zone : getZones()) { zone->thingAdded(thing); } diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index 5b2b260e2ee..59cc23636e2 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -200,11 +200,11 @@ class Weapon : public Script { return m_isDisabledChain; } - const WeaponType_t getWeaponType() const { + WeaponType_t getWeaponType() const { return weaponType; } - const std::shared_ptr<Combat> getCombat() const { + std::shared_ptr<Combat> getCombat() const { if (!m_combat) { g_logger().error("Weapon::getCombat() - m_combat is nullptr"); return nullptr; diff --git a/src/lib/metrics/metrics.cpp b/src/lib/metrics/metrics.cpp index cf11060125a..f005c79c966 100644 --- a/src/lib/metrics/metrics.cpp +++ b/src/lib/metrics/metrics.cpp @@ -87,7 +87,7 @@ void Metrics::shutdown() { metrics_api::Provider::SetMeterProvider(none); } -ScopedLatency::ScopedLatency(std::string_view name, const std::string &histogramName, const std::string &scopeKey) : +ScopedLatency::ScopedLatency(const std::string_view &name, const std::string &histogramName, const std::string &scopeKey) : ScopedLatency(name, g_metrics().latencyHistograms[histogramName], { { scopeKey, std::string(name) } }, g_metrics().defaultContext) { if (histogram == nullptr) { stopped = true; diff --git a/src/lib/metrics/metrics.hpp b/src/lib/metrics/metrics.hpp index 279ea5f91c5..1e3dbe31086 100644 --- a/src/lib/metrics/metrics.hpp +++ b/src/lib/metrics/metrics.hpp @@ -54,9 +54,9 @@ namespace metrics { class ScopedLatency { public: - explicit ScopedLatency(std::string_view name, const std::string &histogramName, const std::string &scopeKey); - explicit ScopedLatency(std::string_view name, Histogram<double> &histogram, std::map<std::string, std::string> attrs = {}, opentelemetry::context::Context context = opentelemetry::context::Context()) : - begin(std::chrono::steady_clock::now()), histogram(histogram), attrs(attrs), context(context) { + explicit ScopedLatency(const std::string_view &name, const std::string &histogramName, const std::string &scopeKey); + explicit ScopedLatency([[maybe_unused]] const std::string_view &name, Histogram<double> &histogram, std::map<std::string, std::string> attrs = {}, opentelemetry::context::Context context = opentelemetry::context::Context()) : + begin(std::chrono::steady_clock::now()), histogram(histogram), attrs(std::move(attrs)), context(std::move(context)) { } void stop(); @@ -64,10 +64,10 @@ namespace metrics { ~ScopedLatency(); private: - opentelemetry::context::Context context; - Histogram<double> &histogram; std::chrono::steady_clock::time_point begin; + Histogram<double> &histogram; std::map<std::string, std::string> attrs; + opentelemetry::context::Context context; bool stopped { false }; }; @@ -94,7 +94,7 @@ namespace metrics { class Metrics final { public: - Metrics() { } + Metrics() = default; ~Metrics() = default; void init(Options opts); diff --git a/src/lib/thread/thread_pool.cpp b/src/lib/thread/thread_pool.cpp index e01028810bc..3971d3a6a02 100644 --- a/src/lib/thread/thread_pool.cpp +++ b/src/lib/thread/thread_pool.cpp @@ -8,7 +8,10 @@ */ #include "pch.hpp" + #include "lib/thread/thread_pool.hpp" + +#include "game/game.hpp" #include "utils/tools.hpp" #ifndef DEFAULT_NUMBER_OF_THREADS @@ -65,7 +68,6 @@ void ThreadPool::shutdown() { while (status == std::future_status::timeout && std::chrono::steady_clock::now() - start < timeout) { tries++; if (tries > 5) { - logger.error("Thread pool shutdown timed out."); break; } for (auto &future : futures) { @@ -84,7 +86,9 @@ asio::io_context &ThreadPool::getIoContext() { void ThreadPool::addLoad(const std::function<void(void)> &load) { asio::post(ioService, [this, load]() { if (ioService.stopped()) { - logger.error("Shutting down, cannot execute task."); + if (g_game().getGameState() != GAME_STATE_SHUTDOWN) { + logger.error("Shutting down, cannot execute task."); + } return; } diff --git a/src/lua/callbacks/callbacks_definitions.hpp b/src/lua/callbacks/callbacks_definitions.hpp index 521a2c4cda7..3b8016f5f5b 100644 --- a/src/lua/callbacks/callbacks_definitions.hpp +++ b/src/lua/callbacks/callbacks_definitions.hpp @@ -56,6 +56,7 @@ enum class EventCallback_t : uint16_t { playerOnCombat, playerOnInventoryUpdate, playerOnRotateItem, + playerOnWalk, // Monster monsterOnDropLoot, monsterPostDropLoot, diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 51c03131fa9..d2b88c30f3a 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -985,6 +985,29 @@ bool EventCallback::playerOnRotateItem(std::shared_ptr<Player> player, std::shar return getScriptInterface()->callFunction(3); } +void EventCallback::playerOnWalk(std::shared_ptr<Player> player, Direction &dir) const { + if (!getScriptInterface()->reserveScriptEnv()) { + g_logger().error("[EventCallback::eventOnWalk - " + "Player {}] " + "Call stack overflow. Too many lua script calls being nested.", + player->getName()); + return; + } + + ScriptEnvironment* scriptEnvironment = getScriptInterface()->getScriptEnv(); + scriptEnvironment->setScriptId(getScriptId(), getScriptInterface()); + + lua_State* L = getScriptInterface()->getLuaState(); + getScriptInterface()->pushFunction(getScriptId()); + + LuaScriptInterface::pushUserdata<Player>(L, player); + LuaScriptInterface::setMetatable(L, -1, "Player"); + + lua_pushnumber(L, dir); + + getScriptInterface()->callVoidFunction(2); +} + void EventCallback::playerOnStorageUpdate(std::shared_ptr<Player> player, const uint32_t key, const int32_t value, int32_t oldValue, uint64_t currentTime) const { if (!getScriptInterface()->reserveScriptEnv()) { g_logger().error("[EventCallback::eventOnStorageUpdate - " diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index d9dc4a9b110..9141235a028 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -116,6 +116,7 @@ class EventCallback : public Script { void playerOnCombat(std::shared_ptr<Player> player, std::shared_ptr<Creature> target, std::shared_ptr<Item> item, CombatDamage &damage) const; void playerOnInventoryUpdate(std::shared_ptr<Player> player, std::shared_ptr<Item> item, Slots_t slot, bool equip) const; bool playerOnRotateItem(std::shared_ptr<Player> player, std::shared_ptr<Item> item, const Position &position) const; + void playerOnWalk(std::shared_ptr<Player> player, Direction &dir) const; // Monster void monsterOnDropLoot(std::shared_ptr<Monster> monster, std::shared_ptr<Container> corpse) const; diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index e3ac954908f..fe2a782b914 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -105,11 +105,9 @@ CreatureEvent::CreatureEvent(LuaScriptInterface* interface) : Script(interface) { } void CreatureEvents::removeInvalidEvents() { - for (auto it = creatureEvents.begin(); it != creatureEvents.end(); ++it) { - if (it->second->getScriptId() == 0) { - creatureEvents.erase(it->second->getName()); - } - } + std::erase_if(creatureEvents, [](const auto &pair) { + return pair.second->getScriptId() == 0; + }); } std::string CreatureEvent::getScriptTypeName() const { diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 0af09476ed8..b302877b3d3 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -24,8 +24,6 @@ void MoveEvents::clear(bool isFromXML /*= false*/) { for (int moveEventType = 0; moveEventType < MOVE_EVENT_LAST; ++moveEventType) { auto &eventList = moveEventList.moveEvent[moveEventType]; - int originalSize = eventList.size(); - eventList.remove_if([&](const std::shared_ptr<MoveEvent> &moveEvent) { bool removed = moveEvent && moveEvent->isFromXML(); if (removed) { diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index 485454a0564..4ce4297b0f5 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -180,7 +180,7 @@ class MoveEvent final : public Script, public SharedObject { } void addVocEquipMap(std::string vocName) { uint16_t vocationId = g_vocations().getVocationId(vocName); - if (vocationId != -1) { + if (vocationId != 65535) { vocEquipMap[vocationId] = true; } } diff --git a/src/lua/functions/core/game/config_functions.cpp b/src/lua/functions/core/game/config_functions.cpp index a84c500b985..d0e77a69352 100644 --- a/src/lua/functions/core/game/config_functions.cpp +++ b/src/lua/functions/core/game/config_functions.cpp @@ -22,7 +22,6 @@ void ConfigFunctions::init(lua_State* L) { #define registerMagicEnumIn(L, tableName, enumValue) \ do { \ - auto number = magic_enum::enum_integer(enumValue); \ auto name = magic_enum::enum_name(enumValue).data(); \ registerVariable(L, tableName, name, value); \ } while (0) diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index ea418dede66..0fdbc96f4d6 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -27,6 +27,8 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" #include "map/spectators.hpp" // Game @@ -212,7 +214,7 @@ int GameFunctions::luaGameGetMonsterTypes(lua_State* L) { const auto type = g_monsters().monsters; lua_createtable(L, type.size(), 0); - for (const auto [typeName, mType] : type) { + for (const auto &[typeName, mType] : type) { pushUserdata<MonsterType>(L, mType); setMetatable(L, -1, "MonsterType"); lua_setfield(L, -2, typeName.c_str()); @@ -515,7 +517,7 @@ int GameFunctions::luaGameGetBestiaryCharm(lua_State* L) { lua_createtable(L, c_list.size(), 0); int index = 0; - for (const auto charmPtr : c_list) { + for (const auto &charmPtr : c_list) { pushUserdata<Charm>(L, charmPtr); setMetatable(L, -1, "Charm"); lua_rawseti(L, -2, ++index); @@ -697,7 +699,7 @@ int GameFunctions::luaGameGetInfluencedMonsters(lua_State* L) { int GameFunctions::luaGameGetLadderIds(lua_State* L) { // Game.getLadderIds() - const auto ladders = Item::items.getLadders(); + const auto &ladders = Item::items.getLadders(); lua_createtable(L, static_cast<int>(ladders.size()), 0); int index = 0; for (const auto ladderId : ladders) { @@ -719,7 +721,7 @@ int GameFunctions::luaGameGetDummies(lua_State* L) { local rate = dummies[1] -- Retrieve dummy rate */ - const auto dummies = Item::items.getDummys(); + const auto &dummies = Item::items.getDummys(); lua_createtable(L, dummies.size(), 0); for (const auto &[dummyId, rate] : dummies) { lua_pushnumber(L, static_cast<lua_Number>(rate)); diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index d2234874749..c8a857cfffa 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -712,7 +712,7 @@ int GlobalFunctions::luaSaveServer(lua_State* L) { } int GlobalFunctions::luaCleanMap(lua_State* L) { - lua_pushnumber(L, Map::clean()); + lua_pushnumber(L, g_game().map.clean()); return 1; } diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index a633afe9749..7a40cc426f1 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -54,7 +54,7 @@ int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { lua_createtable(L, static_cast<int>(eventList.size()), 0); int index = 0; - for (const auto eventPtr : eventList) { + for (const auto &eventPtr : eventList) { pushString(L, eventPtr->getName()); lua_rawseti(L, -2, ++index); } diff --git a/src/lua/functions/creatures/monster/charm_functions.cpp b/src/lua/functions/creatures/monster/charm_functions.cpp index 48f7ff5aec9..d456f1c96a8 100644 --- a/src/lua/functions/creatures/monster/charm_functions.cpp +++ b/src/lua/functions/creatures/monster/charm_functions.cpp @@ -18,7 +18,7 @@ int CharmFunctions::luaCharmCreate(lua_State* L) { if (isNumber(L, 2)) { charmRune_t charmid = getNumber<charmRune_t>(L, 2); const auto charmList = g_game().getCharmList(); - for (const auto charm : charmList) { + for (const auto &charm : charmList) { if (charm->id == charmid) { pushUserdata<Charm>(L, charm); setMetatable(L, -1, "Charm"); diff --git a/src/lua/functions/creatures/monster/monster_spell_functions.cpp b/src/lua/functions/creatures/monster/monster_spell_functions.cpp index ee00fd43af7..a20d57008d2 100644 --- a/src/lua/functions/creatures/monster/monster_spell_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_spell_functions.cpp @@ -170,7 +170,7 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionType(lua_State* L) { const auto spell = getUserdataShared<MonsterSpell>(L, 1); if (spell) { auto conditionType = getNumber<uint8_t>(L, 2); - if (conditionType == -1) { + if (conditionType == 254) { g_logger().error("[{}] trying to register condition type none for monster: {}", __FUNCTION__, spell->name); reportErrorFunc(fmt::format("trying to register condition type none for monster: {}", spell->name)); pushBoolean(L, false); diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index 43c2950a802..8c19a4ede0a 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -400,7 +400,7 @@ int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { if (itemName.empty()) { itemName = Item::items[itemId].name; } - items.emplace_back(itemId, subType, buyPrice, sellPrice, storageKey, storageValue, itemName); + items.emplace_back(itemId, itemName, subType, buyPrice, sellPrice, storageKey, storageValue); lua_pop(L, 8); } lua_pop(L, 3); diff --git a/src/lua/functions/creatures/player/group_functions.cpp b/src/lua/functions/creatures/player/group_functions.cpp index 0ea195fe745..5acc16d72a9 100644 --- a/src/lua/functions/creatures/player/group_functions.cpp +++ b/src/lua/functions/creatures/player/group_functions.cpp @@ -17,7 +17,7 @@ int GroupFunctions::luaGroupCreate(lua_State* L) { // Group(id) uint32_t id = getNumber<uint32_t>(L, 2); - Group* group = g_game().groups.getGroup(id); + std::shared_ptr<Group> group = g_game().groups.getGroup(id); if (group) { pushUserdata<Group>(L, group); setMetatable(L, -1, "Group"); @@ -29,7 +29,7 @@ int GroupFunctions::luaGroupCreate(lua_State* L) { int GroupFunctions::luaGroupGetId(lua_State* L) { // group:getId() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { lua_pushnumber(L, group->id); } else { @@ -40,7 +40,7 @@ int GroupFunctions::luaGroupGetId(lua_State* L) { int GroupFunctions::luaGroupGetName(lua_State* L) { // group:getName() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { pushString(L, group->name); } else { @@ -51,7 +51,7 @@ int GroupFunctions::luaGroupGetName(lua_State* L) { int GroupFunctions::luaGroupGetFlags(lua_State* L) { // group:getFlags() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { std::bitset<magic_enum::enum_integer(PlayerFlags_t::FlagLast)> flags; for (uint8_t i = 0; i < magic_enum::enum_integer(PlayerFlags_t::FlagLast); ++i) { @@ -68,7 +68,7 @@ int GroupFunctions::luaGroupGetFlags(lua_State* L) { int GroupFunctions::luaGroupGetAccess(lua_State* L) { // group:getAccess() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { pushBoolean(L, group->access); } else { @@ -79,7 +79,7 @@ int GroupFunctions::luaGroupGetAccess(lua_State* L) { int GroupFunctions::luaGroupGetMaxDepotItems(lua_State* L) { // group:getMaxDepotItems() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { lua_pushnumber(L, group->maxDepotItems); } else { @@ -90,7 +90,7 @@ int GroupFunctions::luaGroupGetMaxDepotItems(lua_State* L) { int GroupFunctions::luaGroupGetMaxVipEntries(lua_State* L) { // group:getMaxVipEntries() - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { lua_pushnumber(L, group->maxVipEntries); } else { @@ -101,7 +101,7 @@ int GroupFunctions::luaGroupGetMaxVipEntries(lua_State* L) { int GroupFunctions::luaGroupHasFlag(lua_State* L) { // group:hasFlag(flag) - Group* group = getUserdata<Group>(L, 1); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 1); if (group) { auto flag = static_cast<PlayerFlags_t>(getNumber<int>(L, 2)); pushBoolean(L, group->flags[Groups::getFlagNumber(flag)]); diff --git a/src/lua/functions/creatures/player/group_functions.hpp b/src/lua/functions/creatures/player/group_functions.hpp index ecc3ac07280..4a33d1b988e 100644 --- a/src/lua/functions/creatures/player/group_functions.hpp +++ b/src/lua/functions/creatures/player/group_functions.hpp @@ -14,7 +14,7 @@ class GroupFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Group", "", GroupFunctions::luaGroupCreate); + registerSharedClass(L, "Group", "", GroupFunctions::luaGroupCreate); registerMetaMethod(L, "Group", "__eq", GroupFunctions::luaUserdataCompare); registerMethod(L, "Group", "getId", GroupFunctions::luaGroupGetId); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index 3ba2c43841d..5f14db6ea99 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -15,6 +15,8 @@ #include "creatures/players/player.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" #include "game/game.hpp" #include "io/iologindata.hpp" #include "io/ioprey.hpp" @@ -1384,13 +1386,13 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { return 1; } - Vocation* vocation; + std::shared_ptr<Vocation> vocation; if (isNumber(L, 2)) { vocation = g_vocations().getVocation(getNumber<uint16_t>(L, 2)); } else if (isString(L, 2)) { vocation = g_vocations().getVocation(g_vocations().getVocationId(getString(L, 2))); } else if (isUserdata(L, 2)) { - vocation = getUserdata<Vocation>(L, 2); + vocation = getUserdataShared<Vocation>(L, 2); } else { vocation = nullptr; } @@ -1602,7 +1604,7 @@ int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { // player:setGroup(group) - Group* group = getUserdata<Group>(L, 2); + std::shared_ptr<Group> group = getUserdataShared<Group>(L, 2); if (!group) { pushBoolean(L, false); return 1; @@ -1742,6 +1744,11 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { return 1; } + if (key == 0) { + reportErrorFunc("Storage key is nil"); + return 1; + } + if (player) { player->addStorageValue(key, value); pushBoolean(L, true); @@ -1760,6 +1767,7 @@ int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { return 0; } + g_logger().warn("The function 'player:getStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); auto name = getString(L, 2); lua_pushnumber(L, player->getStorageValueByName(name)); return 1; @@ -1774,6 +1782,7 @@ int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { return 0; } + g_logger().warn("The function 'player:setStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); auto storageName = getString(L, 2); int32_t value = getNumber<int32_t>(L, 3); @@ -3015,14 +3024,14 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { if (player->isInGhostMode()) { for (const auto &it : g_game().getPlayers()) { if (!it.second->isAccessPlayer()) { - it.second->notifyStatusChange(player, VIPSTATUS_OFFLINE); + it.second->vip()->notifyStatusChange(player, VipStatus_t::Offline); } } IOLoginData::updateOnlineStatus(player->getGUID(), false); } else { for (const auto &it : g_game().getPlayers()) { if (!it.second->isAccessPlayer()) { - it.second->notifyStatusChange(player, player->statusVipList); + it.second->vip()->notifyStatusChange(player, player->vip()->getStatus()); } } IOLoginData::updateOnlineStatus(player->getGUID(), true); @@ -3219,23 +3228,23 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerGetStoreXpBoost(lua_State* L) { - // player:getStoreXpBoost() +int PlayerFunctions::luaPlayerGetXpBoostPercent(lua_State* L) { + // player:getXpBoostPercent() std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1); if (player) { - lua_pushnumber(L, player->getStoreXpBoost()); + lua_pushnumber(L, player->getXpBoostPercent()); } else { lua_pushnil(L); } return 1; } -int PlayerFunctions::luaPlayerSetStoreXpBoost(lua_State* L) { - // player:setStoreXpBoost(value) +int PlayerFunctions::luaPlayerSetXpBoostPercent(lua_State* L) { + // player:setXpBoostPercent(value) std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1); if (player) { - uint16_t experience = getNumber<uint16_t>(L, 2); - player->setStoreXpBoost(experience); + uint16_t percent = getNumber<uint16_t>(L, 2); + player->setXpBoostPercent(percent); pushBoolean(L, true); } else { lua_pushnil(L); @@ -3267,12 +3276,12 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { - // player:setExpBoostStamina(percent) +int PlayerFunctions::luaPlayerSetXpBoostTime(lua_State* L) { + // player:setXpBoostTime(timeLeft) std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1); if (player) { - uint16_t stamina = getNumber<uint16_t>(L, 2); - player->setExpBoostStamina(stamina); + uint16_t timeLeft = getNumber<uint16_t>(L, 2); + player->setXpBoostTime(timeLeft); player->sendStats(); pushBoolean(L, true); } else { @@ -3281,11 +3290,11 @@ int PlayerFunctions::luaPlayerSetExpBoostStamina(lua_State* L) { return 1; } -int PlayerFunctions::luaPlayerGetExpBoostStamina(lua_State* L) { - // player:getExpBoostStamina() +int PlayerFunctions::luaPlayerGetXpBoostTime(lua_State* L) { + // player:getXpBoostTime() std::shared_ptr<Player> player = getUserdataShared<Player>(L, 1); if (player) { - lua_pushnumber(L, player->getExpBoostStamina()); + lua_pushnumber(L, player->getXpBoostTime()); } else { lua_pushnil(L); } @@ -3997,9 +4006,9 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { } if (lua_gettop(L) == 1) { - lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR)); + lua_pushnumber(L, (lua_Number)player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL)); } else { - player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR, getNumber<int64_t>(L, 2)); + player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, getNumber<int64_t>(L, 2)); pushBoolean(L, true); } return 1; @@ -4279,3 +4288,70 @@ int PlayerFunctions::luaPlayerRemoveAchievementPoints(lua_State* L) { pushBoolean(L, true); return 1; } + +int PlayerFunctions::luaPlayerAddBadge(lua_State* L) { + // player:addBadge(id) + const auto &player = getUserdataShared<Player>(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + player->badge()->add(getNumber<uint8_t>(L, 2, 0)); + pushBoolean(L, true); + return 1; +} + +int PlayerFunctions::luaPlayerAddTitle(lua_State* L) { + // player:addTitle(id) + const auto &player = getUserdataShared<Player>(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + player->title()->manage(true, getNumber<uint8_t>(L, 2, 0)); + pushBoolean(L, true); + return 1; +} + +int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { + // player:getTitles() + const auto &player = getUserdataShared<Player>(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + auto playerTitles = player->title()->getUnlockedTitles(); + lua_createtable(L, static_cast<int>(playerTitles.size()), 0); + + int index = 0; + for (const auto &title : playerTitles) { + lua_createtable(L, 0, 3); + setField(L, "id", title.first.m_id); + setField(L, "name", player->title()->getNameBySex(player->getSex(), title.first.m_maleName, title.first.m_femaleName)); + setField(L, "description", title.first.m_description); + lua_rawseti(L, -2, ++index); + } + return 1; +} + +int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) { + // player:setCurrentTitle(id) + const auto &player = getUserdataShared<Player>(L, 1); + if (!player) { + reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + return 1; + } + + const auto &title = g_game().getTitleById(getNumber<uint8_t>(L, 2, 0)); + if (title.m_id == 0) { + reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); + return 1; + } + + player->title()->setCurrentTitle(title.m_id); + pushBoolean(L, true); + return 1; +} diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index fafc99ff955..4d89a86d27f 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -273,12 +273,12 @@ class PlayerFunctions final : LuaScriptInterface { registerMethod(L, "Player", "setVoucherXpBoost", PlayerFunctions::luaPlayerSetVoucherXpBoost); registerMethod(L, "Player", "getGrindingXpBoost", PlayerFunctions::luaPlayerGetGrindingXpBoost); registerMethod(L, "Player", "setGrindingXpBoost", PlayerFunctions::luaPlayerSetGrindingXpBoost); - registerMethod(L, "Player", "getStoreXpBoost", PlayerFunctions::luaPlayerGetStoreXpBoost); - registerMethod(L, "Player", "setStoreXpBoost", PlayerFunctions::luaPlayerSetStoreXpBoost); + registerMethod(L, "Player", "getXpBoostPercent", PlayerFunctions::luaPlayerGetXpBoostPercent); + registerMethod(L, "Player", "setXpBoostPercent", PlayerFunctions::luaPlayerSetXpBoostPercent); registerMethod(L, "Player", "getStaminaXpBoost", PlayerFunctions::luaPlayerGetStaminaXpBoost); registerMethod(L, "Player", "setStaminaXpBoost", PlayerFunctions::luaPlayerSetStaminaXpBoost); - registerMethod(L, "Player", "getExpBoostStamina", PlayerFunctions::luaPlayerGetExpBoostStamina); - registerMethod(L, "Player", "setExpBoostStamina", PlayerFunctions::luaPlayerSetExpBoostStamina); + registerMethod(L, "Player", "getXpBoostTime", PlayerFunctions::luaPlayerGetXpBoostTime); + registerMethod(L, "Player", "setXpBoostTime", PlayerFunctions::luaPlayerSetXpBoostTime); registerMethod(L, "Player", "getIdleTime", PlayerFunctions::luaPlayerGetIdleTime); registerMethod(L, "Player", "getFreeBackpackSlots", PlayerFunctions::luaPlayerGetFreeBackpackSlots); @@ -364,6 +364,14 @@ class PlayerFunctions final : LuaScriptInterface { registerMethod(L, "Player", "addAchievementPoints", PlayerFunctions::luaPlayerAddAchievementPoints); registerMethod(L, "Player", "removeAchievementPoints", PlayerFunctions::luaPlayerRemoveAchievementPoints); + // Badge Functions + registerMethod(L, "Player", "addBadge", PlayerFunctions::luaPlayerAddBadge); + + // Title Functions + registerMethod(L, "Player", "addTitle", PlayerFunctions::luaPlayerAddTitle); + registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles); + registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle); + GroupFunctions::init(L); GuildFunctions::init(L); MountFunctions::init(L); @@ -627,12 +635,12 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerSetVoucherXpBoost(lua_State* L); static int luaPlayerGetGrindingXpBoost(lua_State* L); static int luaPlayerSetGrindingXpBoost(lua_State* L); - static int luaPlayerGetStoreXpBoost(lua_State* L); - static int luaPlayerSetStoreXpBoost(lua_State* L); + static int luaPlayerGetXpBoostPercent(lua_State* L); + static int luaPlayerSetXpBoostPercent(lua_State* L); static int luaPlayerGetStaminaXpBoost(lua_State* L); static int luaPlayerSetStaminaXpBoost(lua_State* L); - static int luaPlayerGetExpBoostStamina(lua_State* L); - static int luaPlayerSetExpBoostStamina(lua_State* L); + static int luaPlayerGetXpBoostTime(lua_State* L); + static int luaPlayerSetXpBoostTime(lua_State* L); static int luaPlayerGetIdleTime(lua_State* L); static int luaPlayerGetFreeBackpackSlots(lua_State* L); @@ -718,5 +726,11 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerAddAchievementPoints(lua_State* L); static int luaPlayerRemoveAchievementPoints(lua_State* L); + static int luaPlayerAddBadge(lua_State* L); + + static int luaPlayerAddTitle(lua_State* L); + static int luaPlayerGetTitles(lua_State* L); + static int luaPlayerSetCurrentTitle(lua_State* L); + friend class CreatureFunctions; }; diff --git a/src/lua/functions/creatures/player/vocation_functions.cpp b/src/lua/functions/creatures/player/vocation_functions.cpp index 5e95a827ff9..15cf888bf8a 100644 --- a/src/lua/functions/creatures/player/vocation_functions.cpp +++ b/src/lua/functions/creatures/player/vocation_functions.cpp @@ -21,7 +21,7 @@ int VocationFunctions::luaVocationCreate(lua_State* L) { vocationId = g_vocations().getVocationId(getString(L, 2)); } - Vocation* vocation = g_vocations().getVocation(vocationId); + std::shared_ptr<Vocation> vocation = g_vocations().getVocation(vocationId); if (vocation) { pushUserdata<Vocation>(L, vocation); setMetatable(L, -1, "Vocation"); @@ -33,7 +33,7 @@ int VocationFunctions::luaVocationCreate(lua_State* L) { int VocationFunctions::luaVocationGetId(lua_State* L) { // vocation:getId() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getId()); } else { @@ -44,7 +44,7 @@ int VocationFunctions::luaVocationGetId(lua_State* L) { int VocationFunctions::luaVocationGetClientId(lua_State* L) { // vocation:getClientId() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getClientId()); } else { @@ -55,7 +55,7 @@ int VocationFunctions::luaVocationGetClientId(lua_State* L) { int VocationFunctions::luaVocationGetBaseId(lua_State* L) { // vocation:getBaseId() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseId()); } else { @@ -66,7 +66,7 @@ int VocationFunctions::luaVocationGetBaseId(lua_State* L) { int VocationFunctions::luaVocationGetName(lua_State* L) { // vocation:getName() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { pushString(L, vocation->getVocName()); } else { @@ -77,7 +77,7 @@ int VocationFunctions::luaVocationGetName(lua_State* L) { int VocationFunctions::luaVocationGetDescription(lua_State* L) { // vocation:getDescription() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { pushString(L, vocation->getVocDescription()); } else { @@ -88,7 +88,7 @@ int VocationFunctions::luaVocationGetDescription(lua_State* L) { int VocationFunctions::luaVocationGetRequiredSkillTries(lua_State* L) { // vocation:getRequiredSkillTries(skillType, skillLevel) - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { skills_t skillType = getNumber<skills_t>(L, 2); uint16_t skillLevel = getNumber<uint16_t>(L, 3); @@ -101,7 +101,7 @@ int VocationFunctions::luaVocationGetRequiredSkillTries(lua_State* L) { int VocationFunctions::luaVocationGetRequiredManaSpent(lua_State* L) { // vocation:getRequiredManaSpent(magicLevel) - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { uint32_t magicLevel = getNumber<uint32_t>(L, 2); lua_pushnumber(L, vocation->getReqMana(magicLevel)); @@ -113,7 +113,7 @@ int VocationFunctions::luaVocationGetRequiredManaSpent(lua_State* L) { int VocationFunctions::luaVocationGetCapacityGain(lua_State* L) { // vocation:getCapacityGain() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getCapGain()); } else { @@ -124,7 +124,7 @@ int VocationFunctions::luaVocationGetCapacityGain(lua_State* L) { int VocationFunctions::luaVocationGetHealthGain(lua_State* L) { // vocation:getHealthGain() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHPGain()); } else { @@ -135,7 +135,7 @@ int VocationFunctions::luaVocationGetHealthGain(lua_State* L) { int VocationFunctions::luaVocationGetHealthGainTicks(lua_State* L) { // vocation:getHealthGainTicks() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHealthGainTicks()); } else { @@ -146,7 +146,7 @@ int VocationFunctions::luaVocationGetHealthGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetHealthGainAmount(lua_State* L) { // vocation:getHealthGainAmount() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHealthGainAmount()); } else { @@ -157,7 +157,7 @@ int VocationFunctions::luaVocationGetHealthGainAmount(lua_State* L) { int VocationFunctions::luaVocationGetManaGain(lua_State* L) { // vocation:getManaGain() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGain()); } else { @@ -168,7 +168,7 @@ int VocationFunctions::luaVocationGetManaGain(lua_State* L) { int VocationFunctions::luaVocationGetManaGainTicks(lua_State* L) { // vocation:getManaGainTicks() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGainTicks()); } else { @@ -179,7 +179,7 @@ int VocationFunctions::luaVocationGetManaGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetManaGainAmount(lua_State* L) { // vocation:getManaGainAmount() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGainAmount()); } else { @@ -190,7 +190,7 @@ int VocationFunctions::luaVocationGetManaGainAmount(lua_State* L) { int VocationFunctions::luaVocationGetMaxSoul(lua_State* L) { // vocation:getMaxSoul() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getSoulMax()); } else { @@ -201,7 +201,7 @@ int VocationFunctions::luaVocationGetMaxSoul(lua_State* L) { int VocationFunctions::luaVocationGetSoulGainTicks(lua_State* L) { // vocation:getSoulGainTicks() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getSoulGainTicks()); } else { @@ -212,7 +212,7 @@ int VocationFunctions::luaVocationGetSoulGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetBaseAttackSpeed(lua_State* L) { // vocation:getBaseAttackSpeed() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseAttackSpeed()); } else { @@ -223,7 +223,7 @@ int VocationFunctions::luaVocationGetBaseAttackSpeed(lua_State* L) { int VocationFunctions::luaVocationGetAttackSpeed(lua_State* L) { // vocation:getAttackSpeed() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getAttackSpeed()); } else { @@ -234,7 +234,7 @@ int VocationFunctions::luaVocationGetAttackSpeed(lua_State* L) { int VocationFunctions::luaVocationGetBaseSpeed(lua_State* L) { // vocation:getBaseSpeed() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseSpeed()); } else { @@ -245,7 +245,7 @@ int VocationFunctions::luaVocationGetBaseSpeed(lua_State* L) { int VocationFunctions::luaVocationGetDemotion(lua_State* L) { // vocation:getDemotion() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (!vocation) { lua_pushnil(L); return 1; @@ -257,7 +257,7 @@ int VocationFunctions::luaVocationGetDemotion(lua_State* L) { return 1; } - Vocation* demotedVocation = g_vocations().getVocation(fromId); + std::shared_ptr<Vocation> demotedVocation = g_vocations().getVocation(fromId); if (demotedVocation && demotedVocation != vocation) { pushUserdata<Vocation>(L, demotedVocation); setMetatable(L, -1, "Vocation"); @@ -269,7 +269,7 @@ int VocationFunctions::luaVocationGetDemotion(lua_State* L) { int VocationFunctions::luaVocationGetPromotion(lua_State* L) { // vocation:getPromotion() - Vocation* vocation = getUserdata<Vocation>(L, 1); + std::shared_ptr<Vocation> vocation = getUserdataShared<Vocation>(L, 1); if (!vocation) { lua_pushnil(L); return 1; @@ -281,7 +281,7 @@ int VocationFunctions::luaVocationGetPromotion(lua_State* L) { return 1; } - Vocation* promotedVocation = g_vocations().getVocation(promotedId); + std::shared_ptr<Vocation> promotedVocation = g_vocations().getVocation(promotedId); if (promotedVocation && promotedVocation != vocation) { pushUserdata<Vocation>(L, promotedVocation); setMetatable(L, -1, "Vocation"); diff --git a/src/lua/functions/creatures/player/vocation_functions.hpp b/src/lua/functions/creatures/player/vocation_functions.hpp index 7205580f90f..0895f6ac8d6 100644 --- a/src/lua/functions/creatures/player/vocation_functions.hpp +++ b/src/lua/functions/creatures/player/vocation_functions.hpp @@ -14,7 +14,7 @@ class VocationFunctions final : LuaScriptInterface { public: static void init(lua_State* L) { - registerClass(L, "Vocation", "", VocationFunctions::luaVocationCreate); + registerSharedClass(L, "Vocation", "", VocationFunctions::luaVocationCreate); registerMetaMethod(L, "Vocation", "__eq", VocationFunctions::luaUserdataCompare); registerMethod(L, "Vocation", "getId", VocationFunctions::luaVocationGetId); diff --git a/src/map/CMakeLists.txt b/src/map/CMakeLists.txt index 7d744950c1f..cab0eb03b15 100644 --- a/src/map/CMakeLists.txt +++ b/src/map/CMakeLists.txt @@ -2,7 +2,7 @@ target_sources(${PROJECT_NAME}_lib PRIVATE house/house.cpp house/housetile.cpp utils/astarnodes.cpp - utils/qtreenode.cpp + utils/mapsector.cpp map.cpp mapcache.cpp spectators.cpp diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 7967e21c3cc..842622b2af5 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -45,7 +45,7 @@ void House::setNewOwnerGuid(int32_t newOwnerGuid, bool serverStartup) { void House::clearHouseInfo(bool preventOwnerDeletion) { // Remove players from beds - for (auto bed : bedsList) { + for (const auto &bed : bedsList) { if (bed->getSleeper() != 0) { bed->wakeUp(nullptr); } @@ -60,7 +60,7 @@ void House::clearHouseInfo(bool preventOwnerDeletion) { setAccessList(SUBOWNER_LIST, ""); setAccessList(GUEST_LIST, ""); - for (auto door : doorList) { + for (const auto &door : doorList) { door->setAccessList(""); } } @@ -73,7 +73,7 @@ bool House::tryTransferOwnership(std::shared_ptr<Player> player, bool serverStar transferSuccess = transferToDepot(); } - for (auto tile : houseTiles) { + for (const auto &tile : houseTiles) { if (const CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { const auto creature = (*creatures)[i]; @@ -103,7 +103,7 @@ void House::setOwner(uint32_t guid, bool updateDatabase /* = true*/, std::shared isLoaded = true; if (owner != 0) { - tryTransferOwnership(player, false); + tryTransferOwnership(std::move(player), false); } else { std::string strRentPeriod = asLowerCaseString(g_configManager().getString(HOUSE_RENT_PERIOD, __FUNCTION__)); time_t currentTime = time(nullptr); @@ -237,7 +237,7 @@ void House::setAccessList(uint32_t listId, const std::string &textlist) { } // kick uninvited players - for (std::shared_ptr<HouseTile> tile : houseTiles) { + for (const std::shared_ptr<HouseTile> &tile : houseTiles) { if (CreatureVector* creatures = tile->getCreatures()) { for (int32_t i = creatures->size(); --i >= 0;) { std::shared_ptr<Player> player = (*creatures)[i]->getPlayer(); @@ -272,7 +272,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player) const { if (townId == 0 || !player) { return false; } - for (std::shared_ptr<HouseTile> tile : houseTiles) { + for (const std::shared_ptr<HouseTile> &tile : houseTiles) { if (!transferToDepot(player, tile)) { return false; } @@ -304,7 +304,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player, std::shared_ptr<Hous std::unordered_set<std::shared_ptr<Player>> playersToSave = { player }; - for (std::shared_ptr<Item> item : moveItemList) { + for (const std::shared_ptr<Item> &item : moveItemList) { g_logger().debug("[{}] moving item '{}' to depot", __FUNCTION__, item->getName()); auto targetPlayer = player; if (item->hasOwner() && !item->isOwner(targetPlayer)) { @@ -317,7 +317,7 @@ bool House::transferToDepot(std::shared_ptr<Player> player, std::shared_ptr<Hous } g_game().internalMoveItem(item->getParent(), targetPlayer->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT); } - for (auto playerToSave : playersToSave) { + for (const auto &playerToSave : playersToSave) { g_saveManager().savePlayer(playerToSave); } return true; @@ -379,7 +379,7 @@ void House::handleWrapableItem(ItemList &moveItemList, std::shared_ptr<Item> ite void House::handleContainer(ItemList &moveItemList, std::shared_ptr<Item> item) const { if (const auto container = item->getContainer()) { - for (std::shared_ptr<Item> containerItem : container->getItemList()) { + for (const std::shared_ptr<Item> &containerItem : container->getItemList()) { moveItemList.push_back(containerItem); } } @@ -554,32 +554,32 @@ void AccessList::parseList(const std::string &list) { } auto lines = explodeString(validList, "\n", 100); - for (auto &line : lines) { - trimString(line); - trim_left(line, '\t'); - trim_right(line, '\t'); - trimString(line); + for (auto &m_line : lines) { + trimString(m_line); + trim_left(m_line, '\t'); + trim_right(m_line, '\t'); + trimString(m_line); - if (line.empty() || line.front() == '#' || line.length() > 100) { + if (m_line.empty() || m_line.front() == '#' || m_line.length() > 100) { continue; } - toLowerCaseString(line); + toLowerCaseString(m_line); - std::string::size_type at_pos = line.find("@"); + std::string::size_type at_pos = m_line.find('@'); if (at_pos != std::string::npos) { if (at_pos == 0) { - addGuild(line.substr(1)); + addGuild(m_line.substr(1)); } else { - addGuildRank(line.substr(0, at_pos - 1), line.substr(at_pos + 1)); + addGuildRank(m_line.substr(0, at_pos - 1), m_line.substr(at_pos + 1)); } - } else if (line == "*") { + } else if (m_line == "*") { allowEveryone = true; - } else if (line.find_first_of("!*?") != std::string::npos) { + } else if (m_line.find_first_of("!*?") != std::string::npos) { // Remove regular expressions since they don't make much sense in houses continue; - } else if (line.length() <= NETWORKMESSAGE_PLAYERNAME_MAXLENGTH) { - addPlayer(line); + } else if (m_line.length() <= NETWORKMESSAGE_PLAYERNAME_MAXLENGTH) { + addPlayer(m_line); } } } @@ -603,7 +603,7 @@ namespace { return nullptr; } - const auto guild = g_game().getGuild(guildId); + auto guild = g_game().getGuild(guildId); if (guild) { return guild; } @@ -615,7 +615,7 @@ namespace { void AccessList::addGuild(const std::string &name) { const auto guild = getGuildByName(name); if (guild) { - for (const auto rank : guild->getRanks()) { + for (const auto &rank : guild->getRanks()) { guildRankList.insert(rank->id); } } @@ -669,7 +669,7 @@ void Door::setHouse(std::shared_ptr<House> newHouse) { return; } - this->house = newHouse; + this->house = std::move(newHouse); if (!accessList) { accessList = std::make_unique<AccessList>(); diff --git a/src/map/map.cpp b/src/map/map.cpp index 395e6d7d2be..d4d1c4147b1 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -163,7 +163,7 @@ std::shared_ptr<Tile> Map::getLoadedTile(uint16_t x, uint16_t y, uint8_t z) { return nullptr; } - const auto leaf = getQTNode(x, y); + const auto leaf = getMapSector(x, y); if (!leaf) { return nullptr; } @@ -182,12 +182,12 @@ std::shared_ptr<Tile> Map::getTile(uint16_t x, uint16_t y, uint8_t z) { return nullptr; } - const auto leaf = getQTNode(x, y); - if (!leaf) { + const auto sector = getMapSector(x, y); + if (!sector) { return nullptr; } - const auto &floor = leaf->getFloor(z); + const auto &floor = sector->getFloor(z); if (!floor) { return nullptr; } @@ -215,10 +215,10 @@ void Map::setTile(uint16_t x, uint16_t y, uint8_t z, std::shared_ptr<Tile> newTi return; } - if (const auto leaf = getQTNode(x, y)) { - leaf->createFloor(z)->setTile(x, y, newTile); + if (const auto sector = getMapSector(x, y)) { + sector->createFloor(z)->setTile(x, y, newTile); } else { - root.getBestLeaf(x, y, 15)->createFloor(z)->setTile(x, y, newTile); + getBestMapSector(x, y)->createFloor(z)->setTile(x, y, newTile); } } @@ -315,7 +315,7 @@ bool Map::placeCreature(const Position ¢erPos, std::shared_ptr<Creature> cre toCylinder->internalAddThing(creature); const Position &dest = toCylinder->getPosition(); - getQTNode(dest.x, dest.y)->addCreature(creature); + getMapSector(dest.x, dest.y)->addCreature(creature); return true; } @@ -351,13 +351,13 @@ void Map::moveCreature(const std::shared_ptr<Creature> &creature, const std::sha // remove the creature oldTile->removeThing(creature, 0); - auto leaf = getQTNode(oldPos.x, oldPos.y); - auto new_leaf = getQTNode(newPos.x, newPos.y); + MapSector* old_sector = getMapSector(oldPos.x, oldPos.y); + MapSector* new_sector = getMapSector(newPos.x, newPos.y); // Switch the node ownership - if (leaf != new_leaf) { - leaf->removeCreature(creature); - new_leaf->addCreature(creature); + if (old_sector != new_sector) { + old_sector->removeCreature(creature); + new_sector->addCreature(creature); } // add the creature @@ -611,7 +611,7 @@ bool Map::getPathMatching(const std::shared_ptr<Creature> &creature, const Posit const bool withoutCreature = creature == nullptr; const auto &tile = neighborNode || withoutCreature ? getTile(pos.x, pos.y, pos.z) : canWalkTo(creature, pos); - if (!tile || !neighborNode && withoutCreature && tile->hasFlag(TILESTATE_BLOCKSOLID)) { + if (!tile || (!neighborNode && withoutCreature && tile->hasFlag(TILESTATE_BLOCKSOLID))) { continue; } @@ -687,32 +687,47 @@ bool Map::getPathMatching(const std::shared_ptr<Creature> &creature, const Posit uint32_t Map::clean() { uint64_t start = OTSYS_TIME(); - size_t tiles = 0; + size_t qntTiles = 0; if (g_game().getGameState() == GAME_STATE_NORMAL) { g_game().setGameState(GAME_STATE_MAINTAIN); } - std::vector<std::shared_ptr<Item>> toRemove; - for (const auto &tile : g_game().getTilesToClean()) { - if (!tile) { - continue; - } - if (const auto items = tile->getItemList()) { - ++tiles; - for (const auto &item : *items) { - if (item->isCleanable()) { - toRemove.emplace_back(item); + ItemVector toRemove; + toRemove.reserve(128); + for (const auto &mit : mapSectors) { + for (uint8_t z = 0; z < MAP_MAX_LAYERS; ++z) { + if (const auto &floor = mit.second.getFloor(z)) { + for (auto &tiles : floor->getTiles()) { + for (const auto &[tile, cachedTile] : tiles) { + if (!tile || tile->hasFlag(TILESTATE_PROTECTIONZONE)) { + continue; + } + + TileItemVector* itemList = tile->getItemList(); + if (!itemList) { + continue; + } + + ++qntTiles; + + for (auto it = ItemVector::const_reverse_iterator(itemList->getEndDownItem()), end = ItemVector::const_reverse_iterator(itemList->getBeginDownItem()); it != end; ++it) { + const auto &item = *it; + if (item->isCleanable()) { + toRemove.push_back(item); + } + } + } } } } } + const size_t count = toRemove.size(); for (const auto &item : toRemove) { g_game().internalRemoveItem(item, -1); } - size_t count = toRemove.size(); g_game().clearTilesToClean(); if (g_game().getGameState() == GAME_STATE_MAINTAIN) { @@ -720,6 +735,6 @@ uint32_t Map::clean() { } uint64_t end = OTSYS_TIME(); - g_logger().info("CLEAN: Removed {} item{} from {} tile{} in {} seconds", count, (count != 1 ? "s" : ""), tiles, (tiles != 1 ? "s" : ""), (end - start) / (1000.f)); + g_logger().info("CLEAN: Removed {} item{} from {} tile{} in {} seconds", count, (count != 1 ? "s" : ""), qntTiles, (qntTiles != 1 ? "s" : ""), (end - start) / (1000.f)); return count; } diff --git a/src/map/map.hpp b/src/map/map.hpp index 0894853e30e..e57328e12b3 100644 --- a/src/map/map.hpp +++ b/src/map/map.hpp @@ -29,9 +29,9 @@ class FrozenPathingConditionCall; * Map class. * Holds all the actual map-data */ -class Map : protected MapCache { +class Map : public MapCache { public: - static uint32_t clean(); + uint32_t clean(); std::filesystem::path getPath() const { return path; @@ -131,10 +131,6 @@ class Map : protected MapCache { std::map<std::string, Position> waypoints; - QTreeLeafNode* getQTNode(uint16_t x, uint16_t y) { - return QTreeNode::getLeafStatic<QTreeLeafNode*, QTreeNode*>(&root, x, y); - } - // Storage made by "loadFromXML" of houses, monsters and npcs for main map SpawnsMonster spawnsMonster; SpawnsNpc spawnsNpc; diff --git a/src/map/map_const.hpp b/src/map/map_const.hpp index 10f814d7f8b..109641d6bfe 100644 --- a/src/map/map_const.hpp +++ b/src/map/map_const.hpp @@ -18,6 +18,7 @@ static constexpr int8_t MAP_MAX_LAYERS = 16; static constexpr int8_t MAP_INIT_SURFACE_LAYER = 7; // (MAP_MAX_LAYERS / 2) -1 static constexpr int8_t MAP_LAYER_VIEW_LIMIT = 2; -static constexpr int32_t FLOOR_BITS = 3; -static constexpr int32_t FLOOR_SIZE = (1 << FLOOR_BITS); -static constexpr int32_t FLOOR_MASK = (FLOOR_SIZE - 1); +// SECTOR_SIZE must be power of 2 value +// The bigger the SECTOR_SIZE is the less hash map collision there should be but it'll consume more memory +static constexpr int32_t SECTOR_SIZE = 16; +static constexpr int32_t SECTOR_MASK = SECTOR_SIZE - 1; diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index ede4d3fd862..0448615ee99 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -154,10 +154,10 @@ void MapCache::setBasicTile(uint16_t x, uint16_t y, uint8_t z, const std::shared } const auto tile = static_tryGetTileFromCache(newTile); - if (const auto leaf = QTreeNode::getLeafStatic<QTreeLeafNode*, QTreeNode*>(&root, x, y)) { - leaf->createFloor(z)->setTileCache(x, y, tile); + if (const auto sector = getMapSector(x, y)) { + sector->createFloor(z)->setTileCache(x, y, tile); } else { - root.getBestLeaf(x, y, 15)->createFloor(z)->setTileCache(x, y, tile); + getBestMapSector(x, y)->createFloor(z)->setTileCache(x, y, tile); } } @@ -165,6 +165,46 @@ std::shared_ptr<BasicItem> MapCache::tryReplaceItemFromCache(const std::shared_p return static_tryGetItemFromCache(ref); } +MapSector* MapCache::createMapSector(const uint32_t x, const uint32_t y) { + const uint32_t index = x / SECTOR_SIZE | y / SECTOR_SIZE << 16; + const auto it = mapSectors.find(index); + if (it != mapSectors.end()) { + return &it->second; + } + + MapSector::newSector = true; + return &mapSectors[index]; +} + +MapSector* MapCache::getBestMapSector(uint32_t x, uint32_t y) { + MapSector::newSector = false; + const auto sector = createMapSector(x, y); + + if (MapSector::newSector) { + // update north sector + if (const auto northSector = getMapSector(x, y - SECTOR_SIZE)) { + northSector->sectorS = sector; + } + + // update west sector + if (const auto westSector = getMapSector(x - SECTOR_SIZE, y)) { + westSector->sectorE = sector; + } + + // update south sector + if (const auto southSector = getMapSector(x, y + SECTOR_SIZE)) { + sector->sectorS = southSector; + } + + // update east sector + if (const auto eastSector = getMapSector(x + SECTOR_SIZE, y)) { + sector->sectorE = eastSector; + } + } + + return sector; +} + void BasicTile::hash(size_t &h) const { std::array<uint32_t, 4> arr = { flags, houseId, type, isStatic }; for (const auto v : arr) { diff --git a/src/map/mapcache.hpp b/src/map/mapcache.hpp index bc3e59a700a..429d786972b 100644 --- a/src/map/mapcache.hpp +++ b/src/map/mapcache.hpp @@ -10,7 +10,7 @@ #pragma once #include "items/items_definitions.hpp" -#include "utils/qtreenode.hpp" +#include "utils/mapsector.hpp" class Map; class Tile; @@ -79,42 +79,6 @@ struct BasicTile { #pragma pack() -struct Floor { - explicit Floor(uint8_t z) : - z(z) { } - - std::shared_ptr<Tile> getTile(uint16_t x, uint16_t y) const { - std::shared_lock sl(mutex); - return tiles[x & FLOOR_MASK][y & FLOOR_MASK].first; - } - - void setTile(uint16_t x, uint16_t y, std::shared_ptr<Tile> tile) { - tiles[x & FLOOR_MASK][y & FLOOR_MASK].first = tile; - } - - std::shared_ptr<BasicTile> getTileCache(uint16_t x, uint16_t y) const { - std::shared_lock sl(mutex); - return tiles[x & FLOOR_MASK][y & FLOOR_MASK].second; - } - - void setTileCache(uint16_t x, uint16_t y, const std::shared_ptr<BasicTile> &newTile) { - tiles[x & FLOOR_MASK][y & FLOOR_MASK].second = newTile; - } - - uint8_t getZ() const { - return z; - } - - auto &getMutex() const { - return mutex; - } - -private: - std::pair<std::shared_ptr<Tile>, std::shared_ptr<BasicTile>> tiles[FLOOR_SIZE][FLOOR_SIZE] = {}; - mutable std::shared_mutex mutex; - uint8_t z { 0 }; -}; - class MapCache { public: virtual ~MapCache() = default; @@ -125,10 +89,31 @@ class MapCache { void flush(); + /** + * Creates a map sector. + * \returns A pointer to that map sector. + */ + MapSector* createMapSector(uint32_t x, uint32_t y); + MapSector* getBestMapSector(uint32_t x, uint32_t y); + + /** + * Gets a map sector. + * \returns A pointer to that map sector. + */ + MapSector* getMapSector(const uint32_t x, const uint32_t y) { + const auto it = mapSectors.find(x / SECTOR_SIZE | y / SECTOR_SIZE << 16); + return it != mapSectors.end() ? &it->second : nullptr; + } + + const MapSector* getMapSector(const uint32_t x, const uint32_t y) const { + const auto it = mapSectors.find(x / SECTOR_SIZE | y / SECTOR_SIZE << 16); + return it != mapSectors.end() ? &it->second : nullptr; + } + protected: std::shared_ptr<Tile> getOrCreateTileFromCache(const std::unique_ptr<Floor> &floor, uint16_t x, uint16_t y); - QTreeNode root; + std::unordered_map<uint32_t, MapSector> mapSectors; private: void parseItemAttr(const std::shared_ptr<BasicItem> &BasicItem, std::shared_ptr<Item> item); diff --git a/src/map/spectators.cpp b/src/map/spectators.cpp index 18ce13871fe..36cce6d535b 100644 --- a/src/map/spectators.cpp +++ b/src/map/spectators.cpp @@ -79,7 +79,7 @@ bool Spectators::checkCache(const SpectatorsCache::FloorData &specData, bool onl if (checkDistance) { SpectatorList spectators; spectators.reserve(creatures.size()); - for (const auto creature : *list) { + for (const auto &creature : *list) { const auto &specPos = creature->getPosition(); if (centerPos.x - specPos.x >= minRangeX && centerPos.y - specPos.y >= minRangeY @@ -154,64 +154,62 @@ Spectators Spectators::find(const Position ¢erPos, bool multifloor, bool onl } } - const int_fast32_t min_y = centerPos.y + minRangeY; - const int_fast32_t min_x = centerPos.x + minRangeX; - const int_fast32_t max_y = centerPos.y + maxRangeY; - const int_fast32_t max_x = centerPos.x + maxRangeX; + const int32_t min_y = centerPos.y + minRangeY; + const int32_t min_x = centerPos.x + minRangeX; + const int32_t max_y = centerPos.y + maxRangeY; + const int32_t max_x = centerPos.x + maxRangeX; - const int_fast16_t minoffset = centerPos.getZ() - maxRangeZ; - const int_fast32_t x1 = std::min<int_fast32_t>(0xFFFF, std::max<int_fast32_t>(0, (min_x + minoffset))); - const int_fast32_t y1 = std::min<int_fast32_t>(0xFFFF, std::max<int_fast32_t>(0, (min_y + minoffset))); + const auto width = static_cast<uint32_t>(max_x - min_x); + const auto height = static_cast<uint32_t>(max_y - min_y); + const auto depth = static_cast<uint32_t>(maxRangeZ - minRangeZ); - const int_fast16_t maxoffset = centerPos.getZ() - minRangeZ; - const int_fast32_t x2 = std::min<int_fast32_t>(0xFFFF, std::max<int_fast32_t>(0, (max_x + maxoffset))); - const int_fast32_t y2 = std::min<int_fast32_t>(0xFFFF, std::max<int_fast32_t>(0, (max_y + maxoffset))); + const int32_t minoffset = centerPos.getZ() - maxRangeZ; + const int32_t x1 = std::min<int32_t>(0xFFFF, std::max<int32_t>(0, min_x + minoffset)); + const int32_t y1 = std::min<int32_t>(0xFFFF, std::max<int32_t>(0, min_y + minoffset)); - const uint_fast16_t startx1 = x1 - (x1 % FLOOR_SIZE); - const uint_fast16_t starty1 = y1 - (y1 % FLOOR_SIZE); - const uint_fast16_t endx2 = x2 - (x2 % FLOOR_SIZE); - const uint_fast16_t endy2 = y2 - (y2 % FLOOR_SIZE); + const int32_t maxoffset = centerPos.getZ() - minRangeZ; + const int32_t x2 = std::min<int32_t>(0xFFFF, std::max<int32_t>(0, max_x + maxoffset)); + const int32_t y2 = std::min<int32_t>(0xFFFF, std::max<int32_t>(0, max_y + maxoffset)); - const auto startLeaf = g_game().map.getQTNode(static_cast<uint16_t>(startx1), static_cast<uint16_t>(starty1)); - const QTreeLeafNode* leafS = startLeaf; - const QTreeLeafNode* leafE; + const int32_t startx1 = x1 - (x1 & SECTOR_MASK); + const int32_t starty1 = y1 - (y1 & SECTOR_MASK); + const int32_t endx2 = x2 - (x2 & SECTOR_MASK); + const int32_t endy2 = y2 - (y2 & SECTOR_MASK); SpectatorList spectators; spectators.reserve(std::max<uint8_t>(MAP_MAX_VIEW_PORT_X, MAP_MAX_VIEW_PORT_Y) * 2); - for (uint_fast16_t ny = starty1; ny <= endy2; ny += FLOOR_SIZE) { - leafE = leafS; - for (uint_fast16_t nx = startx1; nx <= endx2; nx += FLOOR_SIZE) { - if (leafE) { - const auto &node_list = (onlyPlayers ? leafE->player_list : leafE->creature_list); - for (const auto creature : node_list) { + const MapSector* startSector = g_game().map.getMapSector(startx1, starty1); + const MapSector* sectorS = startSector; + for (int32_t ny = starty1; ny <= endy2; ny += SECTOR_SIZE) { + const MapSector* sectorE = sectorS; + for (int32_t nx = startx1; nx <= endx2; nx += SECTOR_SIZE) { + if (sectorE) { + const auto &node_list = onlyPlayers ? sectorE->player_list : sectorE->creature_list; + for (const auto &creature : node_list) { const auto &cpos = creature->getPosition(); - if (minRangeZ > cpos.z || maxRangeZ < cpos.z) { - continue; + if (static_cast<uint32_t>(static_cast<int32_t>(cpos.z) - minRangeZ) <= depth) { + const int_fast16_t offsetZ = Position::getOffsetZ(centerPos, cpos); + if (static_cast<uint32_t>(cpos.x - offsetZ - min_x) <= width && static_cast<uint32_t>(cpos.y - offsetZ - min_y) <= height) { + spectators.emplace_back(creature); + } } - - const int_fast16_t offsetZ = Position::getOffsetZ(centerPos, cpos); - if ((min_y + offsetZ) > cpos.y || (max_y + offsetZ) < cpos.y || (min_x + offsetZ) > cpos.x || (max_x + offsetZ) < cpos.x) { - continue; - } - - spectators.emplace_back(creature); } - leafE = leafE->leafE; + sectorE = sectorE->sectorE; } else { - leafE = g_game().map.getQTNode(static_cast<uint16_t>(nx + FLOOR_SIZE), static_cast<uint16_t>(ny)); + sectorE = g_game().map.getMapSector(nx + SECTOR_SIZE, ny); } } - if (leafS) { - leafS = leafS->leafS; + if (sectorS) { + sectorS = sectorS->sectorS; } else { - leafS = g_game().map.getQTNode(static_cast<uint16_t>(startx1), static_cast<uint16_t>(ny + FLOOR_SIZE)); + sectorS = g_game().map.getMapSector(startx1, ny + SECTOR_SIZE); } } // It is necessary to create the cache even if no spectators is found, so that there is no future query. - auto &cache = cacheFound ? it->second : spectatorsCache.emplace(centerPos, SpectatorsCache { .minRangeX = minRangeX, .maxRangeX = maxRangeX, .minRangeY = minRangeY, .maxRangeY = maxRangeY }).first->second; + auto &cache = cacheFound ? it->second : spectatorsCache.emplace(centerPos, SpectatorsCache { .minRangeX = minRangeX, .maxRangeX = maxRangeX, .minRangeY = minRangeY, .maxRangeY = maxRangeY, .creatures = {}, .players = {} }).first->second; auto &creaturesCache = onlyPlayers ? cache.players : cache.creatures; auto &creatureList = (multifloor ? creaturesCache.multiFloor : creaturesCache.floor); if (creatureList) { diff --git a/src/map/utils/mapsector.cpp b/src/map/utils/mapsector.cpp new file mode 100644 index 00000000000..de036728b76 --- /dev/null +++ b/src/map/utils/mapsector.cpp @@ -0,0 +1,46 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2023 OpenTibiaBR <opentibiabr@outlook.com> + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#include "pch.hpp" + +#include "creatures/creature.hpp" +#include "mapsector.hpp" + +bool MapSector::newSector = false; + +void MapSector::addCreature(const std::shared_ptr<Creature> &c) { + creature_list.emplace_back(c); + if (c->getPlayer()) { + player_list.emplace_back(c); + } +} + +void MapSector::removeCreature(const std::shared_ptr<Creature> &c) { + auto iter = std::find(creature_list.begin(), creature_list.end(), c); + if (iter == creature_list.end()) { + g_logger().error("[{}]: Creature not found in creature_list!", __FUNCTION__); + return; + } + + assert(iter != creature_list.end()); + *iter = creature_list.back(); + creature_list.pop_back(); + + if (c->getPlayer()) { + iter = std::find(player_list.begin(), player_list.end(), c); + if (iter == player_list.end()) { + g_logger().error("[{}]: Player not found in player_list!", __FUNCTION__); + return; + } + + assert(iter != player_list.end()); + *iter = player_list.back(); + player_list.pop_back(); + } +} diff --git a/src/map/utils/mapsector.hpp b/src/map/utils/mapsector.hpp new file mode 100644 index 00000000000..7b95db7f78b --- /dev/null +++ b/src/map/utils/mapsector.hpp @@ -0,0 +1,92 @@ +/** + * Canary - A free and open-source MMORPG server emulator + * Copyright (©) 2019-2023 OpenTibiaBR <opentibiabr@outlook.com> + * Repository: https://github.com/opentibiabr/canary + * License: https://github.com/opentibiabr/canary/blob/main/LICENSE + * Contributors: https://github.com/opentibiabr/canary/graphs/contributors + * Website: https://docs.opentibiabr.com/ + */ + +#pragma once + +#include "map/map_const.hpp" + +class Creature; +class Tile; +struct BasicTile; + +struct Floor { + explicit Floor(uint8_t z) : + z(z) { } + + std::shared_ptr<Tile> getTile(uint16_t x, uint16_t y) const { + std::shared_lock sl(mutex); + return tiles[x & SECTOR_MASK][y & SECTOR_MASK].first; + } + + void setTile(uint16_t x, uint16_t y, std::shared_ptr<Tile> tile) { + tiles[x & SECTOR_MASK][y & SECTOR_MASK].first = tile; + } + + std::shared_ptr<BasicTile> getTileCache(uint16_t x, uint16_t y) const { + std::shared_lock sl(mutex); + return tiles[x & SECTOR_MASK][y & SECTOR_MASK].second; + } + + void setTileCache(uint16_t x, uint16_t y, const std::shared_ptr<BasicTile> &newTile) { + tiles[x & SECTOR_MASK][y & SECTOR_MASK].second = newTile; + } + + const auto &getTiles() const { + return tiles; + } + + uint8_t getZ() const { + return z; + } + + auto &getMutex() const { + return mutex; + } + +private: + std::pair<std::shared_ptr<Tile>, std::shared_ptr<BasicTile>> tiles[SECTOR_SIZE][SECTOR_SIZE] = {}; + mutable std::shared_mutex mutex; + uint8_t z { 0 }; +}; + +class MapSector { +public: + MapSector() = default; + + // non-copyable + MapSector(const MapSector &) = delete; + MapSector &operator=(const MapSector &) = delete; + + // non-moveable + MapSector(const MapSector &&) = delete; + MapSector &operator=(const MapSector &&) = delete; + + const std::unique_ptr<Floor> &createFloor(uint32_t z) { + return floors[z] ? floors[z] : (floors[z] = std::make_unique<Floor>(z)); + } + + const std::unique_ptr<Floor> &getFloor(uint8_t z) const { + return floors[z]; + } + + void addCreature(const std::shared_ptr<Creature> &c); + void removeCreature(const std::shared_ptr<Creature> &c); + +private: + static bool newSector; + MapSector* sectorS = nullptr; + MapSector* sectorE = nullptr; + std::vector<std::shared_ptr<Creature>> creature_list; + std::vector<std::shared_ptr<Creature>> player_list; + std::unique_ptr<Floor> floors[MAP_MAX_LAYERS] = {}; + uint32_t floorBits = 0; + + friend class Spectators; + friend class MapCache; +}; diff --git a/src/map/utils/qtreenode.cpp b/src/map/utils/qtreenode.cpp deleted file mode 100644 index 279bcabe3fa..00000000000 --- a/src/map/utils/qtreenode.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/** - * Canary - A free and open-source MMORPG server emulator - * Copyright (©) 2019-2023 OpenTibiaBR <opentibiabr@outlook.com> - * Repository: https://github.com/opentibiabr/canary - * License: https://github.com/opentibiabr/canary/blob/main/LICENSE - * Contributors: https://github.com/opentibiabr/canary/graphs/contributors - * Website: https://docs.opentibiabr.com/ - */ - -#include "pch.hpp" - -#include "creatures/creature.hpp" -#include "qtreenode.hpp" - -bool QTreeLeafNode::newLeaf = false; - -QTreeLeafNode* QTreeNode::getLeaf(uint32_t x, uint32_t y) { - if (leaf) { - return static_cast<QTreeLeafNode*>(this); - } - - const auto node = child[((x & 0x8000) >> 15) | ((y & 0x8000) >> 14)]; - return node ? node->getLeaf(x << 1, y << 1) : nullptr; -} - -QTreeLeafNode* QTreeNode::createLeaf(uint32_t x, uint32_t y, uint32_t level) { - if (isLeaf()) { - return static_cast<QTreeLeafNode*>(this); - } - - const uint32_t index = ((x & 0x8000) >> 15) | ((y & 0x8000) >> 14); - if (!child[index]) { - if (level != FLOOR_BITS) { - child[index] = new QTreeNode(); - } else { - child[index] = new QTreeLeafNode(); - QTreeLeafNode::newLeaf = true; - } - } - - return child[index]->createLeaf(x * 2, y * 2, level - 1); -} - -QTreeLeafNode* QTreeNode::getBestLeaf(uint32_t x, uint32_t y, uint32_t level) { - QTreeLeafNode::newLeaf = false; - auto tempLeaf = createLeaf(x, y, level); - - if (QTreeLeafNode::newLeaf) { - // update north - if (const auto northLeaf = getLeaf(x, y - FLOOR_SIZE)) { - northLeaf->leafS = tempLeaf; - } - - // update west leaf - if (const auto westLeaf = getLeaf(x - FLOOR_SIZE, y)) { - westLeaf->leafE = tempLeaf; - } - - // update south - if (const auto southLeaf = getLeaf(x, y + FLOOR_SIZE)) { - tempLeaf->leafS = southLeaf; - } - - // update east - if (const auto eastLeaf = getLeaf(x + FLOOR_SIZE, y)) { - tempLeaf->leafE = eastLeaf; - } - } - - return tempLeaf; -} - -void QTreeLeafNode::addCreature(const std::shared_ptr<Creature> &c) { - creature_list.push_back(c); - - if (c->getPlayer()) { - player_list.push_back(c); - } -} - -void QTreeLeafNode::removeCreature(std::shared_ptr<Creature> c) { - auto iter = std::find(creature_list.begin(), creature_list.end(), c); - if (iter == creature_list.end()) { - g_logger().error("[{}]: Creature not found in creature_list!", __FUNCTION__); - return; - } - - assert(iter != creature_list.end()); - *iter = creature_list.back(); - creature_list.pop_back(); - - if (c->getPlayer()) { - iter = std::find(player_list.begin(), player_list.end(), c); - if (iter == player_list.end()) { - g_logger().error("[{}]: Player not found in player_list!", __FUNCTION__); - return; - } - - assert(iter != player_list.end()); - *iter = player_list.back(); - player_list.pop_back(); - } -} diff --git a/src/map/utils/qtreenode.hpp b/src/map/utils/qtreenode.hpp deleted file mode 100644 index 83f052a6abf..00000000000 --- a/src/map/utils/qtreenode.hpp +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Canary - A free and open-source MMORPG server emulator - * Copyright (©) 2019-2023 OpenTibiaBR <opentibiabr@outlook.com> - * Repository: https://github.com/opentibiabr/canary - * License: https://github.com/opentibiabr/canary/blob/main/LICENSE - * Contributors: https://github.com/opentibiabr/canary/graphs/contributors - * Website: https://docs.opentibiabr.com/ - */ - -#pragma once - -#include "map/map_const.hpp" - -struct Floor; -class QTreeLeafNode; -class Creature; - -class QTreeNode { -public: - constexpr QTreeNode() = default; - - virtual ~QTreeNode() { } - - // non-copyable - QTreeNode(const QTreeNode &) = delete; - QTreeNode &operator=(const QTreeNode &) = delete; - - bool isLeaf() const { - return leaf; - } - - template <typename Leaf, typename Node> - static Leaf getLeafStatic(Node node, uint32_t x, uint32_t y) { - do { - node = node->child[((x & 0x8000) >> 15) | ((y & 0x8000) >> 14)]; - if (!node) { - return nullptr; - } - - x <<= 1; - y <<= 1; - } while (!node->leaf); - return static_cast<Leaf>(node); - } - - QTreeLeafNode* getLeaf(uint32_t x, uint32_t y); - QTreeLeafNode* getBestLeaf(uint32_t x, uint32_t y, uint32_t level); - - QTreeLeafNode* createLeaf(uint32_t x, uint32_t y, uint32_t level); - -protected: - QTreeNode* child[4] = {}; - bool leaf = false; -}; - -class QTreeLeafNode final : public QTreeNode { -public: - QTreeLeafNode() { - QTreeNode::leaf = true; - newLeaf = true; - } - - // non-copyable - QTreeLeafNode(const QTreeLeafNode &) = delete; - QTreeLeafNode &operator=(const QTreeLeafNode &) = delete; - - const std::unique_ptr<Floor> &createFloor(uint32_t z) { - return array[z] ? array[z] : (array[z] = std::make_unique<Floor>(z)); - } - - const std::unique_ptr<Floor> &getFloor(uint8_t z) const { - return array[z]; - } - - void addCreature(const std::shared_ptr<Creature> &c); - void removeCreature(std::shared_ptr<Creature> c); - -private: - static bool newLeaf; - QTreeLeafNode* leafS = nullptr; - QTreeLeafNode* leafE = nullptr; - - std::unique_ptr<Floor> array[MAP_MAX_LAYERS] = {}; - - std::vector<std::shared_ptr<Creature>> creature_list; - std::vector<std::shared_ptr<Creature>> player_list; - - friend class Map; - friend class MapCache; - friend class QTreeNode; - friend class Spectators; -}; diff --git a/src/server/network/connection/connection.cpp b/src/server/network/connection/connection.cpp index cc27eb0e9eb..1c575ff00d0 100644 --- a/src/server/network/connection/connection.cpp +++ b/src/server/network/connection/connection.cpp @@ -399,9 +399,9 @@ void Connection::handleTimeout(ConnectionWeak_ptr connectionWeak, const std::err if (auto connection = connectionWeak.lock()) { if (!error) { - g_logger().warn("Connection Timeout, IP: {}", convertIPToString(connection->getIP())); + g_logger().debug("Connection Timeout, IP: {}", convertIPToString(connection->getIP())); } else { - g_logger().warn("Connection Timeout or error: {}, IP: {}", error.message(), convertIPToString(connection->getIP())); + g_logger().debug("Connection Timeout or error: {}, IP: {}", error.message(), convertIPToString(connection->getIP())); } connection->close(FORCE_CLOSE); } diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 218fc857d3c..751da531273 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -27,6 +27,8 @@ #include "creatures/players/player.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" #include "creatures/players/grouping/familiars.hpp" #include "server/network/protocol/protocolgame.hpp" #include "game/scheduling/dispatcher.hpp" @@ -1090,6 +1092,9 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyt case 0x80: g_game().playerCloseTrade(player->getID()); break; + case 0x81: + parseFriendSystemAction(msg); + break; case 0x82: parseUseItem(msg); break; @@ -1271,6 +1276,9 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage msg, uint8_t recvbyt case 0xDE: parseEditVip(msg); break; + case 0xDF: + parseVipGroupActions(msg); + break; case 0xE1: parseBestiarysendRaces(); break; @@ -1967,11 +1975,43 @@ void ProtocolGame::parseRemoveVip(NetworkMessage &msg) { } void ProtocolGame::parseEditVip(NetworkMessage &msg) { + std::vector<uint8_t> vipGroupsId; uint32_t guid = msg.get<uint32_t>(); const std::string description = msg.getString(); uint32_t icon = std::min<uint32_t>(10, msg.get<uint32_t>()); // 10 is max icon in 9.63 bool notify = msg.getByte() != 0; - g_game().playerRequestEditVip(player->getID(), guid, description, icon, notify); + uint8_t groupsAmount = msg.getByte(); + for (uint8_t i = 0; i < groupsAmount; ++i) { + uint8_t groupId = msg.getByte(); + vipGroupsId.emplace_back(groupId); + } + g_game().playerRequestEditVip(player->getID(), guid, description, icon, notify, vipGroupsId); +} + +void ProtocolGame::parseVipGroupActions(NetworkMessage &msg) { + uint8_t action = msg.getByte(); + + switch (action) { + case 0x01: { + const std::string groupName = msg.getString(); + player->vip()->addGroup(groupName); + break; + } + case 0x02: { + const uint8_t groupId = msg.getByte(); + const std::string newGroupName = msg.getString(); + player->vip()->editGroup(groupId, newGroupName); + break; + } + case 0x03: { + const uint8_t groupId = msg.getByte(); + player->vip()->removeGroup(groupId); + break; + } + default: { + break; + } + } } void ProtocolGame::parseRotateItem(NetworkMessage &msg) { @@ -2051,6 +2091,14 @@ void ProtocolGame::sendItemInspection(uint16_t itemId, uint8_t itemCount, std::s writeToOutputBuffer(msg); } +void ProtocolGame::parseFriendSystemAction(NetworkMessage &msg) { + uint8_t state = msg.getByte(); + if (state == 0x0E) { + uint8_t titleId = msg.getByte(); + g_game().playerFriendSystemAction(player, state, titleId); + } +} + void ProtocolGame::parseCyclopediaCharacterInfo(NetworkMessage &msg) { if (oldProtocol) { return; @@ -2125,11 +2173,12 @@ void ProtocolGame::sendHighscores(const std::vector<HighscoreCharacter> &charact NetworkMessage msg; msg.addByte(0xB1); - msg.addByte(0x00); // No data available + msg.addByte(0x00); // All data available msg.addByte(1); // Worlds - msg.addString(g_configManager().getString(SERVER_NAME, __FUNCTION__), "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // First World - msg.addString(g_configManager().getString(SERVER_NAME, __FUNCTION__), "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // Selected World + auto serverName = g_configManager().getString(SERVER_NAME, __FUNCTION__); + msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // First World + msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // Selected World msg.addByte(0); // Game World Category: 0xFF(-1) - Selected World msg.addByte(0); // BattlEye World Type @@ -2144,12 +2193,12 @@ void ProtocolGame::sendHighscores(const std::vector<HighscoreCharacter> &charact uint32_t selectedVocation = 0xFFFFFFFF; const auto vocationsMap = g_vocations().getVocations(); for (const auto &it : vocationsMap) { - const Vocation &vocation = it.second; - if (vocation.getFromVocation() == static_cast<uint32_t>(vocation.getId())) { - msg.add<uint32_t>(vocation.getFromVocation()); // Vocation Id - msg.addString(vocation.getVocName(), "ProtocolGame::sendHighscores - vocation.getVocName()"); // Vocation Name + const auto &vocation = it.second; + if (vocation->getFromVocation() == static_cast<uint32_t>(vocation->getId())) { + msg.add<uint32_t>(vocation->getFromVocation()); // Vocation Id + msg.addString(vocation->getVocName(), "ProtocolGame::sendHighscores - vocation.getVocName()"); // Vocation Name ++vocations; - if (vocation.getFromVocation() == vocationId) { + if (vocation->getFromVocation() == vocationId) { selectedVocation = vocationId; } } @@ -2177,9 +2226,9 @@ void ProtocolGame::sendHighscores(const std::vector<HighscoreCharacter> &charact for (const HighscoreCharacter &character : characters) { msg.add<uint32_t>(character.rank); // Rank msg.addString(character.name, "ProtocolGame::sendHighscores - character.name"); // Character Name - msg.addString("", "ProtocolGame::sendHighscores - empty"); // Probably Character Title(not visible in window) + msg.addString(character.loyaltyTitle, "ProtocolGame::sendHighscores - character.loyaltyTitle"); // Character Loyalty Title msg.addByte(character.vocation); // Vocation Id - msg.addString(g_configManager().getString(SERVER_NAME, __FUNCTION__), "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // World + msg.addString(serverName, "ProtocolGame::sendHighscores - g_configManager().getString(SERVER_NAME)"); // World msg.add<uint16_t>(character.level); // Level msg.addByte((player->getGUID() == character.id)); // Player Indicator Boolean msg.add<uint64_t>(character.points); // Points @@ -2233,7 +2282,7 @@ void ProtocolGame::parseBestiarysendRaces() { for (uint8_t i = BESTY_RACE_FIRST; i <= BESTY_RACE_LAST; i++) { std::string BestClass = ""; uint16_t count = 0; - for (auto rit : mtype_list) { + for (const auto &rit : mtype_list) { const auto mtype = g_monsters().getMonsterType(rit.second); if (!mtype) { return; @@ -2309,7 +2358,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { std::vector<LootBlock> lootList = mtype->info.lootItems; newmsg.addByte(lootList.size()); - for (LootBlock loot : lootList) { + for (const LootBlock &loot : lootList) { int8_t difficult = g_iobestiary().calculateDifficult(loot.chance); bool shouldAddItem = false; @@ -2621,7 +2670,7 @@ void ProtocolGame::createLeaderTeamFinder(NetworkMessage &msg) { auto party = player->getParty(); if (teamAssemble->partyBool && party) { - for (std::shared_ptr<Player> member : party->getMembers()) { + for (const std::shared_ptr<Player> &member : party->getMembers()) { if (member && member->getGUID() != player->getGUID()) { teamAssemble->membersMap.insert({ member->getGUID(), 3 }); } @@ -2893,7 +2942,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { std::string raceName = msg.getString(); race = g_iobestiary().findRaceByName(raceName); - if (race.size() == 0) { + if (race.empty()) { g_logger().warn("[ProtocolGame::parseBestiarysendCreature] - " "Race was not found: {}, search: {}", raceName, search); @@ -2907,7 +2956,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { newmsg.add<uint16_t>(race.size()); std::map<uint16_t, uint32_t> creaturesKilled = g_iobestiary().getBestiaryKillCountByMonsterIDs(player, race); - for (auto it_ : race) { + for (const auto &it_ : race) { uint16_t raceid_ = it_.first; newmsg.add<uint16_t>(raceid_); @@ -3367,8 +3416,8 @@ void ProtocolGame::sendCyclopediaCharacterBaseInformation() { msg.add<uint16_t>(player->getLevel()); AddOutfit(msg, player->getDefaultOutfit(), false); - msg.addByte(0x00); // hide stamina - msg.addString("", "ProtocolGame::sendCyclopediaCharacterBaseInformation - empty"); // character title + msg.addByte(0x01); // Store summary & Character titles + msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterBaseInformation - player->title()->getCurrentTitleName()"); // character title writeToOutputBuffer(msg); } @@ -3384,16 +3433,17 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() { // 1: No data available at the moment. // 2: You are not allowed to see this character's data. // 3: You are not allowed to inspect this character. - msg.addByte(0x00); + msg.addByte(0x00); // 0x00 Here means 'no error' + msg.add<uint64_t>(player->getExperience()); msg.add<uint16_t>(player->getLevel()); msg.addByte(player->getLevelPercent()); msg.add<uint16_t>(player->getBaseXpGain()); // BaseXPGainRate msg.add<uint16_t>(player->getGrindingXpBoost()); // LowLevelBonus - msg.add<uint16_t>(player->getStoreXpBoost()); // XPBoost + msg.add<uint16_t>(player->getXpBoostPercent()); // XPBoost msg.add<uint16_t>(player->getStaminaXpBoost()); // StaminaMultiplier(100=x1.0) - msg.add<uint16_t>(player->getExpBoostStamina()); // xpBoostRemainingTime - msg.addByte(0x01); // canBuyXpBoost + msg.add<uint16_t>(player->getXpBoostTime()); // xpBoostRemainingTime + msg.addByte(player->getXpBoostTime() > 0 ? 0x00 : 0x01); // canBuyXpBoost msg.add<uint32_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max())); msg.add<uint32_t>(std::min<int32_t>(player->getMaxHealth(), std::numeric_limits<uint16_t>::max())); msg.add<uint32_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max())); @@ -3406,8 +3456,8 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() { msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000); msg.add<uint16_t>(player->getSpeed()); msg.add<uint16_t>(player->getBaseSpeed()); - msg.add<uint32_t>(player->getCapacity()); - msg.add<uint32_t>(player->getCapacity()); + msg.add<uint32_t>(player->getBonusCapacity()); + msg.add<uint32_t>(player->getBaseCapacity()); msg.add<uint32_t>(player->hasFlag(PlayerFlags_t::HasInfiniteCapacity) ? 1000000 : player->getFreeCapacity()); msg.addByte(8); msg.addByte(1); @@ -3611,10 +3661,17 @@ void ProtocolGame::sendCyclopediaCharacterRecentDeaths(uint16_t page, uint16_t p msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_RECENTDEATHS); msg.addByte(0x00); - msg.add<uint16_t>(page); + + uint16_t totalPages = static_cast<uint16_t>(std::ceil(static_cast<double>(entries.size()) / pages)); + uint16_t currentPage = std::min<uint16_t>(page, totalPages); + uint16_t firstObject = (currentPage - 1) * pages; + uint16_t finalObject = firstObject + pages; + + msg.add<uint16_t>(currentPage); + msg.add<uint16_t>(totalPages); msg.add<uint16_t>(pages); - msg.add<uint16_t>(entries.size()); - for (const RecentDeathEntry &entry : entries) { + for (uint16_t i = firstObject; i < finalObject; i++) { + RecentDeathEntry entry = entries[i]; msg.add<uint32_t>(entry.timestamp); msg.addString(entry.cause, "ProtocolGame::sendCyclopediaCharacterRecentDeaths - entry.cause"); } @@ -3630,10 +3687,17 @@ void ProtocolGame::sendCyclopediaCharacterRecentPvPKills(uint16_t page, uint16_t msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_RECENTPVPKILLS); msg.addByte(0x00); - msg.add<uint16_t>(page); + + uint16_t totalPages = static_cast<uint16_t>(std::ceil(static_cast<double>(entries.size()) / pages)); + uint16_t currentPage = std::min<uint16_t>(page, totalPages); + uint16_t firstObject = (currentPage - 1) * pages; + uint16_t finalObject = firstObject + pages; + + msg.add<uint16_t>(currentPage); + msg.add<uint16_t>(totalPages); msg.add<uint16_t>(pages); - msg.add<uint16_t>(entries.size()); - for (const RecentPvPKillEntry &entry : entries) { + for (uint16_t i = firstObject; i < finalObject; i++) { + RecentPvPKillEntry entry = entries[i]; msg.add<uint32_t>(entry.timestamp); msg.addString(entry.description, "ProtocolGame::sendCyclopediaCharacterRecentPvPKills - entry.description"); msg.addByte(entry.status); @@ -3670,7 +3734,7 @@ void ProtocolGame::sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, writeToOutputBuffer(msg); } -void ProtocolGame::sendCyclopediaCharacterItemSummary() { +void ProtocolGame::sendCyclopediaCharacterItemSummary(const ItemsTierCountList &inventoryItems, const ItemsTierCountList &storeInboxItems, const StashItemList &supplyStashItems, const ItemsTierCountList &depotBoxItems, const ItemsTierCountList &inboxItems) { if (!player || oldProtocol) { return; } @@ -3678,13 +3742,106 @@ void ProtocolGame::sendCyclopediaCharacterItemSummary() { NetworkMessage msg; msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_ITEMSUMMARY); - msg.addByte(0x00); + msg.addByte(0x00); // 0x00 Here means 'no error' - msg.add<uint16_t>(0); - msg.add<uint16_t>(0); - msg.add<uint16_t>(0); - msg.add<uint16_t>(0); - msg.add<uint16_t>(0); + uint16_t inventoryItemsCount = 0; + const auto startInventory = msg.getBufferPosition(); + msg.skipBytes(2); + + for (const auto &inventoryItems_it : inventoryItems) { + for (const auto &[itemTier, itemCount] : inventoryItems_it.second) { + const ItemType &it = Item::items[inventoryItems_it.first]; + msg.add<uint16_t>(inventoryItems_it.first); // Item ID + if (it.upgradeClassification > 0) { + msg.addByte(itemTier); + } + msg.add<uint32_t>(itemCount); + + ++inventoryItemsCount; + } + } + + const auto endInventory = msg.getBufferPosition(); + + msg.setBufferPosition(startInventory); + msg.add<uint16_t>(inventoryItemsCount); + + msg.setBufferPosition(endInventory); + + uint16_t storeInboxItemsCount = 0; + const auto startStoreInbox = msg.getBufferPosition(); + msg.skipBytes(2); + + for (const auto &storeInboxItems_it : storeInboxItems) { + for (const auto &[itemTier, itemCount] : storeInboxItems_it.second) { + const ItemType &it = Item::items[storeInboxItems_it.first]; + msg.add<uint16_t>(storeInboxItems_it.first); // Item ID + if (it.upgradeClassification > 0) { + msg.addByte(itemTier); + } + msg.add<uint32_t>(itemCount); + + ++storeInboxItemsCount; + } + } + + const auto endStoreInbox = msg.getBufferPosition(); + + msg.setBufferPosition(startStoreInbox); + msg.add<uint16_t>(storeInboxItemsCount); + + msg.setBufferPosition(endStoreInbox); + + msg.add<uint16_t>(supplyStashItems.size()); + + for (const auto &[itemId, itemCount] : supplyStashItems) { + msg.add<uint16_t>(itemId); + msg.add<uint32_t>(itemCount); + } + + uint16_t depotBoxItemsCount = 0; + const auto startDepotBox = msg.getBufferPosition(); + msg.skipBytes(2); + + for (const auto &depotBoxItems_it : depotBoxItems) { + for (const auto &[itemTier, itemCount] : depotBoxItems_it.second) { + const ItemType &it = Item::items[depotBoxItems_it.first]; + msg.add<uint16_t>(depotBoxItems_it.first); // Item ID + if (it.upgradeClassification > 0) { + msg.addByte(itemTier); + } + msg.add<uint32_t>(itemCount); + + ++depotBoxItemsCount; + } + } + + const auto endDepotBox = msg.getBufferPosition(); + + msg.setBufferPosition(startDepotBox); + msg.add<uint16_t>(depotBoxItemsCount); + + msg.setBufferPosition(endDepotBox); + + uint16_t inboxItemsCount = 0; + const auto startInbox = msg.getBufferPosition(); + msg.skipBytes(2); + + for (const auto &inboxItems_it : inboxItems) { + for (const auto &[itemTier, itemCount] : inboxItems_it.second) { + const ItemType &it = Item::items[inboxItems_it.first]; + msg.add<uint16_t>(inboxItems_it.first); // Item ID + if (it.upgradeClassification > 0) { + msg.addByte(itemTier); + } + msg.add<uint32_t>(itemCount); + + ++inboxItemsCount; + } + } + + msg.setBufferPosition(startInbox); + msg.add<uint16_t>(inboxItemsCount); writeToOutputBuffer(msg); } @@ -3767,14 +3924,14 @@ void ProtocolGame::sendCyclopediaCharacterOutfitsMounts() { auto startFamiliars = msg.getBufferPosition(); msg.skipBytes(2); const auto familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); - for (const Familiar &familiar : familiars) { - const std::string type = familiar.type; + for (const auto &familiar : familiars) { + const std::string type = familiar->type; if (!player->getFamiliar(familiar)) { continue; } ++familiarsSize; - msg.add<uint16_t>(familiar.lookType); - msg.addString(familiar.name, "ProtocolGame::sendCyclopediaCharacterOutfitsMounts - familiar.name"); + msg.add<uint16_t>(familiar->lookType); + msg.addString(familiar->name, "ProtocolGame::sendCyclopediaCharacterOutfitsMounts - familiar.name"); if (type == "quest") { msg.addByte(CYCLOPEDIA_CHARACTERINFO_OUTFITTYPE_QUEST); } else { @@ -3800,20 +3957,19 @@ void ProtocolGame::sendCyclopediaCharacterStoreSummary() { NetworkMessage msg; msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_STORESUMMARY); - msg.addByte(0x00); - // Remaining Store Xp Boost Time - msg.add<uint32_t>(player->getExpBoostStamina()); - // RemainingDailyRewardXpBoostTime - msg.add<uint32_t>(0); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); - msg.add<uint16_t>(0); + msg.addByte(0x00); // 0x00 Here means 'no error' + msg.add<uint32_t>(player->getXpBoostTime()); // Remaining Store Xp Boost Time + msg.add<uint32_t>(0); // RemainingDailyRewardXpBoostTime + + msg.addByte(0x00); // getBlessingsObtained + msg.addByte(0x00); // getTaskHuntingSlotById + msg.addByte(0x00); // getPreyCardsObtained + msg.addByte(0x00); // getRewardCollectionObtained + msg.addByte(0x00); // player->hasCharmExpansion() ? 0x01 : 0x00 + msg.addByte(0x00); // getHirelingsObtained + msg.addByte(0x00); // getHirelinsJobsObtained + msg.addByte(0x00); // getHirelinsOutfitsObtained + msg.add<uint16_t>(0); // getHouseItemsObtained writeToOutputBuffer(msg); } @@ -3837,7 +3993,24 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { msg.addByte(slot); msg.addString(inventoryItem->getName(), "ProtocolGame::sendCyclopediaCharacterInspection - inventoryItem->getName()"); AddItem(msg, inventoryItem); - msg.addByte(0); + + uint8_t itemImbuements = 0; + auto startImbuements = msg.getBufferPosition(); + msg.skipBytes(1); + for (uint8_t slotid = 0; slotid < inventoryItem->getImbuementSlot(); slotid++) { + ImbuementInfo imbuementInfo; + if (!inventoryItem->getImbuementInfo(slotid, &imbuementInfo)) { + continue; + } + + msg.add<uint16_t>(imbuementInfo.imbuement->getID()); + itemImbuements++; + } + + auto endImbuements = msg.getBufferPosition(); + msg.setBufferPosition(startImbuements); + msg.addByte(itemImbuements); + msg.setBufferPosition(endImbuements); auto descriptions = Item::getDescriptions(Item::items[inventoryItem->getID()], inventoryItem); msg.addByte(descriptions.size()); @@ -3865,8 +4038,15 @@ void ProtocolGame::sendCyclopediaCharacterInspection() { msg.addString("Vocation", "ProtocolGame::sendCyclopediaCharacterInspection - Vocation"); msg.addString(player->getVocation()->getVocName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getVocation()->getVocName()"); + // Player title + if (player->title()->getCurrentTitle() != 0) { + playerDescriptionSize++; + msg.addString("Title", "ProtocolGame::sendCyclopediaCharacterInspection - Title"); + msg.addString(player->title()->getCurrentTitleName(), "ProtocolGame::sendCyclopediaCharacterInspection - player->title()->getCurrentTitleName()"); + } + // Loyalty title - if (player->getLoyaltyTitle().length() != 0) { + if (!player->getLoyaltyTitle().empty()) { playerDescriptionSize++; msg.addString("Loyalty Title", "ProtocolGame::sendCyclopediaCharacterInspection - Loyalty Title"); msg.addString(player->getLoyaltyTitle(), "ProtocolGame::sendCyclopediaCharacterInspection - player->getLoyaltyTitle()"); @@ -3899,19 +4079,28 @@ void ProtocolGame::sendCyclopediaCharacterBadges() { msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_BADGES); msg.addByte(0x00); - // ShowAccountInformation - msg.addByte(0x01); - // if ShowAccountInformation show IsOnline, IsPremium, character title, badges - // IsOnline + msg.addByte(0x01); // ShowAccountInformation, if 0x01 will show IsOnline, IsPremium, character title, badges + const auto loggedPlayer = g_game().getPlayerUniqueLogin(player->getName()); - msg.addByte(loggedPlayer ? 0x01 : 0x00); - // IsPremium (GOD has always 'Premium') - msg.addByte(player->isPremium() ? 0x01 : 0x00); + msg.addByte(loggedPlayer ? 0x01 : 0x00); // IsOnline + msg.addByte(player->isPremium() ? 0x01 : 0x00); // IsPremium (GOD has always 'Premium') // Character loyalty title msg.addString(player->getLoyaltyTitle(), "ProtocolGame::sendCyclopediaCharacterBadges - player->getLoyaltyTitle()"); - // Enable badges - msg.addByte(0x00); - // Todo badges loop + + uint8_t badgesSize = 0; + auto badgesSizePosition = msg.getBufferPosition(); + msg.skipBytes(1); + for (const auto &badge : g_game().getBadges()) { + if (player->badge()->hasBadge(badge.m_id)) { + msg.add<uint32_t>(badge.m_id); + msg.addString(badge.m_name, "ProtocolGame::sendCyclopediaCharacterBadges - name"); + badgesSize++; + } + } + + msg.setBufferPosition(badgesSizePosition); + msg.addByte(badgesSize); + writeToOutputBuffer(msg); } @@ -3920,12 +4109,27 @@ void ProtocolGame::sendCyclopediaCharacterTitles() { return; } + auto titles = g_game().getTitles(); + NetworkMessage msg; msg.addByte(0xDA); msg.addByte(CYCLOPEDIA_CHARACTERINFO_TITLES); - msg.addByte(0x00); - msg.addByte(0x00); - msg.addByte(0x00); + msg.addByte(0x00); // 0x00 Here means 'no error' + msg.addByte(player->title()->getCurrentTitle()); + msg.addByte(static_cast<uint8_t>(titles.size())); + + std::string messageTitleName = "ProtocolGame::sendCyclopediaCharacterTitles - title.name"; + std::string messageTitleDesc = "ProtocolGame::sendCyclopediaCharacterTitles - title.description"; + for (const auto &title : titles) { + msg.addByte(title.m_id); + auto titleName = player->title()->getNameBySex(player->getSex(), title.m_maleName, title.m_femaleName); + msg.addString(titleName, messageTitleName); + msg.addString(title.m_description, messageTitleDesc); + msg.addByte(title.m_permanent ? 0x01 : 0x00); + auto isUnlocked = player->title()->isTitleUnlocked(title.m_id); + msg.addByte(isUnlocked ? 0x01 : 0x00); + } + writeToOutputBuffer(msg); } @@ -3982,7 +4186,7 @@ void ProtocolGame::sendBasicData() { // Send total size of spells msg.add<uint16_t>(validSpells.size()); // Send each spell valid ids - for (auto spell : validSpells) { + for (const auto &spell : validSpells) { if (!spell) { continue; } @@ -4088,11 +4292,11 @@ void ProtocolGame::sendTextMessage(const TextMessage &message) { break; } case MESSAGE_MARKET: { - internalType = MESSAGE_GAME_HIGHLIGHT; + internalType = MESSAGE_EVENT_ADVANCE; break; } case MESSAGE_MANA: { - internalType = MESSAGE_THANK_YOU; + internalType = MESSAGE_HEALED; break; } case MESSAGE_BEYOND_LAST: { @@ -4100,7 +4304,7 @@ void ProtocolGame::sendTextMessage(const TextMessage &message) { break; } case MESSAGE_ATTENTION: { - internalType = MESSAGE_DAMAGE_DEALT; + internalType = MESSAGE_EVENT_ADVANCE; break; } case MESSAGE_BOOSTED_CREATURE: { @@ -4143,11 +4347,9 @@ void ProtocolGame::sendTextMessage(const TextMessage &message) { } case MESSAGE_HEALED: case MESSAGE_HEALED_OTHERS: { - if (!oldProtocol) { - msg.addPosition(message.position); - msg.add<uint32_t>(message.primary.value); - msg.addByte(message.primary.color); - } + msg.addPosition(message.position); + msg.add<uint32_t>(message.primary.value); + msg.addByte(message.primary.color); break; } case MESSAGE_EXPERIENCE: @@ -4321,7 +4523,7 @@ void ProtocolGame::sendContainer(uint8_t cid, std::shared_ptr<Container> contain msg.addByte(0x00); } else if (container->getID() == ITEM_STORE_INBOX && !itemsStoreInboxToSend.empty()) { msg.addByte(std::min<uint32_t>(maxItemsToSend, containerSize)); - for (const auto item : itemsStoreInboxToSend) { + for (const auto &item : itemsStoreInboxToSend) { AddItem(msg, item); } } else { @@ -4449,7 +4651,7 @@ void ProtocolGame::sendShop(std::shared_ptr<Npc> npc) { msg.add<uint16_t>(itemsToSend); uint16_t i = 0; - for (ShopBlock shopBlock : shoplist) { + for (const ShopBlock &shopBlock : shoplist) { if (++i > itemsToSend) { break; } @@ -4532,7 +4734,7 @@ void ProtocolGame::sendSaleItemList(const std::vector<ShopBlock> &shopVector, co msg.addByte(0xEE); msg.addByte(0x00); msg.add<uint64_t>(player->getBankBalance()); - uint16_t currency = player->getShopOwner() ? player->getShopOwner()->getCurrency() : ITEM_GOLD_COIN; + uint16_t currency = player->getShopOwner() ? player->getShopOwner()->getCurrency() : static_cast<uint16_t>(ITEM_GOLD_COIN); msg.addByte(0xEE); if (currency == ITEM_GOLD_COIN) { msg.addByte(0x01); @@ -4557,7 +4759,7 @@ void ProtocolGame::sendSaleItemList(const std::vector<ShopBlock> &shopVector, co auto msgPosition = msg.getBufferPosition(); msg.skipBytes(1); - for (ShopBlock shopBlock : shopVector) { + for (const ShopBlock &shopBlock : shopVector) { if (shopBlock.itemSellPrice == 0) { continue; } @@ -5021,7 +5223,7 @@ void ProtocolGame::sendOpenForge() { getForgeInfoMap(item, receiveTierItemMap); } if (itemClassification == 4) { - getForgeInfoMap(item, convergenceItemsMap[item->getSlotPosition()]); + getForgeInfoMap(item, convergenceItemsMap[item->getClassification()]); } } } @@ -5550,7 +5752,12 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } if (!oldProtocol) { - msg.add<uint16_t>(0x00); // Augment + std::string augmentsDescription = it.parseAugmentDescription(true); + if (!augmentsDescription.empty()) { + msg.addString(augmentsDescription, "ProtocolGame::sendMarketDetail - augmentsDescription"); + } else { + msg.add<uint16_t>(0x00); // no augments + } } if (it.imbuementSlot > 0) { @@ -5589,7 +5796,7 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { if (it.abilities->perfectShotDamage > 0) { string.clear(); - string << std::showpos << it.abilities->perfectShotDamage << std::noshowpos << " at " << it.abilities->perfectShotRange << "%"; + string << std::showpos << it.abilities->perfectShotDamage << std::noshowpos << " at range " << unsigned(it.abilities->perfectShotRange); msg.addString(string.str(), "ProtocolGame::sendMarketDetail - string.str()"); } else { msg.add<uint16_t>(0x00); @@ -5632,35 +5839,47 @@ void ProtocolGame::sendMarketDetail(uint16_t itemId, uint8_t tier) { } } - auto purchase = IOMarket::getInstance().getPurchaseStatistics()[itemId][tier]; - if (const MarketStatistics* purchaseStatistics = &purchase; purchaseStatistics) { - msg.addByte(0x01); - msg.add<uint32_t>(purchaseStatistics->numTransactions); - if (oldProtocol) { - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics->totalPrice)); - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics->highestPrice)); - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics->lowestPrice)); - } else { - msg.add<uint64_t>(purchaseStatistics->totalPrice); - msg.add<uint64_t>(purchaseStatistics->highestPrice); - msg.add<uint64_t>(purchaseStatistics->lowestPrice); + const auto &purchaseStatsMap = IOMarket::getInstance().getPurchaseStatistics(); + auto purchaseIterator = purchaseStatsMap.find(itemId); + if (purchaseIterator != purchaseStatsMap.end()) { + const auto &tierStatsMap = purchaseIterator->second; + auto tierStatsIter = tierStatsMap.find(tier); + if (tierStatsIter != tierStatsMap.end()) { + const auto &purchaseStatistics = tierStatsIter->second; + msg.addByte(0x01); + msg.add<uint32_t>(purchaseStatistics.numTransactions); + if (oldProtocol) { + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics.totalPrice)); + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics.highestPrice)); + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), purchaseStatistics.lowestPrice)); + } else { + msg.add<uint64_t>(purchaseStatistics.totalPrice); + msg.add<uint64_t>(purchaseStatistics.highestPrice); + msg.add<uint64_t>(purchaseStatistics.lowestPrice); + } } } else { msg.addByte(0x00); // send to old protocol ? } - auto sale = IOMarket::getInstance().getSaleStatistics()[itemId][tier]; - if (const MarketStatistics* saleStatistics = &sale; saleStatistics) { - msg.addByte(0x01); - msg.add<uint32_t>(saleStatistics->numTransactions); - if (oldProtocol) { - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics->totalPrice)); - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics->highestPrice)); - msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics->lowestPrice)); - } else { - msg.add<uint64_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics->totalPrice)); - msg.add<uint64_t>(saleStatistics->highestPrice); - msg.add<uint64_t>(saleStatistics->lowestPrice); + const auto &saleStatsMap = IOMarket::getInstance().getSaleStatistics(); + auto saleIterator = saleStatsMap.find(itemId); + if (saleIterator != saleStatsMap.end()) { + const auto &tierStatsMap = saleIterator->second; + auto tierStatsIter = tierStatsMap.find(tier); + if (tierStatsIter != tierStatsMap.end()) { + const auto &saleStatistics = tierStatsIter->second; + msg.addByte(0x01); + msg.add<uint32_t>(saleStatistics.numTransactions); + if (oldProtocol) { + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics.totalPrice)); + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics.highestPrice)); + msg.add<uint32_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics.lowestPrice)); + } else { + msg.add<uint64_t>(std::min<uint64_t>(std::numeric_limits<uint32_t>::max(), saleStatistics.totalPrice)); + msg.add<uint64_t>(saleStatistics.highestPrice); + msg.add<uint64_t>(saleStatistics.lowestPrice); + } } } else { msg.addByte(0x00); // send to old protocol ? @@ -5687,7 +5906,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar std::shared_ptr<Container> container = listContainer.front(); listContainer.pop_front(); - for (std::shared_ptr<Item> containerItem : container->getItemList()) { + for (const std::shared_ptr<Item> &containerItem : container->getItemList()) { std::shared_ptr<Container> tmpContainer = containerItem->getContainer(); if (tmpContainer) { listContainer.push_back(tmpContainer); @@ -5697,7 +5916,7 @@ void ProtocolGame::sendTradeItemRequest(const std::string &traderName, std::shar } msg.addByte(itemList.size()); - for (std::shared_ptr<Item> listItem : itemList) { + for (const std::shared_ptr<Item> &listItem : itemList) { AddItem(msg, listItem); } } else { @@ -6351,6 +6570,8 @@ void ProtocolGame::sendAddCreature(std::shared_ptr<Creature> creature, const Pos // player light level sendCreatureLight(creature); + sendVIPGroups(); + const std::forward_list<VIPEntry> &vipEntries = IOLoginData::getVIPEntries(player->getAccountId()); if (player->isAccessPlayer()) { @@ -6359,9 +6580,9 @@ void ProtocolGame::sendAddCreature(std::shared_ptr<Creature> creature, const Pos std::shared_ptr<Player> vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer) { - vipStatus = VIPSTATUS_OFFLINE; + vipStatus = VipStatus_t::Offline; } else { - vipStatus = vipPlayer->statusVipList; + vipStatus = vipPlayer->vip()->getStatus(); } sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus); @@ -6372,9 +6593,9 @@ void ProtocolGame::sendAddCreature(std::shared_ptr<Creature> creature, const Pos std::shared_ptr<Player> vipPlayer = g_game().getPlayerByGUID(entry.guid); if (!vipPlayer || vipPlayer->isInGhostMode()) { - vipStatus = VIPSTATUS_OFFLINE; + vipStatus = VipStatus_t::Offline; } else { - vipStatus = vipPlayer->statusVipList; + vipStatus = vipPlayer->vip()->getStatus(); } sendVIP(entry.guid, entry.name, entry.description, entry.icon, entry.notify, vipStatus); @@ -6638,14 +6859,14 @@ void ProtocolGame::sendOutfitWindow() { } std::vector<std::shared_ptr<Mount>> mounts; - for (const auto mount : g_game().mounts.getMounts()) { + for (const auto &mount : g_game().mounts.getMounts()) { if (player->hasMount(mount)) { mounts.push_back(mount); } } msg.addByte(mounts.size()); - for (const auto mount : mounts) { + for (const auto &mount : mounts) { msg.add<uint16_t>(mount->clientId); msg.addString(mount->name, "ProtocolGame::sendOutfitWindow - mount->name"); } @@ -6707,17 +6928,21 @@ void ProtocolGame::sendOutfitWindow() { msg.addByte(0x00); ++outfitSize; } else if (outfit->lookType == 1210 || outfit->lookType == 1211) { - msg.add<uint16_t>(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); - msg.addByte(3); - msg.addByte(0x02); - ++outfitSize; + if (player->canWear(1210, 0) || player->canWear(1211, 0)) { + msg.add<uint16_t>(outfit->lookType); + msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addByte(3); + msg.addByte(0x02); + ++outfitSize; + } } else if (outfit->lookType == 1456 || outfit->lookType == 1457) { - msg.add<uint16_t>(outfit->lookType); - msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); - msg.addByte(3); - msg.addByte(0x03); - ++outfitSize; + if (player->canWear(1456, 0) || player->canWear(1457, 0)) { + msg.add<uint16_t>(outfit->lookType); + msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); + msg.addByte(3); + msg.addByte(0x03); + ++outfitSize; + } } else if (outfit->from == "store") { msg.add<uint16_t>(outfit->lookType); msg.addString(outfit->name, "ProtocolGame::sendOutfitWindow - outfit->name"); @@ -6743,7 +6968,7 @@ void ProtocolGame::sendOutfitWindow() { msg.skipBytes(2); const auto mounts = g_game().mounts.getMounts(); - for (const auto mount : mounts) { + for (const auto &mount : mounts) { if (player->hasMount(mount)) { msg.add<uint16_t>(mount->clientId); msg.addString(mount->name, "ProtocolGame::sendOutfitWindow - mount->name"); @@ -6774,13 +6999,13 @@ void ProtocolGame::sendOutfitWindow() { const auto familiars = Familiars::getInstance().getFamiliars(player->getVocationId()); - for (const Familiar &familiar : familiars) { + for (const auto &familiar : familiars) { if (!player->getFamiliar(familiar)) { continue; } - msg.add<uint16_t>(familiar.lookType); - msg.addString(familiar.name, "ProtocolGame::sendOutfitWindow - familiar.name"); + msg.add<uint16_t>(familiar->lookType); + msg.addString(familiar->name, "ProtocolGame::sendOutfitWindow - familiar.name"); msg.addByte(0x00); if (++familiarSize == limitFamiliars) { break; @@ -6863,7 +7088,7 @@ void ProtocolGame::sendPodiumWindow(std::shared_ptr<Item> podium, const Position msg.skipBytes(2); const auto mounts = g_game().mounts.getMounts(); - for (const auto mount : mounts) { + for (const auto &mount : mounts) { if (player->hasMount(mount)) { msg.add<uint16_t>(mount->clientId); msg.addString(mount->name, "ProtocolGame::sendPodiumWindow - mount->name"); @@ -6897,19 +7122,19 @@ void ProtocolGame::sendPodiumWindow(std::shared_ptr<Item> podium, const Position } void ProtocolGame::sendUpdatedVIPStatus(uint32_t guid, VipStatus_t newStatus) { - if (oldProtocol && newStatus == VIPSTATUS_TRAINING) { + if (oldProtocol && newStatus == VipStatus_t::Training) { return; } NetworkMessage msg; msg.addByte(0xD3); msg.add<uint32_t>(guid); - msg.addByte(newStatus); + msg.addByte(enumToValue(newStatus)); writeToOutputBuffer(msg); } void ProtocolGame::sendVIP(uint32_t guid, const std::string &name, const std::string &description, uint32_t icon, bool notify, VipStatus_t status) { - if (oldProtocol && status == VIPSTATUS_TRAINING) { + if (oldProtocol && status == VipStatus_t::Training) { return; } @@ -6920,10 +7145,37 @@ void ProtocolGame::sendVIP(uint32_t guid, const std::string &name, const std::st msg.addString(description, "ProtocolGame::sendVIP - description"); msg.add<uint32_t>(std::min<uint32_t>(10, icon)); msg.addByte(notify ? 0x01 : 0x00); - msg.addByte(status); + msg.addByte(enumToValue(status)); + + const auto &vipGuidGroups = player->vip()->getGroupsIdGuidBelongs(guid); + if (!oldProtocol) { - msg.addByte(0x00); // vipGroups + msg.addByte(vipGuidGroups.size()); // vipGroups + for (const auto &vipGroupID : vipGuidGroups) { + msg.addByte(vipGroupID); + } } + + writeToOutputBuffer(msg); +} + +void ProtocolGame::sendVIPGroups() { + if (oldProtocol) { + return; + } + + const auto &vipGroups = player->vip()->getGroups(); + + NetworkMessage msg; + msg.addByte(0xD4); + msg.addByte(vipGroups.size()); // vipGroups.size() + for (const auto &vipGroup : vipGroups) { + msg.addByte(vipGroup->id); + msg.addString(vipGroup->name, "ProtocolGame::sendVIP - vipGroup.name"); + msg.addByte(vipGroup->customizable ? 0x01 : 0x00); // 0x00 = not Customizable, 0x01 = Customizable + } + msg.addByte(player->vip()->getMaxGroupEntries() - vipGroups.size()); // max vip groups + writeToOutputBuffer(msg); } @@ -7256,7 +7508,7 @@ void ProtocolGame::AddCreature(NetworkMessage &msg, std::shared_ptr<Creature> cr } auto bubble = creature->getSpeechBubble(); - msg.addByte(oldProtocol && bubble == SPEECHBUBBLE_HIRELING ? SPEECHBUBBLE_NONE : bubble); + msg.addByte(oldProtocol && bubble == SPEECHBUBBLE_HIRELING ? static_cast<uint8_t>(SPEECHBUBBLE_NONE) : bubble); msg.addByte(0xFF); // MARK_UNMARKED if (!oldProtocol) { msg.addByte(0x00); // inspection type @@ -7299,7 +7551,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { } msg.add<uint16_t>(player->getGrindingXpBoost()); // low level bonus - msg.add<uint16_t>(player->getStoreXpBoost()); // xp boost + msg.add<uint16_t>(player->getXpBoostPercent()); // xp boost msg.add<uint16_t>(player->getStaminaXpBoost()); // stamina multiplier (100 = 1.0x) if (!oldProtocol) { @@ -7325,7 +7577,7 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000); - msg.add<uint16_t>(player->getExpBoostStamina()); // xp boost time (seconds) + msg.add<uint16_t>(player->getXpBoostTime()); // xp boost time (seconds) msg.addByte(1); // enables exp boost in the store if (!oldProtocol) { @@ -7539,7 +7791,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const std::shared_ptr<Party> party msg.addByte(static_cast<uint8_t>(party->priceType)); msg.addByte(static_cast<uint8_t>(party->membersData.size())); - for (const std::shared_ptr<PartyAnalyzer> analyzer : party->membersData) { + for (const std::shared_ptr<PartyAnalyzer> &analyzer : party->membersData) { msg.add<uint32_t>(analyzer->id); if (std::shared_ptr<Player> member = g_game().getPlayerByID(analyzer->id); !member || !member->getParty() || member->getParty() != party) { @@ -7558,7 +7810,7 @@ void ProtocolGame::updatePartyTrackerAnalyzer(const std::shared_ptr<Party> party msg.addByte(showNames ? 0x01 : 0x00); if (showNames) { msg.addByte(static_cast<uint8_t>(party->membersData.size())); - for (const std::shared_ptr<PartyAnalyzer> analyzer : party->membersData) { + for (const std::shared_ptr<PartyAnalyzer> &analyzer : party->membersData) { msg.add<uint32_t>(analyzer->id); msg.addString(analyzer->name, "ProtocolGame::updatePartyTrackerAnalyzer - analyzer->name"); } @@ -8397,7 +8649,7 @@ void ProtocolGame::parseSendBosstiarySlots() { std::string boostedBossName = g_ioBosstiary().getBoostedBossName(); const auto mTypeBoosted = g_monsters().getMonsterType(boostedBossName); auto boostedBossRace = mTypeBoosted ? mTypeBoosted->info.bosstiaryRace : BosstiaryRarity_t::BOSS_INVALID; - auto isValidBoostedBoss = boostedBossId == 0 || boostedBossRace >= BosstiaryRarity_t::RARITY_BANE && boostedBossRace <= BosstiaryRarity_t::RARITY_NEMESIS; + auto isValidBoostedBoss = boostedBossId == 0 || (boostedBossRace >= BosstiaryRarity_t::RARITY_BANE && boostedBossRace <= BosstiaryRarity_t::RARITY_NEMESIS); if (!isValidBoostedBoss) { g_logger().error("[{}] The boosted boss '{}' has an invalid race", __FUNCTION__, boostedBossName); return; @@ -8405,7 +8657,7 @@ void ProtocolGame::parseSendBosstiarySlots() { const auto mTypeSlotOne = g_ioBosstiary().getMonsterTypeByBossRaceId((uint16_t)bossIdSlotOne); auto bossRaceSlotOne = mTypeSlotOne ? mTypeSlotOne->info.bosstiaryRace : BosstiaryRarity_t::BOSS_INVALID; - auto isValidBossSlotOne = bossIdSlotOne == 0 || bossRaceSlotOne >= BosstiaryRarity_t::RARITY_BANE && bossRaceSlotOne <= BosstiaryRarity_t::RARITY_NEMESIS; + auto isValidBossSlotOne = bossIdSlotOne == 0 || (bossRaceSlotOne >= BosstiaryRarity_t::RARITY_BANE && bossRaceSlotOne <= BosstiaryRarity_t::RARITY_NEMESIS); if (!isValidBossSlotOne) { g_logger().error("[{}] boss slot1 with race id '{}' has an invalid race", __FUNCTION__, bossIdSlotOne); return; @@ -8413,7 +8665,7 @@ void ProtocolGame::parseSendBosstiarySlots() { const auto mTypeSlotTwo = g_ioBosstiary().getMonsterTypeByBossRaceId((uint16_t)bossIdSlotTwo); auto bossRaceSlotTwo = mTypeSlotTwo ? mTypeSlotTwo->info.bosstiaryRace : BosstiaryRarity_t::BOSS_INVALID; - auto isValidBossSlotTwo = bossIdSlotTwo == 0 || bossRaceSlotTwo >= BosstiaryRarity_t::RARITY_BANE && bossRaceSlotTwo <= BosstiaryRarity_t::RARITY_NEMESIS; + auto isValidBossSlotTwo = bossIdSlotTwo == 0 || (bossRaceSlotTwo >= BosstiaryRarity_t::RARITY_BANE && bossRaceSlotTwo <= BosstiaryRarity_t::RARITY_NEMESIS); if (!isValidBossSlotTwo) { g_logger().error("[{}] boss slot1 with race id '{}' has an invalid race", __FUNCTION__, bossIdSlotTwo); return; @@ -8768,7 +9020,7 @@ void ProtocolGame::parseSaveWheel(NetworkMessage &msg) { } void ProtocolGame::sendDisableLoginMusic() { - if (oldProtocol) { + if (oldProtocol || !player || player->getOperatingSystem() >= CLIENTOS_OTCLIENT_LINUX) { return; } diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 306bb873f25..0386093cfc4 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -13,9 +13,12 @@ #include "creatures/interactions/chat.hpp" #include "creatures/creature.hpp" #include "enums/forge_conversion.hpp" +#include "creatures/players/cyclopedia/player_badge.hpp" +#include "creatures/players/cyclopedia/player_title.hpp" class NetworkMessage; class Player; +class VIPGroup; class Game; class House; class Container; @@ -29,6 +32,8 @@ class TaskHuntingOption; struct ModalWindow; struct Achievement; +struct Badge; +struct Title; using ProtocolGame_ptr = std::shared_ptr<ProtocolGame>; @@ -126,6 +131,8 @@ class ProtocolGame final : public Protocol { void sendItemInspection(uint16_t itemId, uint8_t itemCount, std::shared_ptr<Item> item, bool cyclopedia); void parseInspectionObject(NetworkMessage &msg); + void parseFriendSystemAction(NetworkMessage &msg); + void parseCyclopediaCharacterInfo(NetworkMessage &msg); void parseHighscores(NetworkMessage &msg); @@ -207,6 +214,7 @@ class ProtocolGame final : public Protocol { void parseAddVip(NetworkMessage &msg); void parseRemoveVip(NetworkMessage &msg); void parseEditVip(NetworkMessage &msg); + void parseVipGroupActions(NetworkMessage &msg); void parseRotateItem(NetworkMessage &msg); void parseConfigureShowOffSocket(NetworkMessage &msg); @@ -313,7 +321,7 @@ class ProtocolGame final : public Protocol { void sendCyclopediaCharacterRecentDeaths(uint16_t page, uint16_t pages, const std::vector<RecentDeathEntry> &entries); void sendCyclopediaCharacterRecentPvPKills(uint16_t page, uint16_t pages, const std::vector<RecentPvPKillEntry> &entries); void sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, std::vector<std::pair<Achievement, uint32_t>> achievementsUnlocked); - void sendCyclopediaCharacterItemSummary(); + void sendCyclopediaCharacterItemSummary(const ItemsTierCountList &inventoryItems, const ItemsTierCountList &storeInboxItems, const StashItemList &supplyStashItems, const ItemsTierCountList &depotBoxItems, const ItemsTierCountList &inboxItems); void sendCyclopediaCharacterOutfitsMounts(); void sendCyclopediaCharacterStoreSummary(); void sendCyclopediaCharacterInspection(); @@ -354,6 +362,7 @@ class ProtocolGame final : public Protocol { void sendUpdatedVIPStatus(uint32_t guid, VipStatus_t newStatus); void sendVIP(uint32_t guid, const std::string &name, const std::string &description, uint32_t icon, bool notify, VipStatus_t status); + void sendVIPGroups(); void sendPendingStateEntered(); void sendEnterWorld(); @@ -471,6 +480,7 @@ class ProtocolGame final : public Protocol { friend class Player; friend class PlayerWheel; + friend class PlayerVIP; std::unordered_set<uint32_t> knownCreatureSet; std::shared_ptr<Player> player = nullptr; diff --git a/src/server/server_definitions.hpp b/src/server/server_definitions.hpp index ad816b76b02..1d5ed5b628e 100644 --- a/src/server/server_definitions.hpp +++ b/src/server/server_definitions.hpp @@ -113,13 +113,14 @@ enum Supply_Stash_Actions_t : uint8_t { }; struct HighscoreCharacter { - HighscoreCharacter(std::string name, uint64_t points, uint32_t id, uint32_t rank, uint16_t level, uint8_t vocation) : + HighscoreCharacter(std::string name, uint64_t points, uint32_t id, uint32_t rank, uint16_t level, uint8_t vocation, std::string loyaltyTitle) : name(std::move(name)), points(points), id(id), rank(rank), level(level), - vocation(vocation) { } + vocation(vocation), + loyaltyTitle(std::move(loyaltyTitle)) { } std::string name; uint64_t points; @@ -127,4 +128,5 @@ struct HighscoreCharacter { uint32_t rank; uint16_t level; uint8_t vocation; + std::string loyaltyTitle; }; diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index 1f12855fa0f..5d1dfce3e62 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -1561,6 +1561,21 @@ void capitalizeWords(std::string &source) { } } +void capitalizeWordsIgnoringString(std::string &source, const std::string stringToIgnore) { + toLowerCaseString(source); + auto size = static_cast<uint8_t>(source.size()); + auto indexFound = source.find(stringToIgnore); + + for (uint8_t i = 0; i < size; i++) { + if (indexFound != std::string::npos && indexFound > 0 && std::cmp_greater(i, static_cast<uint8_t>(indexFound - 1)) && i < (indexFound + stringToIgnore.size())) { + continue; + } + if (i == 0 || source[i - 1] == ' ' || source[i - 1] == '\'') { + source[i] = static_cast<char>(std::toupper(source[i])); + } + } +} + /** * @details * Prevents the console from closing so there is time to read the error information diff --git a/src/utils/tools.hpp b/src/utils/tools.hpp index 2f97e37a6c5..34c91c8c7a6 100644 --- a/src/utils/tools.hpp +++ b/src/utils/tools.hpp @@ -138,6 +138,7 @@ const char* getReturnMessage(ReturnValue value); void sleep_for(uint64_t ms); void capitalizeWords(std::string &source); +void capitalizeWordsIgnoringString(std::string &source, const std::string stringToIgnore); void consoleHandlerExit(); NameEval_t validateName(const std::string &name); diff --git a/vcproj/canary.vcxproj b/vcproj/canary.vcxproj index e31fdbad08a..4cb91d1cb94 100644 --- a/vcproj/canary.vcxproj +++ b/vcproj/canary.vcxproj @@ -45,6 +45,9 @@ <ClInclude Include="..\src\creatures\players\vocations\vocation.hpp" /> <ClInclude Include="..\src\creatures\players\wheel\wheel_gems.hpp" /> <ClInclude Include="..\src\creatures\players\achievement\player_achievement.hpp" /> + <ClInclude Include="..\src\creatures\players\cyclopedia\player_badge.hpp" /> + <ClInclude Include="..\src\creatures\players\cyclopedia\player_title.hpp" /> + <ClInclude Include="..\src\creatures\players\vip\player_vip.hpp" /> <ClInclude Include="..\src\creatures\players\wheel\player_wheel.hpp" /> <ClInclude Include="..\src\creatures\players\wheel\wheel_definitions.hpp" /> <ClInclude Include="..\src\database\database.hpp" /> @@ -201,7 +204,7 @@ <ClInclude Include="..\src\map\spectators.hpp" /> <ClInclude Include="..\src\map\town.hpp" /> <ClInclude Include="..\src\map\utils\astarnodes.hpp" /> - <ClInclude Include="..\src\map\utils\qtreenode.hpp" /> + <ClInclude Include="..\src\map\utils\mapsector.hpp" /> <ClInclude Include="..\src\security\rsa.hpp" /> <ClInclude Include="..\src\server\network\connection\connection.hpp" /> <ClInclude Include="..\src\server\network\message\networkmessage.hpp" /> @@ -257,6 +260,9 @@ <ClCompile Include="..\src\creatures\players\vocations\vocation.cpp" /> <ClCompile Include="..\src\creatures\players\wheel\wheel_gems.cpp" /> <ClCompile Include="..\src\creatures\players\achievement\player_achievement.cpp" /> + <ClCompile Include="..\src\creatures\players\cyclopedia\player_badge.cpp" /> + <ClCompile Include="..\src\creatures\players\cyclopedia\player_title.cpp" /> + <ClCompile Include="..\src\creatures\players\vip\player_vip.cpp" /> <ClCompile Include="..\src\creatures\players\wheel\player_wheel.cpp" /> <ClCompile Include="..\src\database\database.cpp" /> <ClCompile Include="..\src\database\databasemanager.cpp" /> @@ -384,7 +390,7 @@ <ClCompile Include="..\src\map\house\housetile.cpp" /> <ClCompile Include="..\src\map\spectators.cpp" /> <ClCompile Include="..\src\map\utils\astarnodes.cpp" /> - <ClCompile Include="..\src\map\utils\qtreenode.cpp" /> + <ClCompile Include="..\src\map\utils\mapsector.cpp" /> <ClCompile Include="..\src\map\map.cpp" /> <ClCompile Include="..\src\map\mapcache.cpp" /> <ClCompile Include="..\src\main.cpp" /> @@ -595,4 +601,5 @@ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> -</Project> \ No newline at end of file +</Project> +