From 0b105e70d71386dc18acd898788f1b8c0ff0c9bc Mon Sep 17 00:00:00 2001 From: Yunfan Li Date: Mon, 12 Feb 2024 13:59:24 +0800 Subject: [PATCH] Loot roll config --- conf/playerbots.conf.dist | 4 ++ src/PlayerbotAIConfig.cpp | 1 + src/PlayerbotAIConfig.h | 1 + src/strategy/actions/LootRollAction.cpp | 77 ++++++++++++++++++------- 4 files changed, 63 insertions(+), 20 deletions(-) diff --git a/conf/playerbots.conf.dist b/conf/playerbots.conf.dist index 8a0fc1ab..e075affe 100644 --- a/conf/playerbots.conf.dist +++ b/conf/playerbots.conf.dist @@ -162,6 +162,10 @@ AiPlayerbot.AddClassCommand = 1 # Default: 0 (disabled) AiPlayerbot.FreeMethodLoot = 0 +# Bots loot roll level (0 = pass, 1 = greed, 2 = need) +# Default: 1 (greed) +AiPlayerbot.LootRollLevel = 1 + # Bots pick their quest reward (yes = picks first useful item, no = list all rewards, ask = pick useful item and lists if multiple) AiPlayerbot.AutoPickReward = no diff --git a/src/PlayerbotAIConfig.cpp b/src/PlayerbotAIConfig.cpp index 880647d1..5f940fe8 100644 --- a/src/PlayerbotAIConfig.cpp +++ b/src/PlayerbotAIConfig.cpp @@ -273,6 +273,7 @@ bool PlayerbotAIConfig::Initialize() // SPP automation freeMethodLoot = sConfigMgr->GetOption("AiPlayerbot.FreeMethodLoot", false); + lootRollLevel = sConfigMgr->GetOption("AiPlayerbot.LootRollLevel", 1); autoPickReward = sConfigMgr->GetOption("AiPlayerbot.AutoPickReward", "yes"); autoEquipUpgradeLoot = sConfigMgr->GetOption("AiPlayerbot.AutoEquipUpgradeLoot", true); equipUpgradeThreshold = sConfigMgr->GetOption("AiPlayerbot.EquipUpgradeThreshold", 1.1f); diff --git a/src/PlayerbotAIConfig.h b/src/PlayerbotAIConfig.h index 06ed2213..3a3982f6 100644 --- a/src/PlayerbotAIConfig.h +++ b/src/PlayerbotAIConfig.h @@ -161,6 +161,7 @@ class PlayerbotAIConfig uint32 botActiveAlone; bool freeMethodLoot; + int32 lootRollLevel; std::string autoPickReward; bool autoEquipUpgradeLoot; float equipUpgradeThreshold; diff --git a/src/strategy/actions/LootRollAction.cpp b/src/strategy/actions/LootRollAction.cpp index 7ccd7aef..d549b3da 100644 --- a/src/strategy/actions/LootRollAction.cpp +++ b/src/strategy/actions/LootRollAction.cpp @@ -4,7 +4,9 @@ #include "LootRollAction.h" #include "Event.h" +#include "Group.h" #include "ItemUsageValue.h" +#include "PlayerbotAIConfig.h" #include "Playerbots.h" #include "LootAction.h" @@ -16,16 +18,62 @@ bool LootRollAction::Execute(Event event) if (!group) return false; - WorldPacket p(event.getPacket()); //WorldPacket packet for CMSG_LOOT_ROLL, (8+4+1) - ObjectGuid guid; - uint32 slot; - uint8 rollType; - p.rpos(0); //reset packet pointer - p >> guid; //guid of the item rolled - p >> slot; //number of players invited to roll - p >> rollType; //need,greed or pass on roll + std::vector rolls = group->GetRolls(); + for (Roll* &roll : rolls) { + if (roll->playerVote.find(bot->GetGUID())->second != NOT_EMITED_YET) { + continue; + } + ObjectGuid guid = roll->itemGUID; + uint32 slot = roll->itemSlot; + uint32 itemId = roll->itemid; + + RollVote vote = PASS; + ItemTemplate const *proto = sObjectMgr->GetItemTemplate(itemId); + if (!proto) + continue; + ItemUsage usage = AI_VALUE2(ItemUsage, "item usage", itemId); + switch (proto->Class) + { + case ITEM_CLASS_WEAPON: + case ITEM_CLASS_ARMOR: + if (usage == ITEM_USAGE_EQUIP || usage == ITEM_USAGE_REPLACE) { + vote = NEED; + } + else if (usage != ITEM_USAGE_NONE) { + vote = GREED; + } + break; + default: + if (StoreLootAction::IsLootAllowed(itemId, botAI)) + vote = NEED; + break; + } + if (sPlayerbotAIConfig->lootRollLevel == 0) { + vote = PASS; + } else if (sPlayerbotAIConfig->lootRollLevel == 1) { + if (vote == NEED) { + vote = GREED; + } else if (vote == GREED) { + vote = PASS; + } + } + switch (group->GetLootMethod()) + { + case MASTER_LOOT: + case FREE_FOR_ALL: + group->CountRollVote(bot->GetGUID(), guid, PASS); + break; + default: + group->CountRollVote(bot->GetGUID(), guid, vote); + break; + } + } + // WorldPacket p(event.getPacket()); //WorldPacket packet for CMSG_LOOT_ROLL, (8+4+1) + // p.rpos(0); //reset packet pointer + // p >> guid; //guid of the item rolled + // p >> slot; //number of players invited to roll + // p >> rollType; //need,greed or pass on roll - RollVote vote = PASS; // std::vector rolls = group->GetRolls(); // bot->Say("guid:" + std::to_string(guid.GetCounter()) + @@ -74,17 +122,6 @@ bool LootRollAction::Execute(Event event) // } // } - switch (group->GetLootMethod()) - { - case MASTER_LOOT: - case FREE_FOR_ALL: - group->CountRollVote(bot->GetGUID(), guid, PASS); - break; - default: - group->CountRollVote(bot->GetGUID(), guid, vote); - break; - } - return true; }