Skip to content

Commit

Permalink
Fix npc handler
Browse files Browse the repository at this point in the history
The npc system should be rewritten sometime.
  • Loading branch information
dalkon committed Nov 4, 2014
1 parent 3a12d87 commit ba1f5e1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 14 additions & 7 deletions data/npc/lib/npcsystem/npchandler.lua
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
7 changes: 4 additions & 3 deletions src/spells.cpp
Expand Up @@ -156,12 +156,13 @@ bool Spells::registerEvent(Event* event, const pugi::xml_node&)

RuneSpell* rune = dynamic_cast<RuneSpell*>(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;
Expand Down

1 comment on commit ba1f5e1

@Jusgast
Copy link

@Jusgast Jusgast commented on ba1f5e1 Nov 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All NPC's doesn't take money and gives the message: you do not have enough capacity.
But does give the item. All shop NPC's.

Please sign in to comment.