diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/game/Entities/Creature/Creature.cpp | 26 | ||||
-rw-r--r-- | src/server/game/Entities/Creature/Creature.h | 10 | ||||
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.cpp | 26 | ||||
-rw-r--r-- | src/server/game/Texts/CreatureTextMgr.h | 6 |
4 files changed, 40 insertions, 28 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index 3d11965ac6e..809c76c260a 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -2635,3 +2635,29 @@ void Creature::StartPickPocketRefillTimer() _pickpocketLootRestore = time(NULL) + sWorld->getIntConfig(CONFIG_CREATURE_PICKPOCKET_REFILL); } +void Creature::SetTextRepeatId(uint8 textGroup, uint8 id) +{ + CreatureTextRepeatIds& repeats = m_textRepeat[textGroup]; + if (std::find(repeats.begin(), repeats.end(), id) == repeats.end()) + repeats.push_back(id); + else + TC_LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added", uint32(textGroup), GetName().c_str(), GetGUIDLow(), GetEntry(), uint32(id)); +} + +CreatureTextRepeatIds Creature::GetTextRepeatGroup(uint8 textGroup) +{ + CreatureTextRepeatIds ids; + + CreatureTextRepeatGroup::const_iterator groupItr = m_textRepeat.find(textGroup); + if (groupItr != m_textRepeat.end()) + ids = groupItr->second; + + return ids; +} + +void Creature::ClearTextRepeatGroup(uint8 textGroup) +{ + CreatureTextRepeatGroup::iterator groupItr = m_textRepeat.find(textGroup); + if (groupItr != m_textRepeat.end()) + groupItr->second.clear(); +} diff --git a/src/server/game/Entities/Creature/Creature.h b/src/server/game/Entities/Creature/Creature.h index 764a57d4cef..585bc137e0b 100644 --- a/src/server/game/Entities/Creature/Creature.h +++ b/src/server/game/Entities/Creature/Creature.h @@ -409,6 +409,10 @@ struct TrainerSpellData #define MAX_VENDOR_ITEMS 150 // Limitation in 3.x.x item count in SMSG_LIST_INVENTORY +//used for handling non-repeatable random texts +typedef std::vector<uint8> CreatureTextRepeatIds; +typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup; + class Creature : public Unit, public GridObject<Creature>, public MapObject { public: @@ -656,6 +660,10 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject void FocusTarget(Spell const* focusSpell, WorldObject const* target); void ReleaseFocus(Spell const* focusSpell); + CreatureTextRepeatIds GetTextRepeatGroup(uint8 textGroup); + void SetTextRepeatId(uint8 textGroup, uint8 id); + void ClearTextRepeatGroup(uint8 textGroup); + protected: bool CreateFromProto(uint32 guidlow, uint32 entry, CreatureData const* data = nullptr, uint32 vehId = 0); bool InitEntry(uint32 entry, CreatureData const* data = nullptr); @@ -720,6 +728,8 @@ class Creature : public Unit, public GridObject<Creature>, public MapObject bool TriggerJustRespawned; Spell const* _focusSpell; ///> Locks the target during spell cast for proper facing + + CreatureTextRepeatGroup m_textRepeat; }; class AssistDelayEvent : public BasicEvent diff --git a/src/server/game/Texts/CreatureTextMgr.cpp b/src/server/game/Texts/CreatureTextMgr.cpp index 5fbc4b8ae1e..f9ccd2efd16 100644 --- a/src/server/game/Texts/CreatureTextMgr.cpp +++ b/src/server/game/Texts/CreatureTextMgr.cpp @@ -77,7 +77,7 @@ void CreatureTextMgr::LoadCreatureTexts() uint32 oldMSTime = getMSTime(); mTextMap.clear(); // for reload case - mTextRepeatMap.clear(); //reset all currently used temp texts + //all currently used temp texts are NOT reset PreparedStatement* stmt = WorldDatabase.GetPreparedStatement(WORLD_SEL_CREATURE_TEXT); PreparedQueryResult result = WorldDatabase.Query(stmt); @@ -224,13 +224,7 @@ uint32 CreatureTextMgr::SendChat(Creature* source, uint8 textGroup, WorldObject if (tempGroup.empty()) { - CreatureTextRepeatMap::iterator mapItr = mTextRepeatMap.find(source->GetGUID()); - if (mapItr != mTextRepeatMap.end()) - { - CreatureTextRepeatGroup::iterator groupItr = mapItr->second.find(textGroup); - groupItr->second.clear(); - } - + source->ClearTextRepeatGroup(textGroup); tempGroup = textGroupContainer; } @@ -426,26 +420,14 @@ void CreatureTextMgr::SetRepeatId(Creature* source, uint8 textGroup, uint8 id) if (!source) return; - CreatureTextRepeatIds& repeats = mTextRepeatMap[source->GetGUID()][textGroup]; - if (std::find(repeats.begin(), repeats.end(), id) == repeats.end()) - repeats.push_back(id); - else - TC_LOG_ERROR("sql.sql", "CreatureTextMgr: TextGroup %u for Creature(%s) GuidLow %u Entry %u, id %u already added", uint32(textGroup), source->GetName().c_str(), source->GetGUIDLow(), source->GetEntry(), uint32(id)); + source->SetTextRepeatId(textGroup, 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; + return source->GetTextRepeatGroup(textGroup); } bool CreatureTextMgr::TextExist(uint32 sourceEntry, uint8 textGroup) diff --git a/src/server/game/Texts/CreatureTextMgr.h b/src/server/game/Texts/CreatureTextMgr.h index 6ee1e82ce66..237aedd49d0 100644 --- a/src/server/game/Texts/CreatureTextMgr.h +++ b/src/server/game/Texts/CreatureTextMgr.h @@ -75,11 +75,6 @@ typedef std::unordered_map<uint32, CreatureTextHolder> CreatureTextMap; // a typedef std::map<CreatureTextId, CreatureTextLocale> LocaleCreatureTextMap; -//used for handling non-repeatable random texts -typedef std::vector<uint8> CreatureTextRepeatIds; -typedef std::unordered_map<uint8, CreatureTextRepeatIds> CreatureTextRepeatGroup; -typedef std::unordered_map<ObjectGuid, CreatureTextRepeatGroup> CreatureTextRepeatMap;//guid based - class CreatureTextMgr { private: @@ -115,7 +110,6 @@ class CreatureTextMgr float GetRangeForChatType(ChatMsg msgType) const; CreatureTextMap mTextMap; - CreatureTextRepeatMap mTextRepeatMap; LocaleCreatureTextMap mLocaleTextMap; }; |