aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTreeston <treeston.mmoc@gmail.com>2020-08-31 16:56:56 +0200
committerGitHub <noreply@github.com>2020-08-31 16:56:56 +0200
commit5394b2ef0f1c7b48e8886257b93698358abb575f (patch)
treefa864bdefed2097131158b6dd548a9c809c21f62 /src
parent1e8cb1ed1f374e5aaaafad7b6c283000bce8aaee (diff)
UnitTests: Add a first set of item hyperlink tests
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Chat/Hyperlinks.cpp14
-rw-r--r--src/server/game/Chat/Hyperlinks.h2
-rw-r--r--src/server/game/Entities/Item/ItemTemplate.h38
-rw-r--r--src/server/game/Globals/ObjectMgr.h14
4 files changed, 39 insertions, 29 deletions
diff --git a/src/server/game/Chat/Hyperlinks.cpp b/src/server/game/Chat/Hyperlinks.cpp
index 6bc47c8416f..308ec33d46d 100644
--- a/src/server/game/Chat/Hyperlinks.cpp
+++ b/src/server/game/Chat/Hyperlinks.cpp
@@ -152,7 +152,7 @@ struct LinkValidator<LinkTags::item>
{
if (!locale && i != DEFAULT_LOCALE)
continue;
- std::string const& name = (i == DEFAULT_LOCALE) ? data.Item->Name1 : locale->Name[i];
+ std::string_view name = (i == DEFAULT_LOCALE) ? data.Item->Name1 : ObjectMgr::GetLocaleString(locale->Name, i);
if (name.empty())
continue;
if (randomSuffixes)
@@ -184,15 +184,17 @@ struct LinkValidator<LinkTags::quest>
static bool IsTextValid(QuestLinkData const& data, std::string_view text)
{
QuestLocale const* locale = sObjectMgr->GetQuestLocale(data.Quest->GetQuestId());
- if (!locale)
- return text == data.Quest->GetTitle();
+
+ if (text == data.Quest->GetTitle())
+ return true;
for (uint8 i = 0; i < TOTAL_LOCALES; ++i)
{
- std::string const& name = (i == DEFAULT_LOCALE) ? data.Quest->GetTitle() : locale->Title[i];
- if (name.empty())
+ if (i == DEFAULT_LOCALE)
continue;
- if (text == name)
+
+ std::string_view name = ObjectMgr::GetLocaleString(locale->Title, i);
+ if (!name.empty() && (text == name))
return true;
}
diff --git a/src/server/game/Chat/Hyperlinks.h b/src/server/game/Chat/Hyperlinks.h
index 5b39cfc7906..69bfdb28ff0 100644
--- a/src/server/game/Chat/Hyperlinks.h
+++ b/src/server/game/Chat/Hyperlinks.h
@@ -95,7 +95,7 @@ namespace Trinity::Hyperlinks
|* - this method SHOULD be constexpr *|
|* - returns identifier string for the link ("creature", "creature_entry", "item") *|
|* - MUST expose static ::StoreTo method, (storage&, std::string_view) *|
- |* - assign value_type& based on content of std::string_view *|
+ |* - assign storage& based on content of std::string_view *|
|* - return value indicates success/failure *|
|* - for integral/string types this can be achieved by extending base_tag *|
\****************************************************************************************/
diff --git a/src/server/game/Entities/Item/ItemTemplate.h b/src/server/game/Entities/Item/ItemTemplate.h
index e08a04d0063..cba6604fe6a 100644
--- a/src/server/game/Entities/Item/ItemTemplate.h
+++ b/src/server/game/Entities/Item/ItemTemplate.h
@@ -563,31 +563,31 @@ const uint32 MaxItemSubclassValues[MAX_ITEM_CLASS] =
struct _Damage
{
- float DamageMin;
- float DamageMax;
- uint32 DamageType; // id from Resistances.dbc
+ float DamageMin = 0.0f;
+ float DamageMax = 0.0f;
+ uint32 DamageType = 0; // id from Resistances.dbc
};
struct _ItemStat
{
- uint32 ItemStatType;
- int32 ItemStatValue;
+ uint32 ItemStatType = 0;
+ int32 ItemStatValue = 0;
};
struct _Spell
{
- int32 SpellId; // id from Spell.dbc
- uint32 SpellTrigger;
- int32 SpellCharges;
- float SpellPPMRate;
- int32 SpellCooldown;
- uint32 SpellCategory; // id from SpellCategory.dbc
- int32 SpellCategoryCooldown;
+ int32 SpellId = 0; // id from Spell.dbc
+ uint32 SpellTrigger = 0;
+ int32 SpellCharges = 0;
+ float SpellPPMRate = 0.0f;
+ int32 SpellCooldown = -1;
+ uint32 SpellCategory = 0; // id from SpellCategory.dbc
+ int32 SpellCategoryCooldown = -1;
};
struct _Socket
{
- uint32 Color;
- uint32 Content;
+ uint32 Color = 0;
+ uint32 Content = 0;
};
#pragma pack(pop)
@@ -629,10 +629,10 @@ struct ItemTemplate
int32 Stackable; // 0: not allowed, -1: put in player coin info tab and don't limit stacking (so 1 slot)
uint32 ContainerSlots;
uint32 StatsCount;
- _ItemStat ItemStat[MAX_ITEM_PROTO_STATS];
+ std::array<_ItemStat, MAX_ITEM_PROTO_STATS> ItemStat;
uint32 ScalingStatDistribution; // id from ScalingStatDistribution.dbc
uint32 ScalingStatValue; // mask for selecting column in ScalingStatValues.dbc
- _Damage Damage[MAX_ITEM_PROTO_DAMAGES];
+ std::array<_Damage, MAX_ITEM_PROTO_DAMAGES> Damage;
uint32 Armor;
uint32 HolyRes;
uint32 FireRes;
@@ -643,7 +643,7 @@ struct ItemTemplate
uint32 Delay;
uint32 AmmoType;
float RangedModRange;
- _Spell Spells[MAX_ITEM_PROTO_SPELLS];
+ std::array<_Spell, MAX_ITEM_PROTO_SPELLS> Spells;
uint32 Bonding;
std::string Description;
uint32 PageText;
@@ -662,7 +662,7 @@ struct ItemTemplate
uint32 Map; // id from Map.dbc
uint32 BagFamily; // bit mask (1 << id from ItemBagFamily.dbc)
uint32 TotemCategory; // id from TotemCategory.dbc
- _Socket Socket[MAX_ITEM_PROTO_SOCKETS];
+ std::array<_Socket, MAX_ITEM_PROTO_SOCKETS> Socket;
uint32 socketBonus; // id from SpellItemEnchantment.dbc
uint32 GemProperties; // id from GemProperties.dbc
uint32 RequiredDisenchantSkill;
@@ -676,7 +676,7 @@ struct ItemTemplate
uint32 MinMoneyLoot;
uint32 MaxMoneyLoot;
uint32 FlagsCu;
- WorldPacket QueryData[TOTAL_LOCALES];
+ std::array<WorldPacket, TOTAL_LOCALES> QueryData;
// helpers
bool CanChangeEquipStateInCombat() const;
diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h
index ca3fa6eab32..43eb008f2f2 100644
--- a/src/server/game/Globals/ObjectMgr.h
+++ b/src/server/game/Globals/ObjectMgr.h
@@ -940,6 +940,7 @@ class PlayerDumpReader;
class TC_GAME_API ObjectMgr
{
friend class PlayerDumpReader;
+ friend class UnitTestDataLoader;
private:
ObjectMgr();
@@ -1535,10 +1536,17 @@ class TC_GAME_API ObjectMgr
GraveyardContainer GraveyardStore;
static void AddLocaleString(std::string&& value, LocaleConstant localeConstant, std::vector<std::string>& data);
- static inline void GetLocaleString(std::vector<std::string> const& data, LocaleConstant localeConstant, std::string& value)
+ static std::string_view GetLocaleString(std::vector<std::string> const& data, size_t locale)
{
- if (data.size() > size_t(localeConstant) && !data[localeConstant].empty())
- value = data[localeConstant];
+ if (locale < data.size())
+ return data[locale];
+ else
+ return {};
+ }
+ static void GetLocaleString(std::vector<std::string> const& data, LocaleConstant localeConstant, std::string& value)
+ {
+ if (std::string_view str = GetLocaleString(data, static_cast<size_t>(localeConstant)); !str.empty())
+ value.assign(str);
}
CharacterConversionMap FactionChangeAchievements;