mirror of
https://github.com/mod-playerbots/mod-playerbots.git
synced 2026-01-17 10:45:43 +00:00
Big update.
This commit is contained in:
128
src/strategy/actions/SellAction.cpp
Normal file
128
src/strategy/actions/SellAction.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU GPL v2 license, you may redistribute it and/or modify it under version 2 of the License, or (at your option), any later version.
|
||||
*/
|
||||
|
||||
#include "SellAction.h"
|
||||
#include "Event.h"
|
||||
#include "ItemVisitors.h"
|
||||
#include "ItemUsageValue.h"
|
||||
#include "Playerbots.h"
|
||||
|
||||
class SellItemsVisitor : public IterateItemsVisitor
|
||||
{
|
||||
public:
|
||||
SellItemsVisitor(SellAction* action) : IterateItemsVisitor(), action(action) { }
|
||||
|
||||
bool Visit(Item* item) override
|
||||
{
|
||||
action->Sell(item);
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
SellAction* action;
|
||||
};
|
||||
|
||||
class SellGrayItemsVisitor : public SellItemsVisitor
|
||||
{
|
||||
public:
|
||||
SellGrayItemsVisitor(SellAction* action) : SellItemsVisitor(action) { }
|
||||
|
||||
bool Visit(Item* item) override
|
||||
{
|
||||
if (item->GetTemplate()->Quality != ITEM_QUALITY_POOR)
|
||||
return true;
|
||||
|
||||
return SellItemsVisitor::Visit(item);
|
||||
}
|
||||
};
|
||||
|
||||
class SellVendorItemsVisitor : public SellItemsVisitor
|
||||
{
|
||||
public:
|
||||
SellVendorItemsVisitor(SellAction* action, AiObjectContext* con) : SellItemsVisitor(action)
|
||||
{
|
||||
context = con;
|
||||
}
|
||||
|
||||
AiObjectContext* context;
|
||||
|
||||
bool Visit(Item* item) override
|
||||
{
|
||||
ItemUsage usage = context->GetValue<ItemUsage>("item usage", item->GetEntry())->Get();
|
||||
if (usage != ITEM_USAGE_VENDOR && usage != ITEM_USAGE_AH)
|
||||
return true;
|
||||
|
||||
return SellItemsVisitor::Visit(item);
|
||||
}
|
||||
};
|
||||
|
||||
bool SellAction::Execute(Event event)
|
||||
{
|
||||
std::string const text = event.getParam();
|
||||
if (text == "gray" || text == "*")
|
||||
{
|
||||
SellGrayItemsVisitor visitor(this);
|
||||
IterateItems(&visitor);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (text == "vendor")
|
||||
{
|
||||
SellVendorItemsVisitor visitor(this, context);
|
||||
IterateItems(&visitor);
|
||||
return true;
|
||||
}
|
||||
|
||||
std::vector<Item*> items = parseItems(text, ITERATE_ITEMS_IN_BAGS);
|
||||
for (Item* item : items)
|
||||
{
|
||||
Sell(item);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void SellAction::Sell(FindItemVisitor* visitor)
|
||||
{
|
||||
IterateItems(visitor);
|
||||
std::vector<Item*> items = visitor->GetResult();
|
||||
for (Item* item : items)
|
||||
{
|
||||
Sell(item);
|
||||
}
|
||||
}
|
||||
|
||||
void SellAction::Sell(Item* item)
|
||||
{
|
||||
std::ostringstream out;
|
||||
|
||||
GuidVector vendors = botAI->GetAiObjectContext()->GetValue<GuidVector>("nearest npcs")->Get();
|
||||
|
||||
for (ObjectGuid const vendorguid : vendors)
|
||||
{
|
||||
Creature* pCreature = bot->GetNPCIfCanInteractWith(vendorguid,UNIT_NPC_FLAG_VENDOR);
|
||||
if (!pCreature)
|
||||
continue;
|
||||
|
||||
ObjectGuid itemguid = item->GetGUID();
|
||||
uint32 count = item->GetCount();
|
||||
|
||||
uint32 botMoney = bot->GetMoney();
|
||||
|
||||
WorldPacket p;
|
||||
p << vendorguid << itemguid << count;
|
||||
bot->GetSession()->HandleSellItemOpcode(p);
|
||||
|
||||
if (botAI->HasCheat(BotCheatMask::gold))
|
||||
{
|
||||
bot->SetMoney(botMoney);
|
||||
}
|
||||
|
||||
out << "Selling " << chat->FormatItem(item->GetTemplate());
|
||||
botAI->TellMaster(out);
|
||||
|
||||
bot->PlayDistanceSound(120);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user