fix(Scripts/Items): play the Toy Train Set sound (#27750)

Co-authored-by: treeston <[email protected]>
This commit is contained in:
Keleborn
2026-09-23 18:43:28 +02:00
committed by GitHub
co-authored by treeston
parent ca3e66ae00
commit e3bc57dcac
+19 -2
View File
@@ -17,6 +17,7 @@
#include "AreaDefines.h"
#include "Battleground.h"
#include "DBCStores.h"
#include "ObjectMgr.h"
#include "Pet.h"
#include "Player.h"
@@ -561,15 +562,31 @@ class spell_item_toy_train_set : public SpellScript
{
PrepareSpellScript(spell_item_toy_train_set)
void FilterTargets(std::list<WorldObject*>& targets)
{
targets.remove_if([](WorldObject const* target) { return !target->IsPlayer(); });
}
void HandleScriptEffect(SpellEffIndex effIndex)
{
PreventHitDefaultEffect(effIndex);
if (Unit* target = GetHitUnit())
target->HandleEmoteCommand(EMOTE_ONESHOT_TRAIN);
Player* target = GetHitPlayer();
if (!target)
return;
target->HandleEmoteCommand(EMOTE_ONESHOT_TRAIN);
// EmotesTextSound.dbc holds the per race/gender "choo choo" voice line. SMSG_EMOTE only carries
// the animation, and EMOTE_ONESHOT_TRAIN is not enough for the client to pick the sound itself.
uint8 const race = target->getRace();
uint8 const gender = target->getGender();
if (EmotesTextSoundEntry const* soundEntry = FindTextSoundEmoteFor(TEXT_EMOTE_TRAIN, race, gender))
target->PlayDistanceSound(soundEntry->SoundId);
}
void Register() override
{
OnObjectAreaTargetSelect += SpellObjectAreaTargetSelectFn(spell_item_toy_train_set::FilterTargets, EFFECT_ALL, TARGET_UNIT_SRC_AREA_ALLY);
OnEffectHitTarget += SpellEffectFn(spell_item_toy_train_set::HandleScriptEffect, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT);
}
};