diff options
author | Rat <none@none> | 2010-09-26 20:48:25 +0200 |
---|---|---|
committer | Rat <none@none> | 2010-09-26 20:48:25 +0200 |
commit | bbf86641a1c35fcc66de30d7a79175c31effde88 (patch) | |
tree | 165aa4c561800bf54d7037eb5f1fd7cf5b0f8801 /src | |
parent | 133ab88f8c43edf6e987649c86ad4f7b684c2886 (diff) |
Core/Scripts/SmartAI: removed test code
Core/CreatureTextMgr: added reload command
handle text from DB
handle grouped texts
handle repeatable/single texts based on probability
todo: sound/emote, code cleanup
--HG--
branch : trunk
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/AI/SmartAI/SmartAI.cpp | 6 | ||||
-rw-r--r-- | src/server/game/AI/SmartAI/SmartAI.h | 1 | ||||
-rw-r--r-- | src/server/game/Chat/Chat.cpp | 1 | ||||
-rw-r--r-- | src/server/game/Chat/Chat.h | 1 | ||||
-rw-r--r-- | src/server/game/Chat/Commands/Level3.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.cpp | 132 | ||||
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.h | 22 |
7 files changed, 158 insertions, 14 deletions
diff --git a/src/server/game/AI/SmartAI/SmartAI.cpp b/src/server/game/AI/SmartAI/SmartAI.cpp index 8e513950a6f..687c9b99601 100644 --- a/src/server/game/AI/SmartAI/SmartAI.cpp +++ b/src/server/game/AI/SmartAI/SmartAI.cpp @@ -35,7 +35,6 @@ void SmartAIMgr::LoadSmartAIFromDB() SmartAI::SmartAI(Creature *c) : CreatureAI(c) { // copy script to local (pretection for table reload) - mTestTimer = 0; } int SmartAI::Permissible(const Creature *creature) @@ -47,11 +46,6 @@ 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() diff --git a/src/server/game/AI/SmartAI/SmartAI.h b/src/server/game/AI/SmartAI/SmartAI.h index 021791ab1b6..e1a2d2fb8e1 100644 --- a/src/server/game/AI/SmartAI/SmartAI.h +++ b/src/server/game/AI/SmartAI/SmartAI.h @@ -362,7 +362,6 @@ 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()) diff --git a/src/server/game/Chat/Chat.cpp b/src/server/game/Chat/Chat.cpp index a0175b43533..94c33a08585 100644 --- a/src/server/game/Chat/Chat.cpp +++ b/src/server/game/Chat/Chat.cpp @@ -469,6 +469,7 @@ ChatCommand * ChatHandler::getCommandTable() { "autobroadcast", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadAutobroadcastCommand, "", NULL }, { "command", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCommandCommand, "", NULL }, { "conditions", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadConditions, "", NULL }, + { "creature_text", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadCreatureText, "", NULL }, { "creature_ai_scripts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadEventAIScriptsCommand, "", NULL }, { "creature_ai_summons", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadEventAISummonsCommand, "", NULL }, { "creature_ai_texts", SEC_ADMINISTRATOR, true, &ChatHandler::HandleReloadEventAITextsCommand, "", NULL }, diff --git a/src/server/game/Chat/Chat.h b/src/server/game/Chat/Chat.h index 75a28c1a2c0..046e47971a1 100644 --- a/src/server/game/Chat/Chat.h +++ b/src/server/game/Chat/Chat.h @@ -450,6 +450,7 @@ class ChatHandler bool HandleReloadAuctionsCommand(const char* args); bool HandleReloadWpScriptsCommand(const char* args); bool HandleReloadConditions(const char* args); + bool HandleReloadCreatureText(const char* args); bool HandleResetAchievementsCommand(const char * args); bool HandleResetAllCommand(const char * args); diff --git a/src/server/game/Chat/Commands/Level3.cpp b/src/server/game/Chat/Commands/Level3.cpp index 51dca819481..b831d8b6294 100644 --- a/src/server/game/Chat/Commands/Level3.cpp +++ b/src/server/game/Chat/Commands/Level3.cpp @@ -60,6 +60,7 @@ #include "WeatherMgr.h" #include "ScriptMgr.h" #include "LFGMgr.h" +#include "CreatureTextMgr.h" //reload commands bool ChatHandler::HandleReloadAllCommand(const char*) @@ -1170,6 +1171,14 @@ bool ChatHandler::HandleReloadConditions(const char* /*args*/) return true; } +bool ChatHandler::HandleReloadCreatureText(const char* /*args*/) +{ + sLog.outString("Re-Loading Creature Texts..."); + sCreatureTextMgr.LoadCreatureTexts(); + SendGlobalGMSysMessage("Creature Texts reloaded."); + return true; +} + bool ChatHandler::HandleAccountSetGmLevelCommand(const char *args) { if (!*args) diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 9557362ea36..9e165adc8fb 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -26,6 +26,7 @@ void CreatureTextMgr::LoadCreatureTexts() { mTextMap.clear(); // for reload case + mTextRepeatMap.clear(); //reset all currently used temp texts PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_LOAD_CRETEXT); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -108,8 +109,131 @@ void CreatureTextMgr::LoadCreatureTexts() 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 +void CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid, ChatType msgtype, Language language, TextRange range) { + if (!source) + return; + CreatureTextMap::const_iterator sList = mTextMap.find(source->GetEntry()); + if (sList == mTextMap.end()) + { + sLog.outErrorDb("CreatureTextMgr: Could not find Text for Creature(%s) Entry %u in 'creature_text' table. Ignoring.",source->GetName(), source->GetEntry()); + return; + } + CreatureTextHolder TextHolder = (*sList).second; + CreatureTextHolder::const_iterator itr = TextHolder.find(textGroup); + if (itr == TextHolder.end()) + { + sLog.outErrorDb("CreatureTextMgr: Could not find TextGroup %u for Creature(%s) GuidLow %u Entry %u. Ignoring.",uint32(textGroup), source->GetName(), source->GetGUIDLow(), source->GetEntry()); + return; + } + CreatureTextGroup TextGroup = (*itr).second;//has all texts in the group + CreatureTextRepeatIds repeatGroup = GetRepeatGroup(source,textGroup);//has all textIDs from the group that were already said + CreatureTextGroup tempGroup;//will use this to talk after sorting repeatGroup + + for (CreatureTextGroup::const_iterator giter = TextGroup.begin(); giter != TextGroup.end(); ++giter) + { + if (std::find(repeatGroup.begin(), repeatGroup.end(), (*giter).id) == repeatGroup.end()) + tempGroup.push_back((*giter)); + } + if (tempGroup.empty()) + { + //mTextRepeatMap[source->GetGUID()][textGroup].clear(); + CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID()); + if (mapItr != mTextRepeatMap.end()) + { + CreatureTextRepeatGroup::iterator groupItr = (*mapItr).second.find(textGroup); + (*groupItr).second.clear(); + } + tempGroup = TextGroup; + } + uint8 count = 0; + float lastChance = -1; + bool isEqualChanced = true; + + float totalChance = 0; + + for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter) + { + if (lastChance >= 0 && lastChance != (*iter).probability) + isEqualChanced = false; + + lastChance = (*iter).probability; + totalChance += (*iter).probability; + count++; + } + if (isEqualChanced) + { + uint32 pos = urand(0,count - 1); + CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos; + SendChatString(source, (*iter).text.c_str(), (*iter).type, (*iter).lang, whisperGuid); + SetRepeatId(source, textGroup, (*iter).id); + }else + { + for (CreatureTextGroup::const_iterator iter = tempGroup.begin(); iter != tempGroup.end(); ++iter) + { + uint32 chance = uint32((*iter).probability); + uint32 r = urand(0, 100); + if (r <= chance) + { + SendChatString(source, (*iter).text.c_str(), (*iter).type, (*iter).lang, whisperGuid); + if (totalChance == 100.0f)// only if total chances are 100 do not repeat + SetRepeatId(source, textGroup, (*iter).id); + return; + } + } + uint32 pos = urand(0,count - 1); + CreatureTextGroup::const_iterator iter = tempGroup.begin() + pos; + SendChatString(source, (*iter).text.c_str(), (*iter).type, (*iter).lang, whisperGuid); + SetRepeatId(source, textGroup, (*iter).id); + } +} + +void CreatureTextMgr::SetRepeatId(Creature* source, uint8 textGroup, uint8 id) +{ + if (!source) + return; + + if (mTextRepeatMap.find(source->GetGUID()) == mTextRepeatMap.end()) + { + CreatureTextRepeatGroup TextGroup; + mTextRepeatMap[source->GetGUID()] = TextGroup; + } + if (mTextRepeatMap[source->GetGUID()].find(textGroup) == mTextRepeatMap[source->GetGUID()].end()) + { + CreatureTextRepeatIds ids; + mTextRepeatMap[source->GetGUID()][textGroup] = ids; + } + + if (std::find(mTextRepeatMap[source->GetGUID()][textGroup].begin(), mTextRepeatMap[source->GetGUID()][textGroup].end(), id) == mTextRepeatMap[source->GetGUID()][textGroup].end()) + { + mTextRepeatMap[source->GetGUID()][textGroup].push_back(id); + } + else + sLog.outErrorDb("CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added",uint32(textGroup), source->GetName(), source->GetGUIDLow(), source->GetEntry(), uint32(id)); +} + +CreatureTextRepeatIds CreatureTextMgr::GetRepeatGroup(Creature* source, uint8 textGroup) +{ + ASSERT(source);//should never happen + CreatureTextRepeatIds ids; + + CreatureTextRepeatMap::const_iterator mapItr = mTextRepeatMap.find(source->GetGUID()); + if (mapItr != mTextRepeatMap.end()) + { + CreatureTextRepeatGroup::const_iterator groupItr = (*mapItr).second.find(textGroup); + if (groupItr != (*mapItr).second.end()) + { + ids = (*groupItr).second; + } + } + return ids; +} + +void CreatureTextMgr::SendChatString(WorldObject* source, char const* text, ChatType msgtype, Language language, uint64 whisperGuid, TextRange range) const +{ + if (!source) + return; + WorldPacket data(SMSG_MESSAGECHAT, 200); BuildMonsterChat(&data, source, msgtype, text, language, whisperGuid);//build our packet SendChatPacket(&data, source, msgtype, whisperGuid, range);//send our packet @@ -117,6 +241,9 @@ void CreatureTextMgr::SendChat(WorldObject* source, char const* text, ChatType m void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, ChatType msgtype, char const* text, Language language, uint64 whisperGuid) const { + if (!source) + return; + ChatMsg sendType = CHAT_MSG_MONSTER_SAY; switch (msgtype) { @@ -172,6 +299,9 @@ void CreatureTextMgr::BuildMonsterChat(WorldPacket *data, WorldObject* source, C void CreatureTextMgr::SendChatPacket(WorldPacket *data, WorldObject* source, ChatType msgtype, uint64 whisperGuid, TextRange range) const { + if (!source) + return; + float dist = sWorld.getFloatConfig(CONFIG_LISTEN_RANGE_SAY); switch (msgtype) diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h index 11ba84f691b..70ad8b6f9b0 100644 --- a/src/server/game/Texts/CreatureTextMgr.h +++ b/src/server/game/Texts/CreatureTextMgr.h @@ -52,9 +52,14 @@ enum TextRange -typedef std::vector<CreatureTextEntry> CreatureTextGroup; //texts in a group -typedef UNORDERED_MAP<uint32, CreatureTextGroup> CreatureTextHolder; //groups for a creature -typedef UNORDERED_MAP<uint32, CreatureTextHolder> CreatureTextMap; //all creatures +typedef std::vector<CreatureTextEntry> CreatureTextGroup; //texts in a group +typedef UNORDERED_MAP<uint8, CreatureTextGroup> CreatureTextHolder; //groups for a creature by groupid +typedef UNORDERED_MAP<uint32, CreatureTextHolder> CreatureTextMap; //all creatures by entry + +//used for handling non-repeatable random texts +typedef std::vector<uint8> CreatureTextRepeatIds; +typedef UNORDERED_MAP<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup; +typedef UNORDERED_MAP<uint64, CreatureTextRepeatGroup> CreatureTextRepeatMap;//guid based class CreatureTextMgr { @@ -65,12 +70,17 @@ 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; - + void SendChat(Creature* source, uint8 textGroup, uint64 whisperGuid = 0, ChatType msgtype = CHAT_TYPE_SAY, Language language = LANG_UNIVERSAL, TextRange range = TEXT_RANGE_NORMAL); + void SendChatString(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; + CreatureTextRepeatIds GetRepeatGroup(Creature* source, uint8 textGroup); + void SetRepeatId(Creature* source, uint8 textGroup, uint8 id); 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; + + CreatureTextMap mTextMap; + CreatureTextRepeatMap mTextRepeatMap; }; #define sCreatureTextMgr (*ACE_Singleton<CreatureTextMgr, ACE_Null_Mutex>::instance()) |