From 9541e039ff97ef23c658bd8f786dae78b495ee82 Mon Sep 17 00:00:00 2001 From: Marcos <66353315+marcosvf132@users.noreply.github.com> Date: Wed, 26 Aug 2020 07:11:29 -0300 Subject: [PATCH] Feat: Bestiary Tracker (#1688) --- data/creaturescripts/scripts/others/login.lua | 3 + data/modules/modules.xml | 1 + data/modules/scripts/bestiary/assets.lua | 6 +- data/modules/scripts/bestiary/bestiary.lua | 59 ++++++++++++++++++- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/data/creaturescripts/scripts/others/login.lua b/data/creaturescripts/scripts/others/login.lua index 35615ba470..08ae15bc8e 100644 --- a/data/creaturescripts/scripts/others/login.lua +++ b/data/creaturescripts/scripts/others/login.lua @@ -52,6 +52,9 @@ function onLogin(player) -- Boosted creature player:sendTextMessage(MESSAGE_LOOT, "Today's boosted creature: " .. BoostedCreature.name .. " \ Boosted creatures yield more experience points, carry more loot than usual and respawn at a faster rate.") + + -- Bestiary tracker + player:refreshBestiaryTracker() -- Stamina nextUseStaminaTime[playerId] = 1 diff --git a/data/modules/modules.xml b/data/modules/modules.xml index 594a3cb48b..1d6e2f0c3b 100644 --- a/data/modules/modules.xml +++ b/data/modules/modules.xml @@ -1,6 +1,7 @@ + diff --git a/data/modules/scripts/bestiary/assets.lua b/data/modules/scripts/bestiary/assets.lua index 66831dd9b8..bd71219755 100644 --- a/data/modules/scripts/bestiary/assets.lua +++ b/data/modules/scripts/bestiary/assets.lua @@ -7673,7 +7673,7 @@ Bestiary.MonstersName = { ["Orc Warlord"] = 2, ["Orc Rider"] = 4, ["Orc"] = 5, - ["Orc Shamn"] = 6, + ["Orc Shaman"] = 6, ["Orc Warrior"] = 7, ["Orc Berserker"] = 8, ["Troll"] = 15, @@ -7706,7 +7706,7 @@ Bestiary.MonstersName = { ["Grynch Clan Goblin"] = 393, ["Goblin Assassin"] = 463, ["Goblin Scarvenger"] = 464, - ["Furous Troll"] = 540, + ["Furious Troll"] = 540, ["Troll Legionnaire"] = 541, ["Orc Marauder"] = 614, ["Firestarter"] = 737, @@ -7771,7 +7771,7 @@ Bestiary.MonstersName = { ["Medusa"] = 570, ["Midnight Panther"] = 698, ["Thornfire Wolf"] = 739, - ["Crystalwolf"] = 740, + ["Crystal Wolf"] = 740, ["Crystalcrusher"] = 869, ["Armadille"] = 880, ["Dragonling"] = 894, diff --git a/data/modules/scripts/bestiary/bestiary.lua b/data/modules/scripts/bestiary/bestiary.lua index bcf1dd48c2..29cd065bb2 100644 --- a/data/modules/scripts/bestiary/bestiary.lua +++ b/data/modules/scripts/bestiary/bestiary.lua @@ -1,5 +1,6 @@ Bestiary = {} +BestiaryTracker = {} Bestiary.Credits = { Developer = "fernando mieza (flyckks), gpedro, lbaah, Ticardo (Rick), DudZ, Ruiivo", @@ -27,14 +28,16 @@ Bestiary.S_Packets = { SendBestiaryOverview = 0xd6, SendBestiaryMonsterData = 0xd7, SendBestiaryCharmsData = 0xd8, - SendBestiaryTracker = 0xd9 + SendBestiaryTracker = 0xd9, + SendBestiaryTrackerTab = 0xB9 } Bestiary.C_Packets = { RequestBestiaryData = 0xe1, RequestBestiaryOverview = 0xe2, RequestBestiaryMonsterData = 0xe3, - RequestBestiaryCharmUnlock = 0xe4 + RequestBestiaryCharmUnlock = 0xe4, + RequestBestiaryTracker = 0x2a } Bestiary.findRaceByName = function(race) @@ -413,6 +416,9 @@ function onRecvbyte(player, msg, byte) elseif (byte == Bestiary.C_Packets.RequestBestiaryCharmUnlock) then Bestiary.sendBuyCharmRune(player, msg) Bestiary.sendCharms(player) + elseif (byte == Bestiary.C_Packets.RequestBestiaryTracker) then + local racetrackerid = msg:getU16() + player:addBestiaryTracker(racetrackerid) end end @@ -546,6 +552,28 @@ function Player.setCharmRuneSlotExpansion(self, onOff) self:setStorageValue(Bestiary.Storage.PLAYER_CHARM_SLOT_EXPANSION, onOff and 1 or 0) end +function Player.refreshBestiaryTracker(self) + if not(BestiaryTracker[self:getId()]) then + return + end + local msg = NetworkMessage() + msg:addByte(Bestiary.S_Packets.SendBestiaryTrackerTab) + msg:addByte(#BestiaryTracker[self:getId()]) -- capacity + for index, value in pairs(BestiaryTracker[self:getId()]) do + msg:addU16(value) -- race + msg:addU32(self:getBestiaryKillCount(value)) -- total + msg:addU16(Bestiary.Monsters[value].FirstUnlock) -- stage one + msg:addU16(Bestiary.Monsters[value].SecondUnlock) -- stage two + msg:addU16(Bestiary.Monsters[value].toKill) -- stage three + if Bestiary.GetKillStatus(Bestiary.Monsters[value], self:getBestiaryKillCount(value)) == 4 then + msg:addByte(4) -- is complete + else + msg:addByte(0) -- not complete + end + end + msg:sendToPlayer(self) +end + function Player.addBestiaryKill(self, monsterID) --MonsterID can be Name if type(monsterID) == "string" then monsterID = Bestiary.MonstersName[monsterID] @@ -574,7 +602,34 @@ function Player.addBestiaryKill(self, monsterID) --MonsterID can be Name self:sendTextMessage(MESSAGE_STATUS_DEFAULT, 'You unlocked details for the creature "' .. monster.name .. '"') self:addCharmPoints(monster.CharmsPoints) self:sendBestiaryEntryChanged(monsterID) + end + local trackedBestiary = BestiaryTracker[self:getId()] + if trackedBestiary then + for i = 1, #trackedBestiary do + local trackers = trackedBestiary[i] + if trackers and trackers == monsterID then + self:refreshBestiaryTracker() + end + end + end +end + +function Player.addBestiaryTracker(self, raceid) + local trackedBestiary = BestiaryTracker[self:getId()] + if trackedBestiary then + for i = 1, #trackedBestiary do + local trackers = trackedBestiary[i] + if trackers and trackers == raceid then + table.remove(BestiaryTracker[self:getId()], i) + self:refreshBestiaryTracker() + return + end + end + else + BestiaryTracker[self:getId()] = {} end + table.insert(BestiaryTracker[self:getId()], raceid) + self:refreshBestiaryTracker() end function Player.getCharmFromTarget(self, target)