Proxy
Proxy

Reputation: 21

Can't get custom spell to work in AzerothCore

I'm trying to create a custom spell in AzerothCore, specifically I want to be able to cast it and have the effect applied, and the buff icon to be displayed in the top right corner with other auras. But when I try ".cast <spell_id>" nothing happens, no relevant error logs are found, and from what I can tell I have followed the standard protocol for creating a custom spell.

Here is what I have done/tried

  1. First, I copied an existing spell in the spell editor, it is based on Blessing of Kings. I gave it the spell id "400001"

  2. I exported the dbc files and put them in RelWithDebInfo/Data/dbc and in the wotlk client's data folder for the custom patch

  3. I have my C++ spell script located in /src/server/scripts/Custom/DraconicBlood/draconic_blood.cpp, and it looks like this:

#include "ScriptMgr.h"
#include "Player.h"
#include "SpellAuras.h"
#include "SpellScript.h"

enum SpellIds
{
    SPELL_DRACONIC_BLOOD = 400001
};

class DraconicBloodSpell : public SpellScriptLoader
{
public:
    DraconicBloodSpell() : SpellScriptLoader("DraconicBloodSpell") { }

    class DraconicBloodAuraScript : public AuraScript
    {
        PrepareAuraScript(DraconicBloodAuraScript);

        void OnApply(AuraEffect const* aurEff, AuraEffectHandleModes mode)
        {

            Unit* target = GetTarget();
            if (target->IsPlayer())
            {
                Player* player = target->ToPlayer();

                // Apply the stat increases as a percentage
                int32 strengthIncrease = static_cast<int32>(player->GetStat(STAT_STRENGTH) * 1.39f); // 39% increase
                int32 agilityIncrease = static_cast<int32>(player->GetStat(STAT_AGILITY) * 1.39f);
                int32 staminaIncrease = static_cast<int32>(player->GetStat(STAT_STAMINA) * 1.39f);
                int32 intellectIncrease = static_cast<int32>(player->GetStat(STAT_INTELLECT) * 1.39f);
                int32 spiritIncrease = static_cast<int32>(player->GetStat(STAT_SPIRIT) * 1.39f);

                player->SetStat(STAT_STRENGTH, strengthIncrease);
                player->SetStat(STAT_AGILITY, agilityIncrease);
                player->SetStat(STAT_STAMINA, staminaIncrease);
                player->SetStat(STAT_INTELLECT, intellectIncrease);
                player->SetStat(STAT_SPIRIT, spiritIncrease);
            }
        }

        void OnApplyResistance(AuraEffect const* aurEff, AuraEffectHandleModes mode)
        {
            Unit* target = GetTarget();
            if (target->IsPlayer())
            {
                Player* player = target->ToPlayer();

                // Apply the resistance boosts
                player->SetResistance(SPELL_SCHOOL_NORMAL, player->GetResistance(SPELL_SCHOOL_NORMAL) + 450);
                player->SetResistance(SPELL_SCHOOL_HOLY, player->GetResistance(SPELL_SCHOOL_HOLY) + 450);
                player->SetResistance(SPELL_SCHOOL_FIRE, player->GetResistance(SPELL_SCHOOL_FIRE) + 450);
                player->SetResistance(SPELL_SCHOOL_NATURE, player->GetResistance(SPELL_SCHOOL_NATURE) + 450);
                player->SetResistance(SPELL_SCHOOL_FROST, player->GetResistance(SPELL_SCHOOL_FROST) + 450);
                player->SetResistance(SPELL_SCHOOL_SHADOW, player->GetResistance(SPELL_SCHOOL_SHADOW) + 450);
                player->SetResistance(SPELL_SCHOOL_ARCANE, player->GetResistance(SPELL_SCHOOL_ARCANE) + 450);
            }
        }

        void Register() override
        {
            OnEffectApply += AuraEffectApplyFn(DraconicBloodAuraScript::OnApply, EFFECT_0, SPELL_AURA_MOD_TOTAL_STAT_PERCENTAGE, AURA_EFFECT_HANDLE_REAL);
            OnEffectApply += AuraEffectApplyFn(DraconicBloodAuraScript::OnApplyResistance, EFFECT_1, SPELL_AURA_MOD_RESISTANCE, AURA_EFFECT_HANDLE_REAL);
        }
    };

    AuraScript* GetAuraScript() const override
    {
        return new DraconicBloodAuraScript();
    }
};

void AddSC_DraconicBloodSpell()
{
    new DraconicBloodSpell();
}
  1. I have registered this custom spell script in custom_script_loader.cpp:
void AddSC_DraconicBloodSpell();

// The name of this function should match:
// void Add${NameOfDirectory}Scripts()
void AddCustomScripts()
{
    AddSC_DraconicBloodSpell();
}
  1. I have added the identifier string "DraconicBloodSpell" together with the corresponding spell id "400001" in the spell_script_names table:

    enter image description here

  2. after doing all this, I have of course reconfigured cmake, regenerated, cleaned and rebuilt the project (build was successful with no errors), and deleted the cache folder in the wotlk client. Yet despite all this, when I load up the server and boot the game, and try ".cast 400001", nothing happens

I would be so grateful if anyone could tell me what I have missed or ways I can troubleshoot this. Thank you in advance!

Upvotes: 1

Views: 192

Answers (0)

Related Questions