Jump to content

[patch][6512] New Unit::castspell(x,y,z,...) Function For Sd2


Guest megamage
 Share

Recommended Posts

Now we can only use CastSpell to a unit target. But some spells should target at the ground, such as spell 41481, 41482 and 40940. Another problem is that if you cast such spells on a unittarget, you may not see the correct spell visual. You may try to learn 40940 and cast it, you will see the visual effect. But if you use .cast to cast it on a unittarget (that is using CastSpell function), you will not see the visual effect.

The code is simple, only change a few lines of the other CastSpell() function.

Index: Unit.cpp
===================================================================
--- Unit.cpp        (revision 6477)
+++ Unit.cpp        (working copy)
@@ -974,6 +1009,41 @@
        spell->prepare(&targets, triggredByAura);
}

+void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem, Aura* triggredByAura, uint64 originalCaster)
+{
+        SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId );
+
+        if(!spellInfo)
+        {
+                sLog.outError("CastSpell: unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),
(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
+                return;
+        }
+
+        CastSpell(x, y, z,spellInfo,triggered,castItem,triggredByAura, originalCaster);
+}
+
+void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggredByAura, uint64 originalCaster)
+{
+        if(!spellInfo)
+        {
+                sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),
(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
+                return;
+        }
+
+        if (castItem)
+                DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
+
+        if(!originalCaster && triggredByAura)
+                originalCaster = triggredByAura->GetCasterGUID();
+
+        Spell *spell = new Spell(this, spellInfo, triggered, originalCaster );
+
+        SpellCastTargets targets;
+        targets.setDestination(x, y, z);
+        spell->m_CastItem = castItem;
+        spell->prepare(&targets, triggredByAura);
+}
+
void Unit::CastCustomSpell(Unit* Victim,uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem, Aura* triggredByAura, uint64 originalCaster)
{
        SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId );
Index: Unit.h
===================================================================
--- Unit.h        (revision 6477)
+++ Unit.h        (working copy)
@@ -892,6 +894,8 @@
                uint32 SpellNonMeleeDamageLog(Unit *pVictim, uint32 spellID, uint32 damage, bool isTriggeredSpell = false, bool useSpellDamage = true);
                void CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
                void CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
+                void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
+                void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
                void CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
                void CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggredByAura = NULL, uint64 originalCaster = 0);
                bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;

Link to comment
Share on other sites

Hmm, we'll have to make some changes to 3rd party libs (SD2) to handle this though. The problem I see with this is we will have to somehow figure out if a spell is an AoE or not before casting it and then pass the X,Y,Z of target when casting.

The correct way to do this would be to have Unit::CastSpell automatically figure that if we are casting an AoE ground targeted spell on a unit to instead cast on that units position. This will eliminate the need to overcomplicate spell handling in 3rd party script library.

Link to comment
Share on other sites

  • 2 weeks later...
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use