[10761] Basic support for target-name in MonsterSay/etc

Change MonsterSay's target to pointer.

Signed-off-by: VladimirMangos <vladimir@getmangos.com>
This commit is contained in:
Schmoozerd 2010-11-20 20:37:21 +03:00 committed by VladimirMangos
parent 146e7d3970
commit 16cd545df8
9 changed files with 72 additions and 72 deletions

View file

@ -123,7 +123,7 @@ struct MANGOS_DLL_DECL ScriptedAI : public CreatureAI
void DoSay(int32 text_id, uint32 language)
{
m_creature->MonsterSay(text_id, language, ObjectGuid());
m_creature->MonsterSay(text_id, language);
}
void DoGoHome();

View file

@ -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->GetObjectGuid() : ObjectGuid());
pSource->MonsterSay(textEntry, (*i).second.Language, target);
break;
case CHAT_TYPE_YELL:
pSource->MonsterYell(textEntry, (*i).second.Language, target ? target->GetObjectGuid() : ObjectGuid());
pSource->MonsterYell(textEntry, (*i).second.Language, target);
break;
case CHAT_TYPE_TEXT_EMOTE:
pSource->MonsterTextEmote(textEntry, target ? target->GetObjectGuid() : ObjectGuid());
pSource->MonsterTextEmote(textEntry, target);
break;
case CHAT_TYPE_BOSS_EMOTE:
pSource->MonsterTextEmote(textEntry, target ? target->GetObjectGuid() : ObjectGuid(), true);
pSource->MonsterTextEmote(textEntry, target, true);
break;
case CHAT_TYPE_WHISPER:
{
if (target && target->GetTypeId() == TYPEID_PLAYER)
pSource->MonsterWhisper(textEntry, target->GetObjectGuid());
pSource->MonsterWhisper(textEntry, target);
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->GetObjectGuid(), true);
pSource->MonsterWhisper(textEntry, target, 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->GetObjectGuid() : ObjectGuid());
pSource->MonsterYellToZone(textEntry, (*i).second.Language, target);
break;
}
}

View file

@ -1020,7 +1020,7 @@ void GameObject::Use(Unit* user)
Creature* helper = player->SummonCreature(14496, x_i, y_i, GetPositionZ(), GetOrientation(), TEMPSUMMON_TIMED_OR_DEAD_DESPAWN, 10000);
std::ostringstream output;
output << i << ": thisDist: " << thisDistance;
helper->MonsterSay(output.str().c_str(), LANG_UNIVERSAL, 0);
helper->MonsterSay(output.str().c_str(), LANG_UNIVERSAL);
*/
if (thisDistance <= lowestDist)

View file

@ -51,7 +51,7 @@ bool ChatHandler::HandleNpcSayCommand(char* args)
return false;
}
pCreature->MonsterSay(args, LANG_UNIVERSAL, ObjectGuid());
pCreature->MonsterSay(args, LANG_UNIVERSAL);
return true;
}
@ -69,7 +69,7 @@ bool ChatHandler::HandleNpcYellCommand(char* args)
return false;
}
pCreature->MonsterYell(args, LANG_UNIVERSAL, ObjectGuid());
pCreature->MonsterYell(args, LANG_UNIVERSAL);
return true;
}
@ -89,7 +89,7 @@ bool ChatHandler::HandleNpcTextEmoteCommand(char* args)
return false;
}
pCreature->MonsterTextEmote(args, ObjectGuid());
pCreature->MonsterTextEmote(args, NULL);
return true;
}
@ -114,7 +114,7 @@ bool ChatHandler::HandleNpcWhisperCommand(char* args)
if (HasLowerSecurity(target, 0))
return false;
pCreature->MonsterWhisper(args, target->GetObjectGuid());
pCreature->MonsterWhisper(args, target);
return true;
}

View file

@ -1877,7 +1877,7 @@ void Map::ScriptsProcess()
if (step.script->talk.flags & 0x02)
target = source;
ObjectGuid unitTargetGuid = target ? target->GetObjectGuid() : ObjectGuid();
Unit* unitTarget = target && target->isType(TYPEMASK_UNIT) ? static_cast<Unit*>(target) : NULL;
int32 textId = step.script->talk.textId[0];
// May have text for random
@ -1897,35 +1897,35 @@ void Map::ScriptsProcess()
switch(step.script->talk.chatType)
{
case CHAT_TYPE_SAY:
pSource->MonsterSay(textId, step.script->talk.language, unitTargetGuid);
pSource->MonsterSay(textId, step.script->talk.language, unitTarget);
break;
case CHAT_TYPE_YELL:
pSource->MonsterYell(textId, step.script->talk.language, unitTargetGuid);
pSource->MonsterYell(textId, step.script->talk.language, unitTarget);
break;
case CHAT_TYPE_TEXT_EMOTE:
pSource->MonsterTextEmote(textId, unitTargetGuid);
pSource->MonsterTextEmote(textId, unitTarget);
break;
case CHAT_TYPE_BOSS_EMOTE:
pSource->MonsterTextEmote(textId, unitTargetGuid, true);
pSource->MonsterTextEmote(textId, unitTarget, true);
break;
case CHAT_TYPE_WHISPER:
if (!unitTargetGuid.IsPlayer())
if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
{
sLog.outError("SCRIPT_COMMAND_TALK (script id %u) attempt to whisper (%u) to %s, skipping.", step.script->id, step.script->talk.chatType, unitTargetGuid.GetString().c_str());
sLog.outError("SCRIPT_COMMAND_TALK (script id %u) attempt to whisper (%u) to %s, skipping.", step.script->id, step.script->talk.chatType, unitTarget ? unitTarget->GetObjectGuid().GetString().c_str() : "<no target>");
break;
}
pSource->MonsterWhisper(textId, unitTargetGuid);
pSource->MonsterWhisper(textId, unitTarget);
break;
case CHAT_TYPE_BOSS_WHISPER:
if (!unitTargetGuid.IsPlayer())
if (!unitTarget || unitTarget->GetTypeId() != TYPEID_PLAYER)
{
sLog.outError("SCRIPT_COMMAND_TALK (script id %u) attempt to whisper (%u) to %s, skipping.", step.script->id, step.script->talk.chatType, unitTargetGuid.GetString().c_str());
sLog.outError("SCRIPT_COMMAND_TALK (script id %u) attempt to whisper (%u) to %s, skipping.", step.script->id, step.script->talk.chatType, unitTarget ? unitTarget->GetObjectGuid().GetString().c_str() : "<no target>");
break;
}
pSource->MonsterWhisper(textId, unitTargetGuid, true);
pSource->MonsterWhisper(textId, unitTarget, true);
break;
case CHAT_TYPE_ZONE_YELL:
pSource->MonsterYellToZone(textId, step.script->talk.language, unitTargetGuid);
pSource->MonsterYellToZone(textId, step.script->talk.language, unitTarget);
break;
default:
break; // must be already checked at load

View file

@ -1540,36 +1540,37 @@ bool WorldObject::IsPositionValid() const
return MaNGOS::IsValidMapCoord(m_positionX,m_positionY,m_positionZ,m_orientation);
}
void WorldObject::MonsterSay(const char* text, uint32 language, ObjectGuid targetGuid)
void WorldObject::MonsterSay(const char* text, uint32 language, Unit* target)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_SAY, text, language, GetName(), targetGuid);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_SAY, text, language, GetName(), target ? target->GetObjectGuid() : ObjectGuid(), target ? target->GetName() : "");
SendMessageToSetInRange(&data,sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_SAY),true);
}
void WorldObject::MonsterYell(const char* text, uint32 language, ObjectGuid targetGuid)
void WorldObject::MonsterYell(const char* text, uint32 language, Unit* target)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_YELL, text, language, GetName(), targetGuid);
BuildMonsterChat(&data, CHAT_MSG_MONSTER_YELL, text, language, GetName(), target ? target->GetObjectGuid() : ObjectGuid(), target ? target->GetName() : "");
SendMessageToSetInRange(&data,sWorld.getConfig(CONFIG_FLOAT_LISTEN_RANGE_YELL),true);
}
void WorldObject::MonsterTextEmote(const char* text, ObjectGuid targetGuid, bool IsBossEmote)
void WorldObject::MonsterTextEmote(const char* text, Unit* target, bool IsBossEmote)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
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);
BuildMonsterChat(&data, IsBossEmote ? CHAT_MSG_RAID_BOSS_EMOTE : CHAT_MSG_MONSTER_EMOTE, text, LANG_UNIVERSAL,
GetName(), target ? target->GetObjectGuid() : ObjectGuid(), target ? target->GetName() : "");
SendMessageToSetInRange(&data, sWorld.getConfig(IsBossEmote ? CONFIG_FLOAT_LISTEN_RANGE_YELL : CONFIG_FLOAT_LISTEN_RANGE_TEXTEMOTE), true);
}
void WorldObject::MonsterWhisper(const char* text, ObjectGuid targetGuid, bool IsBossWhisper)
void WorldObject::MonsterWhisper(const char* text, Unit* target, bool IsBossWhisper)
{
Player *player = sObjectMgr.GetPlayer(targetGuid);
if (!player || !player->GetSession())
if (!target || target->GetTypeId() != TYPEID_PLAYER)
return;
WorldPacket data(SMSG_MESSAGECHAT, 200);
BuildMonsterChat(&data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, text, LANG_UNIVERSAL, GetName(), targetGuid);
player->GetSession()->SendPacket(&data);
BuildMonsterChat(&data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, text, LANG_UNIVERSAL,
GetName(), target->GetObjectGuid(), target->GetName());
((Player*)target)->GetSession()->SendPacket(&data);
}
namespace MaNGOS
@ -1577,14 +1578,13 @@ namespace MaNGOS
class MonsterChatBuilder
{
public:
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) {}
MonsterChatBuilder(WorldObject const& obj, ChatMsg msgtype, int32 textId, uint32 language, Unit* target)
: i_object(obj), i_msgtype(msgtype), i_textId(textId), i_language(language), i_target(target) {}
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_target ? i_target->GetObjectGuid() : ObjectGuid(), i_target ? i_target->GetNameForLocaleIdx(loc_idx) : "");
}
private:
@ -1592,32 +1592,32 @@ namespace MaNGOS
ChatMsg i_msgtype;
int32 i_textId;
uint32 i_language;
ObjectGuid i_targetGuid;
Unit* i_target;
};
} // namespace MaNGOS
void WorldObject::MonsterSay(int32 textId, uint32 language, ObjectGuid targetGuid)
void WorldObject::MonsterSay(int32 textId, uint32 language, Unit* target)
{
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, textId, language, targetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_SAY, textId, language, target);
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, ObjectGuid targetGuid)
void WorldObject::MonsterYell(int32 textId, uint32 language, Unit* target)
{
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, target);
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, ObjectGuid targetGuid)
void WorldObject::MonsterYellToZone(int32 textId, uint32 language, Unit* target)
{
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId, language, targetGuid);
MaNGOS::MonsterChatBuilder say_build(*this, CHAT_MSG_MONSTER_YELL, textId, language, target);
MaNGOS::LocalizedPacketDo<MaNGOS::MonsterChatBuilder> say_do(say_build);
uint32 zoneid = GetZoneId();
@ -1628,32 +1628,32 @@ void WorldObject::MonsterYellToZone(int32 textId, uint32 language, ObjectGuid ta
say_do(itr->getSource());
}
void WorldObject::MonsterTextEmote(int32 textId, ObjectGuid targetGuid, bool IsBossEmote)
void WorldObject::MonsterTextEmote(int32 textId, Unit* target, 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, target);
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, ObjectGuid targetGuid, bool IsBossWhisper)
void WorldObject::MonsterWhisper(int32 textId, Unit* target, bool IsBossWhisper)
{
Player *player = sObjectMgr.GetPlayer(targetGuid);
if (!player || !player->GetSession())
if (!target || target->GetTypeId() != TYPEID_PLAYER)
return;
uint32 loc_idx = player->GetSession()->GetSessionDbLocaleIndex();
uint32 loc_idx = ((Player*)target)->GetSession()->GetSessionDbLocaleIndex();
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), targetGuid);
BuildMonsterChat(&data, IsBossWhisper ? CHAT_MSG_RAID_BOSS_WHISPER : CHAT_MSG_MONSTER_WHISPER, text, LANG_UNIVERSAL,
GetNameForLocaleIdx(loc_idx), target->GetObjectGuid(), "");
player->GetSession()->SendPacket(&data);
((Player*)target)->GetSession()->SendPacket(&data);
}
void WorldObject::BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, ObjectGuid targetGuid) const
void WorldObject::BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, ObjectGuid targetGuid, char const* targetName) const
{
*data << uint8(msgtype);
*data << uint32(language);
@ -1664,8 +1664,8 @@ void WorldObject::BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const*
*data << ObjectGuid(targetGuid); // Unit Target
if (!targetGuid.IsEmpty() && !targetGuid.IsPlayer())
{
*data << uint32(1); // target name length
*data << uint8(0); // target name
*data << uint32(strlen(targetName)+1); // target name length
*data << targetName; // target name
}
*data << uint32(strlen(text)+1);
*data << text;

View file

@ -444,16 +444,16 @@ class MANGOS_DLL_SPEC WorldObject : public Object
virtual void SendMessageToSetInRange(WorldPacket *data, float dist, bool self);
void SendMessageToSetExcept(WorldPacket *data, Player const* skipped_receiver);
void MonsterSay(const char* text, uint32 language, ObjectGuid targetGuid);
void MonsterYell(const char* text, uint32 language, ObjectGuid targetGuid);
void MonsterTextEmote(const char* text, ObjectGuid targetGuid, bool IsBossEmote = false);
void MonsterWhisper(const char* text, ObjectGuid targetGuid, bool IsBossWhisper = false);
void MonsterSay(int32 textId, uint32 language, ObjectGuid targetGuid);
void MonsterYell(int32 textId, uint32 language, ObjectGuid targetGuid);
void MonsterTextEmote(int32 textId, ObjectGuid targetGuid, bool IsBossEmote = false);
void MonsterWhisper(int32 textId, ObjectGuid targetGuid, bool IsBossWhisper = false);
void MonsterYellToZone(int32 textId, uint32 language, ObjectGuid targetGuid);
void BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, ObjectGuid targetGuid) const;
void MonsterSay(const char* text, uint32 language, Unit* target = NULL);
void MonsterYell(const char* text, uint32 language, Unit* target = NULL);
void MonsterTextEmote(const char* text, Unit* target, bool IsBossEmote = false);
void MonsterWhisper(const char* text, Unit* target, bool IsBossWhisper = false);
void MonsterSay(int32 textId, uint32 language, Unit* target = NULL);
void MonsterYell(int32 textId, uint32 language, Unit* target = NULL);
void MonsterTextEmote(int32 textId, Unit* target, bool IsBossEmote = false);
void MonsterWhisper(int32 textId, Unit* receiver, bool IsBossWhisper = false);
void MonsterYellToZone(int32 textId, uint32 language, Unit* target);
void BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, ObjectGuid targetGuid, char const* targetName) const;
void PlayDistanceSound(uint32 sound_id, Player* target = NULL);
void PlayDirectSound(uint32 sound_id, Player* target = NULL);

View file

@ -220,10 +220,10 @@ bool WaypointMovementGenerator<Creature>::Update(Creature &creature, const uint3
break;
}
creature.MonsterSay(behavior->textid[rand() % i], LANG_UNIVERSAL, ObjectGuid());
creature.MonsterSay(behavior->textid[rand() % i], LANG_UNIVERSAL);
}
else
creature.MonsterSay(behavior->textid[0], LANG_UNIVERSAL, ObjectGuid());
creature.MonsterSay(behavior->textid[0], LANG_UNIVERSAL);
}
} // wpBehaviour found

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10760"
#define REVISION_NR "10761"
#endif // __REVISION_NR_H__