[Cleanup] Cleanup Owner Related Mob Methods (#3960)

* [Cleanup] Cleanup Owner Related Mob Methods

# Notes
- Cleanup `GetOwner()`, `GetOwnerOrSelf()`, `GetUltimateOwner()`, `HasOwner()`, and `IsPet()` methods.

* Update mob.cpp
This commit is contained in:
Alex King 2024-01-12 23:59:30 -05:00 committed by GitHub
parent 06e8d258e4
commit 6968a70310
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 25 deletions

View File

@ -4373,58 +4373,78 @@ void Mob::ChangeSize(float in_size = 0, bool unrestricted)
SendAppearancePacket(AppearanceType::Size, static_cast<uint32>(in_size));
}
Mob* Mob::GetOwnerOrSelf() {
if (!GetOwnerID())
Mob* Mob::GetOwnerOrSelf()
{
if (!GetOwnerID()) {
return this;
Mob* owner = entity_list.GetMob(GetOwnerID());
if (!owner) {
}
Mob* m = entity_list.GetMob(GetOwnerID());
if (!m) {
SetOwnerID(0);
return(this);
return this;
}
if (owner->GetPetID() == GetID()) {
return owner;
if (m->GetPetID() == GetID()) {
return m;
}
if(IsNPC() && CastToNPC()->GetSwarmInfo()){
return (CastToNPC()->GetSwarmInfo()->GetOwner());
if (IsNPC() && CastToNPC()->GetSwarmInfo()){
return CastToNPC()->GetSwarmInfo()->GetOwner();
}
SetOwnerID(0);
return this;
}
Mob* Mob::GetOwner() {
Mob* owner = entity_list.GetMob(GetOwnerID());
if (owner && owner->GetPetID() == GetID()) {
Mob* m = entity_list.GetMob(GetOwnerID());
return owner;
if (m && m->GetPetID() == GetID()) {
return m;
}
if(IsNPC() && CastToNPC()->GetSwarmInfo()){
return (CastToNPC()->GetSwarmInfo()->GetOwner());
return CastToNPC()->GetSwarmInfo()->GetOwner();
}
SetOwnerID(0);
return 0;
}
Mob* Mob::GetUltimateOwner()
{
Mob* Owner = GetOwner();
Mob* m = GetOwner();
if(!Owner)
if (!m) {
return this;
}
while(Owner && Owner->HasOwner())
Owner = Owner->GetOwner();
while (m && m->HasOwner()) {
m = m->GetOwner();
}
return Owner ? Owner : this;
return m ? m : this;
}
void Mob::SetOwnerID(uint16 NewOwnerID) {
if (NewOwnerID == GetID() && NewOwnerID != 0) // ok, no charming yourself now =p
void Mob::SetOwnerID(uint16 new_owner_id) {
if (new_owner_id && new_owner_id == GetID()) {
return;
ownerid = NewOwnerID;
}
ownerid = new_owner_id;
// if we're setting the owner ID to 0 and they're not either charmed or not-a-pet then
// they're a normal pet and should be despawned
if (ownerid == 0 && IsNPC() && GetPetType() != petCharmed && GetPetType() != petNone)
if (
!ownerid &&
IsNPC() &&
GetPetType() != petCharmed &&
GetPetType() != petNone
) {
Depop();
}
}
// used in checking for behind (backstab) and checking in front (melee LoS)

View File

@ -1065,10 +1065,10 @@ public:
bool IsTargetLockPet() const { return type_of_pet == petTargetLock; }
inline uint32 GetPetTargetLockID() { return pet_targetlock_id; };
inline void SetPetTargetLockID(uint32 value) { pet_targetlock_id = value; };
void SetOwnerID(uint16 NewOwnerID);
void SetOwnerID(uint16 new_owner_id);
inline uint16 GetOwnerID() const { return ownerid; }
inline virtual bool HasOwner() { if(GetOwnerID()==0){return false;} return( entity_list.GetMob(GetOwnerID()) != 0); }
inline virtual bool IsPet() { return(HasOwner() && !IsMerc()); }
inline virtual bool HasOwner() { if (!GetOwnerID()){ return false; } return entity_list.GetMob(GetOwnerID()) != 0; }
inline virtual bool IsPet() { return HasOwner() && !IsMerc(); }
bool HasPet() const;
inline bool HasTempPetsActive() const { return(hasTempPet); }
inline void SetTempPetsActive(bool i) { hasTempPet = i; }