#include "StdAfx.h" #include "Setup.h" /************************************************************************/ /* Raid_Karazhan.cpp Script */ /************************************************************************/ // Midnight #define CN_MIDNIGHT 16151 #define CN_ATTUMEN 15550 class MidnightAI : public CreatureAIScript { public: ADD_CREATURE_FACTORY_FUNCTION(MidnightAI); MidnightAI(Creature* pCreature) : CreatureAIScript(pCreature) { attumen = NULL; m_phase = 1; } void OnCombatStart(Unit* mTarget) { RegisterAIUpdateEvent(_unit->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME)); _unit->GetAIInterface()->setOutOfCombatRange(100000); } void OnCombatStop(Unit *mTarget) { _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL); _unit->GetAIInterface()->SetAIState(STATE_IDLE); RemoveAIUpdateEvent(); } void OnTargetDied(Unit* mTarget) { if (_unit->GetHealthPct() > 0) { int RandomSpeach; sRand.randInt(1000); RandomSpeach=rand()%2; switch (RandomSpeach) { case 0: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Well done Midnight !"); _unit->PlaySoundToSet(9173); break; } } void OnDied(Unit * mKiller) { RemoveAIUpdateEvent(); } void AIUpdate() { switch(m_phase) { case 1: { PhaseOne(); }break; case 2: { PhaseTwo(); }break; case 3: { }break; default: { m_phase = 1; }; }; } void PhaseOne() { if(_unit->GetHealthPct() <= 91) { // spawn Attumen // MapScriptInterface::SpawnCreature not yet implemented :( // attumen = _unit->GetMapMgr()->GetInterface()->SpawnCreature(CN_ATTUMEN, // _unit->GetPositionX(), _unit->GetPositionY(), // _unit->GetPositionZ(), _unit->GetOrientation(), // true, false, 0, 0); attumen = _unit->GetMapMgr()->CreateCreature(); attumen->spawnid = 0; attumen->m_spawn = 0; attumen->Load(objmgr.GetCreatureProto(CN_ATTUMEN), _unit->GetPositionX(), _unit->GetPositionY(), _unit->GetPositionZ()); attumen->SetMapId(_unit->GetMapId()); attumen->SetInstanceID(_unit->GetInstanceID()); attumen->PushToWorld(_unit->GetMapMgr()); m_phase = 2; } } void PhaseTwo() { if(_unit->GetHealthPct() <= 25) { _unit->PlaySoundToSet(9168); // change Model & despawn Midnight attumen->SetUInt32Value(UNIT_FIELD_DISPLAYID , 16040); Creature *midnight = ((Creature*) _unit); midnight->Despawn(0, 0); m_phase = 3; } } protected: uint32 m_phase; Creature *attumen; }; // Attumen #define CLEAVE 31345 #define CHARGE 35754 class AttumenAI : public CreatureAIScript { public: ADD_CREATURE_FACTORY_FUNCTION(AttumenAI); AttumenAI(Creature* pCreature) : CreatureAIScript(pCreature) { m_phase = 1; m_spellcheck = new bool[2]; spells = new SP_AI_Spell[2]; for(int i=0;i<2;i++) { m_spellcheck[i] = false; } spells[0].info = sSpellStore.LookupEntry(CLEAVE); spells[0].targettype = TARGET_ATTACKING; spells[0].instant = true; spells[0].perctrigger = 11.0f; spells[0].attackstoptimer = 1000; spells[1].info = sSpellStore.LookupEntry(CHARGE); spells[1].targettype = TARGET_ATTACKING; // Needs checking spells[1].instant = true; spells[1].perctrigger = 6.0f; spells[1].attackstoptimer = 1000; } void OnCombatStart(Unit* mTarget) { int RandomSpeach; sRand.randInt(1000); RandomSpeach=rand()%3; switch (RandomSpeach) { case 0: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Cowards, Wretches !"); _unit->PlaySoundToSet(9167); break; case 1: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Who dares attack the stead of the Huntsman !"); _unit->PlaySoundToSet(9298); break; case 2: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Perhaps you would test yourself against a more formidable opponent..."); _unit->PlaySoundToSet(9299); break; } RegisterAIUpdateEvent(_unit->GetUInt32Value(UNIT_FIELD_BASEATTACKTIME)); } void OnCombatStop(Unit *mTarget) { if (_unit->GetHealthPct() > 0) { int RandomSpeach; sRand.randInt(1000); RandomSpeach=rand()%2; switch (RandomSpeach) { case 0: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "I always knew someday i would become ... The hunted"); _unit->PlaySoundToSet(9165); break; } _unit->GetAIInterface()->setCurrentAgent(AGENT_NULL); _unit->GetAIInterface()->SetAIState(STATE_IDLE); RemoveAIUpdateEvent(); } void OnTargetDied(Unit* mTarget) { if (_unit->GetHealthPct() > 0) { int RandomSpeach; sRand.randInt(1000); RandomSpeach=rand()%2; switch (RandomSpeach) { case 0: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "It was inevetable..."); _unit->PlaySoundToSet(9169); break; case 1: _unit->SendChatMessage(CHAT_MSG_MONSTER_YELL, LANG_UNIVERSAL, "Another trophy to add to my collection"); _unit->PlaySoundToSet(9300); break; } } void AIUpdate() { switch(m_phase) { case 1: { PhaseOne(); }break; case 2: { }break; default: { m_phase = 1; }; }; float val = sRand.rand(100.0f); SpellCast(val); } void PhaseOne() { if(_unit->GetUInt32Value(UNIT_FIELD_DISPLAYID) == 16040) { _unit->SetUInt32Value(UNIT_FIELD_HEALTH, _unit->GetUInt32Value(UNIT_FIELD_MAXHEALTH)); m_phase = 2; } else if(_unit->GetHealthPct() <= 25) { _unit->SetUInt32Value(UNIT_FIELD_MINDAMAGE, 15000); _unit->SetUInt32Value(UNIT_FIELD_MAXDAMAGE, 20000); m_phase = 2; } } void SpellCast(float val) { if(m_spellcheck && spells && _unit->GetCurrentSpell() == NULL && _unit->GetAIInterface()->GetNextTarget()) { float comulativeperc = 0; Unit *target = NULL; for(int i=0;iGetAIInterface()->GetNextTarget(); switch(spells[i].targettype) { case TARGET_SELF: case TARGET_VARIOUS: _unit->CastSpell(_unit, spells[i].info, spells[i].instant); break; case TARGET_ATTACKING: _unit->CastSpell(target, spells[i].info, spells[i].instant); break; case TARGET_DESTINATION: _unit->CastSpellAoF(target->GetPositionX(),target->GetPositionY(),target->GetPositionZ(), spells[i].info, spells[i].instant); break; } m_spellcheck[i] = false; return; } if(val > comulativeperc && val <= (comulativeperc + spells[i].perctrigger)) { _unit->setAttackTimer(spells[i].attackstoptimer, false); m_spellcheck[i] = true; } comulativeperc += spells[i].perctrigger; } } } protected: bool *m_spellcheck; SP_AI_Spell *spells; int m_phase; }; void SetupKarazhan(ScriptMgr * mgr) mgr->register_creature_script(CN_MIDNIGHT, &MidnightAI::Create); mgr->register_creature_script(CN_ATTUMEN, &AttumenAI::Create);