Skip to content

Commit

Permalink
Merge branch 'AzerothCore' of https://github.com/zaicopx/AzerothCore-…
Browse files Browse the repository at this point in the history
…wotlk-with-NPCBots into AzerothCore

# Conflicts:
#	src/server/apps/worldserver/worldserver.conf.dist
  • Loading branch information
zaicopx committed Aug 13, 2023
2 parents 0729baf + 4699f04 commit b45a3fc
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--
ALTER TABLE `creature_template_npcbot_appearance` MODIFY COLUMN `name*` char(100) DEFAULT 'unk' COMMENT 'unused', CHARSET=utf8mb4;
22 changes: 17 additions & 5 deletions src/server/apps/worldserver/worldserver.conf.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4226,13 +4226,16 @@ NpcBot.Botgiver.FilterRaces = 0
NpcBot.BaseFollowDistance = 30

#
# NpcBot.XpReduction
# Description: XP percent penalty for each bot used starting with second.
# Example: 3 bots, xp reduction is 20: ((3-1)*20) = 40%, 60% exp gained only.
# NpcBot.XpReduction.Amount
# NpcBot.XpReduction.StartingNumber
# Description: XP percent penalty for each bot used starting with <StartingNumber>.
# Example: 3 bots, reduction is 20, start is 2: ((3-(2-1))*20) = 40%, 60% exp gained.
# Note: Maximum overall xp reduction is 90%.
# Default: 0
# Default: 0 - (NpcBot.XpReduction.Amount)
# 2 - (NpcBot.XpReduction.StartingNumber)

NpcBot.XpReduction = 20
NpcBot.XpReduction.Amount = 0
NpcBot.XpReduction.StartingNumber = 2

#
# NpcBot.HealTargetIconMask
Expand Down Expand Up @@ -4617,6 +4620,15 @@ NpcBot.WanderingBots.Continents.Maps = 0,1,530,571

NpcBot.WanderingBots.BG.Enable = 0

#
# NpcBot.WanderingBots.BG.CapLevel
# Description: Enforce BG bot maximum level limit set by Expansion and MaxPlayerLevel
# config paramter values.
# Default: 0 - (Disabled)
# 1 - (Enable)

NpcBot.WanderingBots.BG.CapLevel = 0

#
# NpcBot.WanderingBots.BG.TargetTeamPlayersCount.<BGTYPE>
# Description: Target BG players count per team to aim for when generating BG bots.
Expand Down
30 changes: 16 additions & 14 deletions src/server/game/AI/NpcBots/bot_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ bot_ai::bot_ai(Creature* creature) : CreatureAI(creature)
regenTimer = 0;
m_botSpellInfo = nullptr;
waitTimer = 0;
_moveBehindTimer = 0;
itemsAutouseTimer = 0;
_usableItemSlotsMask = 0;
evadeDelayTimer = 0;
Expand Down Expand Up @@ -1128,7 +1129,7 @@ void bot_ai::BotMovement(BotMovementType type, Position const* pos, Unit* target
{
case BOT_MOVE_CHASE:
ASSERT(target);
mover->GetMotionMaster()->MoveChase(target, {}, ChaseAngle(target->GetRelativeAngle(me), float(M_PI / 8.0)));
mover->GetMotionMaster()->MoveChase(target, {}, ChaseAngle(target->GetRelativeAngle(me), float(target->IsPlayer() ? M_PI * 2.0 : M_PI / 8.0)));
break;
case BOT_MOVE_POINT:
mover->GetMotionMaster()->Add(new PointMovementGenerator<Creature>(1, pos->m_positionX, pos->m_positionY, pos->m_positionZ, speed, 0.0f, nullptr, generatePath));
Expand Down Expand Up @@ -2222,14 +2223,9 @@ void bot_ai::_listAuras(Player const* player, Unit const* unit) const

//debug
botstring << "\n_lastWMOAreaId: " << uint32(_lastWMOAreaId);

//debug
botstring << "\nGCD: " << uint32(GC_Timer);

//debug
//botstring << "\nPotion CD: " << uint32(_potionTimer);
//botstring << "\ncurrent Engage timer: " << GetEngageTimer();

//debug
//for (uint32 i = 0; i != 148; ++i)
//{
// float val = me->GetFloatValue(i);
Expand Down Expand Up @@ -3663,6 +3659,10 @@ bool bot_ai::CanBotAttack(Unit const* target, int8 byspell, bool secondary) cons
case 32541: case 32542: case 32543: case 32545: case 32546: case 32547: case 32666: case 32667: // training dummy
case 7668: case 7669: case 7670: case 7671: // Blasted Lands servants
return false;
case 21416: case 21709: case 21710: case 21711: // Shadowmoon Valley Broken element corruptors
if (target->HasAuraTypeWithMiscvalue(SPELL_AURA_SCHOOL_IMMUNITY, 127))
return false;
break;
default:
break;
}
Expand Down Expand Up @@ -5430,15 +5430,15 @@ void bot_ai::CheckAttackState()
//Move behind current target if needed (avoid cleaves and dodges/parries, also rogues/ferals)
void bot_ai::MoveBehind(Unit const* target) const
{
if (HasBotCommandState(BOT_COMMAND_MASK_UNMOVING) || HasRole(BOT_ROLE_RANGED) || JumpingOrFalling() ||
if (_moveBehindTimer > lastdiff || HasBotCommandState(BOT_COMMAND_MASK_UNMOVING) || HasRole(BOT_ROLE_RANGED) || JumpingOrFalling() ||
/*(me->isMoving() && target->GetTypeId() != TYPEID_PLAYER) ||*/
me->GetVehicle() || (IsTank() && target->GetVictim() == me) || CCed(me, true) ||
!target->IsWithinCombatRange(me, ATTACK_DISTANCE) || !target->HasInArc(float(M_PI), me))
return;

bool targetMe = target->GetVictim() == me;
bool cced = CCed(target);
bool isPlayer = target->GetTypeId() == TYPEID_PLAYER;
const bool targetMe = target->GetVictim() == me;
const bool cced = CCed(target);
const bool isPlayer = target->GetTypeId() == TYPEID_PLAYER;

if ((_botclass == BOT_CLASS_ROGUE || GetBotStance() == DRUID_CAT_FORM) ? (!targetMe || cced || isPlayer) : (!targetMe && (!cced || isPlayer)))
{
Expand All @@ -5451,8 +5451,7 @@ void bot_ai::MoveBehind(Unit const* target) const
return;

BotMovement(BOT_MOVE_POINT, &position);
//me->GetMotionMaster()->MovePoint(me->GetMapId(), x, y, z);
const_cast<bot_ai*>(this)->waitTimer = 500;
const_cast<bot_ai*>(this)->_moveBehindTimer = urand(1000, (_botclass == BOT_CLASS_ROGUE || GetBotStance() == DRUID_CAT_FORM) ? 2000 : 4000);
}
}
//MOUNT SUPPORT
Expand Down Expand Up @@ -13893,6 +13892,8 @@ void bot_ai::DefaultInit()
if (IsWanderer())
{
_travel_node_cur = ASSERT_NOTNULL(BotDataMgr::GetClosestWanderNode(me));
if (firstspawn && BotMgr::IsWanderingWorldBot(me))
StartPotionTimer();
}

SetStats(true); // Class passives included
Expand Down Expand Up @@ -17453,6 +17454,7 @@ void bot_ai::CommonTimers(uint32 diff)
if (GC_Timer > diff) GC_Timer -= diff;
if (checkAurasTimer > diff) checkAurasTimer -= diff;
if (waitTimer > diff) waitTimer -= diff;
if (_moveBehindTimer > diff) _moveBehindTimer -= diff;
if (itemsAutouseTimer > diff) itemsAutouseTimer -= diff;
if (evadeDelayTimer > diff) evadeDelayTimer -= diff;
if (roleTimer > diff) roleTimer -= diff;
Expand Down Expand Up @@ -19208,7 +19210,7 @@ bool bot_ai::IsShootingWand(Unit const* u) const

void bot_ai::StartPotionTimer()
{
_potionTimer = POTION_CD;
_potionTimer = POTION_CD * (BotMgr::IsWanderingWorldBot(me) ? std::max<uint32>(uint32(Rand()) >> 3, 1u) : 1u);
}

bool bot_ai::CanBlock() const
Expand Down
1 change: 1 addition & 0 deletions src/server/game/AI/NpcBots/bot_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -672,6 +672,7 @@ class bot_ai : public CreatureAI
//timers
uint32 _reviveTimer, _powersTimer, _chaseTimer, _engageTimer, _potionTimer;
uint32 lastdiff, checkAurasTimer, checkMasterTimer, roleTimer, ordersTimer, regenTimer, _updateTimerMedium, _updateTimerEx1;
uint32 _moveBehindTimer;
uint32 _wmoAreaUpdateTimer;
uint32 waitTimer;
uint32 itemsAutouseTimer;
Expand Down
2 changes: 1 addition & 1 deletion src/server/game/AI/NpcBots/botcommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ enum rbac
RBAC_PERM_COMMAND_NPCBOT_VEHICLE_EJECT = SEC_PLAYER,
RBAC_PERM_COMMAND_NPCBOT_DUMP_LOAD = SEC_ADMINISTRATOR,
RBAC_PERM_COMMAND_NPCBOT_DUMP_WRITE = SEC_ADMINISTRATOR,
RBAC_PERM_COMMAND_NPCBOT_SPAWNED = SEC_ADMINISTRATOR,
RBAC_PERM_COMMAND_NPCBOT_SPAWNED = SEC_GAMEMASTER,
RBAC_PERM_COMMAND_NPCBOT_COMMAND_MISC = SEC_PLAYER,
RBAC_PERM_COMMAND_NPCBOT_CREATENEW = SEC_ADMINISTRATOR,
RBAC_PERM_COMMAND_NPCBOT_SEND = SEC_PLAYER
Expand Down
26 changes: 22 additions & 4 deletions src/server/game/AI/NpcBots/botdatamgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "SpellMgr.h"
#include "StringConvert.h"
#include "Tokenize.h"
#include "World.h"
#include "WorldDatabase.h"
/*
Npc Bot Data Manager by Trickerer (onlysuffering@gmail.com)
Expand Down Expand Up @@ -304,16 +305,33 @@ struct WanderingBotsGenerator
bot_template.SubName = "";
bot_template.speed_run = BotMgr::GetBotWandererSpeedMod();
bot_template.KillCredit[0] = orig_entry;

uint32 max_level = DEFAULT_MAX_LEVEL;
if (bracketEntry && BotMgr::IsBotLevelCappedByConfigBG())
{
uint32 max_expansion_level;
switch (sWorld->getIntConfig(CONFIG_EXPANSION))
{
case EXPANSION_CLASSIC: max_expansion_level = 60; break;
case EXPANSION_THE_BURNING_CRUSADE: max_expansion_level = 70; break;
case EXPANSION_WRATH_OF_THE_LICH_KING: max_expansion_level = 70; break;
default: max_expansion_level = DEFAULT_MAX_LEVEL; break;
}

max_level = std::min<uint32>(sWorld->getIntConfig(CONFIG_MAX_PLAYER_LEVEL), max_level);
max_level = std::min<uint32>(max_expansion_level, max_level);
}

if (bracketEntry)
{
//force level range for bgs
bot_template.minlevel = std::min<uint32>(bracketEntry->minLevel, DEFAULT_MAX_LEVEL);
bot_template.maxlevel = std::min<uint32>(bracketEntry->maxLevel, DEFAULT_MAX_LEVEL);
bot_template.minlevel = std::min<uint32>(bracketEntry->minLevel, max_level);
bot_template.maxlevel = std::min<uint32>(bracketEntry->maxLevel, max_level);
}
else
{
bot_template.minlevel = std::min<uint32>(std::max<uint32>(desired_bracket * 10, spawnLoc->GetLevels().first), DEFAULT_MAX_LEVEL);
bot_template.maxlevel = std::min<uint32>(std::min<uint32>(desired_bracket * 10 + 9, spawnLoc->GetLevels().second), DEFAULT_MAX_LEVEL);
bot_template.minlevel = std::min<uint32>(std::max<uint32>(desired_bracket * 10, spawnLoc->GetLevels().first), max_level);
bot_template.maxlevel = std::min<uint32>(std::min<uint32>(desired_bracket * 10 + 9, spawnLoc->GetLevels().second), max_level);
bot_template.flags_extra &= ~(CREATURE_FLAG_EXTRA_NO_XP);
}

Expand Down
18 changes: 15 additions & 3 deletions src/server/game/AI/NpcBots/botmgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static std::list<BotMgr::delayed_teleport_callback_type> delayed_bot_teleports;
uint8 _basefollowdist;
uint8 _maxNpcBots;
uint8 _maxClassNpcBots;
uint8 _xpReductionNpcBots;
uint8 _xpReductionAmount;
uint8 _xpReductionStartingNumber;
uint8 _healTargetIconFlags;
uint8 _tankingTargetIconFlags;
uint8 _offTankingTargetIconFlags;
Expand Down Expand Up @@ -115,6 +116,7 @@ bool _enableclass_cryptlord;
bool _enrageOnDismiss;
bool _botStatLimits;
bool _enableWanderingBotsBG;
bool _enableConfigLevelCapBG;
bool _bothk_enable;
bool _bothk_message_enable;
bool _bothk_achievements_enable;
Expand Down Expand Up @@ -281,7 +283,8 @@ void BotMgr::LoadConfig(bool reload)
_maxClassNpcBots = sConfigMgr->GetIntDefault("NpcBot.MaxBotsPerClass", 1);
_filterRaces = sConfigMgr->GetBoolDefault("NpcBot.Botgiver.FilterRaces", false);
_basefollowdist = sConfigMgr->GetIntDefault("NpcBot.BaseFollowDistance", 30);
_xpReductionNpcBots = sConfigMgr->GetIntDefault("NpcBot.XpReduction", 0);
_xpReductionAmount = sConfigMgr->GetIntDefault("NpcBot.XpReduction.Amount", 0);
_xpReductionStartingNumber = sConfigMgr->GetIntDefault("NpcBot.XpReduction.StartingNumber", 2);
_healTargetIconFlags = sConfigMgr->GetIntDefault("NpcBot.HealTargetIconMask", 0);
_tankingTargetIconFlags = sConfigMgr->GetIntDefault("NpcBot.TankTargetIconMask", 0);
_offTankingTargetIconFlags = sConfigMgr->GetIntDefault("NpcBot.OffTankTargetIconMask", 0);
Expand Down Expand Up @@ -367,6 +370,7 @@ void BotMgr::LoadConfig(bool reload)
_botStatLimits_crit = sConfigMgr->GetFloatDefault("NpcBot.Stats.Limits.Crit", 95.0f);
_desiredWanderingBotsCount = sConfigMgr->GetIntDefault("NpcBot.WanderingBots.Continents.Count", 0);
_enableWanderingBotsBG = sConfigMgr->GetBoolDefault("NpcBot.WanderingBots.BG.Enable", false);
_enableConfigLevelCapBG = sConfigMgr->GetBoolDefault("NpcBot.WanderingBots.BG.CapLevel", false);
_targetBGPlayersPerTeamCount_AV = sConfigMgr->GetIntDefault("NpcBot.WanderingBots.BG.TargetTeamPlayersCount.AV", 0);
_targetBGPlayersPerTeamCount_WS = sConfigMgr->GetIntDefault("NpcBot.WanderingBots.BG.TargetTeamPlayersCount.WS", 8);
_targetBGPlayersPerTeamCount_AB = sConfigMgr->GetIntDefault("NpcBot.WanderingBots.BG.TargetTeamPlayersCount.AB", 12);
Expand Down Expand Up @@ -706,6 +710,10 @@ bool BotMgr::IsBotGenerationEnabledBGs()
{
return _enableWanderingBotsBG;
}
bool BotMgr::IsBotLevelCappedByConfigBG()
{
return _enableConfigLevelCapBG;
}
bool BotMgr::IsBotGenerationEnabledWorldMapId(uint32 mapId)
{
return std::find(std::cbegin(_enabled_wander_node_maps), std::cend(_enabled_wander_node_maps), mapId) != std::cend(_enabled_wander_node_maps);
Expand Down Expand Up @@ -805,7 +813,11 @@ float BotMgr::GetBotStatLimitCrit()

uint8 BotMgr::GetNpcBotXpReduction()
{
return _xpReductionNpcBots;
return _xpReductionAmount;
}
uint8 BotMgr::GetNpcBotXpReductionStartingNumber()
{
return _xpReductionStartingNumber;
}

uint8 BotMgr::GetMaxNpcBots()
Expand Down
2 changes: 2 additions & 0 deletions src/server/game/AI/NpcBots/botmgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class AC_GAME_API BotMgr
static bool IsFoodInterruptedByMovement();
static bool FilterRaces();
static bool IsBotGenerationEnabledBGs();
static bool IsBotLevelCappedByConfigBG();
static bool IsBotGenerationEnabledWorldMapId(uint32 mapId);
static bool IsBotHKEnabled();
static bool IsBotHKMessageEnabled();
Expand Down Expand Up @@ -187,6 +188,7 @@ class AC_GAME_API BotMgr
uint32 GetAllNpcBotsClassMask() const;
static uint8 GetMaxNpcBots();
static uint8 GetNpcBotXpReduction();
static uint8 GetNpcBotXpReductionStartingNumber();
static int32 GetBotInfoPacketsLimit();
static bool LimitBots(Map const* map);
static bool CanBotParryWhileCasting(Creature const* bot);
Expand Down
13 changes: 6 additions & 7 deletions src/server/game/AI/NpcBots/bpet_ai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ bot_pet_ai::bot_pet_ai(Creature* creature) : CreatureAI(creature)
m_botCommandState = BOT_COMMAND_FOLLOW;
regenTimer = 0;
waitTimer = 0;
_moveBehindTimer = 0;
indoorsTimer = 0;
outdoorsTimer = 0;
GC_Timer = 0;
Expand Down Expand Up @@ -1693,18 +1694,15 @@ void bot_pet_ai::CheckAttackState()

void bot_pet_ai::MoveBehind(Unit const* target) const
{
if (HasBotCommandState(BOT_COMMAND_MASK_UNMOVING)) return;
if (!IsPetMelee() || CCed(me, true)) return;
if (JumpingOrFalling()) return;
if (_moveBehindTimer > lastdiff || HasBotCommandState(BOT_COMMAND_MASK_UNMOVING) || !IsPetMelee() || CCed(me, true) || JumpingOrFalling())
return;

if (target->GetVictim() != me && !CCed(target) &&
target->IsWithinCombatRange(me, ATTACK_DISTANCE) &&
target->HasInArc(float(M_PI), me))
if (target->GetVictim() != me && !CCed(target) && target->IsWithinCombatRange(me, ATTACK_DISTANCE) && target->HasInArc(float(M_PI), me))
{
float x,y,z;
target->GetNearPoint(me, x, y, z, 0.f, me->GetCombatReach(), me->GetAbsoluteAngle(target));
me->GetMotionMaster()->MovePoint(me->GetMapId(), x, y, z);
waitTimer = 500;
const_cast<bot_pet_ai*>(this)->_moveBehindTimer = urand(1000, 4000);
}
}
bool bot_pet_ai::_canRegenerate() const
Expand Down Expand Up @@ -2574,6 +2572,7 @@ void bot_pet_ai::CommonTimers(uint32 diff)
if (GC_Timer > diff) GC_Timer -= diff;
if (checkAurasTimer > diff) checkAurasTimer -= diff;
if (waitTimer > diff) waitTimer -= diff;
if (_moveBehindTimer > diff) _moveBehindTimer -= diff;

if (_updateTimerMedium > diff) _updateTimerMedium -= diff;
if (_updateTimerEx1 > diff) _updateTimerEx1 -= diff;
Expand Down
3 changes: 2 additions & 1 deletion src/server/game/AI/NpcBots/bpet_ai.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,8 @@ class bot_pet_ai : public CreatureAI

//timers
uint32 lastdiff, checkAurasTimer, regenTimer, _updateTimerMedium, _updateTimerEx1;
mutable uint32 waitTimer;
uint32 waitTimer;
uint32 _moveBehindTimer;
uint32 indoorsTimer;
uint32 outdoorsTimer;

Expand Down
12 changes: 6 additions & 6 deletions src/server/game/Entities/Player/KillRewarder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,13 @@ void KillRewarder::_RewardXP(Player* player, float rate)
AddPct(xp, (*i)->GetAmount());

//npcbot 4.2.2.1. Apply NpcBot XP reduction
if (player->GetNpcBotsCount() > 1)
uint8 bots_count = player->GetNpcBotsCount();
uint8 xp_reduction = BotMgr::GetNpcBotXpReduction();
uint8 xp_reduction_start = BotMgr::GetNpcBotXpReductionStartingNumber();
if (xp_reduction_start > 0 && xp_reduction > 0 && bots_count >= xp_reduction_start)
{
if (uint8 xp_reduction = BotMgr::GetNpcBotXpReduction())
{
uint32 ratePct = std::max<int32>(100 - ((player->GetNpcBotsCount() - 1) * xp_reduction), 10);
xp = xp * ratePct / 100;
}
uint32 ratePct = std::max<int32>(100 - ((bots_count - (xp_reduction_start - 1)) * xp_reduction), 10);
xp = xp * ratePct / 100;
}
//end npcbot

Expand Down
10 changes: 9 additions & 1 deletion src/server/game/Handlers/QueryHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,21 @@ void WorldSession::SendNameQueryOpcode(ObjectGuid guid)
CreatureTemplate const* creatureTemplate = sObjectMgr->GetCreatureTemplate(creatureId);
if (creatureTemplate && creatureTemplate->IsNPCBot())
{
std::string creatureName = creatureTemplate->Name;
if (CreatureLocale const* creatureInfo = sObjectMgr->GetCreatureLocale(creatureId))
{
uint32 loc = GetSessionDbLocaleIndex();
if (creatureInfo->Name.size() > loc && !creatureInfo->Name[loc].empty() && Utf8FitTo(creatureInfo->Name[loc], {}))
creatureName = creatureInfo->Name[loc];
}

NpcBotExtras const* extData = ASSERT_NOTNULL(BotDataMgr::SelectNpcBotExtras(creatureId));
NpcBotAppearanceData const* appData = BotDataMgr::SelectNpcBotAppearance(creatureId);

WorldPacket bpdata(SMSG_NAME_QUERY_RESPONSE, (8+1+1+1+1+1+10));
bpdata << guid.WriteAsPacked();
bpdata << uint8(0);
bpdata << creatureTemplate->Name;
bpdata << creatureName;
bpdata << uint8(0);
bpdata << uint8(BotMgr::GetBotPlayerRace(extData->bclass, extData->race));
bpdata << uint8(appData ? appData->gender : uint8(GENDER_MALE));
Expand Down

0 comments on commit b45a3fc

Please sign in to comment.