Kelsidavis-WoWee/include/audio/npc_voice_manager.hpp
Kelsi eb288d2064 Implement NPC greeting voice lines
Added NPC voice manager that plays greeting sounds when clicking on NPCs:

Features:
- Voice line library with multiple race/gender voice types (Human, Dwarf,
  Night Elf, etc.)
- 3D positional audio - voice comes from NPC location
- Cooldown system prevents spam clicking same NPC
- Randomized pitch/volume for variety
- Loads greeting sounds from character voice files in MPQ
- Generic fallback voices for NPCs without specific voice types

Voice lines trigger automatically when gossip window opens (SMSG_GOSSIP_MESSAGE).
Uses same audio system as other sound effects with ma_sound_set_position.
2026-02-09 01:29:44 -08:00

75 lines
1.7 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,
GENERIC, // Fallback
};
class NpcVoiceManager {
public:
NpcVoiceManager();
~NpcVoiceManager();
bool initialize(pipeline::AssetManager* assets);
void shutdown();
// Play greeting sound for NPC at given position
void playGreeting(uint64_t npcGuid, VoiceType voiceType, const glm::vec3& position);
void setVolumeScale(float scale) { volumeScale_ = scale; }
float getVolumeScale() const { return volumeScale_; }
private:
void loadVoiceSounds();
bool loadSound(const std::string& path, VoiceSample& sample);
VoiceType detectVoiceType(uint32_t creatureEntry) const;
pipeline::AssetManager* assetManager_ = nullptr;
float volumeScale_ = 1.0f;
// Voice samples grouped by type
std::unordered_map<VoiceType, std::vector<VoiceSample>> voiceLibrary_;
// Cooldown tracking (prevent spam clicking same NPC)
std::unordered_map<uint64_t, std::chrono::steady_clock::time_point> lastPlayTime_;
static constexpr float GREETING_COOLDOWN = 2.0f; // seconds
std::mt19937 rng_;
};
} // namespace audio
} // namespace wowee