TrinityCore
Loading...
Searching...
No Matches
CommonHelpers.cpp
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#include "CommonHelpers.h"
19#include "Common.h"
20#include "Creature.h"
21#include "CreatureAI.h"
22#include "Item.h"
23#include "ItemTemplate.h"
24#include "ObjectAccessor.h"
25#include "Player.h"
26#include "SharedDefines.h"
27#include "UnitAI.h"
28
30{
31 /* Warrior - Arms */
35
36 /* Warrior - Fury */
40
41 /* Warrior - Protection */
45
46 /* Paladin - Holy*/
50
51 /* Paladin - Protection */
55
56 /* Paladin - Retribution */
60
61 /* Hunter - Beast Mastery */
65
66 /* Hunter - Marksmanship */
70
71 /* Hunter - Survival */
75
76 /* Rogue - Assassination */
80
81 /* Rogue - Combat */
85
86 /* Rogue - Sublety */
90
91 /* Priest - Discipline */
95
96 /* Priest - Holy */
100
101 /* Priest - Shadow */
105
106 /* Death Knight - Blood */
110
111 /* Death Knight - Frost */
115
116 /* Death Knight - Unholy */
120
121 /* Shaman - Elemental*/
125
126 /* Shaman - Enhancement */
130
131 /* Shaman - Restoration*/
135
136 /* Mage - Arcane */
140
141 /* Mage - Fire */
145
146 /* Mage - Frost */
150
151 /* Warlock - Affliction */
154 SPELL_HAUNT = 48181,
155
156 /* Warlock - Demonology */
160
161 /* Warlock - Destruction */
165
166 /* Druid - Balance */
170
171 /* Druid - Feral */
175
176 /* Druid - Restoration */
179 SPELL_WILD_GROWTH = 48438
181
183
184// As it turns out, finding out "how many points does the player have in spec X" is actually really expensive to do frequently
185// So instead, we just check for a handful of spells that, realistically, no spec is gonna go without (and "has spell" is cheap!)
186// Can players deliberately trick this check? Yes.
187// Is it worth doing? No.
188// Close enough.
190 { // CLASS_NONE
191 {0,0,0},
192 {0,0,0},
193 {0,0,0}
194 },
195 { // CLASS_WARRIOR
199 },
200 { // CLASS_PALADIN
204 },
205 { // CLASS_HUNTER
209 },
210 { // CLASS_ROGUE
214 },
215 { // CLASS_PRIEST
219 },
220 { // CLASS_DEATH_KNIGHT
224 },
225 { // CLASS_SHAMAN
229 },
230 { // CLASS_MAGE
234 },
235 { // CLASS_WARLOCK
239 },
240 { // CLASS_UNK
241 {0,0,0},
242 {0,0,0},
243 {0,0,0}
244 },
245 { // CLASS_DRUID
249 }
250};
251
253{
254 if (!who)
255 return 0;
256
257 uint8 playerClass = who->GetClass();
258 for (uint8 tier = 0; tier < MaximumSpecializationIconicSpells; ++tier)
259 {
260 for (uint8 tree = 0; tree < MAX_TALENT_TREES; ++tree)
261 if (PlayerSpecializationIconicSpells[playerClass][tree][tier] && who->HasSpell(PlayerSpecializationIconicSpells[playerClass][tree][tier]))
262 return tree;
263 }
264
265 return 0;
266}
267
269{
270 if (!who)
271 return false;
272
273 switch (who->GetClass())
274 {
275 case CLASS_WARRIOR:
276 case CLASS_HUNTER:
277 case CLASS_ROGUE:
279 case CLASS_MAGE:
280 case CLASS_WARLOCK:
281 default:
282 return false;
283 case CLASS_PALADIN:
285 case CLASS_PRIEST:
287 case CLASS_SHAMAN:
289 case CLASS_DRUID:
291 }
292}
293
295{
296 if (!who)
297 return false;
298
299 switch (who->GetClass())
300 {
301 case CLASS_WARRIOR:
302 case CLASS_PALADIN:
303 case CLASS_ROGUE:
305 default:
306 return false;
307 case CLASS_MAGE:
308 case CLASS_WARLOCK:
309 return true;
310 case CLASS_HUNTER:
311 {
312 // check if we have a ranged weapon equipped
314 if (ItemTemplate const* rangedTemplate = rangedSlot ? rangedSlot->GetTemplate() : nullptr)
315 {
316 if ((1 << rangedTemplate->SubClass) & ITEM_SUBCLASS_MASK_WEAPON_RANGED)
317 return true;
318 }
319 return false;
320 }
321 case CLASS_PRIEST:
323 case CLASS_SHAMAN:
325 case CLASS_DRUID:
327 }
328}
329
330Trinity::Helpers::Events::SetAggresiveStateEvent::SetAggresiveStateEvent(Creature* owner, bool startCombat/* = true*/, ObjectGuid summonerGUID/* = ObjectGuid::Empty*/, StartCombatArgs const& combatArgs/* = { }*/) : _owner(owner), _startCombat(startCombat), _summonerGUID(summonerGUID), _combatArgs(combatArgs)
331{
332}
333
335{
336 _owner->SetReactState(REACT_AGGRESSIVE);
337 if (_startCombat)
338 {
339 if (!_summonerGUID.IsEmpty())
340 {
341 if (Creature* summoner = ObjectAccessor::GetCreature(*_owner, _summonerGUID))
342 if (summoner->IsEngaged() && summoner->IsAIEnabled() && _owner->IsAIEnabled())
343 {
344 if (_combatArgs.AvoidTargetVictim)
345 {
346 if (Unit* target = summoner->AI()->SelectTarget(SelectTargetMethod::Random, 0, NonTankTargetSelector(summoner, _combatArgs.TargetPlayers)))
347 _owner->AI()->AttackStart(target);
348 }
349 else
350 {
351 if (Unit* target = summoner->AI()->SelectTarget(SelectTargetMethod::Random, 0, _combatArgs.Distance, _combatArgs.TargetPlayers))
352 _owner->AI()->AttackStart(target);
353 }
354 }
355 }
356 else if (Unit* currentVictim = _owner->SelectVictim())
357 {
358 if (_owner->IsAIEnabled())
359 _owner->AI()->AttackStart(currentVictim);
360 }
361 else if (_owner->IsAIEnabled())
362 _owner->AI()->DoZoneInCombat();
363 }
364 return true;
365}
static const uint8 MaximumSpecializationIconicSpells
static const uint32 PlayerSpecializationIconicSpells[MAX_CLASSES][MAX_TALENT_TREES][MaximumSpecializationIconicSpells]
PlayerSpecializationIconicSpellIds
@ SPELL_SCOURGE_STRIKE
@ PASSIVE_ILLUMINATION
@ SPELL_GUARDIAN_SPIRIT
@ SPELL_CONFLAGRATE
@ SPELL_VAMPIRIC_EMBRACE
@ SPELL_DEEP_FREEZE
@ SPELL_DEMONIC_EMPOWERMENT
@ SPELL_SHADOWFORM
@ SPELL_DEATH_WISH
@ SPELL_RIPTIDE
@ SPELL_CHIMERA_SHOT
@ SPELL_METAMORPHOSIS
@ SPELL_SOUL_LINK
@ SPELL_ADRENALINE_RUSH
@ PASSIVE_SIPHON_LIFE
@ SPELL_THUNDERSTORM
@ SPELL_FERAL_SPIRIT
@ SPELL_BEACON_OF_LIGHT
@ SPELL_HYSTERIA
@ PASSIVE_ELEMENTAL_FOCUS
@ SPELL_PENANCE
@ SPELL_VAMPIRIC_TOUCH
@ PASSIVE_TRUESHOT_AURA
@ SPELL_ARCANE_BARRAGE
@ SPELL_POWER_INFUSION
@ SPELL_MANGLE
@ SPELL_HOWLING_BLAST
@ PASSIVE_ICY_TALONS
@ PASSIVE_UNHOLY_BLIGHT
@ SPELL_LAVA_LASH
@ SPELL_EXPLOSIVE_SHOT
@ SPELL_UNSTABLE_AFFLICTION
@ SPELL_PREMEDITATION
@ PASSIVE_TITANS_GRIP
@ SPELL_INSECT_SWARM
@ PASSIVE_SPIRIT_WEAPONS
@ SPELL_BLADE_FLURRY
@ SPELL_DESPERATE_PRAYER
@ SPELL_ARCANE_POWER
@ PASSIVE_LOCK_AND_LOAD
@ SPELL_TOTEM_OF_WRATH
@ SPELL_COMBUSTION
@ SPELL_MOONKIN_FORM
@ SPELL_WILD_GROWTH
@ SPELL_CRUSADER_STRIKE
@ SPELL_MORTAL_STRIKE
@ SPELL_SURVIVAL_INSTINCTS
@ SPELL_HOLY_SHOCK
@ SPELL_LIVING_BOMB
@ SPELL_HEART_STRIKE
@ SPELL_AIMED_SHOT
@ SPELL_SHA_NATURE_SWIFT
@ PASSIVE_SOUL_WARDING
@ SPELL_VIGILANCE
@ PASSIVE_BEAST_WITHIN
@ SPELL_CHAOS_BOLT
@ SPELL_SHOCKWAVE
@ SPELL_ICY_VEINS
@ SPELL_HAUNT
@ SPELL_BLADESTORM
@ PASSIVE_SPIRIT_REDEMPTION
@ SPELL_HEMORRHAGE
@ SPELL_HUNGER_FOR_BLOOD
@ SPELL_DIVINE_STORM
@ SPELL_SWEEPING_STRIKES
@ SPELL_HAMMER_OF_RIGHTEOUS
@ PASSIVE_BEAST_MASTERY
@ SPELL_FOCUS_MAGIC
@ SPELL_FROST_STRIKE
@ SPELL_COLD_BLOOD
@ SPELL_ICE_BARRIER
@ SPELL_BERSERK
@ SPELL_BLOODTHIRST
@ SPELL_SHADOWBURN
@ SPELL_KILLING_SPREE
@ SPELL_SHADOW_DANCE
@ SPELL_RUNE_TAP
@ SPELL_DEVASTATE
@ SPELL_MUTILATE
@ SPELL_HOLY_SHIELD
@ PASSIVE_MASTER_OF_GHOUL
@ SPELL_PYROBLAST
@ SPELL_SEAL_OF_COMMAND
@ SPELL_BESTIAL_WRATH
@ SPELL_SWIFTMEND
@ SPELL_MANA_TIDE_TOTEM
@ SPELL_STARFALL
@ SPELL_TREE_OF_LIFE
@ SPELL_WYVERN_STING
@ SPELL_BLESS_OF_SANC
uint8_t uint8
Definition Define.h:135
uint64_t uint64
Definition Define.h:132
uint32_t uint32
Definition Define.h:133
#define ITEM_SUBCLASS_MASK_WEAPON_RANGED
@ EQUIPMENT_SLOT_RANGED
Definition Player.h:569
#define INVENTORY_SLOT_BAG_0
Definition Player.h:547
@ SPEC_DRUID_BALANCE
@ SPEC_PRIEST_SHADOW
@ SPEC_DRUID_RESTORATION
@ SPEC_SHAMAN_ELEMENTAL
@ SPEC_SHAMAN_RESTORATION
@ SPEC_PALADIN_HOLY
@ CLASS_HUNTER
@ CLASS_DRUID
@ CLASS_SHAMAN
@ CLASS_PRIEST
@ CLASS_WARRIOR
@ CLASS_WARLOCK
@ CLASS_MAGE
@ CLASS_DEATH_KNIGHT
@ CLASS_PALADIN
@ CLASS_ROGUE
#define MAX_CLASSES
#define MAX_TALENT_TREES
@ REACT_AGGRESSIVE
Definition Item.h:62
ItemTemplate const * GetTemplate() const
Definition Item.cpp:535
Item * GetItemByPos(uint16 pos) const
Definition Player.cpp:9552
bool HasSpell(uint32 spell) const override
Definition Player.cpp:3853
SetAggresiveStateEvent(Creature *owner, bool startCombat=true, ObjectGuid summonerGUID=ObjectGuid::Empty, StartCombatArgs const &combatArgs={ })
Definition Unit.h:769
uint8 GetClass() const
Definition Unit.h:895
TC_GAME_API Creature * GetCreature(WorldObject const &u, ObjectGuid const &guid)
TC_GAME_API uint8 GetPlayerSpecialization(Player const *who)
bool IsPlayerRangedAttacker(Player const *who)
TC_GAME_API bool IsPlayerHealer(Player const *who)