Skip to content

Commit

Permalink
[12525] EventAI: Use generic DoDisplayText and loading of additional …
Browse files Browse the repository at this point in the history
…text data
  • Loading branch information
xfurry authored and Schmoozerd committed Jun 3, 2013
1 parent d2fd4ba commit f4e0af6
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 209 deletions.
91 changes: 9 additions & 82 deletions src/game/CreatureEventAI.cpp
Expand Up @@ -484,27 +484,27 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
if (!action.text.TextId[0])
return;

int32 temp = 0;
int32 textId = 0;

if (action.type == ACTION_T_TEXT)
{
if (action.text.TextId[1] && action.text.TextId[2])
temp = action.text.TextId[urand(0, 2)];
textId = action.text.TextId[urand(0, 2)];
else if (action.text.TextId[1] && urand(0, 1))
temp = action.text.TextId[1];
textId = action.text.TextId[1];
else
temp = action.text.TextId[0];
textId = action.text.TextId[0];
}
// ACTION_T_CHANCED_TEXT, chance hits
else if (urand(0, 99) < action.chanced_text.chance)
{
if (action.chanced_text.TextId[0] && action.chanced_text.TextId[1])
temp = action.chanced_text.TextId[urand(0, 1)];
textId = action.chanced_text.TextId[urand(0, 1)];
else
temp = action.chanced_text.TextId[0];
textId = action.chanced_text.TextId[0];
}

if (temp)
if (textId)
{
Unit* target = NULL;

Expand All @@ -526,7 +526,8 @@ void CreatureEventAI::ProcessAction(CreatureEventAI_Action const& action, uint32
target = owner;
}

DoScriptText(temp, m_creature, target);
if (!DoDisplayText(m_creature, textId, target))
sLog.outErrorEventAI("Error attempting to display text %i, used by script %u", textId, EventId);
}
break;
}
Expand Down Expand Up @@ -1401,80 +1402,6 @@ void CreatureEventAI::DoFindFriendlyMissingBuff(std::list<Creature*>& _list, flo
//*********************************
//*** Functions used globally ***

void CreatureEventAI::DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target)
{
if (!pSource)
{
sLog.outErrorEventAI("DoScriptText entry %i, invalid Source pointer.", textEntry);
return;
}

if (textEntry >= 0)
{
sLog.outErrorEventAI("DoScriptText with source entry %u (TypeId=%u, guid=%u) attempts to process text entry %i, but text entry must be negative.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
return;
}

CreatureEventAI_TextMap::const_iterator i = sEventAIMgr.GetCreatureEventAITextMap().find(textEntry);

if (i == sEventAIMgr.GetCreatureEventAITextMap().end())
{
sLog.outErrorEventAI("DoScriptText with source entry %u (TypeId=%u, guid=%u) could not find text entry %i.", pSource->GetEntry(), pSource->GetTypeId(), pSource->GetGUIDLow(), textEntry);
return;
}

DEBUG_FILTER_LOG(LOG_FILTER_AI_AND_MOVEGENSS, "CreatureEventAI: DoScriptText: text entry=%i, Sound=%u, Type=%u, Language=%u, Emote=%u", textEntry, (*i).second.SoundId, (*i).second.Type, (*i).second.Language, (*i).second.Emote);

if ((*i).second.SoundId)
{
if (GetSoundEntriesStore()->LookupEntry((*i).second.SoundId))
pSource->PlayDirectSound((*i).second.SoundId);
else
sLog.outErrorEventAI("DoScriptText entry %i tried to process invalid sound id %u.", textEntry, (*i).second.SoundId);
}

if ((*i).second.Emote)
{
if (pSource->GetTypeId() == TYPEID_UNIT || pSource->GetTypeId() == TYPEID_PLAYER)
{
((Unit*)pSource)->HandleEmote((*i).second.Emote);
}
else
sLog.outErrorEventAI("DoScriptText entry %i tried to process emote for invalid TypeId (%u).", textEntry, pSource->GetTypeId());
}

switch ((*i).second.Type)
{
case CHAT_TYPE_SAY:
pSource->MonsterSay(textEntry, (*i).second.Language, target);
break;
case CHAT_TYPE_YELL:
pSource->MonsterYell(textEntry, (*i).second.Language, target);
break;
case CHAT_TYPE_TEXT_EMOTE:
pSource->MonsterTextEmote(textEntry, target);
break;
case CHAT_TYPE_BOSS_EMOTE:
pSource->MonsterTextEmote(textEntry, target, true);
break;
case CHAT_TYPE_WHISPER:
{
if (target && target->GetTypeId() == TYPEID_PLAYER)
pSource->MonsterWhisper(textEntry, target);
else sLog.outErrorEventAI("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, true);
else sLog.outErrorEventAI("DoScriptText entry %i cannot whisper without target unit (TYPEID_PLAYER).", textEntry);
} break;
case CHAT_TYPE_ZONE_YELL:
pSource->MonsterYellToZone(textEntry, (*i).second.Language, target);
break;
}
}

void CreatureEventAI::ReceiveEmote(Player* pPlayer, uint32 text_emote)
{
for (CreatureEventAIList::iterator itr = m_CreatureEventAIList.begin(); itr != m_CreatureEventAIList.end(); ++itr)
Expand Down
13 changes: 0 additions & 13 deletions src/game/CreatureEventAI.h
Expand Up @@ -166,17 +166,6 @@ enum SpawnedEventMode
SPAWNED_EVENT_ZONE = 2
};

// String text additional data, used in (CreatureEventAI)
struct StringTextData
{
uint32 SoundId;
uint8 Type;
uint32 Language;
uint32 Emote;
};
// Text Maps
typedef UNORDERED_MAP<int32, StringTextData> CreatureEventAI_TextMap;

struct CreatureEventAI_Action
{
EventAI_ActionType type: 16;
Expand Down Expand Up @@ -648,8 +637,6 @@ class MANGOS_DLL_SPEC CreatureEventAI : public CreatureAI
/// If the bool& param is true, an error should be reported
inline Unit* GetTargetByType(uint32 Target, Unit* pActionInvoker, Creature* pAIEventSender, bool& isError, uint32 forSpellId = 0, uint32 selectFlags = 0);

void DoScriptText(int32 textEntry, WorldObject* pSource, Unit* target);

bool SpawnedEventConditionsCheck(CreatureEventAI_Event const& event);

Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff);
Expand Down
146 changes: 35 additions & 111 deletions src/game/CreatureEventAIMgr.cpp
Expand Up @@ -34,123 +34,47 @@ INSTANTIATE_SINGLETON_1(CreatureEventAIMgr);
// -------------------
void CreatureEventAIMgr::LoadCreatureEventAI_Texts(bool check_entry_use)
{
// Drop Existing Text Map, only done once and we are ready to add data from multiple sources.
m_CreatureEventAI_TextMap.clear();

// Load EventAI Text
sObjectMgr.LoadMangosStrings(WorldDatabase, "creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID, false);

// Gather Additional data from EventAI Texts
QueryResult* result = WorldDatabase.Query("SELECT entry, sound, type, language, emote FROM creature_ai_texts");

sLog.outString("Loading EventAI Texts additional data...");
if (result)
{
BarGoLink bar(result->GetRowCount());
uint32 count = 0;

do
{
bar.step();
Field* fields = result->Fetch();
StringTextData temp;

int32 i = fields[0].GetInt32();
temp.SoundId = fields[1].GetInt32();
temp.Type = fields[2].GetInt32();
temp.Language = fields[3].GetInt32();
temp.Emote = fields[4].GetInt32();

// range negative
if (i > MIN_CREATURE_AI_TEXT_STRING_ID || i <= MAX_CREATURE_AI_TEXT_STRING_ID)
{
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` is not in valid range(%d-%d)", i, MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID);
continue;
}

// range negative (don't must be happen, loaded from same table)
if (!sObjectMgr.GetMangosStringLocale(i))
{
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` not found", i);
continue;
}

if (temp.SoundId)
{
if (!sSoundEntriesStore.LookupEntry(temp.SoundId))
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` has Sound %u but sound does not exist.", i, temp.SoundId);
}

if (!GetLanguageDescByID(temp.Language))
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` using Language %u but Language does not exist.", i, temp.Language);

if (temp.Type > CHAT_TYPE_ZONE_YELL)
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` has Type %u but this Chat Type does not exist.", i, temp.Type);

if (temp.Emote)
{
if (!sEmotesStore.LookupEntry(temp.Emote))
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` has Emote %u but emote does not exist.", i, temp.Emote);
}

m_CreatureEventAI_TextMap[i] = temp;
++count;
}
while (result->NextRow());

delete result;

if (check_entry_use)
CheckUnusedAITexts();

sLog.outString();
sLog.outString(">> Loaded %u additional CreatureEventAI Texts data.", count);
}
else
{
BarGoLink bar(1);
bar.step();
sLog.outString();
sLog.outString(">> Loaded 0 additional CreatureEventAI Texts data. DB table `creature_ai_texts` is empty.");
}
sObjectMgr.LoadMangosStrings(WorldDatabase, "creature_ai_texts", MIN_CREATURE_AI_TEXT_STRING_ID, MAX_CREATURE_AI_TEXT_STRING_ID, true);
}

void CreatureEventAIMgr::CheckUnusedAITexts()
{
std::set<int32> idx_set;
// ToDo: fix this!!!
// check not used strings this is negative range
for (CreatureEventAI_TextMap::const_iterator itr = m_CreatureEventAI_TextMap.begin(); itr != m_CreatureEventAI_TextMap.end(); ++itr)
idx_set.insert(itr->first);

for (CreatureEventAI_Event_Map::const_iterator itr = m_CreatureEventAI_Event_Map.begin(); itr != m_CreatureEventAI_Event_Map.end(); ++itr)
{
for (size_t i = 0; i < itr->second.size(); ++i)
{
CreatureEventAI_Event const& event = itr->second[i];

for (int j = 0; j < MAX_ACTIONS; ++j)
{
CreatureEventAI_Action const& action = event.action[j];
switch (action.type)
{
case ACTION_T_TEXT:
case ACTION_T_CHANCED_TEXT:
{
// ACTION_T_CHANCED_TEXT contains a chance value in first param
int k = action.type == ACTION_T_TEXT ? 0 : 1;
for (; k < 3; ++k)
if (action.text.TextId[k])
idx_set.erase(action.text.TextId[k]);
break;
}
default: break;
}
}
}
}

for (std::set<int32>::const_iterator itr = idx_set.begin(); itr != idx_set.end(); ++itr)
sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` but not used in EventAI scripts.", *itr);
//for (MangosStringLocaleMap::const_iterator itr = m_CreatureEventAI_TextMap.begin(); itr != m_CreatureEventAI_TextMap.end(); ++itr)
// idx_set.insert(itr->first);

//for (CreatureEventAI_Event_Map::const_iterator itr = m_CreatureEventAI_Event_Map.begin(); itr != m_CreatureEventAI_Event_Map.end(); ++itr)
//{
// for (size_t i = 0; i < itr->second.size(); ++i)
// {
// CreatureEventAI_Event const& event = itr->second[i];

// for (int j = 0; j < MAX_ACTIONS; ++j)
// {
// CreatureEventAI_Action const& action = event.action[j];
// switch (action.type)
// {
// case ACTION_T_TEXT:
// case ACTION_T_CHANCED_TEXT:
// {
// // ACTION_T_CHANCED_TEXT contains a chance value in first param
// int k = action.type == ACTION_T_TEXT ? 0 : 1;
// for (; k < 3; ++k)
// if (action.text.TextId[k])
// idx_set.erase(action.text.TextId[k]);
// break;
// }
// default: break;
// }
// }
// }
//}

//for (std::set<int32>::const_iterator itr = idx_set.begin(); itr != idx_set.end(); ++itr)
// sLog.outErrorEventAI("Entry %i in table `creature_ai_texts` but not used in EventAI scripts.", *itr);
}

// -------------------
Expand Down Expand Up @@ -556,7 +480,7 @@ void CreatureEventAIMgr::LoadCreatureEventAI_Scripts()
sLog.outErrorEventAI("Event %u Action %u param%d references out-of-range entry (%i) in texts table.", i, j + 1, k + 1, action.text.TextId[k]);
action.text.TextId[k] = 0;
}
else if (m_CreatureEventAI_TextMap.find(action.text.TextId[k]) == m_CreatureEventAI_TextMap.end())
else if (!sObjectMgr.GetMangosStringLocale(action.text.TextId[k]))
{
sLog.outErrorEventAI("Event %u Action %u param%d references non-existing entry (%i) in texts table.", i, j + 1, k + 1, action.text.TextId[k]);
action.text.TextId[k] = 0;
Expand Down
2 changes: 0 additions & 2 deletions src/game/CreatureEventAIMgr.h
Expand Up @@ -34,15 +34,13 @@ class CreatureEventAIMgr

CreatureEventAI_Event_Map const& GetCreatureEventAIMap() const { return m_CreatureEventAI_Event_Map; }
CreatureEventAI_Summon_Map const& GetCreatureEventAISummonMap() const { return m_CreatureEventAI_Summon_Map; }
CreatureEventAI_TextMap const& GetCreatureEventAITextMap() const { return m_CreatureEventAI_TextMap; }

private:
void CheckUnusedAITexts();
void CheckUnusedAISummons();

CreatureEventAI_Event_Map m_CreatureEventAI_Event_Map;
CreatureEventAI_Summon_Map m_CreatureEventAI_Summon_Map;
CreatureEventAI_TextMap m_CreatureEventAI_TextMap;
};

#define sEventAIMgr MaNGOS::Singleton<CreatureEventAIMgr>::Instance()
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12524"
#define REVISION_NR "12525"
#endif // __REVISION_NR_H__

0 comments on commit f4e0af6

Please sign in to comment.