mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 00:18:43 +01:00
Core/Scripts/SmartAI: add test for TextMgr (temp)
Core/CreatureTextMgr: added basic chat function, you can now experiment with it if bored --HG-- branch : trunk
This commit is contained in:
@@ -25,15 +25,17 @@
|
||||
#include "ObjectDefines.h"
|
||||
#include "GridDefines.h"
|
||||
#include "ConditionMgr.h"
|
||||
#include "CreatureTextMgr.h"
|
||||
|
||||
void SmartAIMgr::LoadSmartAIFromDB()
|
||||
{
|
||||
//Drop Existing SmartAI List
|
||||
}
|
||||
|
||||
SmartAI::SmartAI(Creature *c) : CreatureAI(c), me(c)
|
||||
SmartAI::SmartAI(Creature *c) : CreatureAI(c)
|
||||
{
|
||||
// copy script to local (pretection for table reload)
|
||||
mTestTimer = 0;
|
||||
}
|
||||
|
||||
int SmartAI::Permissible(const Creature *creature)
|
||||
@@ -45,6 +47,11 @@ int SmartAI::Permissible(const Creature *creature)
|
||||
|
||||
void SmartAI::UpdateAI(const uint32 diff)
|
||||
{
|
||||
if (mTestTimer < diff)
|
||||
{
|
||||
mTestTimer = 60000;
|
||||
sCreatureTextMgr.SendChat(me,"CHAT_TYPE_SAY", CHAT_TYPE_SAY);
|
||||
} else mTestTimer -= diff;
|
||||
}
|
||||
|
||||
void SmartAI::JustRespawned()
|
||||
|
||||
@@ -50,6 +50,8 @@ void setinhabittype
|
||||
|
||||
event change flags
|
||||
|
||||
need a local SendChat()
|
||||
|
||||
*/
|
||||
|
||||
//temp copied from eai, will be modded
|
||||
@@ -247,9 +249,6 @@ class SmartAIMgr
|
||||
|
||||
class SmartAI : public CreatureAI
|
||||
{
|
||||
protected:
|
||||
Creature * const me;
|
||||
|
||||
public:
|
||||
~SmartAI(){};
|
||||
explicit SmartAI(Creature *c);
|
||||
@@ -363,6 +362,7 @@ class SmartAI : public CreatureAI
|
||||
void SetMovePathEndAction(SMARTAI_ACTION action = SMART_ACTION_FORCE_DESPAWN);
|
||||
|
||||
private:
|
||||
uint32 mTestTimer;
|
||||
};
|
||||
|
||||
#define sSmartAIMgr (*ACE_Singleton<SmartAIMgr, ACE_Null_Mutex>::instance())
|
||||
|
||||
@@ -107,3 +107,136 @@ void CreatureTextMgr::LoadCreatureTexts()
|
||||
sLog.outString();
|
||||
sLog.outString(">> Loaded %u Creature Texts for %u Creatures.", TextCount, CreatureCount);
|
||||
}
|
||||
|
||||
void CreatureTextMgr::SendChat(WorldObject* source, char const* text, ChatType msgtype, Language language, uint64 whisperGuid, TextRange range) const
|
||||
{
|
||||
WorldPacket data(SMSG_MESSAGECHAT, 200);
|
||||
BuildMonsterChat(&data, source, msgtype, text, language, whisperGuid);//build our packet
|
||||
SendChatPacket(&data, source, msgtype, whisperGuid, range);//send our packet
|
||||
}
|
||||
|
||||
void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const
|
||||
{
|
||||
ChatMsg sendType = CHAT_MSG_MONSTER_SAY;
|
||||
switch (msgtype)
|
||||
{
|
||||
case CHAT_TYPE_YELL:
|
||||
sendType = CHAT_MSG_MONSTER_YELL;
|
||||
break;
|
||||
case CHAT_TYPE_TEXT_EMOTE:
|
||||
sendType = CHAT_MSG_MONSTER_EMOTE;
|
||||
break;
|
||||
case CHAT_TYPE_BOSS_EMOTE:
|
||||
sendType = CHAT_MSG_RAID_BOSS_EMOTE;
|
||||
break;
|
||||
case CHAT_TYPE_WHISPER:
|
||||
if (whisperGuid)
|
||||
sendType = CHAT_MSG_MONSTER_WHISPER;
|
||||
else
|
||||
{
|
||||
sLog.outError("CreatureTextMgr: WorldObject(%s) TypeId %u GuidLow %u sent CHAT_TYPE_WHISPER with targetGuid 0. Ignoring.",source->GetName(), uint32(source->GetTypeId()), source->GetGUIDLow());
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CHAT_TYPE_BOSS_WHISPER:
|
||||
if (whisperGuid)
|
||||
sendType = CHAT_MSG_RAID_BOSS_WHISPER;
|
||||
else
|
||||
{
|
||||
sLog.outError("CreatureTextMgr: WorldObject(%s) TypeId %u GuidLow %u sent CHAT_TYPE_BOSS_WHISPER with targetGuid 0. Ignoring.",source->GetName(), uint32(source->GetTypeId()), source->GetGUIDLow());
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case CHAT_TYPE_SAY://default type
|
||||
default:
|
||||
break;
|
||||
}
|
||||
*data << (uint8)sendType;
|
||||
*data << (uint32)language;
|
||||
*data << (uint64)source->GetGUID();
|
||||
*data << (uint32)0; // 2.1.0
|
||||
*data << (uint32)(strlen(source->GetName())+1);
|
||||
*data << source->GetName();
|
||||
*data << (uint64)whisperGuid; // Unit Target
|
||||
if (whisperGuid && !IS_PLAYER_GUID(whisperGuid)) //can only whisper players
|
||||
{
|
||||
sLog.outError("CreatureTextMgr: WorldObject(%s) TypeId %u GuidLow %u sent WHISPER msg to Non-Player target. Ignoring.",source->GetName(), uint32(source->GetTypeId()), source->GetGUIDLow());
|
||||
return;
|
||||
//*data << (uint32)1; // target name length
|
||||
//*data << (uint8)0; // target name
|
||||
}
|
||||
*data << (uint32)(strlen(text)+1);
|
||||
*data << text;
|
||||
*data << (uint8)0; // ChatTag
|
||||
}
|
||||
|
||||
void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range) const
|
||||
{
|
||||
float dist = sWorld.getFloatConfig(CONFIG_LISTEN_RANGE_SAY);
|
||||
|
||||
switch (msgtype)
|
||||
{
|
||||
case CHAT_TYPE_YELL:
|
||||
dist = sWorld.getFloatConfig(CONFIG_LISTEN_RANGE_YELL);
|
||||
break;
|
||||
case CHAT_TYPE_BOSS_EMOTE:
|
||||
case CHAT_TYPE_TEXT_EMOTE:
|
||||
dist = sWorld.getFloatConfig(CONFIG_LISTEN_RANGE_TEXTEMOTE);
|
||||
break;
|
||||
case CHAT_TYPE_WHISPER:
|
||||
case CHAT_TYPE_BOSS_WHISPER:
|
||||
{
|
||||
if (range != TEXT_RANGE_NORMAL)
|
||||
{
|
||||
sLog.outError("CreatureTextMgr: WorldObject(%s) TypeId %u GuidLow %u sent WHISPER msg with TextRange set. Ignoring.",source->GetName(), uint32(source->GetTypeId()), source->GetGUIDLow());
|
||||
return;
|
||||
}
|
||||
Player *player = sObjectMgr.GetPlayer(whisperGuid);
|
||||
if (!player || !player->GetSession())
|
||||
return;
|
||||
player->GetSession()->SendPacket(data);
|
||||
}
|
||||
return;
|
||||
case CHAT_TYPE_SAY://default dist
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
switch (range)
|
||||
{
|
||||
case TEXT_RANGE_AREA:
|
||||
{
|
||||
uint32 areaId = source->GetAreaId();
|
||||
Map::PlayerList const& pList = source->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
|
||||
if (itr->getSource()->GetAreaId() == areaId)
|
||||
(itr->getSource())->GetSession()->SendPacket(data);
|
||||
}
|
||||
return;
|
||||
case TEXT_RANGE_ZONE:
|
||||
{
|
||||
uint32 zoneId = source->GetZoneId();
|
||||
Map::PlayerList const& pList = source->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
|
||||
if (itr->getSource()->GetZoneId() == zoneId)
|
||||
(itr->getSource())->GetSession()->SendPacket(data);
|
||||
}
|
||||
return;
|
||||
case TEXT_RANGE_MAP:
|
||||
{
|
||||
Map::PlayerList const& pList = source->GetMap()->GetPlayers();
|
||||
for (Map::PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
|
||||
(itr->getSource())->GetSession()->SendPacket(data);
|
||||
}
|
||||
return;
|
||||
case TEXT_RANGE_WORLD:
|
||||
{
|
||||
sWorld.SendGlobalMessage(data);
|
||||
}
|
||||
return;
|
||||
case TEXT_RANGE_NORMAL:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
source->SendMessageToSetInRange(data, dist, true);
|
||||
}
|
||||
|
||||
@@ -41,6 +41,16 @@ struct CreatureTextEntry
|
||||
uint32 sound;
|
||||
};
|
||||
|
||||
enum TextRange
|
||||
{
|
||||
TEXT_RANGE_NORMAL = 0,
|
||||
TEXT_RANGE_AREA = 1,
|
||||
TEXT_RANGE_ZONE = 2,
|
||||
TEXT_RANGE_MAP = 3,
|
||||
TEXT_RANGE_WORLD = 4
|
||||
};
|
||||
|
||||
|
||||
|
||||
typedef std::vector<CreatureTextEntry> CreatureTextGroup; //texts in a group
|
||||
typedef UNORDERED_MAP<uint32, CreatureTextGroup> CreatureTextHolder; //groups for a creature
|
||||
@@ -55,8 +65,12 @@ class CreatureTextMgr
|
||||
void LoadCreatureTexts();
|
||||
CreatureTextMap const& GetTextMap() const { return mTextMap; }
|
||||
|
||||
void SendChat(WorldObject* source, char const* text, ChatType msgtype = CHAT_TYPE_SAY, Language language = LANG_UNIVERSAL, uint64 whisperGuid = 0, TextRange range = TEXT_RANGE_NORMAL) const;
|
||||
|
||||
private:
|
||||
CreatureTextMap mTextMap;
|
||||
void BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const;
|
||||
void SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range) const;
|
||||
};
|
||||
|
||||
#define sCreatureTextMgr (*ACE_Singleton<CreatureTextMgr, ACE_Null_Mutex>::instance())
|
||||
|
||||
Reference in New Issue
Block a user