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

bugfix and optimizations: kill tracking #3861

Merged
merged 1 commit into from
Dec 18, 2021
Merged
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
77 changes: 39 additions & 38 deletions data/lib/core/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -313,43 +313,44 @@ function Player.getWeaponType(self)
return WEAPON_NONE
end

local function prepareUpdateKillTrackerMsg(monster, corpse)
monsterType = monster:getType()
if monsterType then
return nil
end
local networkMessage = NetworkMessage()
networkMessage:addByte(0xD1)
networkMessage:addString(monster:getName())
networkMessage:addU16(monsterType:getOutfit().lookType or 19)
networkMessage:addByte(monsterType:getOutfit().lookHead)
networkMessage:addByte(monsterType:getOutfit().lookBody)
networkMessage:addByte(monsterType:getOutfit().lookLegs)
networkMessage:addByte(monsterType:getOutfit().lookFeet)
networkMessage:addByte(monsterType:getOutfit().lookAddons)
networkMessage:addByte(corpse:getSize())
for a = corpse:getSize() - 1, 0, -1 do
local item = corpse:getItem(a)
networkMessage:addItem(item)
end
return networkMessage
end

function Player.updateKillTracker(self, monster, corpse)
monsterType = monster.getType()
msg = prepareUpdateKillTrackerMsg(monster, corpse)
if self:getParty() and msg then
msg:sendToPlayer(self:getParty():getLeader())
local membersList = self:getParty():getMembers()
for i = 1, #membersList do
local player = membersList[i]
if player then
msg:sendToPlayer(player)
end
end
msg:delete()
elseif msg then
msg:sendToPlayer(self)
msg:delete()
end
local monsterType = monster:getType()
if not monsterType then
return false
end

local monsterOutfit = monsterType:getOutfit()

local networkMessage = NetworkMessage()
Copy link
Contributor

Choose a reason for hiding this comment

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

we could just use msg, as is done in sources

Copy link
Member Author

@Znote Znote Dec 18, 2021

Choose a reason for hiding this comment

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

Yeah, but msg is ambiguous and could just mean a regular string/text.
Since this is a NetworkMessage with its metamethods, why not call it so? This makes it easier to understand what is going on for players who use this code as reference material to learn how to use NetworkMessage.

networkMessage:addByte(0xD1)
networkMessage:addString(monster:getName())
networkMessage:addU16(monsterOutfit.lookType or 19)
networkMessage:addByte(monsterOutfit.lookHead)
networkMessage:addByte(monsterOutfit.lookBody)
networkMessage:addByte(monsterOutfit.lookLegs)
networkMessage:addByte(monsterOutfit.lookFeet)
networkMessage:addByte(monsterOutfit.lookAddons)
networkMessage:addByte(corpse:getSize())

for i = corpse:getSize() - 1, 0, -1 do
local item = corpse:getItem(i)
networkMessage:addItem(item)
end

if self:getParty() then
networkMessage:sendToPlayer(self:getParty():getLeader())
local membersList = self:getParty():getMembers()
for i = 1, #membersList do
local player = membersList[i]
if player then
networkMessage:sendToPlayer(player)
end
end
networkMessage:delete()
return true
end

networkMessage:sendToPlayer(self)
networkMessage:delete()
return true
end