TrinityCore
Loading...
Searching...
No Matches
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;
26
27constexpr uint8 MAX_SPELL_CHARM = 4;
31
32#define UNIT_ACTION_BUTTON_ACTION(X) (uint32(X) & 0x00FFFFFF)
33#define UNIT_ACTION_BUTTON_TYPE(X) ((uint32(X) & 0xFF000000) >> 24)
34#define MAKE_UNIT_ACTION_BUTTON(A, T) (uint32(A) | (uint32(T) << 24))
35
37{
39
41
42 // helper
46 {
47 ActiveStates Type = GetType();
48 return Type == ACT_DISABLED || Type == ACT_ENABLED || Type == ACT_PASSIVE;
49 }
50
52 {
53 packedData = MAKE_UNIT_ACTION_BUTTON(action, type);
54 }
55
60
61 void SetAction(uint32 action)
62 {
63 packedData = (packedData & 0xFF000000) | UNIT_ACTION_BUTTON_ACTION(action);
64 }
65};
66
74
76
84
85#define MAX_UNIT_ACTION_BAR_INDEX (ACTION_BAR_INDEX_END-ACTION_BAR_INDEX_START)
86
88{
89 public:
90 explicit CharmInfo(Unit* unit);
91 ~CharmInfo();
92 void RestoreState();
93 uint32 GetPetNumber() const { return _petnumber; }
94 void SetPetNumber(uint32 petnumber, bool statwindow);
95
96 void SetCommandState(CommandStates st) { _CommandState = st; }
97 CommandStates GetCommandState() const { return _CommandState; }
98 bool HasCommandState(CommandStates state) const { return (_CommandState == state); }
99
100 void InitPossessCreateSpells();
101 void InitCharmCreateSpells();
102 void InitPetActionBar();
103 void InitEmptyActionBar(bool withAttack = true);
104
105 //return true if successful
106 bool AddSpellToActionBar(SpellInfo const* spellInfo, ActiveStates newstate = ACT_DECIDE, uint8 preferredSlot = 0);
107 bool RemoveSpellFromActionBar(uint32 spell_id);
108 void LoadPetActionBar(const std::string& data);
109 void SetSpellAutocast(SpellInfo const* spellInfo, bool state);
110 void SetActionBar(uint8 index, uint32 spellOrAction, ActiveStates type)
111 {
112 PetActionBar[index].SetActionAndType(spellOrAction, type);
113 }
114
115 UnitActionBarEntry const* GetActionBarEntry(uint8 index) const { return &(PetActionBar[index]); }
116
117 void ToggleCreatureAutocast(SpellInfo const* spellInfo, bool apply);
118
119 CharmSpellInfo* GetCharmSpell(uint8 index) { return &(_charmspells[index]); }
120
121 void SetIsCommandAttack(bool val);
122 bool IsCommandAttack();
123 void SetIsCommandFollow(bool val);
124 bool IsCommandFollow();
125 void SetIsAtStay(bool val);
126 bool IsAtStay();
127 void SetIsFollowing(bool val);
128 bool IsFollowing();
129 void SetIsReturning(bool val);
130 bool IsReturning();
131 void SaveStayPosition();
132 void GetStayPosition(float &x, float &y, float &z);
133
134 private:
135
138 CharmSpellInfo _charmspells[4];
141
142 //for restoration after charmed
144
150 float _stayX;
151 float _stayY;
152 float _stayZ;
153};
154
155#endif // _CharmInfo_h__
UnitActionBarEntry CharmSpellInfo
Definition CharmInfo.h:75
#define MAX_UNIT_ACTION_BAR_INDEX
Definition CharmInfo.h:85
constexpr uint8 MAX_SPELL_VEHICLE
Definition CharmInfo.h:28
#define UNIT_ACTION_BUTTON_ACTION(X)
Definition CharmInfo.h:32
ActionBarIndex
Definition CharmInfo.h:78
@ ACTION_BAR_INDEX_PET_SPELL_START
Definition CharmInfo.h:80
@ ACTION_BAR_INDEX_PET_SPELL_END
Definition CharmInfo.h:81
@ ACTION_BAR_INDEX_END
Definition CharmInfo.h:82
@ ACTION_BAR_INDEX_START
Definition CharmInfo.h:79
constexpr uint8 MAX_SPELL_CHARM
Definition CharmInfo.h:27
CharmType
Definition CharmInfo.h:68
@ CHARM_TYPE_CHARM
Definition CharmInfo.h:69
@ CHARM_TYPE_POSSESS
Definition CharmInfo.h:70
@ CHARM_TYPE_CONVERT
Definition CharmInfo.h:72
@ CHARM_TYPE_VEHICLE
Definition CharmInfo.h:71
#define MAKE_UNIT_ACTION_BUTTON(A, T)
Definition CharmInfo.h:34
#define UNIT_ACTION_BUTTON_TYPE(X)
Definition CharmInfo.h:33
constexpr uint8 MAX_SPELL_CONTROL_BAR
Definition CharmInfo.h:30
constexpr uint8 MAX_SPELL_POSSESS
Definition CharmInfo.h:29
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
uint32_t uint32
Definition Define.h:154
ReactStates
ActiveStates
@ ACT_DECIDE
@ ACT_ENABLED
@ ACT_PASSIVE
@ ACT_DISABLED
CommandStates
Definition Unit.h:635
float _stayY
Definition CharmInfo.h:151
uint32 GetPetNumber() const
Definition CharmInfo.h:93
void SetActionBar(uint8 index, uint32 spellOrAction, ActiveStates type)
Definition CharmInfo.h:110
bool _isAtStay
Definition CharmInfo.h:147
float _stayX
Definition CharmInfo.h:150
CharmSpellInfo * GetCharmSpell(uint8 index)
Definition CharmInfo.h:119
float _stayZ
Definition CharmInfo.h:152
bool _isCommandFollow
Definition CharmInfo.h:146
CommandStates GetCommandState() const
Definition CharmInfo.h:97
CommandStates _CommandState
Definition CharmInfo.h:139
UnitActionBarEntry const * GetActionBarEntry(uint8 index) const
Definition CharmInfo.h:115
bool _isFollowing
Definition CharmInfo.h:148
bool HasCommandState(CommandStates state) const
Definition CharmInfo.h:98
bool _isCommandAttack
Definition CharmInfo.h:145
ReactStates _oldReactState
Definition CharmInfo.h:143
void SetCommandState(CommandStates st)
Definition CharmInfo.h:96
bool _isReturning
Definition CharmInfo.h:149
Unit * _unit
Definition CharmInfo.h:136
uint32 _petnumber
Definition CharmInfo.h:140
ActiveStates GetType() const
Definition CharmInfo.h:43
void SetActionAndType(uint32 action, ActiveStates type)
Definition CharmInfo.h:51
bool IsActionBarForSpell() const
Definition CharmInfo.h:45
void SetType(ActiveStates type)
Definition CharmInfo.h:56
void SetAction(uint32 action)
Definition CharmInfo.h:61
uint32 GetAction() const
Definition CharmInfo.h:44