feat(Core/Scripts): Optimize FormulaScript (#18710)
* Add files via upload * Update FormulaScript.h
This commit is contained in:
@@ -21,42 +21,27 @@
|
|||||||
|
|
||||||
void ScriptMgr::OnHonorCalculation(float& honor, uint8 level, float multiplier)
|
void ScriptMgr::OnHonorCalculation(float& honor, uint8 level, float multiplier)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_HONOR_CALCULATION, script->OnHonorCalculation(honor, level, multiplier));
|
||||||
{
|
|
||||||
script->OnHonorCalculation(honor, level, multiplier);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel)
|
void ScriptMgr::OnGrayLevelCalculation(uint8& grayLevel, uint8 playerLevel)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_GRAY_LEVEL_CALCULATION, script->OnGrayLevelCalculation(grayLevel, playerLevel));
|
||||||
{
|
|
||||||
script->OnGrayLevelCalculation(grayLevel, playerLevel);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel)
|
void ScriptMgr::OnColorCodeCalculation(XPColorChar& color, uint8 playerLevel, uint8 mobLevel)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_COLOR_CODE_CALCULATION, script->OnColorCodeCalculation(color, playerLevel, mobLevel));
|
||||||
{
|
|
||||||
script->OnColorCodeCalculation(color, playerLevel, mobLevel);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnZeroDifferenceCalculation(uint8& diff, uint8 playerLevel)
|
void ScriptMgr::OnZeroDifferenceCalculation(uint8& diff, uint8 playerLevel)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_ZERO_DIFFERENCE_CALCULATION, script->OnZeroDifferenceCalculation(diff, playerLevel));
|
||||||
{
|
|
||||||
script->OnZeroDifferenceCalculation(diff, playerLevel);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content)
|
void ScriptMgr::OnBaseGainCalculation(uint32& gain, uint8 playerLevel, uint8 mobLevel, ContentLevels content)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_BASE_GAIN_CALCULATION, script->OnBaseGainCalculation(gain, playerLevel, mobLevel, content));
|
||||||
{
|
|
||||||
script->OnBaseGainCalculation(gain, playerLevel, mobLevel, content);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnGainCalculation(uint32& gain, Player* player, Unit* unit)
|
void ScriptMgr::OnGainCalculation(uint32& gain, Player* player, Unit* unit)
|
||||||
@@ -64,40 +49,33 @@ void ScriptMgr::OnGainCalculation(uint32& gain, Player* player, Unit* unit)
|
|||||||
ASSERT(player);
|
ASSERT(player);
|
||||||
ASSERT(unit);
|
ASSERT(unit);
|
||||||
|
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_GAIN_CALCULATION, script->OnGainCalculation(gain, player, unit));
|
||||||
{
|
|
||||||
script->OnGainCalculation(gain, player, unit);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnGroupRateCalculation(float& rate, uint32 count, bool isRaid)
|
void ScriptMgr::OnGroupRateCalculation(float& rate, uint32 count, bool isRaid)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_GROUP_RATE_CALCULATION, script->OnGroupRateCalculation(rate, count, isRaid));
|
||||||
{
|
|
||||||
script->OnGroupRateCalculation(rate, count, isRaid);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnAfterArenaRatingCalculation(Battleground* const bg, int32& winnerMatchmakerChange, int32& loserMatchmakerChange, int32& winnerChange, int32& loserChange)
|
void ScriptMgr::OnAfterArenaRatingCalculation(Battleground* const bg, int32& winnerMatchmakerChange, int32& loserMatchmakerChange, int32& winnerChange, int32& loserChange)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_AFTER_ARENA_RATING_CALCULATION, script->OnAfterArenaRatingCalculation(bg, winnerMatchmakerChange, loserMatchmakerChange, winnerChange, loserChange));
|
||||||
{
|
|
||||||
script->OnAfterArenaRatingCalculation(bg, winnerMatchmakerChange, loserMatchmakerChange, winnerChange, loserChange);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnBeforeUpdatingPersonalRating(int32& mod, uint32 type)
|
void ScriptMgr::OnBeforeUpdatingPersonalRating(int32& mod, uint32 type)
|
||||||
{
|
{
|
||||||
ExecuteScript<FormulaScript>([&](FormulaScript* script)
|
CALL_ENABLED_HOOKS(FormulaScript, FORMULAHOOK_ON_BEFORE_UPDATING_PERSONAL_RATING, script->OnBeforeUpdatingPersonalRating(mod, type));
|
||||||
{
|
|
||||||
script->OnBeforeUpdatingPersonalRating(mod, type);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormulaScript::FormulaScript(const char* name)
|
FormulaScript::FormulaScript(const char* name, std::vector<uint16> enabledHooks)
|
||||||
: ScriptObject(name)
|
: ScriptObject(name, FORMULAHOOK_END)
|
||||||
{
|
{
|
||||||
ScriptRegistry<FormulaScript>::AddScript(this);
|
// If empty - enable all available hooks.
|
||||||
|
if (enabledHooks.empty())
|
||||||
|
for (uint16 i = 0; i < FORMULAHOOK_END; ++i)
|
||||||
|
enabledHooks.emplace_back(i);
|
||||||
|
|
||||||
|
ScriptRegistry<FormulaScript>::AddScript(this, std::move(enabledHooks));
|
||||||
}
|
}
|
||||||
|
|
||||||
template class AC_GAME_API ScriptRegistry<FormulaScript>;
|
template class AC_GAME_API ScriptRegistry<FormulaScript>;
|
||||||
|
|||||||
@@ -19,13 +19,28 @@
|
|||||||
#define SCRIPT_OBJECT_FORMULA_SCRIPT_H_
|
#define SCRIPT_OBJECT_FORMULA_SCRIPT_H_
|
||||||
|
|
||||||
#include "ScriptObject.h"
|
#include "ScriptObject.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
enum FormulaHook
|
||||||
|
{
|
||||||
|
FORMULAHOOK_ON_HONOR_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_GRAY_LEVEL_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_COLOR_CODE_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_ZERO_DIFFERENCE_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_BASE_GAIN_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_GAIN_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_GROUP_RATE_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_AFTER_ARENA_RATING_CALCULATION,
|
||||||
|
FORMULAHOOK_ON_BEFORE_UPDATING_PERSONAL_RATING,
|
||||||
|
FORMULAHOOK_END
|
||||||
|
};
|
||||||
|
|
||||||
enum XPColorChar : uint8;
|
enum XPColorChar : uint8;
|
||||||
|
|
||||||
class FormulaScript : public ScriptObject
|
class FormulaScript : public ScriptObject
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
FormulaScript(const char* name);
|
FormulaScript(const char* name, std::vector<uint16> enabledHooks = std::vector<uint16>());
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called after calculating honor.
|
// Called after calculating honor.
|
||||||
|
|||||||
Reference in New Issue
Block a user