TrinityCore
CharmInfo.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef _CharmInfo_h__
19#define _CharmInfo_h__
20
21#include "Define.h"
22#include "UnitDefines.h"
23
24class SpellInfo;
25class Unit;
26class WorldPacket;
27
28constexpr uint8 MAX_SPELL_CHARM = 4;
32
33#define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
34#define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
35#define MAKE_UNIT_ACTION_BUTTON(A, T) (uint32(A) | (uint32(T) << 24))
36
38{
40
42
43 // helper
47 {
49 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
50 }
51
53 {
54 packedData = MAKE_UNIT_ACTION_BUTTON(action, type);
55 }
56
58 {
60 }
61
62 void SetAction(uint32 action)
63 {
64 packedData = (packedData & 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action);
65 }
66};
67
69{
74};
75
77
79{
84};
85
86#define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
87
89{
90 public:
91 explicit CharmInfo(Unit* unit);
92 ~CharmInfo();
93 void RestoreState();
94 uint32 GetPetNumber() const { return _petnumber; }
95 void SetPetNumber(uint32 petnumber, bool statwindow);
96
97 void SetCommandState(CommandStates st) { _CommandState = st; }
98 CommandStates GetCommandState() const { return _CommandState; }
99 bool HasCommandState(CommandStates state) const { return (_CommandState == state); }
100
101 void InitPossessCreateSpells();
102 void InitCharmCreateSpells();
103 void InitPetActionBar();
104 void InitEmptyActionBar(bool withAttack = true);
105
106 //return true if successful
107 bool AddSpellToActionBar(SpellInfo const* spellInfo, ActiveStates newstate = ACT_DECIDE, uint8 preferredSlot = 0);
108 bool RemoveSpellFromActionBar(uint32 spell_id);
109 void LoadPetActionBar(const std::string& data);
110 void BuildActionBar(WorldPacket* data);
111 void SetSpellAutocast(SpellInfo const* spellInfo, bool state);
112 void SetActionBar(uint8 index, uint32 spellOrAction, ActiveStates type)
113 {
114 PetActionBar[index].SetActionAndType(spellOrAction, type);
115 }
116
117 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
118
119 void ToggleCreatureAutocast(SpellInfo const* spellInfo, bool apply);
120
121 CharmSpellInfo* GetCharmSpell(uint8 index) { return &(_charmspells[index]); }
122
123 void SetIsCommandAttack(bool val);
124 bool IsCommandAttack();
125 void SetIsCommandFollow(bool val);
126 bool IsCommandFollow();
127 void SetIsAtStay(bool val);
128 bool IsAtStay();
129 void SetIsFollowing(bool val);
130 bool IsFollowing();
131 void SetIsReturning(bool val);
132 bool IsReturning();
133 void SaveStayPosition();
134 void GetStayPosition(float &x, float &y, float &z);
135
136 private:
137
140 CharmSpellInfo _charmspells[4];
143
144 //for restoration after charmed
146
152 float _stayX;
153 float _stayY;
154 float _stayZ;
155};
156
157#endif // _CharmInfo_h__
UnitActionBarEntry CharmSpellInfo
Definition: CharmInfo.h:76
#define MAX_UNIT_ACTION_BAR_INDEX
Definition: CharmInfo.h:86
constexpr uint8 MAX_SPELL_VEHICLE
Definition: CharmInfo.h:29
#define UNIT_ACTION_BUTTON_ACTION(X)
Definition: CharmInfo.h:33
ActionBarIndex
Definition: CharmInfo.h:79
@ ACTION_BAR_INDEX_PET_SPELL_START
Definition: CharmInfo.h:81
@ ACTION_BAR_INDEX_PET_SPELL_END
Definition: CharmInfo.h:82
@ ACTION_BAR_INDEX_END
Definition: CharmInfo.h:83
@ ACTION_BAR_INDEX_START
Definition: CharmInfo.h:80
constexpr uint8 MAX_SPELL_CHARM
Definition: CharmInfo.h:28
CharmType
Definition: CharmInfo.h:69
@ CHARM_TYPE_CHARM
Definition: CharmInfo.h:70
@ CHARM_TYPE_POSSESS
Definition: CharmInfo.h:71
@ CHARM_TYPE_CONVERT
Definition: CharmInfo.h:73
@ CHARM_TYPE_VEHICLE
Definition: CharmInfo.h:72
#define MAKE_UNIT_ACTION_BUTTON(A, T)
Definition: CharmInfo.h:35
#define UNIT_ACTION_BUTTON_TYPE(X)
Definition: CharmInfo.h:34
constexpr uint8 MAX_SPELL_CONTROL_BAR
Definition: CharmInfo.h:31
constexpr uint8 MAX_SPELL_POSSESS
Definition: CharmInfo.h:30
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
uint32_t uint32
Definition: Define.h:142
ReactStates
Definition: UnitDefines.h:505
ActiveStates
Definition: UnitDefines.h:495
@ ACT_DECIDE
Definition: UnitDefines.h:501
@ ACT_ENABLED
Definition: UnitDefines.h:498
@ ACT_PASSIVE
Definition: UnitDefines.h:496
@ ACT_DISABLED
Definition: UnitDefines.h:497
CommandStates
Definition: UnitDefines.h:525
Definition: Unit.h:627
void apply(T *val)
Definition: ByteConverter.h:41
float _stayY
Definition: CharmInfo.h:153
uint32 GetPetNumber() const
Definition: CharmInfo.h:94
void SetActionBar(uint8 index, uint32 spellOrAction, ActiveStates type)
Definition: CharmInfo.h:112
bool _isAtStay
Definition: CharmInfo.h:149
float _stayX
Definition: CharmInfo.h:152
CharmSpellInfo * GetCharmSpell(uint8 index)
Definition: CharmInfo.h:121
float _stayZ
Definition: CharmInfo.h:154
bool _isCommandFollow
Definition: CharmInfo.h:148
CommandStates GetCommandState() const
Definition: CharmInfo.h:98
CommandStates _CommandState
Definition: CharmInfo.h:141
UnitActionBarEntry const * GetActionBarEntry(uint8 index) const
Definition: CharmInfo.h:117
bool _isFollowing
Definition: CharmInfo.h:150
bool HasCommandState(CommandStates state) const
Definition: CharmInfo.h:99
bool _isCommandAttack
Definition: CharmInfo.h:147
ReactStates _oldReactState
Definition: CharmInfo.h:145
void SetCommandState(CommandStates st)
Definition: CharmInfo.h:97
bool _isReturning
Definition: CharmInfo.h:151
Unit * _unit
Definition: CharmInfo.h:138
uint32 _petnumber
Definition: CharmInfo.h:142
ActiveStates GetType() const
Definition: CharmInfo.h:44
void SetActionAndType(uint32 action, ActiveStates type)
Definition: CharmInfo.h:52
bool IsActionBarForSpell() const
Definition: CharmInfo.h:46
void SetType(ActiveStates type)
Definition: CharmInfo.h:57
void SetAction(uint32 action)
Definition: CharmInfo.h:62
uint32 GetAction() const
Definition: CharmInfo.h:45