Skip to content

Commit

Permalink
-Stat weight: Added proper values for gems and stat enchants.
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlikely4r committed Feb 8, 2023
1 parent 5d38c21 commit 5f3f90d
Show file tree
Hide file tree
Showing 4 changed files with 233 additions and 92 deletions.
222 changes: 162 additions & 60 deletions playerbot/RandomItemMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,96 +2015,198 @@ uint32 RandomItemMgr::CalculateStatWeight(uint8 playerclass, uint8 spec, ItemPro
return statWeight;
}

uint32 RandomItemMgr::CalculateRandomPropertyWeight(uint8 playerclass, uint8 spec, uint32 randomPropertyId)
uint32 RandomItemMgr::CalculateEnchantWeight(uint8 playerclass, uint8 spec, uint32 enchantId)
{
if (!enchantId)
return 0;

SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(enchantId);

if (!pEnchant)
return 0;

uint32 weight = 0;
if (randomPropertyId > 0)

for (int s = 0; s < 3; ++s)
{
ItemRandomPropertiesEntry const* item_rand = sItemRandomPropertiesStore.LookupEntry(randomPropertyId);
if (item_rand)
switch (pEnchant->type[s])
{
for (uint32 i = PROP_ENCHANTMENT_SLOT_0; i < PROP_ENCHANTMENT_SLOT_0 + 3; ++i)
{
if (SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(item_rand->enchant_id[i - PROP_ENCHANTMENT_SLOT_0]))
{
for (int s = 0; s < 3; ++s)
{
switch (pEnchant->type[s])
{
case 1: //Proc //TODO add proc values?
break;
case 2: //Damage
if (!pEnchant->amount[s])
continue;
weight += CalculateSingleStatWeight(playerclass, spec, "mledps", pEnchant->amount[s]);
break;
case 3:
{
if (!pEnchant->spellid[s])
continue;
case 1: //Proc //TODO add proc values?
break;
case 2: //Damage
if (!pEnchant->amount[s])
continue;
weight += CalculateSingleStatWeight(playerclass, spec, "mledps", pEnchant->amount[s]);
break;
case 3:
{
if (!pEnchant->spellid[s])
continue;

SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(pEnchant->spellid[s]);
SpellEntry const* spellInfo = sSpellTemplate.LookupEntry<SpellEntry>(pEnchant->spellid[s]);

if (!spellInfo)
continue;
if (!spellInfo)
continue;

for (uint32 j = 0; j < MAX_EFFECT_INDEX; ++j)
{
if (spellInfo->Effect[j] != SPELL_EFFECT_APPLY_AURA)
continue;
if (spellInfo->EffectApplyAuraName[j] != SPELL_AURA_MOD_STAT)
continue;
for (uint32 j = 0; j < MAX_EFFECT_INDEX; ++j)
{
if (spellInfo->Effect[j] != SPELL_EFFECT_APPLY_AURA)
continue;
if (spellInfo->EffectApplyAuraName[j] != SPELL_AURA_MOD_STAT)
continue;

uint32 stat = spellInfo->EffectMiscValue[j];
uint32 value = spellInfo->EffectBasePoints[j] + 1;
uint32 stat = spellInfo->EffectMiscValue[j];
uint32 value = spellInfo->EffectBasePoints[j] + 1;

if (!value)
continue;
if (!value)
continue;

if (ItemStatLink.find(stat) == ItemStatLink.end())
continue;
if (ItemStatLink.find(stat) == ItemStatLink.end())
continue;

weight += CalculateSingleStatWeight(playerclass, spec, ItemStatLink[stat], value);
}
break;
}
case 4: //Armor
if (!pEnchant->amount[s])
continue;
weight += CalculateSingleStatWeight(playerclass, spec, "armor", pEnchant->amount[s]);
break;
}
weight += CalculateSingleStatWeight(playerclass, spec, ItemStatLink[stat], value);
}
break;
}
case 4: //Armor
if (!pEnchant->amount[s])
continue;
weight += CalculateSingleStatWeight(playerclass, spec, "armor", pEnchant->amount[s]);
break;
case 5: //Stat
{
for (auto& statLink : weightStatLink)
{
if (statLink.second != pEnchant->spellid[s])
continue;

}
}
weight += CalculateSingleStatWeight(playerclass, spec, statLink.first, pEnchant->amount[s]);
}
break;
}
case 6: //Totem
break;
case 7: //Use Spell
break;
case 8: //Prismatic socket
break;
}
}

return weight;
}


uint32 RandomItemMgr::ItemStatWeight(Player* player, ItemPrototype const* proto, uint32 randomPropertyId, uint32 gem1, uint32 gem2, uint32 gem3, uint32 gem4)
uint32 RandomItemMgr::CalculateRandomPropertyWeight(uint8 playerclass, uint8 spec, int32 randomPropertyId)
{
ItemSpecType itSpec;
uint32 weight = CalculateStatWeight(player->getClass(), GetPlayerSpecId(player), proto, itSpec);
uint32 weight = 0;
if (randomPropertyId)
weight += CalculateRandomPropertyWeight(player->getClass(), GetPlayerSpecId(player), randomPropertyId);

//Todo gems.
{
ItemRandomPropertiesEntry const* item_rand = sItemRandomPropertiesStore.LookupEntry(abs(randomPropertyId));
if (item_rand)
{
for (uint32 i = PROP_ENCHANTMENT_SLOT_0; i < PROP_ENCHANTMENT_SLOT_0 + 3; ++i)
{
uint32 enchantId = item_rand->enchant_id[i - PROP_ENCHANTMENT_SLOT_0];

weight += CalculateEnchantWeight(playerclass, spec, enchantId);
}
}
}
return weight;
}

uint32 RandomItemMgr::ItemStatWeight(Player* player, uint32 itemId, uint32 randomPropertyId, uint32 gem1, uint32 gem2, uint32 gem3, uint32 gem4)
uint32 RandomItemMgr::CalculateGemWeight(uint8 playerclass, uint8 spec, uint32 gemId)
{
const ItemPrototype* proto = sObjectMgr.GetItemPrototype(itemId);
return ItemStatWeight(player, proto, randomPropertyId, gem1, gem2, gem3, gem4);
#ifdef MANGOSBOT_ZERO
return 0;
#else
if (!gemId)
return 0;

return CalculateEnchantWeight(playerclass, spec, gemId);
#endif
}

uint32 RandomItemMgr::CalculateSocketWeight(uint8 playerclass, ItemQualifier& qualifier, uint8 spec)
{
#ifdef MANGOSBOT_ZERO
return 0;
#else

vector<uint32> gems = { qualifier.GetGem1() , qualifier.GetGem2(), qualifier.GetGem3(), qualifier.GetGem4() };

ItemPrototype const* proto = qualifier.GetProto();

bool hasGem = false;
for (auto gem : gems)
if(gem)
hasGem = true;

if (!hasGem)
return 0;

for (int i = 0; i < MAX_GEM_SOCKETS; ++i)
{
uint8 SocketColor = proto->Socket[i].Color;

if (!SocketColor)
continue;

uint8 GemColor = 0;

if (!gems[i])
return 0;

SpellItemEnchantmentEntry const* pEnchant = sSpellItemEnchantmentStore.LookupEntry(gems[i]);

if (!pEnchant)
return 0;

uint32 gemid = pEnchant->GemID;
if (!gemid)
return 0;

ItemPrototype const* gemProto = sItemStorage.LookupEntry<ItemPrototype>(gemid);
if (!gemProto)
return 0;

GemPropertiesEntry const* gemProperty = sGemPropertiesStore.LookupEntry(gemProto->GemProperties);

if (!gemProperty)
return 0;

GemColor = gemProperty->color;

if (!(GemColor & SocketColor))
return 0;
}

return CalculateEnchantWeight(playerclass, spec, proto->socketBonus);
#endif;
}


uint32 RandomItemMgr::ItemStatWeight(Player* player, ItemQualifier& qualifier)
{
return ItemStatWeight(player, qualifier.GetId(), qualifier.GetRandomPropertyId(), qualifier.GetGem1(), qualifier.GetGem2(), qualifier.GetGem3(), qualifier.GetGem4());
ItemSpecType itSpec;
uint32 weight = CalculateStatWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetProto(), itSpec);
if(qualifier.GetEnchantId())
weight += CalculateEnchantWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetEnchantId());
if (qualifier.GetRandomPropertyId())
weight += CalculateRandomPropertyWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetRandomPropertyId());
if(qualifier.GetGem1())
weight += CalculateGemWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetGem1());
if (qualifier.GetGem2())
weight += CalculateGemWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetGem2());
if (qualifier.GetGem3())
weight += CalculateGemWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetGem3());
if (qualifier.GetGem4())
weight += CalculateGemWeight(player->getClass(), GetPlayerSpecId(player), qualifier.GetGem4());

weight += CalculateSocketWeight(player->getClass(), qualifier, GetPlayerSpecId(player));

return weight;
}

uint32 RandomItemMgr::ItemStatWeight(Player* player, Item* item)
Expand Down
8 changes: 5 additions & 3 deletions playerbot/RandomItemMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,12 @@ class RandomItemMgr
uint32 GetRandomTrade(uint32 level);
vector<uint32> GetGemsList();

uint32 CalculateRandomPropertyWeight(uint8 playerclass, uint8 spec, uint32 randomPropertyId);
uint32 CalculateEnchantWeight(uint8 playerclass, uint8 spec, uint32 enchantId);
uint32 CalculateRandomPropertyWeight(uint8 playerclass, uint8 spec, int32 randomPropertyId);
uint32 CalculateGemWeight(uint8 playerclass, uint8 spec, uint32 gemId);
uint32 CalculateSocketWeight(uint8 playerclass, ItemQualifier& qualifier, uint8 spec);

uint32 CalculateStatWeight(uint8 playerclass, uint8 spec, ItemPrototype const* proto, ItemSpecType &itSpec);
uint32 ItemStatWeight(Player* player, ItemPrototype const* proto, uint32 randomPropertyId = 0, uint32 gem1 = 0, uint32 gem2 = 0, uint32 gem3 = 0, uint32 gem4 = 0);
uint32 ItemStatWeight(Player* player, uint32 itemId, uint32 randomPropertyId = 0, uint32 gem1 = 0, uint32 gem2 = 0, uint32 gem3 = 0, uint32 gem4 = 0);
uint32 ItemStatWeight(Player* player, ItemQualifier& qualifier);
uint32 ItemStatWeight(Player* player, Item* item);

Expand Down
64 changes: 45 additions & 19 deletions playerbot/strategy/values/ItemUsageValue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,61 @@

using namespace ai;

ItemQualifier::ItemQualifier(string qualifier)
ItemQualifier::ItemQualifier(string qualifier, bool linkQualifier)
{
vector<string> numbers = Qualified::getMultiQualifiers(qualifier, ":");

itemId = stoi(numbers[0]);
if (numbers.size() > 2)
randomPropertyId = stoi(numbers[2]);
else
randomPropertyId = 0;
enchantId = 0;
randomPropertyId = 0;
gem1 = 0;
gem2 = 0;
gem3 = 0;
gem4 = 0;
proto = nullptr;

#ifdef MANGOSBOT_ZERO
uint32 propertyPosition = linkQualifier ? 2 : 5;
#else
uint32 propertyPosition = linkQualifier ? 6 : 5;
#endif

if (numbers.size() > 7)
{
gem1 = stoi(numbers[4]);
gem2 = stoi(numbers[5]);
gem3 = stoi(numbers[6]);
gem4 = stoi(numbers[7]);
}
else
if (numbers.size() > 1)
enchantId = stoi(numbers[1]);

if (numbers.size() > propertyPosition)
randomPropertyId = stoi(numbers[propertyPosition]);

#ifndef MANGOSBOT_ZERO
uint8 gemPosition = linkQualifier ? 2 : 1;

if (numbers.size() > gemPosition + 3)
{
gem1 = 0;
gem2 = 0;
gem3 = 0;
gem4 = 0;
gem1 = stoi(numbers[gemPosition]);
gem2 = stoi(numbers[gemPosition+1]);
gem3 = stoi(numbers[gemPosition+2]);
gem4 = stoi(numbers[gemPosition+3]);
}
#endif;
}

uint32 ItemQualifier::GemId(Item* item, uint8 gemSlot)
{
#ifdef MANGOSBOT_ZERO
return 0;
#else
uint32 enchantId = item->GetEnchantmentId(EnchantmentSlot(SOCK_ENCHANTMENT_SLOT + gemSlot));

if (!enchantId)
return 0;

return enchantId;
#endif
}

ItemUsage ItemUsageValue::Calculate()
{
ItemQualifier itemQualifier(qualifier);
ItemQualifier itemQualifier(qualifier,false);
uint32 itemId = itemQualifier.GetId();
if (!itemId)
return ITEM_USAGE_NONE;
Expand Down Expand Up @@ -226,7 +252,7 @@ ItemUsage ItemUsageValue::QueryItemUsageForEquip(ItemQualifier& itemQualifier)

uint16 dest;

list<Item*> items = AI_VALUE2(list<Item*>, "inventory items", chat->formatItem(itemProto));
list<Item*> items = AI_VALUE2(list<Item*>, "inventory items", chat->formatItem(itemQualifier));
InventoryResult result;
if (!items.empty())
{
Expand Down
Loading

0 comments on commit 5f3f90d

Please sign in to comment.