diff options
| author | Meji <alvaromegias_46@hotmail.com> | 2021-09-29 22:26:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-09-29 22:26:25 +0200 |
| commit | de4eaa0de9565da604fa3b6e2b4b59efe117fd7a (patch) | |
| tree | 1ad955f009dc8796f8d15bc5e2154082c8e8fc85 /src/server/game/BattlePets | |
| parent | f507737ecff5d564da999c56d672274387d70ec2 (diff) | |
Core/BattlePets: Misc fixes (#26964)
* Define BattlePetSpeciesFlags enum class.
* Define BattlePetDbFlags enum class.
* Added check to prevent the pet from being caged if its species has flag BattlePetSpeciesFlags::NotTradable.
* Added check to prevent the pet from being caged if it's in battle pet slots.
* Added check to prevent the pet from being caged if its health is below maximum health.
* Only add pet if the species has flag BattlePetSpeciesFlags::WellKnown.
* Added function to check flag BattlePetSpeciesFlags::LegacyAccountUnique to avoid learning copies of unique pets.
* Implemented CMSG_BATTLE_PET_CLEAR_FANFARE.
Diffstat (limited to 'src/server/game/BattlePets')
| -rw-r--r-- | src/server/game/BattlePets/BattlePetMgr.cpp | 46 | ||||
| -rw-r--r-- | src/server/game/BattlePets/BattlePetMgr.h | 29 |
2 files changed, 68 insertions, 7 deletions
diff --git a/src/server/game/BattlePets/BattlePetMgr.cpp b/src/server/game/BattlePets/BattlePetMgr.cpp index 55531bf20fa..5938595fb50 100644 --- a/src/server/game/BattlePets/BattlePetMgr.cpp +++ b/src/server/game/BattlePets/BattlePetMgr.cpp @@ -196,9 +196,9 @@ void BattlePetMgr::LoadFromDB(PreparedQueryResult pets, PreparedQueryResult slot if (BattlePetSpeciesEntry const* speciesEntry = sBattlePetSpeciesStore.LookupEntry(species)) { - if (GetPetCount(species) >= MAX_BATTLE_PETS_PER_SPECIES) + if (HasMaxPetCount(speciesEntry)) { - TC_LOG_ERROR("misc", "Battlenet account with id %u has more than 3 battle pets of species %u", _owner->GetBattlenetAccountId(), species); + TC_LOG_ERROR("misc", "Battlenet account with id %u has more than maximum battle pets of species %u", _owner->GetBattlenetAccountId(), species); continue; } @@ -314,6 +314,9 @@ void BattlePetMgr::AddPet(uint32 species, uint32 creatureId, uint16 breed, uint8 if (!battlePetSpecies) // should never happen return; + if (!battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::WellKnown)) // Not learnable + return; + BattlePet pet; pet.PacketInfo.Guid = ObjectGuid::Create<HighGuid::BattlePet>(sObjectMgr->GetGenerator<HighGuid::BattlePet>().Generate()); pet.PacketInfo.Species = species; @@ -351,6 +354,27 @@ void BattlePetMgr::RemovePet(ObjectGuid guid) _owner->GetPlayer()->RemoveSpell(speciesEntry->SummonSpellID);*/ } +void BattlePetMgr::ClearFanfare(ObjectGuid guid) +{ + BattlePet* pet = GetPet(guid); + if (!pet) + return; + + pet->PacketInfo.Flags &= ~uint16(BattlePetDbFlags::FanfareNeeded); + + if (pet->SaveInfo != BATTLE_PET_NEW) + pet->SaveInfo = BATTLE_PET_CHANGED; +} + +bool BattlePetMgr::IsPetInSlot(ObjectGuid guid) +{ + for (WorldPackets::BattlePet::BattlePetSlot const& slot : _slots) + if (slot.Pet.Guid == guid) + return true; + + return false; +} + uint8 BattlePetMgr::GetPetCount(uint32 species) const { return uint8(std::count_if(_pets.begin(), _pets.end(), [species](std::pair<uint64 const, BattlePet> const& pet) @@ -359,6 +383,13 @@ uint8 BattlePetMgr::GetPetCount(uint32 species) const })); } +bool BattlePetMgr::HasMaxPetCount(BattlePetSpeciesEntry const* speciesEntry) const +{ + uint8 maxPetsPerSpecies = speciesEntry->GetFlags().HasFlag(BattlePetSpeciesFlags::LegacyAccountUnique) ? 1 : DEFAULT_MAX_BATTLE_PETS_PER_SPECIES; + + return GetPetCount(speciesEntry->ID) >= maxPetsPerSpecies; +} + uint32 BattlePetMgr::GetPetUniqueSpeciesCount() const { std::set<uint32> speciesIds; @@ -399,6 +430,16 @@ void BattlePetMgr::CageBattlePet(ObjectGuid guid) if (!pet) return; + if (BattlePetSpeciesEntry const* battlePetSpecies = sBattlePetSpeciesStore.LookupEntry(pet->PacketInfo.Species)) + if (battlePetSpecies->GetFlags().HasFlag(BattlePetSpeciesFlags::NotTradable)) + return; + + if (IsPetInSlot(guid)) + return; + + if (pet->PacketInfo.Health < pet->PacketInfo.MaxHealth) + return; + ItemPosCountVec dest; if (_owner->GetPlayer()->CanStoreNewItem(NULL_BAG, NULL_SLOT, dest, BATTLE_PET_CAGE_ITEM_ID, 1) != EQUIP_ERR_OK) @@ -413,7 +454,6 @@ void BattlePetMgr::CageBattlePet(ObjectGuid guid) item->SetModifier(ITEM_MODIFIER_BATTLE_PET_LEVEL, pet->PacketInfo.Level); item->SetModifier(ITEM_MODIFIER_BATTLE_PET_DISPLAY_ID, pet->PacketInfo.CreatureID); - // FIXME: "You create: ." - item name missing in chat _owner->GetPlayer()->SendNewItem(item, 1, true, false); RemovePet(guid); diff --git a/src/server/game/BattlePets/BattlePetMgr.h b/src/server/game/BattlePets/BattlePetMgr.h index 49ed9edc23f..721c1aafa3d 100644 --- a/src/server/game/BattlePets/BattlePetMgr.h +++ b/src/server/game/BattlePets/BattlePetMgr.h @@ -22,14 +22,32 @@ #include "DatabaseEnvFwd.h" #include <unordered_map> +struct BattlePetSpeciesEntry; + enum BattlePetMisc { - MAX_PET_BATTLE_SLOTS = 3, - MAX_BATTLE_PETS_PER_SPECIES = 3, - BATTLE_PET_CAGE_ITEM_ID = 82800, - DEFAULT_SUMMON_BATTLE_PET_SPELL = 118301 + MAX_PET_BATTLE_SLOTS = 3, + DEFAULT_MAX_BATTLE_PETS_PER_SPECIES = 3, + BATTLE_PET_CAGE_ITEM_ID = 82800, + DEFAULT_SUMMON_BATTLE_PET_SPELL = 118301 }; +enum class BattlePetDbFlags : uint16 +{ + None = 0x000, + Favorite = 0x001, + Converted = 0x002, + Revoked = 0x004, + LockedForConvert = 0x008, + Ability0Selection = 0x010, + Ability1Selection = 0x020, + Ability2Selection = 0x040, + FanfareNeeded = 0x080, + DisplayOverridden = 0x100 +}; + +DEFINE_ENUM_FLAG(BattlePetDbFlags); + // 6.2.4 enum FlagsControlType { @@ -112,8 +130,11 @@ public: BattlePet* GetPet(ObjectGuid guid); void AddPet(uint32 species, uint32 creatureId, uint16 breed, uint8 quality, uint16 level = 1); void RemovePet(ObjectGuid guid); + void ClearFanfare(ObjectGuid guid); + bool IsPetInSlot(ObjectGuid guid); uint8 GetPetCount(uint32 species) const; + bool HasMaxPetCount(BattlePetSpeciesEntry const* speciesEntry) const; uint32 GetPetUniqueSpeciesCount() const; WorldPackets::BattlePet::BattlePetSlot* GetSlot(uint8 slot) { return slot < _slots.size() ? &_slots[slot] : nullptr; } |
