Last active
December 17, 2015 01:59
-
-
Save Lillecarl/5532400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct MANGOS_DLL_DECL npc_snowballerAI : public Scripted_NoMovementAI | |
{ | |
npc_snowballerAI(Creature* pCreature) : Scripted_NoMovementAI(pCreature){} | |
typedef UNORDERED_MAP<ObjectGuid, int16> NearbyMap; | |
NearbyMap m_NearbyMap; | |
uint32 m_Timer; | |
void Reset() {} | |
void DamageTaken(Unit* pDealer, uint32& uiDamage) | |
{ | |
m_creature->CastSpell(pDealer, 25686, true); | |
} | |
void UpdateAI(const uint32 diff) | |
{ | |
if (m_creature->GetMapId() != 30) | |
return; | |
const float m_SearchDistance = 35.0f; | |
if (m_Timer >= 3*IN_MILLISECONDS) | |
{ | |
// Reset timer | |
m_Timer = 0; | |
// Set health to max | |
m_creature->SetHealth(m_creature->GetMaxHealth()); | |
// search for players in radius | |
std::list<Player*> targets; | |
MaNGOS::AnyUnfriendlyPlayerInObjectRangeCheck u_check(m_creature, m_SearchDistance); | |
MaNGOS::PlayerListSearcher<MaNGOS::AnyUnfriendlyPlayerInObjectRangeCheck> checker(targets, u_check); | |
Cell::VisitWorldObjects(m_creature, checker, m_SearchDistance); | |
// Loop all nearby enemy players and snowball them as hell! | |
for (std::list<Player*>::iterator itr = targets.begin(); itr != targets.end(); ++itr) | |
{ | |
Player* p = *itr; | |
float dist = m_creature->GetDistance2d(p); | |
float tpdist = m_SearchDistance - dist; | |
float angle = p->GetAngle(-387.188f, -536.61f); | |
float x, y, z; | |
p->GetPosition(x, y, z); | |
x = x + cosf(angle)*tpdist; | |
y = y + sinf(angle)*tpdist; | |
z = p->GetMap()->GetHeight(x, y, MAX_HEIGHT); | |
p->NearTeleportTo(x, y, z, angle, false); | |
} | |
} | |
else | |
m_Timer += diff; | |
} | |
}; | |
CreatureAI* GetAI_npc_snowballer(Creature* pCreature) | |
{ | |
return new npc_snowballerAI(pCreature); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment