refactor(Core/Scripts): Optimize Script (#18708)

* Add files via upload

* Update PlayerScript.h
This commit is contained in:
天鹿
2024-04-12 21:50:44 +08:00
committed by GitHub
parent 3a6231cb65
commit 97fc546c4b
7 changed files with 21 additions and 26 deletions

View File

@@ -69,7 +69,7 @@ AccountScript::AccountScript(char const* name, std::vector<uint16> enabledHooks)
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < ACCOUNTHOOK_END; i++)
for (uint16 i = 0; i < ACCOUNTHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<AccountScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -39,7 +39,7 @@ ArenaScript::ArenaScript(const char* name, std::vector<uint16> enabledHooks)
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < ARENAHOOK_END; i++)
for (uint16 i = 0; i < ARENAHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<ArenaScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -49,7 +49,7 @@ ArenaTeamScript::ArenaTeamScript(const char* name, std::vector<uint16> enabledHo
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < ARENATEAMHOOK_END; i++)
for (uint16 i = 0; i < ARENATEAMHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<ArenaTeamScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -91,7 +91,7 @@ AuctionHouseScript::AuctionHouseScript(const char* name, std::vector<uint16> ena
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < AUCTIONHOUSEHOOK_END; i++)
for (uint16 i = 0; i < AUCTIONHOUSEHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<AuctionHouseScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -29,7 +29,7 @@ MovementHandlerScript::MovementHandlerScript(const char* name, std::vector<uint1
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < MOVEMENTHOOK_END; i++)
for (uint16 i = 0; i < MOVEMENTHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<MovementHandlerScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -41,9 +41,7 @@ void ScriptMgr::OnPlayerCompleteQuest(Player* player, Quest const* quest)
void ScriptMgr::OnSendInitialPacketsBeforeAddToMap(Player* player, WorldPacket& data)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_SEND_INITIAL_PACKETS_BEFORE_ADD_TO_MAP, {
script->OnSendInitialPacketsBeforeAddToMap(player, data);
});
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_SEND_INITIAL_PACKETS_BEFORE_ADD_TO_MAP, script->OnSendInitialPacketsBeforeAddToMap(player, data));
}
void ScriptMgr::OnBattlegroundDesertion(Player* player, BattlegroundDesertionType const desertionType)
@@ -73,17 +71,17 @@ void ScriptMgr::OnPVPKill(Player* killer, Player* killed)
void ScriptMgr::OnPlayerPVPFlagChange(Player* player, bool state)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_PLAYER_PVP_FLAG_CHANGE,script->OnPlayerPVPFlagChange(player, state));
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_PLAYER_PVP_FLAG_CHANGE, script->OnPlayerPVPFlagChange(player, state));
}
void ScriptMgr::OnCreatureKill(Player* killer, Creature* killed)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_CREATURE_KILL,script->OnCreatureKill(killer, killed));
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_CREATURE_KILL, script->OnCreatureKill(killer, killed));
}
void ScriptMgr::OnCreatureKilledByPet(Player* petOwner, Creature* killed)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_CREATURE_KILLED_BY_PET,script->OnCreatureKilledByPet(petOwner, killed));
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_CREATURE_KILLED_BY_PET, script->OnCreatureKilledByPet(petOwner, killed));
}
void ScriptMgr::OnPlayerKilledByCreature(Creature* killer, Player* killed)
@@ -198,11 +196,7 @@ void ScriptMgr::OnPlayerEmote(Player* player, uint32 emote)
void ScriptMgr::OnPlayerTextEmote(Player* player, uint32 textEmote, uint32 emoteNum, ObjectGuid guid)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_TEXT_EMOTE,
(
script->OnTextEmote(player, textEmote, emoteNum, guid)
)
);
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_TEXT_EMOTE, script->OnTextEmote(player, textEmote, emoteNum, guid));
}
void ScriptMgr::OnPlayerSpellCast(Player* player, Spell* spell, bool skipCheck)
@@ -605,11 +599,13 @@ bool ScriptMgr::OnPlayerHasActivePowerType(Player const* player, Powers power)
CALL_ENABLED_BOOLEAN_HOOKS(PlayerScript, PLAYERHOOK_ON_PLAYER_HAS_ACTIVE_POWER_TYPE, !script->OnPlayerHasActivePowerType(player, power));
}
void ScriptMgr::OnUpdateGatheringSkill(Player *player, uint32 skillId, uint32 currentLevel, uint32 gray, uint32 green, uint32 yellow, uint32 &gain) {
void ScriptMgr::OnUpdateGatheringSkill(Player *player, uint32 skillId, uint32 currentLevel, uint32 gray, uint32 green, uint32 yellow, uint32 &gain)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_UPDATE_GATHERING_SKILL, script->OnUpdateGatheringSkill(player, skillId, currentLevel, gray, green, yellow, gain));
}
void ScriptMgr::OnUpdateCraftingSkill(Player *player, SkillLineAbilityEntry const* skill, uint32 currentLevel, uint32& gain) {
void ScriptMgr::OnUpdateCraftingSkill(Player *player, SkillLineAbilityEntry const* skill, uint32 currentLevel, uint32& gain)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_UPDATE_CRAFTING_SKILL, script->OnUpdateCraftingSkill(player, skill, currentLevel, gain));
}
@@ -755,16 +751,12 @@ void ScriptMgr::OnFfaPvpStateUpdate(Player* player, bool result)
void ScriptMgr::OnIsPvP(Player* player, bool& result)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_IS_PVP, {
script->OnIsPvP(player, result);
});
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_IS_PVP, script->OnIsPvP(player, result));
}
void ScriptMgr::OnGetMaxSkillValueForLevel(Player* player, uint16& result)
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_GET_MAX_SKILL_VALUE_FOR_LEVEL, {
script->OnGetMaxSkillValueForLevel(player, result);
});
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ON_GET_MAX_SKILL_VALUE_FOR_LEVEL, script->OnGetMaxSkillValueForLevel(player, result));
}
bool ScriptMgr::NotSetArenaTeamInfoField(Player* player, uint8 slot, ArenaTeamInfoType type, uint32 value)
@@ -882,6 +874,7 @@ void ScriptMgr::AnticheatUpdateMovementInfo(Player* player, MovementInfo const&
{
CALL_ENABLED_HOOKS(PlayerScript, PLAYERHOOK_ANTICHEAT_UPDATE_MOVEMENT_INFO, script->AnticheatUpdateMovementInfo(player, movementInfo));
}
bool ScriptMgr::AnticheatHandleDoubleJump(Player* player, Unit* mover)
{
CALL_ENABLED_BOOLEAN_HOOKS(PlayerScript, PLAYERHOOK_ANTICHEAT_HANDLE_DOUBLE_JUMP, !script->AnticheatHandleDoubleJump(player, mover));
@@ -897,7 +890,7 @@ PlayerScript::PlayerScript(const char* name, std::vector<uint16> enabledHooks)
{
// If empty - enable all available hooks.
if (enabledHooks.empty())
for (uint16 i = 0; i < PLAYERHOOK_END; i++)
for (uint16 i = 0; i < PLAYERHOOK_END; ++i)
enabledHooks.emplace_back(i);
ScriptRegistry<PlayerScript>::AddScript(this, std::move(enabledHooks));

View File

@@ -19,12 +19,14 @@
#define SCRIPT_OBJECT_PLAYER_SCRIPT_H_
#include "ScriptObject.h"
#include <vector>
// TODO to remove
#include "AchievementMgr.h"
#include "KillRewarder.h"
enum PlayerHook {
enum PlayerHook
{
PLAYERHOOK_ON_PLAYER_JUST_DIED,
PLAYERHOOK_ON_PLAYER_RELEASED_GHOST,
PLAYERHOOK_ON_SEND_INITIAL_PACKETS_BEFORE_ADD_TO_MAP,