Item usage and equip initialization

This commit is contained in:
Yunfan Li
2024-09-04 18:08:19 +08:00
parent 5de242e80b
commit 484a2ae458
4 changed files with 63 additions and 29 deletions

View File

@@ -845,6 +845,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
if (!strncmp(cmd, "initself=", 9)) if (!strncmp(cmd, "initself=", 9))
{ {
if (!strcmp(cmd, "initself=uncommon"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_UNCOMMON);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
if (!strcmp(cmd, "initself=rare")) if (!strcmp(cmd, "initself=rare"))
{ {
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER) if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
@@ -877,6 +893,22 @@ std::vector<std::string> PlayerbotHolder::HandlePlayerbotCommand(char const* arg
return messages; return messages;
} }
} }
if (!strcmp(cmd, "initself=legendary"))
{
if (master->GetSession()->GetSecurity() >= SEC_GAMEMASTER)
{
// OnBotLogin(master);
PlayerbotFactory factory(master, master->GetLevel(), ITEM_QUALITY_LEGENDARY);
factory.Randomize(false);
messages.push_back("initself ok");
return messages;
}
else
{
messages.push_back("ERROR: Only GM can use this command.");
return messages;
}
}
int32 gs; int32 gs;
if (sscanf(cmd, "initself=%d", &gs) != -1) if (sscanf(cmd, "initself=%d", &gs) != -1)
{ {

View File

@@ -614,7 +614,6 @@ void PlayerbotFactory::InitPetTalents()
} }
std::unordered_map<uint32, std::vector<TalentEntry const*>> spells; std::unordered_map<uint32, std::vector<TalentEntry const*>> spells;
bool diveTypePet = (1LL << ci->family) & diveMask; bool diveTypePet = (1LL << ci->family) & diveMask;
LOG_INFO("playerbots", "DIVEMASK:{}", diveMask);
for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i) for (uint32 i = 0; i < sTalentStore.GetNumRows(); ++i)
{ {
@@ -1513,7 +1512,7 @@ void Shuffle(std::vector<uint32>& items)
// } // }
// } // }
void PlayerbotFactory::InitEquipment(bool incremental) void PlayerbotFactory::InitEquipment(bool incremental, bool second_chance)
{ {
std::unordered_map<uint8, std::vector<uint32>> items; std::unordered_map<uint8, std::vector<uint32>> items;
// int tab = AiFactory::GetPlayerSpecTab(bot); // int tab = AiFactory::GetPlayerSpecTab(bot);
@@ -1553,16 +1552,13 @@ void PlayerbotFactory::InitEquipment(bool incremental)
Item* oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot); Item* oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
if (!incremental && oldItem) if (second_chance && oldItem)
{
continue;
}
if (oldItem)
{ {
bot->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true); bot->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true);
} }
oldItem = bot->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
uint32 desiredQuality = itemQuality; uint32 desiredQuality = itemQuality;
if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL) if (urand(0, 100) < 100 * sPlayerbotAIConfig->randomGearLoweringChance && desiredQuality > ITEM_QUALITY_NORMAL)
{ {
@@ -1668,17 +1664,38 @@ void PlayerbotFactory::InitEquipment(bool incremental)
bestItemForSlot = newItemId; bestItemForSlot = newItemId;
} }
} }
if (bestItemForSlot == 0) if (bestItemForSlot == 0)
{ {
continue; continue;
} }
uint16 dest; uint16 dest;
if (!CanEquipUnseenItem(slot, dest, bestItemForSlot)) if (!CanEquipUnseenItem(slot, dest, bestItemForSlot))
{ {
continue; continue;
} }
if (incremental && oldItem)
{
float old_score = calculator.CalculateItem(oldItem->GetEntry());
if (bestScoreForSlot < 1.2f * old_score)
continue;
}
if (oldItem)
{
uint8 bagIndex = oldItem->GetBagSlot();
uint8 slot = oldItem->GetSlot();
uint8 dstBag = NULL_BAG;
WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3);
packet << bagIndex << slot << dstBag;
bot->GetSession()->HandleAutoStoreBagItemOpcode(packet);
}
Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true); Item* newItem = bot->EquipNewItem(dest, bestItemForSlot, true);
bot->AutoUnequipOffhandIfNeed();
// bot->AutoUnequipOffhandIfNeed();
if (newItem) if (newItem)
{ {
newItem->AddToWorld(); newItem->AddToWorld();
@@ -1686,25 +1703,10 @@ void PlayerbotFactory::InitEquipment(bool incremental)
} }
} }
// secondary init for better equips // secondary init for better equips
if (!incremental) if (!incremental && !second_chance)
InitEquipment(true); InitEquipment(incremental, true);
// for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot)
// {
// if (slot == EQUIPMENT_SLOT_TABARD || slot == EQUIPMENT_SLOT_BODY)
// continue;
// if (level < 40 && (slot == EQUIPMENT_SLOT_TRINKET1 || slot == EQUIPMENT_SLOT_TRINKET2))
// continue;
// if (level < 25 && slot == EQUIPMENT_SLOT_NECK)
// continue;
// if (level < 25 && slot == EQUIPMENT_SLOT_HEAD)
// continue;
// }
} }
bool PlayerbotFactory::IsDesiredReplacement(Item* item) bool PlayerbotFactory::IsDesiredReplacement(Item* item)
@@ -1978,7 +1980,7 @@ bool PlayerbotFactory::CanEquipUnseenItem(uint8 slot, uint16& dest, uint32 item)
if (Item* pItem = Item::CreateItem(item, 1, bot, false, 0, true)) if (Item* pItem = Item::CreateItem(item, 1, bot, false, 0, true))
{ {
InventoryResult result = bot->CanEquipItem(slot, dest, pItem, true, false); InventoryResult result = botAI->CanEquipItem(slot, dest, pItem, true, true);
pItem->RemoveFromUpdateQueueOf(bot); pItem->RemoveFromUpdateQueueOf(bot);
delete pItem; delete pItem;
return result == EQUIP_ERR_OK; return result == EQUIP_ERR_OK;

View File

@@ -122,7 +122,7 @@ public:
static void InitTalentsByParsedSpecLink(Player* bot, std::vector<std::vector<uint32>> parsedSpecLink, bool reset); static void InitTalentsByParsedSpecLink(Player* bot, std::vector<std::vector<uint32>> parsedSpecLink, bool reset);
void InitAvailableSpells(); void InitAvailableSpells();
void InitClassSpells(); void InitClassSpells();
void InitEquipment(bool incremental); void InitEquipment(bool incremental, bool second_chance = false);
void InitPet(); void InitPet();
void InitAmmo(); void InitAmmo();
static uint32 CalcMixedGearScore(uint32 gs, uint32 quality); static uint32 CalcMixedGearScore(uint32 gs, uint32 quality);

View File

@@ -166,7 +166,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemTemplate const* itemProto)
return ITEM_USAGE_NONE; return ITEM_USAGE_NONE;
uint16 dest; uint16 dest;
InventoryResult result = botAI->CanEquipItem(NULL_SLOT, dest, pItem, true, false); InventoryResult result = botAI->CanEquipItem(NULL_SLOT, dest, pItem, true, true);
pItem->RemoveFromUpdateQueueOf(bot); pItem->RemoveFromUpdateQueueOf(bot);
delete pItem; delete pItem;