mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-02-05 20:03:49 +00:00
# Pull Request
- Applies the clean and corrected singletons, Meyer pattern. (cherry
picked from @SmashingQuasar )
Testing by just playing the game in various ways. Been tested by myself
@Celandriel and @SmashingQuasar
---
## 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**)
---
## 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: Nicolas Lebacq <nicolas.cordier@outlook.com>
Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com>
93 lines
2.9 KiB
C++
93 lines
2.9 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 "GiveItemAction.h"
|
|
|
|
#include "Event.h"
|
|
#include "ItemCountValue.h"
|
|
#include "Playerbots.h"
|
|
|
|
std::vector<std::string> split(std::string const s, char delim);
|
|
|
|
bool GiveItemAction::Execute(Event event)
|
|
{
|
|
Unit* target = GetTarget();
|
|
if (!target)
|
|
return false;
|
|
|
|
Player* receiver = dynamic_cast<Player*>(target);
|
|
if (!receiver)
|
|
return false;
|
|
|
|
PlayerbotAI* receiverAi = GET_PLAYERBOT_AI(receiver);
|
|
if (!receiverAi)
|
|
return false;
|
|
|
|
if (receiverAi->GetAiObjectContext()->GetValue<uint32>("item count", item)->Get())
|
|
return true;
|
|
|
|
bool moved = false;
|
|
std::vector<Item*> items = InventoryAction::parseItems(item, ITERATE_ITEMS_IN_BAGS);
|
|
for (Item* item : items)
|
|
{
|
|
if (receiver->CanUseItem(item->GetTemplate()) != EQUIP_ERR_OK)
|
|
continue;
|
|
|
|
ItemPosCountVec dest;
|
|
InventoryResult msg = receiver->CanStoreItem(NULL_BAG, NULL_SLOT, dest, item, false);
|
|
if (msg == EQUIP_ERR_OK)
|
|
{
|
|
bot->MoveItemFromInventory(item->GetBagSlot(), item->GetSlot(), true);
|
|
item->SetOwnerGUID(target->GetGUID());
|
|
receiver->MoveItemToInventory(dest, item, true);
|
|
moved = true;
|
|
|
|
std::ostringstream out;
|
|
out << "Got " << chat->FormatItem(item->GetTemplate(), item->GetCount()) << " from " << bot->GetName();
|
|
receiverAi->TellMasterNoFacing(out.str());
|
|
}
|
|
else
|
|
{
|
|
std::ostringstream out;
|
|
out << "Cannot get " << chat->FormatItem(item->GetTemplate(), item->GetCount()) << " from "
|
|
<< bot->GetName() << "- my bags are full";
|
|
receiverAi->TellError(out.str());
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
Unit* GiveItemAction::GetTarget() { return AI_VALUE2(Unit*, "party member without item", item); }
|
|
|
|
bool GiveItemAction::isUseful()
|
|
{
|
|
return GetTarget() && AI_VALUE2(uint8, "mana", "self target") > sPlayerbotAIConfig.lowMana;
|
|
}
|
|
|
|
Unit* GiveFoodAction::GetTarget() { return AI_VALUE(Unit*, "party member without food"); }
|
|
|
|
bool GiveFoodAction::isUseful()
|
|
{
|
|
if (!GetTarget())
|
|
return false;
|
|
|
|
bool isRandomBot = GetTarget()->IsPlayer() && sRandomPlayerbotMgr.IsRandomBot((Player*)GetTarget());
|
|
|
|
return !isRandomBot || (isRandomBot && !botAI->HasCheat(BotCheatMask::food));
|
|
}
|
|
|
|
Unit* GiveWaterAction::GetTarget() { return AI_VALUE(Unit*, "party member without water"); }
|
|
|
|
bool GiveWaterAction::isUseful()
|
|
{
|
|
if (!GetTarget())
|
|
return false;
|
|
|
|
bool isRandomBot = GetTarget()->IsPlayer() && sRandomPlayerbotMgr.IsRandomBot((Player*)GetTarget());
|
|
|
|
return !isRandomBot || (isRandomBot && !botAI->HasCheat(BotCheatMask::food));
|
|
}
|