|
| 1 | +/** |
| 2 | + * MaNGOS is a full featured server for World of Warcraft, supporting |
| 3 | + * the following clients: 1.12.x, 2.4.3, 3.3.5a, 4.3.4a and 5.4.8 |
| 4 | + * |
| 5 | + * Copyright (C) 2005-2025 MaNGOS <https://www.getmangos.eu> |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU General Public License as published by |
| 9 | + * the Free Software Foundation; either version 2 of the License, or |
| 10 | + * (at your option) any later version. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program; if not, write to the Free Software |
| 19 | + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 | + * |
| 21 | + * World of Warcraft, and all World of Warcraft or Warcraft art, images, |
| 22 | + * and lore are copyrighted by Blizzard Entertainment, Inc. |
| 23 | + */ |
| 24 | + |
| 25 | +#ifndef MANGOS_H_PETMGR |
| 26 | +#define MANGOS_H_PETMGR |
| 27 | + |
| 28 | +#include "Common.h" |
| 29 | +#include "Pet.h" // PetSaveMode enum + MAX_PET_STABLES constant |
| 30 | + |
| 31 | +class Player; |
| 32 | + |
| 33 | +/** |
| 34 | + * PetMgr — owns a Player's pet-ownership metadata: the stable-slot |
| 35 | + * count persisted with the character row and the temporary-unsummon |
| 36 | + * tracking number used by transports / mounts to bring the same pet |
| 37 | + * back after a short interruption. |
| 38 | + * |
| 39 | + * What this DOES NOT own: |
| 40 | + * - The Pet creature itself (a Creature subclass living in the world, |
| 41 | + * managed by Object/Pet.{cpp,h}). Its lifecycle, AI, spells, and |
| 42 | + * persistence to the `character_pet` table all stay in Pet.cpp. |
| 43 | + * - The pet stable opcode handlers (CMSG_STABLE_PET and friends in |
| 44 | + * WorldHandlers/NPCHandler.cpp). They keep reading/updating the slot |
| 45 | + * count through Player's public accessors, so the stable-purchase |
| 46 | + * economics (gold cost via StableSlotPricesStore, MAX_PET_STABLES |
| 47 | + * cap) are untouched. |
| 48 | + */ |
| 49 | +class PetMgr |
| 50 | +{ |
| 51 | + public: |
| 52 | + explicit PetMgr(Player* owner) |
| 53 | + : m_owner(owner), m_stableSlots(0), m_temporaryUnsummonedPetNumber(0) |
| 54 | + { |
| 55 | + } |
| 56 | + |
| 57 | + /// Number of paid stable slots the character has unlocked. |
| 58 | + /// Persisted to `characters`.stable_slots; clamped to |
| 59 | + /// MAX_PET_STABLES on load. |
| 60 | + uint32 GetStableSlots() const { return m_stableSlots; } |
| 61 | + void SetStableSlots(uint32 slots) { m_stableSlots = slots; } |
| 62 | + |
| 63 | + /// Called from Player::LoadFromDB with the raw column value. |
| 64 | + /// Clamps to MAX_PET_STABLES and logs a server error on |
| 65 | + /// out-of-range data so an operator can detect a tampered row. |
| 66 | + void LoadStableSlotsFromField(uint32 raw); |
| 67 | + |
| 68 | + /// Pet number that was active before a temporary unsummon (e.g. |
| 69 | + /// transport zone-in). Zero means no pending resummon. |
| 70 | + uint32 GetTemporaryUnsummonedPetNumber() const { return m_temporaryUnsummonedPetNumber; } |
| 71 | + void SetTemporaryUnsummonedPetNumber(uint32 petnumber) { m_temporaryUnsummonedPetNumber = petnumber; } |
| 72 | + |
| 73 | + /// If the owner currently has a controlled pet, asks it to |
| 74 | + /// unsummon with the given mode (see PetSaveMode). |
| 75 | + void Remove(PetSaveMode mode); |
| 76 | + |
| 77 | + /// SMSG_PET_SPELLS with an empty guid — clears the pet action |
| 78 | + /// bar UI on the client. |
| 79 | + void RemoveActionBar(); |
| 80 | + |
| 81 | + /// Stash the current non-temporary pet's number so we can bring |
| 82 | + /// it back later, then unsummon with PET_SAVE_AS_CURRENT. |
| 83 | + void UnsummonTemporaryIfAny(); |
| 84 | + |
| 85 | + /// Counterpart to UnsummonTemporaryIfAny: if we stashed a pet |
| 86 | + /// number and it's now appropriate to resummon, load it from DB. |
| 87 | + /// Clears the stash either way. |
| 88 | + void ResummonTemporaryUnsummonedIfAny(); |
| 89 | + |
| 90 | + private: |
| 91 | + Player* m_owner; |
| 92 | + uint32 m_stableSlots; |
| 93 | + uint32 m_temporaryUnsummonedPetNumber; |
| 94 | +}; |
| 95 | + |
| 96 | +#endif // MANGOS_H_PETMGR |
0 commit comments