diff --git a/modules/game_cyclopedia/tab/bestiary/bestiary.lua b/modules/game_cyclopedia/tab/bestiary/bestiary.lua index 7c18a6321c..6b8c821ca9 100644 --- a/modules/game_cyclopedia/tab/bestiary/bestiary.lua +++ b/modules/game_cyclopedia/tab/bestiary/bestiary.lua @@ -14,8 +14,13 @@ Cyclopedia.storedBosstiaryTrackerData = Cyclopedia.storedBosstiaryTrackerData or local animusMasteryPoints = 0 function Cyclopedia.loadBestiaryOverview(name, creatures, animusMasteryPoints) - if name == "Result" then + if (name == "Result" or name == "") and #creatures > 0 then + if #creatures == 1 then + g_game.requestBestiarySearch(creatures[1].id) + Cyclopedia.ShowBestiaryCreature() + else Cyclopedia.loadBestiarySearchCreatures(creatures) + end else Cyclopedia.loadBestiaryCreatures(creatures) end @@ -45,6 +50,14 @@ function showBestiary() -- This ensures Track Kills status is properly loaded from cache Cyclopedia.initializeTrackerData() Cyclopedia.ensureStoredRaceIDsPopulated() + + -- Bind Enter key to search when SearchEdit is focused + g_keyboard.bindKeyDown('Enter', function() + if UI and UI:isVisible() and UI.SearchEdit:getText() ~= "" then + Cyclopedia.BestiarySearch() + end + end, UI.SearchEdit) + g_game.requestBestiary() end @@ -306,7 +319,7 @@ function Cyclopedia.ShowBestiaryCreatures(Category) UI.ListBase.CategoryList:setVisible(false) UI.ListBase.CreatureInfo:setVisible(false) UI.ListBase.CreatureList:setVisible(true) - g_game.requestBestiaryOverview(Category) + g_game.requestBestiaryOverview(Category, false, {}) end function Cyclopedia.CreateBestiaryCategoryItem(Data) @@ -347,16 +360,15 @@ function Cyclopedia.loadBestiarySearchCreatures(data) local page = 1 Cyclopedia.Bestiary.Search[page] = {} - for i = 0, #data do - if i % maxCategoriesPerPage == 0 and i > 0 then + for i = 1, #data do + if (i - 1) % maxCategoriesPerPage == 0 and i > 1 then page = page + 1 Cyclopedia.Bestiary.Search[page] = {} end local creature = { id = data[i].id, currentLevel = data[i].currentLevel, - AnimusMasteryBonus = data[i].AnimusMasteryBonus, - + AnimusMasteryBonus = data[i].creatureAnimusMasteryBonus or 0, } table.insert(Cyclopedia.Bestiary.Search[page], creature) @@ -408,10 +420,12 @@ end function Cyclopedia.BestiarySearch() local text = UI.SearchEdit:getText() local raceList = g_things.getRacesByName(text) - if #raceList > 0 then - g_game.requestBestiarySearch(raceList[1].raceId) + local list = {} + for _, race in pairs(raceList) do + list[#list + 1] = race.raceId end + g_game.requestBestiaryOverview("Result", true, list) UI.SearchEdit:setText("") end diff --git a/src/client/game.cpp b/src/client/game.cpp index d16ad1f478..94a8ca88d7 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1942,12 +1942,12 @@ void Game::requestBestiary() m_protocolGame->sendRequestBestiary(); } -void Game::requestBestiaryOverview(const std::string_view catName) +void Game::requestBestiaryOverview(const std::string_view catName, bool search, std::vector raceIds) { if (!canPerformGameAction()) return; - m_protocolGame->sendRequestBestiaryOverview(catName); + m_protocolGame->sendRequestBestiaryOverview(catName, search, raceIds); } void Game::requestBestiarySearch(const uint16_t raceId) diff --git a/src/client/game.h b/src/client/game.h index 6881bcda14..ff765bf0b9 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -411,7 +411,7 @@ class Game void inspectionNormalObject(const Position& position); void inspectionObject(Otc::InspectObjectTypes inspectionType, uint16_t itemId, uint8_t itemCount); void requestBestiary(); - void requestBestiaryOverview(std::string_view catName); + void requestBestiaryOverview(std::string_view catName, bool search = false, std::vector raceIds = {}); void requestBestiarySearch(uint16_t raceId); void requestSendBuyCharmRune(uint8_t runeId, uint8_t action, uint16_t raceId); void requestSendCharacterInfo(uint32_t playerId, Otc::CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage = 0, uint16_t page = 0); diff --git a/src/client/protocolgame.h b/src/client/protocolgame.h index e8034cf5fc..e04bcc100e 100644 --- a/src/client/protocolgame.h +++ b/src/client/protocolgame.h @@ -147,7 +147,7 @@ class ProtocolGame final : public Protocol void sendHighscoreInfo(uint8_t action, uint8_t category, uint32_t vocation, std::string_view world, uint8_t worldType, uint8_t battlEye, uint16_t page, uint8_t totalPages); void sendImbuementDurations(bool isOpen = false); void sendRequestBestiary(); - void sendRequestBestiaryOverview(std::string_view catName); + void sendRequestBestiaryOverview(std::string_view catName, bool search = false, std::vector raceIds = {}); void sendRequestBestiarySearch(uint16_t raceId); void sendBuyCharmRune(uint8_t runeId, uint8_t action, uint16_t raceId); void sendCyclopediaRequestCharacterInfo(uint32_t playerId, Otc::CyclopediaCharacterInfoType_t characterInfoType, uint16_t entriesPerPage, uint16_t page); diff --git a/src/client/protocolgamesend.cpp b/src/client/protocolgamesend.cpp index f48a0f2dcc..b222b68cf4 100644 --- a/src/client/protocolgamesend.cpp +++ b/src/client/protocolgamesend.cpp @@ -1057,12 +1057,19 @@ void ProtocolGame::sendRequestBestiary() send(msg); } -void ProtocolGame::sendRequestBestiaryOverview(const std::string_view catName) +void ProtocolGame::sendRequestBestiaryOverview(const std::string_view catName, bool search, std::vector raceIds) { const auto& msg = std::make_shared(); msg->addU8(Proto::ClientBestiaryRequestOverview); - msg->addU8(0x00); - msg->addString(catName); + msg->addU8(search ? 0x01 : 0x00); + if (search) { + msg->addU16(static_cast(raceIds.size())); + for (const uint16_t raceId : raceIds) { + msg->addU16(raceId); + } + } else { + msg->addString(catName); + } send(msg); }