aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Entities/Pet/PetDefines.h
blob: 3be0ab20d439d3fe45063ed2dce1b914ef2716d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
/*
 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or (at your
 * option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef TRINITYCORE_PET_DEFINES_H
#define TRINITYCORE_PET_DEFINES_H

#include "Define.h"
#include "Optional.h"
#include <array>
#include <string>
#include <vector>

enum ReactStates : uint8;

enum PetType : uint8
{
    SUMMON_PET              = 0,
    HUNTER_PET              = 1,
    MAX_PET_TYPE
};

#define MAX_ACTIVE_PETS         5
#define MAX_PET_STABLES         200

// stored in character_pet.slot
enum PetSaveMode : int16
{
    PET_SAVE_AS_DELETED        = -2,                        // not saved in fact
    PET_SAVE_AS_CURRENT        = -3,                        // in current slot (with player)
    PET_SAVE_FIRST_ACTIVE_SLOT =  0,
    PET_SAVE_LAST_ACTIVE_SLOT  = PET_SAVE_FIRST_ACTIVE_SLOT + MAX_ACTIVE_PETS,
    PET_SAVE_FIRST_STABLE_SLOT =  5,
    PET_SAVE_LAST_STABLE_SLOT  = PET_SAVE_FIRST_STABLE_SLOT + MAX_PET_STABLES, // last in DB stable slot index
    PET_SAVE_NOT_IN_SLOT       = -1                         // for avoid conflict with stable size grow will use negative value
};

constexpr bool IsActivePetSlot(PetSaveMode slot)
{
    return slot >= PET_SAVE_FIRST_ACTIVE_SLOT && slot < PET_SAVE_LAST_ACTIVE_SLOT;
}

constexpr bool IsStabledPetSlot(PetSaveMode slot)
{
    return slot >= PET_SAVE_FIRST_STABLE_SLOT && slot < PET_SAVE_LAST_STABLE_SLOT;
}

enum PetStableFlags : uint8
{
    PET_STABLE_ACTIVE   = 0x1,
    PET_STABLE_INACTIVE = 0x2,
    PET_STABLE_FAVORITE = 0x8
};

enum PetSpellState
{
    PETSPELL_UNCHANGED = 0,
    PETSPELL_CHANGED   = 1,
    PETSPELL_NEW       = 2,
    PETSPELL_REMOVED   = 3
};

enum PetSpellType
{
    PETSPELL_NORMAL = 0,
    PETSPELL_FAMILY = 1,
    PETSPELL_TALENT = 2
};

enum class PetActionFeedback : uint8
{
    None            = 0,
    Dead            = 1,
    NoTarget        = 2,
    InvalidTarget   = 3,
    NoPath          = 4
};

enum PetTalk
{
    PET_TALK_SPECIAL_SPELL  = 0,
    PET_TALK_ATTACK         = 1
};

#define PET_FOLLOW_DIST  1.0f
#define PET_FOLLOW_ANGLE float(M_PI)

enum class PetTameResult : uint8
{
    Ok                      = 0,
    InvalidCreature         = 1,
    TooMany                 = 2,
    CreatureAlreadyOwned    = 3,
    NotTameable             = 4,
    AnotherSummonActive     = 5,
    UnitsCantTame           = 6,
    NoPetAvailable          = 7,
    InternalError           = 8,
    TooHighLevel            = 9,
    Dead                    = 10,
    NotDead                 = 11,
    CantControlExotic       = 12,
    InvalidSlot             = 13,
    EliteTooHighLevel       = 14
};

enum class StableResult : uint8
{
    MaxSlots              = 0,
    InsufficientFunds     = 1,                              // "you don't have enough money"
    NotStableMaster       = 2,
    InvalidSlot           = 3,                              // "That slot is locked"
    NoPet                 = 4,
    AlreadyStabled        = 5,
    AlreadySummoned       = 6,
    NotFound              = 7,
    StableSuccess         = 8,                              // stable success
    UnstableSuccess       = 9,                              // unstable/swap success
    ReviveSuccess         = 10,
    CantControlExotic     = 11,                             // "you are unable to control exotic creatures"
    InternalError         = 12,                             // "Internal pet error"
    CheckForLuaHack       = 13,
    BuySlotSuccess        = 14,
    FavoriteToggle        = 15,
    PetRenamed            = 16
};

constexpr uint32 CALL_PET_SPELL_ID = 883;
constexpr uint32 PET_SUMMONING_DISORIENTATION = 32752;

class PetStable
{
public:
    struct PetInfo
    {
        PetInfo() { }

        std::string Name;
        std::string ActionBar;
        uint32 PetNumber = 0;
        uint32 CreatureId = 0;
        uint32 DisplayId = 0;
        uint32 Experience = 0;
        uint32 Health = 0;
        uint32 Mana = 0;
        uint32 LastSaveTime = 0;
        uint32 CreatedBySpellId = 0;
        uint16 SpecializationId = 0;
        uint8 Level = 0;
        ReactStates ReactState = ReactStates(0);
        PetType Type = MAX_PET_TYPE;
        bool WasRenamed = false;
    };

    Optional<uint32> CurrentPetIndex;                               // index into ActivePets or UnslottedPets if highest bit is set
    std::array<Optional<PetInfo>, MAX_ACTIVE_PETS> ActivePets;      // PET_SAVE_FIRST_ACTIVE_SLOT - PET_SAVE_LAST_ACTIVE_SLOT
    std::array<Optional<PetInfo>, MAX_PET_STABLES> StabledPets;     // PET_SAVE_FIRST_STABLE_SLOT - PET_SAVE_LAST_STABLE_SLOT
    std::vector<PetInfo> UnslottedPets;                             // PET_SAVE_NOT_IN_SLOT

    PetInfo* GetCurrentPet() { return const_cast<PetInfo*>(const_cast<PetStable const*>(this)->GetCurrentPet()); }
    PetInfo const* GetCurrentPet() const
    {
        if (!CurrentPetIndex)
            return nullptr;

        if (Optional<uint32> activePetIndex = GetCurrentActivePetIndex())
            return ActivePets[*activePetIndex] ? &ActivePets[*activePetIndex].value() : nullptr;

        if (Optional<uint32> unslottedPetIndex = GetCurrentUnslottedPetIndex())
            return *unslottedPetIndex < UnslottedPets.size() ? &UnslottedPets[*unslottedPetIndex] : nullptr;

        return nullptr;
    }

    Optional<uint32> GetCurrentActivePetIndex() const { return CurrentPetIndex && ((*CurrentPetIndex & UnslottedPetIndexMask) == 0) ? CurrentPetIndex : std::nullopt; }
    void SetCurrentActivePetIndex(uint32 index) { CurrentPetIndex = index; }
    Optional<uint32> GetCurrentUnslottedPetIndex() const { return CurrentPetIndex && ((*CurrentPetIndex & UnslottedPetIndexMask) != 0) ? Optional<uint32>(*CurrentPetIndex & ~UnslottedPetIndexMask) : std::nullopt; }
    void SetCurrentUnslottedPetIndex(uint32 index) { CurrentPetIndex = index | UnslottedPetIndexMask; }

private:
    static constexpr uint32 UnslottedPetIndexMask = 0x80000000;
};

#endif