Skip to content

Commit

Permalink
perf: remove unnecessary event callbacks (#3076)
Browse files Browse the repository at this point in the history
Removed Lua callbacks from `MonsterType` of various monsters. These
callbacks were empty, which meant the functions were still being
"called" by the monsters without performing any action, creating a
significant performance bottleneck.

Removed the `onHear` event callback, which had a significant impact on
the server and was not used anywhere. It executed the `onHear` callback
for each spectator, causing an unnecessary overload without any real
benefit, especially as we have other methods to check for these events.

Additionally, the `monsterOnSpawn` event callback was removed and
replaced with `MonsterType::onSpawn`, which is much more efficient since
it only needs to be declared in the script for each monster that
actually uses it.

Finally, the way `setRewardBoss` was handled was improved. Previously,
it was executed in an `onSpawn` event callback, but now it is done
directly during the parsing of each monster script, marking them as
reward bosses at the time of script loading, improving efficiency.
  • Loading branch information
dudantas authored Nov 8, 2024
1 parent e6c0995 commit ceace16
Show file tree
Hide file tree
Showing 238 changed files with 168 additions and 3,206 deletions.
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/apocalypse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/apprentice_sheng.lua
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/bazir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/black_knight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/bullwark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/custodian.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/dharalion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,18 +132,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-canary/monster/bosses/shadowpelt.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/alchemist_container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/antenna.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/apocalypse.lua
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/apprentice_sheng.lua
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/armenius.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/bazir.lua
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/bibby_bloodbath.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,18 +122,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/big_boss_trolliver.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/black_knight.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,18 +131,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/brain_head.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,4 @@ monster.voices = {
{ text = "My lich-knights will conquer this world for me!", yell = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/bullwark.lua
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/cerebellum.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,4 @@ monster.voices = {
{ text = "My lich-knights will conquer this world for me!", yell = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
14 changes: 0 additions & 14 deletions data-otservbr-global/monster/bosses/chikhaton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,4 @@ monster.immunities = {
{ type = "bleed", condition = false },
}

mType.onThink = function(monster, interval) end

mType.onAppear = function(monster, creature)
if monster:getType():isRewardBoss() then
monster:setReward(true)
end
end

mType.onDisappear = function(monster, creature) end

mType.onMove = function(monster, creature, fromPosition, toPosition) end

mType.onSay = function(monster, creature, type, message) end

mType:register(monster)
Loading

0 comments on commit ceace16

Please sign in to comment.