Files
TCPlayerbotCore/src/game/Pet.h
T

254 lines
8.7 KiB
C++
Raw Normal View History

2008-11-17 22:07:21 -06:00
/*
* Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
2008-11-17 22:07:21 -06:00
*
2010-01-16 20:19:18 +03:00
* Copyright (C) 2008-2010 Trinity <http://www.trinitycore.org/>
2008-11-17 22:07:21 -06:00
*
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
#ifndef TRINITYCORE_PET_H
#define TRINITYCORE_PET_H
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
#include "ObjectDefines.h"
#include "Unit.h"
2009-03-25 21:32:34 -06:00
#include "TemporarySummon.h"
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum PetType
{
SUMMON_PET = 0,
HUNTER_PET = 1,
2009-03-20 14:01:46 -06:00
MAX_PET_TYPE = 4,
2008-11-17 22:07:21 -06:00
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
extern char const* petTypeSuffix[MAX_PET_TYPE];
2009-10-17 15:51:44 -07:00
#define MAX_PET_STABLES 4
2009-10-17 15:51:44 -07:00
// stored in character_pet.slot
2008-11-17 22:07:21 -06:00
enum PetSaveMode
{
PET_SAVE_AS_DELETED = -1, // not saved in fact
PET_SAVE_AS_CURRENT = 0, // in current slot (with player)
PET_SAVE_FIRST_STABLE_SLOT = 1,
PET_SAVE_LAST_STABLE_SLOT = MAX_PET_STABLES, // last in DB stable slot index (including), all higher have same meaning as PET_SAVE_NOT_IN_SLOT
PET_SAVE_NOT_IN_SLOT = 100 // for avoid conflict with stable size grow will use 100
2008-11-17 22:07:21 -06:00
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum HappinessState
{
UNHAPPY = 1,
CONTENT = 2,
HAPPY = 3
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum PetSpellState
{
PETSPELL_UNCHANGED = 0,
PETSPELL_CHANGED = 1,
PETSPELL_NEW = 2,
PETSPELL_REMOVED = 3
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum PetSpellType
{
PETSPELL_NORMAL = 0,
PETSPELL_FAMILY = 1,
PETSPELL_TALENT = 2,
2008-11-17 22:07:21 -06:00
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
struct PetSpell
{
ActiveStates active;
PetSpellState state;
PetSpellType type;
2008-11-17 22:07:21 -06:00
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum ActionFeedback
{
FEEDBACK_NONE = 0,
FEEDBACK_PET_DEAD = 1,
FEEDBACK_NOTHING_TO_ATT = 2,
FEEDBACK_CANT_ATT_TARGET = 3
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum PetTalk
{
PET_TALK_SPECIAL_SPELL = 0,
PET_TALK_ATTACK = 1
};
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
enum PetNameInvalidReason
{
// custom, not send
PET_NAME_SUCCESS = 0,
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
PET_NAME_INVALID = 1,
PET_NAME_NO_NAME = 2,
PET_NAME_TOO_SHORT = 3,
PET_NAME_TOO_LONG = 4,
PET_NAME_MIXED_LANGUAGES = 6,
PET_NAME_PROFANE = 7,
PET_NAME_RESERVED = 8,
PET_NAME_THREE_CONSECUTIVE = 11,
PET_NAME_INVALID_SPACE = 12,
PET_NAME_CONSECUTIVE_SPACES = 13,
PET_NAME_RUSSIAN_CONSECUTIVE_SILENT_CHARACTERS = 14,
PET_NAME_RUSSIAN_SILENT_CHARACTER_AT_BEGINNING_OR_END = 15,
PET_NAME_DECLENSION_DOESNT_MATCH_BASE_NAME = 16
};
2009-10-17 15:51:44 -07:00
typedef UNORDERED_MAP<uint32, PetSpell> PetSpellMap;
2008-11-17 22:07:21 -06:00
typedef std::vector<uint32> AutoSpellList;
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
#define HAPPINESS_LEVEL_SIZE 333000
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
#define ACTIVE_SPELLS_MAX 4
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
#define PET_FOLLOW_DIST 1
#define PET_FOLLOW_ANGLE (M_PI/2)
2010-01-10 01:23:15 +01:00
#define PET_FOCUS_REGEN_INTERVAL 4 * IN_MILISECONDS
2009-10-17 15:51:44 -07:00
class Player;
2009-10-17 15:51:44 -07:00
2009-03-25 21:32:34 -06:00
class Pet : public Guardian
2008-11-17 22:07:21 -06:00
{
public:
2009-03-25 21:32:34 -06:00
explicit Pet(Player *owner, PetType type = MAX_PET_TYPE);
2008-11-17 22:07:21 -06:00
virtual ~Pet();
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void AddToWorld();
void RemoveFromWorld();
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
PetType getPetType() const { return m_petType; }
void setPetType(PetType type) { m_petType = type; }
2010-04-07 23:25:02 +02:00
bool isControlled() const { return getPetType() == SUMMON_PET || getPetType() == HUNTER_PET; }
2008-11-17 22:07:21 -06:00
bool isTemporarySummoned() const { return m_duration > 0; }
2009-10-17 15:51:44 -07:00
bool IsPermanentPetFor(Player* owner); // pet have tab in character windows and set UNIT_FIELD_PETNUMBER
2009-10-17 15:51:44 -07:00
bool Create (uint32 guidlow, Map *map, uint32 phaseMask, uint32 Entry, uint32 pet_number);
2008-12-12 11:21:28 -06:00
bool CreateBaseAtCreature(Creature* creature);
2010-04-07 22:59:46 +02:00
bool LoadPetFromDB(Player* owner,uint32 petentry = 0,uint32 petnumber = 0, bool current = false);
bool isBeingLoaded() const { return m_loading;}
2008-11-17 22:07:21 -06:00
void SavePetToDB(PetSaveMode mode);
void Remove(PetSaveMode mode, bool returnreagent = false);
static void DeleteFromDB(uint32 guidlow);
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void setDeathState(DeathState s); // overwrite virtual Creature::setDeathState and Unit::setDeathState
void Update(uint32 diff); // overwrite virtual Creature::Update and Unit::Update
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
uint8 GetPetAutoSpellSize() const { return m_autospells.size(); }
uint32 GetPetAutoSpellOnPos(uint8 pos) const
{
if (pos >= m_autospells.size())
return 0;
else
return m_autospells[pos];
}
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void LooseHappiness();
HappinessState GetHappinessState();
void GivePetXP(uint32 xp);
void GivePetLevel(uint8 level);
void SynchronizeLevelWithOwner();
2008-11-17 22:07:21 -06:00
bool HaveInDiet(ItemPrototype const* item) const;
uint32 GetCurrentFoodBenefitLevel(uint32 itemlevel);
void SetDuration(int32 dur) { m_duration = dur; }
2009-10-17 15:51:44 -07:00
/*
2008-11-17 22:07:21 -06:00
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);
*/
2009-10-17 15:51:44 -07:00
bool CanTakeMoreActiveSpells(uint32 SpellIconID);
void ToggleAutocast(uint32 spellid, bool apply);
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
bool HasSpell(uint32 spell) const;
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void LearnPetPassives();
void CastPetAuras(bool current);
void CastPetAura(PetAura const* aura);
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void _LoadSpellCooldowns();
void _SaveSpellCooldowns();
void _LoadAuras(uint32 timediff);
void _SaveAuras();
void _LoadSpells();
void _SaveSpells();
2009-10-17 15:51:44 -07:00
bool addSpell(uint32 spell_id,ActiveStates active = ACT_DECIDE, PetSpellState state = PETSPELL_NEW, PetSpellType type = PETSPELL_NORMAL);
2009-01-25 16:35:14 -06:00
bool learnSpell(uint32 spell_id);
void learnSpellHighRank(uint32 spellid);
void InitLevelupSpellsForLevel();
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();
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
PetSpellMap m_spells;
AutoSpellList m_autospells;
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
void InitPetCreateSpells();
2009-10-17 15:51:44 -07:00
2009-01-20 19:59:43 -06:00
bool resetTalents(bool no_cost = false);
static void resetTalentsForAllPetsOf(Player* owner, Pet* online_pet = NULL);
2008-11-17 22:07:21 -06:00
uint32 resetTalentsCost() const;
2009-01-20 19:59:43 -06:00
void InitTalentForLevel();
2009-10-17 15:51:44 -07:00
uint8 GetMaxTalentPointsForLevel(uint8 level);
uint8 GetFreeTalentPoints() { return GetByteValue(UNIT_FIELD_BYTES_1, 1); }
void SetFreeTalentPoints(uint8 points) { SetByteValue(UNIT_FIELD_BYTES_1, 1, points); }
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
uint32 m_resetTalentsCost;
time_t m_resetTalentsTime;
2009-01-20 19:59:43 -06:00
uint32 m_usedTalentCount;
2009-10-17 15:51:44 -07:00
2009-02-06 19:42:03 +01:00
const uint64& GetAuraUpdateMaskForRaid() const { return m_auraRaidUpdateMask; }
void SetAuraUpdateMaskForRaid(uint8 slot) { m_auraRaidUpdateMask |= (uint64(1) << slot); }
void ResetAuraUpdateMaskForRaid() { m_auraRaidUpdateMask = 0; }
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
bool m_removed; // prevent overwrite pet state in DB at next Pet::Update if pet already removed(saved)
2009-10-17 15:51:44 -07:00
2009-03-27 22:47:28 -06:00
Player *GetOwner() { return m_owner; }
2008-11-17 22:07:21 -06:00
protected:
2009-03-27 22:47:28 -06:00
Player *m_owner;
2008-11-17 22:07:21 -06:00
uint32 m_happinessTimer;
PetType m_petType;
int32 m_duration; // time until unsummon (used mostly for summoned guardians and not used for controlled pets)
2009-02-06 19:42:03 +01:00
uint64 m_auraRaidUpdateMask;
bool m_loading;
uint32 m_regenTimer;
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
DeclinedName *m_declinedname;
2009-10-17 15:51:44 -07:00
2008-11-17 22:07:21 -06:00
private:
void SaveToDB(uint32, uint8) // overwrited of Creature::SaveToDB - don't must be called
{
assert(false);
}
void DeleteFromDB() // overwrited of Creature::DeleteFromDB - don't must be called
{
assert(false);
}
};
#endif