mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-03-25 08:30:13 +00:00
Add comprehensive NPC voice system with interaction and combat sounds
Implements full NPC voice interaction system supporting 6 different sound categories for all playable races/genders. System loads ~450+ voice clips from MPQ archives. Voice Categories: - Greeting: Play on NPC right-click interaction - Farewell: Play when closing gossip/dialog windows - Vendor: Play when opening merchant/vendor windows - Pissed: Play after clicking NPC 5+ times (spam protection) - Aggro: Play when NPC enters combat with player - Flee: Play when NPC is fleeing (ready for low-health triggers) Features: - Race/gender detection from NPC display IDs via CreatureDisplayInfoExtra.dbc - Intelligent click tracking for pissed sounds - Combat sounds use player character vocal files for humanoid NPCs - Cooldown system prevents voice spam (2s default, combat sounds bypass) - Generic fallback voices for unsupported NPC types - 3D positional audio support Voice Support: - All playable races: Human, Dwarf, Gnome, Night Elf, Orc, Tauren, Troll, Undead - Male and female variants for each race - StandardNPC sounds for social interactions - Character vocal sounds for combat Technical Changes: - Refactored NpcVoiceManager to support multiple sound categories - Added callbacks: NpcFarewell, NpcVendor, NpcAggro - Extended voice loading to parse both StandardNPC and Character vocal paths - Integrated with GameHandler for gossip, vendor, and combat events - Added detailed voice detection logging for debugging Also includes: - Sound manifest files added to docs/ for reference - Blacksmith hammer pitch increased to 1.6x (was 1.4x) - Blacksmith volume reduced 30% to 0.25 (was 0.35)
This commit is contained in:
parent
251f0ac246
commit
28d009f7db
8 changed files with 10908 additions and 198 deletions
|
|
@ -23,7 +23,7 @@ bool NpcVoiceManager::initialize(pipeline::AssetManager* assets) {
|
|||
// Files are .WAV not .OGG in WotLK 3.3.5a!
|
||||
LOG_INFO("=== Probing for NPC voice files (.wav format) ===");
|
||||
std::vector<std::string> testPaths = {
|
||||
"Sound\\Creature\\HumanMaleStandardNPC\\HumanMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\HumanMaleStandardNPC\\HumanMaleStandardNPCGreetings01.wav",
|
||||
"Sound\\Creature\\HumanFemaleStandardNPC\\HumanFemaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\DwarfMaleStandardNPC\\DwarfMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\OrcMaleStandardNPC\\OrcMaleStandardNPCGreeting01.wav",
|
||||
|
|
@ -32,260 +32,333 @@ bool NpcVoiceManager::initialize(pipeline::AssetManager* assets) {
|
|||
bool exists = assetManager_->fileExists(path);
|
||||
LOG_INFO(" ", path, ": ", (exists ? "EXISTS" : "NOT FOUND"));
|
||||
}
|
||||
LOG_INFO("=== Probing for tavern music files ===");
|
||||
std::vector<std::string> musicPaths = {
|
||||
"Sound\\Music\\GlueScreenMusic\\tavern_01.mp3",
|
||||
"Sound\\Music\\GlueScreenMusic\\BC_Alehouse.mp3",
|
||||
"Sound\\Music\\ZoneMusic\\Tavern\\tavernAlliance01.mp3",
|
||||
};
|
||||
for (const auto& path : musicPaths) {
|
||||
bool exists = assetManager_->fileExists(path);
|
||||
LOG_INFO(" ", path, ": ", (exists ? "EXISTS" : "NOT FOUND"));
|
||||
}
|
||||
LOG_INFO("===================================");
|
||||
|
||||
loadVoiceSounds();
|
||||
|
||||
int totalSamples = 0;
|
||||
for (const auto& [type, samples] : voiceLibrary_) {
|
||||
totalSamples += samples.size();
|
||||
}
|
||||
for (const auto& [type, samples] : greetingLibrary_) totalSamples += samples.size();
|
||||
for (const auto& [type, samples] : farewellLibrary_) totalSamples += samples.size();
|
||||
for (const auto& [type, samples] : vendorLibrary_) totalSamples += samples.size();
|
||||
for (const auto& [type, samples] : pissedLibrary_) totalSamples += samples.size();
|
||||
for (const auto& [type, samples] : aggroLibrary_) totalSamples += samples.size();
|
||||
for (const auto& [type, samples] : fleeLibrary_) totalSamples += samples.size();
|
||||
LOG_INFO("NPC voice manager initialized (", totalSamples, " voice clips)");
|
||||
return true;
|
||||
}
|
||||
|
||||
void NpcVoiceManager::shutdown() {
|
||||
voiceLibrary_.clear();
|
||||
greetingLibrary_.clear();
|
||||
farewellLibrary_.clear();
|
||||
vendorLibrary_.clear();
|
||||
pissedLibrary_.clear();
|
||||
aggroLibrary_.clear();
|
||||
fleeLibrary_.clear();
|
||||
lastPlayTime_.clear();
|
||||
clickCount_.clear();
|
||||
assetManager_ = nullptr;
|
||||
}
|
||||
|
||||
void NpcVoiceManager::loadVoiceSounds() {
|
||||
if (!assetManager_) return;
|
||||
|
||||
// WotLK 3.3.5a uses .WAV files, not .OGG!
|
||||
// Files use "Greeting" (singular) not "Greetings"
|
||||
// Helper to load voice category for a race/gender
|
||||
auto loadCategory = [this](
|
||||
std::unordered_map<VoiceType, std::vector<VoiceSample>>& library,
|
||||
VoiceType type,
|
||||
const std::string& npcType,
|
||||
const std::string& soundType,
|
||||
int count) {
|
||||
|
||||
// Generic - mix of all races for variety
|
||||
auto& genericVoices = voiceLibrary_[VoiceType::GENERIC];
|
||||
auto& samples = library[type];
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
std::string num = (i < 10) ? ("0" + std::to_string(i)) : std::to_string(i);
|
||||
std::string path = "Sound\\Creature\\" + npcType + "\\" + npcType + soundType + num + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) samples.push_back(std::move(sample));
|
||||
}
|
||||
};
|
||||
|
||||
// Generic fallback voices (male only)
|
||||
auto& genericGreet = greetingLibrary_[VoiceType::GENERIC];
|
||||
for (const auto& path : {
|
||||
"Sound\\Creature\\HumanMaleStandardNPC\\HumanMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\HumanFemaleStandardNPC\\HumanFemaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\DwarfMaleStandardNPC\\DwarfMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\GnomeMaleStandardNPC\\GnomeMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\NightElfMaleStandardNPC\\NightElfMaleStandardNPCGreeting01.wav",
|
||||
"Sound\\Creature\\OrcMaleStandardNPC\\OrcMaleStandardNPCGreeting01.wav",
|
||||
}) {
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) genericVoices.push_back(std::move(sample));
|
||||
if (loadSound(path, sample)) genericGreet.push_back(std::move(sample));
|
||||
}
|
||||
|
||||
// Human Male
|
||||
auto& humanMale = voiceLibrary_[VoiceType::HUMAN_MALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\HumanMaleStandardNPC\\HumanMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) humanMale.push_back(std::move(sample));
|
||||
}
|
||||
// Load all race/gender combinations
|
||||
// Human Male uses "Greetings" (plural), others use "Greeting" (singular)
|
||||
loadCategory(greetingLibrary_, VoiceType::HUMAN_MALE, "HumanMaleStandardNPC", "Greetings", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::HUMAN_MALE, "HumanMaleStandardNPC", "Farewell", 5);
|
||||
loadCategory(vendorLibrary_, VoiceType::HUMAN_MALE, "HumanMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::HUMAN_MALE, "HumanMaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Human Female
|
||||
auto& humanFemale = voiceLibrary_[VoiceType::HUMAN_FEMALE];
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
std::string path = "Sound\\Creature\\HumanFemaleStandardNPC\\HumanFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) humanFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::HUMAN_FEMALE, "HumanFemaleStandardNPC", "Greeting", 5);
|
||||
loadCategory(farewellLibrary_, VoiceType::HUMAN_FEMALE, "HumanFemaleStandardNPC", "Farewell", 5);
|
||||
loadCategory(vendorLibrary_, VoiceType::HUMAN_FEMALE, "HumanFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::HUMAN_FEMALE, "HumanFemaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Dwarf Male
|
||||
auto& dwarfMale = voiceLibrary_[VoiceType::DWARF_MALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\DwarfMaleStandardNPC\\DwarfMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) dwarfMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::DWARF_MALE, "DwarfMaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::DWARF_MALE, "DwarfMaleStandardNPC", "Farewell", 4);
|
||||
loadCategory(vendorLibrary_, VoiceType::DWARF_MALE, "DwarfMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::DWARF_MALE, "DwarfMaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Gnome Male
|
||||
auto& gnomeMale = voiceLibrary_[VoiceType::GNOME_MALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\GnomeMaleStandardNPC\\GnomeMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) gnomeMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::GNOME_MALE, "GnomeMaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::GNOME_MALE, "GnomeMaleStandardNPC", "Farewell", 5);
|
||||
loadCategory(vendorLibrary_, VoiceType::GNOME_MALE, "GnomeMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::GNOME_MALE, "GnomeMaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Gnome Female
|
||||
auto& gnomeFemale = voiceLibrary_[VoiceType::GNOME_FEMALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\GnomeFemaleStandardNPC\\GnomeFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) gnomeFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::GNOME_FEMALE, "GnomeFemaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::GNOME_FEMALE, "GnomeFemaleStandardNPC", "Farewell", 5);
|
||||
loadCategory(vendorLibrary_, VoiceType::GNOME_FEMALE, "GnomeFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::GNOME_FEMALE, "GnomeFemaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Night Elf Male
|
||||
auto& nelfMale = voiceLibrary_[VoiceType::NIGHTELF_MALE];
|
||||
for (int i = 1; i <= 8; ++i) {
|
||||
std::string path = "Sound\\Creature\\NightElfMaleStandardNPC\\NightElfMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) nelfMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::NIGHTELF_MALE, "NightElfMaleStandardNPC", "Greeting", 8);
|
||||
loadCategory(farewellLibrary_, VoiceType::NIGHTELF_MALE, "NightElfMaleStandardNPC", "Farewell", 7);
|
||||
loadCategory(vendorLibrary_, VoiceType::NIGHTELF_MALE, "NightElfMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::NIGHTELF_MALE, "NightElfMaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Night Elf Female
|
||||
auto& nelfFemale = voiceLibrary_[VoiceType::NIGHTELF_FEMALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\NightElfFemaleStandardNPC\\NightElfFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) nelfFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElfFemaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElfFemaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElfFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElfFemaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Orc Male
|
||||
auto& orcMale = voiceLibrary_[VoiceType::ORC_MALE];
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
std::string path = "Sound\\Creature\\OrcMaleStandardNPC\\OrcMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) orcMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::ORC_MALE, "OrcMaleStandardNPC", "Greeting", 5);
|
||||
loadCategory(farewellLibrary_, VoiceType::ORC_MALE, "OrcMaleStandardNPC", "Farewell", 5);
|
||||
loadCategory(vendorLibrary_, VoiceType::ORC_MALE, "OrcMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::ORC_MALE, "OrcMaleStandardNPC", "Pissed", 4);
|
||||
|
||||
// Orc Female
|
||||
auto& orcFemale = voiceLibrary_[VoiceType::ORC_FEMALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\OrcFemaleStandardNPC\\OrcFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) orcFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::ORC_FEMALE, "OrcFemaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::ORC_FEMALE, "OrcFemaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::ORC_FEMALE, "OrcFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::ORC_FEMALE, "OrcFemaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Tauren Male
|
||||
auto& taurenMale = voiceLibrary_[VoiceType::TAUREN_MALE];
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
std::string path = "Sound\\Creature\\TaurenMaleStandardNPC\\TaurenMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) taurenMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::TAUREN_MALE, "TaurenMaleStandardNPC", "Greeting", 5);
|
||||
loadCategory(farewellLibrary_, VoiceType::TAUREN_MALE, "TaurenMaleStandardNPC", "Farewell", 5);
|
||||
// Tauren Male has no Vendor/Pissed sounds in manifest
|
||||
|
||||
// Tauren Female
|
||||
auto& taurenFemale = voiceLibrary_[VoiceType::TAUREN_FEMALE];
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
std::string path = "Sound\\Creature\\TaurenFemaleStandardNPC\\TaurenFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) taurenFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::TAUREN_FEMALE, "TaurenFemaleStandardNPC", "Greeting", 5);
|
||||
loadCategory(farewellLibrary_, VoiceType::TAUREN_FEMALE, "TaurenFemaleStandardNPC", "Farewell", 5);
|
||||
// Tauren Female has no Vendor/Pissed sounds in manifest
|
||||
|
||||
// Troll Male
|
||||
auto& trollMale = voiceLibrary_[VoiceType::TROLL_MALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\TrollMaleStandardNPC\\TrollMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) trollMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::TROLL_MALE, "TrollMaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::TROLL_MALE, "TrollMaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::TROLL_MALE, "TrollMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::TROLL_MALE, "TrollMaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Troll Female
|
||||
auto& trollFemale = voiceLibrary_[VoiceType::TROLL_FEMALE];
|
||||
for (int i = 1; i <= 5; ++i) {
|
||||
std::string path = "Sound\\Creature\\TrollFemaleStandardNPC\\TrollFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) trollFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::TROLL_FEMALE, "TrollFemaleStandardNPC", "Greeting", 5);
|
||||
loadCategory(farewellLibrary_, VoiceType::TROLL_FEMALE, "TrollFemaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::TROLL_FEMALE, "TrollFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::TROLL_FEMALE, "TrollFemaleStandardNPC", "Pissed", 5);
|
||||
|
||||
// Undead Male
|
||||
auto& undeadMale = voiceLibrary_[VoiceType::UNDEAD_MALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\UndeadMaleStandardNPC\\UndeadMaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) undeadMale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::UNDEAD_MALE, "UndeadMaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::UNDEAD_MALE, "UndeadMaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::UNDEAD_MALE, "UndeadMaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::UNDEAD_MALE, "UndeadMaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Undead Female
|
||||
auto& undeadFemale = voiceLibrary_[VoiceType::UNDEAD_FEMALE];
|
||||
for (int i = 1; i <= 6; ++i) {
|
||||
std::string path = "Sound\\Creature\\UndeadFemaleStandardNPC\\UndeadFemaleStandardNPCGreeting0" + std::to_string(i) + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) undeadFemale.push_back(std::move(sample));
|
||||
}
|
||||
loadCategory(greetingLibrary_, VoiceType::UNDEAD_FEMALE, "UndeadFemaleStandardNPC", "Greeting", 6);
|
||||
loadCategory(farewellLibrary_, VoiceType::UNDEAD_FEMALE, "UndeadFemaleStandardNPC", "Farewell", 6);
|
||||
loadCategory(vendorLibrary_, VoiceType::UNDEAD_FEMALE, "UndeadFemaleStandardNPC", "Vendor", 2);
|
||||
loadCategory(pissedLibrary_, VoiceType::UNDEAD_FEMALE, "UndeadFemaleStandardNPC", "Pissed", 6);
|
||||
|
||||
// Log loaded voice types
|
||||
int totalLoaded = 0;
|
||||
for (const auto& [type, samples] : voiceLibrary_) {
|
||||
if (!samples.empty()) {
|
||||
LOG_INFO("Loaded ", samples.size(), " voice samples for type ", static_cast<int>(type));
|
||||
totalLoaded += samples.size();
|
||||
// Load combat sounds from Character vocal files
|
||||
// These use a different path structure: Sound\Character\{Race}\{Race}Vocal{Gender}\{Race}{Gender}{Sound}.wav
|
||||
auto loadCombatCategory = [this](
|
||||
std::unordered_map<VoiceType, std::vector<VoiceSample>>& library,
|
||||
VoiceType type,
|
||||
const std::string& raceFolder,
|
||||
const std::string& raceGender,
|
||||
const std::string& soundType,
|
||||
int count) {
|
||||
|
||||
auto& samples = library[type];
|
||||
for (int i = 1; i <= count; ++i) {
|
||||
std::string num = (i < 10) ? ("0" + std::to_string(i)) : std::to_string(i);
|
||||
std::string path = "Sound\\Character\\" + raceFolder + "\\" + raceFolder + "Vocal" +
|
||||
(raceGender.find("Male") != std::string::npos ? "Male" : "Female") +
|
||||
"\\" + raceGender + soundType + num + ".wav";
|
||||
VoiceSample sample;
|
||||
if (loadSound(path, sample)) samples.push_back(std::move(sample));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (totalLoaded == 0) {
|
||||
LOG_WARNING("NPC voice manager: no voice samples loaded (files may not exist in MPQ)");
|
||||
}
|
||||
// Human combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::HUMAN_MALE, "Human", "HumanMale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::HUMAN_MALE, "Human", "HumanMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::HUMAN_FEMALE, "Human", "HumanFemale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::HUMAN_FEMALE, "Human", "HumanFemale", "Flee", 2);
|
||||
|
||||
// Dwarf combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::DWARF_MALE, "Dwarf", "DwarfMale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::DWARF_MALE, "Dwarf", "DwarfMale", "Flee", 2);
|
||||
|
||||
// Gnome combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::GNOME_MALE, "Gnome", "GnomeMale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::GNOME_MALE, "Gnome", "GnomeMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::GNOME_FEMALE, "Gnome", "GnomeFemale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::GNOME_FEMALE, "Gnome", "GnomeFemale", "Flee", 2);
|
||||
|
||||
// Night Elf combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::NIGHTELF_MALE, "NightElf", "NightElfMale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::NIGHTELF_MALE, "NightElf", "NightElfMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElf", "NightElfFemale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::NIGHTELF_FEMALE, "NightElf", "NightElfFemale", "Flee", 2);
|
||||
|
||||
// Orc combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::ORC_MALE, "Orc", "OrcMale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::ORC_MALE, "Orc", "OrcMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::ORC_FEMALE, "Orc", "OrcFemale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::ORC_FEMALE, "Orc", "OrcFemale", "Flee", 2);
|
||||
|
||||
// Undead combat sounds (Scourge folder)
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::UNDEAD_MALE, "Scourge", "UndeadMale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::UNDEAD_MALE, "Scourge", "UndeadMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::UNDEAD_FEMALE, "Scourge", "UndeadFemale", "AttackMyTarget", 2);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::UNDEAD_FEMALE, "Scourge", "UndeadFemale", "Flee", 2);
|
||||
|
||||
// Tauren combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::TAUREN_MALE, "Tauren", "TaurenMale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::TAUREN_MALE, "Tauren", "TaurenMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::TAUREN_FEMALE, "Tauren", "TaurenFemale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::TAUREN_FEMALE, "Tauren", "TaurenFemale", "Flee", 2);
|
||||
|
||||
// Troll combat sounds
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::TROLL_MALE, "Troll", "TrollMale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::TROLL_MALE, "Troll", "TrollMale", "Flee", 2);
|
||||
|
||||
loadCombatCategory(aggroLibrary_, VoiceType::TROLL_FEMALE, "Troll", "TrollFemale", "AttackMyTarget", 3);
|
||||
loadCombatCategory(fleeLibrary_, VoiceType::TROLL_FEMALE, "Troll", "TrollFemale", "Flee", 2);
|
||||
}
|
||||
|
||||
bool NpcVoiceManager::loadSound(const std::string& path, VoiceSample& sample) {
|
||||
if (!assetManager_ || !assetManager_->fileExists(path)) {
|
||||
return false;
|
||||
}
|
||||
if (!assetManager_) return false;
|
||||
|
||||
auto data = assetManager_->readFile(path);
|
||||
if (data.empty()) {
|
||||
if (!assetManager_->fileExists(path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
sample.path = path;
|
||||
sample.data = std::move(data);
|
||||
sample.data = assetManager_->readFile(path);
|
||||
|
||||
if (sample.data.empty()) {
|
||||
LOG_WARNING("NPC voice: Failed to load sound data from ", path);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NpcVoiceManager::playGreeting(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
LOG_INFO("NPC voice: playGreeting called for GUID ", npcGuid);
|
||||
|
||||
void NpcVoiceManager::playSound(uint64_t npcGuid, VoiceType voiceType, SoundCategory category, const glm::vec3& position) {
|
||||
if (!AudioEngine::instance().isInitialized()) {
|
||||
LOG_WARNING("NPC voice: AudioEngine not initialized");
|
||||
return;
|
||||
}
|
||||
|
||||
// Check cooldown
|
||||
// Check cooldown (except for pissed and combat sounds which override cooldown)
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
if (category != SoundCategory::PISSED && category != SoundCategory::AGGRO && category != SoundCategory::FLEE) {
|
||||
auto it = lastPlayTime_.find(npcGuid);
|
||||
if (it != lastPlayTime_.end()) {
|
||||
float elapsed = std::chrono::duration<float>(now - it->second).count();
|
||||
if (elapsed < GREETING_COOLDOWN) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Select library based on category
|
||||
std::unordered_map<VoiceType, std::vector<VoiceSample>>* library = nullptr;
|
||||
switch (category) {
|
||||
case SoundCategory::GREETING: library = &greetingLibrary_; break;
|
||||
case SoundCategory::FAREWELL: library = &farewellLibrary_; break;
|
||||
case SoundCategory::VENDOR: library = &vendorLibrary_; break;
|
||||
case SoundCategory::PISSED: library = &pissedLibrary_; break;
|
||||
case SoundCategory::AGGRO: library = &aggroLibrary_; break;
|
||||
case SoundCategory::FLEE: library = &fleeLibrary_; break;
|
||||
}
|
||||
|
||||
// Find voice samples for this type
|
||||
auto libIt = library->find(voiceType);
|
||||
if (libIt == library->end() || libIt->second.empty()) {
|
||||
// Fallback to GENERIC
|
||||
libIt = library->find(VoiceType::GENERIC);
|
||||
if (libIt == library->end() || libIt->second.empty()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const auto& samples = libIt->second;
|
||||
std::uniform_int_distribution<size_t> dist(0, samples.size() - 1);
|
||||
const auto& sample = samples[dist(rng_)];
|
||||
|
||||
// Play sound
|
||||
std::uniform_real_distribution<float> pitchDist(0.98f, 1.02f);
|
||||
bool success = AudioEngine::instance().playSound3D(
|
||||
sample.data,
|
||||
position,
|
||||
0.6f * volumeScale_,
|
||||
pitchDist(rng_),
|
||||
60.0f
|
||||
);
|
||||
|
||||
if (success) {
|
||||
lastPlayTime_[npcGuid] = now;
|
||||
}
|
||||
}
|
||||
|
||||
void NpcVoiceManager::playGreeting(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
// Check if on cooldown - if so, increment pissed counter instead
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
auto it = lastPlayTime_.find(npcGuid);
|
||||
if (it != lastPlayTime_.end()) {
|
||||
float elapsed = std::chrono::duration<float>(now - it->second).count();
|
||||
if (elapsed < GREETING_COOLDOWN) {
|
||||
LOG_INFO("NPC voice: on cooldown (", elapsed, "s elapsed)");
|
||||
return; // Still on cooldown
|
||||
// On cooldown - increment click count and maybe play pissed sound
|
||||
playPissed(npcGuid, voiceType, position);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Find voice library for this type
|
||||
auto libIt = voiceLibrary_.find(voiceType);
|
||||
if (libIt == voiceLibrary_.end() || libIt->second.empty()) {
|
||||
LOG_INFO("NPC voice: No samples for type ", static_cast<int>(voiceType), ", falling back to GENERIC");
|
||||
// Fall back to generic
|
||||
libIt = voiceLibrary_.find(VoiceType::GENERIC);
|
||||
if (libIt == voiceLibrary_.end() || libIt->second.empty()) {
|
||||
LOG_WARNING("NPC voice: No voice samples available (library empty)");
|
||||
return; // No voice samples available
|
||||
}
|
||||
// Reset click count on successful greeting
|
||||
clickCount_[npcGuid] = 0;
|
||||
playSound(npcGuid, voiceType, SoundCategory::GREETING, position);
|
||||
}
|
||||
|
||||
void NpcVoiceManager::playFarewell(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
playSound(npcGuid, voiceType, SoundCategory::FAREWELL, position);
|
||||
}
|
||||
|
||||
void NpcVoiceManager::playVendor(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
playSound(npcGuid, voiceType, SoundCategory::VENDOR, position);
|
||||
}
|
||||
|
||||
void NpcVoiceManager::playPissed(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
// Increment click count
|
||||
clickCount_[npcGuid]++;
|
||||
|
||||
// Only play pissed sound after threshold
|
||||
if (clickCount_[npcGuid] >= PISSED_CLICK_THRESHOLD) {
|
||||
playSound(npcGuid, voiceType, SoundCategory::PISSED, position);
|
||||
clickCount_[npcGuid] = 0; // Reset after playing
|
||||
}
|
||||
}
|
||||
|
||||
const auto& samples = libIt->second;
|
||||
void NpcVoiceManager::playAggro(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
playSound(npcGuid, voiceType, SoundCategory::AGGRO, position);
|
||||
}
|
||||
|
||||
// Pick random voice line
|
||||
std::uniform_int_distribution<size_t> dist(0, samples.size() - 1);
|
||||
const auto& sample = samples[dist(rng_)];
|
||||
|
||||
LOG_INFO("NPC voice: Playing sound from: ", sample.path);
|
||||
|
||||
// Play with 3D positioning
|
||||
std::uniform_real_distribution<float> volumeDist(0.85f, 1.0f);
|
||||
std::uniform_real_distribution<float> pitchDist(0.98f, 1.02f);
|
||||
|
||||
bool success = AudioEngine::instance().playSound3D(
|
||||
sample.data,
|
||||
position,
|
||||
volumeDist(rng_) * volumeScale_,
|
||||
pitchDist(rng_),
|
||||
40.0f // Max distance for voice
|
||||
);
|
||||
|
||||
if (success) {
|
||||
LOG_INFO("NPC voice: Sound played successfully");
|
||||
lastPlayTime_[npcGuid] = now;
|
||||
} else {
|
||||
LOG_WARNING("NPC voice: Failed to play sound");
|
||||
}
|
||||
void NpcVoiceManager::playFlee(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position) {
|
||||
playSound(npcGuid, voiceType, SoundCategory::FLEE, position);
|
||||
}
|
||||
|
||||
VoiceType NpcVoiceManager::detectVoiceType(uint32_t creatureEntry) const {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue