mod-playerbots/src/Ai/Base/Actions/GuildCreateActions.cpp
kadeshar 063eabc16e
Spam guild fix (#2341)
<!--
Thank you for contributing to mod-playerbots, please make sure that
you...
1. Submit your PR to the test-staging branch, not master.
2. Read the guidelines below before submitting.
3. Don't delete parts of this template.

DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND
PREDICTABILITY over behavioral realism.

Every action and decision executes PER BOT AND PER TRIGGER. Small
increases in logic complexity scale
poorly across thousands of bots and negatively affect all. We prioritize
a stable system over a smarter
one. Bots don't need to behave perfectly; believable behavior is the
goal, not human simulation.
Default behavior must be cheap in processing; expensive behavior must be
opt-in.

Before submitting, make sure your changes aligns with these principles.
-->

## Pull Request Description
<!-- Describe what this change does and why it is needed -->

Removed messages in failed attempts of buying tabard.
Related with: #1885 

## How to Test the Changes
<!--
- Step-by-step instructions to test the change.
- Any required setup (e.g. multiple players, number of bots, specific
configuration).
- Expected behavior and how to verify it.
-->

Invite bot with guild strategy. Spam should not appear.

## Impact Assessment
<!-- As a generic test, before and after measure of pmon (playerbot pmon
tick) can help you here. -->
- Does this change increase per-bot/per-tick processing or risk scaling
poorly with thousands of bots?
    - - [x] No, not at all
    - - [ ] Minimal impact (**explain below**)
    - - [ ] Moderate impact (**explain below**)



- Does this change modify default bot behavior?
    - - [x] No
    - - [ ] Yes (**explain why**)



- Does this change add new decision branches or increase maintenance
complexity?
    - - [x] No
    - - [ ] Yes (**explain below**)



## AI Assistance
<!--
AI assistance is allowed, but all submitted code must be fully
understood, reviewed, and owned by the contributor.
We expect contributors to be honest about what they do and do not
understand.
-->
Was AI assistance used while working on this change?
- - [x] No
- - [ ] Yes (**explain below**)
<!--
If yes, please specify:
- Purpose of usage (e.g. brainstorming, refactoring, documentation, code
generation).
- Which parts of the change were influenced or generated, and whether it
was thoroughly reviewed.
-->



<!--
TRANSLATIONS:
Anything new that the bots say in chat must be in a translatable format.
This is done using GetBotTextOrDefault,
which you can search for in the codebase to find examples. Your code
needs to have English as the default fallback,
while the full translations need to be in an SQL update file. The
languages in the file are the nine language
options supported by AzerothCore: English, Korean, French, German,
Chinese, Taiwanese, Spanish, Spanish Mexico, and
Russian. See
data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as
an example of a translation SQL
update, whose content are called within the codebase at
src/strategy/actions/FishingAction.cpp
-->

## Final Checklist

- - [x] Stability is not compromised.
- - [x] Performance impact is understood, tested, and acceptable.
- - [x] Added logic complexity is justified and explained.
- - [x] Any new bot dialogue lines are translated.
- - [x] Documentation updated if needed (Conf comments, WiKi commands).

## Notes for Reviewers
<!-- Anything else that's helpful to review or test your pull request.
-->
2026-05-02 12:19:51 -07:00

333 lines
9.5 KiB
C++

/*
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
* and/or modify it under version 3 of the License, or (at your option), any later version.
*/
#include "GuildCreateActions.h"
#include "ArenaTeam.h"
#include "BudgetValues.h"
#include "Event.h"
#include "GuildMgr.h"
#include "Playerbots.h"
#include "RandomPlayerbotFactory.h"
#include "ServerFacade.h"
#include "SharedDefines.h"
bool BuyPetitionAction::Execute(Event /*event*/)
{
GuidVector vendors = botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest npcs")->Get();
for (GuidVector::iterator i = vendors.begin(); i != vendors.end(); ++i)
{
ObjectGuid vendorguid = *i;
Creature* pCreature = bot->GetNPCIfCanInteractWith(vendorguid, UNIT_NPC_FLAG_PETITIONER);
if (!pCreature)
continue;
std::string const guildName = RandomPlayerbotFactory::CreateRandomGuildName();
if (guildName.empty())
continue;
WorldPacket data(CMSG_PETITION_BUY);
data << pCreature->GetGUID();
data << uint32(0);
data << uint64(0);
data << guildName.c_str();
data << std::string("");
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
data << uint16(0);
data << uint32(0);
data << uint32(0);
data << uint32(0);
for (uint8 i = 0; i < 10; ++i)
data << std::string("");
data << uint32(0); // index
data << uint32(0);
bot->GetSession()->HandlePetitionBuyOpcode(data);
return true;
}
return false;
}
bool BuyPetitionAction::isUseful() { return canBuyPetition(bot); };
bool BuyPetitionAction::canBuyPetition(Player* bot)
{
if (bot->GetGuildId())
return false;
if (bot->GetGuildIdInvited())
return false;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(bot);
AiObjectContext* context = botAI->GetAiObjectContext();
if (AI_VALUE2(uint32, "item count", "Hitem:5863:"))
return false;
if (botAI->GetGuilderType() == GuilderType::SOLO)
return false;
if (botAI->GetGrouperType() == GrouperType::SOLO)
return false;
if (!botAI->HasStrategy("guild", BOT_STATE_NON_COMBAT))
return false;
uint32 cost = 1000; // GUILD_CHARTER_COST;
if (AI_VALUE2(uint32, "free money for", uint32(NeedMoneyFor::guild)) < cost)
return false;
return true;
}
bool PetitionOfferAction::Execute(Event event)
{
std::vector<Item*> petitions = AI_VALUE2(std::vector<Item*>, "inventory items", chat->FormatQItem(5863));
if (petitions.empty())
return false;
ObjectGuid guid = event.getObject();
Player* master = GetMaster();
if (!master)
{
if (!guid)
guid = bot->GetTarget();
}
else
{
if (!guid)
guid = master->GetTarget();
}
if (!guid)
return false;
Player* player = ObjectAccessor::FindPlayer(guid);
if (!player)
return false;
WorldPacket data(CMSG_OFFER_PETITION);
data << uint32(0);
data << petitions.front()->GetGUID();
data << guid;
QueryResult result =
CharacterDatabase.Query("SELECT playerguid FROM petition_sign WHERE player_account = {} AND petitionguid = {}",
player->GetSession()->GetAccountId(), petitions.front()->GetGUID().GetCounter());
if (result)
{
return false;
}
bot->GetSession()->HandleOfferPetitionOpcode(data);
result = CharacterDatabase.Query("SELECT playerguid FROM petition_sign WHERE petitionguid = {}",
petitions.front()->GetGUID().GetCounter());
uint8 signs = result ? (uint8)result->GetRowCount() : 0;
context->GetValue<uint8>("petition signs")->Set(signs);
return true;
}
bool PetitionOfferAction::isUseful() { return !bot->GetGuildId(); }
bool PetitionOfferNearbyAction::Execute(Event /*event*/)
{
uint32 found = 0;
GuidVector nearGuids = botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest friendly players")->Get();
for (auto& i : nearGuids)
{
Player* player = ObjectAccessor::FindPlayer(i);
if (!player)
continue;
if (player->GetGuildId())
continue;
if (player->GetGuildIdInvited())
continue;
PlayerbotAI* botAI = GET_PLAYERBOT_AI(player);
if (botAI)
{
/*
if (botAI->GetGrouperType() == SOLO && !botAI->HasRealPlayerMaster()) //Do not invite solo players.
continue;
*/
if (botAI->HasActivePlayerMaster()) // Do not invite alts of active players.
continue;
}
else
{
if (!sPlayerbotAIConfig.randomBotGroupNearby)
return false;
}
if (ServerFacade::instance().GetDistance2d(bot, player) > sPlayerbotAIConfig.sightDistance)
continue;
// Parse rpg target to quest action.
WorldPacket p(CMSG_QUESTGIVER_ACCEPT_QUEST);
p << i;
p.rpos(0);
if (PetitionOfferAction::Execute(Event("petition offer nearby", p)))
found++;
}
return found > 0;
}
bool PetitionOfferNearbyAction::isUseful()
{
return !bot->GetGuildId() && AI_VALUE2(uint32, "item count", chat->FormatQItem(5863)) &&
AI_VALUE(uint8, "petition signs") < sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS);
}
bool PetitionTurnInAction::Execute(Event /*event*/)
{
GuidVector vendors = botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest npcs")->Get();
std::vector<Item*> petitions = AI_VALUE2(std::vector<Item*>, "inventory items", chat->FormatQItem(5863));
if (petitions.empty())
return false;
for (GuidVector::iterator i = vendors.begin(); i != vendors.end(); ++i)
{
ObjectGuid vendorguid = *i;
Creature* pCreature = bot->GetNPCIfCanInteractWith(vendorguid, UNIT_NPC_FLAG_PETITIONER);
if (!pCreature)
continue;
WorldPacket data(CMSG_TURN_IN_PETITION, 8);
Item* petition = petitions.front();
if (!petition)
return false;
data << petition->GetGUID();
bot->GetSession()->HandleTurnInPetitionOpcode(data);
if (bot->GetGuildId())
{
// Ensure that bot has at least 10g for HandleSetEmblem can be managed core side
// (EMBLEM_PRICE = 10 * GOLD in core)
static constexpr uint32 REQUIRED = 10 * GOLD;
uint32 have = bot->GetMoney(); // actual money earned by bot in copper
if (have < REQUIRED)
{
bot->ModifyMoney(int32(REQUIRED - have)); // add only the missing amount to bot to reach 10g
}
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
uint32 st, cl, br, bc, bg;
bg = urand(0, 51);
bc = urand(0, 17);
cl = urand(0, 17);
br = urand(0, 7);
st = urand(0, 180);
EmblemInfo emblemInfo(st, cl, br, bc, bg);
guild->HandleSetEmblem(emblemInfo); // official core handling
// LANG_GUILD_VETERAN -> can invite
guild->HandleSetRankInfo(2, GR_RIGHT_GCHATLISTEN | GR_RIGHT_GCHATSPEAK | GR_RIGHT_INVITE);
}
return true;
}
TravelTarget* oldTarget = context->GetValue<TravelTarget*>("travel target")->Get();
// Select a new target to travel to.
TravelTarget newTarget = TravelTarget(botAI);
bool foundTarget = SetNpcFlagTarget(&newTarget, {UNIT_NPC_FLAG_PETITIONER});
if (!foundTarget || !newTarget.isActive())
return false;
newTarget.setRadius(INTERACTION_DISTANCE);
setNewTarget(&newTarget, oldTarget);
return true;
}
bool PetitionTurnInAction::isUseful()
{
bool inCity = false;
if (AreaTableEntry const* zone = sAreaTableStore.LookupEntry(bot->GetZoneId()))
{
if (zone->flags & AREA_FLAG_CAPITAL)
inCity = true;
}
return inCity && !bot->GetGuildId() && AI_VALUE2(uint32, "item count", chat->FormatQItem(5863)) &&
AI_VALUE(uint8, "petition signs") >= sWorld->getIntConfig(CONFIG_MIN_PETITION_SIGNS) &&
!context->GetValue<TravelTarget*>("travel target")->Get()->isTraveling();
}
bool BuyTabardAction::Execute(Event /*event*/)
{
bool canBuy = botAI->DoSpecificAction("buy", Event("buy tabard", "Hitem:5976:"), true);
if (canBuy && AI_VALUE2(uint32, "item count", chat->FormatQItem(5976)))
return true;
TravelTarget* oldTarget = context->GetValue<TravelTarget*>("travel target")->Get();
// Select a new target to travel to.
TravelTarget newTarget = TravelTarget(botAI);
bool foundTarget = SetNpcFlagTarget(&newTarget, {UNIT_NPC_FLAG_TABARDDESIGNER}, "Tabard Vendor", {5976});
if (!foundTarget || !newTarget.isActive())
return false;
newTarget.setRadius(INTERACTION_DISTANCE);
setNewTarget(&newTarget, oldTarget);
return true;
};
bool BuyTabardAction::isUseful()
{
bool inCity = false;
if (AreaTableEntry const* zone = sAreaTableStore.LookupEntry(bot->GetZoneId()))
{
if (zone->flags & AREA_FLAG_CAPITAL)
inCity = true;
}
return inCity && bot->GetGuildId() && !AI_VALUE2(uint32, "item count", chat->FormatQItem(5976)) &&
AI_VALUE2(uint32, "free money for", uint32(NeedMoneyFor::guild)) >= 10000 &&
!context->GetValue<TravelTarget*>("travel target")->Get()->isTraveling();
}