<commit_before>/*
 * AscEmu Framework based on ArcEmu MMORPG Server
 * Copyright (C) 2014-2016 AscEmu Team <http://www.ascemu.org>
 * Copyright (C) 2008-2012 ArcEmu Team <http://www.ArcEmu.org/>
 * Copyright (C) 2005-2007 Ascent Team
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PET_H
#define _PET_H

#include "Creature.h"

#define PET_SPELL_SPAM_COOLDOWN 2000        /// applied only to spells that have no cooldown

/* Taken from ItemPetFood.dbc
 * Each value is equal to a flag
 * so 1 << PET_FOOD_BREAD for example
 * will result in a usable value.
 */
enum PET_FOOD
{
    PET_FOOD_NONE,
    PET_FOOD_MEAT,
    PET_FOOD_FISH,
    PET_FOOD_CHEESE,
    PET_FOOD_BREAD,
    PET_FOOD_FUNGUS,
    PET_FOOD_FRUIT,
    PET_FOOD_RAW_MEAT,      /// not used in pet diet
    PET_FOOD_RAW_FISH       /// not used in pet diet
};

enum PetReactState
{
    PET_STATE_PASSIVE       = 0,
    PET_STATE_DEFENSIVE     = 1,
    PET_STATE_AGGRESSIVE    = 2
};

enum PetCommands
{
    PET_ACTION_STAY     = 0,
    PET_ACTION_FOLLOW   = 1,
    PET_ACTION_ATTACK   = 2,
    PET_ACTION_DISMISS  = 3,
    PET_ACTION_CASTING  = 4
};

enum PetActionFeedback
{
    PET_FEEDBACK_NONE,
    PET_FEEDBACK_PET_DEAD,
    PET_FEEDBACK_NOTHING_TO_ATTACK,
    PET_FEEDBACK_CANT_ATTACK_TARGET
};

enum PET_RENAME
{
    PET_RENAME_NOT_ALLOWED    = 0x02,
    PET_RENAME_ALLOWED        = 0x03
};

enum PetSpells
{
    PET_SPELL_PASSIVE   = 0x06000000,
    PET_SPELL_DEFENSIVE,
    PET_SPELL_AGRESSIVE,
    PET_SPELL_STAY      = 0x07000000,
    PET_SPELL_FOLLOW,
    PET_SPELL_ATTACK
};

enum StableState
{
    STABLE_STATE_ACTIVE     = 1,
    STABLE_STATE_PASSIVE    = 2
};

enum HappinessState
{
    UNHAPPY     = 1,
    CONTENT     = 2,
    HAPPY       = 3
};

enum AutoCastEvents
{
    AUTOCAST_EVENT_NONE                 = 0,
    AUTOCAST_EVENT_ATTACK               = 1,
    AUTOCAST_EVENT_ON_SPAWN             = 2,
    AUTOCAST_EVENT_OWNER_ATTACKED       = 3,
    AUTOCAST_EVENT_LEAVE_COMBAT         = 4,
    AUTOCAST_EVENT_COUNT                = 5
};

#define PET_TALENT_TREE_START 409           /// Tenacity
#define PET_TALENT_TREE_END 411             /// Cunning

#define PET_DELAYED_REMOVAL_TIME 60000      /// 1 min

#define DEFAULT_SPELL_STATE 0x8100
#define AUTOCAST_SPELL_STATE 0xC100


enum PetType
{
    HUNTERPET   = 1,
    WARLOCKPET  = 2,
};

typedef std::map<SpellEntry*, uint16> PetSpellMap;
struct PlayerPet;


class SERVER_DECL Pet : public Creature
{
    friend class Player;
    friend class Creature;
    friend class WorldSession;

    public:

        Pet(uint64 guid);
        ~Pet();

        /// Override superclass method that returns false
        bool IsPet() { return true; }

        void LoadFromDB(Player* owner, PlayerPet* pi);
        /// returns false if an error occurred. The caller MUST delete us.
        bool CreateAsSummon(uint32 entry, CreatureInfo* ci, Creature* created_from_creature, Player* owner, SpellEntry* created_by_spell, uint32 type, uint32 expiretime, LocationVector* Vec = NULL, bool dismiss_old_pet = true);

        void Update(unsigned long time_passed);
        void OnPushToWorld();

        inline uint32 GetXP(void) { return GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); }

        void InitializeSpells();
        void InitializeMe(bool first);
        void SendSpellsToOwner();
        void SendCastFailed(uint32 spellid, uint8 fail);
        void SendActionFeedback(PetActionFeedback value);
        void BuildPetSpellList(WorldPacket& data);

        inline void SetPetAction(uint32 act) { m_Action = act; }
        inline uint32 GetPetAction(void) { return m_Action; }

        inline void SetPetState(uint32 state) { m_State = state; }
        inline uint32 GetPetState(void) { return m_State; }

        inline void SetPetDiet(uint32 diet) { m_Diet = diet; }
        inline void SetPetDiet() { m_Diet = myFamily->petdietflags; }
        inline uint32 GetPetDiet(void) { return m_Diet; }

        inline AI_Spell* GetAISpellForSpellId(uint32 spellid)
        {
            std::map<uint32, AI_Spell*>::iterator itr = m_AISpellStore.find(spellid);
            if (itr != m_AISpellStore.end())
                return itr->second;
            else
                return NULL;
        }

        void UpdatePetInfo(bool bSetToOffline);
        void Remove(bool bUpdate, bool bSetOffline);
        void Dismiss();
        void setDeathState(DeathState s);<commit_msg>World/Spells: Check invalid pointer. Related to #308<commit_after>/*
 * AscEmu Framework based on ArcEmu MMORPG Server
 * Copyright (C) 2014-2016 AscEmu Team <http://www.ascemu.org>
 * Copyright (C) 2008-2012 ArcEmu Team <http://www.ArcEmu.org/>
 * Copyright (C) 2005-2007 Ascent Team
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * 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 Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _PET_H
#define _PET_H

#include "Creature.h"

#define PET_SPELL_SPAM_COOLDOWN 2000        /// applied only to spells that have no cooldown

/* Taken from ItemPetFood.dbc
 * Each value is equal to a flag
 * so 1 << PET_FOOD_BREAD for example
 * will result in a usable value.
 */
enum PET_FOOD
{
    PET_FOOD_NONE,
    PET_FOOD_MEAT,
    PET_FOOD_FISH,
    PET_FOOD_CHEESE,
    PET_FOOD_BREAD,
    PET_FOOD_FUNGUS,
    PET_FOOD_FRUIT,
    PET_FOOD_RAW_MEAT,      /// not used in pet diet
    PET_FOOD_RAW_FISH       /// not used in pet diet
};

enum PetReactState
{
    PET_STATE_PASSIVE       = 0,
    PET_STATE_DEFENSIVE     = 1,
    PET_STATE_AGGRESSIVE    = 2
};

enum PetCommands
{
    PET_ACTION_STAY     = 0,
    PET_ACTION_FOLLOW   = 1,
    PET_ACTION_ATTACK   = 2,
    PET_ACTION_DISMISS  = 3,
    PET_ACTION_CASTING  = 4
};

enum PetActionFeedback
{
    PET_FEEDBACK_NONE,
    PET_FEEDBACK_PET_DEAD,
    PET_FEEDBACK_NOTHING_TO_ATTACK,
    PET_FEEDBACK_CANT_ATTACK_TARGET
};

enum PET_RENAME
{
    PET_RENAME_NOT_ALLOWED    = 0x02,
    PET_RENAME_ALLOWED        = 0x03
};

enum PetSpells
{
    PET_SPELL_PASSIVE   = 0x06000000,
    PET_SPELL_DEFENSIVE,
    PET_SPELL_AGRESSIVE,
    PET_SPELL_STAY      = 0x07000000,
    PET_SPELL_FOLLOW,
    PET_SPELL_ATTACK
};

enum StableState
{
    STABLE_STATE_ACTIVE     = 1,
    STABLE_STATE_PASSIVE    = 2
};

enum HappinessState
{
    UNHAPPY     = 1,
    CONTENT     = 2,
    HAPPY       = 3
};

enum AutoCastEvents
{
    AUTOCAST_EVENT_NONE                 = 0,
    AUTOCAST_EVENT_ATTACK               = 1,
    AUTOCAST_EVENT_ON_SPAWN             = 2,
    AUTOCAST_EVENT_OWNER_ATTACKED       = 3,
    AUTOCAST_EVENT_LEAVE_COMBAT         = 4,
    AUTOCAST_EVENT_COUNT                = 5
};

#define PET_TALENT_TREE_START 409           /// Tenacity
#define PET_TALENT_TREE_END 411             /// Cunning

#define PET_DELAYED_REMOVAL_TIME 60000      /// 1 min

#define DEFAULT_SPELL_STATE 0x8100
#define AUTOCAST_SPELL_STATE 0xC100


enum PetType
{
    HUNTERPET   = 1,
    WARLOCKPET  = 2,
};

typedef std::map<SpellEntry*, uint16> PetSpellMap;
struct PlayerPet;


class SERVER_DECL Pet : public Creature
{
    friend class Player;
    friend class Creature;
    friend class WorldSession;

    public:

        Pet(uint64 guid);
        ~Pet();

        /// Override superclass method that returns false
        bool IsPet() { return true; }

        void LoadFromDB(Player* owner, PlayerPet* pi);
        /// returns false if an error occurred. The caller MUST delete us.
        bool CreateAsSummon(uint32 entry, CreatureInfo* ci, Creature* created_from_creature, Player* owner, SpellEntry* created_by_spell, uint32 type, uint32 expiretime, LocationVector* Vec = NULL, bool dismiss_old_pet = true);

        void Update(unsigned long time_passed);
        void OnPushToWorld();

        inline uint32 GetXP(void) { return GetUInt32Value(UNIT_FIELD_PETEXPERIENCE); }

        void InitializeSpells();
        void InitializeMe(bool first);
        void SendSpellsToOwner();
        void SendCastFailed(uint32 spellid, uint8 fail);
        void SendActionFeedback(PetActionFeedback value);
        void BuildPetSpellList(WorldPacket& data);

        inline void SetPetAction(uint32 act) { m_Action = act; }
        inline uint32 GetPetAction(void) { return m_Action; }

        inline void SetPetState(uint32 state) { m_State = state; }
        inline uint32 GetPetState(void) { return m_State; }

        inline void SetPetDiet(uint32 diet) { m_Diet = diet; }
        inline void SetPetDiet()
        { 
            if (myFamily)
                m_Diet = myFamily->petdietflags;
            else
                m_Diet = 0;
        }
        inline uint32 GetPetDiet(void) { return m_Diet; }

        inline AI_Spell* GetAISpellForSpellId(uint32 spellid)
        {
            std::map<uint32, AI_Spell*>::iterator itr = m_AISpellStore.find(spellid);
            if (itr != m_AISpellStore.end())
                return itr->second;
            else
                return NULL;
        }

        void UpdatePetInfo(bool bSetToOffline);
        void Remove(bool bUpdate, bool bSetOffline);
        void Dismiss();
        void setDeathState(DeathState s);
{'fraction_non_alphanumeric': 0.0739211638651332, 'fraction_numerical': 0.025754448048756512, 'mean_word_length': 2.6808972503617947, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3573967', 'n_tokens_mistral': 3678, 'n_tokens_neox': 3327, 'n_words': 900}