aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Object
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2022-03-29 23:07:07 +0200
committerShauren <shauren.trinity@gmail.com>2022-03-29 23:07:07 +0200
commite334fdf3ade7c3df8df9e5730434b67fe1ed019a (patch)
treed0d9475591a3dc3f3e75576aca8e27495bdc31e3 /src/server/game/Entities/Object
parentd611925dc7ab2b3f19c5ee9e0f75b8dfb6de1291 (diff)
Core/Units: Reduce differences between branches part 1 - object class
Diffstat (limited to 'src/server/game/Entities/Object')
-rw-r--r--src/server/game/Entities/Object/Object.cpp39
-rw-r--r--src/server/game/Entities/Object/Object.h65
2 files changed, 42 insertions, 62 deletions
diff --git a/src/server/game/Entities/Object/Object.cpp b/src/server/game/Entities/Object/Object.cpp
index cbc5f448e11..96749c87b43 100644
--- a/src/server/game/Entities/Object/Object.cpp
+++ b/src/server/game/Entities/Object/Object.cpp
@@ -220,7 +220,7 @@ void Object::SendUpdateToPlayer(Player* player)
player->SendDirectMessage(&packet);
}
-void Object::BuildValuesUpdateBlockForPlayer(UpdateData* data, Player* target) const
+void Object::BuildValuesUpdateBlockForPlayer(UpdateData* data, Player const* target) const
{
ByteBuffer buf(500);
@@ -468,7 +468,7 @@ void Object::BuildMovementUpdate(ByteBuffer* data, uint16 flags) const
*data << int64(ToGameObject()->GetPackedLocalRotation());
}
-void Object::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player* target) const
+void Object::BuildValuesUpdate(uint8 updateType, ByteBuffer* data, Player const* target) const
{
if (!target)
return;
@@ -2812,7 +2812,7 @@ bool WorldObject::IsNeutralToAll() const
return my_faction->IsNeutralToAll();
}
-SpellCastResult WorldObject::CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
+SpellCastResult WorldObject::CastSpell(CastSpellTargetArg const& targets, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
{
SpellInfo const* info = sSpellMgr->GetSpellInfo(spellId);
if (!info)
@@ -2821,37 +2821,18 @@ SpellCastResult WorldObject::CastSpell(SpellCastTargets const& targets, uint32 s
return SPELL_FAILED_SPELL_UNAVAILABLE;
}
+ if (!targets.Targets)
+ {
+ TC_LOG_ERROR("entities.unit", "CastSpell: Invalid target passed to spell cast %u by %s", spellId, GetGUID().ToString().c_str());
+ return SPELL_FAILED_BAD_TARGETS;
+ }
+
Spell* spell = new Spell(this, info, args.TriggerFlags, args.OriginalCaster);
for (auto const& pair : args.SpellValueOverrides)
spell->SetSpellValue(pair.first, pair.second);
spell->m_CastItem = args.CastItem;
- return spell->prepare(targets, args.TriggeringAura);
-}
-
-SpellCastResult WorldObject::CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
-{
- SpellCastTargets targets;
- if (target)
- {
- if (Unit* unitTarget = target->ToUnit())
- targets.SetUnitTarget(unitTarget);
- else if (GameObject* goTarget = target->ToGameObject())
- targets.SetGOTarget(goTarget);
- else
- {
- TC_LOG_ERROR("entities.unit", "CastSpell: Invalid target %s passed to spell cast by %s", target->GetGUID().ToString().c_str(), GetGUID().ToString().c_str());
- return SPELL_FAILED_BAD_TARGETS;
- }
- }
- return CastSpell(targets, spellId, args);
-}
-
-SpellCastResult WorldObject::CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args /*= { }*/)
-{
- SpellCastTargets targets;
- targets.SetDst(dest);
- return CastSpell(targets, spellId, args);
+ return spell->prepare(*targets.Targets, args.TriggeringAura);
}
// function based on function Unit::CanAttack from 13850 client
diff --git a/src/server/game/Entities/Object/Object.h b/src/server/game/Entities/Object/Object.h
index 7a32337a74b..f1fd3825eca 100644
--- a/src/server/game/Entities/Object/Object.h
+++ b/src/server/game/Entities/Object/Object.h
@@ -94,7 +94,7 @@ class TC_GAME_API Object
virtual void BuildCreateUpdateBlockForPlayer(UpdateData* data, Player* target) const;
void SendUpdateToPlayer(Player* player);
- void BuildValuesUpdateBlockForPlayer(UpdateData* data, Player* target) const;
+ void BuildValuesUpdateBlockForPlayer(UpdateData* data, Player const* target) const;
void BuildOutOfRangeUpdateBlock(UpdateData* data) const;
void BuildMovementUpdateBlock(UpdateData* data, uint32 flags = 0) const;
@@ -163,40 +163,40 @@ class TC_GAME_API Object
void ForceValuesUpdateAtIndex(uint32);
inline bool IsPlayer() const { return GetTypeId() == TYPEID_PLAYER; }
- static Player* ToPlayer(Object* o) { if (o && o->IsPlayer()) return reinterpret_cast<Player*>(o); else return nullptr; }
- static Player const* ToPlayer(Object const* o) { if (o && o->IsPlayer()) return reinterpret_cast<Player const*>(o); else return nullptr; }
- Player* ToPlayer() { return ToPlayer(this); }
- Player const* ToPlayer() const { return ToPlayer(this); }
+ static Player* ToPlayer(Object* o) { return o ? o->ToPlayer() : nullptr; }
+ static Player const* ToPlayer(Object const* o) { return o ? o->ToPlayer() : nullptr; }
+ Player* ToPlayer() { if (IsPlayer()) return reinterpret_cast<Player*>(this); else return nullptr; }
+ Player const* ToPlayer() const { if (IsPlayer()) return reinterpret_cast<Player const*>(this); else return nullptr; }
inline bool IsCreature() const { return GetTypeId() == TYPEID_UNIT; }
- static Creature* ToCreature(Object* o) { if (o && o->IsCreature()) return reinterpret_cast<Creature*>(o); else return nullptr; }
- static Creature const* ToCreature(Object const* o) { if (o && o->IsCreature()) return reinterpret_cast<Creature const*>(o); else return nullptr; }
- Creature* ToCreature() { return ToCreature(this); }
- Creature const* ToCreature() const { return ToCreature(this); }
+ static Creature* ToCreature(Object* o) { return o ? o->ToCreature() : nullptr; }
+ static Creature const* ToCreature(Object const* o) { return o ? o->ToCreature() : nullptr; }
+ Creature* ToCreature() { if (IsCreature()) return reinterpret_cast<Creature*>(this); else return nullptr; }
+ Creature const* ToCreature() const { if (IsCreature()) return reinterpret_cast<Creature const*>(this); else return nullptr; }
inline bool IsUnit() const { return isType(TYPEMASK_UNIT); }
- static Unit* ToUnit(Object* o) { if (o && o->IsUnit()) return reinterpret_cast<Unit*>(o); else return nullptr; }
- static Unit const* ToUnit(Object const* o) { if (o && o->IsUnit()) return reinterpret_cast<Unit const*>(o); else return nullptr; }
- Unit* ToUnit() { return ToUnit(this); }
- Unit const* ToUnit() const { return ToUnit(this); }
+ static Unit* ToUnit(Object* o) { return o ? o->ToUnit() : nullptr; }
+ static Unit const* ToUnit(Object const* o) { return o ? o->ToUnit() : nullptr; }
+ Unit* ToUnit() { if (IsUnit()) return reinterpret_cast<Unit*>(this); else return nullptr; }
+ Unit const* ToUnit() const { if (IsUnit()) return reinterpret_cast<Unit const*>(this); else return nullptr; }
inline bool IsGameObject() const { return GetTypeId() == TYPEID_GAMEOBJECT; }
- static GameObject* ToGameObject(Object* o) { if (o && o->IsGameObject()) return reinterpret_cast<GameObject*>(o); else return nullptr; }
- static GameObject const* ToGameObject(Object const* o) { if (o && o->IsGameObject()) return reinterpret_cast<GameObject const*>(o); else return nullptr; }
- GameObject* ToGameObject() { return ToGameObject(this); }
- GameObject const* ToGameObject() const { return ToGameObject(this); }
+ static GameObject* ToGameObject(Object* o) { return o ? o->ToGameObject() : nullptr; }
+ static GameObject const* ToGameObject(Object const* o) { return o ? o->ToGameObject() : nullptr; }
+ GameObject* ToGameObject() { if (IsGameObject()) return reinterpret_cast<GameObject*>(this); else return nullptr; }
+ GameObject const* ToGameObject() const { if (IsGameObject()) return reinterpret_cast<GameObject const*>(this); else return nullptr; }
inline bool IsCorpse() const { return GetTypeId() == TYPEID_CORPSE; }
- static Corpse* ToCorpse(Object* o) { if (o && o->IsCorpse()) return reinterpret_cast<Corpse*>(o); else return nullptr; }
- static Corpse const* ToCorpse(Object const* o) { if (o && o->IsCorpse()) return reinterpret_cast<Corpse const*>(o); else return nullptr; }
- Corpse* ToCorpse() { return ToCorpse(this); }
- Corpse const* ToCorpse() const { return ToCorpse(this); }
+ static Corpse* ToCorpse(Object* o) { return o ? o->ToCorpse() : nullptr; }
+ static Corpse const* ToCorpse(Object const* o) { return o ? o->ToCorpse() : nullptr; }
+ Corpse* ToCorpse() { if (IsCorpse()) return reinterpret_cast<Corpse*>(this); else return nullptr; }
+ Corpse const* ToCorpse() const { if (IsCorpse()) return reinterpret_cast<Corpse const*>(this); else return nullptr; }
inline bool IsDynObject() const { return GetTypeId() == TYPEID_DYNAMICOBJECT; }
- static DynamicObject* ToDynObject(Object* o) { if (o && o->IsDynObject()) return reinterpret_cast<DynamicObject*>(o); else return nullptr; }
- static DynamicObject const* ToDynObject(Object const* o) { if (o && o->IsDynObject()) return reinterpret_cast<DynamicObject const*>(o); else return nullptr; }
- DynamicObject* ToDynObject() { return ToDynObject(this); }
- DynamicObject const* ToDynObject() const { return ToDynObject(this); }
+ static DynamicObject* ToDynObject(Object* o) { return o ? o->ToDynObject() : nullptr; }
+ static DynamicObject const* ToDynObject(Object const* o) { return o ? o->ToDynObject() : nullptr; }
+ DynamicObject* ToDynObject() { if (IsDynObject()) return reinterpret_cast<DynamicObject*>(this); else return nullptr; }
+ DynamicObject const* ToDynObject() const { if (IsDynObject()) return reinterpret_cast<DynamicObject const*>(this); else return nullptr; }
virtual std::string GetDebugInfo() const;
@@ -211,7 +211,7 @@ class TC_GAME_API Object
uint32 GetUpdateFieldData(Player const* target, uint32*& flags) const;
void BuildMovementUpdate(ByteBuffer* data, uint16 flags) const;
- virtual void BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, Player* target) const;
+ virtual void BuildValuesUpdate(uint8 updatetype, ByteBuffer* data, Player const* target) const;
uint16 m_objectType;
@@ -246,10 +246,12 @@ class TC_GAME_API Object
// for output helpfull error messages from asserts
bool PrintIndexError(uint32 index, bool set) const;
Object(Object const& right) = delete;
+ Object(Object&& right) = delete;
Object& operator=(Object const& right) = delete;
+ Object& operator=(Object&& right) = delete;
};
-template <class T_VALUES, class T_FLAGS, class FLAG_TYPE, uint8 ARRAY_SIZE>
+template <class T_VALUES, class T_FLAGS, class FLAG_TYPE, size_t ARRAY_SIZE>
class FlaggedValuesArray32
{
public:
@@ -322,9 +324,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
InstanceScript* GetInstanceScript() const;
std::string const& GetName() const { return m_name; }
- void SetName(std::string const& newname) { m_name = newname; }
+ void SetName(std::string newname) { m_name = std::move(newname); }
- virtual std::string const& GetNameForLocaleIdx(LocaleConstant /*locale_idx*/) const { return m_name; }
+ virtual std::string const& GetNameForLocaleIdx(LocaleConstant /*locale*/) const { return m_name; }
float GetDistance(WorldObject const* obj) const;
float GetDistance(Position const& pos) const;
@@ -451,9 +453,7 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
bool IsNeutralToAll() const;
// CastSpell's third arg can be a variety of things - check out CastSpellExtraArgs' constructors!
- SpellCastResult CastSpell(SpellCastTargets const& targets, uint32 spellId, CastSpellExtraArgs const& args = { });
- SpellCastResult CastSpell(WorldObject* target, uint32 spellId, CastSpellExtraArgs const& args = { });
- SpellCastResult CastSpell(Position const& dest, uint32 spellId, CastSpellExtraArgs const& args = { });
+ SpellCastResult CastSpell(CastSpellTargetArg const& targets, uint32 spellId, CastSpellExtraArgs const& args = { });
bool IsValidAttackTarget(WorldObject const* target, SpellInfo const* bySpell = nullptr) const;
bool IsValidAssistTarget(WorldObject const* target, SpellInfo const* bySpell = nullptr) const;
@@ -475,7 +475,6 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
void UpdatePositionData();
void BuildUpdate(UpdateDataMapType&) override;
-
bool AddToObjectUpdate() override;
void RemoveFromObjectUpdate() override;