From 1d51013b71d46a2825519cdb85d7049109b226ae Mon Sep 17 00:00:00 2001 From: Matan Shukry Date: Sat, 23 Jan 2021 16:35:22 +0200 Subject: Scripts/Commands: Fixed .modify gender not setting correct customizations (#25920) --- src/server/scripts/Commands/cs_modify.cpp | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src') diff --git a/src/server/scripts/Commands/cs_modify.cpp b/src/server/scripts/Commands/cs_modify.cpp index 2e04bbbae40..4931818f171 100644 --- a/src/server/scripts/Commands/cs_modify.cpp +++ b/src/server/scripts/Commands/cs_modify.cpp @@ -23,6 +23,7 @@ Category: commandscripts EndScriptData */ #include "ScriptMgr.h" +#include "CharacterCache.h" #include "Chat.h" #include "DB2Stores.h" #include "Log.h" @@ -34,6 +35,7 @@ EndScriptData */ #include "ReputationMgr.h" #include "SpellMgr.h" #include "SpellPackets.h" +#include "UpdateFields.h" #include "WorldSession.h" class modify_commandscript : public CommandScript @@ -891,6 +893,40 @@ public: // Change display ID target->InitDisplayIds(); + target->RestoreDisplayId(false); + sCharacterCache->UpdateCharacterGender(target->GetGUID(), gender); + + // Generate random customizations + std::vector customizations; + + Classes playerClass = Classes(target->getClass()); + std::vector const* options = sDB2Manager.GetCustomiztionOptions(target->getRace(), gender); + WorldSession const* worldSession = target->GetSession(); + for (ChrCustomizationOptionEntry const* option : *options) + { + ChrCustomizationReqEntry const* optionReq = sChrCustomizationReqStore.LookupEntry(option->ChrCustomizationReqID); + if (optionReq && !worldSession->MeetsChrCustomizationReq(optionReq, playerClass, false, MakeChrCustomizationChoiceRange(customizations))) + continue; + + // Loop over the options until the first one fits + std::vector const* choicesForOption = sDB2Manager.GetCustomiztionChoices(option->ID); + for (ChrCustomizationChoiceEntry const* choiceForOption : *choicesForOption) + { + ChrCustomizationReqEntry const* choiceReq = sChrCustomizationReqStore.LookupEntry(choiceForOption->ChrCustomizationReqID); + if (choiceReq && !worldSession->MeetsChrCustomizationReq(choiceReq, playerClass, false, MakeChrCustomizationChoiceRange(customizations))) + continue; + + ChrCustomizationChoiceEntry const* choiceEntry = choicesForOption->at(0); + UF::ChrCustomizationChoice choice; + choice.ChrCustomizationOptionID = option->ID; + choice.ChrCustomizationChoiceID = choiceEntry->ID; + customizations.push_back(choice); + break; + } + } + + target->SetCustomizations(Trinity::Containers::MakeIteratorPair(customizations.begin(), customizations.end())); + char const* gender_full = gender ? "female" : "male"; handler->PSendSysMessage(LANG_YOU_CHANGE_GENDER, handler->GetNameLink(target).c_str(), gender_full); -- cgit v1.2.3