Skip to content

Commit

Permalink
[c12872] Implement script library hook for NpcSpellClick
Browse files Browse the repository at this point in the history
(based on commit [12674] - b032ba8)

Signed-off-by: Xfurry <xfurry@scriptdev2.com>
  • Loading branch information
xfurry committed Aug 13, 2014
1 parent 1fbd3f0 commit 785fdcc
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/game/ObjectMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7180,11 +7180,15 @@ void ObjectMgr::LoadNPCSpellClickSpells()
continue;
}

SpellEntry const* spellinfo = sSpellStore.LookupEntry(info.spellId);
if (!spellinfo)
// spell can be 0 for special or custom cases
if (info.spellId)
{
sLog.outErrorDb("Table npc_spellclick_spells references unknown spellid %u. Skipping entry.", info.spellId);
continue;
SpellEntry const* spellinfo = sSpellStore.LookupEntry(info.spellId);
if (!spellinfo)
{
sLog.outErrorDb("Table npc_spellclick_spells references unknown spellid %u. Skipping entry.", info.spellId);
continue;
}
}

if (info.conditionId && !sConditionStorage.LookupEntry<PlayerCondition const*>(info.conditionId))
Expand Down
8 changes: 8 additions & 0 deletions src/game/ScriptMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ ScriptMgr::ScriptMgr() :
m_pOnGOUse(NULL),
m_pOnItemUse(NULL),
m_pOnAreaTrigger(NULL),
m_pOnNpcSpellClick(NULL),
m_pOnProcessEvent(NULL),
m_pOnEffectDummyCreature(NULL),
m_pOnEffectDummyGO(NULL),
Expand Down Expand Up @@ -2111,6 +2112,11 @@ bool ScriptMgr::OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry)
return m_pOnAreaTrigger != NULL && m_pOnAreaTrigger(pPlayer, atEntry);
}

bool ScriptMgr::OnNpcSpellClick(Player* pPlayer, Creature* pClickedCreature, uint32 spellId)
{
return m_pOnNpcSpellClick != NULL && m_pOnNpcSpellClick(pPlayer, pClickedCreature, spellId);
}

bool ScriptMgr::OnProcessEvent(uint32 eventId, Object* pSource, Object* pTarget, bool isStart)
{
return m_pOnProcessEvent != NULL && m_pOnProcessEvent(eventId, pSource, pTarget, isStart);
Expand Down Expand Up @@ -2191,6 +2197,7 @@ ScriptLoadResult ScriptMgr::LoadScriptLibrary(const char* libName)
GET_SCRIPT_HOOK_PTR(m_pOnGOUse, "GOUse");
GET_SCRIPT_HOOK_PTR(m_pOnItemUse, "ItemUse");
GET_SCRIPT_HOOK_PTR(m_pOnAreaTrigger, "AreaTrigger");
GET_SCRIPT_HOOK_PTR(m_pOnNpcSpellClick, "NpcSpellClick");
GET_SCRIPT_HOOK_PTR(m_pOnProcessEvent, "ProcessEvent");
GET_SCRIPT_HOOK_PTR(m_pOnEffectDummyCreature, "EffectDummyCreature");
GET_SCRIPT_HOOK_PTR(m_pOnEffectDummyGO, "EffectDummyGameObject");
Expand Down Expand Up @@ -2245,6 +2252,7 @@ void ScriptMgr::UnloadScriptLibrary()
m_pOnGOUse = NULL;
m_pOnItemUse = NULL;
m_pOnAreaTrigger = NULL;
m_pOnNpcSpellClick = NULL;
m_pOnProcessEvent = NULL;
m_pOnEffectDummyCreature = NULL;
m_pOnEffectDummyGO = NULL;
Expand Down
2 changes: 2 additions & 0 deletions src/game/ScriptMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ class ScriptMgr
bool OnGameObjectUse(Player* pPlayer, GameObject* pGameObject);
bool OnItemUse(Player* pPlayer, Item* pItem, SpellCastTargets const& targets);
bool OnAreaTrigger(Player* pPlayer, AreaTriggerEntry const* atEntry);
bool OnNpcSpellClick(Player* pPlayer, Creature* pClickedCreature, uint32 spellId);
bool OnProcessEvent(uint32 eventId, Object* pSource, Object* pTarget, bool isStart);
bool OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, Creature* pTarget, ObjectGuid originalCasterGuid);
bool OnEffectDummy(Unit* pCaster, uint32 spellId, SpellEffectIndex effIndex, GameObject* pTarget, ObjectGuid originalCasterGuid);
Expand Down Expand Up @@ -572,6 +573,7 @@ class ScriptMgr
bool (MANGOS_IMPORT* m_pOnGOUse)(Player*, GameObject*);
bool (MANGOS_IMPORT* m_pOnItemUse)(Player*, Item*, SpellCastTargets const&);
bool (MANGOS_IMPORT* m_pOnAreaTrigger)(Player*, AreaTriggerEntry const*);
bool (MANGOS_IMPORT* m_pOnNpcSpellClick)(Player*, Creature*, uint32);
bool (MANGOS_IMPORT* m_pOnProcessEvent)(uint32, Object*, Object*, bool);
bool (MANGOS_IMPORT* m_pOnEffectDummyCreature)(Unit*, uint32, SpellEffectIndex, Creature*, ObjectGuid);
bool (MANGOS_IMPORT* m_pOnEffectDummyGO)(Unit*, uint32, SpellEffectIndex, GameObject*, ObjectGuid);
Expand Down
8 changes: 7 additions & 1 deletion src/game/SpellHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -623,10 +623,16 @@ void WorldSession::HandleSpellClick(WorldPacket& recv_data)
{
if (itr->second.IsFitToRequirements(_player, unit))
{
if (sScriptMgr.OnNpcSpellClick(_player, unit, itr->second.spellId))
return;

Unit* caster = (itr->second.castFlags & 0x1) ? (Unit*)_player : (Unit*)unit;
Unit* target = (itr->second.castFlags & 0x2) ? (Unit*)_player : (Unit*)unit;

caster->CastSpell(target, itr->second.spellId, true);
if (itr->second.spellId)
caster->CastSpell(target, itr->second.spellId, true);
else
sLog.outError("WorldSession::HandleSpellClick: npc_spell_click with entry %u has 0 in spell_id. Not handled custom case?", unit->GetEntry());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "12871"
#define REVISION_NR "12872"
#endif // __REVISION_NR_H__

0 comments on commit 785fdcc

Please sign in to comment.