root/trunk/src/bindings/scripts/include/sc_creature.h

Revision 279, 6.4 kB (checked in by yumileroy, 17 years ago)

Merged commit 269 (5f0e38da128a).

Original author: gvcoman
Date: 2008-11-21 14:34:05-05:00

Line 
1/* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
2 *
3 * Thanks to the original authors: ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
4 *
5 * This program is free software licensed under GPL version 2
6 * Please see the included DOCS/LICENSE.TXT for more information */
7
8#ifndef SC_CREATURE_H
9#define SC_CREATURE_H
10
11#include "CreatureAI.h"
12#include "Creature.h"
13
14class SummonList : std::list<uint64>
15{
16public:
17    SummonList(Creature* creature) : m_creature(creature) {}
18    void Summon(Creature *summon) {push_back(summon->GetGUID());}
19    void Despawn(Creature *summon);
20    void DespawnEntry(uint32 entry);
21    void DespawnAll();
22private:
23    Creature *m_creature;
24};
25
26struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
27{
28    ScriptedAI(Creature* creature) : m_creature(creature), InCombat(false), IsFleeing(false) {}
29    ~ScriptedAI() {}
30
31    //*************
32    //CreatureAI Functions
33    //*************
34
35    //Called if IsVisible(Unit *who) is true at each *who move
36    void MoveInLineOfSight(Unit *);
37
38    //Called at each attack of m_creature by any victim
39    void AttackStart(Unit *);
40    void AttackStart(Unit *, bool melee);
41
42    //Called at stoping attack by any attacker
43    void EnterEvadeMode();
44
45    // Called at any Damage from any attacker (before damage apply)
46    void DamageTaken(Unit *done_by, uint32 &damage) {}
47
48    //Is unit visible for MoveInLineOfSight
49    bool IsVisible(Unit *who) const;
50
51    //Called at World update tick
52    void UpdateAI(const uint32);
53
54    //Called at creature death
55    void JustDied(Unit*){}
56
57    //Called at creature killing another unit
58    void KilledUnit(Unit*){}
59
60    // Called when the creature summon successfully other creature
61    void JustSummoned(Creature* ) {}
62
63    // Called when a summoned creature is despawned
64    void SummonedCreatureDespawn(Creature* /*unit*/) {}
65
66    // Called when hit by a spell
67    void SpellHit(Unit* caster, const SpellEntry*) {}
68
69    // Called when spell hits a target
70    void SpellHitTarget(Unit* target, const SpellEntry*) {}
71
72    // Called when creature is spawned or respawned (for reseting variables)
73    void JustRespawned();
74
75    //Called at waypoint reached or PointMovement end
76    void MovementInform(uint32, uint32){}
77
78    // Called when AI is temporarily replaced or put back when possess is applied or removed
79    void OnPossess(bool apply) {}
80
81    //*************
82    // Variables
83    //*************
84
85    //Pointer to creature we are manipulating
86    Creature* m_creature;
87
88    //Bool for if we are in combat or not
89    bool InCombat;
90
91    //For fleeing
92    bool IsFleeing;
93
94    //*************
95    //Pure virtual functions
96    //*************
97
98    //Called at creature reset either by death or evade
99    virtual void Reset() = 0;
100
101    //Called at creature aggro either by MoveInLOS or Attack Start
102    virtual void Aggro(Unit*) = 0;
103
104    //*************
105    //AI Helper Functions
106    //*************
107
108    //Start movement toward victim
109    void DoStartMovement(Unit* victim, float distance = 0, float angle = 0);
110
111    //Start no movement on victim
112    void DoStartNoMovement(Unit* victim);
113
114    //Do melee swing of current victim if in rnage and ready and not casting
115    void DoMeleeAttackIfReady();
116
117    //Stop attack of current victim
118    void DoStopAttack();
119
120    //Cast spell by Id
121    void DoCast(Unit* victim, uint32 spellId, bool triggered = false);
122
123    //Cast spell by spell info
124    void DoCastSpell(Unit* who,SpellEntry const *spellInfo, bool triggered = false);
125
126    //Creature say
127    void DoSay(const char* text, uint32 language, Unit* target);
128
129    //Creature Yell
130    void DoYell(const char* text, uint32 language, Unit* target);
131
132    //Creature Text emote, optional bool for boss emote text
133    void DoTextEmote(const char* text, Unit* target, bool IsBossEmote = false);
134
135    //Creature whisper, optional bool for boss whisper
136    void DoWhisper(const char* text, Unit* reciever, bool IsBossWhisper = false);
137
138    //Plays a sound to all nearby players
139    void DoPlaySoundToSet(Unit* unit, uint32 sound);
140
141    //Places the entire map into combat with creature
142    void DoZoneInCombat(Unit* pUnit = 0);
143
144    //Drops all threat to 0%. Does not remove players from the threat list
145    void DoResetThreat();
146
147    //Teleports a player without dropping threat (only teleports to same map)
148    void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o);
149    void DoTeleportAll(float x, float y, float z, float o);
150
151    //Returns friendly unit with the most amount of hp missing from max hp
152    Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1);
153
154    //Returns a list of friendly CC'd units within range
155    std::list<Creature*> DoFindFriendlyCC(float range);
156
157    //Returns a list of all friendly units missing a specific buff within range
158    std::list<Creature*> DoFindFriendlyMissingBuff(float range, uint32 spellid);
159
160    //Spawns a creature relative to m_creature
161    Creature* DoSpawnCreature(uint32 id, float x, float y, float z, float angle, uint32 type, uint32 despawntime);
162
163    //Selects a unit from the creature's current aggro list
164    Unit* SelectUnit(SelectAggroTarget target, uint32 position);
165    Unit* SelectUnit(SelectAggroTarget target, uint32 position, float dist, bool playerOnly);
166    void SelectUnitList(std::list<Unit*> &targetList, uint32 num, SelectAggroTarget target, float dist, bool playerOnly);
167
168    //Returns spells that meet the specified criteria from the creatures spell list
169    SpellEntry const* SelectSpell(Unit* Target, int32 School, int32 Mechanic, SelectTarget Targets,  uint32 PowerCostMin, uint32 PowerCostMax, float RangeMin, float RangeMax, SelectEffect Effect);
170
171    //Checks if you can cast the specified spell
172    bool CanCast(Unit* Target, SpellEntry const *Spell, bool Triggered = false);
173};
174
175struct TRINITY_DLL_DECL Scripted_NoMovementAI : public ScriptedAI
176{
177    Scripted_NoMovementAI(Creature* creature) : ScriptedAI(creature) {}
178
179    //Called if IsVisible(Unit *who) is true at each *who move
180    void MoveInLineOfSight(Unit *);
181
182    //Called at each attack of m_creature by any victim
183    void AttackStart(Unit *);
184};
185
186struct TRINITY_DLL_DECL NullCreatureAI : public CreatureAI
187{
188    NullCreatureAI(Creature* c) : m_creature(c) {}
189    ~NullCreatureAI() {}
190
191    Creature *m_creature;
192
193    void MoveInLineOfSight(Unit *) {}
194    void AttackStart(Unit *) {}
195    void EnterEvadeMode() {}
196    bool IsVisible(Unit *) const { return false; }
197
198    void UpdateAI(const uint32) {}
199};
200
201#endif
Note: See TracBrowser for help on using the browser.