Implement a PlayerScript class with a handful of new hooks:
* OnPVPKill * OnCreatureKill * OnPlayerKilledByCreature * OnPlayerLevelChanged * OnPlayerFreeTalentPointsChanged * OnPlayerTalentsReset * More hooks may be added in the future --HG-- branch : trunk
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
#include "DisableMgr.h"
|
||||
#include "Transport.h"
|
||||
#include "WeatherMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
//reload commands
|
||||
bool ChatHandler::HandleReloadAllCommand(const char*)
|
||||
@@ -4913,8 +4914,9 @@ bool ChatHandler::HandleResetLevelCommand(const char * args)
|
||||
? sWorld.getConfig(CONFIG_START_PLAYER_LEVEL)
|
||||
: sWorld.getConfig(CONFIG_START_HEROIC_PLAYER_LEVEL);
|
||||
|
||||
target->_ApplyAllLevelScaleItemMods(false);
|
||||
sScriptMgr.OnPlayerLevelChanged(target, start_level);
|
||||
|
||||
target->_ApplyAllLevelScaleItemMods(false);
|
||||
target->SetLevel(start_level);
|
||||
target->InitRunes();
|
||||
target->InitStatsForLevel(true);
|
||||
|
||||
@@ -2655,6 +2655,8 @@ void Player::GiveLevel(uint8 level)
|
||||
if (level == getLevel())
|
||||
return;
|
||||
|
||||
sScriptMgr.OnPlayerLevelChanged(this, level);
|
||||
|
||||
PlayerLevelInfo info;
|
||||
sObjectMgr.GetPlayerLevelInfo(getRace(),getClass(),level,&info);
|
||||
|
||||
@@ -3983,6 +3985,8 @@ uint32 Player::resetTalentsCost() const
|
||||
|
||||
bool Player::resetTalents(bool no_cost)
|
||||
{
|
||||
sScriptMgr.OnPlayerTalentsReset(this, no_cost);
|
||||
|
||||
// not need after this call
|
||||
if (HasAtLoginFlag(AT_LOGIN_RESET_TALENTS))
|
||||
RemoveAtLoginFlag(AT_LOGIN_RESET_TALENTS, true);
|
||||
@@ -4070,6 +4074,12 @@ bool Player::resetTalents(bool no_cost)
|
||||
return true;
|
||||
}
|
||||
|
||||
void Player::SetFreeTalentPoints(uint32 points)
|
||||
{
|
||||
sScriptMgr.OnPlayerFreeTalentPointsChanged(this, points);
|
||||
SetUInt32Value(PLAYER_CHARACTER_POINTS1,points);
|
||||
}
|
||||
|
||||
Mail* Player::GetMail(uint32 id)
|
||||
{
|
||||
for (PlayerMails::iterator itr = m_mail.begin(); itr != m_mail.end(); ++itr)
|
||||
|
||||
@@ -1559,7 +1559,7 @@ class Player : public Unit, public GridObject<Player>
|
||||
uint32 GetReputation(uint32 factionentry);
|
||||
std::string GetGuildName();
|
||||
uint32 GetFreeTalentPoints() const { return GetUInt32Value(PLAYER_CHARACTER_POINTS1); }
|
||||
void SetFreeTalentPoints(uint32 points) { SetUInt32Value(PLAYER_CHARACTER_POINTS1,points); }
|
||||
void SetFreeTalentPoints(uint32 points);
|
||||
bool resetTalents(bool no_cost = false);
|
||||
uint32 resetTalentsCost() const;
|
||||
void InitTalentForLevel();
|
||||
|
||||
@@ -720,15 +720,29 @@ uint32 Unit::DealDamage(Unit *pVictim, uint32 damage, CleanDamage const* cleanDa
|
||||
Kill(pVictim, durabilityLoss);
|
||||
|
||||
//Hook for OnPVPKill Event
|
||||
if (pVictim->GetTypeId() == TYPEID_PLAYER && this->GetTypeId() == TYPEID_PLAYER)
|
||||
if (this->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
Player *killer = this->ToPlayer();
|
||||
Player *killed = pVictim->ToPlayer();
|
||||
if (pVictim->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
Player *killer = this->ToPlayer();
|
||||
Player *killed = pVictim->ToPlayer();
|
||||
sScriptMgr.OnPVPKill(killer, killed);
|
||||
}
|
||||
else if (pVictim->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
Player *killer = this->ToPlayer();
|
||||
Creature *killed = pVictim->ToCreature();
|
||||
sScriptMgr.OnCreatureKill(killer, killed);
|
||||
}
|
||||
}
|
||||
if (pVictim->GetTypeId() == TYPEID_UNIT && this->GetTypeId() == TYPEID_PLAYER)
|
||||
else if (this->GetTypeId() == TYPEID_UNIT)
|
||||
{
|
||||
Player *killer = this->ToPlayer();
|
||||
Creature *pCreature = (pVictim->ToCreature());
|
||||
if (pVictim->GetTypeId() == TYPEID_PLAYER)
|
||||
{
|
||||
Creature *killer = this->ToCreature();
|
||||
Player *killed = pVictim->ToPlayer();
|
||||
sScriptMgr.OnPlayerKilledByCreature(killer, killed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else // if (health <= damage)
|
||||
|
||||
@@ -1067,6 +1067,36 @@ bool ScriptMgr::OnCriteriaCheck(AchievementCriteriaData const* data, Player* sou
|
||||
return tmpscript->OnCheck(source, target);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPVPKill(Player *killer, Player *killed)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnPVPKill(killer, killed);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnCreatureKill(Player *killer, Creature *killed)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnCreatureKill(killer, killed);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerKilledByCreature(Creature *killer, Player *killed)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnPlayerKilledByCreature(killer, killed);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerLevelChanged(Player *player, uint8 newLevel)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnLevelChanged(player, newLevel);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerFreeTalentPointsChanged(Player *player, uint32 points)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnFreeTalentPointsChanged(player, points);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerTalentsReset(Player *player, bool no_cost)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnTalentsReset(player, no_cost);
|
||||
}
|
||||
|
||||
SpellHandlerScript::SpellHandlerScript(const char* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
@@ -1208,6 +1238,12 @@ AchievementCriteriaScript::AchievementCriteriaScript(const char* name)
|
||||
ScriptMgr::ScriptRegistry<AchievementCriteriaScript>::AddScript(this);
|
||||
}
|
||||
|
||||
PlayerScript::PlayerScript(const char* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
ScriptMgr::ScriptRegistry<PlayerScript>::AddScript(this);
|
||||
}
|
||||
|
||||
// Instantiate static members of ScriptMgr::ScriptRegistry.
|
||||
template<class TScript> std::map<uint32, TScript*> ScriptMgr::ScriptRegistry<TScript>::ScriptPointerList;
|
||||
template<class TScript> uint32 ScriptMgr::ScriptRegistry<TScript>::_scriptIdCounter = 0;
|
||||
|
||||
@@ -652,6 +652,33 @@ class AchievementCriteriaScript : public ScriptObject
|
||||
virtual bool OnCheck(Player* source, Unit* target) = 0;
|
||||
};
|
||||
|
||||
class PlayerScript : public ScriptObject
|
||||
{
|
||||
protected:
|
||||
PlayerScript(const char* name);
|
||||
|
||||
public:
|
||||
bool IsDatabaseBound() const { return false; }
|
||||
|
||||
// Called when a player kills another player
|
||||
virtual void OnPVPKill(Player *killer, Player *killed);
|
||||
|
||||
// Called when a player kills a creature
|
||||
virtual void OnCreatureKill(Player *killer, Creature *killed);
|
||||
|
||||
// Called when a player is killed by a creature
|
||||
virtual void OnPlayerKilledByCreature(Creature *killer, Player *killed);
|
||||
|
||||
// Called when a player's level changes (right before the level is applied)
|
||||
virtual void OnLevelChanged(Player *player, uint8 newLevel);
|
||||
|
||||
// Called when a player's free talent points change (right before the change is applied)
|
||||
virtual void OnFreeTalentPointsChanged(Player *player, uint32 points);
|
||||
|
||||
// Called when a player's talent points are reset (right before the reset is done)
|
||||
virtual void OnTalentsReset(Player *player, bool no_cost);
|
||||
};
|
||||
|
||||
// Placed here due to ScriptRegistry::AddScript dependency.
|
||||
#define sScriptMgr (*ACE_Singleton<ScriptMgr, ACE_Null_Mutex>::instance())
|
||||
|
||||
@@ -824,6 +851,14 @@ class ScriptMgr
|
||||
|
||||
bool OnCriteriaCheck(AchievementCriteriaData const* data, Player* source, Unit* target);
|
||||
|
||||
public: /* PlayerScript */
|
||||
void OnPVPKill(Player *killer, Player *killed);
|
||||
void OnCreatureKill(Player *killer, Creature *killed);
|
||||
void OnPlayerKilledByCreature(Creature *killer, Player *killed);
|
||||
void OnPlayerLevelChanged(Player *player, uint8 newLevel);
|
||||
void OnPlayerFreeTalentPointsChanged(Player *player, uint32 newPoints);
|
||||
void OnPlayerTalentsReset(Player *player, bool no_cost);
|
||||
|
||||
public: /* ScriptRegistry */
|
||||
|
||||
// This is the global static registry of scripts.
|
||||
|
||||
Reference in New Issue
Block a user