feat(Core/Pets): Management refactoring (#9712)

* feat(Core/Pets): rework managment

* 1

* 2

* 3

* 4

* 5

* cs pet

* check before ressurect

* pet DECLINED_NAMES

* display

- https://github.com/azerothcore/azerothcore-wotlk/issues/9297

* ArenaSpectator

* 1
This commit is contained in:
Kargatum
2021-12-31 04:45:13 +07:00
committed by GitHub
parent 24ab99919a
commit e12494d993
24 changed files with 1173 additions and 1208 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -21,9 +21,8 @@
#include "PetDefines.h"
#include "TemporarySummon.h"
#define PET_FOCUS_REGEN_INTERVAL 4 * IN_MILLISECONDS
#define PET_LOSE_HAPPINES_INTERVAL 7500
#define HAPPINESS_LEVEL_SIZE 333000
constexpr auto PET_LOSE_HAPPINES_INTERVAL = 7500;
constexpr auto HAPPINESS_LEVEL_SIZE = 333000;
struct PetSpell
{
@@ -32,20 +31,6 @@ struct PetSpell
PetSpellType type;
};
class AsynchPetSummon
{
public:
AsynchPetSummon(uint32 entry, Position position, PetType petType, uint32 duration, uint32 createdBySpell, ObjectGuid casterGUID, int32 healthPct = 0) :
m_entry(entry), pos(position), m_petType(petType), m_duration(duration), m_createdBySpell(createdBySpell), m_casterGUID(casterGUID), m_healthPct(healthPct) { }
uint32 m_entry;
Position pos;
PetType m_petType;
uint32 m_duration, m_createdBySpell;
ObjectGuid m_casterGUID;
int32 m_healthPct;
};
typedef std::unordered_map<uint32, PetSpell> PetSpellMap;
typedef std::vector<uint32> AutoSpellList;
@@ -55,7 +40,7 @@ class Pet : public Guardian
{
public:
explicit Pet(Player* owner, PetType type = MAX_PET_TYPE);
~Pet() override;
~Pet() override = default;
void AddToWorld() override;
void RemoveFromWorld() override;
@@ -65,7 +50,7 @@ public:
PetType getPetType() const { return m_petType; }
void setPetType(PetType type) { m_petType = type; }
bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; }
bool isTemporarySummoned() const { return m_duration > 0; }
bool isTemporarySummoned() const { return m_duration > 0s; }
bool IsPermanentPetFor(Player* owner) const; // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
@@ -73,10 +58,11 @@ public:
bool CreateBaseAtCreature(Creature* creature);
bool CreateBaseAtCreatureInfo(CreatureTemplate const* cinfo, Unit* owner);
bool CreateBaseAtTamed(CreatureTemplate const* cinfo, Map* map, uint32 phaseMask);
static SpellCastResult TryLoadFromDB(Player* owner, bool current = false, PetType mandatoryPetType = MAX_PET_TYPE, bool checkDead = false);
static bool LoadPetFromDB(Player* owner, uint8 asynchLoadType, uint32 petentry = 0, uint32 petnumber = 0, bool current = false, AsynchPetSummon* info = nullptr);
bool isBeingLoaded() const override { return m_loading;}
void SavePetToDB(PetSaveMode mode, bool logout);
static std::pair<PetStable::PetInfo const*, PetSaveMode> GetLoadPetInfo(PetStable const& stable, uint32 petEntry, uint32 petnumber, bool current);
bool LoadPetFromDB(Player* owner, uint32 petEntry, uint32 petnumber, bool current);
bool isBeingLoaded() const override { return m_loading; }
void SavePetToDB(PetSaveMode mode);
void FillPetInfo(PetStable::PetInfo* petInfo) const;
void Remove(PetSaveMode mode, bool returnreagent = false);
static void DeleteFromDB(ObjectGuid::LowType guidlow);
@@ -99,19 +85,8 @@ public:
void SynchronizeLevelWithOwner();
bool HaveInDiet(ItemTemplate const* item) const;
uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel) const;
void SetDuration(int32 dur) { m_duration = dur; }
int32 GetDuration() const { return m_duration; }
/*
bool UpdateStats(Stats stat);
bool UpdateAllStats();
void UpdateResistances(uint32 school);
void UpdateArmor();
void UpdateMaxHealth();
void UpdateMaxPower(Powers power);
void UpdateAttackPowerAndDamage(bool ranged = false);
void UpdateDamagePhysical(WeaponAttackType attType);
*/
void SetDuration(Milliseconds dur) { m_duration = dur; }
Milliseconds GetDuration() const { return m_duration; }
void ToggleAutocast(SpellInfo const* spellInfo, bool apply);
@@ -124,8 +99,8 @@ public:
void ClearCastWhenWillAvailable();
void RemoveSpellCooldown(uint32 spell_id, bool update /* = false */);
void _SaveSpellCooldowns(CharacterDatabaseTransaction trans, bool logout);
void _SaveAuras(CharacterDatabaseTransaction trans, bool logout);
void _SaveSpellCooldowns(CharacterDatabaseTransaction trans);
void _SaveAuras(CharacterDatabaseTransaction trans);
void _SaveSpells(CharacterDatabaseTransaction trans);
void _LoadSpellCooldowns(PreparedQueryResult result);
@@ -139,6 +114,7 @@ public:
bool unlearnSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
bool removeSpell(uint32 spell_id, bool learn_prev, bool clear_ab = true);
void CleanupActionBar();
std::string GenerateActionBarData() const;
PetSpellMap m_spells;
AutoSpellList m_autospells;
@@ -159,37 +135,30 @@ public:
void SetAuraUpdateMaskForRaid(uint8 slot) { m_auraRaidUpdateMask |= (uint64(1) << slot); }
void ResetAuraUpdateMaskForRaid() { m_auraRaidUpdateMask = 0; }
DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
DeclinedName const* GetDeclinedNames() const { return m_declinedname.get(); }
bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
Player* GetOwner() const { return m_owner; }
Player* GetOwner() const;
void SetLoading(bool load) { m_loading = load; }
void HandleAsynchLoadSucceed();
static void HandleAsynchLoadFailed(AsynchPetSummon* info, Player* player, uint8 asynchLoadType, uint8 loadResult);
uint8 GetAsynchLoadType() const { return asynchLoadType; }
void SetAsynchLoadType(uint8 type) { asynchLoadType = type; }
[[nodiscard]] bool HasTempSpell() const { return m_tempspell != 0; }
protected:
Player* m_owner;
int32 m_happinessTimer;
PetType m_petType;
int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
Milliseconds m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
uint64 m_auraRaidUpdateMask;
bool m_loading;
int32 m_petRegenTimer; // xinef: used for focus regeneration
Milliseconds m_petRegenTimer; // xinef: used for focus regeneration
DeclinedName* m_declinedname;
std::unique_ptr<DeclinedName> m_declinedname;
Unit* m_tempspellTarget;
Unit* m_tempoldTarget;
bool m_tempspellIsPositive;
uint32 m_tempspell;
uint8 asynchLoadType;
private:
void SaveToDB(uint32, uint8, uint32) override // override of Creature::SaveToDB - must not be called
{

View File

@@ -18,17 +18,25 @@
#ifndef AZEROTHCORE_PET_DEFINES_H
#define AZEROTHCORE_PET_DEFINES_H
enum PetType
#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 = 4
};
#define MAX_PET_STABLES 4
constexpr auto MAX_PET_STABLES = 4;
// stored in character_pet.slot
enum PetSaveMode
enum PetSaveMode : int8
{
PET_SAVE_AS_DELETED = -1, // not saved in fact
PET_SAVE_AS_CURRENT = 0, // in current slot (with player)
@@ -73,24 +81,6 @@ enum PetTalk
PET_TALK_ATTACK = 1
};
// used at pet loading query list preparing, and later result selection
enum PetLoadQueryIndex
{
PET_LOAD_QUERY_LOADAURAS = 0,
PET_LOAD_QUERY_LOADSPELLS = 1,
PET_LOAD_QUERY_LOADSPELLCOOLDOWN = 2,
MAX_PET_LOAD_QUERY,
};
enum PetLoadStage
{
PET_LOAD_DEFAULT = 0,
PET_LOAD_HANDLE_UNSTABLE_CALLBACK = 1, // used also in HandleStableSwapPetCallback, uses same error / ok messages
PET_LOAD_BG_RESURRECT = 2,
PET_LOAD_SUMMON_PET = 3,
PET_LOAD_SUMMON_DEAD_PET = 4
};
enum PetLoadState
{
PET_LOAD_OK = 0,
@@ -202,4 +192,39 @@ enum PetScalingSpells
#define PET_FOLLOW_DIST 1.0f
#define PET_FOLLOW_ANGLE (M_PI/2)
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 Happiness = 0;
uint32 LastSaveTime = 0;
uint32 CreatedBySpellId = 0;
uint8 Level = 0;
ReactStates ReactState = ReactStates(0);
PetType Type = MAX_PET_TYPE;
bool WasRenamed = false;
};
Optional<PetInfo> CurrentPet; // PET_SAVE_AS_CURRENT
std::array<Optional<PetInfo>, MAX_PET_STABLES> StabledPets; // PET_SAVE_FIRST_STABLE_SLOT - PET_SAVE_LAST_STABLE_SLOT
uint32 MaxStabledPets = 0;
std::vector<PetInfo> UnslottedPets; // PET_SAVE_NOT_IN_SLOT
PetInfo const* GetUnslottedHunterPet() const
{
return UnslottedPets.size() == 1 && UnslottedPets[0].Type == HUNTER_PET ? &UnslottedPets[0] : nullptr;
}
};
#endif