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);

View File

@@ -141,7 +141,7 @@ private:
void Prepare();
// void InitSecondEquipmentSet();
// void InitEquipmentNew(bool incremental);
bool CanEquipItem(ItemTemplate const* proto, uint32 desiredQuality);
bool CanEquipItem(ItemTemplate const* proto);
bool CanEquipUnseenItem(uint8 slot, uint16& dest, uint32 item);
void InitTradeSkills();
void UpdateTradeSkills();

View File

@@ -89,13 +89,21 @@ void StatsCollector::CollectSpellStats(uint32 spellId, float multiplier, int32 s
bool canNextTrigger = true;
uint32 procFlags;
uint32 procChance;
if (eventEntry && eventEntry->procFlags)
procFlags = eventEntry->procFlags;
else
procFlags = spellInfo->ProcFlags;
if (procFlags && !CanBeTriggeredByType(spellInfo, procFlags))
if (eventEntry && eventEntry->customChance)
procChance = eventEntry->customChance;
else
procChance = spellInfo->ProcChance;
bool lowChance = procChance <= 5;
if (lowChance || (procFlags && !CanBeTriggeredByType(spellInfo, procFlags)))
canNextTrigger = false;
if (spellInfo->StackAmount)
{
// Heuristic multiplier for spell with stackAmount since high stackAmount may not be available

View File

@@ -13,7 +13,8 @@
((1 << ITEM_SUBCLASS_WEAPON_AXE) | (1 << ITEM_SUBCLASS_WEAPON_MACE) | (1 << ITEM_SUBCLASS_WEAPON_SWORD) | \
(1 << ITEM_SUBCLASS_WEAPON_DAGGER) | (1 << ITEM_SUBCLASS_WEAPON_FIST))
enum StatsOverflowThreshold {
enum StatsOverflowThreshold
{
SPELL_HIT_OVERFLOW = 17,
MELEE_HIT_OVERFLOW = 8,
RANGED_HIT_OVERFLOW = 8,
@@ -30,6 +31,10 @@ public:
float CalculateItem(uint32 itemId);
float CalculateEnchant(uint32 enchantId);
void SetOverflowPenalty(bool apply) { enable_overflow_penalty_ = apply; }
void SetItemSetBonus(bool apply) { enable_item_set_bonus_ = apply; }
void SetQualityBlend(bool apply) { enable_quality_blend_ = apply; }
private:
void GenerateWeights(Player* player);
void GenerateBasicWeights(Player* player);
@@ -53,7 +58,7 @@ private:
bool enable_overflow_penalty_;
bool enable_item_set_bonus_;
bool enable_quality_blend_;
float weight_;
float stats_weights_[STATS_TYPE_MAX];
};