Skip to content

Commit

Permalink
PlayAttackEmote with chance reduced
Browse files Browse the repository at this point in the history
  • Loading branch information
ike3 authored and celguar committed Dec 4, 2023
1 parent f416cdc commit 2744d3d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
27 changes: 19 additions & 8 deletions playerbot/PlayerbotAI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3331,14 +3331,7 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget, bool
if (spellSuccess != SPELL_CAST_OK)
return false;

if (urand(0, 100) < sPlayerbotAIConfig.attackEmoteChance * 600 && bot->IsInCombat())
{
vector<uint32> sounds;
sounds.push_back(TEXTEMOTE_OPENFIRE);
sounds.push_back(305);
sounds.push_back(307);
PlaySound(sounds[urand(0, sounds.size() - 1)]);
}
PlayAttackEmote(6);

if(waitForSpell)
{
Expand Down Expand Up @@ -6033,3 +6026,21 @@ void PlayerbotAI::QueueChatResponse(uint8 msgtype, ObjectGuid guid1, ObjectGuid
{
chatReplies.push(ChatQueuedReply(msgtype, guid1.GetCounter(), guid2.GetCounter(), message, chanName, name, time(0) + urand(inCombat ? 10 : 5, inCombat ? 25 : 15)));
}


bool PlayerbotAI::PlayAttackEmote(float chanceMultiplier)
{
auto group = bot->GetGroup();
if (group) chanceMultiplier /= (group->GetMembersCount() - 1);
if ((float)urand(0, 10000) * chanceMultiplier < sPlayerbotAIConfig.attackEmoteChance * 10000.0f && bot->IsInCombat())
{
vector<uint32> sounds;
sounds.push_back(TEXTEMOTE_OPENFIRE);
sounds.push_back(305);
sounds.push_back(307);
PlaySound(sounds[urand(0, sounds.size() - 1)]);
return true;
}

return false;
}
1 change: 1 addition & 0 deletions playerbot/PlayerbotAI.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ class PlayerbotAI : public PlayerbotAIBase
void WaitForSpellCast(Spell *spell);
bool PlaySound(uint32 emote);
bool PlayEmote(uint32 emote);
bool PlayAttackEmote(float chanceDivider);
void Ping(float x, float y);
void Poi(float x, float y, string icon_name = "This way", Player* player = nullptr, uint32 flags = 99, uint32 icon = 6 /* red flag */, uint32 icon_data = 0);
Item * FindPoison() const;
Expand Down
2 changes: 1 addition & 1 deletion playerbot/PlayerbotAIConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ bool PlayerbotAIConfig::Initialize()
randomBotMaxLevelChance = config.GetFloatDefault("AiPlayerbot.RandomBotMaxLevelChance", 0.15f);
randomBotRpgChance = config.GetFloatDefault("AiPlayerbot.RandomBotRpgChance", 0.35f);
usePotionChance = config.GetFloatDefault("AiPlayerbot.UsePotionChance", 1.0f);
attackEmoteChance = config.GetFloatDefault("AiPlayerbot.AttackEmoteChance", 0.01f);
attackEmoteChance = config.GetFloatDefault("AiPlayerbot.AttackEmoteChance", 0.0f);

iterationsPerTick = config.GetIntDefault("AiPlayerbot.IterationsPerTick", 100);

Expand Down
10 changes: 1 addition & 9 deletions playerbot/strategy/actions/AttackAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,7 @@ bool AttackAction::Attack(Player* requester, Unit* target)
// Don't attack target if it is waiting for attack or in stealth
if (!ai->HasStrategy("stealthed", BotState::BOT_STATE_COMBAT) && !isWaitingForAttack)
{
if (urand(0, 100) < sPlayerbotAIConfig.attackEmoteChance * 100)
{
vector<uint32> sounds;
sounds.push_back(TEXTEMOTE_OPENFIRE);
sounds.push_back(305);
sounds.push_back(307);
ai->PlaySound(sounds[urand(0, sounds.size() - 1)]);
}

ai->PlayAttackEmote(1);
return bot->Attack(target, !ai->IsRanged(bot) || (sServerFacade.GetDistance2d(bot, target) < 5.0f));
}
else
Expand Down

0 comments on commit 2744d3d

Please sign in to comment.