diff --git a/data-otservbr-global/lib/others/fragment_gems.lua b/data-otservbr-global/lib/others/fragment_gems.lua deleted file mode 100644 index cb82b9e951e..00000000000 --- a/data-otservbr-global/lib/others/fragment_gems.lua +++ /dev/null @@ -1,16 +0,0 @@ -MAX_GEM_BREAK = 10 - -FRAGMENT_GEMS = { - small = { ids = { 44602, 44605, 44608, 44611 }, fragment = 46625, range = { 1, 4 } }, - medium = { ids = { 44603, 44606, 44609, 44612 }, fragment = 46625, range = { 2, 8 } }, - great = { ids = { 44604, 44607, 44610, 44613 }, fragment = 46626, range = { 1, 4 } }, -} - -function getGemData(id) - for _, gem in pairs(FRAGMENT_GEMS) do - if table.contains(gem.ids, id) then - return gem.fragment, gem.range - end - end - return nil -end diff --git a/data-otservbr-global/lib/others/load.lua b/data-otservbr-global/lib/others/load.lua index 3d7da57cc77..031c8fb2026 100644 --- a/data-otservbr-global/lib/others/load.lua +++ b/data-otservbr-global/lib/others/load.lua @@ -1,2 +1 @@ dofile(DATA_DIRECTORY .. "/lib/others/dawnport.lua") -dofile(DATA_DIRECTORY .. "/lib/others/fragment_gems.lua") diff --git a/data-otservbr-global/scripts/actions/tools/amber_crusher.lua b/data-otservbr-global/scripts/actions/tools/amber_crusher.lua deleted file mode 100644 index d9c3edc4ce8..00000000000 --- a/data-otservbr-global/scripts/actions/tools/amber_crusher.lua +++ /dev/null @@ -1,31 +0,0 @@ -local amberCrusher = Action() - -function amberCrusher.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target or not target:isItem() or target:getId() == item:getId() or player:getItemCount(target:getId()) <= 0 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the crusher on a valid gem in your inventory.") - return false - end - - local fragmentType, fragmentRange = getGemData(target:getId()) - if not fragmentType then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This item can't be broken into fragments.") - return false - end - - if target:getCount() >= MAX_GEM_BREAK then - target:remove(MAX_GEM_BREAK) - for i = 1, MAX_GEM_BREAK, 1 do - player:addItem(fragmentType, math.random(fragmentRange[1], fragmentRange[2])) - end - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have broken the gems into fragments.") - else - target:remove(1) - player:addItem(fragmentType, math.random(fragmentRange[1], fragmentRange[2])) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have broken the gem into fragments.") - end - - return true -end - -amberCrusher:id(46628) -amberCrusher:register() diff --git a/data-otservbr-global/scripts/actions/tools/crusher.lua b/data-otservbr-global/scripts/actions/tools/crusher.lua deleted file mode 100644 index 8daa9f2771b..00000000000 --- a/data-otservbr-global/scripts/actions/tools/crusher.lua +++ /dev/null @@ -1,42 +0,0 @@ -local crusher = Action() - -function crusher.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not target or not target:isItem() or target:getId() == item:getId() or player:getItemCount(target:getId()) <= 0 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the crusher on a valid gem in your inventory.") - return false - end - - local fragmentType, fragmentRange = getGemData(target:getId()) - if not fragmentType then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This item can't be broken into fragments.") - return false - end - - local crusherCharges = item:getAttribute(ITEM_ATTRIBUTE_CHARGES) - if not crusherCharges or crusherCharges <= 0 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your crusher has no more charges.") - return false - end - - target:remove(1) - - player:addItem(fragmentType, math.random(fragmentRange[1], fragmentRange[2])) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have broken the gem into fragments.") - - crusherCharges = crusherCharges - 1 - if crusherCharges > 0 then - local container = item:getParent() - item:setAttribute(ITEM_ATTRIBUTE_CHARGES, crusherCharges) - if container:isContainer() then - player:sendUpdateContainer(container) - end - else - item:remove() - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your crusher has been consumed.") - end - - return true -end - -crusher:id(46627) -crusher:register() diff --git a/data/scripts/actions/tools/crushers.lua b/data/scripts/actions/tools/crushers.lua new file mode 100644 index 00000000000..99c3102616d --- /dev/null +++ b/data/scripts/actions/tools/crushers.lua @@ -0,0 +1,86 @@ +local config = { + maxGemBreak = 10, + fragmentGems = { + small = { ids = { 44602, 44605, 44608, 44611 }, fragment = 46625, range = { 1, 4 } }, + medium = { ids = { 44603, 44606, 44609, 44612 }, fragment = 46625, range = { 2, 8 } }, + great = { ids = { 44604, 44607, 44610, 44613 }, fragment = 46626, range = { 1, 4 } }, + }, +} + +local function getGemData(gemId) + for _, gemData in pairs(config.fragmentGems) do + if table.contains(gemData.ids, gemId) then + return gemData.fragment, gemData.range + end + end + return nil +end + +local amberCrusher = Action() + +function amberCrusher.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not target or not target:isItem() or target:getId() == item:getId() or player:getItemCount(target:getId()) <= 0 then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the crusher on a valid gem in your inventory.") + return true + end + + local fragmentType, fragmentRange = getGemData(target:getId()) + if not fragmentType then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This item can't be broken into fragments.") + return true + end + + local breakAmount = (target:getCount() >= config.maxGemBreak) and config.maxGemBreak or 1 + target:remove(breakAmount) + + for _ = 1, breakAmount do + player:addItem(fragmentType, math.random(fragmentRange[1], fragmentRange[2])) + end + + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have broken the gem into fragments.") + return true +end + +amberCrusher:id(46628) +amberCrusher:register() + +local crusher = Action() + +function crusher.onUse(player, item, fromPosition, target, toPosition, isHotkey) + if not target or not target:isItem() or target:getId() == item:getId() or player:getItemCount(target:getId()) <= 0 then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You can only use the crusher on a valid gem in your inventory.") + return true + end + + local fragmentType, fragmentRange = getGemData(target:getId()) + if not fragmentType then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "This item can't be broken into fragments.") + return true + end + + local crusherCharges = item:getAttribute(ITEM_ATTRIBUTE_CHARGES) + if not crusherCharges or crusherCharges <= 0 then + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your crusher has no more charges.") + return true + end + + target:remove(1) + player:addItem(fragmentType, math.random(fragmentRange[1], fragmentRange[2])) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have broken the gem into fragments.") + + crusherCharges = crusherCharges - 1 + if crusherCharges > 0 then + local container = item:getParent() + item:setAttribute(ITEM_ATTRIBUTE_CHARGES, crusherCharges) + if container:isContainer() then + player:sendUpdateContainer(container) + end + else + item:remove() + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your crusher has been consumed.") + end + return true +end + +crusher:id(46627) +crusher:register() diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 153db66dee4..7d7bbc84e34 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -327,7 +327,7 @@ void SpawnMonster::scheduleSpawn(uint32_t spawnMonsterId, spawnBlock_t &sb, cons } void SpawnMonster::cleanup() { - for (auto it = spawnedMonsterMap.begin(); it != spawnedMonsterMap.end(); ) { + for (auto it = spawnedMonsterMap.begin(); it != spawnedMonsterMap.end();) { const auto &monster = it->second; if (!monster || monster->isRemoved()) { auto spawnIt = spawnMonsterMap.find(it->first);