Files
mod-playerbots/src/Ai/Base/Actions/GuildBankAction.cpp
Keleborn 441f9f7552 Warnings PR 1: Event warnings and headers (#2106)
# Pull Request

This is the first in a series of PRs intended to eliminate warnings in
the module. The design intent is to eliminate the calling event when not
needed in the body of the function. Based off of SmashingQuasars work.

---

## How to Test the Changes

- Step-by-step instructions to test the change
- Any required setup (e.g. multiple players, bots, specific
configuration)
- Expected behavior and how to verify it

## Complexity & Impact

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

- Does this change increase per-bot or per-tick processing?
    - [x] No
    - [ ] Yes (**describe and justify impact**)

- Could this logic scale poorly under load?
    - [x] No
    - [ ] Yes (**explain why**)

---

## Defaults & Configuration

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

If this introduces more advanced or AI-heavy logic:

- [ ] Lightweight mode remains the default
- [ ] More complex behavior is optional and thereby configurable

---

## AI Assistance

- Was AI assistance (e.g. ChatGPT or similar tools) used while working
on this change?
    - [x] No
    - [ ] Yes (**explain below**)

---

## Final Checklist

- [x] Stability is not compromised
- [x] Performance impact is understood, tested, and acceptable
- [x] Added logic complexity is justified and explained
- [x] Documentation updated if needed

---

## Notes for Reviewers

Anything that significantly improves realism at the cost of stability or
performance should be carefully discussed
before merging.

---------

Co-authored-by: bashermens <31279994+hermensbas@users.noreply.github.com>
2026-02-14 20:55:10 +01:00

80 lines
2.3 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 "GuildBankAction.h"
#include "GuildMgr.h"
#include "PlayerbotAI.h"
#include "AiObjectContext.h"
bool GuildBankAction::Execute(Event event)
{
std::string const text = event.getParam();
if (text.empty())
return false;
if (!bot->GetGuildId() || (GetMaster() && GetMaster()->GetGuildId() != bot->GetGuildId()))
{
botAI->TellMaster("I'm not in your guild!");
return false;
}
GuidVector gos = *botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest game objects");
for (GuidVector::iterator i = gos.begin(); i != gos.end(); ++i)
{
GameObject* go = botAI->GetGameObject(*i);
if (!go || !bot->GetGameObjectIfCanInteractWith(go->GetGUID(), GAMEOBJECT_TYPE_GUILD_BANK))
continue;
return Execute(text, go);
}
botAI->TellMaster("Cannot find the guild bank nearby");
return false;
}
bool GuildBankAction::Execute(std::string const text, GameObject* bank)
{
bool result = true;
std::vector<Item*> found = parseItems(text);
if (found.empty())
return false;
for (std::vector<Item*>::iterator i = found.begin(); i != found.end(); i++)
{
Item* item = *i;
if (item)
result &= MoveFromCharToBank(item, bank);
}
return result;
}
bool GuildBankAction::MoveFromCharToBank(Item* item, GameObject* bank)
{
uint32 playerSlot = item->GetSlot();
uint32 playerBag = item->GetBagSlot();
std::ostringstream out;
Guild* guild = sGuildMgr->GetGuildById(bot->GetGuildId());
// guild->SwapItems(bot, 0, playerSlot, 0, INVENTORY_SLOT_BAG_0, 0);
// check source pos rights (item moved to bank)
if (!guild->MemberHasTabRights(bot->GetGUID(), 0, GUILD_BANK_RIGHT_DEPOSIT_ITEM))
out << "I can't put " << chat->FormatItem(item->GetTemplate())
<< " to guild bank. I have no rights to put items in the first guild bank tab";
else
{
out << chat->FormatItem(item->GetTemplate()) << " put to guild bank";
guild->SwapItemsWithInventory(bot, false, 0, 255, playerBag, playerSlot, 0);
}
botAI->TellMaster(out);
return true;
}