Add quest rewards to gear initialization

This commit is contained in:
Yunfan Li
2024-08-19 18:46:23 +08:00
parent 0be18889e5
commit 1700a20c89
9 changed files with 151 additions and 122 deletions

View File

@@ -1264,14 +1264,11 @@ bool PlayerbotFactory::CanEquipWeapon(ItemTemplate const* proto)
return true;
}
bool PlayerbotFactory::CanEquipItem(ItemTemplate const* proto, uint32 desiredQuality)
bool PlayerbotFactory::CanEquipItem(ItemTemplate const* proto)
{
if (proto->Duration != 0)
return false;
if (proto->Quality != desiredQuality)
return false;
if (proto->Bonding == BIND_QUEST_ITEM /*|| proto->Bonding == BIND_WHEN_USE*/)
return false;
@@ -1279,29 +1276,15 @@ bool PlayerbotFactory::CanEquipItem(ItemTemplate const* proto, uint32 desiredQua
return true;
uint32 requiredLevel = proto->RequiredLevel;
if (!requiredLevel)
bool hasItem = bot->HasItemCount(proto->ItemId, 1, true);
// bot->GetItemCount()
// !requiredLevel -> it's a quest reward item
if (!requiredLevel && hasItem)
return false;
uint32 level = bot->GetLevel();
uint32 delta = 2;
if (level < 15)
delta = std::min(level, 15u); // urand(7, 15);
// else if (proto->Class == ITEM_CLASS_WEAPON || proto->SubClass == ITEM_SUBCLASS_ARMOR_SHIELD)
// delta = urand(2, 3);
// else if (!(level % 10) || (level % 10) == 9)
// delta = 2;
else if (level < 40)
delta = 10; // urand(5, 10);
else if (level < 60)
delta = 6; // urand(3, 7);
else if (level < 70)
delta = 9; // urand(2, 5);
else if (level < 80)
delta = 9; // urand(2, 4);
else if (level == 80)
delta = 9; // urand(2, 4);
if (desiredQuality > ITEM_QUALITY_NORMAL && (requiredLevel > level || requiredLevel < level - delta))
if (requiredLevel > level)
return false;
return true;
@@ -1493,7 +1476,6 @@ void PlayerbotFactory::InitEquipment(bool incremental)
}
do
{
ItemTemplateContainer const* itemTemplate = sObjectMgr->GetItemTemplateStore();
for (uint32 requiredLevel = bot->GetLevel(); requiredLevel > std::max((int32)bot->GetLevel() - delta, 0);
requiredLevel--)
{
@@ -1528,9 +1510,12 @@ void PlayerbotFactory::InitEquipment(bool incremental)
if (proto->Class != ITEM_CLASS_WEAPON && proto->Class != ITEM_CLASS_ARMOR)
continue;
if (!CanEquipItem(proto, desiredQuality))
if (proto->Quality != desiredQuality)
continue;
if (!CanEquipItem(proto))
continue;
if (proto->Class == ITEM_CLASS_ARMOR &&
(slot == EQUIPMENT_SLOT_HEAD || slot == EQUIPMENT_SLOT_SHOULDERS ||
slot == EQUIPMENT_SLOT_CHEST || slot == EQUIPMENT_SLOT_WAIST ||
@@ -1595,6 +1580,11 @@ void PlayerbotFactory::InitEquipment(bool incremental)
uint32 newItemId = ids[index];
uint16 dest;
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(newItemId);
if (!CanEquipItem(proto))
continue;
if (oldItem && oldItem->GetTemplate()->ItemId == newItemId)
continue;
@@ -1609,36 +1599,12 @@ void PlayerbotFactory::InitEquipment(bool incremental)
bestItemForSlot = newItemId;
}
}
// for (int attempts = 0; attempts < std::max((int)(ids.size() * 0.75), 1); attempts++)
// {
// uint32 index = urand(0, ids.size() - 1);
// uint32 newItemId = ids[index];
// uint16 dest;
// if (oldItem && oldItem->GetTemplate()->ItemId == newItemId)
// continue;
// if (!CanEquipUnseenItem(slot, dest, newItemId))
// continue;
// float cur_score = calculator.CalculateItem(newItemId);
// if (cur_score > bestScoreForSlot)
// {
// bestScoreForSlot = cur_score;
// bestItemForSlot = newItemId;
// }
// }
if (bestItemForSlot == 0)
{
continue;
}
if (oldItem)
{
// uint8 dstBag = NULL_BAG;
// WorldPacket packet(CMSG_AUTOSTORE_BAG_ITEM, 3);
// packet << INVENTORY_SLOT_BAG_0 << slot << dstBag;
// bot->GetSession()->HandleAutoStoreBagItemOpcode(packet);
bot->DestroyItem(INVENTORY_SLOT_BAG_0, slot, true);
}
uint16 dest;
@@ -3334,8 +3300,11 @@ void PlayerbotFactory::InitInventoryEquip()
if (proto->Class == ITEM_CLASS_WEAPON && !CanEquipWeapon(proto))
continue;
if (!CanEquipItem(proto, desiredQuality))
if (proto->Quality != desiredQuality)
continue;
if (!CanEquipItem(proto))
continue;
ids.push_back(itr.first);