mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-03-11 19:35:09 +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>
107 lines
3.2 KiB
C++
107 lines
3.2 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 "DestroyItemAction.h"
|
|
|
|
#include "Event.h"
|
|
#include "ItemCountValue.h"
|
|
#include "Playerbots.h"
|
|
|
|
bool DestroyItemAction::Execute(Event event)
|
|
{
|
|
std::string const text = event.getParam();
|
|
ItemIds ids = chat->parseItems(text);
|
|
|
|
for (ItemIds::iterator i = ids.begin(); i != ids.end(); i++)
|
|
{
|
|
FindItemByIdVisitor visitor(*i);
|
|
DestroyItem(&visitor);
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void DestroyItemAction::DestroyItem(FindItemVisitor* visitor)
|
|
{
|
|
IterateItems(visitor);
|
|
std::vector<Item*> items = visitor->GetResult();
|
|
for (Item* item : items)
|
|
{
|
|
std::ostringstream out;
|
|
out << chat->FormatItem(item->GetTemplate()) << " destroyed";
|
|
botAI->TellMaster(out);
|
|
|
|
bot->DestroyItem(item->GetBagSlot(), item->GetSlot(), true);
|
|
}
|
|
}
|
|
|
|
bool SmartDestroyItemAction::isUseful() { return !botAI->HasActivePlayerMaster(); }
|
|
|
|
bool SmartDestroyItemAction::Execute(Event /*event*/)
|
|
{
|
|
uint8 bagSpace = AI_VALUE(uint8, "bag space");
|
|
|
|
if (bagSpace < 90)
|
|
return false;
|
|
|
|
// only destoy grey items if with real player/guild
|
|
if (botAI->HasRealPlayerMaster() && botAI->IsInRealGuild())
|
|
{
|
|
std::set<Item*> items;
|
|
FindItemsToTradeByQualityVisitor visitor(ITEM_QUALITY_POOR, 5);
|
|
IterateItems(&visitor, ITERATE_ITEMS_IN_BAGS);
|
|
items.insert(visitor.GetResult().begin(), visitor.GetResult().end());
|
|
|
|
for (auto& item : items)
|
|
{
|
|
FindItemByIdVisitor visitor(item->GetTemplate()->ItemId);
|
|
DestroyItem(&visitor);
|
|
|
|
bagSpace = AI_VALUE(uint8, "bag space");
|
|
|
|
if (bagSpace < 90)
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::vector<uint32> bestToDestroy = {ITEM_USAGE_NONE}; // First destroy anything useless.
|
|
|
|
if (!AI_VALUE(bool, "can sell") &&
|
|
AI_VALUE(
|
|
bool,
|
|
"should get money")) // We need money so quest items are less important since they can't directly be sold.
|
|
bestToDestroy.push_back(ITEM_USAGE_QUEST);
|
|
else // We don't need money so destroy the cheapest stuff.
|
|
{
|
|
bestToDestroy.push_back(ITEM_USAGE_VENDOR);
|
|
bestToDestroy.push_back(ITEM_USAGE_AH);
|
|
}
|
|
|
|
// If we still need room
|
|
bestToDestroy.push_back(
|
|
ITEM_USAGE_SKILL); // Items that might help tradeskill are more important than above but still expenable.
|
|
bestToDestroy.push_back(ITEM_USAGE_USE); // These are more likely to be usefull 'soon' but still expenable.
|
|
|
|
for (auto& usage : bestToDestroy)
|
|
{
|
|
std::vector<Item*> items = AI_VALUE2(std::vector<Item*>, "inventory items", "usage " + std::to_string(usage));
|
|
std::reverse(items.begin(), items.end());
|
|
|
|
for (auto& item : items)
|
|
{
|
|
FindItemByIdVisitor visitor(item->GetTemplate()->ItemId);
|
|
DestroyItem(&visitor);
|
|
|
|
bagSpace = AI_VALUE(uint8, "bag space");
|
|
|
|
if (bagSpace < 90)
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|