mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-16 07:30:42 +01:00
Add PlayerScript hooks:
* OnMoneyChanged * OnGiveXP * OnReputationChange * OnChat * OnEmote * OnTextEmote --HG-- branch : trunk
This commit is contained in:
@@ -2614,6 +2614,8 @@ void Player::GiveXP(uint32 xp, Unit* victim)
|
||||
|
||||
uint8 level = getLevel();
|
||||
|
||||
sScriptMgr.OnGivePlayerXP(this, xp, victim);
|
||||
|
||||
// Favored experience increase START
|
||||
uint32 zone = GetZoneId();
|
||||
float favored_exp_mult = 0;
|
||||
@@ -20707,6 +20709,28 @@ void Player::InitPrimaryProfessions()
|
||||
SetFreePrimaryProfessions(sWorld.getConfig(CONFIG_MAX_PRIMARY_TRADE_SKILL));
|
||||
}
|
||||
|
||||
void Player::ModifyMoney(int32 d)
|
||||
{
|
||||
sScriptMgr.OnPlayerMoneyChanged(this, d);
|
||||
|
||||
if (d < 0)
|
||||
SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0);
|
||||
else
|
||||
{
|
||||
uint32 newAmount = 0;
|
||||
if (GetMoney() < uint32(MAX_MONEY_AMOUNT - d))
|
||||
newAmount = GetMoney() + d;
|
||||
else
|
||||
{
|
||||
// "At Gold Limit"
|
||||
newAmount = MAX_MONEY_AMOUNT;
|
||||
if (d)
|
||||
SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
|
||||
}
|
||||
SetMoney (newAmount);
|
||||
}
|
||||
}
|
||||
|
||||
Unit * Player::GetSelectedUnit() const
|
||||
{
|
||||
if (m_curSelection)
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "ItemPrototype.h"
|
||||
#include "Unit.h"
|
||||
#include "Item.h"
|
||||
|
||||
#include "DatabaseEnv.h"
|
||||
#include "NPCHandler.h"
|
||||
#include "QuestDef.h"
|
||||
@@ -1447,25 +1446,8 @@ class Player : public Unit, public GridObject<Player>
|
||||
void setWeaponChangeTimer(uint32 time) {m_weaponChangeTimer = time;}
|
||||
|
||||
uint32 GetMoney() { return GetUInt32Value (PLAYER_FIELD_COINAGE); }
|
||||
void ModifyMoney(int32 d)
|
||||
{
|
||||
if (d < 0)
|
||||
SetMoney (GetMoney() > uint32(-d) ? GetMoney() + d : 0);
|
||||
else
|
||||
{
|
||||
uint32 newAmount = 0;
|
||||
if (GetMoney() < uint32(MAX_MONEY_AMOUNT - d))
|
||||
newAmount = GetMoney() + d;
|
||||
else
|
||||
{
|
||||
// "At Gold Limit"
|
||||
newAmount = MAX_MONEY_AMOUNT;
|
||||
if (d)
|
||||
SendEquipError(EQUIP_ERR_TOO_MUCH_GOLD, NULL, NULL);
|
||||
}
|
||||
SetMoney (newAmount);
|
||||
}
|
||||
}
|
||||
void ModifyMoney(int32 d);
|
||||
|
||||
void SetMoney(uint32 value)
|
||||
{
|
||||
SetUInt32Value (PLAYER_FIELD_COINAGE, value);
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "WorldPacket.h"
|
||||
#include "World.h"
|
||||
#include "ObjectMgr.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
const int32 ReputationMgr::PointsInRank[MAX_REPUTATION_RANK] = {36000, 3000, 3000, 3000, 6000, 12000, 21000, 1000};
|
||||
|
||||
@@ -251,6 +252,8 @@ void ReputationMgr::Initialize()
|
||||
|
||||
bool ReputationMgr::SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental)
|
||||
{
|
||||
sScriptMgr.OnPlayerReputationChange(m_player, factionEntry->ID, standing, incremental);
|
||||
|
||||
if (SimpleFactionsList const* flist = GetFactionTeamList(factionEntry->ID))
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
@@ -1097,6 +1097,36 @@ void ScriptMgr::OnPlayerTalentsReset(Player *player, bool no_cost)
|
||||
FOREACH_SCRIPT(PlayerScript)->OnTalentsReset(player, no_cost);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerMoneyChanged(Player *player, int32& amount)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnMoneyChanged(player, amount);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnGivePlayerXP(Player *player, uint32& amount, Unit *victim)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnGiveXP(player, amount, victim);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerReputationChange(Player *player, uint32 factionID, int32& standing, bool incremental)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnReputationChange(player, factionID, standing, incremental);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerChat(WorldSession *session, uint32 type, uint32 lang, std::string msg, std::string toOrChannel)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnChat(session, type, lang, msg, toOrChannel);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerEmote(WorldSession *session, uint32 emote)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnEmote(session, emote);
|
||||
}
|
||||
|
||||
void ScriptMgr::OnPlayerTextEmote(WorldSession *session, uint32 text_emote, uint32 emoteNum, uint64 guid)
|
||||
{
|
||||
FOREACH_SCRIPT(PlayerScript)->OnTextEmote(session, text_emote, emoteNum, guid);
|
||||
}
|
||||
|
||||
SpellHandlerScript::SpellHandlerScript(const char* name)
|
||||
: ScriptObject(name)
|
||||
{
|
||||
|
||||
@@ -677,6 +677,22 @@ public:
|
||||
|
||||
// Called when a player's talent points are reset (right before the reset is done)
|
||||
virtual void OnTalentsReset(Player *player, bool no_cost) { }
|
||||
|
||||
// Called when a player's money is modified (before the modification is done)
|
||||
virtual void OnMoneyChanged(Player *player, int32& amount) { }
|
||||
|
||||
// Called when a player gains XP (before anything is given)
|
||||
virtual void OnGiveXP(Player *player, uint32& amount, Unit *victim) { }
|
||||
|
||||
// Called when a player's reputation changes (before it is actually changed)
|
||||
virtual void OnReputationChange(Player *player, uint32 factionID, int32& standing, bool incremental) { }
|
||||
|
||||
// Called when a player sends a chat message. toOrChannel is empty when type is neither whisper nor channel
|
||||
virtual void OnChat(WorldSession *session, uint32 type, uint32 lang, std::string msg, std::string toOrChannel) { }
|
||||
|
||||
// Both of the below are called on emote opcodes
|
||||
virtual void OnEmote(WorldSession *session, uint32 emote) { }
|
||||
virtual void OnTextEmote(WorldSession *session, uint32 text_emote, uint32 emoteNum, uint64 guid) { }
|
||||
};
|
||||
|
||||
// Placed here due to ScriptRegistry::AddScript dependency.
|
||||
@@ -858,6 +874,12 @@ class ScriptMgr
|
||||
void OnPlayerLevelChanged(Player *player, uint8 newLevel);
|
||||
void OnPlayerFreeTalentPointsChanged(Player *player, uint32 newPoints);
|
||||
void OnPlayerTalentsReset(Player *player, bool no_cost);
|
||||
void OnPlayerMoneyChanged(Player *player, int32& amount);
|
||||
void OnGivePlayerXP(Player *player, uint32& amount, Unit *victim);
|
||||
void OnPlayerReputationChange(Player *player, uint32 factionID, int32& standing, bool incremental);
|
||||
void OnPlayerChat(WorldSession *session, uint32 type, uint32 lang, std::string msg, std::string toOrChannel);
|
||||
void OnPlayerEmote(WorldSession *session, uint32 emote);
|
||||
void OnPlayerTextEmote(WorldSession *session, uint32 text_emote, uint32 emoteNum, uint64 guid);
|
||||
|
||||
public: /* ScriptRegistry */
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "SpellAuras.h"
|
||||
#include "SpellAuraEffects.h"
|
||||
#include "Util.h"
|
||||
#include "ScriptMgr.h"
|
||||
|
||||
bool WorldSession::processChatmessageFurtherAfterSecurityChecks(std::string& msg, uint32 lang)
|
||||
{
|
||||
@@ -192,6 +193,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -224,6 +226,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
std::string to, msg;
|
||||
recv_data >> to;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, to);
|
||||
|
||||
if (_player->getLevel() < sWorld.getConfig(CONFIG_CHAT_WHISPER_LEVEL_REQ))
|
||||
{
|
||||
@@ -277,6 +280,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -315,6 +319,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -353,6 +358,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -383,6 +389,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -417,6 +424,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty())
|
||||
break;
|
||||
@@ -451,6 +459,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (!processChatmessageFurtherAfterSecurityChecks(msg, lang))
|
||||
return;
|
||||
@@ -476,6 +485,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (!processChatmessageFurtherAfterSecurityChecks(msg, lang))
|
||||
return;
|
||||
@@ -501,6 +511,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (!processChatmessageFurtherAfterSecurityChecks(msg, lang))
|
||||
return;
|
||||
@@ -527,6 +538,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
std::string channel, msg;
|
||||
recv_data >> channel;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, channel);
|
||||
|
||||
if (!processChatmessageFurtherAfterSecurityChecks(msg, lang))
|
||||
return;
|
||||
@@ -565,6 +577,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if ((msg.empty() || !_player->isAFK()) && !_player->isInCombat())
|
||||
{
|
||||
@@ -584,6 +597,7 @@ void WorldSession::HandleMessagechatOpcode(WorldPacket & recv_data)
|
||||
{
|
||||
std::string msg;
|
||||
recv_data >> msg;
|
||||
sScriptMgr.OnPlayerChat(this, type, lang, msg, "");
|
||||
|
||||
if (msg.empty() || !_player->isDND())
|
||||
{
|
||||
@@ -612,6 +626,7 @@ void WorldSession::HandleEmoteOpcode(WorldPacket & recv_data)
|
||||
|
||||
uint32 emote;
|
||||
recv_data >> emote;
|
||||
sScriptMgr.OnPlayerEmote(this, emote);
|
||||
GetPlayer()->HandleEmoteCommand(emote);
|
||||
}
|
||||
|
||||
@@ -666,6 +681,8 @@ void WorldSession::HandleTextEmoteOpcode(WorldPacket & recv_data)
|
||||
recv_data >> emoteNum;
|
||||
recv_data >> guid;
|
||||
|
||||
sScriptMgr.OnPlayerTextEmote(this, text_emote, emoteNum, guid);
|
||||
|
||||
EmotesTextEntry const *em = sEmotesTextStore.LookupEntry(text_emote);
|
||||
if (!em)
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user