Files
TCPlayerbotCore/src/server/game/AI/ScriptedAI/ScriptedCreature.h
T

315 lines
10 KiB
C++
Raw Normal View History

2011-05-25 15:55:14 +02:00
/*
* Copyright (C) 2008-2011 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
2008-10-14 11:57:03 -05:00
*
2011-05-25 15:55:14 +02:00
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
2008-10-14 11:57:03 -05:00
*
2011-05-25 15:55:14 +02:00
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
2009-10-17 15:51:44 -07:00
2011-05-25 15:55:14 +02:00
#ifndef SCRIPTEDCREATURE_H_
#define SCRIPTEDCREATURE_H_
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
#include "Creature.h"
#include "CreatureAI.h"
#include "CreatureAIImpl.h"
2010-08-08 22:54:58 +06:00
#include "InstanceScript.h"
2009-10-17 15:51:44 -07:00
2011-05-25 16:22:13 +02:00
#define CAST_PLR(a) (dynamic_cast<Player*>(a))
#define CAST_CRE(a) (dynamic_cast<Creature*>(a))
#define CAST_AI(a, b) (dynamic_cast<a*>(b))
2009-10-17 15:51:44 -07:00
2009-06-04 17:42:48 -05:00
#define GET_SPELL(a) (const_cast<SpellEntry*>(GetSpellStore()->LookupEntry(a)))
2009-10-17 15:51:44 -07:00
2010-08-08 22:54:58 +06:00
class InstanceScript;
2009-10-17 15:51:44 -07:00
class SummonList : public std::list<uint64>
{
public:
2010-04-14 23:07:41 +02:00
explicit SummonList(Creature* creature) : me(creature) {}
void Summon(Creature* summon) { push_back(summon->GetGUID()); }
void Despawn(Creature* summon) { remove(summon->GetGUID()); }
void DespawnEntry(uint32 entry);
void DespawnAll();
void DoAction(uint32 entry, int32 info);
2009-05-13 10:54:11 -05:00
void DoZoneInCombat(uint32 entry = 0);
void RemoveNotExisting();
bool HasEntry(uint32 entry);
private:
Creature* me;
};
2009-10-17 15:51:44 -07:00
2010-02-05 00:31:28 +01:00
struct ScriptedAI : public CreatureAI
2008-10-02 16:23:55 -05:00
{
explicit ScriptedAI(Creature* creature);
virtual ~ScriptedAI() {}
2009-10-17 15:51:44 -07:00
// *************
2008-10-02 16:23:55 -05:00
//CreatureAI Functions
// *************
2009-10-17 15:51:44 -07:00
void AttackStartNoMove(Unit* target);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Called at any Damage from any attacker (before damage apply)
void DamageTaken(Unit* /*attacker*/, uint32& /*damage*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at World update tick
virtual void UpdateAI(uint32 const diff);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at creature death
void JustDied(Unit* /*killer*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at creature killing another unit
void KilledUnit(Unit* /*victim*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Called when the creature summon successfully other creature
void JustSummoned(Creature* /*summon*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Called when a summoned creature is despawned
void SummonedCreatureDespawn(Creature* /*summon*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
// Called when hit by a spell
void SpellHit(Unit* /*caster*/, SpellEntry const* /*spell*/) {}
2009-10-17 15:51:44 -07:00
// Called when spell hits a target
void SpellHitTarget(Unit* /*target*/, SpellEntry const* /*spell*/) {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at waypoint reached or PointMovement end
void MovementInform(uint32 /*type*/, uint32 /*id*/) {}
2009-10-17 15:51:44 -07:00
// Called when AI is temporarily replaced or put back when possess is applied or removed
2010-04-19 09:26:37 +02:00
void OnPossess(bool /*apply*/) {}
2009-10-17 15:51:44 -07:00
// *************
2008-10-02 16:23:55 -05:00
// Variables
// *************
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Pointer to creature we are manipulating
2010-04-14 23:07:41 +02:00
Creature* me;
2009-10-17 15:51:44 -07:00
//For fleeing
bool IsFleeing;
2009-10-17 15:51:44 -07:00
// *************
2008-10-02 16:23:55 -05:00
//Pure virtual functions
// *************
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at creature reset either by death or evade
void Reset() {}
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Called at creature aggro either by MoveInLOS or Attack Start
void EnterCombat(Unit* /*victim*/) {}
2009-10-17 15:51:44 -07:00
// *************
2008-10-02 16:23:55 -05:00
//AI Helper Functions
// *************
2009-10-17 15:51:44 -07:00
//Start movement toward victim
void DoStartMovement(Unit* target, float distance = 0.0f, float angle = 0.0f);
2009-10-17 15:51:44 -07:00
//Start no movement on victim
void DoStartNoMovement(Unit* target);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Stop attack of current victim
void DoStopAttack();
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Cast spell by spell info
void DoCastSpell(Unit* target, SpellEntry const* spellInfo, bool triggered = false);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Plays a sound to all nearby players
void DoPlaySoundToSet(WorldObject* source, uint32 soundId);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Drops all threat to 0%. Does not remove players from the threat list
void DoResetThreat();
2009-10-17 15:51:44 -07:00
float DoGetThreat(Unit* unit);
void DoModifyThreatPercent(Unit* unit, int32 pct);
2009-10-17 15:51:44 -07:00
void DoTeleportTo(float x, float y, float z, uint32 time = 0);
void DoTeleportTo(float const pos[4]);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Teleports a player without dropping threat (only teleports to same map)
void DoTeleportPlayer(Unit* unit, float x, float y, float z, float o);
void DoTeleportAll(float x, float y, float z, float o);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, uint32 minHPDiff = 1);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Returns a list of friendly CC'd units within range
std::list<Creature*> DoFindFriendlyCC(float range);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Returns a list of all friendly units missing a specific buff within range
std::list<Creature*> DoFindFriendlyMissingBuff(float range, uint32 spellId);
2009-10-17 15:51:44 -07:00
2010-04-14 23:07:41 +02:00
//Return a player with at least minimumRange from me
Player* GetPlayerAtMinimumRange(float minRange);
2009-10-17 15:51:44 -07:00
2010-04-14 23:07:41 +02:00
//Spawns a creature relative to me
Creature* DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime);
2009-10-17 15:51:44 -07:00
2010-08-26 01:20:57 +06:00
bool HealthBelowPct(uint32 pct) const { return me->HealthBelowPct(pct); }
bool HealthAbovePct(uint32 pct) const { return me->HealthAbovePct(pct); }
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Returns spells that meet the specified criteria from the creatures spell list
SpellEntry const* SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, uint32 powerCostMin, uint32 powerCostMax, float rangeMin, float rangeMax, SelectEffect effect);
2009-10-17 15:51:44 -07:00
2008-10-02 16:23:55 -05:00
//Checks if you can cast the specified spell
bool CanCast(Unit* target, SpellEntry const* spell, bool triggered = false);
2009-10-17 15:51:44 -07:00
void SetEquipmentSlots(bool loadDefault, int32 mainHand = EQUIP_NO_CHANGE, int32 offHand = EQUIP_NO_CHANGE, int32 ranged = EQUIP_NO_CHANGE);
2009-10-17 15:51:44 -07:00
2009-08-13 02:48:34 +02:00
//Generally used to control if MoveChase() is to be used or not in AttackStart(). Some creatures does not chase victims
void SetCombatMovement(bool allowMovement);
bool IsCombatMovementAllowed() { return _isCombatMovementAllowed; }
2009-10-17 15:51:44 -07:00
bool EnterEvadeIfOutOfCombatArea(uint32 const diff);
2009-10-17 15:51:44 -07:00
// return true for heroic mode. i.e.
2010-04-07 18:09:10 +02:00
// - for dungeon in mode 10-heroic,
// - for raid in mode 10-Heroic
// - for raid in mode 25-heroic
// DO NOT USE to check raid in mode 25-normal.
bool IsHeroic() { return _isHeroic; }
// return the dungeon or raid difficulty
Difficulty GetDifficulty() { return _difficulty; }
// return true for 25 man or 25 man heroic mode
bool Is25ManRaid() { return _difficulty & 1; }
template<class T> inline
const T& DUNGEON_MODE(const T& normal5, const T& heroic10)
{
switch (_difficulty)
{
case DUNGEON_DIFFICULTY_NORMAL:
return normal5;
case DUNGEON_DIFFICULTY_HEROIC:
return heroic10;
default:
break;
}
return heroic10;
}
template<class T> inline
const T& RAID_MODE(const T& normal10, const T& normal25)
{
switch (_difficulty)
{
case RAID_DIFFICULTY_10MAN_NORMAL:
return normal10;
case RAID_DIFFICULTY_25MAN_NORMAL:
return normal25;
default:
break;
}
return normal25;
}
template<class T> inline
const T& RAID_MODE(const T& normal10, const T& normal25, const T& heroic10, const T& heroic25)
{
switch (_difficulty)
{
case RAID_DIFFICULTY_10MAN_NORMAL:
return normal10;
case RAID_DIFFICULTY_25MAN_NORMAL:
return normal25;
case RAID_DIFFICULTY_10MAN_HEROIC:
return heroic10;
case RAID_DIFFICULTY_25MAN_HEROIC:
return heroic25;
default:
break;
}
return heroic25;
}
2009-08-08 21:29:12 +02:00
private:
Difficulty _difficulty;
uint32 _evadeCheckCooldown;
bool _isCombatMovementAllowed;
bool _isHeroic;
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
2010-02-05 00:31:28 +01:00
struct Scripted_NoMovementAI : public ScriptedAI
2008-10-02 16:23:55 -05:00
{
Scripted_NoMovementAI(Creature* creature) : ScriptedAI(creature) {}
virtual ~Scripted_NoMovementAI() {}
2008-10-02 16:23:55 -05:00
2010-04-14 23:07:41 +02:00
//Called at each attack of me by any victim
void AttackStart(Unit* target);
2008-10-02 16:23:55 -05:00
};
2009-10-17 15:51:44 -07:00
class BossAI : public ScriptedAI
2009-05-10 22:48:22 -05:00
{
public:
BossAI(Creature* creature, uint32 bossId);
virtual ~BossAI() {}
2009-10-17 15:51:44 -07:00
InstanceScript* const instance;
BossBoundaryMap const* GetBoundary() const { return _boundary; }
2009-10-17 15:51:44 -07:00
void JustSummoned(Creature* summon);
void SummonedCreatureDespawn(Creature* summon);
2009-10-17 15:51:44 -07:00
virtual void UpdateAI(uint32 const diff);
// Hook used to execute events scheduled into EventMap without the need
// to override UpdateAI
// note: You must re-schedule the event within this method if the event
// is supposed to run more than once
2011-05-27 14:45:44 +02:00
virtual void ExecuteEvent(uint32 const /*eventId*/) { }
2009-10-17 15:51:44 -07:00
void Reset() { _Reset(); }
void EnterCombat(Unit* /*who*/) { _EnterCombat(); }
void JustDied(Unit* /*killer*/) { _JustDied(); }
void JustReachedHome() { _JustReachedHome(); }
2009-10-17 15:51:44 -07:00
protected:
void _Reset();
void _EnterCombat();
void _JustDied();
void _JustReachedHome() { me->setActive(false); }
2009-10-17 15:51:44 -07:00
bool CheckInRoom()
{
2010-04-07 19:14:10 +02:00
if (CheckBoundary(me))
return true;
EnterEvadeMode();
return false;
}
bool CheckBoundary(Unit* who);
void TeleportCheaters();
EventMap events;
SummonList summons;
private:
BossBoundaryMap const* const _boundary;
uint32 const _bossId;
2009-05-10 22:48:22 -05:00
};
2009-10-17 15:51:44 -07:00
// SD2 grid searchers.
2011-03-27 12:54:42 +02:00
Creature* GetClosestCreatureWithEntry(WorldObject* source, uint32 entry, float maxSearchRange, bool alive = true);
GameObject* GetClosestGameObjectWithEntry(WorldObject* source, uint32 entry, float maxSearchRange);
void GetCreatureListWithEntryInGrid(std::list<Creature*>& list, WorldObject* source, uint32 entry, float maxSearchRange);
void GetGameObjectListWithEntryInGrid(std::list<GameObject*>& list, WorldObject* source, uint32 entry, float maxSearchRange);
2009-10-17 15:51:44 -07:00
2011-05-25 15:55:14 +02:00
#endif // SCRIPTEDCREATURE_H_