mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-16 08:36:10 +00:00
# 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>
105 lines
3.0 KiB
C++
105 lines
3.0 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 "CheckMailAction.h"
|
|
|
|
#include "Event.h"
|
|
#include "GuildTaskMgr.h"
|
|
#include "PlayerbotAIConfig.h"
|
|
#include "PlayerbotAI.h"
|
|
|
|
bool CheckMailAction::Execute(Event /*event*/)
|
|
{
|
|
WorldPacket p;
|
|
bot->GetSession()->HandleQueryNextMailTime(p);
|
|
|
|
CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction();
|
|
|
|
std::vector<uint32> ids;
|
|
for (PlayerMails::const_iterator i = bot->GetMails().begin(); i != bot->GetMails().end(); ++i)
|
|
{
|
|
Mail* mail = *i;
|
|
if (!mail || mail->state == MAIL_STATE_DELETED)
|
|
continue;
|
|
|
|
Player* owner = ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create<HighGuid::Player>(mail->sender));
|
|
if (!owner)
|
|
continue;
|
|
|
|
uint32 account = owner->GetSession()->GetAccountId();
|
|
if (PlayerbotAIConfig::instance().IsInRandomAccountList(account))
|
|
continue;
|
|
|
|
ProcessMail(mail, owner, trans);
|
|
ids.push_back(mail->messageID);
|
|
mail->state = MAIL_STATE_DELETED;
|
|
}
|
|
|
|
for (uint32 id : ids)
|
|
{
|
|
bot->SendMailResult(id, MAIL_DELETED, MAIL_OK);
|
|
|
|
CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_BY_ID);
|
|
stmt->SetData(0, id);
|
|
trans->Append(stmt);
|
|
|
|
stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_MAIL_ITEM_BY_ID);
|
|
stmt->SetData(0, id);
|
|
trans->Append(stmt);
|
|
|
|
bot->RemoveMail(id);
|
|
}
|
|
|
|
CharacterDatabase.CommitTransaction(trans);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool CheckMailAction::isUseful()
|
|
{
|
|
if (botAI->GetMaster() || !bot->GetMailSize() || bot->InBattleground())
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
void CheckMailAction::ProcessMail(Mail* mail, Player* owner, CharacterDatabaseTransaction trans)
|
|
{
|
|
if (mail->items.empty())
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (mail->subject.find("Item(s) you asked for") != std::string::npos)
|
|
return;
|
|
|
|
for (MailItemInfoVec::iterator i = mail->items.begin(); i != mail->items.end(); ++i)
|
|
{
|
|
Item* item = bot->GetMItem(i->item_guid);
|
|
if (!item)
|
|
continue;
|
|
|
|
if (!GuildTaskMgr::instance().CheckItemTask(i->item_template, item->GetCount(), owner, bot, true))
|
|
{
|
|
std::ostringstream body;
|
|
body << "Hello, " << owner->GetName() << ",\n";
|
|
body << "\n";
|
|
body << "Here are the item(s) you've sent me by mistake";
|
|
body << "\n";
|
|
body << "Thanks,\n";
|
|
body << bot->GetName() << "\n";
|
|
|
|
MailDraft draft("Item(s) you've sent me", body.str());
|
|
draft.AddItem(item);
|
|
bot->RemoveMItem(i->item_guid);
|
|
draft.SendMailTo(trans, MailReceiver(owner), MailSender(bot));
|
|
return;
|
|
}
|
|
|
|
bot->RemoveMItem(i->item_guid);
|
|
item->DestroyForPlayer(bot);
|
|
}
|
|
}
|