1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
/*
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRINITY_HYPERLINKS_H
#define TRINITY_HYPERLINKS_H
#include "ObjectGuid.h"
#include "StringConvert.h"
#include <array>
#include <string>
#include <string_view>
#include <type_traits>
#include <utility>
struct AchievementEntry;
struct ArtifactPowerRankEntry;
struct AzeriteEssenceEntry;
struct BattlePetSpeciesEntry;
struct CurrencyContainerEntry;
struct CurrencyTypesEntry;
struct GarrAbilityEntry;
struct GarrFollowerEntry;
struct GarrMissionEntry;
struct GlyphPropertiesEntry;
struct ItemModifiedAppearanceEntry;
struct ItemNameDescriptionEntry;
struct ItemTemplate;
struct LocalizedString;
struct MapEntry;
struct MapChallengeModeEntry;
struct MawPowerEntry;
struct PvpTalentEntry;
class Quest;
struct SkillLineEntry;
struct SoulbindConduitRankEntry;
class SpellInfo;
struct SpellItemEnchantmentEntry;
struct TalentEntry;
struct TransmogSetEntry;
struct UiMapEntry;
namespace Trinity::Hyperlinks
{
struct AchievementLinkData
{
AchievementEntry const* Achievement = nullptr;
ObjectGuid CharacterId;
bool IsFinished = false;
int32 Year = 0;
int32 Month = 0;
int32 Day = 0;
std::array<uint32, 4> Criteria = { };
};
struct ArtifactPowerLinkData
{
ArtifactPowerRankEntry const* ArtifactPower = nullptr;
uint8 PurchasedRank = 0;
uint8 CurrentRankWithBonus = 0;
};
struct AzeriteEssenceLinkData
{
AzeriteEssenceEntry const* Essence = nullptr;
uint8 Rank = 0;
};
struct BattlePetLinkData
{
BattlePetSpeciesEntry const* Species = nullptr;
uint8 Level = 0;
uint8 Quality = 0;
uint32 MaxHealth = 0;
uint32 Power = 0;
uint32 Speed = 0;
ObjectGuid PetGuid;
uint32 DisplayId = 0;
};
struct CurrencyLinkData
{
CurrencyTypesEntry const* Currency = nullptr;
int32 Quantity = 0;
CurrencyContainerEntry const* Container = nullptr;
};
struct GarrisonFollowerLinkData
{
GarrFollowerEntry const* Follower = nullptr;
uint32 Quality = 0;
uint32 Level = 0;
uint32 ItemLevel = 0;
std::array<uint32, 4> Abilities = { };
uint32 Traits[4] = { };
uint32 Specialization = 0;
};
struct GarrisonMissionLinkData
{
GarrMissionEntry const* Mission = nullptr;
uint64 DbID = 0;
};
struct InstanceLockLinkData
{
ObjectGuid Owner;
MapEntry const* Map = nullptr;
uint32 Difficulty = 0;
uint32 CompletedEncountersMask = 0;
};
struct ItemLinkData
{
ItemTemplate const* Item = nullptr;
uint32 EnchantId = 0;
std::array<uint32, 3> GemItemId = { };
uint8 RenderLevel = 0;
uint32 RenderSpecialization = 0;
uint8 Context = 0;
std::vector<int32> ItemBonusListIDs;
struct Modifier
{
uint32 Type = 0;
int32 Value = 0;
};
std::vector<Modifier> Modifiers;
std::vector<int32> GemItemBonusListIDs[3];
ObjectGuid Creator;
uint32 UseEnchantId = 0;
uint32 Quality = 0;
ItemNameDescriptionEntry const* Suffix = nullptr;
};
struct JournalLinkData
{
enum class Types : uint8
{
Instance = 0,
Encounter = 1,
EncounterSection = 2,
Tier = 3
};
uint8 Type = 0;
LocalizedString const* ExpectedText = nullptr;
uint32 Difficulty = 0;
};
struct KeystoneLinkData
{
uint32 ItemId = 0;
MapChallengeModeEntry const* Map = nullptr;
uint32 Level = 0;
std::array<uint32, 4> Affix = { };
};
struct QuestLinkData
{
::Quest const* Quest = nullptr;
uint32 ContentTuningId = 0;
};
struct SpellLinkData
{
SpellInfo const* Spell = nullptr;
GlyphPropertiesEntry const* Glyph = nullptr;
};
struct TradeskillLinkData
{
ObjectGuid Owner;
SpellInfo const* Spell = nullptr;
SkillLineEntry const* Skill = nullptr;
};
struct WorldMapLinkData
{
UiMapEntry const* UiMap = nullptr;
uint32 X = 0;
uint32 Y = 0;
Optional<uint32> Z;
};
namespace LinkTags {
/************************** LINK TAGS ***************************************************\
|* Link tags must abide by the following: *|
|* - MUST expose ::value_type typedef *|
|* - storage type is remove_cvref_t<value_type> *|
|* - MUST expose static ::tag method, void -> std::string_view *|
|* - 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 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 *|
\****************************************************************************************/
struct base_tag
{
static bool StoreTo(std::string_view& val, std::string_view data)
{
val = data;
return true;
}
static bool StoreTo(std::string& val, std::string_view data)
{
val.assign(data);
return true;
}
template <typename T>
static std::enable_if_t<std::is_integral_v<T>, bool> StoreTo(T& val, std::string_view data)
{
if (Optional<T> res = Trinity::StringTo<T>(data))
{
val = *res;
return true;
}
else
return false;
}
static bool StoreTo(ObjectGuid& val, std::string_view data)
{
ObjectGuid parsed = ObjectGuid::FromString(std::string(data));
if (parsed != ObjectGuid::FromStringFailed)
{
val = parsed;
return true;
}
else
return false;
}
};
#define make_base_tag(ltag, type) struct ltag : public base_tag { using value_type = type; static constexpr std::string_view tag() { return #ltag; } }
// custom formats
make_base_tag(area, uint32);
make_base_tag(areatrigger, uint32);
make_base_tag(creature, ObjectGuid::LowType);
make_base_tag(creature_entry, uint32);
make_base_tag(gameevent, uint16);
make_base_tag(gameobject, ObjectGuid::LowType);
make_base_tag(gameobject_entry, uint32);
make_base_tag(itemset, uint32);
make_base_tag(player, std::string const&);
make_base_tag(skill, uint32);
make_base_tag(taxinode, uint32);
make_base_tag(tele, uint32);
make_base_tag(title, uint32);
// client format
make_base_tag(outfit, std::string const&); // some sort of weird base91 derived encoding
#undef make_base_tag
struct TC_GAME_API achievement
{
using value_type = AchievementLinkData const&;
static constexpr std::string_view tag() { return "achievement"; }
static bool StoreTo(AchievementLinkData& val, std::string_view text);
};
struct TC_GAME_API apower
{
using value_type = ArtifactPowerLinkData const&;
static constexpr std::string_view tag() { return "apower"; }
static bool StoreTo(ArtifactPowerLinkData& val, std::string_view text);
};
struct TC_GAME_API azessence
{
using value_type = AzeriteEssenceLinkData const&;
static constexpr std::string_view tag() { return "azessence"; }
static bool StoreTo(AzeriteEssenceLinkData& val, std::string_view text);
};
struct TC_GAME_API battlepet
{
using value_type = BattlePetLinkData const&;
static constexpr std::string_view tag() { return "battlepet"; }
static bool StoreTo(BattlePetLinkData& val, std::string_view text);
};
struct TC_GAME_API conduit
{
using value_type = SoulbindConduitRankEntry const*;
static constexpr std::string_view tag() { return "conduit"; }
static bool StoreTo(SoulbindConduitRankEntry const*& val, std::string_view text);
};
struct TC_GAME_API currency
{
using value_type = CurrencyLinkData const&;
static constexpr std::string_view tag() { return "currency"; }
static bool StoreTo(CurrencyLinkData& val, std::string_view text);
};
struct TC_GAME_API enchant
{
using value_type = SpellInfo const*;
static constexpr std::string_view tag() { return "enchant"; }
static bool StoreTo(SpellInfo const*& val, std::string_view text);
};
struct TC_GAME_API garrfollower
{
using value_type = GarrisonFollowerLinkData const&;
static constexpr std::string_view tag() { return "garrfollower"; }
static bool StoreTo(GarrisonFollowerLinkData& val, std::string_view text);
};
struct TC_GAME_API garrfollowerability
{
using value_type = GarrAbilityEntry const*;
static constexpr std::string_view tag() { return "garrfollowerability"; }
static bool StoreTo(GarrAbilityEntry const*& val, std::string_view text);
};
struct TC_GAME_API garrmission
{
using value_type = GarrisonMissionLinkData const&;
static constexpr std::string_view tag() { return "garrmission"; }
static bool StoreTo(GarrisonMissionLinkData& val, std::string_view text);
};
struct TC_GAME_API instancelock
{
using value_type = InstanceLockLinkData const&;
static constexpr std::string_view tag() { return "instancelock"; }
static bool StoreTo(InstanceLockLinkData& val, std::string_view text);
};
struct TC_GAME_API item
{
using value_type = ItemLinkData const&;
static constexpr std::string_view tag() { return "item"; }
static bool StoreTo(ItemLinkData& val, std::string_view text);
};
struct TC_GAME_API journal
{
using value_type = JournalLinkData const&;
static constexpr std::string_view tag() { return "journal"; }
static bool StoreTo(JournalLinkData& val, std::string_view text);
};
struct TC_GAME_API keystone
{
using value_type = KeystoneLinkData const&;
static constexpr std::string_view tag() { return "keystone"; }
static bool StoreTo(KeystoneLinkData& val, std::string_view text);
};
struct TC_GAME_API mawpower
{
using value_type = MawPowerEntry const*;
static constexpr std::string_view tag() { return "mawpower"; }
static bool StoreTo(MawPowerEntry const*& val, std::string_view text);
};
struct TC_GAME_API pvptal
{
using value_type = PvpTalentEntry const*;
static constexpr std::string_view tag() { return "pvptal"; }
static bool StoreTo(PvpTalentEntry const*& val, std::string_view text);
};
struct TC_GAME_API quest
{
using value_type = QuestLinkData const&;
static constexpr std::string_view tag() { return "quest"; }
static bool StoreTo(QuestLinkData& val, std::string_view text);
};
struct TC_GAME_API spell
{
using value_type = SpellLinkData const&;
static constexpr std::string_view tag() { return "spell"; }
static bool StoreTo(SpellLinkData& val, std::string_view text);
};
struct TC_GAME_API talent
{
using value_type = TalentEntry const*;
static constexpr std::string_view tag() { return "talent"; }
static bool StoreTo(TalentEntry const*& val, std::string_view text);
};
struct TC_GAME_API trade
{
using value_type = TradeskillLinkData const&;
static constexpr std::string_view tag() { return "trade"; }
static bool StoreTo(TradeskillLinkData& val, std::string_view text);
};
struct TC_GAME_API transmogappearance
{
using value_type = ItemModifiedAppearanceEntry const*;
static constexpr std::string_view tag() { return "transmogappearance"; }
static bool StoreTo(ItemModifiedAppearanceEntry const*& val, std::string_view text);
};
struct TC_GAME_API transmogillusion
{
using value_type = SpellItemEnchantmentEntry const*;
static constexpr std::string_view tag() { return "transmogillusion"; }
static bool StoreTo(SpellItemEnchantmentEntry const*& val, std::string_view text);
};
struct TC_GAME_API transmogset
{
using value_type = TransmogSetEntry const*;
static constexpr std::string_view tag() { return "transmogset"; }
static bool StoreTo(TransmogSetEntry const*& val, std::string_view text);
};
struct TC_GAME_API worldmap
{
using value_type = WorldMapLinkData const&;
static constexpr std::string_view tag() { return "worldmap"; }
static bool StoreTo(WorldMapLinkData& val, std::string_view text);
};
}
struct HyperlinkColor
{
HyperlinkColor(uint32 c) : r(c >> 16), g(c >> 8), b(c), a(c >> 24) {}
uint8 const r, g, b, a;
bool operator==(uint32 c) const
{
if ((c & 0xff) ^ b)
return false;
if (((c >>= 8) & 0xff) ^ g)
return false;
if (((c >>= 8) & 0xff) ^ r)
return false;
if ((c >>= 8) ^ a)
return false;
return true;
}
};
struct HyperlinkInfo
{
HyperlinkInfo() : ok(false), color(0) {}
HyperlinkInfo(std::string_view t, uint32 c, std::string_view ta, std::string_view d, std::string_view te) :
ok(true), tail(t), color(c), tag(ta), data(d), text(te) {}
explicit operator bool() { return ok; }
bool const ok;
std::string_view const tail;
HyperlinkColor const color;
std::string_view const tag;
std::string_view const data;
std::string_view const text;
};
HyperlinkInfo TC_GAME_API ParseSingleHyperlink(std::string_view str);
bool TC_GAME_API CheckAllLinks(std::string_view str);
}
#endif
|