Created
February 7, 2024 03:35
-
-
Save AnchyDev/2ee183bfe929f2fac5991fdd07f810c3 to your computer and use it in GitHub Desktop.
Buffs a melee creature when there is 10 or more players nearby.
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
#include "WorldBosses.h" | |
#include <GridNotifiers.h> | |
CreatureAI* WorldBossesScript::GetAI(Creature* creature) const | |
{ | |
return new WorldBossesAIScript(creature); | |
} | |
void WorldBossesScript::WorldBossesAIScript::UpdateAI(uint32 diff) | |
{ | |
events.Update(diff); | |
switch (events.ExecuteEvent()) | |
{ | |
case WORLD_BOSSES_EVENT_CHECK_PLAYERS_IN_RANGE: | |
{ | |
BuffWorldBoss(IsValidPlayersInRange()); | |
events.RescheduleEvent(WORLD_BOSSES_EVENT_CHECK_PLAYERS_IN_RANGE, 10s); | |
break; | |
} | |
} | |
if (!me->IsInCombat()) | |
{ | |
return; | |
} | |
DoMeleeAttackIfReady(); | |
} | |
bool WorldBossesScript::WorldBossesAIScript::IsValidPlayersInRange() | |
{ | |
std::list<Player*> targets; | |
Acore::AnyPlayerInObjectRangeCheck check(this->me, this->me->GetVisibilityRange() + VISIBILITY_COMPENSATION, false); | |
Acore::PlayerListSearcherWithSharedVision<Acore::AnyPlayerInObjectRangeCheck> searcher(this->me, targets, check); | |
Cell::VisitWorldObjects(this->me, searcher, this->me->GetVisibilityRange()); | |
uint32 count = 0; | |
for (std::list<Player*>::const_iterator iter = targets.begin(); iter != targets.end(); ++iter) | |
{ | |
Player* player = (*iter); | |
if (!player) | |
{ | |
continue; | |
} | |
if (player->GetLevel() < 80) | |
{ | |
continue; | |
} | |
count++; | |
} | |
return count >= 10; // Adjust this to change the amount of players needed nearby at level 80. | |
} | |
void WorldBossesScript::WorldBossesAIScript::BuffWorldBoss(bool apply) | |
{ | |
// Buff boss | |
if (apply && !buffed) | |
{ | |
me->SetLevel(80, true); | |
// Add tenacity aura | |
auto aura = me->AddAura(58549, me); | |
aura->SetStackAmount(20); | |
me->SetObjectScale(2); | |
me->Yell("Buffing", Language::LANG_UNIVERSAL); | |
buffed = true; | |
} | |
// Debuff boss | |
if (!apply && buffed) | |
{ | |
auto cProto = me->GetCreatureTemplate(); | |
me->SetLevel(cProto->minlevel); | |
// Remove tenacity aura | |
me->RemoveAura(58549); | |
me->SetObjectScale(1); | |
me->Yell("Debuffing", Language::LANG_UNIVERSAL); | |
buffed = false; | |
} | |
} | |
void SC_AddWorldBossesScripts() | |
{ | |
new WorldBossesScript(); | |
} |
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
#ifndef MODULE_WORLD_BOSSES_H | |
#define MODULE_WORLD_BOSSES_H | |
#include "ScriptMgr.h" | |
#include "ScriptedCreature.h" | |
class WorldBossesScript : public CreatureScript | |
{ | |
public: | |
WorldBossesScript() : CreatureScript("WorldBossesScript") { } | |
private: | |
CreatureAI* GetAI(Creature* /*creature*/) const; | |
class WorldBossesAIScript : public ScriptedAI | |
{ | |
public: | |
enum WorldBossesAIEvents | |
{ | |
WORLD_BOSSES_EVENT_CHECK_PLAYERS_IN_RANGE = 1 | |
}; | |
WorldBossesAIScript(Creature* creature) : ScriptedAI(creature), buffed(false) | |
{ | |
events.Reset(); | |
events.ScheduleEvent(WORLD_BOSSES_EVENT_CHECK_PLAYERS_IN_RANGE, 10s); | |
} | |
void UpdateAI(uint32 diff) override; | |
bool IsValidPlayersInRange(); | |
void BuffWorldBoss(bool /*apply*/); | |
private: | |
bool buffed; | |
}; | |
}; | |
#endif // MODULE_WORLD_BOSSES_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment