Scripts/Razorfen Kraul add script for quest 1221

Credits to @XFurry , he is original author.

Closes #8165
Closes #10152

Signed-off-by: Nay <dnpd.dd@gmail.com>
This commit is contained in:
Mislav Blazevic
2013-07-04 17:00:23 +01:00
committed by Nay
parent 3394f8cf0b
commit 9c1cca395b
3 changed files with 165 additions and 12 deletions

View File

@@ -74,6 +74,7 @@ public:
switch (go->GetEntry())
{
case 21099: DoorWardGUID = go->GetGUID(); break;
case 20920: go->SetUInt32Value(GAMEOBJECT_FACTION, 0); break; // big fat fugly hack
}
}

View File

@@ -1,6 +1,6 @@
/*
* Copyright (C) 2008-2013 TrinityCore <http://www.trinitycore.org/>
* Copyright (C) 2006-2009 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
* Copyright (C) 2006-2013 ScriptDev2 <https://scriptdev2.svn.sourceforge.net/>
*
* 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
@@ -16,22 +16,12 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
SDName: Razorfen Kraul
SD%Complete: 100
SDComment: Quest support: 1144
SDCategory: Razorfen Kraul
EndScriptData */
/* ContentData
npc_willix
EndContentData */
#include "ScriptMgr.h"
#include "ScriptedCreature.h"
#include "ScriptedEscortAI.h"
#include "razorfen_kraul.h"
#include "Player.h"
#include "PetAI.h"
enum Willix
{
@@ -148,7 +138,143 @@ public:
};
enum SnufflenoseGopher
{
NPC_SNUFFLENOSE_GOPHER = 4781,
GO_BLUELEAF_TUBBER = 20920,
ACTION_FIND_NEW_TUBBER = 0x4B726F66,
POINT_TUBBER = 0x6E615748
};
struct DistanceOrder : public std::binary_function<GameObject, GameObject, bool>
{
DistanceOrder(Creature* me) : me(me) {}
bool operator() (GameObject* first, GameObject* second)
{
return me->GetDistanceOrder(first, second);
}
Creature* me;
};
struct npc_snufflenose_gopher : public CreatureScript
{
public:
npc_snufflenose_gopher() : CreatureScript("npc_snufflenose_gopher") { }
CreatureAI* GetAI(Creature* creature) const
{
return new npc_snufflenose_gopherAI(creature);
}
struct npc_snufflenose_gopherAI : public PetAI
{
npc_snufflenose_gopherAI(Creature* creature) : PetAI(creature) { }
void Reset()
{
IsMovementActive = false;
}
void MovementInform(uint32 type, uint32 id)
{
if (type == POINT_MOTION_TYPE && id == POINT_TUBBER)
{
if (GameObject* go = me->GetMap()->GetGameObject(TargetTubberGUID))
{
go->SetRespawnTime(5 * MINUTE);
go->Refresh();
go->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_INTERACT_COND);
}
IsMovementActive = false;
}
else
PetAI::MovementInform(type, id);
}
void DoFindNewTubber()
{
std::list<GameObject*> tubbersInRange;
GetGameObjectListWithEntryInGrid(tubbersInRange, me, GO_BLUELEAF_TUBBER, 40.0f);
if (tubbersInRange.empty())
return;
tubbersInRange.sort(DistanceOrder(me));
GameObject* nearestTubber = NULL;
for (std::list<GameObject*>::const_iterator itr = tubbersInRange.begin(); itr != tubbersInRange.end(); ++itr)
{
if (!(*itr)->isSpawned() && (*itr)->HasFlag(GAMEOBJECT_FLAGS, GO_FLAG_INTERACT_COND))
{
nearestTubber = *itr;
break;
}
}
if (!nearestTubber)
return;
TargetTubberGUID = nearestTubber->GetGUID();
// XFurry was wrong...
me->GetMotionMaster()->MovePoint(POINT_TUBBER, nearestTubber->GetPositionX(),
nearestTubber->GetPositionY(),
nearestTubber->GetPositionZ());
IsMovementActive = true;
}
void UpdateAI(uint32 diff)
{
if (!IsMovementActive)
PetAI::UpdateAI(diff);
}
void DoAction(int32 action)
{
if (action == ACTION_FIND_NEW_TUBBER)
DoFindNewTubber();
}
bool IsMovementActive;
uint64 TargetTubberGUID;
};
};
class spell_snufflenose_command : public SpellScriptLoader
{
public:
spell_snufflenose_command() : SpellScriptLoader("spell_snufflenose_command") { }
class spell_snufflenose_commandSpellScript : public SpellScript
{
PrepareSpellScript(spell_snufflenose_commandSpellScript);
void HandleAfterCast()
{
if (Unit* target = ((Player*)GetCaster())->GetSelectedUnit())
if (target->GetEntry() == NPC_SNUFFLENOSE_GOPHER)
if (Creature* ctarget = dynamic_cast<Creature*>(target))
ctarget->AI()->DoAction(ACTION_FIND_NEW_TUBBER);
}
void Register()
{
AfterCast += SpellCastFn(spell_snufflenose_commandSpellScript::HandleAfterCast);
}
};
SpellScript* GetSpellScript() const
{
return new spell_snufflenose_commandSpellScript();
}
};
void AddSC_razorfen_kraul()
{
new spell_snufflenose_command();
new npc_willix();
new npc_snufflenose_gopher();
}