From b9c739496cb4a98d639d8b2abc568abbacddd73c Mon Sep 17 00:00:00 2001 From: AnchyDev Date: Wed, 18 Oct 2023 21:03:42 +1100 Subject: [PATCH] Added a spectator script and crowd upon completion of a wave. --- data/sql/db-world/base/tos_world_base.sql | 5 ++ src/TrialOfStrength.cpp | 3 + src/TrialOfStrength.h | 1 + src/scripts/ToSArenaSpectatorScript.h | 85 +++++++++++++++++++++++ src/scripts/ToSInstanceScript.cpp | 17 +++++ src/scripts/ToSInstanceScript.h | 3 + 6 files changed, 114 insertions(+) create mode 100644 src/scripts/ToSArenaSpectatorScript.h diff --git a/data/sql/db-world/base/tos_world_base.sql b/data/sql/db-world/base/tos_world_base.sql index 90a372d..5316494 100644 --- a/data/sql/db-world/base/tos_world_base.sql +++ b/data/sql/db-world/base/tos_world_base.sql @@ -22,6 +22,11 @@ INSERT INTO `creature_equip_template` (`CreatureID`, `ID`, `ItemID1`, `ItemID2`, DELETE FROM `creature_template` WHERE `entry`=441250; INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441250, 0, 0, 0, 0, 0, 18039, 0, 0, 0, 'Fortichad Ironfist', 'Arena Master', NULL, 0, 80, 80, 0, 35, 3, 1, 1.14286, 1, 1, 20, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '', 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 'ToSArenaMasterScript', 1); +-- Trial of Strength / Arena Spectator +DELETE FROM `creature_template` WHERE `entry`=441253; +INSERT INTO `creature_template` (`entry`, `difficulty_entry_1`, `difficulty_entry_2`, `difficulty_entry_3`, `KillCredit1`, `KillCredit2`, `modelid1`, `modelid2`, `modelid3`, `modelid4`, `name`, `subname`, `IconName`, `gossip_menu_id`, `minlevel`, `maxlevel`, `exp`, `faction`, `npcflag`, `speed_walk`, `speed_run`, `speed_swim`, `speed_flight`, `detection_range`, `scale`, `rank`, `dmgschool`, `DamageModifier`, `BaseAttackTime`, `RangeAttackTime`, `BaseVariance`, `RangeVariance`, `unit_class`, `unit_flags`, `unit_flags2`, `dynamicflags`, `family`, `trainer_type`, `trainer_spell`, `trainer_class`, `trainer_race`, `type`, `type_flags`, `lootid`, `pickpocketloot`, `skinloot`, `PetSpellDataId`, `VehicleId`, `mingold`, `maxgold`, `AIName`, `MovementType`, `HoverHeight`, `HealthModifier`, `ManaModifier`, `ArmorModifier`, `ExperienceModifier`, `RacialLeader`, `movementId`, `RegenHealth`, `mechanic_immune_mask`, `spell_school_immune_mask`, `flags_extra`, `ScriptName`, `VerifiedBuild`) VALUES (441253, 0, 0, 0, 0, 0, 1485, 3606, 4123, 2224, 'Arena Spectator', NULL, NULL, 0, 78, 80, 0, 35, 0, 1, 1.14286, 1, 1, 20, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'NullCreatureAI', 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 'ToSArenaSpectatorScript', 1); + + DELETE FROM `npc_text` WHERE `ID`=441250; INSERT INTO `npc_text` (`ID`, `text0_0`, `text0_1`, `BroadcastTextID0`, `lang0`, `Probability0`, `em0_0`, `em0_1`, `em0_2`, `em0_3`, `em0_4`, `em0_5`, `text1_0`, `text1_1`, `BroadcastTextID1`, `lang1`, `Probability1`, `em1_0`, `em1_1`, `em1_2`, `em1_3`, `em1_4`, `em1_5`, `text2_0`, `text2_1`, `BroadcastTextID2`, `lang2`, `Probability2`, `em2_0`, `em2_1`, `em2_2`, `em2_3`, `em2_4`, `em2_5`, `text3_0`, `text3_1`, `BroadcastTextID3`, `lang3`, `Probability3`, `em3_0`, `em3_1`, `em3_2`, `em3_3`, `em3_4`, `em3_5`, `text4_0`, `text4_1`, `BroadcastTextID4`, `lang4`, `Probability4`, `em4_0`, `em4_1`, `em4_2`, `em4_3`, `em4_4`, `em4_5`, `text5_0`, `text5_1`, `BroadcastTextID5`, `lang5`, `Probability5`, `em5_0`, `em5_1`, `em5_2`, `em5_3`, `em5_4`, `em5_5`, `text6_0`, `text6_1`, `BroadcastTextID6`, `lang6`, `Probability6`, `em6_0`, `em6_1`, `em6_2`, `em6_3`, `em6_4`, `em6_5`, `text7_0`, `text7_1`, `BroadcastTextID7`, `lang7`, `Probability7`, `em7_0`, `em7_1`, `em7_2`, `em7_3`, `em7_4`, `em7_5`, `VerifiedBuild`) VALUES (441250, 'Greetings, $n.|n|nI am the Arena Master for the Trial of Strength.|n|nIf you seek to test your abilities, then I can transport you to the arena.|n|nAre you ready to face the challenges that lie ahead?', NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL); DELETE FROM `npc_text` WHERE `ID`=441251; diff --git a/src/TrialOfStrength.cpp b/src/TrialOfStrength.cpp index 89d1960..d437825 100644 --- a/src/TrialOfStrength.cpp +++ b/src/TrialOfStrength.cpp @@ -5,6 +5,7 @@ #include "scripts/ToSEnemyCombatantBossScript.h" #include "scripts/ToSArenaMasterScript.h" +#include "scripts/ToSArenaSpectatorScript.h" #include "scripts/ToSInstanceScript.h" #include "scripts/ToSInstanceMapScript.h" @@ -168,7 +169,9 @@ void ToSWorldScript::OnAfterConfigLoad(bool reload) void SC_AddTrialOfStrengthScripts() { new ToSWorldScript(); + new ToSArenaMasterScript(); + new ToSArenaSpectatorScript(); new ToSEnemyCombatantScript(); new ToSEnemyCombatantBossScript(); diff --git a/src/TrialOfStrength.h b/src/TrialOfStrength.h index 583f96c..1061085 100644 --- a/src/TrialOfStrength.h +++ b/src/TrialOfStrength.h @@ -31,6 +31,7 @@ enum ToSConstants { TOS_DATA_ENCOUNTER_TRIAL_COMPLETED = 13, TOS_DATA_ENCOUNTER_CHECK_ARENA_MASTER_RELOCATE = 14, TOS_DATA_ENCOUNTER_WAVE_IN_PROGRESS = 15, + TOS_DATA_ENCOUNTER_CROWD = 16, TOS_CURSE_TYPE_ENEMY = 0, TOS_CURSE_TYPE_PLAYER = 1, diff --git a/src/scripts/ToSArenaSpectatorScript.h b/src/scripts/ToSArenaSpectatorScript.h new file mode 100644 index 0000000..b18460a --- /dev/null +++ b/src/scripts/ToSArenaSpectatorScript.h @@ -0,0 +1,85 @@ +#ifndef MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H +#define MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H + +#include "ScriptedCreature.h" + +class ToSArenaSpectatorScript : public CreatureScript +{ +public: + ToSArenaSpectatorScript() : CreatureScript("ToSArenaSpectatorScript") { } + + CreatureAI* GetAI(Creature* creature) const override + { + return new ToSArenaSpectatorAIScript(creature); + } + + class ToSArenaSpectatorAIScript : public ScriptedAI + { + enum ToSSpectatorConstants + { + TOS_ARENA_SPEC_DO_EMOTE = 1 + }; + + public: + ToSArenaSpectatorAIScript(Creature* creature) : ScriptedAI(creature) + { + events.Reset(); + events.ScheduleEvent(TOS_ARENA_SPEC_DO_EMOTE, randtime(3s, 10s)); + + crowdCheerAlternate = false; + } + + void UpdateAI(uint32 diff) override + { + events.Update(diff); + + switch (events.ExecuteEvent()) + { + case TOS_ARENA_SPEC_DO_EMOTE: + DoEmote(); + events.RescheduleEvent(TOS_ARENA_SPEC_DO_EMOTE, randtime(3s, 10s)); + break; + } + } + + void DoEmote() + { + auto iScript = me->GetInstanceScript(); + if (!iScript) + { + events.Reset(); + LOG_WARN("module", "Failed to find instance script for Arena Spectator."); + return; + } + + if (!iScript->IsEncounterInProgress()) + { + return; + } + + switch (urand(0, 2)) + { + case 0: + me->HandleEmoteCommand(EMOTE_ONESHOT_CHEER); + break; + + case 1: + me->HandleEmoteCommand(EMOTE_ONESHOT_DANCE); + break; + + case 2: + me->HandleEmoteCommand(EMOTE_ONESHOT_APPLAUD); + break; + } + } + + private: + EventMap events; + bool crowdCheerAlternate; + }; + +private: + EventMap events; +}; + +#endif // MODULE_TRIAL_OF_STRENGTH_ARENA_SPECTATOR_H diff --git a/src/scripts/ToSInstanceScript.cpp b/src/scripts/ToSInstanceScript.cpp index 13c5c64..f8d9d94 100644 --- a/src/scripts/ToSInstanceScript.cpp +++ b/src/scripts/ToSInstanceScript.cpp @@ -228,6 +228,20 @@ void ToSInstanceScript::Update(uint32 diff) CheckArenaMasterRelocate(); events.RescheduleEvent(TOS_DATA_ENCOUNTER_CHECK_ARENA_MASTER_RELOCATE, 3s); break; + + case TOS_DATA_ENCOUNTER_CROWD: + PlayCrowd(); + events.RescheduleEvent(TOS_DATA_ENCOUNTER_CROWD, 1s); + break; + } +} + +void ToSInstanceScript::PlayCrowd() +{ + if (IsEncounterInProgress() && IsWaveCleared() && !cheerPlayed) + { + instance->PlayDirectSoundToMap(13904); + cheerPlayed = true; } } @@ -361,6 +375,7 @@ void ToSInstanceScript::SetupEncounter() } events.ScheduleEvent(TOS_DATA_ENCOUNTER_START_NEXT_WAVE, 5s); + events.ScheduleEvent(TOS_DATA_ENCOUNTER_CROWD, 1s); } void ToSInstanceScript::CheckWaveCompletion() @@ -388,6 +403,7 @@ void ToSInstanceScript::CheckWaveCompletion() waveInProgress = false; waveCleared = true; + cheerPlayed = false; if (currentWave == totalWaves) { @@ -606,6 +622,7 @@ void ToSInstanceScript::ResetEncounter() { encounterInProgress = false; waveInProgress = false; + cheerPlayed = false; currentWave = 1; totalWaves = 0; diff --git a/src/scripts/ToSInstanceScript.h b/src/scripts/ToSInstanceScript.h index 0a5cd5a..7a31a7a 100644 --- a/src/scripts/ToSInstanceScript.h +++ b/src/scripts/ToSInstanceScript.h @@ -59,6 +59,8 @@ class ToSInstanceScript : public InstanceScript void PopulateRewardChest(); void AnnounceCompletion(); + void PlayCrowd(); + void SetData(uint32 dataId, uint32 value) override; uint32 GetData(uint32 dataId) const override; @@ -81,6 +83,7 @@ class ToSInstanceScript : public InstanceScript bool waveCleared; bool trialCompleted; + bool cheerPlayed; std::vector waveCreatures; std::vector curses;