*Updated FindCreature and FindGameObject function

--HG--
branch : trunk
This commit is contained in:
Blaymoira
2009-01-25 09:57:40 +01:00
parent fff472c16b
commit 50172faf5a
16 changed files with 70 additions and 75 deletions
+10 -6
View File
@@ -761,21 +761,25 @@ void ScriptedAI::DoTeleportAll(float x, float y, float z, float o)
i_pl->TeleportTo(m_creature->GetMapId(), x, y, z, o, TELE_TO_NOT_LEAVE_COMBAT);
}
Unit* ScriptedAI::FindCreature(uint32 entry, float range)
{
Unit* FindCreature(uint32 entry, float range, Unit* Finder)
{
if(!Finder)
return NULL;
Creature* target = NULL;
Trinity::AllCreaturesOfEntryInRange check(m_creature, entry, range);
Trinity::AllCreaturesOfEntryInRange check(Finder, entry, range);
Trinity::CreatureSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(target, check);
m_creature->VisitNearbyObject(range, searcher);
Finder->VisitNearbyObject(range, searcher);
return target;
}
GameObject* ScriptedAI::FindGameObject(uint32 entry, float range)
GameObject* FindGameObject(uint32 entry, float range, Unit* Finder)
{
if(!Finder)
return NULL;
GameObject* target = NULL;
Trinity::AllGameObjectsWithEntryInGrid go_check(entry);
Trinity::GameObjectSearcher<Trinity::AllGameObjectsWithEntryInGrid> searcher(target, go_check);
m_creature->VisitNearbyGridObject(range, searcher);
Finder->VisitNearbyGridObject(range, searcher);
return target;
}
+6 -6
View File
@@ -25,6 +25,12 @@ private:
Creature *m_creature;
};
//Get a single creature of given entry
Unit* FindCreature(uint32 entry, float range, Unit* Finder);
//Get a single gameobject of given entry
GameObject* FindGameObject(uint32 entry, float range, Unit* Finder);
struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
{
ScriptedAI(Creature* creature) : m_creature(creature), InCombat(false), IsFleeing(false) {}
@@ -153,12 +159,6 @@ struct TRINITY_DLL_DECL ScriptedAI : public CreatureAI
void DoTeleportPlayer(Unit* pUnit, float x, float y, float z, float o);
void DoTeleportAll(float x, float y, float z, float o);
//Get a single creature of given entry
Unit* FindCreature(uint32 entry, float range);
//Get a single gameobject of given entry
GameObject* FindGameObject(uint32 entry, float range);
//Returns friendly unit with the most amount of hp missing from max hp
Unit* DoSelectLowestHpFriendly(float range, uint32 MinHPDiff = 1);
@@ -202,7 +202,7 @@ struct TRINITY_DLL_DECL npc_ruul_snowhoofAI : public npc_escortAI
{
case 0: {
m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
GameObject* Cage = FindGameObject(GO_CAGE, 99);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature);
if(Cage)
Cage->SetGoState(0);
break;}
@@ -232,7 +232,7 @@ struct TRINITY_DLL_DECL npc_ruul_snowhoofAI : public npc_escortAI
if (!IsBeingEscorted)
m_creature->setFaction(1602);
GameObject* Cage = FindGameObject(GO_CAGE, 99);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature);
if(Cage)
Cage->SetGoState(1);
}
@@ -241,7 +241,7 @@ struct TRINITY_DLL_DECL mob_ethereal_beaconAI : public ScriptedAI
{
DoCast(m_creature->getVictim(),SPELL_ARCANE_BOLT);
ArcaneBolt_Timer = 2000 + rand()%2500;
Unit *shaffar = FindCreature(ENTRY_SHAFFAR, 100);
Unit *shaffar = FindCreature(ENTRY_SHAFFAR, 100, m_creature);
if(!shaffar || shaffar->isDead())
{
m_creature->SetVisibility(VISIBILITY_OFF);
@@ -427,7 +427,7 @@ struct TRINITY_DLL_DECL npc_wizzlecrank_shredderAI : public npc_escortAI
case 10: DoScriptText(SAY_PROGRESS_3, m_creature, player);
m_creature->AddUnitMovementFlag(MOVEMENTFLAG_WALK_MODE); break;
case 20:{
Unit* Mercenary = FindCreature(MOB_MERCENARY, 99);
Unit* Mercenary = FindCreature(MOB_MERCENARY, 99, m_creature);
if(Mercenary)
{
DoScriptText(SAY_MERCENARY_4, Mercenary);
@@ -165,7 +165,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
case 0:
{
m_creature->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
GameObject* Cage = FindGameObject(GO_CAGE, 99);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature);
if(Cage)
Cage->SetGoState(0);
DoScriptText(SAY_START, m_creature, player);
@@ -200,7 +200,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
case 33:
m_creature->SetOrientation(5.858011);
DoScriptText(SAY_END2, m_creature, player);
Unit* CaptainHelios = FindCreature(NPC_CAPTAIN_HELIOS, 50);
Unit* CaptainHelios = FindCreature(NPC_CAPTAIN_HELIOS, 50, m_creature);
if(CaptainHelios)
DoScriptText(SAY_CAPTAIN_ANSWER, CaptainHelios, player);
break;
@@ -214,7 +214,7 @@ struct TRINITY_DLL_DECL npc_ranger_lilathaAI : public npc_escortAI
if (!IsBeingEscorted)
m_creature->setFaction(1602);
GameObject* Cage = FindGameObject(GO_CAGE, 99);
GameObject* Cage = FindGameObject(GO_CAGE, 20, m_creature);
if(Cage)
Cage->SetGoState(1);
}
@@ -294,7 +294,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
void Aggro(Unit* who)
{
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100))
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature))
((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerEngaged(who);
if (m_creature->IsNonMeleeSpellCasted(false))
m_creature->InterruptNonMeleeSpells(true);
@@ -303,7 +303,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
void JustDied(Unit* Killer)
{
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100))
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature))
((boss_kelidan_the_breakerAI*)Kelidan->AI())->ChannelerDied(Killer);
}
@@ -314,7 +314,7 @@ struct TRINITY_DLL_DECL mob_shadowmoon_channelerAI : public ScriptedAI
if(check_Timer < diff)
{
if (!m_creature->IsNonMeleeSpellCasted(false))
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100))
if(Creature *Kelidan = (Creature *)FindCreature(ENTRY_KELIDAN, 100, m_creature))
{
uint64 channeler = ((boss_kelidan_the_breakerAI*)Kelidan->AI())->GetChanneled(m_creature);
if(Unit *channeled = Unit::GetUnit(*m_creature, channeler))
@@ -284,7 +284,7 @@ struct TRINITY_DLL_DECL boss_vazruden_the_heraldAI : public ScriptedAI
{
Creature *Nazan = (Creature*)Unit::GetUnit(*m_creature, NazanGUID);
Creature *Vazruden = (Creature*)Unit::GetUnit(*m_creature, VazrudenGUID);
if(Nazan || (Nazan = (Creature *)FindCreature(ENTRY_NAZAN, 5000)))
if(Nazan || (Nazan = (Creature *)FindCreature(ENTRY_NAZAN, 5000, m_creature)))
{
Nazan->SetLootRecipient(NULL);
Nazan->SetVisibility(VISIBILITY_OFF);
@@ -292,7 +292,7 @@ struct TRINITY_DLL_DECL boss_vazruden_the_heraldAI : public ScriptedAI
Nazan->RemoveCorpse();
NazanGUID = 0;
}
if(Vazruden || (Vazruden = (Creature *)FindCreature(ENTRY_VAZRUDEN, 5000)))
if(Vazruden || (Vazruden = (Creature *)FindCreature(ENTRY_VAZRUDEN, 5000, m_creature)))
{
Vazruden->SetLootRecipient(NULL);
Vazruden->SetVisibility(VISIBILITY_OFF);
@@ -424,7 +424,7 @@ struct TRINITY_DLL_DECL mob_hellfire_sentryAI : public ScriptedAI
void JustDied(Unit* who)
{
if(Creature *herald = (Creature *)FindCreature(ENTRY_VAZRUDEN_HERALD,150))
if(Creature *herald = (Creature *)FindCreature(ENTRY_VAZRUDEN_HERALD,150, m_creature))
((boss_vazruden_the_heraldAI *)herald->AI())->SentryDownBy(who);
}
@@ -174,7 +174,7 @@ struct TRINITY_DLL_DECL npc_greengill_slaveAI : public ScriptedAI
((Player*)plr)->KilledMonster(25086, m_creature->GetGUID());
}
DoCast(m_creature, ENRAGE);
Unit* Myrmidon = FindCreature(DM, 70);
Unit* Myrmidon = FindCreature(DM, 70, m_creature);
if(Myrmidon)
{
m_creature->AddThreat(Myrmidon, 100000.0f);
@@ -946,11 +946,11 @@ struct TRINITY_DLL_DECL npc_bessyAI : public npc_escortAI
((Player*)player)->GroupEventHappens(Q_ALMABTRIEB, m_creature);
Completed = true;
}
{Unit* Thadell = FindCreature(N_THADELL, 30);
{Unit* Thadell = FindCreature(N_THADELL, 30, m_creature);
if(Thadell)
DoScriptText(SAY_THADELL_1, m_creature);}break;
case 13:
{Unit* Thadell = FindCreature(N_THADELL, 30);
{Unit* Thadell = FindCreature(N_THADELL, 30, m_creature);
if(Thadell)
DoScriptText(SAY_THADELL_2, m_creature, player);}break;
}
@@ -165,15 +165,6 @@ CreatureAI* GetAI_mob_mature_netherwing_drake(Creature *_creature)
# mob_enslaved_netherwing_drake
####*/
Creature* SelectCreatureInGrid(Unit* pUnit, uint32 entry, float range)
{
Creature* target = NULL;
Trinity::AllCreaturesOfEntryInRange check(pUnit, entry, range);
Trinity::CreatureSearcher<Trinity::AllCreaturesOfEntryInRange> searcher(target, check);
pUnit->VisitNearbyObject(range, searcher);
return target;
}
#define FACTION_DEFAULT 62
#define FACTION_FRIENDLY 1840 // Not sure if this is correct, it was taken off of Mordenai.
@@ -221,7 +212,7 @@ struct TRINITY_DLL_DECL mob_enslaved_netherwing_drakeAI : public ScriptedAI
m_creature->setFaction(FACTION_FRIENDLY);
DoCast(caster, SPELL_FORCE_OF_NELTHARAKU, true);
Creature* Dragonmaw = SelectCreatureInGrid(m_creature, CREATURE_DRAGONMAW_SUBJUGATOR, 50);
Unit* Dragonmaw = FindCreature(CREATURE_DRAGONMAW_SUBJUGATOR, 50, m_creature);
if(Dragonmaw)
{
@@ -281,7 +272,7 @@ struct TRINITY_DLL_DECL mob_enslaved_netherwing_drakeAI : public ScriptedAI
float dx, dy, dz;
Creature* EscapeDummy = SelectCreatureInGrid(m_creature, CREATURE_ESCAPE_DUMMY, 30);
Unit* EscapeDummy = FindCreature(CREATURE_ESCAPE_DUMMY, 30, m_creature);
if(EscapeDummy)
EscapeDummy->GetPosition(dx, dy, dz);
else
@@ -637,7 +628,7 @@ bool QuestAccept_npc_karynaku(Player* player, Creature* creature, Quest const* q
nodes.resize(2);
nodes[0] = 161; // From Karynaku
nodes[1] = 162; // To Mordenai
error_log("SD2: Player %s started quest 10870 which has disabled taxi node, need to be fixed in core", player->GetName());
error_log("TSCR: Player %s started quest 10870 which has disabled taxi node, need to be fixed in core", player->GetName());
//player->ActivateTaxiPathTo(nodes, 20811);
}
@@ -780,7 +771,7 @@ struct TRINITY_DLL_DECL npc_overlord_morghorAI : public ScriptedAI
return 6000; break;
case 27:
{
Unit* Yarzill = FindCreature(C_YARZILL, 50);
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature);
if (Yarzill)
Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, PlayerGUID);
return 500; }break;
@@ -792,19 +783,19 @@ struct TRINITY_DLL_DECL npc_overlord_morghorAI : public ScriptedAI
return 1000; break;
case 29:
{
Unit* Yarzill = FindCreature(C_YARZILL, 50);
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature);
if(Yarzill)
DoScriptText(YARZILL_THE_MERC_SAY, Yarzill, plr);
return 5000; }break;
case 30:
{
Unit* Yarzill = FindCreature(C_YARZILL, 50);
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature);
if (Yarzill)
Yarzill->SetUInt64Value(UNIT_FIELD_TARGET, 0);
return 5000; }break;
case 31:
{
Unit* Yarzill = FindCreature(C_YARZILL, 50);
Unit* Yarzill = FindCreature(C_YARZILL, 50, m_creature);
if (Yarzill)
Yarzill->CastSpell(plr, 41540, true);
return 1000;}break;
@@ -1128,10 +1119,10 @@ struct WaveData
static WaveData WavesInfo[]=
{
{9, 0, 22075, 10000, 7000, -1000371},//Illidari Soldier
{2, 9, 22074, 10000, 7000, -1000372},//Illidari Mind Breaker
{4, 11, 19797, 10000, 7000, -1000373},//Illidari Highlord
{1, 15, 22076, 10000, 7000, -1000374} //Torloth The Magnificent
{9, 0, 22075, 10000, 7000, -1000371}, //Illidari Soldier
{2, 9, 22074, 10000, 7000, -1000372}, //Illidari Mind Breaker
{4, 11, 19797, 10000, 7000, -1000373}, //Illidari Highlord
{1, 15, 22076, 10000, 7000, -1000374} //Torloth The Magnificent
};
struct SpawnSpells
@@ -1141,15 +1132,15 @@ struct SpawnSpells
static SpawnSpells SpawnCast[]=
{
{10000, 15000, 35871},// Illidari Soldier Cast - Spellbreaker
{10000, 10000, 38985},// Illidari Mind Breake Cast - Focused Bursts
{35000, 35000, 22884},// Illidari Mind Breake Cast - Psychic Scream
{20000, 20000, 17194},// Illidari Mind Breake Cast - Mind Blast
{8000, 15000, 38010},// Illidari Highlord Cast - Curse of Flames
{12000, 20000, 16102},// Illidari Highlord Cast - Flamestrike
{10000, 15000, 15284},// Torloth the Magnificent Cast - Cleave
{18000, 20000, 39082},// Torloth the Magnificent Cast - Shadowfury
{25000, 28000, 33961}// Torloth the Magnificent Cast - Spell Reflection
{10000, 15000, 35871}, // Illidari Soldier Cast - Spellbreaker
{10000, 10000, 38985}, // Illidari Mind Breake Cast - Focused Bursts
{35000, 35000, 22884}, // Illidari Mind Breake Cast - Psychic Scream
{20000, 20000, 17194}, // Illidari Mind Breake Cast - Mind Blast
{8000, 15000, 38010}, // Illidari Highlord Cast - Curse of Flames
{12000, 20000, 16102}, // Illidari Highlord Cast - Flamestrike
{10000, 15000, 15284}, // Torloth the Magnificent Cast - Cleave
{18000, 20000, 39082}, // Torloth the Magnificent Cast - Shadowfury
{25000, 28000, 33961} // Torloth the Magnificent Cast - Spell Reflection
};
/*######
@@ -1618,13 +1609,13 @@ bool GOQuestAccept_GO_crystal_prison(Player* plr, GameObject* go, Quest const* q
{
if(quest->GetQuestId() == QUEST_BATTLE_OF_THE_CRIMSON_WATCH )
{
Creature* Illidan = SelectCreatureInGrid(plr, 22083, 50);
Unit* Illidan = FindCreature(22083, 50, plr);
if(Illidan && !(((npc_lord_illidan_stormrageAI*)Illidan->AI())->EventStarted))
if(Illidan && !(((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->EventStarted))
{
((npc_lord_illidan_stormrageAI*)Illidan->AI())->PlayerGUID = plr->GetGUID();
((npc_lord_illidan_stormrageAI*)Illidan->AI())->LiveCount = 0;
((npc_lord_illidan_stormrageAI*)Illidan->AI())->EventStarted=true;
((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->PlayerGUID = plr->GetGUID();
((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->LiveCount = 0;
((npc_lord_illidan_stormrageAI*)((Creature*)Illidan)->AI())->EventStarted=true;
}
}
return true;
@@ -453,13 +453,13 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
Step = 0;
m_creature->setFaction(1194);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature);
if(Creepjack)
{
((Creature*)Creepjack)->AI()->EnterEvadeMode();
Creepjack->setFaction(1194);
}
Unit* Malone = FindCreature(NPC_MALONE, 20);
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature);
if(Malone)
{
((Creature*)Malone)->AI()->EnterEvadeMode();
@@ -474,10 +474,10 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
switch(Step)
{
case 0:{ m_creature->SetInFront(player);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature);
if(Creepjack)
Creepjack->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
Unit* Malone = FindCreature(NPC_MALONE, 20);
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature);
if(Malone)
Malone->SetUInt32Value(UNIT_FIELD_BYTES_1, 0);
m_creature->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_GOSSIP); }return 2000;
@@ -508,14 +508,14 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
m_creature->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
if(player)
{
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature);
if(Creepjack)
{
Creepjack->Attack(player, true);
Creepjack->setFaction(14);
Creepjack->GetMotionMaster()->MoveChase(player);
}
Unit* Malone = FindCreature(NPC_MALONE, 20);
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature);
if(Malone)
{
Malone->Attack(player, true);
@@ -531,13 +531,13 @@ struct TRINITY_DLL_DECL npc_dirty_larryAI : public ScriptedAI
if((m_creature->GetHealth()*100)/m_creature->GetMaxHealth() < 1 && !Done)
{
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20);
Unit* Creepjack = FindCreature(NPC_CREEPJACK, 20, m_creature);
if(Creepjack)
{
((Creature*)Creepjack)->AI()->EnterEvadeMode();
Creepjack->setFaction(1194);
}
Unit* Malone = FindCreature(NPC_MALONE, 20);
Unit* Malone = FindCreature(NPC_MALONE, 20, m_creature);
if(Malone)
{
((Creature*)Malone)->AI()->EnterEvadeMode();
@@ -130,7 +130,7 @@ struct TRINITY_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
((Player*)player)->GroupEventHappens(QUEST_ESCORTING, m_creature);break;
case 14: DoScriptText(SAY_THANKS, m_creature, player);break;
case 15: {
Unit* Rane = FindCreature(NPC_RANE, 20);
Unit* Rane = FindCreature(NPC_RANE, 20, m_creature);
if(Rane)
DoScriptText(SAY_RANE, Rane);
break;}
@@ -138,7 +138,7 @@ struct TRINITY_DLL_DECL npc_deathstalker_erlandAI : public npc_escortAI
case 17: DoScriptText(SAY_MOVE_QUINN, m_creature); break;
case 24: DoScriptText(SAY_GREETINGS, m_creature);break;
case 25: {
Unit* Quinn = FindCreature(NPC_QUINN, 20);
Unit* Quinn = FindCreature(NPC_QUINN, 20, m_creature);
if(Quinn)
DoScriptText(SAY_QUINN, Quinn);
break;}
@@ -405,7 +405,7 @@ struct TRINITY_DLL_DECL npc_OOX17AI : public npc_escortAI
m_creature->SummonCreature(SPAWN_SECOND_2, -7515.07, -4797.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000);
m_creature->SummonCreature(SPAWN_SECOND_2, -7518.07, -4792.50, 9.35, 6.22, TEMPSUMMON_TIMED_DESPAWN_OUT_OF_COMBAT, 25000);
DoScriptText(SAY_CHICKEN_AMB, m_creature);
{Unit* scoff = FindCreature(SPAWN_SECOND_2, 30);
{Unit* scoff = FindCreature(SPAWN_SECOND_2, 30, m_creature);
if(scoff)
DoScriptText(SAY_SCOFF, scoff);}break;
break;
@@ -387,7 +387,7 @@ struct TRINITY_DLL_DECL npc_isla_starmaneAI : public npc_escortAI
{
case 0:
{
GameObject* Cage = FindGameObject(GO_CAGE, 99);
GameObject* Cage = FindGameObject(GO_CAGE, 10, m_creature);
if(Cage)
Cage->SetGoState(0);
}break;