mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-06-20 15:39:25 +02:00
<!-- Thank you for contributing to mod-playerbots, please make sure that you... 1. Submit your PR to the test-staging branch, not master. 2. Read the guidelines below before submitting. 3. Don't delete parts of this template. DESIGN PHILOSOPHY: We prioritize STABILITY, PERFORMANCE, AND PREDICTABILITY over behavioral realism. Every action and decision executes PER BOT AND PER TRIGGER. Small increases in logic complexity scale poorly across thousands of bots and negatively affect all. We prioritize a stable system over a smarter one. Bots don't need to behave perfectly; believable behavior is the goal, not human simulation. Default behavior must be cheap in processing; expensive behavior must be opt-in. Before submitting, make sure your changes aligns with these principles. --> ## Pull Request Description Suffix scoring was already wired up in playerbots, bots could evaluate suffix items they owned, but factory init scored candidates with randomPropertyId = 0 and equipped via EquipNewItem which doesn't roll suffixes, so suffix items always looked like junk and never got picked. Added a cached item_enchantment_template pool in RandomItemMgr, a PickBestRandomPropertyId helper that picks the best suffix per bot class/spec, and added it on the equipped item via SetItemRandomProperties. Tested levels 20-80, suffixes match spec. Closes #2370. ## Feature Evaluation <!-- If your PR is very minimal (comment typo, wrong ID reference, etc), and it is very obvious it will not have any impact on performance, you may skip these question. If necessary, a maintainer may ask you for them later. --> <!-- Please answer the following: --> - Describe the **minimum logic** required to achieve the intended behavior. For items with RandomProperty != 0 or RandomSuffix != 0, run the item_enchantment_template pool once, score each candidate suffix against the bot's existing class/spec stat weights, keep the highest, and stamp that id on the item right after EquipNewItem. Items without a suffix pool skip the helper entirely. Without this, every suffix template scores as base stats only (often near zero) and never gets picked during factory init. - Describe the **processing cost** when this logic executes across many bots. Startup: one SELECT entry, ench FROM item_enchantment_template (few hundred rows), parsed into an unordered_map<uint32, vector<uint32>> once. No SQL afterwards. Per bot during init: PickBestRandomPropertyId only runs on candidates that actually have a suffix pool. Each call is a hash lookup plus a loop over 5-15 enchantment ids, each doing DBC lookups already used by the scoring code. Cost is mostly by the existing CalculateRandomProperty work, not new logic. Scales linearly with bot count, same as the rest of factory init. No new per-tick work. ## How to Test the Changes 1. Generate a fresh random bot at level 20-79 and use autogear (cloth, leather, mail, plate, lots of suffix gear at that range). 2. Inspect the bot's gear. Items with names like "of the Eagle", "of the Monkey", "of Healing", etc... should be equipped, with the suffix stats visible on the tooltip. 3. Generate a level 80 bot at high gear-score limit. Confirm it still equips raid epics normally (epics have no suffix pool, so this path is untouched). ## Impact Assessment <!-- As a generic test, before and after measure of pmon (playerbot pmon tick) can help you here. --> - Does this change increase per-bot/per-tick processing or risk scaling poorly with thousands of bots? - - [x] No, not at all - - [ ] Minimal impact (**explain below**) - - [ ] Moderate impact (**explain below**) - Does this change modify default bot behavior? - - [ ] No - - [x] Yes (**explain why**) Bots now consider random-suffix items during factory init and equip them with the best suffix for their class/spec. Before, suffix items were effectively invisible to init autogear because they scored as base stats only. This is the intended fix for #2370. - Does this change add new decision branches or increase maintenance complexity? - - [ ] No - - [x] Yes (**explain below**) Added one new public method on StatsWeightCalculator (PickBestRandomPropertyId) and one new cache in RandomItemMgr (LoadEnchantmentPool + GetEnchantmentPool). The candidate list in InitEquipment changed from vector<uint32> to vector<pair<uint32, int32>> to carry the chosen suffix id alongside the item id. Logic mirrors existing patterns in the same files (DBC lookups, SQL-backed caches, signed randomPropertyId encoding), no new abstractions, no new wrappers. ## AI Assistance <!-- AI assistance is allowed, but all submitted code must be fully understood, reviewed, and owned by the contributor. We expect contributors to be honest about what they do and do not understand. --> Was AI assistance used while working on this change? - - [ ] No - - [x] Yes (**explain below**) Used AI to help me find the bug. It mapped the existing scoring pipeline and pointed out that PlayerbotFactory::InitEquipment was scoring candidates with randomPropertyId = 0 and equipping via EquipNewItem (which doesn't roll suffixes), so the scoring side was already built, just never fed real suffix ids during init. I reviewed and tested all the code in-game across levels 20-80 and multiple classes/specs. <!-- TRANSLATIONS: Anything new that the bots say in chat must be in a translatable format. This is done using GetBotTextOrDefault, which you can search for in the codebase to find examples. Your code needs to have English as the default fallback, while the full translations need to be in an SQL update file. The languages in the file are the nine language options supported by AzerothCore: English, Korean, French, German, Chinese, Taiwanese, Spanish, Spanish Mexico, and Russian. See data/sql/playerbots/updates/2025_12_27_ai_playerbot_fishing_text.sql as an example of a translation SQL update, whose content are called within the codebase at src/strategy/actions/FishingAction.cpp --> ## Final Checklist - - [x] Stability is not compromised. - - [x] Performance impact is understood, tested, and acceptable. - - [x] Added logic complexity is justified and explained. - - [x] Any new bot dialogue lines are translated. - - [x] Documentation updated if needed (Conf comments, WiKi commands). ## Notes for Reviewers <!-- Anything else that's helpful to review or test your pull request. --> --------- Co-authored-by: Keleborn <22352763+Celandriel@users.noreply.github.com> Co-authored-by: bash <hermensb@gmail.com> Co-authored-by: Revision <tkn963@gmail.com> Co-authored-by: kadeshar <kadeshar@gmail.com>
1003 lines
37 KiB
C++
1003 lines
37 KiB
C++
/*
|
||
* Copyright (C) 2016+ AzerothCore <www.azerothcore.org>, released under GNU AGPL v3 license, you may redistribute it
|
||
* and/or modify it under version 3 of the License, or (at your option), any later version.
|
||
*/
|
||
|
||
#include "StatsWeightCalculator.h"
|
||
|
||
#include <memory>
|
||
|
||
#include "AiFactory.h"
|
||
#include "DBCStores.h"
|
||
#include "ItemEnchantmentMgr.h"
|
||
#include "ItemTemplate.h"
|
||
#include "ObjectMgr.h"
|
||
#include "PlayerbotAI.h"
|
||
#include "PlayerbotFactory.h"
|
||
#include "RandomItemMgr.h"
|
||
#include "SharedDefines.h"
|
||
#include "SpellAuraDefines.h"
|
||
#include "SpellMgr.h"
|
||
#include "StatsCollector.h"
|
||
#include "Unit.h"
|
||
|
||
namespace
|
||
{
|
||
constexpr uint32 SPELL_MOLTEN_ARMOR_RANK_1 = 30482;
|
||
constexpr uint32 SPELL_MOLTEN_ARMOR_RANK_2 = 43045;
|
||
constexpr uint32 SPELL_MOLTEN_ARMOR_RANK_3 = 43046;
|
||
constexpr uint32 SPELL_FEL_ARMOR_RANK_1 = 28176;
|
||
constexpr uint32 SPELL_FEL_ARMOR_RANK_2 = 28189;
|
||
constexpr uint32 SPELL_FEL_ARMOR_RANK_3 = 47892;
|
||
constexpr uint32 SPELL_FEL_ARMOR_RANK_4 = 47893;
|
||
}
|
||
|
||
StatsWeightCalculator::StatsWeightCalculator(Player* player) : player_(player)
|
||
{
|
||
if (PlayerbotAI::IsHeal(player))
|
||
type_ = CollectorType::SPELL_HEAL;
|
||
else if (PlayerbotAI::IsCaster(player))
|
||
type_ = CollectorType::SPELL_DMG;
|
||
else if (PlayerbotAI::IsTank(player))
|
||
type_ = CollectorType::MELEE_TANK;
|
||
else if (PlayerbotAI::IsMelee(player))
|
||
type_ = CollectorType::MELEE_DMG;
|
||
else
|
||
type_ = CollectorType::RANGED;
|
||
cls = player->getClass();
|
||
lvl = player->GetLevel();
|
||
tab = AiFactory::GetPlayerSpecTab(player);
|
||
collector_ = std::make_unique<StatsCollector>(type_, cls);
|
||
|
||
if (cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_UNHOLY)
|
||
hitOverflowType_ = CollectorType::SPELL;
|
||
else if (cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ENHANCEMENT)
|
||
hitOverflowType_ = CollectorType::SPELL;
|
||
else if (cls == CLASS_ROGUE)
|
||
hitOverflowType_ = CollectorType::SPELL;
|
||
else
|
||
hitOverflowType_ = type_;
|
||
|
||
enable_overflow_penalty_ = true;
|
||
enable_item_set_bonus_ = true;
|
||
enable_quality_blend_ = true;
|
||
}
|
||
|
||
void StatsWeightCalculator::Reset()
|
||
{
|
||
collector_->Reset();
|
||
weight_ = 0;
|
||
for (uint32 i = 0; i < STATS_TYPE_MAX; i++)
|
||
{
|
||
stats_weights_[i] = 0;
|
||
}
|
||
}
|
||
|
||
float StatsWeightCalculator::CalculateItem(uint32 itemId, int32 randomPropertyIds, int32 slot)
|
||
{
|
||
ItemTemplate const* proto = &sObjectMgr->GetItemTemplateStore()->at(itemId);
|
||
|
||
if (!proto)
|
||
return 0.0f;
|
||
|
||
Reset();
|
||
|
||
collector_->CollectItemStats(proto);
|
||
|
||
if (randomPropertyIds != 0)
|
||
CalculateRandomProperty(randomPropertyIds, itemId);
|
||
|
||
if (enable_overflow_penalty_)
|
||
ApplyOverflowPenalty(player_);
|
||
|
||
GenerateWeights(player_);
|
||
for (uint32 i = 0; i < STATS_TYPE_MAX; i++)
|
||
{
|
||
weight_ += stats_weights_[i] * collector_->stats[i];
|
||
}
|
||
|
||
CalculateItemTypePenalty(proto);
|
||
|
||
if (enable_item_set_bonus_)
|
||
CalculateItemSetMod(player_, proto);
|
||
|
||
CalculateSocketBonus(player_, proto);
|
||
|
||
if (enable_quality_blend_)
|
||
{
|
||
// Heirloom items scale with player level
|
||
// Use player level as effective item level for heirlooms - Quality EPIC
|
||
// Else - Blend with item quality and level for normal items
|
||
if (proto->Quality == ITEM_QUALITY_HEIRLOOM)
|
||
weight_ *= PlayerbotFactory::CalcMixedGearScore(lvl, ITEM_QUALITY_EPIC);
|
||
else
|
||
weight_ *= PlayerbotFactory::CalcMixedGearScore(proto->ItemLevel, proto->Quality);
|
||
}
|
||
|
||
// Apply weapon speed governance if slot is provided and this is a weapon
|
||
if (sPlayerbotAIConfig.preferredSpecWeapons && slot >= 0 && proto->Class == ITEM_CLASS_WEAPON)
|
||
weight_ *= ApplyPreferredSpecWeapons(proto, slot);
|
||
|
||
return weight_;
|
||
}
|
||
|
||
float StatsWeightCalculator::CalculateEnchant(uint32 enchantId)
|
||
{
|
||
SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);
|
||
|
||
if (!enchant)
|
||
return 0.0f;
|
||
|
||
Reset();
|
||
|
||
collector_->CollectEnchantStats(enchant);
|
||
|
||
if (enable_overflow_penalty_)
|
||
ApplyOverflowPenalty(player_);
|
||
|
||
GenerateWeights(player_);
|
||
for (uint32 i = 0; i < STATS_TYPE_MAX; i++)
|
||
{
|
||
weight_ += stats_weights_[i] * collector_->stats[i];
|
||
}
|
||
|
||
return weight_;
|
||
}
|
||
|
||
void StatsWeightCalculator::CalculateRandomProperty(int32 randomPropertyId, uint32 itemId)
|
||
{
|
||
if (randomPropertyId > 0)
|
||
{
|
||
ItemRandomPropertiesEntry const* item_rand = sItemRandomPropertiesStore.LookupEntry(randomPropertyId);
|
||
if (!item_rand)
|
||
{
|
||
return;
|
||
}
|
||
|
||
for (uint32 i = PROP_ENCHANTMENT_SLOT_0; i < MAX_ENCHANTMENT_SLOT; ++i)
|
||
{
|
||
uint32 enchantId = item_rand->Enchantment[i - PROP_ENCHANTMENT_SLOT_0];
|
||
SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);
|
||
if (enchant)
|
||
collector_->CollectEnchantStats(enchant);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
ItemRandomSuffixEntry const* item_rand = sItemRandomSuffixStore.LookupEntry(-randomPropertyId);
|
||
if (!item_rand)
|
||
{
|
||
return;
|
||
}
|
||
|
||
for (uint32 i = PROP_ENCHANTMENT_SLOT_0; i < MAX_ENCHANTMENT_SLOT; ++i)
|
||
{
|
||
uint32 enchantId = item_rand->Enchantment[i - PROP_ENCHANTMENT_SLOT_0];
|
||
SpellItemEnchantmentEntry const* enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);
|
||
uint32 enchant_amount = 0;
|
||
|
||
for (int k = 0; k < MAX_ITEM_ENCHANTMENT_EFFECTS; ++k)
|
||
{
|
||
if (item_rand->Enchantment[k] == enchantId)
|
||
{
|
||
enchant_amount = uint32((item_rand->AllocationPct[k] * GenerateEnchSuffixFactor(itemId)) / 10000);
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (enchant)
|
||
collector_->CollectEnchantStats(enchant, enchant_amount);
|
||
}
|
||
}
|
||
}
|
||
|
||
int32 StatsWeightCalculator::PickBestRandomPropertyId(uint32 itemId)
|
||
{
|
||
ItemTemplate const* proto = sObjectMgr->GetItemTemplate(itemId);
|
||
if (!proto)
|
||
return 0;
|
||
|
||
bool isSuffix = false;
|
||
uint32 poolEntry = proto->RandomProperty;
|
||
if (!poolEntry)
|
||
{
|
||
poolEntry = proto->RandomSuffix;
|
||
isSuffix = true;
|
||
}
|
||
if (!poolEntry)
|
||
return 0;
|
||
|
||
std::vector<uint32> const& pool = sRandomItemMgr.GetEnchantmentPool(poolEntry);
|
||
if (pool.empty())
|
||
return 0;
|
||
|
||
Reset();
|
||
GenerateWeights(player_);
|
||
|
||
int32 bestId = 0;
|
||
float bestScore = 0.0f;
|
||
for (uint32 enchId : pool)
|
||
{
|
||
int32 candidate = isSuffix ? -static_cast<int32>(enchId) : static_cast<int32>(enchId);
|
||
|
||
collector_->Reset();
|
||
CalculateRandomProperty(candidate, itemId);
|
||
|
||
float score = 0.0f;
|
||
for (uint32 i = 0; i < STATS_TYPE_MAX; ++i)
|
||
score += stats_weights_[i] * collector_->stats[i];
|
||
|
||
if (bestId == 0 || score > bestScore)
|
||
{
|
||
bestId = candidate;
|
||
bestScore = score;
|
||
}
|
||
}
|
||
|
||
collector_->Reset();
|
||
return bestId;
|
||
}
|
||
|
||
void StatsWeightCalculator::GenerateWeights(Player* player)
|
||
{
|
||
GenerateBasicWeights(player);
|
||
GenerateAdditionalWeights(player);
|
||
ApplyWeightFinetune(player);
|
||
}
|
||
|
||
void StatsWeightCalculator::GenerateBasicWeights(Player* player)
|
||
{
|
||
// Basic weights
|
||
stats_weights_[STATS_TYPE_STAMINA] += 0.1f;
|
||
stats_weights_[STATS_TYPE_ARMOR] += 0.001f;
|
||
stats_weights_[STATS_TYPE_BONUS] += 1.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 0.01f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 0.01f;
|
||
|
||
if (cls == CLASS_HUNTER && (tab == HUNTER_TAB_BEAST_MASTERY || tab == HUNTER_TAB_SURVIVAL))
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.5f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.7f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.4f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.6f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 7.5f;
|
||
}
|
||
else if (cls == CLASS_HUNTER && tab == HUNTER_TAB_MARKSMANSHIP)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 2.3f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 2.25f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 2.0f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.8f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 10.0f;
|
||
}
|
||
else if (cls == CLASS_ROGUE && tab == ROGUE_TAB_COMBAT)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 1.9f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 1.1f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.8f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.4f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.7f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 7.0f;
|
||
}
|
||
else if (cls == CLASS_DRUID && tab == DRUID_TAB_FERAL && !PlayerbotAI::IsTank(player))
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 2.2f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.4f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 2.3f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.9f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.5f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 2.1f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.1f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 15.0f;
|
||
}
|
||
else if (cls == CLASS_ROGUE && (tab == ROGUE_TAB_ASSASSINATION || tab == ROGUE_TAB_SUBTLETY))
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 1.5f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 1.1f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.2f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.1f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.8f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.1f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 5.0f;
|
||
}
|
||
else if (cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.8f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.8f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 2.1f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.3f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 2.2f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 0.8f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 2.0f;
|
||
stats_weights_[STATS_TYPE_DEFENSE] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.5f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 7.0f;
|
||
}
|
||
else if (cls == CLASS_WARRIOR && tab == WARRIOR_TAB_ARMS)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.8f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.8f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.7f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.0f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.9f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 0.8f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 2.0f;
|
||
stats_weights_[STATS_TYPE_DEFENSE] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 1.4f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 7.0f;
|
||
}
|
||
else if (cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_FROST)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.5f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.5f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 2.7f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.3f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 2.2f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 2.1f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.5f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 7.0f;
|
||
}
|
||
else if (cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_UNHOLY)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.5f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.5f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.3f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.2f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.7f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.8f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 1.5f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 5.0f;
|
||
}
|
||
else if (cls == CLASS_PALADIN && tab == PALADIN_TAB_RETRIBUTION)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.5f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.5f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.5f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 1.5f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.9f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.7f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.6f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 9.0f;
|
||
}
|
||
else if ((cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ENHANCEMENT))
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 1.4f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 1.1f;
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.3f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] += 0.5f;
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] += 0.9f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.5f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.8f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 8.5f;
|
||
}
|
||
else if (cls == CLASS_WARLOCK ||
|
||
(cls == CLASS_MAGE && tab != MAGE_TAB_FIRE) ||
|
||
(cls == CLASS_PRIEST && tab == PRIEST_TAB_SHADOW) ||
|
||
(cls == CLASS_DRUID && tab == DRUID_TAB_BALANCE))
|
||
{
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.3f;
|
||
stats_weights_[STATS_TYPE_SPIRIT] += 0.6f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 0.8f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 1.0f;
|
||
}
|
||
else if (cls == CLASS_MAGE && tab == MAGE_TAB_FIRE)
|
||
{
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.3f;
|
||
stats_weights_[STATS_TYPE_SPIRIT] += 0.7f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.2f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.1f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 0.8f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 1.0f;
|
||
}
|
||
else if (cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ELEMENTAL)
|
||
{
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.5f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] += 1.2f;
|
||
stats_weights_[STATS_TYPE_HIT] += 1.1f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 0.8f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 1.0f;
|
||
stats_weights_[STATS_TYPE_MANA_REGENERATION] += 0.5f;
|
||
}
|
||
else if ((cls == CLASS_PALADIN && tab == PALADIN_TAB_HOLY) ||
|
||
(cls == CLASS_SHAMAN && tab == SHAMAN_TAB_RESTORATION))
|
||
{
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.9f;
|
||
stats_weights_[STATS_TYPE_SPIRIT] += 0.15f;
|
||
stats_weights_[STATS_TYPE_HEAL_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_MANA_REGENERATION] += 0.9f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 0.6f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 0.8f;
|
||
}
|
||
else if ((cls == CLASS_PRIEST && tab != PRIEST_TAB_SHADOW) ||
|
||
(cls == CLASS_DRUID && tab == DRUID_TAB_RESTORATION))
|
||
{
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 0.8f;
|
||
stats_weights_[STATS_TYPE_SPIRIT] += 0.6f;
|
||
stats_weights_[STATS_TYPE_HEAL_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_MANA_REGENERATION] += 0.9f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 0.6f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 0.8f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_RANGED_DPS] += 1.0f;
|
||
}
|
||
else if ((cls == CLASS_WARRIOR && tab == WARRIOR_TAB_PROTECTION) ||
|
||
(cls == CLASS_PALADIN && tab == PALADIN_TAB_PROTECTION))
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.2f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 1.3f;
|
||
stats_weights_[STATS_TYPE_STAMINA] += 3.0f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.2f;
|
||
stats_weights_[STATS_TYPE_DEFENSE] += 2.5f;
|
||
stats_weights_[STATS_TYPE_PARRY] += 2.0f;
|
||
stats_weights_[STATS_TYPE_DODGE] += 2.0f;
|
||
// stats_weights_[STATS_TYPE_RESILIENCE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_BLOCK_RATING] += 1.0f;
|
||
stats_weights_[STATS_TYPE_BLOCK_VALUE] += 0.5f;
|
||
stats_weights_[STATS_TYPE_ARMOR] += 0.15f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.0f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 2.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 3.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 2.0f;
|
||
}
|
||
else if (cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_BLOOD)
|
||
{
|
||
stats_weights_[STATS_TYPE_AGILITY] += 0.2f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 1.3f;
|
||
stats_weights_[STATS_TYPE_STAMINA] += 3.0f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 0.2f;
|
||
stats_weights_[STATS_TYPE_DEFENSE] += 2.5f;
|
||
stats_weights_[STATS_TYPE_PARRY] += 2.0f;
|
||
stats_weights_[STATS_TYPE_DODGE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_BLOCK_RATING] -= 2.0f;
|
||
stats_weights_[STATS_TYPE_BLOCK_VALUE] -= 2.0f;
|
||
// stats_weights_[STATS_TYPE_RESILIENCE] += 2.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR] += 0.15f;
|
||
stats_weights_[STATS_TYPE_HIT] += 2.0f;
|
||
stats_weights_[STATS_TYPE_SPELL_POWER] -= 1.0f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 3.0f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 2.0f;
|
||
}
|
||
else
|
||
{
|
||
// BEAR DRUID TANK
|
||
stats_weights_[STATS_TYPE_AGILITY] += 2.2f;
|
||
stats_weights_[STATS_TYPE_STRENGTH] += 2.4f;
|
||
stats_weights_[STATS_TYPE_STAMINA] += 4.0f;
|
||
stats_weights_[STATS_TYPE_ATTACK_POWER] += 1.0f;
|
||
stats_weights_[STATS_TYPE_DEFENSE] += 0.3f;
|
||
stats_weights_[STATS_TYPE_DODGE] += 0.7f;
|
||
// stats_weights_[STATS_TYPE_RESILIENCE] += 1.0f;
|
||
stats_weights_[STATS_TYPE_ARMOR] += 0.15f;
|
||
stats_weights_[STATS_TYPE_HIT] += 3.0f;
|
||
stats_weights_[STATS_TYPE_CRIT] += 1.3f;
|
||
stats_weights_[STATS_TYPE_HASTE] += 2.3f;
|
||
stats_weights_[STATS_TYPE_EXPERTISE] += 3.7f;
|
||
stats_weights_[STATS_TYPE_MELEE_DPS] += 3.0f;
|
||
}
|
||
}
|
||
|
||
void StatsWeightCalculator::GenerateAdditionalWeights(Player* player)
|
||
{
|
||
uint8 cls = player->getClass();
|
||
// int tab = AiFactory::GetPlayerSpecTab(player);
|
||
if (cls == CLASS_HUNTER)
|
||
{
|
||
if (player->HasAura(34484))
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 1.1f;
|
||
if (player->HasAura(56341))
|
||
stats_weights_[STATS_TYPE_STAMINA] += 0.3f;
|
||
}
|
||
else if (cls == CLASS_WARRIOR)
|
||
{
|
||
if (player->HasAura(61222))
|
||
stats_weights_[STATS_TYPE_ARMOR] += 0.03f;
|
||
}
|
||
else if (cls == CLASS_SHAMAN)
|
||
{
|
||
if (player->HasAura(51885))
|
||
stats_weights_[STATS_TYPE_INTELLECT] += 1.1f;
|
||
}
|
||
else if (cls == CLASS_MAGE)
|
||
{
|
||
if (!player->HasSpell(SPELL_MOLTEN_ARMOR_RANK_1)
|
||
&& !player->HasSpell(SPELL_MOLTEN_ARMOR_RANK_2)
|
||
&& !player->HasSpell(SPELL_MOLTEN_ARMOR_RANK_3))
|
||
{
|
||
if (tab != MAGE_TAB_FIRE)
|
||
stats_weights_[STATS_TYPE_SPIRIT] -= 0.6f;
|
||
else
|
||
stats_weights_[STATS_TYPE_SPIRIT] -= 0.7f;
|
||
}
|
||
}
|
||
else if (cls == CLASS_WARLOCK)
|
||
{
|
||
if (!player->HasSpell(SPELL_FEL_ARMOR_RANK_1) && !player->HasSpell(SPELL_FEL_ARMOR_RANK_2) &&
|
||
!player->HasSpell(SPELL_FEL_ARMOR_RANK_3) && !player->HasSpell(SPELL_FEL_ARMOR_RANK_4))
|
||
stats_weights_[STATS_TYPE_SPIRIT] -= 0.4f;
|
||
}
|
||
|
||
if (pvpSpec_ && !exclude_resilience_)
|
||
stats_weights_[STATS_TYPE_RESILIENCE] += 7.0f;
|
||
else if (!pvpSpec_)
|
||
stats_weights_[STATS_TYPE_RESILIENCE] -= 3.0f;
|
||
}
|
||
|
||
void StatsWeightCalculator::CalculateItemSetMod(Player* player, ItemTemplate const* proto)
|
||
{
|
||
uint32 itemSet = proto->ItemSet;
|
||
if (!itemSet)
|
||
return;
|
||
|
||
float multiplier = 1.0f;
|
||
size_t i = 0;
|
||
for (i = 0; i < player->ItemSetEff.size(); i++)
|
||
{
|
||
if (player->ItemSetEff[i])
|
||
{
|
||
ItemSetEffect* eff = player->ItemSetEff[i];
|
||
|
||
uint32 setId = eff->setid;
|
||
if (itemSet != setId)
|
||
continue;
|
||
|
||
const ItemSetEntry* setEntry = sItemSetStore.LookupEntry(setId);
|
||
if (!setEntry)
|
||
continue;
|
||
|
||
uint32 itemCount = eff->item_count;
|
||
uint32 max_items = 0;
|
||
for (size_t j = 0; j < MAX_ITEM_SET_SPELLS; j++)
|
||
max_items = std::max(max_items, setEntry->items_to_triggerspell[j]);
|
||
if (itemCount < max_items)
|
||
{
|
||
multiplier += 0.1f * itemCount; // 10% bonus for each item already equipped
|
||
}
|
||
else
|
||
{
|
||
multiplier = 1.0f; // All item set effect has been triggerred
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (i == player->ItemSetEff.size())
|
||
multiplier = 1.05f; // this is the first item in the item set
|
||
|
||
weight_ *= multiplier;
|
||
}
|
||
|
||
void StatsWeightCalculator::CalculateSocketBonus(Player* /*player*/, ItemTemplate const* proto)
|
||
{
|
||
uint32 socketNum = 0;
|
||
for (uint32 enchant_slot = SOCK_ENCHANTMENT_SLOT; enchant_slot < SOCK_ENCHANTMENT_SLOT + MAX_GEM_SOCKETS;
|
||
++enchant_slot)
|
||
{
|
||
uint8 socketColor = proto->Socket[enchant_slot - SOCK_ENCHANTMENT_SLOT].Color;
|
||
|
||
if (!socketColor) // no socket slot
|
||
continue;
|
||
|
||
socketNum++;
|
||
}
|
||
|
||
float multiplier = 1.0f + socketNum * 0.03f; // 3% bonus for socket
|
||
|
||
weight_ *= multiplier;
|
||
}
|
||
|
||
void StatsWeightCalculator::CalculateItemTypePenalty(ItemTemplate const* proto)
|
||
{
|
||
// // penalty for different type armor
|
||
// if (proto->Class == ITEM_CLASS_ARMOR && proto->SubClass >= ITEM_SUBCLASS_ARMOR_CLOTH &&
|
||
// proto->SubClass <= ITEM_SUBCLASS_ARMOR_PLATE && NotBestArmorType(proto->SubClass))
|
||
// {
|
||
// weight_ *= 1.0;
|
||
// }
|
||
if (proto->Class == ITEM_CLASS_WEAPON)
|
||
{
|
||
// double hand
|
||
bool isDoubleHand = proto->Class == ITEM_CLASS_WEAPON &&
|
||
!(ITEM_SUBCLASS_MASK_SINGLE_HAND & (1 << proto->SubClass)) &&
|
||
!(ITEM_SUBCLASS_MASK_WEAPON_RANGED & (1 << proto->SubClass));
|
||
|
||
if (isDoubleHand)
|
||
{
|
||
weight_ *= 0.5;
|
||
// spec without double hand
|
||
// enhancement, rogue, ice dk, unholy dk, shield tank, fury warrior without titan's grip but with duel wield
|
||
if (((cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ENHANCEMENT && player_->CanDualWield()) ||
|
||
(cls == CLASS_ROGUE) || (cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_FROST) ||
|
||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY && !player_->CanTitanGrip() &&
|
||
player_->CanDualWield()) ||
|
||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_PROTECTION) ||
|
||
(cls == CLASS_PALADIN && tab == PALADIN_TAB_PROTECTION) ||
|
||
(cls == CLASS_PALADIN && tab == PALADIN_TAB_HOLY)))
|
||
{
|
||
weight_ *= 0.1;
|
||
}
|
||
}
|
||
// spec with double hand
|
||
// fury without duel wield, arms, bear, retribution, blood dk
|
||
if (!isDoubleHand)
|
||
{
|
||
if ((cls == CLASS_HUNTER && !player_->CanDualWield()) ||
|
||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY && !player_->CanDualWield()) ||
|
||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_ARMS) || (cls == CLASS_DRUID && tab == DRUID_TAB_FERAL) ||
|
||
(cls == CLASS_PALADIN && tab == PALADIN_TAB_RETRIBUTION) ||
|
||
(cls == CLASS_DEATH_KNIGHT && tab == DEATH_KNIGHT_TAB_BLOOD) ||
|
||
(cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ENHANCEMENT && !player_->CanDualWield()))
|
||
{
|
||
weight_ *= 0.1;
|
||
}
|
||
// caster's main hand (cannot duel weapon but can equip two-hands stuff)
|
||
if ((cls == CLASS_MAGE || cls == CLASS_PRIEST || cls == CLASS_WARLOCK || cls == CLASS_DRUID ||
|
||
(cls == CLASS_SHAMAN && !player_->CanDualWield())) &&
|
||
!(cls == CLASS_PALADIN && tab == PALADIN_TAB_HOLY))
|
||
{
|
||
weight_ *= 0.65;
|
||
}
|
||
if (cls == CLASS_PALADIN && tab == PALADIN_TAB_HOLY)
|
||
{
|
||
weight_ *= 0.8;
|
||
}
|
||
}
|
||
// fury with titan's grip
|
||
if ((!isDoubleHand || proto->SubClass == ITEM_SUBCLASS_WEAPON_POLEARM ||
|
||
proto->SubClass == ITEM_SUBCLASS_WEAPON_STAFF) &&
|
||
(cls == CLASS_WARRIOR && tab == WARRIOR_TAB_FURY && player_->CanTitanGrip()))
|
||
{
|
||
weight_ *= 0.1;
|
||
}
|
||
|
||
if (cls == CLASS_HUNTER && proto->SubClass == ITEM_SUBCLASS_WEAPON_THROWN)
|
||
{
|
||
weight_ *= 0.1;
|
||
}
|
||
|
||
if (lvl >= 10 && cls == CLASS_ROGUE && (tab == ROGUE_TAB_ASSASSINATION || tab == ROGUE_TAB_SUBTLETY) &&
|
||
proto->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER)
|
||
{
|
||
weight_ *= 1.5;
|
||
}
|
||
|
||
if (cls == CLASS_ROGUE && player_->HasAura(13964) &&
|
||
(proto->SubClass == ITEM_SUBCLASS_WEAPON_SWORD || proto->SubClass == ITEM_SUBCLASS_WEAPON_AXE))
|
||
{
|
||
weight_ *= 1.1;
|
||
}
|
||
if (cls == CLASS_WARRIOR && player_->HasAura(12785) &&
|
||
(proto->SubClass == ITEM_SUBCLASS_WEAPON_POLEARM || proto->SubClass == ITEM_SUBCLASS_WEAPON_AXE2))
|
||
{
|
||
weight_ *= 1.1;
|
||
}
|
||
if (cls == CLASS_DEATH_KNIGHT && player_->HasAura(50138) && !isDoubleHand)
|
||
{
|
||
weight_ *= 1.3;
|
||
}
|
||
bool slowDelay = proto->Delay > 2500;
|
||
if (cls == CLASS_SHAMAN && tab == SHAMAN_TAB_ENHANCEMENT && slowDelay)
|
||
weight_ *= 1.1;
|
||
}
|
||
}
|
||
|
||
bool StatsWeightCalculator::NotBestArmorType(uint32 item_subclass_armor)
|
||
{
|
||
if (player_->HasSkill(SKILL_PLATE_MAIL))
|
||
{
|
||
return item_subclass_armor != ITEM_SUBCLASS_ARMOR_PLATE;
|
||
}
|
||
if (player_->HasSkill(SKILL_MAIL))
|
||
{
|
||
return item_subclass_armor != ITEM_SUBCLASS_ARMOR_MAIL;
|
||
}
|
||
if (player_->HasSkill(SKILL_LEATHER))
|
||
{
|
||
return item_subclass_armor != ITEM_SUBCLASS_ARMOR_LEATHER;
|
||
}
|
||
return false;
|
||
}
|
||
|
||
void StatsWeightCalculator::ApplyOverflowPenalty(Player* player)
|
||
{
|
||
{
|
||
float hit_current, hit_overflow;
|
||
float validPoints;
|
||
if (hitOverflowType_ & CollectorType::SPELL)
|
||
{
|
||
hit_current = player->GetTotalAuraModifier(SPELL_AURA_MOD_SPELL_HIT_CHANCE);
|
||
hit_current +=
|
||
player->GetTotalAuraModifier(SPELL_AURA_MOD_INCREASES_SPELL_PCT_TO_HIT); // suppression (18176)
|
||
hit_current += player->GetRatingBonusValue(CR_HIT_SPELL);
|
||
|
||
if (cls == CLASS_PRIEST && tab == PRIEST_TAB_SHADOW && player->HasAura(15835)) // Shadow Focus
|
||
hit_current += 3;
|
||
if (cls == CLASS_MAGE && tab == MAGE_TAB_ARCANE && player->HasAura(12840)) // Arcane Focus
|
||
hit_current += 3;
|
||
|
||
hit_overflow = SPELL_HIT_OVERFLOW;
|
||
if (hit_overflow > hit_current)
|
||
validPoints = (hit_overflow - hit_current) / player->GetRatingMultiplier(CR_HIT_SPELL);
|
||
else
|
||
validPoints = 0;
|
||
}
|
||
else if (hitOverflowType_ & CollectorType::MELEE)
|
||
{
|
||
hit_current = player->GetTotalAuraModifier(SPELL_AURA_MOD_HIT_CHANCE);
|
||
hit_current += player->GetRatingBonusValue(CR_HIT_MELEE);
|
||
hit_overflow = MELEE_HIT_OVERFLOW;
|
||
if (hit_overflow > hit_current)
|
||
validPoints = (hit_overflow - hit_current) / player->GetRatingMultiplier(CR_HIT_MELEE);
|
||
else
|
||
validPoints = 0;
|
||
}
|
||
else
|
||
{
|
||
hit_current = player->GetTotalAuraModifier(SPELL_AURA_MOD_HIT_CHANCE);
|
||
hit_current += player->GetRatingBonusValue(CR_HIT_RANGED);
|
||
hit_overflow = RANGED_HIT_OVERFLOW;
|
||
if (hit_overflow > hit_current)
|
||
validPoints = (hit_overflow - hit_current) / player->GetRatingMultiplier(CR_HIT_RANGED);
|
||
else
|
||
validPoints = 0;
|
||
}
|
||
collector_->stats[STATS_TYPE_HIT] = std::min(collector_->stats[STATS_TYPE_HIT], validPoints);
|
||
}
|
||
|
||
{
|
||
if (type_ & CollectorType::MELEE)
|
||
{
|
||
float expertise_current, expertise_overflow;
|
||
expertise_current = player->GetUInt32Value(PLAYER_EXPERTISE);
|
||
expertise_current += player->GetRatingBonusValue(CR_EXPERTISE);
|
||
expertise_overflow = EXPERTISE_OVERFLOW;
|
||
|
||
float validPoints;
|
||
if (expertise_overflow > expertise_current)
|
||
validPoints = (expertise_overflow - expertise_current) / player->GetRatingMultiplier(CR_EXPERTISE);
|
||
else
|
||
validPoints = 0;
|
||
|
||
collector_->stats[STATS_TYPE_EXPERTISE] = std::min(collector_->stats[STATS_TYPE_EXPERTISE], validPoints);
|
||
}
|
||
}
|
||
|
||
{
|
||
if (type_ & CollectorType::MELEE)
|
||
{
|
||
float defense_current, defense_overflow;
|
||
defense_current = player->GetRatingBonusValue(CR_DEFENSE_SKILL);
|
||
defense_overflow = DEFENSE_OVERFLOW;
|
||
|
||
float validPoints;
|
||
if (defense_overflow > defense_current)
|
||
validPoints = (defense_overflow - defense_current) / player->GetRatingMultiplier(CR_DEFENSE_SKILL);
|
||
else
|
||
validPoints = 0;
|
||
|
||
collector_->stats[STATS_TYPE_DEFENSE] = std::min(collector_->stats[STATS_TYPE_DEFENSE], validPoints);
|
||
}
|
||
}
|
||
|
||
{
|
||
if (type_ & (CollectorType::MELEE | CollectorType::RANGED))
|
||
{
|
||
float armor_penetration_current, armor_penetration_overflow;
|
||
armor_penetration_current = player->GetRatingBonusValue(CR_ARMOR_PENETRATION);
|
||
armor_penetration_overflow = ARMOR_PENETRATION_OVERFLOW;
|
||
|
||
float validPoints;
|
||
if (armor_penetration_overflow > armor_penetration_current)
|
||
validPoints = (armor_penetration_overflow - armor_penetration_current) /
|
||
player->GetRatingMultiplier(CR_ARMOR_PENETRATION);
|
||
else
|
||
validPoints = 0;
|
||
|
||
collector_->stats[STATS_TYPE_ARMOR_PENETRATION] =
|
||
std::min(collector_->stats[STATS_TYPE_ARMOR_PENETRATION], validPoints);
|
||
}
|
||
}
|
||
}
|
||
|
||
void StatsWeightCalculator::ApplyWeightFinetune(Player* player)
|
||
{
|
||
{
|
||
if (type_ & (CollectorType::MELEE | CollectorType::RANGED))
|
||
{
|
||
float armor_penetration_current /*, armor_penetration_overflow*/; // not used, line marked for removal.
|
||
armor_penetration_current = player->GetRatingBonusValue(CR_ARMOR_PENETRATION);
|
||
if (armor_penetration_current > 50)
|
||
stats_weights_[STATS_TYPE_ARMOR_PENETRATION] *= 1.2f;
|
||
}
|
||
}
|
||
}
|
||
|
||
float StatsWeightCalculator::ApplyPreferredSpecWeapons(ItemTemplate const* proto, int32 slot)
|
||
{
|
||
// Multiply score by 3x when this weapon's delay matches the spec-ideal speed.
|
||
float weight = 2.0f;
|
||
|
||
// Applies to mainhand, offhand, and ranged slots only.
|
||
if (slot != EQUIPMENT_SLOT_MAINHAND &&
|
||
slot != EQUIPMENT_SLOT_OFFHAND &&
|
||
slot != EQUIPMENT_SLOT_RANGED)
|
||
return 1.0f;
|
||
|
||
uint32 delay = proto->Delay; // milliseconds
|
||
float boost = 1.0f + weight; // applied on a match
|
||
|
||
// Hunter: melee weapons are stat sticks — speed irrelevant.
|
||
// Ranged weapons scale Aimed/Chimera/Explosive Shot from top-end damage,
|
||
// so a slow ranged weapon (>=2600 ms) is strongly preferred.
|
||
if (cls == CLASS_HUNTER)
|
||
{
|
||
if (slot == EQUIPMENT_SLOT_RANGED && delay >= 2600)
|
||
return boost;
|
||
return 1.0f;
|
||
}
|
||
|
||
// Feral Druid: forms normalise attack speed; raw weapon Delay is irrelevant.
|
||
if (cls == CLASS_DRUID && tab == DRUID_TAB_FERAL)
|
||
return 1.0f;
|
||
|
||
switch (cls)
|
||
{
|
||
case CLASS_WARRIOR:
|
||
if (tab == WARRIOR_TAB_ARMS)
|
||
{
|
||
// Arms: slow 2H axes or polearms in mainhand only (Axe Specialization: +5% crit).
|
||
bool isAxeOrPolearm = (proto->SubClass == ITEM_SUBCLASS_WEAPON_AXE2 ||
|
||
proto->SubClass == ITEM_SUBCLASS_WEAPON_POLEARM);
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 3400 && isAxeOrPolearm)
|
||
return boost;
|
||
}
|
||
else if (tab == WARRIOR_TAB_FURY)
|
||
{
|
||
if (!player_->CanDualWield())
|
||
{
|
||
// Pre-DW: treat like Arms — slow 2H in mainhand only.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 3400)
|
||
return boost;
|
||
}
|
||
else if (player_->CanTitanGrip())
|
||
{
|
||
// Titan's Grip: slow 2H (>=3400) in both hands.
|
||
if (delay >= 3400)
|
||
return boost;
|
||
}
|
||
else
|
||
{
|
||
// 1H DW: slow 1H (>=2600) in both hands.
|
||
// 2H must be excluded — delay >= 2600 would otherwise pass
|
||
// for a 2H heirloom (~3600ms) just as it did for Enhancement.
|
||
if (proto->InventoryType == INVTYPE_2HWEAPON)
|
||
break;
|
||
if (delay >= 2600)
|
||
return boost;
|
||
}
|
||
}
|
||
else if (tab == WARRIOR_TAB_PROTECTION)
|
||
{
|
||
// Prot: slow 1H (>=2600) in mainhand. Shield in offhand, no speed bonus.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 2600)
|
||
return boost;
|
||
}
|
||
break;
|
||
|
||
case CLASS_PALADIN:
|
||
if (tab == PALADIN_TAB_RETRIBUTION)
|
||
{
|
||
// Ret: slow 2H in mainhand only.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 3400)
|
||
return boost;
|
||
}
|
||
else if (tab == PALADIN_TAB_PROTECTION)
|
||
{
|
||
// Prot: slow 1H (>=2600) in mainhand. Shield in offhand.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 2600)
|
||
return boost;
|
||
}
|
||
break;
|
||
|
||
case CLASS_DEATH_KNIGHT:
|
||
if (tab == DEATH_KNIGHT_TAB_BLOOD || tab == DEATH_KNIGHT_TAB_UNHOLY)
|
||
{
|
||
// Blood / Unholy: slow 2H in mainhand only.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 3400)
|
||
return boost;
|
||
}
|
||
else if (tab == DEATH_KNIGHT_TAB_FROST)
|
||
{
|
||
// Frost DK has Dual Wield innately — always dual-wields 1H.
|
||
if (proto->InventoryType == INVTYPE_2HWEAPON)
|
||
break;
|
||
if (delay >= 2600)
|
||
return boost;
|
||
}
|
||
break;
|
||
|
||
case CLASS_SHAMAN:
|
||
if (tab == SHAMAN_TAB_ENHANCEMENT)
|
||
{
|
||
if (!player_->CanDualWield())
|
||
{
|
||
// Pre-Dual Wield: Enhancement plays like a 2H spec.
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 3400)
|
||
return boost;
|
||
}
|
||
else
|
||
{
|
||
// Post-Dual Wield: slow 1H (>=2600) in both hands.
|
||
if (proto->InventoryType == INVTYPE_2HWEAPON)
|
||
break;
|
||
|
||
if (delay >= 2600)
|
||
{
|
||
float mult = boost;
|
||
if (slot == EQUIPMENT_SLOT_OFFHAND)
|
||
{
|
||
Item* mh = player_->GetItemByPos(INVENTORY_SLOT_BAG_0, EQUIPMENT_SLOT_MAINHAND);
|
||
if (mh && mh->GetTemplate() && mh->GetTemplate()->Delay == delay)
|
||
mult *= boost; // synchronized: ×(1+weight)² total = ×9 for 2.0f weight
|
||
}
|
||
return mult;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
|
||
case CLASS_ROGUE:
|
||
if (tab == ROGUE_TAB_COMBAT)
|
||
{
|
||
// Combat: slow MH (>=2600), fast OH (<=1500).
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && delay >= 2600)
|
||
return boost;
|
||
if (slot == EQUIPMENT_SLOT_OFFHAND && delay <= 1500)
|
||
return boost;
|
||
}
|
||
else // Assassination or Subtlety: slow dagger MH, fast dagger OH.
|
||
{
|
||
bool isDagger = (proto->SubClass == ITEM_SUBCLASS_WEAPON_DAGGER);
|
||
if (slot == EQUIPMENT_SLOT_MAINHAND && isDagger && delay >= 1700)
|
||
return boost;
|
||
if (slot == EQUIPMENT_SLOT_OFFHAND && isDagger && delay <= 1500)
|
||
return boost;
|
||
}
|
||
break;
|
||
|
||
default:
|
||
break;
|
||
}
|
||
|
||
return 1.0f;
|
||
}
|