[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)); SendAppearancePacket(AppearanceType::Size, static_cast<uint32>(in_size));
} }
Mob* Mob::GetOwnerOrSelf() { Mob* Mob::GetOwnerOrSelf()
if (!GetOwnerID()) {
if (!GetOwnerID()) {
return this; return this;
Mob* owner = entity_list.GetMob(GetOwnerID()); }
if (!owner) {
Mob* m = entity_list.GetMob(GetOwnerID());
if (!m) {
SetOwnerID(0); 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); SetOwnerID(0);
return this; return this;
} }
Mob* Mob::GetOwner() { Mob* Mob::GetOwner() {
Mob* owner = entity_list.GetMob(GetOwnerID()); Mob* m = entity_list.GetMob(GetOwnerID());
if (owner && owner->GetPetID() == GetID()) {
return owner; if (m && m->GetPetID() == GetID()) {
return m;
} }
if(IsNPC() && CastToNPC()->GetSwarmInfo()){ if(IsNPC() && CastToNPC()->GetSwarmInfo()){
return (CastToNPC()->GetSwarmInfo()->GetOwner()); return CastToNPC()->GetSwarmInfo()->GetOwner();
} }
SetOwnerID(0); SetOwnerID(0);
return 0; return 0;
} }
Mob* Mob::GetUltimateOwner() Mob* Mob::GetUltimateOwner()
{ {
Mob* Owner = GetOwner(); Mob* m = GetOwner();
if(!Owner) if (!m) {
return this; return this;
}
while(Owner && Owner->HasOwner()) while (m && m->HasOwner()) {
Owner = Owner->GetOwner(); m = m->GetOwner();
}
return Owner ? Owner : this; return m ? m : this;
} }
void Mob::SetOwnerID(uint16 NewOwnerID) { void Mob::SetOwnerID(uint16 new_owner_id) {
if (NewOwnerID == GetID() && NewOwnerID != 0) // ok, no charming yourself now =p if (new_owner_id && new_owner_id == GetID()) {
return; 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 // 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 // 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(); Depop();
}
} }
// used in checking for behind (backstab) and checking in front (melee LoS) // 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; } bool IsTargetLockPet() const { return type_of_pet == petTargetLock; }
inline uint32 GetPetTargetLockID() { return pet_targetlock_id; }; inline uint32 GetPetTargetLockID() { return pet_targetlock_id; };
inline void SetPetTargetLockID(uint32 value) { pet_targetlock_id = value; }; 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 uint16 GetOwnerID() const { return ownerid; }
inline virtual bool HasOwner() { if(GetOwnerID()==0){return false;} return( entity_list.GetMob(GetOwnerID()) != 0); } inline virtual bool HasOwner() { if (!GetOwnerID()){ return false; } return entity_list.GetMob(GetOwnerID()) != 0; }
inline virtual bool IsPet() { return(HasOwner() && !IsMerc()); } inline virtual bool IsPet() { return HasOwner() && !IsMerc(); }
bool HasPet() const; bool HasPet() const;
inline bool HasTempPetsActive() const { return(hasTempPet); } inline bool HasTempPetsActive() const { return(hasTempPet); }
inline void SetTempPetsActive(bool i) { hasTempPet = i; } inline void SetTempPetsActive(bool i) { hasTempPet = i; }