Bots: "sell junk" sells everything a vendor takes, and sells on arrival

Gun's bags were full and "sell grey" only looked at grey items ("nothing grey to
sell"), only found vendors within 60 yards, and asked to be told again on arrival.

- sell grey / sell junk / sell your junk counts what a vendor visit really sells
  (CountBagRot: greys, trade goods for no profession of the bot's, gear it can't use,
  outgrown greens when the bags are tight), and says so when there is nothing.
- No vendor selected or in the bot's 60 yard scan: the nearest friendly vendor within
  200 yards.
- Farther than 5 yards: the bot walks there and sells once it arrives
  (TickVendorRuns, once a second), or says after a minute that it could not get there.
- "sell junk" is one of the program's safe orders, and the full-bags rule in its prompt
  uses it.

(cherry picked from commit 15e2eb0cc58096621ac68b9374a7edf1f36fb542)
This commit is contained in:
Karrz1
2026-11-11 23:37:46 +00:00
parent 0d49e4e094
commit 8d26e53319
9 changed files with 107 additions and 23 deletions
@@ -79,4 +79,7 @@ Result Step(Player* bot, TradeData* mine, TradeData* his, bool gift_ok);
namespace Playerbot {
// Clears bag rot until `min_free` slots are free (defined with API::make_room).
bool MakeBagRoom(Player* bot, uint32 min_free);
// The bag stacks a vendor visit would sell (API::sell_trash: greys, trade goods for no profession of the bot's, gear it can't use,
// outgrown greens when the bags are tight).
uint32 CountBagRot(Player* bot);
}
@@ -6499,6 +6499,20 @@ bool MakeBagRoom(Player* bot, uint32 min_free)
return cleared >= want;
}
uint32 CountBagRot(Player* bot)
{
if (!bot) return 0;
bool const bags_tight = CountFreeBagSlots(bot) <= 3; // sell_trash's kTightBagThreshold
uint32 n = 0;
bot->ForEachItem(ItemSearchLocation::Inventory, [bot, bags_tight, &n](Item* it)
{
if (IsBagRot(bot, it, it ? it->GetTemplate() : nullptr, bags_tight))
++n;
return ItemSearchCallbackResult::Continue;
});
return n;
}
Result API::make_room(uint32 min_free)
{
if (!p_) return Result::Other;
+4 -4
View File
@@ -158,7 +158,7 @@ from the bot.
| `stats` | yes | yes | `Raveni: health 3120/3120 (100%), item level 66, armor 2250, str 210 agi 110 sta 290 int 40, crit 4.1%`. Mana is added for mana users. `status` is the older diagnostic dump. |
| `gear` / `inventory` | yes | yes | `Raveni: 15 pieces worn, avg item level 66, best: Ironfoe, ...; 14 free bag slots; 12g 40s 5c`. `inv` lists bag items; `equipped` lists each worn slot. |
| `money`, `level`, `xp`, `dur`, `skills`, `recipes`, `rep`, `spec` | yes | no | One-line introspection verbs. |
| `sell grey` / `sell junk` / `s *` | yes | yes | Sells grey items to the vendor you have selected, else the nearest vendor the bot sees within 60 yards. In reach: `Raveni: selling 7 grey stack(s) to Dolanaar Vendor`. Farther away it walks over and asks you to say it again. No vendor: `no vendor within 60 yards`. Plain `sell` (selected vendor) and `sell <bag> <slot> [n]` also exist. |
| `sell grey` / `sell junk` / `sell your junk` / `s *` | yes | yes | Sells everything a vendor visit sells (greys, trade goods for no profession of the bot's, gear it can't use, outgrown greens when the bags are tight) to the vendor you have selected, else the nearest friendly vendor within 200 yards. In reach: `Raveni: selling 7 thing(s) to Dolanaar Vendor`. Farther away it walks over and sells when it arrives (`at Dolanaar Vendor, selling 7 thing(s)`; after a minute without getting there it says so). Nothing to sell: `nothing to sell, my bags only hold things I keep (0 free slots)`. No vendor: `no vendor near here`. Plain `sell` (selected vendor) and `sell <bag> <slot> [n]` also exist. |
| `repair` | yes | yes | Same pattern with a repair vendor: `Raveni: repairing at ...`. |
| `loot` | yes | yes | Need before greed with the usual etiquette (human gets first claim). `Raveni: need before greed, the usual rules`. |
| `loot all` | yes | yes | The bot rolls for itself on every drop and takes every corpse item, greys included. `Raveni: looting everything, greys included, and rolling for myself`. Memory only (resets on relog). |
@@ -407,9 +407,9 @@ The module logs nothing unless `Logger.playerbot.v2=3` is set. Grep the server l
- The ike3 strategy toggles `co`/`nc`/`ss` (+/- strategy lists) are **not implemented**. Trade is: the bot takes
gifts from its owner or a group mate (see Gifts by trade) and a free world bot buys what you put in. The
nearest equivalents are `max dps` / `save mana` / `normal`, `aoe`, `hold`/`defensive`/`aggressive`.
- `sell grey` and `repair` act at once only when the vendor is within interaction reach; from up to 60 yards the
bot walks over and you repeat the order. There is no standing "go and sell, then come back" order; the bots'
own vendor upkeep (idle vendor visit, bag-full recovery) still runs when they are not in a group.
- `repair` acts at once only when the vendor is within interaction reach; from up to 60 yards the bot walks over and
you repeat the order. `sell junk` walks over and sells by itself. The bot stays by the vendor afterwards ("follow" to
bring it back); the bots' own vendor upkeep (idle vendor visit, bag-full recovery) still runs when they are not in a group.
- `loot all` is held in memory per bot and resets on relog.
- `defensive` / `aggressive` / `passive` are the three owner stances (BotAI::OwnerStance Passive / Aggressive / NoFight); there
is no separate attack-stance engine.
@@ -753,7 +753,7 @@ bool SafeOrder(std::string const& raw, std::string& norm, std::string& why)
static constexpr std::string_view kExact[] = {
"follow", "stay", "hold", "resume", "come", "disengage", "flee", "attack", "assist", "mount", "dismount", "sit", "stand",
"release", "passive", "defensive", "aggressive", "accept", "accept all", "turn in", "turnin", "share", "quests",
"quest list", "loot", "loot all", "sell grey", "repair", "equip upgrades", "upgrades", "use your best gear",
"quest list", "loot", "loot all", "sell grey", "sell junk", "repair", "equip upgrades", "upgrades", "use your best gear",
"wear your best gear", "gear", "inventory", "stats", "who", "buff", "heal", "jump", "wave", "salute", "dance",
// The fight's group words: the tank's pull and pull back, falling back to (and setting) the rally point, the group's spacing,
// and ike3's tactics.
@@ -23,6 +23,7 @@
#include "CcDeny.h"
#include "OwnerPicks.h"
#include "../Fleet/PlayerCraftOrders.h"
#include "../Api/BotTradeShop.h" // CountBagRot for "sell junk"
#include "BotAddressResolver.h"
#include "Placement.h"
#include "ClassicUpkeep.h" // Classic::IsMeleeSpec for the Positions tab order
@@ -1372,6 +1373,15 @@ struct VendorPick
float x = 0.f, y = 0.f, z = 0.f;
};
// "sell junk" with the vendor further than 5 yards: the bot walks there, and TickVendorRuns sells once it is in reach.
struct VendorRun { ObjectGuid vendor; std::string to; uint32 started_ms = 0; };
std::unordered_map<BotId, VendorRun> g_vendor_runs; // world thread
void NoteVendorRun(BotId bot, ObjectGuid vendor, std::string to)
{
g_vendor_runs[bot] = VendorRun{ vendor, std::move(to), GameTime::GetGameTimeMS() };
}
VendorPick PickVendor(Player* sender, Player* bot, uint32 flag)
{
VendorPick out;
@@ -1550,36 +1560,54 @@ bool OwnerWordOrder(Player* sender, Player* bot, std::string const& n)
}
// ---- sell grey / repair -----------------------------------------------------------------------------------------
if (n == "sell grey" || n == "sell gray" || n == "sell junk" || n == "sell trash" || n == "s *")
if (n == "sell grey" || n == "sell gray" || n == "sell junk" || n == "sell trash" || n == "s *" || n == "sell your junk")
{
auto snap = Services::Snapshots().latest(bid);
uint32 greys = 0;
if (snap)
for (auto const& it : snap->inventory.bag_items)
if (it.quality == 0)
++greys;
VendorPick const v = PickVendor(sender, bot, UNIT_NPC_FLAG_VENDOR);
if (v.guid.IsEmpty())
// Everything a vendor visit sells (CountBagRot / sell_trash), not only greys: Gun's bags were full of things a vendor
// takes and the order said "nothing grey to sell" (2026-11-09).
uint32 const junk = ::Playerbot::CountBagRot(bot);
if (junk == 0)
{
say(me + ": no vendor within 60 yards - select one and say it again, or walk me to one");
say(fmt::format("{}: nothing to sell, my bags only hold things I keep ({} free slots)", me, bot->GetFreeInventorySlotCount()));
return true;
}
if (greys == 0)
VendorPick v = PickVendor(sender, bot, UNIT_NPC_FLAG_VENDOR);
if (v.guid.IsEmpty())
{
say(me + ": nothing grey to sell");
// Not in the bot's 60 yard scan: the nearest friendly vendor in the town (a bank square, a market street).
std::list<Creature*> found;
FindCreatureOptions opt;
opt.IgnorePhases = false;
bot->GetCreatureListWithOptionsInGrid(found, 200.0f, opt);
Creature const* best = nullptr;
for (Creature const* c : found)
if (c->IsAlive() && c->HasNpcFlag(UNIT_NPC_FLAG_VENDOR) && !c->IsHostileTo(bot)
&& (!best || bot->GetDistance(c) < bot->GetDistance(best)))
best = c;
if (best)
{
v.guid = best->GetGUID();
v.name = best->GetName();
v.dist = bot->GetDistance(best);
best->GetPosition(v.x, v.y, v.z);
}
}
if (v.guid.IsEmpty())
{
say(me + ": no vendor near here - select one and say it again, or walk me to one");
return true;
}
if (v.dist > 5.0f)
{
// Walk the last stretch; the sale itself needs the vendor in reach, so ask again once there.
// Walk there and sell on arrival (TickVendorRuns): one order is enough.
Push(bot, MoveToIntent{v.x, v.y, v.z, /*run=*/true});
if (BotAI* ai = Services::Registry().ai(bid))
ai->enter_manual(BotAI::OwnerCommand::Stay, ObjectGuid::Empty, GameTime::GetGameTimeMS());
say(fmt::format("{}: walking to {} ({:.0f} yards); say 'sell grey' again when I am there", me, v.name, v.dist));
NoteVendorRun(bid, v.guid, sender->GetName());
say(fmt::format("{}: walking to {} ({:.0f} yards) to sell {} thing(s)", me, v.name, v.dist, junk));
return true;
}
Push(bot, VendorSellTrashIntent{v.guid});
say(fmt::format("{}: selling {} grey stack(s) to {}", me, greys, v.name));
say(fmt::format("{}: selling {} thing(s) to {}", me, junk, v.name));
return true;
}
if (n == "repair")
@@ -2310,6 +2338,37 @@ static void ConfirmWhisperOrder(Player* sender, Player* bot, std::string const&
Push(bot, WhisperIntent{sender->GetName(), std::move(text)});
}
void BotCommandParser::TickVendorRuns(uint32 now_ms)
{
for (auto it = g_vendor_runs.begin(); it != g_vendor_runs.end();)
{
BotId const id = it->first;
VendorRun const& run = it->second;
Player* bot = ObjectAccessor::FindConnectedPlayer(ObjectGuid::Create<HighGuid::Player>(id));
Creature* vendor = bot && bot->IsInWorld() ? ObjectAccessor::GetCreature(*bot, run.vendor) : nullptr;
bool done = false;
if (!bot || !bot->IsAlive() || !vendor || !Services::HasIntents(id))
done = true;
else if (bot->IsWithinDistInMap(vendor, INTERACTION_DISTANCE))
{
uint32 const junk = ::Playerbot::CountBagRot(bot);
Push(bot, VendorSellTrashIntent{vendor->GetGUID()});
Push(bot, WhisperIntent{run.to, fmt::format("{}: at {}, selling {} thing(s)", bot->GetName(), vendor->GetName(), junk)});
TC_LOG_INFO("playerbot.v2", "[owner_order] {} reached {}: sells {} bag stack(s)", bot->GetName(), vendor->GetName(), junk);
done = true;
}
else if (now_ms - run.started_ms > 60000u)
{
Push(bot, WhisperIntent{run.to, fmt::format("{}: I couldn't get to {}, walk me closer and ask again", bot->GetName(),
vendor->GetName())});
TC_LOG_INFO("playerbot.v2", "[owner_order] {} did not reach {} in a minute ({:.0f} yards left)", bot->GetName(),
vendor->GetName(), bot->GetDistance(vendor));
done = true;
}
it = done ? g_vendor_runs.erase(it) : std::next(it);
}
}
bool BotCommandParser::ControlsForGroupOrder(Player const* sender, Player const* bot)
{
if (!sender || !bot || sender == bot || !sender->GetSession())
@@ -65,6 +65,9 @@ public:
// who is its controller in the group they share (GroupControl.h): the group leader when human, else the first human
// member. An invited world bot obeys the leader exactly like a companion.
static bool ControlsForGroupOrder(Player const* sender, Player const* bot_player);
// World thread, once a second: a bot walking to a vendor for "sell junk" sells there once it arrives (or gives up after a
// minute), so the owner does not have to say it again.
static void TickVendorRuns(uint32 now_ms);
// The bot's role as its owner set it (`.bot add <class> tank`, setrole), else as its spec reads.
static Role BotRole(Player* bot_player);
+3
View File
@@ -2755,7 +2755,10 @@ void Module::OnWorldUpdate(std::chrono::milliseconds diff)
{
last_player_craft_at_ = player_craft_total_;
if (Services::Initialized())
{
::Playerbot::V2::PlayerCraftOrders::Tick(GameTime::GetGameTimeMS());
BotCommandParser::TickVendorRuns(GameTime::GetGameTimeMS()); // "sell junk": sells on arrival
}
}
// 3. Schedule tick for due bots.
@@ -59,7 +59,7 @@ CANT_LINES = ["can't do that right now, sorry", "hm, can't right now", "sorry, t
# The orders a reply may give through the bots' own command words (the server checks them again: BotBridgeFormat SafeOrder).
ORDERS = ["follow", "stay", "hold", "resume", "come", "disengage", "flee", "attack", "assist", "mount", "dismount", "sit", "stand",
"release", "passive", "defensive", "aggressive", "accept", "accept all", "turn in", "turnin", "share", "quests",
"quest list", "loot", "loot all", "sell grey", "repair", "equip upgrades", "upgrades", "use your best gear",
"quest list", "loot", "loot all", "sell grey", "sell junk", "repair", "equip upgrades", "upgrades", "use your best gear",
"wear your best gear", "gear", "inventory", "stats", "who", "buff", "heal", "jump", "wave", "salute", "dance",
"pull", "pull back", "pullback", "fall back", "fallback", "back", "rally here", "spread", "spread out", "spaced out",
"stack", "tight", "close", "max dps", "save mana", "normal"]
@@ -598,8 +598,8 @@ def static_rules(actions_on, swearing):
"him. He accepts in the window. Use it when he asks you to trade or give him something. YOUR BAGS below says what "
"you really carry: never say you give him something that is not there. Water or food you don't have but can "
"conjure: trade with \"items\":\"water\" (or \"food\") still works, you conjure it first and then trade. When YOUR "
"BAGS says your bags are FULL you can't conjure or make anything: say so; junk is sold at a \"vendor\" "
"(go_to \"place\":\"vendor\"), not at the auction house. Your line is read before the action "
"BAGS says your bags are FULL you can't conjure or make anything: say so; to sell your junk use the order "
"\"sell junk\" (you walk to the nearest vendor and sell it there), not the auction house. Your line is read before the action "
"happens: say what you are about to do (\"one sec, conjuring\"), not that it is done.\n"
"cast needs \"spell\" (a name from YOUR SPELLS). damage spells need \"ref\" of a hostile from NEAR or "
"\"target\":\"speaker_target\"; heal, buff and resurrect go on the player who asks (\"target\":\"speaker\") "
+2
View File
@@ -459,6 +459,8 @@ TEST_CASE("BotBridge: an order is one of the safe parser words", "[BotBridge]")
CHECK(SafeOrder("/drop quest Wolves", norm, why));
CHECK(norm == "drop quest wolves");
CHECK(SafeOrder("use altar", norm, why));
CHECK(SafeOrder("Sell junk", norm, why)); // walks to a vendor and sells everything a vendor takes
CHECK(norm == "sell junk");
CHECK_FALSE(SafeOrder("use", norm, why));
CHECK(SafeOrder("Craft water 20", norm, why));
CHECK(norm == "craft water 20");