Add OnBeforeCreatureSelectLevel() hook

- allows modules to alter the level of a creature just before it is set
This commit is contained in:
KJack
2023-09-30 01:49:32 -04:00
parent b9829b0e94
commit 10304f970a
3 changed files with 16 additions and 0 deletions

View File

@@ -1487,7 +1487,10 @@ void Creature::SelectLevel(bool changelevel)
uint8 maxlevel = std::max(cInfo->maxlevel, cInfo->minlevel);
uint8 level = minlevel == maxlevel ? minlevel : urand(minlevel, maxlevel);
if (changelevel)
{
sScriptMgr->OnBeforeCreatureSelectLevel(cInfo, this, level);
SetLevel(level);
}
CreatureBaseStats const* stats = sObjectMgr->GetCreatureBaseStats(level, cInfo->unit_class);

View File

@@ -48,6 +48,15 @@ void ScriptMgr::OnCreatureSaveToDB(Creature* creature)
});
}
void OnBeforeCreatureSelectLevel(const CreatureTemplate* cinfo, Creature* creature, uint8& level)
{
ExecuteScript<AllCreatureScript>([&](AllCreatureScript* script)
{
script->OnBeforeCreatureSelectLevel(cinfo, creature, level);
});
}
void ScriptMgr::Creature_SelectLevel(const CreatureTemplate* cinfo, Creature* creature)
{
ExecuteScript<AllCreatureScript>([&](AllCreatureScript* script)

View File

@@ -555,6 +555,9 @@ public:
// Called from End of Creature Update.
virtual void OnAllCreatureUpdate(Creature* /*creature*/, uint32 /*diff*/) { }
// Called just before the level of the creature is set.
virtual void OnBeforeCreatureSelectLevel(const CreatureTemplate* /*cinfo*/, Creature* /*creature*/, uint8& /*level*/) { }
// Called from End of Creature SelectLevel.
virtual void Creature_SelectLevel(const CreatureTemplate* /*cinfo*/, Creature* /*creature*/) { }
@@ -2555,6 +2558,7 @@ public: /* MovementHandlerScript */
public: /* AllCreatureScript */
//listener function (OnAllCreatureUpdate) is called by OnCreatureUpdate
//void OnAllCreatureUpdate(Creature* creature, uint32 diff);
void OnBeforeCreatureSelectLevel(const CreatureTemplate* cinfo, Creature* creature, uint8& level);
void Creature_SelectLevel(const CreatureTemplate* cinfo, Creature* creature);
void OnCreatureSaveToDB(Creature* creature);