TrinityCore
Loading...
Searching...
No Matches
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 = {}) noexcept;
54 GameObjectAI(GameObjectAI const&) = delete;
58 virtual ~GameObjectAI();
59
60 // Gets the id of the AI (script id)
61 uint32 GetId() const { return _scriptId; }
62
63 virtual void UpdateAI(uint32 /*diff*/) { }
64
65 virtual void InitializeAI() { Reset(); }
66
67 virtual void Reset() { }
68
69 // Pass parameters between AI
70 virtual void DoAction([[maybe_unused]] int32 param) { }
71 virtual void SetGUID([[maybe_unused]] ObjectGuid const& guid, [[maybe_unused]] int32 id) { }
72 virtual ObjectGuid GetGUID([[maybe_unused]] int32 id) const { return ObjectGuid::Empty; }
73
74 static int32 Permissible(GameObject const* go);
75
76 // Called when the dialog status between a player and the gameobject is requested.
77 virtual Optional<QuestGiverStatus> GetDialogStatus(Player const* player);
78
79 // Called when a player opens a gossip dialog with the gameobject.
80 virtual bool OnGossipHello(Player* /*player*/) { return false; }
81
82 // Called when a player selects a gossip item in the gameobject's gossip menu.
83 virtual bool OnGossipSelect(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/) { return false; }
84
85 // Called when a player selects a gossip with a code in the gameobject's gossip menu.
86 virtual bool OnGossipSelectCode(Player* /*player*/, uint32 /*menuId*/, uint32 /*gossipListId*/, char const* /*code*/) { return false; }
87
88 // Called when a player accepts a quest from the gameobject.
89 virtual void OnQuestAccept(Player* /*player*/, Quest const* /*quest*/) { }
90
91 // Called when a player completes a quest and is rewarded, opt is the selected item's index or 0
92 virtual void OnQuestReward(Player* /*player*/, Quest const* /*quest*/, LootItemType /*type*/, uint32 /*opt*/) { }
93
94 // Called when a Player clicks a GameObject, before GossipHello
95 // prevents achievement tracking if returning true
96 virtual bool OnReportUse(Player* /*player*/) { return false; }
97
98 virtual void Destroyed(WorldObject* /*attacker*/, uint32 /*eventId*/) { }
99 virtual void Damaged(WorldObject* /*attacker*/, uint32 /*eventId*/) { }
100
101 virtual uint32 GetData(uint32 /*id*/) const { return 0; }
102 virtual void SetData64(uint32 /*id*/, uint64 /*value*/) { }
103 virtual uint64 GetData64(uint32 /*id*/) const { return 0; }
104 virtual void SetData(uint32 /*id*/, uint32 /*value*/) { }
105
106 virtual void OnGameEvent(bool /*start*/, uint16 /*eventId*/) { }
107 virtual void OnLootStateChanged(uint32 /*state*/, Unit* /*unit*/) { }
108 virtual void OnStateChanged(uint32 /*state*/) { }
109 virtual void EventInform(uint32 /*eventId*/) { }
110
111 // Called when hit by a spell
112 virtual void SpellHit(WorldObject* /*caster*/, SpellInfo const* /*spellInfo*/) { }
113
114 // Called when spell hits a target
115 virtual void SpellHitTarget(WorldObject* /*target*/, SpellInfo const* /*spellInfo*/) { }
116
117 // Called when the gameobject summon successfully other creature
118 virtual void JustSummoned(Creature* /*summon*/) { }
119
120 virtual void SummonedCreatureDespawn(Creature* /*summon*/) { }
121 virtual void SummonedCreatureDies(Creature* /*summon*/, Unit* /*killer*/) { }
122
123 // Called when the capture point gets assaulted by a player. Return true to disable default behaviour.
124 virtual bool OnCapturePointAssaulted(Player* /*player*/) { return false; }
125 // Called when the capture point state gets updated. Return true to disable default behaviour.
127};
128
130{
131 public:
133
134 void UpdateAI(uint32 /*diff*/) override { }
135
136 static int32 Permissible(GameObject const* go);
137};
138#endif
#define TC_GAME_API
Definition Define.h:129
uint8_t uint8
Definition Define.h:156
int32_t int32
Definition Define.h:150
uint64_t uint64
Definition Define.h:153
uint16_t uint16
Definition Define.h:155
uint32_t uint32
Definition Define.h:154
LootItemType
std::optional< T > Optional
Optional helper class to wrap optional values within.
Definition Optional.h:25
QuestGiverStatus
Definition QuestDef.h:158
virtual ObjectGuid GetGUID(int32 id) const
virtual void Damaged(WorldObject *, uint32)
virtual void SpellHit(WorldObject *, SpellInfo const *)
virtual void OnGameEvent(bool, uint16)
virtual void SummonedCreatureDies(Creature *, Unit *)
virtual uint32 GetData(uint32) const
GameObject *const me
GameObjectAI & operator=(GameObjectAI const &)=delete
GameObjectAI & operator=(GameObjectAI &&)=delete
virtual void OnStateChanged(uint32)
virtual bool OnReportUse(Player *)
virtual ~GameObjectAI()
uint32 GetId() const
GameObjectAI(GameObjectAI &&)=delete
virtual void SpellHitTarget(WorldObject *, SpellInfo const *)
GameObjectAI(GameObject *go, uint32 scriptId={}) noexcept
GameObjectAI(GameObjectAI const &)=delete
virtual bool OnGossipHello(Player *)
virtual void InitializeAI()
virtual void JustSummoned(Creature *)
virtual void SetData64(uint32, uint64)
virtual void SetData(uint32, uint32)
virtual void OnQuestAccept(Player *, Quest const *)
virtual void SummonedCreatureDespawn(Creature *)
virtual bool OnGossipSelect(Player *, uint32, uint32)
virtual void UpdateAI(uint32)
virtual bool OnCapturePointAssaulted(Player *)
virtual void SetGUID(ObjectGuid const &guid, int32 id)
virtual void Destroyed(WorldObject *, uint32)
virtual bool OnGossipSelectCode(Player *, uint32, uint32, char const *)
virtual bool OnCapturePointUpdated(WorldPackets::Battleground::BattlegroundCapturePointState)
uint32 const _scriptId
virtual void DoAction(int32 param)
virtual void OnQuestReward(Player *, Quest const *, LootItemType, uint32)
virtual void Reset()
virtual uint64 GetData64(uint32) const
virtual void EventInform(uint32)
virtual void OnLootStateChanged(uint32, Unit *)
void UpdateAI(uint32) override
static ObjectGuid const Empty
Definition ObjectGuid.h:314
Definition Unit.h:635