TrinityCore
Loading...
Searching...
No Matches
PlayerAI.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 TRINITY_PLAYERAI_H
19#define TRINITY_PLAYERAI_H
20
21#include "Common.h"
22#include "UnitAI.h"
23
24class Creature;
25class Player;
26class Spell;
27class Unit;
28
30{
31 public:
32 explicit PlayerAI(Player* player);
33
34 Creature* GetCharmer() const;
35
36 // helper functions to determine player info
37 // Return values range from 0 (left-most spec) to 2 (right-most spec). If two specs have the same number of talent points, the left-most of those specs is returned.
38 uint8 GetSpec(Player const* who = nullptr) const;
39 bool IsHealer(Player const* who = nullptr) const;
40 bool IsRangedAttacker(Player const* who = nullptr) const;
41
42 protected:
43 struct TargetedSpell : public std::pair<Spell*, Unit*>
44 {
45 TargetedSpell() : pair<Spell*, Unit*>() { }
46 TargetedSpell(Spell* first, Unit* second) : pair<Spell*, Unit*>(first, second) { }
47 explicit operator bool() { return !!first; }
48 };
49 typedef std::pair<TargetedSpell, uint32> PossibleSpell;
50 typedef std::vector<PossibleSpell> PossibleSpellVector;
51
52 Player* const me;
53 void SetIsRangedAttacker(bool state) { _isSelfRangedAttacker = state; } // this allows overriding of the default ranged attacker detection
54
62 /* Check if the specified spell can be cast on that target.
63 Caller is responsible for cleaning up created Spell object from pointer. */
64 TargetedSpell VerifySpellCast(uint32 spellId, Unit* target);
65 /* Check if the specified spell can be cast on that target.
66 Caller is responsible for cleaning up created Spell object from pointer. */
67 TargetedSpell VerifySpellCast(uint32 spellId, SpellTarget target);
68
69 /* Helper method - checks spell cast, then pushes it onto provided vector if valid. */
70 template<typename T> inline void VerifyAndPushSpellCast(PossibleSpellVector& spells, uint32 spellId, T target, uint32 weight)
71 {
72 if (TargetedSpell spell = VerifySpellCast(spellId, target))
73 spells.push_back({ spell,weight });
74 }
75
76 /* Helper method - selects one spell from the vector and returns it, while deleting everything else.
77 This invalidates the vector, and empties it to prevent accidental misuse. */
78 TargetedSpell SelectSpellCast(PossibleSpellVector& spells);
79 /* Helper method - casts the included spell at the included target */
80 void DoCastAtTarget(TargetedSpell spell);
81
82 virtual Unit* SelectAttackTarget() const;
83 void DoRangedAttackIfReady();
84 void DoAutoAttackIfReady();
85
86 // Cancels all shapeshifts that the player could voluntarily cancel
87 void CancelAllShapeshifts();
88
89 private:
91 bool const _isSelfHealer;
93};
94
96{
97 public:
98 SimpleCharmedPlayerAI(Player* player) : PlayerAI(player), _castCheckTimer(2500), _chaseCloser(false), _forceFacing(true), _isFollowing(false) { }
99 void UpdateAI(uint32 diff) override;
100 void OnCharmed(bool isNew) override;
101
102 protected:
103 bool CanAIAttack(Unit const* who) const override;
104 Unit* SelectAttackTarget() const override;
105
106 private:
107 TargetedSpell SelectAppropriateCastForSpec();
112};
113
114#endif
#define TC_GAME_API
Definition Define.h:114
uint8_t uint8
Definition Define.h:135
uint32_t uint32
Definition Define.h:133
void VerifyAndPushSpellCast(PossibleSpellVector &spells, uint32 spellId, T target, uint32 weight)
Definition PlayerAI.h:70
std::pair< TargetedSpell, uint32 > PossibleSpell
Definition PlayerAI.h:49
Player *const me
Definition PlayerAI.h:52
void SetIsRangedAttacker(bool state)
Definition PlayerAI.h:53
@ TARGET_VICTIM
Definition PlayerAI.h:58
@ TARGET_NONE
Definition PlayerAI.h:57
@ TARGET_CHARMER
Definition PlayerAI.h:59
uint8 const _selfSpec
Definition PlayerAI.h:90
bool const _isSelfHealer
Definition PlayerAI.h:91
bool _isSelfRangedAttacker
Definition PlayerAI.h:92
std::vector< PossibleSpell > PossibleSpellVector
Definition PlayerAI.h:50
SimpleCharmedPlayerAI(Player *player)
Definition PlayerAI.h:98
Definition Spell.h:152
virtual bool CanAIAttack(Unit const *) const
Definition UnitAI.h:139
virtual void OnCharmed(bool isNew)
Definition UnitAI.cpp:42
virtual void UpdateAI(uint32 diff)=0
Definition Unit.h:769
TargetedSpell(Spell *first, Unit *second)
Definition PlayerAI.h:46