Core/Items: Add helper function to get item name including suffix

This commit is contained in:
Shauren
2020-04-18 10:59:35 +02:00
parent d7524928e5
commit ecdf3d1a14
7 changed files with 37 additions and 22 deletions

View File

@@ -2836,18 +2836,12 @@ uint32 Creature::UpdateVendorItemCurrentCount(VendorItem const* vItem, uint32 us
}
// overwrite WorldObject function for proper name localization
std::string const & Creature::GetNameForLocaleIdx(LocaleConstant loc_idx) const
std::string Creature::GetNameForLocaleIdx(LocaleConstant locale) const
{
if (loc_idx != DEFAULT_LOCALE)
{
uint8 uloc_idx = uint8(loc_idx);
CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(GetEntry());
if (cl)
{
if (cl->Name.size() > uloc_idx && !cl->Name[uloc_idx].empty())
return cl->Name[uloc_idx];
}
}
if (locale != DEFAULT_LOCALE)
if (CreatureLocale const* cl = sObjectMgr->GetCreatureLocale(GetEntry()))
if (cl->Name.size() > locale && !cl->Name[locale].empty())
return cl->Name[locale];
return GetName();
}

View File

@@ -177,7 +177,7 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
uint32 GetScriptId() const;
// override WorldObject function for proper name localization
std::string const& GetNameForLocaleIdx(LocaleConstant locale_idx) const override;
std::string GetNameForLocaleIdx(LocaleConstant locale) const override;
void setDeathState(DeathState s) override; // override virtual Unit::setDeathState

View File

@@ -2189,15 +2189,12 @@ uint32 GameObject::GetScriptId() const
}
// overwrite WorldObject function for proper name localization
std::string const & GameObject::GetNameForLocaleIdx(LocaleConstant loc_idx) const
std::string GameObject::GetNameForLocaleIdx(LocaleConstant locale) const
{
if (loc_idx != DEFAULT_LOCALE)
{
uint8 uloc_idx = uint8(loc_idx);
if (locale != DEFAULT_LOCALE)
if (GameObjectLocale const* cl = sObjectMgr->GetGameObjectLocale(GetEntry()))
if (cl->Name.size() > uloc_idx && !cl->Name[uloc_idx].empty())
return cl->Name[uloc_idx];
}
if (cl->Name.size() > locale && !cl->Name[locale].empty())
return cl->Name[locale];
return GetName();
}

View File

@@ -117,7 +117,7 @@ class TC_GAME_API GameObject : public WorldObject, public GridObject<GameObject>
int64 GetPackedWorldRotation() const { return m_packedRotation; }
// overwrite WorldObject function for proper name localization
std::string const& GetNameForLocaleIdx(LocaleConstant locale_idx) const override;
std::string GetNameForLocaleIdx(LocaleConstant locale) const override;
void SaveToDB();
void SaveToDB(uint32 mapid, std::vector<Difficulty> const& spawnDifficulties);

View File

@@ -498,6 +498,15 @@ bool Item::Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext contex
return true;
}
std::string Item::GetNameForLocaleIdx(LocaleConstant locale) const
{
ItemTemplate const* itemTemplate = GetTemplate();
if (ItemNameDescriptionEntry const* suffix = sItemNameDescriptionStore.LookupEntry(_bonusData.Suffix))
return Trinity::StringFormat("%s %s", itemTemplate->GetName(locale), suffix->Description->Str[locale]);
return itemTemplate->GetName(locale);
}
// Returns true if Item is a bag AND it is not empty.
// Returns false if Item is not a bag OR it is an empty bag.
bool Item::IsNotEmptyBag() const
@@ -2810,9 +2819,11 @@ void BonusData::Initialize(ItemTemplate const* proto)
if (AzeriteEmpoweredItemEntry const* azeriteEmpoweredItem = sDB2Manager.GetAzeriteEmpoweredItem(proto->GetId()))
AzeriteTierUnlockSetId = azeriteEmpoweredItem->AzeriteTierUnlockSetID;
Suffix = 0;
CanDisenchant = (proto->GetFlags() & ITEM_FLAG_NO_DISENCHANT) == 0;
CanScrap = (proto->GetFlags4() & ITEM_FLAG4_SCRAPABLE) != 0;
_state.SuffixPriority = std::numeric_limits<int32>::max();
_state.AppearanceModPriority = std::numeric_limits<int32>::max();
_state.ScalingStatDistributionPriority = std::numeric_limits<int32>::max();
_state.AzeriteTierUnlockSetPriority = std::numeric_limits<int32>::max();
@@ -2869,6 +2880,13 @@ void BonusData::AddBonus(uint32 type, int32 const (&values)[3])
else if (Quality < static_cast<uint32>(values[0]))
Quality = static_cast<uint32>(values[0]);
break;
case ITEM_BONUS_SUFFIX:
if (values[1] < _state.SuffixPriority)
{
Suffix = static_cast<uint32>(values[0]);
_state.SuffixPriority = values[1];
}
break;
case ITEM_BONUS_SOCKET:
{
uint32 socketCount = values[0];

View File

@@ -92,6 +92,7 @@ struct BonusData
int32 RelicType;
int32 RequiredLevelOverride;
int32 AzeriteTierUnlockSetId;
uint32 Suffix;
bool CanDisenchant;
bool CanScrap;
bool HasFixedLevel;
@@ -104,6 +105,7 @@ struct BonusData
private:
struct
{
int32 SuffixPriority;
int32 AppearanceModPriority;
int32 ScalingStatDistributionPriority;
int32 AzeriteTierUnlockSetPriority;
@@ -178,6 +180,8 @@ class TC_GAME_API Item : public Object
virtual bool Create(ObjectGuid::LowType guidlow, uint32 itemId, ItemContext context, Player const* owner);
std::string GetNameForLocaleIdx(LocaleConstant locale) const override;
ItemTemplate const* GetTemplate() const;
BonusData const* GetBonus() const { return &_bonusData; }

View File

@@ -160,6 +160,8 @@ class TC_GAME_API Object
virtual void ClearUpdateMask(bool remove);
virtual std::string GetNameForLocaleIdx(LocaleConstant locale) const = 0;
virtual bool hasQuest(uint32 /* quest_id */) const { return false; }
virtual bool hasInvolvedQuest(uint32 /* quest_id */) const { return false; }
virtual void BuildUpdate(UpdateDataMapType&) { }
@@ -420,9 +422,9 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
InstanceScript* GetInstanceScript();
std::string const& GetName() const { return m_name; }
void SetName(std::string const& newname) { m_name=newname; }
void SetName(std::string newname) { m_name = std::move(newname); }
virtual std::string const& GetNameForLocaleIdx(LocaleConstant /*locale_idx*/) const { return m_name; }
std::string GetNameForLocaleIdx(LocaleConstant /*locale*/) const override { return m_name; }
float GetDistance(WorldObject const* obj) const;
float GetDistance(Position const &pos) const;