Skip to content

Commit

Permalink
Merge branch 'dressnpcs_master' of github.com:Rochet2/TrinityCore int…
Browse files Browse the repository at this point in the history
…o freedom9_dressnpcs
  • Loading branch information
Kretol committed Sep 6, 2022
2 parents add53fb + f6f2231 commit 7909ace
Show file tree
Hide file tree
Showing 37 changed files with 870 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmake/options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ option(COPY_CONF "Copy authserver and worldserver .conf.dist files to the
set(WITH_SOURCE_TREE "hierarchical" CACHE STRING "Build the source tree for IDE's.")
set_property(CACHE WITH_SOURCE_TREE PROPERTY STRINGS no flat hierarchical hierarchical-folders)
option(WITHOUT_GIT "Disable the GIT testing routines" 0)
option(DISABLE_DRESSNPCS_CORESOUNDS "Disable server side 'missing sounds' workaround" 0)
option(BUILD_TESTING "Build test suite" 0)

if(UNIX)
Expand Down
6 changes: 6 additions & 0 deletions cmake/showoptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@ if(BUILD_SHARED_LIBS)
WarnAboutSpacesInBuildPath()
endif()

if (DISABLE_DRESSNPCS_CORESOUNDS)
message("")
message("DressNPCs sound workaround disabled. Live without sounds or use a client side patch.")
add_definitions(-DDISABLE_DRESSNPCS_CORESOUNDS)
endif()

message("")
Original file line number Diff line number Diff line change
Expand Up @@ -1128,6 +1128,9 @@ void HotfixDatabaseConnection::DoPrepareStatements()
PrepareStatement(HOTFIX_SEL_NAMES_RESERVED_LOCALE, "SELECT ID, Name, LocaleMask FROM names_reserved_locale WHERE (`VerifiedBuild` > 0) = ?", CONNECTION_SYNCH);
PREPARE_MAX_ID_STMT(HOTFIX_SEL_NAMES_RESERVED_LOCALE, "SELECT MAX(ID) + 1 FROM names_reserved_locale", CONNECTION_SYNCH);

// NPCSounds.db2
PrepareStatement(HOTFIX_SEL_NPC_SOUNDS, "SELECT ID, hello, goodbye, pissed, ack FROM npc_sounds WHERE (`VerifiedBuild` > 0) = ? ORDER BY ID DESC", CONNECTION_SYNCH);

// NumTalentsAtLevel.db2
PrepareStatement(HOTFIX_SEL_NUM_TALENTS_AT_LEVEL, "SELECT ID, NumTalents, NumTalentsDeathKnight, NumTalentsDemonHunter FROM num_talents_at_level"
" WHERE (`VerifiedBuild` > 0) = ?", CONNECTION_SYNCH);
Expand Down
2 changes: 2 additions & 0 deletions src/server/database/Database/Implementation/HotfixDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,8 @@ enum HotfixDatabaseStatements : uint32
HOTFIX_SEL_NAMES_RESERVED_LOCALE,
HOTFIX_SEL_NAMES_RESERVED_LOCALE_MAX_ID,

HOTFIX_SEL_NPC_SOUNDS,

HOTFIX_SEL_NUM_TALENTS_AT_LEVEL,
HOTFIX_SEL_NUM_TALENTS_AT_LEVEL_MAX_ID,

Expand Down
17 changes: 17 additions & 0 deletions src/server/game/DataStores/DB2LoadInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -4227,6 +4227,23 @@ struct NamesReservedLocaleLoadInfo
}
};

struct NPCSoundsLoadInfo
{
static DB2LoadInfo const* Instance()
{
static DB2FieldMeta const fields[] =
{
{ false, FT_INT, "ID" },
{ false, FT_INT, "hello" },
{ false, FT_INT, "goodbye" },
{ false, FT_INT, "pissed" },
{ false, FT_INT, "ack" },
};
static DB2LoadInfo const loadInfo(&fields[0], std::extent<decltype(fields)>::value, NPCSoundsMeta::Instance(), HOTFIX_SEL_NPC_SOUNDS);
return &loadInfo;
}
};

struct NumTalentsAtLevelLoadInfo
{
static DB2LoadInfo const* Instance()
Expand Down
12 changes: 10 additions & 2 deletions src/server/game/DataStores/DB2Stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#include "ItemTemplate.h"
#include "IteratorPair.h"
#include "Log.h"
#include "ObjectDefines.h"
#include "ObjectMgr.h"
#include "Random.h"
#include "Regex.h"
#include "Timer.h"
Expand Down Expand Up @@ -108,7 +110,11 @@ DB2Storage<ContentTuningEntry> sContentTuningStore("ContentTuni
DB2Storage<ContentTuningXExpectedEntry> sContentTuningXExpectedStore("ContentTuningXExpected.db2", ContentTuningXExpectedLoadInfo::Instance());
DB2Storage<ConversationLineEntry> sConversationLineStore("ConversationLine.db2", ConversationLineLoadInfo::Instance());
DB2Storage<CorruptionEffectsEntry> sCorruptionEffectsStore("CorruptionEffects.db2", CorruptionEffectsLoadInfo::Instance());
DB2Storage<CreatureDisplayInfoEntry> sCreatureDisplayInfoStore("CreatureDisplayInfo.db2", CreatureDisplayInfoLoadInfo::Instance());
DB2Storage<CreatureDisplayInfoEntry> sCreatureDisplayInfoStoreRaw("CreatureDisplayInfo.db2", CreatureDisplayInfoLoadInfo::Instance());
CreatureDisplayInfoStore sCreatureDisplayInfoStore;
bool CreatureDisplayInfoStore::HasRecord(uint32 id) const { return sCreatureDisplayInfoStoreRaw.HasRecord(sObjectMgr->GetRealDisplayId(id)); }
const CreatureDisplayInfoEntry * CreatureDisplayInfoStore::LookupEntry(uint32 id) const { return sCreatureDisplayInfoStoreRaw.LookupEntry(sObjectMgr->GetRealDisplayId(id)); }
const CreatureDisplayInfoEntry * CreatureDisplayInfoStore::AssertEntry(uint32 id) const { return sCreatureDisplayInfoStoreRaw.AssertEntry(sObjectMgr->GetRealDisplayId(id)); }
DB2Storage<CreatureDisplayInfoExtraEntry> sCreatureDisplayInfoExtraStore("CreatureDisplayInfoExtra.db2", CreatureDisplayInfoExtraLoadInfo::Instance());
DB2Storage<CreatureFamilyEntry> sCreatureFamilyStore("CreatureFamily.db2", CreatureFamilyLoadInfo::Instance());
DB2Storage<CreatureModelDataEntry> sCreatureModelDataStore("CreatureModelData.db2", CreatureModelDataLoadInfo::Instance());
Expand Down Expand Up @@ -228,6 +234,7 @@ DB2Storage<NameGenEntry> sNameGenStore("NameGen.db2", Nam
DB2Storage<NamesProfanityEntry> sNamesProfanityStore("NamesProfanity.db2", NamesProfanityLoadInfo::Instance());
DB2Storage<NamesReservedEntry> sNamesReservedStore("NamesReserved.db2", NamesReservedLoadInfo::Instance());
DB2Storage<NamesReservedLocaleEntry> sNamesReservedLocaleStore("NamesReservedLocale.db2", NamesReservedLocaleLoadInfo::Instance());
DB2Storage<NPCSoundsEntry> sNPCSoundsStore("NPCSounds.db2", NPCSoundsLoadInfo::Instance());
DB2Storage<NumTalentsAtLevelEntry> sNumTalentsAtLevelStore("NumTalentsAtLevel.db2", NumTalentsAtLevelLoadInfo::Instance());
DB2Storage<OverrideSpellDataEntry> sOverrideSpellDataStore("OverrideSpellData.db2", OverrideSpellDataLoadInfo::Instance());
DB2Storage<ParagonReputationEntry> sParagonReputationStore("ParagonReputation.db2", ParagonReputationLoadInfo::Instance());
Expand Down Expand Up @@ -682,7 +689,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
LOAD_DB2(sContentTuningXExpectedStore);
LOAD_DB2(sConversationLineStore);
LOAD_DB2(sCorruptionEffectsStore);
LOAD_DB2(sCreatureDisplayInfoStore);
LOAD_DB2(sCreatureDisplayInfoStoreRaw);
LOAD_DB2(sCreatureDisplayInfoExtraStore);
LOAD_DB2(sCreatureFamilyStore);
LOAD_DB2(sCreatureModelDataStore);
Expand Down Expand Up @@ -802,6 +809,7 @@ uint32 DB2Manager::LoadStores(std::string const& dataPath, LocaleConstant defaul
LOAD_DB2(sNamesProfanityStore);
LOAD_DB2(sNamesReservedStore);
LOAD_DB2(sNamesReservedLocaleStore);
LOAD_DB2(sNPCSoundsStore);
LOAD_DB2(sNumTalentsAtLevelStore);
LOAD_DB2(sOverrideSpellDataStore);
LOAD_DB2(sParagonReputationStore);
Expand Down
4 changes: 3 additions & 1 deletion src/server/game/DataStores/DB2Stores.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ TC_GAME_API extern DB2Storage<CinematicSequencesEntry> sCinematicSe
TC_GAME_API extern DB2Storage<ContentTuningEntry> sContentTuningStore;
TC_GAME_API extern DB2Storage<ConversationLineEntry> sConversationLineStore;
TC_GAME_API extern DB2Storage<CorruptionEffectsEntry> sCorruptionEffectsStore;
TC_GAME_API extern DB2Storage<CreatureDisplayInfoEntry> sCreatureDisplayInfoStore;
TC_GAME_API extern DB2Storage<CreatureDisplayInfoEntry> sCreatureDisplayInfoStoreRaw;
TC_GAME_API extern CreatureDisplayInfoStore sCreatureDisplayInfoStore;
TC_GAME_API extern DB2Storage<CreatureDisplayInfoExtraEntry> sCreatureDisplayInfoExtraStore;
TC_GAME_API extern DB2Storage<CreatureFamilyEntry> sCreatureFamilyStore;
TC_GAME_API extern DB2Storage<CreatureModelDataEntry> sCreatureModelDataStore;
Expand Down Expand Up @@ -172,6 +173,7 @@ TC_GAME_API extern DB2Storage<ModifierTreeEntry> sModifierTre
TC_GAME_API extern DB2Storage<MountCapabilityEntry> sMountCapabilityStore;
TC_GAME_API extern DB2Storage<MountEntry> sMountStore;
TC_GAME_API extern DB2Storage<MovieEntry> sMovieStore;
TC_GAME_API extern DB2Storage<NPCSoundsEntry> sNPCSoundsStore;
TC_GAME_API extern DB2Storage<OverrideSpellDataEntry> sOverrideSpellDataStore;
TC_GAME_API extern DB2Storage<ParagonReputationEntry> sParagonReputationStore;
TC_GAME_API extern DB2Storage<PhaseEntry> sPhaseStore;
Expand Down
16 changes: 16 additions & 0 deletions src/server/game/DataStores/DB2Structure.h
Original file line number Diff line number Diff line change
Expand Up @@ -2707,6 +2707,22 @@ struct NamesReservedLocaleEntry
uint8 LocaleMask;
};

struct NPCSoundsEntry
{
uint32 ID;
uint32 hello;
uint32 goodbye;
uint32 pissed;
uint32 ack;
};

struct CreatureDisplayInfoStore
{
bool HasRecord(uint32 id) const;
const CreatureDisplayInfoEntry * LookupEntry(uint32 id) const;
const CreatureDisplayInfoEntry * AssertEntry(uint32 id) const;
};

struct NumTalentsAtLevelEntry
{
uint32 ID;
Expand Down
99 changes: 99 additions & 0 deletions src/server/game/Entities/Creature/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "CreatureAI.h"
#include "CreatureAISelector.h"
#include "CreatureGroups.h"
#include "CreatureOutfit.h"
#include "DatabaseEnv.h"
#include "DB2Stores.h"
#include "Formulas.h"
Expand Down Expand Up @@ -365,6 +366,49 @@ void Creature::RemoveFromWorld()
}
}

void Creature::SetOutfit(std::shared_ptr<CreatureOutfit> const & outfit)
{
// Set new outfit
if (m_outfit)
{
// if had old outfit
// then delay displayid setting to allow equipment
// to change by using invisible model in between
SetDisplayId(CreatureOutfit::invisible_model);
m_outfit = outfit;
}
else
{
// else set new outfit directly since we change from non-outfit->outfit
m_outfit = outfit;
SetDisplayId(outfit->GetDisplayId());
}
}

void Creature::SendMirrorSound(Player* target, uint8 type)
{
std::shared_ptr<CreatureOutfit> const & outfit = GetOutfit();
if (!outfit)
return;
if (!outfit->npcsoundsid)
return;
if (auto const* npcsounds = sNPCSoundsStore.LookupEntry(outfit->npcsoundsid))
{
switch (type)
{
case 0:
PlayDistanceSound(npcsounds->hello, target);
break;
case 1:
PlayDistanceSound(npcsounds->goodbye, target);
break;
case 2:
PlayDistanceSound(npcsounds->pissed, target);
break;
}
}
}

bool Creature::IsReturningHome() const
{
if (GetMotionMaster()->GetCurrentMovementGeneratorType() == HOME_MOTION_TYPE)
Expand Down Expand Up @@ -620,6 +664,9 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/,

ReplaceAllUnitFlags(UnitFlags(unitFlags));
ReplaceAllUnitFlags2(UnitFlags2(unitFlags2));
bool needsflag = m_outfit && Unit::GetDisplayId() == m_outfit->GetDisplayId();
if (needsflag)
SetMirrorImageFlag(true);
ReplaceAllUnitFlags3(UnitFlags3(unitFlags3));

ReplaceAllDynamicFlags(dynamicFlags);
Expand Down Expand Up @@ -699,8 +746,22 @@ bool Creature::UpdateEntry(uint32 entry, CreatureData const* data /*= nullptr*/,
return true;
}

// copy paste from ClearChangesMask
template<typename Derived, typename T, uint32 BlockBit, uint32 Bit>
static uint32 GetUpdateFieldHolderIndex(UF::UpdateField<T, BlockBit, Bit>(Derived::* /*field*/))
{
return Bit;
}

void Creature::Update(uint32 diff)
{
if (m_outfit && !m_values.HasChanged(GetUpdateFieldHolderIndex(&UF::UnitData::DisplayID)) && Unit::GetDisplayId() == CreatureOutfit::invisible_model)
{
// has outfit, displayid is invisible and displayid update already sent to clients
// set outfit display
SetDisplayId(m_outfit->GetDisplayId());
}

if (IsAIEnabled() && m_triggerJustAppeared && m_deathState != DEAD)
{
if (m_respawnCompatibilityMode && m_vehicleKit)
Expand Down Expand Up @@ -3211,7 +3272,45 @@ void Creature::SetObjectScale(float scale)
}
}

uint32 Creature::GetDisplayId() const
{
if (m_outfit && m_outfit->GetId())
return m_outfit->GetId();
return Unit::GetDisplayId();
}

void Creature::SetDisplayId(uint32 modelId, float displayScale /*= 1.f*/)
{
if (auto const & outfit = sObjectMgr->GetOutfit(modelId))
{
SetOutfit(outfit);
return;
}
else
{
if (m_outfit)
{
// if has outfit
if (modelId != m_outfit->GetDisplayId())
{
// and outfit's real modelid doesnt match modelid being set
// remove outfit and continue setting the new model
m_outfit.reset();
SetMirrorImageFlag(false);
}
else
{
// outfit's real modelid being set
// add flags and continue setting the model
SetMirrorImageFlag(true);
}
}
}

SetDisplayIdRaw(modelId, displayScale);
}

void Creature::SetDisplayIdRaw(uint32 modelId, float displayScale /*= 1.f*/)
{
Unit::SetDisplayId(modelId, displayScale);

Expand Down
12 changes: 12 additions & 0 deletions src/server/game/Entities/Creature/Creature.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#include "MapObject.h"
#include <list>

class CreatureOutfit;
#include <memory>

class CreatureAI;
class CreatureGroup;
class Group;
Expand Down Expand Up @@ -79,6 +82,13 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
void SetObjectScale(float scale) override;
void SetDisplayId(uint32 displayId, float displayScale = 1.f) override;
void SetDisplayFromModel(uint32 modelIdx);
uint32 GetDisplayId() const final;
void SetDisplayIdRaw(uint32 modelId, float displayScale = 1.f);

std::shared_ptr<CreatureOutfit> & GetOutfit() { return m_outfit; };
void SetOutfit(std::shared_ptr<CreatureOutfit> const & outfit);
void SetMirrorImageFlag(bool on) { if (on) SetUnitFlag2(UNIT_FLAG2_MIRROR_IMAGE); else RemoveUnitFlag2(UNIT_FLAG2_MIRROR_IMAGE); };
void SendMirrorSound(Player* target, uint8 type);

void DisappearAndDie() { ForcedDespawn(0); }

Expand Down Expand Up @@ -465,6 +475,8 @@ class TC_GAME_API Creature : public Unit, public GridObject<Creature>, public Ma
float Orientation = 0.0f; // the creature's "real" orientation while casting
} _spellFocusInfo;

std::shared_ptr<CreatureOutfit> m_outfit;

time_t _lastDamagedTime; // Part of Evade mechanics
CreatureTextRepeatGroup m_textRepeat;

Expand Down
27 changes: 27 additions & 0 deletions src/server/game/Entities/Creature/CreatureOutfit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include "CreatureOutfit.h"
#include "DB2Structure.h" // ChrRacesEntry
#include "DB2Stores.h" // sChrRacesStore, sDB2Manager

constexpr uint32 CreatureOutfit::invisible_model;
constexpr uint32 CreatureOutfit::max_real_modelid;
constexpr EquipmentSlots CreatureOutfit::item_slots[];

CreatureOutfit::CreatureOutfit(uint8 race, Gender gender) : race(race), gender(gender)
{
auto* model = sDB2Manager.GetChrModel(race, gender);
if (!model)
{
model = sDB2Manager.GetChrModel(RACE_HUMAN, GENDER_MALE);
ASSERT(model);
}
displayId = model->DisplayID;
}

CreatureOutfit& CreatureOutfit::SetItemEntry(EquipmentSlots slot, uint32 item_entry, uint32 appearancemodid)
{
if (uint32 display = sDB2Manager.GetItemDisplayId(item_entry, appearancemodid))
outfitdisplays[slot] = display;
else
outfitdisplays[slot] = 0;
return *this;
}
Loading

0 comments on commit 7909ace

Please sign in to comment.