Kelsidavis-WoWee/include/audio/npc_voice_manager.hpp
Kelsi 46f2c0df85 Fix SoundEntries.dbc field indices for SMSG_PLAY_MUSIC and remove dead NpcVoiceManager code
Correct SoundEntries.dbc field access in the PlayMusic callback: file names are at
fields 3-12 (not 2-11) and DirectoryBase is at field 23 (not 22). Field 2 is the
Name label string, not a file path.

Remove dead detectVoiceType(creatureEntry) from NpcVoiceManager — it was never
called; actual voice detection uses detectVoiceTypeFromDisplayId() in Application.
2026-03-09 16:01:29 -07:00

100 lines
2.9 KiB
C++

#pragma once
#include <string>
#include <vector>
#include <unordered_map>
#include <cstdint>
#include <random>
#include <chrono>
#include <glm/glm.hpp>
namespace wowee {
namespace pipeline { class AssetManager; }
namespace audio {
struct VoiceSample {
std::string path;
std::vector<uint8_t> data;
};
// NPC voice types (based on creature model/gender)
enum class VoiceType {
HUMAN_MALE,
HUMAN_FEMALE,
DWARF_MALE,
DWARF_FEMALE,
NIGHTELF_MALE,
NIGHTELF_FEMALE,
ORC_MALE,
ORC_FEMALE,
TAUREN_MALE,
TAUREN_FEMALE,
TROLL_MALE,
TROLL_FEMALE,
UNDEAD_MALE,
UNDEAD_FEMALE,
GNOME_MALE,
GNOME_FEMALE,
GOBLIN_MALE,
GOBLIN_FEMALE,
GENERIC, // Fallback
};
class NpcVoiceManager {
public:
NpcVoiceManager();
~NpcVoiceManager();
bool initialize(pipeline::AssetManager* assets);
void shutdown();
// Play NPC interaction sounds
void playGreeting(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void playFarewell(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void playVendor(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void playPissed(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
// Play NPC combat sounds
void playAggro(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void playFlee(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void setVolumeScale(float scale) { volumeScale_ = scale; }
float getVolumeScale() const { return volumeScale_; }
private:
enum class SoundCategory {
GREETING,
FAREWELL,
VENDOR,
PISSED,
AGGRO,
FLEE
};
void loadVoiceSounds();
bool loadSound(const std::string& path, VoiceSample& sample);
void playSound(uint64_t npcGuid, VoiceType voiceType, SoundCategory category, const glm::vec3& position);
pipeline::AssetManager* assetManager_ = nullptr;
float volumeScale_ = 1.0f;
// Voice samples grouped by type and category
std::unordered_map<VoiceType, std::vector<VoiceSample>> greetingLibrary_;
std::unordered_map<VoiceType, std::vector<VoiceSample>> farewellLibrary_;
std::unordered_map<VoiceType, std::vector<VoiceSample>> vendorLibrary_;
std::unordered_map<VoiceType, std::vector<VoiceSample>> pissedLibrary_;
std::unordered_map<VoiceType, std::vector<VoiceSample>> aggroLibrary_;
std::unordered_map<VoiceType, std::vector<VoiceSample>> fleeLibrary_;
// Cooldown tracking (prevent spam clicking same NPC)
std::unordered_map<uint64_t, std::chrono::steady_clock::time_point> lastPlayTime_;
std::unordered_map<uint64_t, int> clickCount_; // Track clicks for pissed sounds
static constexpr float GREETING_COOLDOWN = 2.0f; // seconds
static constexpr int PISSED_CLICK_THRESHOLD = 5; // clicks before pissed
std::mt19937 rng_;
};
} // namespace audio
} // namespace wowee