mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-14 01:29:07 +00:00
refactor(Core): move complex functions from Object.h to Object.cpp (#9016)
Co-authored-by: QAston <qaston@gmail.com>
This commit is contained in:
@@ -291,6 +291,50 @@ void Object::DestroyForPlayer(Player* target, bool onDeath) const
|
||||
target->GetSession()->SendPacket(&data);
|
||||
}
|
||||
|
||||
[[nodiscard]] int32 Object::GetInt32Value(uint16 index) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
return m_int32Values[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] uint32 Object::GetUInt32Value(uint16 index) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
return m_uint32Values[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] uint64 Object::GetUInt64Value(uint16 index) const
|
||||
{
|
||||
ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, false));
|
||||
return *((uint64*) &(m_uint32Values[index]));
|
||||
}
|
||||
|
||||
[[nodiscard]] float Object::GetFloatValue(uint16 index) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
return m_floatValues[index];
|
||||
}
|
||||
|
||||
[[nodiscard]] uint8 Object::GetByteValue(uint16 index, uint8 offset) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
ASSERT(offset < 4);
|
||||
return *(((uint8*) &m_uint32Values[index]) + offset);
|
||||
}
|
||||
|
||||
[[nodiscard]] uint16 Object::GetUInt16Value(uint16 index, uint8 offset) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
ASSERT(offset < 2);
|
||||
return *(((uint16*) &m_uint32Values[index]) + offset);
|
||||
}
|
||||
|
||||
[[nodiscard]] ObjectGuid Object::GetGuidValue(uint16 index) const
|
||||
{
|
||||
ASSERT(index + 1 < m_valuesCount || PrintIndexError(index, false));
|
||||
return *((ObjectGuid*) &(m_uint32Values[index]));
|
||||
}
|
||||
|
||||
void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
|
||||
{
|
||||
Unit const* unit = nullptr;
|
||||
@@ -773,6 +817,13 @@ void Object::ApplyModSignedFloatValue(uint16 index, float val, bool apply)
|
||||
SetFloatValue(index, cur);
|
||||
}
|
||||
|
||||
void Object::ApplyPercentModFloatValue(uint16 index, float val, bool apply)
|
||||
{
|
||||
float value = GetFloatValue(index);
|
||||
ApplyPercentModFloatVar(value, val, apply);
|
||||
SetFloatValue(index, value);
|
||||
}
|
||||
|
||||
void Object::ApplyModPositiveFloatValue(uint16 index, float val, bool apply)
|
||||
{
|
||||
float cur = GetFloatValue(index);
|
||||
@@ -814,6 +865,40 @@ void Object::RemoveFlag(uint16 index, uint32 oldFlag)
|
||||
}
|
||||
}
|
||||
|
||||
void Object::ToggleFlag(uint16 index, uint32 flag)
|
||||
{
|
||||
if (HasFlag(index, flag))
|
||||
{
|
||||
RemoveFlag(index, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFlag(index, flag);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Object::HasFlag(uint16 index, uint32 flag) const
|
||||
{
|
||||
if (index >= m_valuesCount && !PrintIndexError(index, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (m_uint32Values[index] & flag) != 0;
|
||||
}
|
||||
|
||||
void Object::ApplyModFlag(uint16 index, uint32 flag, bool apply)
|
||||
{
|
||||
if (apply)
|
||||
{
|
||||
SetFlag(index, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFlag(index, flag);
|
||||
}
|
||||
}
|
||||
|
||||
void Object::SetByteFlag(uint16 index, uint8 offset, uint8 newFlag)
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, true));
|
||||
@@ -852,6 +937,57 @@ void Object::RemoveByteFlag(uint16 index, uint8 offset, uint8 oldFlag)
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Object::HasByteFlag(uint16 index, uint8 offset, uint8 flag) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
ASSERT(offset < 4);
|
||||
return (((uint8*) &m_uint32Values[index])[offset] & flag) != 0;
|
||||
}
|
||||
|
||||
void Object::SetFlag64(uint16 index, uint64 newFlag)
|
||||
{
|
||||
uint64 oldval = GetUInt64Value(index);
|
||||
uint64 newval = oldval | newFlag;
|
||||
SetUInt64Value(index, newval);
|
||||
}
|
||||
|
||||
void Object::RemoveFlag64(uint16 index, uint64 oldFlag)
|
||||
{
|
||||
uint64 oldval = GetUInt64Value(index);
|
||||
uint64 newval = oldval & ~oldFlag;
|
||||
SetUInt64Value(index, newval);
|
||||
}
|
||||
|
||||
void Object::ToggleFlag64(uint16 index, uint64 flag)
|
||||
{
|
||||
if (HasFlag64(index, flag))
|
||||
{
|
||||
RemoveFlag64(index, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetFlag64(index, flag);
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Object::HasFlag64(uint16 index, uint64 flag) const
|
||||
{
|
||||
ASSERT(index < m_valuesCount || PrintIndexError(index, false));
|
||||
return (GetUInt64Value(index) & flag) != 0;
|
||||
}
|
||||
|
||||
void Object::ApplyModFlag64(uint16 index, uint64 flag, bool apply)
|
||||
{
|
||||
if (apply)
|
||||
{
|
||||
SetFlag64(index, flag);
|
||||
}
|
||||
else
|
||||
{
|
||||
RemoveFlag64(index, flag);
|
||||
}
|
||||
}
|
||||
|
||||
bool Object::PrintIndexError(uint32 index, bool set) const
|
||||
{
|
||||
LOG_INFO("misc", "Attempt %s non-existed value field: %u (count: %u) for object typeid: %u type mask: %u",
|
||||
@@ -1154,6 +1290,87 @@ Position WorldObject::GetHitSpherePointFor(Position const& dest) const
|
||||
return Position(contactPoint.x, contactPoint.y, contactPoint.z, GetAngle(contactPoint.x, contactPoint.y));
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance(const WorldObject* obj) const
|
||||
{
|
||||
float d = GetExactDist(obj) - GetObjectSize() - obj->GetObjectSize();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
[[nodiscard]] float WorldObject::GetDistance(const Position& pos) const
|
||||
{
|
||||
float d = GetExactDist(&pos) - GetObjectSize();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
[[nodiscard]] float WorldObject::GetDistance(float x, float y, float z) const
|
||||
{
|
||||
float d = GetExactDist(x, y, z) - GetObjectSize();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
float WorldObject::GetDistance2d(const WorldObject* obj) const
|
||||
{
|
||||
float d = GetExactDist2d(obj) - GetObjectSize() - obj->GetObjectSize();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
[[nodiscard]] float WorldObject::GetDistance2d(float x, float y) const
|
||||
{
|
||||
float d = GetExactDist2d(x, y) - GetObjectSize();
|
||||
return d > 0.0f ? d : 0.0f;
|
||||
}
|
||||
|
||||
bool WorldObject::IsSelfOrInSameMap(const WorldObject* obj) const
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return IsInMap(obj);
|
||||
}
|
||||
|
||||
bool WorldObject::IsInMap(const WorldObject* obj) const
|
||||
{
|
||||
if (obj)
|
||||
{
|
||||
return IsInWorld() && obj->IsInWorld() && (FindMap() == obj->FindMap());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
[[nodiscard]] bool WorldObject::IsWithinDist3d(float x, float y, float z, float dist) const
|
||||
{
|
||||
return IsInDist(x, y, z, dist + GetObjectSize());
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinDist3d(const Position* pos, float dist) const
|
||||
{
|
||||
return IsInDist(pos, dist + GetObjectSize());
|
||||
}
|
||||
|
||||
[[nodiscard]] bool WorldObject::IsWithinDist2d(float x, float y, float dist) const
|
||||
{
|
||||
return IsInDist2d(x, y, dist + GetObjectSize());
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinDist2d(const Position* pos, float dist) const
|
||||
{
|
||||
return IsInDist2d(pos, dist + GetObjectSize());
|
||||
}
|
||||
|
||||
// use only if you will sure about placing both object at same map
|
||||
bool WorldObject::IsWithinDist(WorldObject const* obj, float dist2compare, bool is3D, bool useBoundingRadius) const
|
||||
{
|
||||
return obj && _IsWithinDist(obj, dist2compare, is3D, useBoundingRadius);
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinDistInMap(WorldObject const* obj, float dist2compare, bool is3D, bool useBoundingRadius) const
|
||||
{
|
||||
return obj && IsInMap(obj) && InSamePhase(obj) && _IsWithinDist(obj, dist2compare, is3D, useBoundingRadius);
|
||||
}
|
||||
|
||||
bool WorldObject::IsWithinLOS(float ox, float oy, float oz, LineOfSightChecks checks) const
|
||||
{
|
||||
if (IsInWorld())
|
||||
@@ -1467,6 +1684,13 @@ void WorldObject::GetRandomPoint(const Position& pos, float distance, float& ran
|
||||
UpdateGroundPositionZ(rand_x, rand_y, rand_z); // update to LOS height if available
|
||||
}
|
||||
|
||||
void WorldObject::GetRandomPoint(const Position& srcPos, float distance, Position& pos) const
|
||||
{
|
||||
float x, y, z;
|
||||
GetRandomPoint(srcPos, distance, x, y, z);
|
||||
pos.Relocate(x, y, z, GetOrientation());
|
||||
}
|
||||
|
||||
void WorldObject::UpdateGroundPositionZ(float x, float y, float &z) const
|
||||
{
|
||||
float new_z = GetMapHeight(x, y, z);
|
||||
@@ -2149,6 +2373,18 @@ void Map::SummonCreatureGroup(uint8 group, std::list<TempSummon*>* list /*= null
|
||||
list->push_back(summon);
|
||||
}
|
||||
|
||||
TempSummon* WorldObject::SummonCreature(uint32 id, float x, float y, float z, float ang, TempSummonType spwtype, uint32 despwtime, SummonPropertiesEntry const* properties)
|
||||
{
|
||||
if (!x && !y && !z)
|
||||
{
|
||||
GetClosePoint(x, y, z, GetObjectSize());
|
||||
ang = GetOrientation();
|
||||
}
|
||||
Position pos;
|
||||
pos.Relocate(x, y, z, ang);
|
||||
return SummonCreature(id, pos, spwtype, despwtime, 0, properties);
|
||||
}
|
||||
|
||||
GameObject* Map::SummonGameObject(uint32 entry, float x, float y, float z, float ang, float rotation0, float rotation1, float rotation2, float rotation3, uint32 respawnTime, bool checkTransport)
|
||||
{
|
||||
GameObjectTemplate const* goinfo = sObjectMgr->GetGameObjectTemplate(entry);
|
||||
@@ -2561,6 +2797,24 @@ bool WorldObject::GetClosePoint(float& x, float& y, float& z, float size, float
|
||||
return true;
|
||||
}
|
||||
|
||||
void WorldObject::GetNearPosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
MovePosition(pos, dist, angle);
|
||||
}
|
||||
|
||||
void WorldObject::GetFirstCollisionPosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
MovePositionToFirstCollision(pos, dist, angle);
|
||||
}
|
||||
|
||||
void WorldObject::GetRandomNearPosition(Position& pos, float radius)
|
||||
{
|
||||
GetPosition(&pos);
|
||||
MovePosition(pos, radius * (float) rand_norm(), (float) rand_norm() * static_cast<float>(2 * M_PI));
|
||||
}
|
||||
|
||||
void WorldObject::GetContactPoint(const WorldObject* obj, float& x, float& y, float& z, float distance2d) const
|
||||
{
|
||||
// angle to face `obj` to `this` using distance includes size of `obj`
|
||||
@@ -2589,6 +2843,11 @@ void WorldObject::GetChargeContactPoint(const WorldObject* obj, float& x, float&
|
||||
}
|
||||
}
|
||||
|
||||
[[nodiscard]] float WorldObject::GetObjectSize() const
|
||||
{
|
||||
return (m_valuesCount > UNIT_FIELD_COMBATREACH) ? m_floatValues[UNIT_FIELD_COMBATREACH] : DEFAULT_WORLD_OBJECT_SIZE * GetObjectScale();
|
||||
}
|
||||
|
||||
void WorldObject::MovePosition(Position& pos, float dist, float angle)
|
||||
{
|
||||
angle += m_orientation;
|
||||
|
||||
Reference in New Issue
Block a user