fix(Core/AI): validate stored targets (#12489)

Co-authored-by: Meji <meji46@users.noreply.github.com>
Co-authored-by: Ariel Silva <ariel-@users.noreply.github.com>
Co-authored-by: Shauren <shauren.trinity@gmail.com>

Co-authored-by: Meji <meji46@users.noreply.github.com>
Co-authored-by: Ariel Silva <ariel-@users.noreply.github.com>
Co-authored-by: Shauren <shauren.trinity@gmail.com>
This commit is contained in:
Nefertumm
2022-07-24 13:06:11 -03:00
committed by GitHub
parent 5bcc54a617
commit f0777d1fd3
4 changed files with 98 additions and 23 deletions

View File

@@ -1785,34 +1785,33 @@ typedef std::vector<WorldObject*> ObjectVector;
class ObjectGuidVector
{
public:
ObjectGuidVector(WorldObject* baseObject, ObjectVector const& objectVector) : _baseObject(baseObject), _objectVector(objectVector)
explicit ObjectGuidVector(ObjectVector const& objectVector) : _objectVector(objectVector)
{
_guidVector.reserve(_objectVector.size());
for (WorldObject* obj : _objectVector)
_guidVector.push_back(obj->GetGUID());
}
ObjectVector const* GetObjectVector() const
ObjectVector const* GetObjectVector(WorldObject const& ref) const
{
UpdateObjects();
UpdateObjects(ref);
return &_objectVector;
}
~ObjectGuidVector() { }
private:
WorldObject* const _baseObject;
mutable ObjectVector _objectVector;
GuidVector _guidVector;
//sanitize vector using _guidVector
void UpdateObjects() const
void UpdateObjects(WorldObject const& ref) const
{
_objectVector.clear();
for (ObjectGuid const& guid : _guidVector)
if (WorldObject* obj = ObjectAccessor::GetWorldObject(*_baseObject, guid))
if (WorldObject* obj = ObjectAccessor::GetWorldObject(ref, guid))
_objectVector.push_back(obj);
}
};