From 7b774c8141128adf9d69bf7d0920e047fd15610d Mon Sep 17 00:00:00 2001 From: Kitzunu <24550914+Kitzunu@users.noreply.github.com> Date: Sat, 7 Jan 2023 20:05:42 +0100 Subject: [PATCH] fix(Core/Spell): Roll 'dem Bones (#14522) * fix(Core/Spell): Roll 'dem Bones * closes https://github.com/azerothcore/azerothcore-wotlk/issues/14357 * Partial cp of https://github.com/TrinityCore/TrinityCore/commit/029527365f1763c45e8668c16ecd25ba7553bb22 Co-Authored-By: joschiwald <736792+joschiwald@users.noreply.github.com> * newline pleb Co-authored-by: joschiwald <736792+joschiwald@users.noreply.github.com> --- .../rev_1673000690518893100.sql | 4 ++ src/server/game/Spells/SpellEffects.cpp | 11 ----- src/server/scripts/Spells/spell_item.cpp | 42 +++++++++++++++++++ 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 data/sql/updates/pending_db_world/rev_1673000690518893100.sql diff --git a/data/sql/updates/pending_db_world/rev_1673000690518893100.sql b/data/sql/updates/pending_db_world/rev_1673000690518893100.sql new file mode 100644 index 000000000..8fd7583a9 --- /dev/null +++ b/data/sql/updates/pending_db_world/rev_1673000690518893100.sql @@ -0,0 +1,4 @@ +-- +DELETE FROM `spell_script_names` WHERE `spell_id` = 47776 AND `ScriptName` = 'spell_item_worn_troll_dice'; +INSERT INTO `spell_script_names` VALUES +(47776, 'spell_item_worn_troll_dice'); diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 4c4b6d6e7..68b2c5bd5 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -3904,17 +3904,6 @@ void Spell::EffectScriptEffect(SpellEffIndex effIndex) m_caster->TextEmote(buf); break; } - // Roll 'dem Bones - Worn Troll Dice - case 47776: - { - char buf[128]; - const char* gender = "his"; - if (m_caster->getGender() > 0) - gender = "her"; - sprintf(buf, "%s causually tosses %s [Worn Troll Dice]. One %u and one %u.", m_caster->GetName().c_str(), gender, urand(1, 6), urand(1, 6)); - m_caster->TextEmote(buf); - break; - } case 52173: // Coyote Spirit Despawn case 60243: // Blood Parrot Despawn if (unitTarget->GetTypeId() == TYPEID_UNIT && unitTarget->ToCreature()->IsSummon()) diff --git a/src/server/scripts/Spells/spell_item.cpp b/src/server/scripts/Spells/spell_item.cpp index c085e64cf..9d527e6fe 100644 --- a/src/server/scripts/Spells/spell_item.cpp +++ b/src/server/scripts/Spells/spell_item.cpp @@ -23,6 +23,7 @@ #include "Battleground.h" #include "GameTime.h" +#include "ObjectMgr.h" #include "Player.h" #include "ScriptMgr.h" #include "ScriptedCreature.h" @@ -3757,6 +3758,46 @@ class spell_item_green_whelp_armor : public AuraScript } }; +enum TrollDice +{ + TEXT_WORN_TROLL_DICE = 26152 +}; + +// 47776 - Roll 'dem Bones +class spell_item_worn_troll_dice : public SpellScript +{ + PrepareSpellScript(spell_item_worn_troll_dice); + + bool Validate(SpellInfo const* /*spellInfo*/) override + { + if (!sObjectMgr->GetBroadcastText(TEXT_WORN_TROLL_DICE)) + return false; + return true; + } + + bool Load() override + { + return GetCaster()->GetTypeId() == TYPEID_PLAYER; + } + + void HandleScript(SpellEffIndex /*effIndex*/) + { + GetCaster()->TextEmote(TEXT_WORN_TROLL_DICE, GetHitUnit()); + + static uint32 const minimum = 1; + static uint32 const maximum = 6; + + // roll twice + GetCaster()->ToPlayer()->DoRandomRoll(minimum, maximum); + GetCaster()->ToPlayer()->DoRandomRoll(minimum, maximum); + } + + void Register() override + { + OnEffectHitTarget += SpellEffectFn(spell_item_worn_troll_dice::HandleScript, EFFECT_0, SPELL_EFFECT_SCRIPT_EFFECT); + } +}; + void AddSC_item_spell_scripts() { RegisterSpellScript(spell_item_massive_seaforium_charge); @@ -3873,4 +3914,5 @@ void AddSC_item_spell_scripts() RegisterSpellScript(spell_item_snowman); RegisterSpellScript(spell_item_freeze_rookery_egg); RegisterSpellScript(spell_item_green_whelp_armor); + RegisterSpellScript(spell_item_worn_troll_dice); }