Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions modules/game_cyclopedia/tab/bestiary/bestiary.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t> raceIds)
{
if (!canPerformGameAction())
return;

m_protocolGame->sendRequestBestiaryOverview(catName);
m_protocolGame->sendRequestBestiaryOverview(catName, search, raceIds);
}

void Game::requestBestiarySearch(const uint16_t raceId)
Expand Down
2 changes: 1 addition & 1 deletion src/client/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t> 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);
Expand Down
2 changes: 1 addition & 1 deletion src/client/protocolgame.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t> 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);
Expand Down
13 changes: 10 additions & 3 deletions src/client/protocolgamesend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t> raceIds)
{
const auto& msg = std::make_shared<OutputMessage>();
msg->addU8(Proto::ClientBestiaryRequestOverview);
msg->addU8(0x00);
msg->addString(catName);
msg->addU8(search ? 0x01 : 0x00);
if (search) {
msg->addU16(static_cast<uint16_t>(raceIds.size()));
for (const uint16_t raceId : raceIds) {
msg->addU16(raceId);
}
} else {
msg->addString(catName);
}
send(msg);
}

Expand Down
Loading