Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Charms #4614

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Charms #4614

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
2 changes: 1 addition & 1 deletion data/events/events.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@

<!-- Monster methods -->
<event class="Monster" method="onDropLoot" enabled="1" />
<event class="Monster" method="onSpawn" enabled="0" />
<event class="Monster" method="onSpawn" enabled="1" />
</events>
53 changes: 53 additions & 0 deletions data/lib/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,11 @@ function Player.addBestiaryKills(self, raceId)
break
end
end

if kills < bestiaryInfo.mastery and newKills >= bestiaryInfo.mastery then
self:addCharmPoints(bestiaryInfo.charmPoints)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be added to unlockCharm (and removeCharm) instead?


return self:setBestiaryKills(raceId, newKills)
end

Expand Down Expand Up @@ -737,3 +742,51 @@ function Player.disableLoginMusic(self)
msg:delete()
return true
end

local charmStatus = {
UNLOCKED = 1,
LOCKED = 0,
}

function Player.isCharmUnlocked(self, charmId)
if (self:getStorageValue(PlayerStorageKeys.charmsUnlocked + charmId) or 0) == charmStatus.UNLOCKED then
return charmStatus.UNLOCKED
end
return charmStatus.LOCKED
end
Comment on lines +751 to +756
Copy link
Member

@ranisalt ranisalt Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would

Suggested change
function Player.isCharmUnlocked(self, charmId)
if (self:getStorageValue(PlayerStorageKeys.charmsUnlocked + charmId) or 0) == charmStatus.UNLOCKED then
return charmStatus.UNLOCKED
end
return charmStatus.LOCKED
end
function Player.isCharmUnlocked(self, charmId)
return self:getStorageValue(PlayerStorageKeys.charmsUnlocked + charmId) or charmStatus.LOCKED
end

work?


function Player.addCharmPoints(self, value)
local points = self:getCharmPoints() or 0
return self:setStorageValue(PlayerStorageKeys.charmPoints, points + value)
end

function Player.removeCharmPoints(self, value)
local points = self:getCharmPoints() or 0

if points < value then
return false
end
return self:setStorageValue(PlayerStorageKeys.charmPoints, points - value)
end

function Player.unlockCharm(self, charmId)
self:setStorageValue(PlayerStorageKeys.charmsUnlocked + charmId, charmStatus.UNLOCKED)
end

function Player.removeCharm(self, charmId)
self:setStorageValue(PlayerStorageKeys.charmsUnlocked + charmId, charmStatus.LOCKED)
end

function Player.setCharmMonster(self, charmId, raceId)
if self:isCharmUnlocked(charmId) == charmStatus.LOCKED then
return false
end
return self:setStorageValue(PlayerStorageKeys.charmsMonster + charmId, raceId)
end

function Player.getCharmPoints(self)
return math.max(0, self:getStorageValue(PlayerStorageKeys.charmPoints) or 0)
end
function Player.getCharmMonster(self, charmId)
return math.max(0, self:getStorageValue(PlayerStorageKeys.charmsMonster + charmId) or 0)
end
5 changes: 4 additions & 1 deletion data/lib/core/storages.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ PlayerStorageKeys = {
achievementsCounter = 20000,
achievementsBase = 300000,

-- Bestiary:
-- Bestiary: 400000 - 410101
bestiaryKillsBase = 400000,
charmPoints = 410000,
charmsMonster = 410001,
charmsUnlocked = 410101,
}
5 changes: 5 additions & 0 deletions data/scripts/network/bestiary_classes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ end
local handler = PacketHandler(0xE1)

function handler.onReceive(player)
sendCharmData(player)
player:sendResourceBalance(RESOURCE_BANK_BALANCE, player:getBankBalance())
player:sendResourceBalance(RESOURCE_GOLD_EQUIPPED, player:getMoney())
player:sendResourceBalance(RESOURCE_CHARM_POINTS, player:getCharmPoints())

local bestiaryClasses = Game.getBestiary()
local msg = NetworkMessage()
msg:addByte(0xD5)
Expand Down
Loading
Loading