Skip to content

Commit

Permalink
NPCBots: Adjust timer between ownership expiration checks
Browse files Browse the repository at this point in the history
  • Loading branch information
trickerer committed Oct 6, 2024
1 parent a4f0c55 commit f33c6a6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,7 @@ void bot_ai::ResetBotAI(uint8 resetType)
if (resetType == BOTAI_RESET_INIT || resetType == BOTAI_RESET_LOGOUT)
{
NpcBotData const* npcBotData = BotDataMgr::SelectNpcBotData(me->GetEntry());
_checkOwershipTimer = (BotMgr::GetOwnershipExpireTime() && npcBotData->owner) ?
((resetType == BOTAI_RESET_INIT || BotMgr::GetOwnershipExpireMode() == BOT_OWNERSHIP_EXPIRE_HIRE) ? 1000 : CalculateOwnershipCheckTime()) : 0;
_checkOwershipTimer = (BotMgr::GetOwnershipExpireTime() && npcBotData->owner) ? (resetType == BOTAI_RESET_INIT) ? 1000 : CalculateOwnershipCheckTime() : 0;
if (resetType == BOTAI_RESET_INIT)
homepos.Relocate(me);
else //if (resetType == BOTAI_RESET_LOGOUT)
Expand Down Expand Up @@ -15214,7 +15213,14 @@ void bot_ai::FindMaster()

uint32 bot_ai::CalculateOwnershipCheckTime()
{
return std::min<uint32>(BotMgr::GetOwnershipExpireTime(), urand(58 * MINUTE * IN_MILLISECONDS, 62 * MINUTE * IN_MILLISECONDS));
NpcBotData const* npcBotData = BotDataMgr::SelectNpcBotData(me->GetEntry());
if (!npcBotData->owner)
return 0;

if (!IAmFree() || BotMgr::GetOwnershipExpireMode() == BOT_OWNERSHIP_EXPIRE_OFFLINE)
return static_cast<uint32>(std::min<uint32>(BotMgr::GetOwnershipExpireTime(), urand(3 * MINUTE, 7 * MINUTE)) * IN_MILLISECONDS);

return static_cast<uint32>(std::max<time_t>(time_t(npcBotData->hire_time + BotMgr::GetOwnershipExpireTime() + 1) - time(0), 5) * IN_MILLISECONDS);
}

bool bot_ai::IAmFree() const
Expand Down

0 comments on commit f33c6a6

Please sign in to comment.