feat(Core/Hook): New PlayerScript hooks (#2639)
This commit is contained in:
@@ -11,6 +11,7 @@
|
|||||||
#include "TemporarySummon.h"
|
#include "TemporarySummon.h"
|
||||||
#include "Pet.h"
|
#include "Pet.h"
|
||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
|
#include "ScriptMgr.h"
|
||||||
|
|
||||||
TempSummon::TempSummon(SummonPropertiesEntry const* properties, uint64 owner, bool isWorldObject) :
|
TempSummon::TempSummon(SummonPropertiesEntry const* properties, uint64 owner, bool isWorldObject) :
|
||||||
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
|
Creature(isWorldObject), m_Properties(properties), m_type(TEMPSUMMON_MANUAL_DESPAWN),
|
||||||
@@ -147,13 +148,16 @@ void TempSummon::InitStats(uint32 duration)
|
|||||||
{
|
{
|
||||||
ASSERT(!IsPet());
|
ASSERT(!IsPet());
|
||||||
|
|
||||||
|
Unit* owner = GetSummoner();
|
||||||
|
if (Player* player = owner->ToPlayer())
|
||||||
|
sScriptMgr->OnBeforeTempSummonInitStats(player, this, duration);
|
||||||
|
|
||||||
m_timer = duration;
|
m_timer = duration;
|
||||||
m_lifetime = duration;
|
m_lifetime = duration;
|
||||||
|
|
||||||
if (m_type == TEMPSUMMON_MANUAL_DESPAWN)
|
if (m_type == TEMPSUMMON_MANUAL_DESPAWN)
|
||||||
m_type = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
|
m_type = (duration == 0) ? TEMPSUMMON_DEAD_DESPAWN : TEMPSUMMON_TIMED_DESPAWN;
|
||||||
|
|
||||||
Unit* owner = GetSummoner();
|
|
||||||
if (owner)
|
if (owner)
|
||||||
{
|
{
|
||||||
if (IsTrigger() && m_spells[0])
|
if (IsTrigger() && m_spells[0])
|
||||||
|
|||||||
@@ -152,9 +152,12 @@ bool Pet::LoadPetFromDB(Player* owner, uint8 asynchLoadType, uint32 petentry, ui
|
|||||||
if (owner->IsSpectator() || owner->GetPet() || !owner->IsInWorld() || !owner->FindMap())
|
if (owner->IsSpectator() || owner->GetPet() || !owner->IsInWorld() || !owner->FindMap())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// DK Pet exception
|
bool forceLoadFromDB = false;
|
||||||
if (owner->getClass() == CLASS_DEATH_KNIGHT && !owner->CanSeeDKPet())
|
sScriptMgr->OnBeforeLoadPetFromDB(owner, petentry, petnumber, current, forceLoadFromDB);
|
||||||
return false;
|
|
||||||
|
if (!forceLoadFromDB)
|
||||||
|
if (owner->getClass() == CLASS_DEATH_KNIGHT && !owner->CanSeeDKPet()) // DK Pet exception
|
||||||
|
return false;
|
||||||
|
|
||||||
uint32 ownerid = owner->GetGUIDLow();
|
uint32 ownerid = owner->GetGUIDLow();
|
||||||
PreparedStatement* stmt;
|
PreparedStatement* stmt;
|
||||||
@@ -720,20 +723,31 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
|
|||||||
|
|
||||||
//Determine pet type
|
//Determine pet type
|
||||||
PetType petType = MAX_PET_TYPE;
|
PetType petType = MAX_PET_TYPE;
|
||||||
if (IsPet() && owner->GetTypeId() == TYPEID_PLAYER)
|
if (owner->GetTypeId() == TYPEID_PLAYER)
|
||||||
{
|
{
|
||||||
if (owner->getClass() == CLASS_WARLOCK ||
|
sScriptMgr->OnBeforeGuardianInitStatsForLevel(owner->ToPlayer(), this, cinfo, petType);
|
||||||
owner->getClass() == CLASS_SHAMAN || // Fire Elemental
|
|
||||||
owner->getClass() == CLASS_DEATH_KNIGHT || // Risen Ghoul
|
if (IsPet())
|
||||||
owner->getClass() == CLASS_MAGE) // Water Elemental with glyph
|
|
||||||
petType = SUMMON_PET;
|
|
||||||
else if (owner->getClass() == CLASS_HUNTER)
|
|
||||||
{
|
{
|
||||||
petType = HUNTER_PET;
|
if (petType == MAX_PET_TYPE)
|
||||||
m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
|
{
|
||||||
|
// The petType was not overwritten by the hook, continue with default initialization
|
||||||
|
if (owner->getClass() == CLASS_WARLOCK ||
|
||||||
|
owner->getClass() == CLASS_SHAMAN || // Fire Elemental
|
||||||
|
owner->getClass() == CLASS_DEATH_KNIGHT || // Risen Ghoul
|
||||||
|
owner->getClass() == CLASS_MAGE) // Water Elemental with glyph
|
||||||
|
petType = SUMMON_PET;
|
||||||
|
else if (owner->getClass() == CLASS_HUNTER)
|
||||||
|
{
|
||||||
|
petType = HUNTER_PET;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (petType == HUNTER_PET)
|
||||||
|
m_unitTypeMask |= UNIT_MASK_HUNTER_PET;
|
||||||
|
else if (petType != SUMMON_PET)
|
||||||
|
sLog->outError("Unknown type pet %u is summoned by player class %u", GetEntry(), owner->getClass());
|
||||||
}
|
}
|
||||||
else
|
|
||||||
sLog->outError("Unknown type pet %u is summoned by player class %u", GetEntry(), owner->getClass());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 creature_ID = (petType == HUNTER_PET) ? 1 : cinfo->Entry;
|
uint32 creature_ID = (petType == HUNTER_PET) ? 1 : cinfo->Entry;
|
||||||
@@ -1066,8 +1080,8 @@ bool Guardian::InitStatsForLevel(uint8 petlevel)
|
|||||||
SetFullHealth();
|
SetFullHealth();
|
||||||
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
|
SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
|
||||||
|
|
||||||
if (Pet* pet = ToPet())
|
if (owner->GetTypeId() == TYPEID_PLAYER)
|
||||||
sScriptMgr->OnPetInitStatsForLevel(pet);
|
sScriptMgr->OnAfterGuardianInitStatsForLevel(owner->ToPlayer(), this);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1653,9 +1653,24 @@ bool ScriptMgr::CanJoinInBattlegroundQueue(Player* player, uint64 BattlemasterGu
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptMgr::OnPetInitStatsForLevel(Pet* pet)
|
void ScriptMgr::OnBeforeTempSummonInitStats(Player* player, TempSummon* tempSummon, uint32& duration)
|
||||||
{
|
{
|
||||||
FOREACH_SCRIPT(PlayerScript)->OnPetInitStatsForLevel(pet);
|
FOREACH_SCRIPT(PlayerScript)->OnBeforeTempSummonInitStats(player, tempSummon, duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMgr::OnBeforeGuardianInitStatsForLevel(Player* player, Guardian* guardian, CreatureTemplate const* cinfo, PetType& petType)
|
||||||
|
{
|
||||||
|
FOREACH_SCRIPT(PlayerScript)->OnBeforeGuardianInitStatsForLevel(player, guardian, cinfo, petType);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMgr::OnAfterGuardianInitStatsForLevel(Player* player, Guardian* guardian)
|
||||||
|
{
|
||||||
|
FOREACH_SCRIPT(PlayerScript)->OnAfterGuardianInitStatsForLevel(player, guardian);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptMgr::OnBeforeLoadPetFromDB(Player* player, uint32& petentry, uint32& petnumber, bool& current, bool& forceLoadFromDB)
|
||||||
|
{
|
||||||
|
FOREACH_SCRIPT(PlayerScript)->OnBeforeLoadPetFromDB(player, petentry, petnumber, current, forceLoadFromDB);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account
|
// Account
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "DynamicObject.h"
|
#include "DynamicObject.h"
|
||||||
#include "ArenaTeam.h"
|
#include "ArenaTeam.h"
|
||||||
#include "GameEventMgr.h"
|
#include "GameEventMgr.h"
|
||||||
|
#include "PetDefines.h"
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
class AuctionHouseObject;
|
class AuctionHouseObject;
|
||||||
@@ -962,8 +963,17 @@ class PlayerScript : public ScriptObject
|
|||||||
|
|
||||||
virtual bool CanJoinInBattlegroundQueue(Player* /*player*/, uint64 /*BattlemasterGuid*/, BattlegroundTypeId /*BGTypeID*/, uint8 /*joinAsGroup*/, GroupJoinBattlegroundResult& /*err*/) { return true; }
|
virtual bool CanJoinInBattlegroundQueue(Player* /*player*/, uint64 /*BattlemasterGuid*/, BattlegroundTypeId /*BGTypeID*/, uint8 /*joinAsGroup*/, GroupJoinBattlegroundResult& /*err*/) { return true; }
|
||||||
|
|
||||||
// Called after the player's pet has been loaded and initialized
|
// Called before the player's temporary summoned creature has initialized it's stats
|
||||||
virtual void OnPetInitStatsForLevel(Pet* /*pet*/) { }
|
virtual void OnBeforeTempSummonInitStats(Player* /*player*/, TempSummon* /*tempSummon*/, uint32& /*duration*/) { }
|
||||||
|
|
||||||
|
// Called before the player's guardian / pet has initialized it's stats for the player's level
|
||||||
|
virtual void OnBeforeGuardianInitStatsForLevel(Player* /*player*/, Guardian* /*guardian*/, CreatureTemplate const* /*cinfo*/, PetType& /*petType*/) { }
|
||||||
|
|
||||||
|
// Called after the player's guardian / pet has initialized it's stats for the player's level
|
||||||
|
virtual void OnAfterGuardianInitStatsForLevel(Player* /*player*/, Guardian* /*guardian*/) { }
|
||||||
|
|
||||||
|
// Called before loading a player's pet from the DB
|
||||||
|
virtual void OnBeforeLoadPetFromDB(Player* /*player*/, uint32& /*petentry*/, uint32& /*petnumber*/, bool& /*current*/, bool& /*forceLoadFromDB*/) { }
|
||||||
};
|
};
|
||||||
|
|
||||||
class AccountScript : public ScriptObject
|
class AccountScript : public ScriptObject
|
||||||
@@ -1415,7 +1425,10 @@ class ScriptMgr
|
|||||||
void OnFirstLogin(Player* player);
|
void OnFirstLogin(Player* player);
|
||||||
void OnPlayerCompleteQuest(Player* player, Quest const* quest);
|
void OnPlayerCompleteQuest(Player* player, Quest const* quest);
|
||||||
bool CanJoinInBattlegroundQueue(Player* player, uint64 BattlemasterGuid, BattlegroundTypeId BGTypeID, uint8 joinAsGroup, GroupJoinBattlegroundResult& err);
|
bool CanJoinInBattlegroundQueue(Player* player, uint64 BattlemasterGuid, BattlegroundTypeId BGTypeID, uint8 joinAsGroup, GroupJoinBattlegroundResult& err);
|
||||||
void OnPetInitStatsForLevel(Pet* pet);
|
void OnBeforeTempSummonInitStats(Player* player, TempSummon* tempSummon, uint32& duration);
|
||||||
|
void OnBeforeGuardianInitStatsForLevel(Player* player, Guardian* guardian, CreatureTemplate const* cinfo, PetType& petType);
|
||||||
|
void OnAfterGuardianInitStatsForLevel(Player* player, Guardian* guardian);
|
||||||
|
void OnBeforeLoadPetFromDB(Player* player, uint32& petentry, uint32& petnumber, bool& current, bool& forceLoadFromDB);
|
||||||
|
|
||||||
public: /* AccountScript */
|
public: /* AccountScript */
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user