Core/Unit: Make HandleEmoteCommand typesafe (#25249)

* Scripts/ScarletMonastery: Fix wrong emote during Headless Horseman encounter

* Scripts/HoR: Fix wrong emote during escape event

* Core/Unit: Make improve type safety of HandleEmoteCommand

Change argument type to the expected enum type Emote

* Scripts/CoS: Use SetUInt32Value to set UNIT_NPC_EMOTESTATE

UNIT_NPC_EMOTESTATE is no flag field

(cherry picked from commit 6c7837f947ff4eb5110a116a371daa6f9e2b3bbe)
This commit is contained in:
Peter Keresztes Schmidt
2022-01-26 21:46:51 +01:00
committed by Shauren
parent 595e89e02b
commit 2e3c612c80
19 changed files with 48 additions and 72 deletions
@@ -321,7 +321,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsUnit(target))
{
target->ToUnit()->HandleEmoteCommand(e.action.emote.emote);
target->ToUnit()->HandleEmoteCommand(static_cast<Emote>(e.action.emote.emote));
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_PLAY_EMOTE: target: %s %s, emote: %u",
target->GetName().c_str(), target->GetGUID().ToString().c_str(), e.action.emote.emote);
}
@@ -475,7 +475,7 @@ void SmartScript::ProcessAction(SmartScriptHolder& e, Unit* unit, uint32 var0, u
{
if (IsUnit(target))
{
uint32 emote = Trinity::Containers::SelectRandomContainerElement(emotes);
Emote emote = static_cast<Emote>(Trinity::Containers::SelectRandomContainerElement(emotes));
target->ToUnit()->HandleEmoteCommand(emote);
TC_LOG_DEBUG("scripts.ai", "SmartScript::ProcessAction:: SMART_ACTION_RANDOM_EMOTE: Creature %s handle random emote %u",
target->GetGUID().ToString().c_str(), emote);
+1 -1
View File
@@ -1513,7 +1513,7 @@ void Unit::DealMeleeDamage(CalcDamageInfo* damageInfo, bool durabilityLoss)
}
}
void Unit::HandleEmoteCommand(uint32 emoteId, Player* target /*=nullptr*/, Trinity::IteratorPair<int32 const*> spellVisualKitIds /*= {}*/)
void Unit::HandleEmoteCommand(Emote emoteId, Player* target /*=nullptr*/, Trinity::IteratorPair<int32 const*> spellVisualKitIds /*= {}*/)
{
WorldPackets::Chat::Emote packet;
packet.Guid = GetGUID();
+1 -1
View File
@@ -1037,7 +1037,7 @@ class TC_GAME_API Unit : public WorldObject
DamageInfo* damageInfo, HealInfo* healInfo);
void TriggerAurasProcOnEvent(ProcEventInfo& eventInfo, AuraApplicationProcContainer& procAuras);
void HandleEmoteCommand(uint32 emoteId, Player* target = nullptr, Trinity::IteratorPair<int32 const*> spellVisualKitIds = {});
void HandleEmoteCommand(Emote emoteId, Player* target = nullptr, Trinity::IteratorPair<int32 const*> spellVisualKitIds = {});
void AttackerStateUpdate (Unit* victim, WeaponAttackType attType = BASE_ATTACK, bool extra = false);
void CalculateMeleeDamage(Unit* victim, CalcDamageInfo* damageInfo, WeaponAttackType attackType = BASE_ATTACK);
+5 -5
View File
@@ -663,9 +663,9 @@ void WorldSession::HandleTextEmoteOpcode(WorldPackets::Chat::CTextEmote& packet)
if (!em)
return;
uint32 emoteAnim = em->EmoteID;
Emote emote = static_cast<Emote>(em->EmoteID);
switch (emoteAnim)
switch (emote)
{
case EMOTE_STATE_SLEEP:
case EMOTE_STATE_SIT:
@@ -674,13 +674,13 @@ void WorldSession::HandleTextEmoteOpcode(WorldPackets::Chat::CTextEmote& packet)
break;
case EMOTE_STATE_DANCE:
case EMOTE_STATE_READ:
_player->SetEmoteState(Emote(emoteAnim));
_player->SetEmoteState(emote);
break;
default:
// Only allow text-emotes for "dead" entities (feign death included)
if (_player->HasUnitState(UNIT_STATE_DIED))
break;
_player->HandleEmoteCommand(emoteAnim, nullptr, { packet.SpellVisualKitIDs.data(), packet.SpellVisualKitIDs.data() + packet.SpellVisualKitIDs.size() });
_player->HandleEmoteCommand(emote, nullptr, { packet.SpellVisualKitIDs.data(), packet.SpellVisualKitIDs.data() + packet.SpellVisualKitIDs.size() });
break;
}
@@ -701,7 +701,7 @@ void WorldSession::HandleTextEmoteOpcode(WorldPackets::Chat::CTextEmote& packet)
if (Creature* creature = unit->ToCreature())
creature->AI()->ReceiveEmote(_player, packet.EmoteID);
if (emoteAnim != EMOTE_ONESHOT_NONE)
if (emote != EMOTE_ONESHOT_NONE)
_player->RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags::Anim);
}
+1 -1
View File
@@ -445,7 +445,7 @@ void Map::ScriptsProcess()
if (step.script->Emote.Flags & SF_EMOTE_USE_STATE)
cSource->SetEmoteState(Emote(step.script->Emote.EmoteID));
else
cSource->HandleEmoteCommand(step.script->Emote.EmoteID);
cSource->HandleEmoteCommand(static_cast<Emote>(step.script->Emote.EmoteID));
}
break;
@@ -3093,7 +3093,7 @@ enum TextEmotes
};
// Emotes.db2 (9.0.2.37176)
enum Emote
enum Emote : uint32
{
EMOTE_ONESHOT_NONE = 0,
EMOTE_ONESHOT_TALK = 1,
@@ -3497,6 +3497,10 @@ enum Emote
EMOTE_ONESHOT_BARSWEEP_STAND = 987,
EMOTE_TORGHAST_TALKING_HEAD_MAW_CAST_SOUND = 989,
EMOTE_TORGHAST_TALKING_HEAD_MAW_CAST_SOUND2 = 990,
EMOTE_ONESHOT_STAND_VAR0 = 991,
EMOTE_ONESHOT_FLYCUSTOMSPELL01 = 992,
EMOTE_ONESHOT_SPELLEFFECT_DECAY = 993,
EMOTE_STATE_CREATURE_SPECIAL = 994,
};
// AnimationData.db2 (6.0.2.18988)
+1
View File
@@ -79,6 +79,7 @@ struct SceneTemplate;
enum BattlegroundTypeId : uint32;
enum Difficulty : uint8;
enum DuelCompleteType : uint8;
enum Emote : uint32;
enum QuestStatus : uint8;
enum RemoveMethod : uint8;
enum ShutdownExitCode : uint32;
+1 -1
View File
@@ -370,7 +370,7 @@ void CreatureTextMgr::SendNonChatPacket(WorldObject* source, WorldPacket const*
source->SendMessageToSetInRange(data, dist, true);
}
void CreatureTextMgr::SendEmote(Unit* source, uint32 emote)
void CreatureTextMgr::SendEmote(Unit* source, Emote emote)
{
if (!source)
return;
+1 -1
View File
@@ -103,7 +103,7 @@ class TC_GAME_API CreatureTextMgr
CreatureTextMap const& GetTextMap() const { return mTextMap; }
static void SendSound(Creature* source, uint32 sound, ChatMsg msgType, WorldObject const* whisperTarget = nullptr, CreatureTextRange range = TEXT_RANGE_NORMAL, Team team = TEAM_OTHER, bool gmOnly = false, uint32 keyBroadcastTextId = 0, SoundKitPlayType playType = SoundKitPlayType::Normal);
static void SendEmote(Unit* source, uint32 emote);
static void SendEmote(Unit* source, Emote emote);
//if sent, returns the 'duration' of the text else 0 if error
uint32 SendChat(Creature* source, uint8 textGroup, WorldObject const* whisperTarget = nullptr, ChatMsg msgType = CHAT_MSG_ADDON, Language language = LANG_ADDON, CreatureTextRange range = TEXT_RANGE_NORMAL, uint32 sound = 0, SoundKitPlayType playType = SoundKitPlayType::Normal, Team team = TEAM_OTHER, bool gmOnly = false, Player* srcPlr = nullptr);
@@ -198,7 +198,7 @@ struct npc_feasting_valarjar : public ScriptedAI
{
_scheduler.Schedule(5s, 30s, [this](TaskContext context)
{
uint32 emoteID = Trinity::Containers::SelectRandomContainerElement(_randomEmotes);
Emote emoteID = Trinity::Containers::SelectRandomContainerElement(_randomEmotes);
if (emoteID == EMOTE_ONESHOT_EAT_NO_SHEATHE)
{
me->SetVirtualItem(0, urand(0, 1) ? ITEM_MONSTER_ITEM_MUTTON_WITH_BITE : ITEM_MONSTER_ITEM_TANKARD_WOODEN);
@@ -235,7 +235,7 @@ struct npc_feasting_valarjar : public ScriptedAI
private:
TaskScheduler _scheduler;
std::unordered_set<uint32> _randomEmotes;
std::unordered_set<Emote> _randomEmotes;
};
struct npc_valarjar_paying_respect_to_odyn : ScriptedAI
@@ -302,7 +302,7 @@ struct npc_valarjar_paying_respect_to_odyn : ScriptedAI
private:
TaskScheduler _scheduler;
std::unordered_set<uint32> _randomEmotes;
std::unordered_set<Emote> _randomEmotes;
};
struct npc_incoming_valarjar_aspirant_1 : public npc_valarjar_paying_respect_to_odyn
@@ -583,7 +583,7 @@ struct npc_spectating_valarjar : public ScriptedAI
private:
TaskScheduler _scheduler;
std::unordered_set<uint32> _randomEmotes;
std::unordered_set<Emote> _randomEmotes;
};
struct npc_valkyr_of_odyn : public ScriptedAI
+2 -6
View File
@@ -1256,14 +1256,10 @@ public:
}
//show animation
static bool HandleDebugAnimCommand(ChatHandler* handler, char const* args)
static bool HandleDebugAnimCommand(ChatHandler* handler, uint32 emoteId)
{
if (!*args)
return false;
uint32 animId = atoi((char*)args);
if (Unit* unit = handler->getSelectedUnit())
unit->HandleEmoteCommand(animId);
unit->HandleEmoteCommand(static_cast<Emote>(emoteId));
return true;
}
@@ -524,7 +524,7 @@ struct boss_headless_horseman : public ScriptedAI
if (Player* player = it->GetSource())
{
player->Say(HeadlessHorsemanInitialPlayerTexts[talkContext.GetRepeatCounter()], LANG_UNIVERSAL);
player->HandleEmoteCommand(ANIM_EMOTE_SHOUT);
player->HandleEmoteCommand(EMOTE_ONESHOT_SHOUT);
}
}
@@ -275,27 +275,20 @@ enum RedridgeCitizen
EVENT_SAY_TEXT = 9, // Used by npc's in Lakeshire Townhall
EVENT_LEAVE_TOWNHALL = 10, // Used by npc's in Lakeshire Townhall
EMOTE_ONESHOTCHEER = 4,
EMOTE_ONESHOTROAR = 15,
EMOTE_ONESHOTSHOT = 22,
EMOTE_ONESHOTPOINT = 25,
EMOTE_ONESHOTBATTLEROAR = 53,
EMOTE_ONESHOTNO = 274,
SAY_IN_TOWNHALL = 0, // Used by npc's in Lakeshire Townhall
SAY_LEAVE_TOWNHALL = 1, // Used by npc's in Lakeshire Townhall
SPELL_APPLY_QUEST_INVIS_ZONE_19 = 82099 // Used by npc's in Lakeshire Townhall
};
const uint32 Emote[6] =
const Emote EmoteID[6] =
{
EMOTE_ONESHOTCHEER,
EMOTE_ONESHOTROAR,
EMOTE_ONESHOTSHOT,
EMOTE_ONESHOTPOINT,
EMOTE_ONESHOTBATTLEROAR,
EMOTE_ONESHOTNO
EMOTE_ONESHOT_CHEER,
EMOTE_ONESHOT_ROAR,
EMOTE_ONESHOT_SHOUT,
EMOTE_ONESHOT_POINT,
EMOTE_ONESHOT_BATTLE_ROAR,
EMOTE_ONESHOT_NO
};
uint32 const pathSize = 8;
@@ -343,7 +336,7 @@ public:
_events.ScheduleEvent(EVENT_SAY_TEXT, Seconds(5), Seconds(30));
break;
case EVENT_PLAYEMOTE:
me->HandleEmoteCommand(Emote[urand(0, 5)]);
me->HandleEmoteCommand(EmoteID[urand(0, 5)]);
_events.ScheduleEvent(EVENT_PLAYEMOTE, Seconds(10), Seconds(25));
break;
case EVENT_SAY_TEXT:
+9 -20
View File
@@ -1046,26 +1046,15 @@ class npc_cw_area_trigger : public CreatureScript
if (player->GetQuestStatus(QUEST_NOW_WHEN_I_GROW_UP) == QUEST_STATUS_COMPLETE)
if (Creature* samuro = me->FindNearestCreature(25151, 20.0f))
{
uint32 emote = 0;
switch (urand(1, 5))
{
case 1:
emote = EMOTE_ONESHOT_WAVE;
break;
case 2:
emote = EMOTE_ONESHOT_ROAR;
break;
case 3:
emote = EMOTE_ONESHOT_FLEX;
break;
case 4:
emote = EMOTE_ONESHOT_SALUTE;
break;
case 5:
emote = EMOTE_ONESHOT_DANCE;
break;
}
samuro->HandleEmoteCommand(emote);
Emote const emotes[] =
{
EMOTE_ONESHOT_WAVE,
EMOTE_ONESHOT_ROAR,
EMOTE_ONESHOT_FLEX,
EMOTE_ONESHOT_SALUTE,
EMOTE_ONESHOT_DANCE
};
samuro->HandleEmoteCommand(Trinity::Containers::SelectRandomContainerElement(emotes));
}
}
break;
@@ -1091,7 +1091,7 @@ class npc_jaina_or_sylvanas_escape_hor : public CreatureScript
break;
case EVENT_ESCAPE_7:
if (Creature* lichking = ObjectAccessor::GetCreature(*me, _instance->GetGuidData(DATA_THE_LICH_KING_ESCAPE)))
lichking->HandleEmoteCommand(TEXT_EMOTE_ROAR);
lichking->HandleEmoteCommand(EMOTE_ONESHOT_ROAR);
me->GetMotionMaster()->MovePoint(0, NpcJainaOrSylvanasEscapeRoute[0]);
_events.ScheduleEvent(EVENT_ESCAPE_8, 3s);
break;
@@ -672,7 +672,7 @@ private:
bool _checkCasting;
};
static std::vector<uint32> const DarkFallensEmotes =
static Emote const DarkFallensEmotes[]=
{
EMOTE_ONESHOT_TALK,
EMOTE_ONESHOT_EXCLAMATION,
@@ -127,7 +127,7 @@ public:
break;
case 20:
if (Creature* RWORG = ObjectAccessor::GetCreature(*me, _RavenousworgGUID))
RWORG->HandleEmoteCommand(34);
RWORG->HandleEmoteCommand(EMOTE_ONESHOT_WOUND_CRITICAL);
break;
case 21:
if (Creature* Mrfloppy = ObjectAccessor::GetCreature(*me, _mrfloppyGUID))
@@ -150,7 +150,7 @@ class boss_broggok : public CreatureScript
}
};
static std::vector<uint32> const PrisionersEmotes =
static Emote const PrisionersEmotes[] =
{
EMOTE_ONESHOT_ROAR,
EMOTE_ONESHOT_SHOUT,
+2 -9
View File
@@ -3094,14 +3094,7 @@ class spell_gen_seaforium_blast : public SpellScript
}
};
enum SpectatorCheerTrigger
{
EMOTE_ONE_SHOT_CHEER = 4,
EMOTE_ONE_SHOT_EXCLAMATION = 5,
EMOTE_ONE_SHOT_APPLAUD = 21
};
uint8 const EmoteArray[3] = { EMOTE_ONE_SHOT_CHEER, EMOTE_ONE_SHOT_EXCLAMATION, EMOTE_ONE_SHOT_APPLAUD };
static Emote const EmoteArray[] = { EMOTE_ONESHOT_CHEER, EMOTE_ONESHOT_EXCLAMATION, EMOTE_ONESHOT_APPLAUD };
class spell_gen_spectator_cheer_trigger : public SpellScript
{
@@ -3110,7 +3103,7 @@ class spell_gen_spectator_cheer_trigger : public SpellScript
void HandleDummy(SpellEffIndex /*effIndex*/)
{
if (roll_chance_i(40))
GetCaster()->HandleEmoteCommand(EmoteArray[urand(0, 2)]);
GetCaster()->HandleEmoteCommand(Trinity::Containers::SelectRandomContainerElement(EmoteArray));
}
void Register() override