TrinityCore
GameObjectAI.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_GAMEOBJECTAI_H
19#define TRINITY_GAMEOBJECTAI_H
20
21#include "Define.h"
22#include "LootItemType.h"
23#include "ObjectGuid.h"
24#include "Optional.h"
25
26class Creature;
27class GameObject;
28class Player;
29class Quest;
30class SpellInfo;
31class Unit;
32class WorldObject;
33enum class QuestGiverStatus : uint64;
34
35namespace WorldPackets
36{
37 namespace Battleground
38 {
40 }
41}
42
44{
45 private:
46 // Script Id
48
49 protected:
50 GameObject* const me;
51
52 public:
53 explicit GameObjectAI(GameObject* go, uint32 scriptId = {});
54 virtual ~GameObjectAI() { }
55
56 // Gets the id of the AI (script id)
57 uint32 GetId() const { return _scriptId; }
58
59 virtual void UpdateAI(uint32 /*diff*/) { }
60
61 virtual void InitializeAI() { Reset(); }
62
63 virtual void Reset() { }
64
65 // Pass parameters between AI
66 virtual void DoAction(int32 /*param = 0 */) { }
67 virtual void SetGUID(ObjectGuid const& /*guid*/, int32 /*id = 0 */) { }
68 virtual ObjectGuid GetGUID(int32 /*id = 0 */) const { return ObjectGuid::Empty; }
69
70 static int32 Permissible(GameObject const* go);
71
72 // Called when the dialog status between a player and the gameobject is requested.
73 virtual Optional<QuestGiverStatus> GetDialogStatus(Player const* player);
74
75 // Called when a player opens a gossip dialog with the gameobject.
76 virtual bool OnGossipHello(Player* /*player*/) { return false; }
77
78 // Called when a player selects a gossip item in the gameobject's gossip menu.
79 virtual bool OnGossipSelect(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/) { return false; }
80
81 // Called when a player selects a gossip with a code in the gameobject's gossip menu.
82 virtual bool OnGossipSelectCode(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/, char const* /*code*/) { return false; }
83
84 // Called when a player accepts a quest from the gameobject.
85 virtual void OnQuestAccept(Player* /*player*/, Quest const* /*quest*/) { }
86
87 // Called when a player completes a quest and is rewarded, opt is the selected item's index or 0
88 virtual void OnQuestReward(Player* /*player*/, Quest const* /*quest*/, LootItemType /*type*/, uint32 /*opt*/) { }
89
90 // Called when a Player clicks a GameObject, before GossipHello
91 // prevents achievement tracking if returning true
92 virtual bool OnReportUse(Player* /*player*/) { return false; }
93
94 virtual void Destroyed(WorldObject* /*attacker*/, uint32 /*eventId*/) { }
95 virtual void Damaged(WorldObject* /*attacker*/, uint32 /*eventId*/) { }
96
97 virtual uint32 GetData(uint32 /*id*/) const { return 0; }
98 virtual void SetData64(uint32 /*id*/, uint64 /*value*/) { }
99 virtual uint64 GetData64(uint32 /*id*/) const { return 0; }
100 virtual void SetData(uint32 /*id*/, uint32 /*value*/) { }
101
102 virtual void OnGameEvent(bool /*start*/, uint16 /*eventId*/) { }
103 virtual void OnLootStateChanged(uint32 /*state*/, Unit* /*unit*/) { }
104 virtual void OnStateChanged(uint32 /*state*/) { }
105 virtual void EventInform(uint32 /*eventId*/) { }
106
107 // Called when hit by a spell
108 virtual void SpellHit(WorldObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
109
110 // Called when spell hits a target
111 virtual void SpellHitTarget(WorldObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
112
113 // Called when the gameobject summon successfully other creature
114 virtual void JustSummoned(Creature* /*summon*/) { }
115
116 virtual void SummonedCreatureDespawn(Creature* /*summon*/) { }
117 virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { }
118
119 // Called when the capture point gets assaulted by a player. Return true to disable default behaviour.
120 virtual bool OnCapturePointAssaulted(Player* /*player*/) { return false; }
121 // Called when the capture point state gets updated. Return true to disable default behaviour.
123};
124
126{
127 public:
129
130 void UpdateAI(uint32 /*diff*/) override { }
131
132 static int32 Permissible(GameObject const* go);
133};
134#endif
#define TC_GAME_API
Definition: Define.h:123
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
LootItemType
Definition: LootItemType.h:24
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition: Optional.h:25
QuestGiverStatus
Definition: QuestDef.h:153
virtual ObjectGuid GetGUID(int32) const
Definition: GameObjectAI.h:68
virtual void Damaged(WorldObject *, uint32)
Definition: GameObjectAI.h:95
virtual void SpellHit(WorldObject *, SpellInfo const *)
Definition: GameObjectAI.h:108
virtual void OnGameEvent(bool, uint16)
Definition: GameObjectAI.h:102
virtual void SummonedCreatureDies(Creature *, Unit *)
Definition: GameObjectAI.h:117
virtual uint32 GetData(uint32) const
Definition: GameObjectAI.h:97
GameObject *const me
Definition: GameObjectAI.h:50
virtual void DoAction(int32)
Definition: GameObjectAI.h:66
GameObjectAI(GameObject *go, uint32 scriptId={})
virtual void OnStateChanged(uint32)
Definition: GameObjectAI.h:104
virtual void SetGUID(ObjectGuid const &, int32)
Definition: GameObjectAI.h:67
virtual bool OnReportUse(Player *)
Definition: GameObjectAI.h:92
uint32 GetId() const
Definition: GameObjectAI.h:57
virtual void SpellHitTarget(WorldObject *, SpellInfo const *)
Definition: GameObjectAI.h:111
virtual bool OnGossipHello(Player *)
Definition: GameObjectAI.h:76
virtual void InitializeAI()
Definition: GameObjectAI.h:61
virtual void JustSummoned(Creature *)
Definition: GameObjectAI.h:114
virtual void SetData64(uint32, uint64)
Definition: GameObjectAI.h:98
virtual void SetData(uint32, uint32)
Definition: GameObjectAI.h:100
virtual void OnQuestAccept(Player *, Quest const *)
Definition: GameObjectAI.h:85
virtual void SummonedCreatureDespawn(Creature *)
Definition: GameObjectAI.h:116
virtual bool OnGossipSelect(Player *, uint32, uint32)
Definition: GameObjectAI.h:79
virtual void UpdateAI(uint32)
Definition: GameObjectAI.h:59
virtual bool OnCapturePointAssaulted(Player *)
Definition: GameObjectAI.h:120
virtual void Destroyed(WorldObject *, uint32)
Definition: GameObjectAI.h:94
virtual bool OnGossipSelectCode(Player *, uint32, uint32, char const *)
Definition: GameObjectAI.h:82
virtual bool OnCapturePointUpdated(WorldPackets::Battleground::BattlegroundCapturePointState)
Definition: GameObjectAI.h:122
uint32 const _scriptId
Definition: GameObjectAI.h:47
virtual ~GameObjectAI()
Definition: GameObjectAI.h:54
virtual void OnQuestReward(Player *, Quest const *, LootItemType, uint32)
Definition: GameObjectAI.h:88
virtual void Reset()
Definition: GameObjectAI.h:63
virtual uint64 GetData64(uint32) const
Definition: GameObjectAI.h:99
virtual void EventInform(uint32)
Definition: GameObjectAI.h:105
virtual void OnLootStateChanged(uint32, Unit *)
Definition: GameObjectAI.h:103
void UpdateAI(uint32) override
Definition: GameObjectAI.h:130
static ObjectGuid const Empty
Definition: ObjectGuid.h:274
Definition: Unit.h:627