Skip to content

Commit

Permalink
always/skip loot list:
Browse files Browse the repository at this point in the history
ll +[item] = always loot item
ll ![item] = ignore item
ll -[item] = remove from both lists
  • Loading branch information
ike3 authored and celguar committed Dec 4, 2023
1 parent 2744d3d commit 0321abf
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 27 deletions.
4 changes: 4 additions & 0 deletions playerbot/strategy/actions/LootAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,10 @@ bool StoreLootAction::IsLootAllowed(ItemQualifier& itemQualifier, PlayerbotAI *a
if (lootItems.find(itemQualifier.GetId()) != lootItems.end())
return true;

set<uint32>& skipItems = AI_VALUE(set<uint32>&, "skip loot list");
if (skipItems.find(itemQualifier.GetId()) != skipItems.end())
return false;

uint32 max = proto->MaxCount;
if (max > 0 && ai->GetBot()->HasItemCount(itemQualifier.GetId(), max, true))
return false;
Expand Down
87 changes: 61 additions & 26 deletions playerbot/strategy/actions/LootStrategyAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ bool LootStrategyAction::Execute(Event& event)

LootObjectStack* lootItems = AI_VALUE(LootObjectStack*, "available loot");
set<uint32>& alwaysLootItems = AI_VALUE(set<uint32>&, "always loot list");
set<uint32>& skipLootItems = AI_VALUE(set<uint32>&, "skip loot list");

if (strategy == "?")
{
Expand All @@ -25,23 +26,16 @@ bool LootStrategyAction::Execute(Event& event)
ai->TellPlayer(requester, out);
}

{
ostringstream out;
out << "Always loot items: ";
for (set<uint32>::iterator i = alwaysLootItems.begin(); i != alwaysLootItems.end(); i++)
{
ItemPrototype const *proto = sItemStorage.LookupEntry<ItemPrototype>(*i);
if (!proto)
{
continue;
}

out << chat->formatItem(proto);
}

ai->TellPlayer(requester, out);
}
TellLootList(requester, "always loot list");
TellLootList(requester, "skip loot list");
}
else if (strategy == "clear")
{
alwaysLootItems.clear();
skipLootItems.clear();
ai->TellPlayer(requester, "My loot list is now empty");
return true;
}
else
{
set<string> itemQualifiers = chat->parseItemQualifiers(strategy);
Expand All @@ -58,11 +52,15 @@ bool LootStrategyAction::Execute(Event& event)
return true;
}

bool ignore = strategy.size() > 1 && strategy.substr(0, 1) == "!";
bool remove = strategy.size() > 1 && strategy.substr(0, 1) == "-";
bool query = strategy.size() > 1 && strategy.substr(0, 1) == "?";
bool add = !ignore && !remove && !query;
bool changes = false;
for (auto& qualifier : itemQualifiers)
{
ItemQualifier itemQualifier(qualifier);
auto itemid = itemQualifier.GetId();
if (query)
{
if (itemQualifier.GetProto())
Expand All @@ -72,24 +70,61 @@ bool LootStrategyAction::Execute(Event& event)
ai->TellPlayer(requester, out.str());
}
}
else if (remove)

if (remove || add)
{
set<uint32>::iterator j = alwaysLootItems.find(itemQualifier.GetId());
if (j != alwaysLootItems.end())
{
alwaysLootItems.erase(j);
}
set<uint32>::iterator j = skipLootItems.find(itemid);
if (j != skipLootItems.end()) skipLootItems.erase(j);
changes = true;
}

if (remove || ignore)
{
set<uint32>::iterator j = alwaysLootItems.find(itemid);
if (j != alwaysLootItems.end()) alwaysLootItems.erase(j);
changes = true;
}

if (ignore)
{
skipLootItems.insert(itemid);
changes = true;
}

ai->TellPlayer(requester, "Item(s) removed from always loot list");
if (add)
{
alwaysLootItems.insert(itemid);
changes = true;
}
else

if (changes)
{
alwaysLootItems.insert(itemQualifier.GetId());
ai->TellPlayer(requester, "Item(s) added to always loot list");
TellLootList(requester, "always loot list");
TellLootList(requester, "skip loot list");
AI_VALUE(LootObjectStack*, "available loot")->Clear();
}
}
}

return true;
}

void LootStrategyAction::TellLootList(Player* requester, const string& name)
{
set<uint32>& alwaysLootItems = AI_VALUE(set<uint32>&, name);
ostringstream out;
out << "My " << name << ":";

for (set<uint32>::iterator i = alwaysLootItems.begin(); i != alwaysLootItems.end(); i++)
{
ItemPrototype const *proto = sItemStorage.LookupEntry<ItemPrototype>(*i);
if (!proto)
{
continue;
}

out << " " << chat->formatItem(proto);
}

ai->TellPlayer(requester, out);
}
3 changes: 3 additions & 0 deletions playerbot/strategy/actions/LootStrategyAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ namespace ai
public:
LootStrategyAction(PlayerbotAI* ai) : ChatCommandAction(ai, "ll") {}
virtual bool Execute(Event& event) override;

private:
void TellLootList(Player* requester, const string& name);
};
}
4 changes: 3 additions & 1 deletion playerbot/strategy/values/ValueContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ namespace ai
creators["stack space for item"] = &ValueContext::stack_space_for_item;
creators["should loot object"] = &ValueContext::should_loot_object;
creators["always loot list"] = &ValueContext::always_loot_list;
creators["skip loot list"] = &ValueContext::skip_loot_list;
creators["loot strategy"] = &ValueContext::loot_strategy;
creators["active rolls"] = &ValueContext::active_rolls;
creators["last movement"] = &ValueContext::last_movement;
Expand Down Expand Up @@ -456,7 +457,8 @@ namespace ai
static UntypedValue* has_available_loot(PlayerbotAI* ai) { return new HasAvailableLootValue(ai); }
static UntypedValue* stack_space_for_item(PlayerbotAI* ai) { return new StackSpaceForItem(ai); }
static UntypedValue* should_loot_object(PlayerbotAI* ai) { return new ShouldLootObject(ai); }
static UntypedValue* always_loot_list(PlayerbotAI* ai) { return new AlwaysLootListValue(ai); }
static UntypedValue* always_loot_list(PlayerbotAI* ai) { return new AlwaysLootListValue(ai, "always loot list"); }
static UntypedValue* skip_loot_list(PlayerbotAI* ai) { return new AlwaysLootListValue(ai, "skip loot list"); }
static UntypedValue* loot_strategy(PlayerbotAI* ai) { return new LootStrategyValue(ai); }
static UntypedValue* active_rolls(PlayerbotAI* ai) { return new ActiveRolls(ai); }

Expand Down

0 comments on commit 0321abf

Please sign in to comment.