mirror of
https://github.com/araxiaonline/TrinityCore.git
synced 2026-06-16 04:59:41 -04:00
Scripted/Pets: Move some player pets in pet_xxx.cpp
This commit is contained in:
131
src/server/scripts/Pet/pet_dk.cpp
Normal file
131
src/server/scripts/Pet/pet_dk.cpp
Normal file
@@ -0,0 +1,131 @@
|
||||
/*
|
||||
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Ordered alphabetically using scriptname.
|
||||
* Scriptnames of files in this file should be prefixed with "npc_pet_dk_".
|
||||
*/
|
||||
|
||||
#include "ScriptMgr.h"
|
||||
#include "ScriptedCreature.h"
|
||||
|
||||
enum DeathKnightSpells
|
||||
{
|
||||
SPELL_DK_SUMMON_GARGOYLE_1 = 49206,
|
||||
SPELL_DK_SUMMON_GARGOYLE_2 = 50514,
|
||||
SPELL_DK_DISMISS_GARGOYLE = 50515,
|
||||
SPELL_DK_SANCTUARY = 54661,
|
||||
};
|
||||
|
||||
class npc_pet_dk_ebon_gargoyle : public CreatureScript
|
||||
{
|
||||
public:
|
||||
npc_pet_dk_ebon_gargoyle() : CreatureScript("npc_pet_dk_ebon_gargoyle") { }
|
||||
|
||||
struct npc_pet_dk_ebon_gargoyleAI : CasterAI
|
||||
{
|
||||
npc_pet_dk_ebon_gargoyleAI(Creature* creature) : CasterAI(creature) { }
|
||||
|
||||
void InitializeAI() OVERRIDE
|
||||
{
|
||||
CasterAI::InitializeAI();
|
||||
uint64 ownerGuid = me->GetOwnerGUID();
|
||||
if (!ownerGuid)
|
||||
return;
|
||||
|
||||
// Not needed to be despawned now
|
||||
_despawnTimer = 0;
|
||||
// Find victim of Summon Gargoyle spell
|
||||
std::list<Unit*> targets;
|
||||
Trinity::AnyUnfriendlyUnitInObjectRangeCheck u_check(me, me, 30.0f);
|
||||
Trinity::UnitListSearcher<Trinity::AnyUnfriendlyUnitInObjectRangeCheck> searcher(me, targets, u_check);
|
||||
me->VisitNearbyObject(30.0f, searcher);
|
||||
for (std::list<Unit*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter)
|
||||
if ((*iter)->GetAura(SPELL_DK_SUMMON_GARGOYLE_1, ownerGuid))
|
||||
{
|
||||
me->Attack((*iter), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void JustDied(Unit* /*killer*/) OVERRIDE
|
||||
{
|
||||
// Stop Feeding Gargoyle when it dies
|
||||
if (Unit* owner = me->GetOwner())
|
||||
owner->RemoveAurasDueToSpell(SPELL_DK_SUMMON_GARGOYLE_2);
|
||||
}
|
||||
|
||||
// Fly away when dismissed
|
||||
void SpellHit(Unit* source, SpellInfo const* spell) OVERRIDE
|
||||
{
|
||||
if (spell->Id != SPELL_DK_DISMISS_GARGOYLE || !me->IsAlive())
|
||||
return;
|
||||
|
||||
Unit* owner = me->GetOwner();
|
||||
if (!owner || owner != source)
|
||||
return;
|
||||
|
||||
// Stop Fighting
|
||||
me->ApplyModFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE, true);
|
||||
|
||||
// Sanctuary
|
||||
me->CastSpell(me, SPELL_DK_SANCTUARY, true);
|
||||
me->SetReactState(REACT_PASSIVE);
|
||||
|
||||
//! HACK: Creature's can't have MOVEMENTFLAG_FLYING
|
||||
// Fly Away
|
||||
me->SetCanFly(true);
|
||||
me->SetSpeed(MOVE_FLIGHT, 0.75f, true);
|
||||
me->SetSpeed(MOVE_RUN, 0.75f, true);
|
||||
float x = me->GetPositionX() + 20 * std::cos(me->GetOrientation());
|
||||
float y = me->GetPositionY() + 20 * std::sin(me->GetOrientation());
|
||||
float z = me->GetPositionZ() + 40;
|
||||
me->GetMotionMaster()->Clear(false);
|
||||
me->GetMotionMaster()->MovePoint(0, x, y, z);
|
||||
|
||||
// Despawn as soon as possible
|
||||
_despawnTimer = 4 * IN_MILLISECONDS;
|
||||
}
|
||||
|
||||
void UpdateAI(uint32 diff) OVERRIDE
|
||||
{
|
||||
if (_despawnTimer > 0)
|
||||
{
|
||||
if (_despawnTimer > diff)
|
||||
_despawnTimer -= diff;
|
||||
else
|
||||
me->DespawnOrUnsummon();
|
||||
return;
|
||||
}
|
||||
|
||||
CasterAI::UpdateAI(diff);
|
||||
}
|
||||
|
||||
private:
|
||||
uint32 _despawnTimer;
|
||||
};
|
||||
|
||||
CreatureAI* GetAI(Creature* creature) const OVERRIDE
|
||||
{
|
||||
return new npc_pet_dk_ebon_gargoyleAI(creature);
|
||||
}
|
||||
};
|
||||
|
||||
void AddSC_deathknight_pet_scripts()
|
||||
{
|
||||
new npc_pet_dk_ebon_gargoyle();
|
||||
}
|
||||
Reference in New Issue
Block a user