opentibiabr / canary

Canary Server 13.x for OpenTibia community.
https://docs.opentibiabr.com/
GNU General Public License v2.0
384 stars 637 forks source link

feat/improve: create "custom loot" for monsters #3080

Open dudantas opened 2 weeks ago

dudantas commented 2 weeks ago

Description

This update introduces several enhancements to the loot system, allowing for more flexible loot management across different monsters without the need to modify each monster's individual script. A global loot option has been added, which is disabled by default, to assign items that any monster can drop. This feature simplifies the addition of common loot across multiple monsters, enhancing the modularity of loot management.

The registerLoot function has been improved to eliminate code duplication and enhance efficiency. The closeContainer function has been updated to remove problematic code that could cause crashes when "container" used before "erase". Additionally, a new Lua function, getMonsterTypeByName, has been introduced to facilitate getting monster types.

Behaviour

Actual

Previously, adding or modifying loot required changes to each monster's script individually, which was cumbersome and error-prone.

Expected

With the new system, it's now possible to assign specific loot to monsters or set global loot defaults without direct script modifications. This update also ensures more stability and performance in managing loot containers.

Type of change

How Has This Been Tested

Testing focused on ensuring that the new global loot system functions correctly without impacting the specific loot settings for individual monsters. Tests were also conducted to ensure that the modifications to the closeContainer function did not lead to crashes under various scenarios.

Checklist

sonarcloud[bot] commented 2 weeks ago

Please retry analysis of this Pull-Request directly on SonarCloud