From ba1f5e1c950cd3a9f0379409ae23f11105aa94a8 Mon Sep 17 00:00:00 2001 From: dalkon Date: Tue, 4 Nov 2014 16:42:34 +0100 Subject: [PATCH] Fix npc handler The npc system should be rewritten sometime. --- data/npc/lib/npcsystem/npchandler.lua | 21 ++++++++++++++------- src/spells.cpp | 7 ++++--- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/data/npc/lib/npcsystem/npchandler.lua b/data/npc/lib/npcsystem/npchandler.lua index 7436bad94b..cc2066ec6a 100644 --- a/data/npc/lib/npcsystem/npchandler.lua +++ b/data/npc/lib/npcsystem/npchandler.lua @@ -352,7 +352,8 @@ if NpcHandler == nil then end -- Handles onCreatureAppear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_APPEAR callback. - function NpcHandler:onCreatureAppear(cid) + function NpcHandler:onCreatureAppear(creature) + local cid = creature:getId() if cid == getNpcCid() and next(self.shopItems) ~= nil then local npc = Npc() local speechBubble = npc:getSpeechBubble() @@ -372,7 +373,8 @@ if NpcHandler == nil then end -- Handles onCreatureDisappear events. If you with to handle this yourself, please use the CALLBACK_CREATURE_DISAPPEAR callback. - function NpcHandler:onCreatureDisappear(cid) + function NpcHandler:onCreatureDisappear(creature) + local cid = creature:getId() if getNpcCid() == cid then return end @@ -388,7 +390,8 @@ if NpcHandler == nil then end -- Handles onCreatureSay events. If you with to handle this yourself, please use the CALLBACK_CREATURE_SAY callback. - function NpcHandler:onCreatureSay(cid, msgtype, msg) + function NpcHandler:onCreatureSay(creature, msgtype, msg) + local cid = creature:getId() local callback = self:getCallback(CALLBACK_CREATURE_SAY) if callback == nil or callback(cid, msgtype, msg) then if self:processModuleCallback(CALLBACK_CREATURE_SAY, cid, msgtype, msg) then @@ -414,7 +417,8 @@ if NpcHandler == nil then end -- Handles onPlayerEndTrade events. If you wish to handle this yourself, use the CALLBACK_PLAYER_ENDTRADE callback. - function NpcHandler:onPlayerEndTrade(cid) + function NpcHandler:onPlayerEndTrade(creature) + local cid = creature:getId() local callback = self:getCallback(CALLBACK_PLAYER_ENDTRADE) if callback == nil or callback(cid) then if self:processModuleCallback(CALLBACK_PLAYER_ENDTRADE, cid, msgtype, msg) then @@ -428,7 +432,8 @@ if NpcHandler == nil then end -- Handles onPlayerCloseChannel events. If you wish to handle this yourself, use the CALLBACK_PLAYER_CLOSECHANNEL callback. - function NpcHandler:onPlayerCloseChannel(cid) + function NpcHandler:onPlayerCloseChannel(creature) + local cid = creature:getId() local callback = self:getCallback(CALLBACK_PLAYER_CLOSECHANNEL) if callback == nil or callback(cid) then if self:processModuleCallback(CALLBACK_PLAYER_CLOSECHANNEL, cid, msgtype, msg) then @@ -440,7 +445,8 @@ if NpcHandler == nil then end -- Handles onBuy events. If you wish to handle this yourself, use the CALLBACK_ONBUY callback. - function NpcHandler:onBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks) + function NpcHandler:onBuy(creature, itemid, subType, amount, ignoreCap, inBackpacks) + local cid = creature:getId() local callback = self:getCallback(CALLBACK_ONBUY) if callback == nil or callback(cid, itemid, subType, amount, ignoreCap, inBackpacks) then if self:processModuleCallback(CALLBACK_ONBUY, cid, itemid, subType, amount, ignoreCap, inBackpacks) then @@ -450,7 +456,8 @@ if NpcHandler == nil then end -- Handles onSell events. If you wish to handle this yourself, use the CALLBACK_ONSELL callback. - function NpcHandler:onSell(cid, itemid, subType, amount, ignoreCap, inBackpacks) + function NpcHandler:onSell(creature, itemid, subType, amount, ignoreCap, inBackpacks) + local cid = creature:getId() local callback = self:getCallback(CALLBACK_ONSELL) if callback == nil or callback(cid, itemid, subType, amount, ignoreCap, inBackpacks) then if self:processModuleCallback(CALLBACK_ONSELL, cid, itemid, subType, amount, ignoreCap, inBackpacks) then diff --git a/src/spells.cpp b/src/spells.cpp index 385fe81be4..f342081b90 100644 --- a/src/spells.cpp +++ b/src/spells.cpp @@ -156,12 +156,13 @@ bool Spells::registerEvent(Event* event, const pugi::xml_node&) RuneSpell* rune = dynamic_cast(event); if (rune) { - if (runes.find(rune->getRuneItemId()) != runes.end()) { - std::cout << "[Warning - Spells::registerEvent] Duplicate registered rune with id: " << rune->getRuneItemId() << std::endl; + uint32_t runeId = rune->getRuneItemId(); + if (runes.find(runeId) != runes.end()) { + std::cout << "[Warning - Spells::registerEvent] Duplicate registered rune with id: " << runeId << std::endl; return false; } - runes[rune->getRuneItemId()] = rune; + runes[runeId] = rune; return true; } return false;