Skip to content
This repository has been archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Feat: Bestiary Tracker (#1688)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcosvf132 authored Aug 26, 2020
1 parent 89542f8 commit 9541e03
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 5 deletions.
3 changes: 3 additions & 0 deletions data/creaturescripts/scripts/others/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions data/modules/modules.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<modules>
<!-- Bestiary -->
<module type="recvbyte" byte="42" script="bestiary/bestiary.lua"/> <!-- Tracker -->
<module type="recvbyte" byte="225" script="bestiary/bestiary.lua" />
<module type="recvbyte" byte="226" script="bestiary/bestiary.lua" />
<module type="recvbyte" byte="227" script="bestiary/bestiary.lua" />
Expand Down
6 changes: 3 additions & 3 deletions data/modules/scripts/bestiary/assets.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
59 changes: 57 additions & 2 deletions data/modules/scripts/bestiary/bestiary.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

Bestiary = {}
BestiaryTracker = {}

Bestiary.Credits = {
Developer = "fernando mieza (flyckks), gpedro, lbaah, Ticardo (Rick), DudZ, Ruiivo",
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9541e03

Please sign in to comment.