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:
@@ -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