Core/Players: Fixed appearance validation

Closes #20090
This commit is contained in:
Shauren
2017-08-23 17:36:17 +02:00
parent cdd76f31cb
commit 2d0e653866
3 changed files with 29 additions and 24 deletions

View File

@@ -20,6 +20,7 @@
#include "DatabaseEnv.h"
#include "DB2LoadInfo.h"
#include "Hash.h"
#include "IteratorPair.h"
#include "Log.h"
#include "ObjectDefines.h"
#include "Regex.h"
@@ -1179,12 +1180,17 @@ char const* DB2Manager::GetBroadcastTextValue(BroadcastTextEntry const* broadcas
return broadcastText->MaleText->Str[DEFAULT_LOCALE];
}
bool DB2Manager::HasCharSections(uint8 race, CharSectionType genType, uint8 gender) const
{
auto range = Trinity::Containers::MapEqualRange(_charSections, uint32(genType) | uint32(gender << 8) | uint32(race << 16));
return range.begin() != range.end();
}
CharSectionsEntry const* DB2Manager::GetCharSectionEntry(uint8 race, CharSectionType genType, uint8 gender, uint8 type, uint8 color) const
{
auto eqr = _charSections.equal_range(uint32(genType) | uint32(gender << 8) | uint32(race << 16));
for (auto itr = eqr.first; itr != eqr.second; ++itr)
if (itr->second->Type == type && itr->second->Color == color)
return itr->second;
for (auto const& section : Trinity::Containers::MapEqualRange(_charSections, uint32(genType) | uint32(gender << 8) | uint32(race << 16)))
if (section.second->Type == type && section.second->Color == color)
return section.second;
return nullptr;
}

View File

@@ -253,6 +253,7 @@ public:
std::unordered_set<uint32> const* GetArtifactPowerLinks(uint32 artifactPowerId) const;
ArtifactPowerRankEntry const* GetArtifactPowerRank(uint32 artifactPowerId, uint8 rank) const;
static char const* GetBroadcastTextValue(BroadcastTextEntry const* broadcastText, LocaleConstant locale = DEFAULT_LOCALE, uint8 gender = GENDER_MALE, bool forceGender = false);
bool HasCharSections(uint8 race, CharSectionType genType, uint8 gender) const;
CharSectionsEntry const* GetCharSectionEntry(uint8 race, CharSectionType genType, uint8 gender, uint8 type, uint8 color) const;
CharStartOutfitEntry const* GetCharStartOutfitEntry(uint8 race, uint8 class_, uint8 gender) const;
static char const* GetClassName(uint8 class_, LocaleConstant locale = DEFAULT_LOCALE);

View File

@@ -27606,37 +27606,35 @@ bool IsSectionFlagValid(CharSectionsEntry const* entry, uint8 class_, bool creat
return ComponentFlagsMatch(entry, GetSelectionFromContext(2, class_));
}
bool IsSectionValid(uint8 race, uint8 class_, CharSectionType genType, uint8 gender, uint8 type, uint8 color, bool create)
{
CharSectionsEntry const* section = sDB2Manager.GetCharSectionEntry(race, genType, gender, type, color);
if (section)
return IsSectionFlagValid(section, class_, create);
if (!sDB2Manager.HasCharSections(race, genType, gender))
return type == 0;
return false;
}
bool Player::ValidateAppearance(uint8 race, uint8 class_, uint8 gender, uint8 hairID, uint8 hairColor, uint8 faceID, uint8 facialHairID, uint8 skinColor, std::array<uint8, PLAYER_CUSTOM_DISPLAY_SIZE> const& customDisplay, bool create /*= false*/)
{
CharSectionsEntry const* skin = sDB2Manager.GetCharSectionEntry(race, SECTION_TYPE_SKIN, gender, 0, skinColor);
if (!skin)
if (!IsSectionValid(race, class_, SECTION_TYPE_SKIN, gender, 0, skinColor, create))
return false;
if (!IsSectionFlagValid(skin, class_, create))
if (!IsSectionValid(race, class_, SECTION_TYPE_FACE, gender, faceID, skinColor, create))
return false;
CharSectionsEntry const* face = sDB2Manager.GetCharSectionEntry(race, SECTION_TYPE_FACE, gender, faceID, skinColor);
if (!face)
if (!IsSectionValid(race, class_, SECTION_TYPE_HAIR, gender, hairID, hairColor, create))
return false;
if (!IsSectionFlagValid(face, class_, create))
return false;
CharSectionsEntry const* hair = sDB2Manager.GetCharSectionEntry(race, SECTION_TYPE_HAIR, gender, hairID, hairColor);
if (!hair)
return false;
if (!IsSectionFlagValid(hair, class_, create))
return false;
CharSectionsEntry const* facialHair = sDB2Manager.GetCharSectionEntry(race, SECTION_TYPE_FACIAL_HAIR, gender, facialHairID, hairColor);
if (!facialHair)
if (!IsSectionValid(race, class_, SECTION_TYPE_FACIAL_HAIR, gender, facialHairID, hairColor, create))
return false;
for (uint32 i = 0; i < PLAYER_CUSTOM_DISPLAY_SIZE; ++i)
if (CharSectionsEntry const* entry = sDB2Manager.GetCharSectionEntry(race, CharSectionType(SECTION_TYPE_CUSTOM_DISPLAY_1 + i * 2), gender, customDisplay[i], 0))
if (!IsSectionFlagValid(entry, class_, create))
return false;
if (!IsSectionValid(race, class_, CharSectionType(SECTION_TYPE_CUSTOM_DISPLAY_1 + i * 2), gender, customDisplay[i], 0, create))
return false;
return true;
}