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

667 lines
18 KiB
C++
Raw Normal View History

2013-11-10 03:31:20 -03:30
/*
2018-01-01 00:40:17 +01:00
* Copyright (C) 2008-2018 TrinityCore <https://www.trinitycore.org/>
2013-11-10 03:31:20 -03:30
* Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
2008-10-14 11:57:03 -05:00
*
2013-11-10 03:31:20 -03:30
* 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
*
2013-11-10 03:31:20 -03:30
* 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
#include "ScriptedCreature.h"
2017-05-28 16:34:44 +02:00
#include "AreaBoundary.h"
2017-06-04 01:00:45 +02:00
#include "DB2Stores.h"
#include "Cell.h"
#include "CellImpl.h"
2017-05-28 16:34:44 +02:00
#include "GridNotifiers.h"
#include "GridNotifiersImpl.h"
#include "InstanceScript.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
2017-06-04 01:00:45 +02:00
#include "MotionMaster.h"
#include "ObjectAccessor.h"
2017-05-28 16:34:44 +02:00
#include "Spell.h"
2017-06-04 01:00:45 +02:00
#include "SpellMgr.h"
#include "TemporarySummon.h"
2009-10-17 15:51:44 -07:00
// Spell summary for ScriptedAI::SelectSpell
2009-08-14 19:45:06 +02:00
struct TSpellSummary
{
uint8 Targets; // set of enum SelectTarget
uint8 Effects; // set of enum SelectEffect
2011-08-18 14:55:27 -03:00
} extern* SpellSummary;
2009-10-17 15:51:44 -07:00
2017-05-28 16:34:44 +02:00
void SummonList::Summon(Creature const* summon)
{
storage_.push_back(summon->GetGUID());
}
void SummonList::Despawn(Creature const* summon)
{
storage_.remove(summon->GetGUID());
}
2016-05-11 23:24:26 +02:00
void SummonList::DoZoneInCombat(uint32 entry, float maxRangeToNearestTarget)
2009-05-13 10:54:11 -05:00
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
2009-05-13 10:54:11 -05:00
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
2009-05-13 10:54:11 -05:00
++i;
2010-04-07 19:14:10 +02:00
if (summon && summon->IsAIEnabled
&& (!entry || summon->GetEntry() == entry))
{
2016-05-11 23:24:26 +02:00
summon->AI()->DoZoneInCombat(nullptr, maxRangeToNearestTarget);
}
2009-05-13 10:54:11 -05:00
}
}
2009-10-17 15:51:44 -07:00
void SummonList::DespawnEntry(uint32 entry)
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
2010-04-07 19:14:10 +02:00
if (!summon)
i = storage_.erase(i);
2010-04-07 19:14:10 +02:00
else if (summon->GetEntry() == entry)
{
i = storage_.erase(i);
2011-10-05 20:48:34 +02:00
summon->DespawnOrUnsummon();
}
else
++i;
}
}
2009-10-17 15:51:44 -07:00
void SummonList::DespawnAll()
{
while (!storage_.empty())
{
Creature* summon = ObjectAccessor::GetCreature(*me, storage_.front());
storage_.pop_front();
if (summon)
2011-10-05 20:48:34 +02:00
summon->DespawnOrUnsummon();
}
}
2009-10-17 15:51:44 -07:00
void SummonList::RemoveNotExisting()
{
for (StorageType::iterator i = storage_.begin(); i != storage_.end();)
{
if (ObjectAccessor::GetCreature(*me, *i))
++i;
else
i = storage_.erase(i);
}
}
2012-11-20 09:29:52 +01:00
bool SummonList::HasEntry(uint32 entry) const
{
for (StorageType::const_iterator i = storage_.begin(); i != storage_.end(); ++i)
{
Creature* summon = ObjectAccessor::GetCreature(*me, *i);
2012-11-20 09:29:52 +01:00
if (summon && summon->GetEntry() == entry)
return true;
}
return false;
}
2017-05-20 00:09:37 +02:00
void SummonList::DoActionImpl(int32 action, StorageType const& summons)
{
for (auto const& guid : summons)
{
Creature* summon = ObjectAccessor::GetCreature(*me, guid);
if (summon && summon->IsAIEnabled)
summon->AI()->DoAction(action);
}
}
2011-08-18 14:55:27 -03:00
ScriptedAI::ScriptedAI(Creature* creature) : CreatureAI(creature),
2009-08-16 21:46:31 +02:00
IsFleeing(false),
2011-05-09 03:37:31 +02:00
_isCombatMovementAllowed(true)
2009-04-29 00:15:18 -05:00
{
_isHeroic = me->GetMap()->IsHeroic();
_difficulty = Difficulty(me->GetMap()->GetSpawnMode());
2009-04-29 00:15:18 -05:00
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::AttackStartNoMove(Unit* who)
{
2011-08-18 14:55:27 -03:00
if (!who)
return;
2009-10-17 15:51:44 -07:00
if (me->Attack(who, true))
2011-08-18 14:55:27 -03:00
DoStartNoMovement(who);
}
2009-10-17 15:51:44 -07:00
void ScriptedAI::AttackStart(Unit* who)
{
if (IsCombatMovementAllowed())
CreatureAI::AttackStart(who);
else
AttackStartNoMove(who);
}
void ScriptedAI::UpdateAI(uint32 /*diff*/)
{
//Check if we have a current target
2009-08-14 19:45:06 +02:00
if (!UpdateVictim())
return;
2009-10-17 15:51:44 -07:00
DoMeleeAttackIfReady();
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoStartMovement(Unit* victim, float distance, float angle)
{
2011-08-18 14:55:27 -03:00
if (victim)
me->GetMotionMaster()->MoveChase(victim, distance, angle);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoStartNoMovement(Unit* victim)
{
2011-08-18 14:55:27 -03:00
if (!victim)
return;
2009-10-17 15:51:44 -07:00
2010-04-14 23:07:41 +02:00
me->GetMotionMaster()->MoveIdle();
}
2009-10-17 15:51:44 -07:00
void ScriptedAI::DoStopAttack()
{
2013-06-11 19:54:27 -02:30
if (me->GetVictim())
2010-04-14 23:07:41 +02:00
me->AttackStop();
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoCastSpell(Unit* target, SpellInfo const* spellInfo, bool triggered)
{
if (!target || me->IsNonMeleeSpellCast(false))
return;
2009-10-17 15:51:44 -07:00
2010-04-14 23:07:41 +02:00
me->StopMoving();
2011-08-18 14:55:27 -03:00
me->CastSpell(target, spellInfo, triggered ? TRIGGERED_FULL_MASK : TRIGGERED_NONE);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoPlaySoundToSet(WorldObject* source, uint32 soundId)
{
2011-08-18 14:55:27 -03:00
if (!source)
return;
2009-10-17 15:51:44 -07:00
if (!sSoundKitStore.LookupEntry(soundId))
{
TC_LOG_ERROR("scripts", "Invalid soundId %u used in DoPlaySoundToSet (Source: %s)", soundId, source->GetGUID().ToString().c_str());
return;
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
source->PlayDirectSound(soundId);
}
2009-10-17 15:51:44 -07:00
Creature* ScriptedAI::DoSpawnCreature(uint32 entry, float offsetX, float offsetY, float offsetZ, float angle, uint32 type, uint32 despawntime)
{
return me->SummonCreature(entry, me->GetPositionX() + offsetX, me->GetPositionY() + offsetY, me->GetPositionZ() + offsetZ, angle, TempSummonType(type), despawntime);
}
2009-10-17 15:51:44 -07:00
2017-05-28 16:34:44 +02:00
bool ScriptedAI::HealthBelowPct(uint32 pct) const
{
return me->HealthBelowPct(pct);
}
bool ScriptedAI::HealthAbovePct(uint32 pct) const
{
return me->HealthAbovePct(pct);
}
SpellInfo const* ScriptedAI::SelectSpell(Unit* target, uint32 school, uint32 mechanic, SelectTargetType targets, float rangeMin, float rangeMax, SelectEffect effect)
{
2009-10-27 21:39:53 -07:00
//No target so we can't cast
if (!target)
2016-05-11 23:24:26 +02:00
return nullptr;
2009-10-17 15:51:44 -07:00
//Silenced so we can't cast
2010-04-14 23:07:41 +02:00
if (me->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_SILENCED))
2016-05-11 23:24:26 +02:00
return nullptr;
2009-10-17 15:51:44 -07:00
//Using the extended script system we first create a list of viable spells
2016-03-24 16:12:53 +01:00
SpellInfo const* apSpell[MAX_CREATURE_SPELLS];
memset(apSpell, 0, MAX_CREATURE_SPELLS * sizeof(SpellInfo*));
2009-10-17 15:51:44 -07:00
uint32 spellCount = 0;
2009-10-17 15:51:44 -07:00
2016-05-11 23:24:26 +02:00
SpellInfo const* tempSpell = nullptr;
2009-10-17 15:51:44 -07:00
//Check if each spell is viable(set it to null if not)
2016-03-24 16:12:53 +01:00
for (uint32 i = 0; i < MAX_CREATURE_SPELLS; i++)
{
tempSpell = sSpellMgr->GetSpellInfo(me->m_spells[i]);
2009-10-17 15:51:44 -07:00
//This spell doesn't exist
if (!tempSpell)
continue;
2009-10-17 15:51:44 -07:00
// Targets and Effects checked first as most used restrictions
//Check the spell targets if specified
if (targets && !(SpellSummary[me->m_spells[i]].Targets & (1 << (targets-1))))
continue;
2009-10-17 15:51:44 -07:00
//Check the type of spell if we are looking for a specific spell type
if (effect && !(SpellSummary[me->m_spells[i]].Effects & (1 << (effect-1))))
continue;
2009-10-17 15:51:44 -07:00
//Check for school if specified
if (school && (tempSpell->SchoolMask & school) == 0)
continue;
2009-10-17 15:51:44 -07:00
//Check for spell mechanic if specified
if (mechanic && tempSpell->Mechanic != mechanic)
continue;
2009-10-17 15:51:44 -07:00
//Check if the spell meets our range requirements
if (rangeMin && me->GetSpellMinRangeForTarget(target, tempSpell) < rangeMin)
continue;
if (rangeMax && me->GetSpellMaxRangeForTarget(target, tempSpell) > rangeMax)
continue;
2009-10-17 15:51:44 -07:00
2009-10-27 21:39:53 -07:00
//Check if our target is in range
if (me->IsWithinDistInMap(target, float(me->GetSpellMinRangeForTarget(target, tempSpell))) || !me->IsWithinDistInMap(target, float(me->GetSpellMaxRangeForTarget(target, tempSpell))))
continue;
2009-10-17 15:51:44 -07:00
//All good so lets add it to the spell list
apSpell[spellCount] = tempSpell;
++spellCount;
}
2009-10-17 15:51:44 -07:00
//We got our usable spells so now lets randomly pick one
if (!spellCount)
2016-05-11 23:24:26 +02:00
return nullptr;
2009-10-17 15:51:44 -07:00
return apSpell[urand(0, spellCount - 1)];
}
2009-10-17 15:51:44 -07:00
void ScriptedAI::DoResetThreat()
{
2010-04-14 23:07:41 +02:00
if (!me->CanHaveThreatList() || me->getThreatManager().isThreatListEmpty())
{
TC_LOG_ERROR("scripts", "DoResetThreat called for creature that either cannot have threat list or has empty threat list (me entry = %d)", me->GetEntry());
return;
}
2009-10-17 15:51:44 -07:00
ThreatContainer::StorageType threatlist = me->getThreatManager().getThreatList();
2009-10-17 15:51:44 -07:00
for (ThreatContainer::StorageType::const_iterator itr = threatlist.begin(); itr != threatlist.end(); ++itr)
{
Unit* unit = ObjectAccessor::GetUnit(*me, (*itr)->getUnitGuid());
2011-08-18 14:55:27 -03:00
if (unit && DoGetThreat(unit))
DoModifyThreatPercent(unit, -100);
}
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
float ScriptedAI::DoGetThreat(Unit* unit)
{
2011-08-18 14:55:27 -03:00
if (!unit)
return 0.0f;
return me->getThreatManager().getThreat(unit);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoModifyThreatPercent(Unit* unit, int32 pct)
{
2011-08-18 14:55:27 -03:00
if (!unit)
return;
me->getThreatManager().modifyThreatPercent(unit, pct);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoTeleportTo(float x, float y, float z, uint32 time)
2009-02-23 13:14:04 -06:00
{
2011-08-18 14:55:27 -03:00
me->Relocate(x, y, z);
float speed = me->GetDistance(x, y, z) / ((float)time * 0.001f);
me->MonsterMoveWithSpeed(x, y, z, speed);
2009-02-23 13:14:04 -06:00
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoTeleportTo(const float position[4])
2009-05-13 10:54:11 -05:00
{
2011-08-18 14:55:27 -03:00
me->NearTeleportTo(position[0], position[1], position[2], position[3]);
2009-05-13 10:54:11 -05:00
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoTeleportPlayer(Unit* unit, float x, float y, float z, float o)
{
if (!unit)
return;
2009-10-17 15:51:44 -07:00
if (Player* player = unit->ToPlayer())
player->TeleportTo(unit->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
else
TC_LOG_ERROR("scripts", "Creature %s Tried to teleport non-player unit (%s) to x: %f y:%f z: %f o: %f. Aborted.",
me->GetGUID().ToString().c_str(), unit->GetGUID().ToString().c_str(), x, y, z, o);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
void ScriptedAI::DoTeleportAll(float x, float y, float z, float o)
{
2011-08-18 14:55:27 -03:00
Map* map = me->GetMap();
if (!map->IsDungeon())
return;
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
Map::PlayerList const& PlayerList = map->GetPlayers();
for (Map::PlayerList::const_iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr)
2013-06-11 21:25:12 -02:30
if (Player* player = itr->GetSource())
2013-06-11 19:54:27 -02:30
if (player->IsAlive())
2011-08-18 14:55:27 -03:00
player->TeleportTo(me->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
Unit* ScriptedAI::DoSelectLowestHpFriendly(float range, uint32 minHPDiff)
{
2016-05-11 23:24:26 +02:00
Unit* unit = nullptr;
2011-08-18 14:55:27 -03:00
Trinity::MostHPMissingInRange u_check(me, range, minHPDiff);
Trinity::UnitLastSearcher<Trinity::MostHPMissingInRange> searcher(me, unit, u_check);
Cell::VisitAllObjects(me, searcher, range);
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
return unit;
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
std::list<Creature*> ScriptedAI::DoFindFriendlyCC(float range)
{
2011-08-18 14:55:27 -03:00
std::list<Creature*> list;
Trinity::FriendlyCCedInRange u_check(me, range);
Trinity::CreatureListSearcher<Trinity::FriendlyCCedInRange> searcher(me, list, u_check);
Cell::VisitAllObjects(me, searcher, range);
2011-08-18 14:55:27 -03:00
return list;
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
std::list<Creature*> ScriptedAI::DoFindFriendlyMissingBuff(float range, uint32 uiSpellid)
{
2011-08-18 14:55:27 -03:00
std::list<Creature*> list;
Trinity::FriendlyMissingBuffInRange u_check(me, range, uiSpellid);
Trinity::CreatureListSearcher<Trinity::FriendlyMissingBuffInRange> searcher(me, list, u_check);
Cell::VisitAllObjects(me, searcher, range);
2011-08-18 14:55:27 -03:00
return list;
}
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
Player* ScriptedAI::GetPlayerAtMinimumRange(float minimumRange)
2009-07-24 05:27:49 +02:00
{
2016-05-11 23:24:26 +02:00
Player* player = nullptr;
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
Trinity::PlayerAtMinimumRangeAway check(me, minimumRange);
Trinity::PlayerSearcher<Trinity::PlayerAtMinimumRangeAway> searcher(me, player, check);
Cell::VisitWorldObjects(me, searcher, minimumRange);
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
return player;
2009-07-24 05:27:49 +02:00
}
2009-10-17 15:51:44 -07:00
void ScriptedAI::SetEquipmentSlots(bool loadDefault, int32 mainHand /*= EQUIP_NO_CHANGE*/, int32 offHand /*= EQUIP_NO_CHANGE*/, int32 ranged /*= EQUIP_NO_CHANGE*/)
2009-04-19 21:16:11 +02:00
{
if (loadDefault)
2009-04-19 21:16:11 +02:00
{
2013-02-18 12:24:18 +00:00
me->LoadEquipment(me->GetOriginalEquipmentId(), true);
2009-04-19 21:16:11 +02:00
return;
}
2009-10-17 15:51:44 -07:00
if (mainHand >= 0)
2015-07-01 02:22:03 +02:00
me->SetVirtualItem(0, uint32(mainHand));
2009-10-17 15:51:44 -07:00
if (offHand >= 0)
2015-07-01 02:22:03 +02:00
me->SetVirtualItem(1, uint32(offHand));
2009-10-17 15:51:44 -07:00
if (ranged >= 0)
2015-07-01 02:22:03 +02:00
me->SetVirtualItem(2, uint32(ranged));
2009-04-19 21:16:11 +02:00
}
2009-10-17 15:51:44 -07:00
void ScriptedAI::SetCombatMovement(bool allowMovement)
2009-05-19 21:03:43 +02:00
{
_isCombatMovementAllowed = allowMovement;
2009-05-19 21:03:43 +02:00
}
2009-10-17 15:51:44 -07:00
2013-07-06 01:00:05 +02:00
enum NPCs
2009-08-14 19:45:06 +02:00
{
NPC_BROODLORD = 12017,
NPC_VOID_REAVER = 19516,
NPC_JAN_ALAI = 23578,
NPC_SARTHARION = 28860
};
2009-10-17 15:51:44 -07:00
2009-08-08 21:29:12 +02:00
// Hacklike storage used for misc creatures that are expected to evade of outside of a certain area.
2010-02-05 00:31:28 +01:00
// It is assumed the information is found elswehere and can be handled by the core. So far no luck finding such information/way to extract it.
/*bool ScriptedAI::EnterEvadeIfOutOfCombatArea(uint32 const diff)
2009-08-08 21:29:12 +02:00
{
if (_evadeCheckCooldown <= diff)
_evadeCheckCooldown = 2500;
2009-08-08 21:29:12 +02:00
else
{
_evadeCheckCooldown -= diff;
2009-08-08 21:29:12 +02:00
return false;
}
2009-10-17 15:51:44 -07:00
2013-06-11 19:54:27 -02:30
if (me->IsInEvadeMode() || !me->GetVictim())
2009-08-08 21:29:12 +02:00
return false;
2009-10-17 15:51:44 -07:00
2011-08-18 14:55:27 -03:00
float x = me->GetPositionX();
float y = me->GetPositionY();
float z = me->GetPositionZ();
2009-10-17 15:51:44 -07:00
2011-09-29 12:43:05 +02:00
switch (me->GetEntry())
2009-08-08 21:29:12 +02:00
{
2009-08-14 19:45:06 +02:00
case NPC_BROODLORD: // broodlord (not move down stairs)
2011-08-18 14:55:27 -03:00
if (z > 448.60f)
2009-08-08 21:29:12 +02:00
return false;
break;
2009-08-14 19:45:06 +02:00
case NPC_VOID_REAVER: // void reaver (calculate from center of room)
2010-04-14 23:07:41 +02:00
if (me->GetDistance2d(432.59f, 371.93f) < 105.0f)
2009-08-08 21:29:12 +02:00
return false;
break;
2009-08-14 19:45:06 +02:00
case NPC_JAN_ALAI: // jan'alai (calculate by Z)
2011-08-18 14:55:27 -03:00
if (z > 12.0f)
2009-08-08 21:29:12 +02:00
return false;
break;
2009-08-14 19:45:06 +02:00
case NPC_SARTHARION: // sartharion (calculate box)
2011-08-18 14:55:27 -03:00
if (x > 3218.86f && x < 3275.69f && y < 572.40f && y > 484.68f)
2009-08-08 21:29:12 +02:00
return false;
break;
default: // For most of creatures that certain area is their home area.
TC_LOG_INFO("misc", "TSCR: EnterEvadeIfOutOfCombatArea used for creature entry %u, but does not have any definition. Using the default one.", me->GetEntry());
uint32 homeAreaId = me->GetMap()->GetAreaId(me->GetHomePosition().GetPositionX(), me->GetHomePosition().GetPositionY(), me->GetHomePosition().GetPositionZ());
2011-09-29 12:43:05 +02:00
if (me->GetAreaId() == homeAreaId)
return false;
2009-08-08 21:29:12 +02:00
}
2009-10-17 15:51:44 -07:00
2009-08-08 21:29:12 +02:00
EnterEvadeMode();
return true;
}*/
2009-10-17 15:51:44 -07:00
// BossAI - for instanced bosses
2011-05-09 03:37:31 +02:00
BossAI::BossAI(Creature* creature, uint32 bossId) : ScriptedAI(creature),
instance(creature->GetInstanceScript()),
summons(creature),
_bossId(bossId)
{
if (instance)
SetBoundary(instance->GetBossBoundary(bossId));
scheduler.SetValidator([this]
{
return !me->HasUnitState(UNIT_STATE_CASTING);
});
}
2009-10-17 15:51:44 -07:00
2009-05-10 22:48:22 -05:00
void BossAI::_Reset()
{
2013-06-11 19:54:27 -02:30
if (!me->IsAlive())
return;
2009-10-17 15:51:44 -07:00
me->SetCombatPulseDelay(0);
me->ResetLootMode();
2009-05-10 22:48:22 -05:00
events.Reset();
summons.DespawnAll();
scheduler.CancelAll();
2010-04-07 19:14:10 +02:00
if (instance)
instance->SetBossState(_bossId, NOT_STARTED);
2009-05-10 22:48:22 -05:00
}
2009-10-17 15:51:44 -07:00
2009-05-10 22:48:22 -05:00
void BossAI::_JustDied()
{
events.Reset();
summons.DespawnAll();
scheduler.CancelAll();
2010-04-07 19:14:10 +02:00
if (instance)
instance->SetBossState(_bossId, DONE);
2009-05-10 22:48:22 -05:00
}
2009-10-17 15:51:44 -07:00
2017-05-28 16:34:44 +02:00
void BossAI::_JustReachedHome()
{
me->setActive(false);
}
2009-05-10 22:48:22 -05:00
void BossAI::_EnterCombat()
{
2010-04-07 19:14:10 +02:00
if (instance)
{
// bosses do not respawn, check only on enter combat
if (!instance->CheckRequiredBosses(_bossId))
{
EnterEvadeMode(EVADE_REASON_SEQUENCE_BREAK);
return;
}
instance->SetBossState(_bossId, IN_PROGRESS);
}
me->SetCombatPulseDelay(5);
me->setActive(true);
DoZoneInCombat();
ScheduleTasks();
2009-05-10 22:48:22 -05:00
}
2009-10-17 15:51:44 -07:00
void BossAI::TeleportCheaters()
{
float x, y, z;
me->GetPosition(x, y, z);
ThreatContainer::StorageType threatList = me->getThreatManager().getThreatList();
for (ThreatContainer::StorageType::const_iterator itr = threatList.begin(); itr != threatList.end(); ++itr)
if (Unit* target = (*itr)->getTarget())
if (target->GetTypeId() == TYPEID_PLAYER && !CheckBoundary(target))
target->NearTeleportTo(x, y, z, 0);
}
2009-10-17 15:51:44 -07:00
void BossAI::JustSummoned(Creature* summon)
2009-05-10 22:48:22 -05:00
{
summons.Summon(summon);
2013-06-11 19:54:27 -02:30
if (me->IsInCombat())
2009-05-13 10:54:11 -05:00
DoZoneInCombat(summon);
2009-05-10 22:48:22 -05:00
}
2009-10-17 15:51:44 -07:00
void BossAI::SummonedCreatureDespawn(Creature* summon)
2009-05-10 22:48:22 -05:00
{
summons.Despawn(summon);
}
2009-10-17 15:51:44 -07:00
void BossAI::UpdateAI(uint32 diff)
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
ExecuteEvent(eventId);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
}
DoMeleeAttackIfReady();
}
2017-05-28 16:34:44 +02:00
bool BossAI::CanAIAttack(Unit const* target) const
{
return CheckBoundary(target);
}
void BossAI::_DespawnAtEvade(uint32 delayToRespawn, Creature* who)
{
if (delayToRespawn < 2)
{
TC_LOG_ERROR("scripts", "_DespawnAtEvade called with delay of %u seconds, defaulting to 2.", delayToRespawn);
delayToRespawn = 2;
}
if (!who)
who = me;
if (TempSummon* whoSummon = who->ToTempSummon())
{
TC_LOG_WARN("scripts", "_DespawnAtEvade called on a temporary summon.");
whoSummon->UnSummon();
return;
}
who->DespawnOrUnsummon(0, Seconds(delayToRespawn));
if (instance && who == me)
instance->SetBossState(_bossId, FAIL);
}
// WorldBossAI - for non-instanced bosses
WorldBossAI::WorldBossAI(Creature* creature) :
ScriptedAI(creature),
summons(creature) { }
void WorldBossAI::_Reset()
{
2013-06-11 19:54:27 -02:30
if (!me->IsAlive())
return;
events.Reset();
summons.DespawnAll();
}
void WorldBossAI::_JustDied()
{
events.Reset();
summons.DespawnAll();
}
void WorldBossAI::_EnterCombat()
{
2011-05-28 02:14:47 +02:00
Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true);
if (target)
AttackStart(target);
}
void WorldBossAI::JustSummoned(Creature* summon)
{
summons.Summon(summon);
2011-05-28 02:14:47 +02:00
Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 0.0f, true);
2011-06-12 02:30:32 +02:00
if (target)
summon->AI()->AttackStart(target);
}
void WorldBossAI::SummonedCreatureDespawn(Creature* summon)
{
summons.Despawn(summon);
}
void WorldBossAI::UpdateAI(uint32 diff)
{
if (!UpdateVictim())
return;
events.Update(diff);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
while (uint32 eventId = events.ExecuteEvent())
{
ExecuteEvent(eventId);
if (me->HasUnitState(UNIT_STATE_CASTING))
return;
}
DoMeleeAttackIfReady();
}