Skip to content

Commit

Permalink
[10748] Convert MonsterSay/Say and similar functions to ObjectGuid use.
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirMangos committed Nov 19, 2010
1 parent a346ca0 commit 9667406
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 85 deletions.
2 changes: 1 addition & 1 deletion src/bindings/universal/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI

void DoSay(int32 text_id, uint32 language)
{
m_creature->Say(text_id,language,0);
m_creature->Say(text_id, language, ObjectGuid());
}

void DoGoHome();
Expand Down
10 changes: 5 additions & 5 deletions src/game/Corpse.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ class Corpse : public WorldObject
Player* lootRecipient;
bool lootForBody;

void Say(int32 textId, uint32 language, uint64 TargetGuid) { MonsterSay(textId,language,TargetGuid); }
void Yell(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYell(textId,language,TargetGuid); }
void TextEmote(int32 textId, uint64 TargetGuid) { MonsterTextEmote(textId,TargetGuid); }
void Whisper(int32 textId,uint64 receiver) { MonsterWhisper(textId,receiver); }
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
void Say(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterSay(textId, language, targetGuid); }
void Yell(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYell(textId, language, targetGuid); }
void TextEmote(int32 textId, ObjectGuid targetGuid) { MonsterTextEmote(textId, targetGuid); }
void Whisper(int32 textId, ObjectGuid targetGuid) { MonsterWhisper(textId, targetGuid); }
void YellToZone(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYellToZone(textId,language, targetGuid); }

GridReference<Corpse> &GetGridRef() { return m_gridRef; }

Expand Down
10 changes: 5 additions & 5 deletions src/game/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,11 +524,11 @@ class MANGOS_DLL_SPEC Creature : public Unit
std::string GetScriptName() const;
uint32 GetScriptId() const;

void Say(int32 textId, uint32 language, uint64 TargetGuid) { MonsterSay(textId,language,TargetGuid); }
void Yell(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYell(textId,language,TargetGuid); }
void TextEmote(int32 textId, uint64 TargetGuid, bool IsBossEmote = false) { MonsterTextEmote(textId,TargetGuid,IsBossEmote); }
void Whisper(int32 textId, uint64 receiver, bool IsBossWhisper = false) { MonsterWhisper(textId,receiver,IsBossWhisper); }
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
void Say(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterSay(textId, language, targetGuid); }
void Yell(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYell(textId, language, targetGuid); }
void TextEmote(int32 textId, ObjectGuid targetGuid, bool IsBossEmote = false) { MonsterTextEmote(textId, targetGuid, IsBossEmote); }
void Whisper(int32 textId, ObjectGuid targetGuid, bool IsBossWhisper = false) { MonsterWhisper(textId, targetGuid, IsBossWhisper); }
void YellToZone(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYellToZone(textId, language, targetGuid); }

// overwrite WorldObject function for proper name localization
const char* GetNameForLocaleIdx(int32 locale_idx) const;
Expand Down
14 changes: 7 additions & 7 deletions src/game/CreatureEventAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,31 +1335,31 @@ void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit*
switch((*i).second.Type)
{
case CHAT_TYPE_SAY:
pSource->MonsterSay(textEntry, (*i).second.Language, target ? target->GetGUID() : 0);
pSource->MonsterSay(textEntry, (*i).second.Language, target ? target->GetObjectGuid() : ObjectGuid());
break;
case CHAT_TYPE_YELL:
pSource->MonsterYell(textEntry, (*i).second.Language, target ? target->GetGUID() : 0);
pSource->MonsterYell(textEntry, (*i).second.Language, target ? target->GetObjectGuid() : ObjectGuid());
break;
case CHAT_TYPE_TEXT_EMOTE:
pSource->MonsterTextEmote(textEntry, target ? target->GetGUID() : 0);
pSource->MonsterTextEmote(textEntry, target ? target->GetObjectGuid() : ObjectGuid());
break;
case CHAT_TYPE_BOSS_EMOTE:
pSource->MonsterTextEmote(textEntry, target ? target->GetGUID() : 0, true);
pSource->MonsterTextEmote(textEntry, target ? target->GetObjectGuid() : ObjectGuid(), true);
break;
case CHAT_TYPE_WHISPER:
{
if (target && target->GetTypeId() == TYPEID_PLAYER)
pSource->MonsterWhisper(textEntry, target->GetGUID());
pSource->MonsterWhisper(textEntry, target->GetObjectGuid());
else sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
}break;
case CHAT_TYPE_BOSS_WHISPER:
{
if (target && target->GetTypeId() == TYPEID_PLAYER)
pSource->MonsterWhisper(textEntry, target->GetGUID(), true);
pSource->MonsterWhisper(textEntry, target->GetObjectGuid(), true);
else sLog.outErrorDb("CreatureEventAI: DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
}break;
case CHAT_TYPE_ZONE_YELL:
pSource->MonsterYellToZone(textEntry, (*i).second.Language, target ? target->GetGUID() : 0);
pSource->MonsterYellToZone(textEntry, (*i).second.Language, target ? target->GetObjectGuid() : ObjectGuid());
break;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/game/DynamicObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ class DynamicObject : public WorldObject

bool isVisibleForInState(Player const* u, WorldObject const* viewPoint, bool inVisibleList) const;

void Say(int32 textId, uint32 language, uint64 TargetGuid) { MonsterSay(textId,language,TargetGuid); }
void Yell(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYell(textId,language,TargetGuid); }
void TextEmote(int32 textId, uint64 TargetGuid) { MonsterTextEmote(textId,TargetGuid); }
void Whisper(int32 textId,uint64 receiver) { MonsterWhisper(textId,receiver); }
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
void Say(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterSay(textId, language, targetGuid); }
void Yell(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYell(textId, language, targetGuid); }
void TextEmote(int32 textId, ObjectGuid targetGuid) { MonsterTextEmote(textId, targetGuid); }
void Whisper(int32 textId, ObjectGuid targetGuid) { MonsterWhisper(textId, targetGuid); }
void YellToZone(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYellToZone(textId, language, targetGuid); }

GridReference<DynamicObject> &GetGridRef() { return m_gridRef; }

Expand Down
10 changes: 5 additions & 5 deletions src/game/GameObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,11 +597,11 @@ class MANGOS_DLL_SPEC GameObject : public WorldObject

void UpdateRotationFields(float rotation2 = 0.0f, float rotation3 = 0.0f);

void Say(int32 textId, uint32 language, uint64 TargetGuid) { MonsterSay(textId,language,TargetGuid); }
void Yell(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYell(textId,language,TargetGuid); }
void TextEmote(int32 textId, uint64 TargetGuid) { MonsterTextEmote(textId,TargetGuid); }
void Whisper(int32 textId, uint64 receiver) { MonsterWhisper(textId,receiver); }
void YellToZone(int32 textId, uint32 language, uint64 TargetGuid) { MonsterYellToZone(textId,language,TargetGuid); }
void Say(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterSay(textId, language, targetGuid); }
void Yell(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYell(textId, language, targetGuid); }
void TextEmote(int32 textId, ObjectGuid targetGuid) { MonsterTextEmote(textId, targetGuid); }
void Whisper(int32 textId, ObjectGuid targetGuid) { MonsterWhisper(textId, targetGuid); }
void YellToZone(int32 textId, uint32 language, ObjectGuid targetGuid) { MonsterYellToZone(textId, language, targetGuid); }

// overwrite WorldObject function for proper name localization
const char* GetNameForLocaleIdx(int32 locale_idx) const;
Expand Down
8 changes: 4 additions & 4 deletions src/game/Level1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool ChatHandler::HandleNpcSayCommand(char* args)
return false;
}

pCreature->MonsterSay(args, LANG_UNIVERSAL, 0);
pCreature->MonsterSay(args, LANG_UNIVERSAL, ObjectGuid());

return true;
}
Expand All @@ -69,7 +69,7 @@ bool ChatHandler::HandleNpcYellCommand(char* args)
return false;
}

pCreature->MonsterYell(args, LANG_UNIVERSAL, 0);
pCreature->MonsterYell(args, LANG_UNIVERSAL, ObjectGuid());

return true;
}
Expand All @@ -89,7 +89,7 @@ bool ChatHandler::HandleNpcTextEmoteCommand(char* args)
return false;
}

pCreature->MonsterTextEmote(args, 0);
pCreature->MonsterTextEmote(args, ObjectGuid());

return true;
}
Expand All @@ -114,7 +114,7 @@ bool ChatHandler::HandleNpcWhisperCommand(char* args)
if (HasLowerSecurity(target, 0))
return false;

pCreature->MonsterWhisper(args, target->GetGUID());
pCreature->MonsterWhisper(args, target->GetObjectGuid());

return true;
}
Expand Down
79 changes: 39 additions & 40 deletions src/game/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1532,36 +1532,35 @@ bool WorldObject::IsPositionValid() const
return MaNGOS::IsValidMapCoord(m_positionX,m_positionY,m_positionZ,m_orientation);
}

void WorldObject::MonsterSay(const char* text, uint32 language, uint64 TargetGuid)
void WorldObject::MonsterSay(const char* text, uint32 language, ObjectGuid targetGuid)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data,CHAT_MSG_MONSTER_SAY,text,language,GetName(),TargetGuid);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_SAY, text, language, GetName(), targetGuid);
SendMessageToSetInRange(&data,sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_SAY),true);
}

void WorldObject::MonsterYell(const char* text, uint32 language, uint64 TargetGuid)
void WorldObject::MonsterYell(const char* text, uint32 language, ObjectGuid targetGuid)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data,CHAT_MSG_MONSTER_YELL,text,language,GetName(),TargetGuid);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_YELL, text, language, GetName(), targetGuid);
SendMessageToSetInRange(&data,sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_YELL),true);
}

void WorldObject::MonsterTextEmote(const char* text, uint64 TargetGuid, bool IsBossEmote)
void WorldObject::MonsterTextEmote(const char* text, ObjectGuid targetGuid, bool IsBossEmote)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data,IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE,text,LANG_UNIVERSAL,GetName(),TargetGuid);
BuildMonsterChat(&data, IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, text, LANG_UNIVERSAL, GetName(), targetGuid);
SendMessageToSetInRange(&data,sWorld.getConfig(IsBossEmote ? CONFIG_FLOAT_LISTEN_RANGE_YELL : CONFIG_FLOAT_LISTEN_RANGE_TEXTEMOTE),true);
}

void WorldObject::MonsterWhisper(const char* text, uint64 receiver, bool IsBossWhisper)
void WorldObject::MonsterWhisper(const char* text, ObjectGuid targetGuid, bool IsBossWhisper)
{
Player *player = sObjectMgr.GetPlayer(receiver);
if(!player || !player->GetSession())
Player *player = sObjectMgr.GetPlayer(targetGuid);
if (!player || !player->GetSession())
return;

WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data,IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER,text,LANG_UNIVERSAL,GetName(),receiver);

BuildMonsterChat(&data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, text, LANG_UNIVERSAL, GetName(), targetGuid);
player->GetSession()->SendPacket(&data);
}

Expand All @@ -1570,47 +1569,47 @@ namespace MaNGOS
class MonsterChatBuilder
{
public:
MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, uint32 language, uint64 targetGUID)
: i_object(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_targetGUID(targetGUID) {}
MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, uint32 language, ObjectGuid targetGuid)
: i_object(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_targetGuid(targetGuid) {}
void operator()(WorldPacket& data, int32 loc_idx)
{
char const* text = sObjectMgr.GetMangosString(i_textId,loc_idx);

// TODO: i_object.GetName() also must be localized?
i_object.BuildMonsterChat(&data,i_msgtype,text,i_language,i_object.GetNameForLocaleIdx(loc_idx),i_targetGUID);
i_object.BuildMonsterChat(&data, i_msgtype, text, i_language, i_object.GetNameForLocaleIdx(loc_idx), i_targetGuid);
}

private:
WorldObject const& i_object;
ChatMsg i_msgtype;
int32 i_textId;
uint32 i_language;
uint64 i_targetGUID;
ObjectGuid i_targetGuid;
};
} // namespace MaNGOS

void WorldObject::MonsterSay(int32 textId, uint32 language, uint64 TargetGuid)
void WorldObject::MonsterSay(int32 textId, uint32 language, ObjectGuid targetGuid)
{
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, textId,language,TargetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, textId, language, targetGuid);
MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> say_do(say_build);
MaNGOS::CameraDistWorker<MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> > say_worker(this,sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_SAY),say_do);
Cell::VisitWorldObjects(this, say_worker, sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_SAY));
}

void WorldObject::MonsterYell(int32 textId, uint32 language, uint64 TargetGuid)
void WorldObject::MonsterYell(int32 textId, uint32 language, ObjectGuid targetGuid)
{

float range = sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_YELL);

MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId,language,TargetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId, language, targetGuid);
MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> say_do(say_build);
MaNGOS::CameraDistWorker<MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> > say_worker(this,range,say_do);
Cell::VisitWorldObjects(this, say_worker, sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_YELL));
}

void WorldObject::MonsterYellToZone(int32 textId, uint32 language, uint64 TargetGuid)
void WorldObject::MonsterYellToZone(int32 textId, uint32 language, ObjectGuid targetGuid)
{
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId,language,TargetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId, language, targetGuid);
MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> say_do(say_build);

uint32 zoneid = GetZoneId();
Expand All @@ -1621,48 +1620,48 @@ void WorldObject::MonsterYellToZone(int32 textId, uint32 language, uint64 Target
say_do(itr->getSource());
}

void WorldObject::MonsterTextEmote(int32 textId, uint64 TargetGuid, bool IsBossEmote)
void WorldObject::MonsterTextEmote(int32 textId, ObjectGuid targetGuid, bool IsBossEmote)
{
float range = sWorld.getConfig(IsBossEmote ? CONFIG_FLOAT_LISTEN_RANGE_YELL : CONFIG_FLOAT_LISTEN_RANGE_TEXTEMOTE);

MaNGOS::MonsterChatBuilder say_build(*this, IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, textId,LANG_UNIVERSAL,TargetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, textId, LANG_UNIVERSAL, targetGuid);
MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> say_do(say_build);
MaNGOS::CameraDistWorker<MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> > say_worker(this,range,say_do);
Cell::VisitWorldObjects(this, say_worker, range);
}

void WorldObject::MonsterWhisper(int32 textId, uint64 receiver, bool IsBossWhisper)
void WorldObject::MonsterWhisper(int32 textId, ObjectGuid targetGuid, bool IsBossWhisper)
{
Player *player = sObjectMgr.GetPlayer(receiver);
if(!player || !player->GetSession())
Player *player = sObjectMgr.GetPlayer(targetGuid);
if (!player || !player->GetSession())
return;

uint32 loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
char const* text = sObjectMgr.GetMangosString(textId,loc_idx);
char const* text = sObjectMgr.GetMangosString(textId, loc_idx);

WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data,IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER,text,LANG_UNIVERSAL,GetNameForLocaleIdx(loc_idx),receiver);
BuildMonsterChat(&data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, text, LANG_UNIVERSAL, GetNameForLocaleIdx(loc_idx), targetGuid);

player->GetSession()->SendPacket(&data);
}

void WorldObject::BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, uint64 targetGuid) const
void WorldObject::BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, ObjectGuid targetGuid) const
{
*data << (uint8)msgtype;
*data << (uint32)language;
*data << (uint64)GetGUID();
*data << (uint32)0; // 2.1.0
*data << (uint32)(strlen(name)+1);
*data << uint8(msgtype);
*data << uint32(language);
*data << ObjectGuid(GetObjectGuid());
*data << uint32(0); // 2.1.0
*data << uint32(strlen(name)+1);
*data << name;
*data << (uint64)targetGuid; // Unit Target
if( targetGuid && !IS_PLAYER_GUID(targetGuid) )
*data << ObjectGuid(targetGuid); // Unit Target
if (!targetGuid.IsEmpty() && !targetGuid.IsPlayer())
{
*data << (uint32)1; // target name length
*data << (uint8)0; // target name
*data << uint32(1); // target name length
*data << uint8(0); // target name
}
*data << (uint32)(strlen(text)+1);
*data << uint32(strlen(text)+1);
*data << text;
*data << (uint8)0; // ChatTag
*data << uint8(0); // ChatTag
}

void WorldObject::SendMessageToSet(WorldPacket *data, bool /*bToSelf*/)
Expand Down

0 comments on commit 9667406

Please sign in to comment.