/** * FleeFromNpcWithAuraIfCan() * return boolean Check if the bot can move from a creature having a specific aura, then try to find a proper destination and move towards it * * params: goEntry uint32 the ID of the hostile trap the bot is supposed to move from. It is used to find the radius of the trap * params: spellId uint32 the spell ID of the aura the creature is supposed to have (directly or from triggered spell). It is used to find the radius of the aura * params: pTarget Unit* the creature or gameobject the bot will use to define one of the prefered direction in which to flee * * return true if bot has found a proper destination, false if none was found */ bool PlayerbotClassAI::FleeFromNpcWithAuraIfCan(uint32 NpcEntry, uint32 spellId, Unit* pTarget) { if (!m_bot) return false; if (!NpcEntry) return false; if (!spellId) return false; // Step 1: Get radius from hostile aura spell float radius = 0; SpellEntry const* spellproto = sSpellTemplate.LookupEntry<SpellEntry>(spellId); if (spellproto) radius = GetSpellRadius(sSpellRadiusStore.LookupEntry(spellproto->EffectRadiusIndex[EFFECT_INDEX_0])); if (radius == 0) return false; // Step 2: find a close creature with the right entry: Creature* pCreature = nullptr; MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*m_bot, NpcEntry, false, false, radius, true); MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); Cell::VisitGridObjects(m_bot, searcher, radius); if (!pCreature) return false; // Force to flee on a direction opposite to the position of the creature (fleeing from it, not only avoiding it) return FleeFromPointIfCan(radius, pTarget, pCreature->GetPositionX(), pCreature->GetPositionY(), pCreature->GetPositionZ(), M_PI_F); }
Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 Entry, float MaxSearchRange, bool alive, bool inLoS) { Creature *pCreature = NULL; Hellground::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, Entry, alive, MaxSearchRange, inLoS); Hellground::ObjectLastSearcher<Creature, Hellground::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); Cell::VisitGridObjects(pSource, searcher, MaxSearchRange); return pCreature; }
void hyjalAI::WaypointReached(uint32 waypointId) { if (waypointId == 1 || (waypointId == 0 && me->GetEntry() == THRALL)) { me->MonsterYell(YELL_HURRY, 0, 0); WaitForTeleport = true; TeleportTimer = 20000; if (me->GetEntry() == JAINA) DoCast(me, SPELL_MASS_TELEPORT, false); if (me->GetEntry() == THRALL && DummyGuid) { if (Creature* creature = Unit::GetCreature(*me, DummyGuid)) { hyjalAI* ai = CAST_AI(hyjalAI, creature->AI()); ai->DoMassTeleport = true; ai->MassTeleportTimer = 20000; creature->CastSpell(me, SPELL_MASS_TELEPORT, false); } } //do some talking //all alive guards walk near here CellCoord pair(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); cell.SetNoCreate(); // First get all creatures. std::list<Creature*> creatures; Trinity::AllFriendlyCreaturesInGrid creature_check(me); Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid> creature_searcher(me, creatures, creature_check); TypeContainerVisitor <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { for (std::list<Creature*>::const_iterator itr = creatures.begin(); itr != creatures.end(); ++itr) { if ((*itr) && (*itr)->isAlive() && (*itr) != me && (*itr)->GetEntry() != JAINA) { if (!(*itr)->IsWithinDist(me, 60)) (*itr)->SetWalk(false); float x, y, z; (*itr)->SetDefaultMovementType(IDLE_MOTION_TYPE); (*itr)->GetMotionMaster()->Initialize(); float range = 10; if (me->GetEntry() == THRALL)range = 20; me->GetNearPoint(me, x, y, z, range, 0, me->GetAngle((*itr))); (*itr)->GetMotionMaster()->MovePoint(0, x+irand(-5, 5), y+irand(-5, 5), me->GetPositionZ()); } } } } }
// return closest creature alive in grid, with range from pSource Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange, bool bOnlyAlive/*=true*/, bool bOnlyDead/*=false*/, bool bExcludeSelf/*=false*/) { Creature* pCreature = nullptr; MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, uiEntry, bOnlyAlive, bOnlyDead, fMaxSearchRange, bExcludeSelf); MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); Cell::VisitGridObjects(pSource, searcher, fMaxSearchRange); return pCreature; }
//return closest creature alive in grid, with range from pSource Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) { Creature* pCreature = NULL; MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, uiEntry, true, fMaxSearchRange); MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); Cell::VisitGridObjects(pSource, searcher, fMaxSearchRange); return pCreature; }
Creature* SelectCreatureInGrid(uint32 entry, float range) { Creature* pCreature = NULL; CellPair pair(BlizzLike::ComputeCellPair(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*me, entry, true, range); BlizzLike::CreatureLastSearcher<BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); TypeContainerVisitor<BlizzLike::CreatureLastSearcher<BlizzLike::NearestCreatureEntryWithLiveStateInObjectRangeCheck>, GridTypeMapContainer> creature_searcher(searcher); cell.Visit(pair, creature_searcher,*(me->GetMap())); return pCreature; }
Creature* SearchDawnforge(Player *source, uint32 entry, float range) { Creature* pCreature = NULL; CellPair pair(Oregon::ComputeCellPair(source->GetPositionX(), source->GetPositionY())); Cell cell(pair); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); Oregon::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*source, entry, true, range); Oregon::CreatureLastSearcher<Oregon::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); TypeContainerVisitor<Oregon::CreatureLastSearcher<Oregon::NearestCreatureEntryWithLiveStateInObjectRangeCheck>, GridTypeMapContainer> creature_searcher(searcher); cell.Visit(pair, creature_searcher,*(source->GetMap())); return pCreature; }
//return closest creature alive in grid, with range from pSource Creature* GetClosestCreatureWithEntry(WorldObject* pSource, uint32 uiEntry, float fMaxSearchRange) { Creature* pCreature = NULL; CellPair pair(MaNGOS::ComputeCellPair(pSource->GetPositionX(), pSource->GetPositionY())); Cell cell(pair); cell.data.Part.reserved = ALL_DISTRICT; cell.SetNoCreate(); MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck creature_check(*pSource, uiEntry, true, fMaxSearchRange); MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck> searcher(pCreature, creature_check); TypeContainerVisitor<MaNGOS::CreatureLastSearcher<MaNGOS::NearestCreatureEntryWithLiveStateInObjectRangeCheck>, GridTypeMapContainer> creature_searcher(searcher); CellLock<GridReadGuard> cell_lock(cell, pair); cell_lock->Visit(cell_lock, creature_searcher,*(pSource->GetMap()), *pSource, fMaxSearchRange); return pCreature; }
void hyjalAI::HideNearPos(float x, float y) { CellCoord pair(Trinity::ComputeCellCoord(x, y)); Cell cell(pair); cell.SetNoCreate(); // First get all creatures. std::list<Creature*> creatures; Trinity::AllFriendlyCreaturesInGrid creature_check(me); Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid> creature_searcher(me, creatures, creature_check); TypeContainerVisitor <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { for (std::list<Creature*>::const_iterator itr = creatures.begin(); itr != creatures.end(); ++itr) { (*itr)->SetVisible(false); (*itr)->setFaction(35);//make them friendly so mobs won't attack them } } }
void hyjalAI::DoOverrun(uint32 faction, const uint32 diff) { npc_escortAI::UpdateAI(diff); if (WaitForTeleport) { if (TeleportTimer <= diff) { CellCoord pair(Trinity::ComputeCellCoord(me->GetPositionX(), me->GetPositionY())); Cell cell(pair); cell.SetNoCreate(); std::list<Creature*> creatures; Trinity::AllFriendlyCreaturesInGrid creature_check(me); Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid> creature_searcher(me, creatures, creature_check); TypeContainerVisitor <Trinity::CreatureListSearcher<Trinity::AllFriendlyCreaturesInGrid>, GridTypeMapContainer> creature_visitor(creature_searcher); cell.Visit(pair, creature_visitor, *(me->GetMap()), *me, me->GetGridActivationRange()); if (!creatures.empty()) { for (std::list<Creature*>::const_iterator itr = creatures.begin(); itr != creatures.end(); ++itr) { if ((*itr) && (*itr)->isAlive()) { (*itr)->CastSpell(*itr, SPELL_TELEPORT_VISUAL, true); (*itr)->setFaction(35);//make them friendly so mobs won't attack them (*itr)->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE); } } DoCast(me, SPELL_TELEPORT_VISUAL); bRetreat = true; RetreatTimer = 1000; } WaitForTeleport = false; Teleported = true; }TeleportTimer -= diff; } if (!Teleported) return; Overrun = false;//execute once switch (faction) { case 0://alliance for (uint8 i = 0; i < 92; ++i)//summon fires me->SummonGameObject(FLAMEOBJECT, AllianceFirePos[i][0], AllianceFirePos[i][1], AllianceFirePos[i][2], AllianceFirePos[i][3], AllianceFirePos[i][4], AllianceFirePos[i][5], AllianceFirePos[i][6], AllianceFirePos[i][7], 0); for (uint8 i = 0; i < 25; ++i)//summon 25 ghouls { uint8 r = rand()%4; Creature* unit = me->SummonCreature(GHOUL, AllianceBase[r][0]+irand(-15, 15), AllianceBase[r][1]+irand(-15, 15), AllianceBase[r][2], 0, TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } for (uint8 i = 0; i < 3; ++i)//summon 3 abominations { uint8 r = rand()%4; Creature* unit = me->SummonCreature(ABOMINATION, AllianceBase[r][0]+irand(-15, 15), AllianceBase[r][1]+irand(-15, 15), AllianceBase[r][2], 0, TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } for (uint8 i = 0; i < 5; ++i)//summon 5 gargoyles { Creature* unit = me->SummonCreature(GARGOYLE, AllianceOverrunGargPos[i][0], AllianceOverrunGargPos[i][1], AllianceOverrunGargPos[i][2], AllianceOverrunGargPos[i][3], TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { unit->SetHomePosition(AllianceOverrunGargPos[i][0], AllianceOverrunGargPos[i][1], AllianceOverrunGargPos[i][2], AllianceOverrunGargPos[i][3]); CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } break; case 1://horde for (uint8 i = 0; i < 65; ++i)//summon fires me->SummonGameObject(FLAMEOBJECT, HordeFirePos[i][0], HordeFirePos[i][1], HordeFirePos[i][2], HordeFirePos[i][3], HordeFirePos[i][4], HordeFirePos[i][5], HordeFirePos[i][6], HordeFirePos[i][7], 0); for (uint8 i = 0; i < 26; ++i)//summon infernals { Creature* unit = me->SummonCreature(GIANT_INFERNAL, InfernalSPWP[i][0], InfernalSPWP[i][1], InfernalSPWP[i][2], InfernalSPWP[i][3], TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { unit->SetHomePosition(InfernalSPWP[i][0], InfernalSPWP[i][1], InfernalSPWP[i][2], InfernalSPWP[i][3]); CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } for (uint8 i = 0; i < 25; ++i)//summon 25 ghouls { uint8 r = rand()%4; Creature* unit = me->SummonCreature(GHOUL, HordeBase[r][0]+irand(-15, 15), HordeBase[r][1]+irand(-15, 15), HordeBase[r][2], 0, TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } for (uint8 i = 0; i < 5; ++i)//summon 5 abominations { uint8 r = rand()%4; Creature* unit = me->SummonCreature(ABOMINATION, HordeBase[r][0]+irand(-15, 15), HordeBase[r][1]+irand(-15, 15), HordeBase[r][2], 0, TEMPSUMMON_MANUAL_DESPAWN, 2*60*1000); if (unit) { CAST_AI(hyjal_trashAI, unit->AI())->faction = Faction; CAST_AI(hyjal_trashAI, unit->AI())->IsOverrun = true; CAST_AI(hyjal_trashAI, unit->AI())->OverrunType = i; unit->setActive(true); } } break; } }