Skip to content

Commit

Permalink
NPCBots: Fix Dark Ranger and Necromancer getting too many minions / n…
Browse files Browse the repository at this point in the history
…ot aborting summon at max minions
  • Loading branch information
trickerer committed Oct 6, 2024
1 parent 1d53be1 commit 9bd6f97
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/server/game/AI/NpcBots/bot_dark_ranger_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,10 @@ class dark_ranger_bot : public CreatureScript
u = *itr;
}
}
//try 2: by minimal duration
//try 2: by minimal duration (if expiring already)
if (!u)
{
uint32 minduration = 0;
uint32 minduration = static_cast<uint32>((*_minions.begin())->GetAI()->GetData(BOTPETAI_MISC_DURATION_MAX) * 3 / 4);
for (Summons::const_iterator itr = _minions.begin(); itr != _minions.end(); ++itr)
{
if ((*itr)->GetAI()->GetData(BOTPETAI_MISC_DURATION) > minduration)
Expand All @@ -447,6 +447,8 @@ class dark_ranger_bot : public CreatureScript

if (!u)
return;

u->ToTempSummon()->UnSummon();
}

//addition: change unit's modelid
Expand Down
6 changes: 4 additions & 2 deletions src/server/game/AI/NpcBots/bot_necromancer_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,10 +577,10 @@ class necromancer_bot : public CreatureScript
u = *itr;
}
}
//try 2: by minimal duration
//try 2: by minimal duration (if expiring already)
if (!u)
{
uint32 minduration = 0;
uint32 minduration = static_cast<uint32>((*_minions.begin())->GetAI()->GetData(BOTPETAI_MISC_DURATION_MAX) * 3 / 4);
for (Summons::const_iterator itr = _minions.begin(); itr != _minions.end(); ++itr)
{
if ((*itr)->GetAI()->GetData(BOTPETAI_MISC_DURATION) > minduration)
Expand All @@ -593,6 +593,8 @@ class necromancer_bot : public CreatureScript

if (!u)
return;

u->ToTempSummon()->UnSummon();
}

Position pos = from->GetPosition();
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/NpcBots/botcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ enum BotCommonValues
BOTAI_MISC_PET_AVAILABLE_11,
BOTAI_MISC_WEAPON_SPEC,
BOTPETAI_MISC_DURATION,
BOTPETAI_MISC_DURATION_MAX,
BOTPETAI_MISC_MAXLEVEL,
BOTPETAI_MISC_FIXEDLEVEL,
BOTPETAI_MISC_CARRY,
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/NpcBots/bpet_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ uint32 bot_pet_ai::GetData(uint32 data) const
{
case BOTPETAI_MISC_DURATION:
return 0;
case BOTPETAI_MISC_DURATION_MAX:
return 0;
case BOTPETAI_MISC_MAXLEVEL:
return petOwner->GetLevel();
case BOTPETAI_MISC_FIXEDLEVEL:
Expand Down
9 changes: 8 additions & 1 deletion src/server/game/AI/NpcBots/bpet_dark_ranger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class dark_ranger_pet_bot : public CreatureScript

void UpdateAI(uint32 diff) override
{
if ((liveTimer += diff) >= MINION_DURATION * (IAmFree() ? 5u : 1u))
if ((liveTimer += diff) >= _getMaxDuration())
{
canUpdate = false;
me->setDeathState(JUST_DIED);
Expand Down Expand Up @@ -159,6 +159,8 @@ class dark_ranger_pet_bot : public CreatureScript
{
case BOTPETAI_MISC_DURATION:
return liveTimer;
case BOTPETAI_MISC_DURATION_MAX:
return _getMaxDuration();
case BOTPETAI_MISC_MAXLEVEL:
return maxlevel;
default:
Expand Down Expand Up @@ -201,6 +203,11 @@ class dark_ranger_pet_bot : public CreatureScript
}

private:
uint32 _getMaxDuration() const
{
return MINION_DURATION * (IAmFree() ? 5u : 1u);
}

uint32 liveTimer;
uint8 maxlevel;
};
Expand Down
9 changes: 8 additions & 1 deletion src/server/game/AI/NpcBots/bpet_necromancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class necromancer_pet_bot : public CreatureScript

void UpdateAI(uint32 diff) override
{
if ((liveTimer += diff) >= MINION_DURATION * (IAmFree() ? 5u : 1u))
if ((liveTimer += diff) >= _getMaxDuration())
{
canUpdate = false;
me->setDeathState(JUST_DIED);
Expand Down Expand Up @@ -143,6 +143,8 @@ class necromancer_pet_bot : public CreatureScript
{
case BOTPETAI_MISC_DURATION:
return liveTimer;
case BOTPETAI_MISC_DURATION_MAX:
return _getMaxDuration();
case BOTPETAI_MISC_MAXLEVEL:
return maxlevel;
default:
Expand Down Expand Up @@ -180,6 +182,11 @@ class necromancer_pet_bot : public CreatureScript
}

private:
uint32 _getMaxDuration() const
{
return MINION_DURATION * (IAmFree() ? 5u : 1u);
}

uint32 liveTimer;
uint8 maxlevel;
};
Expand Down

0 comments on commit 9bd6f97

Please sign in to comment.