diff --git a/data-canary/monster/bosses/apocalypse.lua b/data-canary/monster/bosses/apocalypse.lua index fba0ab1613a..47957c3ceab 100644 --- a/data-canary/monster/bosses/apocalypse.lua +++ b/data-canary/monster/bosses/apocalypse.lua @@ -143,18 +143,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/apprentice_sheng.lua b/data-canary/monster/bosses/apprentice_sheng.lua index 5e16a274500..07eeb42917a 100644 --- a/data-canary/monster/bosses/apprentice_sheng.lua +++ b/data-canary/monster/bosses/apprentice_sheng.lua @@ -117,18 +117,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/bazir.lua b/data-canary/monster/bosses/bazir.lua index 6c4a6eeccb5..353c392a3b0 100644 --- a/data-canary/monster/bosses/bazir.lua +++ b/data-canary/monster/bosses/bazir.lua @@ -179,18 +179,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/black_knight.lua b/data-canary/monster/bosses/black_knight.lua index 1ca457b449e..fd9ff673ab4 100644 --- a/data-canary/monster/bosses/black_knight.lua +++ b/data-canary/monster/bosses/black_knight.lua @@ -126,18 +126,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/bullwark.lua b/data-canary/monster/bosses/bullwark.lua index 7674d1dec01..1aa7974cfa0 100644 --- a/data-canary/monster/bosses/bullwark.lua +++ b/data-canary/monster/bosses/bullwark.lua @@ -124,18 +124,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/custodian.lua b/data-canary/monster/bosses/custodian.lua index 21b9721d6a8..cf2d0c1fdf4 100644 --- a/data-canary/monster/bosses/custodian.lua +++ b/data-canary/monster/bosses/custodian.lua @@ -102,18 +102,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/dharalion.lua b/data-canary/monster/bosses/dharalion.lua index 3f86d4a5269..3d3cb689684 100644 --- a/data-canary/monster/bosses/dharalion.lua +++ b/data-canary/monster/bosses/dharalion.lua @@ -132,18 +132,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/monster/bosses/shadowpelt.lua b/data-canary/monster/bosses/shadowpelt.lua index 16fb1e60256..dcae734c0d3 100644 --- a/data-canary/monster/bosses/shadowpelt.lua +++ b/data-canary/monster/bosses/shadowpelt.lua @@ -135,18 +135,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-canary/scripts/actions/objects/imbuement_shrine.lua b/data-canary/scripts/actions/objects/imbuement_shrine.lua index 71e3776f2f0..11d75150cf8 100644 --- a/data-canary/scripts/actions/objects/imbuement_shrine.lua +++ b/data-canary/scripts/actions/objects/imbuement_shrine.lua @@ -13,5 +13,7 @@ function imbuement.onUse(player, item, fromPosition, target, toPosition, isHotke return true end +imbuement:position({ x = 1943, y = 1340, z = 7 }, 25061) + imbuement:id(25060, 25061, 25103, 25104, 25202, 25174, 25175, 25182, 25183) imbuement:register() diff --git a/data-canary/scripts/actions/other/christmas_bundle.lua b/data-canary/scripts/actions/other/christmas_bundle.lua deleted file mode 100644 index 3c74fa30a4d..00000000000 --- a/data-canary/scripts/actions/other/christmas_bundle.lua +++ /dev/null @@ -1,72 +0,0 @@ -local setting = { -- [christmas bundle item id] = {{reward item id, count}, ...} - [6506] = { -- red bundle - { 6569, 15 }, -- candy - { 3585, 5 }, -- red apple - { 3586, 10 }, -- orange - { 3598, 20 }, -- cookie - { 3599, 10 }, -- candy cane - 6500, -- gingerbreadman - 6501, -- christmas wreath - 6489, -- christmas branch - 6503, -- red christmas garland - 6387, -- christmas card - }, - [6507] = { -- blue bundle - { 6569, 15 }, -- candy - { 3585, 5 }, -- red apple - { 3586, 10 }, -- orange - { 3598, 20 }, -- cookie - { 3599, 10 }, -- candy cane - 6500, -- gingerbreadman - 6501, -- christmas wreath - 6489, -- christmas branch - 6505, -- blue christmas garland - 6387, -- christmas card - }, - [6508] = { -- green bundle - { 6569, 15 }, -- candy - { 3585, 5 }, -- red apple - { 3586, 10 }, -- orange - { 3598, 20 }, -- cookie - { 3599, 10 }, -- candy cane - 6500, -- gingerbreadman - 6501, -- christmas wreath - 6489, -- christmas branch - 6502, -- christmas garland - 6387, -- christmas card - }, -} - -local christmasBundle = Action() - -function christmasBundle.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local targetItem = setting[item.itemid] - if not targetItem then - return true - end - - local rewards = {} - while #rewards < 7 do - local count = 1 - local rand = math.random(#targetItem) - local gift = targetItem[rand] - if type(gift) == "table" then - gift, count = unpack(gift) - end - rewards[#rewards + 1] = { gift, count } - table.remove(targetItem, rand) - end - - for i = 1, #rewards do - player:addItem(unpack(rewards[i])) - end - item:remove(1) - player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS) - return true -end - -for index, value in pairs(setting) do - christmasBundle:id(index) -end - -christmasBundle:register() diff --git a/data-canary/scripts/actions/other/destroy.lua b/data-canary/scripts/actions/other/destroy.lua index 587df2f5ea7..62af94ab101 100644 --- a/data-canary/scripts/actions/other/destroy.lua +++ b/data-canary/scripts/actions/other/destroy.lua @@ -250,7 +250,7 @@ local setting = { local destroy = Action() function destroy.onUse(player, item, fromPosition, target, toPosition, isHotkey) - return ActionsLib.destroyItem(player, target, toPosition) + return destroyItem(player, target, toPosition) end for index, value in ipairs(setting) do diff --git a/data-canary/scripts/actions/other/ferumbras_amulet.lua b/data-canary/scripts/actions/other/ferumbras_amulet.lua deleted file mode 100644 index 01f1ca7a502..00000000000 --- a/data-canary/scripts/actions/other/ferumbras_amulet.lua +++ /dev/null @@ -1,17 +0,0 @@ -local ferumbrasAmulet = Action() - -function ferumbrasAmulet.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if math.random(2) == 1 then - player:addMana(1000) - else - player:addHealth(1000) - end - item:transform(22768) - item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) - item:decay() - player:say("Magical sparks whirl around the amulet and you suddenly feel refreshed.", TALKTYPE_MONSTER_SAY) - return true -end - -ferumbrasAmulet:id(22767) -ferumbrasAmulet:register() diff --git a/data-canary/scripts/actions/other/ferumbras_mana_keg.lua b/data-canary/scripts/actions/other/ferumbras_mana_keg.lua deleted file mode 100644 index c1400379d6d..00000000000 --- a/data-canary/scripts/actions/other/ferumbras_mana_keg.lua +++ /dev/null @@ -1,13 +0,0 @@ -local ferumbrasManaKeg = Action() - -function ferumbrasManaKeg.onUse(player, item, fromPosition, target, toPosition, isHotkey) - player:addItem(238, 10) - item:transform(22770) - item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) - item:decay() - player:say("Magical sparks whirl around the keg as you open the spigot and you fill ten empty vials with mana fluid.", TALKTYPE_MONSTER_SAY) - return true -end - -ferumbrasManaKeg:id(22769) -ferumbrasManaKeg:register() diff --git a/data-canary/scripts/actions/other/ferumbras_staff.lua b/data-canary/scripts/actions/other/ferumbras_staff.lua deleted file mode 100644 index f2f897f2c3f..00000000000 --- a/data-canary/scripts/actions/other/ferumbras_staff.lua +++ /dev/null @@ -1,16 +0,0 @@ -local ferumbrasStaff = Action() - -function ferumbrasStaff.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if math.random(100) > 20 then - item:transform(22767) - else - item:transform(22766) - end - item:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED) - item:decay() - player:say("Magical sparks whirl around the staff and suddenly it changes its appearance.", TALKTYPE_MONSTER_SAY) - return ActionsLib.destroyItem(player, target, toPosition) -end - -ferumbrasStaff:id(22764) -ferumbrasStaff:register() diff --git a/data-canary/scripts/actions/other/music.lua b/data-canary/scripts/actions/other/music.lua index eb44c56aeed..589723a1f89 100644 --- a/data-canary/scripts/actions/other/music.lua +++ b/data-canary/scripts/actions/other/music.lua @@ -27,8 +27,6 @@ local setting = { [2966] = { effect = CONST_ME_SOUND_RED }, -- war drum [3103] = { effect = CONST_ME_SOUND_YELLOW, itemId = 3592, itemCount = 10, chance = 80, remove = true }, -- cornucopia [5786] = { effects = { failure = CONST_ME_SOUND_RED, success = CONST_ME_SOUND_YELLOW }, monster = "war wolf", chance = 60, remove = true }, -- wooden whistle - [6572] = { effect = CONST_ME_SOUND_GREEN, text = "TOOOOOOT", transformId = 6573, decayId = 6572 }, -- party trumpet - [6573] = { effect = CONST_ME_SOUND_GREEN, text = "TOOOOOOT", transformId = 6572, decayId = 6573 }, -- party trumpet [12602] = { effect = CONST_ME_SOUND_BLUE }, -- small whistle (actual effect is unknown) [23725] = { effect = CONST_ME_SOUND_WHITE }, -- small crystal bell } diff --git a/data-canary/scripts/actions/other/sewer.lua b/data-canary/scripts/actions/other/sewer.lua deleted file mode 100644 index 2868e887ae5..00000000000 --- a/data-canary/scripts/actions/other/sewer.lua +++ /dev/null @@ -1,12 +0,0 @@ -local sewer = Action() - -function sewer.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if item:getId() == 435 then - fromPosition.z = fromPosition.z + 1 - end - player:teleportTo(fromPosition, false) - return true -end - -sewer:id(435) -sewer:register() diff --git a/data-canary/scripts/actions/other/surprise_bag.lua b/data-canary/scripts/actions/other/surprise_bag.lua deleted file mode 100644 index be59af96267..00000000000 --- a/data-canary/scripts/actions/other/surprise_bag.lua +++ /dev/null @@ -1,62 +0,0 @@ -local setting = { - -- Blue present - [6570] = { - { 3598, 10 }, - { 6393, 3 }, - 2995, - 6569, - 6572, - 6574, - 6575, - 6576, - 6577, - 6578, - 6279, - }, - -- Red present - [6571] = { - { 3035, 10 }, - { 3035, 10 }, - { 3035, 10 }, - { 2995, 3 }, - { 6392, 2 }, - { 6574, 2 }, - { 6576, 2 }, - { 6578, 2 }, - 2993, - 3036, - 3079, - 3386, - 3420, - 5944, - 6566, - 6568, - }, -} - -local surpriseBag = Action() - -function surpriseBag.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local count = 1 - local targetItem = setting[item.itemid] - if not targetItem then - return true - end - - local gift = targetItem[math.random(#targetItem)] - if type(gift) == "table" then - gift = gift[1] - count = gift[2] - end - - player:addItem(gift, count) - item:remove(1) - fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS) - return true -end - -for index, value in pairs(setting) do - surpriseBag:id(index) -end - -surpriseBag:register() diff --git a/data-canary/scripts/creaturescripts/#modal_window_example.lua b/data-canary/scripts/creaturescripts/#modal_window_example.lua deleted file mode 100644 index e2de4a9e474..00000000000 --- a/data-canary/scripts/creaturescripts/#modal_window_example.lua +++ /dev/null @@ -1,63 +0,0 @@ ---[[ - ModalWindowHelper Example -]] --- - -local moveDirectionTest = { - ["Right"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_EAST) - player:teleportTo(pos, true) - end, - ["Left"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_WEST) - player:teleportTo(pos, true) - end, - ["Up"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_NORTH) - player:teleportTo(pos, true) - end, - ["Down"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_SOUTH) - player:teleportTo(pos, true) - end, -} - -local talkAction = TalkAction("!modalTest") - -function talkAction.onSay(player, words, param, type) - local modalWindow = ModalWindow({ - title = "Modal Window Helper Example", - message = "This is an example of ModalWindowHelper.", - }) - if param == "choices" then - for text, callback in pairs(moveDirectionTest) do - modalWindow:addChoice(text, function(player, button, choice) - if button.name == "Select" then - callback(player) - modalWindow:sendToPlayer(player) - end - end) - end - - modalWindow:addButton("Select") - modalWindow:addButton("Cancel") - elseif param == "buttons" then - for direction, callback in pairs(moveDirectionTest) do - modalWindow:addButton(direction, function(player, button, choice) - callback(player) - modalWindow:sendToPlayer(player) - end) - end - end - modalWindow:sendToPlayer(player) - return false -end - ---talkAction:accountType(ACCOUNT_TYPE_GOD) ---talkAction:access(true) -talkAction:separator(" ") -talkAction:register() diff --git a/data-canary/scripts/creaturescripts/monster.lua b/data-canary/scripts/creaturescripts/monster.lua deleted file mode 100644 index abbdae1aea4..00000000000 --- a/data-canary/scripts/creaturescripts/monster.lua +++ /dev/null @@ -1,24 +0,0 @@ -local monsterDeath = CreatureEvent("monsterDeath") -function monsterDeath.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified) - if creature:isMonster() then - local self = creature:getStorageValue(MonsterStorage.Spawn.monster_spawn_object) - self:executeFunctionMonster("onDeath", creature) - self:deleteMonster(creature) - return true - end - return true -end - -local monsterDeathBoss = CreatureEvent("monsterDeathBoss") -function monsterDeathBoss.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamage_unjustified) - if creature:isMonster() then - local self = creature:getStorageValue(MonsterStorage.Spawn.monster_spawn_object) - self:removeSpawn() - self:removeMonsters() - return true - end - return true -end - -monsterDeathBoss:register() -monsterDeath:register() 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/lib/quests/soul_war.lua b/data-otservbr-global/lib/quests/soul_war.lua index f5b2d75f5ba..a6058bc4715 100644 --- a/data-otservbr-global/lib/quests/soul_war.lua +++ b/data-otservbr-global/lib/quests/soul_war.lua @@ -1455,7 +1455,7 @@ function Player:getSoulWarZoneMonster() return zoneMonsterName end -function Player:isInBoatSpot() +function Creature:isInBoatSpot() -- Get ebb and flow zone and check if player is in zone local zone = SoulWarQuest.ebbAndFlow.getZone() local tile = Tile(self:getPosition()) @@ -1464,11 +1464,11 @@ function Player:isInBoatSpot() groundId = tile:getGround():getId() end if zone and zone:isInZone(self:getPosition()) and tile and groundId == SoulWarQuest.ebbAndFlow.boatId then - logger.trace("Player {} is in boat spot", self:getName()) + logger.trace("Creature {} is in boat spot", self:getName()) return true end - logger.trace("Player {} is not in boat spot", self:getName()) + logger.trace("Creature {} is not in boat spot", self:getName()) return false end diff --git a/data-otservbr-global/migrations/46.lua b/data-otservbr-global/migrations/46.lua index 86a6d8ffec1..506da3a132b 100644 --- a/data-otservbr-global/migrations/46.lua +++ b/data-otservbr-global/migrations/46.lua @@ -1,3 +1,7 @@ function onUpdateDatabase() - return false -- true = There are others migrations file | false = this is the last migration file + logger.info("Updating database to version 47 (fix: creature speed and conditions)") + + db.query("ALTER TABLE `players` MODIFY `conditions` mediumblob NOT NULL;") + + return true end diff --git a/data-otservbr-global/migrations/47.lua b/data-otservbr-global/migrations/47.lua new file mode 100644 index 00000000000..86a6d8ffec1 --- /dev/null +++ b/data-otservbr-global/migrations/47.lua @@ -0,0 +1,3 @@ +function onUpdateDatabase() + return false -- true = There are others migrations file | false = this is the last migration file +end diff --git a/data-otservbr-global/monster/bosses/alchemist_container.lua b/data-otservbr-global/monster/bosses/alchemist_container.lua index 62905d5975e..5a15740a4f3 100644 --- a/data-otservbr-global/monster/bosses/alchemist_container.lua +++ b/data-otservbr-global/monster/bosses/alchemist_container.lua @@ -79,18 +79,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/antenna.lua b/data-otservbr-global/monster/bosses/antenna.lua index f1a165177cc..127d9fe77bf 100644 --- a/data-otservbr-global/monster/bosses/antenna.lua +++ b/data-otservbr-global/monster/bosses/antenna.lua @@ -79,18 +79,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/apocalypse.lua b/data-otservbr-global/monster/bosses/apocalypse.lua index 3e60fe75e34..422ebf84059 100644 --- a/data-otservbr-global/monster/bosses/apocalypse.lua +++ b/data-otservbr-global/monster/bosses/apocalypse.lua @@ -144,18 +144,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/apprentice_sheng.lua b/data-otservbr-global/monster/bosses/apprentice_sheng.lua index f0c6feacd95..b5d326f94a2 100644 --- a/data-otservbr-global/monster/bosses/apprentice_sheng.lua +++ b/data-otservbr-global/monster/bosses/apprentice_sheng.lua @@ -118,18 +118,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/armenius.lua b/data-otservbr-global/monster/bosses/armenius.lua index ffe6c7b412e..b80f2ff3b06 100644 --- a/data-otservbr-global/monster/bosses/armenius.lua +++ b/data-otservbr-global/monster/bosses/armenius.lua @@ -102,18 +102,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/bazir.lua b/data-otservbr-global/monster/bosses/bazir.lua index e9abbed723c..f9aa138933b 100644 --- a/data-otservbr-global/monster/bosses/bazir.lua +++ b/data-otservbr-global/monster/bosses/bazir.lua @@ -180,18 +180,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/bibby_bloodbath.lua b/data-otservbr-global/monster/bosses/bibby_bloodbath.lua index 8c1b09af2b5..d16b2f287d9 100644 --- a/data-otservbr-global/monster/bosses/bibby_bloodbath.lua +++ b/data-otservbr-global/monster/bosses/bibby_bloodbath.lua @@ -122,18 +122,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/big_boss_trolliver.lua b/data-otservbr-global/monster/bosses/big_boss_trolliver.lua index 24bc4ef5250..187b8e05d92 100644 --- a/data-otservbr-global/monster/bosses/big_boss_trolliver.lua +++ b/data-otservbr-global/monster/bosses/big_boss_trolliver.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/black_knight.lua b/data-otservbr-global/monster/bosses/black_knight.lua index 2905e1a7814..359ef3e2d5b 100644 --- a/data-otservbr-global/monster/bosses/black_knight.lua +++ b/data-otservbr-global/monster/bosses/black_knight.lua @@ -131,18 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/brain_head.lua b/data-otservbr-global/monster/bosses/brain_head.lua index c67524c5411..0c8b59b4a4a 100644 --- a/data-otservbr-global/monster/bosses/brain_head.lua +++ b/data-otservbr-global/monster/bosses/brain_head.lua @@ -102,18 +102,4 @@ monster.voices = { { text = "My lich-knights will conquer this world for me!", yell = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/bullwark.lua b/data-otservbr-global/monster/bosses/bullwark.lua index 2bc9ff91f02..2ae627598c9 100644 --- a/data-otservbr-global/monster/bosses/bullwark.lua +++ b/data-otservbr-global/monster/bosses/bullwark.lua @@ -127,18 +127,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/cerebellum.lua b/data-otservbr-global/monster/bosses/cerebellum.lua index b83fcec8615..5ca05351efb 100644 --- a/data-otservbr-global/monster/bosses/cerebellum.lua +++ b/data-otservbr-global/monster/bosses/cerebellum.lua @@ -77,18 +77,4 @@ monster.voices = { { text = "My lich-knights will conquer this world for me!", yell = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/chikhaton.lua b/data-otservbr-global/monster/bosses/chikhaton.lua index 53a430621ca..63b5629431c 100644 --- a/data-otservbr-global/monster/bosses/chikhaton.lua +++ b/data-otservbr-global/monster/bosses/chikhaton.lua @@ -102,18 +102,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/clubarc_the_plunderer.lua b/data-otservbr-global/monster/bosses/clubarc_the_plunderer.lua index aa10611af90..d2e7ca6c29f 100644 --- a/data-otservbr-global/monster/bosses/clubarc_the_plunderer.lua +++ b/data-otservbr-global/monster/bosses/clubarc_the_plunderer.lua @@ -108,18 +108,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/custodian.lua b/data-otservbr-global/monster/bosses/custodian.lua index d004ab5c3df..2a2e414d3d9 100644 --- a/data-otservbr-global/monster/bosses/custodian.lua +++ b/data-otservbr-global/monster/bosses/custodian.lua @@ -113,18 +113,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/dharalion.lua b/data-otservbr-global/monster/bosses/dharalion.lua index 3233e57448b..9268919df94 100644 --- a/data-otservbr-global/monster/bosses/dharalion.lua +++ b/data-otservbr-global/monster/bosses/dharalion.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/diblis_the_fair.lua b/data-otservbr-global/monster/bosses/diblis_the_fair.lua index 531dc6c2818..585fb0eff0a 100644 --- a/data-otservbr-global/monster/bosses/diblis_the_fair.lua +++ b/data-otservbr-global/monster/bosses/diblis_the_fair.lua @@ -123,18 +123,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/diseased_bill.lua b/data-otservbr-global/monster/bosses/diseased_bill.lua index 42df3b5c771..bc6babe9171 100644 --- a/data-otservbr-global/monster/bosses/diseased_bill.lua +++ b/data-otservbr-global/monster/bosses/diseased_bill.lua @@ -114,18 +114,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/diseased_dan.lua b/data-otservbr-global/monster/bosses/diseased_dan.lua index c44f9bc9702..f3b0de85388 100644 --- a/data-otservbr-global/monster/bosses/diseased_dan.lua +++ b/data-otservbr-global/monster/bosses/diseased_dan.lua @@ -114,18 +114,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/diseased_fred.lua b/data-otservbr-global/monster/bosses/diseased_fred.lua index 59304042e5c..41994a777ea 100644 --- a/data-otservbr-global/monster/bosses/diseased_fred.lua +++ b/data-otservbr-global/monster/bosses/diseased_fred.lua @@ -114,18 +114,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/doctor_marrow.lua b/data-otservbr-global/monster/bosses/doctor_marrow.lua index cccdd2e4d57..cd694d83b62 100644 --- a/data-otservbr-global/monster/bosses/doctor_marrow.lua +++ b/data-otservbr-global/monster/bosses/doctor_marrow.lua @@ -98,18 +98,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/ekatrix.lua b/data-otservbr-global/monster/bosses/ekatrix.lua index 99c7fc0f603..42500ee134f 100644 --- a/data-otservbr-global/monster/bosses/ekatrix.lua +++ b/data-otservbr-global/monster/bosses/ekatrix.lua @@ -111,18 +111,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/energized_raging_mage.lua b/data-otservbr-global/monster/bosses/energized_raging_mage.lua index 0d3aea8aaf0..643ea7428a3 100644 --- a/data-otservbr-global/monster/bosses/energized_raging_mage.lua +++ b/data-otservbr-global/monster/bosses/energized_raging_mage.lua @@ -115,18 +115,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/fleshslicer.lua b/data-otservbr-global/monster/bosses/fleshslicer.lua index 53aafc0fd31..7308101c0d4 100644 --- a/data-otservbr-global/monster/bosses/fleshslicer.lua +++ b/data-otservbr-global/monster/bosses/fleshslicer.lua @@ -99,18 +99,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/freegoiz.lua b/data-otservbr-global/monster/bosses/freegoiz.lua index eee6234add3..8f2ad6839b3 100644 --- a/data-otservbr-global/monster/bosses/freegoiz.lua +++ b/data-otservbr-global/monster/bosses/freegoiz.lua @@ -167,18 +167,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/gaffir.lua b/data-otservbr-global/monster/bosses/gaffir.lua index a3e2feb16a6..a51115cb094 100644 --- a/data-otservbr-global/monster/bosses/gaffir.lua +++ b/data-otservbr-global/monster/bosses/gaffir.lua @@ -141,18 +141,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/general_murius.lua b/data-otservbr-global/monster/bosses/general_murius.lua index 4c761e0b89f..f3cf1837f0f 100644 --- a/data-otservbr-global/monster/bosses/general_murius.lua +++ b/data-otservbr-global/monster/bosses/general_murius.lua @@ -129,18 +129,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/glitterscale.lua b/data-otservbr-global/monster/bosses/glitterscale.lua index 0705a895176..c14fae7f785 100644 --- a/data-otservbr-global/monster/bosses/glitterscale.lua +++ b/data-otservbr-global/monster/bosses/glitterscale.lua @@ -101,18 +101,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/grandfather_tridian.lua b/data-otservbr-global/monster/bosses/grandfather_tridian.lua index 6c2f0e9f188..3d58c8d768d 100644 --- a/data-otservbr-global/monster/bosses/grandfather_tridian.lua +++ b/data-otservbr-global/monster/bosses/grandfather_tridian.lua @@ -124,18 +124,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/gravelord_oshuran.lua b/data-otservbr-global/monster/bosses/gravelord_oshuran.lua index 442c014dcbb..53ed2381c4f 100644 --- a/data-otservbr-global/monster/bosses/gravelord_oshuran.lua +++ b/data-otservbr-global/monster/bosses/gravelord_oshuran.lua @@ -121,18 +121,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/groam.lua b/data-otservbr-global/monster/bosses/groam.lua index e010d50e708..8e9e56a2c5f 100644 --- a/data-otservbr-global/monster/bosses/groam.lua +++ b/data-otservbr-global/monster/bosses/groam.lua @@ -109,18 +109,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/guard_captain_quaid.lua b/data-otservbr-global/monster/bosses/guard_captain_quaid.lua index 479757ca620..85507170974 100644 --- a/data-otservbr-global/monster/bosses/guard_captain_quaid.lua +++ b/data-otservbr-global/monster/bosses/guard_captain_quaid.lua @@ -126,18 +126,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/hairman_the_huge.lua b/data-otservbr-global/monster/bosses/hairman_the_huge.lua index 735c1b3b263..5b0aa24de1d 100644 --- a/data-otservbr-global/monster/bosses/hairman_the_huge.lua +++ b/data-otservbr-global/monster/bosses/hairman_the_huge.lua @@ -107,18 +107,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/heoni.lua b/data-otservbr-global/monster/bosses/heoni.lua index b5e9cfdcfd3..9f099de756d 100644 --- a/data-otservbr-global/monster/bosses/heoni.lua +++ b/data-otservbr-global/monster/bosses/heoni.lua @@ -105,18 +105,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/incredibly_old_witch.lua b/data-otservbr-global/monster/bosses/incredibly_old_witch.lua index 8680042f7ca..4cd69a5fef2 100644 --- a/data-otservbr-global/monster/bosses/incredibly_old_witch.lua +++ b/data-otservbr-global/monster/bosses/incredibly_old_witch.lua @@ -104,18 +104,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/infernatil.lua b/data-otservbr-global/monster/bosses/infernatil.lua index c7ca8c53050..0a493c91177 100644 --- a/data-otservbr-global/monster/bosses/infernatil.lua +++ b/data-otservbr-global/monster/bosses/infernatil.lua @@ -176,18 +176,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/koshei_the_deathless.lua b/data-otservbr-global/monster/bosses/koshei_the_deathless.lua index e0b1c5e1ecc..ff6cc6e8654 100644 --- a/data-otservbr-global/monster/bosses/koshei_the_deathless.lua +++ b/data-otservbr-global/monster/bosses/koshei_the_deathless.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/kraknaknork's_demon.lua b/data-otservbr-global/monster/bosses/kraknaknork's_demon.lua index 8902bd9e527..a1579035a6f 100644 --- a/data-otservbr-global/monster/bosses/kraknaknork's_demon.lua +++ b/data-otservbr-global/monster/bosses/kraknaknork's_demon.lua @@ -97,18 +97,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/kraknaknork.lua b/data-otservbr-global/monster/bosses/kraknaknork.lua index 2bb4eb32b4a..c639a0c8bfd 100644 --- a/data-otservbr-global/monster/bosses/kraknaknork.lua +++ b/data-otservbr-global/monster/bosses/kraknaknork.lua @@ -112,14 +112,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/kroazur.lua b/data-otservbr-global/monster/bosses/kroazur.lua index 1664c14347a..ea38b19db8f 100644 --- a/data-otservbr-global/monster/bosses/kroazur.lua +++ b/data-otservbr-global/monster/bosses/kroazur.lua @@ -127,18 +127,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/lisa.lua b/data-otservbr-global/monster/bosses/lisa.lua index 7cbff8d7d49..2890e8d692a 100644 --- a/data-otservbr-global/monster/bosses/lisa.lua +++ b/data-otservbr-global/monster/bosses/lisa.lua @@ -130,18 +130,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/mad_mage.lua b/data-otservbr-global/monster/bosses/mad_mage.lua index 2ff8144d310..307f26a9aa0 100644 --- a/data-otservbr-global/monster/bosses/mad_mage.lua +++ b/data-otservbr-global/monster/bosses/mad_mage.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/mad_technomancer.lua b/data-otservbr-global/monster/bosses/mad_technomancer.lua index 7d72216b88a..0a329a858a6 100644 --- a/data-otservbr-global/monster/bosses/mad_technomancer.lua +++ b/data-otservbr-global/monster/bosses/mad_technomancer.lua @@ -104,18 +104,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/morik_the_gladiator.lua b/data-otservbr-global/monster/bosses/morik_the_gladiator.lua index 5a8a012ca84..670294b12e8 100644 --- a/data-otservbr-global/monster/bosses/morik_the_gladiator.lua +++ b/data-otservbr-global/monster/bosses/morik_the_gladiator.lua @@ -109,18 +109,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/morshabaal.lua b/data-otservbr-global/monster/bosses/morshabaal.lua index 4273977e2eb..363c103cad2 100644 --- a/data-otservbr-global/monster/bosses/morshabaal.lua +++ b/data-otservbr-global/monster/bosses/morshabaal.lua @@ -145,10 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/munster.lua b/data-otservbr-global/monster/bosses/munster.lua index daeeac7655e..21c2761d0f8 100644 --- a/data-otservbr-global/monster/bosses/munster.lua +++ b/data-otservbr-global/monster/bosses/munster.lua @@ -109,18 +109,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/pythius_the_rotten.lua b/data-otservbr-global/monster/bosses/pythius_the_rotten.lua index 80f694af6bc..742285c193f 100644 --- a/data-otservbr-global/monster/bosses/pythius_the_rotten.lua +++ b/data-otservbr-global/monster/bosses/pythius_the_rotten.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/raging_mage.lua b/data-otservbr-global/monster/bosses/raging_mage.lua index 5fd30131b8a..84e0232f37f 100644 --- a/data-otservbr-global/monster/bosses/raging_mage.lua +++ b/data-otservbr-global/monster/bosses/raging_mage.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/raxias.lua b/data-otservbr-global/monster/bosses/raxias.lua index ea62576f52d..3f0f7cf1ce6 100644 --- a/data-otservbr-global/monster/bosses/raxias.lua +++ b/data-otservbr-global/monster/bosses/raxias.lua @@ -103,18 +103,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/renegade_orc.lua b/data-otservbr-global/monster/bosses/renegade_orc.lua index 53f075751ae..157b75d352a 100644 --- a/data-otservbr-global/monster/bosses/renegade_orc.lua +++ b/data-otservbr-global/monster/bosses/renegade_orc.lua @@ -115,18 +115,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/rukor_zad.lua b/data-otservbr-global/monster/bosses/rukor_zad.lua index 361365745b5..bbcf1706943 100644 --- a/data-otservbr-global/monster/bosses/rukor_zad.lua +++ b/data-otservbr-global/monster/bosses/rukor_zad.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/smuggler_baron_silvertoe.lua b/data-otservbr-global/monster/bosses/smuggler_baron_silvertoe.lua index b59d09d2387..c35cc2dcf40 100644 --- a/data-otservbr-global/monster/bosses/smuggler_baron_silvertoe.lua +++ b/data-otservbr-global/monster/bosses/smuggler_baron_silvertoe.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/spider_queen.lua b/data-otservbr-global/monster/bosses/spider_queen.lua index 1f2b018f26c..88a0aa939c1 100644 --- a/data-otservbr-global/monster/bosses/spider_queen.lua +++ b/data-otservbr-global/monster/bosses/spider_queen.lua @@ -94,18 +94,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/splasher.lua b/data-otservbr-global/monster/bosses/splasher.lua index 426d3be3c26..825f56607db 100644 --- a/data-otservbr-global/monster/bosses/splasher.lua +++ b/data-otservbr-global/monster/bosses/splasher.lua @@ -110,18 +110,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/teleskor.lua b/data-otservbr-global/monster/bosses/teleskor.lua index 0c27b032658..e5941477479 100644 --- a/data-otservbr-global/monster/bosses/teleskor.lua +++ b/data-otservbr-global/monster/bosses/teleskor.lua @@ -104,18 +104,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_abomination.lua b/data-otservbr-global/monster/bosses/the_abomination.lua index e6ba0b1ae06..0249b2453ae 100644 --- a/data-otservbr-global/monster/bosses/the_abomination.lua +++ b/data-otservbr-global/monster/bosses/the_abomination.lua @@ -125,18 +125,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_astral_source.lua b/data-otservbr-global/monster/bosses/the_astral_source.lua index abc46bfc1d4..008da5078b5 100644 --- a/data-otservbr-global/monster/bosses/the_astral_source.lua +++ b/data-otservbr-global/monster/bosses/the_astral_source.lua @@ -96,18 +96,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_blightfather.lua b/data-otservbr-global/monster/bosses/the_blightfather.lua index 1cb8c870901..7e1c0515e87 100644 --- a/data-otservbr-global/monster/bosses/the_blightfather.lua +++ b/data-otservbr-global/monster/bosses/the_blightfather.lua @@ -108,18 +108,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_book_of_death.lua b/data-otservbr-global/monster/bosses/the_book_of_death.lua index 4f2d3288447..53d37c08795 100644 --- a/data-otservbr-global/monster/bosses/the_book_of_death.lua +++ b/data-otservbr-global/monster/bosses/the_book_of_death.lua @@ -100,18 +100,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_brainstealer.lua b/data-otservbr-global/monster/bosses/the_brainstealer.lua index 57a4beba537..78d783d4618 100644 --- a/data-otservbr-global/monster/bosses/the_brainstealer.lua +++ b/data-otservbr-global/monster/bosses/the_brainstealer.lua @@ -129,18 +129,4 @@ monster.voices = { { text = "My lich-knights will conquer this world for me!", yell = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_collector.lua b/data-otservbr-global/monster/bosses/the_collector.lua index b3fa70f85c6..5fd5a4a6336 100644 --- a/data-otservbr-global/monster/bosses/the_collector.lua +++ b/data-otservbr-global/monster/bosses/the_collector.lua @@ -98,18 +98,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_evil_eye.lua b/data-otservbr-global/monster/bosses/the_evil_eye.lua index f712959cdd7..b3be845c629 100644 --- a/data-otservbr-global/monster/bosses/the_evil_eye.lua +++ b/data-otservbr-global/monster/bosses/the_evil_eye.lua @@ -123,18 +123,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_first_dragon.lua b/data-otservbr-global/monster/bosses/the_first_dragon.lua index 34294280dd1..921f8394622 100644 --- a/data-otservbr-global/monster/bosses/the_first_dragon.lua +++ b/data-otservbr-global/monster/bosses/the_first_dragon.lua @@ -108,18 +108,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_frog_prince.lua b/data-otservbr-global/monster/bosses/the_frog_prince.lua index d90c6c78b2e..745757dc621 100644 --- a/data-otservbr-global/monster/bosses/the_frog_prince.lua +++ b/data-otservbr-global/monster/bosses/the_frog_prince.lua @@ -102,18 +102,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/the_monster.lua b/data-otservbr-global/monster/bosses/the_monster.lua index c7f84935b20..368bff98af0 100644 --- a/data-otservbr-global/monster/bosses/the_monster.lua +++ b/data-otservbr-global/monster/bosses/the_monster.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/verminor.lua b/data-otservbr-global/monster/bosses/verminor.lua index 1712cccab2e..43b4c194257 100644 --- a/data-otservbr-global/monster/bosses/verminor.lua +++ b/data-otservbr-global/monster/bosses/verminor.lua @@ -166,18 +166,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/visco.lua b/data-otservbr-global/monster/bosses/visco.lua index 96223ee28c0..d78729aeaf6 100644 --- a/data-otservbr-global/monster/bosses/visco.lua +++ b/data-otservbr-global/monster/bosses/visco.lua @@ -124,18 +124,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/warlord_ruzad.lua b/data-otservbr-global/monster/bosses/warlord_ruzad.lua index b66a9c3284b..1970e2d47f6 100644 --- a/data-otservbr-global/monster/bosses/warlord_ruzad.lua +++ b/data-otservbr-global/monster/bosses/warlord_ruzad.lua @@ -124,18 +124,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/weakened_demon.lua b/data-otservbr-global/monster/bosses/weakened_demon.lua index 7daf2f5dfb2..936849b379f 100644 --- a/data-otservbr-global/monster/bosses/weakened_demon.lua +++ b/data-otservbr-global/monster/bosses/weakened_demon.lua @@ -95,14 +95,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/weakened_shlorg.lua b/data-otservbr-global/monster/bosses/weakened_shlorg.lua index 615bd45f158..3734d602406 100644 --- a/data-otservbr-global/monster/bosses/weakened_shlorg.lua +++ b/data-otservbr-global/monster/bosses/weakened_shlorg.lua @@ -122,18 +122,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/williwasp.lua b/data-otservbr-global/monster/bosses/williwasp.lua index 64a90d09de1..93868eba760 100644 --- a/data-otservbr-global/monster/bosses/williwasp.lua +++ b/data-otservbr-global/monster/bosses/williwasp.lua @@ -104,18 +104,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/yaga_the_crone.lua b/data-otservbr-global/monster/bosses/yaga_the_crone.lua index 4987d01b4c2..5f47c5c907c 100644 --- a/data-otservbr-global/monster/bosses/yaga_the_crone.lua +++ b/data-otservbr-global/monster/bosses/yaga_the_crone.lua @@ -120,18 +120,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/zarabustor.lua b/data-otservbr-global/monster/bosses/zarabustor.lua index 8bb36a5e904..fbe771c51b9 100644 --- a/data-otservbr-global/monster/bosses/zarabustor.lua +++ b/data-otservbr-global/monster/bosses/zarabustor.lua @@ -128,18 +128,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/zavarash.lua b/data-otservbr-global/monster/bosses/zavarash.lua index a3f41dc6d04..3fd5b60c1e4 100644 --- a/data-otservbr-global/monster/bosses/zavarash.lua +++ b/data-otservbr-global/monster/bosses/zavarash.lua @@ -136,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/zevelon_duskbringer.lua b/data-otservbr-global/monster/bosses/zevelon_duskbringer.lua index 7dd4739741e..836ecdf37c2 100644 --- a/data-otservbr-global/monster/bosses/zevelon_duskbringer.lua +++ b/data-otservbr-global/monster/bosses/zevelon_duskbringer.lua @@ -124,18 +124,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/zoralurk.lua b/data-otservbr-global/monster/bosses/zoralurk.lua index e8095a70f68..6afc231f0d9 100644 --- a/data-otservbr-global/monster/bosses/zoralurk.lua +++ b/data-otservbr-global/monster/bosses/zoralurk.lua @@ -125,18 +125,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/bosses/zushuka.lua b/data-otservbr-global/monster/bosses/zushuka.lua index 2491261be7b..6e5c027d4c4 100644 --- a/data-otservbr-global/monster/bosses/zushuka.lua +++ b/data-otservbr-global/monster/bosses/zushuka.lua @@ -145,18 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/constructs/iron_servant_replica.lua b/data-otservbr-global/monster/constructs/iron_servant_replica.lua index 4ff09899972..a0fa2c74c74 100644 --- a/data-otservbr-global/monster/constructs/iron_servant_replica.lua +++ b/data-otservbr-global/monster/constructs/iron_servant_replica.lua @@ -113,4 +113,27 @@ monster.immunities = { { type = "bleed", condition = false }, } +mType.onSpawn = function(monster) + local chance = math.random(100) + if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismDiamond) >= 1 and Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismGolden) >= 1 then + if chance > 30 then + local monsterType = math.random(2) == 1 and "diamond servant replica" or "golden servant replica" + Game.createMonster(monsterType, monster:getPosition(), false, true) + monster:remove() + end + return + end + + if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismDiamond) >= 1 and chance > 30 then + Game.createMonster("diamond servant replica", monster:getPosition(), false, true) + monster:remove() + return + end + + if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismGolden) >= 1 and chance > 30 then + Game.createMonster("golden servant replica", monster:getPosition(), false, true) + monster:remove() + end +end + mType:register(monster) diff --git a/data-otservbr-global/monster/event_creatures/the_mutated_pumpkin.lua b/data-otservbr-global/monster/event_creatures/the_mutated_pumpkin.lua index 5e219736804..4abdfe16340 100644 --- a/data-otservbr-global/monster/event_creatures/the_mutated_pumpkin.lua +++ b/data-otservbr-global/monster/event_creatures/the_mutated_pumpkin.lua @@ -130,18 +130,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/humans/cobra_assassin.lua b/data-otservbr-global/monster/humans/cobra_assassin.lua index a2206a77ad5..fa834503e56 100644 --- a/data-otservbr-global/monster/humans/cobra_assassin.lua +++ b/data-otservbr-global/monster/humans/cobra_assassin.lua @@ -121,4 +121,8 @@ monster.immunities = { { type = "bleed", condition = false }, } +mType.onSpawn = function(monster) + monster:handleCobraOnSpawn() +end + mType:register(monster) diff --git a/data-otservbr-global/monster/humans/cobra_scout.lua b/data-otservbr-global/monster/humans/cobra_scout.lua index 7aded2b24ec..6fc3e893497 100644 --- a/data-otservbr-global/monster/humans/cobra_scout.lua +++ b/data-otservbr-global/monster/humans/cobra_scout.lua @@ -126,4 +126,8 @@ monster.immunities = { { type = "bleed", condition = false }, } +mType.onSpawn = function(monster) + monster:handleCobraOnSpawn() +end + mType:register(monster) diff --git a/data-otservbr-global/monster/humans/cobra_vizier.lua b/data-otservbr-global/monster/humans/cobra_vizier.lua index c6052ab7829..934b015842a 100644 --- a/data-otservbr-global/monster/humans/cobra_vizier.lua +++ b/data-otservbr-global/monster/humans/cobra_vizier.lua @@ -129,4 +129,8 @@ monster.immunities = { { type = "bleed", condition = false }, } +mType.onSpawn = function(monster) + monster:handleCobraOnSpawn() +end + mType:register(monster) diff --git a/data-otservbr-global/monster/quests/a_pirates_tail_quest/ratmiral_blackwhiskers.lua b/data-otservbr-global/monster/quests/a_pirates_tail_quest/ratmiral_blackwhiskers.lua index d399413ed93..03a093b3afb 100644 --- a/data-otservbr-global/monster/quests/a_pirates_tail_quest/ratmiral_blackwhiskers.lua +++ b/data-otservbr-global/monster/quests/a_pirates_tail_quest/ratmiral_blackwhiskers.lua @@ -141,10 +141,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/a_pirates_tail_quest/tentuglys_head.lua b/data-otservbr-global/monster/quests/a_pirates_tail_quest/tentuglys_head.lua index 07fef10a1fd..2fe0c2d05ce 100644 --- a/data-otservbr-global/monster/quests/a_pirates_tail_quest/tentuglys_head.lua +++ b/data-otservbr-global/monster/quests/a_pirates_tail_quest/tentuglys_head.lua @@ -121,10 +121,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/adventures_of_galthen/megasylvan_yselda.lua b/data-otservbr-global/monster/quests/adventures_of_galthen/megasylvan_yselda.lua index 606427d8afe..d3343d38d23 100644 --- a/data-otservbr-global/monster/quests/adventures_of_galthen/megasylvan_yselda.lua +++ b/data-otservbr-global/monster/quests/adventures_of_galthen/megasylvan_yselda.lua @@ -128,10 +128,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ancient_feud/katex_blood_tongue.lua b/data-otservbr-global/monster/quests/ancient_feud/katex_blood_tongue.lua index b6806adbed6..5c7ff8775e3 100644 --- a/data-otservbr-global/monster/quests/ancient_feud/katex_blood_tongue.lua +++ b/data-otservbr-global/monster/quests/ancient_feud/katex_blood_tongue.lua @@ -134,10 +134,4 @@ monster.immunities = { { type = "bleed", condition = true }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ancient_feud/srezz_yellow_eyes.lua b/data-otservbr-global/monster/quests/ancient_feud/srezz_yellow_eyes.lua index 3c849c72aa3..5246bf87bc4 100644 --- a/data-otservbr-global/monster/quests/ancient_feud/srezz_yellow_eyes.lua +++ b/data-otservbr-global/monster/quests/ancient_feud/srezz_yellow_eyes.lua @@ -128,10 +128,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ancient_feud/utua_stone_sting.lua b/data-otservbr-global/monster/quests/ancient_feud/utua_stone_sting.lua index 511c78787aa..06562f10883 100644 --- a/data-otservbr-global/monster/quests/ancient_feud/utua_stone_sting.lua +++ b/data-otservbr-global/monster/quests/ancient_feud/utua_stone_sting.lua @@ -131,10 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ancient_feud/yirkas_blue_scales.lua b/data-otservbr-global/monster/quests/ancient_feud/yirkas_blue_scales.lua index e469fa36986..1b170cb7447 100644 --- a/data-otservbr-global/monster/quests/ancient_feud/yirkas_blue_scales.lua +++ b/data-otservbr-global/monster/quests/ancient_feud/yirkas_blue_scales.lua @@ -129,10 +129,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/essence_of_malice.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/essence_of_malice.lua index 26aceb32010..c1cd61949aa 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/essence_of_malice.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/essence_of_malice.lua @@ -130,18 +130,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/ravenous_hunger.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/ravenous_hunger.lua index e3eef7671c6..cf456f603fb 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/ravenous_hunger.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/ravenous_hunger.lua @@ -145,18 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_false_god.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_false_god.lua index a1ec678bdf0..fc7fc63b2ad 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_false_god.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_false_god.lua @@ -139,18 +139,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_sandking.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_sandking.lua index 3e0914007db..ecddb810da0 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_sandking.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_sandking.lua @@ -144,18 +144,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_souldespoiler.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_souldespoiler.lua index 976fe5fe317..b6d08409ec8 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_souldespoiler.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_souldespoiler.lua @@ -155,18 +155,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_source_of_corruption.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_source_of_corruption.lua index 83f14ead593..3361299d9a9 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_source_of_corruption.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_source_of_corruption.lua @@ -117,18 +117,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_unarmored_voidborn.lua b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_unarmored_voidborn.lua index 04df78685ac..42fc6498721 100644 --- a/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_unarmored_voidborn.lua +++ b/data-otservbr-global/monster/quests/cults_of_tibia/bosses/the_unarmored_voidborn.lua @@ -136,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_baron_from_below.lua b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_baron_from_below.lua index a381c3b07d6..1a666a75342 100644 --- a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_baron_from_below.lua +++ b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_baron_from_below.lua @@ -151,18 +151,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_count_of_the_core.lua b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_count_of_the_core.lua index 17cb6520d29..60769958a14 100644 --- a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_count_of_the_core.lua +++ b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_count_of_the_core.lua @@ -152,18 +152,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_duke_of_the_depths.lua b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_duke_of_the_depths.lua index 99053b93882..29f3d1d3e40 100644 --- a/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_duke_of_the_depths.lua +++ b/data-otservbr-global/monster/quests/dangerous_depth/bosses/the_duke_of_the_depths.lua @@ -152,18 +152,4 @@ monster.heals = { { type = COMBAT_FIREDAMAGE, percent = 100 }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/irgix_the_flimsy.lua b/data-otservbr-global/monster/quests/feaster_of_souls/irgix_the_flimsy.lua index 307f1b27380..1d2507cb3e5 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/irgix_the_flimsy.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/irgix_the_flimsy.lua @@ -113,18 +113,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/the_dread_maiden.lua b/data-otservbr-global/monster/quests/feaster_of_souls/the_dread_maiden.lua index 83308c9c2fc..9fbbf66ce16 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/the_dread_maiden.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/the_dread_maiden.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/the_fear_feaster.lua b/data-otservbr-global/monster/quests/feaster_of_souls/the_fear_feaster.lua index 85a6444085b..dda3018993c 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/the_fear_feaster.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/the_fear_feaster.lua @@ -136,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/the_pale_worm.lua b/data-otservbr-global/monster/quests/feaster_of_souls/the_pale_worm.lua index ab309d2f583..6c816a7ee52 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/the_pale_worm.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/the_pale_worm.lua @@ -144,18 +144,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/the_unwelcome.lua b/data-otservbr-global/monster/quests/feaster_of_souls/the_unwelcome.lua index e4abf230b1d..a3a283b0a7f 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/the_unwelcome.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/the_unwelcome.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/unaz_the_mean.lua b/data-otservbr-global/monster/quests/feaster_of_souls/unaz_the_mean.lua index fb871252bea..52582834231 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/unaz_the_mean.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/unaz_the_mean.lua @@ -113,18 +113,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/feaster_of_souls/vok_the_freakish.lua b/data-otservbr-global/monster/quests/feaster_of_souls/vok_the_freakish.lua index 4efff07d202..7de35d1b9d1 100644 --- a/data-otservbr-global/monster/quests/feaster_of_souls/vok_the_freakish.lua +++ b/data-otservbr-global/monster/quests/feaster_of_souls/vok_the_freakish.lua @@ -111,18 +111,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ferumbras_mortal_shell.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ferumbras_mortal_shell.lua index 7ad855bc88a..a7c9f071385 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ferumbras_mortal_shell.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ferumbras_mortal_shell.lua @@ -186,18 +186,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/mazoran.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/mazoran.lua index 3f32bac95d4..8213e9a4d51 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/mazoran.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/mazoran.lua @@ -141,18 +141,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/plagirath.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/plagirath.lua index 364b4f864a8..b8fff3b3006 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/plagirath.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/plagirath.lua @@ -141,18 +141,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ragiaz.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ragiaz.lua index df016edfd84..856dbf02d2b 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ragiaz.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/ragiaz.lua @@ -144,18 +144,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/razzagorn.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/razzagorn.lua index 066e22237c0..f95b0b69093 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/razzagorn.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/razzagorn.lua @@ -158,18 +158,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/shulgrax.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/shulgrax.lua index 72c908104af..2168dcc3bf2 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/shulgrax.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/shulgrax.lua @@ -81,7 +81,6 @@ monster.loot = { { id = 6558, chance = 10000 }, -- flask of demonic blood { id = 6558, chance = 10000 }, -- flask of demonic blood { id = 6558, chance = 10000 }, -- flask of demonic blood - { id = 17838, chance = 1800 }, -- unknown item { id = 3019, chance = 1000 }, -- demonbone amulet { id = 3026, chance = 12000, maxCount = 8 }, -- white pearl { id = 3029, chance = 12000, maxCount = 9 }, -- small sapphire @@ -153,18 +152,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/tarbaz.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/tarbaz.lua index 30b99353cdf..7cb57a1040d 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/tarbaz.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/tarbaz.lua @@ -143,18 +143,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/zamulosh.lua b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/zamulosh.lua index 03fa92d3394..41e8b074228 100644 --- a/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/zamulosh.lua +++ b/data-otservbr-global/monster/quests/ferumbras_ascension/bosses/zamulosh.lua @@ -143,18 +143,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lady_tenebris.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lady_tenebris.lua index 17d68ca6994..c4228eefe54 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lady_tenebris.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lady_tenebris.lua @@ -149,18 +149,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lloyd.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lloyd.lua index 5d5f729e749..1f73944519a 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lloyd.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/lloyd.lua @@ -146,18 +146,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/melting_frozen_horror.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/melting_frozen_horror.lua index 6fa44fff690..5f50a0c3e22 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/melting_frozen_horror.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/melting_frozen_horror.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/soul_of_dragonking_zyrtarch.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/soul_of_dragonking_zyrtarch.lua index 2def55d9283..c45a1fc4ef0 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/soul_of_dragonking_zyrtarch.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/soul_of_dragonking_zyrtarch.lua @@ -147,18 +147,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_blazing_time_guardian.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_blazing_time_guardian.lua index fef77ab81cf..e13c2f7fd22 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_blazing_time_guardian.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_blazing_time_guardian.lua @@ -131,18 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_enraged_thorn_knight.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_enraged_thorn_knight.lua index c664a5e21d2..ab868b6f58c 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_enraged_thorn_knight.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_enraged_thorn_knight.lua @@ -152,18 +152,4 @@ monster.heals = { { type = COMBAT_DEATHDAMAGE, percent = 100 }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_freezing_time_guardian.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_freezing_time_guardian.lua index 8fcbd1ddbab..b3f64c4331a 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_freezing_time_guardian.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_freezing_time_guardian.lua @@ -132,18 +132,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_last_lore_keeper.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_last_lore_keeper.lua index f1d96fe25bc..30dd34b9766 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_last_lore_keeper.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_last_lore_keeper.lua @@ -164,18 +164,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_time_guardian.lua b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_time_guardian.lua index 7bf8e0c82ad..902c9a28950 100644 --- a/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_time_guardian.lua +++ b/data-otservbr-global/monster/quests/forgotten_knowledge/bosses/the_time_guardian.lua @@ -150,18 +150,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/count_vlarkorth.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/count_vlarkorth.lua index ced550fbc84..f2de105033d 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/count_vlarkorth.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/count_vlarkorth.lua @@ -142,18 +142,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/duke_krule.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/duke_krule.lua index 518eda46ac2..851867e0161 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/duke_krule.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/duke_krule.lua @@ -135,18 +135,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/earl_osam.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/earl_osam.lua index c996116a336..930a744f326 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/earl_osam.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/earl_osam.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/king_zelos.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/king_zelos.lua index cafd09f34a7..b723715c55d 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/king_zelos.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/king_zelos.lua @@ -122,18 +122,4 @@ monster.voices = { { text = "My lich-knights will conquer this world for me!", yell = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/lord_azaram.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/lord_azaram.lua index 8507c3a0c1c..188f11c9dc6 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/lord_azaram.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/lord_azaram.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/scarlett_etzel.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/scarlett_etzel.lua index 6673313045f..9dcb6503d38 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/scarlett_etzel.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/scarlett_etzel.lua @@ -146,18 +146,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/grave_danger/bosses/sir_baeloc.lua b/data-otservbr-global/monster/quests/grave_danger/bosses/sir_baeloc.lua index 042ce32e981..957ad10e5ff 100644 --- a/data-otservbr-global/monster/quests/grave_danger/bosses/sir_baeloc.lua +++ b/data-otservbr-global/monster/quests/grave_danger/bosses/sir_baeloc.lua @@ -136,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/aftershock.lua b/data-otservbr-global/monster/quests/heart_of_destruction/aftershock.lua index 04c1b3a2589..8f14e9d3fb1 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/aftershock.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/aftershock.lua @@ -106,18 +106,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/anomaly.lua b/data-otservbr-global/monster/quests/heart_of_destruction/anomaly.lua index 2d6c0e44405..6350b49a3c6 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/anomaly.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/anomaly.lua @@ -145,18 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/charged_anomaly.lua b/data-otservbr-global/monster/quests/heart_of_destruction/charged_anomaly.lua index 075c308d7df..aa3f5589fc5 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/charged_anomaly.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/charged_anomaly.lua @@ -103,18 +103,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/charging_outburst.lua b/data-otservbr-global/monster/quests/heart_of_destruction/charging_outburst.lua index 273ab8f579e..d765d016a8a 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/charging_outburst.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/charging_outburst.lua @@ -103,18 +103,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/eradicator.lua b/data-otservbr-global/monster/quests/heart_of_destruction/eradicator.lua index d81c9b4faf1..e7eb2443a4d 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/eradicator.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/eradicator.lua @@ -137,18 +137,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/eradicator2.lua b/data-otservbr-global/monster/quests/heart_of_destruction/eradicator2.lua index 14b92badfbe..0c8dba87dac 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/eradicator2.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/eradicator2.lua @@ -136,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/foreshock.lua b/data-otservbr-global/monster/quests/heart_of_destruction/foreshock.lua index 99f5be41e19..7e1f3fc214a 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/foreshock.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/foreshock.lua @@ -106,18 +106,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/outburst.lua b/data-otservbr-global/monster/quests/heart_of_destruction/outburst.lua index c40159545ed..e0efdb42d16 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/outburst.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/outburst.lua @@ -128,18 +128,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/realityquake.lua b/data-otservbr-global/monster/quests/heart_of_destruction/realityquake.lua index c9d7601584f..3870524d5a9 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/realityquake.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/realityquake.lua @@ -127,18 +127,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/rupture.lua b/data-otservbr-global/monster/quests/heart_of_destruction/rupture.lua index 5d68108bba4..672bd5ecc0c 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/rupture.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/rupture.lua @@ -131,18 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/heart_of_destruction/world_devourer.lua b/data-otservbr-global/monster/quests/heart_of_destruction/world_devourer.lua index c8e7198a2e1..6bf55bf348d 100644 --- a/data-otservbr-global/monster/quests/heart_of_destruction/world_devourer.lua +++ b/data-otservbr-global/monster/quests/heart_of_destruction/world_devourer.lua @@ -135,18 +135,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/hero_of_rathleton/deep_terror.lua b/data-otservbr-global/monster/quests/hero_of_rathleton/deep_terror.lua index debd09c9bb9..aaa7f1936af 100644 --- a/data-otservbr-global/monster/quests/hero_of_rathleton/deep_terror.lua +++ b/data-otservbr-global/monster/quests/hero_of_rathleton/deep_terror.lua @@ -109,18 +109,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/hero_of_rathleton/professor_maxxen.lua b/data-otservbr-global/monster/quests/hero_of_rathleton/professor_maxxen.lua index 947a56a0187..4085e5eab86 100644 --- a/data-otservbr-global/monster/quests/hero_of_rathleton/professor_maxxen.lua +++ b/data-otservbr-global/monster/quests/hero_of_rathleton/professor_maxxen.lua @@ -127,18 +127,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/kilmaresh/bragrumol.lua b/data-otservbr-global/monster/quests/kilmaresh/bragrumol.lua index bb7ef950744..125a017735b 100644 --- a/data-otservbr-global/monster/quests/kilmaresh/bragrumol.lua +++ b/data-otservbr-global/monster/quests/kilmaresh/bragrumol.lua @@ -117,18 +117,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/kilmaresh/mozradek.lua b/data-otservbr-global/monster/quests/kilmaresh/mozradek.lua index 8602923a08b..da498edede4 100644 --- a/data-otservbr-global/monster/quests/kilmaresh/mozradek.lua +++ b/data-otservbr-global/monster/quests/kilmaresh/mozradek.lua @@ -111,18 +111,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/kilmaresh/urmahlullu_the_weakened.lua b/data-otservbr-global/monster/quests/kilmaresh/urmahlullu_the_weakened.lua index 96a8dd39081..1060d49b26f 100644 --- a/data-otservbr-global/monster/quests/kilmaresh/urmahlullu_the_weakened.lua +++ b/data-otservbr-global/monster/quests/kilmaresh/urmahlullu_the_weakened.lua @@ -147,18 +147,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/kilmaresh/xogixath.lua b/data-otservbr-global/monster/quests/kilmaresh/xogixath.lua index 3c77465e1ab..70dc531f5ce 100644 --- a/data-otservbr-global/monster/quests/kilmaresh/xogixath.lua +++ b/data-otservbr-global/monster/quests/kilmaresh/xogixath.lua @@ -117,18 +117,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/liquid_black/jaul.lua b/data-otservbr-global/monster/quests/liquid_black/jaul.lua index 965bbacb14c..7802788a73e 100644 --- a/data-otservbr-global/monster/quests/liquid_black/jaul.lua +++ b/data-otservbr-global/monster/quests/liquid_black/jaul.lua @@ -123,18 +123,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/liquid_black/obujos.lua b/data-otservbr-global/monster/quests/liquid_black/obujos.lua index 1f32fd54f1c..5e732cdcbd0 100644 --- a/data-otservbr-global/monster/quests/liquid_black/obujos.lua +++ b/data-otservbr-global/monster/quests/liquid_black/obujos.lua @@ -115,18 +115,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/liquid_black/tanjis.lua b/data-otservbr-global/monster/quests/liquid_black/tanjis.lua index 586af950be3..f726e36fe55 100644 --- a/data-otservbr-global/monster/quests/liquid_black/tanjis.lua +++ b/data-otservbr-global/monster/quests/liquid_black/tanjis.lua @@ -118,18 +118,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/marapur/timira_the_many-headed.lua b/data-otservbr-global/monster/quests/marapur/timira_the_many-headed.lua index 43d0a1502c3..09ed0f19be8 100644 --- a/data-otservbr-global/monster/quests/marapur/timira_the_many-headed.lua +++ b/data-otservbr-global/monster/quests/marapur/timira_the_many-headed.lua @@ -125,10 +125,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/primal_ordeal_quest/magma_bubble.lua b/data-otservbr-global/monster/quests/primal_ordeal_quest/magma_bubble.lua index 8f3bf7f6166..9607bf8310c 100644 --- a/data-otservbr-global/monster/quests/primal_ordeal_quest/magma_bubble.lua +++ b/data-otservbr-global/monster/quests/primal_ordeal_quest/magma_bubble.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/primal_ordeal_quest/plunder_patriarch.lua b/data-otservbr-global/monster/quests/primal_ordeal_quest/plunder_patriarch.lua index 25d7c224f09..42fbf1fcdd9 100644 --- a/data-otservbr-global/monster/quests/primal_ordeal_quest/plunder_patriarch.lua +++ b/data-otservbr-global/monster/quests/primal_ordeal_quest/plunder_patriarch.lua @@ -127,18 +127,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua b/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua index 7ad43b016c9..b0ba0ae8686 100644 --- a/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua +++ b/data-otservbr-global/monster/quests/primal_ordeal_quest/the_primal_menace.lua @@ -162,16 +162,6 @@ local function initialize(monster) end -- Functions for the fight -mType.onAppear = function(monster, creature) - if monster:getId() == creature:getId() then - initialize(monster) - end - - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - local function getHazardPoints(monster) local hazard = Hazard.getByName("hazard.gnomprona-gardens") if not hazard then diff --git a/data-otservbr-global/monster/quests/roshamuul/gaz'haragoth.lua b/data-otservbr-global/monster/quests/roshamuul/gaz'haragoth.lua index 0e6d5695d33..6dce4e10838 100644 --- a/data-otservbr-global/monster/quests/roshamuul/gaz'haragoth.lua +++ b/data-otservbr-global/monster/quests/roshamuul/gaz'haragoth.lua @@ -179,18 +179,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/roshamuul/omrafir.lua b/data-otservbr-global/monster/quests/roshamuul/omrafir.lua index e3f09b27dd0..03254912b71 100644 --- a/data-otservbr-global/monster/quests/roshamuul/omrafir.lua +++ b/data-otservbr-global/monster/quests/roshamuul/omrafir.lua @@ -148,18 +148,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/roshamuul/prince_drazzak.lua b/data-otservbr-global/monster/quests/roshamuul/prince_drazzak.lua index f969d02e6aa..d2a65e59fea 100644 --- a/data-otservbr-global/monster/quests/roshamuul/prince_drazzak.lua +++ b/data-otservbr-global/monster/quests/roshamuul/prince_drazzak.lua @@ -126,18 +126,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_blue.lua b/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_blue.lua index cfd0f53f7fa..cf81168aa00 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_blue.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_blue.lua @@ -127,12 +127,6 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - local intervalBetweenExecutions = 10000 local zone = Zone.getByName("boss.goshnar's-megalomania-purple") diff --git a/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_green.lua b/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_green.lua index 8e8effb5e08..787ab94b662 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_green.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnar's_megalomania_green.lua @@ -138,12 +138,6 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - local intervalBetweenExecutions = 10000 local zone = Zone.getByName("boss.goshnar's-megalomania-purple") diff --git a/data-otservbr-global/monster/quests/soul_war/goshnars_cruelty.lua b/data-otservbr-global/monster/quests/soul_war/goshnars_cruelty.lua index 3f1cb2c4421..468e6a312e4 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnars_cruelty.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnars_cruelty.lua @@ -144,16 +144,6 @@ mType.onThink = function(monster, interval) end end -mType.onAppear = function(monster, creature) end - -mType.onSpawn = function(monsterCallback) - if monsterCallback:getType():isRewardBoss() then - monsterCallback:setReward(true) - end - - firstTime = 0 -end - mType.onDisappear = function(monster, creature) if creature:getName() == "Goshnar's Cruelty" then local eyeCreature = Creature("A Greedy Eye") @@ -163,8 +153,4 @@ mType.onDisappear = function(monster, creature) end end -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/soul_war/goshnars_greed.lua b/data-otservbr-global/monster/quests/soul_war/goshnars_greed.lua index 16d995988a5..e17e581212e 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnars_greed.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnars_greed.lua @@ -185,8 +185,4 @@ mType.onDisappear = function(monster, creature) end end -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/soul_war/goshnars_hatred.lua b/data-otservbr-global/monster/quests/soul_war/goshnars_hatred.lua index f218e0b7e9f..cc6652eb9d9 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnars_hatred.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnars_hatred.lua @@ -133,18 +133,6 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) end - -mType.onSpawn = function(monster) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end - - monster:resetHatredDamageMultiplier() -end - mType.onDisappear = function(monster, creature) if creature:getName() == "Goshnar's Hatred" then for _, monsterName in pairs(SoulWarQuest.burningHatredMonsters) do @@ -156,8 +144,4 @@ mType.onDisappear = function(monster, creature) end end -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/soul_war/goshnars_malice.lua b/data-otservbr-global/monster/quests/soul_war/goshnars_malice.lua index c4598e9bbe0..1cda5185bbe 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnars_malice.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnars_malice.lua @@ -147,16 +147,4 @@ mType.onThink = function(monster, interval) end end -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/soul_war/goshnars_spite.lua b/data-otservbr-global/monster/quests/soul_war/goshnars_spite.lua index 7501e466f54..1daedf2a191 100644 --- a/data-otservbr-global/monster/quests/soul_war/goshnars_spite.lua +++ b/data-otservbr-global/monster/quests/soul_war/goshnars_spite.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/black_vixen.lua b/data-otservbr-global/monster/quests/the_curse_spreads/black_vixen.lua index 214b8c6f2ce..6f7f41694fe 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/black_vixen.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/black_vixen.lua @@ -138,18 +138,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/bloodback.lua b/data-otservbr-global/monster/quests/the_curse_spreads/bloodback.lua index 3b9dd8e0eea..5423c6e2e9e 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/bloodback.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/bloodback.lua @@ -131,18 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/darkfang.lua b/data-otservbr-global/monster/quests/the_curse_spreads/darkfang.lua index 5506350848b..70b6c25bb1e 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/darkfang.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/darkfang.lua @@ -134,18 +134,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/feroxa5.lua b/data-otservbr-global/monster/quests/the_curse_spreads/feroxa5.lua index 39fed1dc78c..57ccdba515a 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/feroxa5.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/feroxa5.lua @@ -118,18 +118,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/shadowpelt.lua b/data-otservbr-global/monster/quests/the_curse_spreads/shadowpelt.lua index 2b195487dfd..1e28879cd9c 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/shadowpelt.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/shadowpelt.lua @@ -134,18 +134,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_curse_spreads/sharpclaw.lua b/data-otservbr-global/monster/quests/the_curse_spreads/sharpclaw.lua index 50ad689b7c7..08f757afcfc 100644 --- a/data-otservbr-global/monster/quests/the_curse_spreads/sharpclaw.lua +++ b/data-otservbr-global/monster/quests/the_curse_spreads/sharpclaw.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/alptramun.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/alptramun.lua index 46b5cf6c91d..af8b385ddb2 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/alptramun.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/alptramun.lua @@ -150,18 +150,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/faceless_bane.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/faceless_bane.lua index 868fe08e756..f129a99f00a 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/faceless_bane.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/faceless_bane.lua @@ -145,23 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - -- reset global storage state to default / ensure sqm's reset for the next team - Game.setStorageValue(GlobalStorage.TheDreamCourts.FacelessBane.Deaths, -1) - Game.setStorageValue(GlobalStorage.TheDreamCourts.FacelessBane.StepsOn, -1) - Game.setStorageValue(GlobalStorage.TheDreamCourts.FacelessBane.ResetSteps, 1) - monster:registerEvent("facelessBaneImmunity") - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/izcandar_the_banished.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/izcandar_the_banished.lua index 9c693024899..88688c4fffc 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/izcandar_the_banished.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/izcandar_the_banished.lua @@ -152,18 +152,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/malofur_mangrinder.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/malofur_mangrinder.lua index 2bd63f042be..651ee8cb59b 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/malofur_mangrinder.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/malofur_mangrinder.lua @@ -145,18 +145,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/maxxenius.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/maxxenius.lua index 8db50108f56..a54257df723 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/maxxenius.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/maxxenius.lua @@ -152,18 +152,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/plagueroot.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/plagueroot.lua index d62affd19a4..3d5675c4486 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/plagueroot.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/plagueroot.lua @@ -178,18 +178,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_dream_courts/bosses/the_nightmare_beast.lua b/data-otservbr-global/monster/quests/the_dream_courts/bosses/the_nightmare_beast.lua index d0520193aad..3937edcd2d4 100644 --- a/data-otservbr-global/monster/quests/the_dream_courts/bosses/the_nightmare_beast.lua +++ b/data-otservbr-global/monster/quests/the_dream_courts/bosses/the_nightmare_beast.lua @@ -154,18 +154,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_order_of_lion/bosses/ancient_lion_knight.lua b/data-otservbr-global/monster/quests/the_order_of_lion/bosses/ancient_lion_knight.lua index aba0cc866b4..3f5ad2a3cd7 100644 --- a/data-otservbr-global/monster/quests/the_order_of_lion/bosses/ancient_lion_knight.lua +++ b/data-otservbr-global/monster/quests/the_order_of_lion/bosses/ancient_lion_knight.lua @@ -131,10 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_order_of_lion/bosses/drume.lua b/data-otservbr-global/monster/quests/the_order_of_lion/bosses/drume.lua index 9d86b77cd48..34d15a0a248 100644 --- a/data-otservbr-global/monster/quests/the_order_of_lion/bosses/drume.lua +++ b/data-otservbr-global/monster/quests/the_order_of_lion/bosses/drume.lua @@ -161,10 +161,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_order_of_lion/lion_commander.lua b/data-otservbr-global/monster/quests/the_order_of_lion/lion_commander.lua index f409fca3c4b..378bbc0e1a5 100644 --- a/data-otservbr-global/monster/quests/the_order_of_lion/lion_commander.lua +++ b/data-otservbr-global/monster/quests/the_order_of_lion/lion_commander.lua @@ -111,19 +111,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster ~= creature then - return true - end - for i = 1, 5 do - local sum = Game.createMonster(monster:getType():getSummonList()[math.random(1, #monster:getType():getSummonList())].name, monster:getPosition(), true) - if sum then - monster:setSummon(sum) - sum:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - sum:setStorageValue(Storage.TheOrderOfTheLion.Drume.Commander, 1) - end - end - monster:setStorageValue(Storage.TheOrderOfTheLion.Drume.Commander, 1) -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_order_of_lion/usurper_commander.lua b/data-otservbr-global/monster/quests/the_order_of_lion/usurper_commander.lua index fd31fa62806..f46ff987e92 100644 --- a/data-otservbr-global/monster/quests/the_order_of_lion/usurper_commander.lua +++ b/data-otservbr-global/monster/quests/the_order_of_lion/usurper_commander.lua @@ -112,20 +112,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onAppear = function(monster, creature) - if monster ~= creature then - return true - end - local sum - for i = 1, 5 do - sum = Game.createMonster(monster:getType():getSummonList()[math.random(1, #monster:getType():getSummonList())].name, monster:getPosition(), true) - if sum then - monster:setSummon(sum) - sum:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - sum:setStorageValue(Storage.TheOrderOfTheLion.Drume.Commander, 1) - end - end - monster:setStorageValue(Storage.TheOrderOfTheLion.Drume.Commander, 1) -end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/brokul.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/brokul.lua index ffe52519e85..f05a8adae85 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/brokul.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/brokul.lua @@ -129,18 +129,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/ghulosh.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/ghulosh.lua index f9d04e40db4..fe80352ff13 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/ghulosh.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/ghulosh.lua @@ -95,7 +95,6 @@ monster.loot = { { name = "butcher's axe", chance = 1000 }, { name = "dreaded cleaver", chance = 1000 }, { name = "mercenary sword", chance = 1000 }, - { id = 28341, chance = 1000 }, -- tessellated wall { name = "slightly rusted shield", chance = 5880 }, { name = "slightly rusted helmet", chance = 35290 }, { name = "epaulette", chance = 500 }, @@ -137,18 +136,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/gorzindel.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/gorzindel.lua index 4d549175bab..7a31d798d9a 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/gorzindel.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/gorzindel.lua @@ -143,18 +143,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_canon_dominus.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_canon_dominus.lua index 23390f0145f..453c3be3389 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_canon_dominus.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_canon_dominus.lua @@ -119,18 +119,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_chaplain_gaunder.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_chaplain_gaunder.lua index 57589cb7b17..f27050df438 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_chaplain_gaunder.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_chaplain_gaunder.lua @@ -126,18 +126,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_commander_soeren.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_commander_soeren.lua index 685b1f10f07..bb01cf3c515 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_commander_soeren.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_commander_soeren.lua @@ -118,18 +118,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_master_oberon.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_master_oberon.lua index c57bf0815ae..5de851ac4c1 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_master_oberon.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/grand_master_oberon.lua @@ -131,20 +131,6 @@ mType.onThink = function(monster, interval) end end -mType.onAppear = function(monster, creature) - if monster:getId() == creature:getId() then - monster:setStorageValue(GrandMasterOberonConfig.Storage.Asking, 1) - monster:setStorageValue(GrandMasterOberonConfig.Storage.Life, 1) - end - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - mType.onSay = function(monster, creature, type, message) if type ~= TALKTYPE_SAY then return false diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/preceptor_lazare.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/preceptor_lazare.lua index c9db8d4446c..f5477192be6 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/preceptor_lazare.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/preceptor_lazare.lua @@ -130,18 +130,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/thawing_dragon_lord.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/thawing_dragon_lord.lua index fa175a85a2b..ad7e340ffb2 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/thawing_dragon_lord.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/thawing_dragon_lord.lua @@ -105,18 +105,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/bosses/the_scourge_of_oblivion.lua b/data-otservbr-global/monster/quests/the_secret_library/bosses/the_scourge_of_oblivion.lua index 491b946adba..2d0e1069f30 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/bosses/the_scourge_of_oblivion.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/bosses/the_scourge_of_oblivion.lua @@ -183,18 +183,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/lokathmor.lua b/data-otservbr-global/monster/quests/the_secret_library/lokathmor.lua index 699f0550d52..8ef0357fca8 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/lokathmor.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/lokathmor.lua @@ -100,7 +100,6 @@ monster.loot = { { name = "dreaded cleaver", chance = 30000 }, { name = "slightly rusted shield", chance = 26670 }, { name = "wand of inferno", chance = 30000 }, - { id = 28341, chance = 1000 }, -- tessellated wall { name = "sturdy book", chance = 1000 }, } @@ -140,18 +139,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/quests/the_secret_library/mazzinor.lua b/data-otservbr-global/monster/quests/the_secret_library/mazzinor.lua index f482dfe4b9e..f93e6785563 100644 --- a/data-otservbr-global/monster/quests/the_secret_library/mazzinor.lua +++ b/data-otservbr-global/monster/quests/the_secret_library/mazzinor.lua @@ -129,18 +129,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/chayenne.lua b/data-otservbr-global/monster/raids/chayenne.lua index 0f8f64d9686..2ab96a01c2d 100644 --- a/data-otservbr-global/monster/raids/chayenne.lua +++ b/data-otservbr-global/monster/raids/chayenne.lua @@ -105,18 +105,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/chizzoron_the_distorter.lua b/data-otservbr-global/monster/raids/chizzoron_the_distorter.lua index 7fbc5d3cd71..3569332eaf2 100644 --- a/data-otservbr-global/monster/raids/chizzoron_the_distorter.lua +++ b/data-otservbr-global/monster/raids/chizzoron_the_distorter.lua @@ -123,18 +123,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/ferumbras.lua b/data-otservbr-global/monster/raids/ferumbras.lua index c3dfea647ea..f49eb8075ab 100644 --- a/data-otservbr-global/monster/raids/ferumbras.lua +++ b/data-otservbr-global/monster/raids/ferumbras.lua @@ -168,18 +168,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/furyosa.lua b/data-otservbr-global/monster/raids/furyosa.lua index acbf9711298..bc4ffdc3477 100644 --- a/data-otservbr-global/monster/raids/furyosa.lua +++ b/data-otservbr-global/monster/raids/furyosa.lua @@ -133,18 +133,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/ghazbaran.lua b/data-otservbr-global/monster/raids/ghazbaran.lua index 5f57655679f..f014e06e82a 100644 --- a/data-otservbr-global/monster/raids/ghazbaran.lua +++ b/data-otservbr-global/monster/raids/ghazbaran.lua @@ -164,18 +164,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/glooth_bomb.lua b/data-otservbr-global/monster/raids/glooth_bomb.lua index b1973e7b8ec..a69c59a3c6c 100644 --- a/data-otservbr-global/monster/raids/glooth_bomb.lua +++ b/data-otservbr-global/monster/raids/glooth_bomb.lua @@ -114,18 +114,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/hirintror.lua b/data-otservbr-global/monster/raids/hirintror.lua index 12a4d20d183..aa3ac63011d 100644 --- a/data-otservbr-global/monster/raids/hirintror.lua +++ b/data-otservbr-global/monster/raids/hirintror.lua @@ -125,18 +125,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/mawhawk.lua b/data-otservbr-global/monster/raids/mawhawk.lua index f00407ca304..697638fdda4 100644 --- a/data-otservbr-global/monster/raids/mawhawk.lua +++ b/data-otservbr-global/monster/raids/mawhawk.lua @@ -121,18 +121,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/morgaroth.lua b/data-otservbr-global/monster/raids/morgaroth.lua index 2e965cc99ec..02a65453da4 100644 --- a/data-otservbr-global/monster/raids/morgaroth.lua +++ b/data-otservbr-global/monster/raids/morgaroth.lua @@ -178,18 +178,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/ocyakao.lua b/data-otservbr-global/monster/raids/ocyakao.lua index 2e036c0837b..5321a0b59ff 100644 --- a/data-otservbr-global/monster/raids/ocyakao.lua +++ b/data-otservbr-global/monster/raids/ocyakao.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/orshabaal.lua b/data-otservbr-global/monster/raids/orshabaal.lua index 7d7ef6052df..2054c1e2a3b 100644 --- a/data-otservbr-global/monster/raids/orshabaal.lua +++ b/data-otservbr-global/monster/raids/orshabaal.lua @@ -167,18 +167,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/the_pale_count.lua b/data-otservbr-global/monster/raids/the_pale_count.lua index 31a40bcfff2..29f1cf6b043 100644 --- a/data-otservbr-global/monster/raids/the_pale_count.lua +++ b/data-otservbr-global/monster/raids/the_pale_count.lua @@ -144,18 +144,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/the_welter.lua b/data-otservbr-global/monster/raids/the_welter.lua index addb7008d75..7e2f2c3ed8f 100644 --- a/data-otservbr-global/monster/raids/the_welter.lua +++ b/data-otservbr-global/monster/raids/the_welter.lua @@ -137,18 +137,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/tyrn.lua b/data-otservbr-global/monster/raids/tyrn.lua index 0c19ac9944f..158a4e93833 100644 --- a/data-otservbr-global/monster/raids/tyrn.lua +++ b/data-otservbr-global/monster/raids/tyrn.lua @@ -131,18 +131,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/white_pale.lua b/data-otservbr-global/monster/raids/white_pale.lua index 06b6dcab4f3..17d093fb5bf 100644 --- a/data-otservbr-global/monster/raids/white_pale.lua +++ b/data-otservbr-global/monster/raids/white_pale.lua @@ -116,18 +116,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/raids/zulazza_the_corruptor.lua b/data-otservbr-global/monster/raids/zulazza_the_corruptor.lua index b7d14d9c966..0c2212c2a45 100644 --- a/data-otservbr-global/monster/raids/zulazza_the_corruptor.lua +++ b/data-otservbr-global/monster/raids/zulazza_the_corruptor.lua @@ -132,18 +132,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/monster/undeads/ahau.lua b/data-otservbr-global/monster/undeads/ahau.lua index 9d7f0f17c9c..ce5704769a9 100644 --- a/data-otservbr-global/monster/undeads/ahau.lua +++ b/data-otservbr-global/monster/undeads/ahau.lua @@ -130,18 +130,4 @@ monster.immunities = { { type = "bleed", condition = false }, } -mType.onThink = function(monster, interval) end - -mType.onAppear = function(monster, creature) - if monster:getType():isRewardBoss() then - monster:setReward(true) - end -end - -mType.onDisappear = function(monster, creature) end - -mType.onMove = function(monster, creature, fromPosition, toPosition) end - -mType.onSay = function(monster, creature, type, message) end - mType:register(monster) diff --git a/data-otservbr-global/npc/hireling.lua b/data-otservbr-global/npc/hireling.lua index ce5c6737e02..bfc9000ca0f 100644 --- a/data-otservbr-global/npc/hireling.lua +++ b/data-otservbr-global/npc/hireling.lua @@ -420,11 +420,13 @@ function createHirelingType(HirelingName) local TOPIC_FOOD = { SKILL_CHOOSE = 1301, + SKILL_SURPRISE = 1302, } local GREETINGS = { BANK = "Alright! What can I do for you and your bank business, |PLAYERNAME|?", - FOOD = "Hmm, yes! A variety of fine food awaits! However, a small expense of 15000 gold is expected to make these delicious masterpieces happen. Shall I?", + FOOD = [[Hmm, yes! A variety of fine food awaits! However, a small expense of 15000 gold is expected to make these delicious masterpieces happen. + For 90000 gold I will also serve you a specific dish. Just tell me what it shall be: a {specific} meal or a little {surprise}.]], STASH = "Of course, here is your stash! Well-maintained and neatly sorted for your convenience!", } @@ -513,7 +515,7 @@ function createHirelingType(HirelingName) return message end - local function deliverFood(npc, creature, food_id) + local function deliverFood(npc, creature, food_id, cost) local playerId = creature:getId() local player = Player(creature) local itType = ItemType(food_id) @@ -523,8 +525,8 @@ function createHirelingType(HirelingName) npcHandler:say("Sorry, but you don't have enough capacity.", npc, creature) elseif not inbox or #inboxItems >= inbox:getMaxCapacity() then player:getPosition():sendMagicEffect(CONST_ME_POFF) - npcHandler:say("Sorry, you don't have enough room on your inbox", npc, creature) - elseif not player:removeMoneyBank(15000) then + npcHandler:say("Sorry, you don't have enough room on your inbox.", npc, creature) + elseif not player:removeMoneyBank(cost) then npcHandler:say("Sorry, you don't have enough money.", npc, creature) else local message = getDeliveredMessageByFoodId(food_id) @@ -534,38 +536,66 @@ function createHirelingType(HirelingName) npcHandler:setTopic(playerId, TOPIC.SERVICES) end - local function cookFood(npc, creature) + local function cookFood(npc, creature, specificRequest) local playerId = creature:getId() - local random = math.random(6) - if random == 6 then - -- ask for preferred skill + if specificRequest then + npcHandler:say("Very well. You may choose one of the following: {chilli con carniphila}, {svargrond salmon filet}, {carrion casserole}, {consecrated beef}, {roasted wyvern wings}, {carrot pie}, {tropical marinated tiger}, or {delicatessen salad}.", npc, creature) npcHandler:setTopic(playerId, TOPIC_FOOD.SKILL_CHOOSE) - npcHandler:say("Yay! I have the ingredients to make a skill boost dish. Would you rather like to boost your {magic}, {melee}, {shielding} or {distance} skill?", npc, creature) - else -- deliver the random generated index - deliverFood(npc, creature, HIRELING_FOODS_IDS[random]) + else + npcHandler:say("Alright, let me astonish you. Shall I?", npc, creature) + deliverFood(npc, creature, HIRELING_FOODS_IDS[math.random(#HIRELING_FOODS_IDS)], 15000) end end local function handleFoodActions(npc, creature, message) local playerId = creature:getId() + if npcHandler:getTopic(playerId) == TOPIC.FOOD then - if MsgContains(message, "yes") then - cookFood(npc, creature) + if MsgContains(message, "specific") then + npcHandler:setTopic(playerId, TOPIC_FOOD.SPECIFIC) + npcHandler:say("Which specific meal would you like? Choices are: {chilli con carniphila}, {svargrond salmon filet}, {carrion casserole}, {consecrated beef}, {roasted wyvern wings}, {carrot pie}, {tropical marinated tiger}, or {delicatessen salad}.", npc, creature) + elseif MsgContains(message, "surprise") then + local random = math.random(6) + if random == 6 then + npcHandler:setTopic(playerId, TOPIC_FOOD.SKILL_CHOOSE) + npcHandler:say("Yay! I have the ingredients to make a skill boost dish. Would you rather like to boost your {magic}, {melee}, {shielding}, or {distance} skill?", npc, creature) + else + deliverFood(npc, creature, HIRELING_FOODS_IDS[random], 15000) + end + elseif MsgContains(message, "yes") then + deliverFood(npc, creature, HIRELING_FOODS_IDS[math.random(#HIRELING_FOODS_IDS)], 15000) elseif MsgContains(message, "no") then npcHandler:setTopic(playerId, TOPIC.SERVICES) npcHandler:say("Alright then, ask me for other {services}, if you want.", npc, creature) end elseif npcHandler:getTopic(playerId) == TOPIC_FOOD.SKILL_CHOOSE then if MsgContains(message, "magic") then - deliverFood(npc, creature, HIRELING_FOODS_BOOST.MAGIC) + deliverFood(npc, creature, HIRELING_FOODS_BOOST.MAGIC, 15000) elseif MsgContains(message, "melee") then - deliverFood(npc, creature, HIRELING_FOODS_BOOST.MELEE) + deliverFood(npc, creature, HIRELING_FOODS_BOOST.MELEE, 15000) elseif MsgContains(message, "shielding") then - deliverFood(npc, creature, HIRELING_FOODS_BOOST.SHIELDING) + deliverFood(npc, creature, HIRELING_FOODS_BOOST.SHIELDING, 15000) elseif MsgContains(message, "distance") then - deliverFood(npc, creature, HIRELING_FOODS_BOOST.DISTANCE) + deliverFood(npc, creature, HIRELING_FOODS_BOOST.DISTANCE, 15000) + else + npcHandler:say("Sorry, but you must choose a valid skill class. Would you like to boost your {magic}, {melee}, {shielding}, or {distance} skill?", npc, creature) + end + elseif npcHandler:getTopic(playerId) == TOPIC_FOOD.SPECIFIC then + local specificFoodOptions = { + ["chilli con carniphila"] = 29412, + ["svargrond salmon filet"] = 29413, + ["carrion casserole"] = 29414, + ["consecrated beef"] = 29415, + ["roasted wyvern wings"] = 29408, + ["carrot pie"] = 29409, + ["tropical marinated tiger"] = 29410, + ["delicatessen salad"] = 29411, + } + + if specificFoodOptions[message:lower()] then + deliverFood(npc, creature, specificFoodOptions[message:lower()], 90000) else - npcHandler:say("Sorry, but you must choose a valid skill class. Would you like to boost your {magic}, {melee}, {shielding} or {distance} skill?", npc, creature) + npcHandler:say("I'm sorry, but that's not a valid food option. Please choose from: {chilli con carniphila}, {svargrond salmon filet}, {carrion casserole}, {consecrated beef}, {roasted wyvern wings}, {carrot pie}, {tropical marinated tiger}, or {delicatessen salad}.", npc, creature) end end end @@ -656,7 +686,7 @@ function createHirelingType(HirelingName) end elseif npcHandler:getTopic(playerId) == TOPIC.BANK then enableBankSystem[playerId] = true - elseif npcHandler:getTopic(playerId) == TOPIC.FOOD or npcHandler:getTopic(playerId) == TOPIC_FOOD.SKILL_CHOOSE then + elseif npcHandler:getTopic(playerId) == TOPIC.FOOD or npcHandler:getTopic(playerId) == TOPIC_FOOD.SKILL_CHOOSE or npcHandler:getTopic(playerId) == TOPIC_FOOD.SPECIFIC then handleFoodActions(npc, creature, message) elseif npcHandler:getTopic(playerId) == TOPIC.GOODS then -- Ensures players cannot access other shop categories diff --git a/data-otservbr-global/npc/kais.lua b/data-otservbr-global/npc/kais.lua index d7fe97f0e75..5da84b1d9cf 100644 --- a/data-otservbr-global/npc/kais.lua +++ b/data-otservbr-global/npc/kais.lua @@ -46,8 +46,8 @@ npcType.onCloseChannel = function(npc, creature) end -- Blood of the Mountain -local blessKeyword = keywordHandler:addKeyword({ "blood" }, StdModule.say, { npcHandler = npcHandler, text = "Would you like to receive that protection for a sacrifice of |BLESSCOST| gold, child?" }) -blessKeyword:addChildKeyword({ "yes" }, StdModule.bless, { npcHandler = npcHandler, text = "So receive the Blood of the Mountain, pilgrim.", cost = "|BLESSCOST|", bless = 7 }) +local blessKeyword = keywordHandler:addKeyword({ "enhanced" }, StdModule.say, { npcHandler = npcHandler, text = "I have the power to grant you the blood of the mountain's blessing. But I must ask of you to sacrifice |BLESSCOST| gold. Are you prepared for that?" }) +blessKeyword:addChildKeyword({ "yes" }, StdModule.bless, { npcHandler = npcHandler, text = "So receive the blood of the mountain, master.", cost = "|BLESSCOST|", bless = 8 }) blessKeyword:addChildKeyword({ "" }, StdModule.say, { npcHandler = npcHandler, text = "Fine. You are free to decline my offer.", reset = true }) -- Healing @@ -58,6 +58,7 @@ local function addHealKeyword(text, condition, effect) player:removeCondition(condition) player:getPosition():sendMagicEffect(effect) end) + keywordHandler:addAliasKeyword({ "help" }) end addHealKeyword("You are burning. Let me quench those flames.", CONDITION_FIRE, CONST_ME_MAGIC_GREEN) @@ -74,26 +75,19 @@ end, function(player) player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) end) keywordHandler:addKeyword({ "heal" }, StdModule.say, { npcHandler = npcHandler, text = "You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here." }) +keywordHandler:addAliasKeyword({ "help" }) -- Basic -keywordHandler:addKeyword({ "pilgrimage" }, StdModule.say, { npcHandler = npcHandler, text = "Whenever you receive a lethal wound, your vital force is damaged and there is a chance that you lose some of your equipment. With every single of the five {blessings} you have, this damage and chance of loss will be reduced." }) -keywordHandler:addKeyword({ "blessings" }, StdModule.say, { npcHandler = npcHandler, text = "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. Additionally, you can receive the {twist of fate} here." }) -keywordHandler:addKeyword({ "spiritual" }, StdModule.say, { npcHandler = npcHandler, text = "I see you received the spiritual shielding in the whiteflower temple south of Thais." }, function(player) - return player:hasBlessing(1) -end) -keywordHandler:addAliasKeyword({ "shield" }) -keywordHandler:addKeyword({ "suns" }, StdModule.say, { npcHandler = npcHandler, text = "I can see you received the blessing of the two suns in the suntower near Ab'Dendriel." }, function(player) - return player:hasBlessing(3) -end) -keywordHandler:addAliasKeyword({ "fire" }) -keywordHandler:addKeyword({ "phoenix" }, StdModule.say, { npcHandler = npcHandler, text = "I can sense that the spark of the phoenix already was given to you by the dwarven priests of earth and fire in Kazordoon." }, function(player) - return player:hasBlessing(4) -end) -keywordHandler:addAliasKeyword({ "spark" }) -keywordHandler:addKeyword({ "solitude" }, StdModule.say, { npcHandler = npcHandler, text = "I can sense you already talked to the hermit Eremo on the isle of Cormaya and received this blessing." }, function(player) - return player:hasBlessing(5) -end) -keywordHandler:addAliasKeyword({ "wisdom" }) +keywordHandler:addKeyword({ "Kais" }, StdModule.say, { npcHandler = npcHandler, text = "I am Kais, Kais the Bound. Eternally {fixed} to the wretched place, unless... unless I prove my worth in aiding all those who seek my {help}." }) + +keywordHandler:addKeyword({ "pilgrimage" }, StdModule.say, { npcHandler = npcHandler, text = "Well, as I am quite in a fix currently, my only hope to escape this situation may be to grant you {healing} or an {enhanced} blessing if you wish. You must desire SOMETHING, right? Sure you do." }) +keywordHandler:addAliasKeyword({ "job" }) + +keywordHandler:addKeyword({ "blessing" }, StdModule.say, { + npcHandler = npcHandler, + text = "Besides the {enhanced} blessing available from me, I know of one other, granted by a solitary {nomad} far west of Svargrond. There are also five different other blessings available, each in a sacred place. ...\nThese blessings are: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}.", +}) + keywordHandler:addKeyword({ "spiritual" }, StdModule.say, { npcHandler = npcHandler, text = "You can ask for the blessing of spiritual shielding in the whiteflower temple south of Thais." }) keywordHandler:addAliasKeyword({ "shield" }) keywordHandler:addKeyword({ "suns" }, StdModule.say, { npcHandler = npcHandler, text = "You can ask for the blessing of the two suns in the suntower near Ab'Dendriel." }) @@ -102,10 +96,14 @@ keywordHandler:addKeyword({ "phoenix" }, StdModule.say, { npcHandler = npcHandle keywordHandler:addAliasKeyword({ "spark" }) keywordHandler:addKeyword({ "solitude" }, StdModule.say, { npcHandler = npcHandler, text = "Talk to the hermit Eremo on the isle of Cormaya about this blessing." }) keywordHandler:addAliasKeyword({ "wisdom" }) +keywordHandler:addKeyword({ "embrace" }, StdModule.say, { npcHandler = npcHandler, text = "The druids north of Carlin will provide you with the embrace of Tibia." }) +keywordHandler:addAliasKeyword({ "tibia" }) + +keywordHandler:addKeyword({ "nomad" }, StdModule.say, { npcHandler = npcHandler, text = "I know everyone and everything. It is certain that there is another enhanced blessing, the 'heart of the mountain'. Talk to a nomad far to the west of Svargrond, hiding slightly above ground." }) -npcHandler:setMessage(MESSAGE_GREET, "Welcome, noble |PLAYERNAME|") -npcHandler:setMessage(MESSAGE_WALKAWAY, "Good Bye, noble |PLAYERNAME|") -npcHandler:setMessage(MESSAGE_FAREWELL, "Good Bye, noble |PLAYERNAME|") +npcHandler:setMessage(MESSAGE_GREET, "Hmm... surely you are in need of {help} - will you let me? I am {Kais} the Bound and I can lend you a hand in {healing} your body and soul or even grant an {enhanced} blessing!") +npcHandler:setMessage(MESSAGE_WALKAWAY, "Fare you well... |PLAYERNAME|") +npcHandler:setMessage(MESSAGE_FAREWELL, "Fare you well... |PLAYERNAME|") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/npc/nomad.lua b/data-otservbr-global/npc/nomad.lua index 79dee9cc229..2e33e91a872 100644 --- a/data-otservbr-global/npc/nomad.lua +++ b/data-otservbr-global/npc/nomad.lua @@ -50,8 +50,8 @@ npcType.onCloseChannel = function(npc, creature) end -- Heart of the Mountain -local blessKeyword = keywordHandler:addKeyword({ "heart" }, StdModule.say, { npcHandler = npcHandler, text = "Would you like to receive that protection for a sacrifice of |BLESSCOST| gold, child?" }) -blessKeyword:addChildKeyword({ "yes" }, StdModule.bless, { npcHandler = npcHandler, text = "So receive the Heart of the Mountain, pilgrim.", cost = "|BLESSCOST|", bless = 8 }) +local blessKeyword = keywordHandler:addKeyword({ "enhanced" }, StdModule.say, { npcHandler = npcHandler, text = "I am able to grant you the heart of the mountain's blessing. But I must ask of you to sacrifice |BLESSCOST| gold. Are you willing to part with that amount of wealth?" }) +blessKeyword:addChildKeyword({ "yes" }, StdModule.bless, { npcHandler = npcHandler, text = "Receive the heart of the mountain then.", cost = "|BLESSCOST|", bless = 7 }) blessKeyword:addChildKeyword({ "" }, StdModule.say, { npcHandler = npcHandler, text = "Fine. You are free to decline my offer.", reset = true }) -- Healing @@ -62,6 +62,7 @@ local function addHealKeyword(text, condition, effect) player:removeCondition(condition) player:getPosition():sendMagicEffect(effect) end) + keywordHandler:addAliasKeyword({ "help" }) end addHealKeyword("You are burning. Let me quench those flames.", CONDITION_FIRE, CONST_ME_MAGIC_GREEN) @@ -78,26 +79,17 @@ end, function(player) player:getPosition():sendMagicEffect(CONST_ME_MAGIC_GREEN) end) keywordHandler:addKeyword({ "heal" }, StdModule.say, { npcHandler = npcHandler, text = "You aren't looking that bad. Sorry, I can't help you. But if you are looking for additional protection you should go on the {pilgrimage} of ashes or get the protection of the {twist of fate} here." }) +keywordHandler:addAliasKeyword({ "help" }) -- Basic -keywordHandler:addKeyword({ "pilgrimage" }, StdModule.say, { npcHandler = npcHandler, text = "Whenever you receive a lethal wound, your vital force is damaged and there is a chance that you lose some of your equipment. With every single of the five {blessings} you have, this damage and chance of loss will be reduced." }) -keywordHandler:addKeyword({ "blessings" }, StdModule.say, { npcHandler = npcHandler, text = "There are five blessings available in five sacred places: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}. Additionally, you can receive the {twist of fate} here." }) -keywordHandler:addKeyword({ "spiritual" }, StdModule.say, { npcHandler = npcHandler, text = "I see you received the spiritual shielding in the whiteflower temple south of Thais." }, function(player) - return player:hasBlessing(1) -end) -keywordHandler:addAliasKeyword({ "shield" }) -keywordHandler:addKeyword({ "suns" }, StdModule.say, { npcHandler = npcHandler, text = "I can see you received the blessing of the two suns in the suntower near Ab'Dendriel." }, function(player) - return player:hasBlessing(3) -end) -keywordHandler:addAliasKeyword({ "fire" }) -keywordHandler:addKeyword({ "phoenix" }, StdModule.say, { npcHandler = npcHandler, text = "I can sense that the spark of the phoenix already was given to you by the dwarven priests of earth and fire in Kazordoon." }, function(player) - return player:hasBlessing(4) -end) -keywordHandler:addAliasKeyword({ "spark" }) -keywordHandler:addKeyword({ "solitude" }, StdModule.say, { npcHandler = npcHandler, text = "I can sense you already talked to the hermit Eremo on the isle of Cormaya and received this blessing." }, function(player) - return player:hasBlessing(5) -end) -keywordHandler:addAliasKeyword({ "wisdom" }) +keywordHandler:addKeyword({ "blessing" }, StdModule.say, { + npcHandler = npcHandler, + text = "Besides the {enhanced} blessing available from me, I know of one other, granted by a solitary {nomad} far west of Svargrond. There are also five different other blessings available, each in a sacred place. ...\nThese blessings are: the {spiritual} shielding, the spark of the {phoenix}, the {embrace} of Tibia, the fire of the {suns} and the wisdom of {solitude}.", +}) + +keywordHandler:addKeyword({ "pilgrimage" }, StdModule.say, { npcHandler = npcHandler, text = "Well, as I am quite in a {fix} currently, my only hope to escape this situation may be to grant you {healing} or an {enhanced} blessing if you wish. You must desire SOMETHING, right? Sure you do." }) +keywordHandler:addAliasKeyword({ "job" }) + keywordHandler:addKeyword({ "spiritual" }, StdModule.say, { npcHandler = npcHandler, text = "You can ask for the blessing of spiritual shielding in the whiteflower temple south of Thais." }) keywordHandler:addAliasKeyword({ "shield" }) keywordHandler:addKeyword({ "suns" }, StdModule.say, { npcHandler = npcHandler, text = "You can ask for the blessing of the two suns in the suntower near Ab'Dendriel." }) @@ -106,10 +98,16 @@ keywordHandler:addKeyword({ "phoenix" }, StdModule.say, { npcHandler = npcHandle keywordHandler:addAliasKeyword({ "spark" }) keywordHandler:addKeyword({ "solitude" }, StdModule.say, { npcHandler = npcHandler, text = "Talk to the hermit Eremo on the isle of Cormaya about this blessing." }) keywordHandler:addAliasKeyword({ "wisdom" }) +keywordHandler:addKeyword({ "embrace" }, StdModule.say, { npcHandler = npcHandler, text = "The druids north of Carlin will provide you with the embrace of Tibia." }) +keywordHandler:addAliasKeyword({ "tibia" }) + +keywordHandler:addKeyword({ "djinn" }, StdModule.say, { npcHandler = npcHandler, text = "I know of a mysterious djinn, bound to an existence of slavery far to the north of Tiquanda's jungles. He is bound to tell you his secrets and offer you the 'blood of the mountain'. ...\nI do not know where exactly but I guess you must first dig that one out to actually talk to him." }) +keywordHandler:addKeyword({ "nomad" }, StdModule.say, { npcHandler = npcHandler, text = "I am one with nature, one with the ice and the cold. Names are of no worth out here. Out here, you face isolation and loneliness. Only your strength, willpower and {training} can keep you alive." }) +keywordHandler:addKeyword({ "training" }, StdModule.say, { npcHandler = npcHandler, text = "My life is one of hardship, hardship I chose freely. Endurance, strength and the power of the will are my only companions in this frigid wilderness. My strength comes from disciplined training and knowledge of the outdoors." }) -npcHandler:setMessage(MESSAGE_GREET, "Welcome, noble |PLAYERNAME|") -npcHandler:setMessage(MESSAGE_WALKAWAY, "Good Bye, noble |PLAYERNAME|") -npcHandler:setMessage(MESSAGE_FAREWELL, "Good Bye, noble |PLAYERNAME|") +npcHandler:setMessage(MESSAGE_GREET, "Ah, another diciple of the extreme... surviving the icy outdoors? Let me {help}! If you need some first aid out here, I can provide {healing} or grant you an {enhanced} blessing!") +npcHandler:setMessage(MESSAGE_WALKAWAY, "Keep a stiff upper lip!") +npcHandler:setMessage(MESSAGE_FAREWELL, "Keep a stiff upper lip!") npcHandler:addModule(FocusModule:new(), npcConfig.name, true, true, true) diff --git a/data-otservbr-global/scripts/actions/bosses_levers/brokul.lua b/data-otservbr-global/scripts/actions/bosses_levers/brokul.lua deleted file mode 100644 index 2cdded463af..00000000000 --- a/data-otservbr-global/scripts/actions/bosses_levers/brokul.lua +++ /dev/null @@ -1,23 +0,0 @@ -local config = { - boss = { - name = "Brokul", - position = Position(33483, 31434, 15), - }, - requiredLevel = 150, - playerPositions = { - { pos = Position(33522, 31465, 15), teleport = Position(33483, 31445, 15), effect = CONST_ME_TELEPORT }, - { pos = Position(33520, 31465, 15), teleport = Position(33483, 31445, 15), effect = CONST_ME_TELEPORT }, - { pos = Position(33521, 31465, 15), teleport = Position(33483, 31445, 15), effect = CONST_ME_TELEPORT }, - { pos = Position(33523, 31465, 15), teleport = Position(33483, 31445, 15), effect = CONST_ME_TELEPORT }, - { pos = Position(33524, 31465, 15), teleport = Position(33483, 31445, 15), effect = CONST_ME_TELEPORT }, - }, - specPos = { - from = Position(33469, 31430, 15), - to = Position(33497, 31453, 15), - }, - exit = Position(33522, 31468, 15), -} - -local lever = BossLever(config) -lever:aid(34000) -lever:register() diff --git a/data-otservbr-global/scripts/actions/bosses_levers/grand_master_oberon.lua b/data-otservbr-global/scripts/actions/bosses_levers/grand_master_oberon.lua deleted file mode 100644 index e7a1a104d52..00000000000 --- a/data-otservbr-global/scripts/actions/bosses_levers/grand_master_oberon.lua +++ /dev/null @@ -1,22 +0,0 @@ -local config = { - boss = { - name = "Grand Master Oberon", - position = Position(33364, 31317, 9), - }, - playerPositions = { - { pos = Position(33362, 31344, 9), teleport = Position(33364, 31322, 9) }, - { pos = Position(33363, 31344, 9), teleport = Position(33364, 31322, 9) }, - { pos = Position(33364, 31344, 9), teleport = Position(33364, 31322, 9) }, - { pos = Position(33365, 31344, 9), teleport = Position(33364, 31322, 9) }, - { pos = Position(33366, 31344, 9), teleport = Position(33364, 31322, 9) }, - }, - specPos = { - from = Position(33357, 31312, 9), - to = Position(33371, 31324, 9), - }, - exit = Position(33364, 31341, 9), -} - -local lever = BossLever(config) -lever:aid(57605) -lever:register() diff --git a/data-otservbr-global/scripts/actions/other/bed_modification_kits.lua b/data-otservbr-global/scripts/actions/other/bed_modification_kits.lua deleted file mode 100644 index 4dd68ff834d..00000000000 --- a/data-otservbr-global/scripts/actions/other/bed_modification_kits.lua +++ /dev/null @@ -1,54 +0,0 @@ -local beds = { - [831] = { { 734, 735 }, { 736, 737 } }, -- green kit - [832] = { { 742, 743 }, { 744, 745 } }, -- yellow kit - [833] = { { 738, 739 }, { 740, 741 } }, -- red kit - [834] = { { 2487, 2488 }, { 2493, 2494 } }, -- removal kit - [17972] = { { 17917, 17918 }, { 17919, 17920 } }, -- canopy kit -} - -local function internalBedTransform(item, target, toPosition, itemArray) - target:transform(itemArray[1]) - target:getPosition():sendMagicEffect(CONST_ME_POFF) - - toPosition:getTile():getItemByType(ITEM_TYPE_BED):transform(itemArray[2]) - toPosition:sendMagicEffect(CONST_ME_POFF) - - item:remove() -end - -local bedModificationKits = Action() - -function bedModificationKits.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local newBed = beds[item.itemid] - if not newBed then - return false - end - - local tile = toPosition:getTile() - if not tile or not tile:getHouse() then - return false - end - - if target.itemid == newBed[1][1] or target.itemid == newBed[2][1] then - player:sendTextMessage(MESSAGE_FAILURE, "You already have this bed modification.") - return true - end - - for kit, bed in pairs(beds) do - if bed[1][1] == target.itemid or table.contains({ 2491, 5501, 15506 }, target.itemid) then - toPosition:sendMagicEffect(CONST_ME_POFF) - toPosition.y = toPosition.y + 1 - internalBedTransform(item, target, toPosition, newBed[1]) - break - elseif bed[2][1] == target.itemid or table.contains({ 2489, 5499, 15508 }, target.itemid) then - toPosition:sendMagicEffect(CONST_ME_POFF) - toPosition.x = toPosition.x + 1 - internalBedTransform(item, target, toPosition, newBed[2]) - break - end - end - return true -end - -bedModificationKits:id(831, 832, 833, 834, 17972) -bedModificationKits:register() diff --git a/data-otservbr-global/scripts/actions/other/dolls.lua b/data-otservbr-global/scripts/actions/other/dolls.lua deleted file mode 100644 index 32864dcd109..00000000000 --- a/data-otservbr-global/scripts/actions/other/dolls.lua +++ /dev/null @@ -1,106 +0,0 @@ -local dolls = { - [5080] = { "Hug me." }, - [5668] = { - "It's not winning that matters, but winning in style.", - "Today's your lucky day. Probably.", - "Do not meddle in the affairs of dragons, for you are crunchy and taste good with ketchup.", - "That is one stupid question.", - "You'll need more rum for that.", - "Do or do not. There is no try.", - "You should do something you always wanted to.", - "If you walk under a ladder and it falls down on you it probably means bad luck.", - "Never say 'oops'. Always say 'Ah, interesting!'", - "Five steps east, fourteen steps south, two steps north and seventeen steps west!", - }, - [6566] = { - "Fchhhhhh!", - "Zchhhhhh!", - "Grooaaaaar*cough*", - "Aaa... CHOO!", - "You... will.... burn!!", - }, - [6387] = { "Merry Christmas |PLAYERNAME|." }, - [6511] = { - "Ho ho ho", - "Jingle bells, jingle bells...", - "Have you been naughty?", - "Have you been nice?", - "Merry Christmas!", - "Can you stop squeezing me now... I'm starting to feel a little sick.", - }, - [8146] = { "ARE YOU PREPARED TO FACE YOUR DESTINY?" }, - [8149] = { - "Weirdo, you're a weirdo! Actually all of you are!", - "Pie for breakfast, pie for lunch and pie for dinner!", - "All hail the control panel!", - "I own, Tibiacity owns, perfect match!", - "Hug me! Feed me! Hail me!", - }, - [8153] = { - "It's news to me.", - "News, updated as infrequently as possible!", - "Extra! Extra! Read all about it!", - "Fresh off the press!", - }, - [8154] = { - "Hail TibiaNordic!", - "So cold..", - "Run, mammoth!", - }, - [21435] = { - "I can hear their whisperings... Revenge!", - "You shall feel pain and terror, |PLAYERNAME|", - "I do not need a sword to slaughter you", - "My sword is broken, but my spirit is not dead", - "I can say 469 and more...", - "My dark magic lies on tibialatina.wikia.com", - }, - [21962] = { "Hail Tibia Brasileiros! (União&Força)" }, - [32918] = { - "COME HERE! FREE ITEMS FOR EVERYONE!", - "DON'T BE AFRAID! I AM COMING IN PEACE!", - "BOW TO THE POWER OF THE RUTHLESS SEVEN!", - "Slay your friends and I will spare you!", - }, -} - -local doll = Action() - -function doll.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local sounds = dolls[item.itemid] - if not sounds then - return false - end - - if fromPosition.x == CONTAINER_POSITION then - fromPosition = player:getPosition() - end - - local random = math.random(#sounds) - local sound = sounds[random] - if item.itemid == 6566 then - if random == 3 then - fromPosition:sendMagicEffect(CONST_ME_POFF) - elseif random == 4 then - fromPosition:sendMagicEffect(CONST_ME_FIREAREA) - elseif random == 5 then - doTargetCombatHealth(0, player, COMBAT_PHYSICALDAMAGE, -1, -1, CONST_ME_EXPLOSIONHIT) - end - elseif item.itemid == 5668 then - fromPosition:sendMagicEffect(CONST_ME_MAGIC_RED) - item:transform(item.itemid + 1) - item:decay() - elseif item.itemid == 6387 then - fromPosition:sendMagicEffect(CONST_ME_SOUND_YELLOW) - end - - sound = sound:gsub("|PLAYERNAME|", player:getName()) - player:say(sound, TALKTYPE_MONSTER_SAY, false, 0, fromPosition) - return true -end - -for index, value in pairs(dolls) do - doll:id(index) -end - -doll:register() diff --git a/data-otservbr-global/scripts/actions/other/surprise_bag.lua b/data-otservbr-global/scripts/actions/other/surprise_bag.lua deleted file mode 100644 index 052fc987c61..00000000000 --- a/data-otservbr-global/scripts/actions/other/surprise_bag.lua +++ /dev/null @@ -1,103 +0,0 @@ -local config = { - [6570] = { -- bluePresent - { 3598, 10 }, - { 6393, 3 }, - 6279, - 6574, - 6578, - 6575, - 6577, - 6569, - 6576, - 6572, - 2995, - 14027, - 14681, - }, - [6571] = { -- redPresent - 6574, - 3079, - 6393, - 6576, - 6578, - 2995, - 14027, - 3036, - 5944, - 3386, - 3420, - 3039, - 5080, - 2993, - 3392, - 3057, - 5791, - }, - [8853] = { -- surpriseBag - { 3031, 10 }, - 123, - 2995, - 2397, - 651, - 3218, - 6574, - 6393, - 7377, - 3578, - 8778, - }, - [14751] = { -- surpriseBag - { 9642, 15 }, - { 3581, 15 }, - 5917, - 3273, - 10302, - 9019, - 5928, - 5926, - 5927, - 6095, - 5918, - 6097, - 6098, - 5461, - 5090, - }, - [14759] = { -- surpriseBag - { 6569, 10 }, - { 6541, 10 }, - { 6542, 10 }, - { 6543, 10 }, - { 6544, 10 }, - { 6545, 10 }, - 6574, - 4839, - 6570, - 6571, - 3215, - }, -} - -local surpriseBag = Action() - -function surpriseBag.onUse(cid, item, fromPosition, itemEx, toPosition) - local present = config[item.itemid] - if not present then - return false - end - - local count = 1 - local gift = present[math.random(1, #present)] - if type(gift) == "table" then - count = math.random(1, gift[2]) - gift = gift[1] - end - - Player(cid):addItem(gift, count) - Item(item.uid):remove(1) - fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS) - return true -end - -surpriseBag:id(6570, 6571, 8853, 14751, 14759) -surpriseBag:register() diff --git a/data-otservbr-global/scripts/actions/other/surprise_box.lua b/data-otservbr-global/scripts/actions/other/surprise_box.lua deleted file mode 100644 index 94fdb95eb2d..00000000000 --- a/data-otservbr-global/scripts/actions/other/surprise_box.lua +++ /dev/null @@ -1,31 +0,0 @@ -local prize = { - [1] = { chance = 1, id = 3246, amount = 1 }, - [2] = { chance = 2, id = 10227, amount = 1 }, - [3] = { chance = 3, id = 11588, amount = 1 }, - [4] = { chance = 4, id = 3549, amount = 1 }, - [5] = { chance = 5, id = 3420, amount = 1 }, - [6] = { chance = 10, id = ITEM_CRYSTAL_COIN, amount = 17 }, - [7] = { chance = 20, id = ITEM_GOLD_COIN, amount = 1 }, - [8] = { chance = 30, id = ITEM_CRYSTAL_COIN, amount = 1 }, - [9] = { chance = 40, id = ITEM_GOLD_COIN, amount = 50 }, - [10] = { chance = 50, id = ITEM_PLATINUM_COIN, amount = 15 }, - [11] = { chance = 90, id = ITEM_GOLD_COIN, amount = 80 }, -} - -local surpriseBox = Action() - -function surpriseBox.onUse(player, item, fromPosition, target, toPosition, isHotkey) - for i = 1, #prize do - local number = math.random() * 100 - if prize[i].chance > 100 - number then - player:getPosition():sendMagicEffect(CONST_ME_POFF) - player:addItem(prize[i].id, prize[i].amount) - item:remove() - break - end - end - return true -end - -surpriseBox:id(12045) -surpriseBox:register() diff --git a/data-otservbr-global/scripts/actions/other/teleport.lua b/data-otservbr-global/scripts/actions/other/teleport.lua deleted file mode 100644 index 7e763f00594..00000000000 --- a/data-otservbr-global/scripts/actions/other/teleport.lua +++ /dev/null @@ -1,19 +0,0 @@ -local ladderTable = Game.getLadderIds() - -local upFloorIds = ladderTable - -local teleport = Action() - -function teleport.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if table.contains(upFloorIds, item.itemid) then - fromPosition:moveUpstairs() - else - fromPosition.z = fromPosition.z + 1 - end - player:teleportTo(fromPosition, false) - return true -end - -teleport:id(435) -teleport:id(unpack(ladderTable)) -teleport:register() diff --git a/data-otservbr-global/scripts/actions/other/transform_to.lua b/data-otservbr-global/scripts/actions/other/transform_to.lua deleted file mode 100644 index 5257544eb60..00000000000 --- a/data-otservbr-global/scripts/actions/other/transform_to.lua +++ /dev/null @@ -1,484 +0,0 @@ -local voices = { - [23708] = "Au au!", - [23443] = "Grooaarr!", -} - -local transformItems = { - [2062] = 2063, - [2063] = 2062, -- sacred statue - [2064] = 2065, - [2065] = 2064, -- sacred statue - [2108] = 2109, - [2109] = 2108, -- street lamp - [2334] = 2335, - [2335] = 2334, -- table - [2336] = 2337, - [2337] = 2336, -- table - [2338] = 2339, - [2339] = 2338, -- table - [2340] = 2341, - [2341] = 2340, -- table - [2535] = 2536, - [2536] = 2535, -- oven - [2537] = 2538, - [2538] = 2537, -- oven - [2539] = 2540, - [2540] = 2539, -- oven - [2541] = 2542, - [2542] = 2541, -- oven - [2660] = 2661, - [2661] = 2660, -- cuckoo clock - [2662] = 2663, - [2663] = 2662, -- cuckoo clock - [2772] = 2773, - [2773] = 2772, -- lever - [2911] = 2912, - [2912] = 2911, -- candelabrum - [2914] = 2915, - [2915] = 2914, -- lamp - [2917] = 2918, - [2918] = 2917, -- candlestick - [2920] = 2921, - [2921] = 2920, -- torch - [2922] = 2923, - [2923] = 2922, -- torch - [2924] = 2925, - [2925] = 2924, -- torch - [2928] = 2929, - [2929] = 2928, -- torch bearer - [2930] = 2931, - [2931] = 2930, -- torch bearer - [2934] = 2935, - [2935] = 2934, -- table lamp - [2977] = 2978, - [2978] = 2977, -- pumpkinhead - [3046] = 3047, - [3047] = 3046, -- magic light wand - [3481] = 3482, -- closed trap - [5812] = 5813, - [5813] = 5812, -- skull candle - [6488] = 6489, - [6489] = 6488, -- christmas branch - [7058] = 7059, - [7059] = 7058, -- skull pillar - [7856] = 7857, - [7857] = 7856, -- chimney - [7858] = 7859, - [7859] = 7858, -- chimney - [7860] = 7861, - [7861] = 7860, -- chimney - [7862] = 7863, - [7863] = 7862, -- chimney - [8659] = 8660, - [8660] = 8659, -- street lamp - [8661] = 8662, - [8662] = 8661, -- street lamp - [8663] = 8664, - [8664] = 8663, -- street lamp - [8665] = 8666, - [8666] = 8665, -- street lamp - [8832] = 8833, - [8833] = 8832, -- wall lamp - [8834] = 8835, - [8835] = 8834, -- wall lamp - [17411] = 17412, - [17412] = 17411, -- street lamp - [20280] = 20281, - [20281] = 20280, -- beacon - [20498] = 20497, - [20497] = 20498, -- street lamp - [20500] = 20499, - [20499] = 20500, -- street lamp - [20501] = 20502, - [20502] = 20501, -- candle - [20503] = 20504, - [20504] = 20503, -- candle - [22153] = 22154, - [22154] = 22153, -- skull - [22764] = 22765, - [22765] = 22764, -- ferumbras staff - [23434] = 23436, - [23436] = 23434, -- predador lamp - [23435] = 23437, - [23437] = 23435, -- predador lamp - [23438] = 23440, - [23440] = 23438, -- protectress lamp - [23439] = 23441, - [23441] = 23439, -- protectress lamp - [23442] = 23443, - [23443] = 23442, -- baby dragon - [23444] = 23445, - [23445] = 23444, -- hamster wheel - [23451] = 23452, - [23452] = 23451, -- cat in a basket - [23485] = 23486, - [23486] = 23485, -- barrel - [23708] = 23709, - [23709] = 23708, -- dog house - [24432] = 24433, - [24433] = 24432, -- parrot - [24434] = 24436, - [24435] = 24434, -- skull lamp - [25212] = 25210, - [25211] = 25212, -- vengothic lamp - [26078] = 26079, -- spider terrarium - [26081] = 26083, - [26083] = 26081, -- hrodmiran weapons rack - [26084] = 26082, - [26082] = 26084, -- hrodmiran weapons rack side - [26171] = 26169, - [26172] = 26170, -- snake terrarium - [26173] = 26175, - [26174] = 26176, -- demon pet - [27667] = 27668, -- light of change empty to red - [27668] = 27669, -- light of change red to green - [27669] = 27670, -- light of change green to blue - [27670] = 27667, -- light of change blue to empty - [27671] = 27673, -- torch of change empty to red - [27673] = 27674, -- torch of change red to green - [27674] = 27675, -- torch of change green to blue - [27675] = 27671, -- torch of change blue to empty - [27683] = 27685, - [27684] = 27686, -- alchemistic scales - [27687] = 27688, - [27688] = 27687, -- pile of alchemistic books - [27691] = 27692, - [27692] = 27691, -- ferumbras bust - [27693] = 27694, - [27694] = 27693, -- ferumbras bust - [27986] = 27988, - [27988] = 27986, -- bonelord statue - [27987] = 27989, - [27989] = 27987, -- bonelord statue - [27996] = 27998, - [27998] = 27996, -- scholar bust - [27997] = 27999, - [27999] = 27997, -- scholar bust - [28000] = 28002, - [28002] = 28000, -- scholar bust - [28001] = 28003, - [28003] = 28001, -- scholar bust - [28674] = 28675, - [28675] = 28674, -- anglerfish lamp - [28690] = 28691, - [28692] = 28693, -- baby rotworm - [28694] = 28695, --fennec - [28915] = 28916, - [28917] = 28918, -- adamant shield - [28920] = 28921, - [28921] = 28920, -- fluorescent fungi - [28922] = 28923, - [28923] = 28922, -- luminescent fungi - [28924] = 28925, - [28925] = 28924, -- glowing sulphur fungi - [28926] = 28927, - [28927] = 28926, -- gloomy poisonous fungi - [30229] = 30230, - [30230] = 30231, -- festive table - [30231] = 30229, -- festive table - [30233] = 30234, - [30234] = 30233, -- festive fireplace - [30235] = 30236, - [30236] = 30235, -- festive fireplace - [30237] = 30238, - [30238] = 30237, -- festive tree - [30248] = 30249, - [30249] = 30248, -- festive pyramid - [30362] = 30365, -- Badbara - [30363] = 30366, -- Tearesa - [30364] = 30367, -- Cryana - [31196] = 31197, - [31197] = 31196, -- crystal lamp - [31213] = 31215, - [31215] = 31213, -- idol lamp - [31214] = 31216, - [31216] = 31214, -- idol lamp side - [31462] = 31463, - [31464] = 31465, -- jousting eagle baby - [31674] = 31675, -- omniscient owl - [31681] = 31682, -- hedgehog - [31683] = 31684, - [31684] = 31683, -- exalted sarcophagus - [31695] = 31696, - [31696] = 31695, -- curly hortensis lamp - [31697] = 31698, - [31698] = 31697, -- little big flower lamp - [31703] = 31704, -- baby unicorn - [32760] = 32758, - [32761] = 32759, -- mini NaBbot - [32784] = 32785, - [32785] = 32784, -- ice chandelier - [32788] = 32789, -- baby seal - [32790] = 32791, - [32792] = 32793, -- baby polar bear - [32897] = 32899, - [32899] = 32897, -- wall lamp - [32900] = 32901, - [32901] = 32900, -- torch bearer - [32902] = 32903, - [32903] = 32902, -- bamboo wall lamp - [32904] = 32905, - [32905] = 32904, -- wall candle - [32907] = 32910, -- guzzlemaw grub - [32908] = 32911, -- baby vulcongra - [32909] = 32912, -- baby brain squid - [33026] = 33047, - [33027] = 33026, -- heart lamp - [33028] = 33048, - [33029] = 33028, -- heart lamp (flower) - [33030] = 33049, - [33031] = 33030, -- heart lamp (small flower) - [33040] = 33042, -- bat - [33331] = 33332, - [33333] = 33334, -- bard doll - [34026] = 34027, -- baby bonelord - [34030] = 34031, - [34031] = 34030, -- artist shelf - [34032] = 34033, - [34033] = 34032, -- artist shelf - [34034] = 34035, - [34035] = 34034, -- artist table - [34044] = 34045, - [34045] = 34044, -- sculptor shelf - [34046] = 34047, - [34047] = 34046, -- sculptor shelf - [34048] = 34049, - [34049] = 34048, -- sculptor table - [34064] = 34065, - [34065] = 34066, -- sculpture of a noblewoman - [34066] = 34067, - [34067] = 34064, -- sculpture of a noblewoman - [34068] = 34069, - [34069] = 34070, -- sculpture of a noblewoman - [34070] = 34071, - [34071] = 34068, -- sculpture of a noblewoman - [34264] = 34265, - [34266] = 34267, -- Tibiapedia - [34268] = 34269, - [34269] = 34268, -- Baby Munster - [34270] = 34271, - [34271] = 34270, -- glowworms - [34272] = 34273, - [34273] = 34272, -- oven - [34274] = 34275, - [34275] = 34274, -- oven - [34284] = 34285, - [34285] = 34284, -- kitchen table (empty) - [34287] = 34288, - [34288] = 34287, -- kitchen table (empty) - [34286] = 34290, - [34290] = 34286, -- kitchen table - [34289] = 34291, - [34291] = 34289, -- kitchen table - [34300] = 34301, - [34301] = 34300, -- barrel - [34304] = 34305, - [34305] = 34304, -- kitchen lamp - [34326] = 34327, -- wicked witch - [35153] = 35154, -- baby elephant - [35155] = 35157, - [35157] = 35159, -- forge - [35159] = 35155, - [35156] = 35158, -- forge - [35158] = 35160, - [35160] = 35156, -- forge - [35161] = 35162, - [35162] = 35161, -- metal wall lamp - [35163] = 35165, - [35165] = 35163, -- workbench - [35164] = 35166, - [35166] = 35164, -- workbench - [35177] = 35180, - [35180] = 35177, -- grinding wheel - [35178] = 35179, - [35179] = 35178, -- grinding wheel - [35181] = 35183, - [35183] = 35181, -- pair of bellows - [35182] = 35184, - [35184] = 35182, -- pair of bellows - [35185] = 35186, - [35186] = 35185, -- anvil - [35187] = 35188, - [35188] = 35187, -- water bucket - [35909] = 35910, -- chaos critical dice - [36019] = 36020, -- white lion doll - [36478] = 36479, - [36480] = 36481, -- banor doll - [36618] = 36619, - [36619] = 36618, -- volcanic basin - [36620] = 36621, - [36621] = 36620, -- volcanic sphere - [36622] = 36623, - [36623] = 36622, -- volcanic spire - [36624] = 36625, - [36625] = 36624, -- volcanic bulb - [36626] = 36628, - [36628] = 36626, -- volcanic mirror - [36627] = 36629, - [36629] = 36627, -- volcanic mirror - [36638] = 36639, - [36639] = 36638, -- volcanic table - [36640] = 36642, - [36642] = 36644, -- volcanic shelf - [36644] = 36640, - [36641] = 36643, -- volcanic shelf - [36643] = 36645, - [36645] = 36641, -- volcanic shelf - [36646] = 36649, - [36647] = 36650, -- demon baller - [36648] = 36651, - [36653] = 36652, -- demon baller - [36654] = 36646, -- demon baller - [36750] = 36751, - [36754] = 36752, -- falcon pet - [36756] = 36753, -- falcon pet - [36959] = 36960, -- megasylvan plant - [36978] = 36979, - [36979] = 36978, -- magic hat - [36996] = 36997, - [36998] = 36999, -- Luna - [37015] = 37016, - [37016] = 37015, -- yellow shroom lamp - [37017] = 37018, - [37018] = 37017, -- pink shroom lamp - [37021] = 37022, -- dragon plant - [37052] = 37053, - [37053] = 37052, -- bonelord tome - [37054] = 37055, - [37056] = 37057, -- Bella Bonecrusher's doll - [37061] = 37062, - [37063] = 37064, -- Evora - [37111] = 37112, - [37113] = 37114, -- armillary sphere - [37185] = 37186, - [37186] = 37700, -- kraken watcher lamp - [37700] = 37185, -- kraken watcher lamp - [37187] = 37519, - [37519] = 37187, -- kraken buoy lamp - [37188] = 37520, - [37520] = 37188, -- kraken tentacle lamp - [37189] = 37191, - [37191] = 37189, -- kraken shelf - [37190] = 37192, - [37192] = 37190, -- kraken shelf - [37205] = 37206, - [37206] = 37207, -- sculpture of an octoputz - [37207] = 37205, - [37208] = 37209, -- sculpture of an octoputz - [37209] = 37210, - [37210] = 37208, -- sculpture of an octoputz - [37211] = 37212, - [37212] = 37211, -- octoputz - [37543] = 37580, - [37580] = 37543, -- string of fairy lights RYG - [37544] = 37581, - [37581] = 37544, -- string of fairy lights BRG - [37545] = 37582, - [37582] = 37545, -- string of fairy lights BGY - [37557] = 37558, - [37559] = 37560, -- dragon pinata - [37743] = 37744, - [37745] = 37746, -- draptor doll - [37749] = 37750, - [37750] = 37749, -- dark oracle - [37806] = 37807, - [37807] = 37806, -- zaoan wall lamp - [37808] = 37809, - [37809] = 37808, -- zaoan wall lamps - [37811] = 37813, - [37812] = 37814, -- sculpture of a fox - [38522] = 38524, - [38524] = 38522, -- naga lamp - [38523] = 38525, - [38525] = 38523, -- naga lamp - [38526] = 38528, - [38528] = 38526, -- basin with a glowing flower - [38677] = 38680, - [38704] = 38705, -- beaver of wisdom - [38827] = 38828, - [38828] = 38827, -- wall lamp - [39423] = 39425, - [39425] = 39423, -- knightly table - [39424] = 39426, - [39426] = 39424, -- knightly table - [39427] = 39428, - [39428] = 39427, -- knightly chess table - [39443] = 39444, - [39444] = 39445, -- knightly fire bowl - [39445] = 39443, -- knightly fire bowl - [39498] = 39499, - [39499] = 39498, -- knightly candelabra - [39500] = 39501, - [39501] = 39500, -- knightly candle holder - [39508] = 39509, - [39668] = 39510, -- knightly guard - [39694] = 39696, -- lucky dragon - [39697] = 39698, - [39698] = 39697, -- rainbow torch - [39699] = 39700, - [39700] = 39699, -- rainbow torch - [39701] = 39702, - [39702] = 39701, -- rainbow torch - [39757] = 39758, -- yeti doll - [39759] = 39760, - [39761] = 39762, -- the gods' twilight doll - [39772] = 39773, - [39773] = 39774, -- flower table - [39774] = 39772, -- flower table - [39793] = 39794, - [39794] = 39793, -- turquoise flower lamp - [39795] = 39796, - [39796] = 39795, -- purple flower lamp - [39801] = 39802, - [39802] = 39801, -- wall leaves - [39803] = 39804, - [39804] = 39803, -- tendrils - [39805] = 39806, - [39807] = 39808, -- water nymph - [39810] = 39809, -- water nymph - [42271] = 42272, - [42272] = 42271, -- seafarer table - [42291] = 42292, - [42292] = 42291, -- seashell lamp - [42293] = 42294, - [42294] = 42293, -- seashell lamp - [42295] = 42296, - [42296] = 42295, -- tentacle lamp - [42297] = 42298, - [42298] = 42297, -- tentacle lamp - [42299] = 42300, - [42300] = 42299, -- sea-devil wall lamp - [42301] = 42302, - [42302] = 42301, -- seafood bucket - [42324] = 42326, - [42326] = 42324, -- opulent table - [42325] = 42327, - [42327] = 42325, -- opulent table - [42346] = 42347, - [42347] = 42346, -- opulent floor lamp - [42348] = 42349, - [42349] = 42348, -- opulent floor lamp - [42363] = 42364, -- djinn lamp - [42365] = 42366, -- djinn lamp -} - -local transformTo = Action() - -function transformTo.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if voices[item:getId()] then - local spectators = Game.getSpectators(fromPosition, false, true, 3, 3) - for i = 1, #spectators do - player:say(voices[item:getId()], TALKTYPE_MONSTER_SAY, false, spectators[i], fromPosition) - end - end - - item:transform(transformItems[item.itemid]) - item:decay() - return true -end - -for index, value in pairs(transformItems) do - transformTo:id(index) -end - -transformTo:register() diff --git a/data-otservbr-global/scripts/actions/other/vessels.lua b/data-otservbr-global/scripts/actions/other/vessels.lua deleted file mode 100644 index b1f0701becb..00000000000 --- a/data-otservbr-global/scripts/actions/other/vessels.lua +++ /dev/null @@ -1,30 +0,0 @@ -local config = { - [37572] = CONST_ME_GAZHARAGOTH, -- vessel of Gaz'haragoth - [37573] = CONST_ME_FERUMBRAS_1, -- vessel of Ferumbras - [37574] = CONST_ME_MAD_MAGE, -- vessel of the Mad Mage - [37575] = CONST_ME_HORESTIS, -- vessel of Horestis - [37576] = CONST_ME_DEVOVORGA, -- vessel of Devovorga -} - -local vessels = Action() - -function vessels.onUse(player, item, fromPosition, itemEx, toPosition) - local vessel = config[item.itemid] - local tile = toPosition:getTile() - if not vessel or not player then - return false - end - if not tile:isWalkable() then - player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM) - else - item:remove(1) - toPosition:sendMagicEffect(vessel) - end - return true -end - -for index, value in pairs(config) do - vessels:id(index) -end -vessels:allowFarUse(true) -vessels:register() 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-otservbr-global/scripts/creaturescripts/customs/freequests.lua b/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua index 1cbca17c563..bfeac7acad0 100644 --- a/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua +++ b/data-otservbr-global/scripts/creaturescripts/customs/freequests.lua @@ -1,392 +1,354 @@ local stage = configManager.getNumber(configKeys.FREE_QUEST_STAGE) local questTable = { - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 2 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 4 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 7 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 9 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 12 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.Shooting, storageValue = 5 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 16 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 20 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 23 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.QuestLineComplete, storageValue = 2 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.Rank, storageValue = 1440 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.Warzone1Access, storageValue = 2 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.Warzone2Access, storageValue = 2 }, - { storage = Storage.Quest.U9_60.BigfootsBurden.Warzone3Access, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Questline, storageValue = 10 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneVI, storageValue = 10 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneV, storageValue = 10 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneIV, storageValue = 30 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Points, storageValue = 10 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Points, storageValue = 10 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Points, storageValue = 10 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Questline, storageValue = 51 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission01, storageValue = 6 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission02, storageValue = 8 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission03, storageValue = 6 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission04, storageValue = 6 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission05, storageValue = 8 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission06, storageValue = 5 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission07, storageValue = 5 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission08, storageValue = 4 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission09, storageValue = 2 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission10, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe01, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe02, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe03, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe04, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedDan, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedBill, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedFred, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.AlchemistFormula, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.BadSide, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.GoodSide, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.MrWestDoor, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.MrWestStatus, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.TamerinStatus, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.MorikSummon, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraState, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraSplasher, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraSharptooth, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraInky, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.MatrixState, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.NotesPalimuth, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.NotesAzerus, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToAzerus, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToBog, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToLastFight, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToMatrix, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToQuara, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Questline, storageValue = 7 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.JamesfrancisTask, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.BossTimer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone1, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone2, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone3, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Answer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.MotA.QuestionId, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.sulphur, storageValue = 4 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Tar, storageValue = 3 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Ice, storageValue = 3 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Objects, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Temp, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.LookType, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.BossTimer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Life.Mission, storageValue = 7 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Life.BossTimer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Vaporized, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Decaying, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Humans.BossTimer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Mission, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Monsters, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Exorcisms, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Time, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.BossTimer, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.EntranceAccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.AccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 1 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 4 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 7 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 16 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 26 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 29 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 32 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 35 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 38 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 41 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 43 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 46 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 47 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 50 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 55 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 56 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 58 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 61 }, - { storage = Storage.Quest.U7_6.ExplorerSociety.CalassaQuest, storageValue = 2 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.Tomes, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.LastLoreKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.TimeGuardianKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.HorrorKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.DragonkingKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.ThornKnightKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.LloydKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.LadyTenebrisKilled, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessMachine, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessLavaTeleport, storageValue = 1 }, - { storage = Storage.Quest.U8_0.BarbarianTest.Questline, storageValue = 8 }, - { storage = Storage.Quest.U8_0.BarbarianTest.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U8_0.BarbarianTest.Mission02, storageValue = 3 }, - { storage = Storage.Quest.U8_0.BarbarianTest.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Questline, storageValue = 21 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission00, storageValue = 2 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission02, storageValue = 5 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission04, storageValue = 6 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission05, storageValue = 3 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding01, storageValue = 1 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding02, storageValue = 1 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding03, storageValue = 1 }, - { storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.StrangeSymbols, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.Faction.Greeting, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.Faction.MaridDoor, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.Faction.EfreetDoor, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Start, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission02, storageValue = 3 }, - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Start, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission01, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission02, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.RataMari, storageValue = 2 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.TheWayToYalahar, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.TownsCounter, storageValue = 5 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.AbDendriel, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Darashia, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Venore, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Ankrahmun, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.PortHope, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Thais, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.LibertyBay, storageValue = 1 }, - { storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Carlin, storageValue = 1 }, - { storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.DefaultStart, storageValue = 1 }, - { storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.GoingDown, storageValue = 1 }, - { storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.WayToBeregar, storageValue = 1 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Questline, storageValue = 40 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission02, storageValue = 5 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission04, storageValue = 2 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission05, storageValue = 6 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission06, storageValue = 8 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission07, storageValue = 3 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission08, storageValue = 4 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission09, storageValue = 2 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission10, storageValue = 2 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission11, storageValue = 2 }, - { storage = Storage.Quest.U8_0.TheIceIslands.Mission12, storageValue = 6 }, - { storage = Storage.Quest.U8_0.TheIceIslands.yakchalDoor, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Questline, storageValue = 25 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission01, storageValue = 7 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission02, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission03, storageValue = 6 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission04, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission05, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission06, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission07, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.GrofGuard, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.KulagGuard, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.TimGuard, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.WalterGuard, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheInquisitionQuest.StorkusVampiredust, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Questline, storageValue = 29 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission02[1], storageValue = 4 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission04, storageValue = 2 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05[1], storageValue = 2 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission06, storageValue = 5 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission07[1], storageValue = 2 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission08, storageValue = 2 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission09[1], storageValue = 3 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission10[1], storageValue = 2 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission10.MagicCarpetDoor, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.TomeofKnowledge, storageValue = 12 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver1, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver2, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver3, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.KingTibianus, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Leeland, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Angus, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Wyrdin, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Telas, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Humgolf, storageValue = 1 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.DefaultStart, storageValue = 3 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.TheGovernorDaughter, storageValue = 3 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.TheErrand, storageValue = 2 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToMeriana, storageValue = 1 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.APoemForTheMermaid, storageValue = 3 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.ADjinnInLove, storageValue = 5 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToLagunaIsland, storageValue = 1 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToGoroma, storageValue = 1 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.Shipwrecked, storageValue = 2 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.DragahsSpellbook, storageValue = 1 }, - { storage = Storage.Quest.U7_8.TheShatteredIsles.TheCounterspell, storageValue = 4 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Questline, storageValue = 1 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission01, storageValue = 2 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission02, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission04, storageValue = 8 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission05, storageValue = 2 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission06, storageValue = 4 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission07, storageValue = 2 }, - { storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission08, storageValue = 1 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission01, storageValue = 1 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission01, storageValue = 2 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission02, storageValue = 5 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission04, storageValue = 3 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission05, storageValue = 3 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission06, storageValue = 2 }, - { storage = Storage.Quest.U8_1.TheTravellingTrader.Mission07, storageValue = 1 }, - { storage = Storage.Quest.U8_0.BarbarianArena.QuestLogGreenhorn, storageValue = 1 }, - { storage = Storage.Quest.U8_1.TibiaTales.DefaultStart, storageValue = 1 }, - { storage = Storage.Quest.U8_1.TibiaTales.ToAppeaseTheMightyQuest, storageValue = 1 }, - { storage = 12450, storageValue = 6 }, - { storage = 12330, storageValue = 1 }, - { storage = 12332, storageValue = 13 }, - { storage = 12333, storageValue = 3 }, - { storage = Storage.Quest.U7_8.FriendsAndTraders.DefaultStart, storageValue = 1 }, - { storage = Storage.Quest.U7_8.FriendsAndTraders.TheSweatyCyclops, storageValue = 2 }, - { storage = Storage.Quest.U7_8.FriendsAndTraders.TheMermaidMarina, storageValue = 2 }, - { storage = Storage.Quest.U7_8.FriendsAndTraders.TheBlessedStake, storageValue = 12 }, - { storage = 100157, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Questline, storageValue = 29 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission01, storageValue = 3 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission02, storageValue = 3 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission03, storageValue = 3 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission04, storageValue = 3 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission05, storageValue = 3 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission06, storageValue = 4 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission07, storageValue = 6 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission08, storageValue = 2 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission09, storageValue = 2 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission10, storageValue = 1 }, - { storage = Storage.Quest.U7_6.TheApeCity.Started, storageValue = 1 }, - { storage = Storage.Quest.U7_6.TheApeCity.Questline, storageValue = 18 }, - { storage = Storage.BanutaSecretTunnel.DeeperBanutaShortcut, storageValue = 1 }, - { storage = Storage.Quest.U10_50.OramondQuest.QuestLine, storageValue = 1 }, - { storage = Storage.Quest.U10_50.OramondQuest.ToTakeRoots.Mission, storageValue = 3000 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Questline, storageValue = 1 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Home, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Subterranean, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Measurements, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Ordnance, storageValue = 3 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Charting, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Growth, storageValue = 2 }, - { storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Diremaw, storageValue = 2 }, - { storage = Storage.Quest.U11_40.ThreatenedDreams.QuestLine, storageValue = 1 }, - { storage = Storage.Quest.U11_40.ThreatenedDreams.Mission01[1], storageValue = 16 }, - { storage = Storage.Quest.U11_40.ThreatenedDreams.Mission02.KroazurAccess, storageValue = 1 }, - { storage = Storage.Quest.U9_80.AdventurersGuild.QuestLine, storageValue = 1 }, - { storage = Storage.Quest.U10_80.TheGreatDragonHunt.WarriorSkeleton, storageValue = 1 }, - { storage = Storage.Quest.U10_80.TheGreatDragonHunt.WarriorSkeleton, storageValue = 2 }, - { storage = Storage.Quest.U10_80.TheLostBrotherQuest, storageValue = 3 }, - { storage = Storage.Quest.U10_55.Dawnport.Questline, storageValue = 1 }, - { storage = Storage.Quest.U10_55.Dawnport.GoMain, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessDeath, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessViolet, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessEarth, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessFire, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessIce, storageValue = 1 }, - { storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessGolden, storageValue = 1 }, - { storage = Storage.Quest.U10_80.GrimvaleQuest.AncientFeudDoors, storageValue = 1 }, - { storage = Storage.Quest.U10_80.GrimvaleQuest.AncientFeudShortcut, storageValue = 1 }, - { storage = Storage.Kilmaresh.AccessDoor, storageValue = 1 }, - { storage = Storage.Kilmaresh.CatacombDoors, storageValue = 1 }, - { storage = Storage.Quest.U12_00.TheDreamCourts.AccessDoors, storageValue = 1 }, - { storage = Storage.Quest.U12_00.TheDreamCourts.HauntedHouseAccess, storageValue = 1 }, - { storage = Storage.Quest.U12_00.TheDreamCourts.BuriedCathedralAccess, storageValue = 1 }, - { storage = Storage.Quest.U12_00.TheDreamCourts.DreamScarAccess, storageValue = 1 }, - { storage = Storage.Quest.U12_40.TheOrderOfTheLion.AccessEastSide, storageValue = 1 }, - { storage = Storage.Quest.U12_40.TheOrderOfTheLion.AccessSouthernSide, storageValue = 1 }, - { storage = Storage.Quest.U12_60.APiratesTail.TentuglyDoor, storageValue = 1 }, - { storage = Storage.Quest.U12_60.APiratesTail.RascacoonShortcut, storageValue = 1 }, - { storage = Storage.Quest.U12_70.AdventuresOfGalthen.AccessDoor, storageValue = 1 }, - - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.AccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.TrialAccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.TarAccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.BossAccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Life.AccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.AccessDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_40.CultsOfTibia.FinalBoss.AccessDoor, storageValue = 1 }, - - { storage = Storage.Quest.U10_90.FerumbrasAscension.FirstDoor, storageValue = 1 }, - { storage = Storage.Quest.U10_90.FerumbrasAscension.MonsterDoor, storageValue = 1 }, - { storage = Storage.Quest.U10_90.FerumbrasAscension.TarbazDoor, storageValue = 1 }, - { storage = Storage.Quest.U10_90.FerumbrasAscension.HabitatsAccess, storageValue = 1 }, - { storage = Storage.Quest.U10_90.FerumbrasAscension.TheLordOfTheLiceAccess, storageValue = 1 }, - { storage = Storage.Quest.U10_90.FerumbrasAscension.Statue, storageValue = 1 }, - - { storage = Storage.Quest.U12_00.TheDreamCourts.AndrewDoor, storageValue = 1 }, - - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.AwarnessEmperor, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.BossRoom, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.InnerSanctum, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Rebel, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.SleepingDragon, storageValue = 2 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Wote10, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Zizzle, storageValue = 1 }, - { storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Zlak, storageValue = 1 }, - - --[[ { storage = Storage.Quest.U11_80.TheSecretLibrary.FalconBastionAccess, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.LowerBastionAccess, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.UndergroundBastionAccess, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.ShortcutToBastion, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.OberonAccess, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MotaDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.BasinDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.SkullDoor, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.Mota, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MiniBosses.PreceptorLazare, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MiniBosses.GrandCanonDominus, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MiniBosses.GrandChaplainGaunder, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MiniBosses.GrandCommanderSoeren, storageValue = 1 }, - { storage = Storage.Quest.U11_80.TheSecretLibrary.MiniBosses.DazedLeafGolem, storageValue = 1 }, ]] - - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.DoorToLamp, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.DoorToMaridTerritory, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.DoorToLamp, storageValue = 1 }, - { storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.DoorToEfreetTerritory, storageValue = 1 }, - - { storage = Storage.Quest.U12_20.GraveDanger.QuestLine, storageValue = 14 }, - { storage = Storage.Quest.U12_20.GraveDanger.Bosses.KingZelosDoor, storageValue = 1 }, - - { storage = Storage.Quest.U13_10.CradleOfMonsters.Access.Ingol, storageValue = 1 }, - { storage = Storage.Quest.U13_10.CradleOfMonsters.Access.LowerIngol, storageValue = 1 }, - { storage = Storage.Quest.U13_10.CradleOfMonsters.Access.Monster, storageValue = 1 }, - { storage = Storage.Quest.U13_10.CradleOfMonsters.Access.MutatedAbomination, storageValue = 1 }, - { storage = Storage.Quest.U8_54.TheNewFrontier.SnakeHeadTeleport, storageValue = 1 }, - { storage = Storage.Quest.U9_4.LiquidBlackQuest.Visitor, storageValue = 5 }, - { storage = Storage.Quest.U8_4.BloodBrothers.VengothAccess, storageValue = 1 }, - - -- Assassin Outfit quests - { storage = Storage.Quest.U8_5.KillingInTheNameOf.BudrikMinos, storageValue = 0 }, - { storage = Storage.Quest.U8_1.ToOutfoxAFoxQuest.Questline, storageValue = 2 }, - - -- Hunter Outfit quests - { storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet01, storageValue = 1 }, - { storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet02, storageValue = 1 }, - { storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet03, storageValue = 1 }, - { storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet04, storageValue = 1 }, - - -- Norseman - { storage = Storage.Quest.U8_0.TheIceIslands.NorsemanOutfit, storageValue = 1 }, - { storage = Storage.OutfitQuest.DefaultStart, storageValue = 1 }, - - { storage = Storage.HeroRathleton.AccessDoor, storageValue = 1 }, - { storage = Storage.HeroRathleton.AccessTeleport1, storageValue = 1 }, - { storage = Storage.HeroRathleton.AccessTeleport2, storageValue = 1 }, - { storage = Storage.HeroRathleton.AccessTeleport3, storageValue = 1 }, - - -- Sea Serpent Quest - { storage = Storage.Quest.U8_2.TheHuntForTheSeaSerpent.FishForASerpent, storageValue = 5 }, - { storage = Storage.Quest.U8_2.TheHuntForTheSeaSerpent.QuestLine, storageValue = 2 }, - - --The White Raven Monastery - { storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.QuestLog, storageValue = 1 }, - { storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Passage, storageValue = 1 }, - { storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Diary, storageValue = 2 }, - { storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Door, storageValue = 1 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 2 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 4 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 7 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 9 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 12 }, + { storageName = "BigfootsBurden.Shooting", storage = Storage.Quest.U9_60.BigfootsBurden.Shooting, storageValue = 5 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 16 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 20 }, + { storageName = "BigfootsBurden.QuestLine", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLine, storageValue = 23 }, + { storageName = "BigfootsBurden.QuestLineComplete", storage = Storage.Quest.U9_60.BigfootsBurden.QuestLineComplete, storageValue = 2 }, + { storageName = "BigfootsBurden.Rank", storage = Storage.Quest.U9_60.BigfootsBurden.Rank, storageValue = 1440 }, + { storageName = "BigfootsBurden.Warzone1Access", storage = Storage.Quest.U9_60.BigfootsBurden.Warzone1Access, storageValue = 2 }, + { storageName = "BigfootsBurden.Warzone2Access", storage = Storage.Quest.U9_60.BigfootsBurden.Warzone2Access, storageValue = 2 }, + { storageName = "BigfootsBurden.Warzone3Access", storage = Storage.Quest.U9_60.BigfootsBurden.Warzone3Access, storageValue = 2 }, + { storageName = "DangerousDepths.Questline", storage = Storage.Quest.U11_50.DangerousDepths.Questline, storageValue = 10 }, + { storageName = "DangerousDepths.Access.LavaPumpWarzoneVI", storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneVI, storageValue = 10 }, + { storageName = "DangerousDepths.Access.LavaPumpWarzoneV", storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneV, storageValue = 10 }, + { storageName = "DangerousDepths.Access.LavaPumpWarzoneIV", storage = Storage.Quest.U11_50.DangerousDepths.Access.LavaPumpWarzoneIV, storageValue = 30 }, + { storageName = "DangerousDepths.Dwarves.Points", storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Points, storageValue = 10 }, + { storageName = "DangerousDepths.Scouts.Points", storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Points, storageValue = 10 }, + { storageName = "DangerousDepths.Gnomes.Points", storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Points, storageValue = 10 }, + { storageName = "InServiceOfYalahar.Questline", storage = Storage.Quest.U8_4.InServiceOfYalahar.Questline, storageValue = 51 }, + { storageName = "InServiceOfYalahar.Mission01", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission01, storageValue = 6 }, + { storageName = "InServiceOfYalahar.Mission02", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission02, storageValue = 8 }, + { storageName = "InServiceOfYalahar.Mission03", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission03, storageValue = 6 }, + { storageName = "InServiceOfYalahar.Mission04", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission04, storageValue = 6 }, + { storageName = "InServiceOfYalahar.Mission05", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission05, storageValue = 8 }, + { storageName = "InServiceOfYalahar.Mission06", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission06, storageValue = 5 }, + { storageName = "InServiceOfYalahar.Mission07", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission07, storageValue = 5 }, + { storageName = "InServiceOfYalahar.Mission08", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission08, storageValue = 4 }, + { storageName = "InServiceOfYalahar.Mission09", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission09, storageValue = 2 }, + { storageName = "InServiceOfYalahar.Mission10", storage = Storage.Quest.U8_4.InServiceOfYalahar.Mission10, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SewerPipe01", storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe01, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SewerPipe02", storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe02, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SewerPipe03", storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe03, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SewerPipe04", storage = Storage.Quest.U8_4.InServiceOfYalahar.SewerPipe04, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DiseasedDan", storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedDan, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DiseasedBill", storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedBill, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DiseasedFred", storage = Storage.Quest.U8_4.InServiceOfYalahar.DiseasedFred, storageValue = 1 }, + { storageName = "InServiceOfYalahar.AlchemistFormula", storage = Storage.Quest.U8_4.InServiceOfYalahar.AlchemistFormula, storageValue = 1 }, + { storageName = "InServiceOfYalahar.BadSide", storage = Storage.Quest.U8_4.InServiceOfYalahar.BadSide, storageValue = 1 }, + { storageName = "InServiceOfYalahar.GoodSide", storage = Storage.Quest.U8_4.InServiceOfYalahar.GoodSide, storageValue = 1 }, + { storageName = "InServiceOfYalahar.MrWestDoor", storage = Storage.Quest.U8_4.InServiceOfYalahar.MrWestDoor, storageValue = 1 }, + { storageName = "InServiceOfYalahar.MrWestStatus", storage = Storage.Quest.U8_4.InServiceOfYalahar.MrWestStatus, storageValue = 1 }, + { storageName = "InServiceOfYalahar.TamerinStatus", storage = Storage.Quest.U8_4.InServiceOfYalahar.TamerinStatus, storageValue = 1 }, + { storageName = "InServiceOfYalahar.MorikSummon", storage = Storage.Quest.U8_4.InServiceOfYalahar.MorikSummon, storageValue = 1 }, + { storageName = "InServiceOfYalahar.QuaraState", storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraState, storageValue = 1 }, + { storageName = "InServiceOfYalahar.QuaraSplasher", storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraSplasher, storageValue = 1 }, + { storageName = "InServiceOfYalahar.QuaraSharptooth", storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraSharptooth, storageValue = 1 }, + { storageName = "InServiceOfYalahar.QuaraInky", storage = Storage.Quest.U8_4.InServiceOfYalahar.QuaraInky, storageValue = 1 }, + { storageName = "InServiceOfYalahar.MatrixState", storage = Storage.Quest.U8_4.InServiceOfYalahar.MatrixState, storageValue = 1 }, + { storageName = "InServiceOfYalahar.NotesPalimuth", storage = Storage.Quest.U8_4.InServiceOfYalahar.NotesPalimuth, storageValue = 1 }, + { storageName = "InServiceOfYalahar.NotesAzerus", storage = Storage.Quest.U8_4.InServiceOfYalahar.NotesAzerus, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DoorToAzerus", storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToAzerus, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DoorToBog", storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToBog, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DoorToLastFight", storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToLastFight, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DoorToMatrix", storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToMatrix, storageValue = 1 }, + { storageName = "InServiceOfYalahar.DoorToQuara", storage = Storage.Quest.U8_4.InServiceOfYalahar.DoorToQuara, storageValue = 1 }, + { storageName = "CultsOfTibia.Questline", storage = Storage.Quest.U11_40.CultsOfTibia.Questline, storageValue = 7 }, + { storageName = "CultsOfTibia.Minotaurs.JamesfrancisTask", storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.JamesfrancisTask, storageValue = 1 }, + { storageName = "CultsOfTibia.Minotaurs.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.Minotaurs.BossTimer", storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.BossTimer, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.Stone1", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone1, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.Stone2", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone2, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.Stone3", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Stone3, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.Answer", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.Answer, storageValue = 1 }, + { storageName = "CultsOfTibia.MotA.QuestionId", storage = Storage.Quest.U11_40.CultsOfTibia.MotA.QuestionId, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.Sulphur", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Sulphur, storageValue = 4 }, + { storageName = "CultsOfTibia.Barkless.Tar", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Tar, storageValue = 3 }, + { storageName = "CultsOfTibia.Barkless.Ice", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Ice, storageValue = 3 }, + { storageName = "CultsOfTibia.Barkless.Objects", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Objects, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.Temp", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.Temp, storageValue = 1 }, + { storageName = "CultsOfTibia.Orcs.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.Orcs.LookType", storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.LookType, storageValue = 1 }, + { storageName = "CultsOfTibia.Orcs.BossTimer", storage = Storage.Quest.U11_40.CultsOfTibia.Orcs.BossTimer, storageValue = 1 }, + { storageName = "CultsOfTibia.Life.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Life.Mission, storageValue = 7 }, + { storageName = "CultsOfTibia.Life.BossTimer", storage = Storage.Quest.U11_40.CultsOfTibia.Life.BossTimer, storageValue = 1 }, + { storageName = "CultsOfTibia.Humans.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.Humans.Vaporized", storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Vaporized, storageValue = 1 }, + { storageName = "CultsOfTibia.Humans.Decaying", storage = Storage.Quest.U11_40.CultsOfTibia.Humans.Decaying, storageValue = 1 }, + { storageName = "CultsOfTibia.Humans.BossTimer", storage = Storage.Quest.U11_40.CultsOfTibia.Humans.BossTimer, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.Mission", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Mission, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.Monsters", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Monsters, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.Exorcisms", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Exorcisms, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.Time", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.Time, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.BossTimer", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.BossTimer, storageValue = 1 }, + { storageName = "CultsOfTibia.Minotaurs.BossAccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.BossAccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Minotaurs.AccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Minotaurs.AccessDoor, storageValue = 1 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 1 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 4 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 7 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 16 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 26 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 29 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 32 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 35 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 38 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 41 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 43 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 46 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 47 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 50 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 55 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 56 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 58 }, + { storageName = "ExplorerSociety.QuestLine", storage = Storage.Quest.U7_6.ExplorerSociety.QuestLine, storageValue = 61 }, + { storageName = "ExplorerSociety.CalassaQuest", storage = Storage.Quest.U7_6.ExplorerSociety.CalassaQuest, storageValue = 2 }, + { storageName = "ForgottenKnowledge.Tomes", storage = Storage.Quest.U11_02.ForgottenKnowledge.Tomes, storageValue = 1 }, + { storageName = "ForgottenKnowledge.LastLoreKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.LastLoreKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.TimeGuardianKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.TimeGuardianKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.HorrorKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.HorrorKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.DragonkingKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.DragonkingKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.ThornKnightKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.ThornKnightKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.LloydKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.LloydKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.LadyTenebrisKilled", storage = Storage.Quest.U11_02.ForgottenKnowledge.LadyTenebrisKilled, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessMachine", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessMachine, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessLavaTeleport", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessLavaTeleport, storageValue = 1 }, + { storageName = "BarbarianTest.Questline", storage = Storage.Quest.U8_0.BarbarianTest.Questline, storageValue = 8 }, + { storageName = "BarbarianTest.Mission01", storage = Storage.Quest.U8_0.BarbarianTest.Mission01, storageValue = 3 }, + { storageName = "BarbarianTest.Mission02", storage = Storage.Quest.U8_0.BarbarianTest.Mission02, storageValue = 3 }, + { storageName = "BarbarianTest.Mission03", storage = Storage.Quest.U8_0.BarbarianTest.Mission03, storageValue = 3 }, + { storageName = "ChildrenOfTheRevolution.Questline", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Questline, storageValue = 21 }, + { storageName = "ChildrenOfTheRevolution.Mission00", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission00, storageValue = 2 }, + { storageName = "ChildrenOfTheRevolution.Mission01", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission01, storageValue = 3 }, + { storageName = "ChildrenOfTheRevolution.Mission02", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission02, storageValue = 5 }, + { storageName = "ChildrenOfTheRevolution.Mission03", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission03, storageValue = 3 }, + { storageName = "ChildrenOfTheRevolution.Mission04", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission04, storageValue = 6 }, + { storageName = "ChildrenOfTheRevolution.Mission05", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.Mission05, storageValue = 3 }, + { storageName = "ChildrenOfTheRevolution.SpyBuilding01", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding01, storageValue = 1 }, + { storageName = "ChildrenOfTheRevolution.SpyBuilding02", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding02, storageValue = 1 }, + { storageName = "ChildrenOfTheRevolution.SpyBuilding03", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.SpyBuilding03, storageValue = 1 }, + { storageName = "ChildrenOfTheRevolution.StrangeSymbols", storage = Storage.Quest.U8_54.ChildrenOfTheRevolution.StrangeSymbols, storageValue = 1 }, + { storageName = "DjinnWar.Faction.Greeting", storage = Storage.Quest.U7_4.DjinnWar.Faction.Greeting, storageValue = 2 }, + { storageName = "DjinnWar.Faction.MaridDoor", storage = Storage.Quest.U7_4.DjinnWar.Faction.MaridDoor, storageValue = 2 }, + { storageName = "DjinnWar.Faction.EfreetDoor", storage = Storage.Quest.U7_4.DjinnWar.Faction.EfreetDoor, storageValue = 2 }, + { storageName = "DjinnWar.EfreetFaction.Start", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Start, storageValue = 1 }, + { storageName = "DjinnWar.EfreetFaction.Mission01", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission01, storageValue = 3 }, + { storageName = "DjinnWar.EfreetFaction.Mission02", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission02, storageValue = 3 }, + { storageName = "DjinnWar.EfreetFaction.Mission03", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.Mission03, storageValue = 3 }, + { storageName = "DjinnWar.MaridFaction.Start", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Start, storageValue = 1 }, + { storageName = "DjinnWar.MaridFaction.Mission01", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission01, storageValue = 2 }, + { storageName = "DjinnWar.MaridFaction.Mission02", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission02, storageValue = 2 }, + { storageName = "DjinnWar.MaridFaction.RataMari", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.RataMari, storageValue = 2 }, + { storageName = "DjinnWar.MaridFaction.Mission03", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.Mission03, storageValue = 3 }, + { storageName = "InServiceOfYalahar.TheWayToYalahar", storage = Storage.Quest.U8_4.InServiceOfYalahar.TheWayToYalahar, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.TownsCounter", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.TownsCounter, storageValue = 5 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.AbDendriel", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.AbDendriel, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.Darashia", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Darashia, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.Venore", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Venore, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.Ankrahmun", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Ankrahmun, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.PortHope", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.PortHope, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.Thais", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Thais, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.LibertyBay", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.LibertyBay, storageValue = 1 }, + { storageName = "InServiceOfYalahar.SearoutesAroundYalahar.Carlin", storage = Storage.Quest.U8_4.InServiceOfYalahar.SearoutesAroundYalahar.Carlin, storageValue = 1 }, + { storageName = "TheHiddenCityOfBeregar.DefaultStart", storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.DefaultStart, storageValue = 1 }, + { storageName = "TheHiddenCityOfBeregar.GoingDown", storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.GoingDown, storageValue = 1 }, + { storageName = "TheHiddenCityOfBeregar.WayToBeregar", storage = Storage.Quest.U8_4.TheHiddenCityOfBeregar.WayToBeregar, storageValue = 1 }, + { storageName = "TheIceIslands.Questline", storage = Storage.Quest.U8_0.TheIceIslands.Questline, storageValue = 40 }, + { storageName = "TheIceIslands.Mission01", storage = Storage.Quest.U8_0.TheIceIslands.Mission01, storageValue = 3 }, + { storageName = "TheIceIslands.Mission02", storage = Storage.Quest.U8_0.TheIceIslands.Mission02, storageValue = 5 }, + { storageName = "TheIceIslands.Mission03", storage = Storage.Quest.U8_0.TheIceIslands.Mission03, storageValue = 3 }, + { storageName = "TheIceIslands.Mission04", storage = Storage.Quest.U8_0.TheIceIslands.Mission04, storageValue = 2 }, + { storageName = "TheIceIslands.Mission05", storage = Storage.Quest.U8_0.TheIceIslands.Mission05, storageValue = 6 }, + { storageName = "TheIceIslands.Mission06", storage = Storage.Quest.U8_0.TheIceIslands.Mission06, storageValue = 8 }, + { storageName = "TheIceIslands.Mission07", storage = Storage.Quest.U8_0.TheIceIslands.Mission07, storageValue = 3 }, + { storageName = "TheIceIslands.Mission08", storage = Storage.Quest.U8_0.TheIceIslands.Mission08, storageValue = 4 }, + { storageName = "TheIceIslands.Mission09", storage = Storage.Quest.U8_0.TheIceIslands.Mission09, storageValue = 2 }, + { storageName = "TheIceIslands.Mission10", storage = Storage.Quest.U8_0.TheIceIslands.Mission10, storageValue = 2 }, + { storageName = "TheIceIslands.Mission11", storage = Storage.Quest.U8_0.TheIceIslands.Mission11, storageValue = 2 }, + { storageName = "TheIceIslands.Mission12", storage = Storage.Quest.U8_0.TheIceIslands.Mission12, storageValue = 6 }, + { storageName = "TheIceIslands.yakchalDoor", storage = Storage.Quest.U8_0.TheIceIslands.yakchalDoor, storageValue = 1 }, + { storageName = "TheInquisitionQuest.Questline", storage = Storage.Quest.U8_2.TheInquisitionQuest.Questline, storageValue = 25 }, + { storageName = "TheInquisitionQuest.Mission01", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission01, storageValue = 7 }, + { storageName = "TheInquisitionQuest.Mission02", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission02, storageValue = 3 }, + { storageName = "TheInquisitionQuest.Mission03", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission03, storageValue = 6 }, + { storageName = "TheInquisitionQuest.Mission04", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission04, storageValue = 3 }, + { storageName = "TheInquisitionQuest.Mission05", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission05, storageValue = 3 }, + { storageName = "TheInquisitionQuest.Mission06", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission06, storageValue = 3 }, + { storageName = "TheInquisitionQuest.Mission07", storage = Storage.Quest.U8_2.TheInquisitionQuest.Mission07, storageValue = 1 }, + { storageName = "TheInquisitionQuest.GrofGuard", storage = Storage.Quest.U8_2.TheInquisitionQuest.GrofGuard, storageValue = 1 }, + { storageName = "TheInquisitionQuest.KulagGuard", storage = Storage.Quest.U8_2.TheInquisitionQuest.KulagGuard, storageValue = 1 }, + { storageName = "TheInquisitionQuest.TimGuard", storage = Storage.Quest.U8_2.TheInquisitionQuest.TimGuard, storageValue = 1 }, + { storageName = "TheInquisitionQuest.WalterGuard", storage = Storage.Quest.U8_2.TheInquisitionQuest.WalterGuard, storageValue = 1 }, + { storageName = "TheInquisitionQuest.StorkusVampiredust", storage = Storage.Quest.U8_2.TheInquisitionQuest.StorkusVampiredust, storageValue = 1 }, + { storageName = "TheNewFrontier.Questline", storage = Storage.Quest.U8_54.TheNewFrontier.Questline, storageValue = 29 }, + { storageName = "TheNewFrontier.Mission01", storage = Storage.Quest.U8_54.TheNewFrontier.Mission01, storageValue = 3 }, + { storageName = "TheNewFrontier.Mission02[1]", storage = Storage.Quest.U8_54.TheNewFrontier.Mission02[1], storageValue = 4 }, + { storageName = "TheNewFrontier.Mission03", storage = Storage.Quest.U8_54.TheNewFrontier.Mission03, storageValue = 3 }, + { storageName = "TheNewFrontier.Mission04", storage = Storage.Quest.U8_54.TheNewFrontier.Mission04, storageValue = 2 }, + { storageName = "TheNewFrontier.Mission05[1]", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05[1], storageValue = 2 }, + { storageName = "TheNewFrontier.Mission06", storage = Storage.Quest.U8_54.TheNewFrontier.Mission06, storageValue = 5 }, + { storageName = "TheNewFrontier.Mission07[1]", storage = Storage.Quest.U8_54.TheNewFrontier.Mission07[1], storageValue = 2 }, + { storageName = "TheNewFrontier.Mission08", storage = Storage.Quest.U8_54.TheNewFrontier.Mission08, storageValue = 2 }, + { storageName = "TheNewFrontier.Mission09[1]", storage = Storage.Quest.U8_54.TheNewFrontier.Mission09[1], storageValue = 3 }, + { storageName = "TheNewFrontier.Mission10[1]", storage = Storage.Quest.U8_54.TheNewFrontier.Mission10[1], storageValue = 2 }, + { storageName = "TheNewFrontier.Mission10.MagicCarpetDoor", storage = Storage.Quest.U8_54.TheNewFrontier.Mission10.MagicCarpetDoor, storageValue = 1 }, + { storageName = "TheNewFrontier.TomeofKnowledge", storage = Storage.Quest.U8_54.TheNewFrontier.TomeofKnowledge, storageValue = 12 }, + { storageName = "TheNewFrontier.Mission02.Beaver1", storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver1, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission02.Beaver2", storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver2, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission02.Beaver3", storage = Storage.Quest.U8_54.TheNewFrontier.Mission02.Beaver3, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.KingTibianus", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.KingTibianus, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.Leeland", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Leeland, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.Angus", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Angus, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.Wyrdin", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Wyrdin, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.Telas", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Telas, storageValue = 1 }, + { storageName = "TheNewFrontier.Mission05.Humgolf", storage = Storage.Quest.U8_54.TheNewFrontier.Mission05.Humgolf, storageValue = 1 }, + { storageName = "TheShatteredIsles.DefaultStart", storage = Storage.Quest.U7_8.TheShatteredIsles.DefaultStart, storageValue = 3 }, + { storageName = "TheShatteredIsles.TheGovernorDaughter", storage = Storage.Quest.U7_8.TheShatteredIsles.TheGovernorDaughter, storageValue = 3 }, + { storageName = "TheShatteredIsles.TheErrand", storage = Storage.Quest.U7_8.TheShatteredIsles.TheErrand, storageValue = 2 }, + { storageName = "TheShatteredIsles.AccessToMeriana", storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToMeriana, storageValue = 1 }, + { storageName = "TheShatteredIsles.APoemForTheMermaid", storage = Storage.Quest.U7_8.TheShatteredIsles.APoemForTheMermaid, storageValue = 3 }, + { storageName = "TheShatteredIsles.ADjinnInLove", storage = Storage.Quest.U7_8.TheShatteredIsles.ADjinnInLove, storageValue = 5 }, + { storageName = "TheShatteredIsles.AccessToLagunaIsland", storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToLagunaIsland, storageValue = 1 }, + { storageName = "TheShatteredIsles.AccessToGoroma", storage = Storage.Quest.U7_8.TheShatteredIsles.AccessToGoroma, storageValue = 1 }, + { storageName = "TheShatteredIsles.Shipwrecked", storage = Storage.Quest.U7_8.TheShatteredIsles.Shipwrecked, storageValue = 2 }, + { storageName = "TheShatteredIsles.DragahsSpellbook", storage = Storage.Quest.U7_8.TheShatteredIsles.DragahsSpellbook, storageValue = 1 }, + { storageName = "TheShatteredIsles.TheCounterspell", storage = Storage.Quest.U7_8.TheShatteredIsles.TheCounterspell, storageValue = 4 }, + { storageName = "TheThievesGuildQuest.Questline", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Questline, storageValue = 1 }, + { storageName = "TheThievesGuildQuest.Mission01", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission01, storageValue = 2 }, + { storageName = "TheThievesGuildQuest.Mission02", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission02, storageValue = 3 }, + { storageName = "TheThievesGuildQuest.Mission03", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission03, storageValue = 3 }, + { storageName = "TheThievesGuildQuest.Mission04", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission04, storageValue = 8 }, + { storageName = "TheThievesGuildQuest.Mission05", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission05, storageValue = 2 }, + { storageName = "TheThievesGuildQuest.Mission06", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission06, storageValue = 4 }, + { storageName = "TheThievesGuildQuest.Mission07", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission07, storageValue = 2 }, + { storageName = "TheThievesGuildQuest.Mission08", storage = Storage.Quest.U8_2.TheThievesGuildQuest.Mission08, storageValue = 1 }, + { storageName = "TheTravellingTrader.Mission01", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission01, storageValue = 1 }, + { storageName = "TheTravellingTrader.Mission01_2", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission01, storageValue = 2 }, + { storageName = "TheTravellingTrader.Mission02", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission02, storageValue = 5 }, + { storageName = "TheTravellingTrader.Mission03", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission03, storageValue = 3 }, + { storageName = "TheTravellingTrader.Mission04", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission04, storageValue = 3 }, + { storageName = "TheTravellingTrader.Mission05", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission05, storageValue = 3 }, + { storageName = "TheTravellingTrader.Mission06", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission06, storageValue = 2 }, + { storageName = "TheTravellingTrader.Mission07", storage = Storage.Quest.U8_1.TheTravellingTrader.Mission07, storageValue = 1 }, + { storageName = "BarbarianArena.QuestLogGreenhorn", storage = Storage.Quest.U8_0.BarbarianArena.QuestLogGreenhorn, storageValue = 1 }, + { storageName = "TibiaTales.DefaultStart", storage = Storage.Quest.U8_1.TibiaTales.DefaultStart, storageValue = 1 }, + { storageName = "TibiaTales.ToAppeaseTheMightyQuest", storage = Storage.Quest.U8_1.TibiaTales.ToAppeaseTheMightyQuest, storageValue = 1 }, + { storageName = "12450", storage = 12450, storageValue = 6 }, + { storageName = "12330", storage = 12330, storageValue = 1 }, + { storageName = "12332", storage = 12332, storageValue = 13 }, + { storageName = "12333", storage = 12333, storageValue = 3 }, + { storageName = "FriendsAndTraders.DefaultStart", storage = Storage.Quest.U7_8.FriendsAndTraders.DefaultStart, storageValue = 1 }, + { storageName = "FriendsAndTraders.TheSweatyCyclops", storage = Storage.Quest.U7_8.FriendsAndTraders.TheSweatyCyclops, storageValue = 2 }, + { storageName = "FriendsAndTraders.TheMermaidMarina", storage = Storage.Quest.U7_8.FriendsAndTraders.TheMermaidMarina, storageValue = 2 }, + { storageName = "FriendsAndTraders.TheBlessedStake", storage = Storage.Quest.U7_8.FriendsAndTraders.TheBlessedStake, storageValue = 12 }, + { storageName = "100157", storage = 100157, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.Questline", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Questline, storageValue = 29 }, + { storageName = "WrathOfTheEmperor.Mission01", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission01, storageValue = 3 }, + { storageName = "WrathOfTheEmperor.Mission02", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission02, storageValue = 3 }, + { storageName = "WrathOfTheEmperor.Mission03", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission03, storageValue = 3 }, + { storageName = "WrathOfTheEmperor.Mission04", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission04, storageValue = 3 }, + { storageName = "WrathOfTheEmperor.Mission05", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission05, storageValue = 3 }, + { storageName = "WrathOfTheEmperor.Mission06", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission06, storageValue = 4 }, + { storageName = "WrathOfTheEmperor.Mission07", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission07, storageValue = 6 }, + { storageName = "WrathOfTheEmperor.Mission08", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission08, storageValue = 2 }, + { storageName = "WrathOfTheEmperor.Mission09", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission09, storageValue = 2 }, + { storageName = "WrathOfTheEmperor.Mission10", storage = Storage.Quest.U8_6.WrathOfTheEmperor.Mission10, storageValue = 1 }, + { storageName = "TheApeCity.Started", storage = Storage.Quest.U7_6.TheApeCity.Started, storageValue = 1 }, + { storageName = "TheApeCity.Questline", storage = Storage.Quest.U7_6.TheApeCity.Questline, storageValue = 18 }, + { storageName = "BanutaSecretTunnel.DeeperBanutaShortcut", storage = Storage.BanutaSecretTunnel.DeeperBanutaShortcut, storageValue = 1 }, + { storageName = "OramondQuest.QuestLine", storage = Storage.Quest.U10_50.OramondQuest.QuestLine, storageValue = 1 }, + { storageName = "OramondQuest.ToTakeRoots.Mission", storage = Storage.Quest.U10_50.OramondQuest.ToTakeRoots.Mission, storageValue = 3000 }, + { storageName = "DangerousDepths.Questline", storage = Storage.Quest.U11_50.DangerousDepths.Questline, storageValue = 1 }, + { storageName = "DangerousDepths.Dwarves.Home", storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Home, storageValue = 2 }, + { storageName = "DangerousDepths.Dwarves.Subterranean", storage = Storage.Quest.U11_50.DangerousDepths.Dwarves.Subterranean, storageValue = 2 }, + { storageName = "DangerousDepths.Gnomes.Measurements", storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Measurements, storageValue = 2 }, + { storageName = "DangerousDepths.Gnomes.Ordnance", storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Ordnance, storageValue = 3 }, + { storageName = "DangerousDepths.Gnomes.Charting", storage = Storage.Quest.U11_50.DangerousDepths.Gnomes.Charting, storageValue = 2 }, + { storageName = "DangerousDepths.Scouts.Growth", storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Growth, storageValue = 2 }, + { storageName = "DangerousDepths.Scouts.Diremaw", storage = Storage.Quest.U11_50.DangerousDepths.Scouts.Diremaw, storageValue = 2 }, + { storageName = "ThreatenedDreams.QuestLine", storage = Storage.Quest.U11_40.ThreatenedDreams.QuestLine, storageValue = 1 }, + { storageName = "ThreatenedDreams.Mission01[1]", storage = Storage.Quest.U11_40.ThreatenedDreams.Mission01[1], storageValue = 16 }, + { storageName = "ThreatenedDreams.Mission02.KroazurAccess", storage = Storage.Quest.U11_40.ThreatenedDreams.Mission02.KroazurAccess, storageValue = 1 }, + { storageName = "AdventurersGuild.QuestLine", storage = Storage.Quest.U9_80.AdventurersGuild.QuestLine, storageValue = 1 }, + { storageName = "TheGreatDragonHunt.WarriorSkeleton", storage = Storage.Quest.U10_80.TheGreatDragonHunt.WarriorSkeleton, storageValue = 1 }, + { storageName = "TheGreatDragonHunt.WarriorSkeleton_2", storage = Storage.Quest.U10_80.TheGreatDragonHunt.WarriorSkeleton, storageValue = 2 }, + { storageName = "TheLostBrotherQuest", storage = Storage.Quest.U10_80.TheLostBrotherQuest, storageValue = 3 }, + { storageName = "Dawnport.Questline", storage = Storage.Quest.U10_55.Dawnport.Questline, storageValue = 1 }, + { storageName = "Dawnport.GoMain", storage = Storage.Quest.U10_55.Dawnport.GoMain, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessDeath", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessDeath, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessViolet", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessViolet, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessEarth", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessEarth, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessFire", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessFire, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessIce", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessIce, storageValue = 1 }, + { storageName = "ForgottenKnowledge.AccessGolden", storage = Storage.Quest.U11_02.ForgottenKnowledge.AccessGolden, storageValue = 1 }, + { storageName = "GrimvaleQuest.AncientFeudDoors", storage = Storage.Quest.U10_80.GrimvaleQuest.AncientFeudDoors, storageValue = 1 }, + { storageName = "GrimvaleQuest.AncientFeudShortcut", storage = Storage.Quest.U10_80.GrimvaleQuest.AncientFeudShortcut, storageValue = 1 }, + { storageName = "Kilmaresh.AccessDoor", storage = Storage.Kilmaresh.AccessDoor, storageValue = 1 }, + { storageName = "Kilmaresh.CatacombDoors", storage = Storage.Kilmaresh.CatacombDoors, storageValue = 1 }, + { storageName = "TheOrderOfTheLion.AccessEastSide", storage = Storage.Quest.U12_40.TheOrderOfTheLion.AccessEastSide, storageValue = 1 }, + { storageName = "TheOrderOfTheLion.AccessSouthernSide", storage = Storage.Quest.U12_40.TheOrderOfTheLion.AccessSouthernSide, storageValue = 1 }, + { storageName = "APiratesTail.TentuglyDoor", storage = Storage.Quest.U12_60.APiratesTail.TentuglyDoor, storageValue = 1 }, + { storageName = "APiratesTail.RascacoonShortcut", storage = Storage.Quest.U12_60.APiratesTail.RascacoonShortcut, storageValue = 1 }, + { storageName = "AdventuresOfGalthen.AccessDoor", storage = Storage.Quest.U12_70.AdventuresOfGalthen.AccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.AccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.AccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.TrialAccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.TrialAccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.TarAccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.TarAccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Barkless.BossAccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Barkless.BossAccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Life.AccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Life.AccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.Misguided.AccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.Misguided.AccessDoor, storageValue = 1 }, + { storageName = "CultsOfTibia.FinalBoss.AccessDoor", storage = Storage.Quest.U11_40.CultsOfTibia.FinalBoss.AccessDoor, storageValue = 1 }, + { storageName = "FerumbrasAscension.FirstDoor", storage = Storage.Quest.U10_90.FerumbrasAscension.FirstDoor, storageValue = 1 }, + { storageName = "FerumbrasAscension.MonsterDoor", storage = Storage.Quest.U10_90.FerumbrasAscension.MonsterDoor, storageValue = 1 }, + { storageName = "FerumbrasAscension.TarbazDoor", storage = Storage.Quest.U10_90.FerumbrasAscension.TarbazDoor, storageValue = 1 }, + { storageName = "FerumbrasAscension.HabitatsAccess", storage = Storage.Quest.U10_90.FerumbrasAscension.HabitatsAccess, storageValue = 1 }, + { storageName = "FerumbrasAscension.TheLordOfTheLiceAccess", storage = Storage.Quest.U10_90.FerumbrasAscension.TheLordOfTheLiceAccess, storageValue = 1 }, + { storageName = "FerumbrasAscension.Statue", storage = Storage.Quest.U10_90.FerumbrasAscension.Statue, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.AwarnessEmperor", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.AwarnessEmperor, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.BossRoom", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.BossRoom, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.InnerSanctum", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.InnerSanctum, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.Rebel", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Rebel, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.SleepingDragon", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.SleepingDragon, storageValue = 2 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.Wote10", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Wote10, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.Zizzle", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Zizzle, storageValue = 1 }, + { storageName = "WrathOfTheEmperor.TeleportAccess.Zlak", storage = Storage.Quest.U8_6.WrathOfTheEmperor.TeleportAccess.Zlak, storageValue = 1 }, + { storageName = "DjinnWar.EfreetFaction.DoorToLamp", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.DoorToLamp, storageValue = 1 }, + { storageName = "DjinnWar.EfreetFaction.DoorToMaridTerritory", storage = Storage.Quest.U7_4.DjinnWar.EfreetFaction.DoorToMaridTerritory, storageValue = 1 }, + { storageName = "DjinnWar.MaridFaction.DoorToLamp", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.DoorToLamp, storageValue = 1 }, + { storageName = "DjinnWar.MaridFaction.DoorToEfreetTerritory", storage = Storage.Quest.U7_4.DjinnWar.MaridFaction.DoorToEfreetTerritory, storageValue = 1 }, + { storageName = "GraveDanger.QuestLine", storage = Storage.Quest.U12_20.GraveDanger.QuestLine, storageValue = 14 }, + { storageName = "GraveDanger.Bosses.KingZelosDoor", storage = Storage.Quest.U12_20.GraveDanger.Bosses.KingZelosDoor, storageValue = 1 }, + { storageName = "CradleOfMonsters.Access.Ingol", storage = Storage.Quest.U13_10.CradleOfMonsters.Access.Ingol, storageValue = 1 }, + { storageName = "CradleOfMonsters.Access.LowerIngol", storage = Storage.Quest.U13_10.CradleOfMonsters.Access.LowerIngol, storageValue = 1 }, + { storageName = "CradleOfMonsters.Access.Monster", storage = Storage.Quest.U13_10.CradleOfMonsters.Access.Monster, storageValue = 1 }, + { storageName = "CradleOfMonsters.Access.MutatedAbomination", storage = Storage.Quest.U13_10.CradleOfMonsters.Access.MutatedAbomination, storageValue = 1 }, + { storageName = "TheNewFrontier.SnakeHeadTeleport", storage = Storage.Quest.U8_54.TheNewFrontier.SnakeHeadTeleport, storageValue = 1 }, + { storageName = "LiquidBlackQuest.Visitor", storage = Storage.Quest.U9_4.LiquidBlackQuest.Visitor, storageValue = 5 }, + { storageName = "BloodBrothers.VengothAccess", storage = Storage.Quest.U8_4.BloodBrothers.VengothAccess, storageValue = 1 }, + { storageName = "KillingInTheNameOf.BudrikMinos", storage = Storage.Quest.U8_5.KillingInTheNameOf.BudrikMinos, storageValue = 0 }, + { storageName = "ToOutfoxAFoxQuest.Questline", storage = Storage.Quest.U8_1.ToOutfoxAFoxQuest.Questline, storageValue = 2 }, + { storageName = "HunterOutfits.HunterMusicSheet01", storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet01, storageValue = 1 }, + { storageName = "HunterOutfits.HunterMusicSheet02", storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet02, storageValue = 1 }, + { storageName = "HunterOutfits.HunterMusicSheet03", storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet03, storageValue = 1 }, + { storageName = "HunterOutfits.HunterMusicSheet04", storage = Storage.Quest.U7_8.HunterOutfits.HunterMusicSheet04, storageValue = 1 }, + { storageName = "TheIceIslands.NorsemanOutfit", storage = Storage.Quest.U8_0.TheIceIslands.NorsemanOutfit, storageValue = 1 }, + { storageName = "OutfitQuest.DefaultStart", storage = Storage.OutfitQuest.DefaultStart, storageValue = 1 }, + { storageName = "HeroRathleton.AccessDoor", storage = Storage.HeroRathleton.AccessDoor, storageValue = 1 }, + { storageName = "HeroRathleton.AccessTeleport1", storage = Storage.HeroRathleton.AccessTeleport1, storageValue = 1 }, + { storageName = "HeroRathleton.AccessTeleport2", storage = Storage.HeroRathleton.AccessTeleport2, storageValue = 1 }, + { storageName = "HeroRathleton.AccessTeleport3", storage = Storage.HeroRathleton.AccessTeleport3, storageValue = 1 }, + { storageName = "TheHuntForTheSeaSerpent.FishForASerpent", storage = Storage.Quest.U8_2.TheHuntForTheSeaSerpent.FishForASerpent, storageValue = 5 }, + { storageName = "TheHuntForTheSeaSerpent.QuestLine", storage = Storage.Quest.U8_2.TheHuntForTheSeaSerpent.QuestLine, storageValue = 2 }, + { storageName = "TheWhiteRavenMonastery.QuestLog", storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.QuestLog, storageValue = 1 }, + { storageName = "TheWhiteRavenMonastery.Passage", storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Passage, storageValue = 1 }, + { storageName = "TheWhiteRavenMonastery.Diary", storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Diary, storageValue = 2 }, + { storageName = "TheWhiteRavenMonastery.Door", storage = Storage.Quest.U7_24.TheWhiteRavenMonastery.Door, storageValue = 1 }, } -- from Position: (33201, 31762, 1) @@ -405,8 +367,15 @@ local function playerFreeQuestStart(playerId, index) return end - if player:getStorageValue(questTable[index].storage) ~= questTable[index].storageValue then - player:setStorageValue(questTable[index].storage, questTable[index].storageValue) + local questData = questTable[index] + local currentStorageValue = player:getStorageValue(questData.storage) + + if not questData.storage then + logger.warn("[Freequest System]: error storage for '" .. questData.storageName .. "' is nil for the index") + elseif currentStorageValue ~= questData.storageValue then + player:setStorageValue(questData.storage, questData.storageValue) + elseif currentStorageValue == -1 then + logger.warn("[Freequest System]: warning Storage '" .. questData.storageName .. "' currently nil for player ID " .. playerId) end end diff --git a/data-otservbr-global/scripts/creaturescripts/others/#modal_window_example.lua b/data-otservbr-global/scripts/creaturescripts/others/#modal_window_example.lua deleted file mode 100644 index e2de4a9e474..00000000000 --- a/data-otservbr-global/scripts/creaturescripts/others/#modal_window_example.lua +++ /dev/null @@ -1,63 +0,0 @@ ---[[ - ModalWindowHelper Example -]] --- - -local moveDirectionTest = { - ["Right"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_EAST) - player:teleportTo(pos, true) - end, - ["Left"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_WEST) - player:teleportTo(pos, true) - end, - ["Up"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_NORTH) - player:teleportTo(pos, true) - end, - ["Down"] = function(player) - local pos = player:getPosition() - pos:getNextPosition(DIRECTION_SOUTH) - player:teleportTo(pos, true) - end, -} - -local talkAction = TalkAction("!modalTest") - -function talkAction.onSay(player, words, param, type) - local modalWindow = ModalWindow({ - title = "Modal Window Helper Example", - message = "This is an example of ModalWindowHelper.", - }) - if param == "choices" then - for text, callback in pairs(moveDirectionTest) do - modalWindow:addChoice(text, function(player, button, choice) - if button.name == "Select" then - callback(player) - modalWindow:sendToPlayer(player) - end - end) - end - - modalWindow:addButton("Select") - modalWindow:addButton("Cancel") - elseif param == "buttons" then - for direction, callback in pairs(moveDirectionTest) do - modalWindow:addButton(direction, function(player, button, choice) - callback(player) - modalWindow:sendToPlayer(player) - end) - end - end - modalWindow:sendToPlayer(player) - return false -end - ---talkAction:accountType(ACCOUNT_TYPE_GOD) ---talkAction:access(true) -talkAction:separator(" ") -talkAction:register() diff --git a/data-otservbr-global/scripts/creaturescripts/others/droploot.lua b/data-otservbr-global/scripts/creaturescripts/others/droploot.lua index 7be3564048d..9bf77afa71b 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/droploot.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/droploot.lua @@ -1,5 +1,7 @@ -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/blessings.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") + local dropLoot = CreatureEvent("DropLoot") + function dropLoot.onDeath(player, corpse, killer, mostDamage, unjustified, mostDamage_unjustified) local town = player:getTown() if town and town:getId() == TOWNS_LIST.DAWNPORT and player:getLevel() < 8 then @@ -9,6 +11,7 @@ function dropLoot.onDeath(player, corpse, killer, mostDamage, unjustified, mostD if player:hasFlag(PlayerFlag_NotGenerateLoot) then return true end + Blessings.DebugPrint("onDeath DROPLOOT EVENT DropLoot") return Blessings.PlayerDeath(player, corpse, killer) end diff --git a/data-otservbr-global/scripts/creaturescripts/others/login.lua b/data-otservbr-global/scripts/creaturescripts/others/login.lua index 8457209e90a..c833dfd90fb 100644 --- a/data-otservbr-global/scripts/creaturescripts/others/login.lua +++ b/data-otservbr-global/scripts/creaturescripts/others/login.lua @@ -12,18 +12,18 @@ function playerLogin.onLogin(player) town = table.contains(freeTowns, town:getName()) and town or Town(defaultTown) player:teleportTo(town:getTemplePosition()) player:setTown(town) - player:sendTextMessage(MESSAGE_FAILURE, "Your premium time has expired.") + player:sendTextMessage(MESSAGE_FAILURE, "Your premium time has expired!") if sex == 1 then - player:setOutfit({ lookType = 128, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 }) + player:setOutfit({ lookType = 128, lookHead = 114, lookBody = 120, lookLegs = 132, lookFeet = 115, lookAddons = 0 }) elseif sex == 0 then - player:setOutfit({ lookType = 136, lookFeet = 114, lookLegs = 134, lookHead = 114, lookAddons = 0 }) + player:setOutfit({ lookType = 136, lookHead = 114, lookBody = 120, lookLegs = 132, lookFeet = 115, lookAddons = 0 }) end if home and not player:isPremium() then setHouseOwner(home, 0) - player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "You've lost your house because you are not premium anymore.") - player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Your items from house are send to your inbox.") + player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "You have lost your house because you are no longer a premium account.") + player:sendTextMessage(MESSAGE_GAME_HIGHLIGHT, "Your items from the house have been sent to your inbox.") end end diff --git a/data-otservbr-global/scripts/globalevents/others/guild_war.lua b/data-otservbr-global/scripts/globalevents/others/guild_war.lua deleted file mode 100644 index 41238755494..00000000000 --- a/data-otservbr-global/scripts/globalevents/others/guild_war.lua +++ /dev/null @@ -1,10 +0,0 @@ -local guildWar = GlobalEvent("guildwar") - -function guildWar.onThink(interval) - local time = os.time() - db.query("UPDATE `guild_wars` SET `status` = 4, `ended` = " .. time .. " WHERE `status` = 1 AND `ended` != 0 AND `ended` < " .. time) - return true -end - -guildWar:interval(60000) -guildWar:register() diff --git a/data-otservbr-global/scripts/lib/monster_functions.lua b/data-otservbr-global/scripts/lib/monster_functions.lua new file mode 100644 index 00000000000..cdb56c5e177 --- /dev/null +++ b/data-otservbr-global/scripts/lib/monster_functions.lua @@ -0,0 +1,8 @@ +function Monster:handleCobraOnSpawn() + if Game.getStorageValue(Global.Storage.CobraFlask) >= os.time() then + monster:setHealth(monster:getMaxHealth() * 0.75) + monster:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS) + else + Game.setStorageValue(Global.Storage.CobraFlask, -1) + end +end diff --git a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_lever.lua b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_lever.lua index 7828b7d935e..bd4e2b171fe 100644 --- a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_lever.lua +++ b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_lever.lua @@ -1,91 +1,69 @@ -local crystals = { - [1] = { crystalPosition = Position(33390, 31468, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal1 }, - [2] = { crystalPosition = Position(33394, 31468, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal2 }, - [3] = { crystalPosition = Position(33397, 31471, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal3 }, - [4] = { crystalPosition = Position(33397, 31475, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal4 }, - [5] = { crystalPosition = Position(33394, 31478, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal5 }, - [6] = { crystalPosition = Position(33390, 31478, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal6 }, - [7] = { crystalPosition = Position(33387, 31475, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal7 }, - [8] = { crystalPosition = Position(33387, 31471, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal8 }, -} - local config = { - centerRoom = Position(33392, 31473, 14), - BossPosition = Position(33392, 31473, 14), + boss = { + name = "Ascending Ferumbras", + position = Position(33392, 31473, 14), + }, + timeToFightAgain = 60 * 60 * 20 * 24, playerPositions = { - Position(33269, 31477, 14), - Position(33269, 31478, 14), - Position(33269, 31479, 14), - Position(33269, 31480, 14), - Position(33269, 31481, 14), - Position(33270, 31477, 14), - Position(33270, 31478, 14), - Position(33270, 31479, 14), - Position(33270, 31480, 14), - Position(33270, 31481, 14), - Position(33271, 31477, 14), - Position(33271, 31478, 14), - Position(33271, 31479, 14), - Position(33271, 31480, 14), - Position(33271, 31481, 14), + { pos = Position(33270, 31477, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33269, 31477, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33269, 31478, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33269, 31479, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33269, 31480, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33269, 31481, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33270, 31478, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33270, 31479, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33270, 31480, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33270, 31481, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33271, 31477, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33271, 31478, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33271, 31479, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33271, 31480, 14), teleport = Position(33392, 31479, 14) }, + { pos = Position(33271, 31481, 14), teleport = Position(33392, 31479, 14) }, }, - newPosition = Position(33392, 31479, 14), -} - -local leverFerumbras = Action() - -function leverFerumbras.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local playersTable = {} - if item.itemid == 8911 then - if player:getPosition() ~= Position(33270, 31477, 14) then - item:transform(8912) - return true - end - end - if item.itemid == 8911 then - if player:doCheckBossRoom("Ascending Ferumbras", Position(33379, 31460, 14), Position(33405, 31485, 14)) then - Game.createMonster("Ascending Ferumbras", config.BossPosition, true, true) - for b = 1, 10 do - local xrand = math.random(-10, 10) - local yrand = math.random(-10, 10) - local position = Position(33392 + xrand, 31473 + yrand, 14) - if Game.createMonster("rift invader", position) then - end - end - for x = 33269, 33271 do - for y = 31477, 31481 do - local playerTile = Tile(Position(x, y, 14)):getTopCreature() - if playerTile and playerTile:isPlayer() then - playerTile:getPosition():sendMagicEffect(CONST_ME_POFF) - playerTile:teleportTo(config.newPosition) - playerTile:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - playerTile:setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.FerumbrasTimer, os.time() + 60 * 60 * 20 * 24) - table.insert(playersTable, playerTile:getId()) - end - end - end - Game.setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.Crystals.AllCrystals, 0) - Game.setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.FerumbrasEssence, 0) - for _, crystal in pairs(crystals) do - local pos = crystal.crystalPosition - local stg = crystal.globalStorage - local sqm = Tile(pos) - if sqm then - local item = sqm:getItemById(14961) - if item then - item:transform(14955) - end + specPos = { + from = Position(33379, 31460, 14), + to = Position(33405, 31485, 14), + }, + exit = Position(33319, 32318, 13), + monsters = { + { name = "rift invader", pos = Position(33385, 31466, 14) }, + { name = "rift invader", pos = Position(33396, 31466, 14) }, + { name = "rift invader", pos = Position(33392, 31480, 14) }, + { name = "rift invader", pos = Position(33392, 31468, 14) }, + { name = "rift invader", pos = Position(33385, 31473, 14) }, + { name = "rift invader", pos = Position(33398, 31478, 14) }, + { name = "rift invader", pos = Position(33384, 31478, 14) }, + { name = "rift invader", pos = Position(33390, 31463, 14) }, + { name = "rift invader", pos = Position(33400, 31473, 14) }, + { name = "rift invader", pos = Position(33400, 31465, 14) }, + }, + onUseExtra = function(player) + local crystals = { + [1] = { crystalPosition = Position(33390, 31468, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal1 }, + [2] = { crystalPosition = Position(33394, 31468, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal2 }, + [3] = { crystalPosition = Position(33397, 31471, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal3 }, + [4] = { crystalPosition = Position(33397, 31475, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal4 }, + [5] = { crystalPosition = Position(33394, 31478, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal5 }, + [6] = { crystalPosition = Position(33390, 31478, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal6 }, + [7] = { crystalPosition = Position(33387, 31475, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal7 }, + [8] = { crystalPosition = Position(33387, 31471, 14), globalStorage = Storage.Quest.U10_90.FerumbrasAscension.Crystals.Crystal8 }, + } + Game.setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.Crystals.AllCrystals, 0) + Game.setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.FerumbrasEssence, 0) + for _, crystal in pairs(crystals) do + local tile = Tile(crystal.crystalPosition) + if tile then + local item = tile:getItemById(14961) + if item then + item:transform(14955) end - Game.setStorageValue(stg, 0) end - addEvent(kickPlayersAfterTime, 30 * 60 * 1000, playersTable, Position(33379, 31460, 14), Position(33405, 31485, 14), Position(33319, 32318, 13)) - item:transform(8912) + Game.setStorageValue(crystal.globalStorage, 0) end - elseif item.itemid == 8912 then - item:transform(8911) - end - return true -end + end, +} -leverFerumbras:uid(1021) +local leverFerumbras = BossLever(config) +leverFerumbras:position(Position(33270, 31476, 14)) leverFerumbras:register() diff --git a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_rat_lever.lua b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_rat_lever.lua index e9592b71585..97cb6fef4f9 100644 --- a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_rat_lever.lua +++ b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_rat_lever.lua @@ -1,57 +1,23 @@ local config = { - centerRoom = Position(33215, 31456, 12), - BossPosition = Position(33220, 31460, 12), + boss = { + name = "The Lord of the Lice", + position = Position(33220, 31460, 12), + }, + timeToFightAgain = 2 * 24 * 60 * 60, playerPositions = { - Position(33197, 31475, 11), - Position(33198, 31475, 11), - Position(33199, 31475, 11), - Position(33200, 31475, 11), - Position(33201, 31475, 11), + { pos = Position(33201, 31475, 11), teleport = Position(33215, 31470, 12) }, + { pos = Position(33197, 31475, 11), teleport = Position(33215, 31470, 12) }, + { pos = Position(33198, 31475, 11), teleport = Position(33215, 31470, 12) }, + { pos = Position(33199, 31475, 11), teleport = Position(33215, 31470, 12) }, + { pos = Position(33200, 31475, 11), teleport = Position(33215, 31470, 12) }, + }, + specPos = { + from = Position(33187, 31429, 12), + to = Position(33242, 31487, 12), }, - newPosition = Position(33215, 31470, 12), + exit = Position(33319, 32318, 13), } -local ferumbrasAscendantRatLever = Action() - -function ferumbrasAscendantRatLever.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if item.itemid == 8911 then - if player:getPosition() ~= Position(33201, 31475, 11) then - item:transform(8912) - return true - end - end - - if item.itemid == 8911 then - local playersTable = {} - if player:doCheckBossRoom("The Lord of the Lice", Position(33187, 31429, 12), Position(33242, 31487, 12)) then - local specs, spec = Game.getSpectators(config.centerRoom, false, false, 30, 30, 30, 30) - for i = 1, #specs do - spec = specs[i] - if spec:isPlayer() then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting with The Lord of The Lice.") - return true - end - end - Game.createMonster("the lord of the lice", config.BossPosition, true, true) - for x = 33197, 33201 do - local playerTile = Tile(Position(x, 31475, 11)):getTopCreature() - if playerTile and playerTile:isPlayer() then - playerTile:getPosition():sendMagicEffect(CONST_ME_POFF) - playerTile:teleportTo(config.newPosition) - playerTile:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - playerTile:setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.TheLordOfTheLiceTimer, os.time() + 60 * 60 * 2 * 24) - table.insert(playersTable, playerTile:getId()) - end - end - addEvent(kickPlayersAfterTime, 30 * 60 * 1000, playersTable, Position(33187, 31429, 12), Position(33242, 31487, 12), Position(33319, 32318, 13)) - item:transform(8912) - end - elseif item.itemid == 8912 then - item:transform(8911) - end - - return true -end - -ferumbrasAscendantRatLever:uid(1030) -ferumbrasAscendantRatLever:register() +local leverLordOfTheLice = BossLever(config) +leverLordOfTheLice:position(Position(33202, 31475, 11)) +leverLordOfTheLice:register() diff --git a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_the_shatterer_lever.lua b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_the_shatterer_lever.lua index 9e061a2f4a4..6782d30c024 100644 --- a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_the_shatterer_lever.lua +++ b/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_the_shatterer_lever.lua @@ -1,56 +1,23 @@ local config = { - centerRoom = Position(33406, 32418, 14), - BossPosition = Position(33406, 32418, 14), + boss = { + name = "The Shatterer", + position = Position(33406, 32418, 14), + }, + timeToFightAgain = 2 * 24 * 60 * 60, playerPositions = { - Position(33403, 32465, 13), - Position(33404, 32465, 13), - Position(33405, 32465, 13), - Position(33406, 32465, 13), - Position(33407, 32465, 13), + { pos = Position(33403, 32465, 13), teleport = Position(33398, 32414, 14) }, + { pos = Position(33404, 32465, 13), teleport = Position(33398, 32414, 14) }, + { pos = Position(33405, 32465, 13), teleport = Position(33398, 32414, 14) }, + { pos = Position(33406, 32465, 13), teleport = Position(33398, 32414, 14) }, + { pos = Position(33407, 32465, 13), teleport = Position(33398, 32414, 14) }, + }, + specPos = { + from = Position(33377, 32390, 14), + to = Position(33446, 32447, 14), }, - newPosition = Position(33398, 32414, 14), + exit = Position(33319, 32318, 13), } -local ferumbrasAscendantTheShattererLever = Action() - -function ferumbrasAscendantTheShattererLever.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if item.itemid == 8912 then - if player:getPosition() ~= Position(33403, 32465, 13) then - item:transform(8911) - return true - end - end - if item.itemid == 8912 then - local playersTable = {} - if player:doCheckBossRoom("The Shatterer", Position(33377, 32390, 14), Position(33446, 32447, 14)) then - local specs, spec = Game.getSpectators(config.centerRoom, false, false, 30, 30, 30, 30) - for i = 1, #specs do - spec = specs[i] - if spec:isPlayer() then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Someone is fighting with The Shatterer.") - return true - end - end - Game.createMonster("The Shatterer", config.BossPosition, true, true) - for x = 33403, 33407 do - local playerTile = Tile(Position(x, 32465, 13)):getTopCreature() - if playerTile and playerTile:isPlayer() then - playerTile:getPosition():sendMagicEffect(CONST_ME_POFF) - playerTile:teleportTo(config.newPosition) - playerTile:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - playerTile:setStorageValue(Storage.Quest.U10_90.FerumbrasAscension.TheShattererTimer, os.time() + 60 * 60 * 2 * 24) - table.insert(playersTable, playerTile:getId()) - end - end - addEvent(kickPlayersAfterTime, 30 * 60 * 1000, playersTable, Position(33377, 32390, 14), Position(33446, 32447, 14), Position(33319, 32318, 13)) - item:transform(8911) - end - elseif item.itemid == 8911 then - item:transform(8912) - end - - return true -end - -ferumbrasAscendantTheShattererLever:uid(1029) -ferumbrasAscendantTheShattererLever:register() +local leverShatterer = BossLever(config) +leverShatterer:position(Position(33402, 32465, 13)) +leverShatterer:register() diff --git a/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua b/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua index fae3fc59794..652a74af84b 100644 --- a/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua +++ b/data-otservbr-global/scripts/quests/soul_war/action-reward_soul_war.lua @@ -26,35 +26,3 @@ end rewardSoulWar:position({ x = 33620, y = 31400, z = 10 }) rewardSoulWar:register() - -local phantasmalJadeMount = Action() - -function phantasmalJadeMount.onUse(player, item, fromPosition, target, toPosition, isHotkey) - local soulWarQuest = player:soulWarQuestKV() - if soulWarQuest:get("panthasmal-jade-mount") then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You already have Phantasmal Jade mount!") - return true - end - - if table.contains({ 34072, 34073, 34074 }, item.itemid) then - if player:getItemCount(34072) >= 4 and player:getItemCount(34073) == 1 and player:getItemCount(34074) == 1 then - player:removeItem(34072, 4) - player:removeItem(34073, 1) - player:removeItem(34074, 1) - player:addMount(167) - player:addAchievement("You got Horse Power") - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You won Phantasmal Jade mount.") - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Congratulations! You won You got Horse Power achievement.") - player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE) - soulWarQuest:set("panthasmal-jade-mount", true) - else - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You don't have the necessary items!") - player:getPosition():sendMagicEffect(CONST_ME_POFF) - end - end - - return true -end - -phantasmalJadeMount:id(34072, 34073, 34074) -phantasmalJadeMount:register() diff --git a/data-otservbr-global/scripts/quests/soul_war/globalevent-ebb_and_flow_change_maps.lua b/data-otservbr-global/scripts/quests/soul_war/globalevent-ebb_and_flow_change_maps.lua index 91273ac4cbd..e5166038db2 100644 --- a/data-otservbr-global/scripts/quests/soul_war/globalevent-ebb_and_flow_change_maps.lua +++ b/data-otservbr-global/scripts/quests/soul_war/globalevent-ebb_and_flow_change_maps.lua @@ -18,17 +18,25 @@ local function updateWaterPoolsSize() end local function loadMapEmpty() - if SoulWarQuest.ebbAndFlow.getZone():countPlayers() > 0 then - local players = SoulWarQuest.ebbAndFlow.getZone():getPlayers() - for _, player in ipairs(players) do - if player:getPosition().z == 8 then - if player:isInBoatSpot() then - local teleportPosition = player:getPosition() - teleportPosition.z = 9 - player:teleportTo(teleportPosition) - logger.trace("Teleporting player to down.") + local playersInZone = SoulWarQuest.ebbAndFlow.getZone():countPlayers() + local monstersInZone = SoulWarQuest.ebbAndFlow.getZone():countMonsters() + if playersInZone > 0 or monstersInZone > 0 then + local creatures = SoulWarQuest.ebbAndFlow.getZone():getCreatures() + for _, creature in ipairs(creatures) do + local creatureMaster = creature:getMaster() + local player = creature:getPlayer() + if creature:isPlayer() or (creature:isMonster() and creatureMaster and creatureMaster:getPlayer()) then + if creature:getPosition().z == 8 then + if creature:isInBoatSpot() then + local teleportPosition = creature:getPosition() + teleportPosition.z = 9 + creature:teleportTo(teleportPosition) + logger.trace("Teleporting player to down.") + end + if player then + player:sendCreatureAppear() + end end - player:sendCreatureAppear() end end end @@ -72,22 +80,30 @@ local function findNearestRoomPosition(playerPosition) end local function loadMapInundate() - if SoulWarQuest.ebbAndFlow.getZone():countPlayers() > 0 then - local players = SoulWarQuest.ebbAndFlow.getZone():getPlayers() - for _, player in ipairs(players) do - local playerPosition = player:getPosition() - if playerPosition.z == 9 then - if player:isInBoatSpot() then - local nearestCenterPosition = findNearestRoomPosition(playerPosition) - player:teleportTo(nearestCenterPosition) - logger.trace("Teleporting player to the near center position room and updating tile.") - else - player:teleportTo(SoulWarQuest.ebbAndFlow.waitPosition) - logger.trace("Teleporting player to wait position and updating tile.") + local playersInZone = SoulWarQuest.ebbAndFlow.getZone():countPlayers() + local monstersInZone = SoulWarQuest.ebbAndFlow.getZone():countMonsters() + if playersInZone > 0 or monstersInZone > 0 then + local creatures = SoulWarQuest.ebbAndFlow.getZone():getCreatures() + for _, creature in ipairs(creatures) do + local creatureMaster = creature:getMaster() + local player = creature:getPlayer() + if creature:isPlayer() or (creature:isMonster() and creatureMaster and creatureMaster:getPlayer()) then + local creaturePosition = creature:getPosition() + if creaturePosition.z == 9 then + if creature:isInBoatSpot() then + local nearestCenterPosition = findNearestRoomPosition(creaturePosition) + creature:teleportTo(nearestCenterPosition) + logger.trace("Teleporting player to the near center position room and updating tile.") + else + creature:teleportTo(SoulWarQuest.ebbAndFlow.waitPosition) + logger.trace("Teleporting player to wait position and updating tile.") + end + creaturePosition:sendMagicEffect(CONST_ME_TELEPORT) + end + if player then + player:sendCreatureAppear() end - playerPosition:sendMagicEffect(CONST_ME_TELEPORT) end - player:sendCreatureAppear() end end diff --git a/data-otservbr-global/scripts/quests/the_first_dragon/actions_lever.lua b/data-otservbr-global/scripts/quests/the_first_dragon/actions_lever.lua index 698ada382b2..ff4c20ff88d 100644 --- a/data-otservbr-global/scripts/quests/the_first_dragon/actions_lever.lua +++ b/data-otservbr-global/scripts/quests/the_first_dragon/actions_lever.lua @@ -1,168 +1,50 @@ -local lever = Action() - local config = { - centerRoom = { x = 33616, y = 31022, z = 14 }, - range = 10, - storage = Storage.Quest.U11_02.TheFirstDragon.FirstDragonTimer, - monsterPosition = { - { position = Position(33574, 31013, 14) }, - { position = Position(33592, 31013, 14) }, - { position = Position(33583, 31022, 14) }, - { position = Position(33574, 31031, 14) }, - { position = Position(33592, 31031, 14) }, + boss = { + name = "spirit of fertility", + position = Position(33625, 31021, 14), }, + timeToFightAgain = 20 * 60 * 60, playerPositions = { - Position(33582, 30993, 14), - Position(33583, 30993, 14), - Position(33584, 30993, 14), - Position(33582, 30994, 14), - Position(33583, 30994, 14), - Position(33584, 30994, 14), - Position(33582, 30995, 14), - Position(33583, 30995, 14), - Position(33584, 30995, 14), - Position(33582, 30996, 14), - Position(33583, 30996, 14), - Position(33584, 30996, 14), - Position(33582, 30997, 14), - Position(33583, 30997, 14), - Position(33584, 30997, 14), - }, - toPosition1 = Position(33574, 31017, 14), - roomTile1 = { - { fromPosition = Position(33582, 30993, 14) }, - { fromPosition = Position(33583, 30993, 14) }, - { fromPosition = Position(33584, 30993, 14) }, - }, - toPosition2 = Position(33592, 31017, 14), - roomTile2 = { - { fromPosition = Position(33582, 30994, 14) }, - { fromPosition = Position(33583, 30994, 14) }, - { fromPosition = Position(33584, 30994, 14) }, - }, - toPosition3 = Position(33592, 31035, 14), - roomTile3 = { - { fromPosition = Position(33582, 30995, 14) }, - { fromPosition = Position(33583, 30995, 14) }, - { fromPosition = Position(33584, 30995, 14) }, - }, - toPosition4 = Position(33574, 31035, 14), - roomTile4 = { - { fromPosition = Position(33582, 30996, 14) }, - { fromPosition = Position(33583, 30996, 14) }, - { fromPosition = Position(33584, 30996, 14) }, - }, - toPosition5 = Position(33583, 31026, 14), - roomTile5 = { - { fromPosition = Position(33582, 30997, 14) }, - { fromPosition = Position(33583, 30997, 14) }, - { fromPosition = Position(33584, 30997, 14) }, - }, - clearArea = { + { pos = Position(33583, 30993, 14), teleport = Position(33592, 31017, 14) }, + { pos = Position(33582, 30993, 14), teleport = Position(33574, 31017, 14) }, + { pos = Position(33584, 30993, 14), teleport = Position(33592, 31035, 14) }, + { pos = Position(33582, 30994, 14), teleport = Position(33574, 31035, 14) }, + { pos = Position(33583, 30994, 14), teleport = Position(33583, 31026, 14) }, + { pos = Position(33584, 30994, 14), teleport = Position(33574, 31017, 14) }, + { pos = Position(33582, 30995, 14), teleport = Position(33592, 31017, 14) }, + { pos = Position(33583, 30995, 14), teleport = Position(33592, 31035, 14) }, + { pos = Position(33584, 30995, 14), teleport = Position(33574, 31035, 14) }, + { pos = Position(33582, 30996, 14), teleport = Position(33583, 31026, 14) }, + { pos = Position(33583, 30996, 14), teleport = Position(33574, 31017, 14) }, + { pos = Position(33584, 30996, 14), teleport = Position(33592, 31017, 14) }, + { pos = Position(33582, 30997, 14), teleport = Position(33592, 31035, 14) }, + { pos = Position(33583, 30997, 14), teleport = Position(33574, 31035, 14) }, + { pos = Position(33584, 30997, 14), teleport = Position(33583, 31026, 14) }, + }, + specPos = { from = Position(33566, 31006, 14), to = Position(33626, 31032, 14), }, -} - -local function clearMonstersInArea(fromPos, toPos) - for z = fromPos.z, toPos.z do - for y = fromPos.y, toPos.y do - for x = fromPos.x, toPos.x do - local tile = Tile(Position(x, y, z)) - if tile then - local creature = tile:getTopCreature() - if creature and creature:isMonster() then - creature:remove() - end - end - end - end - end -end - -local function isRoomOccupied(fromPos, toPos) - for z = fromPos.z, toPos.z do - for y = fromPos.y, toPos.y do - for x = fromPos.x, toPos.x do - local tile = Tile(Position(x, y, z)) - if tile then - local creature = tile:getTopCreature() - if creature and creature:isPlayer() then - return true - end - end - end + monsters = { + { name = "fallen challenger", pos = Position(33592, 31013, 14) }, + { name = "fallen challenger", pos = Position(33583, 31022, 14) }, + { name = "fallen challenger", pos = Position(33574, 31013, 14) }, + { name = "fallen challenger", pos = Position(33574, 31031, 14) }, + { name = "fallen challenger", pos = Position(33592, 31031, 14) }, + { name = "unbeatable dragon", pos = Position(math.random(33610, 33622), math.random(31016, 31030), 14) }, + { name = "unbeatable dragon", pos = Position(math.random(33610, 33622), math.random(31016, 31030), 14) }, + { name = "unbeatable dragon", pos = Position(math.random(33610, 33622), math.random(31016, 31030), 14) }, + { name = "unbeatable dragon", pos = Position(math.random(33610, 33622), math.random(31016, 31030), 14) }, + { name = "unbeatable dragon", pos = Position(math.random(33610, 33622), math.random(31016, 31030), 14) }, + }, + exit = Position(33597, 30994, 14), + onUseExtra = function(creature) + if creature and creature:isPlayer() then + creature:setStorageValue(Storage.Quest.U11_02.TheFirstDragon.SomewhatBeatable, 0) end - end - return false -end - -function lever.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if item.itemid == 8911 then - for i = 1, #config.playerPositions do - local creature = Tile(config.playerPositions[i]):getTopCreature() - if not creature then - item:transform(8912) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need 15 players to fight with this boss.") - return true - end - end - end - - if item.itemid == 8911 then - if isRoomOccupied(config.clearArea.from, config.clearArea.to) then - player:say("Someone is fighting against the boss! You need to wait awhile.", TALKTYPE_MONSTER_SAY) - return true - else - clearMonstersInArea(config.clearArea.from, config.clearArea.to) - end - - for d = 1, 5 do - Game.createMonster("unbeatable dragon", Position(math.random(33610, 33622), math.random(31016, 31030), 14), true, true) - end - for b = 1, #config.monsterPosition do - Game.createMonster("fallen challenger", config.monsterPosition[b].position, true, true) - end - - for i = 1, #config.playerPositions do - local creature = Tile(config.playerPositions[i]):getTopCreature() - if creature then - for i = 1, #config.roomTile1 do - local toRoom1 = Tile(config.roomTile1[i].fromPosition):getTopCreature() - if toRoom1 then - toRoom1:teleportTo(config.toPosition1) - end - local toRoom2 = Tile(config.roomTile2[i].fromPosition):getTopCreature() - if toRoom2 then - toRoom2:teleportTo(config.toPosition2) - end - local toRoom3 = Tile(config.roomTile3[i].fromPosition):getTopCreature() - if toRoom3 then - toRoom3:teleportTo(config.toPosition3) - end - local toRoom4 = Tile(config.roomTile4[i].fromPosition):getTopCreature() - if toRoom4 then - toRoom4:teleportTo(config.toPosition4) - end - local toRoom5 = Tile(config.roomTile5[i].fromPosition):getTopCreature() - if toRoom5 then - toRoom5:teleportTo(config.toPosition5) - end - end - creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - creature:setStorageValue(config.storage, os.time() + 20 * 3600) - creature:setStorageValue(Storage.Quest.U11_02.TheFirstDragon.SomewhatBeatable, 0) - end - end - - addEvent(clearRoom, 60 * 60 * 1000, Position(33583, 31022, 14), 50, 50, config.storage) - Game.createMonster("spirit of fertility", Position(33625, 31021, 14), true, true) - item:transform(8912) - elseif item.itemid == 8912 then - item:transform(8911) - end - return true -end + end, +} -lever:uid(30003) -lever:register() +local leverFirstDragon = BossLever(config) +leverFirstDragon:position(Position(33583, 30992, 14)) +leverFirstDragon:register() diff --git a/data-otservbr-global/scripts/quests/the_hidden_city_of_beregar/actions_ladder.lua b/data-otservbr-global/scripts/quests/the_hidden_city_of_beregar/actions_ladder.lua index 5260bc4469a..83074b595e3 100644 --- a/data-otservbr-global/scripts/quests/the_hidden_city_of_beregar/actions_ladder.lua +++ b/data-otservbr-global/scripts/quests/the_hidden_city_of_beregar/actions_ladder.lua @@ -1,7 +1,7 @@ local dwarvenLadder = Action() function dwarvenLadder.onUse(player, item, fromPosition, itemEx, toPosition) if player:getStorageValue(Storage.DwarvenLegs) < 1 then - player:teleportTo({ x = 32681, y = 31507, z = 10 }) + player:teleportTo({ x = 32681, y = 31507, z = 10 }, true) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) return true else diff --git a/data-otservbr-global/scripts/quests/the_secret_library_quest/liquid_death/actions_brokulLever.lua b/data-otservbr-global/scripts/quests/the_secret_library_quest/liquid_death/actions_brokulLever.lua index 2cab34c6e48..89c8ac4c479 100644 --- a/data-otservbr-global/scripts/quests/the_secret_library_quest/liquid_death/actions_brokulLever.lua +++ b/data-otservbr-global/scripts/quests/the_secret_library_quest/liquid_death/actions_brokulLever.lua @@ -1,113 +1,32 @@ -local transform = { - [2772] = 2773, - [2773] = 2772, -} - -local leverInfo = { - [1] = { - bossName = "Brokul", - bossPosition = Position(33483, 31437, 15), - leverPosition = Position(33522, 31464, 15), - pushPosition = Position(33522, 31465, 15), - leverFromPos = Position(33520, 31465, 15), - leverToPos = Position(33524, 31465, 15), - storageTimer = Storage.Quest.U11_80.TheSecretLibrary.LiquidDeath.BrokulTimer, - teleportTo = Position(33484, 31446, 15), - globalTimer = Storage.Quest.U11_80.TheSecretLibrary.LiquidDeath.BrokulTimerGlobal, - roomFromPosition = Position(33472, 31427, 15), - roomToPosition = Position(33496, 31450, 15), - exitPosition = Position(33528, 31464, 14), +local config = { + boss = { + name = "Brokul", + position = Position(33483, 31437, 15), }, -} - -local function clearBossRoom(fromPos, toPos) - local spectators = Game.getSpectators(fromPos, false, false, 0, 0, 0, 0, toPos) - for _, spec in pairs(spectators) do - if not spec:isPlayer() then - spec:remove() - end - end -end - -local function isBossInRoom(fromPos, toPos, bossName) - local hasBoss = false - local hasPlayers = false - local spectators = Game.getSpectators(fromPos, false, false, 0, 0, 0, 0, toPos) - - for _, spec in pairs(spectators) do - if spec:isPlayer() then - hasPlayers = true - elseif spec:isMonster() and spec:getName():lower() == bossName:lower() then - hasBoss = true - end - end - - return hasBoss, hasPlayers -end - -local actions_liquid_brokulLever = Action() - -function actions_liquid_brokulLever.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if not player then - return true - end - - local playersTable = {} - local iPos = item:getPosition() - local pPos = player:getPosition() - - if item.itemid == 2772 then - for i = 1, #leverInfo do - if iPos == leverInfo[i].leverPosition then - local leverTable = leverInfo[i] - if pPos == leverTable.pushPosition then - local hasBoss, hasPlayers = isBossInRoom(leverTable.roomFromPosition, leverTable.roomToPosition, leverTable.bossName) - - if hasPlayers then - player:sendCancelMessage("The room is already occupied by other players.") - return true - elseif hasBoss then - clearBossRoom(leverTable.roomFromPosition, leverTable.roomToPosition) - end - - local playerCount = 0 - for i = leverTable.leverFromPos.x, leverTable.leverToPos.x do - local newPos = Position(i, leverTable.leverFromPos.y, leverTable.leverFromPos.z) - local creature = Tile(newPos):getTopCreature() - if creature and creature:isPlayer() then - if creature:getStorageValue(Storage.Quest.U11_80.TheSecretLibrary.LiquidDeath.Questline) >= 6 then - playerCount = playerCount + 1 - table.insert(playersTable, creature:getId()) - else - creature:sendCancelMessage("You are not qualified to face the boss.") - end - end - end - - if playerCount < 5 then - player:sendCancelMessage("You need 5 qualified players for this challenge.") - return true - end - - for _, playerId in ipairs(playersTable) do - local creature = Creature(playerId) - if creature then - creature:setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.LiquidDeath.BrokulTimer, os.time() + 20 * 60 * 60) - creature:teleportTo(leverTable.teleportTo, true) - creature:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - end - end - - local monster = Game.createMonster(leverTable.bossName, leverTable.bossPosition) - addEvent(kickPlayersAfterTime, 30 * 60 * 1000, playersTable, leverTable.roomFromPosition, leverTable.roomToPosition, leverTable.exitPosition) - end + timeToFightAgain = 20 * 60 * 60, + minPlayers = 5, + playerPositions = { + { pos = Position(33522, 31465, 15), teleport = Position(33484, 31446, 15) }, + { pos = Position(33520, 31465, 15), teleport = Position(33484, 31446, 15) }, + { pos = Position(33521, 31465, 15), teleport = Position(33484, 31446, 15) }, + { pos = Position(33523, 31465, 15), teleport = Position(33484, 31446, 15) }, + { pos = Position(33524, 31465, 15), teleport = Position(33484, 31446, 15) }, + }, + specPos = { + from = Position(33472, 31427, 15), + to = Position(33496, 31450, 15), + }, + exit = Position(33528, 31464, 14), + onUseExtra = function(creature, infoPositions) + if creature and creature:isPlayer() then + if creature:getStorageValue(Storage.Quest.U11_80.TheSecretLibrary.LiquidDeath.Questline) >= 6 then + return true end + return false end - end - - item:transform(transform[item.itemid]) - return true -end + end, +} -actions_liquid_brokulLever:aid(4901) -actions_liquid_brokulLever:register() +local leverBrokul = BossLever(config) +leverBrokul:aid(34000) +leverBrokul:register() diff --git a/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/actions_oberonLever.lua b/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/actions_oberonLever.lua index c6e6841f714..e736be79de5 100644 --- a/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/actions_oberonLever.lua +++ b/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/actions_oberonLever.lua @@ -1,39 +1,26 @@ -local actions_falcon_oberon_lever = Action() +local config = { + boss = { + name = "Grand Master Oberon", + createFunction = function() + Game.createMonster("Grand Master Oberon", Position(33365, 31318, 9), true, true):setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.FalconBastion.OberonHeal, 0) + return true + end, + }, + timeToFightAgain = 20 * 60 * 60, + playerPositions = { + { pos = Position(33364, 31344, 9), teleport = Position(33364, 31322, 9) }, + { pos = Position(33362, 31344, 9), teleport = Position(33364, 31322, 9) }, + { pos = Position(33363, 31344, 9), teleport = Position(33364, 31322, 9) }, + { pos = Position(33365, 31344, 9), teleport = Position(33364, 31322, 9) }, + { pos = Position(33366, 31344, 9), teleport = Position(33364, 31322, 9) }, + }, + specPos = { + from = Position(33356, 31311, 9), + to = Position(33376, 31328, 9), + }, + exit = Position(33297, 31285, 9), +} -function actions_falcon_oberon_lever.onUse(player, item, fromPosition, itemEx, toPosition) - local bossName = "Grand Master Oberon" - local playersTable = {} - local fromPosition_ = Position(33356, 31311, 9) - local toPosition_ = Position(33376, 31328, 9) - local exitPosition = Position(33297, 31285, 9) - - if item:getId() == 2772 then - if doCheckBossRoom(player:getId(), bossName, fromPosition_, toPosition_) then - for i = 33362, 33366, 1 do - local newpos = Position(i, 31344, 9) - local nplayer = Tile(newpos):getTopCreature() - if nplayer and nplayer:isPlayer() then - nplayer:teleportTo(Position(33364, 31322, 9), true) - nplayer:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - table.insert(playersTable, nplayer:getId()) - nplayer:setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.FalconBastion.OberonTimer, os.time() + 20 * 60 * 60) - end - end - local oberon = Game.createMonster("Grand Master Oberon", Position(33365, 31318, 9)) - if oberon then - oberon:setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.FalconBastion.OberonHeal, 0) - end - Game.setStorageValue(Storage.Quest.U11_80.TheSecretLibrary.FalconBastion.OberonSay, -1) - Game.createNpc("Oberon's Spite", Position(33361, 31320, 9)) - Game.createNpc("Oberon's Ire", Position(33367, 31320, 9)) - Game.createNpc("Oberon's Bile", Position(33361, 31316, 9)) - Game.createNpc("Oberon's Hate", Position(33367, 31316, 9)) - addEvent(kickPlayersAfterTime, 30 * 60 * 1000, playersTable, fromPosition_, toPosition_, exitPosition) - end - end - - return true -end - -actions_falcon_oberon_lever:aid(4922) -actions_falcon_oberon_lever:register() +local leverOberon = BossLever(config) +leverOberon:aid(57605) +leverOberon:register() diff --git a/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/movements_bossEntrance.lua b/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/movements_bossEntrance.lua index 0f000b94e7c..f6068da667b 100644 --- a/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/movements_bossEntrance.lua +++ b/data-otservbr-global/scripts/quests/the_secret_library_quest/the_order_of_the_falcon/movements_bossEntrance.lua @@ -36,7 +36,7 @@ function movements_falcon_bossEntrance.onStepIn(creature, item, position, fromPo if isInArray(blockedPositions, position) then return true else - if creature:getStorageValue(Storage.Quest.U11_80.TheSecretLibrary.FalconBastion.OberonTimer) <= os.time() then + if creature:canFightBoss("Grand Master Oberon") then creature:teleportTo(Position(33363, 31341, 9), true) else creature:teleportTo(fromPosition, true) diff --git a/data-otservbr-global/scripts/world_changes/iron_servant_transformation.lua b/data-otservbr-global/scripts/world_changes/iron_servant_transformation.lua deleted file mode 100644 index e62cd23c876..00000000000 --- a/data-otservbr-global/scripts/world_changes/iron_servant_transformation.lua +++ /dev/null @@ -1,31 +0,0 @@ -local ironServantTransformation = EventCallback("IronServantTransformationOnSpawn") - -ironServantTransformation.monsterOnSpawn = function(monster, position) - if monster:getName():lower() ~= "iron servant replica" then - return - end - - local chance = math.random(100) - if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismDiamond) >= 1 and Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismGolden) >= 1 then - if chance > 30 then - local monsterType = math.random(2) == 1 and "diamond servant replica" or "golden servant replica" - Game.createMonster(monsterType, monster:getPosition(), false, true) - monster:remove() - end - return - end - - if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismDiamond) >= 1 and chance > 30 then - Game.createMonster("diamond servant replica", monster:getPosition(), false, true) - monster:remove() - return - end - - if Game.getStorageValue(Storage.Quest.U11_02.ForgottenKnowledge.MechanismGolden) >= 1 and chance > 30 then - Game.createMonster("golden servant replica", monster:getPosition(), false, true) - monster:remove() - end - return true -end - -ironServantTransformation:register() diff --git a/data-otservbr-global/startup/tables/lever.lua b/data-otservbr-global/startup/tables/lever.lua index e7db97ab859..ab887209866 100644 --- a/data-otservbr-global/startup/tables/lever.lua +++ b/data-otservbr-global/startup/tables/lever.lua @@ -16,12 +16,6 @@ LeverAction = { }, }, -- The Secret Library Quest - [4901] = { - itemId = 2772, - itemPos = { - { x = 33522, y = 31464, z = 15 }, - }, - }, [4906] = { itemId = false, itemPos = { @@ -29,12 +23,6 @@ LeverAction = { { x = 33218, y = 32096, z = 10 }, }, }, - [4922] = { - itemId = 2772, - itemPos = { - { x = 33364, y = 31343, z = 9 }, - }, - }, -- Cults of Tibia Quest [5500] = { itemId = 8911, @@ -315,10 +303,6 @@ LeverUnique = { itemPos = { x = 33172, y = 31896, z = 8 }, }, -- Ferumbras' Ascension Quest - [1021] = { - itemId = 8911, - itemPos = { x = 33270, y = 31476, z = 14 }, - }, [1022] = { itemId = 8911, itemPos = { x = 33229, y = 31499, z = 13 }, @@ -547,12 +531,6 @@ LeverUnique = { itemId = 2773, itemPos = { x = 33582, y = 31844, z = 10 }, }, - -- The first dragon quest lever - -- Path: data\scripts\actions\quests\first_dragon\lever.lua - [30003] = { - itemId = 8911, - itemPos = { x = 33583, y = 30992, z = 14 }, - }, -- Thais lighthouse quest -- Path: data\scripts\quests\thais_lighthouse\action-lever.lua [30004] = { diff --git a/data-otservbr-global/startup/tables/writeable.lua b/data-otservbr-global/startup/tables/writeable.lua index 226fe46c3b7..538fccdf72a 100644 --- a/data-otservbr-global/startup/tables/writeable.lua +++ b/data-otservbr-global/startup/tables/writeable.lua @@ -132,7 +132,6 @@ Nobody knows where the elder gods came from, or whether they had always existed Uman Zathroth regarded Fardos's undertakings thoughtfully. Uman was sagacious and held awesome magical powers. Most importantly, however, he was driven by an insatiable hunger for knowledge and enlightenment. In his essence he resembled Fardos, but where Fardos worked openly and logically, Uman's domain was the realm of mystery. Still, he shared Fardos's interest in creation, whereas his dark half Zathroth was essentially corruptive. Zathroth was a vain god who was painfully aware that his own creative powers were poor. Because of this he looked at Fardos's work of creation with jealousy, and from the very beginning he was determined to prevent or at least corrupt it in any way he could. Fardos, who did not suspect this, asked him for assistance because he had accepted the fact that he could not achieve creation on his own, but of course Zathroth denied. Uman, however, agreed to help. And from that he and Fardos worked together on the great project that was creation. - Unfortunately, their combined efforts were hardly more successful. Just like before, everything Fardos and Uman created was swallowed by the void as soon as it came into existence, and the two gods sadly saw their creation run through their fingers like water through a sieve. On the other hand, Zathroth, who had been watching their efforts with suspicion, rejoiced. He ridiculed their efforts. However, his glee changed into surprise and anger when he found that something strange happened, something which perhaps Uman and Fardos did not expect themselves. To this day, nobody knows precisely what it was that caused it. Perhaps the power that had been spent lured another entity out of the void, or it might be that it simply awoke another divine entity from its slumber. Some even claim that in some mysterious way the power that had been spent by Uman and Fardos actually created a new entity. Whatever the truth may be, a new goddess stepped out of the void like a new-born mermaid from her shell. The amazed elder gods watched her divine beauty in awed admiration, for everything in her was perfect harmony. They agreed to call her Tibiasula. Zathroth, however, stood by and fumed with silent hate. But cunning as he was, he hid his resentment well and feigned to share the joy of the other elder gods. ]], }, @@ -147,7 +146,6 @@ Zathroth watched the progress of creation with wrath and disgust. If he had had As he grew up, Brog was pained by the fire burning inside him, until one day when it grew unbearable he summoned all his magical powers and released as much of the painful flame into the world as he could. The searing fire mixed with his rage, and from it rose Garsharak, the very first dragon, who later sired a whole race of intelligent, giant lizards, a race that would eventually bring terror and chaos into Tibia. Brog watched the terrible creature he had created rather accidentally, and he rejoiced when he saw just how fierce and powerful it was. Though he was rather stupid he, too, had the gift to create life, which in an act of vanity he next used to create the cyclopes in his own image. - Zathroth watched Brog's experiments with great interest. So far he had not held his son in high esteem, but here was something for which he himself admittedly had little talent for. Since he did not understand the laws of life himself he knew that Brog's gift could prove to be a great asset. He called his son to him and told him to go on with his experiments, urging him to create something more terrifying and destructive than cyclopes. Even though these giants were ferocious and strong, they were not quite as destructive as he wanted them to be. In fact, due to their love of mining and smithing the cyclopes were a creative rather than a destructive race. Worse, they were not propagating fast enough to make them a real threat to creation. For this reason Brog went on to create trolls and goblins, races that were weaker than the cyclopes, but propagated much faster. However, his undisputed masterpiece were the orcs, a race of fearsome, single-minded warriors who lived only to expand and conquer. Soon they had spread all over Tibia, and they were the scourge of all that was alive. ]], }, @@ -723,7 +721,6 @@ Thoughts and Notations on the Noble Craft of Potion-Making, by Grandsieur Haruva The Gods gave their gifts freely, but bestowed them not on all creatures alike. Some ancient creatures were possessed of a far-reaching will to conquer and subdue all others through their thoughts alone, while the newer beings could weave magic in defense or had strength and swiftness to defend and escape the wiles laid out to ensnare them. Some animals and plants, simple though they may seem to us, yet are deadly poisonous in order to ward off their hunter. - But only the more intelligent beings - and of those, only a select few - possess the art of making powerful concoctions that enhance their faculties. The humble woodman or wanderer will never be able to fulfil the complex rites, or even grasp the concept, of the trimagical umbralistic principle of the equinox formula that is crucial to the craft of magical potions. But still, they can drink, and appreciate, the brews we make to keep a warrior's body alive in a fight, the mage's mana when drained, the paladin's spirit when they need to gather holy force. ... (you lose interest and close the book) @@ -742,7 +739,6 @@ The cyclops ... ... hid the ancient amulet beneath the sand, before ...should have listened to ... Must hide... paper, hope an adventurer will... - ... amulet will be washed ashore if not found... To any adventurer friend: ... shovel... beach... .. dig there. ... take it to Morris, maybe he ... decipher the engravings. diff --git a/data/events/scripts/player.lua b/data/events/scripts/player.lua index 78653733b58..c526553132d 100644 --- a/data/events/scripts/player.lua +++ b/data/events/scripts/player.lua @@ -315,7 +315,8 @@ function Player:onMoveItem(item, count, fromPosition, toPosition, fromCylinder, end -- Reward System - if toPosition.x == CONTAINER_POSITION then + local containerThing = tile and tile:getItemByType(ITEM_TYPE_CONTAINER) + if containerThing and toPosition.x == CONTAINER_POSITION then local containerId = toPosition.y - 64 local container = self:getContainerById(containerId) if not container then diff --git a/data/items/items.xml b/data/items/items.xml index eb00ac6bdf3..c1b8e8a63ba 100644 --- a/data/items/items.xml +++ b/data/items/items.xml @@ -4435,6 +4435,9 @@ + + + @@ -76427,5 +76430,3305 @@ Granted by TibiaGoals.com"/> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/data/libs/compat/compat.lua b/data/libs/compat/compat.lua index 061d1dbe47e..ed1a229a826 100644 --- a/data/libs/compat/compat.lua +++ b/data/libs/compat/compat.lua @@ -572,8 +572,8 @@ function isPremium(cid) return p ~= nil and p:isPremium() or false end -function getBlessingsCost(level, byCommand) - return Blessings.getBlessingsCost(level, byCommand) +function getBlessingCost(level, byCommand, blessId) + return Blessings.getBlessingCost(level, byCommand, blessId) end function getPvpBlessingCost(level, byCommand) @@ -618,18 +618,7 @@ function getPlayerGUIDByName(name) end function getAccountNumberByPlayerName(name) - local player = Player(name) - if player then - return player:getAccountId() - end - - local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) - if resultId ~= false then - local accountId = Result.getNumber(resultId, "account_id") - Result.free(resultId) - return accountId - end - return 0 + return Game.getPlayerAccountId(name) end getPlayerAccountBalance = getPlayerBalance diff --git a/data/libs/functions/boss_lever.lua b/data/libs/functions/boss_lever.lua index da3b81d3704..ae8a89d0e54 100644 --- a/data/libs/functions/boss_lever.lua +++ b/data/libs/functions/boss_lever.lua @@ -4,6 +4,7 @@ ---@field private createBoss function ---@field private timeToFightAgain number ---@field private timeToDefeat number +---@field private minPlayers number ---@field private timeAfterKill number ---@field private requiredLevel number ---@field private disabled boolean @@ -29,6 +30,7 @@ local config = { } requiredLevel = 250, timeToFightAgain = 10 * 60 * 60, -- In seconds + minPlayers = 4, playerPositions = { { pos = Position(33638, 32562, 13), teleport = Position(33617, 32567, 13) }, { pos = Position(33639, 32562, 13), teleport = Position(33617, 32567, 13) }, @@ -40,7 +42,7 @@ local config = { from = Position(33607, 32553, 13), to = Position(33627, 32570, 13) }, - onUseExtra = function(player) + onUseExtra = function(player, infoPositions) player:teleportTo(Position(33618, 32523, 15)) player:getPosition():sendMagicEffect(CONST_ME_TELEPORT) end, @@ -56,7 +58,7 @@ setmetatable(BossLever, { error("BossLever: boss is required") end return setmetatable({ - name = boss.name, + name = boss.name:lower(), encounter = config.encounter, bossPosition = boss.position, timeToFightAgain = config.timeToFightAgain or configManager.getNumber(configKeys.BOSS_DEFAULT_TIME_TO_FIGHT_AGAIN), @@ -65,6 +67,7 @@ setmetatable(BossLever, { requiredLevel = config.requiredLevel or 0, createBoss = boss.createFunction, disabled = config.disabled, + minPlayers = config.minPlayers or 1, playerPositions = config.playerPositions, onUseExtra = config.onUseExtra or function() end, exitTeleporter = config.exitTeleporter, @@ -146,22 +149,10 @@ end function BossLever:onUse(player) local monsterName = MonsterType(self.name):getName() local isParticipant = false - local players = {} - - for i = 1, #self.playerPositions do - local pos = self.playerPositions[i].pos - local creature = Tile(pos):getTopCreature() - - if not creature or not creature:isPlayer() then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need " .. #self.playerPositions .. " players to challenge " .. self.name .. ".") - return true - end - - if pos == player:getPosition() then + for _, v in ipairs(self.playerPositions) do + if Position(v.pos) == player:getPosition() then isParticipant = true end - - table.insert(players, creature) end if not isParticipant then return false @@ -186,7 +177,7 @@ function BossLever:onUse(player) return true end - local isAccountNormal = creature:getAccountType() == ACCOUNT_TYPE_NORMAL + local isAccountNormal = creature:getAccountType() < ACCOUNT_TYPE_GAMEMASTER if isAccountNormal and creature:getLevel() < self.requiredLevel then local message = "All players need to be level " .. self.requiredLevel .. " or higher." creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, message) @@ -194,8 +185,8 @@ function BossLever:onUse(player) return false end + local infoPositions = lever:getInfoPositions() if creature:getGroup():getId() < GROUP_TYPE_GOD and isAccountNormal and self:lastEncounterTime(creature) > os.time() then - local infoPositions = lever:getInfoPositions() for _, posInfo in pairs(infoPositions) do local currentPlayer = posInfo.creature if currentPlayer then @@ -218,11 +209,18 @@ function BossLever:onUse(player) return false end - self.onUseExtra(creature) - return true + return self.onUseExtra(creature, infoPositions) ~= false end) lever:checkPositions() + if #lever:getPlayers() < self.minPlayers then + lever:executeOnPlayers(function(creature) + local message = string.format("You need %d qualified players for this challenge.", self.minPlayers) + creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, message) + creature:getPosition():sendMagicEffect(CONST_ME_POFF) + end) + return false + end if lever:checkConditions() then zone:removeMonsters() for _, monster in pairs(self.monsters) do diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 2327a1cf937..4b9a94968ca 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -110,21 +110,6 @@ function getRateFromTable(t, level, default) return default end -function getAccountNumberByPlayerName(name) - local player = Player(name) - if player ~= nil then - return player:getAccountId() - end - - local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) - if resultId ~= false then - local accountId = Result.getNumber(resultId, "account_id") - Result.free(resultId) - return accountId - end - return 0 -end - function getMoneyCount(string) local b, e = string:find("%d+") local money = b and e and tonumber(string:sub(b, e)) or -1 diff --git a/data/libs/functions/game.lua b/data/libs/functions/game.lua index a7c7f7617ce..ae13f50038a 100644 --- a/data/libs/functions/game.lua +++ b/data/libs/functions/game.lua @@ -167,3 +167,18 @@ function Game.getTimeInWords(seconds) end return timeStr end + +function Game.getPlayerAccountId(name) + local player = Player(name) + if player then + return player:getAccountId() + end + + local resultId = db.storeQuery("SELECT `account_id` FROM `players` WHERE `name` = " .. db.escapeString(name)) + if resultId then + local accountId = result.getNumber(resultId, "account_id") + result.free(resultId) + return accountId + end + return 0 +end diff --git a/data/libs/functions/lever.lua b/data/libs/functions/lever.lua index 54e6e5c4915..39802af49d2 100644 --- a/data/libs/functions/lever.lua +++ b/data/libs/functions/lever.lua @@ -5,6 +5,7 @@ setmetatable(Lever, { local lever_data = { positions = {}, info_positions = nil, + players = {}, condition = function() return true end, @@ -51,6 +52,19 @@ function Lever.getInfoPositions(self) return self.info_positions end +---@return table +function Lever.getPlayers(self) + return self.players +end + +---@param player Player +---@return nil +function Lever.addPlayer(self, player) + if player and player:isPlayer() then + table.insert(self.players, player) + end +end + --[[ lever:setCondition(function(creature)) @@ -109,6 +123,7 @@ function Lever:checkPositions() local ground = tile:getGround() local actionID = ground:getActionId() local uniqueID = ground:getUniqueId() + self:addPlayer(creature) table.insert(array, { tile = tile, creature = creature, @@ -140,6 +155,12 @@ function Lever.checkConditions(self) -- It will check the conditions defined in return true end +function Lever.executeOnPlayers(self, func) + for _, player in pairs(self:getPlayers()) do + func(player) + end +end + ---@return nil function Lever.teleportPlayers(self) -- It will teleport all players to the positions defined in setPositions() local info = self:getInfoPositions() diff --git a/data/libs/functions/player.lua b/data/libs/functions/player.lua index 3f7c8e17b75..0350310e397 100644 --- a/data/libs/functions/player.lua +++ b/data/libs/functions/player.lua @@ -459,17 +459,6 @@ function Player.getSubjectVerb(self, past) return Pronouns.getPlayerSubjectVerb(self:getPronoun(), past) end -function Player.findItemInInbox(self, itemId) - local inbox = self:getStoreInbox() - local items = inbox:getItems() - for _, item in pairs(items) do - if item:getId() == itemId then - return item - end - end - return nil -end - function Player.updateHazard(self) local zones = self:getZones() if not zones or #zones == 0 then @@ -618,28 +607,6 @@ function Player:setFiendish() return false end -function Player:findItemInInbox(itemId, name) - local inbox = self:getStoreInbox() - local items = inbox:getItems() - for _, item in pairs(items) do - if item:getId() == itemId and (not name or item:getName() == name) then - return item - end - end - return nil -end - -function Player:sendColoredMessage(message) - local grey = 3003 - local blue = 3043 - local green = 3415 - local purple = 36792 - local yellow = 34021 - - local msg = message:gsub("{grey|", "{" .. grey .. "|"):gsub("{blue|", "{" .. blue .. "|"):gsub("{green|", "{" .. green .. "|"):gsub("{purple|", "{" .. purple .. "|"):gsub("{yellow|", "{" .. yellow .. "|") - return self:sendTextMessage(MESSAGE_LOOT, msg) -end - function Player:showInfoModal(title, message, buttonText) local modal = ModalWindow({ title = title, @@ -746,15 +713,6 @@ function Player.getNextRewardTime(self) return math.max(self:getStorageValue(DailyReward.storages.nextRewardTime), 0) end -function Player.isRestingAreaBonusActive(self) - local levelStreak = self:getStreakLevel() - if levelStreak > 1 then - return true - else - return false - end -end - function Player.getActiveDailyRewardBonusesName(self) local msg = "" local streakLevel = self:getStreakLevel() @@ -846,45 +804,6 @@ function Player.inBossFight(self) return false end --- For use of data/events/scripts/player.lua -function Player:executeRewardEvents(item, toPosition) - if toPosition.x == CONTAINER_POSITION then - local containerId = toPosition.y - 64 - local container = self:getContainerById(containerId) - if not container then - return true - end - - -- Do not let the player insert items into either the Reward Container or the Reward Chest - local itemId = container:getId() - if itemId == ITEM_REWARD_CONTAINER or itemId == ITEM_REWARD_CHEST then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - - -- The player also shouldn't be able to insert items into the boss corpse - local tileCorpse = Tile(container:getPosition()) - for index, value in ipairs(tileCorpse:getItems() or {}) do - if value:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 and value:getName() == container:getName() then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - end - end - -- Do not let the player move the boss corpse. - if item:getAttribute(ITEM_ATTRIBUTE_CORPSEOWNER) == 2 ^ 31 - 1 then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - return false - end - -- Players cannot throw items on reward chest - local tileChest = Tile(toPosition) - if tileChest and tileChest:getItemById(ITEM_REWARD_CHEST) then - self:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE) - self:getPosition():sendMagicEffect(CONST_ME_POFF) - return false - end -end - do local loyaltySystem = { enable = configManager.getBoolean(configKeys.LOYALTY_ENABLED), @@ -1009,3 +928,15 @@ function Player.getMarkdownLink(self) return string.format("**[%s](%s)** %s [_%s_]", self:getName(), playerURL, emoji, vocation) end + +function Player.findItemInInbox(self, itemId, name) + local inbox = self:getStoreInbox() + local items = inbox:getItems() + + for _, item in pairs(items) do + if item:getId() == itemId and (not name or item:getName() == name) then + return item + end + end + return nil +end diff --git a/data/modules/scripts/blessings/blessings.lua b/data/libs/systems/blessing.lua similarity index 50% rename from data/modules/scripts/blessings/blessings.lua rename to data/libs/systems/blessing.lua index e061501a330..f5403fbb07b 100644 --- a/data/modules/scripts/blessings/blessings.lua +++ b/data/libs/systems/blessing.lua @@ -6,29 +6,44 @@ Blessings.Credits = { lastUpdate = "08/04/2020", todo = { "Insert & Select query in blessings_history", - "Add unfair fight reductio (convert the get killer is pvp fight with getDamageMap of dead player)", - "Gamestore buy blessing", - "Test ank print text", - "Test all functions", - "Test henricus prices/blessings", - "Add data \\movements\\scripts\\quests\\cults of tibia\\icedeath.lua blessing information", - "WotE data\\movements\\scripts\\quests\\wrath of the emperor\\realmTeleport.lua has line checking if player has bless 1??? wtf", - "add blessings module support npc\\lib\\npcsystem\\modules.lua", - "Fix store buying bless", - "Check if store is inside lua or source...", }, } Blessings.Config = { AdventurerBlessingLevel = configManager.getNumber(configKeys.ADVENTURERSBLESSING_LEVEL), -- Free full bless until level HasToF = not configManager.getBoolean(configKeys.TOGGLE_SERVER_IS_RETRO), -- Enables/disables twist of fate - InquisitonBlessPriceMultiplier = 1.1, -- Bless price multiplied by henricus + InquisitonBlessPriceMultiplier = 1.1, -- Bless price multiplier by henricus SkulledDeathLoseStoreItem = configManager.getBoolean(configKeys.SKULLED_DEATH_LOSE_STORE_ITEM), -- Destroy all items on store when dying with red/blackskull - InventoryGlowOnFiveBless = configManager.getBoolean(configKeys.INVENTORY_GLOW), -- Glow in yellow inventory items when the player has 5 or more bless, - Debug = false, -- Prin debug messages in console if enabled } -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/assets.lua") +Blessings.Types = { + REGULAR = 1, + ENHANCED = 2, + PvP = 3, +} + +Blessings.All = { + [1] = { id = 1, name = "Twist of Fate", type = Blessings.Types.PvP }, + [2] = { id = 2, name = "The Wisdom of Solitude", charm = 10345, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, + [3] = { id = 3, name = "The Spark of the Phoenix", charm = 10341, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, + [4] = { id = 4, name = "The Fire of the Suns", charm = 10344, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, + [5] = { id = 5, name = "The Spiritual Shielding", charm = 10343, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, + [6] = { id = 6, name = "The Embrace of Tibia", charm = 10342, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, + [7] = { id = 7, name = "Heart of the Mountain", charm = 25360, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false }, + [8] = { id = 8, name = "Blood of the Mountain", charm = 25361, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false }, +} + +Blessings.LossPercent = { + [0] = { item = 100, skill = 0 }, + [1] = { item = 70, skill = 8 }, + [2] = { item = 45, skill = 16 }, + [3] = { item = 25, skill = 24 }, + [4] = { item = 10, skill = 32 }, + [5] = { item = 0, skill = 40 }, + [6] = { item = 0, skill = 48 }, + [7] = { item = 0, skill = 56 }, + [8] = { item = 0, skill = 56 }, +} --[=====[ -- @@ -45,9 +60,6 @@ CREATE TABLE IF NOT EXISTS `blessings_history` ( --]=====] Blessings.DebugPrint = function(content, pre, pos) - if not Blessings.Config.Debug then - return - end if pre == nil then pre = "" else @@ -67,145 +79,93 @@ Blessings.DebugPrint = function(content, pre, pos) end end -Blessings.C_Packet = { - OpenWindow = 0xCF, -} - -Blessings.S_Packet = { - BlessDialog = 0x9B, - BlessStatus = 0x9C, -} - -function onRecvbyte(player, msg, byte) - if byte == Blessings.C_Packet.OpenWindow then - Blessings.sendBlessDialog(player) - end -end - -Blessings.sendBlessStatus = function(player, curBless) - if player:getClient().version < 1200 then - return true - end - - -- why not using ProtocolGame::sendBlessStatus ? - local msg = NetworkMessage() - msg:addByte(Blessings.S_Packet.BlessStatus) - callback = function(k) - return true - end - if curBless == nil then - curBless = player:getBlessings(callback) -- ex: {1, 2, 5, 7} - end - Blessings.DebugPrint(#curBless, "sendBlessStatus curBless") - local bitWiseCurrentBless = 0 - local blessCount = 0 +Blessings.PlayerDeath = function(player, corpse, killer) + local hasAol = (player:getSlotItem(CONST_SLOT_NECKLACE) and player:getSlotItem(CONST_SLOT_NECKLACE):getId() == ITEM_AMULETOFLOSS) + local hasSkull = table.contains({ SKULL_RED, SKULL_BLACK }, player:getSkull()) + local currBlessCount = player:getBlessings() - for i = 1, #curBless do - if curBless[i].losscount then - blessCount = blessCount + 1 - end - if (not curBless[i].losscount and Blessings.Config.HasToF) or curBless[i].losscount then - bitWiseCurrentBless = bit.bor(bitWiseCurrentBless, Blessings.BitWiseTable[curBless[i].id]) - end + if hasSkull then + Blessings.DropLoot(player, corpse, 100, true) + elseif #currBlessCount < 5 and not hasAol then + local equipLossChance = Blessings.LossPercent[#currBlessCount].item + Blessings.DropLoot(player, corpse, equipLossChance) end - if blessCount > 5 and Blessings.Config.InventoryGlowOnFiveBless then - bitWiseCurrentBless = bit.bor(bitWiseCurrentBless, 1) + if not player:getSlotItem(CONST_SLOT_BACKPACK) then + player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK) end - msg:addU16(bitWiseCurrentBless) - msg:addByte(blessCount >= 7 and 3 or (blessCount > 0 and 2 or 1)) -- Bless dialog button colour 1 = Disabled | 2 = normal | 3 = green - - -- if #curBless >= 5 then - -- msg:addU16(1) -- TODO ? - -- else - -- msg:addU16(0) - -- end - - msg:sendToPlayer(player) + return true end -Blessings.sendBlessDialog = function(player) - -- TODO: Migrate to protocolgame.cpp - local msg = NetworkMessage() - msg:addByte(Blessings.S_Packet.BlessDialog) +Blessings.DropLoot = function(player, corpse, chance, skulled) + local multiplier = 100 + math.randomseed(os.time()) + chance = chance * multiplier + Blessings.DebugPrint("DropLoot chance " .. chance) + for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do + local item = player:getSlotItem(i) + if item then + local thisChance = item:isContainer() and chance or (chance / 10) + local thisRandom = math.random(100 * multiplier) - callback = function(k) - return true - end - local curBless = player:getBlessings() - - msg:addByte(Blessings.Config.HasToF and #Blessings.All or (#Blessings.All - 1)) -- total blessings - for k = 1, #Blessings.All do - v = Blessings.All[k] - if v.type ~= Blessings.Types.PvP or Blessings.Config.HasToF then - msg:addU16(Blessings.BitWiseTable[v.id]) - msg:addByte(player:getBlessingCount(v.id)) - if player:getClient().version > 1200 then - msg:addByte(player:getBlessingCount(v.id, true)) -- Store Blessings Count + Blessings.DebugPrint(thisChance / multiplier .. "%" .. " | thisRandom " .. thisRandom / multiplier .. "%", "DropLoot item " .. item:getName() .. " |") + if skulled or thisRandom <= thisChance then + Blessings.DebugPrint("Dropped " .. item:getName()) + item:moveTo(corpse) end end end - local promotion = (player:isPremium() and player:isPromoted()) and 30 or 0 - local PvPminXPLoss = Blessings.LossPercent[#curBless].skill + promotion - local PvPmaxXPLoss = PvPminXPLoss - if Blessings.Config.HasToF then - PvPmaxXPLoss = math.floor(PvPminXPLoss * 1.15) - end - local PvEXPLoss = PvPminXPLoss - - local playerAmulet = player:getSlotItem(CONST_SLOT_NECKLACE) - local haveSkull = player:getSkull() >= 4 - hasAol = (playerAmulet and playerAmulet:getId() == ITEM_AMULETOFLOSS) - - equipLoss = Blessings.LossPercent[#curBless].item - if haveSkull then - equipLoss = 100 - elseif hasAol then - equipLoss = 0 - end - - msg:addByte(2) -- BYTE PREMIUM (only work with premium days) - msg:addByte(promotion) -- XP Loss Lower POR SER PREMIUM - msg:addByte(PvPminXPLoss) -- XP/Skill loss min pvp death - msg:addByte(PvPmaxXPLoss) -- XP/Skill loss max pvp death - msg:addByte(PvEXPLoss) -- XP/Skill pve death - msg:addByte(equipLoss) -- Equip container lose pvp death - msg:addByte(equipLoss) -- Equip container pve death - - msg:addByte(haveSkull and 1 or 0) -- is red/black skull - msg:addByte(hasAol and 1 or 0) - - -- History - local historyAmount = 1 - msg:addByte(historyAmount) -- History log count - for i = 1, historyAmount do - msg:addU32(os.time()) -- timestamp - msg:addByte(0) -- Color message (1 - Red | 0 = White loss) - msg:addString("Blessing Purchased", "Blessings.sendBlessDialog - Blessing Purchased") -- History message + if skulled and Blessings.Config.SkulledDeathLoseStoreItem then + local inbox = player:getStoreInbox() + local toBeDeleted = {} + if inbox and inbox:getSize() > 0 then + for i = 0, inbox:getSize() do + local item = inbox:getItem(i) + if item then + toBeDeleted[#toBeDeleted + 1] = item.uid + end + end + if #toBeDeleted > 0 then + for i, v in pairs(toBeDeleted) do + local item = Item(v) + if item then + item:remove() + end + end + end + end end - - msg:sendToPlayer(player) end +-- Blessing Helpers -- Blessings.getCommandFee = function(cost) local fee = configManager.getNumber(configKeys.BUY_BLESS_COMMAND_FEE) or 0 return cost + cost * (((fee > 100 and 100) or fee) / 100) end -Blessings.getBlessingsCost = function(level, byCommand) +Blessings.getBlessingCost = function(level, byCommand, enhanced) if byCommand == nil then byCommand = false end + + if enhanced == nil then + enhanced = false + end + local cost if level <= 30 then cost = 2000 elseif level >= 120 then - cost = 20000 + local base_cost = enhanced and 26000 or 20000 + local multiplier = enhanced and 100 or 75 + cost = base_cost + multiplier * (level - 120) else - cost = (level - 20) * 200 + local multiplier = enhanced and 260 or 200 + cost = multiplier * (level - 20) end + return byCommand and Blessings.getCommandFee(cost) or cost end @@ -213,6 +173,7 @@ Blessings.getPvpBlessingCost = function(level, byCommand) if byCommand == nil then byCommand = false end + local cost if level <= 30 then cost = 2000 @@ -221,6 +182,7 @@ Blessings.getPvpBlessingCost = function(level, byCommand) else cost = (level - 20) * 200 end + return byCommand and Blessings.getCommandFee(cost) or cost end @@ -250,6 +212,7 @@ Blessings.checkBless = function(player) for k, v in pairs(Blessings.All) do result = player:hasBlessing(k) and result .. "\n" .. v.name or result end + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 20 > result:len() and "No blessings received." or result) return true end @@ -258,6 +221,7 @@ Blessings.doAdventurerBlessing = function(player) if player:getLevel() > Blessings.Config.AdventurerBlessingLevel then return true end + player:addMissingBless(true, true) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have adventurer's blessings for being level lower than " .. Blessings.Config.AdventurerBlessingLevel .. "!") @@ -270,70 +234,16 @@ Blessings.getInquisitionPrice = function(player) inquifilter = function(b) return b.inquisition end + donthavefilter = function(p, b) return not p:hasBlessing(b) end + local missing = #player:getBlessings(inquifilter, donthavefilter) - local totalBlessPrice = Blessings.getBlessingsCost(player:getLevel(), false) * missing * Blessings.Config.InquisitonBlessPriceMultiplier + local totalBlessPrice = Blessings.getBlessingCost(player:getLevel(), false) * missing * Blessings.Config.InquisitonBlessPriceMultiplier return missing, totalBlessPrice end -Blessings.DropLoot = function(player, corpse, chance, skulled) - local multiplier = 100 -- Improve the loot randomness spectrum - math.randomseed(os.time()) -- Improve the loot randomness spectrum - chance = chance * multiplier - Blessings.DebugPrint(chance, "DropLoot chance") - for i = CONST_SLOT_HEAD, CONST_SLOT_AMMO do - local item = player:getSlotItem(i) - if item then - local thisChance = chance - local thisRandom = math.random(100 * multiplier) - if not item:isContainer() then - thisChance = chance / 10 - end - Blessings.DebugPrint(thisChance / multiplier .. "%" .. " | thisRandom " .. thisRandom / multiplier .. "%", "DropLoot item " .. item:getName() .. " |") - if skulled or thisRandom <= thisChance then - Blessings.DebugPrint("Dropped " .. item:getName()) - item:moveTo(corpse) - end - end - end - if skulled and Blessings.Config.SkulledDeathLoseStoreItem then - local inbox = player:getStoreInbox() - local toBeDeleted = {} - if inbox and inbox:getSize() > 0 then - for i = 0, inbox:getSize() do - local item = inbox:getItem(i) - if item then - toBeDeleted[#toBeDeleted + 1] = item.uid - end - end - if #toBeDeleted > 0 then - for i, v in pairs(toBeDeleted) do - local item = Item(v) - if item then - item:remove() - end - end - end - end - end -end - -Blessings.ClearBless = function(player, killer, currentBless) - Blessings.DebugPrint(#currentBless, "ClearBless #currentBless") - local hasToF = Blessings.Config.HasToF and player:hasBlessing(1) or false - if hasToF and killer(killer:isPlayer() or (killer:getMaster() and killer:getMaster():isPlayer())) then -- TODO add better check if its pvp or pve - player:removeBlessing(1) - return - end - for i = 1, #currentBless do - Blessings.DebugPrint(i, "ClearBless curBless i", " | " .. currentBless[i].name) - player:removeBlessing(currentBless[i].id, 1) - end -end - --- bought by command Blessings.BuyAllBlesses = function(player) if not Tile(player:getPosition()):hasFlag(TILESTATE_PROTECTIONZONE) and (player:isPzLocked() or player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)) then player:sendCancelMessage("You can't buy bless while in battle.") @@ -341,66 +251,49 @@ Blessings.BuyAllBlesses = function(player) return true end - local blessCost = Blessings.getBlessingsCost(player:getLevel(), true) - local PvPBlessCost = Blessings.getPvpBlessingCost(player:getLevel(), true) - local hasToF = Blessings.Config.HasToF and player:hasBlessing(1) or true donthavefilter = function(p, b) return not p:hasBlessing(b) end + + local hasToF = Blessings.Config.HasToF and player:hasBlessing(1) or true local missingBless = player:getBlessings(nil, donthavefilter) local missingBlessAmt = #missingBless + (hasToF and 0 or 1) - local totalCost = blessCost * #missingBless + local totalCost = 0 + + for _, bless in ipairs(missingBless) do + totalCost = totalCost + Blessings.getBlessingCost(player:getLevel(), true, bless.id >= 7) + end if missingBlessAmt == 0 then player:sendCancelMessage("You are already blessed.") player:getPosition():sendMagicEffect(CONST_ME_POFF) return true end + if not hasToF then - totalCost = totalCost + PvPBlessCost + totalCost = totalCost + Blessings.getPvpBlessingCost(player:getLevel(), true) end if player:removeMoneyBank(totalCost) then - metrics.addCounter("balance_decrease", remainsPrice, { + metrics.addCounter("balance_decrease", totalCost, { player = player:getName(), context = "blessings", }) - for i, v in ipairs(missingBless) do - player:addBlessing(v.id, 1) + + for _, bless in ipairs(missingBless) do + player:addBlessing(bless.id, 1) end - player:sendCancelMessage("You received the remaining " .. missingBlessAmt .. " blesses for a total of " .. totalCost .. " gold.") + + player:sendCancelMessage(string.format("You received the remaining %d blesses for a total of %d gold.", missingBlessAmt, totalCost)) player:getPosition():sendMagicEffect(CONST_ME_HOLYAREA) else - player:sendCancelMessage("You don't have enough money. You need " .. totalCost .. " to buy all blesses.", cid) + player:sendCancelMessage(string.format("You don't have enough money. You need %d to buy all blesses.", totalCost)) player:getPosition():sendMagicEffect(CONST_ME_POFF) end return true end -Blessings.PlayerDeath = function(player, corpse, killer) - local hasToF = Blessings.Config.HasToF and player:hasBlessing(1) or false - local hasAol = (player:getSlotItem(CONST_SLOT_NECKLACE) and player:getSlotItem(CONST_SLOT_NECKLACE):getId() == ITEM_AMULETOFLOSS) - local haveSkull = table.contains({ SKULL_RED, SKULL_BLACK }, player:getSkull()) - local curBless = player:getBlessings() - - if haveSkull then -- lose all bless + drop all items - Blessings.DropLoot(player, corpse, 100, true) - elseif #curBless < 5 and not hasAol then -- lose all items - local equipLoss = Blessings.LossPercent[#curBless].item - Blessings.DropLoot(player, corpse, equipLoss) - elseif #curBless < 5 and hasAol and not hasToF then - player:removeItem(ITEM_AMULETOFLOSS, 1, -1, false) - end - --Blessings.ClearBless(player, killer, curBless) IMPLEMENTED IN SOURCE BECAUSE THIS WAS HAPPENING BEFORE SKILL/EXP CALCULATIONS - - if not player:getSlotItem(CONST_SLOT_BACKPACK) then - player:addItem(ITEM_BAG, 1, false, CONST_SLOT_BACKPACK) - end - - return true -end - function Player.getBlessings(self, filter, hasblessingFilter) local blessings = {} if filter == nil then @@ -414,11 +307,13 @@ function Player.getBlessings(self, filter, hasblessingFilter) return p:hasBlessing(b) end end + for k, v in pairs(Blessings.All) do if filter(v) and hasblessingFilter(self, k) then table.insert(blessings, v) end end + return blessings end @@ -426,11 +321,13 @@ function Player.addMissingBless(self, all, tof) if all == nil then all = true end + if tof == nil then tof = false elseif tof then tof = tof and Blessings.Config.HasToF end + for k, v in pairs(Blessings.All) do if all or (v.type == Blessings.Types.REGULAR) or (tof and v.type == Blessings.Types.PvP) then if not self:hasBlessing(k) then @@ -438,5 +335,5 @@ function Player.addMissingBless(self, all, tof) end end end - Blessings.sendBlessStatus(self) + self:sendBlessStatus() end diff --git a/data/libs/systems/load.lua b/data/libs/systems/load.lua index 281b8b1d466..ffe02320b96 100644 --- a/data/libs/systems/load.lua +++ b/data/libs/systems/load.lua @@ -1,4 +1,5 @@ -- Load systems functions +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") dofile(CORE_DIRECTORY .. "/libs/systems/concoctions.lua") dofile(CORE_DIRECTORY .. "/libs/systems/daily_reward.lua") dofile(CORE_DIRECTORY .. "/libs/systems/encounters.lua") diff --git a/data/libs/systems/vip.lua b/data/libs/systems/vip.lua index 9e76fd8ad80..49ef7bcf8cc 100644 --- a/data/libs/systems/vip.lua +++ b/data/libs/systems/vip.lua @@ -45,17 +45,17 @@ function Player.onAddVip(self, days, silent) self:kv():scoped("account"):set("vip-system", true) end -function CheckPremiumAndPrint(player, msgType) - if player:getVipDays() == 0xFFFF then - player:sendTextMessage(msgType, "You have an unlimited VIP status.") +function Player.sendVipStatus(self) + if self:getVipDays() == 0xFFFF then + self:sendTextMessage(MESSAGE_LOGIN, "You have unlimited VIP status.") return true end - local playerVipTime = player:getVipTime() + local playerVipTime = self:getVipTime() if playerVipTime < os.time() then - player:sendTextMessage(msgType, "Your VIP status is currently inactive.") + self:sendTextMessage(MESSAGE_STATUS, "Your VIP status is currently inactive.") return true end - player:sendTextMessage(msgType, string.format("You have %s of VIP time remaining.", getFormattedTimeRemaining(playerVipTime))) + self:sendTextMessage(MESSAGE_LOGIN, string.format("You have %s of VIP time remaining.", getFormattedTimeRemaining(playerVipTime))) end diff --git a/data/modules/modules.xml b/data/modules/modules.xml index c45646183ac..e51bf055f2a 100644 --- a/data/modules/modules.xml +++ b/data/modules/modules.xml @@ -10,9 +10,6 @@ - - - @@ -26,5 +23,4 @@ - diff --git a/data/modules/scripts/blessings/assets.lua b/data/modules/scripts/blessings/assets.lua deleted file mode 100644 index 73d02a272f3..00000000000 --- a/data/modules/scripts/blessings/assets.lua +++ /dev/null @@ -1,47 +0,0 @@ -Blessings.Types = { - REGULAR = 1, - ENHANCED = 2, - PvP = 3, -} - -Blessings.All = { - [1] = { id = 1, name = "Twist of Fate", type = Blessings.Types.PvP }, - [2] = { id = 2, name = "The Wisdom of Solitude", charm = 10345, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, - [3] = { id = 3, name = "The Spark of the Phoenix", charm = 10341, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, - [4] = { id = 4, name = "The Fire of the Suns", charm = 10344, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, - [5] = { id = 5, name = "The Spiritual Shielding", charm = 10343, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, - [6] = { id = 6, name = "The Embrace of Tibia", charm = 10342, type = Blessings.Types.REGULAR, losscount = true, inquisition = true }, - [7] = { id = 7, name = "Blood of the Mountain", charm = 25360, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false }, - [8] = { id = 8, name = "Heart of the Mountain", charm = 25361, type = Blessings.Types.ENHANCED, losscount = true, inquisition = false }, -} - -Blessings.LossPercent = { - [0] = { item = 100, skill = 0 }, - [1] = { item = 70, skill = 8 }, - [2] = { item = 45, skill = 16 }, - [3] = { item = 25, skill = 24 }, - [4] = { item = 10, skill = 32 }, - [5] = { item = 0, skill = 40 }, - [6] = { item = 0, skill = 48 }, - [7] = { item = 0, skill = 56 }, - [8] = { item = 0, skill = 56 }, -} - -Blessings.BitWiseTable = { - [0] = 1, - [1] = 2, - [2] = 4, - [3] = 8, - [4] = 16, - [5] = 32, - [6] = 64, - [7] = 128, - [8] = 256, - [9] = 512, - [10] = 1024, - [11] = 2048, - [12] = 4096, - [13] = 8192, - [14] = 16384, - [15] = 32768, -} diff --git a/data/npclib/npc.lua b/data/npclib/npc.lua index 4de60c45c49..4a8097ff27f 100644 --- a/data/npclib/npc.lua +++ b/data/npclib/npc.lua @@ -89,7 +89,7 @@ function SayEvent(npcId, playerId, messageDelayed, npcHandler, textType) local parseInfo = { [TAG_PLAYERNAME] = player:getName(), [TAG_TIME] = getFormattedWorldTime(), - [TAG_BLESSCOST] = Blessings.getBlessingsCost(player:getLevel(), false), + [TAG_BLESSCOST] = Blessings.getBlessingCost(player:getLevel(), false, (npc:getName() == "Kais" or npc:getName() == "Nomad") and true), [TAG_PVPBLESSCOST] = Blessings.getPvpBlessingCost(player:getLevel(), false), } npc:say(npcHandler:parseMessage(messageDelayed, parseInfo), textType or TALKTYPE_PRIVATE_NP, false, player, npc:getPosition()) diff --git a/data/npclib/npc_system/modules.lua b/data/npclib/npc_system/modules.lua index aca92804e80..08027a67d2b 100644 --- a/data/npclib/npc_system/modules.lua +++ b/data/npclib/npc_system/modules.lua @@ -60,7 +60,7 @@ if Modules == nil then local parseInfo = { [TAG_PLAYERNAME] = player:getName(), [TAG_TIME] = getFormattedWorldTime(), - [TAG_BLESSCOST] = Blessings.getBlessingsCost(player:getLevel(), false), + [TAG_BLESSCOST] = Blessings.getBlessingCost(player:getLevel(), false, (npc:getName() == "Kais" or npc:getName() == "Nomad") and true), [TAG_PVPBLESSCOST] = Blessings.getPvpBlessingCost(player:getLevel(), false), [TAG_TRAVELCOST] = costMessage, } @@ -160,7 +160,7 @@ if Modules == nil then end local parseInfo = { - [TAG_BLESSCOST] = Blessings.getBlessingsCost(player:getLevel(), false), + [TAG_BLESSCOST] = Blessings.getBlessingCost(player:getLevel(), false, (npc:getName() == "Kais" or npc:getName() == "Nomad") and true), [TAG_PVPBLESSCOST] = Blessings.getPvpBlessingCost(player:getLevel(), false), } if player:hasBlessing(parameters.bless) then @@ -175,7 +175,7 @@ if Modules == nil then npc, player ) - elseif not player:removeMoneyBank(type(parameters.cost) == "string" and npcHandler:parseMessage(parameters.cost, parseInfo) or parameters.cost) then + elseif not player:removeMoneyBank(type(parameters.cost) == "string" and tonumber(npcHandler:parseMessage(parameters.cost, parseInfo)) or parameters.cost) then npcHandler:say("Oh. You do not have enough money.", npc, player) else npcHandler:say(parameters.text or "You have been blessed by one of the seven gods!", npc, player) diff --git a/data-otservbr-global/scripts/actions/other/balloons.lua b/data/scripts/actions/items/anniversary_balloons.lua similarity index 79% rename from data-otservbr-global/scripts/actions/other/balloons.lua rename to data/scripts/actions/items/anniversary_balloons.lua index 35e84eec531..8fbeecee110 100644 --- a/data-otservbr-global/scripts/actions/other/balloons.lua +++ b/data/scripts/actions/items/anniversary_balloons.lua @@ -1,4 +1,4 @@ -local balloonItems = { +local settings = { [37471] = 37414, [37414] = 37471, -- blue balloon [37472] = 37416, @@ -77,32 +77,28 @@ local balloonItems = { [39692] = 39680, -- balloon no.9 } -local balloons = Action() +local anniversaryBalloons = Action() -function balloons.onUse(player, item, fp, target, toPosition, isHotkey) - local balloon = balloonItems[item.itemid] +function anniversaryBalloons.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local balloon = settings[item.itemid] if not balloon then - return false + return true end local fromPosition = item:getPosition() local tile = Tile(fromPosition) - if not fromPosition:getTile():getHouse() then + + if not tile:getHouse() then player:sendTextMessage(MESSAGE_FAILURE, "You may use this only inside a house.") - elseif tile:getItemCountById(item.itemid) == 1 then - for index, value in pairs(balloonItems) do - if tile:getItemCountById(index) > 0 and index ~= item.itemid then - player:sendCancelMessage(Game.getReturnMessage(RETURNVALUE_NOTPOSSIBLE)) - return true - end - end - item:transform(balloon) + return true end + + item:transform(balloon, 1) return true end -for index, value in pairs(balloonItems) do - balloons:id(index) +for itemId in pairs(settings) do + anniversaryBalloons:id(itemId) end -balloons:register() +anniversaryBalloons:register() diff --git a/data-canary/scripts/actions/other/bed_modification_kits.lua b/data/scripts/actions/items/bed_modification_kits.lua similarity index 90% rename from data-canary/scripts/actions/other/bed_modification_kits.lua rename to data/scripts/actions/items/bed_modification_kits.lua index 431e3cef5eb..a406f7fd5b2 100644 --- a/data-canary/scripts/actions/other/bed_modification_kits.lua +++ b/data/scripts/actions/items/bed_modification_kits.lua @@ -20,7 +20,7 @@ local bedModificationKits = Action() function bedModificationKits.onUse(player, item, fromPosition, target, toPosition, isHotkey) local newBed = setting[item:getId()] - if not newBed or type(target) ~= "userdata" or not target:isItem() then + if not newBed or not target or not target:isItem() then return false end @@ -35,7 +35,7 @@ function bedModificationKits.onUse(player, item, fromPosition, target, toPositio return true end - for index, value in pairs(setting) do + for _, value in pairs(setting) do if value[1][1] == targetItemId or table.contains({ 2491, 5501, 15506 }, targetItemId) then toPosition:sendMagicEffect(CONST_ME_POFF) toPosition.y = toPosition.y + 1 @@ -51,8 +51,8 @@ function bedModificationKits.onUse(player, item, fromPosition, target, toPositio return true end -for index, value in pairs(setting) do - bedModificationKits:id(index) +for id in pairs(setting) do + bedModificationKits:id(id) end bedModificationKits:register() diff --git a/data/scripts/actions/items/blessing_charms.lua b/data/scripts/actions/items/blessing_charms.lua index 7e70c5a6719..fdca561c3a2 100644 --- a/data/scripts/actions/items/blessing_charms.lua +++ b/data/scripts/actions/items/blessing_charms.lua @@ -1,4 +1,4 @@ -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/blessings.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") local blessingCharms = Action() diff --git a/data/scripts/actions/items/check_bless.lua b/data/scripts/actions/items/check_bless.lua index 0d2478f5f11..09d07fffd85 100644 --- a/data/scripts/actions/items/check_bless.lua +++ b/data/scripts/actions/items/check_bless.lua @@ -1,4 +1,4 @@ -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/blessings.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") local checkBless = Action() diff --git a/data/scripts/actions/items/christmas_bundle.lua b/data/scripts/actions/items/christmas_bundle.lua new file mode 100644 index 00000000000..d0a56f6d050 --- /dev/null +++ b/data/scripts/actions/items/christmas_bundle.lua @@ -0,0 +1,42 @@ +local setting = { + [6506] = { { 6569, 15 }, { 3585, 5 }, { 3586, 10 }, { 3598, 20 }, { 3599, 10 }, 6500, 6501, 6489, 6503, 6387 }, -- red bundle + [6507] = { { 6569, 15 }, { 3585, 5 }, { 3586, 10 }, { 3598, 20 }, { 3599, 10 }, 6500, 6501, 6489, 6505, 6387 }, -- blue bundle + [6508] = { { 6569, 15 }, { 3585, 5 }, { 3586, 10 }, { 3598, 20 }, { 3599, 10 }, 6500, 6501, 6489, 6502, 6387 }, -- green bundle +} + +local christmasBundle = Action() + +function christmasBundle.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local targetItem = setting[item.itemid] + if not targetItem then + return true + end + + local rewards = {} + while #rewards < 7 do + local randIndex = math.random(#targetItem) + local gift = targetItem[randIndex] + + local count = 1 + if type(gift) == "table" then + gift, count = unpack(gift) + end + + rewards[#rewards + 1] = { gift, count } + table.remove(targetItem, randIndex) + end + + for _, reward in ipairs(rewards) do + player:addItem(unpack(reward)) + end + + player:getPosition():sendMagicEffect(CONST_ME_GIFT_WRAPS) + item:remove(1) + return true +end + +for itemId in pairs(setting) do + christmasBundle:id(itemId) +end + +christmasBundle:register() diff --git a/data/scripts/actions/items/cobra_flask.lua b/data/scripts/actions/items/cobra_flask.lua index c36d42983c5..0556373afae 100644 --- a/data/scripts/actions/items/cobra_flask.lua +++ b/data/scripts/actions/items/cobra_flask.lua @@ -1,19 +1,3 @@ -local applyCobraFlaskEffectOnMonsterSpawn = EventCallback("CobraFlaskEffectOnMonsterSpawn") - -applyCobraFlaskEffectOnMonsterSpawn.monsterOnSpawn = function(monster, position) - if table.contains({ "cobra scout", "cobra vizier", "cobra assassin" }, monster:getName():lower()) then - if Game.getStorageValue(Global.Storage.CobraFlask) >= os.time() then - monster:setHealth(monster:getMaxHealth() * 0.75) - monster:getPosition():sendMagicEffect(CONST_ME_GREEN_RINGS) - else - Game.setStorageValue(Global.Storage.CobraFlask, -1) - end - end - return true -end - -applyCobraFlaskEffectOnMonsterSpawn:register() - local cobraFlask = Action() function cobraFlask.onUse(player, item, fromPosition, target, toPosition, isHotkey) diff --git a/data-canary/scripts/actions/other/decay_to.lua b/data/scripts/actions/items/decay_to.lua similarity index 87% rename from data-canary/scripts/actions/other/decay_to.lua rename to data/scripts/actions/items/decay_to.lua index bfceedb288e..bb68e346e1f 100644 --- a/data-canary/scripts/actions/other/decay_to.lua +++ b/data/scripts/actions/items/decay_to.lua @@ -1,5 +1,9 @@ -local setting = { - --[itemid] = decayto +local voices = { + [23708] = "Au au!", + [23443] = "Grooaarr!", +} + +local transformItems = { [2062] = 2063, [2063] = 2062, -- sacred statue [2064] = 2065, @@ -439,16 +443,69 @@ local setting = { [39700] = 39699, -- rainbow torch [39701] = 39702, [39702] = 39701, -- rainbow torch + [39757] = 39758, -- yeti doll + [39759] = 39760, + [39761] = 39762, -- the gods' twilight doll + [39772] = 39773, + [39773] = 39774, -- flower table + [39774] = 39772, -- flower table + [39793] = 39794, + [39794] = 39793, -- turquoise flower lamp + [39795] = 39796, + [39796] = 39795, -- purple flower lamp + [39801] = 39802, + [39802] = 39801, -- wall leaves + [39803] = 39804, + [39804] = 39803, -- tendrils + [39805] = 39806, + [39807] = 39808, -- water nymph + [39810] = 39809, -- water nymph + [42271] = 42272, + [42272] = 42271, -- seafarer table + [42291] = 42292, + [42292] = 42291, -- seashell lamp + [42293] = 42294, + [42294] = 42293, -- seashell lamp + [42295] = 42296, + [42296] = 42295, -- tentacle lamp + [42297] = 42298, + [42298] = 42297, -- tentacle lamp + [42299] = 42300, + [42300] = 42299, -- sea-devil wall lamp + [42301] = 42302, + [42302] = 42301, -- seafood bucket + [42324] = 42326, + [42326] = 42324, -- opulent table + [42325] = 42327, + [42327] = 42325, -- opulent table + [42346] = 42347, + [42347] = 42346, -- opulent floor lamp + [42348] = 42349, + [42349] = 42348, -- opulent floor lamp + [42363] = 42364, -- djinn lamp + [42365] = 42366, -- djinn lamp } local decayTo = Action() function decayTo.onUse(player, item, fromPosition, target, toPosition, isHotkey) - item:transform(setting[item.itemid]) + local itemId = item:getId() + if voices[itemId] then + local spectators = Game.getSpectators(fromPosition, false, true, 3, 3) + for _, spectator in ipairs(spectators) do + player:say(voices[itemId], TALKTYPE_MONSTER_SAY, false, spectator, fromPosition) + end + end + + local newItemId = transformItems[itemId] + if newItemId then + item:transform(newItemId) + item:decay() + end return true end -for index, value in pairs(setting) do +for index in pairs(transformItems) do decayTo:id(index) end diff --git a/data-canary/scripts/actions/other/dolls.lua b/data/scripts/actions/items/dolls.lua similarity index 100% rename from data-canary/scripts/actions/other/dolls.lua rename to data/scripts/actions/items/dolls.lua diff --git a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_amulet.lua b/data/scripts/actions/items/ferumbras_amulet.lua similarity index 95% rename from data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_amulet.lua rename to data/scripts/actions/items/ferumbras_amulet.lua index d92c496e165..dee32339a46 100644 --- a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_amulet.lua +++ b/data/scripts/actions/items/ferumbras_amulet.lua @@ -1,10 +1,12 @@ local ferumbrasAscendantAmulet = Action() + function ferumbrasAscendantAmulet.onUse(player, item, fromPosition, target, toPosition, isHotkey) local amulet = player:getSlotItem(CONST_SLOT_NECKLACE) - if amulet ~= item or amulet ~= item then + if amulet ~= item then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You need to equip the amulet to try use it.") return true end + if item.itemid == 22767 then if math.random(2) == 1 then player:addHealth(1000, true, true) @@ -13,10 +15,10 @@ function ferumbrasAscendantAmulet.onUse(player, item, fromPosition, target, toPo player:addMana(1000, true, true) player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Magical sparks whirl around the amulet as you use it and you was restored.") end + item:transform(22768) item:decay() player:getPosition():sendMagicEffect(CONST_ME_MAGIC_BLUE) - return true elseif item.itemid == 22768 then player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are tired of the last use of the amulet, you must wait for the recharge.") end diff --git a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_mana_keg.lua b/data/scripts/actions/items/ferumbras_mana_keg.lua similarity index 99% rename from data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_mana_keg.lua rename to data/scripts/actions/items/ferumbras_mana_keg.lua index 8ece01ed6e8..04bbc7b6e50 100644 --- a/data-otservbr-global/scripts/quests/ferumbras_ascension/actions_ferumbras_mana_keg.lua +++ b/data/scripts/actions/items/ferumbras_mana_keg.lua @@ -1,4 +1,5 @@ local ferumbrasAscendantManaKeg = Action() + function ferumbrasAscendantManaKeg.onUse(player, item, fromPosition, target, toPosition, isHotkey) if item.itemid == 22769 then player:addItem("ultimate mana potion", 10) diff --git a/data-canary/scripts/actions/other/ladder_up.lua b/data/scripts/actions/items/ladder_up.lua similarity index 64% rename from data-canary/scripts/actions/other/ladder_up.lua rename to data/scripts/actions/items/ladder_up.lua index efea920c9b8..5ec5f7c5b67 100644 --- a/data-canary/scripts/actions/other/ladder_up.lua +++ b/data/scripts/actions/items/ladder_up.lua @@ -1,9 +1,9 @@ -local setting = { 1948, 1968, 5542, 20474, 20475, 28656, 31262 } +local ladderTable = Game.getLadderIds() local ladder = Action() function ladder.onUse(player, item, fromPosition, target, toPosition, isHotkey) - if table.contains(setting, item.itemid) then + if table.contains(ladderTable, item.itemid) then fromPosition:moveUpstairs() else fromPosition.z = fromPosition.z + 1 @@ -14,12 +14,9 @@ function ladder.onUse(player, item, fromPosition, target, toPosition, isHotkey) return true end - player:teleportTo(fromPosition, false) + player:teleportTo(fromPosition, true) return true end -for index, value in ipairs(setting) do - ladder:id(value) -end - +ladder:id(435, unpack(ladderTable)) ladder:register() diff --git a/data-otservbr-global/scripts/actions/other/party_trumpet.lua b/data/scripts/actions/items/party_trumpet.lua similarity index 100% rename from data-otservbr-global/scripts/actions/other/party_trumpet.lua rename to data/scripts/actions/items/party_trumpet.lua index 71ee617ec69..a1cb77bf56d 100644 --- a/data-otservbr-global/scripts/actions/other/party_trumpet.lua +++ b/data/scripts/actions/items/party_trumpet.lua @@ -1,10 +1,10 @@ local partyTrumpet = Action() function partyTrumpet.onUse(player, item, fromPosition, target, toPosition, isHotkey) - item:transform(6573) - item:decay() player:say("TOOOOOOT!", TALKTYPE_MONSTER_SAY) fromPosition:sendMagicEffect(CONST_ME_SOUND_BLUE) + item:transform(6573) + item:decay() return true end diff --git a/data-otservbr-global/scripts/actions/other/roasted_meat.lua b/data/scripts/actions/items/roasted_meat.lua similarity index 100% rename from data-otservbr-global/scripts/actions/other/roasted_meat.lua rename to data/scripts/actions/items/roasted_meat.lua diff --git a/data/scripts/actions/items/surprise_bags.lua b/data/scripts/actions/items/surprise_bags.lua new file mode 100644 index 00000000000..09c03e516db --- /dev/null +++ b/data/scripts/actions/items/surprise_bags.lua @@ -0,0 +1,32 @@ +local settings = { + [6570] = { { 3598, 10 }, 6393, 6279, 6574, 6578, 6575, 6577, 6569, 6576, 6572, 2995, 14027, 14681 }, -- blue present + [6571] = { 6574, 3079, 6393, 6576, 6578, 2995, 14027, 3036, 5944, 3386, 3420, 3039, 5080, 2993, 3392, 3057, 5791 }, -- red present + [8853] = { { 3031, 10 }, 123, 2995, 2397, 651, 3218, 6574, 6393, 7377, 3578, 8778 }, -- surprise bag + [14751] = { { 9642, 15 }, { 3581, 15 }, 5917, 3273, 10302, 9019, 5928, 5926, 5927, 6095, 5918, 6097, 6098, 5461, 5090 }, -- surprise bag + [14759] = { { 6569, 10 }, { 6541, 10 }, { 6542, 10 }, { 6543, 10 }, { 6544, 10 }, { 6545, 10 }, 6574, 4839, 6570, 6571, 3215 }, -- surprise bag +} + +local surpriseBag = Action() + +function surpriseBag.onUse(player, item, fromPosition) + local present = settings[item.itemid] + if not present then + return true + end + + local gift = present[math.random(#present)] + local count = 1 + + if type(gift) == "table" then + count = math.random(gift[2]) + gift = gift[1] + end + + player:addItem(gift, count) + fromPosition:sendMagicEffect(CONST_ME_GIFT_WRAPS) + item:remove(1) + return true +end + +surpriseBag:id(6570, 6571, 8853, 14751, 14759) +surpriseBag:register() diff --git a/data/scripts/actions/items/surprise_music_box.lua b/data/scripts/actions/items/surprise_music_box.lua new file mode 100644 index 00000000000..05abbac3d08 --- /dev/null +++ b/data/scripts/actions/items/surprise_music_box.lua @@ -0,0 +1,34 @@ +local prize = { + { chance = 1, id = 3246, amount = 1 }, + { chance = 2, id = 10227, amount = 1 }, + { chance = 3, id = 11588, amount = 1 }, + { chance = 4, id = 3549, amount = 1 }, + { chance = 5, id = 3420, amount = 1 }, + { chance = 10, id = ITEM_CRYSTAL_COIN, amount = 17 }, + { chance = 20, id = ITEM_GOLD_COIN, amount = 1 }, + { chance = 30, id = ITEM_CRYSTAL_COIN, amount = 1 }, + { chance = 40, id = ITEM_GOLD_COIN, amount = 50 }, + { chance = 50, id = ITEM_PLATINUM_COIN, amount = 15 }, + { chance = 90, id = ITEM_GOLD_COIN, amount = 80 }, +} + +local surpriseBox = Action() + +function surpriseBox.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local number = math.random(1, 100) + local cumulativeChance = 0 + + for _, prizeEntry in ipairs(prize) do + cumulativeChance = cumulativeChance + prizeEntry.chance + if number <= cumulativeChance then + player:getPosition():sendMagicEffect(CONST_ME_POFF) + player:addItem(prizeEntry.id, prizeEntry.amount) + item:remove() + break + end + end + return true +end + +surpriseBox:id(12045) +surpriseBox:register() diff --git a/data/scripts/actions/items/usable_phantasmal_jade_items.lua b/data/scripts/actions/items/usable_phantasmal_jade_items.lua new file mode 100644 index 00000000000..8075125df25 --- /dev/null +++ b/data/scripts/actions/items/usable_phantasmal_jade_items.lua @@ -0,0 +1,45 @@ +local config = { + requiredItems = { + [34072] = { key = "spectral-horseshoes", count = 4 }, + [34073] = { key = "spectral-saddle", count = 1 }, + [34074] = { key = "spectral-horse-tac", count = 1 }, + }, + + mountId = 167, +} + +local usablePhantasmalJadeItems = Action() + +function usablePhantasmalJadeItems.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local itemInfo = config.requiredItems[item:getId()] + if not itemInfo then + return true + end + + if player:hasMount(config.mountId) then + return true + end + + local currentCount = (player:kv():get(itemInfo.key) or 0) + 1 + player:kv():set(itemInfo.key, currentCount) + player:getPosition():sendMagicEffect(CONST_ME_HOLYDAMAGE) + item:remove(1) + + for _, info in pairs(config.requiredItems) do + if (player:kv():get(info.key) or 0) < info.count then + return true + end + end + + player:addMount(config.mountId) + player:addAchievement("Natural Born Cowboy") + player:addAchievement("You got Horse Power") + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Phantasmal jade is now yours!") + return true +end + +for itemId, _ in pairs(config.requiredItems) do + usablePhantasmalJadeItems:id(itemId) +end + +usablePhantasmalJadeItems:register() diff --git a/data/scripts/actions/items/vessels.lua b/data/scripts/actions/items/vessels.lua new file mode 100644 index 00000000000..2d6fe19bf00 --- /dev/null +++ b/data/scripts/actions/items/vessels.lua @@ -0,0 +1,26 @@ +local config = { + [37572] = CONST_ME_GAZHARAGOTH, + [37573] = CONST_ME_FERUMBRAS_1, + [37574] = CONST_ME_MAD_MAGE, + [37575] = CONST_ME_HORESTIS, + [37576] = CONST_ME_DEVOVORGA, +} + +local vessels = Action() + +function vessels.onUse(player, item, fromPosition, target, toPosition, isHotkey) + local vessel = config[item.itemid] + if not vessel or not target:isPlayer() then + return true + end + + toPosition:sendMagicEffect(vessel) + item:remove(1) + return true +end + +for index in pairs(config) do + vessels:id(index) +end + +vessels:register() diff --git a/data-otservbr-global/scripts/actions/other/bath_tub.lua b/data/scripts/actions/objects/bath_tub_drain.lua similarity index 99% rename from data-otservbr-global/scripts/actions/other/bath_tub.lua rename to data/scripts/actions/objects/bath_tub_drain.lua index cd1b3238ca6..a09886a2ad1 100644 --- a/data-otservbr-global/scripts/actions/other/bath_tub.lua +++ b/data/scripts/actions/objects/bath_tub_drain.lua @@ -1,4 +1,5 @@ local bathtubDrain = Action() + function bathtubDrain.onUse(player, item, fromPosition, itemEx, toPosition) local tile = Tile(fromPosition) if tile:getTopCreature() then 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/data/scripts/creaturescripts/monster/boss_lever_death.lua b/data/scripts/creaturescripts/monster/boss_lever_death.lua index 4e035271623..35a86a97e92 100644 --- a/data/scripts/creaturescripts/monster/boss_lever_death.lua +++ b/data/scripts/creaturescripts/monster/boss_lever_death.lua @@ -13,7 +13,7 @@ function onBossDeath.onDeath(creature) return true end - local bossLever = BossLever[name] + local bossLever = BossLever[name:lower()] if not bossLever then return true end diff --git a/data-otservbr-global/scripts/creaturescripts/monster/spawn_system.lua b/data/scripts/creaturescripts/monster/spawn_system.lua similarity index 99% rename from data-otservbr-global/scripts/creaturescripts/monster/spawn_system.lua rename to data/scripts/creaturescripts/monster/spawn_system.lua index 580dba6d07c..710585cced3 100644 --- a/data-otservbr-global/scripts/creaturescripts/monster/spawn_system.lua +++ b/data/scripts/creaturescripts/monster/spawn_system.lua @@ -1,4 +1,5 @@ local monsterDeath = CreatureEvent("monsterDeath") + function monsterDeath.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamageUnjustified) if creature and creature:isMonster() then local self = creature:getStorageValue(MonsterStorage.Spawn.monster_spawn_object) @@ -12,6 +13,7 @@ end monsterDeath:register() local monsterDeathBoss = CreatureEvent("monsterDeathBoss") + function monsterDeathBoss.onDeath(creature, corpse, killer, mostDamage, unjustified, mostDamageUnjustified) if creature and creature:isMonster() then local self = creature:getStorageValue(MonsterStorage.Spawn.monster_spawn_object) diff --git a/data-canary/scripts/creaturescripts/extended_opcode.lua b/data/scripts/creaturescripts/others/#extended_opcode.lua similarity index 100% rename from data-canary/scripts/creaturescripts/extended_opcode.lua rename to data/scripts/creaturescripts/others/#extended_opcode.lua diff --git a/data/scripts/creaturescripts/player/adventure_blessing_login.lua b/data/scripts/creaturescripts/player/adventure_blessing_login.lua index 8ebf88a72e9..79c694d73bc 100644 --- a/data/scripts/creaturescripts/player/adventure_blessing_login.lua +++ b/data/scripts/creaturescripts/player/adventure_blessing_login.lua @@ -1,4 +1,4 @@ -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/blessings.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") local adventurerBlessingLogin = CreatureEvent("AdventurerBlessingLogin") diff --git a/data/scripts/creaturescripts/player/login.lua b/data/scripts/creaturescripts/player/login.lua index 5f9f0e695f4..fe52be71b06 100644 --- a/data/scripts/creaturescripts/player/login.lua +++ b/data/scripts/creaturescripts/player/login.lua @@ -80,7 +80,7 @@ function playerLoginGlobal.onLogin(player) end -- Send Recruiter Outfit - local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. getAccountNumberByPlayerName(getPlayerName(player))) + local resultId = db.storeQuery("SELECT `recruiter` FROM `accounts` WHERE `id`= " .. Game.getPlayerAccountId(getPlayerName(player))) if resultId then local recruiterStatus = Result.getNumber(resultId, "recruiter") local sex = player:getSex() @@ -118,19 +118,19 @@ function playerLoginGlobal.onLogin(player) -- Updates the player's VIP status and executes corresponding actions if applicable. if configManager.getBoolean(configKeys.VIP_SYSTEM_ENABLED) then - local isVipNow = player:isVip() - local wasVip = player:kv():scoped("account"):get("vip-system") or false + local isCurrentlyVip = player:isVip() + local hadVipStatus = player:kv():scoped("account"):get("vip-system") or false - if wasVip ~= isVipNow then - if wasVip then + if hadVipStatus ~= isCurrentlyVip then + if hadVipStatus then player:onRemoveVip() else player:onAddVip(player:getVipDays()) end end - if isVipNow then - CheckPremiumAndPrint(player, MESSAGE_LOGIN) + if isCurrentlyVip then + player:sendVipStatus() end end diff --git a/data/scripts/eventcallbacks/README.md b/data/scripts/eventcallbacks/README.md index 6e0bacfcd6e..bbcee5de3c4 100644 --- a/data/scripts/eventcallbacks/README.md +++ b/data/scripts/eventcallbacks/README.md @@ -16,7 +16,6 @@ Event callbacks are available for several categories of game entities, such as ` - `(bool)` `creatureOnChangeOutfit` - `(ReturnValue)` `creatureOnAreaCombat` - `(ReturnValue)` `creatureOnTargetCombat` -- `(void)` `creatureOnHear` - `(void)` `creatureOnDrainHealth` - `(void)` `creatureOnCombat` - `(bool)` `partyOnJoin` @@ -51,8 +50,6 @@ Event callbacks are available for several categories of game entities, such as ` - `(void)` `playerOnWalk` - `(void)` `monsterOnDropLoot` - `(void)` `monsterPostDropLoot` -- `(void)` `monsterOnSpawn` -- `(void)` `npcOnSpawn` ## Event Callback Usage @@ -102,20 +99,8 @@ callback:register() ```lua local callback = EventCallback("UniqueCallbackName") -function callback.monsterOnSpawn(monster, position) - -- custom behavior when a monster spawns -end - -callback:register() -``` - -### Npc Callback - -```lua -local callback = EventCallback("UniqueCallbackName") - -function callback.npcOnSpawn(npc, position) - -- custom behavior when a npc spawns +function callback.monsterOnDropLoot(monster, corpse) + logger.info("Monster {} has corpse {}", monster:getName(), corpse:getName()); end callback:register() diff --git a/data/scripts/eventcallbacks/creature/on_hear.lua b/data/scripts/eventcallbacks/creature/on_hear.lua deleted file mode 100644 index 2954c81c8fb..00000000000 --- a/data/scripts/eventcallbacks/creature/on_hear.lua +++ /dev/null @@ -1,5 +0,0 @@ -local callback = EventCallback("CreatureOnHearBaseEvent") - -function callback.creatureOnHear(creature, speaker, words, type) end - -callback:register() diff --git a/data/scripts/eventcallbacks/monster/on_spawn.lua b/data/scripts/eventcallbacks/monster/on_spawn.lua deleted file mode 100644 index 5a490a8edac..00000000000 --- a/data/scripts/eventcallbacks/monster/on_spawn.lua +++ /dev/null @@ -1,27 +0,0 @@ -local callback = EventCallback("MonsterOnSpawnBase") - -function callback.monsterOnSpawn(monster, position) - if not monster then - return - end - - HazardMonster.onSpawn(monster, position) - - if monster:getType():isRewardBoss() then - monster:setReward(true) - end - - if not monster:getType():canSpawn(position) then - monster:remove() - else - local spec = Game.getSpectators(position, false, false) - for _, creatureId in pairs(spec) do - local monster = Monster(creatureId) - if monster and not monster:getType():canSpawn(position) then - monster:remove() - end - end - end -end - -callback:register() diff --git a/data/scripts/globalevents/update_guild_war_status.lua b/data/scripts/globalevents/update_guild_war_status.lua new file mode 100644 index 00000000000..e499d5aa22e --- /dev/null +++ b/data/scripts/globalevents/update_guild_war_status.lua @@ -0,0 +1,10 @@ +local updateGuildWarStatus = GlobalEvent("UpdateGuildWarStatus") + +function updateGuildWarStatus.onThink(interval) + local currentTime = os.time() + db.query(string.format("UPDATE `guild_wars` SET `status` = 4, `ended` = %d WHERE `status` = 1 AND `ended` != 0 AND `ended` < %d", currentTime, currentTime)) + return true +end + +updateGuildWarStatus:interval(60000) +updateGuildWarStatus:register() diff --git a/data/scripts/lib/register_monster_type.lua b/data/scripts/lib/register_monster_type.lua index cfb0a6bfaaa..ed5de6421d9 100644 --- a/data/scripts/lib/register_monster_type.lua +++ b/data/scripts/lib/register_monster_type.lua @@ -194,6 +194,9 @@ registerMonsterType.flags = function(mtype, mask) end if mask.flags.rewardBoss then mtype:isRewardBoss(mask.flags.rewardBoss) + mtype.onSpawn = function(monster) + monster:setRewardBoss() + end end if mask.flags.familiar then mtype:familiar(mask.flags.familiar) diff --git a/data/scripts/lib/register_spells.lua b/data/scripts/lib/register_spells.lua index 8c549859640..f2e7cacee3d 100644 --- a/data/scripts/lib/register_spells.lua +++ b/data/scripts/lib/register_spells.lua @@ -386,7 +386,7 @@ AREA_RING1_BURST3 = { { 0, 0, 1, 1, 1, 1, 1, 0, 0 }, { 0, 1, 1, 1, 1, 1, 1, 1, 0 }, { 1, 1, 1, 0, 0, 0, 1, 1, 1 }, - { 1, 1, 1, 0, 3, 0, 1, 1, 1 }, + { 1, 1, 1, 0, 2, 0, 1, 1, 1 }, { 1, 1, 1, 0, 0, 0, 1, 1, 1 }, { 0, 1, 1, 1, 1, 1, 1, 1, 0 }, { 0, 0, 1, 1, 1, 1, 1, 0, 0 }, diff --git a/data-otservbr-global/scripts/movements/others/bath_tub.lua b/data/scripts/movements/bath_tub.lua similarity index 64% rename from data-otservbr-global/scripts/movements/others/bath_tub.lua rename to data/scripts/movements/bath_tub.lua index 7ff7d1fe841..258efae4bb7 100644 --- a/data-otservbr-global/scripts/movements/others/bath_tub.lua +++ b/data/scripts/movements/bath_tub.lua @@ -1,35 +1,38 @@ -local playerBathTub = 26087 - local bathtubEnter = MoveEvent() function bathtubEnter.onStepIn(creature, item, position, fromPosition) - if not creature:isPlayer() then - return false + local player = creature:getPlayer() + if not player then + return true end local condition = Condition(CONDITION_OUTFIT) - condition:setOutfit({ lookTypeEx = playerBathTub }) + condition:setOutfit({ lookTypeEx = 26087 }) condition:setTicks(-1) position:sendMagicEffect(CONST_ME_WATERSPLASH) item:transform(BATHTUB_FILLED_NOTMOVABLE) - creature:addCondition(condition) + player:addCondition(condition) return true end +bathtubEnter:type("stepin") bathtubEnter:id(BATHTUB_FILLED) bathtubEnter:register() local bathtubExit = MoveEvent() + function bathtubExit.onStepOut(creature, item, position, fromPosition) - if not creature:isPlayer() then - return false + local player = creature:getPlayer() + if not player then + return true end item:transform(BATHTUB_FILLED) - creature:removeCondition(CONDITION_OUTFIT) + player:removeCondition(CONDITION_OUTFIT) return true end +bathtubExit:type("stepout") bathtubExit:id(BATHTUB_FILLED_NOTMOVABLE) bathtubExit:register() diff --git a/data/scripts/spells/attack/divine_grenade.lua b/data/scripts/spells/attack/divine_grenade.lua index b1dc6399c7d..488962cb2f8 100644 --- a/data/scripts/spells/attack/divine_grenade.lua +++ b/data/scripts/spells/attack/divine_grenade.lua @@ -35,7 +35,7 @@ local explodeGrenade = function(position, playerId) end local var = {} - var.instantName = "Divine Grenade Explode" + var.instantName = "Divine Grenade" var.runeName = "" var.type = 2 -- VARIANT_POSITION var.pos = position diff --git a/data/scripts/spells/attack/energy_beam.lua b/data/scripts/spells/attack/energy_beam.lua index d3be218c0ca..049470f0ecb 100644 --- a/data/scripts/spells/attack/energy_beam.lua +++ b/data/scripts/spells/attack/energy_beam.lua @@ -28,11 +28,10 @@ local spell = Spell("instant") function spell.onCastSpell(creature, var) local player = creature:getPlayer() - if creature and player and player:instantSkillWOD("Beam Mastery") then - var.runeName = "Beam Mastery" - return combatWOD:execute(creature, var) + if not creature or not player then + return false end - return combat:execute(creature, var) + return player:instantSkillWOD("Beam Mastery") and combatWOD:execute(creature, var) or combat:execute(creature, var) end spell:group("attack") diff --git a/data/scripts/spells/attack/executioners_throw.lua b/data/scripts/spells/attack/executioners_throw.lua index 2f2220625c5..08d700bfe54 100644 --- a/data/scripts/spells/attack/executioners_throw.lua +++ b/data/scripts/spells/attack/executioners_throw.lua @@ -40,28 +40,11 @@ function spell.onCastSpell(creature, var) local grade = creature:revelationStageWOD("Executioner's Throw") if grade == 0 then - creature:sendCancelMessage("You cannot cast this spell") + creature:sendCancelMessage("You need to learn this spell first") creature:getPosition():sendMagicEffect(CONST_ME_POFF) return false end - - local cooldown = 0 - if grade >= 3 then - cooldown = 10 - elseif grade >= 2 then - cooldown = 14 - elseif grade >= 1 then - cooldown = 18 - end - - var.instantName = "Executioner's Throw" - if combat:execute(creature, var) then - local condition = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 261) - condition:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition) - return true - end - return false + return combat:execute(creature, var) end spell:group("attack") @@ -75,7 +58,7 @@ spell:range(5) spell:needTarget(true) spell:blockWalls(true) spell:needWeapon(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(18 * 1000) spell:groupCooldown(2 * 1000) spell:needLearn(true) spell:vocation("knight;true", "elite knight;true") diff --git a/data/scripts/spells/attack/great_death_beam.lua b/data/scripts/spells/attack/great_death_beam.lua index 02a17c78f41..84c75132d76 100644 --- a/data/scripts/spells/attack/great_death_beam.lua +++ b/data/scripts/spells/attack/great_death_beam.lua @@ -17,6 +17,7 @@ end local combat1 = createCombat(initCombat, AREA_BEAM6) local combat2 = createCombat(initCombat, AREA_BEAM7) local combat3 = createCombat(initCombat, AREA_BEAM8) +local combat = { combat1, combat2, combat3 } local spell = Spell("instant") @@ -28,32 +29,15 @@ function spell.onCastSpell(creature, var) local grade = creature:upgradeSpellsWOD("Great Death Beam") if grade == WHEEL_GRADE_NONE then - creature:sendCancelMessage("You cannot cast this spell") + creature:sendCancelMessage("You need to learn this spell first") creature:getPosition():sendMagicEffect(CONST_ME_POFF) return false end - local cooldown = { 10, 8, 6 } - var.runeName = "Beam Mastery" - local executed = false - - local combat = { combat1, combat2, combat3 } - - executed = combat[grade]:execute(creature, var) - - if executed then - local condition = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 260) - local executedCooldown = cooldown[grade] - if executedCooldown ~= nil then - condition:setTicks((executedCooldown * 1000)) - end - creature:addCondition(condition) - return true - end - return false + return combat[grade]:execute(creature, var) end -spell:group("attack") +spell:group("attack", "greatbeams") spell:id(260) spell:name("Great Death Beam") spell:words("exevo max mort") @@ -62,8 +46,8 @@ spell:mana(140) spell:isPremium(false) spell:needDirection(true) spell:blockWalls(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting -spell:groupCooldown(2 * 1000) +spell:cooldown(10 * 1000) +spell:groupCooldown(2 * 1000, 6 * 1000) spell:needLearn(true) spell:vocation("sorcerer;true", "master sorcerer;true") spell:register() diff --git a/data/scripts/spells/attack/great_energy_beam.lua b/data/scripts/spells/attack/great_energy_beam.lua index aae93e95c9a..f6b61f19fa4 100644 --- a/data/scripts/spells/attack/great_energy_beam.lua +++ b/data/scripts/spells/attack/great_energy_beam.lua @@ -28,15 +28,13 @@ local spell = Spell("instant") function spell.onCastSpell(creature, var) local player = creature:getPlayer() - if creature and player and player:instantSkillWOD("Beam Mastery") then - var.runeName = "Beam Mastery" - return combatWOD:execute(creature, var) + if not creature or not player then + return false end - - return combat:execute(creature, var) + return player:instantSkillWOD("Beam Mastery") and combatWOD:execute(creature, var) or combat:execute(creature, var) end -spell:group("attack") +spell:group("attack", "greatbeams") spell:id(23) spell:name("Great Energy Beam") spell:words("exevo gran vis lux") @@ -47,7 +45,7 @@ spell:isPremium(false) spell:needDirection(true) spell:blockWalls(true) spell:cooldown(6 * 1000) -spell:groupCooldown(2 * 1000) +spell:groupCooldown(2 * 1000, 6 * 1000) spell:needLearn(false) spell:vocation("sorcerer;true", "master sorcerer;true") spell:register() diff --git a/data/scripts/spells/attack/ice_burst.lua b/data/scripts/spells/attack/ice_burst.lua index 9e1560f9dc9..fedcd9d5a04 100644 --- a/data/scripts/spells/attack/ice_burst.lua +++ b/data/scripts/spells/attack/ice_burst.lua @@ -14,50 +14,27 @@ combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues") local spell = Spell("instant") function spell.onCastSpell(creature, var) - if not creature or not creature:isPlayer() then - return false - end - local grade = creature:revelationStageWOD("Twin Burst") if grade == 0 then - creature:sendCancelMessage("You cannot cast this spell") + creature:sendCancelMessage("You need to learn this spell first") creature:getPosition():sendMagicEffect(CONST_ME_POFF) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 14 - elseif grade >= 2 then - cooldown = 18 - elseif grade >= 1 then - cooldown = 22 - end - - var.instantName = "Twin Burst" - if combat:execute(creature, var) then - -- Ice cooldown - local condition1 = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 262) - condition1:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition1) - -- Earth cooldown - local condition2 = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 263) - condition2:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition2) - return true - end - return false + return combat:execute(creature, var) end -spell:group("attack") +spell:group("attack", "burstsofnature") spell:id(262) spell:name("Ice Burst") spell:words("exevo ulus frigo") +spell:castSound(SOUND_EFFECT_TYPE_SPELL_ETERNAL_WINTER) spell:level(300) spell:mana(230) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting -spell:groupCooldown(2 * 1000) +spell:isSelfTarget(true) +spell:cooldown(22 * 1000) +spell:groupCooldown(2 * 1000, 22 * 1000) spell:needLearn(true) spell:vocation("druid;true", "elder druid;true") spell:register() diff --git a/data/scripts/spells/attack/terra_burst.lua b/data/scripts/spells/attack/terra_burst.lua index 8a805c0ba48..15ce35c4912 100644 --- a/data/scripts/spells/attack/terra_burst.lua +++ b/data/scripts/spells/attack/terra_burst.lua @@ -14,50 +14,27 @@ combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues") local spell = Spell("instant") function spell.onCastSpell(creature, var) - if not creature or not creature:isPlayer() then - return false - end - local grade = creature:revelationStageWOD("Twin Burst") if grade == 0 then - creature:sendCancelMessage("You cannot cast this spell") + creature:sendCancelMessage("You need to learn this spell first") creature:getPosition():sendMagicEffect(CONST_ME_POFF) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 14 - elseif grade >= 2 then - cooldown = 18 - elseif grade >= 1 then - cooldown = 22 - end - - var.instantName = "Twin Burst" - if combat:execute(creature, var) then - -- Ice cooldown - local condition1 = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 262) - condition1:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition1) - -- Earth cooldown - local condition2 = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 263) - condition2:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition2) - return true - end - return false + return combat:execute(creature, var) end -spell:group("attack") +spell:group("attack", "burstsofnature") spell:id(263) spell:name("Terra Burst") spell:words("exevo ulus tera") +spell:castSound(SOUND_EFFECT_TYPE_SPELL_WRATH_OF_NATURE) spell:level(300) spell:mana(230) spell:isPremium(true) -spell:cooldown(1000) -- Cooldown is calculated on the casting -spell:groupCooldown(2 * 1000) +spell:isSelfTarget(true) +spell:cooldown(22 * 1000) +spell:groupCooldown(2 * 1000, 22 * 1000) spell:needLearn(true) spell:vocation("druid;true", "elder druid;true") spell:register() diff --git a/data/scripts/spells/support/divine_empowerment.lua b/data/scripts/spells/support/divine_empowerment.lua index e05203359f8..248f01a6e0f 100644 --- a/data/scripts/spells/support/divine_empowerment.lua +++ b/data/scripts/spells/support/divine_empowerment.lua @@ -26,18 +26,6 @@ function spell.onCastSpell(creature, var) return false end - local cooldown = 0 - if grade >= 3 then - cooldown = 24 - elseif grade >= 2 then - cooldown = 28 - elseif grade >= 1 then - cooldown = 32 - end - local condition = Condition(CONDITION_SPELLCOOLDOWN, CONDITIONID_DEFAULT, 268) - condition:setTicks((cooldown * 1000) / configManager.getFloat(configKeys.RATE_SPELL_COOLDOWN)) - creature:addCondition(condition) - local position = creature:getPosition() for x = -1, 1 do for y = -1, 1 do @@ -63,7 +51,7 @@ spell:isPremium(true) spell:range(7) spell:isSelfTarget(true) spell:isAggressive(false) -spell:cooldown(1000) -- Cooldown is calculated on the casting +spell:cooldown(32 * 1000) spell:groupCooldown(2 * 1000) spell:needLearn(true) spell:vocation("paladin;true", "royal paladin;true") diff --git a/data/scripts/spells/support/sharpshooter.lua b/data/scripts/spells/support/sharpshooter.lua index 568fec86e00..e5111781562 100644 --- a/data/scripts/spells/support/sharpshooter.lua +++ b/data/scripts/spells/support/sharpshooter.lua @@ -4,9 +4,9 @@ local combat = Combat() combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_GREEN) combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false) -local speed = Condition(CONDITION_HASTE) +local speed = Condition(CONDITION_PARALYZE) speed:setParameter(CONDITION_PARAM_TICKS, spellDuration) -speed:setFormula(0.7, 0, 0.7, 0) +speed:setFormula(0.7, 56, 0.7, 56) combat:addCondition(speed) local exhaustHealGroup = Condition(CONDITION_SPELLGROUPCOOLDOWN) diff --git a/data/scripts/systems/item_tiers.lua b/data/scripts/systems/item_tiers.lua index 06a8321a034..cc7a2a2697d 100644 --- a/data/scripts/systems/item_tiers.lua +++ b/data/scripts/systems/item_tiers.lua @@ -90,7 +90,7 @@ local itemTierClassifications = { }, } --- Item tier with gold price for uprading it +-- Item tier with gold price for upgrading it for classificationId, classificationTable in ipairs(itemTierClassifications) do local itemClassification = Game.createItemClassification(classificationId) local classification = {} diff --git a/data/scripts/talkactions/gm/ban.lua b/data/scripts/talkactions/gm/ban.lua index 0ab07040333..4d7569c78f5 100644 --- a/data/scripts/talkactions/gm/ban.lua +++ b/data/scripts/talkactions/gm/ban.lua @@ -1,48 +1,48 @@ -local banDays = 7 - local ban = TalkAction("/ban") function ban.onSay(player, words, param) -- create log logCommand(player, words, param) - if param == "" then - player:sendCancelMessage("Command param required.") + local params = param:split(",") + if #params < 3 then + player:sendCancelMessage("Command requires 3 parameters: /ban , , ") return true end - local name = param - local reason = "" + local playerName = params[1]:trim() + local banDuration = tonumber(params[2]:trim()) + local banReason = params[3]:trim() - local separatorPos = param:find(",") - if separatorPos then - name = param:sub(0, separatorPos - 1) - reason = string.trim(param:sub(separatorPos + 1)) + if not banDuration or banDuration <= 0 then + player:sendCancelMessage("Ban duration must be a positive number.") + return true end - local accountId = getAccountNumberByPlayerName(name) + local accountId = Game.getPlayerAccountId(playerName) if accountId == 0 then return true end local resultId = db.storeQuery("SELECT 1 FROM `account_bans` WHERE `account_id` = " .. accountId) - if resultId ~= false then - Result.free(resultId) + if resultId then + result.free(resultId) return true end - local timeNow = os.time() - db.query("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (" .. accountId .. ", " .. db.escapeString(reason) .. ", " .. timeNow .. ", " .. timeNow + (banDays * 86400) .. ", " .. player:getGuid() .. ")") + local currentTime = os.time() + local expirationTime = currentTime + (banDuration * 24 * 60 * 60) + db.query(string.format("INSERT INTO `account_bans` (`account_id`, `reason`, `banned_at`, `expires_at`, `banned_by`) VALUES (%d, %s, %d, %d, %d)", accountId, db.escapeString(banReason), currentTime, expirationTime, player:getGuid())) - local target = Player(name) + local target = Player(playerName) if target then - local text = target:getName() .. " has been banned" - player:sendTextMessage(MESSAGE_ADMINISTRATOR, text) - Webhook.sendMessage("Player Banned", text .. " reason: " .. reason .. ". (by: " .. player:getName() .. ")", WEBHOOK_COLOR_YELLOW, announcementChannels["serverAnnouncements"]) + player:sendTextMessage(MESSAGE_ADMINISTRATOR, string.format("%s has been banned for %d days.", target:getName(), banDuration)) target:remove() + Webhook.sendMessage("Player Banned", string.format("%s has been banned for %d days. Reason: %s (by: %s)", target:getName(), banDuration, banReason, player:getName()), WEBHOOK_COLOR_YELLOW, announcementChannels["serverAnnouncements"]) else - player:sendTextMessage(MESSAGE_ADMINISTRATOR, name .. " has been banned.") + player:sendTextMessage(MESSAGE_ADMINISTRATOR, string.format("%s has been banned for %d days.", playerName, banDuration)) end + return true end ban:separator(" ") diff --git a/data/scripts/talkactions/gm/bless_status.lua b/data/scripts/talkactions/gm/bless_status.lua index 7cb861947dd..a316330db31 100644 --- a/data/scripts/talkactions/gm/bless_status.lua +++ b/data/scripts/talkactions/gm/bless_status.lua @@ -1,4 +1,4 @@ -dofile(CORE_DIRECTORY .. "/modules/scripts/blessings/blessings.lua") +dofile(CORE_DIRECTORY .. "/libs/systems/blessing.lua") local blessStatus = TalkAction("/bless") @@ -6,7 +6,7 @@ function blessStatus.onSay(player, words, param) -- create log logCommand(player, words, param) - Blessings.sendBlessStatus(player) + player:sendBlessStatus() return true end diff --git a/data/scripts/talkactions/gm/gold_highscore.lua b/data/scripts/talkactions/gm/gold_highscore.lua index de923712887..a68df6900a5 100644 --- a/data/scripts/talkactions/gm/gold_highscore.lua +++ b/data/scripts/talkactions/gm/gold_highscore.lua @@ -1,28 +1,33 @@ -local gold_rank = TalkAction("/goldrank") +local goldRank = TalkAction("/goldrank") -function gold_rank.onSay(player, words, param) +function goldRank.onSay(player, words, param) -- create log logCommand(player, words, param) - local resultId = db.storeQuery("SELECT `balance`, `name` FROM `players` WHERE group_id < 3 ORDER BY balance DESC LIMIT 10") - if resultId ~= false then - local str = "" - local x = 0 - repeat - x = x + 1 - str = str .. "\n" .. x .. "- " .. Result.getString(resultId, "name") .. " (" .. Result.getNumber(resultId, "balance") .. ")." - until not Result.next(resultId) - Result.free(resultId) - if str == "" then - str = "No highscore to show." - end - player:popupFYI("Current gold highscore for this server:\n" .. str) - else + local highscoreQuery = db.storeQuery("SELECT `balance`, `name` FROM `players` WHERE group_id < 3 ORDER BY balance DESC LIMIT 10") + if not highscoreQuery then player:sendCancelMessage("No highscore to show.") + return true end + + local highscoreList = "" + local rank = 0 + repeat + rank = rank + 1 + local playerName = Result.getString(highscoreQuery, "name") + local playerBalance = FormatNumber(Result.getNumber(highscoreQuery, "balance")) + highscoreList = highscoreList .. "\n" .. rank .. "- " .. playerName .. " (" .. playerBalance .. ")." + until not Result.next(highscoreQuery) + + Result.free(highscoreQuery) + if highscoreList == "" then + highscoreList = "No highscore to show." + end + + player:popupFYI("Current gold highscore for this server:\n" .. highscoreList) return true end -gold_rank:separator(" ") -gold_rank:groupType("gamemaster") -gold_rank:register() +goldRank:separator(" ") +goldRank:groupType("gamemaster") +goldRank:register() diff --git a/data/scripts/talkactions/god/add_addon.lua b/data/scripts/talkactions/god/add_addon.lua index 026336e270e..bbcd21c94fa 100644 --- a/data/scripts/talkactions/god/add_addon.lua +++ b/data/scripts/talkactions/god/add_addon.lua @@ -1,45 +1,305 @@ -local addons = TalkAction("/addaddon") +local addaddon = TalkAction("/addaddon") -function addons.onSay(player, words, param) - -- create log - logCommand(player, words, param) +local looktypes = { + -- Female Outfits + 136, + 137, + 138, + 139, + 140, + 141, + 142, + 147, + 148, + 149, + 150, + 155, + 156, + 157, + 158, + 252, + 269, + 270, + 279, + 288, + 324, + 329, + 336, + 366, + 431, + 433, + 464, + 466, + 471, + 513, + 514, + 542, + 575, + 578, + 618, + 620, + 632, + 635, + 636, + 664, + 666, + 683, + 694, + 696, + 698, + 724, + 732, + 745, + 749, + 759, + 845, + 852, + 874, + 885, + 900, + 909, + 929, + 956, + 958, + 963, + 965, + 967, + 969, + 971, + 973, + 975, + 1020, + 1024, + 1043, + 1050, + 1057, + 1070, + 1095, + 1103, + 1128, + 1147, + 1162, + 1174, + 1187, + 1203, + 1205, + 1207, + 1211, + 1244, + 1246, + 1252, + 1271, + 1280, + 1283, + 1289, + 1293, + 1323, + 1332, + 1339, + 1372, + 1383, + 1385, + 1387, + 1416, + 1437, + 1445, + 1450, + 1456, + 1461, + 1490, + 1501, + 1569, + 1576, + 1582, + 1598, + 1613, + 1619, + 1663, + 1676, + 1681, - local target - local split = param:split(",") - local name = split[1] + -- Male Outfits + 1714, + 1723, + 1726, + 1746, + 1775, + 1777, + 128, + 129, + 130, + 131, + 132, + 133, + 134, + 143, + 144, + 145, + 146, + 151, + 152, + 153, + 154, + 251, + 268, + 273, + 278, + 289, + 325, + 328, + 335, + 367, + 430, + 432, + 463, + 465, + 472, + 512, + 516, + 541, + 574, + 577, + 610, + 619, + 633, + 634, + 637, + 665, + 667, + 684, + 695, + 697, + 699, + 725, + 733, + 746, + 750, + 760, + 846, + 853, + 873, + 884, + 899, + 908, + 931, + 955, + 957, + 962, + 964, + 966, + 968, + 970, + 972, + 974, + 1021, + 1023, + 1042, + 1051, + 1056, + 1069, + 1094, + 1102, + 1127, + 1146, + 1161, + 1173, + 1186, + 1202, + 1204, + 1206, + 1210, + 1243, + 1245, + 1251, + 1270, + 1279, + 1282, + 1288, + 1292, + 1322, + 1331, + 1338, + 1371, + 1382, + 1384, + 1386, + 1415, + 1436, + 1444, + 1449, + 1457, + 1460, + 1489, + 1500, + 1568, + 1575, + 1581, + 1597, + 1612, + 1618, + 1662, + 1675, + 1680, + 1713, + 1722, + 1725, + 1745, + 1774, + 1776, +} + +function addaddon.onSay(player, words, param) + -- Create log + logCommand(player, words, param) if param == "" then - target = player:getTarget() - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Gives players the ability to wear addon for a specific outfit. Usage: /addaddon , ") - return true - end - else - target = Player(name) + player:sendCancelMessage("Command param required.") + return true end - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player " .. name .. " is currently not online.") + local split = param:split(",") + if #split < 3 then + player:sendCancelMessage("Usage: /addaddon , , ") return true end - local looktype = tonumber(split[2]) - if not looktype then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Invalid looktype.") + local playerName = split[1] + local target = Player(playerName) + + if not target then + player:sendCancelMessage("Player not found.") return true end - local addons = tonumber(split[3]) - if not addons or addons < 0 or addons > 3 then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Invalid addon.") + local addonParam = string.trim(split[2]) + local addonValue = tonumber(string.trim(split[3])) + + if not addonValue or addonValue < 0 or addonValue > 3 then + player:sendCancelMessage("Invalid addon value. It should be between 0 and 3.") return true end - target:addOutfitAddon(looktype, addons) - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Addon for looktype " .. looktype .. "a for " .. target:getName() .. " set to " .. addons .. ".") + if addonParam == "all" then + for _, looktype in ipairs(looktypes) do + target:addOutfitAddon(looktype, addonValue) + end + + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added addon %d to all your looktypes.", player:getName(), addonValue)) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added addon %d to all looktypes of player %s.", addonValue, target:getName())) + else + local looktype = tonumber(addonParam) + if not looktype then + player:sendCancelMessage("Invalid looktype.") + return true + end + + target:addOutfitAddon(looktype, addonValue) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("Addon %d for looktype %d set for player %s.", addonValue, looktype, target:getName())) + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added addon %d for looktype %d to you.", player:getName(), addonValue, looktype)) + end return true end -addons:separator(" ") -addons:groupType("god") -addons:register() +addaddon:separator(" ") +addaddon:groupType("god") +addaddon:register() diff --git a/data/scripts/talkactions/god/add_addons.lua b/data/scripts/talkactions/god/add_addons.lua deleted file mode 100644 index 5498ae1e11b..00000000000 --- a/data/scripts/talkactions/god/add_addons.lua +++ /dev/null @@ -1,277 +0,0 @@ --- /addaddons playername - -local addons = TalkAction("/addaddons") -local looktypes = { - - -- Female Outfits - 136, - 137, - 138, - 139, - 140, - 141, - 142, - 147, - 148, - 149, - 150, - 155, - 156, - 157, - 158, - 252, - 269, - 270, - 279, - 288, - 324, - 329, - 336, - 366, - 431, - 433, - 464, - 466, - 471, - 513, - 514, - 542, - 575, - 578, - 618, - 620, - 632, - 635, - 636, - 664, - 666, - 683, - 694, - 696, - 698, - 724, - 732, - 745, - 749, - 759, - 845, - 852, - 874, - 885, - 900, - 909, - 929, - 956, - 958, - 963, - 965, - 967, - 969, - 971, - 973, - 975, - 1020, - 1024, - 1043, - 1050, - 1057, - 1070, - 1095, - 1103, - 1128, - 1147, - 1162, - 1174, - 1187, - 1203, - 1205, - 1207, - 1211, - 1244, - 1246, - 1252, - 1271, - 1280, - 1283, - 1289, - 1293, - 1323, - 1332, - 1339, - 1372, - 1383, - 1385, - 1387, - 1416, - 1437, - 1445, - 1450, - 1456, - 1461, - 1490, - 1501, - 1569, - 1576, - 1582, - 1598, - 1613, - 1619, - 1663, - 1676, - 1681, - - -- Male Outfits - 128, - 129, - 130, - 131, - 132, - 133, - 134, - 143, - 144, - 145, - 146, - 151, - 152, - 153, - 154, - 251, - 268, - 273, - 278, - 289, - 325, - 328, - 335, - 367, - 430, - 432, - 463, - 465, - 472, - 512, - 516, - 541, - 574, - 577, - 610, - 619, - 633, - 634, - 637, - 665, - 667, - 684, - 695, - 697, - 699, - 725, - 733, - 746, - 750, - 760, - 846, - 853, - 873, - 884, - 899, - 908, - 931, - 955, - 957, - 962, - 964, - 966, - 968, - 970, - 972, - 974, - 1021, - 1023, - 1042, - 1051, - 1056, - 1069, - 1094, - 1102, - 1127, - 1146, - 1161, - 1173, - 1186, - 1202, - 1204, - 1206, - 1210, - 1243, - 1245, - 1251, - 1270, - 1279, - 1282, - 1288, - 1292, - 1322, - 1331, - 1338, - 1371, - 1382, - 1384, - 1386, - 1415, - 1436, - 1444, - 1449, - 1457, - 1460, - 1489, - 1500, - 1568, - 1575, - 1581, - 1597, - 1612, - 1618, - 1662, - 1675, - 1680, -} - -function addons.onSay(player, words, param) - -- create log - logCommand(player, words, param) - - local target - if param == "" then - target = player:getTarget() - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Gives players the ability to wear all addons. Usage: /addaddons ") - return true - end - else - target = Player(param) - end - - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player " .. param .. " is currently not online.") - return true - end - - if player:getAccountType() < ACCOUNT_TYPE_GOD then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Cannot perform action.") - return true - end - - for i = 1, #looktypes do - target:addOutfitAddon(looktypes[i], 3) - end - - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All addons unlocked for " .. target:getName() .. ".") - target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All of your addons have been unlocked!") - return true -end - -addons:separator(" ") -addons:groupType("god") -addons:register() diff --git a/data/scripts/talkactions/god/add_mount.lua b/data/scripts/talkactions/god/add_mount.lua index b8b2f00dda1..5dc8c9a97fb 100644 --- a/data/scripts/talkactions/god/add_mount.lua +++ b/data/scripts/talkactions/god/add_mount.lua @@ -1,13 +1,7 @@ ---[[ - /addmount playername, mount -]] +local addmount = TalkAction("/addmount") -local printConsole = true - -local addOutfit = TalkAction("/addmount") - -function addOutfit.onSay(player, words, param) - -- create log +function addmount.onSay(player, words, param) + -- Create log logCommand(player, words, param) if param == "" then @@ -16,23 +10,41 @@ function addOutfit.onSay(player, words, param) end local split = param:split(",") - local name = split[1] - - local target = Player(name) - if target then - local mount = tonumber(split[2]) - target:addMount(mount) - target:sendTextMessage(MESSAGE_ADMINISTRATOR, "" .. player:getName() .. " has been added a new mount for you.") - player:sendTextMessage(MESSAGE_ADMINISTRATOR, "You have sucessfull added mount " .. mount .. " to the player " .. target:getName() .. ".") - if printConsole then - logger.info("[addOutfit.onSay] - Player: {} has been added mount: {} to the player: {}", player:getName(), lookType, target:getName()) - end + if #split < 2 then + player:sendCancelMessage("Usage: /addmount , ") + return true + end + + local playerName = split[1] + local target = Player(playerName) + + if not target then + player:sendCancelMessage("Player not found.") return true end - player:sendCancelMessage("Player not found.") + + local mountParam = string.trim(split[2]) + if mountParam == "all" then + for mountId = 1, 231 do + target:addMount(mountId) + end + + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added all mounts to you.", player:getName())) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added all mounts to player %s.", target:getName())) + else + local mountId = tonumber(mountParam) + if not mountId then + player:sendCancelMessage("Invalid mount ID.") + return true + end + + target:addMount(mountId) + target:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added a new mount for you.", player:getName())) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added mount %d to player %s.", mountId, target:getName())) + end return true end -addOutfit:separator(" ") -addOutfit:groupType("god") -addOutfit:register() +addmount:separator(" ") +addmount:groupType("god") +addmount:register() diff --git a/data/scripts/talkactions/god/add_mounts.lua b/data/scripts/talkactions/god/add_mounts.lua deleted file mode 100644 index 3de09916505..00000000000 --- a/data/scripts/talkactions/god/add_mounts.lua +++ /dev/null @@ -1,32 +0,0 @@ --- /addmounts playername - -local mounts = TalkAction("/addmounts") -function mounts.onSay(player, words, param) - local target - if param == "" then - target = player:getTarget() - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Unlocks all mounts for certain player. Usage: /mounts ") - return true - end - else - target = Player(param) - end - - if not target then - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Player " .. param .. " is not currently online.") - return true - end - - for i = 1, 221 do - target:addMount(i) - end - - player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All mounts unlocked for: " .. target:getName()) - target:sendTextMessage(MESSAGE_EVENT_ADVANCE, "All of your mounts have been unlocked!") - return true -end - -mounts:separator(" ") -mounts:groupType("god") -mounts:register() diff --git a/data/scripts/talkactions/god/add_outfit.lua b/data/scripts/talkactions/god/add_outfit.lua deleted file mode 100644 index a27fb4f8a18..00000000000 --- a/data/scripts/talkactions/god/add_outfit.lua +++ /dev/null @@ -1,42 +0,0 @@ ---[[ - /addoutfit playername, looktype - make sure you’re adding a male outfit to a male character - if you try to add a female outfit to a male character, it won’t work -]] - -local printConsole = true - -local addOutfit = TalkAction("/addoutfit") - -function addOutfit.onSay(player, words, param) - -- create log - logCommand(player, words, param) - - if param == "" then - player:sendCancelMessage("Command param required.") - return true - end - - local split = param:split(",") - local name = split[1] - - local target = Player(name) - if target then - local lookType = tonumber(split[2]) - target:addOutfit(lookType) - target:sendTextMessage(MESSAGE_ADMINISTRATOR, "" .. player:getName() .. " has been added a new outfit for you.") - player:sendTextMessage(MESSAGE_ADMINISTRATOR, "You have sucessfull added looktype " .. lookType .. " to the player " .. target:getName() .. ".") - if printConsole then - logger.info("[addOutfit.onSay] - Player: {} has been added looktype: {} to the player: {}", player:getName(), lookType, target:getName()) - end - return true - else - player:sendCancelMessage("Player not found.") - return true - end - return true -end - -addOutfit:separator(" ") -addOutfit:groupType("god") -addOutfit:register() diff --git a/data/scripts/talkactions/god/add_skill.lua b/data/scripts/talkactions/god/add_skill.lua index 09d240ece4d..3d082f656af 100644 --- a/data/scripts/talkactions/god/add_skill.lua +++ b/data/scripts/talkactions/god/add_skill.lua @@ -1,25 +1,20 @@ +local skillMap = { + club = SKILL_CLUB, + sword = SKILL_SWORD, + axe = SKILL_AXE, + dist = SKILL_DISTANCE, + shield = SKILL_SHIELD, + fish = SKILL_FISHING, +} + local function getSkillId(skillName) - if skillName == "club" then - return SKILL_CLUB - elseif skillName == "sword" then - return SKILL_SWORD - elseif skillName == "axe" then - return SKILL_AXE - elseif skillName:sub(1, 4) == "dist" then - return SKILL_DISTANCE - elseif skillName:sub(1, 6) == "shield" then - return SKILL_SHIELD - elseif skillName:sub(1, 4) == "fish" then - return SKILL_FISHING - else - return SKILL_FIST - end + return skillMap[skillName:match("^%a+")] or SKILL_FIST end local addSkill = TalkAction("/addskill") function addSkill.onSay(player, words, param) - -- create log + -- Create log logCommand(player, words, param) if param == "" then @@ -28,39 +23,51 @@ function addSkill.onSay(player, words, param) end local split = param:split(",") - if not split[2] then - player:sendCancelMessage("Insufficient parameters.") + if #split < 2 then + player:sendCancelMessage("Usage: /addskill , , [amount]") return true end - local target = Player(split[1]) - if not target then - player:sendCancelMessage("A player with that name is not online.") + local targetPlayerName = split[1]:trim() + local targetPlayer = Player(targetPlayerName) + + if not targetPlayer then + player:sendCancelMessage("Player not found.") return true end - split[2] = split[2]:trimSpace() + local skillParam = split[2]:trim() + local skillIncreaseAmount = tonumber(split[3]) or 1 + local skillPrefix = skillParam:sub(1, 1) - local count = 1 - if split[3] then - count = tonumber(split[3]) - end + if skillPrefix == "l" then + local targetNewLevel = targetPlayer:getLevel() + skillIncreaseAmount + local targetNewExp = Game.getExperienceForLevel(targetNewLevel) + local experienceToAdd = targetNewExp - targetPlayer:getExperience() + local levelText = (skillIncreaseAmount > 1) and "levels" or "level" - local ch = split[2]:sub(1, 1) - if ch == "l" or ch == "e" then - targetLevel = target:getLevel() + count - targetExp = Game.getExperienceForLevel(targetLevel) - addExp = targetExp - target:getExperience() - target:addExperience(addExp, false) - elseif ch == "m" then - for i = 1, count do - target:addManaSpent(target:getVocation():getRequiredManaSpent(target:getBaseMagicLevel() + 1) - target:getManaSpent(), true) + targetPlayer:addExperience(experienceToAdd, false) + targetPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added %d %s to you.", player:getName(), skillIncreaseAmount, levelText)) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added %d %s to player %s.", skillIncreaseAmount, levelText, targetPlayer:getName())) + elseif skillPrefix == "m" then + for _ = 1, skillIncreaseAmount do + local requiredManaSpent = targetPlayer:getVocation():getRequiredManaSpent(targetPlayer:getBaseMagicLevel() + 1) + targetPlayer:addManaSpent(requiredManaSpent - targetPlayer:getManaSpent(), true) end + + local magicText = (skillIncreaseAmount > 1) and "magic levels" or "magic level" + targetPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added %d %s to you.", player:getName(), skillIncreaseAmount, magicText)) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added %d %s to player %s.", skillIncreaseAmount, magicText, targetPlayer:getName())) else - local skillId = getSkillId(split[2]) - for i = 1, count do - target:addSkillTries(skillId, target:getVocation():getRequiredSkillTries(skillId, target:getSkillLevel(skillId) + 1) - target:getSkillTries(skillId), true) + local skillId = getSkillId(skillParam) + for _ = 1, skillIncreaseAmount do + local requiredSkillTries = targetPlayer:getVocation():getRequiredSkillTries(skillId, targetPlayer:getSkillLevel(skillId) + 1) + targetPlayer:addSkillTries(skillId, requiredSkillTries - targetPlayer:getSkillTries(skillId), true) end + + local skillText = (skillIncreaseAmount > 1) and "skill levels" or "skill level" + targetPlayer:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("%s has added %d %s %s to you.", player:getName(), skillIncreaseAmount, skillParam, skillText)) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, string.format("You have successfully added %d %s %s to player %s.", skillIncreaseAmount, skillParam, skillText, targetPlayer:getName())) end return true end diff --git a/data/scripts/talkactions/god/manage_monster.lua b/data/scripts/talkactions/god/manage_monster.lua index da110d59265..106acefa078 100644 --- a/data/scripts/talkactions/god/manage_monster.lua +++ b/data/scripts/talkactions/god/manage_monster.lua @@ -1,37 +1,38 @@ -local function createCreaturesAround(player, maxRadius, creatureName, creatureCount, creatureForge, boolForceCreate) - local position = player:getPosition() - local createdCount = 0 +local function createCreaturesAround(player, maxRadius, creatureName, creatureCount, creatureForge, forceCreateMonsters) + local playerPosition = player:getPosition() + local createdCreatureCount = 0 local sendMessage = false local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(creatureForge, player) + for radius = 1, maxRadius do - if createdCount >= creatureCount then + if createdCreatureCount >= creatureCount then break end - local minX = position.x - radius - local maxX = position.x + radius - local minY = position.y - radius - local maxY = position.y + radius + local minX, maxX = playerPosition.x - radius, playerPosition.x + radius + local minY, maxY = playerPosition.y - radius, playerPosition.y + radius for dx = minX, maxX do for dy = minY, maxY do - if (dx == minX or dx == maxX or dy == minY or dy == maxY) and createdCount < creatureCount then - local checkPosition = Position(dx, dy, position.z) + if (dx == minX or dx == maxX or dy == minY or dy == maxY) and createdCreatureCount < creatureCount then + local checkPosition = Position(dx, dy, playerPosition.z) local tile = Tile(checkPosition) if tile and not tile:hasProperty(CONST_PROP_IMMOVABLEBLOCKSOLID) then - local monster = Game.createMonster(creatureName, checkPosition, false, boolForceCreate) + local monster = Game.createMonster(creatureName, checkPosition, false, forceCreateMonsters) if monster then - createdCount = createdCount + 1 + createdCreatureCount = createdCreatureCount + 1 monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - position:sendMagicEffect(CONST_ME_MAGIC_RED) - if creatureForge ~= nil and monster:isForgeable() then + playerPosition:sendMagicEffect(CONST_ME_MAGIC_RED) + + if creatureForge and monster:isForgeable() then local monsterType = monster:getType() if canSetFiendish then - SetFiendish(monsterType, position, player, monster) + SetFiendish(monsterType, playerPosition, player, monster) end + if canSetInfluenced then SetInfluenced(monsterType, monster, player, influencedLevel) end - elseif notSendMessage then + elseif not sendMessage then sendMessage = true end end @@ -40,86 +41,58 @@ local function createCreaturesAround(player, maxRadius, creatureName, creatureCo end end end - if sendMessage == true then + + if sendMessage then player:sendCancelMessage("Only allowed monsters can be fiendish or influenced.") end - - logger.info("Player {} created '{}' monsters", player:getName(), createdCount) end local createMonster = TalkAction("/m") --- @function createMonster.onSay --- @desc TalkAction to create monsters with multiple options. --- @param player: The player executing the command. --- @param words: Command words. --- @param param: String containing the command parameters. --- Format: "/m monstername, monstercount, [fiendish/influenced level], spawnRadius, [forceCreate]" --- Example: "/m rat, 10, fiendish, 5, true" --- @param: the last param is by default "false", if add "," or any value it's set to true --- @return true if the command is executed successfully, false otherwise. function createMonster.onSay(player, words, param) -- create log logCommand(player, words, param) + if param == "" then player:sendCancelMessage("Monster name param required.") - logger.error("[createMonster.onSay] - Monster name param not found.") return true end - local position = player:getPosition() - - local split = param:split(",") - local monsterName = split[1] - local monsterCount = 0 - if split[2] then - split[2] = split[2]:trimSpace() - monsterCount = tonumber(split[2]) - end - - local monsterForge = nil - if split[3] then - split[3] = split[3]:trimSpace() - monsterForge = split[3] - end + local playerPosition = player:getPosition() + local splitParams = param:split(",") + local monsterName = splitParams[1] + local monsterCount = tonumber(splitParams[2] or 1) + local monsterForge = splitParams[3] and splitParams[3]:trimSpace() or nil + local spawnRadius = tonumber(splitParams[4] or 5) + local forceCreate = splitParams[5] and true or false if monsterCount > 1 then - local spawnRadius = 5 - if split[4] then - split[4] = split[4]:trimSpace() - spawnRadius = split[4] - print(spawnRadius) - end - - local forceCreate = false - if split[5] then - forceCreate = true - end - createCreaturesAround(player, spawnRadius, monsterName, monsterCount, monsterForge, forceCreate) return true end - local monster = Game.createMonster(monsterName, position) + local monster = Game.createMonster(monsterName, playerPosition) if monster then local canSetFiendish, canSetInfluenced, influencedLevel = CheckDustLevel(monsterForge, player) monster:getPosition():sendMagicEffect(CONST_ME_TELEPORT) - position:sendMagicEffect(CONST_ME_MAGIC_RED) - if monsterForge ~= nil and not monster:isForgeable() then + playerPosition:sendMagicEffect(CONST_ME_MAGIC_RED) + + if monsterForge and not monster:isForgeable() then player:sendCancelMessage("Only allowed monsters can be fiendish or influenced.") return true end local monsterType = monster:getType() if canSetFiendish then - SetFiendish(monsterType, position, player, monster) + SetFiendish(monsterType, playerPosition, player, monster) end + if canSetInfluenced then SetInfluenced(monsterType, monster, player, influencedLevel) end else player:sendCancelMessage("There is not enough room.") - position:sendMagicEffect(CONST_ME_POFF) + playerPosition:sendMagicEffect(CONST_ME_POFF) end return true end @@ -128,29 +101,27 @@ createMonster:separator(" ") createMonster:groupType("god") createMonster:register() ------------------ Rename monster name ----------------- local setMonsterName = TalkAction("/setmonstername") --- @function setMonsterName.onSay --- @desc TalkAction to rename nearby monsters within a radius of 4 sqm. --- Format: "/setmonstername newName" function setMonsterName.onSay(player, words, param) + -- create log + logCommand(player, words, param) + if param == "" then player:sendCancelMessage("Command param required.") return true end - local split = param:split(",") - local monsterNewName = split[1] - + local splitParams = param:split(",") + local newMonsterName = splitParams[1] local spectators, spectator = Game.getSpectators(player:getPosition(), false, false, 4, 4, 4, 4) + for i = 1, #spectators do spectator = spectators[i] if spectator:isMonster() then - spectator:setName(monsterNewName) + spectator:setName(newMonsterName) end end - return true end diff --git a/data/scripts/talkactions/player/vip.lua b/data/scripts/talkactions/player/vip.lua index 65ca4be99f8..a80f6dd54dc 100644 --- a/data/scripts/talkactions/player/vip.lua +++ b/data/scripts/talkactions/player/vip.lua @@ -1,12 +1,10 @@ local vip = TalkAction("!checkvip", "!vip") function vip.onSay(player, words, param) - if not player:isVip() then - local msg = "You do not have VIP on your account." - player:sendCancelMessage(msg) - player:sendTextMessage(MESSAGE_STATUS, msg) + if player:isVip() then + player:sendVipStatus() else - CheckPremiumAndPrint(player, MESSAGE_STATUS) + player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You do not have VIP on your account.") end return true end diff --git a/docs/python-scripts/convert_monsters_callbacks.py b/docs/python-scripts/convert_monsters_callbacks.py new file mode 100644 index 00000000000..140b2562df0 --- /dev/null +++ b/docs/python-scripts/convert_monsters_callbacks.py @@ -0,0 +1,116 @@ +""" +Script for processing Lua files in a project. + +This script is designed to modify `.lua` files in the root directory of the project and all of its subdirectories. +The following modifications are made to each `.lua` file: +1. Remove empty callback functions. +2. Remove the 'onAppear' callback function entirely, including its corresponding `end`. +3. Clean up unnecessary blank lines resulting from the removal of callback functions. + +Usage: +1. Save this script in the `docs/python-scripts` directory of your project. +2. Open a terminal and navigate to the `docs/python-scripts` directory: + cd path/to/your/project/docs/python-scripts +3. Run the script using Python: + python convert_monsters_callbacks.py + +Prerequisites: +- Ensure Python 3 is installed. +- Make sure you have read and write permissions for all `.lua` files in the project directory. + +Output: +- The script will print the root directory being processed. +- At the end, it will output the number of files that were modified. + +Example: +Root path: /path/to/your/project +Script completed. Modified 5 file(s). +""" + +import re +import os + +def get_root_path(): + """Get the root path of the project (two levels above the current script directory).""" + return os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) + +def process_lua_code(code): + """Process the Lua code: remove specific callbacks and clean up empty lines. + + Args: + code (str): The Lua code to be processed. + + Returns: + str: The modified Lua code. + """ + # Remove specific callbacks including 'onAppear' and empty callbacks + code = re.sub(r'\n?mType\.onAppear = function\(.*?\)\n(.*?)\nend\n?', '', code, flags=re.DOTALL) + code = re.sub(r'\n?mType\.\w+ = function\(.*?\) end\n?', '', code) + + # Remove extra blank lines created by the removal of callbacks + code = re.sub(r'\n{3,}', '\n\n', code) # Limit multiple blank lines to just two + + return code + +def process_lua_file(file_path): + """Process a single Lua file by applying the required modifications. + + Args: + file_path (str): The path to the Lua file to be processed. + + Returns: + bool: True if the file was modified and saved, False otherwise. + """ + try: + with open(file_path, 'r', encoding='utf-8') as file: + code = file.read() + except Exception as e: + print(f"Error reading file {file_path}: {e}") + return False + + original_code = code + modified_code = process_lua_code(code) + + if modified_code != original_code: + try: + with open(file_path, 'w', encoding='utf-8') as file: + file.write(modified_code) + return True + except Exception as e: + print(f"Error writing file {file_path}: {e}") + return False + +def process_all_lua_files(root_path): + """Process all Lua files in the root path and its subdirectories. + + Args: + root_path (str): The root directory in which to search for Lua files. + + Returns: + int: The count of modified Lua files. + """ + modified_files_count = 0 + + for dirpath, _, filenames in os.walk(root_path): + for filename in filenames: + if filename.endswith(".lua"): + file_path = os.path.join(dirpath, filename) + if process_lua_file(file_path): + modified_files_count += 1 + + return modified_files_count + +def main(): + """Main function to run the script. + + This function determines the root path of the project, processes all Lua files + found in the root path and subdirectories, and prints the number of files modified. + """ + root_path = get_root_path() + print(f"Root path: {root_path}") + + modified_files_count = process_all_lua_files(root_path) + print(f"Script completed. Modified {modified_files_count} file(s).") + +if __name__ == "__main__": + main() diff --git a/docs/python-scripts/modify_lua_script_interfaces.py b/docs/python-scripts/modify_lua_script_interfaces.py new file mode 100644 index 00000000000..881a8453d90 --- /dev/null +++ b/docs/python-scripts/modify_lua_script_interfaces.py @@ -0,0 +1,211 @@ +import os +import re +import argparse + +# Functions that modify the file + +def remove_constructor_and_destructor(content): + # Remove the class constructor and destructor, including a blank line after the destructor + pattern = r"explicit\s+\w+\(lua_State\* L\)\s*:\s*LuaScriptInterface\(\"[^\"]+\"\)\s*\{[^\}]*\}\n\s*~\w+\(\)\s*override\s*=\s*default;\n\s*\n?" + content = re.sub(pattern, "", content, flags=re.DOTALL) + return content + +def remove_include_luascript(content): + # Remove the specified include and the blank line below it + pattern = r'#include\s+"lua/scripts/luascript.hpp"\n\n?' + content = re.sub(pattern, "", content) + return content + +def remove_final_luascriptinterface(content): + # Remove "final : LuaScriptInterface", "public LuaScriptInterface", "final :", and "LuaScriptInterface" alone + pattern = r'final\s*:\s*public\s+LuaScriptInterface|public\s+LuaScriptInterface|final\s*:\s*|LuaScriptInterface\s*' + content = re.sub(pattern, "", content) + # Remove extra spaces between the class name and the opening block + content = re.sub(r'class\s+(\w+)\s*\{', r'class \1 {', content) + return content + +def move_init_function_to_cpp(hpp_content, cpp_content, class_name): + # Extracts the init function from the hpp, keeping the signature + pattern = r'static void init\(lua_State\* L\)\s*\{[^\}]*\}' + match = re.search(pattern, hpp_content, flags=re.DOTALL) + if match: + # Keep the function signature in the hpp, but remove the body + init_function_signature = "static void init(lua_State* L);" + hpp_content = re.sub(pattern, init_function_signature, hpp_content, flags=re.DOTALL) + + # Adjust the function signature for the cpp + init_function = match.group() + init_function = re.sub(r'static void\s+', f'void {class_name}::', init_function) + # Remove extra indentation + init_function = init_function.replace(' \n\t\t', '\n\t') + # Remove the extra tab from the function closure + init_function = init_function.replace('\n\t}', '\n}') + + # Add a blank line before and after the function + init_function = f"\n{init_function}\n" + + # Add the function to the beginning of the cpp, after the includes + last_include = re.findall(r'#include\s+<[^>]+>|#include\s+"[^"]+"', cpp_content) + if last_include: + last_include_pos = cpp_content.rfind(last_include[-1]) + len(last_include[-1]) + cpp_content = cpp_content[:last_include_pos] + "\n" + init_function + cpp_content[last_include_pos:] + else: + cpp_content = init_function + cpp_content + return hpp_content, cpp_content + +def add_include_to_cpp(cpp_content): + # Add the new include after the last include, if it is not already present + include_statement = '#include "lua/functions/lua_functions_loader.hpp"' + if include_statement not in cpp_content: + # Locate the last include + last_include = re.findall(r'#include\s+<[^>]+>|#include\s+"[^"]+"', cpp_content) + if last_include: + last_include_pos = cpp_content.rfind(last_include[-1]) + len(last_include[-1]) + # Make sure there are not multiple line breaks before the include + cpp_content = cpp_content[:last_include_pos].rstrip() + "\n" + include_statement + "\n\n" + cpp_content[last_include_pos:].lstrip() + return cpp_content + +def process_files(hpp_file_path, cpp_file_path): + with open(hpp_file_path, 'r', encoding='utf-8') as hpp_file: + hpp_content = hpp_file.read() + + with open(cpp_file_path, 'r', encoding='utf-8') as cpp_file: + cpp_content = cpp_file.read() + + # Get the class name from the hpp file + class_name_match = re.search(r'class\s+(\w+)', hpp_content) + class_name = class_name_match.group(1) if class_name_match else None + + if class_name: + # Apply all modifications + hpp_content = remove_constructor_and_destructor(hpp_content) + hpp_content = remove_include_luascript(hpp_content) + hpp_content = remove_final_luascriptinterface(hpp_content) + hpp_content, cpp_content = move_init_function_to_cpp(hpp_content, cpp_content, class_name) + cpp_content = add_include_to_cpp(cpp_content) + + # Save the modified files + with open(hpp_file_path, 'w', encoding='utf-8') as hpp_file: + hpp_file.write(hpp_content) + + with open(cpp_file_path, 'w', encoding='utf-8') as cpp_file: + cpp_file.write(cpp_content) + + print(f'Modifications applied to: {hpp_file_path} and {cpp_file_path}') + +def main(directory): + # Scan the specified folder and find all .hpp and .cpp files + for root, _, files in os.walk(directory): + for file in files: + if file.endswith('.hpp'): + hpp_file_path = os.path.join(root, file) + cpp_file_path = hpp_file_path.replace('.hpp', '.cpp') + if os.path.exists(cpp_file_path): + process_files(hpp_file_path, cpp_file_path) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Apply modifications to .hpp and .cpp files according to specifications.') + parser.add_argument('directory', type=str, nargs='?', default='../../src/lua/functions/', help='Path of the directory to be scanned.') + args = parser.parse_args() + + main(args.directory) + +# Functions you want to migrate to static calls +functions_to_convert = [ + "getNumber", + "getBoolean", + "getString", + "getUserdata", + "getScriptEnv", + "getCreature", + "getPlayer", + "getPosition", + "getOutfit", + "getThing", + "getUserdataShared", + "getUserdataType", + "getRawUserDataShared", + "getErrorDesc", + "getFormatedLoggerMessage", + "getField", + "getFieldString", + "getVariant", + "getGuild", + "isTable", + "isString", + "isNumber", + "isBoolean", + "isNil", + "isFunction", + "isUserdata", + "reportError", + "reportErrorFunc", + "pushInstantSpell", + "pushVariant", + "pushOutfit", + "pushCylinder", + "pushBoolean", + "pushString", + "pushUserdata", + "pushPosition", + "setMetatable", + "setWeakMetatable", + "setCreatureMetatable", + "setItemMetatable", + "setField", + "registerVariable", + "registerGlobalMethod", + "registerGlobalVariable", + "registerGlobalBoolean", + "registerMethod", + "registerClass", + "registerTable", + "registerSharedClass", + "registerMetaMethod", +] + +# Files you want to exclude from scanning (relative paths) +files_to_exclude = [ + os.path.normpath("lua_functions_loader.cpp"), + os.path.normpath("lua_functions_loader.hpp") +] + +def convert_to_static(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + original_content = content # Keep the original content to check for changes + + for function in functions_to_convert: + # Regex to capture function calls and replace them with Lua::function + # Skip calls that are part of g_configManager() and handle both regular and template functions + pattern = r'(?)?\(' + replacement = rf'Lua::{function}\1(' + content = re.sub(pattern, replacement, content) + + if content != original_content: + with open(file_path, 'w', encoding='utf-8') as file: + file.write(content) + print(f'File converted: {file_path}') + else: + print(f'No changes made to file: {file_path}') + +def main(directory): + # Scan the specified folder and find all .cpp and .hpp files + for root, _, files in os.walk(directory): + for file in files: + if file.endswith(('.cpp', '.hpp')): + file_path = os.path.normpath(os.path.join(root, file)) + + # Check if the file is in the exclusion list + if any(os.path.basename(file_path) == exclude_file for exclude_file in files_to_exclude): + print(f'File ignored: {file_path}') + continue # Skip the specified files + + convert_to_static(file_path) + +if __name__ == "__main__": + parser = argparse.ArgumentParser(description='Convert functions to static calls.') + parser.add_argument('directory', type=str, nargs='?', default='../../src/lua/functions/', help='Path of the directory to be scanned.') + + main(args.directory) diff --git a/schema.sql b/schema.sql index af245067057..86ea9e1bf6b 100644 --- a/schema.sql +++ b/schema.sql @@ -70,7 +70,7 @@ CREATE TABLE IF NOT EXISTS `players` ( `posx` int(11) NOT NULL DEFAULT '0', `posy` int(11) NOT NULL DEFAULT '0', `posz` int(11) NOT NULL DEFAULT '0', - `conditions` blob NOT NULL, + `conditions` mediumblob NOT NULL, `cap` int(11) NOT NULL DEFAULT '0', `sex` int(11) NOT NULL DEFAULT '0', `pronoun` int(11) NOT NULL DEFAULT '0', diff --git a/src/canary_server.cpp b/src/canary_server.cpp index 687fa51b6cd..8dfbcfc954c 100644 --- a/src/canary_server.cpp +++ b/src/canary_server.cpp @@ -9,6 +9,7 @@ #include "canary_server.hpp" +#include "core.hpp" #include "config/configmanager.hpp" #include "creatures/npcs/npcs.hpp" #include "creatures/players/grouping/familiars.hpp" @@ -31,8 +32,7 @@ #include "server/network/protocol/protocollogin.hpp" #include "server/network/protocol/protocolstatus.hpp" #include "server/network/webhook/webhook.hpp" - -#include "core.hpp" +#include "creatures/players/vocations/vocation.hpp" CanaryServer::CanaryServer( Logger &logger, @@ -322,6 +322,7 @@ void CanaryServer::initializeDatabase() { && !DatabaseManager::optimizeTables()) { logger.debug("No tables were optimized"); } + g_logger().info("Database connection established!"); } void CanaryServer::loadModules() { diff --git a/src/creatures/combat/combat.cpp b/src/creatures/combat/combat.cpp index a63f42093db..6b7667a71a5 100644 --- a/src/creatures/combat/combat.cpp +++ b/src/creatures/combat/combat.cpp @@ -15,18 +15,21 @@ #include "creatures/monsters/monster.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/players/grouping/party.hpp" +#include "creatures/players/player.hpp" #include "creatures/players/imbuements/imbuements.hpp" #include "creatures/players/wheel/player_wheel.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" #include "io/iobestiary.hpp" #include "io/ioprey.hpp" +#include "creatures/players/vocations/vocation.hpp" #include "items/weapons/weapons.hpp" #include "lib/metrics/metrics.hpp" #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" #include "lua/creature/events.hpp" #include "map/spectators.hpp" +#include "creatures/players/player.hpp" int32_t Combat::getLevelFormula(const std::shared_ptr &player, const std::shared_ptr &wheelSpell, const CombatDamage &damage) const { if (!player) { @@ -1063,7 +1066,7 @@ void Combat::setupChain(const std::shared_ptr &weapon) { } bool Combat::doCombatChain(const std::shared_ptr &caster, const std::shared_ptr &target, bool aggressive) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!params.chainCallback) { return false; } @@ -1086,7 +1089,7 @@ bool Combat::doCombatChain(const std::shared_ptr &caster, const std::s auto delay = i * std::max(50, g_configManager().getNumber(COMBAT_CHAIN_DELAY)); ++i; for (const auto &to : toVector) { - auto nextTarget = g_game().getCreatureByID(to); + const auto &nextTarget = g_game().getCreatureByID(to); if (!nextTarget) { continue; } @@ -1278,11 +1281,6 @@ void Combat::CombatFunc(const std::shared_ptr &caster, const Position combatTileEffects(spectators.data(), caster, tile, params); } - // Wheel of destiny update beam mastery damage - if (casterPlayer) { - casterPlayer->wheel()->updateBeamMasteryDamage(tmpDamage, beamAffectedTotal, beamAffectedCurrent); - } - postCombatEffects(caster, origin, pos, params); } @@ -1471,7 +1469,7 @@ void Combat::setRuneSpellName(const std::string &value) { std::vector>> Combat::pickChainTargets(const std::shared_ptr &caster, const CombatParams ¶ms, uint8_t chainDistance, uint8_t maxTargets, bool backtracking, bool aggressive, const std::shared_ptr &initialTarget /* = nullptr */) { Benchmark bm_pickChain; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!caster) { return {}; } @@ -1514,7 +1512,7 @@ std::vector>> Combat::pickChainTargets } if (closestSpectator) { - g_logger().trace("[{}] closestSpectator: {}", __METHOD_NAME__, closestSpectator->getName()); + g_logger().trace("[{}] closestSpectator: {}", __FUNCTION__, closestSpectator->getName()); bool found = false; for (auto &[pos, vec] : resultMap) { @@ -1533,7 +1531,7 @@ std::vector>> Combat::pickChainTargets continue; } if (backtracking) { - g_logger().debug("[{}] backtracking", __METHOD_NAME__); + g_logger().debug("[{}] backtracking", __FUNCTION__); targets.pop_back(); backtrackingAttempts--; continue; @@ -1541,7 +1539,7 @@ std::vector>> Combat::pickChainTargets break; } - g_logger().debug("[{}] resultMap: {} in {} ms", __METHOD_NAME__, resultMap.size(), bm_pickChain.duration()); + g_logger().debug("[{}] resultMap: {} in {} ms", __FUNCTION__, resultMap.size(), bm_pickChain.duration()); return resultMap; } @@ -2223,7 +2221,7 @@ void MagicField::onStepInField(const std::shared_ptr &creature) { } void Combat::applyExtensions(const std::shared_ptr &caster, const std::shared_ptr &target, CombatDamage &damage, const CombatParams ¶ms) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (damage.extension || !caster || damage.primary.type == COMBAT_HEALING) { return; } diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 0d66602ddca..f522eac86a6 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -20,10 +20,8 @@ #include "game/game.hpp" #include "lua/global/lua_variant.hpp" #include "lua/scripts/lua_environment.hpp" -#include "lua/scripts/luascript.hpp" - -std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 }; -std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 }; +#include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" Spells::Spells() = default; Spells::~Spells() = default; @@ -156,7 +154,7 @@ bool Spells::registerRuneLuaEvent(const std::shared_ptr &rune) { "[{}] duplicate registered rune with id: {}, for script: {}", __FUNCTION__, id, - rune->getScriptInterface()->getLoadingScriptName() + rune->getRuneSpellScriptInterface()->getLoadingScriptName() ); } return inserted; @@ -277,29 +275,45 @@ Position Spells::getCasterPosition(const std::shared_ptr &creature, Di return getNextPosition(dir, creature->getPosition()); } +LuaScriptInterface* BaseSpell::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool BaseSpell::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_spellScriptId = luaInterface.getEvent(); + if (m_spellScriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t BaseSpell::getScriptId() const { + return m_spellScriptId; +} + +void BaseSpell::setScriptId(int32_t newScriptId) { + m_spellScriptId = newScriptId; +} + +bool BaseSpell::isLoadedScriptId() const { + return m_spellScriptId != 0; +} + CombatSpell::CombatSpell(const std::shared_ptr &newCombat, bool newNeedTarget, bool newNeedDirection) : - Script(&g_spells().getScriptInterface()), m_combat(newCombat), needDirection(newNeedDirection), needTarget(newNeedTarget) { - // Empty -} - -bool CombatSpell::loadScriptCombat() { - m_combat = g_luaEnvironment().getCombatObject(g_luaEnvironment().lastCombatId); - return m_combat != nullptr; } std::shared_ptr CombatSpell::getCombat() const { return m_combat; } -std::string CombatSpell::getScriptTypeName() const { - return "onCastSpell"; -} - bool CombatSpell::castSpell(const std::shared_ptr &creature) { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { LuaVariant var; var.type = VARIANT_POSITION; @@ -346,7 +360,7 @@ bool CombatSpell::castSpell(const std::shared_ptr &creature, const std return false; } - if (isLoadedCallback()) { + if (isLoadedScriptId()) { LuaVariant var; if (combat->hasArea()) { var.type = VARIANT_POSITION; @@ -412,6 +426,8 @@ bool CombatSpell::executeCastSpell(const std::shared_ptr &creature, co return getScriptInterface()->callFunction(2); } +Spell::Spell() = default; + bool Spell::playerSpellCheck(const std::shared_ptr &player) const { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return false; @@ -730,7 +746,10 @@ void Spell::applyCooldownConditions(const std::shared_ptr &player) const g_logger().debug("[{}] spell name: {}, spellCooldown: {}, bonus: {}, augment {}", __FUNCTION__, name, spellCooldown, player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN), augmentCooldownReduction); spellCooldown -= player->wheel()->getSpellBonus(name, WheelSpellBoost_t::COOLDOWN); spellCooldown -= augmentCooldownReduction; + const int32_t halfBaseCooldown = cooldown / 2; + spellCooldown = halfBaseCooldown > spellCooldown ? halfBaseCooldown : spellCooldown; // The cooldown should never be reduced less than half (50%) of its base cooldown if (spellCooldown > 0) { + player->wheel()->handleTwinBurstsCooldown(player, name, spellCooldown, rateCooldown); const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, m_spellId); player->addCondition(condition); } @@ -752,7 +771,9 @@ void Spell::applyCooldownConditions(const std::shared_ptr &player) const if (isUpgraded) { spellSecondaryGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, spellGrade); } + spellSecondaryGroupCooldown -= player->wheel()->getSpellBonus(name, WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN); if (spellSecondaryGroupCooldown > 0) { + player->wheel()->handleBeamMasteryCooldown(player, name, spellSecondaryGroupCooldown, rateCooldown); const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rateCooldown, 0, false, secondaryGroup); player->addCondition(condition); } @@ -1030,6 +1051,8 @@ void Spell::setLockedPZ(bool b) { pzLocked = b; } +InstantSpell::InstantSpell() = default; + bool InstantSpell::playerCastInstant(const std::shared_ptr &player, std::string ¶m) const { if (!playerSpellCheck(player)) { return false; @@ -1161,10 +1184,6 @@ bool InstantSpell::canThrowSpell(const std::shared_ptr &creature, cons return true; } -std::string InstantSpell::getScriptTypeName() const { - return "onCastSpell"; -} - bool InstantSpell::castSpell(const std::shared_ptr &creature) { LuaVariant var; var.instantName = getName(); @@ -1294,6 +1313,33 @@ bool InstantSpell::canCast(const std::shared_ptr &player) const { return false; } +LuaScriptInterface* RuneSpell::getRuneSpellScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool RuneSpell::loadRuneSpellScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_runeSpellScriptId = luaInterface.getEvent(); + if (m_runeSpellScriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t RuneSpell::getRuneSpellScriptId() const { + return m_runeSpellScriptId; +} + +void RuneSpell::setRuneSpellScriptId(int32_t newScriptId) { + m_runeSpellScriptId = newScriptId; +} + +bool RuneSpell::isRuneSpellLoadedScriptId() const { + return m_runeSpellScriptId != 0; +} + ReturnValue RuneSpell::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { if (player->hasFlag(PlayerFlags_t::CannotUseSpells)) { return RETURNVALUE_CANNOTUSETHISOBJECT; @@ -1329,7 +1375,7 @@ bool RuneSpell::executeUse(const std::shared_ptr &player, const std::sha } // If script not loaded correctly, return - if (!isLoadedCallback()) { + if (!isRuneSpellLoadedScriptId()) { return false; } @@ -1391,13 +1437,9 @@ bool RuneSpell::castSpell(const std::shared_ptr &creature, const std:: return internalCastSpell(creature, var, false); } -std::string RuneSpell::getScriptTypeName() const { - return "onCastSpell"; -} - bool RuneSpell::internalCastSpell(const std::shared_ptr &creature, const LuaVariant &var, bool isHotkey) const { bool result; - if (isLoadedCallback()) { + if (isRuneSpellLoadedScriptId()) { result = executeCastSpell(creature, var, isHotkey); } else { result = false; @@ -1415,11 +1457,11 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr &creature, cons } ScriptEnvironment* env = LuaEnvironment::getScriptEnv(); - env->setScriptId(getScriptId(), getScriptInterface()); + env->setScriptId(getRuneSpellScriptId(), getRuneSpellScriptInterface()); - lua_State* L = getScriptInterface()->getLuaState(); + lua_State* L = getRuneSpellScriptInterface()->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); + getRuneSpellScriptInterface()->pushFunction(getRuneSpellScriptId()); LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); @@ -1428,7 +1470,7 @@ bool RuneSpell::executeCastSpell(const std::shared_ptr &creature, cons LuaScriptInterface::pushBoolean(L, isHotkey); - return getScriptInterface()->callFunction(3); + return getRuneSpellScriptInterface()->callFunction(3); } bool RuneSpell::isInstant() const { diff --git a/src/creatures/combat/spells.hpp b/src/creatures/combat/spells.hpp index ab34fa6dbce..56ff1a330de 100644 --- a/src/creatures/combat/spells.hpp +++ b/src/creatures/combat/spells.hpp @@ -10,20 +10,22 @@ #pragma once #include "lua/creature/actions.hpp" -#include "lua/scripts/scripts.hpp" - -enum class WheelSpellBoost_t : uint8_t; -enum class WheelSpellGrade_t : uint8_t; +#include "creatures/players/wheel/wheel_definitions.hpp" class InstantSpell; class RuneSpell; class Spell; +class Combat; +class Player; +class Creature; +class LuaScriptInterface; struct LuaVariant; +struct Position; using VocSpellMap = std::map; -class Spells final : public Scripts { +class Spells { public: Spells(); ~Spells(); @@ -78,11 +80,20 @@ class BaseSpell { virtual bool castSpell(const std::shared_ptr &creature) = 0; virtual bool castSpell(const std::shared_ptr &creature, const std::shared_ptr &target) = 0; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + SoundEffect_t soundImpactEffect = SoundEffect_t::SILENCE; SoundEffect_t soundCastEffect = SoundEffect_t::SPELL_OR_RUNE; + +protected: + int32_t m_spellScriptId {}; }; -class CombatSpell final : public Script, public BaseSpell, public std::enable_shared_from_this { +class CombatSpell final : public BaseSpell, public std::enable_shared_from_this { public: // Constructor CombatSpell(const std::shared_ptr &newCombat, bool newNeedTarget, bool newNeedDirection); @@ -97,12 +108,9 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh // Scripting spell bool executeCastSpell(const std::shared_ptr &creature, const LuaVariant &var) const; - bool loadScriptCombat(); std::shared_ptr getCombat() const; private: - std::string getScriptTypeName() const override; - std::shared_ptr m_combat; bool needDirection; @@ -111,7 +119,7 @@ class CombatSpell final : public Script, public BaseSpell, public std::enable_sh class Spell : public BaseSpell { public: - Spell() = default; + Spell(); [[nodiscard]] const std::string &getName() const; void setName(std::string n); @@ -246,6 +254,8 @@ class Spell : public BaseSpell { bool pzLocked = false; bool whellOfDestinyUpgraded = false; + std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyRegularBoost = { 0 }; + std::array(WheelSpellBoost_t::TOTAL_COUNT)> wheelOfDestinyUpgradedBoost = { 0 }; private: uint32_t mana = 0; @@ -267,10 +277,9 @@ class Spell : public BaseSpell { friend class SpellFunctions; }; -class InstantSpell final : public Script, public Spell { +class InstantSpell final : public Spell { public: - using Script::Script; - + InstantSpell(); bool playerCastInstant(const std::shared_ptr &player, std::string ¶m) const; bool castSpell(const std::shared_ptr &creature) override; @@ -294,8 +303,6 @@ class InstantSpell final : public Script, public Spell { bool canThrowSpell(const std::shared_ptr &creature, const std::shared_ptr &target) const; private: - [[nodiscard]] std::string getScriptTypeName() const override; - bool needDirection = false; bool hasParam = false; bool hasPlayerNameParam = false; @@ -307,6 +314,12 @@ class RuneSpell final : public Action, public Spell { public: using Action::Action; + LuaScriptInterface* getRuneSpellScriptInterface() const; + bool loadRuneSpellScriptId(); + int32_t getRuneSpellScriptId() const; + void setRuneSpellScriptId(int32_t newScriptId); + bool isRuneSpellLoadedScriptId() const; + ReturnValue canExecuteAction(const std::shared_ptr &player, const Position &toPos) override; bool hasOwnErrorHandler() override; std::shared_ptr getTarget(const std::shared_ptr &, const std::shared_ptr &targetCreature, const Position &, uint8_t) const override; @@ -326,10 +339,10 @@ class RuneSpell final : public Action, public Spell { void setCharges(uint32_t c); private: - [[nodiscard]] std::string getScriptTypeName() const override; - bool internalCastSpell(const std::shared_ptr &creature, const LuaVariant &var, bool isHotkey) const; + int32_t m_runeSpellScriptId = 0; + uint16_t runeId = 0; uint32_t charges = 0; bool hasCharges = false; diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index baf93fb651a..32f3c598b81 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -35,7 +35,7 @@ Creature::~Creature() { } bool Creature::canSee(const Position &myPos, const Position &pos, int32_t viewRangeX, int32_t viewRangeY) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (myPos.z <= MAP_INIT_SURFACE_LAYER) { // we are on ground level or above (7 -> 0) // view is from 7 -> 0 @@ -95,11 +95,7 @@ int32_t Creature::getWalkSize() { } void Creature::onThink(uint32_t interval) { - metrics::method_latency measure(__METHOD_NAME__); - if (!isMapLoaded && useCacheMap()) { - isMapLoaded = true; - updateMapCache(); - } + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &followCreature = getFollowCreature(); const auto &master = getMaster(); @@ -172,7 +168,7 @@ void Creature::onCreatureWalk() { checkingWalkCreature = true; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); g_dispatcher().addWalkEvent([self = getCreature(), this] { checkingWalkCreature = false; @@ -270,18 +266,17 @@ void Creature::addEventWalk(bool firstStep) { return; } - g_dispatcher().context().tryAddEvent([ticks, self = getCreature()]() { + safeCall([this, ticks]() { // Take first step right away, but still queue the next if (ticks == 1) { - g_game().checkCreatureWalk(self->getID()); + g_game().checkCreatureWalk(getID()); } - self->eventWalk = g_dispatcher().scheduleEvent( + eventWalk = g_dispatcher().scheduleEvent( static_cast(ticks), - [creatureId = self->getID()] { g_game().checkCreatureWalk(creatureId); }, "Game::checkCreatureWalk" + [creatureId = getID()] { g_game().checkCreatureWalk(creatureId); }, "Game::checkCreatureWalk" ); - }, - "addEventWalk"); + }); } void Creature::stopEventWalk() { @@ -291,125 +286,18 @@ void Creature::stopEventWalk() { } } -void Creature::updateMapCache() { - if (!useCacheMap()) { - return; - } - - metrics::method_latency measure(__METHOD_NAME__); - std::shared_ptr newTile; - const Position &myPos = getPosition(); - Position pos(0, 0, myPos.z); - - for (int32_t y = -maxWalkCacheHeight; y <= maxWalkCacheHeight; ++y) { - for (int32_t x = -maxWalkCacheWidth; x <= maxWalkCacheWidth; ++x) { - pos.x = myPos.getX() + x; - pos.y = myPos.getY() + y; - newTile = g_game().map.getTile(pos); - updateTileCache(newTile, pos); - } - } -} - -void Creature::updateTileCache(const std::shared_ptr &newTile, int32_t dx, int32_t dy) { - metrics::method_latency measure(__METHOD_NAME__); - if (std::abs(dx) <= maxWalkCacheWidth && std::abs(dy) <= maxWalkCacheHeight) { - localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx] = newTile && newTile->queryAdd(0, getCreature(), 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR; - } -} - -void Creature::updateTileCache(const std::shared_ptr &upTile, const Position &pos) { - const Position &myPos = getPosition(); - if (pos.z == myPos.z) { - int32_t dx = Position::getOffsetX(pos, myPos); - int32_t dy = Position::getOffsetY(pos, myPos); - updateTileCache(upTile, dx, dy); - } -} - -int32_t Creature::getWalkCache(const Position &pos) { - metrics::method_latency measure(__METHOD_NAME__); - if (!useCacheMap()) { - return 2; - } - - const Position &myPos = getPosition(); - if (myPos.z != pos.z) { - return 0; - } - - if (pos == myPos) { - return 1; - } - - int32_t dx = Position::getOffsetX(pos, myPos); - if (std::abs(dx) <= maxWalkCacheWidth) { - int32_t dy = Position::getOffsetY(pos, myPos); - if (std::abs(dy) <= maxWalkCacheHeight) { - return localMapCache[maxWalkCacheHeight + dy][maxWalkCacheWidth + dx]; - } - } - - // out of range - return 2; -} - -void Creature::onAddTileItem(const std::shared_ptr &tileItem, const Position &pos) { - if (isMapLoaded && pos.z == getPosition().z) { - updateTileCache(tileItem, pos); - } -} - -void Creature::onUpdateTileItem(const std::shared_ptr &updateTile, const Position &pos, const std::shared_ptr &, const ItemType &oldType, const std::shared_ptr &, const ItemType &newType) { - if (!isMapLoaded) { - return; - } - - if (oldType.blockSolid || oldType.blockPathFind || newType.blockPathFind || newType.blockSolid) { - if (pos.z == getPosition().z) { - updateTileCache(updateTile, pos); - } - } -} - -void Creature::onRemoveTileItem(const std::shared_ptr &updateTile, const Position &pos, const ItemType &iType, const std::shared_ptr &) { - if (!isMapLoaded) { - return; - } - - if (iType.blockSolid || iType.blockPathFind || iType.isGroundTile()) { - if (pos.z == getPosition().z) { - updateTileCache(updateTile, pos); - } - } -} - void Creature::onCreatureAppear(const std::shared_ptr &creature, bool isLogin) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature.get() == this) { - if (useCacheMap()) { - isMapLoaded = true; - updateMapCache(); - } - if (isLogin) { setLastPosition(getPosition()); } - } else if (isMapLoaded) { - if (creature->getPosition().z == getPosition().z) { - updateTileCache(creature->getTile(), creature->getPosition()); - } } } void Creature::onRemoveCreature(const std::shared_ptr &creature, bool) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); onCreatureDisappear(creature, true); - if (creature && creature != getCreature() && isMapLoaded) { - if (creature->getPosition().z == getPosition().z) { - updateTileCache(creature->getTile(), creature->getPosition()); - } - } // Update player from monster target list (avoid memory usage after clean) if (const auto &monster = getMonster(); monster && monster->getAttackedCreature() == creature) { @@ -419,7 +307,7 @@ void Creature::onRemoveCreature(const std::shared_ptr &creature, bool) } void Creature::onCreatureDisappear(const std::shared_ptr &creature, bool isLogout) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (getAttackedCreature() == creature) { setAttackedCreature(nullptr); onAttackedCreatureDisappear(isLogout); @@ -432,7 +320,7 @@ void Creature::onCreatureDisappear(const std::shared_ptr &creature, bo } void Creature::onChangeZone(ZoneType_t zone) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &attackedCreature = getAttackedCreature(); if (attackedCreature && zone == ZONE_PROTECTION) { onCreatureDisappear(attackedCreature, false); @@ -440,7 +328,7 @@ void Creature::onChangeZone(ZoneType_t zone) { } void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (zone == ZONE_PROTECTION) { const auto &attackedCreature = getAttackedCreature(); if (attackedCreature) { @@ -450,7 +338,7 @@ void Creature::onAttackedCreatureChangeZone(ZoneType_t zone) { } void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (hasSummons()) { std::vector> despawnMonsterList; for (const auto &summon : getSummons()) { @@ -497,7 +385,7 @@ void Creature::checkSummonMove(const Position &newPos, bool teleportSummon) { } void Creature::onCreatureMove(const std::shared_ptr &creature, const std::shared_ptr &newTile, const Position &newPos, const std::shared_ptr &oldTile, const Position &oldPos, bool teleport) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature.get() == this) { lastStep = OTSYS_TIME(); lastStepCost = 1; @@ -527,101 +415,6 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s if (newTile->getZoneType() != oldTile->getZoneType()) { onChangeZone(getZoneType()); } - - // update map cache - if (isMapLoaded) { - if (teleport || oldPos.z != newPos.z) { - updateMapCache(); - } else { - const Position &myPos = getPosition(); - - if (oldPos.y > newPos.y) { // north - // shift y south - for (int32_t y = mapWalkHeight - 1; --y >= 0;) { - std::ranges::copy(std::span(localMapCache[y]), localMapCache[y + 1]); - } - - // update 0 - for (int32_t x = -maxWalkCacheWidth; x <= maxWalkCacheWidth; ++x) { - const auto &cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() - maxWalkCacheHeight), myPos.z); - updateTileCache(cacheTile, x, -maxWalkCacheHeight); - } - } else if (oldPos.y < newPos.y) { // south - // shift y north - for (int32_t y = 0; y <= mapWalkHeight - 2; ++y) { - std::ranges::copy(std::span(localMapCache[y + 1]), localMapCache[y]); - } - - // update mapWalkHeight - 1 - for (int32_t x = -maxWalkCacheWidth; x <= maxWalkCacheWidth; ++x) { - const auto &cacheTile = g_game().map.getTile(static_cast(myPos.getX() + x), static_cast(myPos.getY() + maxWalkCacheHeight), myPos.z); - updateTileCache(cacheTile, x, maxWalkCacheHeight); - } - } - - if (oldPos.x < newPos.x) { // east - // shift y west - int32_t starty = 0; - int32_t endy = mapWalkHeight - 1; - int32_t dy = Position::getDistanceY(oldPos, newPos); - - if (dy < 0) { - endy += dy; - } else if (dy > 0) { - starty = dy; - } - - for (int32_t y = starty; y <= endy; ++y) { - for (int32_t x = 0; x <= mapWalkWidth - 2; ++x) { - localMapCache[y][x] = localMapCache[y][x + 1]; - } - } - - // update mapWalkWidth - 1 - for (int32_t y = -maxWalkCacheHeight; y <= maxWalkCacheHeight; ++y) { - const auto &cacheTile = g_game().map.getTile(myPos.x + maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); - updateTileCache(cacheTile, maxWalkCacheWidth, y); - } - } else if (oldPos.x > newPos.x) { // west - // shift y east - int32_t starty = 0; - int32_t endy = mapWalkHeight - 1; - int32_t dy = Position::getDistanceY(oldPos, newPos); - - if (dy < 0) { - endy += dy; - } else if (dy > 0) { - starty = dy; - } - - for (int32_t y = starty; y <= endy; ++y) { - for (int32_t x = mapWalkWidth - 1; --x >= 0;) { - localMapCache[y][x + 1] = localMapCache[y][x]; - } - } - - // update 0 - for (int32_t y = -maxWalkCacheHeight; y <= maxWalkCacheHeight; ++y) { - const auto &cacheTile = g_game().map.getTile(myPos.x - maxWalkCacheWidth, static_cast(myPos.y + y), myPos.z); - updateTileCache(cacheTile, -maxWalkCacheWidth, y); - } - } - - updateTileCache(oldTile, oldPos); - } - } - } else { - if (isMapLoaded) { - const Position &myPos = getPosition(); - - if (newPos.z == myPos.z) { - updateTileCache(newTile, newPos); - } - - if (oldPos.z == myPos.z) { - updateTileCache(oldTile, oldPos); - } - } } const auto &followCreature = getFollowCreature(); @@ -654,7 +447,7 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s } void Creature::onDeath() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); bool lastHitUnjustified = false; bool mostDamageUnjustified = false; const auto &lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); @@ -792,7 +585,7 @@ void Creature::onDeath() { } bool Creature::dropCorpse(const std::shared_ptr &lastHitCreature, const std::shared_ptr &mostDamageCreature, bool lastHitUnjustified, bool mostDamageUnjustified) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!lootDrop && getMonster()) { if (getMaster()) { // Scripting event onDeath @@ -1082,14 +875,14 @@ void Creature::getPathSearchParams(const std::shared_ptr &, FindPathPa void Creature::goToFollowCreature_async(std::function &&onComplete) { if (!hasAsyncTaskFlag(Pathfinder) && onComplete) { - g_dispatcher().context().addEvent(std::move(onComplete), "goToFollowCreature_async"); + g_dispatcher().addEvent(std::move(onComplete), "goToFollowCreature_async"); } setAsyncTaskFlag(Pathfinder, true); } void Creature::goToFollowCreature() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &followCreature = getFollowCreature(); if (!followCreature) { return; @@ -1144,7 +937,7 @@ bool Creature::canFollowMaster() const { } bool Creature::setFollowCreature(const std::shared_ptr &creature) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature) { if (getFollowCreature() == creature) { return true; @@ -1293,7 +1086,7 @@ void Creature::onAttackedCreatureDrainHealth(const std::shared_ptr &ta } void Creature::onAttackedCreatureKilled(const std::shared_ptr &target) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (target != getCreature()) { uint64_t gainExp = target->getGainedExperience(static_self_cast()); onGainExperience(gainExp, target); @@ -1301,7 +1094,7 @@ void Creature::onAttackedCreatureKilled(const std::shared_ptr &target) } bool Creature::deprecatedOnKilledCreature(const std::shared_ptr &target, bool lastHit) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &master = getMaster(); if (master) { master->deprecatedOnKilledCreature(target, lastHit); @@ -1316,7 +1109,7 @@ bool Creature::deprecatedOnKilledCreature(const std::shared_ptr &targe } void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr &target) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &master = getMaster(); if (gainExp == 0 || !master) { return; @@ -1347,7 +1140,7 @@ void Creature::onGainExperience(uint64_t gainExp, const std::shared_ptr &newMaster, bool reloadCreature /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); // Persists if this creature has ever been a summon this->summoned = true; const auto &oldMaster = getMaster(); @@ -1380,7 +1173,7 @@ bool Creature::setMaster(const std::shared_ptr &newMaster, bool reload } bool Creature::addCondition(const std::shared_ptr &condition, bool attackerPlayer /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (condition == nullptr) { return false; } @@ -1418,7 +1211,7 @@ bool Creature::addCombatCondition(const std::shared_ptr &condition, b } void Creature::removeCondition(ConditionType_t type) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(), end = conditions.end(); while (it != end) { std::shared_ptr condition = *it; @@ -1436,7 +1229,7 @@ void Creature::removeCondition(ConditionType_t type) { } void Creature::removeCondition(ConditionType_t conditionType, ConditionId_t conditionId, bool force /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(); const auto end = conditions.end(); while (it != end) { @@ -1499,7 +1292,7 @@ std::shared_ptr Creature::getCondition(ConditionType_t type) const { } std::shared_ptr Creature::getCondition(ConditionType_t type, ConditionId_t conditionId, uint32_t subId /* = 0*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); for (const auto &condition : conditions) { if (condition->getType() == type && condition->getId() == conditionId && condition->getSubId() == subId) { return condition; @@ -1519,7 +1312,7 @@ std::vector> Creature::getConditionsByType(ConditionT } void Creature::executeConditions(uint32_t interval) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); auto it = conditions.begin(), end = conditions.end(); while (it != end) { std::shared_ptr condition = *it; @@ -1538,7 +1331,7 @@ void Creature::executeConditions(uint32_t interval) { } bool Creature::hasCondition(ConditionType_t type, uint32_t subId /* = 0*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (isSuppress(type, false)) { return false; } @@ -1592,6 +1385,10 @@ LightInfo Creature::getCreatureLight() const { return internalLight; } +uint16_t Creature::getSpeed() const { + return std::clamp(baseSpeed + varSpeed, 0, static_cast(std::numeric_limits::max())); +} + void Creature::setSpeed(int32_t varSpeedDelta) { // Prevents creatures from not exceeding the maximum allowed speed if (getSpeed() >= PLAYER_MAX_SPEED) { @@ -1810,7 +1607,7 @@ ZoneType_t Creature::getZoneType() { } bool Creature::getPathTo(const Position &targetPos, std::vector &dirList, const FindPathParams &fpp) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (fpp.maxSearchDist != 0 || fpp.keepDistance) { return g_game().map.getPathMatchingCond(getCreature(), targetPos, dirList, FrozenPathingConditionCall(targetPos), fpp); } @@ -2002,3 +1799,18 @@ void Creature::sendAsyncTasks() { }, TaskGroup::WalkParallel); } + +void Creature::safeCall(std::function &&action) const { + if (g_dispatcher().context().isAsync()) { + g_dispatcher().addEvent([weak_self = std::weak_ptr(static_self_cast()), action = std::move(action)] { + if (const auto self = weak_self.lock()) { + if (!self->isInternalRemoved) { + action(); + } + } + }, + g_dispatcher().context().getName()); + } else if (!isInternalRemoved) { + action(); + } +} diff --git a/src/creatures/creature.hpp b/src/creatures/creature.hpp index 46f628188e5..fcea0a6b0f2 100644 --- a/src/creatures/creature.hpp +++ b/src/creatures/creature.hpp @@ -194,9 +194,7 @@ class Creature : virtual public Thing, public SharedObject { virtual uint16_t getStepSpeed() const { return getSpeed(); } - uint16_t getSpeed() const { - return static_cast(baseSpeed + varSpeed); - } + uint16_t getSpeed() const; void setSpeed(int32_t varSpeedDelta); void setBaseSpeed(uint16_t newBaseSpeed) { @@ -490,9 +488,9 @@ class Creature : virtual public Thing, public SharedObject { virtual void turnToCreature(const std::shared_ptr &creature); - void onAddTileItem(const std::shared_ptr &tile, const Position &pos); - virtual void onUpdateTileItem(const std::shared_ptr &tile, const Position &pos, const std::shared_ptr &oldItem, const ItemType &oldType, const std::shared_ptr &newItem, const ItemType &newType); - virtual void onRemoveTileItem(const std::shared_ptr &tile, const Position &pos, const ItemType &iType, const std::shared_ptr &item); + void onAddTileItem(const std::shared_ptr & /*tile*/, const Position & /*pos*/) { } + virtual void onUpdateTileItem(const std::shared_ptr &tile, const Position &pos, const std::shared_ptr &oldItem, const ItemType &oldType, const std::shared_ptr &newItem, const ItemType &newType) { } + virtual void onRemoveTileItem(const std::shared_ptr &tile, const Position &pos, const ItemType &iType, const std::shared_ptr &item) { } virtual void onCreatureAppear(const std::shared_ptr &creature, bool isLogin); virtual void onRemoveCreature(const std::shared_ptr &creature, bool isLogout); @@ -562,8 +560,6 @@ class Creature : virtual public Thing, public SharedObject { return m_tile.lock(); } - int32_t getWalkCache(const Position &pos); - const Position &getLastPosition() const { return lastPosition; } @@ -701,19 +697,10 @@ class Creature : virtual public Thing, public SharedObject { Pathfinder = 1 << 3 }; - virtual bool useCacheMap() const { - return false; - } - virtual bool isDead() const { return false; } - static constexpr int32_t mapWalkWidth = MAP_MAX_VIEW_PORT_X * 2 + 1; - static constexpr int32_t mapWalkHeight = MAP_MAX_VIEW_PORT_Y * 2 + 1; - static constexpr int32_t maxWalkCacheWidth = (mapWalkWidth - 1) / 2; - static constexpr int32_t maxWalkCacheHeight = (mapWalkHeight - 1) / 2; - Position position; CountMap damageMap; @@ -777,9 +764,7 @@ class Creature : virtual public Thing, public SharedObject { std::atomic_bool creatureCheck = false; std::atomic_bool inCheckCreaturesVector = false; - bool localMapCache[mapWalkHeight][mapWalkWidth] = { { false } }; bool isInternalRemoved = false; - bool isMapLoaded = false; bool isUpdatingPath = false; bool skillLoss = true; bool lootDrop = true; @@ -803,9 +788,6 @@ class Creature : virtual public Thing, public SharedObject { bool hasEventRegistered(CreatureEventType_t event) const; CreatureEventList getCreatureEvents(CreatureEventType_t type) const; - void updateMapCache(); - void updateTileCache(const std::shared_ptr &tile, int32_t dx, int32_t dy); - void updateTileCache(const std::shared_ptr &tile, const Position &pos); void onCreatureDisappear(const std::shared_ptr &creature, bool isLogout); virtual void doAttacking(uint32_t) { } virtual bool hasExtraSwing() { @@ -848,6 +830,9 @@ class Creature : virtual public Thing, public SharedObject { virtual void onExecuteAsyncTasks() {}; + // This method maintains safety in asynchronous calls, avoiding competition between threads. + void safeCall(std::function &&action) const; + private: bool canFollowMaster() const; bool isLostSummon(); diff --git a/src/creatures/creatures_definitions.hpp b/src/creatures/creatures_definitions.hpp index f7ba1e203b1..dd554c086b3 100644 --- a/src/creatures/creatures_definitions.hpp +++ b/src/creatures/creatures_definitions.hpp @@ -706,6 +706,8 @@ enum SpellGroup_t : uint8_t { SPELLGROUP_CRIPPLING = 6, SPELLGROUP_FOCUS = 7, SPELLGROUP_ULTIMATESTRIKES = 8, + SPELLGROUP_BURSTS_OF_NATURE = 9, + SPELLGROUP_GREAT_BEAMS = 10, }; enum ChannelEvent_t : uint8_t { diff --git a/src/creatures/monsters/monster.cpp b/src/creatures/monsters/monster.cpp index 2e9140dcc18..7276bea19d1 100644 --- a/src/creatures/monsters/monster.cpp +++ b/src/creatures/monsters/monster.cpp @@ -967,7 +967,6 @@ void Monster::setIdle(bool idle) { if (!isIdle) { g_game().addCreatureCheck(getMonster()); - } else { onIdleStatus(); clearTargetList(); @@ -1015,10 +1014,7 @@ void Monster::onAddCondition(ConditionType_t type) { onConditionStatusChange(type); } -void Monster::onConditionStatusChange(ConditionType_t type) { - if (type == CONDITION_FIRE || type == CONDITION_ENERGY || type == CONDITION_POISON) { - updateMapCache(); - } +void Monster::onConditionStatusChange(ConditionType_t /*type*/) { updateIdleStatus(); } @@ -1518,7 +1514,6 @@ void Monster::doWalkBack(uint32_t &flags, Direction &nextDirection, bool &result } else { if (ignoreFieldDamage) { ignoreFieldDamage = false; - updateMapCache(); } int32_t distance = std::max(Position::getDistanceX(position, masterPos), Position::getDistanceY(position, masterPos)); @@ -1544,7 +1539,6 @@ void Monster::doFollowCreature(uint32_t &flags, Direction &nextDirection, bool & } else { if (ignoreFieldDamage) { ignoreFieldDamage = false; - updateMapCache(); } // target dancing const auto &attackedCreature = getAttackedCreature(); @@ -2226,10 +2220,6 @@ void Monster::setHazardSystemDefenseBoost(bool value) { bool Monster::canWalkTo(Position pos, Direction moveDirection) { pos = getNextPosition(moveDirection, pos); if (isInSpawnRange(pos)) { - if (getWalkCache(pos) == 0) { - return false; - } - const auto &tile = g_game().map.getTile(pos); if (tile && tile->getTopVisibleCreature(getMonster()) == nullptr && tile->queryAdd(0, getMonster(), 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) == RETURNVALUE_NOERROR) { return true; @@ -2406,7 +2396,6 @@ void Monster::drainHealth(const std::shared_ptr &attacker, int32_t dam if (damage > 0 && randomStepping) { ignoreFieldDamage = true; - updateMapCache(); } if (isInvisible()) { diff --git a/src/creatures/monsters/monster.hpp b/src/creatures/monsters/monster.hpp index ed9a628159f..b8a6087acc1 100644 --- a/src/creatures/monsters/monster.hpp +++ b/src/creatures/monsters/monster.hpp @@ -332,13 +332,6 @@ class Monster final : public Creature { uint16_t getLookCorpse() const override; void dropLoot(const std::shared_ptr &corpse, const std::shared_ptr &lastHitCreature) override; void getPathSearchParams(const std::shared_ptr &creature, FindPathParams &fpp) override; - bool useCacheMap() const override { - // return !randomStepping; - // As the map cache is done synchronously for each movement that a monster makes, it is better to disable it, - // as the pathfinder, which is one of the resources that uses this cache the most, - // is multithreding and thus the processing cost is divided between the threads. - return false; - } friend class MonsterFunctions; friend class Map; diff --git a/src/creatures/monsters/monsters.cpp b/src/creatures/monsters/monsters.cpp index 87fd967ab46..cd33e12e248 100644 --- a/src/creatures/monsters/monsters.cpp +++ b/src/creatures/monsters/monsters.cpp @@ -16,6 +16,7 @@ #include "game/game.hpp" #include "items/weapons/weapons.hpp" #include "lua/scripts/luascript.hpp" +#include "lib/di/container.hpp" void MonsterType::loadLoot(const std::shared_ptr &monsterType, LootBlock lootBlock) const { if (lootBlock.childLoot.empty()) { diff --git a/src/creatures/monsters/spawns/spawn_monster.cpp b/src/creatures/monsters/spawns/spawn_monster.cpp index 7d7bbc84e34..3a915d737b2 100644 --- a/src/creatures/monsters/spawns/spawn_monster.cpp +++ b/src/creatures/monsters/spawns/spawn_monster.cpp @@ -232,9 +232,7 @@ bool SpawnMonster::spawnMonster(uint32_t spawnMonsterId, spawnBlock_t &sb, const spawnedMonsterMap[spawnMonsterId] = monster; sb.lastSpawn = OTSYS_TIME(); - g_events().eventMonsterOnSpawn(monster, sb.pos); monster->onSpawn(); - g_callbacks().executeCallback(EventCallback_t::monsterOnSpawn, &EventCallback::monsterOnSpawn, monster, sb.pos); return true; } diff --git a/src/creatures/npcs/npcs.cpp b/src/creatures/npcs/npcs.cpp index cff44588d71..53ed757336f 100644 --- a/src/creatures/npcs/npcs.cpp +++ b/src/creatures/npcs/npcs.cpp @@ -14,6 +14,7 @@ #include "lua/scripts/lua_environment.hpp" #include "lua/scripts/luascript.hpp" #include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" bool NpcType::canSpawn(const Position &pos) const { bool canSpawn = true; diff --git a/src/creatures/npcs/spawns/spawn_npc.cpp b/src/creatures/npcs/spawns/spawn_npc.cpp index bf3b6a1bc65..404f6ce588e 100644 --- a/src/creatures/npcs/spawns/spawn_npc.cpp +++ b/src/creatures/npcs/spawns/spawn_npc.cpp @@ -202,9 +202,6 @@ bool SpawnNpc::spawnNpc(uint32_t spawnId, const std::shared_ptr &npcTyp spawnedNpcMap.insert(spawned_pair(spawnId, npc)); spawnNpcMap[spawnId].lastSpawnNpc = OTSYS_TIME(); - - g_events().eventNpcOnSpawn(npc, pos); - g_callbacks().executeCallback(EventCallback_t::npcOnSpawn, &EventCallback::npcOnSpawn, npc, pos); return true; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index dfdf467aa97..4335db2bd53 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -9,6 +9,7 @@ #include "creatures/players/player.hpp" +#include "account/account.hpp" #include "config/configmanager.hpp" #include "core.hpp" #include "creatures/appearance/mounts/mounts.hpp" @@ -61,6 +62,7 @@ #include "lua/creature/events.hpp" #include "lua/creature/movement.hpp" #include "map/spectators.hpp" +#include "creatures/players/vocations/vocation.hpp" MuteCountMap Player::muteCountMap; @@ -976,8 +978,6 @@ void Player::closeContainer(uint8_t cid) { removeEmptyRewards(); } openContainers.erase(it); - if (container && container->getID() == ITEM_BROWSEFIELD) { - } } void Player::removeEmptyRewards() { @@ -1773,8 +1773,8 @@ std::shared_ptr Player::getDepotLocker(uint32_t depotId) { depotLocker->internalAddThing(marketItem); depotLocker->internalAddThing(inbox); if (createSupplyStash) { - const auto &supplyStash = Item::CreateItem(ITEM_SUPPLY_STASH); - depotLocker->internalAddThing(supplyStash); + const auto &supplyStashPtr = Item::CreateItem(ITEM_SUPPLY_STASH); + depotLocker->internalAddThing(supplyStashPtr); } const auto &depotChest = Item::CreateItemAsContainer(ITEM_DEPOT, static_cast(g_configManager().getNumber(DEPOT_BOXES))); for (uint32_t i = g_configManager().getNumber(DEPOT_BOXES); i > 0; i--) { @@ -2739,6 +2739,10 @@ uint16_t Player::getGrindingXpBoost() const { return grindingXpBoost; } +uint16_t Player::getDisplayGrindingXpBoost() const { + return std::clamp(grindingXpBoost * (baseXpGain / 100), 0, std::numeric_limits::max()); +} + void Player::setGrindingXpBoost(uint16_t value) { grindingXpBoost = std::min(std::numeric_limits::max(), value); } @@ -2747,6 +2751,10 @@ uint16_t Player::getXpBoostPercent() const { return xpBoostPercent; } +uint16_t Player::getDisplayXpBoostPercent() const { + return std::clamp(xpBoostPercent * (baseXpGain / 100), 0, std::numeric_limits::max()); +} + void Player::setXpBoostPercent(uint16_t percent) { xpBoostPercent = percent; } @@ -3450,7 +3458,6 @@ void Player::death(const std::shared_ptr &lastHitCreature) { g_game().sendSingleSoundEffect(static_self_cast()->getPosition(), sex == PLAYERSEX_FEMALE ? SoundEffect_t::HUMAN_FEMALE_DEATH : SoundEffect_t::HUMAN_MALE_DEATH, getPlayer()); if (skillLoss) { - uint8_t unfairFightReduction = 100; int playerDmg = 0; int othersDmg = 0; uint32_t sumLevels = 0; @@ -3467,10 +3474,13 @@ void Player::death(const std::shared_ptr &lastHitCreature) { } } } + bool pvpDeath = false; if (playerDmg > 0 || othersDmg > 0) { pvpDeath = (Player::lastHitIsPlayer(lastHitCreature) || playerDmg / (playerDmg + static_cast(othersDmg)) >= 0.05); } + + uint8_t unfairFightReduction = 100; if (pvpDeath && sumLevels > level) { double reduce = level / static_cast(sumLevels); unfairFightReduction = std::max(20, std::floor((reduce * 100) + 0.5)); @@ -3480,7 +3490,7 @@ void Player::death(const std::shared_ptr &lastHitCreature) { uint64_t sumMana = 0; uint64_t lostMana = 0; - // sum up all the mana + // Sum up all the mana for (uint32_t i = 1; i <= magLevel; ++i) { sumMana += vocation->getReqMana(i); } @@ -3490,12 +3500,10 @@ void Player::death(const std::shared_ptr &lastHitCreature) { double deathLossPercent = getLostPercent() * (unfairFightReduction / 100.); // Charm bless bestiary - if (lastHitCreature && lastHitCreature->getMonster()) { - if (charmRuneBless != 0) { - const auto mType = g_monsters().getMonsterType(lastHitCreature->getName()); - if (mType && mType->info.raceid == charmRuneBless) { - deathLossPercent = (deathLossPercent * 90) / 100; - } + if (lastHitCreature && lastHitCreature->getMonster() && charmRuneBless != 0) { + const auto &mType = g_monsters().getMonsterType(lastHitCreature->getName()); + if (mType && mType->info.raceid == charmRuneBless) { + deathLossPercent = (deathLossPercent * 90) / 100; } } @@ -3517,7 +3525,9 @@ void Player::death(const std::shared_ptr &lastHitCreature) { } // Level loss - auto expLoss = static_cast(experience * deathLossPercent); + auto expLoss = static_cast(std::ceil(experience * deathLossPercent)); + g_logger().debug("[{}] - experience lost {}", __FUNCTION__, expLoss); + g_events().eventPlayerOnLoseExperience(static_self_cast(), expLoss); g_callbacks().executeCallback(EventCallback_t::playerOnLoseExperience, &EventCallback::playerOnLoseExperience, getPlayer(), expLoss); @@ -3526,9 +3536,9 @@ void Player::death(const std::shared_ptr &lastHitCreature) { lostExp << "You lost " << expLoss << " experience."; // Skill loss - for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { // for each skill + for (uint8_t i = SKILL_FIRST; i <= SKILL_LAST; ++i) { // For each skill uint64_t sumSkillTries = 0; - for (uint16_t c = 11; c <= skills[i].level; ++c) { // sum up all required tries for all skill levels + for (uint16_t c = 11; c <= skills[i].level; ++c) { // Sum up all required tries for all skill levels sumSkillTries += vocation->getReqSkillTries(i, c); } @@ -3604,14 +3614,21 @@ void Player::death(const std::shared_ptr &lastHitCreature) { bless.empty() ? blessOutput << "You weren't protected with any blessings." : blessOutput << "You were blessed with " << bless; - // Make player lose bless + const auto playerSkull = getSkull(); + bool hasSkull = (playerSkull == Skulls_t::SKULL_RED || playerSkull == Skulls_t::SKULL_BLACK); uint8_t maxBlessing = 8; - if (pvpDeath && hasBlessing(1)) { + if (!hasSkull && pvpDeath && hasBlessing(1)) { removeBlessing(1, 1); // Remove TOF only } else { for (int i = 2; i <= maxBlessing; i++) { removeBlessing(i, 1); } + + const auto &playerAmulet = getThing(CONST_SLOT_NECKLACE); + bool usingAol = (playerAmulet && playerAmulet->getItem()->getID() == ITEM_AMULETOFLOSS); + if (usingAol) { + removeItemOfType(ITEM_AMULETOFLOSS, 1, -1); + } } } sendTextMessage(MESSAGE_EVENT_ADVANCE, blessOutput.str()); @@ -3783,14 +3800,9 @@ void Player::addInFightTicks(bool pzlock /*= false*/) { updateImbuementTrackerStats(); - // this method can be called asynchronously. - g_dispatcher().context().tryAddEvent([self = std::weak_ptr(getPlayer())] { - if (const auto &player = self.lock()) { - const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(PZ_LOCKED), 0); - player->addCondition(condition); - } - }, - "Player::addInFightTicks"); + safeCall([this] { + addCondition(Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_INFIGHT, g_configManager().getNumber(PZ_LOCKED), 0)); + }); } void Player::setDailyReward(uint8_t reward) { @@ -5026,11 +5038,15 @@ ItemsTierCountList Player::getDepotChestItemsId() const { ItemsTierCountList Player::getDepotInboxItemsId() const { ItemsTierCountList itemMap; - const auto &inbox = getInbox(); - const auto &container = inbox->getContainer(); + const auto &inboxPtr = getInbox(); + const auto &container = inboxPtr ? inboxPtr->getContainer() : nullptr; if (container) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { const auto &item = *it; + if (!item) { + continue; + } + (itemMap[item->getID()])[item->getTier()] += Item::countByType(item, -1); } } @@ -6298,21 +6314,30 @@ double Player::getLostPercent() const { return std::max(0, deathLosePercent) / 100.; } + bool isRetro = g_configManager().getBoolean(TOGGLE_SERVER_IS_RETRO); + const auto factor = (isRetro ? 6.31 : 8); + double percentReduction = (blessingCount * factor) / 100.; + double lossPercent; if (level >= 24) { const double tmpLevel = level + (levelPercent / 100.); lossPercent = ((tmpLevel + 50) * 50 * ((tmpLevel * tmpLevel) - (5 * tmpLevel) + 8)) / experience; } else { - lossPercent = 5; + percentReduction = (percentReduction >= 0.40 ? 0.50 : percentReduction); + lossPercent = 10; } - double percentReduction = 0; + g_logger().debug("[{}] - lossPercent {}", __FUNCTION__, lossPercent); + g_logger().debug("[{}] - before promotion {}", __FUNCTION__, percentReduction); + if (isPromoted()) { - percentReduction += 30; + percentReduction += 30 / 100.; + g_logger().debug("[{}] - after promotion {}", __FUNCTION__, percentReduction); } - percentReduction += blessingCount * 8; - return lossPercent * (1 - (percentReduction / 100.)) / 100.; + g_logger().debug("[{}] - total lost percent {}", __FUNCTION__, (lossPercent * (1 - percentReduction)) / 100.); + + return (lossPercent * (1 - percentReduction)) / 100.; } [[nodiscard]] const std::string &Player::getGuildNick() const { @@ -6344,7 +6369,7 @@ uint32_t Player::getMagicLevel() const { uint32_t magic = std::max(0, getLoyaltyMagicLevel() + varStats[STAT_MAGICPOINTS]); // Wheel of destiny magic bonus magic += m_wheelPlayer->getStat(WheelStat_t::MAGIC); // Regular bonus - magic += m_wheelPlayer->getMajorStatConditional("Positional Tatics", WheelMajor_t::MAGIC); // Revelation bonus + magic += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); // Revelation bonus return magic; } @@ -6402,12 +6427,12 @@ uint16_t Player::getSkillLevel(skills_t skill) const { skillLevel += m_wheelPlayer->getStat(WheelStat_t::MELEE); skillLevel += m_wheelPlayer->getMajorStatConditional("Battle Instinct", WheelMajor_t::MELEE); } else if (skill == SKILL_DISTANCE) { - skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tatics", WheelMajor_t::DISTANCE); + skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::DISTANCE); skillLevel += m_wheelPlayer->getStat(WheelStat_t::DISTANCE); } else if (skill == SKILL_SHIELD) { skillLevel += m_wheelPlayer->getMajorStatConditional("Battle Instinct", WheelMajor_t::SHIELD); } else if (skill == SKILL_MAGLEVEL) { - skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tatics", WheelMajor_t::MAGIC); + skillLevel += m_wheelPlayer->getMajorStatConditional("Positional Tactics", WheelMajor_t::MAGIC); skillLevel += m_wheelPlayer->getStat(WheelStat_t::MAGIC); } else if (skill == SKILL_LIFE_LEECH_AMOUNT) { skillLevel += m_wheelPlayer->getStat(WheelStat_t::LIFE_LEECH); @@ -6509,7 +6534,7 @@ void Player::setPerfectShotDamage(uint8_t range, int32_t damage) { } int32_t Player::getSpecializedMagicLevel(CombatType_t combat, bool useCharges) const { - int32_t result = specializedMagicLevel[combatTypeToIndex(combat)]; + int32_t result = specializedMagicLevel[combatTypeToIndex(combat)] + m_wheelPlayer->getSpecializedMagic(combat); for (const auto &item : getEquippedItems()) { const ItemType &itemType = Item::items[item->getID()]; if (!itemType.abilities) { @@ -8023,7 +8048,7 @@ void sendStowItems(const std::shared_ptr &item, const std::shared_ptr &item, uint32_t count, bool allItems) { - if (!item || !item->isItemStorable()) { + if (!item || (!item->isItemStorable() && item->getID() != ITEM_GOLD_POUCH)) { sendCancelMessage("This item cannot be stowed here."); return; } @@ -8718,10 +8743,6 @@ bool Player::saySpell(SpeakClasses type, const std::string &text, bool isGhostMo } tmpPlayer->onCreatureSay(static_self_cast(), type, text); - if (static_self_cast() != tmpPlayer) { - g_events().eventCreatureOnHear(tmpPlayer, getPlayer(), text, type); - g_callbacks().executeCallback(EventCallback_t::creatureOnHear, &EventCallback::creatureOnHear, tmpPlayer, getPlayer(), text, type); - } } return true; } @@ -8829,8 +8850,6 @@ void Player::triggerTranscendance() { } // Forge system -// Forge system - void Player::forgeFuseItems(ForgeAction_t actionType, uint16_t firstItemId, uint8_t tier, uint16_t secondItemId, bool success, bool reduceTierLoss, bool convergence, uint8_t bonus, uint8_t coreCount) { if (getFreeBackpackSlots() == 0) { sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); @@ -9058,7 +9077,7 @@ void Player::forgeFuseItems(ForgeAction_t actionType, uint16_t firstItemId, uint returnValue = g_game().internalAddItem(static_self_cast(), exaltationContainer, INDEX_WHEREEVER); if (returnValue != RETURNVALUE_NOERROR) { - g_logger().error("Failed to add exaltation chest to player with name {}", fmt::underlying(ITEM_EXALTATION_CHEST), getName()); + g_logger().error("Failed to add exaltation chest to player with name {}", getName()); sendCancelMessage(getReturnMessage(returnValue)); sendForgeError(RETURNVALUE_CONTACTADMINISTRATOR); return; diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 03f248cfa2f..6ab3be4ca7a 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -972,8 +972,10 @@ class Player final : public Creature, public Cylinder, public Bankable { uint16_t getVoucherXpBoost() const; void setVoucherXpBoost(uint16_t value); uint16_t getGrindingXpBoost() const; + uint16_t getDisplayGrindingXpBoost() const; void setGrindingXpBoost(uint16_t value); uint16_t getXpBoostPercent() const; + uint16_t getDisplayXpBoostPercent() const; void setXpBoostPercent(uint16_t percent); uint16_t getStaminaXpBoost() const; void setStaminaXpBoost(uint16_t value); diff --git a/src/creatures/players/vip/player_vip.cpp b/src/creatures/players/vip/player_vip.cpp index 195480ca5fd..8a64aebcf85 100644 --- a/src/creatures/players/vip/player_vip.cpp +++ b/src/creatures/players/vip/player_vip.cpp @@ -9,6 +9,7 @@ #include "creatures/players/vip/player_vip.hpp" +#include "account/account.hpp" #include "creatures/players/grouping/groups.hpp" #include "creatures/players/player.hpp" #include "io/iologindata.hpp" diff --git a/src/creatures/players/wheel/player_wheel.cpp b/src/creatures/players/wheel/player_wheel.cpp index 6d3ee2713a7..165a43f0687 100644 --- a/src/creatures/players/wheel/player_wheel.cpp +++ b/src/creatures/players/wheel/player_wheel.cpp @@ -9,6 +9,8 @@ #include "creatures/players/wheel/player_wheel.hpp" +#include "map/spectators.hpp" +#include "creatures/monsters/monster.hpp" #include "config/configmanager.hpp" #include "creatures/combat/condition.hpp" #include "creatures/combat/spells.hpp" @@ -957,6 +959,45 @@ int PlayerWheel::getSpellAdditionalDuration(const std::string &spellName) const return 0; } +bool PlayerWheel::handleTwinBurstsCooldown(const std::shared_ptr &player, const std::string &spellName, int spellCooldown, int rateCooldown) const { + // Map of spell pairs for Twin Bursts + static const std::unordered_map spellPairs = { + { "Terra Burst", "Ice Burst" }, + { "Ice Burst", "Terra Burst" } + }; + + auto it = spellPairs.find(spellName); + if (it != spellPairs.end()) { + const auto &spell = g_spells().getSpellByName(it->second); + if (spell) { + const auto spellId = spell->getSpellId(); + const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, spellId); + return player->addCondition(condition); + } + } + + return false; +} + +bool PlayerWheel::handleBeamMasteryCooldown(const std::shared_ptr &player, const std::string &spellName, int spellCooldown, int rateCooldown) const { + static const std::unordered_map spellPairs = { + { "Great Death Beam", "Great Energy Beam" }, + { "Great Energy Beam", "Great Death Beam" } + }; + + auto it = spellPairs.find(spellName); + if (it != spellPairs.end()) { + const auto &spell = g_spells().getSpellByName(it->second); + if (spell) { + const auto spellId = spell->getSpellId(); + const auto &condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, spellId); + return player->addCondition(condition); + } + } + + return false; +} + void PlayerWheel::addPromotionScrolls(NetworkMessage &msg) const { std::vector unlockedScrolls; @@ -988,7 +1029,7 @@ std::shared_ptr PlayerWheel::gemsGradeKV(WheelFragmentType_t type, uint8_t p uint8_t PlayerWheel::getGemGrade(WheelFragmentType_t type, uint8_t pos) const { uint8_t grade = 0; - auto gradeKV = gemsGradeKV(type, pos)->get("grade"); + const auto gradeKV = gemsGradeKV(type, pos)->get("grade"); if (gradeKV.has_value()) { grade = static_cast(gradeKV->get()); @@ -1190,7 +1231,7 @@ void PlayerWheel::destroyGem(uint16_t index) const { if (greaterFragments > 0) { const auto &fragmentsItem = Item::CreateItem(ITEM_GREATER_FRAGMENT, greaterFragments); - auto returnValue = g_game().internalPlayerAddItem(m_player.getPlayer(), fragmentsItem, false, CONST_SLOT_BACKPACK); + auto returnValue = g_game().internalPlayerAddItem(m_player.getPlayer(), fragmentsItem, false, CONST_SLOT_WHEREEVER); if (returnValue != RETURNVALUE_NOERROR) { g_logger().error("Failed to add {} greater fragments to player with name {}", greaterFragments, m_player.getName()); m_player.sendCancelMessage(getReturnMessage(RETURNVALUE_CONTACTADMINISTRATOR)); @@ -1201,8 +1242,11 @@ void PlayerWheel::destroyGem(uint16_t index) const { gem.remove(gemsKV()); - m_player.client->sendResourceBalance(RESOURCE_LESSER_FRAGMENT, m_player.getItemTypeCount(ITEM_LESSER_FRAGMENT)); - m_player.client->sendResourceBalance(RESOURCE_GREATER_FRAGMENT, m_player.getItemTypeCount(ITEM_GREATER_FRAGMENT)); + const auto totalLesserFragment = m_player.getItemTypeCount(ITEM_LESSER_FRAGMENT) + m_player.getStashItemCount(ITEM_LESSER_FRAGMENT); + const auto totalGreaterFragment = m_player.getItemTypeCount(ITEM_GREATER_FRAGMENT) + m_player.getStashItemCount(ITEM_GREATER_FRAGMENT); + + m_player.client->sendResourceBalance(RESOURCE_LESSER_FRAGMENT, totalLesserFragment); + m_player.client->sendResourceBalance(RESOURCE_GREATER_FRAGMENT, totalGreaterFragment); sendOpenWheelWindow(m_player.getID()); } @@ -1233,7 +1277,7 @@ void PlayerWheel::toggleGemLock(uint16_t index) const { } void PlayerWheel::setActiveGem(WheelGemAffinity_t affinity, uint16_t index) const { - const auto gem = getGem(index); + auto gem = getGem(index); if (gem.uuid.empty()) { g_logger().error("[{}] Failed to load gem with index {}", __FUNCTION__, index); return; @@ -1251,6 +1295,67 @@ void PlayerWheel::removeActiveGem(WheelGemAffinity_t affinity) const { gemsKV()->scoped("active")->remove(key); } +void PlayerWheel::addRevelationBonus(WheelGemAffinity_t affinity, uint16_t points) { + m_bonusRevelationPoints[static_cast(affinity)] += points; +} + +void PlayerWheel::resetRevelationBonus() { + m_bonusRevelationPoints = { 0, 0, 0, 0 }; +} + +void PlayerWheel::addSpellBonus(const std::string &spellName, const WheelSpells::Bonus &bonus) { + if (m_spellsBonuses.contains(spellName)) { + m_spellsBonuses[spellName].decrease.cooldown += bonus.decrease.cooldown; + m_spellsBonuses[spellName].decrease.manaCost += bonus.decrease.manaCost; + m_spellsBonuses[spellName].decrease.secondaryGroupCooldown += bonus.decrease.secondaryGroupCooldown; + m_spellsBonuses[spellName].increase.aditionalTarget += bonus.increase.aditionalTarget; + m_spellsBonuses[spellName].increase.area = bonus.increase.area; + m_spellsBonuses[spellName].increase.criticalChance += bonus.increase.criticalChance; + m_spellsBonuses[spellName].increase.criticalDamage += bonus.increase.criticalDamage; + m_spellsBonuses[spellName].increase.damage += bonus.increase.damage; + m_spellsBonuses[spellName].increase.damageReduction += bonus.increase.damageReduction; + m_spellsBonuses[spellName].increase.duration += bonus.increase.duration; + m_spellsBonuses[spellName].increase.heal += bonus.increase.heal; + m_spellsBonuses[spellName].leech.life += bonus.leech.life; + m_spellsBonuses[spellName].leech.mana += bonus.leech.mana; + return; + } + m_spellsBonuses[spellName] = bonus; +} + +int32_t PlayerWheel::getSpellBonus(const std::string &spellName, WheelSpellBoost_t boost) const { + using enum WheelSpellBoost_t; + + if (!m_spellsBonuses.contains(spellName)) { + return 0; + } + const auto &[leech, increase, decrease] = m_spellsBonuses.at(spellName); + switch (boost) { + case COOLDOWN: + return decrease.cooldown; + case MANA: + return decrease.manaCost; + case SECONDARY_GROUP_COOLDOWN: + return decrease.secondaryGroupCooldown; + case CRITICAL_CHANCE: + return increase.criticalChance; + case CRITICAL_DAMAGE: + return increase.criticalDamage; + case DAMAGE: + return increase.damage; + case DAMAGE_REDUCTION: + return increase.damageReduction; + case HEAL: + return increase.heal; + case LIFE_LEECH: + return leech.life; + case MANA_LEECH: + return leech.mana; + default: + return 0; + } +} + void PlayerWheel::addGems(NetworkMessage &msg) const { const auto activeGems = getActiveGems(); msg.addByte(activeGems.size()); @@ -1343,8 +1448,13 @@ void PlayerWheel::improveGemGrade(WheelFragmentType_t fragmentType, uint8_t pos) return; } - if (!m_player.hasItemCountById(fragmentId, quantity, false)) { - g_logger().error("[{}] Player {} does not have the required {} fragments with id {}", __FUNCTION__, m_player.getName(), quantity, fragmentId); + if (value == 0 && quantity == 0) { + g_logger().error("[{}] Player {} trying to upgrade gem to grade greater than 3", std::source_location::current().function_name(), m_player.getName()); + return; + } + + if (!m_player.hasItemCountById(fragmentId, quantity, true)) { + g_logger().error("[{}] Player {} does not have the required {} fragments with id {}", std::source_location::current().function_name(), m_player.getName(), quantity, fragmentId); return; } @@ -1353,7 +1463,7 @@ void PlayerWheel::improveGemGrade(WheelFragmentType_t fragmentType, uint8_t pos) return; } - if (!m_player.removeItemCountById(fragmentId, quantity, false)) { + if (!m_player.removeItemCountById(fragmentId, quantity, true)) { g_logger().error("[{}] Failed to remove {} fragments with id {} from player {}", std::source_location::current().function_name(), quantity, fragmentId, m_player.getName()); return; } @@ -1372,7 +1482,7 @@ std::tuple PlayerWheel::getLesserGradeCost(uint8_t grade) const { case 3: return std::make_tuple(30000000, 30); default: - throw std::invalid_argument("Invalid level for Lesser Fragment."); + return {}; } } @@ -1385,7 +1495,7 @@ std::tuple PlayerWheel::getGreaterGradeCost(uint8_t grade) const { case 3: return std::make_tuple(75000000, 30); default: - throw std::invalid_argument("Invalid level for Greater Fragment."); + return {}; } } @@ -1414,20 +1524,23 @@ void PlayerWheel::sendOpenWheelWindow(NetworkMessage &msg, uint32_t ownerId) { addPromotionScrolls(msg); addGems(msg); addGradeModifiers(msg); - // TODO: read items from inventory + const auto &voc = m_player.getVocation(); if (!voc) { g_logger().error("[{}] Failed to get vocation for player {}", __FUNCTION__, m_player.getName()); return; } + const auto totalLesserFragment = m_player.getItemTypeCount(ITEM_LESSER_FRAGMENT) + m_player.getStashItemCount(ITEM_LESSER_FRAGMENT); + const auto totalGreaterFragment = m_player.getItemTypeCount(ITEM_GREATER_FRAGMENT) + m_player.getStashItemCount(ITEM_GREATER_FRAGMENT); + m_player.client->sendResourceBalance(RESOURCE_BANK, m_player.getBankBalance()); m_player.client->sendResourceBalance(RESOURCE_INVENTORY_MONEY, m_player.getMoney()); m_player.client->sendResourceBalance(RESOURCE_LESSER_GEMS, m_player.getItemTypeCount(voc->getWheelGemId(WheelGemQuality_t::Lesser))); m_player.client->sendResourceBalance(RESOURCE_REGULAR_GEMS, m_player.getItemTypeCount(voc->getWheelGemId(WheelGemQuality_t::Regular))); m_player.client->sendResourceBalance(RESOURCE_GREATER_GEMS, m_player.getItemTypeCount(voc->getWheelGemId(WheelGemQuality_t::Greater))); - m_player.client->sendResourceBalance(RESOURCE_LESSER_FRAGMENT, m_player.getItemTypeCount(ITEM_LESSER_FRAGMENT)); - m_player.client->sendResourceBalance(RESOURCE_GREATER_FRAGMENT, m_player.getItemTypeCount(ITEM_GREATER_FRAGMENT)); + m_player.client->sendResourceBalance(RESOURCE_LESSER_FRAGMENT, totalLesserFragment); + m_player.client->sendResourceBalance(RESOURCE_GREATER_FRAGMENT, totalGreaterFragment); } void PlayerWheel::sendGiftOfLifeCooldown() const { @@ -1569,7 +1682,7 @@ void PlayerWheel::saveSlotPointsOnPressSaveButton(NetworkMessage &msg) { */ void PlayerWheel::loadDBPlayerSlotPointsOnLogin() { auto resultString = fmt::format("SELECT `slot` FROM `player_wheeldata` WHERE `player_id` = {}", m_player.getGUID()); - const DBResult_ptr &result = Database::getInstance().storeQuery(resultString); + const DBResult_ptr &result = g_database().storeQuery(resultString); // Ignore if player not have nothing inserted in the table if (!result) { return; @@ -1590,17 +1703,12 @@ void PlayerWheel::loadDBPlayerSlotPointsOnLogin() { } bool PlayerWheel::saveDBPlayerSlotPointsOnLogout() const { - const Database &db = Database::getInstance(); - std::ostringstream query; DBInsert insertWheelData("INSERT INTO `player_wheeldata` (`player_id`, `slot`) VALUES "); insertWheelData.upsert({ "slot" }); PropWriteStream stream; const auto wheelSlots = getSlots(); for (uint8_t i = 1; i < wheelSlots.size(); ++i) { auto value = wheelSlots[i]; - if (value == 0) { - continue; - } stream.write(i); stream.write(value); @@ -1610,7 +1718,7 @@ bool PlayerWheel::saveDBPlayerSlotPointsOnLogout() const { size_t attributesSize; const char* attributes = stream.getStream(attributesSize); if (attributesSize > 0) { - query << m_player.getGUID() << ',' << db.escapeBlob(attributes, static_cast(attributesSize)); + const auto query = fmt::format("{}, {}", m_player.getGUID(), g_database().escapeBlob(attributes, static_cast(attributesSize))); if (!insertWheelData.addRow(query)) { g_logger().debug("[{}] failed to insert row data", __FUNCTION__); return false; @@ -1819,7 +1927,7 @@ void PlayerWheel::reloadPlayerData() const { void PlayerWheel::registerPlayerBonusData() { addStat(WheelStat_t::HEALTH, m_playerBonusData.stats.health); addStat(WheelStat_t::MANA, m_playerBonusData.stats.mana); - addStat(WheelStat_t::CAPACITY, m_playerBonusData.stats.capacity * 100); + addStat(WheelStat_t::CAPACITY, m_playerBonusData.stats.capacity); addStat(WheelStat_t::MITIGATION, m_playerBonusData.mitigation * 100); addStat(WheelStat_t::DAMAGE, m_playerBonusData.stats.damage); addStat(WheelStat_t::HEALING, m_playerBonusData.stats.healing); @@ -1836,7 +1944,7 @@ void PlayerWheel::registerPlayerBonusData() { // Instant setSpellInstant("Battle Instinct", m_playerBonusData.instant.battleInstinct); setSpellInstant("Battle Healing", m_playerBonusData.instant.battleHealing); - setSpellInstant("Positional Tatics", m_playerBonusData.instant.positionalTatics); + setSpellInstant("Positional Tactics", m_playerBonusData.instant.positionalTactics); setSpellInstant("Ballistic Mastery", m_playerBonusData.instant.ballisticMastery); setSpellInstant("Healing Link", m_playerBonusData.instant.healingLink); setSpellInstant("Runic Mastery", m_playerBonusData.instant.runicMastery); @@ -1871,14 +1979,13 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.stages.divineEmpowerment; ++i) { setSpellInstant("Divine Empowerment", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 4 * 1000; + if (m_playerBonusData.stages.divineEmpowerment >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 4000; addSpellBonus("Divine Empowerment", bonus); } if (m_playerBonusData.stages.divineEmpowerment >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 4000; addSpellBonus("Divine Empowerment", bonus); } } else { @@ -1891,12 +1998,12 @@ void PlayerWheel::registerPlayerBonusData() { } if (m_playerBonusData.stages.divineGrenade >= 2) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 4000; + bonus.decrease.cooldown = 4 * 1000; addSpellBonus("Divine Grenade", bonus); } if (m_playerBonusData.stages.divineGrenade >= 3) { WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 6000; + bonus.decrease.cooldown = 6 * 1000; addSpellBonus("Divine Grenade", bonus); } } else { @@ -1911,9 +2018,21 @@ void PlayerWheel::registerPlayerBonusData() { setSpellInstant("Drain Body", false); } if (m_playerBonusData.stages.beamMastery > 0) { + m_beamMasterySpells.emplace("Energy Beam"); + m_beamMasterySpells.emplace("Great Death Beam"); + m_beamMasterySpells.emplace("Great Energy Beam"); for (int i = 0; i < m_playerBonusData.stages.beamMastery; ++i) { setSpellInstant("Beam Mastery", true); } + WheelSpells::Bonus deathBeamBonus; + deathBeamBonus.decrease.cooldown = 2 * 1000; + deathBeamBonus.increase.damage = 6; + if (m_playerBonusData.stages.beamMastery >= 2) { + addSpellBonus("Great Death Beam", deathBeamBonus); + } + if (m_playerBonusData.stages.beamMastery >= 3) { + addSpellBonus("Great Death Beam", deathBeamBonus); + } } else { setSpellInstant("Beam Mastery", false); } @@ -1922,6 +2041,17 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.stages.twinBurst; ++i) { setSpellInstant("Twin Burst", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 4 * 1000; + bonus.decrease.secondaryGroupCooldown = 4 * 1000; + if (m_playerBonusData.stages.twinBurst >= 2) { + addSpellBonus("Ice Burst", bonus); + addSpellBonus("Terra Burst", bonus); + } + if (m_playerBonusData.stages.twinBurst >= 3) { + addSpellBonus("Ice Burst", bonus); + addSpellBonus("Terra Burst", bonus); + } } else { setSpellInstant("Twin Burst", false); } @@ -1930,6 +2060,14 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.stages.executionersThrow; ++i) { setSpellInstant("Executioner's Throw", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 4 * 1000; + if (m_playerBonusData.stages.executionersThrow >= 2) { + addSpellBonus("Executioner's Throw", bonus); + } + if (m_playerBonusData.stages.executionersThrow >= 3) { + addSpellBonus("Executioner's Throw", bonus); + } } else { setSpellInstant("Executioner's Throw", false); } @@ -1939,14 +2077,13 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.avatar.light; ++i) { setSpellInstant("Avatar of Light", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes + if (m_playerBonusData.avatar.light >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Light", bonus); } if (m_playerBonusData.avatar.light >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Light", bonus); } } else { @@ -1957,14 +2094,13 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.avatar.nature; ++i) { setSpellInstant("Avatar of Nature", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes + if (m_playerBonusData.avatar.nature >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Nature", bonus); } if (m_playerBonusData.avatar.nature >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Nature", bonus); } } else { @@ -1975,14 +2111,12 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.avatar.steel; ++i) { setSpellInstant("Avatar of Steel", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes if (m_playerBonusData.avatar.steel >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Steel", bonus); } if (m_playerBonusData.avatar.steel >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Steel", bonus); } } else { @@ -1993,14 +2127,12 @@ void PlayerWheel::registerPlayerBonusData() { for (int i = 0; i < m_playerBonusData.avatar.storm; ++i) { setSpellInstant("Avatar of Storm", true); } + WheelSpells::Bonus bonus; + bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes if (m_playerBonusData.avatar.storm >= 2) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Storm", bonus); } if (m_playerBonusData.avatar.storm >= 3) { - WheelSpells::Bonus bonus; - bonus.decrease.cooldown = 30 * 60 * 1000; // 30 minutes addSpellBonus("Avatar of Storm", bonus); } } else { @@ -2100,8 +2232,8 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus if (bonusData.instant.battleHealing) { g_logger().debug(" battleHealing: {}", bonusData.instant.battleHealing); } - if (bonusData.instant.positionalTatics) { - g_logger().debug(" positionalTatics: {}", bonusData.instant.positionalTatics); + if (bonusData.instant.positionalTactics) { + g_logger().debug(" positionalTactics: {}", bonusData.instant.positionalTactics); } if (bonusData.instant.ballisticMastery) { g_logger().debug(" ballisticMastery: {}", bonusData.instant.ballisticMastery); @@ -2167,10 +2299,10 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus g_logger().debug("mitigation: {}", bonusData.mitigation); } - auto &spellsVector = bonusData.spells; + const auto &spellsVector = bonusData.spells; if (!spellsVector.empty()) { g_logger().debug("Spells:"); - for (const auto &spell : bonusData.spells) { + for (const auto &spell : spellsVector) { g_logger().debug(" {}", spell); } } @@ -2180,7 +2312,7 @@ void PlayerWheel::printPlayerWheelMethodsBonusData(const PlayerWheelMethodsBonus void PlayerWheel::loadDedicationAndConvictionPerks() { using VocationBonusFunction = std::function &, uint16_t, uint8_t, PlayerWheelMethodsBonusData &)>; - auto wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); + const auto &wheelFunctions = g_game().getIOWheel()->getWheelMapFunctions(); const auto vocationCipId = m_player.getPlayerVocationEnum(); if (vocationCipId < VOCATION_KNIGHT_CIP || vocationCipId > VOCATION_DRUID_CIP) { return; @@ -2245,7 +2377,7 @@ void PlayerWheel::processActiveGems() { if (count >= 3 && quality >= WheelGemQuality_t::Greater) { uint8_t grade = getGemGrade(WheelFragmentType_t::Greater, static_cast(supremeModifier)); std::string modifierName(magic_enum::enum_name(supremeModifier)); - g_logger().info("[{}] Adding supreme modifier {} to player {} from {} gem affinity {}", __FUNCTION__, modifierName, playerName, magic_enum::enum_name(quality), magic_enum::enum_name(affinity)); + g_logger().debug("[{}] Adding supreme modifier {} to player {} from {} gem affinity {}", __FUNCTION__, modifierName, playerName, magic_enum::enum_name(quality), magic_enum::enum_name(affinity)); m_modifierContext->addStrategies(supremeModifier, grade); } } @@ -2267,7 +2399,7 @@ void PlayerWheel::applyStageBonusForColor(const std::string &color) { return; } - auto [statsDamage, statsHealing] = g_game().getIOWheel()->getRevelationStatByStage(stageEnum); + const auto &[statsDamage, statsHealing] = g_game().getIOWheel()->getRevelationStatByStage(stageEnum); m_playerBonusData.stats.damage += statsDamage; m_playerBonusData.stats.healing += statsHealing; @@ -2345,7 +2477,6 @@ void PlayerWheel::applyBlueStageBonus(uint8_t stageValue, Vocation_t vocationEnu } else if (vocationEnum == Vocation_t::VOCATION_DRUID_CIP) { m_playerBonusData.stages.twinBurst = stageValue; for (uint8_t i = 1; i <= stageValue; ++i) { - addSpellToVector("Twin Burst"); addSpellToVector("Terra Burst"); addSpellToVector("Ice Burst"); } @@ -2429,7 +2560,7 @@ WheelStageEnum_t PlayerWheel::getPlayerSliceStage(const std::string &color) cons const auto modsSupremeIt = modsSupremePositionByVocation.find(vocationBaseId); if (modsSupremeIt != modsSupremePositionByVocation.end()) { - for (auto modPosition : modsSupremeIt->second.get()) { + for (const auto &modPosition : modsSupremeIt->second.get()) { const auto pos = static_cast(modPosition); uint8_t grade = 0; auto gradeKV = gemsGradeKV(WheelFragmentType_t::Greater, pos)->get("grade"); @@ -2465,7 +2596,7 @@ void PlayerWheel::checkAbilities() { if (getInstant("Battle Instinct") && getOnThinkTimer(WheelOnThink_t::BATTLE_INSTINCT) < OTSYS_TIME() && checkBattleInstinct()) { reloadClient = true; } - if (getInstant("Positional Tatics") && getOnThinkTimer(WheelOnThink_t::POSITIONAL_TATICS) < OTSYS_TIME() && checkPositionalTatics()) { + if (getInstant("Positional Tactics") && getOnThinkTimer(WheelOnThink_t::POSITIONAL_TACTICS) < OTSYS_TIME() && checkPositionalTactics()) { reloadClient = true; } if (getInstant("Ballistic Mastery") && getOnThinkTimer(WheelOnThink_t::BALLISTIC_MASTERY) < OTSYS_TIME() && checkBallisticMastery()) { @@ -2482,35 +2613,7 @@ bool PlayerWheel::checkBattleInstinct() { setOnThinkTimer(WheelOnThink_t::BATTLE_INSTINCT, OTSYS_TIME() + 2000); bool updateClient = false; m_creaturesNearby = 0; - uint16_t creaturesNearby = 0; - for (int offsetX = -1; offsetX <= 1; offsetX++) { - if (creaturesNearby >= 8) { - break; - } - for (int offsetY = -1; offsetY <= 1; offsetY++) { - if (creaturesNearby >= 8) { - break; - } - - const auto playerPositionOffSet = Position( - m_player.getPosition().x + offsetX, - m_player.getPosition().y + offsetY, - m_player.getPosition().z - ); - const auto &tile = g_game().map.getTile(playerPositionOffSet); - if (!tile) { - continue; - } - - const auto &creature = tile->getTopVisibleCreature(m_player.getPlayer()); - if (!creature || creature == m_player.getPlayer() || (creature->getMaster() && creature->getMaster()->getPlayer() == m_player.getPlayer())) { - continue; - } - - creaturesNearby++; - } - } - + uint16_t creaturesNearby = Spectators().find(m_player.getPosition(), false, 1, 1, 1, 1).excludePlayerMaster().size(); if (creaturesNearby >= 5) { m_creaturesNearby = creaturesNearby; creaturesNearby -= 4; @@ -2530,36 +2633,13 @@ bool PlayerWheel::checkBattleInstinct() { return updateClient; } -bool PlayerWheel::checkPositionalTatics() { - setOnThinkTimer(WheelOnThink_t::POSITIONAL_TATICS, OTSYS_TIME() + 2000); +bool PlayerWheel::checkPositionalTactics() { + setOnThinkTimer(WheelOnThink_t::POSITIONAL_TACTICS, OTSYS_TIME() + 2000); m_creaturesNearby = 0; bool updateClient = false; - uint16_t creaturesNearby = 0; - for (int offsetX = -1; offsetX <= 1; offsetX++) { - if (creaturesNearby > 0) { - break; - } - for (int offsetY = -1; offsetY <= 1; offsetY++) { - const auto playerPositionOffSet = Position( - m_player.getPosition().x + offsetX, - m_player.getPosition().y + offsetY, - m_player.getPosition().z - ); - const auto &tile = g_game().map.getTile(playerPositionOffSet); - if (!tile) { - continue; - } - - const auto &creature = tile->getTopVisibleCreature(m_player.getPlayer()); - if (!creature || creature == m_player.getPlayer() || !creature->getMonster() || (creature->getMaster() && creature->getMaster()->getPlayer())) { - continue; - } - - creaturesNearby++; - break; - } - } - constexpr uint16_t magicSkill = 3; + uint16_t creaturesNearby = Spectators().find(m_player.getPosition(), false, 1, 1, 1, 1).excludePlayerMaster().size(); + constexpr uint16_t holyMagicSkill = 3; + constexpr uint16_t healingMagicSkill = 3; constexpr uint16_t distanceSkill = 3; if (creaturesNearby == 0) { m_creaturesNearby = creaturesNearby; @@ -2567,8 +2647,12 @@ bool PlayerWheel::checkPositionalTatics() { setMajorStat(WheelMajor_t::DISTANCE, distanceSkill); updateClient = true; } - if (getMajorStat(WheelMajor_t::MAGIC) != 0) { - setMajorStat(WheelMajor_t::MAGIC, 0); + if (getSpecializedMagic(COMBAT_HOLYDAMAGE) != 0) { + setSpecializedMagic(COMBAT_HOLYDAMAGE, 0); + updateClient = true; + } + if (getSpecializedMagic(COMBAT_HEALING) != 0) { + setSpecializedMagic(COMBAT_HEALING, 0); updateClient = true; } } else { @@ -2576,8 +2660,12 @@ bool PlayerWheel::checkPositionalTatics() { setMajorStat(WheelMajor_t::DISTANCE, 0); updateClient = true; } - if (getMajorStat(WheelMajor_t::MAGIC) != magicSkill) { - setMajorStat(WheelMajor_t::MAGIC, magicSkill); + if (getSpecializedMagic(COMBAT_HOLYDAMAGE) != holyMagicSkill) { + setSpecializedMagic(COMBAT_HOLYDAMAGE, holyMagicSkill); + updateClient = true; + } + if (getSpecializedMagic(COMBAT_HEALING) != healingMagicSkill) { + setSpecializedMagic(COMBAT_HEALING, healingMagicSkill); updateClient = true; } } @@ -2954,7 +3042,7 @@ void PlayerWheel::onThink(bool force /* = false*/) { if (getGiftOfCooldown() > 0 /*getInstant("Gift of Life")*/ && getOnThinkTimer(WheelOnThink_t::GIFT_OF_LIFE) <= OTSYS_TIME()) { decreaseGiftOfCooldown(1); } - if (!m_player.hasCondition(CONDITION_INFIGHT) || m_player.getZoneType() == ZONE_PROTECTION || (!getInstant("Battle Instinct") && !getInstant("Positional Tatics") && !getInstant("Ballistic Mastery") && !getInstant("Gift of Life") && !getInstant("Combat Mastery") && !getInstant("Divine Empowerment") && getGiftOfCooldown() == 0)) { + if (!m_player.hasCondition(CONDITION_INFIGHT) || m_player.getZoneType() == ZONE_PROTECTION || (!getInstant("Battle Instinct") && !getInstant("Positional Tactics") && !getInstant("Ballistic Mastery") && !getInstant("Gift of Life") && !getInstant("Combat Mastery") && !getInstant("Divine Empowerment") && getGiftOfCooldown() == 0)) { bool mustReset = false; for (int i = 0; i < static_cast(WheelMajor_t::TOTAL_COUNT); i++) { if (getMajorStat(static_cast(i)) != 0) { @@ -2979,8 +3067,8 @@ void PlayerWheel::onThink(bool force /* = false*/) { if (getInstant("Battle Instinct") && (force || getOnThinkTimer(WheelOnThink_t::BATTLE_INSTINCT) < OTSYS_TIME()) && checkBattleInstinct()) { updateClient = true; } - // Positional Tatics - if (getInstant("Positional Tatics") && (force || getOnThinkTimer(WheelOnThink_t::POSITIONAL_TATICS) < OTSYS_TIME()) && checkPositionalTatics()) { + // Positional Tactics + if (getInstant("Positional Tactics") && (force || getOnThinkTimer(WheelOnThink_t::POSITIONAL_TACTICS) < OTSYS_TIME()) && checkPositionalTactics()) { updateClient = true; } // Ballistic Mastery @@ -3003,12 +3091,33 @@ void PlayerWheel::onThink(bool force /* = false*/) { void PlayerWheel::reduceAllSpellsCooldownTimer(int32_t value) const { for (const auto &condition : m_player.getConditionsByType(CONDITION_SPELLCOOLDOWN)) { - if (condition->getTicks() <= value) { - m_player.sendSpellCooldown(condition->getSubId(), 0); - condition->endCondition(m_player.getPlayer()); - } else { - condition->setTicks(condition->getTicks() - value); - m_player.sendSpellCooldown(condition->getSubId(), condition->getTicks()); + const auto spellId = condition->getSubId(); + const auto &spell = g_spells().getInstantSpellById(spellId); + if (!spell) { + continue; + } + + const auto spellSecondaryGroup = spell->getSecondaryGroup(); + const auto &secondCondition = m_player.getCondition(CONDITION_SPELLGROUPCOOLDOWN, CONDITIONID_DEFAULT, spellSecondaryGroup); + + if (secondCondition) { + if (secondCondition->getTicks() <= value) { + m_player.sendSpellGroupCooldown(spellSecondaryGroup, 0); + secondCondition->endCondition(m_player.getPlayer()); + } else { + secondCondition->setTicks(secondCondition->getTicks() - value); + m_player.sendSpellGroupCooldown(spellSecondaryGroup, secondCondition->getTicks()); + } + } + + if (condition) { + if (condition->getTicks() <= value) { + m_player.sendSpellCooldown(spellId, 0); + condition->endCondition(m_player.getPlayer()); + } else { + condition->setTicks(condition->getTicks() - value); + m_player.sendSpellCooldown(spellId, condition->getTicks()); + } } } } @@ -3022,6 +3131,7 @@ void PlayerWheel::resetUpgradedSpells() { m_creaturesNearby = 0; m_spellsSelected.clear(); m_learnedSpellsSelected.clear(); + m_beamMasterySpells.clear(); for (int i = 0; i < static_cast(WheelMajor_t::TOTAL_COUNT); i++) { setMajorStat(static_cast(i), 0); } @@ -3087,17 +3197,15 @@ std::shared_ptr PlayerWheel::getCombatDataSpell(CombatDamage &damage) { damage.lifeLeechChance += spell->getWheelOfDestinyBoost(WheelSpellBoost_t::LIFE_LEECH_CHANCE, spellGrade); } - if (m_spellsBonuses.contains(spellName)) { - damage.criticalDamage += (getSpellBonus(spellName, WheelSpellBoost_t::CRITICAL_DAMAGE) * 100); - damage.criticalChance += getSpellBonus(spellName, WheelSpellBoost_t::CRITICAL_CHANCE); - damage.damageMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::DAMAGE); - damage.damageReductionMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::DAMAGE_REDUCTION); - damage.healingMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::HEAL); - damage.manaLeech += getSpellBonus(spellName, WheelSpellBoost_t::MANA_LEECH); - damage.manaLeechChance += getSpellBonus(spellName, WheelSpellBoost_t::MANA_LEECH_CHANCE); - damage.lifeLeech += getSpellBonus(spellName, WheelSpellBoost_t::LIFE_LEECH); - damage.lifeLeechChance += getSpellBonus(spellName, WheelSpellBoost_t::LIFE_LEECH_CHANCE); - } + damage.criticalDamage += (getSpellBonus(spellName, WheelSpellBoost_t::CRITICAL_DAMAGE) * 100); + damage.criticalChance += getSpellBonus(spellName, WheelSpellBoost_t::CRITICAL_CHANCE); + damage.damageMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::DAMAGE); + damage.damageReductionMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::DAMAGE_REDUCTION); + damage.healingMultiplier += getSpellBonus(spellName, WheelSpellBoost_t::HEAL); + damage.manaLeech += getSpellBonus(spellName, WheelSpellBoost_t::MANA_LEECH); + damage.manaLeechChance += getSpellBonus(spellName, WheelSpellBoost_t::MANA_LEECH_CHANCE); + damage.lifeLeech += getSpellBonus(spellName, WheelSpellBoost_t::LIFE_LEECH); + damage.lifeLeechChance += getSpellBonus(spellName, WheelSpellBoost_t::LIFE_LEECH_CHANCE); } return spell; @@ -3131,6 +3239,15 @@ void PlayerWheel::setMajorStat(WheelMajor_t type, int32_t value) { } } +void PlayerWheel::setSpecializedMagic(CombatType_t type, int32_t value) { + auto enumValue = static_cast(type); + try { + m_specializedMagic.at(enumValue) = value; + } catch (const std::out_of_range &e) { + g_logger().error("[{}]. Type {} is out of range, value {}. Error message: {}", __FUNCTION__, enumValue, value, e.what()); + } +} + void PlayerWheel::setInstant(WheelInstant_t type, bool toggle) { auto enumValue = static_cast(type); try { @@ -3167,9 +3284,9 @@ void PlayerWheel::setSpellInstant(const std::string &name, bool value) { } } else if (name == "Battle Healing") { setInstant(WheelInstant_t::BATTLE_HEALING, value); - } else if (name == "Positional Tatics") { - setInstant(WheelInstant_t::POSITIONAL_TATICS, value); - if (!getInstant(WheelInstant_t::POSITIONAL_TATICS)) { + } else if (name == "Positional Tactics") { + setInstant(WheelInstant_t::POSITIONAL_TACTICS, value); + if (!getInstant(WheelInstant_t::POSITIONAL_TACTICS)) { setMajorStat(WheelMajor_t::MAGIC, 0); setMajorStat(WheelMajor_t::HOLY_RESISTANCE, 0); } @@ -3296,65 +3413,38 @@ bool PlayerWheel::getInstant(WheelInstant_t type) const { uint8_t PlayerWheel::getStage(std::string_view name) const { using enum WheelInstant_t; using enum WheelStage_t; - if (name == "Battle Instinct") { - return PlayerWheel::getInstant(BATTLE_INSTINCT); - } - if (name == "Battle Healing") { - return PlayerWheel::getInstant(BATTLE_HEALING); - } - if (name == "Positional Tatics") { - return PlayerWheel::getInstant(POSITIONAL_TATICS); - } - if (name == "Ballistic Mastery") { - return PlayerWheel::getInstant(BALLISTIC_MASTERY); - } - if (name == "Healing Link") { - return PlayerWheel::getInstant(HEALING_LINK); - } - if (name == "Runic Mastery") { - return PlayerWheel::getInstant(RUNIC_MASTERY); - } - if (name == "Focus Mastery") { - return PlayerWheel::getInstant(FOCUS_MASTERY); - } - if (name == "Beam Mastery") { - return PlayerWheel::getStage(BEAM_MASTERY); - } - if (name == "Combat Mastery") { - return PlayerWheel::getStage(COMBAT_MASTERY); - } - if (name == "Gift of Life") { - return PlayerWheel::getStage(GIFT_OF_LIFE); - } - if (name == "Blessing of the Grove") { - return PlayerWheel::getStage(BLESSING_OF_THE_GROVE); - } - if (name == "Drain Body") { - return PlayerWheel::getStage(DRAIN_BODY); - } - if (name == "Divine Empowerment") { - return PlayerWheel::getStage(DIVINE_EMPOWERMENT); - } - if (name == "Divine Grenade") { - return PlayerWheel::getStage(DIVINE_GRENADE); - } - if (name == "Twin Burst") { - return PlayerWheel::getStage(TWIN_BURST); - } - if (name == "Executioner's Throw") { - return PlayerWheel::getStage(EXECUTIONERS_THROW); - } - if (name == "Avatar of Light") { - return PlayerWheel::getStage(AVATAR_OF_LIGHT); - } - if (name == "Avatar of Nature") { - return PlayerWheel::getStage(AVATAR_OF_NATURE); - } - if (name == "Avatar of Steel") { - return PlayerWheel::getStage(AVATAR_OF_STEEL); + + static const std::unordered_map instantMapping = { + { "Battle Instinct", BATTLE_INSTINCT }, + { "Battle Healing", BATTLE_HEALING }, + { "Positional Tatics", POSITIONAL_TACTICS }, + { "Ballistic Mastery", BALLISTIC_MASTERY }, + { "Healing Link", HEALING_LINK }, + { "Runic Mastery", RUNIC_MASTERY }, + { "Focus Mastery", FOCUS_MASTERY } + }; + + static const std::unordered_map stageMapping = { + { "Beam Mastery", BEAM_MASTERY }, + { "Combat Mastery", COMBAT_MASTERY }, + { "Gift of Life", GIFT_OF_LIFE }, + { "Blessing of the Grove", BLESSING_OF_THE_GROVE }, + { "Drain Body", DRAIN_BODY }, + { "Divine Empowerment", DIVINE_EMPOWERMENT }, + { "Divine Grenade", DIVINE_GRENADE }, + { "Twin Burst", TWIN_BURST }, + { "Executioner's Throw", EXECUTIONERS_THROW }, + { "Avatar of Light", AVATAR_OF_LIGHT }, + { "Avatar of Nature", AVATAR_OF_NATURE }, + { "Avatar of Steel", AVATAR_OF_STEEL }, + { "Avatar of Storm", AVATAR_OF_STORM } + }; + + if (auto it = instantMapping.find(name); it != instantMapping.end()) { + return PlayerWheel::getInstant(it->second); } - if (name == "Avatar of Storm") { - return PlayerWheel::getStage(AVATAR_OF_STORM); + if (auto it = stageMapping.find(name); it != stageMapping.end()) { + return PlayerWheel::getStage(it->second); } return false; @@ -3380,6 +3470,16 @@ int32_t PlayerWheel::getMajorStat(WheelMajor_t type) const { return 0; } +int32_t PlayerWheel::getSpecializedMagic(CombatType_t type) const { + auto enumValue = static_cast(type); + try { + return m_specializedMagic.at(enumValue); + } catch (const std::out_of_range &e) { + g_logger().error("[{}]. Instant type {}. Error message: {}", __FUNCTION__, enumValue, e.what()); + } + return 0; +} + int32_t PlayerWheel::getStat(WheelStat_t type) const { auto enumValue = static_cast(type); try { @@ -3440,65 +3540,39 @@ int64_t PlayerWheel::getOnThinkTimer(WheelOnThink_t type) const { bool PlayerWheel::getInstant(std::string_view name) const { using enum WheelInstant_t; - if (name == "Battle Instinct") { - return PlayerWheel::getInstant(BATTLE_INSTINCT); - } - if (name == "Battle Healing") { - return PlayerWheel::getInstant(BATTLE_HEALING); - } - if (name == "Positional Tatics") { - return PlayerWheel::getInstant(POSITIONAL_TATICS); - } - if (name == "Ballistic Mastery") { - return PlayerWheel::getInstant(BALLISTIC_MASTERY); - } - if (name == "Healing Link") { - return PlayerWheel::getInstant(HEALING_LINK); - } - if (name == "Runic Mastery") { - return PlayerWheel::getInstant(RUNIC_MASTERY); - } - if (name == "Focus Mastery") { - return PlayerWheel::getInstant(FOCUS_MASTERY); - } - if (name == "Beam Mastery") { - return PlayerWheel::getStage(WheelStage_t::BEAM_MASTERY); - } - if (name == "Combat Mastery") { - return PlayerWheel::getStage(WheelStage_t::COMBAT_MASTERY); - } - if (name == "Gift of Life") { - return PlayerWheel::getStage(WheelStage_t::GIFT_OF_LIFE); - } - if (name == "Blessing of the Grove") { - return PlayerWheel::getStage(WheelStage_t::BLESSING_OF_THE_GROVE); - } - if (name == "Drain Body") { - return PlayerWheel::getStage(WheelStage_t::DRAIN_BODY); - } - if (name == "Divine Empowerment") { - return PlayerWheel::getStage(WheelStage_t::DIVINE_EMPOWERMENT); - } - if (name == "Divine Grenade") { - return PlayerWheel::getStage(WheelStage_t::DIVINE_GRENADE); - } - if (name == "Twin Burst") { - return PlayerWheel::getStage(WheelStage_t::TWIN_BURST); - } - if (name == "Executioner's Throw") { - return PlayerWheel::getStage(WheelStage_t::EXECUTIONERS_THROW); - } - if (name == "Avatar of Light") { - return PlayerWheel::getStage(WheelStage_t::AVATAR_OF_LIGHT); - } - if (name == "Avatar of Nature") { - return PlayerWheel::getStage(WheelStage_t::AVATAR_OF_NATURE); - } - if (name == "Avatar of Steel") { - return PlayerWheel::getStage(WheelStage_t::AVATAR_OF_STEEL); + using enum WheelStage_t; + + static const std::unordered_map instantMapping = { + { "Battle Instinct", BATTLE_INSTINCT }, + { "Battle Healing", BATTLE_HEALING }, + { "Positional Tactics", POSITIONAL_TACTICS }, + { "Ballistic Mastery", BALLISTIC_MASTERY }, + { "Healing Link", HEALING_LINK }, + { "Runic Mastery", RUNIC_MASTERY }, + { "Focus Mastery", FOCUS_MASTERY } + }; + + static const std::unordered_map stageMapping = { + { "Beam Mastery", BEAM_MASTERY }, + { "Combat Mastery", COMBAT_MASTERY }, + { "Gift of Life", GIFT_OF_LIFE }, + { "Blessing of the Grove", BLESSING_OF_THE_GROVE }, + { "Drain Body", DRAIN_BODY }, + { "Divine Empowerment", DIVINE_EMPOWERMENT }, + { "Divine Grenade", DIVINE_GRENADE }, + { "Twin Burst", TWIN_BURST }, + { "Executioner's Throw", EXECUTIONERS_THROW }, + { "Avatar of Light", AVATAR_OF_LIGHT }, + { "Avatar of Nature", AVATAR_OF_NATURE }, + { "Avatar of Steel", AVATAR_OF_STEEL }, + { "Avatar of Storm", AVATAR_OF_STORM } + }; + + if (auto it = instantMapping.find(name); it != instantMapping.end()) { + return PlayerWheel::getInstant(it->second); } - if (name == "Avatar of Storm") { - return PlayerWheel::getStage(WheelStage_t::AVATAR_OF_STORM); + if (auto it = stageMapping.find(name); it != stageMapping.end()) { + return PlayerWheel::getStage(it->second); } return false; @@ -3599,7 +3673,7 @@ void PlayerWheel::setWheelBonusData(const PlayerWheelMethodsBonusData &newBonusD // Functions used to Manage Combat uint8_t PlayerWheel::getBeamAffectedTotal(const CombatDamage &tmpDamage) const { uint8_t beamAffectedTotal = 0; // Removed const - if (tmpDamage.runeSpellName == "Beam Mastery" && getInstant("Beam Mastery")) { + if (m_beamMasterySpells.contains(tmpDamage.instantSpellName) && getInstant("Beam Mastery")) { beamAffectedTotal = 3; } return beamAffectedTotal; @@ -3608,6 +3682,7 @@ uint8_t PlayerWheel::getBeamAffectedTotal(const CombatDamage &tmpDamage) const { void PlayerWheel::updateBeamMasteryDamage(CombatDamage &tmpDamage, uint8_t &beamAffectedTotal, uint8_t &beamAffectedCurrent) const { if (beamAffectedTotal > 0) { tmpDamage.damageMultiplier += checkBeamMasteryDamage(); + reduceAllSpellsCooldownTimer(1000); // Reduces all spell cooldown by 1 second per target hit (max 3 seconds) --beamAffectedTotal; beamAffectedCurrent++; } diff --git a/src/creatures/players/wheel/player_wheel.hpp b/src/creatures/players/wheel/player_wheel.hpp index 840cc72d8dc..7c3bd2348a6 100644 --- a/src/creatures/players/wheel/player_wheel.hpp +++ b/src/creatures/players/wheel/player_wheel.hpp @@ -107,6 +107,9 @@ class PlayerWheel { int getSpellAdditionalDuration(const std::string &spellName) const; bool getSpellAdditionalArea(const std::string &spellName) const; + bool handleTwinBurstsCooldown(const std::shared_ptr &player, const std::string &spellName, int spellCooldown, int rateCooldown) const; + bool handleBeamMasteryCooldown(const std::shared_ptr &player, const std::string &spellName, int spellCooldown, int rateCooldown) const; + /* * Functions for manage slots */ @@ -209,7 +212,7 @@ class PlayerWheel { void checkAbilities(); void checkGiftOfLife(); bool checkBattleInstinct(); - bool checkPositionalTatics(); + bool checkPositionalTactics(); bool checkBallisticMastery(); bool checkCombatMastery(); bool checkDivineEmpowerment(); @@ -260,6 +263,16 @@ class PlayerWheel { */ void setMajorStat(WheelMajor_t type, int32_t value); + /** + * @brief Sets the value of a specific specialized magic in the Wheel of Destiny. + * + * This function sets the value of the specified specialized magic in the Wheel of Destiny to the provided value. + * + * @param type The type of the combat to set the specialized magic. + * @param value The value to set for the specialized magic. + */ + void setSpecializedMagic(CombatType_t type, int32_t value); + /** * @brief Sets the value of a specific instant in the Wheel of Destiny. * @@ -310,6 +323,7 @@ class PlayerWheel { uint8_t getStage(WheelStage_t type) const; WheelSpellGrade_t getSpellUpgrade(const std::string &name) const; int32_t getMajorStat(WheelMajor_t type) const; + int32_t getSpecializedMagic(CombatType_t type) const; int32_t getStat(WheelStat_t type) const; int32_t getResistance(CombatType_t type) const; int32_t getMajorStatConditional(const std::string &instant, WheelMajor_t major) const; @@ -379,63 +393,11 @@ class PlayerWheel { void toggleGemLock(uint16_t index) const; void setActiveGem(WheelGemAffinity_t affinity, uint16_t index) const; void removeActiveGem(WheelGemAffinity_t affinity) const; - void addRevelationBonus(WheelGemAffinity_t affinity, uint16_t points) { - m_bonusRevelationPoints[static_cast(affinity)] += points; - } - void resetRevelationBonus() { - m_bonusRevelationPoints = { 0, 0, 0, 0 }; - } - - void addSpellBonus(const std::string &spellName, const WheelSpells::Bonus &bonus) { - if (m_spellsBonuses.contains(spellName)) { - m_spellsBonuses[spellName].decrease.cooldown += bonus.decrease.cooldown; - m_spellsBonuses[spellName].decrease.manaCost += bonus.decrease.manaCost; - m_spellsBonuses[spellName].decrease.secondaryGroupCooldown += bonus.decrease.secondaryGroupCooldown; - m_spellsBonuses[spellName].increase.aditionalTarget += bonus.increase.aditionalTarget; - m_spellsBonuses[spellName].increase.area = bonus.increase.area; - m_spellsBonuses[spellName].increase.criticalChance += bonus.increase.criticalChance; - m_spellsBonuses[spellName].increase.criticalDamage += bonus.increase.criticalDamage; - m_spellsBonuses[spellName].increase.damage += bonus.increase.damage; - m_spellsBonuses[spellName].increase.damageReduction += bonus.increase.damageReduction; - m_spellsBonuses[spellName].increase.duration += bonus.increase.duration; - m_spellsBonuses[spellName].increase.heal += bonus.increase.heal; - m_spellsBonuses[spellName].leech.life += bonus.leech.life; - m_spellsBonuses[spellName].leech.mana += bonus.leech.mana; - return; - } - m_spellsBonuses[spellName] = bonus; - } - - int32_t getSpellBonus(const std::string &spellName, WheelSpellBoost_t boost) const { - if (!m_spellsBonuses.contains(spellName)) { - return 0; - } - auto [leech, increase, decrease] = m_spellsBonuses.at(spellName); - switch (boost) { - case WheelSpellBoost_t::COOLDOWN: - return decrease.cooldown; - case WheelSpellBoost_t::MANA: - return decrease.manaCost; - case WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN: - return decrease.secondaryGroupCooldown; - case WheelSpellBoost_t::CRITICAL_CHANCE: - return increase.criticalChance; - case WheelSpellBoost_t::CRITICAL_DAMAGE: - return increase.criticalDamage; - case WheelSpellBoost_t::DAMAGE: - return increase.damage; - case WheelSpellBoost_t::DAMAGE_REDUCTION: - return increase.damageReduction; - case WheelSpellBoost_t::HEAL: - return increase.heal; - case WheelSpellBoost_t::LIFE_LEECH: - return leech.life; - case WheelSpellBoost_t::MANA_LEECH: - return leech.mana; - default: - return 0; - } - } + void addRevelationBonus(WheelGemAffinity_t affinity, uint16_t points); + void resetRevelationBonus(); + void addSpellBonus(const std::string &spellName, const WheelSpells::Bonus &bonus); + + int32_t getSpellBonus(const std::string &spellName, WheelSpellBoost_t boost) const; WheelGemBasicModifier_t selectBasicModifier2(WheelGemBasicModifier_t modifier1) const; @@ -465,9 +427,11 @@ class PlayerWheel { std::array(WheelMajor_t::TOTAL_COUNT)> m_majorStats = { 0 }; std::array(WheelInstant_t::INSTANT_COUNT)> m_instant = { false }; std::array m_resistance = { 0 }; + std::array m_specializedMagic = { 0 }; int32_t m_creaturesNearby = 0; std::map m_spellsSelected; std::vector m_learnedSpellsSelected; std::unordered_map m_spellsBonuses; + std::unordered_set m_beamMasterySpells; }; diff --git a/src/creatures/players/wheel/wheel_definitions.hpp b/src/creatures/players/wheel/wheel_definitions.hpp index 0aa22c5a7b9..a136bd620d3 100644 --- a/src/creatures/players/wheel/wheel_definitions.hpp +++ b/src/creatures/players/wheel/wheel_definitions.hpp @@ -97,7 +97,7 @@ enum class WheelStage_t : uint8_t { enum class WheelOnThink_t : uint8_t { BATTLE_INSTINCT = 0, - POSITIONAL_TATICS = 1, + POSITIONAL_TACTICS = 1, BALLISTIC_MASTERY = 2, COMBAT_MASTERY = 3, FOCUS_MASTERY = 4, @@ -148,7 +148,7 @@ enum class WheelMajor_t : uint8_t { enum class WheelInstant_t : uint8_t { BATTLE_INSTINCT = 0, BATTLE_HEALING = 1, - POSITIONAL_TATICS = 2, + POSITIONAL_TACTICS = 2, BALLISTIC_MASTERY = 3, HEALING_LINK = 4, RUNIC_MASTERY = 5, @@ -217,7 +217,7 @@ struct PlayerWheelMethodsBonusData { struct Instant { bool battleInstinct = false; // Knight bool battleHealing = false; // Knight - bool positionalTatics = false; // Paladin + bool positionalTactics = false; // Paladin bool ballisticMastery = false; // Paladin bool healingLink = false; // Druid bool runicMastery = false; // Druid/sorcerer @@ -282,7 +282,7 @@ namespace WheelSpells { struct Decrease { int cooldown = 0; int manaCost = 0; - uint8_t secondaryGroupCooldown = 0; + int secondaryGroupCooldown = 0; }; struct Leech { diff --git a/src/creatures/players/wheel/wheel_gems.cpp b/src/creatures/players/wheel/wheel_gems.cpp index a2c7a898766..766fa9ee049 100644 --- a/src/creatures/players/wheel/wheel_gems.cpp +++ b/src/creatures/players/wheel/wheel_gems.cpp @@ -238,16 +238,16 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin switch (modifier) { case WheelGemSupremeModifier_t::General_Dodge: - m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::DODGE, 25 * gradeMultiplier)); + m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::DODGE, 28 * gradeMultiplier)); break; case WheelGemSupremeModifier_t::General_LifeLeech: - m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::LIFE_LEECH, 120 * gradeMultiplier)); + m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::LIFE_LEECH, 200 * gradeMultiplier)); break; case WheelGemSupremeModifier_t::General_ManaLeech: - m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::MANA_LEECH, 40 * gradeMultiplier)); + m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::MANA_LEECH, 80 * gradeMultiplier)); break; case WheelGemSupremeModifier_t::General_CriticalDamage: - m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::CRITICAL_DAMAGE, 150 * gradeMultiplier)); + m_strategies.emplace_back(std::make_unique(m_wheel, WheelStat_t::CRITICAL_DAMAGE, 200 * gradeMultiplier)); break; case WheelGemSupremeModifier_t::General_RevelationMastery_GiftOfLife: m_strategies.emplace_back(std::make_unique(m_wheel, WheelGemAffinity_t::Green, 150 * gradeMultiplier)); @@ -255,7 +255,7 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin break; case WheelGemSupremeModifier_t::SorcererDruid_UltimateHealing: - bonus.increase.heal = 10 * gradeMultiplier; + bonus.increase.heal = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Ultimate Healing", bonus)); break; @@ -312,25 +312,25 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin break; case WheelGemSupremeModifier_t::Knight_AvatarOfSteel_Cooldown: - bonus.decrease.cooldown = 300 * 1000; + bonus.decrease.cooldown = 900 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Avatar of Steel", bonus)); break; case WheelGemSupremeModifier_t::Knight_ExecutionersThrow_Cooldown: - bonus.decrease.cooldown = 1 * 1000; + bonus.decrease.cooldown = 2 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Executioner's Throw", bonus)); break; case WheelGemSupremeModifier_t::Knight_ExecutionersThrow_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 6 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Executioner's Throw", bonus)); break; case WheelGemSupremeModifier_t::Knight_ExecutionersThrow_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Executioner's Throw", bonus)); break; case WheelGemSupremeModifier_t::Knight_Fierce_Berserk_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Fierce Berserk", bonus)); break; case WheelGemSupremeModifier_t::Knight_Fierce_Berserk_CriticalExtraDamage: @@ -338,35 +338,35 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin m_strategies.emplace_back(std::make_unique(m_wheel, "Fierce Berserk", bonus)); break; case WheelGemSupremeModifier_t::Knight_Berserk_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Berserk", bonus)); break; case WheelGemSupremeModifier_t::Knight_Berserk_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Berserk", bonus)); break; case WheelGemSupremeModifier_t::Knight_Front_Sweep_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Front Sweep", bonus)); break; case WheelGemSupremeModifier_t::Knight_Front_Sweep_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Front Sweep", bonus)); break; case WheelGemSupremeModifier_t::Knight_Groundshaker_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = static_cast(std::round(6.5 * gradeMultiplier)); m_strategies.emplace_back(std::make_unique(m_wheel, "Groundshaker", bonus)); break; case WheelGemSupremeModifier_t::Knight_Groundshaker_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Groundshaker", bonus)); break; case WheelGemSupremeModifier_t::Knight_Annihilation_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 15 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Annihilation", bonus)); break; case WheelGemSupremeModifier_t::Knight_Annihilation_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Annihilation", bonus)); break; case WheelGemSupremeModifier_t::Knight_FairWoundCleansing_HealingIncrease: @@ -375,72 +375,72 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin break; case WheelGemSupremeModifier_t::Paladin_AvatarOfLight_Cooldown: - bonus.decrease.cooldown = 300 * 1000; + bonus.decrease.cooldown = 900 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Avatar of Light", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineDazzle_Cooldown: - bonus.decrease.cooldown = 2 * 1000; + bonus.decrease.cooldown = 4 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Dazzle", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineGrenade_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 6 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Grenade", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineGrenade_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Grenade", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineCaldera_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Caldera", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineCaldera_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Caldera", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineMissile_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Missile", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineMissile_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Missile", bonus)); break; case WheelGemSupremeModifier_t::Paladin_EtherealSpear_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 10 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Ethereal Spear", bonus)); break; case WheelGemSupremeModifier_t::Paladin_EtherealSpear_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 15 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Ethereal Spear", bonus)); break; case WheelGemSupremeModifier_t::Paladin_StrongEtherealSpear_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Strong Ethereal Spear", bonus)); break; case WheelGemSupremeModifier_t::Paladin_StrongEtherealSpear_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Strong Ethereal Spear", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineEmpowerment_Cooldown: - bonus.decrease.cooldown = 3 * 1000; + bonus.decrease.cooldown = 6 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Empowerment", bonus)); break; case WheelGemSupremeModifier_t::Paladin_DivineGrenade_Cooldown: - bonus.decrease.cooldown = 1 * 1000; + bonus.decrease.cooldown = 2 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Divine Grenade", bonus)); break; case WheelGemSupremeModifier_t::Paladin_Salvation_HealingIncrease: - bonus.increase.heal = 10 * gradeMultiplier; + bonus.increase.heal = 6 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Salvation", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_AvatarOfStorm_Cooldown: - bonus.decrease.cooldown = 300 * 1000; + bonus.decrease.cooldown = 900 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Avatar of Storm", bonus)); break; @@ -450,31 +450,31 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin m_strategies.emplace_back(std::make_unique(m_wheel, "Energy Wave", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatDeathBeam_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 10 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Great Death Beam", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatDeathBeam_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 15 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Great Death Beam", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_HellsCore_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Hell's Core", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_HellsCore_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Hell's Core", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_EnergyWave_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Energy Wave", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_EnergyWave_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Energy Wave", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatFireWave_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Great Fire Wave", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatFireWave_CriticalExtraDamage: @@ -482,24 +482,24 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin m_strategies.emplace_back(std::make_unique(m_wheel, "Great Fire Wave", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_RageOfTheSkies_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Rage of the Skies", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_RageOfTheSkies_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Rage of the Skies", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatEnergyBeam_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 10 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Great Energy Beam", bonus)); break; case WheelGemSupremeModifier_t::Sorcerer_GreatEnergyBeam_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 15 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Great Energy Beam", bonus)); break; case WheelGemSupremeModifier_t::Druid_AvatarOfNature_Cooldown: - bonus.decrease.cooldown = 300 * 1000; + bonus.decrease.cooldown = 900 * 1000; wheelBonus.momentum += grade < 3 ? 0.33 * grade : 1; m_strategies.emplace_back(std::make_unique(m_wheel, "Avatar of Nature", bonus)); break; @@ -509,51 +509,51 @@ void WheelModifierContext::addStrategies(WheelGemSupremeModifier_t modifier, uin m_strategies.emplace_back(std::make_unique(m_wheel, "Nature's Embrace", bonus)); break; case WheelGemSupremeModifier_t::Druid_TerraBurst_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 7 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Terra Burst", bonus)); break; case WheelGemSupremeModifier_t::Druid_TerraBurst_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Terra Burst", bonus)); break; case WheelGemSupremeModifier_t::Druid_IceBurst_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 7 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Ice Burst", bonus)); break; case WheelGemSupremeModifier_t::Druid_IceBurst_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Ice Burst", bonus)); break; case WheelGemSupremeModifier_t::Druid_EternalWinter_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Eternal Winter", bonus)); break; case WheelGemSupremeModifier_t::Druid_EternalWinter_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Eternal Winter", bonus)); break; case WheelGemSupremeModifier_t::Druid_TerraWave_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Terra Wave", bonus)); break; case WheelGemSupremeModifier_t::Druid_TerraWave_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 12 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Terra Wave", bonus)); break; case WheelGemSupremeModifier_t::Druid_StrongIceWave_DamageIncrease: - bonus.increase.damage = 25 * gradeMultiplier; + bonus.increase.damage = 8 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Strong Ice Wave", bonus)); break; case WheelGemSupremeModifier_t::Druid_StrongIceWave_CriticalExtraDamage: - bonus.increase.criticalDamage = 8 * gradeMultiplier; + bonus.increase.criticalDamage = 15 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Strong Ice Wave", bonus)); break; case WheelGemSupremeModifier_t::Druid_HealFriend_HealingIncrease: - bonus.increase.heal = 10 * gradeMultiplier; + bonus.increase.heal = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Heal Friend", bonus)); break; case WheelGemSupremeModifier_t::Druid_MassHealing_HealingIncrease: - bonus.increase.heal = 10 * gradeMultiplier; + bonus.increase.heal = 5 * gradeMultiplier; m_strategies.emplace_back(std::make_unique(m_wheel, "Mass Healing", bonus)); break; default: diff --git a/src/enums/player_blessings.hpp b/src/enums/player_blessings.hpp index 086f04a6442..f71396f71b3 100644 --- a/src/enums/player_blessings.hpp +++ b/src/enums/player_blessings.hpp @@ -20,6 +20,6 @@ enum class Blessings : uint8_t { TheFireOfTheSuns = 4, TheSpiritualShielding = 5, TheEmbraceOfTibia = 6, - BloodOfTheMountain = 7, - HearthOfTheMountain = 8 + HearthOfTheMountain = 7, + BloodOfTheMountain = 8 }; diff --git a/src/game/functions/game_reload.cpp b/src/game/functions/game_reload.cpp index 10f20595042..5de3e98b0b0 100644 --- a/src/game/functions/game_reload.cpp +++ b/src/game/functions/game_reload.cpp @@ -22,6 +22,7 @@ #include "lua/modules/modules.hpp" #include "lua/scripts/lua_environment.hpp" #include "lua/scripts/scripts.hpp" +#include "creatures/players/vocations/vocation.hpp" GameReload::GameReload() = default; GameReload::~GameReload() = default; diff --git a/src/game/game.cpp b/src/game/game.cpp index 49f8bf21d98..e69654a47ad 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -62,6 +62,7 @@ #include "server/server.hpp" #include "utils/tools.hpp" #include "utils/wildcardtree.hpp" +#include "creatures/players/vocations/vocation.hpp" #include "enums/account_coins.hpp" #include "enums/account_errors.hpp" @@ -1160,7 +1161,7 @@ bool Game::internalPlaceCreature(const std::shared_ptr &creature, cons } bool Game::placeCreature(const std::shared_ptr &creature, const Position &pos, bool extendedPos /*=false*/, bool forced /*= false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!internalPlaceCreature(creature, pos, extendedPos, forced)) { return false; } @@ -1187,7 +1188,7 @@ bool Game::placeCreature(const std::shared_ptr &creature, const Positi } bool Game::removeCreature(const std::shared_ptr &creature, bool isLogout /* = true*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (!creature || creature->isRemoved()) { return false; } @@ -1255,7 +1256,7 @@ bool Game::removeCreature(const std::shared_ptr &creature, bool isLogo } void Game::executeDeath(uint32_t creatureId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); std::shared_ptr creature = getCreatureByID(creatureId); if (creature && !creature->isRemoved()) { afterCreatureZoneChange(creature, creature->getZones(), {}); @@ -1264,7 +1265,7 @@ void Game::executeDeath(uint32_t creatureId) { } void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player || !player->hasFlag(PlayerFlags_t::CanMapClickTeleport)) { return; @@ -1277,7 +1278,7 @@ void Game::playerTeleport(uint32_t playerId, const Position &newPosition) { } void Game::playerInspectItem(const std::shared_ptr &player, const Position &pos) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const std::shared_ptr &thing = internalGetThing(player, pos, 0, 0, STACKPOS_TOPDOWN_ITEM); if (!thing) { player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE); @@ -1294,7 +1295,7 @@ void Game::playerInspectItem(const std::shared_ptr &player, const Positi } void Game::playerInspectItem(const std::shared_ptr &player, uint16_t itemId, uint8_t itemCount, bool cyclopedia) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); player->sendItemInspection(itemId, itemCount, nullptr, cyclopedia); } @@ -1348,7 +1349,7 @@ FILELOADER_ERRORS Game::loadAppearanceProtobuf(const std::string &file) { } void Game::playerMoveThing(uint32_t playerId, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -1418,7 +1419,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, return; } - std::shared_ptr movingCreature = getCreatureByID(movingCreatureId); + const auto &movingCreature = getCreatureByID(movingCreatureId); if (!movingCreature) { return; } @@ -1433,7 +1434,7 @@ void Game::playerMoveCreatureByID(uint32_t playerId, uint32_t movingCreatureId, } void Game::playerMoveCreature(const std::shared_ptr &player, const std::shared_ptr &movingCreature, const Position &movingCreatureOrigPos, const std::shared_ptr &toTile) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); g_dispatcher().addWalkEvent([=, this] { if (!player->canDoAction()) { @@ -1589,7 +1590,7 @@ ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature } ReturnValue Game::internalMoveCreature(const std::shared_ptr &creature, const std::shared_ptr &toTile, uint32_t flags /*= 0*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature->hasCondition(CONDITION_ROOTED)) { return RETURNVALUE_NOTPOSSIBLE; } @@ -1666,7 +1667,7 @@ void Game::playerMoveItemByPlayerID(uint32_t playerId, const Position &fromPos, void Game::playerMoveItem(const std::shared_ptr &player, const Position &fromPos, uint16_t itemId, uint8_t fromStackPos, const Position &toPos, uint8_t count, std::shared_ptr item, std::shared_ptr toCylinder) { if (!player->canDoAction()) { - uint32_t delay = player->getNextActionTime(); + const uint32_t delay = player->getNextActionTime(); const auto &task = createPlayerTask( delay, [this, playerId = player->getID(), fromPos, itemId, fromStackPos, toPos, count] { @@ -1741,7 +1742,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } // check if we can move this item - if (ReturnValue ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item, toPos); ret != RETURNVALUE_NOERROR) { + if (auto ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item, toPos); ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return; } @@ -1773,8 +1774,8 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position return; } - std::shared_ptr toCylinderTile = toCylinder->getTile(); - const Position &mapToPos = toCylinderTile->getPosition(); + const auto toCylinderTile = toCylinder->getTile(); + const auto &mapToPos = toCylinderTile->getPosition(); // hangable item specific code if (item->isHangable() && toCylinderTile->hasFlag(TILESTATE_SUPPORTS_HANGABLE)) { @@ -1793,14 +1794,14 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } if (!Position::areInRange<1, 1, 0>(playerPos, mapToPos)) { - Position walkPos = mapToPos; + auto walkPos = mapToPos; if (vertical) { walkPos.x++; } else { walkPos.y++; } - Position itemPos = fromPos; + auto itemPos = fromPos; uint8_t itemStackPos = fromStackPos; if (fromPos.x != 0xFFFF && Position::areInRange<1, 1>(mapFromPos, playerPos) @@ -1808,7 +1809,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position // need to pickup the item first std::shared_ptr moveItem = nullptr; - ReturnValue ret = internalMoveItem(fromCylinder, player, INDEX_WHEREEVER, item, count, &moveItem); + const auto ret = internalMoveItem(fromCylinder, player, INDEX_WHEREEVER, item, count, &moveItem); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); return; @@ -1836,7 +1837,7 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } } - auto throwRange = item->getThrowRange(); + const auto throwRange = item->getThrowRange(); if ((Position::getDistanceX(playerPos, mapToPos) > throwRange) || (Position::getDistanceY(playerPos, mapToPos) > throwRange) || (Position::getDistanceZ(mapFromPos, mapToPos) * 4 > throwRange)) { player->sendCancelMessage(RETURNVALUE_DESTINATIONOUTOFREACH); return; @@ -1865,8 +1866,8 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position } if (item->isWrapable() || item->isStoreItem() || (item->hasOwner() && !item->isOwner(player))) { - auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast(); - auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast(); + const auto toHouseTile = map.getTile(mapToPos)->dynamic_self_cast(); + const auto fromHouseTile = map.getTile(mapFromPos)->dynamic_self_cast(); if (fromHouseTile && (!toHouseTile || toHouseTile->getHouse()->getId() != fromHouseTile->getHouse()->getId())) { player->sendCancelMessage("You cannot move this item out of this house."); return; @@ -1881,12 +1882,14 @@ void Game::playerMoveItem(const std::shared_ptr &player, const Position player->sendCancelMessage(RETURNVALUE_NOTMOVABLE); return; } - ReturnValue ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player); + + const auto ret = internalMoveItem(fromCylinder, toCylinder, toIndex, item, count, nullptr, 0, player); if (ret != RETURNVALUE_NOERROR) { player->sendCancelMessage(ret); } else if (toCylinder->getContainer() && fromCylinder->getContainer() && fromCylinder->getContainer()->countsToLootAnalyzerBalance() && toCylinder->getContainer()->getTopParent() == player) { player->sendLootStats(item, count); } + player->cancelPush(); item->checkDecayMapItemOnMove(); @@ -1915,7 +1918,9 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, } } - if (containerID == ITEM_GOLD_POUCH) { + const auto containerToStow = isTryingToStow(toPos, toCylinder); + + if (containerID == ITEM_GOLD_POUCH && !containerToStow) { if (g_configManager().getBoolean(TOGGLE_GOLD_POUCH_QUICKLOOT_ONLY)) { return RETURNVALUE_CONTAINERNOTENOUGHROOM; } @@ -1941,7 +1946,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, return RETURNVALUE_NOTBOUGHTINSTORE; } - if (item->isStoreItem()) { + if (item->isStoreItem() && !containerToStow) { bool isValidMoveItem = false; auto fromHouseTile = fromCylinder->getTile(); auto house = fromHouseTile ? fromHouseTile->getHouse() : nullptr; @@ -1972,7 +1977,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, if (item->getContainer() && !item->isStoreItem()) { for (const std::shared_ptr &containerItem : item->getContainer()->getItems(true)) { - if (containerItem->isStoreItem() && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { + if (containerItem->isStoreItem() && !containerToStow && ((containerID != ITEM_GOLD_POUCH && containerID != ITEM_DEPOT && containerID != ITEM_STORE_INBOX) || (topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && (!topParentContainer->getParent()->getContainer()->isDepotChest() || topParentContainer->getParent()->getContainer()->getID() != ITEM_STORE_INBOX)))) { return RETURNVALUE_NOTPOSSIBLE; } } @@ -2004,7 +2009,7 @@ ReturnValue Game::checkMoveItemToCylinder(const std::shared_ptr &player, } ReturnValue Game::internalMoveItem(std::shared_ptr fromCylinder, std::shared_ptr toCylinder, int32_t index, const std::shared_ptr &item, uint32_t count, std::shared_ptr* movedItem, uint32_t flags /*= 0*/, const std::shared_ptr &actor /*=nullptr*/, const std::shared_ptr &tradeItem /* = nullptr*/, bool checkTile /* = true*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (fromCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2266,7 +2271,7 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const st } ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const std::shared_ptr &item, int32_t index, uint32_t flags, bool test, uint32_t &remainderCount) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (toCylinder == nullptr) { g_logger().error("[{}] fromCylinder is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2354,7 +2359,7 @@ ReturnValue Game::internalAddItem(std::shared_ptr toCylinder, const st ReturnValue Game::internalRemoveItem(const std::shared_ptr &items, int32_t count /*= -1*/, bool test /*= false*/, uint32_t flags /*= 0*/, bool force /*= false*/) { auto item = items; - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (item == nullptr) { g_logger().debug("{} - Item is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2434,7 +2439,7 @@ std::tuple Game::addItemBatch(const std::shared return std::make_tuple(ret, totalAdded, containersCreated); } - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = toCylinder->getPlayer(); bool dropping = false; auto setupDestination = [&]() -> std::shared_ptr { @@ -2514,7 +2519,7 @@ std::tuple Game::addItemBatch(const std::shared } std::tuple Game::createItemBatch(const std::shared_ptr &toCylinder, const std::vector> &itemCounts, uint32_t flags /* = 0 */, bool dropOnMap /* = true */, uint32_t autoContainerId /* = 0 */) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); std::vector> items; for (const auto &[itemId, count, subType] : itemCounts) { const auto &itemType = Item::items[itemId]; @@ -2548,7 +2553,7 @@ std::tuple Game::createItem(const std::shared_p } ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, const std::shared_ptr &item, bool dropOnMap /*= true*/, Slots_t slot /*= CONST_SLOT_WHEREEVER*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); uint32_t remainderCount = 0; ReturnValue ret; if (slot == CONST_SLOT_WHEREEVER) { @@ -2580,7 +2585,7 @@ ReturnValue Game::internalPlayerAddItem(const std::shared_ptr &player, c } std::shared_ptr Game::findItemOfType(const std::shared_ptr &cylinder, uint16_t itemId, bool depthSearch /*= true*/, int32_t subType /*= -1*/) const { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (cylinder == nullptr) { g_logger().error("[{}] Cylinder is nullptr", __FUNCTION__); return nullptr; @@ -2746,7 +2751,7 @@ void Game::addMoney(const std::shared_ptr &cylinder, uint64_t money, u } std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t newId, int32_t newCount /*= -1*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (item->getID() == newId && (newCount == -1 || (newCount == item->getSubType() && newCount != 0))) { // chargeless item placed on map = infinite return item; } @@ -2884,7 +2889,7 @@ std::shared_ptr Game::transformItem(std::shared_ptr item, uint16_t n } ReturnValue Game::internalTeleport(const std::shared_ptr &thing, const Position &newPos, bool pushMove /* = true*/, uint32_t flags /*= 0*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (thing == nullptr) { g_logger().error("[{}] thing is nullptr", __FUNCTION__); return RETURNVALUE_NOTPOSSIBLE; @@ -2907,9 +2912,7 @@ ReturnValue Game::internalTeleport(const std::shared_ptr &thing, const Po return ret; } - g_dispatcher().addWalkEvent([=] { - g_game().map.moveCreature(creature, toTile, !pushMove); - }); + map.moveCreature(creature, toTile, !pushMove); return RETURNVALUE_NOERROR; } else if (const auto &item = thing->getItem()) { @@ -3406,18 +3409,22 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = const auto &slotItem = player->getInventoryItem(slot); const auto &equipItem = searchForItem(backpack, it.id, hasTier, tier); ReturnValue ret = RETURNVALUE_NOERROR; + if (slotItem && slotItem->getID() == it.id && (!it.stackable || slotItem->getItemCount() == slotItem->getStackSize() || !equipItem)) { ret = internalMoveItem(slotItem->getParent(), player, CONST_SLOT_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr); g_logger().debug("Item {} was unequipped", slotItem->getName()); } else if (equipItem) { // Shield slot item const auto &rightItem = player->getInventoryItem(CONST_SLOT_RIGHT); + // Check Ammo item if (it.weaponType == WEAPON_AMMO) { if (rightItem && rightItem->isQuiver()) { ret = internalMoveItem(equipItem->getParent(), rightItem->getContainer(), 0, equipItem, equipItem->getItemCount(), nullptr); } } else { + const auto &leftItem = player->getInventoryItem(CONST_SLOT_LEFT); + const int32_t &slotPosition = equipItem->getSlotPosition(); // Checks if a two-handed item is being equipped in the left slot when the right slot is already occupied and move to backpack if ( @@ -3426,10 +3433,35 @@ void Game::playerEquipItem(uint32_t playerId, uint16_t itemId, bool hasTier /* = && rightItem && !(it.weaponType == WEAPON_DISTANCE) && !rightItem->isQuiver() + && (!leftItem || leftItem->getWeaponType() != WEAPON_DISTANCE) ) { ret = internalCollectManagedItems(player, rightItem, getObjectCategory(rightItem), false); } + // Check if trying to equip a quiver while another quiver is already equipped in the right slot + if (slot == CONST_SLOT_RIGHT && rightItem && rightItem->isQuiver() && it.isQuiver()) { + // Replace the existing quiver with the new one + ret = internalMoveItem(rightItem->getParent(), player, INDEX_WHEREEVER, rightItem, rightItem->getItemCount(), nullptr); + if (ret == RETURNVALUE_NOERROR) { + g_logger().debug("Quiver {} was unequipped to equip new quiver", rightItem->getName()); + } else { + player->sendCancelMessage(ret); + return; + } + } else { + // Check if trying to equip a shield while a two-handed weapon is equipped in the left slot + if (slot == CONST_SLOT_RIGHT && leftItem && leftItem->getSlotPosition() & SLOTP_TWO_HAND) { + // Unequip the two-handed weapon from the left slot + ret = internalMoveItem(leftItem->getParent(), player, INDEX_WHEREEVER, leftItem, leftItem->getItemCount(), nullptr); + if (ret == RETURNVALUE_NOERROR) { + g_logger().debug("Two-handed weapon {} was unequipped to equip shield", leftItem->getName()); + } else { + player->sendCancelMessage(ret); + return; + } + } + } + if (slotItem) { ret = internalMoveItem(slotItem->getParent(), player, INDEX_WHEREEVER, slotItem, slotItem->getItemCount(), nullptr); g_logger().debug("Item {} was moved back to player", slotItem->getName()); @@ -3673,7 +3705,7 @@ void Game::playerStopAutoWalk(uint32_t playerId) { } void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint16_t fromItemId, const Position &toPos, uint8_t toStackPos, uint16_t toItemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -3818,7 +3850,7 @@ void Game::playerUseItemEx(uint32_t playerId, const Position &fromPos, uint8_t f } void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPos, uint8_t index, uint16_t itemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -3928,7 +3960,7 @@ void Game::playerUseItem(uint32_t playerId, const Position &pos, uint8_t stackPo } void Game::playerUseWithCreature(uint32_t playerId, const Position &fromPos, uint8_t fromStackPos, uint32_t creatureId, uint16_t itemId) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -5282,7 +5314,7 @@ void Game::internalCloseTrade(const std::shared_ptr &player) { } void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint16_t amount, bool ignoreCap /* = false*/, bool inBackpacks /* = false*/) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (amount == 0) { return; } @@ -5338,7 +5370,7 @@ void Game::playerBuyItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint } void Game::playerSellItem(uint32_t playerId, uint16_t itemId, uint8_t count, uint16_t amount, bool ignoreEquipped) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (amount == 0) { return; } @@ -5452,7 +5484,7 @@ void Game::playerLookInBattleList(uint32_t playerId, uint32_t creatureId) { return; } - std::shared_ptr creature = getCreatureByID(creatureId); + const auto &creature = getCreatureByID(creatureId); if (!creature) { return; } @@ -5864,7 +5896,7 @@ void Game::playerSetAttackedCreature(uint32_t playerId, uint32_t creatureId) { return; } - std::shared_ptr attackCreature = getCreatureByID(creatureId); + const auto &attackCreature = getCreatureByID(creatureId); if (!attackCreature) { player->setAttackedCreature(nullptr); player->sendCancelTarget(); @@ -6397,10 +6429,6 @@ bool Game::internalCreatureSay(const std::shared_ptr &creature, SpeakC // event method for (const auto &spectator : spectators) { spectator->onCreatureSay(creature, type, text); - if (creature != spectator) { - g_events().eventCreatureOnHear(spectator, creature, text, type); - g_callbacks().executeCallback(EventCallback_t::creatureOnHear, &EventCallback::creatureOnHear, spectator, creature, text, type); - } } return true; } @@ -6440,24 +6468,23 @@ void Game::addCreatureCheck(const std::shared_ptr &creature) { creature->inCheckCreaturesVector.store(true); - g_dispatcher().context().tryAddEvent([creature] { + creature->safeCall([this, creature] { checkCreatureLists[uniform_random(0, EVENT_CREATURECOUNT - 1)].emplace_back(creature); - }, - "addCreatureCheck"); + }); } void Game::removeCreatureCheck(const std::shared_ptr &creature) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); if (creature->inCheckCreaturesVector.load()) { creature->creatureCheck.store(false); } } void Game::checkCreatures() { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); static size_t index = 0; - std::erase_if(checkCreatureLists[index], [this](const std::shared_ptr &creature) { + std::erase_if(checkCreatureLists[index], [this](const std::shared_ptr creature) { if (creature->creatureCheck && creature->isAlive()) { creature->onThink(EVENT_CREATURE_THINK_INTERVAL); creature->onAttacking(EVENT_CREATURE_THINK_INTERVAL); @@ -7008,7 +7035,7 @@ void Game::applyWheelOfDestinyEffectsToDamage(CombatDamage &damage, const std::s if (damage.secondary.value != 0) { damage.secondary.value -= attackerPlayer->wheel()->getStat(WheelStat_t::DAMAGE); } - if (damage.instantSpellName == "Twin Burst") { + if (damage.instantSpellName == "Ice Burst" || damage.instantSpellName == "Terra Burst") { int32_t damageBonus = attackerPlayer->wheel()->checkTwinBurstByTarget(target); if (damageBonus != 0) { damage.primary.value += (damage.primary.value * damageBonus) / 100.; @@ -7430,13 +7457,8 @@ bool Game::combatChangeHealth(const std::shared_ptr &attacker, const s target->drainHealth(attacker, realDamage); if (realDamage > 0 && targetMonster) { - if (attackerPlayer && attackerPlayer->getPlayer()) { - attackerPlayer->updateImpactTracker(damage.secondary.type, damage.secondary.value); - } - if (targetMonster->israndomStepping()) { targetMonster->setIgnoreFieldDamage(true); - targetMonster->updateMapCache(); } } @@ -8250,8 +8272,8 @@ void Game::checkPlayersRecord() { uint32_t previousRecord = playersRecord; playersRecord = playersOnline; - for (auto &[key, it] : g_globalEvents().getEventMap(GLOBALEVENT_RECORD)) { - it->executeRecord(playersRecord, previousRecord); + for (const auto &[key, globalEvent] : g_globalEvents().getEventMap(GLOBALEVENT_RECORD)) { + globalEvent->executeRecord(playersRecord, previousRecord); } updatePlayersRecord(); } @@ -9003,7 +9025,7 @@ void Game::playerCreateMarketOffer(uint32_t playerId, uint8_t type, uint16_t ite return; } - std::shared_ptr depotLocker = player->getDepotLocker(player->getLastDepotId()); + const std::shared_ptr &depotLocker = player->getDepotLocker(player->getLastDepotId()); if (depotLocker == nullptr) { offerStatus << "Depot locker is nullptr for player " << player->getName(); return; @@ -9086,6 +9108,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } + const auto &playerInbox = player->getInbox(); if (offer.type == MARKETACTION_BUY) { player->setBankBalance(player->getBankBalance() + offer.price * offer.amount); g_metrics().addCounter("balance_decrease", offer.price * offer.amount, { { "player", player->getName() }, { "context", "market_purchase" } }); @@ -9102,10 +9125,11 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 player->getAccount()->addCoins(CoinType::Transferable, offer.amount, ""); } else if (it.stackable) { uint16_t tmpAmount = offer.amount; + while (tmpAmount > 0) { int32_t stackCount = std::min(it.stackSize, tmpAmount); const auto &item = Item::CreateItem(it.id, stackCount); - if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { break; } @@ -9125,7 +9149,7 @@ void Game::playerCancelMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 for (uint16_t i = 0; i < offer.amount; ++i) { const auto &item = Item::CreateItem(it.id, subType); - if (internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { break; } @@ -9183,35 +9207,41 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } + const auto &playerInbox = player->getInbox(); + uint64_t totalPrice = offer.price * amount; // The player has an offer to by something and someone is going to sell to item type // so the market action is 'buy' as who created the offer is buying. if (offer.type == MARKETACTION_BUY) { - std::shared_ptr depotLocker = player->getDepotLocker(player->getLastDepotId()); + const std::shared_ptr &depotLocker = player->getDepotLocker(player->getLastDepotId()); if (depotLocker == nullptr) { offerStatus << "Depot locker is nullptr"; return; } - std::shared_ptr buyerPlayer = getPlayerByGUID(offer.playerId, true); + const std::shared_ptr &buyerPlayer = getPlayerByGUID(offer.playerId, true); if (!buyerPlayer) { offerStatus << "Failed to load buyer player " << player->getName(); return; } - if (!buyerPlayer->getAccount()) { + const auto &buyerPlayerAccount = buyerPlayer->getAccount(); + if (!buyerPlayerAccount) { player->sendTextMessage(MESSAGE_MARKET, "Cannot accept offer."); return; } - if (player == buyerPlayer || player->getAccount() == buyerPlayer->getAccount()) { + const auto &playerAccount = player->getAccount(); + if (player == buyerPlayer || playerAccount == buyerPlayerAccount) { player->sendTextMessage(MESSAGE_MARKET, "You cannot accept your own offer."); return; } + const auto &buyerPlayerInbox = buyerPlayer->getInbox(); + if (it.id == ITEM_STORE_COIN) { - auto [transferableCoins, error] = player->getAccount()->getCoins(CoinType::Transferable); + auto [transferableCoins, error] = playerAccount->getCoins(CoinType::Transferable); if (error != AccountErrors_t::Ok) { offerStatus << "Failed to load transferable coins for player " << player->getName(); @@ -9223,7 +9253,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 return; } - player->getAccount()->removeCoins( + playerAccount->removeCoins( CoinType::Transferable, amount, "Sold on Market" @@ -9258,7 +9288,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 while (tmpAmount > 0) { uint16_t stackCount = std::min(it.stackSize, tmpAmount); const auto &item = Item::CreateItem(it.id, stackCount); - if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (internalAddItem(buyerPlayerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { offerStatus << "Failed to add player inbox stackable item for buy offer for player " << player->getName(); break; @@ -9280,7 +9310,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 for (uint16_t i = 0; i < amount; ++i) { const auto &item = Item::CreateItem(it.id, subType); - if (internalAddItem(buyerPlayer->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (internalAddItem(buyerPlayerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { offerStatus << "Failed to add player inbox item for buy offer for player " << player->getName(); break; @@ -9331,7 +9361,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 const auto &item = Item::CreateItem(it.id, stackCount); if ( // Init-statement - auto ret = internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT); + auto ret = internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT); // Condition ret != RETURNVALUE_NOERROR ) { @@ -9359,7 +9389,7 @@ void Game::playerAcceptMarketOffer(uint32_t playerId, uint32_t timestamp, uint16 const auto &item = Item::CreateItem(it.id, subType); if ( // Init-statement - auto ret = internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT); + auto ret = internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT); // Condition ret != RETURNVALUE_NOERROR ) { @@ -9431,7 +9461,7 @@ void Game::parsePlayerExtendedOpcode(uint32_t playerId, uint8_t opcode, const st } void Game::forceRemoveCondition(uint32_t creatureId, ConditionType_t conditionType, ConditionId_t conditionId) { - std::shared_ptr creature = getCreatureByID(creatureId); + const auto &creature = getCreatureByID(creatureId); if (!creature) { return; } @@ -9484,7 +9514,7 @@ void Game::playerAnswerModalWindow(uint32_t playerId, uint32_t modalWindowId, ui } void Game::playerForgeFuseItems(uint32_t playerId, ForgeAction_t actionType, uint16_t firstItemId, uint8_t tier, uint16_t secondItemId, bool usedCore, bool reduceTierLoss, bool convergence) { - metrics::method_latency measure(__METHOD_NAME__); + metrics::method_latency measure(__METRICS_METHOD_NAME__); const auto &player = getPlayerByID(playerId); if (!player) { return; @@ -9841,7 +9871,7 @@ void Game::playerSaveWheel(uint32_t playerId, NetworkMessage &msg) { return; } - if (player->isUIExhausted()) { + if (player->isUIExhausted(1000)) { player->sendCancelMessage(RETURNVALUE_YOUAREEXHAUSTED); return; } diff --git a/src/game/game_definitions.hpp b/src/game/game_definitions.hpp index e122cdf979f..50fa1307764 100644 --- a/src/game/game_definitions.hpp +++ b/src/game/game_definitions.hpp @@ -54,7 +54,7 @@ enum Faction_t { FACTION_LAST = FACTION_FAFNAR, }; -enum LightState_t { +enum LightState_t : uint8_t { LIGHT_STATE_DAY, LIGHT_STATE_NIGHT, LIGHT_STATE_SUNSET, diff --git a/src/game/movement/teleport.cpp b/src/game/movement/teleport.cpp index 935ec443617..d11552220a3 100644 --- a/src/game/movement/teleport.cpp +++ b/src/game/movement/teleport.cpp @@ -80,20 +80,17 @@ void Teleport::addThing(int32_t, const std::shared_ptr &thing) { // Prevent infinity loop if (checkInfinityLoop(destTile)) { const Position &pos = getPosition(); - g_logger().warn("[Teleport:addThing] - " - "Infinity loop teleport at position: {}", - pos.toString()); + g_logger().warn("[Teleport:addThing] - Infinity loop teleport at position: {}", pos.toString()); return; } const MagicEffectClasses effect = Item::items[id].magicEffect; - if (const std::shared_ptr &creature = thing->getCreature()) { + if (const auto &creature = thing->getCreature()) { Position origPos = creature->getPosition(); g_game().internalCreatureTurn(creature, origPos.x > destPos.x ? DIRECTION_WEST : DIRECTION_EAST); - g_dispatcher().addWalkEvent([=] { - g_game().map.moveCreature(creature, destTile); - }); + g_game().map.moveCreature(creature, destTile); + if (effect != CONST_ME_NONE) { g_game().addMagicEffect(origPos, effect); g_game().addMagicEffect(destTile->getPosition(), effect); @@ -103,6 +100,7 @@ void Teleport::addThing(int32_t, const std::shared_ptr &thing) { g_game().addMagicEffect(destTile->getPosition(), effect); g_game().addMagicEffect(item->getPosition(), effect); } + g_game().internalMoveItem(getTile(), destTile, INDEX_WHEREEVER, item, item->getItemCount(), nullptr); } } diff --git a/src/game/scheduling/dispatcher.cpp b/src/game/scheduling/dispatcher.cpp index e716e9867cc..cb27cba23f1 100644 --- a/src/game/scheduling/dispatcher.cpp +++ b/src/game/scheduling/dispatcher.cpp @@ -251,22 +251,6 @@ void Dispatcher::stopEvent(uint64_t eventId) { } } -void DispatcherContext::addEvent(std::function &&f, std::string_view context) const { - g_dispatcher().addEvent(std::move(f), context); -} - -void DispatcherContext::tryAddEvent(std::function &&f, std::string_view context) const { - if (!f) { - return; - } - - if (isAsync()) { - g_dispatcher().addEvent(std::move(f), context); - } else { - f(); - } -} - bool DispatcherContext::isOn() { return OTSYS_TIME() != 0; } diff --git a/src/game/scheduling/dispatcher.hpp b/src/game/scheduling/dispatcher.hpp index 5e84d5d5fc7..d2c6819593c 100644 --- a/src/game/scheduling/dispatcher.hpp +++ b/src/game/scheduling/dispatcher.hpp @@ -55,12 +55,6 @@ struct DispatcherContext { return type; } - // postpone the event - void addEvent(std::function &&f, std::string_view context) const; - - // if the context is async, the event will be postponed, if not, it will be executed immediately. - void tryAddEvent(std::function &&f, std::string_view context) const; - private: void reset() { group = TaskGroup::ThreadPool; diff --git a/src/game/scheduling/save_manager.cpp b/src/game/scheduling/save_manager.cpp index 9cccc4052a7..45cd9392194 100644 --- a/src/game/scheduling/save_manager.cpp +++ b/src/game/scheduling/save_manager.cpp @@ -16,6 +16,7 @@ #include "io/iologindata.hpp" #include "kv/kv.hpp" #include "lib/di/container.hpp" +#include "creatures/players/player.hpp" SaveManager::SaveManager(ThreadPool &threadPool, KVStore &kvStore, Logger &logger, Game &game) : threadPool(threadPool), kv(kvStore), logger(logger), game(game) { } diff --git a/src/game/scheduling/task.cpp b/src/game/scheduling/task.cpp index b3a79f7ab18..1edd246a702 100644 --- a/src/game/scheduling/task.cpp +++ b/src/game/scheduling/task.cpp @@ -15,22 +15,22 @@ std::atomic_uint_fast64_t Task::LAST_EVENT_ID = 0; -Task::Task(uint32_t expiresAfterMs, std::function &&f, std::string_view context, const std::source_location &location) : - func(std::move(f)), context(context), functionName(location.function_name()), utime(OTSYS_TIME()), +Task::Task(uint32_t expiresAfterMs, std::function &&f, std::string_view context) : + func(std::move(f)), context(context), utime(OTSYS_TIME()), expiration(expiresAfterMs > 0 ? OTSYS_TIME() + expiresAfterMs : 0) { if (this->context.empty()) { - g_logger().error("[{}]: task context cannot be empty! Function: {}", __FUNCTION__, functionName); + g_logger().error("[{}]: task context cannot be empty!", __FUNCTION__); return; } assert(!this->context.empty() && "Context cannot be empty!"); } -Task::Task(std::function &&f, std::string_view context, uint32_t delay, bool cycle /* = false*/, bool log /*= true*/, const std::source_location &location) : - func(std::move(f)), context(context), functionName(location.function_name()), utime(OTSYS_TIME() + delay), delay(delay), +Task::Task(std::function &&f, std::string_view context, uint32_t delay, bool cycle /* = false*/, bool log /*= true*/) : + func(std::move(f)), context(context), utime(OTSYS_TIME() + delay), delay(delay), cycle(cycle), log(log) { if (this->context.empty()) { - g_logger().error("[{}]: task context cannot be empty! Function: {}", __FUNCTION__, functionName); + g_logger().error("[{}]: task context cannot be empty!", __FUNCTION__); return; } @@ -48,15 +48,15 @@ bool Task::execute() const { } if (hasExpired()) { - g_logger().info("The task '{}' has expired, it has not been executed in {}. Function: {}", getContext(), expiration - utime, functionName); + g_logger().info("The task '{}' has expired, it has not been executed in {}.", getContext(), expiration - utime); return false; } if (log) { if (hasTraceableContext()) { - g_logger().trace("Executing task {}. Function: {}", getContext(), functionName); + g_logger().trace("Executing task {}.", getContext()); } else { - g_logger().debug("Executing task {}. Function: {}", getContext(), functionName); + g_logger().debug("Executing task {}.", getContext()); } } diff --git a/src/game/scheduling/task.hpp b/src/game/scheduling/task.hpp index 948bdea0215..c01dbe2f676 100644 --- a/src/game/scheduling/task.hpp +++ b/src/game/scheduling/task.hpp @@ -13,9 +13,9 @@ class Dispatcher; class Task { public: - Task(uint32_t expiresAfterMs, std::function &&f, std::string_view context, const std::source_location &location = std::source_location::current()); + Task(uint32_t expiresAfterMs, std::function &&f, std::string_view context); - Task(std::function &&f, std::string_view context, uint32_t delay, bool cycle = false, bool log = true, const std::source_location &location = std::source_location::current()); + Task(std::function &&f, std::string_view context, uint32_t delay, bool cycle = false, bool log = true); ~Task() = default; @@ -37,10 +37,6 @@ class Task { return context; } - [[nodiscard]] std::string_view getFunctionName() const { - return functionName; - } - [[nodiscard]] auto getTime() const { return utime; } @@ -106,7 +102,6 @@ class Task { std::function func; std::string context; - std::string functionName; int64_t utime = 0; int64_t expiration = 0; diff --git a/src/io/functions/iologindata_load_player.cpp b/src/io/functions/iologindata_load_player.cpp index 477572dfbc8..e724d0ceda9 100644 --- a/src/io/functions/iologindata_load_player.cpp +++ b/src/io/functions/iologindata_load_player.cpp @@ -9,8 +9,10 @@ #include "io/functions/iologindata_load_player.hpp" +#include "account/account.hpp" #include "config/configmanager.hpp" #include "creatures/combat/condition.hpp" +#include "database/database.hpp" #include "creatures/monsters/monsters.hpp" #include "creatures/players/achievement/player_achievement.hpp" #include "creatures/players/cyclopedia/player_badge.hpp" @@ -29,6 +31,7 @@ #include "items/containers/inbox/inbox.hpp" #include "items/containers/rewards/reward.hpp" #include "items/containers/rewards/rewardchest.hpp" +#include "creatures/players/player.hpp" #include "utils/tools.hpp" void IOLoginDataLoad::loadItems(ItemsMap &itemsMap, const DBResult_ptr &result, const std::shared_ptr &player) { @@ -676,8 +679,14 @@ void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr &player ItemsMap inboxItems; loadItems(inboxItems, result, player); - for (auto it = inboxItems.rbegin(), end = inboxItems.rend(); it != end; ++it) { - const std::pair, int32_t> &pair = it->second; + const auto &playerInbox = player->getInbox(); + if (!playerInbox) { + g_logger().warn("[{}] - Player inbox nullptr", __FUNCTION__); + return; + } + + for (const auto &it : std::ranges::reverse_view(inboxItems)) { + const std::pair, int32_t> &pair = it.second; const auto &item = pair.first; if (!item) { continue; @@ -685,7 +694,7 @@ void IOLoginDataLoad::loadPlayerInboxItems(const std::shared_ptr &player int32_t pid = pair.second; if (pid >= 0 && pid < 100) { - player->getInbox()->internalAddThing(item); + playerInbox->internalAddThing(item); item->startDecaying(); } else { auto inboxIt = inboxItems.find(pid); diff --git a/src/io/functions/iologindata_load_player.hpp b/src/io/functions/iologindata_load_player.hpp index 2d1a4305cf3..ca05bdcb1b8 100644 --- a/src/io/functions/iologindata_load_player.hpp +++ b/src/io/functions/iologindata_load_player.hpp @@ -11,6 +11,10 @@ #include "io/iologindata.hpp" +class Player; +class DBResult; +using DBResult_ptr = std::shared_ptr; + class IOLoginDataLoad : public IOLoginData { public: static bool loadPlayerBasicInfo(const std::shared_ptr &player, const DBResult_ptr &result); diff --git a/src/io/functions/iologindata_save_player.cpp b/src/io/functions/iologindata_save_player.cpp index b38e6e2b84c..613fdac1cb0 100644 --- a/src/io/functions/iologindata_save_player.cpp +++ b/src/io/functions/iologindata_save_player.cpp @@ -17,6 +17,7 @@ #include "items/containers/depot/depotchest.hpp" #include "items/containers/inbox/inbox.hpp" #include "items/containers/rewards/reward.hpp" +#include "creatures/players/player.hpp" bool IOLoginDataSave::saveItems(const std::shared_ptr &player, const ItemBlockList &itemList, DBInsert &query_insert, PropWriteStream &propWriteStream) { if (!player) { diff --git a/src/io/functions/iologindata_save_player.hpp b/src/io/functions/iologindata_save_player.hpp index abafc2c186a..1f871a3b5db 100644 --- a/src/io/functions/iologindata_save_player.hpp +++ b/src/io/functions/iologindata_save_player.hpp @@ -12,6 +12,7 @@ #include "io/iologindata.hpp" class PropWriteStream; +class DBInsert; class IOLoginDataSave : public IOLoginData { public: diff --git a/src/io/io_wheel.cpp b/src/io/io_wheel.cpp index 72d5e207d4c..cfcf6593010 100644 --- a/src/io/io_wheel.cpp +++ b/src/io/io_wheel.cpp @@ -58,7 +58,7 @@ namespace InternalPlayerWheel { return; } - auto spell = g_spells().getInstantSpellByName(name); + const auto &spell = g_spells().getInstantSpellByName(name); if (spell) { g_logger().trace("[{}] registering instant spell with name {}", __FUNCTION__, spell->getName()); // Increase data @@ -127,7 +127,7 @@ bool IOWheel::initializeGlobalData(bool reload /* = false*/) { // Register spells for druid for (const auto &data : getWheelBonusData().spells.druid) { for (size_t i = 1; i < 3; ++i) { - const auto grade = data.grade[i]; + const auto &grade = data.grade[i]; InternalPlayerWheel::registerWheelSpellTable(grade, data.name, static_cast(i)); } } @@ -181,7 +181,7 @@ const VocationBonusMap &IOWheel::getWheelMapFunctions() const { std::pair IOWheel::getRevelationStatByStage(WheelStageEnum_t stageType) const { // Let's remove one, because the std::array starts with 0 and the stages with 1 - auto array = m_wheelBonusData.revelation.stats[static_cast(stageType) - 1]; + const auto &array = m_wheelBonusData.revelation.stats[static_cast(stageType) - 1]; return std::make_pair(array.damage, array.healing); } @@ -222,32 +222,32 @@ void IOWheel::initializeMapData() { void IOWheel::initializeDruidSpells() { m_wheelBonusData.spells.druid[0].name = "Strong Ice Wave"; m_wheelBonusData.spells.druid[0].grade[1].leech.mana = 3; - m_wheelBonusData.spells.druid[0].grade[2].increase.damage = 30; + m_wheelBonusData.spells.druid[0].grade[2].increase.damage = 10; m_wheelBonusData.spells.druid[1].name = "Mass Healing"; - m_wheelBonusData.spells.druid[1].grade[1].increase.heal = 10; + m_wheelBonusData.spells.druid[1].grade[1].increase.heal = 4; m_wheelBonusData.spells.druid[1].grade[2].increase.area = true; m_wheelBonusData.spells.druid[2].name = "Nature's Embrace"; - m_wheelBonusData.spells.druid[2].grade[1].increase.heal = 10; + m_wheelBonusData.spells.druid[2].grade[1].increase.heal = 11; m_wheelBonusData.spells.druid[2].grade[2].decrease.cooldown = 10; m_wheelBonusData.spells.druid[3].name = "Terra Wave"; - m_wheelBonusData.spells.druid[3].grade[1].increase.damage = 25; + m_wheelBonusData.spells.druid[3].grade[1].increase.damage = static_cast(std::round(6.5)); m_wheelBonusData.spells.druid[3].grade[2].leech.life = 5; m_wheelBonusData.spells.druid[4].name = "Heal Friend"; m_wheelBonusData.spells.druid[4].grade[1].decrease.manaCost = 10; - m_wheelBonusData.spells.druid[4].grade[2].increase.heal = 10; + m_wheelBonusData.spells.druid[4].grade[2].increase.heal = static_cast(std::round(5.5)); } void IOWheel::initializeKnightSpells() { m_wheelBonusData.spells.knight[0].name = "Front Sweep"; m_wheelBonusData.spells.knight[0].grade[1].leech.life = 5; - m_wheelBonusData.spells.knight[0].grade[2].increase.damage = 30; + m_wheelBonusData.spells.knight[0].grade[2].increase.damage = 14; m_wheelBonusData.spells.knight[1].name = "Groundshaker"; - m_wheelBonusData.spells.knight[1].grade[1].increase.damage = 25; + m_wheelBonusData.spells.knight[1].grade[1].increase.damage = static_cast(std::round(12.5)); m_wheelBonusData.spells.knight[1].grade[2].decrease.cooldown = 2; m_wheelBonusData.spells.knight[2].name = "Chivalrous Challenge"; @@ -255,12 +255,12 @@ void IOWheel::initializeKnightSpells() { m_wheelBonusData.spells.knight[2].grade[2].increase.aditionalTarget = 1; m_wheelBonusData.spells.knight[3].name = "Intense Wound Cleansing"; - m_wheelBonusData.spells.knight[3].grade[1].increase.heal = 10; + m_wheelBonusData.spells.knight[3].grade[1].increase.heal = 125; m_wheelBonusData.spells.knight[3].grade[2].decrease.cooldown = 300; m_wheelBonusData.spells.knight[4].name = "Fierce Berserk"; m_wheelBonusData.spells.knight[4].grade[1].decrease.manaCost = 30; - m_wheelBonusData.spells.knight[4].grade[2].increase.damage = 25; + m_wheelBonusData.spells.knight[4].grade[2].increase.damage = 10; } void IOWheel::initializePaladinSpells() { @@ -270,7 +270,7 @@ void IOWheel::initializePaladinSpells() { m_wheelBonusData.spells.paladin[1].name = "Strong Ethereal Spear"; m_wheelBonusData.spells.paladin[1].grade[1].decrease.cooldown = 2; - m_wheelBonusData.spells.paladin[1].grade[2].increase.damage = 25; + m_wheelBonusData.spells.paladin[1].grade[2].increase.damage = 380; m_wheelBonusData.spells.paladin[2].name = "Divine Dazzle"; m_wheelBonusData.spells.paladin[2].grade[1].increase.aditionalTarget = 1; @@ -283,7 +283,7 @@ void IOWheel::initializePaladinSpells() { m_wheelBonusData.spells.paladin[4].name = "Divine Caldera"; m_wheelBonusData.spells.paladin[4].grade[1].decrease.manaCost = 20; - m_wheelBonusData.spells.paladin[4].grade[2].increase.damage = 25; + m_wheelBonusData.spells.paladin[4].grade[2].increase.damage = static_cast(std::round(8.5)); } void IOWheel::initializeSorcererSpells() { @@ -292,19 +292,19 @@ void IOWheel::initializeSorcererSpells() { m_wheelBonusData.spells.sorcerer[1].name = "Sap Strength"; m_wheelBonusData.spells.sorcerer[1].grade[1].increase.area = true; - m_wheelBonusData.spells.sorcerer[1].grade[2].increase.damageReduction = 10; + m_wheelBonusData.spells.sorcerer[1].grade[2].increase.damageReduction = 1; m_wheelBonusData.spells.sorcerer[2].name = "Energy Wave"; - m_wheelBonusData.spells.sorcerer[2].grade[1].increase.damage = 25; + m_wheelBonusData.spells.sorcerer[2].grade[1].increase.damage = 5; m_wheelBonusData.spells.sorcerer[2].grade[2].increase.area = true; m_wheelBonusData.spells.sorcerer[3].name = "Great Fire Wave"; m_wheelBonusData.spells.sorcerer[3].grade[1].increase.criticalDamage = 15; m_wheelBonusData.spells.sorcerer[3].grade[1].increase.criticalChance = 10; - m_wheelBonusData.spells.sorcerer[3].grade[2].increase.damage = 25; + m_wheelBonusData.spells.sorcerer[3].grade[2].increase.damage = 5; m_wheelBonusData.spells.sorcerer[4].name = "Any_Focus_Mage_Spell"; - m_wheelBonusData.spells.sorcerer[4].grade[1].increase.damage = 25; + m_wheelBonusData.spells.sorcerer[4].grade[1].increase.damage = 5; m_wheelBonusData.spells.sorcerer[4].grade[2].decrease.cooldown = 4; m_wheelBonusData.spells.sorcerer[4].grade[2].decrease.secondaryGroupCooldown = 4; } @@ -399,7 +399,7 @@ void IOWheel::slotGreen200(const std::shared_ptr &player, uint16_t point bonusData.stats.health += 2 * points; bonusData.stats.mana += 3 * points; if (pointsInSlot) { - bonusData.instant.positionalTatics = true; + bonusData.instant.positionalTactics = true; } } else { bonusData.stats.health += 1 * points; diff --git a/src/io/iologindata.cpp b/src/io/iologindata.cpp index 0249d70a517..c0a6a13f363 100644 --- a/src/io/iologindata.cpp +++ b/src/io/iologindata.cpp @@ -9,12 +9,15 @@ #include "io/iologindata.hpp" +#include "account/account.hpp" #include "config/configmanager.hpp" +#include "database/database.hpp" #include "io/functions/iologindata_load_player.hpp" #include "io/functions/iologindata_save_player.hpp" #include "game/game.hpp" #include "creatures/monsters/monster.hpp" #include "creatures/players/wheel/player_wheel.hpp" +#include "creatures/players/player.hpp" #include "lib/metrics/metrics.hpp" #include "enums/account_type.hpp" #include "enums/account_errors.hpp" diff --git a/src/io/iologindata.hpp b/src/io/iologindata.hpp index 29eac0c812f..d379031cd55 100644 --- a/src/io/iologindata.hpp +++ b/src/io/iologindata.hpp @@ -9,9 +9,12 @@ #pragma once -#include "account/account.hpp" -#include "creatures/players/player.hpp" -#include "database/database.hpp" +class Player; +class Item; +class DBResult; + +struct VIPEntry; +struct VIPGroupEntry; using ItemBlockList = std::list>>; @@ -21,7 +24,7 @@ class IOLoginData { static uint8_t getAccountType(uint32_t accountId); static bool loadPlayerById(const std::shared_ptr &player, uint32_t id, bool disableIrrelevantInfo = true); static bool loadPlayerByName(const std::shared_ptr &player, const std::string &name, bool disableIrrelevantInfo = true); - static bool loadPlayer(const std::shared_ptr &player, const DBResult_ptr &result, bool disableIrrelevantInfo = false); + static bool loadPlayer(const std::shared_ptr &player, const std::shared_ptr &result, bool disableIrrelevantInfo = false); static bool savePlayer(const std::shared_ptr &player); static uint32_t getGuidByName(const std::string &name); static bool getGuidByNameEx(uint32_t &guid, bool &specialVip, std::string &name); diff --git a/src/io/iomarket.cpp b/src/io/iomarket.cpp index 3332ffab1c3..fe91b3f6d94 100644 --- a/src/io/iomarket.cpp +++ b/src/io/iomarket.cpp @@ -16,6 +16,7 @@ #include "game/scheduling/save_manager.hpp" #include "io/iologindata.hpp" #include "items/containers/inbox/inbox.hpp" +#include "creatures/players/player.hpp" uint8_t IOMarket::getTierFromDatabaseTable(const std::string &string) { auto tier = static_cast(std::atoi(string.c_str())); @@ -174,12 +175,14 @@ void IOMarket::processExpiredOffers(const DBResult_ptr &result, bool) { continue; } + const auto &playerInbox = player->getInbox(); + if (itemType.stackable) { uint16_t tmpAmount = amount; while (tmpAmount > 0) { uint16_t stackCount = std::min(100, tmpAmount); const auto &item = Item::CreateItem(itemType.id, stackCount); - if (g_game().internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (g_game().internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { g_logger().error("[{}] Ocurred an error to add item with id {} to player {}", __FUNCTION__, itemType.id, player->getName()); break; @@ -201,7 +204,7 @@ void IOMarket::processExpiredOffers(const DBResult_ptr &result, bool) { for (uint16_t i = 0; i < amount; ++i) { const auto &item = Item::CreateItem(itemType.id, subType); - if (g_game().internalAddItem(player->getInbox(), item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { + if (g_game().internalAddItem(playerInbox, item, INDEX_WHEREEVER, FLAG_NOLIMIT) != RETURNVALUE_NOERROR) { break; } diff --git a/src/items/bed.cpp b/src/items/bed.cpp index 25e95318e74..527f052e2d0 100644 --- a/src/items/bed.cpp +++ b/src/items/bed.cpp @@ -16,6 +16,7 @@ #include "game/scheduling/save_manager.hpp" #include "io/iologindata.hpp" #include "server/network/protocol/protocolgame.hpp" +#include "creatures/players/player.hpp" BedItem::BedItem(uint16_t id) : Item(id) { diff --git a/src/items/containers/container.cpp b/src/items/containers/container.cpp index 70ad1cbabbf..77a37942e37 100644 --- a/src/items/containers/container.cpp +++ b/src/items/containers/container.cpp @@ -78,9 +78,9 @@ std::shared_ptr Container::createBrowseField(const std::shared_ptrgetTile(); + const auto &tile = parent->getTile(); if (tile) { auto browseField = g_game().browseFields.find(tile); if (browseField != g_game().browseFields.end()) { @@ -385,7 +385,12 @@ uint32_t Container::getContainerHoldingCount() { bool Container::isHoldingItem(const std::shared_ptr &item) { for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { - if (*it == item) { + const auto &compareItem = *it; + if (!compareItem || !item) { + continue; + } + + if (compareItem == item) { return true; } } @@ -395,6 +400,10 @@ bool Container::isHoldingItem(const std::shared_ptr &item) { bool Container::isHoldingItemWithId(const uint16_t id) { for (ContainerIterator it = iterator(); it.hasNext(); it.advance()) { const auto &item = *it; + if (!item) { + continue; + } + if (item && item->getID() == id) { return true; } @@ -1024,9 +1033,9 @@ void ContainerIterator::advance() { return; } - auto currentItem = container->itemlist[top.index]; + const auto ¤tItem = container->itemlist[top.index]; if (currentItem) { - auto subContainer = currentItem->getContainer(); + const auto &subContainer = currentItem->getContainer(); if (subContainer && !subContainer->itemlist.empty()) { size_t newDepth = top.depth + 1; if (newDepth <= maxTraversalDepth) { diff --git a/src/items/containers/mailbox/mailbox.cpp b/src/items/containers/mailbox/mailbox.cpp index 9abe6d0f6a3..27562e92d7e 100644 --- a/src/items/containers/mailbox/mailbox.cpp +++ b/src/items/containers/mailbox/mailbox.cpp @@ -98,7 +98,9 @@ bool Mailbox::sendItem(const std::shared_ptr &item) const { text = item->getAttribute(ItemAttribute_t::TEXT); } if (player && item) { - if (g_game().internalMoveItem(item->getParent(), player->getInbox(), INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { + const auto &playerInbox = player->getInbox(); + const auto &itemParent = item->getParent(); + if (g_game().internalMoveItem(itemParent, playerInbox, INDEX_WHEREEVER, item, item->getItemCount(), nullptr, FLAG_NOLIMIT) == RETURNVALUE_NOERROR) { const auto &newItem = g_game().transformItem(item, item->getID() + 1); if (newItem && newItem->getID() == ITEM_LETTER_STAMPED && !writer.empty()) { newItem->setAttribute(ItemAttribute_t::WRITER, writer); diff --git a/src/items/functions/item/item_parse.cpp b/src/items/functions/item/item_parse.cpp index 761740bfc2d..357e0c03e8b 100644 --- a/src/items/functions/item/item_parse.cpp +++ b/src/items/functions/item/item_parse.cpp @@ -15,6 +15,7 @@ #include "utils/pugicast.hpp" #include "utils/tools.hpp" #include "creatures/combat/combat.hpp" +#include "lua/scripts/scripts.hpp" void ItemParse::initParse(const std::string &stringValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType) { // Parse all item attributes @@ -675,17 +676,11 @@ void ItemParse::parseFieldCombatDamage(const std::shared_ptr &c void ItemParse::parseField(const std::string &stringValue, pugi::xml_node attributeNode, pugi::xml_attribute valueAttribute, ItemType &itemType) { if (stringValue == "field") { CombatType_t combatType = COMBAT_NONE; - std::shared_ptr conditionDamage = nullptr; - // Parse fields conditions (fire/energy/poison/drown/physical) combatType = parseFieldCombatType(valueAttribute); auto [conditionId, conditionType] = parseFieldConditions(valueAttribute); - if (combatType != COMBAT_NONE) { - if (conditionDamage) { - } - - conditionDamage = std::make_shared(conditionId, conditionType); + auto conditionDamage = std::make_shared(conditionId, conditionType); itemType.combatType = combatType; itemType.conditionDamage = conditionDamage; @@ -974,7 +969,7 @@ void ItemParse::parseHouseRelated(std::string_view stringValue, pugi::xml_attrib void ItemParse::createAndRegisterScript(ItemType &itemType, pugi::xml_node attributeNode, MoveEvent_t eventType /*= MOVE_EVENT_NONE*/, WeaponType_t weaponType /*= WEAPON_NONE*/) { std::shared_ptr moveevent; if (eventType != MOVE_EVENT_NONE) { - moveevent = std::make_shared(&g_moveEvents().getScriptInterface()); + moveevent = std::make_shared(); moveevent->setItemId(itemType.id); moveevent->setEventType(eventType); @@ -996,11 +991,11 @@ void ItemParse::createAndRegisterScript(ItemType &itemType, pugi::xml_node attri std::shared_ptr weapon = nullptr; if (weaponType != WEAPON_NONE) { if (weaponType == WEAPON_DISTANCE || weaponType == WEAPON_AMMO || weaponType == WEAPON_MISSILE) { - weapon = std::make_shared(&g_weapons().getScriptInterface()); + weapon = std::make_shared(); } else if (weaponType == WEAPON_WAND) { - weapon = std::make_shared(&g_weapons().getScriptInterface()); + weapon = std::make_shared(); } else { - weapon = std::make_shared(&g_weapons().getScriptInterface()); + weapon = std::make_shared(); } weapon->weaponType = weaponType; diff --git a/src/items/items_definitions.hpp b/src/items/items_definitions.hpp index 19d7f30b942..9b6990c0cb7 100644 --- a/src/items/items_definitions.hpp +++ b/src/items/items_definitions.hpp @@ -140,34 +140,35 @@ enum ItemGroup_t { enum ItemTypes_t { ITEM_TYPE_NONE, - // Odered to make the cast from protobuf::itemCategory to ItemTypes_t easier. + // Ordered to make the cast from protobuf::itemCategory to ItemTypes_t easier. // Do not edit it from Start-End // Start - ITEM_TYPE_ARMOR, - ITEM_TYPE_AMULET, - ITEM_TYPE_BOOTS, - ITEM_TYPE_CONTAINER, - ITEM_TYPE_DECORATION, - ITEM_TYPE_FOOD, - ITEM_TYPE_HELMET, - ITEM_TYPE_LEGS, - ITEM_TYPE_OTHER, - ITEM_TYPE_POTION, - ITEM_TYPE_RING, - ITEM_TYPE_RUNE, - ITEM_TYPE_SHIELD, - ITEM_TYPE_TOOLS, - ITEM_TYPE_VALUABLE, - ITEM_TYPE_AMMO, - ITEM_TYPE_AXE, - ITEM_TYPE_CLUB, - ITEM_TYPE_DISTANCE, - ITEM_TYPE_SWORD, - ITEM_TYPE_WAND, - ITEM_TYPE_PREMIUMSCROLL, - ITEM_TYPE_TIBIACOIN, - ITEM_TYPE_CREATUREPRODUCT, - ITEM_TYPE_QUIVER, + ITEM_TYPE_ARMOR = 1, + ITEM_TYPE_AMULET = 2, + ITEM_TYPE_BOOTS = 3, + ITEM_TYPE_CONTAINER = 4, + ITEM_TYPE_DECORATION = 5, + ITEM_TYPE_FOOD = 6, + ITEM_TYPE_HELMET = 7, + ITEM_TYPE_LEGS = 8, + ITEM_TYPE_OTHER = 9, + ITEM_TYPE_POTION = 10, + ITEM_TYPE_RING = 11, + ITEM_TYPE_RUNE = 12, + ITEM_TYPE_SHIELD = 13, + ITEM_TYPE_TOOLS = 14, + ITEM_TYPE_VALUABLE = 15, + ITEM_TYPE_AMMO = 16, + ITEM_TYPE_AXE = 17, + ITEM_TYPE_CLUB = 18, + ITEM_TYPE_DISTANCE = 19, + ITEM_TYPE_SWORD = 20, + ITEM_TYPE_WAND = 21, + ITEM_TYPE_PREMIUMSCROLL = 22, + ITEM_TYPE_TIBIACOIN = 23, + ITEM_TYPE_CREATUREPRODUCT = 24, + ITEM_TYPE_QUIVER = 25, + ITEM_TYPE_SOULCORES = 26, // End ITEM_TYPE_DEPOT, diff --git a/src/items/tile.cpp b/src/items/tile.cpp index f15e2bd8a94..edd827db0e5 100644 --- a/src/items/tile.cpp +++ b/src/items/tile.cpp @@ -23,6 +23,7 @@ #include "lua/creature/movement.hpp" #include "map/spectators.hpp" #include "utils/tools.hpp" +#include "game/scheduling/dispatcher.hpp" auto real_nullptr_tile = std::make_shared(0xFFFF, 0xFFFF, 0xFF); const std::shared_ptr &Tile::nullptr_tile = real_nullptr_tile; @@ -986,11 +987,13 @@ std::shared_ptr Tile::queryDestination(int32_t &, const std::shared_pt const auto &destThing = destTile->getTopDownItem(); if (destThing) { destItem = destThing->getItem(); - if (thing && thing->getItem()) { - const auto &destCylinder = destThing->getCylinder(); - if (destCylinder && !destCylinder->getContainer()) { - return destThing->getCylinder(); - } + const auto &thingItem = thing ? thing->getItem() : nullptr; + if (!thingItem || thingItem->getMailbox() != destItem->getMailbox()) { + return destTile; + } + const auto &destCylinder = destThing->getCylinder(); + if (destCylinder && !destCylinder->getContainer()) { + return destThing->getCylinder(); } } } @@ -1942,3 +1945,16 @@ void Tile::clearZones() { zones.erase(zone); } } + +void Tile::safeCall(std::function &&action) const { + if (g_dispatcher().context().isAsync()) { + g_dispatcher().addEvent([weak_self = std::weak_ptr(shared_from_this()), action = std::move(action)] { + if (weak_self.lock()) { + action(); + } + }, + g_dispatcher().context().getName()); + } else { + action(); + } +} diff --git a/src/items/tile.hpp b/src/items/tile.hpp index 4137b6e115d..a719f5dcef3 100644 --- a/src/items/tile.hpp +++ b/src/items/tile.hpp @@ -259,6 +259,9 @@ class Tile : public Cylinder, public SharedObject { } } + // This method maintains safety in asynchronous calls, avoiding competition between threads. + void safeCall(std::function &&action) const; + private: void onAddTileItem(const std::shared_ptr &item); void onUpdateTileItem(const std::shared_ptr &oldItem, const ItemType &oldType, const std::shared_ptr &newItem, const ItemType &newType); @@ -285,6 +288,8 @@ class DynamicTile : public Tile { CreatureVector creatures; public: + explicit DynamicTile(const Position &position) : + Tile(position.x, position.y, position.z) { } DynamicTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } @@ -320,6 +325,8 @@ class StaticTile final : public Tile { std::unique_ptr creatures; public: + explicit StaticTile(const Position &position) : + Tile(position.x, position.y, position.z) { } StaticTile(uint16_t x, uint16_t y, uint8_t z) : Tile(x, y, z) { } diff --git a/src/items/weapons/weapons.cpp b/src/items/weapons/weapons.cpp index 81e59f6a739..2ec09945f36 100644 --- a/src/items/weapons/weapons.cpp +++ b/src/items/weapons/weapons.cpp @@ -13,12 +13,19 @@ #include "creatures/combat/combat.hpp" #include "game/game.hpp" #include "lua/creature/events.hpp" - +#include "creatures/players/vocations/vocation.hpp" +#include "lib/di/container.hpp" +#include "lua/scripts/scripts.hpp" #include "lua/global/lua_variant.hpp" +#include "creatures/players/player.hpp" Weapons::Weapons() = default; Weapons::~Weapons() = default; +Weapons &Weapons::getInstance() { + return inject(); +} + WeaponShared_ptr Weapons::getWeapon(const std::shared_ptr &item) const { if (!item) { return nullptr; @@ -77,6 +84,35 @@ int32_t Weapons::getMaxWeaponDamage(uint32_t level, int32_t attackSkill, int32_t } } +Weapon::Weapon() = default; + +LuaScriptInterface* Weapon::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool Weapon::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t Weapon::getScriptId() const { + return m_scriptId; +} + +void Weapon::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool Weapon::isLoadedScriptId() const { + return m_scriptId != 0; +} + void Weapon::configureWeapon(const ItemType &it) { id = it.id; } @@ -203,7 +239,7 @@ void Weapon::internalUseWeapon(const std::shared_ptr &player, const std: } } - if (isLoadedCallback()) { + if (isLoadedScriptId()) { if (cleavePercent != 0) { return; } @@ -259,7 +295,7 @@ void Weapon::internalUseWeapon(const std::shared_ptr &player, const std: } void Weapon::internalUseWeapon(const std::shared_ptr &player, const std::shared_ptr &item, const std::shared_ptr &tile) const { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { LuaVariant var; var.type = VARIANT_TARGETPOSITION; var.pos = tile->getPosition(); @@ -424,8 +460,31 @@ bool Weapon::calculateSkillFormula(const std::shared_ptr &player, int32_ return shouldCalculateSecondaryDamage; } -WeaponMelee::WeaponMelee(LuaScriptInterface* interface) : - Weapon(interface) { +void Weapon::addVocWeaponMap(const std::string &vocName) { + const int32_t vocationId = g_vocations().getVocationId(vocName); + if (vocationId != -1) { + vocWeaponMap[vocationId] = true; + } +} + +std::shared_ptr Weapon::getCombat() const { + if (!m_combat) { + g_logger().error("Weapon::getCombat() - m_combat is nullptr"); + return nullptr; + } + + return m_combat; +} + +std::shared_ptr Weapon::getCombat() { + if (!m_combat) { + m_combat = std::make_shared(); + } + + return m_combat; +} + +WeaponMelee::WeaponMelee() { // Add combat type and blocked attributes to the weapon params.blockedByArmor = true; params.blockedByShield = true; @@ -573,8 +632,7 @@ int32_t WeaponMelee::getWeaponDamage(const std::shared_ptr &player, cons return -normal_random(minValue, (maxValue * static_cast(player->getVocation()->meleeDamageMultiplier))); } -WeaponDistance::WeaponDistance(LuaScriptInterface* interface) : - Weapon(interface) { +WeaponDistance::WeaponDistance() { // Add combat type and distance effect to the weapon params.blockedByArmor = true; params.combatType = COMBAT_PHYSICALDAMAGE; @@ -874,6 +932,8 @@ bool WeaponDistance::getSkillType(const std::shared_ptr &player, const s return true; } +WeaponWand::WeaponWand() = default; + void WeaponWand::configureWeapon(const ItemType &it) { params.distanceEffect = it.shootType; const_cast(it).combatType = params.combatType; @@ -882,35 +942,7 @@ void WeaponWand::configureWeapon(const ItemType &it) { } int32_t WeaponWand::getWeaponDamage(const std::shared_ptr &player, const std::shared_ptr &, const std::shared_ptr &, bool maxDamage /* = false*/) const { - if (!g_configManager().getBoolean(TOGGLE_CHAIN_SYSTEM)) { - // Returns maximum damage or a random value between minChange and maxChange - return maxDamage ? -maxChange : -normal_random(minChange, maxChange); - } - - // If chain system is enabled, calculates magic-based damage - int32_t attackSkill = 0; - int32_t attackValue = 0; - float attackFactor = 0.0; - [[maybe_unused]] int16_t elementAttack = 0; - [[maybe_unused]] CombatDamage combatDamage; - calculateSkillFormula(player, attackSkill, attackValue, attackFactor, elementAttack, combatDamage); - - const auto magLevel = player->getMagicLevel(); - const auto level = player->getLevel(); - - // Check if level is greater than zero before performing division - const auto levelDivision = level > 0 ? level / 5.0 : 0.0; - - const auto totalAttackValue = magLevel + attackValue; - - // Check if magLevel is greater than zero before performing division - const auto magicLevelDivision = totalAttackValue > 0 ? totalAttackValue / 3.0 : 0.0; - - const double min = levelDivision + magicLevelDivision; - const double max = levelDivision + totalAttackValue; - - // Returns the calculated maximum damage or a random value between the calculated minimum and maximum - return maxDamage ? -max : -normal_random(min, max); + return maxDamage ? -maxChange : -normal_random(minChange, maxChange); } int16_t WeaponWand::getElementDamageValue() const { diff --git a/src/items/weapons/weapons.hpp b/src/items/weapons/weapons.hpp index bbe15e12a7d..dca7d814033 100644 --- a/src/items/weapons/weapons.hpp +++ b/src/items/weapons/weapons.hpp @@ -9,24 +9,29 @@ #pragma once -#include "lua/scripts/luascript.hpp" -#include "creatures/players/player.hpp" -#include "lua/scripts/scripts.hpp" -#include "creatures/combat/combat.hpp" #include "utils/utils_definitions.hpp" -#include "creatures/players/vocations/vocation.hpp" +#include "creatures/creatures_definitions.hpp" +#include "creatures/combat/combat.hpp" class Weapon; class WeaponMelee; class WeaponDistance; class WeaponWand; +class LuaScriptInterface; +class Combat; +class Player; +class Creature; +class Item; +class ItemType; +class Vocation; +class Tile; struct LuaVariant; using WeaponUnique_ptr = std::unique_ptr; using WeaponShared_ptr = std::shared_ptr; -class Weapons final : public Scripts { +class Weapons { public: Weapons(); ~Weapons(); @@ -35,9 +40,7 @@ class Weapons final : public Scripts { Weapons(const Weapons &) = delete; Weapons &operator=(const Weapons &) = delete; - static Weapons &getInstance() { - return inject(); - } + static Weapons &getInstance(); WeaponShared_ptr getWeapon(const std::shared_ptr &item) const; @@ -53,10 +56,9 @@ class Weapons final : public Scripts { constexpr auto g_weapons = Weapons::getInstance; -class Weapon : public Script { +class Weapon { public: - using Script::Script; - + Weapon(); virtual void configureWeapon(const ItemType &it); virtual bool interruptSwing() const { return false; @@ -162,12 +164,7 @@ class Weapon : public Script { wieldInfo |= info; } - void addVocWeaponMap(const std::string &vocName) { - const int32_t vocationId = g_vocations().getVocationId(vocName); - if (vocationId != -1) { - vocWeaponMap[vocationId] = true; - } - } + void addVocWeaponMap(const std::string &vocName); const std::string &getVocationString() const { return vocationString; @@ -204,30 +201,25 @@ class Weapon : public Script { return weaponType; } - std::shared_ptr getCombat() const { - if (!m_combat) { - g_logger().error("Weapon::getCombat() - m_combat is nullptr"); - return nullptr; - } + std::shared_ptr getCombat() const; - return m_combat; - } - - std::shared_ptr getCombat() { - if (!m_combat) { - m_combat = std::make_shared(); - } - - return m_combat; - } + std::shared_ptr getCombat(); bool calculateSkillFormula(const std::shared_ptr &player, int32_t &attackSkill, int32_t &attackValue, float &attackFactor, int16_t &elementAttack, CombatDamage &damage, bool useCharges = false) const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + protected: void internalUseWeapon(const std::shared_ptr &player, const std::shared_ptr &item, const std::shared_ptr &target, int32_t damageModifier, int32_t cleavePercent = 0) const; void internalUseWeapon(const std::shared_ptr &player, const std::shared_ptr &item, const std::shared_ptr &tile) const; private: + int32_t m_scriptId {}; + virtual bool getSkillType(const std::shared_ptr &, const std::shared_ptr &, skills_t &, uint32_t &) const { return false; } @@ -276,11 +268,7 @@ class Weapon : public Script { class WeaponMelee final : public Weapon { public: - explicit WeaponMelee(LuaScriptInterface* interface); - - std::string getScriptTypeName() const override { - return "onUseWeapon"; - } + explicit WeaponMelee(); void configureWeapon(const ItemType &it) override; @@ -301,11 +289,7 @@ class WeaponMelee final : public Weapon { class WeaponDistance final : public Weapon { public: - explicit WeaponDistance(LuaScriptInterface* interface); - - std::string getScriptTypeName() const override { - return "onUseWeapon"; - } + explicit WeaponDistance(); void configureWeapon(const ItemType &it) override; bool interruptSwing() const override { @@ -330,11 +314,7 @@ class WeaponDistance final : public Weapon { class WeaponWand : public Weapon { public: - using Weapon::Weapon; - - std::string getScriptTypeName() const override { - return "onUseWeapon"; - } + explicit WeaponWand(); void configureWeapon(const ItemType &it) override; diff --git a/src/lua/callbacks/callbacks_definitions.hpp b/src/lua/callbacks/callbacks_definitions.hpp index 6c19cc809c9..faea6b2d1e2 100644 --- a/src/lua/callbacks/callbacks_definitions.hpp +++ b/src/lua/callbacks/callbacks_definitions.hpp @@ -23,7 +23,6 @@ enum class EventCallback_t : uint16_t { creatureOnChangeOutfit, creatureOnAreaCombat, creatureOnTargetCombat, - creatureOnHear, creatureOnDrainHealth, creatureOnCombat, // Party @@ -62,9 +61,6 @@ enum class EventCallback_t : uint16_t { // Monster monsterOnDropLoot, monsterPostDropLoot, - monsterOnSpawn, - // Npc - npcOnSpawn, // Zone zoneBeforeCreatureEnter, zoneBeforeCreatureLeave, diff --git a/src/lua/callbacks/event_callback.cpp b/src/lua/callbacks/event_callback.cpp index 3d95543f1b9..16e0aa182d0 100644 --- a/src/lua/callbacks/event_callback.cpp +++ b/src/lua/callbacks/event_callback.cpp @@ -14,6 +14,7 @@ #include "game/zones/zone.hpp" #include "items/containers/container.hpp" #include "items/item.hpp" +#include "lua/scripts/scripts.hpp" /** * @class EventCallback @@ -24,26 +25,52 @@ * * @see Script */ -EventCallback::EventCallback(LuaScriptInterface* scriptInterface, const std::string &callbackName, bool skipDuplicationCheck) : - Script(scriptInterface), m_callbackName(callbackName), m_skipDuplicationCheck(skipDuplicationCheck) { -} +EventCallback::EventCallback(const std::string &callbackName, bool skipDuplicationCheck) : + m_callbackName(callbackName), m_skipDuplicationCheck(skipDuplicationCheck) { } -std::string EventCallback::getName() const { - return m_callbackName; +LuaScriptInterface* EventCallback::getScriptInterface() const { + return &g_scripts().getScriptInterface(); } -bool EventCallback::skipDuplicationCheck() const { - return m_skipDuplicationCheck; +bool EventCallback::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[EventCallback::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; } std::string EventCallback::getScriptTypeName() const { return m_scriptTypeName; } -void EventCallback::setScriptTypeName(const std::string_view newName) { +void EventCallback::setScriptTypeName(std::string_view newName) { m_scriptTypeName = newName; } +int32_t EventCallback::getScriptId() const { + return m_scriptId; +} + +void EventCallback::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool EventCallback::isLoadedScriptId() const { + return m_scriptId != 0; +} + +std::string EventCallback::getName() const { + return m_callbackName; +} + +bool EventCallback::skipDuplicationCheck() const { + return m_skipDuplicationCheck; +} + EventCallback_t EventCallback::getType() const { return m_callbackType; } @@ -154,33 +181,6 @@ ReturnValue EventCallback::creatureOnTargetCombat(const std::shared_ptr &creature, const std::shared_ptr &speaker, const std::string &words, SpeakClasses type) const { - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("[EventCallback::creatureOnHear - " - "Creature {} speaker {}] " - "Call stack overflow. Too many lua script calls being nested.", - creature->getName(), speaker->getName()); - return; - } - - ScriptEnvironment* scriptEnvironment = LuaScriptInterface::getScriptEnv(); - scriptEnvironment->setScriptId(getScriptId(), getScriptInterface()); - - lua_State* L = getScriptInterface()->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); - - LuaScriptInterface::pushUserdata(L, creature); - LuaScriptInterface::setCreatureMetatable(L, -1, creature); - - LuaScriptInterface::pushUserdata(L, speaker); - LuaScriptInterface::setCreatureMetatable(L, -1, speaker); - - LuaScriptInterface::pushString(L, words); - lua_pushnumber(L, type); - - getScriptInterface()->callVoidFunction(4); -} - void EventCallback::creatureOnDrainHealth(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const { if (!LuaScriptInterface::reserveScriptEnv()) { g_logger().error("[EventCallback::creatureOnDrainHealth - " @@ -1162,63 +1162,6 @@ void EventCallback::monsterPostDropLoot(const std::shared_ptr &monster, return getScriptInterface()->callVoidFunction(2); } -void EventCallback::monsterOnSpawn(const std::shared_ptr &monster, const Position &position) const { - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("{} - " - "Position {}" - ". Call stack overflow. Too many lua script calls being nested.", - __FUNCTION__, position.toString()); - return; - } - - ScriptEnvironment* scriptEnvironment = LuaScriptInterface::getScriptEnv(); - scriptEnvironment->setScriptId(getScriptId(), getScriptInterface()); - - lua_State* L = getScriptInterface()->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); - - LuaScriptInterface::pushUserdata(L, monster); - LuaScriptInterface::setMetatable(L, -1, "Monster"); - LuaScriptInterface::pushPosition(L, position); - - if (LuaScriptInterface::protectedCall(L, 2, 1) != 0) { - LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L)); - } else { - lua_pop(L, 1); - } - - LuaScriptInterface::resetScriptEnv(); -} - -// Npc -void EventCallback::npcOnSpawn(const std::shared_ptr &npc, const Position &position) const { - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("{} - " - "Position {}" - ". Call stack overflow. Too many lua script calls being nested.", - __FUNCTION__, position.toString()); - return; - } - - ScriptEnvironment* scriptEnvironment = LuaScriptInterface::getScriptEnv(); - scriptEnvironment->setScriptId(getScriptId(), getScriptInterface()); - - lua_State* L = getScriptInterface()->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); - - LuaScriptInterface::pushUserdata(L, npc); - LuaScriptInterface::setMetatable(L, -1, "Npc"); - LuaScriptInterface::pushPosition(L, position); - - if (LuaScriptInterface::protectedCall(L, 2, 1) != 0) { - LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L)); - } else { - lua_pop(L, 1); - } - - LuaScriptInterface::resetScriptEnv(); -} - bool EventCallback::zoneBeforeCreatureEnter(const std::shared_ptr &zone, const std::shared_ptr &creature) const { if (!LuaScriptInterface::reserveScriptEnv()) { g_logger().error("[EventCallback::zoneBeforeCreatureEnter - " diff --git a/src/lua/callbacks/event_callback.hpp b/src/lua/callbacks/event_callback.hpp index fb0eb760a20..c7df7929774 100644 --- a/src/lua/callbacks/event_callback.hpp +++ b/src/lua/callbacks/event_callback.hpp @@ -13,7 +13,6 @@ #include "creatures/creatures_definitions.hpp" #include "items/items_definitions.hpp" #include "utils/utils_definitions.hpp" -#include "lua/scripts/scripts.hpp" class Creature; class Player; @@ -22,6 +21,25 @@ class Party; class ItemType; class Monster; class Zone; +class LuaScriptInterface; +class Thing; +class Item; +class Cylinder; +class Npc; +class Container; + +struct Position; +struct CombatDamage; +struct Outfit_t; + +enum Direction : uint8_t; +enum ReturnValue : uint16_t; +enum SpeakClasses : uint8_t; +enum Slots_t : uint8_t; +enum ZoneType_t : uint8_t; +enum skills_t : int8_t; +enum CombatType_t : uint8_t; +enum TextColor_t : uint8_t; /** * @class EventCallback @@ -31,19 +49,23 @@ class Zone; * registration, and execution of custom behavior tied to specific game events. * @note It inherits from the Script class, providing scripting capabilities. */ -class EventCallback final : public Script { +class EventCallback { private: EventCallback_t m_callbackType = EventCallback_t::none; ///< The type of the event callback. std::string m_scriptTypeName; ///< The name associated with the script type. std::string m_callbackName; ///< The name of the callback. bool m_skipDuplicationCheck = false; ///< Whether the callback is silent error for already registered log error. + int32_t m_scriptId {}; + public: - /** - * @brief Constructor that initializes the EventCallback with a given script interface. - * @param scriptInterface Pointer to the LuaScriptInterface object. - */ - explicit EventCallback(LuaScriptInterface* scriptInterface, const std::string &callbackName, bool silentAlreadyRegistered); + explicit EventCallback(const std::string &callbackName, bool silentAlreadyRegistered); + + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; /** * @brief Retrieves the callback name. @@ -61,7 +83,7 @@ class EventCallback final : public Script { * @brief Retrieves the script type name. * @return The script type name as a string. */ - std::string getScriptTypeName() const override; + std::string getScriptTypeName() const; /** * @brief Sets a new script type name. @@ -96,7 +118,6 @@ class EventCallback final : public Script { bool creatureOnChangeOutfit(const std::shared_ptr &creature, const Outfit_t &outfit) const; ReturnValue creatureOnAreaCombat(const std::shared_ptr &creature, const std::shared_ptr &tile, bool aggressive) const; ReturnValue creatureOnTargetCombat(const std::shared_ptr &creature, const std::shared_ptr &target) const; - void creatureOnHear(const std::shared_ptr &creature, const std::shared_ptr &speaker, const std::string &words, SpeakClasses type) const; void creatureOnDrainHealth(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) const; void creatureOnCombat(std::shared_ptr attacker, std::shared_ptr target, CombatDamage &damage) const; @@ -137,10 +158,6 @@ class EventCallback final : public Script { // Monster void monsterOnDropLoot(const std::shared_ptr &monster, const std::shared_ptr &corpse) const; void monsterPostDropLoot(const std::shared_ptr &monster, const std::shared_ptr &corpse) const; - void monsterOnSpawn(const std::shared_ptr &monster, const Position &position) const; - - // Npc - void npcOnSpawn(const std::shared_ptr &npc, const Position &position) const; // Zone bool zoneBeforeCreatureEnter(const std::shared_ptr &zone, const std::shared_ptr &creature) const; diff --git a/src/lua/callbacks/events_callbacks.hpp b/src/lua/callbacks/events_callbacks.hpp index 8913ee1dc4b..df321bbd02d 100644 --- a/src/lua/callbacks/events_callbacks.hpp +++ b/src/lua/callbacks/events_callbacks.hpp @@ -11,7 +11,6 @@ #include "lua/callbacks/callbacks_definitions.hpp" #include "lua/callbacks/event_callback.hpp" -#include "lua/scripts/luascript.hpp" class EventCallback; @@ -81,7 +80,7 @@ class EventsCallbacks { } for (const auto &entry : it->second) { - if (entry.callback && entry.callback->isLoadedCallback()) { + if (entry.callback && entry.callback->isLoadedScriptId()) { std::invoke(callbackFunc, *entry.callback, args...); } } @@ -102,7 +101,7 @@ class EventsCallbacks { } for (const auto &entry : it->second) { - if (entry.callback && entry.callback->isLoadedCallback()) { + if (entry.callback && entry.callback->isLoadedScriptId()) { ReturnValue callbackResult = std::invoke(callbackFunc, *entry.callback, args...); if (callbackResult != RETURNVALUE_NOERROR) { return callbackResult; @@ -128,7 +127,7 @@ class EventsCallbacks { } for (const auto &entry : it->second) { - if (entry.callback && entry.callback->isLoadedCallback()) { + if (entry.callback && entry.callback->isLoadedScriptId()) { bool callbackResult = std::invoke(callbackFunc, *entry.callback, args...); allCallbacksSucceeded &= callbackResult; } diff --git a/src/lua/creature/actions.cpp b/src/lua/creature/actions.cpp index b79cb5d03c7..2ee02fac9ab 100644 --- a/src/lua/creature/actions.cpp +++ b/src/lua/creature/actions.cpp @@ -19,10 +19,16 @@ #include "items/containers/depot/depotlocker.hpp" #include "items/containers/rewards/reward.hpp" #include "items/containers/rewards/rewardchest.hpp" +#include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" Actions::Actions() = default; Actions::~Actions() = default; +Actions &Actions::getInstance() { + return inject(); +} + void Actions::clear() { useItemMap.clear(); uniqueItemMap.clear(); @@ -273,7 +279,7 @@ ReturnValue Actions::internalUseItem(const std::shared_ptr &player, cons } if (action != nullptr) { - if (action->isLoadedCallback()) { + if (action->isLoadedScriptId()) { if (action->executeUse(player, item, pos, nullptr, pos, isHotkey)) { return RETURNVALUE_NOERROR; } @@ -495,8 +501,34 @@ void Actions::showUseHotkeyMessage(const std::shared_ptr &player, const */ // Action constructor -Action::Action(LuaScriptInterface* interface) : - Script(interface) { } +Action::Action() = default; + +LuaScriptInterface* Action::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool Action::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t Action::getScriptId() const { + return m_scriptId; +} + +void Action::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool Action::isLoadedScriptId() const { + return m_scriptId != 0; +} ReturnValue Action::canExecuteAction(const std::shared_ptr &player, const Position &toPos) { if (!allowFarUse) { diff --git a/src/lua/creature/actions.hpp b/src/lua/creature/actions.hpp index ed5c6adc399..f0d73811354 100644 --- a/src/lua/creature/actions.hpp +++ b/src/lua/creature/actions.hpp @@ -9,16 +9,20 @@ #pragma once -#include "lua/scripts/scripts.hpp" #include "declarations.hpp" -#include "lua/scripts/luascript.hpp" class Action; +class LuaScriptInterface; +class Player; +class Item; +class Creature; +class Thing; + struct Position; -class Action : public Script { +class Action { public: - explicit Action(LuaScriptInterface* interface); + explicit Action(); // Scripting virtual bool executeUse(const std::shared_ptr &player, const std::shared_ptr &item, const Position &fromPosition, const std::shared_ptr &target, const Position &toPosition, bool isHotkey); @@ -104,10 +108,14 @@ class Action : public Script { virtual std::shared_ptr getTarget(const std::shared_ptr &player, const std::shared_ptr &targetCreature, const Position &toPosition, uint8_t toStackPos) const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + private: - std::string getScriptTypeName() const override { - return "onUse"; - } + int32_t m_scriptId {}; std::function &player, const std::shared_ptr &item, @@ -130,7 +138,7 @@ class Action : public Script { friend class Actions; }; -class Actions final : public Scripts { +class Actions { public: Actions(); ~Actions(); @@ -139,9 +147,7 @@ class Actions final : public Scripts { Actions(const Actions &) = delete; Actions &operator=(const Actions &) = delete; - static Actions &getInstance() { - return inject(); - } + static Actions &getInstance(); bool useItem(const std::shared_ptr &player, const Position &pos, uint8_t index, const std::shared_ptr &item, bool isHotkey); bool useItemEx(const std::shared_ptr &player, const Position &fromPos, const Position &toPos, uint8_t toStackPos, const std::shared_ptr &item, bool isHotkey, const std::shared_ptr &creature = nullptr); diff --git a/src/lua/creature/creatureevent.cpp b/src/lua/creature/creatureevent.cpp index 575394b605c..c13c8180556 100644 --- a/src/lua/creature/creatureevent.cpp +++ b/src/lua/creature/creatureevent.cpp @@ -11,6 +11,8 @@ #include "creatures/players/player.hpp" #include "items/item.hpp" +#include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" void CreatureEvents::clear() { for (const auto &[name, event] : creatureEvents) { @@ -104,8 +106,34 @@ bool CreatureEvents::playerAdvance( ======================= */ -CreatureEvent::CreatureEvent(LuaScriptInterface* interface) : - Script(interface) { } +CreatureEvent::CreatureEvent() = default; + +LuaScriptInterface* CreatureEvent::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool CreatureEvent::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t CreatureEvent::getScriptId() const { + return m_scriptId; +} + +void CreatureEvent::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool CreatureEvent::isLoadedScriptId() const { + return m_scriptId != 0; +} void CreatureEvents::removeInvalidEvents() { std::erase_if(creatureEvents, [](const auto &pair) { @@ -160,15 +188,11 @@ std::string CreatureEvent::getScriptTypeName() const { void CreatureEvent::copyEvent(const std::shared_ptr &creatureEvent) { setScriptId(creatureEvent->getScriptId()); - setScriptInterface(creatureEvent->getScriptInterface()); - setLoadedCallback(creatureEvent->isLoadedCallback()); loaded = creatureEvent->loaded; } void CreatureEvent::clearEvent() { setScriptId(0); - setScriptInterface(nullptr); - setLoadedCallback(false); loaded = false; } diff --git a/src/lua/creature/creatureevent.hpp b/src/lua/creature/creatureevent.hpp index 5000a4b2e0a..1d5c612a68c 100644 --- a/src/lua/creature/creatureevent.hpp +++ b/src/lua/creature/creatureevent.hpp @@ -9,14 +9,21 @@ #pragma once -#include "lua/scripts/scripts.hpp" +#include "lua/lua_definitions.hpp" class CreatureEvent; class LuaScriptInterface; +class Creature; +class Player; +class Item; -class CreatureEvent final : public Script { +struct CombatDamage; + +enum skills_t : int8_t; + +class CreatureEvent { public: - explicit CreatureEvent(LuaScriptInterface* interface); + explicit CreatureEvent(); CreatureEventType_t getEventType() const { return type; @@ -53,17 +60,23 @@ class CreatureEvent final : public Script { void executeHealthChange(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatDamage &damage) const; void executeManaChange(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatDamage &damage) const; void executeExtendedOpcode(const std::shared_ptr &player, uint8_t opcode, const std::string &buffer) const; - // + + std::string getScriptTypeName() const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; private: - std::string getScriptTypeName() const override; + int32_t m_scriptId {}; std::string eventName; CreatureEventType_t type = CREATURE_EVENT_NONE; bool loaded = false; }; -class CreatureEvents final : public Scripts { +class CreatureEvents { public: CreatureEvents() = default; diff --git a/src/lua/creature/events.cpp b/src/lua/creature/events.cpp index 57a8ff45d31..9e03858107b 100644 --- a/src/lua/creature/events.cpp +++ b/src/lua/creature/events.cpp @@ -62,8 +62,6 @@ bool Events::loadFromXml() { info.creatureOnAreaCombat = event; } else if (methodName == "onTargetCombat") { info.creatureOnTargetCombat = event; - } else if (methodName == "onHear") { - info.creatureOnHear = event; } else if (methodName == "onDrainHealth") { info.creatureOnDrainHealth = event; } else { @@ -136,17 +134,9 @@ bool Events::loadFromXml() { } else if (className == "Monster") { if (methodName == "onDropLoot") { info.monsterOnDropLoot = event; - } else if (methodName == "onSpawn") { - info.monsterOnSpawn = event; } else { g_logger().warn("{} - Unknown monster method: {}", __FUNCTION__, methodName); } - } else if (className == "Npc") { - if (methodName == "onSpawn") { - info.monsterOnSpawn = event; - } else { - g_logger().warn("{} - Unknown npc method: {}", __FUNCTION__, methodName); - } } else { g_logger().warn("{} - Unknown class: {}", __FUNCTION__, className); } @@ -154,74 +144,6 @@ bool Events::loadFromXml() { return true; } -// Monster -void Events::eventMonsterOnSpawn(const std::shared_ptr &monster, const Position &position) { - // Monster:onSpawn(position) or Monster.onSpawn(self, position) - if (info.monsterOnSpawn == -1) { - return; - } - - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("{} - " - "Position {}" - ". Call stack overflow. Too many lua script calls being nested.", - __FUNCTION__, position.toString()); - return; - } - - ScriptEnvironment* env = LuaScriptInterface::getScriptEnv(); - env->setScriptId(info.monsterOnSpawn, &scriptInterface); - - lua_State* L = scriptInterface.getLuaState(); - scriptInterface.pushFunction(info.monsterOnSpawn); - - LuaScriptInterface::pushUserdata(L, monster); - LuaScriptInterface::setMetatable(L, -1, "Monster"); - LuaScriptInterface::pushPosition(L, position); - - if (LuaScriptInterface::protectedCall(L, 2, 1) != 0) { - LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L)); - } else { - lua_pop(L, 1); - } - - LuaScriptInterface::resetScriptEnv(); -} - -// Npc -void Events::eventNpcOnSpawn(const std::shared_ptr &npc, const Position &position) { - // Npc:onSpawn(position) or Npc.onSpawn(self, position) - if (info.npcOnSpawn == -1) { - return; - } - - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("{} - " - "Position {}" - ". Call stack overflow. Too many lua script calls being nested.", - __FUNCTION__, position.toString()); - return; - } - - ScriptEnvironment* env = LuaScriptInterface::getScriptEnv(); - env->setScriptId(info.npcOnSpawn, &scriptInterface); - - lua_State* L = scriptInterface.getLuaState(); - scriptInterface.pushFunction(info.npcOnSpawn); - - LuaScriptInterface::pushUserdata(L, npc); - LuaScriptInterface::setMetatable(L, -1, "Npc"); - LuaScriptInterface::pushPosition(L, position); - - if (LuaScriptInterface::protectedCall(L, 2, 1) != 0) { - LuaScriptInterface::reportError(nullptr, LuaScriptInterface::popString(L)); - } else { - lua_pop(L, 1); - } - - LuaScriptInterface::resetScriptEnv(); -} - Events &Events::getInstance() { return inject(); } @@ -342,38 +264,6 @@ ReturnValue Events::eventCreatureOnTargetCombat(const std::shared_ptr return returnValue; } -void Events::eventCreatureOnHear(const std::shared_ptr &creature, const std::shared_ptr &speaker, const std::string &words, SpeakClasses type) { - // Creature:onHear(speaker, words, type) - if (info.creatureOnHear == -1) { - return; - } - - if (!LuaScriptInterface::reserveScriptEnv()) { - g_logger().error("[Events::eventCreatureOnHear - " - "Creature {} speaker {}] " - "Call stack overflow. Too many lua script calls being nested.", - creature->getName(), speaker->getName()); - return; - } - - ScriptEnvironment* env = LuaScriptInterface::getScriptEnv(); - env->setScriptId(info.creatureOnHear, &scriptInterface); - - lua_State* L = scriptInterface.getLuaState(); - scriptInterface.pushFunction(info.creatureOnHear); - - LuaScriptInterface::pushUserdata(L, creature); - LuaScriptInterface::setCreatureMetatable(L, -1, creature); - - LuaScriptInterface::pushUserdata(L, speaker); - LuaScriptInterface::setCreatureMetatable(L, -1, speaker); - - LuaScriptInterface::pushString(L, words); - lua_pushnumber(L, type); - - scriptInterface.callVoidFunction(4); -} - void Events::eventCreatureOnDrainHealth(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary) { if (info.creatureOnDrainHealth == -1) { return; diff --git a/src/lua/creature/events.hpp b/src/lua/creature/events.hpp index a74cbaf3ccf..59d6b2f20d0 100644 --- a/src/lua/creature/events.hpp +++ b/src/lua/creature/events.hpp @@ -41,7 +41,6 @@ class Events { int32_t creatureOnChangeOutfit = -1; int32_t creatureOnAreaCombat = -1; int32_t creatureOnTargetCombat = -1; - int32_t creatureOnHear = -1; int32_t creatureOnDrainHealth = -1; // Party @@ -78,10 +77,6 @@ class Events { // Monster int32_t monsterOnDropLoot = -1; - int32_t monsterOnSpawn = -1; - - // Npc - int32_t npcOnSpawn = -1; }; public: @@ -99,7 +94,6 @@ class Events { bool eventCreatureOnChangeOutfit(const std::shared_ptr &creature, const Outfit_t &outfit); ReturnValue eventCreatureOnAreaCombat(const std::shared_ptr &creature, const std::shared_ptr &tile, bool aggressive); ReturnValue eventCreatureOnTargetCombat(const std::shared_ptr &creature, const std::shared_ptr &target); - void eventCreatureOnHear(const std::shared_ptr &creature, const std::shared_ptr &speaker, const std::string &words, SpeakClasses type); void eventCreatureOnDrainHealth(const std::shared_ptr &creature, const std::shared_ptr &attacker, CombatType_t &typePrimary, int32_t &damagePrimary, CombatType_t &typeSecondary, int32_t &damageSecondary, TextColor_t &colorPrimary, TextColor_t &colorSecondary); // Party @@ -135,10 +129,6 @@ class Events { // Monster void eventMonsterOnDropLoot(const std::shared_ptr &monster, const std::shared_ptr &corpse); - void eventMonsterOnSpawn(const std::shared_ptr &monster, const Position &position); - - // Monster - void eventNpcOnSpawn(const std::shared_ptr &npc, const Position &position); private: LuaScriptInterface scriptInterface; diff --git a/src/lua/creature/movement.cpp b/src/lua/creature/movement.cpp index 684f0844ee1..6804cdfa7e9 100644 --- a/src/lua/creature/movement.cpp +++ b/src/lua/creature/movement.cpp @@ -9,6 +9,7 @@ #include "lua/creature/movement.hpp" +#include "lib/di/container.hpp" #include "creatures/combat/combat.hpp" #include "creatures/combat/condition.hpp" #include "creatures/players/player.hpp" @@ -16,6 +17,14 @@ #include "lua/callbacks/event_callback.hpp" #include "lua/callbacks/events_callbacks.hpp" #include "lua/creature/events.hpp" +#include "lua/scripts/scripts.hpp" +#include "creatures/players/vocations/vocation.hpp" +#include "items/item.hpp" +#include "lua/functions/events/move_event_functions.hpp" + +MoveEvents &MoveEvents::getInstance() { + return inject(); +} void MoveEvents::clear() { uniqueIdMap.clear(); @@ -384,8 +393,8 @@ uint32_t MoveEvents::onItemMove(const std::shared_ptr &item, const std::sh MoveEvent class ================ */ -MoveEvent::MoveEvent(LuaScriptInterface* interface) : - Script(interface) { } + +MoveEvent::MoveEvent() = default; std::string MoveEvent::getScriptTypeName() const { switch (eventType) { @@ -411,6 +420,33 @@ std::string MoveEvent::getScriptTypeName() const { } } +LuaScriptInterface* MoveEvent::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool MoveEvent::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t MoveEvent::getScriptId() const { + return m_scriptId; +} + +void MoveEvent::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool MoveEvent::isLoadedScriptId() const { + return m_scriptId != 0; +} + uint32_t MoveEvent::StepInField(const std::shared_ptr &creature, const std::shared_ptr &item, const Position &) { if (creature == nullptr) { g_logger().error("[MoveEvent::StepInField] - Creature is nullptr"); @@ -676,7 +712,7 @@ void MoveEvent::setEventType(MoveEvent_t type) { } uint32_t MoveEvent::fireStepEvent(const std::shared_ptr &creature, const std::shared_ptr &item, const Position &pos) const { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { return executeStep(creature, item, pos); } else { return stepFunction(creature, item, pos); @@ -714,23 +750,24 @@ bool MoveEvent::executeStep(const std::shared_ptr &creature, const std return false; } + const auto scriptInterface = getScriptInterface(); ScriptEnvironment* env = LuaScriptInterface::getScriptEnv(); - env->setScriptId(getScriptId(), getScriptInterface()); + env->setScriptId(getScriptId(), scriptInterface); - lua_State* L = getScriptInterface()->getLuaState(); + lua_State* L = scriptInterface->getLuaState(); - getScriptInterface()->pushFunction(getScriptId()); + scriptInterface->pushFunction(getScriptId()); LuaScriptInterface::pushUserdata(L, creature); LuaScriptInterface::setCreatureMetatable(L, -1, creature); LuaScriptInterface::pushThing(L, item); LuaScriptInterface::pushPosition(L, pos); LuaScriptInterface::pushPosition(L, fromPosition); - return getScriptInterface()->callFunction(4); + return scriptInterface->callFunction(4); } uint32_t MoveEvent::fireEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t toSlot, bool isCheck) { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { if (!equipFunction || equipFunction(static_self_cast(), player, item, toSlot, isCheck) == 1) { if (executeEquip(player, item, toSlot, isCheck)) { return 1; @@ -768,7 +805,7 @@ bool MoveEvent::executeEquip(const std::shared_ptr &player, const std::s } uint32_t MoveEvent::fireAddRemItem(const std::shared_ptr &item, const std::shared_ptr &fromTile, const Position &pos) const { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { return executeAddRemItem(item, fromTile, pos); } else { return moveFunction(item, fromTile, pos); @@ -800,7 +837,7 @@ bool MoveEvent::executeAddRemItem(const std::shared_ptr &item, const std:: } uint32_t MoveEvent::fireAddRemItem(const std::shared_ptr &item, const Position &pos) const { - if (isLoadedCallback()) { + if (isLoadedScriptId()) { return executeAddRemItem(item, pos); } else { return moveFunction(item, nullptr, pos); @@ -829,3 +866,8 @@ bool MoveEvent::executeAddRemItem(const std::shared_ptr &item, const Posit return getScriptInterface()->callFunction(2); } + +void MoveEvent::addVocEquipMap(const std::string &vocName) { + const uint16_t vocationId = g_vocations().getVocationId(vocName); + vocEquipMap[vocationId] = true; +} diff --git a/src/lua/creature/movement.hpp b/src/lua/creature/movement.hpp index 58f42296f40..bb4554b94d2 100644 --- a/src/lua/creature/movement.hpp +++ b/src/lua/creature/movement.hpp @@ -10,12 +10,13 @@ #pragma once #include "declarations.hpp" -#include "items/item.hpp" -#include "lua/functions/events/move_event_functions.hpp" -#include "lua/scripts/scripts.hpp" -#include "creatures/players/vocations/vocation.hpp" class MoveEvent; +class LuaScriptInterface; +class Item; +class Tile; +class Creature; +class Player; struct MoveEventList { std::list> moveEvent[MOVE_EVENT_LAST]; @@ -23,7 +24,7 @@ struct MoveEventList { using VocEquipMap = std::map; -class MoveEvents final : public Scripts { +class MoveEvents { public: MoveEvents() = default; ~MoveEvents() = default; @@ -32,9 +33,7 @@ class MoveEvents final : public Scripts { MoveEvents(const MoveEvents &) = delete; MoveEvents &operator=(const MoveEvents &) = delete; - static MoveEvents &getInstance() { - return inject(); - } + static MoveEvents &getInstance(); uint32_t onCreatureMove(const std::shared_ptr &creature, const std::shared_ptr &tile, MoveEvent_t eventType); uint32_t onPlayerEquip(const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool isCheck); @@ -129,9 +128,9 @@ class MoveEvents final : public Scripts { constexpr auto g_moveEvents = MoveEvents::getInstance; -class MoveEvent final : public Script, public SharedObject { +class MoveEvent final : public SharedObject { public: - explicit MoveEvent(LuaScriptInterface* interface); + explicit MoveEvent(); MoveEvent_t getEventType() const; void setEventType(MoveEvent_t type); @@ -175,12 +174,7 @@ class MoveEvent final : public Script, public SharedObject { const std::map &getVocEquipMap() const { return vocEquipMap; } - void addVocEquipMap(const std::string &vocName) { - const uint16_t vocationId = g_vocations().getVocationId(vocName); - if (vocationId != 65535) { - vocEquipMap[vocationId] = true; - } - } + void addVocEquipMap(const std::string &vocName); bool getTileItem() const { return tileItem; } @@ -245,8 +239,15 @@ class MoveEvent final : public Script, public SharedObject { static uint32_t EquipItem(const std::shared_ptr &moveEvent, const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool boolean); static uint32_t DeEquipItem(const std::shared_ptr &, const std::shared_ptr &player, const std::shared_ptr &item, Slots_t slot, bool boolean); + std::string getScriptTypeName() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + LuaScriptInterface* getScriptInterface() const; + private: - std::string getScriptTypeName() const override; + int32_t m_scriptId {}; uint32_t slot = SLOTP_WHEREEVER; diff --git a/src/lua/creature/talkaction.cpp b/src/lua/creature/talkaction.cpp index 77323d9acf2..abe9303a5ba 100644 --- a/src/lua/creature/talkaction.cpp +++ b/src/lua/creature/talkaction.cpp @@ -13,10 +13,15 @@ #include "creatures/players/grouping/groups.hpp" #include "creatures/players/player.hpp" #include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" TalkActions::TalkActions() = default; TalkActions::~TalkActions() = default; +TalkActions &TalkActions::getInstance() { + return inject(); +} + void TalkActions::clear() { talkActions.clear(); } @@ -80,6 +85,33 @@ TalkActionResult_t TalkActions::checkPlayerCanSayTalkAction(const std::shared_pt return TALKACTION_CONTINUE; } +LuaScriptInterface* TalkAction::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool TalkAction::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t TalkAction::getScriptId() const { + return m_scriptId; +} + +void TalkAction::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool TalkAction::isLoadedScriptId() const { + return m_scriptId != 0; +} + bool TalkAction::executeSay(const std::shared_ptr &player, const std::string &words, const std::string ¶m, SpeakClasses type) const { // onSay(player, words, param, type) if (!LuaScriptInterface::reserveScriptEnv()) { @@ -101,7 +133,7 @@ bool TalkAction::executeSay(const std::shared_ptr &player, const std::st LuaScriptInterface::pushString(L, words); LuaScriptInterface::pushString(L, param); - lua_pushnumber(L, type); + LuaScriptInterface::pushNumber(L, static_cast(type)); return getScriptInterface()->callFunction(4); } diff --git a/src/lua/creature/talkaction.hpp b/src/lua/creature/talkaction.hpp index d11a5487924..4040a10f873 100644 --- a/src/lua/creature/talkaction.hpp +++ b/src/lua/creature/talkaction.hpp @@ -10,19 +10,16 @@ #pragma once #include "account/account.hpp" -#include "lua/global/baseevents.hpp" #include "utils/utils_definitions.hpp" #include "declarations.hpp" -#include "lua/scripts/luascript.hpp" -#include "lua/scripts/scripts.hpp" +class Player; +class LuaScriptInterface; class TalkAction; using TalkAction_ptr = std::shared_ptr; -class TalkAction final : public Script { +class TalkAction final { public: - using Script::Script; - const std::string &getWords() const { return m_word; } @@ -58,10 +55,14 @@ class TalkAction final : public Script { void setGroupType(uint8_t newGroupType); const uint8_t &getGroupType() const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + private: - std::string getScriptTypeName() const override { - return "onSay"; - } + int32_t m_scriptId {}; std::string m_word; std::string m_description; @@ -69,7 +70,7 @@ class TalkAction final : public Script { uint8_t m_groupType = 0; }; -class TalkActions final : public Scripts { +class TalkActions { public: TalkActions(); ~TalkActions(); @@ -78,9 +79,7 @@ class TalkActions final : public Scripts { TalkActions(const TalkActions &) = delete; TalkActions &operator=(const TalkActions &) = delete; - static TalkActions &getInstance() { - return inject(); - } + static TalkActions &getInstance(); bool checkWord(const std::shared_ptr &player, SpeakClasses type, const std::string &words, std::string_view word, const TalkAction_ptr &talkActionPtr) const; TalkActionResult_t checkPlayerCanSayTalkAction(const std::shared_ptr &player, SpeakClasses type, const std::string &words) const; diff --git a/src/lua/functions/core/CMakeLists.txt b/src/lua/functions/core/CMakeLists.txt index 1cf919da3ec..e9ac9899a6c 100644 --- a/src/lua/functions/core/CMakeLists.txt +++ b/src/lua/functions/core/CMakeLists.txt @@ -6,7 +6,6 @@ target_sources(${PROJECT_NAME}_lib PRIVATE game/lua_enums.cpp game/modal_window_functions.cpp game/zone_functions.cpp - libs/bit_functions.cpp libs/db_functions.cpp libs/result_functions.cpp libs/logger_functions.cpp diff --git a/src/lua/functions/core/game/bank_functions.cpp b/src/lua/functions/core/game/bank_functions.cpp index ce608939304..88665337a42 100644 --- a/src/lua/functions/core/game/bank_functions.cpp +++ b/src/lua/functions/core/game/bank_functions.cpp @@ -12,16 +12,29 @@ #include "creatures/players/player.hpp" #include "game/bank/bank.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void BankFunctions::init(lua_State* L) { + Lua::registerTable(L, "Bank"); + Lua::registerMethod(L, "Bank", "credit", BankFunctions::luaBankCredit); + Lua::registerMethod(L, "Bank", "debit", BankFunctions::luaBankDebit); + Lua::registerMethod(L, "Bank", "balance", BankFunctions::luaBankBalance); + Lua::registerMethod(L, "Bank", "hasBalance", BankFunctions::luaBankHasBalance); + Lua::registerMethod(L, "Bank", "transfer", BankFunctions::luaBankTransfer); + Lua::registerMethod(L, "Bank", "transferToGuild", BankFunctions::luaBankTransferToGuild); + Lua::registerMethod(L, "Bank", "withdraw", BankFunctions::luaBankWithdraw); + Lua::registerMethod(L, "Bank", "deposit", BankFunctions::luaBankDeposit); +} int BankFunctions::luaBankCredit(lua_State* L) { // Bank.credit(playerOrGuild, amount) const auto &bank = getBank(L, 1); if (bank == nullptr) { - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } - const uint64_t amount = getNumber(L, 2); - pushBoolean(L, bank->credit(amount)); + const uint64_t amount = Lua::getNumber(L, 2); + Lua::pushBoolean(L, bank->credit(amount)); return 1; } @@ -29,11 +42,11 @@ int BankFunctions::luaBankDebit(lua_State* L) { // Bank.debit(playerOrGuild, amount) const auto &bank = getBank(L, 1); if (bank == nullptr) { - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } - const uint64_t amount = getNumber(L, 2); - pushBoolean(L, bank->debit(amount)); + const uint64_t amount = Lua::getNumber(L, 2); + Lua::pushBoolean(L, bank->debit(amount)); return 1; } @@ -41,15 +54,15 @@ int BankFunctions::luaBankBalance(lua_State* L) { // Bank.balance(playerOrGuild[, amount]]) const auto &bank = getBank(L, 1); if (bank == nullptr) { - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, bank->balance()); return 1; } - const uint64_t amount = getNumber(L, 2); - pushBoolean(L, bank->balance(amount)); + const uint64_t amount = Lua::getNumber(L, 2); + Lua::pushBoolean(L, bank->balance(amount)); return 1; } @@ -57,11 +70,11 @@ int BankFunctions::luaBankHasBalance(lua_State* L) { // Bank.hasBalance(playerOrGuild, amount) const auto &bank = getBank(L, 1); if (bank == nullptr) { - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } - const uint64_t amount = getNumber(L, 2); - pushBoolean(L, bank->hasBalance(amount)); + const uint64_t amount = Lua::getNumber(L, 2); + Lua::pushBoolean(L, bank->hasBalance(amount)); return 1; } @@ -70,17 +83,17 @@ int BankFunctions::luaBankTransfer(lua_State* L) { const auto &source = getBank(L, 1); if (source == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: source is null"); - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } const auto &destination = getBank(L, 2); if (destination == nullptr) { g_logger().debug("BankFunctions::luaBankTransfer: destination is null"); - reportErrorFunc("Bank is nullptr"); + Lua::reportErrorFunc("Bank is nullptr"); return 1; } - const uint64_t amount = getNumber(L, 3); - pushBoolean(L, source->transferTo(destination, amount)); + const uint64_t amount = Lua::getNumber(L, 3); + Lua::pushBoolean(L, source->transferTo(destination, amount)); return 1; } @@ -88,83 +101,83 @@ int BankFunctions::luaBankTransferToGuild(lua_State* L) { // Bank.transfer(fromPlayerOrGuild, toGuild, amount) const auto &source = getBank(L, 1); if (source == nullptr) { - reportErrorFunc("Source is nullptr"); + Lua::reportErrorFunc("Source is nullptr"); return 1; } const auto &destination = getBank(L, 2, true /* isGuild */); if (destination == nullptr) { - reportErrorFunc("Destination is nullptr"); + Lua::reportErrorFunc("Destination is nullptr"); return 1; } - const uint64_t amount = getNumber(L, 3); - pushBoolean(L, source->transferTo(destination, amount)); + const uint64_t amount = Lua::getNumber(L, 3); + Lua::pushBoolean(L, source->transferTo(destination, amount)); return 1; } int BankFunctions::luaBankWithdraw(lua_State* L) { // Bank.withdraw(player, amount[, source = player]) - const auto &player = getPlayer(L, 1); + const auto &player = Lua::getPlayer(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const uint64_t amount = getNumber(L, 2); + const uint64_t amount = Lua::getNumber(L, 2); if (lua_gettop(L) == 2) { auto bank = std::make_shared(player); - pushBoolean(L, bank->withdraw(player, amount)); + Lua::pushBoolean(L, bank->withdraw(player, amount)); return 1; } const auto &source = getBank(L, 3); if (source == nullptr) { - reportErrorFunc("Source is nullptr"); + Lua::reportErrorFunc("Source is nullptr"); return 1; } - pushBoolean(L, source->withdraw(player, amount)); + Lua::pushBoolean(L, source->withdraw(player, amount)); return 1; } int BankFunctions::luaBankDeposit(lua_State* L) { // Bank.deposit(player, amount[, destination = player]) - const auto &player = getPlayer(L, 1); + const auto &player = Lua::getPlayer(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } auto bank = std::make_shared(player); uint64_t amount = 0; if (lua_isnumber(L, 2)) { - amount = getNumber(L, 2); + amount = Lua::getNumber(L, 2); } else if (lua_isnil(L, 2)) { amount = player->getMoney(); } if (lua_gettop(L) == 2) { - pushBoolean(L, g_game().removeMoney(player, amount) && bank->credit(amount)); + Lua::pushBoolean(L, g_game().removeMoney(player, amount) && bank->credit(amount)); return 1; } const auto &destination = getBank(L, 3); if (destination == nullptr) { - reportErrorFunc("Destination is nullptr"); + Lua::reportErrorFunc("Destination is nullptr"); return 1; } - pushBoolean(L, g_game().removeMoney(player, amount) && destination->credit(amount)); + Lua::pushBoolean(L, g_game().removeMoney(player, amount) && destination->credit(amount)); return 1; } std::shared_ptr BankFunctions::getBank(lua_State* L, int32_t arg, bool isGuild /*= false*/) { - if (getUserdataType(L, arg) == LuaData_t::Guild) { - return std::make_shared(getGuild(L, arg)); + if (Lua::getUserdataType(L, arg) == LuaData_t::Guild) { + return std::make_shared(Lua::getGuild(L, arg)); } if (isGuild) { - const auto &guild = getGuild(L, arg, true); + const auto &guild = Lua::getGuild(L, arg, true); if (!guild) { return nullptr; } return std::make_shared(guild); } - const auto &player = getPlayer(L, arg, true); + const auto &player = Lua::getPlayer(L, arg, true); if (!player) { return nullptr; } diff --git a/src/lua/functions/core/game/bank_functions.hpp b/src/lua/functions/core/game/bank_functions.hpp index f2a94a40435..a93de48424b 100644 --- a/src/lua/functions/core/game/bank_functions.hpp +++ b/src/lua/functions/core/game/bank_functions.hpp @@ -9,29 +9,11 @@ #pragma once -#include "lua/scripts/luascript.hpp" - class Bank; -class BankFunctions final : LuaScriptInterface { +class BankFunctions { public: - explicit BankFunctions(lua_State* L) : - LuaScriptInterface("BankFunctions") { - init(L); - } - ~BankFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "Bank"); - registerMethod(L, "Bank", "credit", BankFunctions::luaBankCredit); - registerMethod(L, "Bank", "debit", BankFunctions::luaBankDebit); - registerMethod(L, "Bank", "balance", BankFunctions::luaBankBalance); - registerMethod(L, "Bank", "hasBalance", BankFunctions::luaBankHasBalance); - registerMethod(L, "Bank", "transfer", BankFunctions::luaBankTransfer); - registerMethod(L, "Bank", "transferToGuild", BankFunctions::luaBankTransferToGuild); - registerMethod(L, "Bank", "withdraw", BankFunctions::luaBankWithdraw); - registerMethod(L, "Bank", "deposit", BankFunctions::luaBankDeposit); - } + static void init(lua_State* L); private: static int luaBankCredit(lua_State* L); diff --git a/src/lua/functions/core/game/config_functions.cpp b/src/lua/functions/core/game/config_functions.cpp index d8ee6e3ea77..029895a43e5 100644 --- a/src/lua/functions/core/game/config_functions.cpp +++ b/src/lua/functions/core/game/config_functions.cpp @@ -10,20 +10,21 @@ #include "lua/functions/core/game/config_functions.hpp" #include "config/configmanager.hpp" +#include "lua/functions/lua_functions_loader.hpp" void ConfigFunctions::init(lua_State* L) { - registerTable(L, "configManager"); - registerMethod(L, "configManager", "getString", luaConfigManagerGetString); - registerMethod(L, "configManager", "getNumber", luaConfigManagerGetNumber); - registerMethod(L, "configManager", "getBoolean", luaConfigManagerGetBoolean); - registerMethod(L, "configManager", "getFloat", luaConfigManagerGetFloat); + Lua::registerTable(L, "configManager"); + Lua::registerMethod(L, "configManager", "getString", luaConfigManagerGetString); + Lua::registerMethod(L, "configManager", "getNumber", luaConfigManagerGetNumber); + Lua::registerMethod(L, "configManager", "getBoolean", luaConfigManagerGetBoolean); + Lua::registerMethod(L, "configManager", "getFloat", luaConfigManagerGetFloat); #define registerMagicEnumIn(L, tableName, enumValue) \ do { \ auto name = magic_enum::enum_name(enumValue).data(); \ - registerVariable(L, tableName, name, value); \ + Lua::registerVariable(L, tableName, name, value); \ } while (0) - registerTable(L, "configKeys"); + Lua::registerTable(L, "configKeys"); for (auto value : magic_enum::enum_values()) { auto enumName = magic_enum::enum_name(value).data(); if (enumName) { @@ -35,35 +36,35 @@ void ConfigFunctions::init(lua_State* L) { } int ConfigFunctions::luaConfigManagerGetString(lua_State* L) { - const auto key = getNumber(L, -1); + const auto key = Lua::getNumber(L, -1); if (!key) { - reportErrorFunc("Wrong enum"); + Lua::reportErrorFunc("Wrong enum"); return 1; } - pushString(L, g_configManager().getString(getNumber(L, -1))); + Lua::pushString(L, g_configManager().getString(Lua::getNumber(L, -1))); return 1; } int ConfigFunctions::luaConfigManagerGetNumber(lua_State* L) { - const auto key = getNumber(L, -1); + const auto key = Lua::getNumber(L, -1); if (!key) { - reportErrorFunc("Wrong enum"); + Lua::reportErrorFunc("Wrong enum"); return 1; } - lua_pushnumber(L, g_configManager().getNumber(getNumber(L, -1))); + lua_pushnumber(L, g_configManager().getNumber(Lua::getNumber(L, -1))); return 1; } int ConfigFunctions::luaConfigManagerGetBoolean(lua_State* L) { - const auto key = getNumber(L, -1); + const auto key = Lua::getNumber(L, -1); if (!key) { - reportErrorFunc("Wrong enum"); + Lua::reportErrorFunc("Wrong enum"); return 1; } - pushBoolean(L, g_configManager().getBoolean(getNumber(L, -1))); + Lua::pushBoolean(L, g_configManager().getBoolean(Lua::getNumber(L, -1))); return 1; } @@ -71,18 +72,18 @@ int ConfigFunctions::luaConfigManagerGetFloat(lua_State* L) { // configManager.getFloat(key, shouldRound = true) // Ensure the first argument (key) is provided and is a valid enum - const auto key = getNumber(L, 1); + const auto key = Lua::getNumber(L, 1); if (!key) { - reportErrorFunc("Wrong enum"); + Lua::reportErrorFunc("Wrong enum"); return 1; } // Check if the second argument (shouldRound) is provided and is a boolean; default to true if not provided - bool shouldRound = getBoolean(L, 2, true); + bool shouldRound = Lua::getBoolean(L, 2, true); float value = g_configManager().getFloat(key); double finalValue = shouldRound ? static_cast(std::round(value * 100.0) / 100.0) : value; - g_logger().debug("[{}] key: {}, finalValue: {}, shouldRound: {}", __METHOD_NAME__, magic_enum::enum_name(key), finalValue, shouldRound); + g_logger().debug("[{}] key: {}, finalValue: {}, shouldRound: {}", __FUNCTION__, magic_enum::enum_name(key), finalValue, shouldRound); lua_pushnumber(L, finalValue); return 1; } diff --git a/src/lua/functions/core/game/config_functions.hpp b/src/lua/functions/core/game/config_functions.hpp index 973ed5c1d63..c22144ee08e 100644 --- a/src/lua/functions/core/game/config_functions.hpp +++ b/src/lua/functions/core/game/config_functions.hpp @@ -10,16 +10,8 @@ #pragma once #include "declarations.hpp" -#include "lua/scripts/luascript.hpp" - -class ConfigFunctions final : LuaScriptInterface { +class ConfigFunctions { public: - explicit ConfigFunctions(lua_State* L) : - LuaScriptInterface("ConfigFunctions") { - init(L); - } - ~ConfigFunctions() override = default; - static void init(lua_State* L); private: diff --git a/src/lua/functions/core/game/game_functions.cpp b/src/lua/functions/core/game/game_functions.cpp index 16133833bbc..aad4b71d06c 100644 --- a/src/lua/functions/core/game/game_functions.cpp +++ b/src/lua/functions/core/game/game_functions.cpp @@ -14,6 +14,7 @@ #include "creatures/monsters/monsters.hpp" #include "creatures/npcs/npc.hpp" #include "creatures/players/achievement/player_achievement.hpp" +#include "creatures/players/player.hpp" #include "game/functions/game_reload.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" @@ -28,15 +29,94 @@ #include "lua/functions/events/event_callback_functions.hpp" #include "lua/scripts/lua_environment.hpp" #include "map/spectators.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void GameFunctions::init(lua_State* L) { + Lua::registerTable(L, "Game"); + + Lua::registerMethod(L, "Game", "createNpcType", GameFunctions::luaGameCreateNpcType); + Lua::registerMethod(L, "Game", "createMonsterType", GameFunctions::luaGameCreateMonsterType); + + Lua::registerMethod(L, "Game", "getSpectators", GameFunctions::luaGameGetSpectators); + + Lua::registerMethod(L, "Game", "getBoostedCreature", GameFunctions::luaGameGetBoostedCreature); + Lua::registerMethod(L, "Game", "getBestiaryList", GameFunctions::luaGameGetBestiaryList); + + Lua::registerMethod(L, "Game", "getPlayers", GameFunctions::luaGameGetPlayers); + Lua::registerMethod(L, "Game", "loadMap", GameFunctions::luaGameLoadMap); + Lua::registerMethod(L, "Game", "loadMapChunk", GameFunctions::luaGameloadMapChunk); + + Lua::registerMethod(L, "Game", "getExperienceForLevel", GameFunctions::luaGameGetExperienceForLevel); + Lua::registerMethod(L, "Game", "getMonsterCount", GameFunctions::luaGameGetMonsterCount); + Lua::registerMethod(L, "Game", "getPlayerCount", GameFunctions::luaGameGetPlayerCount); + Lua::registerMethod(L, "Game", "getNpcCount", GameFunctions::luaGameGetNpcCount); + Lua::registerMethod(L, "Game", "getMonsterTypes", GameFunctions::luaGameGetMonsterTypes); + + Lua::registerMethod(L, "Game", "getTowns", GameFunctions::luaGameGetTowns); + Lua::registerMethod(L, "Game", "getHouses", GameFunctions::luaGameGetHouses); + + Lua::registerMethod(L, "Game", "getGameState", GameFunctions::luaGameGetGameState); + Lua::registerMethod(L, "Game", "setGameState", GameFunctions::luaGameSetGameState); + + Lua::registerMethod(L, "Game", "getWorldType", GameFunctions::luaGameGetWorldType); + Lua::registerMethod(L, "Game", "setWorldType", GameFunctions::luaGameSetWorldType); + + Lua::registerMethod(L, "Game", "getReturnMessage", GameFunctions::luaGameGetReturnMessage); + + Lua::registerMethod(L, "Game", "createItem", GameFunctions::luaGameCreateItem); + Lua::registerMethod(L, "Game", "createContainer", GameFunctions::luaGameCreateContainer); + Lua::registerMethod(L, "Game", "createMonster", GameFunctions::luaGameCreateMonster); + Lua::registerMethod(L, "Game", "createNpc", GameFunctions::luaGameCreateNpc); + Lua::registerMethod(L, "Game", "generateNpc", GameFunctions::luaGameGenerateNpc); + Lua::registerMethod(L, "Game", "createTile", GameFunctions::luaGameCreateTile); + Lua::registerMethod(L, "Game", "createBestiaryCharm", GameFunctions::luaGameCreateBestiaryCharm); + + Lua::registerMethod(L, "Game", "createItemClassification", GameFunctions::luaGameCreateItemClassification); + + Lua::registerMethod(L, "Game", "getBestiaryCharm", GameFunctions::luaGameGetBestiaryCharm); + + Lua::registerMethod(L, "Game", "startRaid", GameFunctions::luaGameStartRaid); + + Lua::registerMethod(L, "Game", "getClientVersion", GameFunctions::luaGameGetClientVersion); + + Lua::registerMethod(L, "Game", "reload", GameFunctions::luaGameReload); + + Lua::registerMethod(L, "Game", "hasDistanceEffect", GameFunctions::luaGameHasDistanceEffect); + Lua::registerMethod(L, "Game", "hasEffect", GameFunctions::luaGameHasEffect); + Lua::registerMethod(L, "Game", "getOfflinePlayer", GameFunctions::luaGameGetOfflinePlayer); + Lua::registerMethod(L, "Game", "getNormalizedPlayerName", GameFunctions::luaGameGetNormalizedPlayerName); + Lua::registerMethod(L, "Game", "getNormalizedGuildName", GameFunctions::luaGameGetNormalizedGuildName); + + Lua::registerMethod(L, "Game", "addInfluencedMonster", GameFunctions::luaGameAddInfluencedMonster); + Lua::registerMethod(L, "Game", "removeInfluencedMonster", GameFunctions::luaGameRemoveInfluencedMonster); + Lua::registerMethod(L, "Game", "getInfluencedMonsters", GameFunctions::luaGameGetInfluencedMonsters); + Lua::registerMethod(L, "Game", "makeFiendishMonster", GameFunctions::luaGameMakeFiendishMonster); + Lua::registerMethod(L, "Game", "removeFiendishMonster", GameFunctions::luaGameRemoveFiendishMonster); + Lua::registerMethod(L, "Game", "getFiendishMonsters", GameFunctions::luaGameGetFiendishMonsters); + Lua::registerMethod(L, "Game", "getBoostedBoss", GameFunctions::luaGameGetBoostedBoss); + + Lua::registerMethod(L, "Game", "getLadderIds", GameFunctions::luaGameGetLadderIds); + Lua::registerMethod(L, "Game", "getDummies", GameFunctions::luaGameGetDummies); + + Lua::registerMethod(L, "Game", "getTalkActions", GameFunctions::luaGameGetTalkActions); + Lua::registerMethod(L, "Game", "getEventCallbacks", GameFunctions::luaGameGetEventCallbacks); + + Lua::registerMethod(L, "Game", "registerAchievement", GameFunctions::luaGameRegisterAchievement); + Lua::registerMethod(L, "Game", "getAchievementInfoById", GameFunctions::luaGameGetAchievementInfoById); + Lua::registerMethod(L, "Game", "getAchievementInfoByName", GameFunctions::luaGameGetAchievementInfoByName); + Lua::registerMethod(L, "Game", "getSecretAchievements", GameFunctions::luaGameGetSecretAchievements); + Lua::registerMethod(L, "Game", "getPublicAchievements", GameFunctions::luaGameGetPublicAchievements); + Lua::registerMethod(L, "Game", "getAchievements", GameFunctions::luaGameGetAchievements); +} // Game int GameFunctions::luaGameCreateMonsterType(lua_State* L) { // Game.createMonsterType(name[, variant = ""[, alternateName = ""]]) - if (isString(L, 1)) { - const auto name = getString(L, 1); + if (Lua::isString(L, 1)) { + const auto name = Lua::getString(L, 1); std::string uniqueName = name; - auto variant = getString(L, 2, ""); - const auto alternateName = getString(L, 3, ""); + auto variant = Lua::getString(L, 2, ""); + const auto alternateName = Lua::getString(L, 3, ""); std::set names; const auto monsterType = std::make_shared(name); if (!monsterType) { @@ -72,8 +152,8 @@ int GameFunctions::luaGameCreateMonsterType(lua_State* L) { } } - pushUserdata(L, monsterType); - setMetatable(L, -1, "MonsterType"); + Lua::pushUserdata(L, monsterType); + Lua::setMetatable(L, -1, "MonsterType"); } else { lua_pushnil(L); } @@ -86,13 +166,13 @@ int GameFunctions::luaGameCreateNpcType(lua_State* L) { int GameFunctions::luaGameGetSpectators(lua_State* L) { // Game.getSpectators(position[, multifloor = false[, onlyPlayer = false[, minRangeX = 0[, maxRangeX = 0[, minRangeY = 0[, maxRangeY = 0]]]]]]) - const Position &position = getPosition(L, 1); - const bool multifloor = getBoolean(L, 2, false); - const bool onlyPlayers = getBoolean(L, 3, false); - const auto minRangeX = getNumber(L, 4, 0); - const auto maxRangeX = getNumber(L, 5, 0); - const auto minRangeY = getNumber(L, 6, 0); - const auto maxRangeY = getNumber(L, 7, 0); + const Position &position = Lua::getPosition(L, 1); + const bool multifloor = Lua::getBoolean(L, 2, false); + const bool onlyPlayers = Lua::getBoolean(L, 3, false); + const auto minRangeX = Lua::getNumber(L, 4, 0); + const auto maxRangeX = Lua::getNumber(L, 5, 0); + const auto minRangeY = Lua::getNumber(L, 6, 0); + const auto maxRangeY = Lua::getNumber(L, 7, 0); Spectators spectators; @@ -106,8 +186,8 @@ int GameFunctions::luaGameGetSpectators(lua_State* L) { int index = 0; for (const auto &creature : spectators) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); } return 1; @@ -115,7 +195,7 @@ int GameFunctions::luaGameGetSpectators(lua_State* L) { int GameFunctions::luaGameGetBoostedCreature(lua_State* L) { // Game.getBoostedCreature() - pushString(L, g_game().getBoostedMonsterName()); + Lua::pushString(L, g_game().getBoostedMonsterName()); return 1; } @@ -123,34 +203,34 @@ int GameFunctions::luaGameGetBestiaryList(lua_State* L) { // Game.getBestiaryList([bool[string or BestiaryType_t]]) lua_newtable(L); int index = 0; - const bool name = getBoolean(L, 2, false); + const bool name = Lua::getBoolean(L, 2, false); if (lua_gettop(L) <= 2) { const std::map &mtype_list = g_game().getBestiaryList(); for (const auto &ita : mtype_list) { if (name) { - pushString(L, ita.second); + Lua::pushString(L, ita.second); } else { lua_pushnumber(L, ita.first); } lua_rawseti(L, -2, ++index); } } else { - if (isNumber(L, 2)) { - const std::map tmplist = g_iobestiary().findRaceByName("CANARY", false, getNumber(L, 2)); + if (Lua::isNumber(L, 2)) { + const std::map tmplist = g_iobestiary().findRaceByName("CANARY", false, Lua::getNumber(L, 2)); for (const auto &itb : tmplist) { if (name) { - pushString(L, itb.second); + Lua::pushString(L, itb.second); } else { lua_pushnumber(L, itb.first); } lua_rawseti(L, -2, ++index); } } else { - const std::map tmplist = g_iobestiary().findRaceByName(getString(L, 2)); + const std::map tmplist = g_iobestiary().findRaceByName(Lua::getString(L, 2)); for (const auto &itc : tmplist) { if (name) { - pushString(L, itc.second); + Lua::pushString(L, itc.second); } else { lua_pushnumber(L, itc.first); } @@ -167,8 +247,8 @@ int GameFunctions::luaGameGetPlayers(lua_State* L) { int index = 0; for (const auto &playerEntry : g_game().getPlayers()) { - pushUserdata(L, playerEntry.second); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, playerEntry.second); + Lua::setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); } return 1; @@ -176,24 +256,24 @@ int GameFunctions::luaGameGetPlayers(lua_State* L) { int GameFunctions::luaGameLoadMap(lua_State* L) { // Game.loadMap(path) - const std::string &path = getString(L, 1); + const std::string &path = Lua::getString(L, 1); g_dispatcher().addEvent([path]() { g_game().loadMap(path); }, __FUNCTION__); return 0; } int GameFunctions::luaGameloadMapChunk(lua_State* L) { // Game.loadMapChunk(path, position, remove) - const std::string &path = getString(L, 1); - const Position &position = getPosition(L, 2); + const std::string &path = Lua::getString(L, 1); + const Position &position = Lua::getPosition(L, 2); g_dispatcher().addEvent([path, position]() { g_game().loadMap(path, position); }, __FUNCTION__); return 0; } int GameFunctions::luaGameGetExperienceForLevel(lua_State* L) { // Game.getExperienceForLevel(level) - const uint32_t level = getNumber(L, 1); + const uint32_t level = Lua::getNumber(L, 1); if (level == 0) { - reportErrorFunc("Level must be greater than 0."); + Lua::reportErrorFunc("Level must be greater than 0."); } else { lua_pushnumber(L, Player::getExpForLevel(level)); } @@ -224,8 +304,8 @@ int GameFunctions::luaGameGetMonsterTypes(lua_State* L) { lua_createtable(L, type.size(), 0); for (const auto &[typeName, mType] : type) { - pushUserdata(L, mType); - setMetatable(L, -1, "MonsterType"); + Lua::pushUserdata(L, mType); + Lua::setMetatable(L, -1, "MonsterType"); lua_setfield(L, -2, typeName.c_str()); } return 1; @@ -238,8 +318,8 @@ int GameFunctions::luaGameGetTowns(lua_State* L) { int index = 0; for (const auto &townEntry : towns) { - pushUserdata(L, townEntry.second); - setMetatable(L, -1, "Town"); + Lua::pushUserdata(L, townEntry.second); + Lua::setMetatable(L, -1, "Town"); lua_rawseti(L, -2, ++index); } return 1; @@ -252,8 +332,8 @@ int GameFunctions::luaGameGetHouses(lua_State* L) { int index = 0; for (const auto &houseEntry : houses) { - pushUserdata(L, houseEntry.second); - setMetatable(L, -1, "House"); + Lua::pushUserdata(L, houseEntry.second); + Lua::setMetatable(L, -1, "House"); lua_rawseti(L, -2, ++index); } return 1; @@ -267,9 +347,9 @@ int GameFunctions::luaGameGetGameState(lua_State* L) { int GameFunctions::luaGameSetGameState(lua_State* L) { // Game.setGameState(state) - const GameState_t state = getNumber(L, 1); + const GameState_t state = Lua::getNumber(L, 1); g_game().setGameState(state); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -281,33 +361,33 @@ int GameFunctions::luaGameGetWorldType(lua_State* L) { int GameFunctions::luaGameSetWorldType(lua_State* L) { // Game.setWorldType(type) - const WorldType_t type = getNumber(L, 1); + const WorldType_t type = Lua::getNumber(L, 1); g_game().setWorldType(type); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GameFunctions::luaGameGetReturnMessage(lua_State* L) { // Game.getReturnMessage(value) - const ReturnValue value = getNumber(L, 1); - pushString(L, getReturnMessage(value)); + const ReturnValue value = Lua::getNumber(L, 1); + Lua::pushString(L, getReturnMessage(value)); return 1; } int GameFunctions::luaGameCreateItem(lua_State* L) { // Game.createItem(itemId or name[, count[, position]]) uint16_t itemId; - if (isNumber(L, 1)) { - itemId = getNumber(L, 1); + if (Lua::isNumber(L, 1)) { + itemId = Lua::getNumber(L, 1); } else { - itemId = Item::items.getItemIdByName(getString(L, 1)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 1)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto count = getNumber(L, 2, 1); + const auto count = Lua::getNumber(L, 2, 1); int32_t itemCount = 1; int32_t subType = 1; @@ -324,7 +404,7 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { Position position; if (lua_gettop(L) >= 3) { - position = getPosition(L, 3); + position = Lua::getPosition(L, 3); } const bool hasTable = itemCount > 1; @@ -367,18 +447,18 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { return 1; } } else { - getScriptEnv()->addTempItem(item); + Lua::getScriptEnv()->addTempItem(item); item->setParent(VirtualCylinder::virtualCylinder); } if (hasTable) { lua_pushnumber(L, i); - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); lua_settable(L, -3); } else { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } } @@ -387,12 +467,12 @@ int GameFunctions::luaGameCreateItem(lua_State* L) { int GameFunctions::luaGameCreateContainer(lua_State* L) { // Game.createContainer(itemId, size[, position]) - const uint16_t size = getNumber(L, 2); + const uint16_t size = Lua::getNumber(L, 2); uint16_t id; - if (isNumber(L, 1)) { - id = getNumber(L, 1); + if (Lua::isNumber(L, 1)) { + id = Lua::getNumber(L, 1); } else { - id = Item::items.getItemIdByName(getString(L, 1)); + id = Item::items.getItemIdByName(Lua::getString(L, 1)); if (id == 0) { lua_pushnil(L); return 1; @@ -406,7 +486,7 @@ int GameFunctions::luaGameCreateContainer(lua_State* L) { } if (lua_gettop(L) >= 3) { - const Position &position = getPosition(L, 3); + const Position &position = Lua::getPosition(L, 3); const auto &tile = g_game().map.getTile(position); if (!tile) { lua_pushnil(L); @@ -415,18 +495,18 @@ int GameFunctions::luaGameCreateContainer(lua_State* L) { g_game().internalAddItem(tile, container, INDEX_WHEREEVER, FLAG_NOLIMIT); } else { - getScriptEnv()->addTempItem(container); + Lua::getScriptEnv()->addTempItem(container); container->setParent(VirtualCylinder::virtualCylinder); } - pushUserdata(L, container); - setMetatable(L, -1, "Container"); + Lua::pushUserdata(L, container); + Lua::setMetatable(L, -1, "Container"); return 1; } int GameFunctions::luaGameCreateMonster(lua_State* L) { // Game.createMonster(monsterName, position[, extended = false[, force = false[, master = nil]]]) - const auto &monster = Monster::createMonster(getString(L, 1)); + const auto &monster = Monster::createMonster(Lua::getString(L, 1)); if (!monster) { lua_pushnil(L); return 1; @@ -434,18 +514,16 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { bool isSummon = false; if (lua_gettop(L) >= 5) { - if (const auto &master = getCreature(L, 5)) { + if (const auto &master = Lua::getCreature(L, 5)) { monster->setMaster(master, true); isSummon = true; } } - const Position &position = getPosition(L, 2); - const bool extended = getBoolean(L, 3, false); - const bool force = getBoolean(L, 4, false); + const Position &position = Lua::getPosition(L, 2); + const bool extended = Lua::getBoolean(L, 3, false); + const bool force = Lua::getBoolean(L, 4, false); if (g_game().placeCreature(monster, position, extended, force)) { - g_events().eventMonsterOnSpawn(monster, position); - g_callbacks().executeCallback(EventCallback_t::monsterOnSpawn, &EventCallback::monsterOnSpawn, monster, position); monster->onSpawn(); const auto &mtype = monster->getMonsterType(); if (mtype && mtype->info.raceid > 0 && mtype->info.bosstiaryRace == BosstiaryRarity_t::RARITY_ARCHFOE) { @@ -456,8 +534,8 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { } } - pushUserdata(L, monster); - setMetatable(L, -1, "Monster"); + Lua::pushUserdata(L, monster); + Lua::setMetatable(L, -1, "Monster"); } else { if (isSummon) { monster->setMaster(nullptr); @@ -470,31 +548,31 @@ int GameFunctions::luaGameCreateMonster(lua_State* L) { int GameFunctions::luaGameGenerateNpc(lua_State* L) { // Game.generateNpc(npcName) - const auto &npc = Npc::createNpc(getString(L, 1)); + const auto &npc = Npc::createNpc(Lua::getString(L, 1)); if (!npc) { lua_pushnil(L); return 1; } else { - pushUserdata(L, npc); - setMetatable(L, -1, "Npc"); + Lua::pushUserdata(L, npc); + Lua::setMetatable(L, -1, "Npc"); } return 1; } int GameFunctions::luaGameCreateNpc(lua_State* L) { // Game.createNpc(npcName, position[, extended = false[, force = false]]) - const auto &npc = Npc::createNpc(getString(L, 1)); + const auto &npc = Npc::createNpc(Lua::getString(L, 1)); if (!npc) { lua_pushnil(L); return 1; } - const Position &position = getPosition(L, 2); - const bool extended = getBoolean(L, 3, false); - const bool force = getBoolean(L, 4, false); + const Position &position = Lua::getPosition(L, 2); + const bool extended = Lua::getBoolean(L, 3, false); + const bool force = Lua::getBoolean(L, 4, false); if (g_game().placeCreature(npc, position, extended, force)) { - pushUserdata(L, npc); - setMetatable(L, -1, "Npc"); + Lua::pushUserdata(L, npc); + Lua::setMetatable(L, -1, "Npc"); } else { lua_pushnil(L); } @@ -506,18 +584,18 @@ int GameFunctions::luaGameCreateTile(lua_State* L) { // Game.createTile(position[, isDynamic = false]) Position position; bool isDynamic; - if (isTable(L, 1)) { - position = getPosition(L, 1); - isDynamic = getBoolean(L, 2, false); + if (Lua::isTable(L, 1)) { + position = Lua::getPosition(L, 1); + isDynamic = Lua::getBoolean(L, 2, false); } else { - position.x = getNumber(L, 1); - position.y = getNumber(L, 2); - position.z = getNumber(L, 3); - isDynamic = getBoolean(L, 4, false); + position.x = Lua::getNumber(L, 1); + position.y = Lua::getNumber(L, 2); + position.z = Lua::getNumber(L, 3); + isDynamic = Lua::getBoolean(L, 4, false); } - pushUserdata(L, g_game().map.getOrCreateTile(position, isDynamic)); - setMetatable(L, -1, "Tile"); + Lua::pushUserdata(L, g_game().map.getOrCreateTile(position, isDynamic)); + Lua::setMetatable(L, -1, "Tile"); return 1; } @@ -528,8 +606,8 @@ int GameFunctions::luaGameGetBestiaryCharm(lua_State* L) { int index = 0; for (const auto &charmPtr : c_list) { - pushUserdata(L, charmPtr); - setMetatable(L, -1, "Charm"); + Lua::pushUserdata(L, charmPtr); + Lua::setMetatable(L, -1, "Charm"); lua_rawseti(L, -2, ++index); } return 1; @@ -537,9 +615,9 @@ int GameFunctions::luaGameGetBestiaryCharm(lua_State* L) { int GameFunctions::luaGameCreateBestiaryCharm(lua_State* L) { // Game.createBestiaryCharm(id) - if (const std::shared_ptr &charm = g_iobestiary().getBestiaryCharm(static_cast(getNumber(L, 1, 0)), true)) { - pushUserdata(L, charm); - setMetatable(L, -1, "Charm"); + if (const std::shared_ptr &charm = g_iobestiary().getBestiaryCharm(static_cast(Lua::getNumber(L, 1, 0)), true)) { + Lua::pushUserdata(L, charm); + Lua::setMetatable(L, -1, "Charm"); } else { lua_pushnil(L); } @@ -548,10 +626,10 @@ int GameFunctions::luaGameCreateBestiaryCharm(lua_State* L) { int GameFunctions::luaGameCreateItemClassification(lua_State* L) { // Game.createItemClassification(id) - const ItemClassification* itemClassification = g_game().getItemsClassification(getNumber(L, 1), true); + const ItemClassification* itemClassification = g_game().getItemsClassification(Lua::getNumber(L, 1), true); if (itemClassification) { - pushUserdata(L, itemClassification); - setMetatable(L, -1, "ItemClassification"); + Lua::pushUserdata(L, itemClassification); + Lua::setMetatable(L, -1, "ItemClassification"); } else { lua_pushnil(L); } @@ -560,7 +638,7 @@ int GameFunctions::luaGameCreateItemClassification(lua_State* L) { int GameFunctions::luaGameStartRaid(lua_State* L) { // Game.startRaid(raidName) - const std::string &raidName = getString(L, 1); + const std::string &raidName = Lua::getString(L, 1); const auto &raid = g_game().raids.getRaidByName(raidName); if (!raid || !raid->isLoaded()) { @@ -582,66 +660,66 @@ int GameFunctions::luaGameStartRaid(lua_State* L) { int GameFunctions::luaGameGetClientVersion(lua_State* L) { // Game.getClientVersion() lua_createtable(L, 0, 3); - setField(L, "min", CLIENT_VERSION); - setField(L, "max", CLIENT_VERSION); + Lua::setField(L, "min", CLIENT_VERSION); + Lua::setField(L, "max", CLIENT_VERSION); const std::string version = fmt::format("{}.{}", CLIENT_VERSION_UPPER, CLIENT_VERSION_LOWER); - setField(L, "string", version); + Lua::setField(L, "string", version); return 1; } int GameFunctions::luaGameReload(lua_State* L) { // Game.reload(reloadType) - const Reload_t reloadType = getNumber(L, 1); + const Reload_t reloadType = Lua::getNumber(L, 1); if (GameReload::getReloadNumber(reloadType) == GameReload::getReloadNumber(Reload_t::RELOAD_TYPE_NONE)) { - reportErrorFunc("Reload type is none"); - pushBoolean(L, false); + Lua::reportErrorFunc("Reload type is none"); + Lua::pushBoolean(L, false); return 0; } if (GameReload::getReloadNumber(reloadType) >= GameReload::getReloadNumber(Reload_t::RELOAD_TYPE_LAST)) { - reportErrorFunc("Reload type not exist"); - pushBoolean(L, false); + Lua::reportErrorFunc("Reload type not exist"); + Lua::pushBoolean(L, false); return 0; } - pushBoolean(L, GameReload::init(reloadType)); + Lua::pushBoolean(L, GameReload::init(reloadType)); lua_gc(g_luaEnvironment().getLuaState(), LUA_GCCOLLECT, 0); return 1; } int GameFunctions::luaGameHasEffect(lua_State* L) { // Game.hasEffect(effectId) - const uint16_t effectId = getNumber(L, 1); - pushBoolean(L, g_game().hasEffect(effectId)); + const uint16_t effectId = Lua::getNumber(L, 1); + Lua::pushBoolean(L, g_game().hasEffect(effectId)); return 1; } int GameFunctions::luaGameHasDistanceEffect(lua_State* L) { // Game.hasDistanceEffect(effectId) - const uint16_t effectId = getNumber(L, 1); - pushBoolean(L, g_game().hasDistanceEffect(effectId)); + const uint16_t effectId = Lua::getNumber(L, 1); + Lua::pushBoolean(L, g_game().hasDistanceEffect(effectId)); return 1; } int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { // Game.getOfflinePlayer(name or id) std::shared_ptr player = nullptr; - if (isNumber(L, 1)) { - const uint32_t id = getNumber(L, 1); + if (Lua::isNumber(L, 1)) { + const uint32_t id = Lua::getNumber(L, 1); if (id >= Player::getFirstID() && id <= Player::getLastID()) { player = g_game().getPlayerByID(id, true); } else { player = g_game().getPlayerByGUID(id, true); } - } else if (isString(L, 1)) { - const auto name = getString(L, 1); + } else if (Lua::isString(L, 1)) { + const auto name = Lua::getString(L, 1); player = g_game().getPlayerByName(name, true); } if (!player) { lua_pushnil(L); } else { - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); } return 1; @@ -649,11 +727,11 @@ int GameFunctions::luaGameGetOfflinePlayer(lua_State* L) { int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { // Game.getNormalizedPlayerName(name[, isNewName = false]) - const auto name = getString(L, 1); - const auto isNewName = getBoolean(L, 2, false); + const auto name = Lua::getString(L, 1); + const auto isNewName = Lua::getBoolean(L, 2, false); const auto &player = g_game().getPlayerByName(name, true, isNewName); if (player) { - pushString(L, player->getName()); + Lua::pushString(L, player->getName()); } else { lua_pushnil(L); } @@ -662,10 +740,10 @@ int GameFunctions::luaGameGetNormalizedPlayerName(lua_State* L) { int GameFunctions::luaGameGetNormalizedGuildName(lua_State* L) { // Game.getNormalizedGuildName(name) - const auto name = getString(L, 1); + const auto name = Lua::getString(L, 1); const auto &guild = g_game().getGuildByName(name, true); if (guild) { - pushString(L, guild->getName()); + Lua::pushString(L, guild->getName()); } else { lua_pushnil(L); } @@ -674,10 +752,10 @@ int GameFunctions::luaGameGetNormalizedGuildName(lua_State* L) { int GameFunctions::luaGameAddInfluencedMonster(lua_State* L) { // Game.addInfluencedMonster(monster) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -687,8 +765,8 @@ int GameFunctions::luaGameAddInfluencedMonster(lua_State* L) { int GameFunctions::luaGameRemoveInfluencedMonster(lua_State* L) { // Game.removeInfluencedMonster(monsterId) - const uint32_t monsterId = getNumber(L, 1); - const auto create = getBoolean(L, 2, false); + const uint32_t monsterId = Lua::getNumber(L, 1); + const auto create = Lua::getBoolean(L, 2, false); lua_pushnumber(L, g_game().removeInfluencedMonster(monsterId, create)); return 1; } @@ -742,16 +820,16 @@ int GameFunctions::luaGameGetDummies(lua_State* L) { int GameFunctions::luaGameMakeFiendishMonster(lua_State* L) { // Game.makeFiendishMonster(monsterId[default= 0]) - const auto monsterId = getNumber(L, 1, 0); - const auto createForgeableMonsters = getBoolean(L, 2, false); + const auto monsterId = Lua::getNumber(L, 1, 0); + const auto createForgeableMonsters = Lua::getBoolean(L, 2, false); lua_pushnumber(L, g_game().makeFiendishMonster(monsterId, createForgeableMonsters)); return 1; } int GameFunctions::luaGameRemoveFiendishMonster(lua_State* L) { // Game.removeFiendishMonster(monsterId) - const uint32_t monsterId = getNumber(L, 1); - const auto create = getBoolean(L, 2, false); + const uint32_t monsterId = Lua::getNumber(L, 1); + const auto create = Lua::getBoolean(L, 2, false); lua_pushnumber(L, g_game().removeFiendishMonster(monsterId, create)); return 1; } @@ -773,7 +851,7 @@ int GameFunctions::luaGameGetFiendishMonsters(lua_State* L) { int GameFunctions::luaGameGetBoostedBoss(lua_State* L) { // Game.getBoostedBoss() - pushString(L, g_ioBosstiary().getBoostedBossName()); + Lua::pushString(L, g_ioBosstiary().getBoostedBossName()); return 1; } @@ -783,8 +861,8 @@ int GameFunctions::luaGameGetTalkActions(lua_State* L) { lua_createtable(L, static_cast(talkactionsMap.size()), 0); for (const auto &[talkName, talkactionSharedPtr] : talkactionsMap) { - pushUserdata(L, talkactionSharedPtr); - setMetatable(L, -1, "TalkAction"); + Lua::pushUserdata(L, talkactionSharedPtr); + Lua::setMetatable(L, -1, "TalkAction"); lua_setfield(L, -2, talkName.c_str()); } return 1; @@ -810,56 +888,56 @@ int GameFunctions::luaGameGetEventCallbacks(lua_State* L) { int GameFunctions::luaGameRegisterAchievement(lua_State* L) { // Game.registerAchievement(id, name, description, secret, grade, points) if (lua_gettop(L) < 6) { - reportErrorFunc("Achievement can only be registered with all params."); + Lua::reportErrorFunc("Achievement can only be registered with all params."); return 1; } - const uint16_t id = getNumber(L, 1); - const std::string name = getString(L, 2); - const std::string description = getString(L, 3); - const bool secret = getBoolean(L, 4); - const uint8_t grade = getNumber(L, 5); - const uint8_t points = getNumber(L, 6); + const uint16_t id = Lua::getNumber(L, 1); + const std::string name = Lua::getString(L, 2); + const std::string description = Lua::getString(L, 3); + const bool secret = Lua::getBoolean(L, 4); + const uint8_t grade = Lua::getNumber(L, 5); + const uint8_t points = Lua::getNumber(L, 6); g_game().registerAchievement(id, name, description, secret, grade, points); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GameFunctions::luaGameGetAchievementInfoById(lua_State* L) { // Game.getAchievementInfoById(id) - const uint16_t id = getNumber(L, 1); + const uint16_t id = Lua::getNumber(L, 1); const Achievement achievement = g_game().getAchievementById(id); if (achievement.id == 0) { - reportErrorFunc("Achievement id is wrong"); + Lua::reportErrorFunc("Achievement id is wrong"); return 1; } lua_createtable(L, 0, 6); - setField(L, "id", achievement.id); - setField(L, "name", achievement.name); - setField(L, "description", achievement.description); - setField(L, "points", achievement.points); - setField(L, "grade", achievement.grade); - setField(L, "secret", achievement.secret); + Lua::setField(L, "id", achievement.id); + Lua::setField(L, "name", achievement.name); + Lua::setField(L, "description", achievement.description); + Lua::setField(L, "points", achievement.points); + Lua::setField(L, "grade", achievement.grade); + Lua::setField(L, "secret", achievement.secret); return 1; } int GameFunctions::luaGameGetAchievementInfoByName(lua_State* L) { // Game.getAchievementInfoByName(name) - const std::string name = getString(L, 1); + const std::string name = Lua::getString(L, 1); const Achievement achievement = g_game().getAchievementByName(name); if (achievement.id == 0) { - reportErrorFunc("Achievement name is wrong"); + Lua::reportErrorFunc("Achievement name is wrong"); return 1; } lua_createtable(L, 0, 6); - setField(L, "id", achievement.id); - setField(L, "name", achievement.name); - setField(L, "description", achievement.description); - setField(L, "points", achievement.points); - setField(L, "grade", achievement.grade); - setField(L, "secret", achievement.secret); + Lua::setField(L, "id", achievement.id); + Lua::setField(L, "name", achievement.name); + Lua::setField(L, "description", achievement.description); + Lua::setField(L, "points", achievement.points); + Lua::setField(L, "grade", achievement.grade); + Lua::setField(L, "secret", achievement.secret); return 1; } @@ -870,12 +948,12 @@ int GameFunctions::luaGameGetSecretAchievements(lua_State* L) { lua_createtable(L, achievements.size(), 0); for (const auto &achievement : achievements) { lua_createtable(L, 0, 6); - setField(L, "id", achievement.id); - setField(L, "name", achievement.name); - setField(L, "description", achievement.description); - setField(L, "points", achievement.points); - setField(L, "grade", achievement.grade); - setField(L, "secret", achievement.secret); + Lua::setField(L, "id", achievement.id); + Lua::setField(L, "name", achievement.name); + Lua::setField(L, "description", achievement.description); + Lua::setField(L, "points", achievement.points); + Lua::setField(L, "grade", achievement.grade); + Lua::setField(L, "secret", achievement.secret); lua_rawseti(L, -2, ++index); } return 1; @@ -888,12 +966,12 @@ int GameFunctions::luaGameGetPublicAchievements(lua_State* L) { lua_createtable(L, achievements.size(), 0); for (const auto &achievement : achievements) { lua_createtable(L, 0, 6); - setField(L, "id", achievement.id); - setField(L, "name", achievement.name); - setField(L, "description", achievement.description); - setField(L, "points", achievement.points); - setField(L, "grade", achievement.grade); - setField(L, "secret", achievement.secret); + Lua::setField(L, "id", achievement.id); + Lua::setField(L, "name", achievement.name); + Lua::setField(L, "description", achievement.description); + Lua::setField(L, "points", achievement.points); + Lua::setField(L, "grade", achievement.grade); + Lua::setField(L, "secret", achievement.secret); lua_rawseti(L, -2, ++index); } return 1; @@ -906,12 +984,12 @@ int GameFunctions::luaGameGetAchievements(lua_State* L) { lua_createtable(L, achievements.size(), 0); for (const auto &achievement_it : achievements) { lua_createtable(L, 0, 6); - setField(L, "id", achievement_it.first); - setField(L, "name", achievement_it.second.name); - setField(L, "description", achievement_it.second.description); - setField(L, "points", achievement_it.second.points); - setField(L, "grade", achievement_it.second.grade); - setField(L, "secret", achievement_it.second.secret); + Lua::setField(L, "id", achievement_it.first); + Lua::setField(L, "name", achievement_it.second.name); + Lua::setField(L, "description", achievement_it.second.description); + Lua::setField(L, "points", achievement_it.second.points); + Lua::setField(L, "grade", achievement_it.second.grade); + Lua::setField(L, "secret", achievement_it.second.secret); lua_rawseti(L, -2, ++index); } return 1; diff --git a/src/lua/functions/core/game/game_functions.hpp b/src/lua/functions/core/game/game_functions.hpp index 3c668c54fb4..6d332face9f 100644 --- a/src/lua/functions/core/game/game_functions.hpp +++ b/src/lua/functions/core/game/game_functions.hpp @@ -9,93 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class GameFunctions final : LuaScriptInterface { +class GameFunctions { public: - explicit GameFunctions(lua_State* L) : - LuaScriptInterface("GameFunctions") { - init(L); - } - ~GameFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "Game"); - - registerMethod(L, "Game", "createNpcType", GameFunctions::luaGameCreateNpcType); - registerMethod(L, "Game", "createMonsterType", GameFunctions::luaGameCreateMonsterType); - - registerMethod(L, "Game", "getSpectators", GameFunctions::luaGameGetSpectators); - - registerMethod(L, "Game", "getBoostedCreature", GameFunctions::luaGameGetBoostedCreature); - registerMethod(L, "Game", "getBestiaryList", GameFunctions::luaGameGetBestiaryList); - - registerMethod(L, "Game", "getPlayers", GameFunctions::luaGameGetPlayers); - registerMethod(L, "Game", "loadMap", GameFunctions::luaGameLoadMap); - registerMethod(L, "Game", "loadMapChunk", GameFunctions::luaGameloadMapChunk); - - registerMethod(L, "Game", "getExperienceForLevel", GameFunctions::luaGameGetExperienceForLevel); - registerMethod(L, "Game", "getMonsterCount", GameFunctions::luaGameGetMonsterCount); - registerMethod(L, "Game", "getPlayerCount", GameFunctions::luaGameGetPlayerCount); - registerMethod(L, "Game", "getNpcCount", GameFunctions::luaGameGetNpcCount); - registerMethod(L, "Game", "getMonsterTypes", GameFunctions::luaGameGetMonsterTypes); - - registerMethod(L, "Game", "getTowns", GameFunctions::luaGameGetTowns); - registerMethod(L, "Game", "getHouses", GameFunctions::luaGameGetHouses); - - registerMethod(L, "Game", "getGameState", GameFunctions::luaGameGetGameState); - registerMethod(L, "Game", "setGameState", GameFunctions::luaGameSetGameState); - - registerMethod(L, "Game", "getWorldType", GameFunctions::luaGameGetWorldType); - registerMethod(L, "Game", "setWorldType", GameFunctions::luaGameSetWorldType); - - registerMethod(L, "Game", "getReturnMessage", GameFunctions::luaGameGetReturnMessage); - - registerMethod(L, "Game", "createItem", GameFunctions::luaGameCreateItem); - registerMethod(L, "Game", "createContainer", GameFunctions::luaGameCreateContainer); - registerMethod(L, "Game", "createMonster", GameFunctions::luaGameCreateMonster); - registerMethod(L, "Game", "createNpc", GameFunctions::luaGameCreateNpc); - registerMethod(L, "Game", "generateNpc", GameFunctions::luaGameGenerateNpc); - registerMethod(L, "Game", "createTile", GameFunctions::luaGameCreateTile); - registerMethod(L, "Game", "createBestiaryCharm", GameFunctions::luaGameCreateBestiaryCharm); - - registerMethod(L, "Game", "createItemClassification", GameFunctions::luaGameCreateItemClassification); - - registerMethod(L, "Game", "getBestiaryCharm", GameFunctions::luaGameGetBestiaryCharm); - - registerMethod(L, "Game", "startRaid", GameFunctions::luaGameStartRaid); - - registerMethod(L, "Game", "getClientVersion", GameFunctions::luaGameGetClientVersion); - - registerMethod(L, "Game", "reload", GameFunctions::luaGameReload); - - registerMethod(L, "Game", "hasDistanceEffect", GameFunctions::luaGameHasDistanceEffect); - registerMethod(L, "Game", "hasEffect", GameFunctions::luaGameHasEffect); - registerMethod(L, "Game", "getOfflinePlayer", GameFunctions::luaGameGetOfflinePlayer); - registerMethod(L, "Game", "getNormalizedPlayerName", GameFunctions::luaGameGetNormalizedPlayerName); - registerMethod(L, "Game", "getNormalizedGuildName", GameFunctions::luaGameGetNormalizedGuildName); - - registerMethod(L, "Game", "addInfluencedMonster", GameFunctions::luaGameAddInfluencedMonster); - registerMethod(L, "Game", "removeInfluencedMonster", GameFunctions::luaGameRemoveInfluencedMonster); - registerMethod(L, "Game", "getInfluencedMonsters", GameFunctions::luaGameGetInfluencedMonsters); - registerMethod(L, "Game", "makeFiendishMonster", GameFunctions::luaGameMakeFiendishMonster); - registerMethod(L, "Game", "removeFiendishMonster", GameFunctions::luaGameRemoveFiendishMonster); - registerMethod(L, "Game", "getFiendishMonsters", GameFunctions::luaGameGetFiendishMonsters); - registerMethod(L, "Game", "getBoostedBoss", GameFunctions::luaGameGetBoostedBoss); - - registerMethod(L, "Game", "getLadderIds", GameFunctions::luaGameGetLadderIds); - registerMethod(L, "Game", "getDummies", GameFunctions::luaGameGetDummies); - - registerMethod(L, "Game", "getTalkActions", GameFunctions::luaGameGetTalkActions); - registerMethod(L, "Game", "getEventCallbacks", GameFunctions::luaGameGetEventCallbacks); - - registerMethod(L, "Game", "registerAchievement", GameFunctions::luaGameRegisterAchievement); - registerMethod(L, "Game", "getAchievementInfoById", GameFunctions::luaGameGetAchievementInfoById); - registerMethod(L, "Game", "getAchievementInfoByName", GameFunctions::luaGameGetAchievementInfoByName); - registerMethod(L, "Game", "getSecretAchievements", GameFunctions::luaGameGetSecretAchievements); - registerMethod(L, "Game", "getPublicAchievements", GameFunctions::luaGameGetPublicAchievements); - registerMethod(L, "Game", "getAchievements", GameFunctions::luaGameGetAchievements); - } + static void init(lua_State* L); private: static int luaGameCreateMonsterType(lua_State* L); diff --git a/src/lua/functions/core/game/global_functions.cpp b/src/lua/functions/core/game/global_functions.cpp index 14d87e5afb2..6eb21910701 100644 --- a/src/lua/functions/core/game/global_functions.cpp +++ b/src/lua/functions/core/game/global_functions.cpp @@ -10,9 +10,11 @@ #include "lua/functions/core/game/global_functions.hpp" #include "config/configmanager.hpp" +#include "creatures/creature.hpp" #include "creatures/combat/condition.hpp" #include "creatures/interactions/chat.hpp" #include "creatures/players/wheel/player_wheel.hpp" +#include "creatures/players/player.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" #include "game/scheduling/save_manager.hpp" @@ -22,6 +24,8 @@ #include "lua/scripts/lua_environment.hpp" #include "lua/scripts/script_environment.hpp" #include "server/network/protocol/protocolstatus.hpp" +#include "lua/functions/lua_functions_loader.hpp" +#include "creatures/players/player.hpp" void GlobalFunctions::init(lua_State* L) { lua_register(L, "addEvent", GlobalFunctions::luaAddEvent); @@ -53,30 +57,30 @@ void GlobalFunctions::init(lua_State* L) { lua_register(L, "sendGuildChannelMessage", GlobalFunctions::luaSendGuildChannelMessage); lua_register(L, "stopEvent", GlobalFunctions::luaStopEvent); - registerGlobalVariable(L, "INDEX_WHEREEVER", INDEX_WHEREEVER); - registerGlobalBoolean(L, "VIRTUAL_PARENT", true); - registerGlobalMethod(L, "isType", GlobalFunctions::luaIsType); - registerGlobalMethod(L, "rawgetmetatable", GlobalFunctions::luaRawGetMetatable); - registerGlobalMethod(L, "createTable", GlobalFunctions::luaCreateTable); - registerGlobalMethod(L, "systemTime", GlobalFunctions::luaSystemTime); - registerGlobalMethod(L, "getFormattedTimeRemaining", GlobalFunctions::luaGetFormattedTimeRemaining); - registerGlobalMethod(L, "reportError", GlobalFunctions::luaReportError); + Lua::registerGlobalVariable(L, "INDEX_WHEREEVER", INDEX_WHEREEVER); + Lua::registerGlobalBoolean(L, "VIRTUAL_PARENT", true); + Lua::registerGlobalMethod(L, "isType", GlobalFunctions::luaIsType); + Lua::registerGlobalMethod(L, "rawgetmetatable", GlobalFunctions::luaRawGetMetatable); + Lua::registerGlobalMethod(L, "createTable", GlobalFunctions::luaCreateTable); + Lua::registerGlobalMethod(L, "systemTime", GlobalFunctions::luaSystemTime); + Lua::registerGlobalMethod(L, "getFormattedTimeRemaining", GlobalFunctions::luaGetFormattedTimeRemaining); + Lua::registerGlobalMethod(L, "reportError", GlobalFunctions::luaReportError); } int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { // doPlayerAddItem(cid, itemid, count/subtype, canDropOnMap) // doPlayerAddItem(cid, itemid, count, canDropOnMap, subtype) - const auto &player = getPlayer(L, 1); + const auto &player = Lua::getPlayer(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint16_t itemId = getNumber(L, 2); - const auto count = getNumber(L, 3, 1); - const bool canDropOnMap = getBoolean(L, 4, true); - auto subType = getNumber(L, 5, 1); + const uint16_t itemId = Lua::getNumber(L, 2); + const auto count = Lua::getNumber(L, 3, 1); + const bool canDropOnMap = Lua::getBoolean(L, 4, true); + auto subType = Lua::getNumber(L, 5, 1); const ItemType &it = Item::items[itemId]; int32_t itemCount; @@ -104,8 +108,8 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { const auto &newItem = Item::CreateItem(itemId, stackCount); if (!newItem) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -115,66 +119,66 @@ int GlobalFunctions::luaDoPlayerAddItem(lua_State* L) { ReturnValue ret = g_game().internalPlayerAddItem(player, newItem, canDropOnMap); if (ret != RETURNVALUE_NOERROR) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } if (--itemCount == 0) { if (newItem->getParent()) { - const uint32_t uid = getScriptEnv()->addThing(newItem); + const uint32_t uid = Lua::getScriptEnv()->addThing(newItem); lua_pushnumber(L, uid); return 1; } else { // stackable item stacked with existing object, newItem will be released - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } } } - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } int GlobalFunctions::luaIsValidUID(lua_State* L) { // isValidUID(uid) - pushBoolean(L, getScriptEnv()->getThingByUID(getNumber(L, -1)) != nullptr); + Lua::pushBoolean(L, Lua::getScriptEnv()->getThingByUID(Lua::getNumber(L, -1)) != nullptr); return 1; } int GlobalFunctions::luaIsDepot(lua_State* L) { // isDepot(uid) - const auto &container = getScriptEnv()->getContainerByUID(getNumber(L, -1)); - pushBoolean(L, container && container->getDepotLocker()); + const auto &container = Lua::getScriptEnv()->getContainerByUID(Lua::getNumber(L, -1)); + Lua::pushBoolean(L, container && container->getDepotLocker()); return 1; } int GlobalFunctions::luaIsMovable(lua_State* L) { // isMovable(uid) // isMovable(uid) - const auto &thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); - pushBoolean(L, thing && thing->isPushable()); + const auto &thing = Lua::getScriptEnv()->getThingByUID(Lua::getNumber(L, -1)); + Lua::pushBoolean(L, thing && thing->isPushable()); return 1; } int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { // doAddContainerItem(uid, itemid, count/subtype) - const uint32_t uid = getNumber(L, 1); + const uint32_t uid = Lua::getNumber(L, 1); - ScriptEnvironment* env = getScriptEnv(); + ScriptEnvironment* env = Lua::getScriptEnv(); const auto &container = env->getContainerByUID(uid); if (!container) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint16_t itemId = getNumber(L, 2); + const uint16_t itemId = Lua::getNumber(L, 2); const ItemType &it = Item::items[itemId]; int32_t itemCount = 1; int32_t subType = 1; - const auto count = getNumber(L, 3, 1); + const auto count = Lua::getNumber(L, 3, 1); if (it.hasSubType()) { if (it.stackable) { @@ -190,8 +194,8 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { const int32_t stackCount = std::min(it.stackSize, subType); const auto &newItem = Item::CreateItem(itemId, stackCount); if (!newItem) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -201,7 +205,7 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { ReturnValue ret = g_game().internalAddItem(container, newItem); if (ret != RETURNVALUE_NOERROR) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -210,31 +214,31 @@ int GlobalFunctions::luaDoAddContainerItem(lua_State* L) { lua_pushnumber(L, env->addThing(newItem)); } else { // stackable item stacked with existing object, newItem will be released - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } } - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } int GlobalFunctions::luaGetDepotId(lua_State* L) { // getDepotId(uid) - const uint32_t uid = getNumber(L, -1); + const uint32_t uid = Lua::getNumber(L, -1); - const auto &container = getScriptEnv()->getContainerByUID(uid); + const auto &container = Lua::getScriptEnv()->getContainerByUID(uid); if (!container) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CONTAINER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &depotLocker = container->getDepotLocker(); if (!depotLocker) { - reportErrorFunc("Depot not found"); - pushBoolean(L, false); + Lua::reportErrorFunc("Depot not found"); + Lua::pushBoolean(L, false); return 1; } @@ -266,10 +270,10 @@ int GlobalFunctions::luaGetWorldUpTime(lua_State* L) { int GlobalFunctions::luaCreateCombatArea(lua_State* L) { // createCombatArea( {area}, {extArea} ) - const ScriptEnvironment* env = getScriptEnv(); + const ScriptEnvironment* env = Lua::getScriptEnv(); if (env->getScriptId() != EVENT_ID_LOADING) { - reportErrorFunc("This function can only be used while loading the script."); - pushBoolean(L, false); + Lua::reportErrorFunc("This function can only be used while loading the script."); + Lua::pushBoolean(L, false); return 1; } @@ -280,9 +284,9 @@ int GlobalFunctions::luaCreateCombatArea(lua_State* L) { if (parameters >= 2) { uint32_t rowsExtArea; std::list listExtArea; - if (!isTable(L, 2) || !getArea(L, listExtArea, rowsExtArea)) { - reportErrorFunc("Invalid extended area table."); - pushBoolean(L, false); + if (!Lua::isTable(L, 2) || !getArea(L, listExtArea, rowsExtArea)) { + Lua::reportErrorFunc("Invalid extended area table."); + Lua::pushBoolean(L, false); return 1; } area->setupExtArea(listExtArea, rowsExtArea); @@ -290,9 +294,9 @@ int GlobalFunctions::luaCreateCombatArea(lua_State* L) { uint32_t rowsArea = 0; std::list listArea; - if (!isTable(L, 1) || !getArea(L, listArea, rowsArea)) { - reportErrorFunc("Invalid area table."); - pushBoolean(L, false); + if (!Lua::isTable(L, 1) || !getArea(L, listArea, rowsArea)) { + Lua::reportErrorFunc("Invalid area table."); + Lua::pushBoolean(L, false); return 1; } @@ -303,73 +307,73 @@ int GlobalFunctions::luaCreateCombatArea(lua_State* L) { int GlobalFunctions::luaDoAreaCombatHealth(lua_State* L) { // doAreaCombatHealth(cid, type, pos, area, min, max, effect[, origin = ORIGIN_SPELL]) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint32_t areaId = getNumber(L, 4); + const uint32_t areaId = Lua::getNumber(L, 4); const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { - const CombatType_t combatType = getNumber(L, 2); + const CombatType_t combatType = Lua::getNumber(L, 2); CombatParams params; params.combatType = combatType; - params.impactEffect = getNumber(L, 7); + params.impactEffect = Lua::getNumber(L, 7); CombatDamage damage; - damage.origin = getNumber(L, 8, ORIGIN_SPELL); + damage.origin = Lua::getNumber(L, 8, ORIGIN_SPELL); damage.primary.type = combatType; - damage.primary.value = normal_random(getNumber(L, 6), getNumber(L, 5)); + damage.primary.value = normal_random(Lua::getNumber(L, 6), Lua::getNumber(L, 5)); - damage.instantSpellName = getString(L, 9); - damage.runeSpellName = getString(L, 10); + damage.instantSpellName = Lua::getString(L, 9); + damage.runeSpellName = Lua::getString(L, 10); if (creature) { if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } - Combat::doCombatHealth(creature, getPosition(L, 3), area, damage, params); - pushBoolean(L, true); + Combat::doCombatHealth(creature, Lua::getPosition(L, 3), area, damage, params); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { // doTargetCombatHealth(cid, target, type, min, max, effect[, origin = ORIGIN_SPELL]) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &target = getCreature(L, 2); + const auto &target = Lua::getCreature(L, 2); if (!target) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const CombatType_t combatType = getNumber(L, 3); + const CombatType_t combatType = Lua::getNumber(L, 3); CombatParams params; params.combatType = combatType; - params.impactEffect = getNumber(L, 6); + params.impactEffect = Lua::getNumber(L, 6); CombatDamage damage; - damage.origin = getNumber(L, 7, ORIGIN_SPELL); + damage.origin = Lua::getNumber(L, 7, ORIGIN_SPELL); damage.primary.type = combatType; - damage.primary.value = normal_random(getNumber(L, 4), getNumber(L, 5)); + damage.primary.value = normal_random(Lua::getNumber(L, 4), Lua::getNumber(L, 5)); - damage.instantSpellName = getString(L, 9); - damage.runeSpellName = getString(L, 10); + damage.instantSpellName = Lua::getString(L, 9); + damage.runeSpellName = Lua::getString(L, 10); if (creature) { if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); @@ -382,77 +386,77 @@ int GlobalFunctions::luaDoTargetCombatHealth(lua_State* L) { } Combat::doCombatHealth(creature, target, damage, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaDoAreaCombatMana(lua_State* L) { // doAreaCombatMana(cid, pos, area, min, max, effect[, origin = ORIGIN_SPELL]) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint32_t areaId = getNumber(L, 3); + const uint32_t areaId = Lua::getNumber(L, 3); const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; - params.impactEffect = getNumber(L, 6); + params.impactEffect = Lua::getNumber(L, 6); CombatDamage damage; - damage.origin = getNumber(L, 7, ORIGIN_SPELL); + damage.origin = Lua::getNumber(L, 7, ORIGIN_SPELL); damage.primary.type = COMBAT_MANADRAIN; - damage.primary.value = normal_random(getNumber(L, 4), getNumber(L, 5)); + damage.primary.value = normal_random(Lua::getNumber(L, 4), Lua::getNumber(L, 5)); - damage.instantSpellName = getString(L, 8); - damage.runeSpellName = getString(L, 9); + damage.instantSpellName = Lua::getString(L, 8); + damage.runeSpellName = Lua::getString(L, 9); if (creature) { if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); } } - const Position pos = getPosition(L, 2); + const Position pos = Lua::getPosition(L, 2); Combat::doCombatMana(creature, pos, area, damage, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { // doTargetCombatMana(cid, target, min, max, effect[, origin = ORIGIN_SPELL) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &target = getCreature(L, 2); + const auto &target = Lua::getCreature(L, 2); if (!target) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } CombatParams params; - const auto minval = getNumber(L, 3); - const auto maxval = getNumber(L, 4); + const auto minval = Lua::getNumber(L, 3); + const auto maxval = Lua::getNumber(L, 4); params.aggressive = minval + maxval < 0; - params.impactEffect = getNumber(L, 5); + params.impactEffect = Lua::getNumber(L, 5); CombatDamage damage; - damage.origin = getNumber(L, 6, ORIGIN_SPELL); + damage.origin = Lua::getNumber(L, 6, ORIGIN_SPELL); damage.primary.type = COMBAT_MANADRAIN; damage.primary.value = normal_random(minval, maxval); - damage.instantSpellName = getString(L, 7); - damage.runeSpellName = getString(L, 8); + damage.instantSpellName = Lua::getString(L, 7); + damage.runeSpellName = Lua::getString(L, 8); if (creature) { if (const auto &player = creature->getPlayer()) { player->wheel()->getCombatDataSpell(damage); @@ -460,142 +464,142 @@ int GlobalFunctions::luaDoTargetCombatMana(lua_State* L) { } Combat::doCombatMana(creature, target, damage, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaDoAreaCombatCondition(lua_State* L) { // doAreaCombatCondition(cid, pos, area, condition, effect) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &condition = getUserdataShared(L, 4); + const auto &condition = Lua::getUserdataShared(L, 4); if (!condition) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint32_t areaId = getNumber(L, 3); + const uint32_t areaId = Lua::getNumber(L, 3); const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; - params.impactEffect = getNumber(L, 5); + params.impactEffect = Lua::getNumber(L, 5); params.conditionList.emplace_back(condition); - Combat::doCombatCondition(creature, getPosition(L, 2), area, params); - pushBoolean(L, true); + Combat::doCombatCondition(creature, Lua::getPosition(L, 2), area, params); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int GlobalFunctions::luaDoTargetCombatCondition(lua_State* L) { // doTargetCombatCondition(cid, target, condition, effect) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &target = getCreature(L, 2); + const auto &target = Lua::getCreature(L, 2); if (!target) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &condition = getUserdataShared(L, 3); + const auto &condition = Lua::getUserdataShared(L, 3); if (!condition) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CONDITION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } CombatParams params; - params.impactEffect = getNumber(L, 4); + params.impactEffect = Lua::getNumber(L, 4); params.conditionList.emplace_back(condition->clone()); Combat::doCombatCondition(creature, target, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaDoAreaCombatDispel(lua_State* L) { // doAreaCombatDispel(cid, pos, area, type, effect) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint32_t areaId = getNumber(L, 3); + const uint32_t areaId = Lua::getNumber(L, 3); const auto &area = g_luaEnvironment().getAreaObject(areaId); if (area || areaId == 0) { CombatParams params; - params.impactEffect = getNumber(L, 5); - params.dispelType = getNumber(L, 4); - Combat::doCombatDispel(creature, getPosition(L, 2), area, params); + params.impactEffect = Lua::getNumber(L, 5); + params.dispelType = Lua::getNumber(L, 4); + Combat::doCombatDispel(creature, Lua::getPosition(L, 2), area, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int GlobalFunctions::luaDoTargetCombatDispel(lua_State* L) { // doTargetCombatDispel(cid, target, type, effect) - const auto &creature = getCreature(L, 1); - if (!creature && (!isNumber(L, 1) || getNumber(L, 1) != 0)) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + const auto &creature = Lua::getCreature(L, 1); + if (!creature && (!Lua::isNumber(L, 1) || Lua::getNumber(L, 1) != 0)) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &target = getCreature(L, 2); + const auto &target = Lua::getCreature(L, 2); if (!target) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } CombatParams params; - params.dispelType = getNumber(L, 3); - params.impactEffect = getNumber(L, 4); + params.dispelType = Lua::getNumber(L, 3); + params.impactEffect = Lua::getNumber(L, 4); Combat::doCombatDispel(creature, target, params); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaDoChallengeCreature(lua_State* L) { // doChallengeCreature(cid, target, targetChangeCooldown) - const auto &creature = getCreature(L, 1); + const auto &creature = Lua::getCreature(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &target = getCreature(L, 2); + const auto &target = Lua::getCreature(L, 2); if (!target) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const int targetChangeCooldown = getNumber(L, 3, 6000); + const int targetChangeCooldown = Lua::getNumber(L, 3, 6000); // This function must be defined to take and handle the targetChangeCooldown. target->challengeCreature(creature, targetChangeCooldown); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -603,17 +607,17 @@ int GlobalFunctions::luaAddEvent(lua_State* L) { // addEvent(callback, delay, ...) lua_State* globalState = g_luaEnvironment().getLuaState(); if (!globalState) { - reportErrorFunc("No valid script interface!"); - pushBoolean(L, false); + Lua::reportErrorFunc("No valid script interface!"); + Lua::pushBoolean(L, false); return 1; } else if (globalState != L) { lua_xmove(L, globalState, lua_gettop(L)); } const int parameters = lua_gettop(globalState); - if (!isFunction(globalState, -parameters)) { // -parameters means the first parameter from left to right - reportErrorFunc("callback parameter should be a function."); - pushBoolean(L, false); + if (!Lua::isFunction(globalState, -parameters)) { // -parameters means the first parameter from left to right + Lua::reportErrorFunc("callback parameter should be a function."); + Lua::pushBoolean(L, false); return 1; } @@ -625,7 +629,7 @@ int GlobalFunctions::luaAddEvent(lua_State* L) { } lua_rawgeti(L, -1, 't'); - LuaData_t type = getNumber(L, -1); + LuaData_t type = Lua::getNumber(L, -1); if (type != LuaData_t::Unknown && type <= LuaData_t::Npc) { indexes.emplace_back(i, type); } @@ -659,7 +663,7 @@ int GlobalFunctions::luaAddEvent(lua_State* L) { warningString += " is unsafe"; } - reportErrorFunc(warningString); + Lua::reportErrorFunc(warningString); } if (g_configManager().getBoolean(CONVERT_UNSAFE_SCRIPTS)) { @@ -696,12 +700,12 @@ int GlobalFunctions::luaAddEvent(lua_State* L) { eventDesc.parameters.push_back(luaL_ref(globalState, LUA_REGISTRYINDEX)); } - const uint32_t delay = std::max(100, getNumber(globalState, 2)); + const uint32_t delay = std::max(100, Lua::getNumber(globalState, 2)); lua_pop(globalState, 1); eventDesc.function = luaL_ref(globalState, LUA_REGISTRYINDEX); - eventDesc.scriptId = getScriptEnv()->getScriptId(); - eventDesc.scriptName = getScriptEnv()->getScriptInterface()->getLoadingScriptName(); + eventDesc.scriptId = Lua::getScriptEnv()->getScriptId(); + eventDesc.scriptName = Lua::getScriptEnv()->getScriptInterface()->getLoadingScriptName(); auto &lastTimerEventId = g_luaEnvironment().lastEventTimerId; eventDesc.eventId = g_dispatcher().scheduleEvent( @@ -719,17 +723,17 @@ int GlobalFunctions::luaStopEvent(lua_State* L) { // stopEvent(eventid) lua_State* globalState = g_luaEnvironment().getLuaState(); if (!globalState) { - reportErrorFunc("No valid script interface!"); - pushBoolean(L, false); + Lua::reportErrorFunc("No valid script interface!"); + Lua::pushBoolean(L, false); return 1; } - const uint32_t eventId = getNumber(L, 1); + const uint32_t eventId = Lua::getNumber(L, 1); auto &timerEvents = g_luaEnvironment().timerEvents; const auto it = timerEvents.find(eventId); if (it == timerEvents.end()) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -743,14 +747,14 @@ int GlobalFunctions::luaStopEvent(lua_State* L) { luaL_unref(globalState, LUA_REGISTRYINDEX, parameter); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaSaveServer(lua_State* L) { g_globalEvents().save(); g_saveManager().scheduleAll(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -761,27 +765,27 @@ int GlobalFunctions::luaCleanMap(lua_State* L) { int GlobalFunctions::luaDebugPrint(lua_State* L) { // debugPrint(text) - reportErrorFunc(getString(L, -1)); + Lua::reportErrorFunc(Lua::getString(L, -1)); return 0; } int GlobalFunctions::luaIsInWar(lua_State* L) { // isInWar(cid, target) - const auto &player = getPlayer(L, 1); + const auto &player = Lua::getPlayer(L, 1); if (!player) { - reportErrorFunc(fmt::format("{} - Player", getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); - pushBoolean(L, false); + Lua::reportErrorFunc(fmt::format("{} - Player", Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); + Lua::pushBoolean(L, false); return 1; } - const auto &targetPlayer = getPlayer(L, 2); + const auto &targetPlayer = Lua::getPlayer(L, 2); if (!targetPlayer) { - reportErrorFunc(fmt::format("{} - TargetPlayer", getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); - pushBoolean(L, false); + Lua::reportErrorFunc(fmt::format("{} - TargetPlayer", Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND))); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, player->isInWar(targetPlayer)); + Lua::pushBoolean(L, player->isInWar(targetPlayer)); return 1; } @@ -789,44 +793,44 @@ int GlobalFunctions::luaGetWaypointPositionByName(lua_State* L) { // getWaypointPositionByName(name) auto &waypoints = g_game().map.waypoints; - const auto it = waypoints.find(getString(L, -1)); + const auto it = waypoints.find(Lua::getString(L, -1)); if (it != waypoints.end()) { - pushPosition(L, it->second); + Lua::pushPosition(L, it->second); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int GlobalFunctions::luaSendChannelMessage(lua_State* L) { // sendChannelMessage(channelId, type, message) - const uint16_t channelId = getNumber(L, 1); + const uint16_t channelId = Lua::getNumber(L, 1); const auto &channel = g_chat().getChannelById(channelId); if (!channel) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const SpeakClasses type = getNumber(L, 2); - const std::string message = getString(L, 3); + const SpeakClasses type = Lua::getNumber(L, 2); + const std::string message = Lua::getString(L, 3); channel->sendToAll(message, type); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GlobalFunctions::luaSendGuildChannelMessage(lua_State* L) { // sendGuildChannelMessage(guildId, type, message) - const uint32_t guildId = getNumber(L, 1); + const uint32_t guildId = Lua::getNumber(L, 1); const auto &channel = g_chat().getGuildChannelById(guildId); if (!channel) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const SpeakClasses type = getNumber(L, 2); - const std::string message = getString(L, 3); + const SpeakClasses type = Lua::getNumber(L, 2); + const std::string message = Lua::getString(L, 3); channel->sendToAll(message, type); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -836,34 +840,34 @@ int GlobalFunctions::luaIsType(lua_State* L) { lua_getmetatable(L, -2); lua_rawgeti(L, -2, 'p'); - const uint_fast8_t parentsB = getNumber(L, 1); + const uint_fast8_t parentsB = Lua::getNumber(L, 1); lua_rawgeti(L, -3, 'h'); - const size_t hashB = getNumber(L, 1); + const size_t hashB = Lua::getNumber(L, 1); lua_rawgeti(L, -3, 'p'); - const uint_fast8_t parentsA = getNumber(L, 1); + const uint_fast8_t parentsA = Lua::getNumber(L, 1); for (uint_fast8_t i = parentsA; i < parentsB; ++i) { lua_getfield(L, -3, "__index"); lua_replace(L, -4); } lua_rawgeti(L, -4, 'h'); - const size_t hashA = getNumber(L, 1); + const size_t hashA = Lua::getNumber(L, 1); - pushBoolean(L, hashA == hashB); + Lua::pushBoolean(L, hashA == hashB); return 1; } int GlobalFunctions::luaRawGetMetatable(lua_State* L) { // rawgetmetatable(metatableName) - luaL_getmetatable(L, getString(L, 1).c_str()); + luaL_getmetatable(L, Lua::getString(L, 1).c_str()); return 1; } int GlobalFunctions::luaCreateTable(lua_State* L) { // createTable(arrayLength, keyLength) - lua_createtable(L, getNumber(L, 1), getNumber(L, 2)); + lua_createtable(L, Lua::getNumber(L, 1), Lua::getNumber(L, 2)); return 1; } @@ -875,31 +879,31 @@ int GlobalFunctions::luaSystemTime(lua_State* L) { int GlobalFunctions::luaGetFormattedTimeRemaining(lua_State* L) { // getFormattedTimeRemaining(time) - const time_t time = getNumber(L, 1); + const time_t time = Lua::getNumber(L, 1); lua_pushstring(L, getFormattedTimeRemaining(time).c_str()); return 1; } int GlobalFunctions::luaReportError(lua_State* L) { // reportError(errorDescription) - const auto errorDescription = getString(L, 1); - reportError(__func__, errorDescription, true); + const auto errorDescription = Lua::getString(L, 1); + Lua::reportError(__func__, errorDescription, true); return 1; } bool GlobalFunctions::getArea(lua_State* L, std::list &list, uint32_t &rows) { lua_pushnil(L); for (rows = 0; lua_next(L, -2) != 0; ++rows) { - if (!isTable(L, -1)) { + if (!Lua::isTable(L, -1)) { return false; } lua_pushnil(L); while (lua_next(L, -2) != 0) { - if (!isNumber(L, -1)) { + if (!Lua::isNumber(L, -1)) { return false; } - list.push_back(getNumber(L, -1)); + list.push_back(Lua::getNumber(L, -1)); lua_pop(L, 1); } diff --git a/src/lua/functions/core/game/global_functions.hpp b/src/lua/functions/core/game/global_functions.hpp index 9d4ce14b1cf..7ed0c177c88 100644 --- a/src/lua/functions/core/game/global_functions.hpp +++ b/src/lua/functions/core/game/global_functions.hpp @@ -9,16 +9,8 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class GlobalFunctions final : LuaScriptInterface { +class GlobalFunctions { public: - explicit GlobalFunctions(lua_State* L) : - LuaScriptInterface("GlobalFunctions") { - init(L); - } - ~GlobalFunctions() override = default; - static void init(lua_State* L); private: diff --git a/src/lua/functions/core/game/lua_enums.cpp b/src/lua/functions/core/game/lua_enums.cpp index 5a03fa246fa..2136a3e5927 100644 --- a/src/lua/functions/core/game/lua_enums.cpp +++ b/src/lua/functions/core/game/lua_enums.cpp @@ -15,6 +15,7 @@ #include "enums/item_attribute.hpp" #include "game/functions/game_reload.hpp" #include "io/io_bosstiary.hpp" +#include "lua/functions/lua_functions_loader.hpp" constexpr const char* soundNamespace = "SOUND_EFFECT_TYPE_"; @@ -22,7 +23,7 @@ constexpr const char* soundNamespace = "SOUND_EFFECT_TYPE_"; { \ auto number = magic_enum::enum_integer(enumClassType); \ auto name = magic_enum::enum_name(enumClassType).data(); \ - registerGlobalVariable(luaState, name, number); \ + Lua::registerGlobalVariable(luaState, name, number); \ } \ void(0) @@ -30,15 +31,15 @@ constexpr const char* soundNamespace = "SOUND_EFFECT_TYPE_"; { \ auto number = magic_enum::enum_integer(enumClassType); \ auto name = std::string(luaNamespace) + magic_enum::enum_name(enumClassType).data(); \ - registerGlobalVariable(luaState, name, number); \ + Lua::registerGlobalVariable(luaState, name, number); \ } \ void(0) -#define registerEnum(L, value) \ - { \ - std::string enumName = #value; \ - registerGlobalVariable(L, enumName.substr(enumName.find_last_of(':') + 1), value); \ - } \ +#define registerEnum(L, value) \ + { \ + std::string enumName = #value; \ + Lua::registerGlobalVariable(L, enumName.substr(enumName.find_last_of(':') + 1), value); \ + } \ void(0) /** @@ -55,7 +56,7 @@ is "SILENCE", the registered full name will be "SOUND_EFFECT_TYPE_SILENCE". { \ std::string enumName = #enumValue; \ std::string enumNameWithNamespace = std::string(luaNamespace) + std::string(enumName.substr(enumName.find_last_of(':') + 1)); \ - registerGlobalVariable(L, enumNameWithNamespace, enumValue); \ + Lua::registerGlobalVariable(L, enumNameWithNamespace, enumValue); \ } \ void(0) @@ -792,7 +793,7 @@ void LuaEnums::initItemAttributeEnums(lua_State* L) { auto number = magic_enum::enum_integer(value); // Creation of the "ITEM_ATTRIBUTE_" namespace for lua scripts std::string enumName = "ITEM_ATTRIBUTE_" + std::string(magic_enum::enum_name(value)); - registerGlobalVariable(L, enumName, static_cast(number)); + Lua::registerGlobalVariable(L, enumName, static_cast(number)); } } diff --git a/src/lua/functions/core/game/lua_enums.hpp b/src/lua/functions/core/game/lua_enums.hpp index 44c79da7a31..465cc96afc3 100644 --- a/src/lua/functions/core/game/lua_enums.hpp +++ b/src/lua/functions/core/game/lua_enums.hpp @@ -9,16 +9,8 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class LuaEnums final : LuaScriptInterface { +class LuaEnums { public: - explicit LuaEnums(lua_State* L) : - LuaScriptInterface("LuaEnums") { - init(L); - } - ~LuaEnums() override = default; - static void init(lua_State* L); private: diff --git a/src/lua/functions/core/game/modal_window_functions.cpp b/src/lua/functions/core/game/modal_window_functions.cpp index 95994450424..9d288716137 100644 --- a/src/lua/functions/core/game/modal_window_functions.cpp +++ b/src/lua/functions/core/game/modal_window_functions.cpp @@ -11,22 +11,52 @@ #include "creatures/players/player.hpp" #include "game/modal_window/modal_window.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ModalWindowFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "ModalWindow", "", ModalWindowFunctions::luaModalWindowCreate); + Lua::registerMetaMethod(L, "ModalWindow", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "ModalWindow", "getId", ModalWindowFunctions::luaModalWindowGetId); + Lua::registerMethod(L, "ModalWindow", "getTitle", ModalWindowFunctions::luaModalWindowGetTitle); + Lua::registerMethod(L, "ModalWindow", "getMessage", ModalWindowFunctions::luaModalWindowGetMessage); + + Lua::registerMethod(L, "ModalWindow", "setTitle", ModalWindowFunctions::luaModalWindowSetTitle); + Lua::registerMethod(L, "ModalWindow", "setMessage", ModalWindowFunctions::luaModalWindowSetMessage); + + Lua::registerMethod(L, "ModalWindow", "getButtonCount", ModalWindowFunctions::luaModalWindowGetButtonCount); + Lua::registerMethod(L, "ModalWindow", "getChoiceCount", ModalWindowFunctions::luaModalWindowGetChoiceCount); + + Lua::registerMethod(L, "ModalWindow", "addButton", ModalWindowFunctions::luaModalWindowAddButton); + Lua::registerMethod(L, "ModalWindow", "addChoice", ModalWindowFunctions::luaModalWindowAddChoice); + + Lua::registerMethod(L, "ModalWindow", "getDefaultEnterButton", ModalWindowFunctions::luaModalWindowGetDefaultEnterButton); + Lua::registerMethod(L, "ModalWindow", "setDefaultEnterButton", ModalWindowFunctions::luaModalWindowSetDefaultEnterButton); + + Lua::registerMethod(L, "ModalWindow", "getDefaultEscapeButton", ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton); + Lua::registerMethod(L, "ModalWindow", "setDefaultEscapeButton", ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton); + + Lua::registerMethod(L, "ModalWindow", "hasPriority", ModalWindowFunctions::luaModalWindowHasPriority); + Lua::registerMethod(L, "ModalWindow", "setPriority", ModalWindowFunctions::luaModalWindowSetPriority); + + Lua::registerMethod(L, "ModalWindow", "sendToPlayer", ModalWindowFunctions::luaModalWindowSendToPlayer); +} // ModalWindow int ModalWindowFunctions::luaModalWindowCreate(lua_State* L) { // ModalWindow(id, title, message) - const std::string &message = getString(L, 4); - const std::string &title = getString(L, 3); - uint32_t id = getNumber(L, 2); + const std::string &message = Lua::getString(L, 4); + const std::string &title = Lua::getString(L, 3); + uint32_t id = Lua::getNumber(L, 2); - pushUserdata(L, std::make_shared(id, title, message)); - setMetatable(L, -1, "ModalWindow"); + Lua::pushUserdata(L, std::make_shared(id, title, message)); + Lua::setMetatable(L, -1, "ModalWindow"); return 1; } int ModalWindowFunctions::luaModalWindowGetId(lua_State* L) { // modalWindow:getId() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->id); } else { @@ -37,9 +67,9 @@ int ModalWindowFunctions::luaModalWindowGetId(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetTitle(lua_State* L) { // modalWindow:getTitle() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - pushString(L, window->title); + Lua::pushString(L, window->title); } else { lua_pushnil(L); } @@ -48,9 +78,9 @@ int ModalWindowFunctions::luaModalWindowGetTitle(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetMessage(lua_State* L) { // modalWindow:getMessage() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - pushString(L, window->message); + Lua::pushString(L, window->message); } else { lua_pushnil(L); } @@ -59,11 +89,11 @@ int ModalWindowFunctions::luaModalWindowGetMessage(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetTitle(lua_State* L) { // modalWindow:setTitle(text) - const std::string &text = getString(L, 2); - const auto &window = getUserdataShared(L, 1); + const std::string &text = Lua::getString(L, 2); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { window->title = text; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -72,11 +102,11 @@ int ModalWindowFunctions::luaModalWindowSetTitle(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetMessage(lua_State* L) { // modalWindow:setMessage(text) - const std::string &text = getString(L, 2); - const auto &window = getUserdataShared(L, 1); + const std::string &text = Lua::getString(L, 2); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { window->message = text; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -85,7 +115,7 @@ int ModalWindowFunctions::luaModalWindowSetMessage(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetButtonCount(lua_State* L) { // modalWindow:getButtonCount() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->buttons.size()); } else { @@ -96,7 +126,7 @@ int ModalWindowFunctions::luaModalWindowGetButtonCount(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetChoiceCount(lua_State* L) { // modalWindow:getChoiceCount() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->choices.size()); } else { @@ -107,12 +137,12 @@ int ModalWindowFunctions::luaModalWindowGetChoiceCount(lua_State* L) { int ModalWindowFunctions::luaModalWindowAddButton(lua_State* L) { // modalWindow:addButton(id, text) - const std::string &text = getString(L, 3); - uint8_t id = getNumber(L, 2); - const auto &window = getUserdataShared(L, 1); + const std::string &text = Lua::getString(L, 3); + uint8_t id = Lua::getNumber(L, 2); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { window->buttons.emplace_back(text, id); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -121,12 +151,12 @@ int ModalWindowFunctions::luaModalWindowAddButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowAddChoice(lua_State* L) { // modalWindow:addChoice(id, text) - const std::string &text = getString(L, 3); - uint8_t id = getNumber(L, 2); - const auto &window = getUserdataShared(L, 1); + const std::string &text = Lua::getString(L, 3); + uint8_t id = Lua::getNumber(L, 2); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { window->choices.emplace_back(text, id); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -135,7 +165,7 @@ int ModalWindowFunctions::luaModalWindowAddChoice(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetDefaultEnterButton(lua_State* L) { // modalWindow:getDefaultEnterButton() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->defaultEnterButton); } else { @@ -146,10 +176,10 @@ int ModalWindowFunctions::luaModalWindowGetDefaultEnterButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetDefaultEnterButton(lua_State* L) { // modalWindow:setDefaultEnterButton(buttonId) - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - window->defaultEnterButton = getNumber(L, 2); - pushBoolean(L, true); + window->defaultEnterButton = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -158,7 +188,7 @@ int ModalWindowFunctions::luaModalWindowSetDefaultEnterButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton(lua_State* L) { // modalWindow:getDefaultEscapeButton() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { lua_pushnumber(L, window->defaultEscapeButton); } else { @@ -169,10 +199,10 @@ int ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton(lua_State* L) { // modalWindow:setDefaultEscapeButton(buttonId) - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - window->defaultEscapeButton = getNumber(L, 2); - pushBoolean(L, true); + window->defaultEscapeButton = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -181,9 +211,9 @@ int ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton(lua_State* L) { int ModalWindowFunctions::luaModalWindowHasPriority(lua_State* L) { // modalWindow:hasPriority() - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - pushBoolean(L, window->priority); + Lua::pushBoolean(L, window->priority); } else { lua_pushnil(L); } @@ -192,10 +222,10 @@ int ModalWindowFunctions::luaModalWindowHasPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { // modalWindow:setPriority(priority) - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { - window->priority = getBoolean(L, 2); - pushBoolean(L, true); + window->priority = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -204,18 +234,18 @@ int ModalWindowFunctions::luaModalWindowSetPriority(lua_State* L) { int ModalWindowFunctions::luaModalWindowSendToPlayer(lua_State* L) { // modalWindow:sendToPlayer(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &window = getUserdataShared(L, 1); + const auto &window = Lua::getUserdataShared(L, 1); if (window) { if (!player->hasModalWindowOpen(window->id)) { player->sendModalWindow(*window); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/core/game/modal_window_functions.hpp b/src/lua/functions/core/game/modal_window_functions.hpp index 1e2242d8570..83867888d89 100644 --- a/src/lua/functions/core/game/modal_window_functions.hpp +++ b/src/lua/functions/core/game/modal_window_functions.hpp @@ -9,44 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ModalWindowFunctions final : LuaScriptInterface { +class ModalWindowFunctions { public: - explicit ModalWindowFunctions(lua_State* L) : - LuaScriptInterface("ModalWindowFunctions") { - init(L); - } - ~ModalWindowFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "ModalWindow", "", ModalWindowFunctions::luaModalWindowCreate); - registerMetaMethod(L, "ModalWindow", "__eq", ModalWindowFunctions::luaUserdataCompare); - - registerMethod(L, "ModalWindow", "getId", ModalWindowFunctions::luaModalWindowGetId); - registerMethod(L, "ModalWindow", "getTitle", ModalWindowFunctions::luaModalWindowGetTitle); - registerMethod(L, "ModalWindow", "getMessage", ModalWindowFunctions::luaModalWindowGetMessage); - - registerMethod(L, "ModalWindow", "setTitle", ModalWindowFunctions::luaModalWindowSetTitle); - registerMethod(L, "ModalWindow", "setMessage", ModalWindowFunctions::luaModalWindowSetMessage); - - registerMethod(L, "ModalWindow", "getButtonCount", ModalWindowFunctions::luaModalWindowGetButtonCount); - registerMethod(L, "ModalWindow", "getChoiceCount", ModalWindowFunctions::luaModalWindowGetChoiceCount); - - registerMethod(L, "ModalWindow", "addButton", ModalWindowFunctions::luaModalWindowAddButton); - registerMethod(L, "ModalWindow", "addChoice", ModalWindowFunctions::luaModalWindowAddChoice); - - registerMethod(L, "ModalWindow", "getDefaultEnterButton", ModalWindowFunctions::luaModalWindowGetDefaultEnterButton); - registerMethod(L, "ModalWindow", "setDefaultEnterButton", ModalWindowFunctions::luaModalWindowSetDefaultEnterButton); - - registerMethod(L, "ModalWindow", "getDefaultEscapeButton", ModalWindowFunctions::luaModalWindowGetDefaultEscapeButton); - registerMethod(L, "ModalWindow", "setDefaultEscapeButton", ModalWindowFunctions::luaModalWindowSetDefaultEscapeButton); - - registerMethod(L, "ModalWindow", "hasPriority", ModalWindowFunctions::luaModalWindowHasPriority); - registerMethod(L, "ModalWindow", "setPriority", ModalWindowFunctions::luaModalWindowSetPriority); - - registerMethod(L, "ModalWindow", "sendToPlayer", ModalWindowFunctions::luaModalWindowSendToPlayer); - } + static void init(lua_State* L); private: static int luaModalWindowCreate(lua_State* L); diff --git a/src/lua/functions/core/game/zone_functions.cpp b/src/lua/functions/core/game/zone_functions.cpp index e53c777d675..43fe586997a 100644 --- a/src/lua/functions/core/game/zone_functions.cpp +++ b/src/lua/functions/core/game/zone_functions.cpp @@ -11,111 +11,141 @@ #include "game/zones/zone.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ZoneFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Zone", "", ZoneFunctions::luaZoneCreate); + Lua::registerMetaMethod(L, "Zone", "__eq", ZoneFunctions::luaZoneCompare); + + Lua::registerMethod(L, "Zone", "getName", ZoneFunctions::luaZoneGetName); + Lua::registerMethod(L, "Zone", "addArea", ZoneFunctions::luaZoneAddArea); + Lua::registerMethod(L, "Zone", "subtractArea", ZoneFunctions::luaZoneSubtractArea); + Lua::registerMethod(L, "Zone", "getRemoveDestination", ZoneFunctions::luaZoneGetRemoveDestination); + Lua::registerMethod(L, "Zone", "setRemoveDestination", ZoneFunctions::luaZoneSetRemoveDestination); + Lua::registerMethod(L, "Zone", "getPositions", ZoneFunctions::luaZoneGetPositions); + Lua::registerMethod(L, "Zone", "getCreatures", ZoneFunctions::luaZoneGetCreatures); + Lua::registerMethod(L, "Zone", "getPlayers", ZoneFunctions::luaZoneGetPlayers); + Lua::registerMethod(L, "Zone", "getMonsters", ZoneFunctions::luaZoneGetMonsters); + Lua::registerMethod(L, "Zone", "getNpcs", ZoneFunctions::luaZoneGetNpcs); + Lua::registerMethod(L, "Zone", "getItems", ZoneFunctions::luaZoneGetItems); + + Lua::registerMethod(L, "Zone", "removePlayers", ZoneFunctions::luaZoneRemovePlayers); + Lua::registerMethod(L, "Zone", "removeMonsters", ZoneFunctions::luaZoneRemoveMonsters); + Lua::registerMethod(L, "Zone", "removeNpcs", ZoneFunctions::luaZoneRemoveNpcs); + Lua::registerMethod(L, "Zone", "refresh", ZoneFunctions::luaZoneRefresh); + + Lua::registerMethod(L, "Zone", "setMonsterVariant", ZoneFunctions::luaZoneSetMonsterVariant); + + // static methods + Lua::registerMethod(L, "Zone", "getByPosition", ZoneFunctions::luaZoneGetByPosition); + Lua::registerMethod(L, "Zone", "getByName", ZoneFunctions::luaZoneGetByName); + Lua::registerMethod(L, "Zone", "getAll", ZoneFunctions::luaZoneGetAll); +} // Zone int ZoneFunctions::luaZoneCreate(lua_State* L) { // Zone(name) - const auto name = getString(L, 2); + const auto name = Lua::getString(L, 2); auto zone = Zone::getZone(name); if (!zone) { zone = Zone::addZone(name); } - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); return 1; } int ZoneFunctions::luaZoneCompare(lua_State* L) { - const auto &zone1 = getUserdataShared(L, 1); - const auto &zone2 = getUserdataShared(L, 2); + const auto &zone1 = Lua::getUserdataShared(L, 1); + const auto &zone2 = Lua::getUserdataShared(L, 2); if (!zone1) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (!zone2) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, zone1->getName() == zone2->getName()); + Lua::pushBoolean(L, zone1->getName() == zone2->getName()); return 1; } int ZoneFunctions::luaZoneGetName(lua_State* L) { // Zone:getName() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushString(L, zone->getName()); + Lua::pushString(L, zone->getName()); return 1; } int ZoneFunctions::luaZoneAddArea(lua_State* L) { // Zone:addArea(fromPos, toPos) - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto fromPos = getPosition(L, 2); - const auto toPos = getPosition(L, 3); + const auto fromPos = Lua::getPosition(L, 2); + const auto toPos = Lua::getPosition(L, 3); const auto area = Area(fromPos, toPos); zone->addArea(area); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ZoneFunctions::luaZoneSubtractArea(lua_State* L) { // Zone:subtractArea(fromPos, toPos) - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto fromPos = getPosition(L, 2); - const auto toPos = getPosition(L, 3); + const auto fromPos = Lua::getPosition(L, 2); + const auto toPos = Lua::getPosition(L, 3); const auto area = Area(fromPos, toPos); zone->subtractArea(area); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ZoneFunctions::luaZoneGetRemoveDestination(lua_State* L) { // Zone:getRemoveDestination() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); return 1; } - pushPosition(L, zone->getRemoveDestination()); + Lua::pushPosition(L, zone->getRemoveDestination()); return 1; } int ZoneFunctions::luaZoneSetRemoveDestination(lua_State* L) { // Zone:setRemoveDestination(pos) - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); return 1; } - const auto pos = getPosition(L, 2); + const auto pos = Lua::getPosition(L, 2); zone->setRemoveDestination(pos); return 1; } int ZoneFunctions::luaZoneGetPositions(lua_State* L) { // Zone:getPositions() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto positions = zone->getPositions(); @@ -124,7 +154,7 @@ int ZoneFunctions::luaZoneGetPositions(lua_State* L) { int index = 0; for (auto pos : positions) { index++; - pushPosition(L, pos); + Lua::pushPosition(L, pos); lua_rawseti(L, -2, index); } return 1; @@ -132,10 +162,10 @@ int ZoneFunctions::luaZoneGetPositions(lua_State* L) { int ZoneFunctions::luaZoneGetCreatures(lua_State* L) { // Zone:getCreatures() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &creatures = zone->getCreatures(); @@ -144,8 +174,8 @@ int ZoneFunctions::luaZoneGetCreatures(lua_State* L) { int index = 0; for (const auto &creature : creatures) { index++; - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, index); } return 1; @@ -153,10 +183,10 @@ int ZoneFunctions::luaZoneGetCreatures(lua_State* L) { int ZoneFunctions::luaZoneGetPlayers(lua_State* L) { // Zone:getPlayers() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &players = zone->getPlayers(); @@ -165,8 +195,8 @@ int ZoneFunctions::luaZoneGetPlayers(lua_State* L) { int index = 0; for (const auto &player : players) { index++; - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); lua_rawseti(L, -2, index); } return 1; @@ -174,10 +204,10 @@ int ZoneFunctions::luaZoneGetPlayers(lua_State* L) { int ZoneFunctions::luaZoneGetMonsters(lua_State* L) { // Zone:getMonsters() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &monsters = zone->getMonsters(); @@ -186,8 +216,8 @@ int ZoneFunctions::luaZoneGetMonsters(lua_State* L) { int index = 0; for (const auto &monster : monsters) { index++; - pushUserdata(L, monster); - setMetatable(L, -1, "Monster"); + Lua::pushUserdata(L, monster); + Lua::setMetatable(L, -1, "Monster"); lua_rawseti(L, -2, index); } return 1; @@ -195,10 +225,10 @@ int ZoneFunctions::luaZoneGetMonsters(lua_State* L) { int ZoneFunctions::luaZoneGetNpcs(lua_State* L) { // Zone:getNpcs() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &npcs = zone->getNpcs(); @@ -207,8 +237,8 @@ int ZoneFunctions::luaZoneGetNpcs(lua_State* L) { int index = 0; for (const auto &npc : npcs) { index++; - pushUserdata(L, npc); - setMetatable(L, -1, "Npc"); + Lua::pushUserdata(L, npc); + Lua::setMetatable(L, -1, "Npc"); lua_rawseti(L, -2, index); } return 1; @@ -216,10 +246,10 @@ int ZoneFunctions::luaZoneGetNpcs(lua_State* L) { int ZoneFunctions::luaZoneGetItems(lua_State* L) { // Zone:getItems() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &items = zone->getItems(); @@ -228,8 +258,8 @@ int ZoneFunctions::luaZoneGetItems(lua_State* L) { int index = 0; for (const auto &item : items) { index++; - pushUserdata(L, item); - setMetatable(L, -1, "Item"); + Lua::pushUserdata(L, item); + Lua::setMetatable(L, -1, "Item"); lua_rawseti(L, -2, index); } return 1; @@ -237,10 +267,10 @@ int ZoneFunctions::luaZoneGetItems(lua_State* L) { int ZoneFunctions::luaZoneRemovePlayers(lua_State* L) { // Zone:removePlayers() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -250,10 +280,10 @@ int ZoneFunctions::luaZoneRemovePlayers(lua_State* L) { int ZoneFunctions::luaZoneRemoveMonsters(lua_State* L) { // Zone:removeMonsters() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } zone->removeMonsters(); @@ -262,10 +292,10 @@ int ZoneFunctions::luaZoneRemoveMonsters(lua_State* L) { int ZoneFunctions::luaZoneRemoveNpcs(lua_State* L) { // Zone:removeNpcs() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } zone->removeNpcs(); @@ -274,38 +304,38 @@ int ZoneFunctions::luaZoneRemoveNpcs(lua_State* L) { int ZoneFunctions::luaZoneSetMonsterVariant(lua_State* L) { // Zone:setMonsterVariant(variant) - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto variant = getString(L, 2); + const auto variant = Lua::getString(L, 2); if (variant.empty()) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } zone->setMonsterVariant(variant); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ZoneFunctions::luaZoneGetByName(lua_State* L) { // Zone.getByName(name) - const auto name = getString(L, 1); + const auto name = Lua::getString(L, 1); const auto &zone = Zone::getZone(name); if (!zone) { lua_pushnil(L); return 1; } - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); return 1; } int ZoneFunctions::luaZoneGetByPosition(lua_State* L) { // Zone.getByPosition(pos) - const auto pos = getPosition(L, 1); + const auto pos = Lua::getPosition(L, 1); const auto &tile = g_game().map.getTile(pos); if (!tile) { lua_pushnil(L); @@ -316,8 +346,8 @@ int ZoneFunctions::luaZoneGetByPosition(lua_State* L) { lua_createtable(L, static_cast(zones.size()), 0); for (const auto &zone : zones) { index++; - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); lua_rawseti(L, -2, index); } return 1; @@ -330,8 +360,8 @@ int ZoneFunctions::luaZoneGetAll(lua_State* L) { int index = 0; for (const auto &zone : zones) { index++; - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); lua_rawseti(L, -2, index); } return 1; @@ -339,9 +369,9 @@ int ZoneFunctions::luaZoneGetAll(lua_State* L) { int ZoneFunctions::luaZoneRefresh(lua_State* L) { // Zone:refresh() - const auto &zone = getUserdataShared(L, 1); + const auto &zone = Lua::getUserdataShared(L, 1); if (!zone) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ZONE_NOT_FOUND)); return 1; } zone->refresh(); diff --git a/src/lua/functions/core/game/zone_functions.hpp b/src/lua/functions/core/game/zone_functions.hpp index 0860595f0a8..cf1fa7cd73e 100644 --- a/src/lua/functions/core/game/zone_functions.hpp +++ b/src/lua/functions/core/game/zone_functions.hpp @@ -1,45 +1,10 @@ #pragma once -#include "lua/scripts/luascript.hpp" - class Zone; -class ZoneFunctions final : LuaScriptInterface { +class ZoneFunctions { public: - explicit ZoneFunctions(lua_State* L) : - LuaScriptInterface("ZoneFunctions") { - init(L); - } - ~ZoneFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Zone", "", ZoneFunctions::luaZoneCreate); - registerMetaMethod(L, "Zone", "__eq", ZoneFunctions::luaZoneCompare); - - registerMethod(L, "Zone", "getName", ZoneFunctions::luaZoneGetName); - registerMethod(L, "Zone", "addArea", ZoneFunctions::luaZoneAddArea); - registerMethod(L, "Zone", "subtractArea", ZoneFunctions::luaZoneSubtractArea); - registerMethod(L, "Zone", "getRemoveDestination", ZoneFunctions::luaZoneGetRemoveDestination); - registerMethod(L, "Zone", "setRemoveDestination", ZoneFunctions::luaZoneSetRemoveDestination); - registerMethod(L, "Zone", "getPositions", ZoneFunctions::luaZoneGetPositions); - registerMethod(L, "Zone", "getCreatures", ZoneFunctions::luaZoneGetCreatures); - registerMethod(L, "Zone", "getPlayers", ZoneFunctions::luaZoneGetPlayers); - registerMethod(L, "Zone", "getMonsters", ZoneFunctions::luaZoneGetMonsters); - registerMethod(L, "Zone", "getNpcs", ZoneFunctions::luaZoneGetNpcs); - registerMethod(L, "Zone", "getItems", ZoneFunctions::luaZoneGetItems); - - registerMethod(L, "Zone", "removePlayers", ZoneFunctions::luaZoneRemovePlayers); - registerMethod(L, "Zone", "removeMonsters", ZoneFunctions::luaZoneRemoveMonsters); - registerMethod(L, "Zone", "removeNpcs", ZoneFunctions::luaZoneRemoveNpcs); - registerMethod(L, "Zone", "refresh", ZoneFunctions::luaZoneRefresh); - - registerMethod(L, "Zone", "setMonsterVariant", ZoneFunctions::luaZoneSetMonsterVariant); - - // static methods - registerMethod(L, "Zone", "getByPosition", ZoneFunctions::luaZoneGetByPosition); - registerMethod(L, "Zone", "getByName", ZoneFunctions::luaZoneGetByName); - registerMethod(L, "Zone", "getAll", ZoneFunctions::luaZoneGetAll); - } + static void init(lua_State* L); private: static int luaZoneCreate(lua_State* L); diff --git a/src/lua/functions/core/libs/bit_functions.cpp b/src/lua/functions/core/libs/bit_functions.cpp deleted file mode 100644 index 94e5f709b5d..00000000000 --- a/src/lua/functions/core/libs/bit_functions.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Canary - A free and open-source MMORPG server emulator - * Copyright (©) 2019-2024 OpenTibiaBR - * Repository: https://github.com/opentibiabr/canary - * License: https://github.com/opentibiabr/canary/blob/main/LICENSE - * Contributors: https://github.com/opentibiabr/canary/graphs/contributors - * Website: https://docs.opentibiabr.com/ - */ - -#include "lua/functions/core/libs/bit_functions.hpp" - -#ifndef LUAJIT_VERSION -int GlobalFunctions::luaBitNot(lua_State* L) { - int32_t number = getNumber(L, -1); - lua_pushnumber(L, ~number); - return 1; -} - - #define MULTIOP(name, op) \ - int GlobalFunctions::luaBit##name(lua_State* L) \ { \ - int n = lua_gettop(L); \ - uint32_t w = getNumber(L, -1); \ - for (int i = 1; i < n; ++i) \ - w op getNumber(L, i); \ - lua_pushnumber(L, w); \ - return 1; \ - } - -MULTIOP(And, &=) -MULTIOP(Or, |=) -MULTIOP(Xor, ^=) - - #define SHIFTOP(name, op) \ - int GlobalFunctions::luaBit##name(lua_State* L) \ { \ - uint32_t n1 = getNumber(L, 1), n2 = getNumber(L, 2); \ - lua_pushnumber(L, (n1 op n2)); \ - return 1; \ - } - -SHIFTOP(LeftShift, <<) -SHIFTOP(RightShift, >>) -#endif diff --git a/src/lua/functions/core/libs/bit_functions.hpp b/src/lua/functions/core/libs/bit_functions.hpp deleted file mode 100644 index 3d117e74b55..00000000000 --- a/src/lua/functions/core/libs/bit_functions.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/** - * Canary - A free and open-source MMORPG server emulator - * Copyright (©) 2019-2024 OpenTibiaBR - * Repository: https://github.com/opentibiabr/canary - * License: https://github.com/opentibiabr/canary/blob/main/LICENSE - * Contributors: https://github.com/opentibiabr/canary/graphs/contributors - * Website: https://docs.opentibiabr.com/ - */ - -#pragma once - -#include "lua/scripts/luascript.hpp" - -class BitFunctions final : LuaScriptInterface { -public: - explicit BitFunctions(lua_State* L) : - LuaScriptInterface("BitFunctions") { - init(L); - } - ~BitFunctions() override = default; - - static void init(lua_State* L) { -#ifndef LUAJIT_VERSION - registerTable(L, "bit"); - registerMethod(L, "bit", "bnot", BitFunctions::luaBitNot); - registerMethod(L, "bit", "band", BitFunctions::luaBitAnd); - registerMethod(L, "bit", "bor", BitFunctions::luaBitOr); - registerMethod(L, "bit", "bxor", BitFunctions::luaBitXor); - registerMethod(L, "bit", "lshift", BitFunctions::luaBitLeftShift); - registerMethod(L, "bit", "rshift", BitFunctions::luaBitRightShift); -#endif - } - -private: -#ifndef LUAJIT_VERSION - static int luaBitAnd(lua_State* L); - static int luaBitLeftShift(lua_State* L); - static int luaBitNot(lua_State* L); - static int luaBitOr(lua_State* L); - static int luaBitRightShift(lua_State* L); - static int luaBitXor(lua_State* L); -#endif -}; diff --git a/src/lua/functions/core/libs/core_libs_functions.hpp b/src/lua/functions/core/libs/core_libs_functions.hpp index fdfa2d9de81..658b560c2f4 100644 --- a/src/lua/functions/core/libs/core_libs_functions.hpp +++ b/src/lua/functions/core/libs/core_libs_functions.hpp @@ -10,7 +10,6 @@ #pragma once #include "lua/scripts/luascript.hpp" -#include "lua/functions/core/libs/bit_functions.hpp" #include "lua/functions/core/libs/db_functions.hpp" #include "lua/functions/core/libs/result_functions.hpp" #include "lua/functions/core/libs/logger_functions.hpp" @@ -26,7 +25,6 @@ class CoreLibsFunctions final : LuaScriptInterface { ~CoreLibsFunctions() override = default; static void init(lua_State* L) { - BitFunctions::init(L); DBFunctions::init(L); ResultFunctions::init(L); LoggerFunctions::init(L); diff --git a/src/lua/functions/core/libs/db_functions.cpp b/src/lua/functions/core/libs/db_functions.cpp index 858b8faee6d..6b56c5cd148 100644 --- a/src/lua/functions/core/libs/db_functions.cpp +++ b/src/lua/functions/core/libs/db_functions.cpp @@ -12,9 +12,22 @@ #include "database/databasemanager.hpp" #include "database/databasetasks.hpp" #include "lua/scripts/lua_environment.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void DBFunctions::init(lua_State* L) { + Lua::registerTable(L, "db"); + Lua::registerMethod(L, "db", "query", DBFunctions::luaDatabaseExecute); + Lua::registerMethod(L, "db", "asyncQuery", DBFunctions::luaDatabaseAsyncExecute); + Lua::registerMethod(L, "db", "storeQuery", DBFunctions::luaDatabaseStoreQuery); + Lua::registerMethod(L, "db", "asyncStoreQuery", DBFunctions::luaDatabaseAsyncStoreQuery); + Lua::registerMethod(L, "db", "escapeString", DBFunctions::luaDatabaseEscapeString); + Lua::registerMethod(L, "db", "escapeBlob", DBFunctions::luaDatabaseEscapeBlob); + Lua::registerMethod(L, "db", "lastInsertId", DBFunctions::luaDatabaseLastInsertId); + Lua::registerMethod(L, "db", "tableExists", DBFunctions::luaDatabaseTableExists); +} int DBFunctions::luaDatabaseExecute(lua_State* L) { - pushBoolean(L, Database::getInstance().executeQuery(getString(L, -1))); + Lua::pushBoolean(L, Database::getInstance().executeQuery(Lua::getString(L, -1))); return 1; } @@ -22,36 +35,36 @@ int DBFunctions::luaDatabaseAsyncExecute(lua_State* L) { std::function callback; if (lua_gettop(L) > 1) { int32_t ref = luaL_ref(L, LUA_REGISTRYINDEX); - auto scriptId = getScriptEnv()->getScriptId(); + auto scriptId = Lua::getScriptEnv()->getScriptId(); callback = [ref, scriptId](const DBResult_ptr &, bool success) { lua_State* luaState = g_luaEnvironment().getLuaState(); if (!luaState) { return; } - if (!DBFunctions::reserveScriptEnv()) { + if (!Lua::reserveScriptEnv()) { luaL_unref(luaState, LUA_REGISTRYINDEX, ref); return; } lua_rawgeti(luaState, LUA_REGISTRYINDEX, ref); - pushBoolean(luaState, success); - const auto env = getScriptEnv(); + Lua::pushBoolean(luaState, success); + const auto env = Lua::getScriptEnv(); env->setScriptId(scriptId, &g_luaEnvironment()); g_luaEnvironment().callFunction(1); luaL_unref(luaState, LUA_REGISTRYINDEX, ref); }; } - g_databaseTasks().execute(getString(L, -1), callback); + g_databaseTasks().execute(Lua::getString(L, -1), callback); return 0; } int DBFunctions::luaDatabaseStoreQuery(lua_State* L) { - if (const DBResult_ptr &res = Database::getInstance().storeQuery(getString(L, -1))) { + if (const DBResult_ptr &res = Database::getInstance().storeQuery(Lua::getString(L, -1))) { lua_pushnumber(L, ScriptEnvironment::addResult(res)); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } @@ -60,14 +73,14 @@ int DBFunctions::luaDatabaseAsyncStoreQuery(lua_State* L) { std::function callback; if (lua_gettop(L) > 1) { int32_t ref = luaL_ref(L, LUA_REGISTRYINDEX); - auto scriptId = getScriptEnv()->getScriptId(); + auto scriptId = Lua::getScriptEnv()->getScriptId(); callback = [ref, scriptId](const DBResult_ptr &result, bool) { lua_State* luaState = g_luaEnvironment().getLuaState(); if (!luaState) { return; } - if (!DBFunctions::reserveScriptEnv()) { + if (!Lua::reserveScriptEnv()) { luaL_unref(luaState, LUA_REGISTRYINDEX, ref); return; } @@ -76,27 +89,27 @@ int DBFunctions::luaDatabaseAsyncStoreQuery(lua_State* L) { if (result) { lua_pushnumber(luaState, ScriptEnvironment::addResult(result)); } else { - pushBoolean(luaState, false); + Lua::pushBoolean(luaState, false); } - const auto env = getScriptEnv(); + const auto env = Lua::getScriptEnv(); env->setScriptId(scriptId, &g_luaEnvironment()); g_luaEnvironment().callFunction(1); luaL_unref(luaState, LUA_REGISTRYINDEX, ref); }; } - g_databaseTasks().store(getString(L, -1), callback); + g_databaseTasks().store(Lua::getString(L, -1), callback); return 0; } int DBFunctions::luaDatabaseEscapeString(lua_State* L) { - pushString(L, Database::getInstance().escapeString(getString(L, -1))); + Lua::pushString(L, Database::getInstance().escapeString(Lua::getString(L, -1))); return 1; } int DBFunctions::luaDatabaseEscapeBlob(lua_State* L) { - const uint32_t length = getNumber(L, 2); - pushString(L, Database::getInstance().escapeBlob(getString(L, 1).c_str(), length)); + const uint32_t length = Lua::getNumber(L, 2); + Lua::pushString(L, Database::getInstance().escapeBlob(Lua::getString(L, 1).c_str(), length)); return 1; } @@ -106,6 +119,6 @@ int DBFunctions::luaDatabaseLastInsertId(lua_State* L) { } int DBFunctions::luaDatabaseTableExists(lua_State* L) { - pushBoolean(L, DatabaseManager::tableExists(getString(L, -1))); + Lua::pushBoolean(L, DatabaseManager::tableExists(Lua::getString(L, -1))); return 1; } diff --git a/src/lua/functions/core/libs/db_functions.hpp b/src/lua/functions/core/libs/db_functions.hpp index 6d95acdeae9..50181411add 100644 --- a/src/lua/functions/core/libs/db_functions.hpp +++ b/src/lua/functions/core/libs/db_functions.hpp @@ -9,27 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class DBFunctions final : LuaScriptInterface { +class DBFunctions { public: - explicit DBFunctions(lua_State* L) : - LuaScriptInterface("DBFunctions") { - init(L); - } - ~DBFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "db"); - registerMethod(L, "db", "query", DBFunctions::luaDatabaseExecute); - registerMethod(L, "db", "asyncQuery", DBFunctions::luaDatabaseAsyncExecute); - registerMethod(L, "db", "storeQuery", DBFunctions::luaDatabaseStoreQuery); - registerMethod(L, "db", "asyncStoreQuery", DBFunctions::luaDatabaseAsyncStoreQuery); - registerMethod(L, "db", "escapeString", DBFunctions::luaDatabaseEscapeString); - registerMethod(L, "db", "escapeBlob", DBFunctions::luaDatabaseEscapeBlob); - registerMethod(L, "db", "lastInsertId", DBFunctions::luaDatabaseLastInsertId); - registerMethod(L, "db", "tableExists", DBFunctions::luaDatabaseTableExists); - } + static void init(lua_State* L); private: static int luaDatabaseAsyncExecute(lua_State* L); diff --git a/src/lua/functions/core/libs/kv_functions.cpp b/src/lua/functions/core/libs/kv_functions.cpp index d18a306944a..8061e2e9cd8 100644 --- a/src/lua/functions/core/libs/kv_functions.cpp +++ b/src/lua/functions/core/libs/kv_functions.cpp @@ -13,45 +13,62 @@ #include "kv/kv.hpp" #include "lua/scripts/lua_environment.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void KVFunctions::init(lua_State* L) { + Lua::registerTable(L, "kv"); + Lua::registerMethod(L, "kv", "scoped", KVFunctions::luaKVScoped); + Lua::registerMethod(L, "kv", "set", KVFunctions::luaKVSet); + Lua::registerMethod(L, "kv", "get", KVFunctions::luaKVGet); + Lua::registerMethod(L, "kv", "keys", KVFunctions::luaKVKeys); + Lua::registerMethod(L, "kv", "remove", KVFunctions::luaKVRemove); + + Lua::registerClass(L, "KV", ""); + Lua::registerMethod(L, "KV", "scoped", KVFunctions::luaKVScoped); + Lua::registerMethod(L, "KV", "set", KVFunctions::luaKVSet); + Lua::registerMethod(L, "KV", "get", KVFunctions::luaKVGet); + Lua::registerMethod(L, "KV", "keys", KVFunctions::luaKVKeys); + Lua::registerMethod(L, "KV", "remove", KVFunctions::luaKVRemove); +} int KVFunctions::luaKVScoped(lua_State* L) { // KV.scoped(key) | KV:scoped(key) - const auto key = getString(L, -1); + const auto key = Lua::getString(L, -1); - if (isUserdata(L, 1)) { - const auto &scopedKV = getUserdataShared(L, 1); + if (Lua::isUserdata(L, 1)) { + const auto &scopedKV = Lua::getUserdataShared(L, 1); const auto &newScope = scopedKV->scoped(key); - pushUserdata(L, newScope); - setMetatable(L, -1, "KV"); + Lua::pushUserdata(L, newScope); + Lua::setMetatable(L, -1, "KV"); return 1; } const auto &scopedKV = g_kv().scoped(key); - pushUserdata(L, scopedKV); - setMetatable(L, -1, "KV"); + Lua::pushUserdata(L, scopedKV); + Lua::setMetatable(L, -1, "KV"); return 1; } int KVFunctions::luaKVSet(lua_State* L) { // KV.set(key, value) | scopedKV:set(key, value) - const auto key = getString(L, -2); + const auto key = Lua::getString(L, -2); const auto &valueWrapper = getValueWrapper(L); if (!valueWrapper) { g_logger().warn("[{}] invalid param type", __FUNCTION__); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - if (isUserdata(L, 1)) { - const auto &scopedKV = getUserdataShared(L, 1); + if (Lua::isUserdata(L, 1)) { + const auto &scopedKV = Lua::getUserdataShared(L, 1); scopedKV->set(key, valueWrapper.value()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } g_kv().set(key, valueWrapper.value()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -59,13 +76,13 @@ int KVFunctions::luaKVGet(lua_State* L) { // KV.get(key[, forceLoad = false]) | scopedKV:get(key[, forceLoad = false]) std::optional valueWrapper; bool forceLoad = false; - auto key = getString(L, -1); - if (isBoolean(L, -1)) { - forceLoad = getBoolean(L, -1); - key = getString(L, -2); + auto key = Lua::getString(L, -1); + if (Lua::isBoolean(L, -1)) { + forceLoad = Lua::getBoolean(L, -1); + key = Lua::getString(L, -2); } - if (isUserdata(L, 1)) { - const auto &scopedKV = getUserdataShared(L, 1); + if (Lua::isUserdata(L, 1)) { + const auto &scopedKV = Lua::getUserdataShared(L, 1); valueWrapper = scopedKV->get(key, forceLoad); } else { valueWrapper = g_kv().get(key, forceLoad); @@ -81,9 +98,9 @@ int KVFunctions::luaKVGet(lua_State* L) { int KVFunctions::luaKVRemove(lua_State* L) { // KV.remove(key) | scopedKV:remove(key) - const auto key = getString(L, -1); - if (isUserdata(L, 1)) { - const auto &scopedKV = getUserdataShared(L, 1); + const auto key = Lua::getString(L, -1); + if (Lua::isUserdata(L, 1)) { + const auto &scopedKV = Lua::getUserdataShared(L, 1); scopedKV->remove(key); } else { g_kv().remove(key); @@ -97,12 +114,12 @@ int KVFunctions::luaKVKeys(lua_State* L) { std::unordered_set keys; std::string prefix; - if (isString(L, -1)) { - prefix = getString(L, -1); + if (Lua::isString(L, -1)) { + prefix = Lua::getString(L, -1); } - if (isUserdata(L, 1)) { - const auto &scopedKV = getUserdataShared(L, 1); + if (Lua::isUserdata(L, 1)) { + const auto &scopedKV = Lua::getUserdataShared(L, 1); keys = scopedKV->keys(); } else { keys = g_kv().keys(prefix); @@ -111,24 +128,24 @@ int KVFunctions::luaKVKeys(lua_State* L) { int index = 0; lua_createtable(L, static_cast(keys.size()), 0); for (const auto &key : keys) { - pushString(L, key); + Lua::pushString(L, key); lua_rawseti(L, -2, ++index); } return 1; } std::optional KVFunctions::getValueWrapper(lua_State* L) { - if (isBoolean(L, -1)) { - return ValueWrapper(getBoolean(L, -1)); + if (Lua::isBoolean(L, -1)) { + return ValueWrapper(Lua::getBoolean(L, -1)); } - if (isNumber(L, -1)) { - return ValueWrapper(getNumber(L, -1)); + if (Lua::isNumber(L, -1)) { + return ValueWrapper(Lua::getNumber(L, -1)); } - if (isString(L, -1)) { - return ValueWrapper(getString(L, -1)); + if (Lua::isString(L, -1)) { + return ValueWrapper(Lua::getString(L, -1)); } - if (isTable(L, -1) && lua_objlen(L, -1) > 0) { + if (Lua::isTable(L, -1) && lua_objlen(L, -1) > 0) { ArrayType array; for (int i = 1; i <= lua_objlen(L, -1); ++i) { lua_rawgeti(L, -1, i); @@ -143,7 +160,7 @@ std::optional KVFunctions::getValueWrapper(lua_State* L) { return ValueWrapper(array); } - if (isTable(L, -1)) { + if (Lua::isTable(L, -1)) { MapType map; lua_pushnil(L); while (lua_next(L, -2) != 0) { @@ -152,13 +169,13 @@ std::optional KVFunctions::getValueWrapper(lua_State* L) { g_logger().warn("[{}] invalid param type", __FUNCTION__); return std::nullopt; } - map[getString(L, -2)] = std::make_shared(value.value()); + map[Lua::getString(L, -2)] = std::make_shared(value.value()); lua_pop(L, 1); } return ValueWrapper(map); } - if (isNil(L, -1)) { + if (Lua::isNil(L, -1)) { return std::nullopt; } @@ -167,7 +184,7 @@ std::optional KVFunctions::getValueWrapper(lua_State* L) { } void KVFunctions::pushStringValue(lua_State* L, const StringType &value) { - pushString(L, value); + Lua::pushString(L, value); } void KVFunctions::pushIntValue(lua_State* L, const IntType &value) { @@ -201,7 +218,7 @@ void KVFunctions::pushValueWrapper(lua_State* L, const ValueWrapper &valueWrappe if constexpr (std::is_same_v) { pushStringValue(L, arg); } else if constexpr (std::is_same_v) { - pushBoolean(L, arg); + Lua::pushBoolean(L, arg); } else if constexpr (std::is_same_v) { pushIntValue(L, arg); } else if constexpr (std::is_same_v) { diff --git a/src/lua/functions/core/libs/kv_functions.hpp b/src/lua/functions/core/libs/kv_functions.hpp index 4ef47333f2f..63f9eb8850b 100644 --- a/src/lua/functions/core/libs/kv_functions.hpp +++ b/src/lua/functions/core/libs/kv_functions.hpp @@ -9,8 +9,6 @@ #pragma once -#include "lua/scripts/luascript.hpp" - class ValueWrapper; #ifndef USE_PRECOMPILED_HEADERS @@ -25,29 +23,9 @@ using MapType = phmap::flat_hash_map> struct lua_State; -class KVFunctions final : LuaScriptInterface { +class KVFunctions { public: - explicit KVFunctions(lua_State* L) : - LuaScriptInterface("KVFunctions") { - init(L); - } - ~KVFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "kv"); - registerMethod(L, "kv", "scoped", KVFunctions::luaKVScoped); - registerMethod(L, "kv", "set", KVFunctions::luaKVSet); - registerMethod(L, "kv", "get", KVFunctions::luaKVGet); - registerMethod(L, "kv", "keys", KVFunctions::luaKVKeys); - registerMethod(L, "kv", "remove", KVFunctions::luaKVRemove); - - registerClass(L, "KV", ""); - registerMethod(L, "KV", "scoped", KVFunctions::luaKVScoped); - registerMethod(L, "KV", "set", KVFunctions::luaKVSet); - registerMethod(L, "KV", "get", KVFunctions::luaKVGet); - registerMethod(L, "KV", "keys", KVFunctions::luaKVKeys); - registerMethod(L, "KV", "remove", KVFunctions::luaKVRemove); - } + static void init(lua_State* L); private: static int luaKVScoped(lua_State* L); diff --git a/src/lua/functions/core/libs/logger_functions.cpp b/src/lua/functions/core/libs/logger_functions.cpp index 741d35fec9d..c54f534813a 100644 --- a/src/lua/functions/core/libs/logger_functions.cpp +++ b/src/lua/functions/core/libs/logger_functions.cpp @@ -8,27 +8,28 @@ */ #include "lua/functions/core/libs/logger_functions.hpp" +#include "lua/functions/lua_functions_loader.hpp" void LoggerFunctions::init(lua_State* L) { // Kept for compatibility purposes only, it's deprecated - registerTable(L, "Spdlog"); - registerMethod(L, "Spdlog", "info", LoggerFunctions::luaSpdlogInfo); - registerMethod(L, "Spdlog", "warn", LoggerFunctions::luaSpdlogWarn); - registerMethod(L, "Spdlog", "error", LoggerFunctions::luaSpdlogError); - registerMethod(L, "Spdlog", "debug", LoggerFunctions::luaSpdlogDebug); + Lua::registerTable(L, "Spdlog"); + Lua::registerMethod(L, "Spdlog", "info", LoggerFunctions::luaSpdlogInfo); + Lua::registerMethod(L, "Spdlog", "warn", LoggerFunctions::luaSpdlogWarn); + Lua::registerMethod(L, "Spdlog", "error", LoggerFunctions::luaSpdlogError); + Lua::registerMethod(L, "Spdlog", "debug", LoggerFunctions::luaSpdlogDebug); - registerTable(L, "logger"); - registerMethod(L, "logger", "info", LoggerFunctions::luaLoggerInfo); - registerMethod(L, "logger", "warn", LoggerFunctions::luaLoggerWarn); - registerMethod(L, "logger", "error", LoggerFunctions::luaLoggerError); - registerMethod(L, "logger", "debug", LoggerFunctions::luaLoggerDebug); - registerMethod(L, "logger", "trace", LoggerFunctions::luaLoggerTrace); + Lua::registerTable(L, "logger"); + Lua::registerMethod(L, "logger", "info", LoggerFunctions::luaLoggerInfo); + Lua::registerMethod(L, "logger", "warn", LoggerFunctions::luaLoggerWarn); + Lua::registerMethod(L, "logger", "error", LoggerFunctions::luaLoggerError); + Lua::registerMethod(L, "logger", "debug", LoggerFunctions::luaLoggerDebug); + Lua::registerMethod(L, "logger", "trace", LoggerFunctions::luaLoggerTrace); } int LoggerFunctions::luaSpdlogInfo(lua_State* L) { // Spdlog.info(text) - if (isString(L, 1)) { - g_logger().info(getString(L, 1)); + if (Lua::isString(L, 1)) { + g_logger().info(Lua::getString(L, 1)); } else { lua_pushnil(L); } @@ -37,8 +38,8 @@ int LoggerFunctions::luaSpdlogInfo(lua_State* L) { int LoggerFunctions::luaSpdlogWarn(lua_State* L) { // Spdlog.warn(text) - if (isString(L, 1)) { - g_logger().warn(getString(L, 1)); + if (Lua::isString(L, 1)) { + g_logger().warn(Lua::getString(L, 1)); } else { lua_pushnil(L); } @@ -47,8 +48,8 @@ int LoggerFunctions::luaSpdlogWarn(lua_State* L) { int LoggerFunctions::luaSpdlogError(lua_State* L) { // Spdlog.error(text) - if (isString(L, 1)) { - g_logger().error(getString(L, 1)); + if (Lua::isString(L, 1)) { + g_logger().error(Lua::getString(L, 1)); } else { lua_pushnil(L); } @@ -57,8 +58,8 @@ int LoggerFunctions::luaSpdlogError(lua_State* L) { int LoggerFunctions::luaSpdlogDebug(lua_State* L) { // Spdlog.debug(text) - if (isString(L, 1)) { - g_logger().debug(getString(L, 1)); + if (Lua::isString(L, 1)) { + g_logger().debug(Lua::getString(L, 1)); } else { lua_pushnil(L); } @@ -68,30 +69,30 @@ int LoggerFunctions::luaSpdlogDebug(lua_State* L) { // Logger int LoggerFunctions::luaLoggerInfo(lua_State* L) { // logger.info(text) - if (isString(L, 1)) { - g_logger().info(getFormatedLoggerMessage(L)); + if (Lua::isString(L, 1)) { + g_logger().info(Lua::getFormatedLoggerMessage(L)); } else { - reportErrorFunc("First parameter needs to be a string"); + Lua::reportErrorFunc("First parameter needs to be a string"); } return 1; } int LoggerFunctions::luaLoggerWarn(lua_State* L) { // logger.warn(text) - if (isString(L, 1)) { - g_logger().warn(getFormatedLoggerMessage(L)); + if (Lua::isString(L, 1)) { + g_logger().warn(Lua::getFormatedLoggerMessage(L)); } else { - reportErrorFunc("First parameter needs to be a string"); + Lua::reportErrorFunc("First parameter needs to be a string"); } return 1; } int LoggerFunctions::luaLoggerError(lua_State* L) { // logger.error(text) - if (isString(L, 1)) { - g_logger().error(getFormatedLoggerMessage(L)); + if (Lua::isString(L, 1)) { + g_logger().error(Lua::getFormatedLoggerMessage(L)); } else { - reportErrorFunc("First parameter needs to be a string"); + Lua::reportErrorFunc("First parameter needs to be a string"); } return 1; @@ -99,20 +100,20 @@ int LoggerFunctions::luaLoggerError(lua_State* L) { int LoggerFunctions::luaLoggerDebug(lua_State* L) { // logger.debug(text) - if (isString(L, 1)) { - g_logger().debug(getFormatedLoggerMessage(L)); + if (Lua::isString(L, 1)) { + g_logger().debug(Lua::getFormatedLoggerMessage(L)); } else { - reportErrorFunc("First parameter needs to be a string"); + Lua::reportErrorFunc("First parameter needs to be a string"); } return 1; } int LoggerFunctions::luaLoggerTrace(lua_State* L) { // logger.trace(text) - if (isString(L, 1)) { - g_logger().trace(getFormatedLoggerMessage(L)); + if (Lua::isString(L, 1)) { + g_logger().trace(Lua::getFormatedLoggerMessage(L)); } else { - reportErrorFunc("First parameter needs to be a string"); + Lua::reportErrorFunc("First parameter needs to be a string"); } return 1; } diff --git a/src/lua/functions/core/libs/logger_functions.hpp b/src/lua/functions/core/libs/logger_functions.hpp index fb3c265f21d..aa5b4d3f80c 100644 --- a/src/lua/functions/core/libs/logger_functions.hpp +++ b/src/lua/functions/core/libs/logger_functions.hpp @@ -9,16 +9,8 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class LoggerFunctions final : public LuaScriptInterface { +class LoggerFunctions { public: - explicit LoggerFunctions(lua_State* L) : - LuaScriptInterface("LoggerFunctions") { - init(L); - } - ~LoggerFunctions() override = default; - static void init(lua_State* L); private: diff --git a/src/lua/functions/core/libs/metrics_functions.cpp b/src/lua/functions/core/libs/metrics_functions.cpp index 84d81fd214e..919f39da07e 100644 --- a/src/lua/functions/core/libs/metrics_functions.cpp +++ b/src/lua/functions/core/libs/metrics_functions.cpp @@ -10,17 +10,18 @@ #include "lua/functions/core/libs/metrics_functions.hpp" #include "lib/metrics/metrics.hpp" +#include "lua/functions/lua_functions_loader.hpp" void MetricsFunctions::init(lua_State* L) { - registerTable(L, "metrics"); - registerMethod(L, "metrics", "addCounter", MetricsFunctions::luaMetricsAddCounter); + Lua::registerTable(L, "metrics"); + Lua::registerMethod(L, "metrics", "addCounter", MetricsFunctions::luaMetricsAddCounter); } // Metrics int MetricsFunctions::luaMetricsAddCounter(lua_State* L) { // metrics.addCounter(name, value, attributes) - const auto name = getString(L, 1); - const auto value = getNumber(L, 2); + const auto name = Lua::getString(L, 1); + const auto value = Lua::getNumber(L, 2); const auto attributes = getAttributes(L, 3); g_metrics().addCounter(name, value, attributes); return 1; @@ -28,10 +29,10 @@ int MetricsFunctions::luaMetricsAddCounter(lua_State* L) { std::map MetricsFunctions::getAttributes(lua_State* L, int32_t index) { std::map attributes; - if (isTable(L, index)) { + if (Lua::isTable(L, index)) { lua_pushnil(L); while (lua_next(L, index) != 0) { - attributes[getString(L, -2)] = getString(L, -1); + attributes[Lua::getString(L, -2)] = Lua::getString(L, -1); lua_pop(L, 1); } } diff --git a/src/lua/functions/core/libs/metrics_functions.hpp b/src/lua/functions/core/libs/metrics_functions.hpp index 4155646cb51..8b375244476 100644 --- a/src/lua/functions/core/libs/metrics_functions.hpp +++ b/src/lua/functions/core/libs/metrics_functions.hpp @@ -9,16 +9,8 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class MetricsFunctions final : public LuaScriptInterface { +class MetricsFunctions { public: - explicit MetricsFunctions(lua_State* L) : - LuaScriptInterface("MetricsFunctions") { - init(L); - } - ~MetricsFunctions() override = default; - static void init(lua_State* L); private: diff --git a/src/lua/functions/core/libs/result_functions.cpp b/src/lua/functions/core/libs/result_functions.cpp index 2c55645b3b8..eda7bbad332 100644 --- a/src/lua/functions/core/libs/result_functions.cpp +++ b/src/lua/functions/core/libs/result_functions.cpp @@ -8,57 +8,67 @@ */ #include "lua/functions/core/libs/result_functions.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ResultFunctions::init(lua_State* L) { + Lua::registerTable(L, "Result"); + Lua::registerMethod(L, "Result", "getNumber", ResultFunctions::luaResultGetNumber); + Lua::registerMethod(L, "Result", "getString", ResultFunctions::luaResultGetString); + Lua::registerMethod(L, "Result", "getStream", ResultFunctions::luaResultGetStream); + Lua::registerMethod(L, "Result", "next", ResultFunctions::luaResultNext); + Lua::registerMethod(L, "Result", "free", ResultFunctions::luaResultFree); +} int ResultFunctions::luaResultGetNumber(lua_State* L) { - const auto &res = ScriptEnvironment::getResultByID(getNumber(L, 1)); + const auto &res = ScriptEnvironment::getResultByID(Lua::getNumber(L, 1)); if (!res) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const std::string &s = getString(L, 2); + const std::string &s = Lua::getString(L, 2); lua_pushnumber(L, res->getNumber(s)); return 1; } int ResultFunctions::luaResultGetString(lua_State* L) { - const auto &res = ScriptEnvironment::getResultByID(getNumber(L, 1)); + const auto &res = ScriptEnvironment::getResultByID(Lua::getNumber(L, 1)); if (!res) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const std::string &s = getString(L, 2); - pushString(L, res->getString(s)); + const std::string &s = Lua::getString(L, 2); + Lua::pushString(L, res->getString(s)); return 1; } int ResultFunctions::luaResultGetStream(lua_State* L) { - const auto &res = ScriptEnvironment::getResultByID(getNumber(L, 1)); + const auto &res = ScriptEnvironment::getResultByID(Lua::getNumber(L, 1)); if (!res) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } unsigned long length; - const char* stream = res->getStream(getString(L, 2), length); + const char* stream = res->getStream(Lua::getString(L, 2), length); lua_pushlstring(L, stream, length); lua_pushnumber(L, length); return 2; } int ResultFunctions::luaResultNext(lua_State* L) { - const auto &res = ScriptEnvironment::getResultByID(getNumber(L, -1)); + const auto &res = ScriptEnvironment::getResultByID(Lua::getNumber(L, -1)); if (!res) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, res->next()); + Lua::pushBoolean(L, res->next()); return 1; } int ResultFunctions::luaResultFree(lua_State* L) { - pushBoolean(L, ScriptEnvironment::removeResult(getNumber(L, -1))); + Lua::pushBoolean(L, ScriptEnvironment::removeResult(Lua::getNumber(L, -1))); return 1; } diff --git a/src/lua/functions/core/libs/result_functions.hpp b/src/lua/functions/core/libs/result_functions.hpp index 7e7f74f1add..3b979da3c86 100644 --- a/src/lua/functions/core/libs/result_functions.hpp +++ b/src/lua/functions/core/libs/result_functions.hpp @@ -9,24 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ResultFunctions final : LuaScriptInterface { +class ResultFunctions { public: - explicit ResultFunctions(lua_State* L) : - LuaScriptInterface("ResultFunctions") { - init(L); - } - ~ResultFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "Result"); - registerMethod(L, "Result", "getNumber", ResultFunctions::luaResultGetNumber); - registerMethod(L, "Result", "getString", ResultFunctions::luaResultGetString); - registerMethod(L, "Result", "getStream", ResultFunctions::luaResultGetStream); - registerMethod(L, "Result", "next", ResultFunctions::luaResultNext); - registerMethod(L, "Result", "free", ResultFunctions::luaResultFree); - } + static void init(lua_State* L); private: static int luaResultFree(lua_State* L); diff --git a/src/lua/functions/core/network/network_message_functions.cpp b/src/lua/functions/core/network/network_message_functions.cpp index 18bb454ee45..bfd3b86897e 100644 --- a/src/lua/functions/core/network/network_message_functions.cpp +++ b/src/lua/functions/core/network/network_message_functions.cpp @@ -12,17 +12,48 @@ #include "server/network/protocol/protocolgame.hpp" #include "creatures/players/player.hpp" #include "server/network/protocol/protocolstatus.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void NetworkMessageFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); + Lua::registerMetaMethod(L, "NetworkMessage", "__eq", Lua::luaUserdataCompare); + Lua::registerMethod(L, "NetworkMessage", "delete", Lua::luaGarbageCollection); + + Lua::registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); + Lua::registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); + Lua::registerMethod(L, "NetworkMessage", "getU32", NetworkMessageFunctions::luaNetworkMessageGetU32); + Lua::registerMethod(L, "NetworkMessage", "getU64", NetworkMessageFunctions::luaNetworkMessageGetU64); + Lua::registerMethod(L, "NetworkMessage", "getString", NetworkMessageFunctions::luaNetworkMessageGetString); + Lua::registerMethod(L, "NetworkMessage", "getPosition", NetworkMessageFunctions::luaNetworkMessageGetPosition); + + Lua::registerMethod(L, "NetworkMessage", "addByte", NetworkMessageFunctions::luaNetworkMessageAddByte); + Lua::registerMethod(L, "NetworkMessage", "addU16", NetworkMessageFunctions::luaNetworkMessageAddU16); + Lua::registerMethod(L, "NetworkMessage", "addU32", NetworkMessageFunctions::luaNetworkMessageAddU32); + Lua::registerMethod(L, "NetworkMessage", "addU64", NetworkMessageFunctions::luaNetworkMessageAddU64); + Lua::registerMethod(L, "NetworkMessage", "add8", NetworkMessageFunctions::luaNetworkMessageAdd8); + Lua::registerMethod(L, "NetworkMessage", "add16", NetworkMessageFunctions::luaNetworkMessageAdd16); + Lua::registerMethod(L, "NetworkMessage", "add32", NetworkMessageFunctions::luaNetworkMessageAdd32); + Lua::registerMethod(L, "NetworkMessage", "add64", NetworkMessageFunctions::luaNetworkMessageAdd64); + Lua::registerMethod(L, "NetworkMessage", "addString", NetworkMessageFunctions::luaNetworkMessageAddString); + Lua::registerMethod(L, "NetworkMessage", "addPosition", NetworkMessageFunctions::luaNetworkMessageAddPosition); + Lua::registerMethod(L, "NetworkMessage", "addDouble", NetworkMessageFunctions::luaNetworkMessageAddDouble); + Lua::registerMethod(L, "NetworkMessage", "addItem", NetworkMessageFunctions::luaNetworkMessageAddItem); + + Lua::registerMethod(L, "NetworkMessage", "reset", NetworkMessageFunctions::luaNetworkMessageReset); + Lua::registerMethod(L, "NetworkMessage", "skipBytes", NetworkMessageFunctions::luaNetworkMessageSkipBytes); + Lua::registerMethod(L, "NetworkMessage", "sendToPlayer", NetworkMessageFunctions::luaNetworkMessageSendToPlayer); +} int NetworkMessageFunctions::luaNetworkMessageCreate(lua_State* L) { // NetworkMessage() - pushUserdata(L, std::make_shared()); - setMetatable(L, -1, "NetworkMessage"); + Lua::pushUserdata(L, std::make_shared()); + Lua::setMetatable(L, -1, "NetworkMessage"); return 1; } int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { // networkMessage:getByte() - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->getByte()); } else { @@ -33,7 +64,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { // networkMessage:getU16() - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -44,7 +75,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { // networkMessage:getU32() - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -55,7 +86,7 @@ int NetworkMessageFunctions::luaNetworkMessageGetU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { // networkMessage:getU64() - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { lua_pushnumber(L, message->get()); } else { @@ -65,10 +96,10 @@ int NetworkMessageFunctions::luaNetworkMessageGetU64(lua_State* L) { } int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { - // networkMessage:getString() - const auto &message = getUserdataShared(L, 1); + // networkMessage:Lua::getString() + const auto &message = Lua::getUserdataShared(L, 1); if (message) { - pushString(L, message->getString()); + Lua::pushString(L, message->getString()); } else { lua_pushnil(L); } @@ -76,10 +107,10 @@ int NetworkMessageFunctions::luaNetworkMessageGetString(lua_State* L) { } int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { - // networkMessage:getPosition() - const auto &message = getUserdataShared(L, 1); + // networkMessage:Lua::getPosition() + const auto &message = Lua::getUserdataShared(L, 1); if (message) { - pushPosition(L, message->getPosition()); + Lua::pushPosition(L, message->getPosition()); } else { lua_pushnil(L); } @@ -88,11 +119,11 @@ int NetworkMessageFunctions::luaNetworkMessageGetPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { // networkMessage:addByte(number) - const uint8_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const uint8_t number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->addByte(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -101,11 +132,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddByte(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { // networkMessage:addU16(number) - const uint16_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const uint16_t number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -114,11 +145,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddU16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { // networkMessage:addU32(number) - const uint32_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const uint32_t number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -127,11 +158,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddU32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { // networkMessage:addU64(number) - const uint64_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const uint64_t number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -140,11 +171,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddU64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { // networkMessage:add8(number) - const auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const auto number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -153,11 +184,11 @@ int NetworkMessageFunctions::luaNetworkMessageAdd8(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { // networkMessage:add16(number) - const auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const auto number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -166,11 +197,11 @@ int NetworkMessageFunctions::luaNetworkMessageAdd16(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { // networkMessage:add32(number) - const auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const auto number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -179,11 +210,11 @@ int NetworkMessageFunctions::luaNetworkMessageAdd32(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { // networkMessage:add64(number) - const auto number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const auto number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->add(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -192,12 +223,12 @@ int NetworkMessageFunctions::luaNetworkMessageAdd64(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { // networkMessage:addString(string, function) - const std::string &string = getString(L, 2); - const std::string &function = getString(L, 3); - const auto &message = getUserdataShared(L, 1); + const std::string &string = Lua::getString(L, 2); + const std::string &function = Lua::getString(L, 3); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->addString(string, std::source_location::current(), function); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -206,11 +237,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddString(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { // networkMessage:addPosition(position) - const Position &position = getPosition(L, 2); - const auto &message = getUserdataShared(L, 1); + const Position &position = Lua::getPosition(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->addPosition(position); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -219,11 +250,11 @@ int NetworkMessageFunctions::luaNetworkMessageAddPosition(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { // networkMessage:addDouble(number) - const double number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const double number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->addDouble(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -232,24 +263,24 @@ int NetworkMessageFunctions::luaNetworkMessageAddDouble(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { // networkMessage:addItem(item, player) - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); lua_pushnil(L); return 1; } - const auto &player = getUserdataShared(L, 3); + const auto &player = Lua::getUserdataShared(L, 3); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message && player->client) { player->client->AddItem(*message, item); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -258,10 +289,10 @@ int NetworkMessageFunctions::luaNetworkMessageAddItem(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { // networkMessage:reset() - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->reset(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -270,11 +301,11 @@ int NetworkMessageFunctions::luaNetworkMessageReset(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { // networkMessage:skipBytes(number) - const int16_t number = getNumber(L, 2); - const auto &message = getUserdataShared(L, 1); + const int16_t number = Lua::getNumber(L, 2); + const auto &message = Lua::getUserdataShared(L, 1); if (message) { message->skipBytes(number); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -283,19 +314,19 @@ int NetworkMessageFunctions::luaNetworkMessageSkipBytes(lua_State* L) { int NetworkMessageFunctions::luaNetworkMessageSendToPlayer(lua_State* L) { // networkMessage:sendToPlayer(player) - const auto &message = getUserdataShared(L, 1); + const auto &message = Lua::getUserdataShared(L, 1); if (!message) { lua_pushnil(L); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } player->sendNetworkMessage(*message); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/core/network/network_message_functions.hpp b/src/lua/functions/core/network/network_message_functions.hpp index 783e06aec57..906d649f7ea 100644 --- a/src/lua/functions/core/network/network_message_functions.hpp +++ b/src/lua/functions/core/network/network_message_functions.hpp @@ -9,45 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class NetworkMessageFunctions final : LuaScriptInterface { +class NetworkMessageFunctions { public: - explicit NetworkMessageFunctions(lua_State* L) : - LuaScriptInterface("NetworkMessageFunctions") { - init(L); - } - ~NetworkMessageFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "NetworkMessage", "", NetworkMessageFunctions::luaNetworkMessageCreate); - registerMetaMethod(L, "NetworkMessage", "__eq", NetworkMessageFunctions::luaUserdataCompare); - registerMethod(L, "NetworkMessage", "delete", luaGarbageCollection); - - registerMethod(L, "NetworkMessage", "getByte", NetworkMessageFunctions::luaNetworkMessageGetByte); - registerMethod(L, "NetworkMessage", "getU16", NetworkMessageFunctions::luaNetworkMessageGetU16); - registerMethod(L, "NetworkMessage", "getU32", NetworkMessageFunctions::luaNetworkMessageGetU32); - registerMethod(L, "NetworkMessage", "getU64", NetworkMessageFunctions::luaNetworkMessageGetU64); - registerMethod(L, "NetworkMessage", "getString", NetworkMessageFunctions::luaNetworkMessageGetString); - registerMethod(L, "NetworkMessage", "getPosition", NetworkMessageFunctions::luaNetworkMessageGetPosition); - - registerMethod(L, "NetworkMessage", "addByte", NetworkMessageFunctions::luaNetworkMessageAddByte); - registerMethod(L, "NetworkMessage", "addU16", NetworkMessageFunctions::luaNetworkMessageAddU16); - registerMethod(L, "NetworkMessage", "addU32", NetworkMessageFunctions::luaNetworkMessageAddU32); - registerMethod(L, "NetworkMessage", "addU64", NetworkMessageFunctions::luaNetworkMessageAddU64); - registerMethod(L, "NetworkMessage", "add8", NetworkMessageFunctions::luaNetworkMessageAdd8); - registerMethod(L, "NetworkMessage", "add16", NetworkMessageFunctions::luaNetworkMessageAdd16); - registerMethod(L, "NetworkMessage", "add32", NetworkMessageFunctions::luaNetworkMessageAdd32); - registerMethod(L, "NetworkMessage", "add64", NetworkMessageFunctions::luaNetworkMessageAdd64); - registerMethod(L, "NetworkMessage", "addString", NetworkMessageFunctions::luaNetworkMessageAddString); - registerMethod(L, "NetworkMessage", "addPosition", NetworkMessageFunctions::luaNetworkMessageAddPosition); - registerMethod(L, "NetworkMessage", "addDouble", NetworkMessageFunctions::luaNetworkMessageAddDouble); - registerMethod(L, "NetworkMessage", "addItem", NetworkMessageFunctions::luaNetworkMessageAddItem); - - registerMethod(L, "NetworkMessage", "reset", NetworkMessageFunctions::luaNetworkMessageReset); - registerMethod(L, "NetworkMessage", "skipBytes", NetworkMessageFunctions::luaNetworkMessageSkipBytes); - registerMethod(L, "NetworkMessage", "sendToPlayer", NetworkMessageFunctions::luaNetworkMessageSendToPlayer); - } + static void init(lua_State* L); private: static int luaNetworkMessageCreate(lua_State* L); diff --git a/src/lua/functions/core/network/webhook_functions.cpp b/src/lua/functions/core/network/webhook_functions.cpp index 23cba449515..7a55b656a74 100644 --- a/src/lua/functions/core/network/webhook_functions.cpp +++ b/src/lua/functions/core/network/webhook_functions.cpp @@ -10,14 +10,20 @@ #include "lua/functions/core/network/webhook_functions.hpp" #include "server/network/webhook/webhook.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void WebhookFunctions::init(lua_State* L) { + Lua::registerTable(L, "Webhook"); + Lua::registerMethod(L, "Webhook", "sendMessage", WebhookFunctions::luaWebhookSendMessage); +} int WebhookFunctions::luaWebhookSendMessage(lua_State* L) { // Webhook.sendMessage(title, message, color, url = "WEBHOOK_DISCORD_URL") | // Webhook.sendMessage(message, url = "WEBHOOK_DISCORD_URL") - const std::string title = getString(L, 1); - const std::string message = getString(L, 2); - const auto color = getNumber(L, 3, 0); - const std::string url = getString(L, -1); + const std::string title = Lua::getString(L, 1); + const std::string message = Lua::getString(L, 2); + const auto color = Lua::getNumber(L, 3, 0); + const std::string url = Lua::getString(L, -1); if (url == title) { g_webhook().sendMessage(title); } else if (url == message) { diff --git a/src/lua/functions/core/network/webhook_functions.hpp b/src/lua/functions/core/network/webhook_functions.hpp index 83ecb377c80..c7f24115520 100644 --- a/src/lua/functions/core/network/webhook_functions.hpp +++ b/src/lua/functions/core/network/webhook_functions.hpp @@ -9,20 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class WebhookFunctions final : LuaScriptInterface { +class WebhookFunctions { public: - explicit WebhookFunctions(lua_State* L) : - LuaScriptInterface("WebhookFunctions") { - init(L); - } - ~WebhookFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "Webhook"); - registerMethod(L, "Webhook", "sendMessage", WebhookFunctions::luaWebhookSendMessage); - } + static void init(lua_State* L); private: static int luaWebhookSendMessage(lua_State* L); diff --git a/src/lua/functions/creatures/combat/combat_functions.cpp b/src/lua/functions/creatures/combat/combat_functions.cpp index 27d3a76ef04..776f447952e 100644 --- a/src/lua/functions/creatures/combat/combat_functions.cpp +++ b/src/lua/functions/creatures/combat/combat_functions.cpp @@ -9,77 +9,100 @@ #include "lua/functions/creatures/combat/combat_functions.hpp" +#include "creatures/creature.hpp" #include "creatures/combat/combat.hpp" #include "creatures/combat/condition.hpp" #include "game/game.hpp" #include "lua/global/lua_variant.hpp" #include "lua/scripts/lua_environment.hpp" +#include "creatures/players/player.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void CombatFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Combat", "", CombatFunctions::luaCombatCreate); + Lua::registerMetaMethod(L, "Combat", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Combat", "setParameter", CombatFunctions::luaCombatSetParameter); + Lua::registerMethod(L, "Combat", "setFormula", CombatFunctions::luaCombatSetFormula); + + Lua::registerMethod(L, "Combat", "setArea", CombatFunctions::luaCombatSetArea); + Lua::registerMethod(L, "Combat", "addCondition", CombatFunctions::luaCombatSetCondition); + Lua::registerMethod(L, "Combat", "setCallback", CombatFunctions::luaCombatSetCallback); + Lua::registerMethod(L, "Combat", "setOrigin", CombatFunctions::luaCombatSetOrigin); + + Lua::registerMethod(L, "Combat", "execute", CombatFunctions::luaCombatExecute); + + ConditionFunctions::init(L); + SpellFunctions::init(L); + VariantFunctions::init(L); +} int CombatFunctions::luaCombatCreate(lua_State* L) { // Combat() - pushUserdata(L, g_luaEnvironment().createCombatObject(getScriptEnv()->getScriptInterface())); - setMetatable(L, -1, "Combat"); + auto combat = std::make_shared(); + Lua::pushUserdata(L, combat); + Lua::setMetatable(L, -1, "Combat"); return 1; } int CombatFunctions::luaCombatSetParameter(lua_State* L) { // combat:setParameter(key, value) - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; } - const CombatParam_t key = getNumber(L, 2); + const CombatParam_t key = Lua::getNumber(L, 2); uint32_t value; - if (isBoolean(L, 3)) { - value = getBoolean(L, 3) ? 1 : 0; + if (Lua::isBoolean(L, 3)) { + value = Lua::getBoolean(L, 3) ? 1 : 0; } else { - value = getNumber(L, 3); + value = Lua::getNumber(L, 3); } combat->setParam(key, value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CombatFunctions::luaCombatSetFormula(lua_State* L) { // combat:setFormula(type, mina, minb, maxa, maxb) - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; } - const formulaType_t type = getNumber(L, 2); - const double mina = getNumber(L, 3); - const double minb = getNumber(L, 4); - const double maxa = getNumber(L, 5); - const double maxb = getNumber(L, 6); + const formulaType_t type = Lua::getNumber(L, 2); + const double mina = Lua::getNumber(L, 3); + const double minb = Lua::getNumber(L, 4); + const double maxa = Lua::getNumber(L, 5); + const double maxb = Lua::getNumber(L, 6); combat->setPlayerCombatValues(type, mina, minb, maxa, maxb); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CombatFunctions::luaCombatSetArea(lua_State* L) { // combat:setArea(area) - if (getScriptEnv()->getScriptId() != EVENT_ID_LOADING) { - reportErrorFunc("This function can only be used while loading the script."); + if (Lua::getScriptEnv()->getScriptId() != EVENT_ID_LOADING) { + Lua::reportErrorFunc("This function can only be used while loading the script."); lua_pushnil(L); return 1; } - const std::unique_ptr &area = g_luaEnvironment().getAreaObject(getNumber(L, 2)); + const std::unique_ptr &area = g_luaEnvironment().getAreaObject(Lua::getNumber(L, 2)); if (!area) { - reportErrorFunc(getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_AREA_NOT_FOUND)); lua_pushnil(L); return 1; } - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (combat) { auto areaClone = area->clone(); combat->setArea(areaClone); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -88,11 +111,11 @@ int CombatFunctions::luaCombatSetArea(lua_State* L) { int CombatFunctions::luaCombatSetCondition(lua_State* L) { // combat:addCondition(condition) - const std::shared_ptr &condition = getUserdataShared(L, 2); - auto* combat = getUserdata(L, 1); + const std::shared_ptr &condition = Lua::getUserdataShared(L, 2); + auto* combat = Lua::getUserdata(L, 1); if (combat && condition) { combat->addCondition(condition->clone()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -101,13 +124,13 @@ int CombatFunctions::luaCombatSetCondition(lua_State* L) { int CombatFunctions::luaCombatSetCallback(lua_State* L) { // combat:setCallback(key, function) - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (!combat) { lua_pushnil(L); return 1; } - const CallBackParam_t key = getNumber(L, 2); + const CallBackParam_t key = Lua::getNumber(L, 2); if (!combat->setCallback(key)) { lua_pushnil(L); return 1; @@ -119,17 +142,17 @@ int CombatFunctions::luaCombatSetCallback(lua_State* L) { return 1; } - const std::string &function = getString(L, 3); - pushBoolean(L, callback->loadCallBack(getScriptEnv()->getScriptInterface(), function)); + const std::string &function = Lua::getString(L, 3); + Lua::pushBoolean(L, callback->loadCallBack(Lua::getScriptEnv()->getScriptInterface(), function)); return 1; } int CombatFunctions::luaCombatSetOrigin(lua_State* L) { // combat:setOrigin(origin) - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (combat) { - combat->setOrigin(getNumber(L, 2)); - pushBoolean(L, true); + combat->setOrigin(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -138,27 +161,28 @@ int CombatFunctions::luaCombatSetOrigin(lua_State* L) { int CombatFunctions::luaCombatExecute(lua_State* L) { // combat:execute(creature, variant) - const auto &combat = getUserdataShared(L, 1); + const auto &combat = Lua::getUserdataShared(L, 1); if (!combat) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - if (isUserdata(L, 2)) { - const LuaData_t type = getUserdataType(L, 2); - if (type != LuaData_t::Player && type != LuaData_t::Monster && type != LuaData_t::Npc) { - pushBoolean(L, false); + if (Lua::isUserdata(L, 2)) { + using enum LuaData_t; + const LuaData_t type = Lua::getUserdataType(L, 2); + if (type != Player && type != Monster && type != Npc) { + Lua::pushBoolean(L, false); return 1; } } - const auto &creature = getCreature(L, 2); + const auto &creature = Lua::getCreature(L, 2); if (!creature) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const LuaVariant &variant = getVariant(L, 3); + const LuaVariant &variant = Lua::getVariant(L, 3); combat->setInstantSpellName(variant.instantName); combat->setRuneSpellName(variant.runeName); bool result = true; @@ -166,7 +190,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { case VARIANT_NUMBER: { const std::shared_ptr &target = g_game().getCreatureByID(variant.number); if (!target) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -196,7 +220,7 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { case VARIANT_STRING: { const std::shared_ptr &target = g_game().getPlayerByName(variant.text); if (!target) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -205,8 +229,8 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } case VARIANT_NONE: { - reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -215,6 +239,6 @@ int CombatFunctions::luaCombatExecute(lua_State* L) { } } - pushBoolean(L, result); + Lua::pushBoolean(L, result); return 1; } diff --git a/src/lua/functions/creatures/combat/combat_functions.hpp b/src/lua/functions/creatures/combat/combat_functions.hpp index a24b7c63bdd..9cf0923eb67 100644 --- a/src/lua/functions/creatures/combat/combat_functions.hpp +++ b/src/lua/functions/creatures/combat/combat_functions.hpp @@ -9,37 +9,13 @@ #pragma once -#include "lua/scripts/luascript.hpp" #include "lua/functions/creatures/combat/condition_functions.hpp" #include "lua/functions/creatures/combat/spell_functions.hpp" #include "lua/functions/creatures/combat/variant_functions.hpp" -class CombatFunctions final : LuaScriptInterface { +class CombatFunctions { public: - explicit CombatFunctions(lua_State* L) : - LuaScriptInterface("CombatFunctions") { - init(L); - } - ~CombatFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Combat", "", CombatFunctions::luaCombatCreate); - registerMetaMethod(L, "Combat", "__eq", CombatFunctions::luaUserdataCompare); - - registerMethod(L, "Combat", "setParameter", CombatFunctions::luaCombatSetParameter); - registerMethod(L, "Combat", "setFormula", CombatFunctions::luaCombatSetFormula); - - registerMethod(L, "Combat", "setArea", CombatFunctions::luaCombatSetArea); - registerMethod(L, "Combat", "addCondition", CombatFunctions::luaCombatSetCondition); - registerMethod(L, "Combat", "setCallback", CombatFunctions::luaCombatSetCallback); - registerMethod(L, "Combat", "setOrigin", CombatFunctions::luaCombatSetOrigin); - - registerMethod(L, "Combat", "execute", CombatFunctions::luaCombatExecute); - - ConditionFunctions::init(L); - SpellFunctions::init(L); - VariantFunctions::init(L); - } + static void init(lua_State* L); private: static int luaCombatCreate(lua_State* L); diff --git a/src/lua/functions/creatures/combat/condition_functions.cpp b/src/lua/functions/creatures/combat/condition_functions.cpp index 1362f0f1f31..0f2f9a56759 100644 --- a/src/lua/functions/creatures/combat/condition_functions.cpp +++ b/src/lua/functions/creatures/combat/condition_functions.cpp @@ -12,23 +12,48 @@ #include "creatures/combat/condition.hpp" #include "enums/player_icons.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ConditionFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Condition", "", ConditionFunctions::luaConditionCreate); + Lua::registerMetaMethod(L, "Condition", "__eq", Lua::luaUserdataCompare); + Lua::registerMetaMethod(L, "Condition", "__gc", ConditionFunctions::luaConditionDelete); + Lua::registerMethod(L, "Condition", "delete", ConditionFunctions::luaConditionDelete); + + Lua::registerMethod(L, "Condition", "getId", ConditionFunctions::luaConditionGetId); + Lua::registerMethod(L, "Condition", "getSubId", ConditionFunctions::luaConditionGetSubId); + Lua::registerMethod(L, "Condition", "getType", ConditionFunctions::luaConditionGetType); + Lua::registerMethod(L, "Condition", "getIcons", ConditionFunctions::luaConditionGetIcons); + Lua::registerMethod(L, "Condition", "getEndTime", ConditionFunctions::luaConditionGetEndTime); + + Lua::registerMethod(L, "Condition", "clone", ConditionFunctions::luaConditionClone); + + Lua::registerMethod(L, "Condition", "getTicks", ConditionFunctions::luaConditionGetTicks); + Lua::registerMethod(L, "Condition", "setTicks", ConditionFunctions::luaConditionSetTicks); + + Lua::registerMethod(L, "Condition", "setParameter", ConditionFunctions::luaConditionSetParameter); + Lua::registerMethod(L, "Condition", "setFormula", ConditionFunctions::luaConditionSetFormula); + Lua::registerMethod(L, "Condition", "setOutfit", ConditionFunctions::luaConditionSetOutfit); + + Lua::registerMethod(L, "Condition", "addDamage", ConditionFunctions::luaConditionAddDamage); +} int ConditionFunctions::luaConditionCreate(lua_State* L) { // Condition(conditionType, conditionId = CONDITIONID_COMBAT, subid = 0, isPersistent = false) - const ConditionType_t conditionType = getNumber(L, 2); + const ConditionType_t conditionType = Lua::getNumber(L, 2); if (conditionType == CONDITION_NONE) { - reportErrorFunc("Invalid condition type"); + Lua::reportErrorFunc("Invalid condition type"); return 1; } - const auto conditionId = getNumber(L, 3, CONDITIONID_COMBAT); - const auto subId = getNumber(L, 4, 0); - const bool isPersistent = getBoolean(L, 5, false); + const auto conditionId = Lua::getNumber(L, 3, CONDITIONID_COMBAT); + const auto subId = Lua::getNumber(L, 4, 0); + const bool isPersistent = Lua::getBoolean(L, 5, false); const auto &condition = Condition::createCondition(conditionId, conditionType, 0, 0, false, subId, isPersistent); if (condition) { - pushUserdata(L, condition); - setMetatable(L, -1, "Condition"); + Lua::pushUserdata(L, condition); + Lua::setMetatable(L, -1, "Condition"); } else { lua_pushnil(L); } @@ -37,7 +62,7 @@ int ConditionFunctions::luaConditionCreate(lua_State* L) { int ConditionFunctions::luaConditionDelete(lua_State* L) { // condition:delete() - std::shared_ptr* conditionPtr = getRawUserDataShared(L, 1); + std::shared_ptr* conditionPtr = Lua::getRawUserDataShared(L, 1); if (conditionPtr && *conditionPtr) { conditionPtr->reset(); } @@ -46,7 +71,7 @@ int ConditionFunctions::luaConditionDelete(lua_State* L) { int ConditionFunctions::luaConditionGetId(lua_State* L) { // condition:getId() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getId()); } else { @@ -57,7 +82,7 @@ int ConditionFunctions::luaConditionGetId(lua_State* L) { int ConditionFunctions::luaConditionGetSubId(lua_State* L) { // condition:getSubId() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getSubId()); } else { @@ -68,7 +93,7 @@ int ConditionFunctions::luaConditionGetSubId(lua_State* L) { int ConditionFunctions::luaConditionGetType(lua_State* L) { // condition:getType() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getType()); } else { @@ -79,7 +104,7 @@ int ConditionFunctions::luaConditionGetType(lua_State* L) { int ConditionFunctions::luaConditionGetIcons(lua_State* L) { // condition:getIcons() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { const auto icons = condition->getIcons(); lua_newtable(L); // Creates a new table on the Lua stack @@ -96,7 +121,7 @@ int ConditionFunctions::luaConditionGetIcons(lua_State* L) { int ConditionFunctions::luaConditionGetEndTime(lua_State* L) { // condition:getEndTime() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getEndTime()); } else { @@ -107,10 +132,10 @@ int ConditionFunctions::luaConditionGetEndTime(lua_State* L) { int ConditionFunctions::luaConditionClone(lua_State* L) { // condition:clone() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { - pushUserdata(L, condition->clone()); - setMetatable(L, -1, "Condition"); + Lua::pushUserdata(L, condition->clone()); + Lua::setMetatable(L, -1, "Condition"); } else { lua_pushnil(L); } @@ -119,7 +144,7 @@ int ConditionFunctions::luaConditionClone(lua_State* L) { int ConditionFunctions::luaConditionGetTicks(lua_State* L) { // condition:getTicks() - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { lua_pushnumber(L, condition->getTicks()); } else { @@ -130,11 +155,11 @@ int ConditionFunctions::luaConditionGetTicks(lua_State* L) { int ConditionFunctions::luaConditionSetTicks(lua_State* L) { // condition:setTicks(ticks) - const int32_t ticks = getNumber(L, 2); - const auto &condition = getUserdataShared(L, 1); + const int32_t ticks = Lua::getNumber(L, 2); + const auto &condition = Lua::getUserdataShared(L, 1); if (condition) { condition->setTicks(ticks); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -143,34 +168,34 @@ int ConditionFunctions::luaConditionSetTicks(lua_State* L) { int ConditionFunctions::luaConditionSetParameter(lua_State* L) { // condition:setParameter(key, value) - const auto &condition = getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 1); if (!condition) { lua_pushnil(L); return 1; } - const ConditionParam_t key = getNumber(L, 2); + const ConditionParam_t key = Lua::getNumber(L, 2); int32_t value; - if (isBoolean(L, 3)) { - value = getBoolean(L, 3) ? 1 : 0; + if (Lua::isBoolean(L, 3)) { + value = Lua::getBoolean(L, 3) ? 1 : 0; } else { - value = getNumber(L, 3); + value = Lua::getNumber(L, 3); } condition->setParam(key, value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ConditionFunctions::luaConditionSetFormula(lua_State* L) { // condition:setFormula(mina, minb, maxa, maxb) - const double maxb = getNumber(L, 5); - const double maxa = getNumber(L, 4); - const double minb = getNumber(L, 3); - const double mina = getNumber(L, 2); - const std::shared_ptr &condition = getUserdataShared(L, 1)->dynamic_self_cast(); + const double maxb = Lua::getNumber(L, 5); + const double maxa = Lua::getNumber(L, 4); + const double minb = Lua::getNumber(L, 3); + const double mina = Lua::getNumber(L, 2); + const std::shared_ptr &condition = Lua::getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { condition->setFormulaVars(mina, minb, maxa, maxb); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -182,28 +207,28 @@ int ConditionFunctions::luaConditionSetOutfit(lua_State* L) { // condition:setOutfit(lookTypeEx, lookType, lookHead, lookBody, lookLegs, lookFeet[, // lookAddons[, lookMount[, lookMountHead[, lookMountBody[, lookMountLegs[, lookMountFeet[, lookFamiliarsType]]]]]]]) Outfit_t outfit; - if (isTable(L, 2)) { - outfit = getOutfit(L, 2); + if (Lua::isTable(L, 2)) { + outfit = Lua::getOutfit(L, 2); } else { - outfit.lookFamiliarsType = getNumber(L, 14, outfit.lookFamiliarsType); - outfit.lookMountFeet = getNumber(L, 13, outfit.lookMountFeet); - outfit.lookMountLegs = getNumber(L, 12, outfit.lookMountLegs); - outfit.lookMountBody = getNumber(L, 11, outfit.lookMountBody); - outfit.lookMountHead = getNumber(L, 10, outfit.lookMountHead); - outfit.lookMount = getNumber(L, 9, outfit.lookMount); - outfit.lookAddons = getNumber(L, 8, outfit.lookAddons); - outfit.lookFeet = getNumber(L, 7); - outfit.lookLegs = getNumber(L, 6); - outfit.lookBody = getNumber(L, 5); - outfit.lookHead = getNumber(L, 4); - outfit.lookType = getNumber(L, 3); - outfit.lookTypeEx = getNumber(L, 2); - } - - const std::shared_ptr &condition = getUserdataShared(L, 1)->dynamic_self_cast(); + outfit.lookFamiliarsType = Lua::getNumber(L, 14, outfit.lookFamiliarsType); + outfit.lookMountFeet = Lua::getNumber(L, 13, outfit.lookMountFeet); + outfit.lookMountLegs = Lua::getNumber(L, 12, outfit.lookMountLegs); + outfit.lookMountBody = Lua::getNumber(L, 11, outfit.lookMountBody); + outfit.lookMountHead = Lua::getNumber(L, 10, outfit.lookMountHead); + outfit.lookMount = Lua::getNumber(L, 9, outfit.lookMount); + outfit.lookAddons = Lua::getNumber(L, 8, outfit.lookAddons); + outfit.lookFeet = Lua::getNumber(L, 7); + outfit.lookLegs = Lua::getNumber(L, 6); + outfit.lookBody = Lua::getNumber(L, 5); + outfit.lookHead = Lua::getNumber(L, 4); + outfit.lookType = Lua::getNumber(L, 3); + outfit.lookTypeEx = Lua::getNumber(L, 2); + } + + const std::shared_ptr &condition = Lua::getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { condition->setOutfit(outfit); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -212,12 +237,12 @@ int ConditionFunctions::luaConditionSetOutfit(lua_State* L) { int ConditionFunctions::luaConditionAddDamage(lua_State* L) { // condition:addDamage(rounds, time, value) - const int32_t value = getNumber(L, 4); - const int32_t time = getNumber(L, 3); - const int32_t rounds = getNumber(L, 2); - const std::shared_ptr &condition = getUserdataShared(L, 1)->dynamic_self_cast(); + const int32_t value = Lua::getNumber(L, 4); + const int32_t time = Lua::getNumber(L, 3); + const int32_t rounds = Lua::getNumber(L, 2); + const std::shared_ptr &condition = Lua::getUserdataShared(L, 1)->dynamic_self_cast(); if (condition) { - pushBoolean(L, condition->addDamage(rounds, time, value)); + Lua::pushBoolean(L, condition->addDamage(rounds, time, value)); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/combat/condition_functions.hpp b/src/lua/functions/creatures/combat/condition_functions.hpp index 931a4fc2f5e..e8a3e834207 100644 --- a/src/lua/functions/creatures/combat/condition_functions.hpp +++ b/src/lua/functions/creatures/combat/condition_functions.hpp @@ -9,39 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ConditionFunctions final : LuaScriptInterface { +class ConditionFunctions { public: - explicit ConditionFunctions(lua_State* L) : - LuaScriptInterface("ConditionFunctions") { - init(L); - } - ~ConditionFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Condition", "", ConditionFunctions::luaConditionCreate); - registerMetaMethod(L, "Condition", "__eq", ConditionFunctions::luaUserdataCompare); - registerMetaMethod(L, "Condition", "__gc", ConditionFunctions::luaConditionDelete); - registerMethod(L, "Condition", "delete", ConditionFunctions::luaConditionDelete); - - registerMethod(L, "Condition", "getId", ConditionFunctions::luaConditionGetId); - registerMethod(L, "Condition", "getSubId", ConditionFunctions::luaConditionGetSubId); - registerMethod(L, "Condition", "getType", ConditionFunctions::luaConditionGetType); - registerMethod(L, "Condition", "getIcons", ConditionFunctions::luaConditionGetIcons); - registerMethod(L, "Condition", "getEndTime", ConditionFunctions::luaConditionGetEndTime); - - registerMethod(L, "Condition", "clone", ConditionFunctions::luaConditionClone); - - registerMethod(L, "Condition", "getTicks", ConditionFunctions::luaConditionGetTicks); - registerMethod(L, "Condition", "setTicks", ConditionFunctions::luaConditionSetTicks); - - registerMethod(L, "Condition", "setParameter", ConditionFunctions::luaConditionSetParameter); - registerMethod(L, "Condition", "setFormula", ConditionFunctions::luaConditionSetFormula); - registerMethod(L, "Condition", "setOutfit", ConditionFunctions::luaConditionSetOutfit); - - registerMethod(L, "Condition", "addDamage", ConditionFunctions::luaConditionAddDamage); - } + static void init(lua_State* L); private: static int luaConditionCreate(lua_State* L); diff --git a/src/lua/functions/creatures/combat/spell_functions.cpp b/src/lua/functions/creatures/combat/spell_functions.cpp index 1a19485afd4..0d2d4a955ef 100644 --- a/src/lua/functions/creatures/combat/spell_functions.cpp +++ b/src/lua/functions/creatures/combat/spell_functions.cpp @@ -13,6 +13,55 @@ #include "creatures/players/vocations/vocation.hpp" #include "items/item.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void SpellFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Spell", "", SpellFunctions::luaSpellCreate); + Lua::registerMetaMethod(L, "Spell", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Spell", "onCastSpell", SpellFunctions::luaSpellOnCastSpell); + Lua::registerMethod(L, "Spell", "register", SpellFunctions::luaSpellRegister); + Lua::registerMethod(L, "Spell", "name", SpellFunctions::luaSpellName); + Lua::registerMethod(L, "Spell", "id", SpellFunctions::luaSpellId); + Lua::registerMethod(L, "Spell", "group", SpellFunctions::luaSpellGroup); + Lua::registerMethod(L, "Spell", "cooldown", SpellFunctions::luaSpellCooldown); + Lua::registerMethod(L, "Spell", "groupCooldown", SpellFunctions::luaSpellGroupCooldown); + Lua::registerMethod(L, "Spell", "level", SpellFunctions::luaSpellLevel); + Lua::registerMethod(L, "Spell", "magicLevel", SpellFunctions::luaSpellMagicLevel); + Lua::registerMethod(L, "Spell", "mana", SpellFunctions::luaSpellMana); + Lua::registerMethod(L, "Spell", "manaPercent", SpellFunctions::luaSpellManaPercent); + Lua::registerMethod(L, "Spell", "soul", SpellFunctions::luaSpellSoul); + Lua::registerMethod(L, "Spell", "range", SpellFunctions::luaSpellRange); + Lua::registerMethod(L, "Spell", "isPremium", SpellFunctions::luaSpellPremium); + Lua::registerMethod(L, "Spell", "isEnabled", SpellFunctions::luaSpellEnabled); + Lua::registerMethod(L, "Spell", "needTarget", SpellFunctions::luaSpellNeedTarget); + Lua::registerMethod(L, "Spell", "needWeapon", SpellFunctions::luaSpellNeedWeapon); + Lua::registerMethod(L, "Spell", "needLearn", SpellFunctions::luaSpellNeedLearn); + Lua::registerMethod(L, "Spell", "allowOnSelf", SpellFunctions::luaSpellAllowOnSelf); + Lua::registerMethod(L, "Spell", "setPzLocked", SpellFunctions::luaSpellPzLocked); + Lua::registerMethod(L, "Spell", "isSelfTarget", SpellFunctions::luaSpellSelfTarget); + Lua::registerMethod(L, "Spell", "isBlocking", SpellFunctions::luaSpellBlocking); + Lua::registerMethod(L, "Spell", "isAggressive", SpellFunctions::luaSpellAggressive); + Lua::registerMethod(L, "Spell", "vocation", SpellFunctions::luaSpellVocation); + + Lua::registerMethod(L, "Spell", "castSound", SpellFunctions::luaSpellCastSound); + Lua::registerMethod(L, "Spell", "impactSound", SpellFunctions::luaSpellImpactSound); + + // Only for InstantSpell. + Lua::registerMethod(L, "Spell", "words", SpellFunctions::luaSpellWords); + Lua::registerMethod(L, "Spell", "needDirection", SpellFunctions::luaSpellNeedDirection); + Lua::registerMethod(L, "Spell", "hasParams", SpellFunctions::luaSpellHasParams); + Lua::registerMethod(L, "Spell", "hasPlayerNameParam", SpellFunctions::luaSpellHasPlayerNameParam); + Lua::registerMethod(L, "Spell", "needCasterTargetOrDirection", SpellFunctions::luaSpellNeedCasterTargetOrDirection); + Lua::registerMethod(L, "Spell", "isBlockingWalls", SpellFunctions::luaSpellIsBlockingWalls); + + // Only for RuneSpells. + Lua::registerMethod(L, "Spell", "runeId", SpellFunctions::luaSpellRuneId); + Lua::registerMethod(L, "Spell", "charges", SpellFunctions::luaSpellCharges); + Lua::registerMethod(L, "Spell", "allowFarUse", SpellFunctions::luaSpellAllowFarUse); + Lua::registerMethod(L, "Spell", "blockWalls", SpellFunctions::luaSpellBlockWalls); + Lua::registerMethod(L, "Spell", "checkFloor", SpellFunctions::luaSpellCheckFloor); +} int SpellFunctions::luaSpellCreate(lua_State* L) { // Spell(words, name or id) to get an existing spell @@ -26,35 +75,35 @@ int SpellFunctions::luaSpellCreate(lua_State* L) { SpellType_t spellType = SPELL_UNDEFINED; - if (isNumber(L, 2)) { - uint16_t id = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + uint16_t id = Lua::getNumber(L, 2); const auto &rune = g_spells().getRuneSpell(id); if (rune) { - pushUserdata(L, rune); - setMetatable(L, -1, "Spell"); + Lua::pushUserdata(L, rune); + Lua::setMetatable(L, -1, "Spell"); return 1; } spellType = static_cast(id); - } else if (isString(L, 2)) { - const std::string arg = getString(L, 2); + } else if (Lua::isString(L, 2)) { + const std::string arg = Lua::getString(L, 2); auto instant = g_spells().getInstantSpellByName(arg); if (instant) { - pushUserdata(L, instant); - setMetatable(L, -1, "Spell"); + Lua::pushUserdata(L, instant); + Lua::setMetatable(L, -1, "Spell"); return 1; } instant = g_spells().getInstantSpell(arg); if (instant) { - pushUserdata(L, instant); - setMetatable(L, -1, "Spell"); + Lua::pushUserdata(L, instant); + Lua::setMetatable(L, -1, "Spell"); return 1; } const auto &rune = g_spells().getRuneSpellByName(arg); if (rune) { - pushUserdata(L, rune); - setMetatable(L, -1, "Spell"); + Lua::pushUserdata(L, rune); + Lua::setMetatable(L, -1, "Spell"); return 1; } @@ -67,15 +116,15 @@ int SpellFunctions::luaSpellCreate(lua_State* L) { } if (spellType == SPELL_INSTANT) { - const auto &spell = std::make_shared(getScriptEnv()->getScriptInterface()); - pushUserdata(L, spell); - setMetatable(L, -1, "Spell"); + const auto &spell = std::make_shared(); + Lua::pushUserdata(L, spell); + Lua::setMetatable(L, -1, "Spell"); spell->spellType = SPELL_INSTANT; return 1; } else if (spellType == SPELL_RUNE) { - const auto &runeSpell = std::make_shared(getScriptEnv()->getScriptInterface()); - pushUserdata(L, runeSpell); - setMetatable(L, -1, "Spell"); + const auto &runeSpell = std::make_shared(); + Lua::pushUserdata(L, runeSpell); + Lua::setMetatable(L, -1, "Spell"); runeSpell->spellType = SPELL_RUNE; return 1; } @@ -86,24 +135,22 @@ int SpellFunctions::luaSpellCreate(lua_State* L) { int SpellFunctions::luaSpellOnCastSpell(lua_State* L) { // spell:onCastSpell(callback) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (spell->spellType == SPELL_INSTANT) { const auto &instant = std::static_pointer_cast(spell); - if (!instant->loadCallback()) { - pushBoolean(L, false); + if (!instant->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - instant->setLoadedCallback(true); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else if (spell->spellType == SPELL_RUNE) { const auto &rune = std::static_pointer_cast(spell); - if (!rune->loadCallback()) { - pushBoolean(L, false); + if (!rune->loadRuneSpellScriptId()) { + Lua::pushBoolean(L, false); return 1; } - rune->setLoadedCallback(true); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -113,23 +160,23 @@ int SpellFunctions::luaSpellOnCastSpell(lua_State* L) { int SpellFunctions::luaSpellRegister(lua_State* L) { // spell:register() - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (!spell) { - reportErrorFunc(getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (spell->spellType == SPELL_INSTANT) { - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &instant = std::static_pointer_cast(spellBase); - if (!instant->isLoadedCallback()) { - pushBoolean(L, false); + if (!instant->isLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_spells().registerInstantLuaEvent(instant)); + Lua::pushBoolean(L, g_spells().registerInstantLuaEvent(instant)); } else if (spell->spellType == SPELL_RUNE) { - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &rune = std::static_pointer_cast(spellBase); if (rune->getMagicLevel() != 0 || rune->getLevel() != 0) { // Change information in the ItemType to get accurate description @@ -142,11 +189,11 @@ int SpellFunctions::luaSpellRegister(lua_State* L) { iType.runeLevel = rune->getLevel(); iType.charges = rune->getCharges(); } - if (!rune->isLoadedCallback()) { - pushBoolean(L, false); + if (!rune->isRuneSpellLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_spells().registerRuneLuaEvent(rune)); + Lua::pushBoolean(L, g_spells().registerRuneLuaEvent(rune)); } return 1; } @@ -154,13 +201,13 @@ int SpellFunctions::luaSpellRegister(lua_State* L) { int SpellFunctions::luaSpellName(lua_State* L) { // spell:name(name) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushString(L, spell->getName()); + Lua::pushString(L, spell->getName()); } else { - spell->setName(getString(L, 2)); - pushBoolean(L, true); + spell->setName(Lua::getString(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -170,18 +217,18 @@ int SpellFunctions::luaSpellName(lua_State* L) { int SpellFunctions::luaSpellId(lua_State* L) { // spell:id(id) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (spell->spellType != SPELL_INSTANT && spell->spellType != SPELL_RUNE) { - reportErrorFunc("The method: 'spell:id(id)' is only for use of instant spells and rune spells"); - pushBoolean(L, false); + Lua::reportErrorFunc("The method: 'spell:id(id)' is only for use of instant spells and rune spells"); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getSpellId()); } else { - spell->setSpellId(getNumber(L, 2)); - pushBoolean(L, true); + spell->setSpellId(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -191,70 +238,70 @@ int SpellFunctions::luaSpellId(lua_State* L) { int SpellFunctions::luaSpellGroup(lua_State* L) { // spell:group(primaryGroup[, secondaryGroup]) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getGroup()); lua_pushnumber(L, spell->getSecondaryGroup()); return 2; } else if (lua_gettop(L) == 2) { - auto group = getNumber(L, 2); + auto group = Lua::getNumber(L, 2); if (group) { spell->setGroup(group); - pushBoolean(L, true); - } else if (isString(L, 2)) { - group = stringToSpellGroup(getString(L, 2)); + Lua::pushBoolean(L, true); + } else if (Lua::isString(L, 2)) { + group = stringToSpellGroup(Lua::getString(L, 2)); if (group != SPELLGROUP_NONE) { spell->setGroup(group); } else { g_logger().warn("[SpellFunctions::luaSpellGroup] - " "Unknown group: {}", - getString(L, 2)); - pushBoolean(L, false); + Lua::getString(L, 2)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { g_logger().warn("[SpellFunctions::luaSpellGroup] - " "Unknown group: {}", - getString(L, 2)); - pushBoolean(L, false); + Lua::getString(L, 2)); + Lua::pushBoolean(L, false); return 1; } } else { - auto primaryGroup = getNumber(L, 2); - auto secondaryGroup = getNumber(L, 2); + auto primaryGroup = Lua::getNumber(L, 2); + auto secondaryGroup = Lua::getNumber(L, 2); if (primaryGroup && secondaryGroup) { spell->setGroup(primaryGroup); spell->setSecondaryGroup(secondaryGroup); - pushBoolean(L, true); - } else if (isString(L, 2) && isString(L, 3)) { - primaryGroup = stringToSpellGroup(getString(L, 2)); + Lua::pushBoolean(L, true); + } else if (Lua::isString(L, 2) && Lua::isString(L, 3)) { + primaryGroup = stringToSpellGroup(Lua::getString(L, 2)); if (primaryGroup != SPELLGROUP_NONE) { spell->setGroup(primaryGroup); } else { g_logger().warn("[SpellFunctions::luaSpellGroup] - " "Unknown primaryGroup: {}", - getString(L, 2)); - pushBoolean(L, false); + Lua::getString(L, 2)); + Lua::pushBoolean(L, false); return 1; } - secondaryGroup = stringToSpellGroup(getString(L, 3)); + secondaryGroup = stringToSpellGroup(Lua::getString(L, 3)); if (secondaryGroup != SPELLGROUP_NONE) { spell->setSecondaryGroup(secondaryGroup); } else { g_logger().warn("[SpellFunctions::luaSpellGroup] - " "Unknown secondaryGroup: {}", - getString(L, 3)); - pushBoolean(L, false); + Lua::getString(L, 3)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { g_logger().warn("[SpellFunctions::luaSpellGroup] - " "Unknown primaryGroup: {} or secondaryGroup: {}", - getString(L, 2), getString(L, 3)); - pushBoolean(L, false); + Lua::getString(L, 2), Lua::getString(L, 3)); + Lua::pushBoolean(L, false); return 1; } } @@ -266,13 +313,13 @@ int SpellFunctions::luaSpellGroup(lua_State* L) { int SpellFunctions::luaSpellCastSound(lua_State* L) { // get: spell:castSound() set: spell:castSound(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(spell->soundCastEffect)); } else { - spell->soundCastEffect = static_cast(getNumber(L, 2)); - pushBoolean(L, true); + spell->soundCastEffect = static_cast(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -282,13 +329,13 @@ int SpellFunctions::luaSpellCastSound(lua_State* L) { int SpellFunctions::luaSpellImpactSound(lua_State* L) { // get: spell:impactSound() set: spell:impactSound(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(spell->soundImpactEffect)); } else { - spell->soundImpactEffect = static_cast(getNumber(L, 2)); - pushBoolean(L, true); + spell->soundImpactEffect = static_cast(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -298,13 +345,13 @@ int SpellFunctions::luaSpellImpactSound(lua_State* L) { int SpellFunctions::luaSpellCooldown(lua_State* L) { // spell:cooldown(cooldown) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getCooldown()); } else { - spell->setCooldown(getNumber(L, 2)); - pushBoolean(L, true); + spell->setCooldown(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -314,19 +361,19 @@ int SpellFunctions::luaSpellCooldown(lua_State* L) { int SpellFunctions::luaSpellGroupCooldown(lua_State* L) { // spell:groupCooldown(primaryGroupCd[, secondaryGroupCd]) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getGroupCooldown()); lua_pushnumber(L, spell->getSecondaryCooldown()); return 2; } else if (lua_gettop(L) == 2) { - spell->setGroupCooldown(getNumber(L, 2)); - pushBoolean(L, true); + spell->setGroupCooldown(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { - spell->setGroupCooldown(getNumber(L, 2)); - spell->setSecondaryCooldown(getNumber(L, 3)); - pushBoolean(L, true); + spell->setGroupCooldown(Lua::getNumber(L, 2)); + spell->setSecondaryCooldown(Lua::getNumber(L, 3)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -336,13 +383,13 @@ int SpellFunctions::luaSpellGroupCooldown(lua_State* L) { int SpellFunctions::luaSpellLevel(lua_State* L) { // spell:level(lvl) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getLevel()); } else { - spell->setLevel(getNumber(L, 2)); - pushBoolean(L, true); + spell->setLevel(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -352,13 +399,13 @@ int SpellFunctions::luaSpellLevel(lua_State* L) { int SpellFunctions::luaSpellMagicLevel(lua_State* L) { // spell:magicLevel(lvl) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getMagicLevel()); } else { - spell->setMagicLevel(getNumber(L, 2)); - pushBoolean(L, true); + spell->setMagicLevel(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -368,13 +415,13 @@ int SpellFunctions::luaSpellMagicLevel(lua_State* L) { int SpellFunctions::luaSpellMana(lua_State* L) { // spell:mana(mana) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getMana()); } else { - spell->setMana(getNumber(L, 2)); - pushBoolean(L, true); + spell->setMana(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -384,13 +431,13 @@ int SpellFunctions::luaSpellMana(lua_State* L) { int SpellFunctions::luaSpellManaPercent(lua_State* L) { // spell:manaPercent(percent) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getManaPercent()); } else { - spell->setManaPercent(getNumber(L, 2)); - pushBoolean(L, true); + spell->setManaPercent(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -400,13 +447,13 @@ int SpellFunctions::luaSpellManaPercent(lua_State* L) { int SpellFunctions::luaSpellSoul(lua_State* L) { // spell:soul(soul) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getSoulCost()); } else { - spell->setSoulCost(getNumber(L, 2)); - pushBoolean(L, true); + spell->setSoulCost(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -416,13 +463,13 @@ int SpellFunctions::luaSpellSoul(lua_State* L) { int SpellFunctions::luaSpellRange(lua_State* L) { // spell:range(range) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getRange()); } else { - spell->setRange(getNumber(L, 2)); - pushBoolean(L, true); + spell->setRange(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -432,13 +479,13 @@ int SpellFunctions::luaSpellRange(lua_State* L) { int SpellFunctions::luaSpellPremium(lua_State* L) { // spell:isPremium(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->isPremium()); + Lua::pushBoolean(L, spell->isPremium()); } else { - spell->setPremium(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setPremium(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -448,13 +495,13 @@ int SpellFunctions::luaSpellPremium(lua_State* L) { int SpellFunctions::luaSpellEnabled(lua_State* L) { // spell:isEnabled(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->isEnabled()); + Lua::pushBoolean(L, spell->isEnabled()); } else { - spell->setEnabled(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setEnabled(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -464,13 +511,13 @@ int SpellFunctions::luaSpellEnabled(lua_State* L) { int SpellFunctions::luaSpellNeedTarget(lua_State* L) { // spell:needTarget(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getNeedTarget()); + Lua::pushBoolean(L, spell->getNeedTarget()); } else { - spell->setNeedTarget(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setNeedTarget(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -480,13 +527,13 @@ int SpellFunctions::luaSpellNeedTarget(lua_State* L) { int SpellFunctions::luaSpellNeedWeapon(lua_State* L) { // spell:needWeapon(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getNeedWeapon()); + Lua::pushBoolean(L, spell->getNeedWeapon()); } else { - spell->setNeedWeapon(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setNeedWeapon(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -496,13 +543,13 @@ int SpellFunctions::luaSpellNeedWeapon(lua_State* L) { int SpellFunctions::luaSpellNeedLearn(lua_State* L) { // spell:needLearn(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getNeedLearn()); + Lua::pushBoolean(L, spell->getNeedLearn()); } else { - spell->setNeedLearn(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setNeedLearn(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -512,12 +559,12 @@ int SpellFunctions::luaSpellNeedLearn(lua_State* L) { int SpellFunctions::luaSpellSelfTarget(lua_State* L) { // spell:isSelfTarget(bool) - if (const auto &spell = getUserdataShared(L, 1)) { + if (const auto &spell = Lua::getUserdataShared(L, 1)) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getSelfTarget()); + Lua::pushBoolean(L, spell->getSelfTarget()); } else { - spell->setSelfTarget(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setSelfTarget(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -527,15 +574,15 @@ int SpellFunctions::luaSpellSelfTarget(lua_State* L) { int SpellFunctions::luaSpellBlocking(lua_State* L) { // spell:isBlocking(blockingSolid, blockingCreature) - if (const auto &spell = getUserdataShared(L, 1)) { + if (const auto &spell = Lua::getUserdataShared(L, 1)) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getBlockingSolid()); - pushBoolean(L, spell->getBlockingCreature()); + Lua::pushBoolean(L, spell->getBlockingSolid()); + Lua::pushBoolean(L, spell->getBlockingCreature()); return 2; } else { - spell->setBlockingSolid(getBoolean(L, 2)); - spell->setBlockingCreature(getBoolean(L, 3)); - pushBoolean(L, true); + spell->setBlockingSolid(Lua::getBoolean(L, 2)); + spell->setBlockingCreature(Lua::getBoolean(L, 3)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -545,13 +592,13 @@ int SpellFunctions::luaSpellBlocking(lua_State* L) { int SpellFunctions::luaSpellAggressive(lua_State* L) { // spell:isAggressive(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getAggressive()); + Lua::pushBoolean(L, spell->getAggressive()); } else { - spell->setAggressive(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setAggressive(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -561,13 +608,13 @@ int SpellFunctions::luaSpellAggressive(lua_State* L) { int SpellFunctions::luaSpellAllowOnSelf(lua_State* L) { // spell:allowOnSelf(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getAllowOnSelf()); + Lua::pushBoolean(L, spell->getAllowOnSelf()); } else { - spell->setAllowOnSelf(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setAllowOnSelf(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -577,13 +624,13 @@ int SpellFunctions::luaSpellAllowOnSelf(lua_State* L) { int SpellFunctions::luaSpellPzLocked(lua_State* L) { // spell:isPzLocked(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getLockedPZ()); + Lua::pushBoolean(L, spell->getLockedPZ()); } else { - spell->setLockedPZ(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setLockedPZ(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -593,7 +640,7 @@ int SpellFunctions::luaSpellPzLocked(lua_State* L) { int SpellFunctions::luaSpellVocation(lua_State* L) { // spell:vocation(vocation) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { if (lua_gettop(L) == 1) { lua_createtable(L, 0, 0); @@ -603,14 +650,14 @@ int SpellFunctions::luaSpellVocation(lua_State* L) { std::string s = std::to_string(it); const char* pchar = s.c_str(); std::string name = g_vocations().getVocation(voc.first)->getVocName(); - setField(L, pchar, name); + Lua::setField(L, pchar, name); } - setMetatable(L, -1, "Spell"); + Lua::setMetatable(L, -1, "Spell"); } else { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc for (int i = 0; i < parameters; ++i) { - if (getString(L, 2 + i).find(';') != std::string::npos) { - std::vector vocList = explodeString(getString(L, 2 + i), ";"); + if (Lua::getString(L, 2 + i).find(';') != std::string::npos) { + std::vector vocList = explodeString(Lua::getString(L, 2 + i), ";"); const int32_t vocationId = g_vocations().getVocationId(vocList[0]); if (!vocList.empty()) { if (vocList[1] == "true") { @@ -620,11 +667,11 @@ int SpellFunctions::luaSpellVocation(lua_State* L) { } } } else { - const int32_t vocationId = g_vocations().getVocationId(getString(L, 2 + i)); + const int32_t vocationId = g_vocations().getVocationId(Lua::getString(L, 2 + i)); spell->addVocMap(vocationId, false); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -635,7 +682,7 @@ int SpellFunctions::luaSpellVocation(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellWords(lua_State* L) { // spell:words(words[, separator = ""]) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -645,17 +692,17 @@ int SpellFunctions::luaSpellWords(lua_State* L) { } if (lua_gettop(L) == 1) { - pushString(L, spell->getWords()); - pushString(L, spell->getSeparator()); + Lua::pushString(L, spell->getWords()); + Lua::pushString(L, spell->getSeparator()); return 2; } else { std::string sep; if (lua_gettop(L) == 3) { - sep = getString(L, 3); + sep = Lua::getString(L, 3); } - spell->setWords(getString(L, 2)); + spell->setWords(Lua::getString(L, 2)); spell->setSeparator(sep); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -666,7 +713,7 @@ int SpellFunctions::luaSpellWords(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellNeedDirection(lua_State* L) { // spell:needDirection(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -676,10 +723,10 @@ int SpellFunctions::luaSpellNeedDirection(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getNeedDirection()); + Lua::pushBoolean(L, spell->getNeedDirection()); } else { - spell->setNeedDirection(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setNeedDirection(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -690,7 +737,7 @@ int SpellFunctions::luaSpellNeedDirection(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellHasParams(lua_State* L) { // spell:hasParams(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -700,10 +747,10 @@ int SpellFunctions::luaSpellHasParams(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getHasParam()); + Lua::pushBoolean(L, spell->getHasParam()); } else { - spell->setHasParam(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setHasParam(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -714,7 +761,7 @@ int SpellFunctions::luaSpellHasParams(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellHasPlayerNameParam(lua_State* L) { // spell:hasPlayerNameParam(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -724,10 +771,10 @@ int SpellFunctions::luaSpellHasPlayerNameParam(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getHasPlayerNameParam()); + Lua::pushBoolean(L, spell->getHasPlayerNameParam()); } else { - spell->setHasPlayerNameParam(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setHasPlayerNameParam(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -738,7 +785,7 @@ int SpellFunctions::luaSpellHasPlayerNameParam(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellNeedCasterTargetOrDirection(lua_State* L) { // spell:needCasterTargetOrDirection(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -748,10 +795,10 @@ int SpellFunctions::luaSpellNeedCasterTargetOrDirection(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getNeedCasterTargetOrDirection()); + Lua::pushBoolean(L, spell->getNeedCasterTargetOrDirection()); } else { - spell->setNeedCasterTargetOrDirection(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setNeedCasterTargetOrDirection(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -762,7 +809,7 @@ int SpellFunctions::luaSpellNeedCasterTargetOrDirection(lua_State* L) { // only for InstantSpells int SpellFunctions::luaSpellIsBlockingWalls(lua_State* L) { // spell:blockWalls(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_INSTANT, it means that this actually is no InstantSpell, so we return nil @@ -772,10 +819,10 @@ int SpellFunctions::luaSpellIsBlockingWalls(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getBlockWalls()); + Lua::pushBoolean(L, spell->getBlockWalls()); } else { - spell->setBlockWalls(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setBlockWalls(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -786,7 +833,7 @@ int SpellFunctions::luaSpellIsBlockingWalls(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellRuneId(lua_State* L) { // spell:runeId(id) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -798,8 +845,8 @@ int SpellFunctions::luaSpellRuneId(lua_State* L) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getRuneItemId()); } else { - spell->setRuneItemId(getNumber(L, 2)); - pushBoolean(L, true); + spell->setRuneItemId(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -810,7 +857,7 @@ int SpellFunctions::luaSpellRuneId(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellCharges(lua_State* L) { // spell:charges(charges) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -822,8 +869,8 @@ int SpellFunctions::luaSpellCharges(lua_State* L) { if (lua_gettop(L) == 1) { lua_pushnumber(L, spell->getCharges()); } else { - spell->setCharges(getNumber(L, 2)); - pushBoolean(L, true); + spell->setCharges(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -834,7 +881,7 @@ int SpellFunctions::luaSpellCharges(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellAllowFarUse(lua_State* L) { // spell:allowFarUse(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -844,10 +891,10 @@ int SpellFunctions::luaSpellAllowFarUse(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getAllowFarUse()); + Lua::pushBoolean(L, spell->getAllowFarUse()); } else { - spell->setAllowFarUse(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setAllowFarUse(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -858,7 +905,7 @@ int SpellFunctions::luaSpellAllowFarUse(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellBlockWalls(lua_State* L) { // spell:blockWalls(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -868,10 +915,10 @@ int SpellFunctions::luaSpellBlockWalls(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getCheckLineOfSight()); + Lua::pushBoolean(L, spell->getCheckLineOfSight()); } else { - spell->setCheckLineOfSight(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setCheckLineOfSight(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -882,7 +929,7 @@ int SpellFunctions::luaSpellBlockWalls(lua_State* L) { // only for RuneSpells int SpellFunctions::luaSpellCheckFloor(lua_State* L) { // spell:checkFloor(bool) - const auto &spellBase = getUserdataShared(L, 1); + const auto &spellBase = Lua::getUserdataShared(L, 1); const auto &spell = std::static_pointer_cast(spellBase); if (spell) { // if spell != SPELL_RUNE, it means that this actually is no RuneSpell, so we return nil @@ -892,10 +939,10 @@ int SpellFunctions::luaSpellCheckFloor(lua_State* L) { } if (lua_gettop(L) == 1) { - pushBoolean(L, spell->getCheckFloor()); + Lua::pushBoolean(L, spell->getCheckFloor()); } else { - spell->setCheckFloor(getBoolean(L, 2)); - pushBoolean(L, true); + spell->setCheckFloor(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); diff --git a/src/lua/functions/creatures/combat/spell_functions.hpp b/src/lua/functions/creatures/combat/spell_functions.hpp index 429ebe11270..684b8af8ba2 100644 --- a/src/lua/functions/creatures/combat/spell_functions.hpp +++ b/src/lua/functions/creatures/combat/spell_functions.hpp @@ -9,63 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class SpellFunctions final : LuaScriptInterface { +class SpellFunctions { public: - explicit SpellFunctions(lua_State* L) : - LuaScriptInterface("SpellFunctions") { - init(L); - } - ~SpellFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Spell", "", SpellFunctions::luaSpellCreate); - registerMetaMethod(L, "Spell", "__eq", SpellFunctions::luaUserdataCompare); - - registerMethod(L, "Spell", "onCastSpell", SpellFunctions::luaSpellOnCastSpell); - registerMethod(L, "Spell", "register", SpellFunctions::luaSpellRegister); - registerMethod(L, "Spell", "name", SpellFunctions::luaSpellName); - registerMethod(L, "Spell", "id", SpellFunctions::luaSpellId); - registerMethod(L, "Spell", "group", SpellFunctions::luaSpellGroup); - registerMethod(L, "Spell", "cooldown", SpellFunctions::luaSpellCooldown); - registerMethod(L, "Spell", "groupCooldown", SpellFunctions::luaSpellGroupCooldown); - registerMethod(L, "Spell", "level", SpellFunctions::luaSpellLevel); - registerMethod(L, "Spell", "magicLevel", SpellFunctions::luaSpellMagicLevel); - registerMethod(L, "Spell", "mana", SpellFunctions::luaSpellMana); - registerMethod(L, "Spell", "manaPercent", SpellFunctions::luaSpellManaPercent); - registerMethod(L, "Spell", "soul", SpellFunctions::luaSpellSoul); - registerMethod(L, "Spell", "range", SpellFunctions::luaSpellRange); - registerMethod(L, "Spell", "isPremium", SpellFunctions::luaSpellPremium); - registerMethod(L, "Spell", "isEnabled", SpellFunctions::luaSpellEnabled); - registerMethod(L, "Spell", "needTarget", SpellFunctions::luaSpellNeedTarget); - registerMethod(L, "Spell", "needWeapon", SpellFunctions::luaSpellNeedWeapon); - registerMethod(L, "Spell", "needLearn", SpellFunctions::luaSpellNeedLearn); - registerMethod(L, "Spell", "allowOnSelf", SpellFunctions::luaSpellAllowOnSelf); - registerMethod(L, "Spell", "setPzLocked", SpellFunctions::luaSpellPzLocked); - registerMethod(L, "Spell", "isSelfTarget", SpellFunctions::luaSpellSelfTarget); - registerMethod(L, "Spell", "isBlocking", SpellFunctions::luaSpellBlocking); - registerMethod(L, "Spell", "isAggressive", SpellFunctions::luaSpellAggressive); - registerMethod(L, "Spell", "vocation", SpellFunctions::luaSpellVocation); - - registerMethod(L, "Spell", "castSound", SpellFunctions::luaSpellCastSound); - registerMethod(L, "Spell", "impactSound", SpellFunctions::luaSpellImpactSound); - - // Only for InstantSpell. - registerMethod(L, "Spell", "words", SpellFunctions::luaSpellWords); - registerMethod(L, "Spell", "needDirection", SpellFunctions::luaSpellNeedDirection); - registerMethod(L, "Spell", "hasParams", SpellFunctions::luaSpellHasParams); - registerMethod(L, "Spell", "hasPlayerNameParam", SpellFunctions::luaSpellHasPlayerNameParam); - registerMethod(L, "Spell", "needCasterTargetOrDirection", SpellFunctions::luaSpellNeedCasterTargetOrDirection); - registerMethod(L, "Spell", "isBlockingWalls", SpellFunctions::luaSpellIsBlockingWalls); - - // Only for RuneSpells. - registerMethod(L, "Spell", "runeId", SpellFunctions::luaSpellRuneId); - registerMethod(L, "Spell", "charges", SpellFunctions::luaSpellCharges); - registerMethod(L, "Spell", "allowFarUse", SpellFunctions::luaSpellAllowFarUse); - registerMethod(L, "Spell", "blockWalls", SpellFunctions::luaSpellBlockWalls); - registerMethod(L, "Spell", "checkFloor", SpellFunctions::luaSpellCheckFloor); - } + static void init(lua_State* L); private: static int luaSpellCreate(lua_State* L); diff --git a/src/lua/functions/creatures/combat/variant_functions.cpp b/src/lua/functions/creatures/combat/variant_functions.cpp index 19225017c07..5a386fca803 100644 --- a/src/lua/functions/creatures/combat/variant_functions.cpp +++ b/src/lua/functions/creatures/combat/variant_functions.cpp @@ -11,32 +11,41 @@ #include "items/cylinder.hpp" #include "lua/global/lua_variant.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void VariantFunctions::init(lua_State* L) { + Lua::registerClass(L, "Variant", "", VariantFunctions::luaVariantCreate); + + Lua::registerMethod(L, "Variant", "getNumber", VariantFunctions::luaVariantGetNumber); + Lua::registerMethod(L, "Variant", "getString", VariantFunctions::luaVariantGetString); + Lua::registerMethod(L, "Variant", "getPosition", VariantFunctions::luaVariantGetPosition); +} int VariantFunctions::luaVariantCreate(lua_State* L) { // Variant(number or string or position or thing) LuaVariant variant; - if (isUserdata(L, 2)) { - if (const auto &thing = getThing(L, 2)) { + if (Lua::isUserdata(L, 2)) { + if (const auto &thing = Lua::getThing(L, 2)) { variant.type = VARIANT_TARGETPOSITION; variant.pos = thing->getPosition(); } - } else if (isTable(L, 2)) { + } else if (Lua::isTable(L, 2)) { variant.type = VARIANT_POSITION; - variant.pos = getPosition(L, 2); - } else if (isNumber(L, 2)) { + variant.pos = Lua::getPosition(L, 2); + } else if (Lua::isNumber(L, 2)) { variant.type = VARIANT_NUMBER; - variant.number = getNumber(L, 2); - } else if (isString(L, 2)) { + variant.number = Lua::getNumber(L, 2); + } else if (Lua::isString(L, 2)) { variant.type = VARIANT_STRING; - variant.text = getString(L, 2); + variant.text = Lua::getString(L, 2); } - pushVariant(L, variant); + Lua::pushVariant(L, variant); return 1; } int VariantFunctions::luaVariantGetNumber(lua_State* L) { - // Variant:getNumber() - const LuaVariant &variant = getVariant(L, 1); + // Variant:Lua::getNumber() + const LuaVariant &variant = Lua::getVariant(L, 1); if (variant.type == VARIANT_NUMBER) { lua_pushnumber(L, variant.number); } else { @@ -46,23 +55,23 @@ int VariantFunctions::luaVariantGetNumber(lua_State* L) { } int VariantFunctions::luaVariantGetString(lua_State* L) { - // Variant:getString() - const LuaVariant &variant = getVariant(L, 1); + // Variant:Lua::getString() + const LuaVariant &variant = Lua::getVariant(L, 1); if (variant.type == VARIANT_STRING) { - pushString(L, variant.text); + Lua::pushString(L, variant.text); } else { - pushString(L, std::string()); + Lua::pushString(L, std::string()); } return 1; } int VariantFunctions::luaVariantGetPosition(lua_State* L) { - // Variant:getPosition() - const LuaVariant &variant = getVariant(L, 1); + // Variant:Lua::getPosition() + const LuaVariant &variant = Lua::getVariant(L, 1); if (variant.type == VARIANT_POSITION || variant.type == VARIANT_TARGETPOSITION) { - pushPosition(L, variant.pos); + Lua::pushPosition(L, variant.pos); } else { - pushPosition(L, Position()); + Lua::pushPosition(L, Position()); } return 1; } diff --git a/src/lua/functions/creatures/combat/variant_functions.hpp b/src/lua/functions/creatures/combat/variant_functions.hpp index eba239b221c..2ab5e29516a 100644 --- a/src/lua/functions/creatures/combat/variant_functions.hpp +++ b/src/lua/functions/creatures/combat/variant_functions.hpp @@ -9,23 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class VariantFunctions final : LuaScriptInterface { +class VariantFunctions { public: - explicit VariantFunctions(lua_State* L) : - LuaScriptInterface("VariantFunctions") { - init(L); - } - ~VariantFunctions() override = default; - - static void init(lua_State* L) { - registerClass(L, "Variant", "", VariantFunctions::luaVariantCreate); - - registerMethod(L, "Variant", "getNumber", VariantFunctions::luaVariantGetNumber); - registerMethod(L, "Variant", "getString", VariantFunctions::luaVariantGetString); - registerMethod(L, "Variant", "getPosition", VariantFunctions::luaVariantGetPosition); - } + static void init(lua_State* L); private: static int luaVariantCreate(lua_State* L); diff --git a/src/lua/functions/creatures/creature_functions.cpp b/src/lua/functions/creatures/creature_functions.cpp index 0da3b6cc07a..72b41d01928 100644 --- a/src/lua/functions/creatures/creature_functions.cpp +++ b/src/lua/functions/creatures/creature_functions.cpp @@ -16,28 +16,107 @@ #include "game/game.hpp" #include "lua/creature/creatureevent.hpp" #include "map/spectators.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void CreatureFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Creature", "", CreatureFunctions::luaCreatureCreate); + Lua::registerMetaMethod(L, "Creature", "__eq", Lua::luaUserdataCompare); + Lua::registerMethod(L, "Creature", "getEvents", CreatureFunctions::luaCreatureGetEvents); + Lua::registerMethod(L, "Creature", "registerEvent", CreatureFunctions::luaCreatureRegisterEvent); + Lua::registerMethod(L, "Creature", "unregisterEvent", CreatureFunctions::luaCreatureUnregisterEvent); + Lua::registerMethod(L, "Creature", "isRemoved", CreatureFunctions::luaCreatureIsRemoved); + Lua::registerMethod(L, "Creature", "isCreature", CreatureFunctions::luaCreatureIsCreature); + Lua::registerMethod(L, "Creature", "isInGhostMode", CreatureFunctions::luaCreatureIsInGhostMode); + Lua::registerMethod(L, "Creature", "isHealthHidden", CreatureFunctions::luaCreatureIsHealthHidden); + Lua::registerMethod(L, "Creature", "isImmune", CreatureFunctions::luaCreatureIsImmune); + Lua::registerMethod(L, "Creature", "canSee", CreatureFunctions::luaCreatureCanSee); + Lua::registerMethod(L, "Creature", "canSeeCreature", CreatureFunctions::luaCreatureCanSeeCreature); + Lua::registerMethod(L, "Creature", "getParent", CreatureFunctions::luaCreatureGetParent); + Lua::registerMethod(L, "Creature", "getId", CreatureFunctions::luaCreatureGetId); + Lua::registerMethod(L, "Creature", "getName", CreatureFunctions::luaCreatureGetName); + Lua::registerMethod(L, "Creature", "getTypeName", CreatureFunctions::luaCreatureGetTypeName); + Lua::registerMethod(L, "Creature", "getTarget", CreatureFunctions::luaCreatureGetTarget); + Lua::registerMethod(L, "Creature", "setTarget", CreatureFunctions::luaCreatureSetTarget); + Lua::registerMethod(L, "Creature", "getFollowCreature", CreatureFunctions::luaCreatureGetFollowCreature); + Lua::registerMethod(L, "Creature", "setFollowCreature", CreatureFunctions::luaCreatureSetFollowCreature); + Lua::registerMethod(L, "Creature", "reload", CreatureFunctions::luaCreatureReload); + Lua::registerMethod(L, "Creature", "getMaster", CreatureFunctions::luaCreatureGetMaster); + Lua::registerMethod(L, "Creature", "setMaster", CreatureFunctions::luaCreatureSetMaster); + Lua::registerMethod(L, "Creature", "getLight", CreatureFunctions::luaCreatureGetLight); + Lua::registerMethod(L, "Creature", "setLight", CreatureFunctions::luaCreatureSetLight); + Lua::registerMethod(L, "Creature", "getSpeed", CreatureFunctions::luaCreatureGetSpeed); + Lua::registerMethod(L, "Creature", "setSpeed", CreatureFunctions::luaCreatureSetSpeed); + Lua::registerMethod(L, "Creature", "getBaseSpeed", CreatureFunctions::luaCreatureGetBaseSpeed); + Lua::registerMethod(L, "Creature", "changeSpeed", CreatureFunctions::luaCreatureChangeSpeed); + Lua::registerMethod(L, "Creature", "setDropLoot", CreatureFunctions::luaCreatureSetDropLoot); + Lua::registerMethod(L, "Creature", "setSkillLoss", CreatureFunctions::luaCreatureSetSkillLoss); + Lua::registerMethod(L, "Creature", "getPosition", CreatureFunctions::luaCreatureGetPosition); + Lua::registerMethod(L, "Creature", "getTile", CreatureFunctions::luaCreatureGetTile); + Lua::registerMethod(L, "Creature", "getDirection", CreatureFunctions::luaCreatureGetDirection); + Lua::registerMethod(L, "Creature", "setDirection", CreatureFunctions::luaCreatureSetDirection); + Lua::registerMethod(L, "Creature", "getHealth", CreatureFunctions::luaCreatureGetHealth); + Lua::registerMethod(L, "Creature", "setHealth", CreatureFunctions::luaCreatureSetHealth); + Lua::registerMethod(L, "Creature", "addHealth", CreatureFunctions::luaCreatureAddHealth); + Lua::registerMethod(L, "Creature", "getMaxHealth", CreatureFunctions::luaCreatureGetMaxHealth); + Lua::registerMethod(L, "Creature", "setMaxHealth", CreatureFunctions::luaCreatureSetMaxHealth); + Lua::registerMethod(L, "Creature", "setHiddenHealth", CreatureFunctions::luaCreatureSetHiddenHealth); + Lua::registerMethod(L, "Creature", "isMoveLocked", CreatureFunctions::luaCreatureIsMoveLocked); + Lua::registerMethod(L, "Creature", "isDirectionLocked", CreatureFunctions::luaCreatureIsDirectionLocked); + Lua::registerMethod(L, "Creature", "setMoveLocked", CreatureFunctions::luaCreatureSetMoveLocked); + Lua::registerMethod(L, "Creature", "setDirectionLocked", CreatureFunctions::luaCreatureSetDirectionLocked); + Lua::registerMethod(L, "Creature", "getSkull", CreatureFunctions::luaCreatureGetSkull); + Lua::registerMethod(L, "Creature", "setSkull", CreatureFunctions::luaCreatureSetSkull); + Lua::registerMethod(L, "Creature", "getOutfit", CreatureFunctions::luaCreatureGetOutfit); + Lua::registerMethod(L, "Creature", "setOutfit", CreatureFunctions::luaCreatureSetOutfit); + Lua::registerMethod(L, "Creature", "getCondition", CreatureFunctions::luaCreatureGetCondition); + Lua::registerMethod(L, "Creature", "addCondition", CreatureFunctions::luaCreatureAddCondition); + Lua::registerMethod(L, "Creature", "removeCondition", CreatureFunctions::luaCreatureRemoveCondition); + Lua::registerMethod(L, "Creature", "hasCondition", CreatureFunctions::luaCreatureHasCondition); + Lua::registerMethod(L, "Creature", "remove", CreatureFunctions::luaCreatureRemove); + Lua::registerMethod(L, "Creature", "teleportTo", CreatureFunctions::luaCreatureTeleportTo); + Lua::registerMethod(L, "Creature", "say", CreatureFunctions::luaCreatureSay); + Lua::registerMethod(L, "Creature", "getDamageMap", CreatureFunctions::luaCreatureGetDamageMap); + Lua::registerMethod(L, "Creature", "getSummons", CreatureFunctions::luaCreatureGetSummons); + Lua::registerMethod(L, "Creature", "hasBeenSummoned", CreatureFunctions::luaCreatureHasBeenSummoned); + Lua::registerMethod(L, "Creature", "getDescription", CreatureFunctions::luaCreatureGetDescription); + Lua::registerMethod(L, "Creature", "getPathTo", CreatureFunctions::luaCreatureGetPathTo); + Lua::registerMethod(L, "Creature", "move", CreatureFunctions::luaCreatureMove); + Lua::registerMethod(L, "Creature", "getZoneType", CreatureFunctions::luaCreatureGetZoneType); + Lua::registerMethod(L, "Creature", "getZones", CreatureFunctions::luaCreatureGetZones); + Lua::registerMethod(L, "Creature", "setIcon", CreatureFunctions::luaCreatureSetIcon); + Lua::registerMethod(L, "Creature", "getIcon", CreatureFunctions::luaCreatureGetIcon); + Lua::registerMethod(L, "Creature", "getIcons", CreatureFunctions::luaCreatureGetIcons); + Lua::registerMethod(L, "Creature", "removeIcon", CreatureFunctions::luaCreatureRemoveIcon); + Lua::registerMethod(L, "Creature", "clearIcons", CreatureFunctions::luaCreatureClearIcons); + + CombatFunctions::init(L); + MonsterFunctions::init(L); + NpcFunctions::init(L); + PlayerFunctions::init(L); +} int CreatureFunctions::luaCreatureCreate(lua_State* L) { // Creature(id or name or userdata) std::shared_ptr creature; - if (isNumber(L, 2)) { - creature = g_game().getCreatureByID(getNumber(L, 2)); - } else if (isString(L, 2)) { - creature = g_game().getCreatureByName(getString(L, 2)); - } else if (isUserdata(L, 2)) { - const LuaData_t type = getUserdataType(L, 2); - if (type != LuaData_t::Player && type != LuaData_t::Monster && type != LuaData_t::Npc) { + if (Lua::isNumber(L, 2)) { + creature = g_game().getCreatureByID(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + creature = g_game().getCreatureByName(Lua::getString(L, 2)); + } else if (Lua::isUserdata(L, 2)) { + using enum LuaData_t; + const LuaData_t type = Lua::getUserdataType(L, 2); + if (type != Player && type != Monster && type != Npc) { lua_pushnil(L); return 1; } - creature = getUserdataShared(L, 2); + creature = Lua::getUserdataShared(L, 2); } else { creature = nullptr; } if (creature) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); } else { lua_pushnil(L); } @@ -46,19 +125,19 @@ int CreatureFunctions::luaCreatureCreate(lua_State* L) { int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { // creature:getEvents(type) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - const CreatureEventType_t eventType = getNumber(L, 2); + const CreatureEventType_t eventType = Lua::getNumber(L, 2); const auto eventList = creature->getCreatureEvents(eventType); lua_createtable(L, static_cast(eventList.size()), 0); int index = 0; for (const auto &eventPtr : eventList) { - pushString(L, eventPtr->getName()); + Lua::pushString(L, eventPtr->getName()); lua_rawseti(L, -2, ++index); } return 1; @@ -66,10 +145,10 @@ int CreatureFunctions::luaCreatureGetEvents(lua_State* L) { int CreatureFunctions::luaCreatureRegisterEvent(lua_State* L) { // creature:registerEvent(name) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - const std::string &name = getString(L, 2); - pushBoolean(L, creature->registerCreatureEvent(name)); + const std::string &name = Lua::getString(L, 2); + Lua::pushBoolean(L, creature->registerCreatureEvent(name)); } else { lua_pushnil(L); } @@ -78,10 +157,10 @@ int CreatureFunctions::luaCreatureRegisterEvent(lua_State* L) { int CreatureFunctions::luaCreatureUnregisterEvent(lua_State* L) { // creature:unregisterEvent(name) - const std::string &name = getString(L, 2); - const auto &creature = getUserdataShared(L, 1); + const std::string &name = Lua::getString(L, 2); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->unregisterCreatureEvent(name)); + Lua::pushBoolean(L, creature->unregisterCreatureEvent(name)); } else { lua_pushnil(L); } @@ -90,9 +169,9 @@ int CreatureFunctions::luaCreatureUnregisterEvent(lua_State* L) { int CreatureFunctions::luaCreatureIsRemoved(lua_State* L) { // creature:isRemoved() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->isRemoved()); + Lua::pushBoolean(L, creature->isRemoved()); } else { lua_pushnil(L); } @@ -101,15 +180,15 @@ int CreatureFunctions::luaCreatureIsRemoved(lua_State* L) { int CreatureFunctions::luaCreatureIsCreature(lua_State* L) { // creature:isCreature() - pushBoolean(L, getUserdataShared(L, 1) != nullptr); + Lua::pushBoolean(L, Lua::getUserdataShared(L, 1) != nullptr); return 1; } int CreatureFunctions::luaCreatureIsInGhostMode(lua_State* L) { // creature:isInGhostMode() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->isInGhostMode()); + Lua::pushBoolean(L, creature->isInGhostMode()); } else { lua_pushnil(L); } @@ -118,9 +197,9 @@ int CreatureFunctions::luaCreatureIsInGhostMode(lua_State* L) { int CreatureFunctions::luaCreatureIsHealthHidden(lua_State* L) { // creature:isHealthHidden() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->isHealthHidden()); + Lua::pushBoolean(L, creature->isHealthHidden()); } else { lua_pushnil(L); } @@ -129,10 +208,10 @@ int CreatureFunctions::luaCreatureIsHealthHidden(lua_State* L) { int CreatureFunctions::luaCreatureCanSee(lua_State* L) { // creature:canSee(position) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - const Position &position = getPosition(L, 2); - pushBoolean(L, creature->canSee(position)); + const Position &position = Lua::getPosition(L, 2); + Lua::pushBoolean(L, creature->canSee(position)); } else { lua_pushnil(L); } @@ -141,10 +220,10 @@ int CreatureFunctions::luaCreatureCanSee(lua_State* L) { int CreatureFunctions::luaCreatureCanSeeCreature(lua_State* L) { // creature:canSeeCreature(creature) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - const auto &otherCreature = getCreature(L, 2); - pushBoolean(L, creature->canSeeCreature(otherCreature)); + const auto &otherCreature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, creature->canSeeCreature(otherCreature)); } else { lua_pushnil(L); } @@ -153,7 +232,7 @@ int CreatureFunctions::luaCreatureCanSeeCreature(lua_State* L) { int CreatureFunctions::luaCreatureGetParent(lua_State* L) { // creature:getParent() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -165,13 +244,13 @@ int CreatureFunctions::luaCreatureGetParent(lua_State* L) { return 1; } - pushCylinder(L, parent); + Lua::pushCylinder(L, parent); return 1; } int CreatureFunctions::luaCreatureGetId(lua_State* L) { // creature:getId() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getID()); } else { @@ -182,9 +261,9 @@ int CreatureFunctions::luaCreatureGetId(lua_State* L) { int CreatureFunctions::luaCreatureGetName(lua_State* L) { // creature:getName() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushString(L, creature->getName()); + Lua::pushString(L, creature->getName()); } else { lua_pushnil(L); } @@ -193,9 +272,9 @@ int CreatureFunctions::luaCreatureGetName(lua_State* L) { int CreatureFunctions::luaCreatureGetTypeName(lua_State* L) { // creature:getTypeName() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushString(L, creature->getTypeName()); + Lua::pushString(L, creature->getTypeName()); } else { lua_pushnil(L); } @@ -204,7 +283,7 @@ int CreatureFunctions::luaCreatureGetTypeName(lua_State* L) { int CreatureFunctions::luaCreatureGetTarget(lua_State* L) { // creature:getTarget() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -212,8 +291,8 @@ int CreatureFunctions::luaCreatureGetTarget(lua_State* L) { const auto &target = creature->getAttackedCreature(); if (target) { - pushUserdata(L, target); - setCreatureMetatable(L, -1, target); + Lua::pushUserdata(L, target); + Lua::setCreatureMetatable(L, -1, target); } else { lua_pushnil(L); } @@ -222,10 +301,10 @@ int CreatureFunctions::luaCreatureGetTarget(lua_State* L) { int CreatureFunctions::luaCreatureSetTarget(lua_State* L) { // creature:setTarget(target) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - const auto &target = getCreature(L, 2); - pushBoolean(L, creature->setAttackedCreature(target)); + const auto &target = Lua::getCreature(L, 2); + Lua::pushBoolean(L, creature->setAttackedCreature(target)); } else { lua_pushnil(L); } @@ -234,7 +313,7 @@ int CreatureFunctions::luaCreatureSetTarget(lua_State* L) { int CreatureFunctions::luaCreatureGetFollowCreature(lua_State* L) { // creature:getFollowCreature() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -242,8 +321,8 @@ int CreatureFunctions::luaCreatureGetFollowCreature(lua_State* L) { const auto &followCreature = creature->getFollowCreature(); if (followCreature) { - pushUserdata(L, followCreature); - setCreatureMetatable(L, -1, followCreature); + Lua::pushUserdata(L, followCreature); + Lua::setCreatureMetatable(L, -1, followCreature); } else { lua_pushnil(L); } @@ -252,10 +331,10 @@ int CreatureFunctions::luaCreatureGetFollowCreature(lua_State* L) { int CreatureFunctions::luaCreatureSetFollowCreature(lua_State* L) { // creature:setFollowCreature(followedCreature) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - const auto &followCreature = getCreature(L, 2); - pushBoolean(L, creature->setFollowCreature(followCreature)); + const auto &followCreature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, creature->setFollowCreature(followCreature)); } else { lua_pushnil(L); } @@ -264,7 +343,7 @@ int CreatureFunctions::luaCreatureSetFollowCreature(lua_State* L) { int CreatureFunctions::luaCreatureGetMaster(lua_State* L) { // creature:getMaster() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -276,33 +355,33 @@ int CreatureFunctions::luaCreatureGetMaster(lua_State* L) { return 1; } - pushUserdata(L, master); - setCreatureMetatable(L, -1, master); + Lua::pushUserdata(L, master); + Lua::setCreatureMetatable(L, -1, master); return 1; } int CreatureFunctions::luaCreatureReload(lua_State* L) { // creature:reload() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } g_game().reloadCreature(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureSetMaster(lua_State* L) { // creature:setMaster(master) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - pushBoolean(L, creature->setMaster(getCreature(L, 2), true)); + Lua::pushBoolean(L, creature->setMaster(Lua::getCreature(L, 2), true)); // Reloading creature icon/knownCreature CreatureFunctions::luaCreatureReload(L); return 1; @@ -310,7 +389,7 @@ int CreatureFunctions::luaCreatureSetMaster(lua_State* L) { int CreatureFunctions::luaCreatureGetLight(lua_State* L) { // creature:getLight() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -324,24 +403,24 @@ int CreatureFunctions::luaCreatureGetLight(lua_State* L) { int CreatureFunctions::luaCreatureSetLight(lua_State* L) { // creature:setLight(color, level) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } LightInfo light; - light.color = getNumber(L, 2); - light.level = getNumber(L, 3); + light.color = Lua::getNumber(L, 2); + light.level = Lua::getNumber(L, 3); creature->setCreatureLight(light); g_game().changeLight(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureGetSpeed(lua_State* L) { // creature:getSpeed() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getSpeed()); } else { @@ -352,22 +431,22 @@ int CreatureFunctions::luaCreatureGetSpeed(lua_State* L) { int CreatureFunctions::luaCreatureSetSpeed(lua_State* L) { // creature:setSpeed(speed) - const auto &creature = getCreature(L, 1); + const auto &creature = Lua::getCreature(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const int32_t speed = getNumber(L, 2); + const int32_t speed = Lua::getNumber(L, 2); g_game().setCreatureSpeed(creature, speed); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureGetBaseSpeed(lua_State* L) { // creature:getBaseSpeed() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getBaseSpeed()); } else { @@ -378,25 +457,25 @@ int CreatureFunctions::luaCreatureGetBaseSpeed(lua_State* L) { int CreatureFunctions::luaCreatureChangeSpeed(lua_State* L) { // creature:changeSpeed(delta) - const auto &creature = getCreature(L, 1); + const auto &creature = Lua::getCreature(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const int32_t delta = getNumber(L, 2); + const int32_t delta = Lua::getNumber(L, 2); g_game().changeSpeed(creature, delta); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureSetDropLoot(lua_State* L) { // creature:setDropLoot(doDrop) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setDropLoot(getBoolean(L, 2)); - pushBoolean(L, true); + creature->setDropLoot(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -405,10 +484,10 @@ int CreatureFunctions::luaCreatureSetDropLoot(lua_State* L) { int CreatureFunctions::luaCreatureSetSkillLoss(lua_State* L) { // creature:setSkillLoss(skillLoss) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setSkillLoss(getBoolean(L, 2)); - pushBoolean(L, true); + creature->setSkillLoss(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -416,10 +495,10 @@ int CreatureFunctions::luaCreatureSetSkillLoss(lua_State* L) { } int CreatureFunctions::luaCreatureGetPosition(lua_State* L) { - // creature:getPosition() - const auto &creature = getUserdataShared(L, 1); + // creature:Lua::getPosition() + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushPosition(L, creature->getPosition()); + Lua::pushPosition(L, creature->getPosition()); } else { lua_pushnil(L); } @@ -428,7 +507,7 @@ int CreatureFunctions::luaCreatureGetPosition(lua_State* L) { int CreatureFunctions::luaCreatureGetTile(lua_State* L) { // creature:getTile() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -436,8 +515,8 @@ int CreatureFunctions::luaCreatureGetTile(lua_State* L) { const auto &tile = creature->getTile(); if (tile) { - pushUserdata(L, tile); - setMetatable(L, -1, "Tile"); + Lua::pushUserdata(L, tile); + Lua::setMetatable(L, -1, "Tile"); } else { lua_pushnil(L); } @@ -446,7 +525,7 @@ int CreatureFunctions::luaCreatureGetTile(lua_State* L) { int CreatureFunctions::luaCreatureGetDirection(lua_State* L) { // creature:getDirection() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getDirection()); } else { @@ -457,9 +536,9 @@ int CreatureFunctions::luaCreatureGetDirection(lua_State* L) { int CreatureFunctions::luaCreatureSetDirection(lua_State* L) { // creature:setDirection(direction) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, g_game().internalCreatureTurn(creature, getNumber(L, 2))); + Lua::pushBoolean(L, g_game().internalCreatureTurn(creature, Lua::getNumber(L, 2))); } else { lua_pushnil(L); } @@ -468,7 +547,7 @@ int CreatureFunctions::luaCreatureSetDirection(lua_State* L) { int CreatureFunctions::luaCreatureGetHealth(lua_State* L) { // creature:getHealth() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getHealth()); } else { @@ -479,47 +558,47 @@ int CreatureFunctions::luaCreatureGetHealth(lua_State* L) { int CreatureFunctions::luaCreatureSetHealth(lua_State* L) { // creature:setHealth(health) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - creature->health = std::min(getNumber(L, 2), creature->healthMax); + creature->health = std::min(Lua::getNumber(L, 2), creature->healthMax); g_game().addCreatureHealth(creature); const auto &player = creature->getPlayer(); if (player) { player->sendStats(); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureAddHealth(lua_State* L) { // creature:addHealth(healthChange, combatType) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } CombatDamage damage; - damage.primary.value = getNumber(L, 2); + damage.primary.value = Lua::getNumber(L, 2); if (damage.primary.value >= 0) { damage.primary.type = COMBAT_HEALING; } else if (damage.primary.value < 0) { - damage.primary.type = getNumber(L, 3); + damage.primary.type = Lua::getNumber(L, 3); } else { damage.primary.type = COMBAT_UNDEFINEDDAMAGE; } - pushBoolean(L, g_game().combatChangeHealth(nullptr, creature, damage)); + Lua::pushBoolean(L, g_game().combatChangeHealth(nullptr, creature, damage)); return 1; } int CreatureFunctions::luaCreatureGetMaxHealth(lua_State* L) { // creature:getMaxHealth() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getMaxHealth()); } else { @@ -530,13 +609,13 @@ int CreatureFunctions::luaCreatureGetMaxHealth(lua_State* L) { int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { // creature:setMaxHealth(maxHealth) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - creature->healthMax = getNumber(L, 2); + creature->healthMax = Lua::getNumber(L, 2); creature->health = std::min(creature->health, creature->healthMax); g_game().addCreatureHealth(creature); @@ -544,17 +623,17 @@ int CreatureFunctions::luaCreatureSetMaxHealth(lua_State* L) { if (player) { player->sendStats(); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureSetHiddenHealth(lua_State* L) { // creature:setHiddenHealth(hide) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setHiddenHealth(getBoolean(L, 2)); + creature->setHiddenHealth(Lua::getBoolean(L, 2)); g_game().addCreatureHealth(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -563,9 +642,9 @@ int CreatureFunctions::luaCreatureSetHiddenHealth(lua_State* L) { int CreatureFunctions::luaCreatureIsMoveLocked(lua_State* L) { // creature:isMoveLocked() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->isMoveLocked()); + Lua::pushBoolean(L, creature->isMoveLocked()); } else { lua_pushnil(L); } @@ -574,10 +653,10 @@ int CreatureFunctions::luaCreatureIsMoveLocked(lua_State* L) { int CreatureFunctions::luaCreatureSetMoveLocked(lua_State* L) { // creature:setMoveLocked(moveLocked) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setMoveLocked(getBoolean(L, 2)); - pushBoolean(L, true); + creature->setMoveLocked(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -586,9 +665,9 @@ int CreatureFunctions::luaCreatureSetMoveLocked(lua_State* L) { int CreatureFunctions::luaCreatureIsDirectionLocked(lua_State* L) { // creature:isDirectionLocked() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->isDirectionLocked()); + Lua::pushBoolean(L, creature->isDirectionLocked()); } else { lua_pushnil(L); } @@ -597,10 +676,10 @@ int CreatureFunctions::luaCreatureIsDirectionLocked(lua_State* L) { int CreatureFunctions::luaCreatureSetDirectionLocked(lua_State* L) { // creature:setDirectionLocked(directionLocked) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setDirectionLocked(getBoolean(L, 2)); - pushBoolean(L, true); + creature->setDirectionLocked(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -609,7 +688,7 @@ int CreatureFunctions::luaCreatureSetDirectionLocked(lua_State* L) { int CreatureFunctions::luaCreatureGetSkull(lua_State* L) { // creature:getSkull() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getSkull()); } else { @@ -620,10 +699,10 @@ int CreatureFunctions::luaCreatureGetSkull(lua_State* L) { int CreatureFunctions::luaCreatureSetSkull(lua_State* L) { // creature:setSkull(skull) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - creature->setSkull(getNumber(L, 2)); - pushBoolean(L, true); + creature->setSkull(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -631,10 +710,10 @@ int CreatureFunctions::luaCreatureSetSkull(lua_State* L) { } int CreatureFunctions::luaCreatureGetOutfit(lua_State* L) { - // creature:getOutfit() - const auto &creature = getUserdataShared(L, 1); + // creature:Lua::getOutfit() + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushOutfit(L, creature->getCurrentOutfit()); + Lua::pushOutfit(L, creature->getCurrentOutfit()); } else { lua_pushnil(L); } @@ -643,9 +722,9 @@ int CreatureFunctions::luaCreatureGetOutfit(lua_State* L) { int CreatureFunctions::luaCreatureSetOutfit(lua_State* L) { // creature:setOutfit(outfit) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - Outfit_t outfit = getOutfit(L, 2); + Outfit_t outfit = Lua::getOutfit(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[CreatureFunctions::luaCreatureSetOutfit] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); return 1; @@ -653,7 +732,7 @@ int CreatureFunctions::luaCreatureSetOutfit(lua_State* L) { creature->defaultOutfit = outfit; g_game().internalCreatureChangeOutfit(creature, creature->defaultOutfit); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -662,20 +741,20 @@ int CreatureFunctions::luaCreatureSetOutfit(lua_State* L) { int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { // creature:getCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0]]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - const ConditionType_t conditionType = getNumber(L, 2); - const auto conditionId = getNumber(L, 3, CONDITIONID_COMBAT); - const auto subId = getNumber(L, 4, 0); + const ConditionType_t conditionType = Lua::getNumber(L, 2); + const auto conditionId = Lua::getNumber(L, 3, CONDITIONID_COMBAT); + const auto subId = Lua::getNumber(L, 4, 0); const auto &condition = creature->getCondition(conditionType, conditionId, subId); if (condition) { - pushUserdata(L, condition); - setWeakMetatable(L, -1, "Condition"); + Lua::pushUserdata(L, condition); + Lua::setWeakMetatable(L, -1, "Condition"); } else { lua_pushnil(L); } @@ -684,10 +763,10 @@ int CreatureFunctions::luaCreatureGetCondition(lua_State* L) { int CreatureFunctions::luaCreatureAddCondition(lua_State* L) { // creature:addCondition(condition) - const auto &creature = getUserdataShared(L, 1); - const auto &condition = getUserdataShared(L, 2); + const auto &creature = Lua::getUserdataShared(L, 1); + const auto &condition = Lua::getUserdataShared(L, 2); if (creature && condition) { - pushBoolean(L, creature->addCondition(condition->clone())); + Lua::pushBoolean(L, creature->addCondition(condition->clone())); } else { lua_pushnil(L); } @@ -696,24 +775,24 @@ int CreatureFunctions::luaCreatureAddCondition(lua_State* L) { int CreatureFunctions::luaCreatureRemoveCondition(lua_State* L) { // creature:removeCondition(conditionType[, conditionId = CONDITIONID_COMBAT[, subId = 0[, force = false]]]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - const ConditionType_t conditionType = getNumber(L, 2); - const auto conditionId = getNumber(L, 3, CONDITIONID_COMBAT); - const auto subId = getNumber(L, 4, 0); + const ConditionType_t conditionType = Lua::getNumber(L, 2); + const auto conditionId = Lua::getNumber(L, 3, CONDITIONID_COMBAT); + const auto subId = Lua::getNumber(L, 4, 0); const auto &condition = creature->getCondition(conditionType, conditionId, subId); if (condition) { - const bool force = getBoolean(L, 5, false); + const bool force = Lua::getBoolean(L, 5, false); if (subId == 0) { creature->removeCondition(conditionType, conditionId, force); } else { creature->removeCondition(condition); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -722,30 +801,30 @@ int CreatureFunctions::luaCreatureRemoveCondition(lua_State* L) { int CreatureFunctions::luaCreatureHasCondition(lua_State* L) { // creature:hasCondition(conditionType[, subId = 0]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - const ConditionType_t conditionType = getNumber(L, 2); - const auto subId = getNumber(L, 3, 0); - pushBoolean(L, creature->hasCondition(conditionType, subId)); + const ConditionType_t conditionType = Lua::getNumber(L, 2); + const auto subId = Lua::getNumber(L, 3, 0); + Lua::pushBoolean(L, creature->hasCondition(conditionType, subId)); return 1; } int CreatureFunctions::luaCreatureIsImmune(lua_State* L) { // creature:isImmune(condition or conditionType) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - if (isNumber(L, 2)) { - pushBoolean(L, creature->isImmune(getNumber(L, 2))); - } else if (const auto condition = getUserdataShared(L, 2)) { - pushBoolean(L, creature->isImmune(condition->getType())); + if (Lua::isNumber(L, 2)) { + Lua::pushBoolean(L, creature->isImmune(Lua::getNumber(L, 2))); + } else if (const auto condition = Lua::getUserdataShared(L, 2)) { + Lua::pushBoolean(L, creature->isImmune(condition->getType())); } else { lua_pushnil(L); } @@ -754,7 +833,7 @@ int CreatureFunctions::luaCreatureIsImmune(lua_State* L) { int CreatureFunctions::luaCreatureRemove(lua_State* L) { // creature:remove([forced = true]) - auto* creaturePtr = getRawUserDataShared(L, 1); + auto* creaturePtr = Lua::getRawUserDataShared(L, 1); if (!creaturePtr) { lua_pushnil(L); return 1; @@ -766,7 +845,7 @@ int CreatureFunctions::luaCreatureRemove(lua_State* L) { return 1; } - const bool forced = getBoolean(L, 2, true); + const bool forced = Lua::getBoolean(L, 2, true); if (const auto &player = creature->getPlayer()) { if (forced) { player->removePlayer(true); @@ -778,19 +857,19 @@ int CreatureFunctions::luaCreatureRemove(lua_State* L) { } *creaturePtr = nullptr; - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureTeleportTo(lua_State* L) { // creature:teleportTo(position[, pushMovement = false]) - const bool pushMovement = getBoolean(L, 3, false); + const bool pushMovement = Lua::getBoolean(L, 3, false); - const Position &position = getPosition(L, 2); - const auto &creature = getUserdataShared(L, 1); + const Position &position = Lua::getPosition(L, 2); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature == nullptr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -798,7 +877,7 @@ int CreatureFunctions::luaCreatureTeleportTo(lua_State* L) { if (const auto ret = g_game().internalTeleport(creature, position, pushMovement); ret != RETURNVALUE_NOERROR) { g_logger().debug("[{}] Failed to teleport creature {}, on position {}, error code: {}", __FUNCTION__, creature->getName(), oldPosition.toString(), getReturnMessage(ret)); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -815,7 +894,7 @@ int CreatureFunctions::luaCreatureTeleportTo(lua_State* L) { g_game().internalCreatureTurn(creature, DIRECTION_EAST); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -825,24 +904,24 @@ int CreatureFunctions::luaCreatureSay(lua_State* L) { Position position; if (parameters >= 6) { - position = getPosition(L, 6); + position = Lua::getPosition(L, 6); if (!position.x || !position.y) { - reportErrorFunc("Invalid position specified."); - pushBoolean(L, false); + Lua::reportErrorFunc("Invalid position specified."); + Lua::pushBoolean(L, false); return 1; } } std::shared_ptr target = nullptr; if (parameters >= 5) { - target = getCreature(L, 5); + target = Lua::getCreature(L, 5); } - const bool ghost = getBoolean(L, 4, false); + const bool ghost = Lua::getBoolean(L, 4, false); - const auto type = getNumber(L, 3, TALKTYPE_MONSTER_SAY); - const std::string &text = getString(L, 2); - const auto &creature = getUserdataShared(L, 1); + const auto type = Lua::getNumber(L, 3, TALKTYPE_MONSTER_SAY); + const std::string &text = Lua::getString(L, 2); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -854,16 +933,16 @@ int CreatureFunctions::luaCreatureSay(lua_State* L) { } if (position.x != 0) { - pushBoolean(L, g_game().internalCreatureSay(creature, type, text, ghost, &spectators, &position)); + Lua::pushBoolean(L, g_game().internalCreatureSay(creature, type, text, ghost, &spectators, &position)); } else { - pushBoolean(L, g_game().internalCreatureSay(creature, type, text, ghost, &spectators)); + Lua::pushBoolean(L, g_game().internalCreatureSay(creature, type, text, ghost, &spectators)); } return 1; } int CreatureFunctions::luaCreatureGetDamageMap(lua_State* L) { // creature:getDamageMap() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -872,8 +951,8 @@ int CreatureFunctions::luaCreatureGetDamageMap(lua_State* L) { lua_createtable(L, creature->damageMap.size(), 0); for (const auto damageEntry : creature->damageMap) { lua_createtable(L, 0, 2); - setField(L, "total", damageEntry.second.total); - setField(L, "ticks", damageEntry.second.ticks); + Lua::setField(L, "total", damageEntry.second.total); + Lua::setField(L, "ticks", damageEntry.second.ticks); lua_rawseti(L, -2, damageEntry.first); } return 1; @@ -881,7 +960,7 @@ int CreatureFunctions::luaCreatureGetDamageMap(lua_State* L) { int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { // creature:getSummons() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; @@ -892,8 +971,8 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { int index = 0; for (const auto &summon : creature->getSummons()) { if (summon) { - pushUserdata(L, summon); - setCreatureMetatable(L, -1, summon); + Lua::pushUserdata(L, summon); + Lua::setCreatureMetatable(L, -1, summon); lua_rawseti(L, -2, ++index); } } @@ -902,9 +981,9 @@ int CreatureFunctions::luaCreatureGetSummons(lua_State* L) { int CreatureFunctions::luaCreatureHasBeenSummoned(lua_State* L) { // creature:hasBeenSummoned() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushBoolean(L, creature->hasBeenSummoned()); + Lua::pushBoolean(L, creature->hasBeenSummoned()); } else { lua_pushnil(L); } @@ -914,10 +993,10 @@ int CreatureFunctions::luaCreatureHasBeenSummoned(lua_State* L) { int CreatureFunctions::luaCreatureGetDescription(lua_State* L) { // creature:getDescription(distance) - const int32_t distance = getNumber(L, 2); - const auto &creature = getUserdataShared(L, 1); + const int32_t distance = Lua::getNumber(L, 2); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { - pushString(L, creature->getDescription(distance)); + Lua::pushString(L, creature->getDescription(distance)); } else { lua_pushnil(L); } @@ -926,20 +1005,20 @@ int CreatureFunctions::luaCreatureGetDescription(lua_State* L) { int CreatureFunctions::luaCreatureGetPathTo(lua_State* L) { // creature:getPathTo(pos[, minTargetDist = 0[, maxTargetDist = 1[, fullPathSearch = true[, clearSight = true[, maxSearchDist = 0]]]]]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - const Position &position = getPosition(L, 2); + const Position &position = Lua::getPosition(L, 2); FindPathParams fpp; - fpp.minTargetDist = getNumber(L, 3, 0); - fpp.maxTargetDist = getNumber(L, 4, 1); - fpp.fullPathSearch = getBoolean(L, 5, fpp.fullPathSearch); - fpp.clearSight = getBoolean(L, 6, fpp.clearSight); - fpp.maxSearchDist = getNumber(L, 7, fpp.maxSearchDist); + fpp.minTargetDist = Lua::getNumber(L, 3, 0); + fpp.maxTargetDist = Lua::getNumber(L, 4, 1); + fpp.fullPathSearch = Lua::getBoolean(L, 5, fpp.fullPathSearch); + fpp.clearSight = Lua::getBoolean(L, 6, fpp.clearSight); + fpp.maxSearchDist = Lua::getNumber(L, 7, fpp.maxSearchDist); std::vector dirList; if (creature->getPathTo(position, dirList, fpp)) { @@ -951,7 +1030,7 @@ int CreatureFunctions::luaCreatureGetPathTo(lua_State* L) { lua_rawseti(L, -2, ++index); } } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } @@ -959,33 +1038,33 @@ int CreatureFunctions::luaCreatureGetPathTo(lua_State* L) { int CreatureFunctions::luaCreatureMove(lua_State* L) { // creature:move(direction) // creature:move(tile[, flags = 0]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { lua_pushnil(L); return 1; } - if (isNumber(L, 2)) { - const Direction direction = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + const Direction direction = Lua::getNumber(L, 2); if (direction > DIRECTION_LAST) { lua_pushnil(L); return 1; } lua_pushnumber(L, g_game().internalMoveCreature(creature, direction, FLAG_NOLIMIT)); } else { - const auto &tile = getUserdataShared(L, 2); + const auto &tile = Lua::getUserdataShared(L, 2); if (!tile) { lua_pushnil(L); return 1; } - lua_pushnumber(L, g_game().internalMoveCreature(creature, tile, getNumber(L, 3))); + lua_pushnumber(L, g_game().internalMoveCreature(creature, tile, Lua::getNumber(L, 3))); } return 1; } int CreatureFunctions::luaCreatureGetZoneType(lua_State* L) { // creature:getZoneType() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature) { lua_pushnumber(L, creature->getZoneType()); } else { @@ -996,7 +1075,7 @@ int CreatureFunctions::luaCreatureGetZoneType(lua_State* L) { int CreatureFunctions::luaCreatureGetZones(lua_State* L) { // creature:getZones() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (creature == nullptr) { lua_pushnil(L); return 1; @@ -1007,8 +1086,8 @@ int CreatureFunctions::luaCreatureGetZones(lua_State* L) { int index = 0; for (const auto &zone : zones) { index++; - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); lua_rawseti(L, -2, index); } return 1; @@ -1016,35 +1095,35 @@ int CreatureFunctions::luaCreatureGetZones(lua_State* L) { int CreatureFunctions::luaCreatureSetIcon(lua_State* L) { // creature:setIcon(key, category, icon[, number]) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto key = getString(L, 2); - const auto category = getNumber(L, 3); - const auto count = getNumber(L, 5, 0); + const auto key = Lua::getString(L, 2); + const auto category = Lua::getNumber(L, 3); + const auto count = Lua::getNumber(L, 5, 0); CreatureIcon creatureIcon; if (category == CreatureIconCategory_t::Modifications) { - const auto icon = getNumber(L, 4); + const auto icon = Lua::getNumber(L, 4); creatureIcon = CreatureIcon(icon, count); } else { - const auto icon = getNumber(L, 4); + const auto icon = Lua::getNumber(L, 4); creatureIcon = CreatureIcon(icon, count); } creature->setIcon(key, creatureIcon); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureGetIcons(lua_State* L) { // creature:getIcons() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -1052,9 +1131,9 @@ int CreatureFunctions::luaCreatureGetIcons(lua_State* L) { lua_createtable(L, static_cast(icons.size()), 0); for (auto &icon : icons) { lua_createtable(L, 0, 3); - setField(L, "category", static_cast(icon.category)); - setField(L, "icon", icon.serialize()); - setField(L, "count", icon.count); + Lua::setField(L, "category", static_cast(icon.category)); + Lua::setField(L, "icon", icon.serialize()); + Lua::setField(L, "count", icon.count); lua_rawseti(L, -2, static_cast(icon.category)); } return 1; @@ -1062,19 +1141,19 @@ int CreatureFunctions::luaCreatureGetIcons(lua_State* L) { int CreatureFunctions::luaCreatureGetIcon(lua_State* L) { // creature:getIcon(key) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto key = getString(L, 2); + const auto key = Lua::getString(L, 2); auto icon = creature->getIcon(key); if (icon.isSet()) { lua_createtable(L, 0, 3); - setField(L, "category", static_cast(icon.category)); - setField(L, "icon", icon.serialize()); - setField(L, "count", icon.count); + Lua::setField(L, "category", static_cast(icon.category)); + Lua::setField(L, "icon", icon.serialize()); + Lua::setField(L, "count", icon.count); } else { lua_pushnil(L); } @@ -1083,27 +1162,27 @@ int CreatureFunctions::luaCreatureGetIcon(lua_State* L) { int CreatureFunctions::luaCreatureRemoveIcon(lua_State* L) { // creature:removeIcon(key) - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto key = getString(L, 2); + const auto key = Lua::getString(L, 2); creature->removeIcon(key); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int CreatureFunctions::luaCreatureClearIcons(lua_State* L) { // creature:clearIcons() - const auto &creature = getUserdataShared(L, 1); + const auto &creature = Lua::getUserdataShared(L, 1); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } creature->clearIcons(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/creatures/creature_functions.hpp b/src/lua/functions/creatures/creature_functions.hpp index f0f1d12bb77..8d1c5b8ce52 100644 --- a/src/lua/functions/creatures/creature_functions.hpp +++ b/src/lua/functions/creatures/creature_functions.hpp @@ -13,92 +13,9 @@ #include "lua/functions/creatures/monster/monster_functions.hpp" #include "lua/functions/creatures/npc/npc_functions.hpp" #include "lua/functions/creatures/player/player_functions.hpp" -#include "lua/scripts/luascript.hpp" - -class CreatureFunctions final : LuaScriptInterface { +class CreatureFunctions { public: - explicit CreatureFunctions(lua_State* L) : - LuaScriptInterface("CreatureFunctions") { - init(L); - } - ~CreatureFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Creature", "", CreatureFunctions::luaCreatureCreate); - registerMetaMethod(L, "Creature", "__eq", CreatureFunctions::luaUserdataCompare); - registerMethod(L, "Creature", "getEvents", CreatureFunctions::luaCreatureGetEvents); - registerMethod(L, "Creature", "registerEvent", CreatureFunctions::luaCreatureRegisterEvent); - registerMethod(L, "Creature", "unregisterEvent", CreatureFunctions::luaCreatureUnregisterEvent); - registerMethod(L, "Creature", "isRemoved", CreatureFunctions::luaCreatureIsRemoved); - registerMethod(L, "Creature", "isCreature", CreatureFunctions::luaCreatureIsCreature); - registerMethod(L, "Creature", "isInGhostMode", CreatureFunctions::luaCreatureIsInGhostMode); - registerMethod(L, "Creature", "isHealthHidden", CreatureFunctions::luaCreatureIsHealthHidden); - registerMethod(L, "Creature", "isImmune", CreatureFunctions::luaCreatureIsImmune); - registerMethod(L, "Creature", "canSee", CreatureFunctions::luaCreatureCanSee); - registerMethod(L, "Creature", "canSeeCreature", CreatureFunctions::luaCreatureCanSeeCreature); - registerMethod(L, "Creature", "getParent", CreatureFunctions::luaCreatureGetParent); - registerMethod(L, "Creature", "getId", CreatureFunctions::luaCreatureGetId); - registerMethod(L, "Creature", "getName", CreatureFunctions::luaCreatureGetName); - registerMethod(L, "Creature", "getTypeName", CreatureFunctions::luaCreatureGetTypeName); - registerMethod(L, "Creature", "getTarget", CreatureFunctions::luaCreatureGetTarget); - registerMethod(L, "Creature", "setTarget", CreatureFunctions::luaCreatureSetTarget); - registerMethod(L, "Creature", "getFollowCreature", CreatureFunctions::luaCreatureGetFollowCreature); - registerMethod(L, "Creature", "setFollowCreature", CreatureFunctions::luaCreatureSetFollowCreature); - registerMethod(L, "Creature", "reload", CreatureFunctions::luaCreatureReload); - registerMethod(L, "Creature", "getMaster", CreatureFunctions::luaCreatureGetMaster); - registerMethod(L, "Creature", "setMaster", CreatureFunctions::luaCreatureSetMaster); - registerMethod(L, "Creature", "getLight", CreatureFunctions::luaCreatureGetLight); - registerMethod(L, "Creature", "setLight", CreatureFunctions::luaCreatureSetLight); - registerMethod(L, "Creature", "getSpeed", CreatureFunctions::luaCreatureGetSpeed); - registerMethod(L, "Creature", "setSpeed", CreatureFunctions::luaCreatureSetSpeed); - registerMethod(L, "Creature", "getBaseSpeed", CreatureFunctions::luaCreatureGetBaseSpeed); - registerMethod(L, "Creature", "changeSpeed", CreatureFunctions::luaCreatureChangeSpeed); - registerMethod(L, "Creature", "setDropLoot", CreatureFunctions::luaCreatureSetDropLoot); - registerMethod(L, "Creature", "setSkillLoss", CreatureFunctions::luaCreatureSetSkillLoss); - registerMethod(L, "Creature", "getPosition", CreatureFunctions::luaCreatureGetPosition); - registerMethod(L, "Creature", "getTile", CreatureFunctions::luaCreatureGetTile); - registerMethod(L, "Creature", "getDirection", CreatureFunctions::luaCreatureGetDirection); - registerMethod(L, "Creature", "setDirection", CreatureFunctions::luaCreatureSetDirection); - registerMethod(L, "Creature", "getHealth", CreatureFunctions::luaCreatureGetHealth); - registerMethod(L, "Creature", "setHealth", CreatureFunctions::luaCreatureSetHealth); - registerMethod(L, "Creature", "addHealth", CreatureFunctions::luaCreatureAddHealth); - registerMethod(L, "Creature", "getMaxHealth", CreatureFunctions::luaCreatureGetMaxHealth); - registerMethod(L, "Creature", "setMaxHealth", CreatureFunctions::luaCreatureSetMaxHealth); - registerMethod(L, "Creature", "setHiddenHealth", CreatureFunctions::luaCreatureSetHiddenHealth); - registerMethod(L, "Creature", "isMoveLocked", CreatureFunctions::luaCreatureIsMoveLocked); - registerMethod(L, "Creature", "isDirectionLocked", CreatureFunctions::luaCreatureIsDirectionLocked); - registerMethod(L, "Creature", "setMoveLocked", CreatureFunctions::luaCreatureSetMoveLocked); - registerMethod(L, "Creature", "setDirectionLocked", CreatureFunctions::luaCreatureSetDirectionLocked); - registerMethod(L, "Creature", "getSkull", CreatureFunctions::luaCreatureGetSkull); - registerMethod(L, "Creature", "setSkull", CreatureFunctions::luaCreatureSetSkull); - registerMethod(L, "Creature", "getOutfit", CreatureFunctions::luaCreatureGetOutfit); - registerMethod(L, "Creature", "setOutfit", CreatureFunctions::luaCreatureSetOutfit); - registerMethod(L, "Creature", "getCondition", CreatureFunctions::luaCreatureGetCondition); - registerMethod(L, "Creature", "addCondition", CreatureFunctions::luaCreatureAddCondition); - registerMethod(L, "Creature", "removeCondition", CreatureFunctions::luaCreatureRemoveCondition); - registerMethod(L, "Creature", "hasCondition", CreatureFunctions::luaCreatureHasCondition); - registerMethod(L, "Creature", "remove", CreatureFunctions::luaCreatureRemove); - registerMethod(L, "Creature", "teleportTo", CreatureFunctions::luaCreatureTeleportTo); - registerMethod(L, "Creature", "say", CreatureFunctions::luaCreatureSay); - registerMethod(L, "Creature", "getDamageMap", CreatureFunctions::luaCreatureGetDamageMap); - registerMethod(L, "Creature", "getSummons", CreatureFunctions::luaCreatureGetSummons); - registerMethod(L, "Creature", "hasBeenSummoned", CreatureFunctions::luaCreatureHasBeenSummoned); - registerMethod(L, "Creature", "getDescription", CreatureFunctions::luaCreatureGetDescription); - registerMethod(L, "Creature", "getPathTo", CreatureFunctions::luaCreatureGetPathTo); - registerMethod(L, "Creature", "move", CreatureFunctions::luaCreatureMove); - registerMethod(L, "Creature", "getZoneType", CreatureFunctions::luaCreatureGetZoneType); - registerMethod(L, "Creature", "getZones", CreatureFunctions::luaCreatureGetZones); - registerMethod(L, "Creature", "setIcon", CreatureFunctions::luaCreatureSetIcon); - registerMethod(L, "Creature", "getIcon", CreatureFunctions::luaCreatureGetIcon); - registerMethod(L, "Creature", "getIcons", CreatureFunctions::luaCreatureGetIcons); - registerMethod(L, "Creature", "removeIcon", CreatureFunctions::luaCreatureRemoveIcon); - registerMethod(L, "Creature", "clearIcons", CreatureFunctions::luaCreatureClearIcons); - - CombatFunctions::init(L); - MonsterFunctions::init(L); - NpcFunctions::init(L); - PlayerFunctions::init(L); - } + static void init(lua_State* L); private: static int luaCreatureCreate(lua_State* L); diff --git a/src/lua/functions/creatures/monster/charm_functions.cpp b/src/lua/functions/creatures/monster/charm_functions.cpp index 920f4891afe..88d27314431 100644 --- a/src/lua/functions/creatures/monster/charm_functions.cpp +++ b/src/lua/functions/creatures/monster/charm_functions.cpp @@ -11,17 +11,36 @@ #include "game/game.hpp" #include "io/iobestiary.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void CharmFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Charm", "", CharmFunctions::luaCharmCreate); + Lua::registerMetaMethod(L, "Charm", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Charm", "name", CharmFunctions::luaCharmName); + Lua::registerMethod(L, "Charm", "description", CharmFunctions::luaCharmDescription); + Lua::registerMethod(L, "Charm", "type", CharmFunctions::luaCharmType); + Lua::registerMethod(L, "Charm", "points", CharmFunctions::luaCharmPoints); + Lua::registerMethod(L, "Charm", "damageType", CharmFunctions::luaCharmDamageType); + Lua::registerMethod(L, "Charm", "percentage", CharmFunctions::luaCharmPercentage); + Lua::registerMethod(L, "Charm", "chance", CharmFunctions::luaCharmChance); + Lua::registerMethod(L, "Charm", "messageCancel", CharmFunctions::luaCharmMessageCancel); + Lua::registerMethod(L, "Charm", "messageServerLog", CharmFunctions::luaCharmMessageServerLog); + Lua::registerMethod(L, "Charm", "effect", CharmFunctions::luaCharmEffect); + Lua::registerMethod(L, "Charm", "castSound", CharmFunctions::luaCharmCastSound); + Lua::registerMethod(L, "Charm", "impactSound", CharmFunctions::luaCharmImpactSound); +} int CharmFunctions::luaCharmCreate(lua_State* L) { // charm(id) - if (isNumber(L, 2)) { - const charmRune_t charmid = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + const charmRune_t charmid = Lua::getNumber(L, 2); const auto charmList = g_game().getCharmList(); for (const auto &charm : charmList) { if (charm->id == charmid) { - pushUserdata(L, charm); - setMetatable(L, -1, "Charm"); - pushBoolean(L, true); + Lua::pushUserdata(L, charm); + Lua::setMetatable(L, -1, "Charm"); + Lua::pushBoolean(L, true); } } } @@ -32,144 +51,144 @@ int CharmFunctions::luaCharmCreate(lua_State* L) { int CharmFunctions::luaCharmName(lua_State* L) { // get: charm:name() set: charm:name(string) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { - pushString(L, charm->name); + Lua::pushString(L, charm->name); } else { - charm->name = getString(L, 2); - pushBoolean(L, true); + charm->name = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmDescription(lua_State* L) { // get: charm:description() set: charm:description(string) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { - pushString(L, charm->description); + Lua::pushString(L, charm->description); } else { - charm->description = getString(L, 2); - pushBoolean(L, true); + charm->description = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmType(lua_State* L) { // get: charm:type() set: charm:type(charm_t) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->type); } else { - charm->type = getNumber(L, 2); - pushBoolean(L, true); + charm->type = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmPoints(lua_State* L) { // get: charm:points() set: charm:points(value) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->points); } else { - charm->points = getNumber(L, 2); - pushBoolean(L, true); + charm->points = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmDamageType(lua_State* L) { // get: charm:damageType() set: charm:damageType(type) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->dmgtype); } else { - charm->dmgtype = getNumber(L, 2); - pushBoolean(L, true); + charm->dmgtype = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmPercentage(lua_State* L) { // get: charm:percentage() set: charm:percentage(value) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->percent); } else { - charm->percent = getNumber(L, 2); - pushBoolean(L, true); + charm->percent = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmChance(lua_State* L) { // get: charm:chance() set: charm:chance(value) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->chance); } else { - charm->chance = getNumber(L, 2); - pushBoolean(L, true); + charm->chance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmMessageCancel(lua_State* L) { // get: charm:messageCancel() set: charm:messageCancel(string) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { - pushString(L, charm->cancelMsg); + Lua::pushString(L, charm->cancelMsg); } else { - charm->cancelMsg = getString(L, 2); - pushBoolean(L, true); + charm->cancelMsg = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmMessageServerLog(lua_State* L) { // get: charm:messageServerLog() set: charm:messageServerLog(string) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { - pushString(L, charm->logMsg); + Lua::pushString(L, charm->logMsg); } else { - charm->logMsg = getString(L, 2); - pushBoolean(L, true); + charm->logMsg = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmEffect(lua_State* L) { // get: charm:effect() set: charm:effect(value) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, charm->effect); } else { - charm->effect = getNumber(L, 2); - pushBoolean(L, true); + charm->effect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmCastSound(lua_State* L) { // get: charm:castSound() set: charm:castSound(sound) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(charm->soundCastEffect)); } else { - charm->soundCastEffect = getNumber(L, 2); - pushBoolean(L, true); + charm->soundCastEffect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int CharmFunctions::luaCharmImpactSound(lua_State* L) { // get: charm:impactSound() set: charm:impactSound(sound) - const auto &charm = getUserdataShared(L, 1); + const auto &charm = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(charm->soundImpactEffect)); } else { - charm->soundImpactEffect = getNumber(L, 2); - pushBoolean(L, true); + charm->soundImpactEffect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } diff --git a/src/lua/functions/creatures/monster/charm_functions.hpp b/src/lua/functions/creatures/monster/charm_functions.hpp index 837c1c14fa7..10b9f96f124 100644 --- a/src/lua/functions/creatures/monster/charm_functions.hpp +++ b/src/lua/functions/creatures/monster/charm_functions.hpp @@ -9,33 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class CharmFunctions final : LuaScriptInterface { +class CharmFunctions { public: - explicit CharmFunctions(lua_State* L) : - LuaScriptInterface("CharmFunctions") { - init(L); - } - ~CharmFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Charm", "", CharmFunctions::luaCharmCreate); - registerMetaMethod(L, "Charm", "__eq", CharmFunctions::luaUserdataCompare); - - registerMethod(L, "Charm", "name", CharmFunctions::luaCharmName); - registerMethod(L, "Charm", "description", CharmFunctions::luaCharmDescription); - registerMethod(L, "Charm", "type", CharmFunctions::luaCharmType); - registerMethod(L, "Charm", "points", CharmFunctions::luaCharmPoints); - registerMethod(L, "Charm", "damageType", CharmFunctions::luaCharmDamageType); - registerMethod(L, "Charm", "percentage", CharmFunctions::luaCharmPercentage); - registerMethod(L, "Charm", "chance", CharmFunctions::luaCharmChance); - registerMethod(L, "Charm", "messageCancel", CharmFunctions::luaCharmMessageCancel); - registerMethod(L, "Charm", "messageServerLog", CharmFunctions::luaCharmMessageServerLog); - registerMethod(L, "Charm", "effect", CharmFunctions::luaCharmEffect); - registerMethod(L, "Charm", "castSound", CharmFunctions::luaCharmCastSound); - registerMethod(L, "Charm", "impactSound", CharmFunctions::luaCharmImpactSound); - } + static void init(lua_State* L); private: static int luaCharmCreate(lua_State* L); diff --git a/src/lua/functions/creatures/monster/loot_functions.cpp b/src/lua/functions/creatures/monster/loot_functions.cpp index 79260ccc935..87e7c8c2588 100644 --- a/src/lua/functions/creatures/monster/loot_functions.cpp +++ b/src/lua/functions/creatures/monster/loot_functions.cpp @@ -12,22 +12,46 @@ #include "creatures/monsters/monsters.hpp" #include "items/item.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void LootFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Loot", "", LootFunctions::luaCreateLoot); + + Lua::registerMethod(L, "Loot", "setId", LootFunctions::luaLootSetId); + Lua::registerMethod(L, "Loot", "setIdFromName", LootFunctions::luaLootSetIdFromName); + Lua::registerMethod(L, "Loot", "setMinCount", LootFunctions::luaLootSetMinCount); + Lua::registerMethod(L, "Loot", "setMaxCount", LootFunctions::luaLootSetMaxCount); + Lua::registerMethod(L, "Loot", "setSubType", LootFunctions::luaLootSetSubType); + Lua::registerMethod(L, "Loot", "setChance", LootFunctions::luaLootSetChance); + Lua::registerMethod(L, "Loot", "setActionId", LootFunctions::luaLootSetActionId); + Lua::registerMethod(L, "Loot", "setText", LootFunctions::luaLootSetText); + Lua::registerMethod(L, "Loot", "setNameItem", LootFunctions::luaLootSetNameItem); + Lua::registerMethod(L, "Loot", "setArticle", LootFunctions::luaLootSetArticle); + Lua::registerMethod(L, "Loot", "setAttack", LootFunctions::luaLootSetAttack); + Lua::registerMethod(L, "Loot", "setDefense", LootFunctions::luaLootSetDefense); + Lua::registerMethod(L, "Loot", "setExtraDefense", LootFunctions::luaLootSetExtraDefense); + Lua::registerMethod(L, "Loot", "setArmor", LootFunctions::luaLootSetArmor); + Lua::registerMethod(L, "Loot", "setShootRange", LootFunctions::luaLootSetShootRange); + Lua::registerMethod(L, "Loot", "setHitChance", LootFunctions::luaLootSetHitChance); + Lua::registerMethod(L, "Loot", "setUnique", LootFunctions::luaLootSetUnique); + Lua::registerMethod(L, "Loot", "addChildLoot", LootFunctions::luaLootAddChildLoot); +} int LootFunctions::luaCreateLoot(lua_State* L) { // Loot() will create a new loot item auto loot = std::make_shared(); - pushUserdata(L, loot); - setMetatable(L, -1, "Loot"); + Lua::pushUserdata(L, loot); + Lua::setMetatable(L, -1, "Loot"); return 1; } int LootFunctions::luaLootSetId(lua_State* L) { // loot:setId(id) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - if (isNumber(L, 2)) { - loot->lootBlock.id = getNumber(L, 2); - pushBoolean(L, true); + if (Lua::isNumber(L, 2)) { + loot->lootBlock.id = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { g_logger().warn("[LootFunctions::luaLootSetId] - " "Unknown loot item loot, int value expected"); @@ -41,9 +65,9 @@ int LootFunctions::luaLootSetId(lua_State* L) { int LootFunctions::luaLootSetIdFromName(lua_State* L) { // loot:setIdFromName(name) - const auto &loot = getUserdataShared(L, 1); - if (loot && isString(L, 2)) { - auto name = getString(L, 2); + const auto &loot = Lua::getUserdataShared(L, 1); + if (loot && Lua::isString(L, 2)) { + auto name = Lua::getString(L, 2); const auto ids = Item::items.nameToItems.equal_range(asLowerCaseString(name)); if (ids.first == Item::items.nameToItems.cend()) { @@ -63,7 +87,7 @@ int LootFunctions::luaLootSetIdFromName(lua_State* L) { } loot->lootBlock.id = ids.first->second; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { g_logger().warn("[LootFunctions::luaLootSetIdFromName] - " "Unknown loot item loot, string value expected"); @@ -74,10 +98,10 @@ int LootFunctions::luaLootSetIdFromName(lua_State* L) { int LootFunctions::luaLootSetSubType(lua_State* L) { // loot:setSubType(type) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.subType = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.subType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -86,10 +110,10 @@ int LootFunctions::luaLootSetSubType(lua_State* L) { int LootFunctions::luaLootSetChance(lua_State* L) { // loot:setChance(chance) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.chance = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.chance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -98,10 +122,10 @@ int LootFunctions::luaLootSetChance(lua_State* L) { int LootFunctions::luaLootSetMinCount(lua_State* L) { // loot:setMinCount(min) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.countmin = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.countmin = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -110,10 +134,10 @@ int LootFunctions::luaLootSetMinCount(lua_State* L) { int LootFunctions::luaLootSetMaxCount(lua_State* L) { // loot:setMaxCount(max) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.countmax = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.countmax = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -122,10 +146,10 @@ int LootFunctions::luaLootSetMaxCount(lua_State* L) { int LootFunctions::luaLootSetActionId(lua_State* L) { // loot:setActionId(actionid) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.actionId = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.actionId = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -134,10 +158,10 @@ int LootFunctions::luaLootSetActionId(lua_State* L) { int LootFunctions::luaLootSetText(lua_State* L) { // loot:setText(text) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.text = getString(L, 2); - pushBoolean(L, true); + loot->lootBlock.text = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -146,10 +170,10 @@ int LootFunctions::luaLootSetText(lua_State* L) { int LootFunctions::luaLootSetNameItem(lua_State* L) { // loot:setNameItem(name) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.name = getString(L, 2); - pushBoolean(L, true); + loot->lootBlock.name = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -158,10 +182,10 @@ int LootFunctions::luaLootSetNameItem(lua_State* L) { int LootFunctions::luaLootSetArticle(lua_State* L) { // loot:setArticle(article) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.article = getString(L, 2); - pushBoolean(L, true); + loot->lootBlock.article = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -170,10 +194,10 @@ int LootFunctions::luaLootSetArticle(lua_State* L) { int LootFunctions::luaLootSetAttack(lua_State* L) { // loot:setAttack(attack) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.attack = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.attack = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -182,10 +206,10 @@ int LootFunctions::luaLootSetAttack(lua_State* L) { int LootFunctions::luaLootSetDefense(lua_State* L) { // loot:setDefense(defense) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.defense = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.defense = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -194,10 +218,10 @@ int LootFunctions::luaLootSetDefense(lua_State* L) { int LootFunctions::luaLootSetExtraDefense(lua_State* L) { // loot:setExtraDefense(defense) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.extraDefense = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.extraDefense = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -206,10 +230,10 @@ int LootFunctions::luaLootSetExtraDefense(lua_State* L) { int LootFunctions::luaLootSetArmor(lua_State* L) { // loot:setArmor(armor) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.armor = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.armor = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -218,10 +242,10 @@ int LootFunctions::luaLootSetArmor(lua_State* L) { int LootFunctions::luaLootSetShootRange(lua_State* L) { // loot:setShootRange(range) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.shootRange = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.shootRange = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -230,10 +254,10 @@ int LootFunctions::luaLootSetShootRange(lua_State* L) { int LootFunctions::luaLootSetHitChance(lua_State* L) { // loot:setHitChance(chance) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - loot->lootBlock.hitChance = getNumber(L, 2); - pushBoolean(L, true); + loot->lootBlock.hitChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -242,13 +266,13 @@ int LootFunctions::luaLootSetHitChance(lua_State* L) { int LootFunctions::luaLootSetUnique(lua_State* L) { // loot:setUnique(bool) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { if (lua_gettop(L) == 1) { - pushBoolean(L, loot->lootBlock.unique); + Lua::pushBoolean(L, loot->lootBlock.unique); } else { - loot->lootBlock.unique = getBoolean(L, 2); - pushBoolean(L, true); + loot->lootBlock.unique = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -258,14 +282,14 @@ int LootFunctions::luaLootSetUnique(lua_State* L) { int LootFunctions::luaLootAddChildLoot(lua_State* L) { // loot:addChildLoot(loot) - const auto &loot = getUserdataShared(L, 1); + const auto &loot = Lua::getUserdataShared(L, 1); if (loot) { - const auto childLoot = getUserdata(L, 2); + const auto childLoot = Lua::getUserdata(L, 2); if (childLoot) { loot->lootBlock.childLoot.push_back(childLoot->lootBlock); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } } else { lua_pushnil(L); diff --git a/src/lua/functions/creatures/monster/loot_functions.hpp b/src/lua/functions/creatures/monster/loot_functions.hpp index 321f6bd8365..faa9abc2ef1 100644 --- a/src/lua/functions/creatures/monster/loot_functions.hpp +++ b/src/lua/functions/creatures/monster/loot_functions.hpp @@ -9,38 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class LootFunctions final : LuaScriptInterface { +class LootFunctions { public: - explicit LootFunctions(lua_State* L) : - LuaScriptInterface("LootFunctions") { - init(L); - } - ~LootFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Loot", "", LootFunctions::luaCreateLoot); - - registerMethod(L, "Loot", "setId", LootFunctions::luaLootSetId); - registerMethod(L, "Loot", "setIdFromName", LootFunctions::luaLootSetIdFromName); - registerMethod(L, "Loot", "setMinCount", LootFunctions::luaLootSetMinCount); - registerMethod(L, "Loot", "setMaxCount", LootFunctions::luaLootSetMaxCount); - registerMethod(L, "Loot", "setSubType", LootFunctions::luaLootSetSubType); - registerMethod(L, "Loot", "setChance", LootFunctions::luaLootSetChance); - registerMethod(L, "Loot", "setActionId", LootFunctions::luaLootSetActionId); - registerMethod(L, "Loot", "setText", LootFunctions::luaLootSetText); - registerMethod(L, "Loot", "setNameItem", LootFunctions::luaLootSetNameItem); - registerMethod(L, "Loot", "setArticle", LootFunctions::luaLootSetArticle); - registerMethod(L, "Loot", "setAttack", LootFunctions::luaLootSetAttack); - registerMethod(L, "Loot", "setDefense", LootFunctions::luaLootSetDefense); - registerMethod(L, "Loot", "setExtraDefense", LootFunctions::luaLootSetExtraDefense); - registerMethod(L, "Loot", "setArmor", LootFunctions::luaLootSetArmor); - registerMethod(L, "Loot", "setShootRange", LootFunctions::luaLootSetShootRange); - registerMethod(L, "Loot", "setHitChance", LootFunctions::luaLootSetHitChance); - registerMethod(L, "Loot", "setUnique", LootFunctions::luaLootSetUnique); - registerMethod(L, "Loot", "addChildLoot", LootFunctions::luaLootAddChildLoot); - } + static void init(lua_State* L); private: static int luaCreateLoot(lua_State* L); diff --git a/src/lua/functions/creatures/monster/monster_functions.cpp b/src/lua/functions/creatures/monster/monster_functions.cpp index 4b85fc98c3a..3f5d0c25ea8 100644 --- a/src/lua/functions/creatures/monster/monster_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_functions.cpp @@ -17,25 +17,86 @@ #include "game/game.hpp" #include "game/scheduling/events_scheduler.hpp" #include "map/spectators.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void MonsterFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Monster", "Creature", MonsterFunctions::luaMonsterCreate); + Lua::registerMetaMethod(L, "Monster", "__eq", Lua::luaUserdataCompare); + Lua::registerMethod(L, "Monster", "isMonster", MonsterFunctions::luaMonsterIsMonster); + Lua::registerMethod(L, "Monster", "getType", MonsterFunctions::luaMonsterGetType); + Lua::registerMethod(L, "Monster", "setType", MonsterFunctions::luaMonsterSetType); + Lua::registerMethod(L, "Monster", "getSpawnPosition", MonsterFunctions::luaMonsterGetSpawnPosition); + Lua::registerMethod(L, "Monster", "isInSpawnRange", MonsterFunctions::luaMonsterIsInSpawnRange); + Lua::registerMethod(L, "Monster", "isIdle", MonsterFunctions::luaMonsterIsIdle); + Lua::registerMethod(L, "Monster", "setIdle", MonsterFunctions::luaMonsterSetIdle); + Lua::registerMethod(L, "Monster", "isTarget", MonsterFunctions::luaMonsterIsTarget); + Lua::registerMethod(L, "Monster", "isOpponent", MonsterFunctions::luaMonsterIsOpponent); + Lua::registerMethod(L, "Monster", "isFriend", MonsterFunctions::luaMonsterIsFriend); + Lua::registerMethod(L, "Monster", "addFriend", MonsterFunctions::luaMonsterAddFriend); + Lua::registerMethod(L, "Monster", "removeFriend", MonsterFunctions::luaMonsterRemoveFriend); + Lua::registerMethod(L, "Monster", "getFriendList", MonsterFunctions::luaMonsterGetFriendList); + Lua::registerMethod(L, "Monster", "getFriendCount", MonsterFunctions::luaMonsterGetFriendCount); + Lua::registerMethod(L, "Monster", "addTarget", MonsterFunctions::luaMonsterAddTarget); + Lua::registerMethod(L, "Monster", "removeTarget", MonsterFunctions::luaMonsterRemoveTarget); + Lua::registerMethod(L, "Monster", "getTargetList", MonsterFunctions::luaMonsterGetTargetList); + Lua::registerMethod(L, "Monster", "getTargetCount", MonsterFunctions::luaMonsterGetTargetCount); + Lua::registerMethod(L, "Monster", "changeTargetDistance", MonsterFunctions::luaMonsterChangeTargetDistance); + Lua::registerMethod(L, "Monster", "isChallenged", MonsterFunctions::luaMonsterIsChallenged); + Lua::registerMethod(L, "Monster", "selectTarget", MonsterFunctions::luaMonsterSelectTarget); + Lua::registerMethod(L, "Monster", "searchTarget", MonsterFunctions::luaMonsterSearchTarget); + Lua::registerMethod(L, "Monster", "setSpawnPosition", MonsterFunctions::luaMonsterSetSpawnPosition); + Lua::registerMethod(L, "Monster", "getRespawnType", MonsterFunctions::luaMonsterGetRespawnType); + + Lua::registerMethod(L, "Monster", "getTimeToChangeFiendish", MonsterFunctions::luaMonsterGetTimeToChangeFiendish); + Lua::registerMethod(L, "Monster", "setTimeToChangeFiendish", MonsterFunctions::luaMonsterSetTimeToChangeFiendish); + Lua::registerMethod(L, "Monster", "getMonsterForgeClassification", MonsterFunctions::luaMonsterGetMonsterForgeClassification); + Lua::registerMethod(L, "Monster", "setMonsterForgeClassification", MonsterFunctions::luaMonsterSetMonsterForgeClassification); + Lua::registerMethod(L, "Monster", "getForgeStack", MonsterFunctions::luaMonsterGetForgeStack); + Lua::registerMethod(L, "Monster", "setForgeStack", MonsterFunctions::luaMonsterSetForgeStack); + Lua::registerMethod(L, "Monster", "configureForgeSystem", MonsterFunctions::luaMonsterConfigureForgeSystem); + Lua::registerMethod(L, "Monster", "clearFiendishStatus", MonsterFunctions::luaMonsterClearFiendishStatus); + Lua::registerMethod(L, "Monster", "isForgeable", MonsterFunctions::luaMonsterIsForgeable); + + Lua::registerMethod(L, "Monster", "getName", MonsterFunctions::luaMonsterGetName); + Lua::registerMethod(L, "Monster", "setName", MonsterFunctions::luaMonsterSetName); + + Lua::registerMethod(L, "Monster", "hazard", MonsterFunctions::luaMonsterHazard); + Lua::registerMethod(L, "Monster", "hazardCrit", MonsterFunctions::luaMonsterHazardCrit); + Lua::registerMethod(L, "Monster", "hazardDodge", MonsterFunctions::luaMonsterHazardDodge); + Lua::registerMethod(L, "Monster", "hazardDamageBoost", MonsterFunctions::luaMonsterHazardDamageBoost); + Lua::registerMethod(L, "Monster", "hazardDefenseBoost", MonsterFunctions::luaMonsterHazardDefenseBoost); + + Lua::registerMethod(L, "Monster", "addReflectElement", MonsterFunctions::luaMonsterAddReflectElement); + Lua::registerMethod(L, "Monster", "addDefense", MonsterFunctions::luaMonsterAddDefense); + Lua::registerMethod(L, "Monster", "getDefense", MonsterFunctions::luaMonsterGetDefense); + + Lua::registerMethod(L, "Monster", "isDead", MonsterFunctions::luaMonsterIsDead); + Lua::registerMethod(L, "Monster", "immune", MonsterFunctions::luaMonsterImmune); + + CharmFunctions::init(L); + LootFunctions::init(L); + MonsterSpellFunctions::init(L); + MonsterTypeFunctions::init(L); +} int MonsterFunctions::luaMonsterCreate(lua_State* L) { // Monster(id or userdata) std::shared_ptr monster; - if (isNumber(L, 2)) { - monster = g_game().getMonsterByID(getNumber(L, 2)); - } else if (isUserdata(L, 2)) { - if (getUserdataType(L, 2) != LuaData_t::Monster) { + if (Lua::isNumber(L, 2)) { + monster = g_game().getMonsterByID(Lua::getNumber(L, 2)); + } else if (Lua::isUserdata(L, 2)) { + if (Lua::getUserdataType(L, 2) != LuaData_t::Monster) { lua_pushnil(L); return 1; } - monster = getUserdataShared(L, 2); + monster = Lua::getUserdataShared(L, 2); } else { monster = nullptr; } if (monster) { - pushUserdata(L, monster); - setMetatable(L, -1, "Monster"); + Lua::pushUserdata(L, monster); + Lua::setMetatable(L, -1, "Monster"); } else { lua_pushnil(L); } @@ -44,16 +105,16 @@ int MonsterFunctions::luaMonsterCreate(lua_State* L) { int MonsterFunctions::luaMonsterIsMonster(lua_State* L) { // monster:isMonster() - pushBoolean(L, getUserdataShared(L, 1) != nullptr); + Lua::pushBoolean(L, Lua::getUserdataShared(L, 1) != nullptr); return 1; } int MonsterFunctions::luaMonsterGetType(lua_State* L) { // monster:getType() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - pushUserdata(L, monster->mType); - setMetatable(L, -1, "MonsterType"); + Lua::pushUserdata(L, monster->mType); + Lua::setMetatable(L, -1, "MonsterType"); } else { lua_pushnil(L); } @@ -62,14 +123,14 @@ int MonsterFunctions::luaMonsterGetType(lua_State* L) { int MonsterFunctions::luaMonsterSetType(lua_State* L) { // monster:setType(name or raceid, restoreHealth = false) - bool restoreHealth = getBoolean(L, 3, false); - const auto &monster = getUserdataShared(L, 1); + bool restoreHealth = Lua::getBoolean(L, 3, false); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { std::shared_ptr mType; - if (isNumber(L, 2)) { - mType = g_monsters().getMonsterTypeByRaceId(getNumber(L, 2)); + if (Lua::isNumber(L, 2)) { + mType = g_monsters().getMonsterTypeByRaceId(Lua::getNumber(L, 2)); } else { - mType = g_monsters().getMonsterType(getString(L, 2)); + mType = g_monsters().getMonsterType(Lua::getString(L, 2)); } // Unregister creature events (current MonsterType) for (const std::string &scriptName : monster->mType->info.scripts) { @@ -105,7 +166,7 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { for (const auto &spectator : Spectators().find(monster->getPosition(), true)) { spectator->getPlayer()->sendCreatureReload(monster); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -114,9 +175,9 @@ int MonsterFunctions::luaMonsterSetType(lua_State* L) { int MonsterFunctions::luaMonsterGetSpawnPosition(lua_State* L) { // monster:getSpawnPosition() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - pushPosition(L, monster->getMasterPos()); + Lua::pushPosition(L, monster->getMasterPos()); } else { lua_pushnil(L); } @@ -125,9 +186,9 @@ int MonsterFunctions::luaMonsterGetSpawnPosition(lua_State* L) { int MonsterFunctions::luaMonsterIsInSpawnRange(lua_State* L) { // monster:isInSpawnRange([position]) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - pushBoolean(L, monster->isInSpawnRange(lua_gettop(L) >= 2 ? getPosition(L, 2) : monster->getPosition())); + Lua::pushBoolean(L, monster->isInSpawnRange(lua_gettop(L) >= 2 ? Lua::getPosition(L, 2) : monster->getPosition())); } else { lua_pushnil(L); } @@ -136,9 +197,9 @@ int MonsterFunctions::luaMonsterIsInSpawnRange(lua_State* L) { int MonsterFunctions::luaMonsterIsIdle(lua_State* L) { // monster:isIdle() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - pushBoolean(L, monster->getIdleStatus()); + Lua::pushBoolean(L, monster->getIdleStatus()); } else { lua_pushnil(L); } @@ -147,23 +208,23 @@ int MonsterFunctions::luaMonsterIsIdle(lua_State* L) { int MonsterFunctions::luaMonsterSetIdle(lua_State* L) { // monster:setIdle(idle) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; } - monster->setIdle(getBoolean(L, 2)); - pushBoolean(L, true); + monster->setIdle(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterIsTarget(lua_State* L) { // monster:isTarget(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); - pushBoolean(L, monster->isTarget(creature)); + const auto &creature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, monster->isTarget(creature)); } else { lua_pushnil(L); } @@ -172,10 +233,10 @@ int MonsterFunctions::luaMonsterIsTarget(lua_State* L) { int MonsterFunctions::luaMonsterIsOpponent(lua_State* L) { // monster:isOpponent(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); - pushBoolean(L, monster->isOpponent(creature)); + const auto &creature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, monster->isOpponent(creature)); } else { lua_pushnil(L); } @@ -184,10 +245,10 @@ int MonsterFunctions::luaMonsterIsOpponent(lua_State* L) { int MonsterFunctions::luaMonsterIsFriend(lua_State* L) { // monster:isFriend(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); - pushBoolean(L, monster->isFriend(creature)); + const auto &creature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, monster->isFriend(creature)); } else { lua_pushnil(L); } @@ -196,11 +257,11 @@ int MonsterFunctions::luaMonsterIsFriend(lua_State* L) { int MonsterFunctions::luaMonsterAddFriend(lua_State* L) { // monster:addFriend(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); + const auto &creature = Lua::getCreature(L, 2); monster->addFriend(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -209,11 +270,11 @@ int MonsterFunctions::luaMonsterAddFriend(lua_State* L) { int MonsterFunctions::luaMonsterRemoveFriend(lua_State* L) { // monster:removeFriend(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); + const auto &creature = Lua::getCreature(L, 2); monster->removeFriend(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -222,7 +283,7 @@ int MonsterFunctions::luaMonsterRemoveFriend(lua_State* L) { int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { // monster:getFriendList() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -233,8 +294,8 @@ int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { int index = 0; for (const auto &creature : friendList) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); } return 1; @@ -242,7 +303,7 @@ int MonsterFunctions::luaMonsterGetFriendList(lua_State* L) { int MonsterFunctions::luaMonsterGetFriendCount(lua_State* L) { // monster:getFriendCount() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { lua_pushnumber(L, monster->getFriendList().size()); } else { @@ -253,35 +314,35 @@ int MonsterFunctions::luaMonsterGetFriendCount(lua_State* L) { int MonsterFunctions::luaMonsterAddTarget(lua_State* L) { // monster:addTarget(creature[, pushFront = false]) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; } - const auto &creature = getCreature(L, 2); - const bool pushFront = getBoolean(L, 3, false); + const auto &creature = Lua::getCreature(L, 2); + const bool pushFront = Lua::getBoolean(L, 3, false); monster->addTarget(creature, pushFront); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterRemoveTarget(lua_State* L) { // monster:removeTarget(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; } - monster->removeTarget(getCreature(L, 2)); - pushBoolean(L, true); + monster->removeTarget(Lua::getCreature(L, 2)); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { // monster:getTargetList() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -292,8 +353,8 @@ int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { int index = 0; for (const auto &creature : targetList) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); } return 1; @@ -301,7 +362,7 @@ int MonsterFunctions::luaMonsterGetTargetList(lua_State* L) { int MonsterFunctions::luaMonsterGetTargetCount(lua_State* L) { // monster:getTargetCount() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { lua_pushnumber(L, monster->getTargetList().size()); } else { @@ -312,11 +373,11 @@ int MonsterFunctions::luaMonsterGetTargetCount(lua_State* L) { int MonsterFunctions::luaMonsterChangeTargetDistance(lua_State* L) { // monster:changeTargetDistance(distance[, duration = 12000]) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto distance = getNumber(L, 2, 1); - const auto duration = getNumber(L, 3, 12000); - pushBoolean(L, monster->changeTargetDistance(distance, duration)); + const auto distance = Lua::getNumber(L, 2, 1); + const auto duration = Lua::getNumber(L, 3, 12000); + Lua::pushBoolean(L, monster->changeTargetDistance(distance, duration)); } else { lua_pushnil(L); } @@ -325,9 +386,9 @@ int MonsterFunctions::luaMonsterChangeTargetDistance(lua_State* L) { int MonsterFunctions::luaMonsterIsChallenged(lua_State* L) { // monster:isChallenged() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - pushBoolean(L, monster->isChallenged()); + Lua::pushBoolean(L, monster->isChallenged()); } else { lua_pushnil(L); } @@ -336,10 +397,10 @@ int MonsterFunctions::luaMonsterIsChallenged(lua_State* L) { int MonsterFunctions::luaMonsterSelectTarget(lua_State* L) { // monster:selectTarget(creature) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &creature = getCreature(L, 2); - pushBoolean(L, monster->selectTarget(creature)); + const auto &creature = Lua::getCreature(L, 2); + Lua::pushBoolean(L, monster->selectTarget(creature)); } else { lua_pushnil(L); } @@ -348,10 +409,10 @@ int MonsterFunctions::luaMonsterSelectTarget(lua_State* L) { int MonsterFunctions::luaMonsterSearchTarget(lua_State* L) { // monster:searchTarget([searchType = TARGETSEARCH_DEFAULT]) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (monster) { - const auto &searchType = getNumber(L, 2, TARGETSEARCH_DEFAULT); - pushBoolean(L, monster->searchTarget(searchType)); + const auto &searchType = Lua::getNumber(L, 2, TARGETSEARCH_DEFAULT); + Lua::pushBoolean(L, monster->searchTarget(searchType)); } else { lua_pushnil(L); } @@ -360,7 +421,7 @@ int MonsterFunctions::luaMonsterSearchTarget(lua_State* L) { int MonsterFunctions::luaMonsterSetSpawnPosition(lua_State* L) { // monster:setSpawnPosition(interval) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); return 1; @@ -372,17 +433,17 @@ int MonsterFunctions::luaMonsterSetSpawnPosition(lua_State* L) { monster->setMasterPos(pos); const auto &spawnMonster = g_game().map.spawnsMonster.getspawnMonsterList().emplace_back(std::make_shared(pos, 5)); - uint32_t interval = getNumber(L, 2, 90) * 1000 * 100 / std::max((uint32_t)1, (g_configManager().getNumber(RATE_SPAWN) * eventschedule)); + uint32_t interval = Lua::getNumber(L, 2, 90) * 1000 * 100 / std::max((uint32_t)1, (g_configManager().getNumber(RATE_SPAWN) * eventschedule)); spawnMonster->addMonster(monster->mType->typeName, pos, DIRECTION_NORTH, static_cast(interval)); spawnMonster->startSpawnMonsterCheck(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterGetRespawnType(lua_State* L) { // monster:getRespawnType() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { lua_pushnil(L); @@ -391,17 +452,17 @@ int MonsterFunctions::luaMonsterGetRespawnType(lua_State* L) { const RespawnType respawnType = monster->getRespawnType(); lua_pushnumber(L, respawnType.period); - pushBoolean(L, respawnType.underground); + Lua::pushBoolean(L, respawnType.underground); return 2; } int MonsterFunctions::luaMonsterGetTimeToChangeFiendish(lua_State* L) { // monster:getTimeToChangeFiendish() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -411,11 +472,11 @@ int MonsterFunctions::luaMonsterGetTimeToChangeFiendish(lua_State* L) { int MonsterFunctions::luaMonsterSetTimeToChangeFiendish(lua_State* L) { // monster:setTimeToChangeFiendish(endTime) - const time_t endTime = getNumber(L, 2, 1); - const auto &monster = getUserdataShared(L, 1); + const time_t endTime = Lua::getNumber(L, 2, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -425,10 +486,10 @@ int MonsterFunctions::luaMonsterSetTimeToChangeFiendish(lua_State* L) { int MonsterFunctions::luaMonsterGetMonsterForgeClassification(lua_State* L) { // monster:getMonsterForgeClassification() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -439,11 +500,11 @@ int MonsterFunctions::luaMonsterGetMonsterForgeClassification(lua_State* L) { int MonsterFunctions::luaMonsterSetMonsterForgeClassification(lua_State* L) { // monster:setMonsterForgeClassification(classication) - const ForgeClassifications_t classification = getNumber(L, 2); - const auto &monster = getUserdataShared(L, 1); + const ForgeClassifications_t classification = Lua::getNumber(L, 2); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -453,10 +514,10 @@ int MonsterFunctions::luaMonsterSetMonsterForgeClassification(lua_State* L) { int MonsterFunctions::luaMonsterGetForgeStack(lua_State* L) { // monster:getForgeStack() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -466,11 +527,11 @@ int MonsterFunctions::luaMonsterGetForgeStack(lua_State* L) { int MonsterFunctions::luaMonsterSetForgeStack(lua_State* L) { // monster:setForgeStack(stack) - const auto stack = getNumber(L, 2, 0); - const auto &monster = getUserdataShared(L, 1); + const auto stack = Lua::getNumber(L, 2, 0); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -486,10 +547,10 @@ int MonsterFunctions::luaMonsterSetForgeStack(lua_State* L) { int MonsterFunctions::luaMonsterConfigureForgeSystem(lua_State* L) { // monster:configureForgeSystem() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -499,10 +560,10 @@ int MonsterFunctions::luaMonsterConfigureForgeSystem(lua_State* L) { int MonsterFunctions::luaMonsterClearFiendishStatus(lua_State* L) { // monster:clearFiendishStatus() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -512,58 +573,58 @@ int MonsterFunctions::luaMonsterClearFiendishStatus(lua_State* L) { int MonsterFunctions::luaMonsterIsForgeable(lua_State* L) { // monster:isForgeable() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushBoolean(L, monster->canBeForgeMonster()); + Lua::pushBoolean(L, monster->canBeForgeMonster()); return 1; } int MonsterFunctions::luaMonsterGetName(lua_State* L) { // monster:getName() - const auto monster = getUserdataShared(L, 1); + const auto monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushString(L, monster->getName()); + Lua::pushString(L, monster->getName()); return 1; } int MonsterFunctions::luaMonsterSetName(lua_State* L) { // monster:setName(name[, nameDescription]) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - monster->setName(getString(L, 2)); + monster->setName(Lua::getString(L, 2)); if (lua_gettop(L) >= 3) { - monster->setNameDescription(getString(L, 3)); + monster->setNameDescription(Lua::getString(L, 3)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterHazard(lua_State* L) { // get: monster:hazard() ; set: monster:hazard(hazard) - const auto &monster = getUserdataShared(L, 1); - const bool hazard = getBoolean(L, 2, false); + const auto &monster = Lua::getUserdataShared(L, 1); + const bool hazard = Lua::getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { - pushBoolean(L, monster->getHazard()); + Lua::pushBoolean(L, monster->getHazard()); } else { monster->setHazard(hazard); - pushBoolean(L, monster->getHazard()); + Lua::pushBoolean(L, monster->getHazard()); } } else { lua_pushnil(L); @@ -573,14 +634,14 @@ int MonsterFunctions::luaMonsterHazard(lua_State* L) { int MonsterFunctions::luaMonsterHazardCrit(lua_State* L) { // get: monster:hazardCrit() ; set: monster:hazardCrit(hazardCrit) - const auto &monster = getUserdataShared(L, 1); - const bool hazardCrit = getBoolean(L, 2, false); + const auto &monster = Lua::getUserdataShared(L, 1); + const bool hazardCrit = Lua::getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { - pushBoolean(L, monster->getHazardSystemCrit()); + Lua::pushBoolean(L, monster->getHazardSystemCrit()); } else { monster->setHazardSystemCrit(hazardCrit); - pushBoolean(L, monster->getHazardSystemCrit()); + Lua::pushBoolean(L, monster->getHazardSystemCrit()); } } else { lua_pushnil(L); @@ -590,14 +651,14 @@ int MonsterFunctions::luaMonsterHazardCrit(lua_State* L) { int MonsterFunctions::luaMonsterHazardDodge(lua_State* L) { // get: monster:hazardDodge() ; set: monster:hazardDodge(hazardDodge) - const auto &monster = getUserdataShared(L, 1); - const bool hazardDodge = getBoolean(L, 2, false); + const auto &monster = Lua::getUserdataShared(L, 1); + const bool hazardDodge = Lua::getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { - pushBoolean(L, monster->getHazardSystemDodge()); + Lua::pushBoolean(L, monster->getHazardSystemDodge()); } else { monster->setHazardSystemDodge(hazardDodge); - pushBoolean(L, monster->getHazardSystemDodge()); + Lua::pushBoolean(L, monster->getHazardSystemDodge()); } } else { lua_pushnil(L); @@ -607,14 +668,14 @@ int MonsterFunctions::luaMonsterHazardDodge(lua_State* L) { int MonsterFunctions::luaMonsterHazardDamageBoost(lua_State* L) { // get: monster:hazardDamageBoost() ; set: monster:hazardDamageBoost(hazardDamageBoost) - const auto &monster = getUserdataShared(L, 1); - const bool hazardDamageBoost = getBoolean(L, 2, false); + const auto &monster = Lua::getUserdataShared(L, 1); + const bool hazardDamageBoost = Lua::getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { - pushBoolean(L, monster->getHazardSystemDamageBoost()); + Lua::pushBoolean(L, monster->getHazardSystemDamageBoost()); } else { monster->setHazardSystemDamageBoost(hazardDamageBoost); - pushBoolean(L, monster->getHazardSystemDamageBoost()); + Lua::pushBoolean(L, monster->getHazardSystemDamageBoost()); } } else { lua_pushnil(L); @@ -624,14 +685,14 @@ int MonsterFunctions::luaMonsterHazardDamageBoost(lua_State* L) { int MonsterFunctions::luaMonsterHazardDefenseBoost(lua_State* L) { // get: monster:hazardDefenseBoost() ; set: monster:hazardDefenseBoost(hazardDefenseBoost) - const auto &monster = getUserdataShared(L, 1); - const bool hazardDefenseBoost = getBoolean(L, 2, false); + const auto &monster = Lua::getUserdataShared(L, 1); + const bool hazardDefenseBoost = Lua::getBoolean(L, 2, false); if (monster) { if (lua_gettop(L) == 1) { - pushBoolean(L, monster->getHazardSystemDefenseBoost()); + Lua::pushBoolean(L, monster->getHazardSystemDefenseBoost()); } else { monster->setHazardSystemDefenseBoost(hazardDefenseBoost); - pushBoolean(L, monster->getHazardSystemDefenseBoost()); + Lua::pushBoolean(L, monster->getHazardSystemDefenseBoost()); } } else { lua_pushnil(L); @@ -641,39 +702,39 @@ int MonsterFunctions::luaMonsterHazardDefenseBoost(lua_State* L) { int MonsterFunctions::luaMonsterAddReflectElement(lua_State* L) { // monster:addReflectElement(type, percent) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - CombatType_t element = getNumber(L, 2); - monster->addReflectElement(element, getNumber(L, 3)); - pushBoolean(L, true); + CombatType_t element = Lua::getNumber(L, 2); + monster->addReflectElement(element, Lua::getNumber(L, 3)); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterAddDefense(lua_State* L) { // monster:addDefense(defense) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - monster->addDefense(getNumber(L, 2)); - pushBoolean(L, true); + monster->addDefense(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int MonsterFunctions::luaMonsterGetDefense(lua_State* L) { // monster:getDefense(defense) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -683,31 +744,31 @@ int MonsterFunctions::luaMonsterGetDefense(lua_State* L) { int MonsterFunctions::luaMonsterIsDead(lua_State* L) { // monster:isDead() - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushBoolean(L, monster->isDead()); + Lua::pushBoolean(L, monster->isDead()); return 1; } int MonsterFunctions::luaMonsterImmune(lua_State* L) { // to get: isImmune = monster:immune() // to set and get: newImmuneBool = monster:immune(newImmuneBool) - const auto &monster = getUserdataShared(L, 1); + const auto &monster = Lua::getUserdataShared(L, 1); if (!monster) { - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } if (lua_gettop(L) > 1) { - monster->setImmune(getBoolean(L, 2)); + monster->setImmune(Lua::getBoolean(L, 2)); } - pushBoolean(L, monster->isImmune()); + Lua::pushBoolean(L, monster->isImmune()); return 1; } diff --git a/src/lua/functions/creatures/monster/monster_functions.hpp b/src/lua/functions/creatures/monster/monster_functions.hpp index 0674bf64433..4ba696e941b 100644 --- a/src/lua/functions/creatures/monster/monster_functions.hpp +++ b/src/lua/functions/creatures/monster/monster_functions.hpp @@ -9,79 +9,14 @@ #pragma once -#include "lua/scripts/luascript.hpp" #include "lua/functions/creatures/monster/charm_functions.hpp" #include "lua/functions/creatures/monster/loot_functions.hpp" #include "lua/functions/creatures/monster/monster_spell_functions.hpp" #include "lua/functions/creatures/monster/monster_type_functions.hpp" -class MonsterFunctions final : LuaScriptInterface { +class MonsterFunctions { private: - explicit MonsterFunctions(lua_State* L) : - LuaScriptInterface("MonsterFunctions") { - init(L); - } - ~MonsterFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Monster", "Creature", MonsterFunctions::luaMonsterCreate); - registerMetaMethod(L, "Monster", "__eq", MonsterFunctions::luaUserdataCompare); - registerMethod(L, "Monster", "isMonster", MonsterFunctions::luaMonsterIsMonster); - registerMethod(L, "Monster", "getType", MonsterFunctions::luaMonsterGetType); - registerMethod(L, "Monster", "setType", MonsterFunctions::luaMonsterSetType); - registerMethod(L, "Monster", "getSpawnPosition", MonsterFunctions::luaMonsterGetSpawnPosition); - registerMethod(L, "Monster", "isInSpawnRange", MonsterFunctions::luaMonsterIsInSpawnRange); - registerMethod(L, "Monster", "isIdle", MonsterFunctions::luaMonsterIsIdle); - registerMethod(L, "Monster", "setIdle", MonsterFunctions::luaMonsterSetIdle); - registerMethod(L, "Monster", "isTarget", MonsterFunctions::luaMonsterIsTarget); - registerMethod(L, "Monster", "isOpponent", MonsterFunctions::luaMonsterIsOpponent); - registerMethod(L, "Monster", "isFriend", MonsterFunctions::luaMonsterIsFriend); - registerMethod(L, "Monster", "addFriend", MonsterFunctions::luaMonsterAddFriend); - registerMethod(L, "Monster", "removeFriend", MonsterFunctions::luaMonsterRemoveFriend); - registerMethod(L, "Monster", "getFriendList", MonsterFunctions::luaMonsterGetFriendList); - registerMethod(L, "Monster", "getFriendCount", MonsterFunctions::luaMonsterGetFriendCount); - registerMethod(L, "Monster", "addTarget", MonsterFunctions::luaMonsterAddTarget); - registerMethod(L, "Monster", "removeTarget", MonsterFunctions::luaMonsterRemoveTarget); - registerMethod(L, "Monster", "getTargetList", MonsterFunctions::luaMonsterGetTargetList); - registerMethod(L, "Monster", "getTargetCount", MonsterFunctions::luaMonsterGetTargetCount); - registerMethod(L, "Monster", "changeTargetDistance", MonsterFunctions::luaMonsterChangeTargetDistance); - registerMethod(L, "Monster", "isChallenged", MonsterFunctions::luaMonsterIsChallenged); - registerMethod(L, "Monster", "selectTarget", MonsterFunctions::luaMonsterSelectTarget); - registerMethod(L, "Monster", "searchTarget", MonsterFunctions::luaMonsterSearchTarget); - registerMethod(L, "Monster", "setSpawnPosition", MonsterFunctions::luaMonsterSetSpawnPosition); - registerMethod(L, "Monster", "getRespawnType", MonsterFunctions::luaMonsterGetRespawnType); - - registerMethod(L, "Monster", "getTimeToChangeFiendish", MonsterFunctions::luaMonsterGetTimeToChangeFiendish); - registerMethod(L, "Monster", "setTimeToChangeFiendish", MonsterFunctions::luaMonsterSetTimeToChangeFiendish); - registerMethod(L, "Monster", "getMonsterForgeClassification", MonsterFunctions::luaMonsterGetMonsterForgeClassification); - registerMethod(L, "Monster", "setMonsterForgeClassification", MonsterFunctions::luaMonsterSetMonsterForgeClassification); - registerMethod(L, "Monster", "getForgeStack", MonsterFunctions::luaMonsterGetForgeStack); - registerMethod(L, "Monster", "setForgeStack", MonsterFunctions::luaMonsterSetForgeStack); - registerMethod(L, "Monster", "configureForgeSystem", MonsterFunctions::luaMonsterConfigureForgeSystem); - registerMethod(L, "Monster", "clearFiendishStatus", MonsterFunctions::luaMonsterClearFiendishStatus); - registerMethod(L, "Monster", "isForgeable", MonsterFunctions::luaMonsterIsForgeable); - - registerMethod(L, "Monster", "getName", MonsterFunctions::luaMonsterGetName); - registerMethod(L, "Monster", "setName", MonsterFunctions::luaMonsterSetName); - - registerMethod(L, "Monster", "hazard", MonsterFunctions::luaMonsterHazard); - registerMethod(L, "Monster", "hazardCrit", MonsterFunctions::luaMonsterHazardCrit); - registerMethod(L, "Monster", "hazardDodge", MonsterFunctions::luaMonsterHazardDodge); - registerMethod(L, "Monster", "hazardDamageBoost", MonsterFunctions::luaMonsterHazardDamageBoost); - registerMethod(L, "Monster", "hazardDefenseBoost", MonsterFunctions::luaMonsterHazardDefenseBoost); - - registerMethod(L, "Monster", "addReflectElement", MonsterFunctions::luaMonsterAddReflectElement); - registerMethod(L, "Monster", "addDefense", MonsterFunctions::luaMonsterAddDefense); - registerMethod(L, "Monster", "getDefense", MonsterFunctions::luaMonsterGetDefense); - - registerMethod(L, "Monster", "isDead", MonsterFunctions::luaMonsterIsDead); - registerMethod(L, "Monster", "immune", MonsterFunctions::luaMonsterImmune); - - CharmFunctions::init(L); - LootFunctions::init(L); - MonsterSpellFunctions::init(L); - MonsterTypeFunctions::init(L); - } + static void init(lua_State* L); static int luaMonsterCreate(lua_State* L); diff --git a/src/lua/functions/creatures/monster/monster_spell_functions.cpp b/src/lua/functions/creatures/monster/monster_spell_functions.cpp index 693da8e6b7e..9fec549c3dd 100644 --- a/src/lua/functions/creatures/monster/monster_spell_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_spell_functions.cpp @@ -10,20 +10,49 @@ #include "lua/functions/creatures/monster/monster_spell_functions.hpp" #include "creatures/monsters/monsters.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void MonsterSpellFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "MonsterSpell", "", MonsterSpellFunctions::luaCreateMonsterSpell); + + Lua::registerMethod(L, "MonsterSpell", "setType", MonsterSpellFunctions::luaMonsterSpellSetType); + Lua::registerMethod(L, "MonsterSpell", "setScriptName", MonsterSpellFunctions::luaMonsterSpellSetScriptName); + Lua::registerMethod(L, "MonsterSpell", "setChance", MonsterSpellFunctions::luaMonsterSpellSetChance); + Lua::registerMethod(L, "MonsterSpell", "setInterval", MonsterSpellFunctions::luaMonsterSpellSetInterval); + Lua::registerMethod(L, "MonsterSpell", "setRange", MonsterSpellFunctions::luaMonsterSpellSetRange); + Lua::registerMethod(L, "MonsterSpell", "setCombatValue", MonsterSpellFunctions::luaMonsterSpellSetCombatValue); + Lua::registerMethod(L, "MonsterSpell", "setCombatType", MonsterSpellFunctions::luaMonsterSpellSetCombatType); + Lua::registerMethod(L, "MonsterSpell", "setAttackValue", MonsterSpellFunctions::luaMonsterSpellSetAttackValue); + Lua::registerMethod(L, "MonsterSpell", "setNeedTarget", MonsterSpellFunctions::luaMonsterSpellSetNeedTarget); + Lua::registerMethod(L, "MonsterSpell", "setCombatLength", MonsterSpellFunctions::luaMonsterSpellSetCombatLength); + Lua::registerMethod(L, "MonsterSpell", "setCombatSpread", MonsterSpellFunctions::luaMonsterSpellSetCombatSpread); + Lua::registerMethod(L, "MonsterSpell", "setCombatRadius", MonsterSpellFunctions::luaMonsterSpellSetCombatRadius); + Lua::registerMethod(L, "MonsterSpell", "setConditionType", MonsterSpellFunctions::luaMonsterSpellSetConditionType); + Lua::registerMethod(L, "MonsterSpell", "setConditionDamage", MonsterSpellFunctions::luaMonsterSpellSetConditionDamage); + Lua::registerMethod(L, "MonsterSpell", "setConditionSpeedChange", MonsterSpellFunctions::luaMonsterSpellSetConditionSpeedChange); + Lua::registerMethod(L, "MonsterSpell", "setConditionDuration", MonsterSpellFunctions::luaMonsterSpellSetConditionDuration); + Lua::registerMethod(L, "MonsterSpell", "setConditionTickInterval", MonsterSpellFunctions::luaMonsterSpellSetConditionTickInterval); + Lua::registerMethod(L, "MonsterSpell", "setCombatShootEffect", MonsterSpellFunctions::luaMonsterSpellSetCombatShootEffect); + Lua::registerMethod(L, "MonsterSpell", "setCombatEffect", MonsterSpellFunctions::luaMonsterSpellSetCombatEffect); + Lua::registerMethod(L, "MonsterSpell", "setOutfitMonster", MonsterSpellFunctions::luaMonsterSpellSetOutfitMonster); + Lua::registerMethod(L, "MonsterSpell", "setOutfitItem", MonsterSpellFunctions::luaMonsterSpellSetOutfitItem); + Lua::registerMethod(L, "MonsterSpell", "castSound", MonsterSpellFunctions::luaMonsterSpellCastSound); + Lua::registerMethod(L, "MonsterSpell", "impactSound", MonsterSpellFunctions::luaMonsterSpellImpactSound); +} int MonsterSpellFunctions::luaCreateMonsterSpell(lua_State* L) { const auto spell = std::make_shared(); - pushUserdata(L, spell); - setMetatable(L, -1, "MonsterSpell"); + Lua::pushUserdata(L, spell); + Lua::setMetatable(L, -1, "MonsterSpell"); return 1; } int MonsterSpellFunctions::luaMonsterSpellSetType(lua_State* L) { // monsterSpell:setType(type) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->name = getString(L, 2); - pushBoolean(L, true); + spell->name = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -32,10 +61,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetType(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetScriptName(lua_State* L) { // monsterSpell:setScriptName(name) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->scriptName = getString(L, 2); - pushBoolean(L, true); + spell->scriptName = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -44,10 +73,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetScriptName(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetChance(lua_State* L) { // monsterSpell:setChance(chance) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->chance = getNumber(L, 2); - pushBoolean(L, true); + spell->chance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -56,10 +85,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetChance(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetInterval(lua_State* L) { // monsterSpell:setInterval(interval) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->interval = getNumber(L, 2); - pushBoolean(L, true); + spell->interval = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -68,10 +97,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetInterval(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetRange(lua_State* L) { // monsterSpell:setRange(range) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->range = getNumber(L, 2); - pushBoolean(L, true); + spell->range = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -80,11 +109,11 @@ int MonsterSpellFunctions::luaMonsterSpellSetRange(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatValue(lua_State* L) { // monsterSpell:setCombatValue(min, max) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->minCombatValue = getNumber(L, 2); - spell->maxCombatValue = getNumber(L, 3); - pushBoolean(L, true); + spell->minCombatValue = Lua::getNumber(L, 2); + spell->maxCombatValue = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -93,10 +122,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatValue(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatType(lua_State* L) { // monsterSpell:setCombatType(combatType_t) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->combatType = getNumber(L, 2); - pushBoolean(L, true); + spell->combatType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -105,11 +134,11 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatType(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetAttackValue(lua_State* L) { // monsterSpell:setAttackValue(attack, skill) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->attack = getNumber(L, 2); - spell->skill = getNumber(L, 3); - pushBoolean(L, true); + spell->attack = Lua::getNumber(L, 2); + spell->skill = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -118,10 +147,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetAttackValue(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetNeedTarget(lua_State* L) { // monsterSpell:setNeedTarget(bool) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->needTarget = getBoolean(L, 2); - pushBoolean(L, true); + spell->needTarget = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -130,10 +159,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetNeedTarget(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatLength(lua_State* L) { // monsterSpell:setCombatLength(length) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->length = getNumber(L, 2); - pushBoolean(L, true); + spell->length = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -142,10 +171,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatLength(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatSpread(lua_State* L) { // monsterSpell:setCombatSpread(spread) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->spread = getNumber(L, 2); - pushBoolean(L, true); + spell->spread = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -154,10 +183,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatSpread(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatRadius(lua_State* L) { // monsterSpell:setCombatRadius(radius) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->radius = getNumber(L, 2); - pushBoolean(L, true); + spell->radius = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -166,18 +195,18 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatRadius(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetConditionType(lua_State* L) { // monsterSpell:setConditionType(type) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - auto conditionType = getNumber(L, 2); + auto conditionType = Lua::getNumber(L, 2); if (conditionType == 254) { g_logger().error("[{}] trying to register condition type none for monster: {}", __FUNCTION__, spell->name); - reportErrorFunc(fmt::format("trying to register condition type none for monster: {}", spell->name)); - pushBoolean(L, false); + Lua::reportErrorFunc(fmt::format("trying to register condition type none for monster: {}", spell->name)); + Lua::pushBoolean(L, false); return 1; } spell->conditionType = static_cast(conditionType); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -186,12 +215,12 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionType(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetConditionDamage(lua_State* L) { // monsterSpell:setConditionDamage(min, max, start) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->conditionMinDamage = getNumber(L, 2); - spell->conditionMaxDamage = getNumber(L, 3); - spell->conditionStartDamage = getNumber(L, 4); - pushBoolean(L, true); + spell->conditionMinDamage = Lua::getNumber(L, 2); + spell->conditionMaxDamage = Lua::getNumber(L, 3); + spell->conditionStartDamage = Lua::getNumber(L, 4); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -200,10 +229,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionDamage(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetConditionSpeedChange(lua_State* L) { // monsterSpell:setConditionSpeedChange(speed) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->speedChange = getNumber(L, 2); - pushBoolean(L, true); + spell->speedChange = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -212,10 +241,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionSpeedChange(lua_State* L) int MonsterSpellFunctions::luaMonsterSpellSetConditionDuration(lua_State* L) { // monsterSpell:setConditionDuration(duration) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->duration = getNumber(L, 2); - pushBoolean(L, true); + spell->duration = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -224,10 +253,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionDuration(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetConditionTickInterval(lua_State* L) { // monsterSpell:setConditionTickInterval(interval) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->tickInterval = getNumber(L, 2); - pushBoolean(L, true); + spell->tickInterval = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -236,10 +265,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetConditionTickInterval(lua_State* L) int MonsterSpellFunctions::luaMonsterSpellSetCombatShootEffect(lua_State* L) { // monsterSpell:setCombatShootEffect(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->shoot = getNumber(L, 2); - pushBoolean(L, true); + spell->shoot = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -248,10 +277,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatShootEffect(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetCombatEffect(lua_State* L) { // monsterSpell:setCombatEffect(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->effect = getNumber(L, 2); - pushBoolean(L, true); + spell->effect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -260,10 +289,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetCombatEffect(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetOutfitMonster(lua_State* L) { // monsterSpell:setOutfitMonster(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->outfitMonster = getString(L, 2); - pushBoolean(L, true); + spell->outfitMonster = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -272,10 +301,10 @@ int MonsterSpellFunctions::luaMonsterSpellSetOutfitMonster(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellSetOutfitItem(lua_State* L) { // monsterSpell:setOutfitItem(effect) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (spell) { - spell->outfitItem = getNumber(L, 2); - pushBoolean(L, true); + spell->outfitItem = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -284,24 +313,24 @@ int MonsterSpellFunctions::luaMonsterSpellSetOutfitItem(lua_State* L) { int MonsterSpellFunctions::luaMonsterSpellCastSound(lua_State* L) { // get: monsterSpell:castSound() set: monsterSpell:castSound(sound) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(spell->soundCastEffect)); } else { - spell->soundCastEffect = getNumber(L, 2); - pushBoolean(L, true); + spell->soundCastEffect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int MonsterSpellFunctions::luaMonsterSpellImpactSound(lua_State* L) { // get: monsterSpell:impactSound() set: monsterSpell:impactSound(sound) - const auto &spell = getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 1); if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(spell->soundImpactEffect)); } else { - spell->soundImpactEffect = getNumber(L, 2); - pushBoolean(L, true); + spell->soundImpactEffect = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } diff --git a/src/lua/functions/creatures/monster/monster_spell_functions.hpp b/src/lua/functions/creatures/monster/monster_spell_functions.hpp index e44c5e53470..4816e899d9a 100644 --- a/src/lua/functions/creatures/monster/monster_spell_functions.hpp +++ b/src/lua/functions/creatures/monster/monster_spell_functions.hpp @@ -9,43 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class MonsterSpellFunctions final : LuaScriptInterface { +class MonsterSpellFunctions { public: - explicit MonsterSpellFunctions(lua_State* L) : - LuaScriptInterface("MonsterSpellFunctions") { - init(L); - } - ~MonsterSpellFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "MonsterSpell", "", MonsterSpellFunctions::luaCreateMonsterSpell); - - registerMethod(L, "MonsterSpell", "setType", MonsterSpellFunctions::luaMonsterSpellSetType); - registerMethod(L, "MonsterSpell", "setScriptName", MonsterSpellFunctions::luaMonsterSpellSetScriptName); - registerMethod(L, "MonsterSpell", "setChance", MonsterSpellFunctions::luaMonsterSpellSetChance); - registerMethod(L, "MonsterSpell", "setInterval", MonsterSpellFunctions::luaMonsterSpellSetInterval); - registerMethod(L, "MonsterSpell", "setRange", MonsterSpellFunctions::luaMonsterSpellSetRange); - registerMethod(L, "MonsterSpell", "setCombatValue", MonsterSpellFunctions::luaMonsterSpellSetCombatValue); - registerMethod(L, "MonsterSpell", "setCombatType", MonsterSpellFunctions::luaMonsterSpellSetCombatType); - registerMethod(L, "MonsterSpell", "setAttackValue", MonsterSpellFunctions::luaMonsterSpellSetAttackValue); - registerMethod(L, "MonsterSpell", "setNeedTarget", MonsterSpellFunctions::luaMonsterSpellSetNeedTarget); - registerMethod(L, "MonsterSpell", "setCombatLength", MonsterSpellFunctions::luaMonsterSpellSetCombatLength); - registerMethod(L, "MonsterSpell", "setCombatSpread", MonsterSpellFunctions::luaMonsterSpellSetCombatSpread); - registerMethod(L, "MonsterSpell", "setCombatRadius", MonsterSpellFunctions::luaMonsterSpellSetCombatRadius); - registerMethod(L, "MonsterSpell", "setConditionType", MonsterSpellFunctions::luaMonsterSpellSetConditionType); - registerMethod(L, "MonsterSpell", "setConditionDamage", MonsterSpellFunctions::luaMonsterSpellSetConditionDamage); - registerMethod(L, "MonsterSpell", "setConditionSpeedChange", MonsterSpellFunctions::luaMonsterSpellSetConditionSpeedChange); - registerMethod(L, "MonsterSpell", "setConditionDuration", MonsterSpellFunctions::luaMonsterSpellSetConditionDuration); - registerMethod(L, "MonsterSpell", "setConditionTickInterval", MonsterSpellFunctions::luaMonsterSpellSetConditionTickInterval); - registerMethod(L, "MonsterSpell", "setCombatShootEffect", MonsterSpellFunctions::luaMonsterSpellSetCombatShootEffect); - registerMethod(L, "MonsterSpell", "setCombatEffect", MonsterSpellFunctions::luaMonsterSpellSetCombatEffect); - registerMethod(L, "MonsterSpell", "setOutfitMonster", MonsterSpellFunctions::luaMonsterSpellSetOutfitMonster); - registerMethod(L, "MonsterSpell", "setOutfitItem", MonsterSpellFunctions::luaMonsterSpellSetOutfitItem); - registerMethod(L, "MonsterSpell", "castSound", MonsterSpellFunctions::luaMonsterSpellCastSound); - registerMethod(L, "MonsterSpell", "impactSound", MonsterSpellFunctions::luaMonsterSpellImpactSound); - } + static void init(lua_State* L); private: static int luaCreateMonsterSpell(lua_State* L); diff --git a/src/lua/functions/creatures/monster/monster_type_functions.cpp b/src/lua/functions/creatures/monster/monster_type_functions.cpp index 3df28d12738..07ce44b626c 100644 --- a/src/lua/functions/creatures/monster/monster_type_functions.cpp +++ b/src/lua/functions/creatures/monster/monster_type_functions.cpp @@ -17,6 +17,141 @@ #include "io/io_bosstiary.hpp" #include "lua/scripts/scripts.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void MonsterTypeFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "MonsterType", "", MonsterTypeFunctions::luaMonsterTypeCreate); + Lua::registerMetaMethod(L, "MonsterType", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "MonsterType", "isAttackable", MonsterTypeFunctions::luaMonsterTypeIsAttackable); + Lua::registerMethod(L, "MonsterType", "isConvinceable", MonsterTypeFunctions::luaMonsterTypeIsConvinceable); + Lua::registerMethod(L, "MonsterType", "isSummonable", MonsterTypeFunctions::luaMonsterTypeIsSummonable); + Lua::registerMethod(L, "MonsterType", "isPreyable", MonsterTypeFunctions::luaMonsterTypeIsPreyable); + Lua::registerMethod(L, "MonsterType", "isPreyExclusive", MonsterTypeFunctions::luaMonsterTypeIsPreyExclusive); + Lua::registerMethod(L, "MonsterType", "isIllusionable", MonsterTypeFunctions::luaMonsterTypeIsIllusionable); + Lua::registerMethod(L, "MonsterType", "isHostile", MonsterTypeFunctions::luaMonsterTypeIsHostile); + Lua::registerMethod(L, "MonsterType", "isPushable", MonsterTypeFunctions::luaMonsterTypeIsPushable); + Lua::registerMethod(L, "MonsterType", "isHealthHidden", MonsterTypeFunctions::luaMonsterTypeIsHealthHidden); + Lua::registerMethod(L, "MonsterType", "isBlockable", MonsterTypeFunctions::luaMonsterTypeIsBlockable); + Lua::registerMethod(L, "MonsterType", "isForgeCreature", MonsterTypeFunctions::luaMonsterTypeIsForgeCreature); + + Lua::registerMethod(L, "MonsterType", "familiar", MonsterTypeFunctions::luaMonsterTypeFamiliar); + Lua::registerMethod(L, "MonsterType", "isRewardBoss", MonsterTypeFunctions::luaMonsterTypeIsRewardBoss); + + Lua::registerMethod(L, "MonsterType", "canSpawn", MonsterTypeFunctions::luaMonsterTypeCanSpawn); + + Lua::registerMethod(L, "MonsterType", "canPushItems", MonsterTypeFunctions::luaMonsterTypeCanPushItems); + Lua::registerMethod(L, "MonsterType", "canPushCreatures", MonsterTypeFunctions::luaMonsterTypeCanPushCreatures); + + Lua::registerMethod(L, "MonsterType", "critChance", MonsterTypeFunctions::luaMonsterTypeCritChance); + + Lua::registerMethod(L, "MonsterType", "name", MonsterTypeFunctions::luaMonsterTypeName); + + Lua::registerMethod(L, "MonsterType", "nameDescription", MonsterTypeFunctions::luaMonsterTypeNameDescription); + + Lua::registerMethod(L, "MonsterType", "getCorpseId", MonsterTypeFunctions::luaMonsterTypegetCorpseId); + + Lua::registerMethod(L, "MonsterType", "health", MonsterTypeFunctions::luaMonsterTypeHealth); + Lua::registerMethod(L, "MonsterType", "maxHealth", MonsterTypeFunctions::luaMonsterTypeMaxHealth); + Lua::registerMethod(L, "MonsterType", "runHealth", MonsterTypeFunctions::luaMonsterTypeRunHealth); + Lua::registerMethod(L, "MonsterType", "experience", MonsterTypeFunctions::luaMonsterTypeExperience); + + Lua::registerMethod(L, "MonsterType", "faction", MonsterTypeFunctions::luaMonsterTypeFaction); + Lua::registerMethod(L, "MonsterType", "enemyFactions", MonsterTypeFunctions::luaMonsterTypeEnemyFactions); + Lua::registerMethod(L, "MonsterType", "targetPreferPlayer", MonsterTypeFunctions::luaMonsterTypeTargetPreferPlayer); + Lua::registerMethod(L, "MonsterType", "targetPreferMaster", MonsterTypeFunctions::luaMonsterTypeTargetPreferMaster); + + Lua::registerMethod(L, "MonsterType", "raceId", MonsterTypeFunctions::luaMonsterTypeRaceid); + Lua::registerMethod(L, "MonsterType", "Bestiaryclass", MonsterTypeFunctions::luaMonsterTypeBestiaryclass); + Lua::registerMethod(L, "MonsterType", "BestiaryOccurrence", MonsterTypeFunctions::luaMonsterTypeBestiaryOccurrence); + Lua::registerMethod(L, "MonsterType", "BestiaryLocations", MonsterTypeFunctions::luaMonsterTypeBestiaryLocations); + Lua::registerMethod(L, "MonsterType", "BestiaryStars", MonsterTypeFunctions::luaMonsterTypeBestiaryStars); + Lua::registerMethod(L, "MonsterType", "BestiaryCharmsPoints", MonsterTypeFunctions::luaMonsterTypeBestiaryCharmsPoints); + Lua::registerMethod(L, "MonsterType", "BestiarySecondUnlock", MonsterTypeFunctions::luaMonsterTypeBestiarySecondUnlock); + Lua::registerMethod(L, "MonsterType", "BestiaryFirstUnlock", MonsterTypeFunctions::luaMonsterTypeBestiaryFirstUnlock); + Lua::registerMethod(L, "MonsterType", "BestiarytoKill", MonsterTypeFunctions::luaMonsterTypeBestiarytoKill); + Lua::registerMethod(L, "MonsterType", "Bestiaryrace", MonsterTypeFunctions::luaMonsterTypeBestiaryrace); + + Lua::registerMethod(L, "MonsterType", "combatImmunities", MonsterTypeFunctions::luaMonsterTypeCombatImmunities); + Lua::registerMethod(L, "MonsterType", "conditionImmunities", MonsterTypeFunctions::luaMonsterTypeConditionImmunities); + + Lua::registerMethod(L, "MonsterType", "getAttackList", MonsterTypeFunctions::luaMonsterTypeGetAttackList); + Lua::registerMethod(L, "MonsterType", "addAttack", MonsterTypeFunctions::luaMonsterTypeAddAttack); + + Lua::registerMethod(L, "MonsterType", "getDefenseList", MonsterTypeFunctions::luaMonsterTypeGetDefenseList); + Lua::registerMethod(L, "MonsterType", "addDefense", MonsterTypeFunctions::luaMonsterTypeAddDefense); + + Lua::registerMethod(L, "MonsterType", "getTypeName", MonsterTypeFunctions::luaMonsterTypeGetTypeName); + + Lua::registerMethod(L, "MonsterType", "getElementList", MonsterTypeFunctions::luaMonsterTypeGetElementList); + Lua::registerMethod(L, "MonsterType", "addElement", MonsterTypeFunctions::luaMonsterTypeAddElement); + + Lua::registerMethod(L, "MonsterType", "addReflect", MonsterTypeFunctions::luaMonsterTypeAddReflect); + Lua::registerMethod(L, "MonsterType", "addHealing", MonsterTypeFunctions::luaMonsterTypeAddHealing); + + Lua::registerMethod(L, "MonsterType", "getVoices", MonsterTypeFunctions::luaMonsterTypeGetVoices); + Lua::registerMethod(L, "MonsterType", "addVoice", MonsterTypeFunctions::luaMonsterTypeAddVoice); + + Lua::registerMethod(L, "MonsterType", "getLoot", MonsterTypeFunctions::luaMonsterTypeGetLoot); + Lua::registerMethod(L, "MonsterType", "addLoot", MonsterTypeFunctions::luaMonsterTypeAddLoot); + + Lua::registerMethod(L, "MonsterType", "getCreatureEvents", MonsterTypeFunctions::luaMonsterTypeGetCreatureEvents); + Lua::registerMethod(L, "MonsterType", "registerEvent", MonsterTypeFunctions::luaMonsterTypeRegisterEvent); + + Lua::registerMethod(L, "MonsterType", "eventType", MonsterTypeFunctions::luaMonsterTypeEventType); + Lua::registerMethod(L, "MonsterType", "onThink", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onAppear", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onDisappear", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onMove", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onSay", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onPlayerAttack", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + Lua::registerMethod(L, "MonsterType", "onSpawn", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); + + Lua::registerMethod(L, "MonsterType", "getSummonList", MonsterTypeFunctions::luaMonsterTypeGetSummonList); + Lua::registerMethod(L, "MonsterType", "addSummon", MonsterTypeFunctions::luaMonsterTypeAddSummon); + + Lua::registerMethod(L, "MonsterType", "maxSummons", MonsterTypeFunctions::luaMonsterTypeMaxSummons); + + Lua::registerMethod(L, "MonsterType", "armor", MonsterTypeFunctions::luaMonsterTypeArmor); + Lua::registerMethod(L, "MonsterType", "mitigation", MonsterTypeFunctions::luaMonsterTypeMitigation); + Lua::registerMethod(L, "MonsterType", "defense", MonsterTypeFunctions::luaMonsterTypeDefense); + Lua::registerMethod(L, "MonsterType", "outfit", MonsterTypeFunctions::luaMonsterTypeOutfit); + Lua::registerMethod(L, "MonsterType", "race", MonsterTypeFunctions::luaMonsterTypeRace); + Lua::registerMethod(L, "MonsterType", "corpseId", MonsterTypeFunctions::luaMonsterTypeCorpseId); + Lua::registerMethod(L, "MonsterType", "manaCost", MonsterTypeFunctions::luaMonsterTypeManaCost); + Lua::registerMethod(L, "MonsterType", "baseSpeed", MonsterTypeFunctions::luaMonsterTypeBaseSpeed); + Lua::registerMethod(L, "MonsterType", "light", MonsterTypeFunctions::luaMonsterTypeLight); + + Lua::registerMethod(L, "MonsterType", "staticAttackChance", MonsterTypeFunctions::luaMonsterTypeStaticAttackChance); + Lua::registerMethod(L, "MonsterType", "targetDistance", MonsterTypeFunctions::luaMonsterTypeTargetDistance); + Lua::registerMethod(L, "MonsterType", "yellChance", MonsterTypeFunctions::luaMonsterTypeYellChance); + Lua::registerMethod(L, "MonsterType", "yellSpeedTicks", MonsterTypeFunctions::luaMonsterTypeYellSpeedTicks); + Lua::registerMethod(L, "MonsterType", "changeTargetChance", MonsterTypeFunctions::luaMonsterTypeChangeTargetChance); + Lua::registerMethod(L, "MonsterType", "changeTargetSpeed", MonsterTypeFunctions::luaMonsterTypeChangeTargetSpeed); + + Lua::registerMethod(L, "MonsterType", "canWalkOnEnergy", MonsterTypeFunctions::luaMonsterTypeCanWalkOnEnergy); + Lua::registerMethod(L, "MonsterType", "canWalkOnFire", MonsterTypeFunctions::luaMonsterTypeCanWalkOnFire); + Lua::registerMethod(L, "MonsterType", "canWalkOnPoison", MonsterTypeFunctions::luaMonsterTypeCanWalkOnPoison); + + Lua::registerMethod(L, "MonsterType", "strategiesTargetNearest", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetNearest); + Lua::registerMethod(L, "MonsterType", "strategiesTargetHealth", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetHealth); + Lua::registerMethod(L, "MonsterType", "strategiesTargetDamage", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetDamage); + Lua::registerMethod(L, "MonsterType", "strategiesTargetRandom", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetRandom); + + Lua::registerMethod(L, "MonsterType", "respawnTypePeriod", MonsterTypeFunctions::luaMonsterTypeRespawnTypePeriod); + Lua::registerMethod(L, "MonsterType", "respawnTypeIsUnderground", MonsterTypeFunctions::luaMonsterTypeRespawnTypeIsUnderground); + + Lua::registerMethod(L, "MonsterType", "bossRace", MonsterTypeFunctions::luaMonsterTypeBossRace); + Lua::registerMethod(L, "MonsterType", "bossRaceId", MonsterTypeFunctions::luaMonsterTypeBossRaceId); + + Lua::registerMethod(L, "MonsterType", "soundChance", MonsterTypeFunctions::luaMonsterTypeSoundChance); + Lua::registerMethod(L, "MonsterType", "soundSpeedTicks", MonsterTypeFunctions::luaMonsterTypeSoundSpeedTicks); + Lua::registerMethod(L, "MonsterType", "addSound", MonsterTypeFunctions::luaMonsterTypeAddSound); + Lua::registerMethod(L, "MonsterType", "getSounds", MonsterTypeFunctions::luaMonsterTypeGetSounds); + Lua::registerMethod(L, "MonsterType", "deathSound", MonsterTypeFunctions::luaMonsterTypedeathSound); + + Lua::registerMethod(L, "MonsterType", "variant", MonsterTypeFunctions::luaMonsterTypeVariant); +} void MonsterTypeFunctions::createMonsterTypeLootLuaTable(lua_State* L, const std::vector &lootList) { lua_createtable(L, lootList.size(), 0); @@ -25,14 +160,14 @@ void MonsterTypeFunctions::createMonsterTypeLootLuaTable(lua_State* L, const std for (const auto &lootBlock : lootList) { lua_createtable(L, 0, 8); - setField(L, "itemId", lootBlock.id); - setField(L, "chance", lootBlock.chance); - setField(L, "subType", lootBlock.subType); - setField(L, "maxCount", lootBlock.countmax); - setField(L, "minCount", lootBlock.countmin); - setField(L, "actionId", lootBlock.actionId); - setField(L, "text", lootBlock.text); - pushBoolean(L, lootBlock.unique); + Lua::setField(L, "itemId", lootBlock.id); + Lua::setField(L, "chance", lootBlock.chance); + Lua::setField(L, "subType", lootBlock.subType); + Lua::setField(L, "maxCount", lootBlock.countmax); + Lua::setField(L, "minCount", lootBlock.countmin); + Lua::setField(L, "actionId", lootBlock.actionId); + Lua::setField(L, "text", lootBlock.text); + Lua::pushBoolean(L, lootBlock.unique); lua_setfield(L, -2, "unique"); createMonsterTypeLootLuaTable(L, lootBlock.childLoot); @@ -45,15 +180,15 @@ void MonsterTypeFunctions::createMonsterTypeLootLuaTable(lua_State* L, const std int MonsterTypeFunctions::luaMonsterTypeCreate(lua_State* L) { // MonsterType(name or raceid) std::shared_ptr monsterType; - if (isNumber(L, 2)) { - monsterType = g_monsters().getMonsterTypeByRaceId(getNumber(L, 2)); + if (Lua::isNumber(L, 2)) { + monsterType = g_monsters().getMonsterTypeByRaceId(Lua::getNumber(L, 2)); } else { - monsterType = g_monsters().getMonsterType(getString(L, 2)); + monsterType = g_monsters().getMonsterType(Lua::getString(L, 2)); } if (monsterType) { - pushUserdata(L, monsterType); - setMetatable(L, -1, "MonsterType"); + Lua::pushUserdata(L, monsterType); + Lua::setMetatable(L, -1, "MonsterType"); } else { lua_pushnil(L); } @@ -62,13 +197,13 @@ int MonsterTypeFunctions::luaMonsterTypeCreate(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsAttackable(lua_State* L) { // get: monsterType:isAttackable() set: monsterType:isAttackable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isAttackable); + Lua::pushBoolean(L, monsterType->info.isAttackable); } else { - monsterType->info.isAttackable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isAttackable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -78,13 +213,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsAttackable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsConvinceable(lua_State* L) { // get: monsterType:isConvinceable() set: monsterType:isConvinceable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isConvinceable); + Lua::pushBoolean(L, monsterType->info.isConvinceable); } else { - monsterType->info.isConvinceable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isConvinceable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -94,13 +229,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsConvinceable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsSummonable(lua_State* L) { // get: monsterType:isSummonable() set: monsterType:isSummonable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isSummonable); + Lua::pushBoolean(L, monsterType->info.isSummonable); } else { - monsterType->info.isSummonable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isSummonable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -110,13 +245,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsSummonable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsPreyExclusive(lua_State* L) { // get: monsterType:isPreyExclusive() set: monsterType:isPreyExclusive(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isPreyExclusive); + Lua::pushBoolean(L, monsterType->info.isPreyExclusive); } else { - monsterType->info.isPreyExclusive = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isPreyExclusive = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -126,13 +261,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsPreyExclusive(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsPreyable(lua_State* L) { // get: monsterType:isPreyable() set: monsterType:isPreyable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isPreyable); + Lua::pushBoolean(L, monsterType->info.isPreyable); } else { - monsterType->info.isPreyable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isPreyable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -142,13 +277,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsPreyable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsIllusionable(lua_State* L) { // get: monsterType:isIllusionable() set: monsterType:isIllusionable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isIllusionable); + Lua::pushBoolean(L, monsterType->info.isIllusionable); } else { - monsterType->info.isIllusionable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isIllusionable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -158,13 +293,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsIllusionable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsHostile(lua_State* L) { // get: monsterType:isHostile() set: monsterType:isHostile(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isHostile); + Lua::pushBoolean(L, monsterType->info.isHostile); } else { - monsterType->info.isHostile = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isHostile = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -174,13 +309,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsHostile(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeFamiliar(lua_State* L) { // get: monsterType:familiar() set: monsterType:familiar(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isFamiliar); + Lua::pushBoolean(L, monsterType->info.isFamiliar); } else { - monsterType->info.isFamiliar = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isFamiliar = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -190,13 +325,13 @@ int MonsterTypeFunctions::luaMonsterTypeFamiliar(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsRewardBoss(lua_State* L) { // get: monsterType:isRewardBoss() set: monsterType:isRewardBoss(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isRewardBoss); + Lua::pushBoolean(L, monsterType->info.isRewardBoss); } else { - monsterType->info.isRewardBoss = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isRewardBoss = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -206,13 +341,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsRewardBoss(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsPushable(lua_State* L) { // get: monsterType:isPushable() set: monsterType:isPushable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.pushable); + Lua::pushBoolean(L, monsterType->info.pushable); } else { - monsterType->info.pushable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.pushable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -222,13 +357,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsPushable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsHealthHidden(lua_State* L) { // get: monsterType:isHealthHidden() set: monsterType:isHealthHidden(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.hiddenHealth); + Lua::pushBoolean(L, monsterType->info.hiddenHealth); } else { - monsterType->info.hiddenHealth = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.hiddenHealth = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -238,13 +373,13 @@ int MonsterTypeFunctions::luaMonsterTypeIsHealthHidden(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsBlockable(lua_State* L) { // get: monsterType:isBlockable() set: monsterType:isBlockable(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isBlockable); + Lua::pushBoolean(L, monsterType->info.isBlockable); } else { - monsterType->info.isBlockable = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isBlockable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -254,28 +389,28 @@ int MonsterTypeFunctions::luaMonsterTypeIsBlockable(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeIsForgeCreature(lua_State* L) { // get: monsterType:isForgeCreature() set: monsterType:isForgeCreature(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 0; } if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.isForgeCreature); + Lua::pushBoolean(L, monsterType->info.isForgeCreature); } else { - monsterType->info.isForgeCreature = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.isForgeCreature = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } return 1; } int MonsterTypeFunctions::luaMonsterTypeCanSpawn(lua_State* L) { // monsterType:canSpawn(pos) - const auto &monsterType = getUserdataShared(L, 1); - const Position &position = getPosition(L, 2); + const auto &monsterType = Lua::getUserdataShared(L, 1); + const Position &position = Lua::getPosition(L, 2); if (monsterType) { - pushBoolean(L, monsterType->canSpawn(position)); + Lua::pushBoolean(L, monsterType->canSpawn(position)); } else { lua_pushnil(L); } @@ -284,13 +419,13 @@ int MonsterTypeFunctions::luaMonsterTypeCanSpawn(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCanPushItems(lua_State* L) { // get: monsterType:canPushItems() set: monsterType:canPushItems(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.canPushItems); + Lua::pushBoolean(L, monsterType->info.canPushItems); } else { - monsterType->info.canPushItems = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.canPushItems = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -300,13 +435,13 @@ int MonsterTypeFunctions::luaMonsterTypeCanPushItems(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCanPushCreatures(lua_State* L) { // get: monsterType:canPushCreatures() set: monsterType:canPushCreatures(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.canPushCreatures); + Lua::pushBoolean(L, monsterType->info.canPushCreatures); } else { - monsterType->info.canPushCreatures = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.canPushCreatures = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -316,10 +451,10 @@ int MonsterTypeFunctions::luaMonsterTypeCanPushCreatures(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCritChance(lua_State* L) { // get: monsterType:critChance() set: monsterType:critChance(int) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 2) { - monsterType->info.critChance = getNumber(L, 2); + monsterType->info.critChance = Lua::getNumber(L, 2); } lua_pushnumber(L, monsterType->info.critChance); } else { @@ -330,13 +465,13 @@ int MonsterTypeFunctions::luaMonsterTypeCritChance(lua_State* L) { int32_t MonsterTypeFunctions::luaMonsterTypeName(lua_State* L) { // get: monsterType:name() set: monsterType:name(name) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushString(L, monsterType->name); + Lua::pushString(L, monsterType->name); } else { - monsterType->name = getString(L, 2); - pushBoolean(L, true); + monsterType->name = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -346,13 +481,13 @@ int32_t MonsterTypeFunctions::luaMonsterTypeName(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeNameDescription(lua_State* L) { // get: monsterType:nameDescription() set: monsterType:nameDescription(desc) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushString(L, monsterType->nameDescription); + Lua::pushString(L, monsterType->nameDescription); } else { - monsterType->nameDescription = getString(L, 2); - pushBoolean(L, true); + monsterType->nameDescription = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -362,7 +497,7 @@ int MonsterTypeFunctions::luaMonsterTypeNameDescription(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypegetCorpseId(lua_State* L) { // monsterType:getCorpseId() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { lua_pushnumber(L, monsterType->info.lookcorpse); } else { @@ -373,13 +508,13 @@ int MonsterTypeFunctions::luaMonsterTypegetCorpseId(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeHealth(lua_State* L) { // get: monsterType:health() set: monsterType:health(health) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.health); } else { - monsterType->info.health = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.health = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -389,13 +524,13 @@ int MonsterTypeFunctions::luaMonsterTypeHealth(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeMaxHealth(lua_State* L) { // get: monsterType:maxHealth() set: monsterType:maxHealth(health) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.healthMax); } else { - monsterType->info.healthMax = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.healthMax = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -405,13 +540,13 @@ int MonsterTypeFunctions::luaMonsterTypeMaxHealth(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRunHealth(lua_State* L) { // get: monsterType:runHealth() set: monsterType:runHealth(health) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.runAwayHealth); } else { - monsterType->info.runAwayHealth = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.runAwayHealth = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -421,13 +556,13 @@ int MonsterTypeFunctions::luaMonsterTypeRunHealth(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeExperience(lua_State* L) { // get: monsterType:experience() set: monsterType:experience(exp) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.experience); } else { - monsterType->info.experience = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.experience = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -437,13 +572,13 @@ int MonsterTypeFunctions::luaMonsterTypeExperience(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeFaction(lua_State* L) { // get: monsterType:faction() set: monsterType:faction(faction) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.faction); } else { - monsterType->info.faction = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.faction = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -453,7 +588,7 @@ int MonsterTypeFunctions::luaMonsterTypeFaction(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeEnemyFactions(lua_State* L) { // get: monsterType:enemyFactions() set: monsterType:enemyFactions(enemyFaction) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_createtable(L, monsterType->info.enemyFactions.size(), 0); @@ -464,9 +599,9 @@ int MonsterTypeFunctions::luaMonsterTypeEnemyFactions(lua_State* L) { lua_rawseti(L, -2, ++index); } } else { - const Faction_t faction = getNumber(L, 2); + const Faction_t faction = Lua::getNumber(L, 2); monsterType->info.enemyFactions.insert(faction); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -476,13 +611,13 @@ int MonsterTypeFunctions::luaMonsterTypeEnemyFactions(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeTargetPreferPlayer(lua_State* L) { // get: monsterType:targetPreferPlayer() set: monsterType:targetPreferPlayer(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushboolean(L, monsterType->info.targetPreferPlayer); } else { - monsterType->info.targetPreferPlayer = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.targetPreferPlayer = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -492,13 +627,13 @@ int MonsterTypeFunctions::luaMonsterTypeTargetPreferPlayer(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeTargetPreferMaster(lua_State* L) { // get: monsterType:targetPreferMaster() set: monsterType:targetPreferMaster(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.faction); } else { - monsterType->info.targetPreferMaster = getBoolean(L, 2); - pushBoolean(L, true); + monsterType->info.targetPreferMaster = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -508,14 +643,14 @@ int MonsterTypeFunctions::luaMonsterTypeTargetPreferMaster(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRaceid(lua_State* L) { // get: monsterType:raceId() set: monsterType:raceId(id) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.raceid); } else { - monsterType->info.raceid = getNumber(L, 2); - g_game().addBestiaryList(getNumber(L, 2), monsterType->name); - pushBoolean(L, true); + monsterType->info.raceid = Lua::getNumber(L, 2); + g_game().addBestiaryList(Lua::getNumber(L, 2), monsterType->name); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -525,13 +660,13 @@ int MonsterTypeFunctions::luaMonsterTypeRaceid(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiarytoKill(lua_State* L) { // get: monsterType:BestiarytoKill() set: monsterType:BestiarytoKill(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryToUnlock); } else { - monsterType->info.bestiaryToUnlock = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryToUnlock = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -541,13 +676,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiarytoKill(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryFirstUnlock(lua_State* L) { // get: monsterType:BestiaryFirstUnlock() set: monsterType:BestiaryFirstUnlock(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryFirstUnlock); } else { - monsterType->info.bestiaryFirstUnlock = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryFirstUnlock = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -557,13 +692,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryFirstUnlock(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiarySecondUnlock(lua_State* L) { // get: monsterType:BestiarySecondUnlock() set: monsterType:BestiarySecondUnlock(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiarySecondUnlock); } else { - monsterType->info.bestiarySecondUnlock = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiarySecondUnlock = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -573,13 +708,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiarySecondUnlock(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryCharmsPoints(lua_State* L) { // get: monsterType:BestiaryCharmsPoints() set: monsterType:BestiaryCharmsPoints(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryCharmsPoints); } else { - monsterType->info.bestiaryCharmsPoints = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryCharmsPoints = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -589,13 +724,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryCharmsPoints(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryStars(lua_State* L) { // get: monsterType:BestiaryStars() set: monsterType:BestiaryStars(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryStars); } else { - monsterType->info.bestiaryStars = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryStars = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -605,13 +740,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryStars(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryOccurrence(lua_State* L) { // get: monsterType:BestiaryOccurrence() set: monsterType:BestiaryOccurrence(value) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryOccurrence); } else { - monsterType->info.bestiaryOccurrence = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryOccurrence = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -621,13 +756,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryOccurrence(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryLocations(lua_State* L) { // get: monsterType:BestiaryLocations() set: monsterType:BestiaryLocations(string) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushString(L, monsterType->info.bestiaryLocations); + Lua::pushString(L, monsterType->info.bestiaryLocations); } else { - monsterType->info.bestiaryLocations = getString(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryLocations = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -637,13 +772,13 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryLocations(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryclass(lua_State* L) { // get: monsterType:Bestiaryclass() set: monsterType:Bestiaryclass(string) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushString(L, monsterType->info.bestiaryClass); + Lua::pushString(L, monsterType->info.bestiaryClass); } else { - monsterType->info.bestiaryClass = getString(L, 2); - pushBoolean(L, true); + monsterType->info.bestiaryClass = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -653,14 +788,14 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryclass(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBestiaryrace(lua_State* L) { // get: monsterType:Bestiaryrace() set: monsterType:Bestiaryrace(raceid) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.bestiaryRace); } else { - const BestiaryType_t race = getNumber(L, 2); + const BestiaryType_t race = Lua::getNumber(L, 2); monsterType->info.bestiaryRace = race; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -670,10 +805,10 @@ int MonsterTypeFunctions::luaMonsterTypeBestiaryrace(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCombatImmunities(lua_State* L) { // get: monsterType:combatImmunities() set: monsterType:combatImmunities(immunity) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 1; } @@ -686,7 +821,7 @@ int MonsterTypeFunctions::luaMonsterTypeCombatImmunities(lua_State* L) { return 1; } - std::string immunity = getString(L, 2); + std::string immunity = Lua::getString(L, 2); CombatType_t combatType = COMBAT_NONE; if (immunity == "physical") { combatType = COMBAT_PHYSICALDAMAGE; @@ -720,16 +855,16 @@ int MonsterTypeFunctions::luaMonsterTypeCombatImmunities(lua_State* L) { } monsterType->info.m_damageImmunities.set(combatTypeToIndex(combatType), true); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MonsterTypeFunctions::luaMonsterTypeConditionImmunities(lua_State* L) { // get: monsterType:conditionImmunities() set: monsterType:conditionImmunities(immunity) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 1; } @@ -742,7 +877,7 @@ int MonsterTypeFunctions::luaMonsterTypeConditionImmunities(lua_State* L) { return 1; } - std::string immunity = getString(L, 2); + std::string immunity = Lua::getString(L, 2); ConditionType_t conditionType = CONDITION_NONE; if (immunity == "physical") { conditionType = CONDITION_BLEEDING; @@ -778,13 +913,13 @@ int MonsterTypeFunctions::luaMonsterTypeConditionImmunities(lua_State* L) { } monsterType->info.m_conditionImmunities[static_cast(conditionType)] = true; - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MonsterTypeFunctions::luaMonsterTypeGetAttackList(lua_State* L) { // monsterType:getAttackList() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -796,15 +931,15 @@ int MonsterTypeFunctions::luaMonsterTypeGetAttackList(lua_State* L) { for (const auto &spellBlock : monsterType->info.attackSpells) { lua_createtable(L, 0, 8); - setField(L, "chance", spellBlock.chance); - setField(L, "isCombatSpell", spellBlock.combatSpell ? 1 : 0); - setField(L, "isMelee", spellBlock.isMelee ? 1 : 0); - setField(L, "minCombatValue", spellBlock.minCombatValue); - setField(L, "maxCombatValue", spellBlock.maxCombatValue); - setField(L, "range", spellBlock.range); - setField(L, "speed", spellBlock.speed); + Lua::setField(L, "chance", spellBlock.chance); + Lua::setField(L, "isCombatSpell", spellBlock.combatSpell ? 1 : 0); + Lua::setField(L, "isMelee", spellBlock.isMelee ? 1 : 0); + Lua::setField(L, "minCombatValue", spellBlock.minCombatValue); + Lua::setField(L, "maxCombatValue", spellBlock.maxCombatValue); + Lua::setField(L, "range", spellBlock.range); + Lua::setField(L, "speed", spellBlock.speed); const auto combatSpell = std::static_pointer_cast(spellBlock.spell); - pushUserdata(L, combatSpell); + Lua::pushUserdata(L, combatSpell); lua_setfield(L, -2, "spell"); lua_rawseti(L, -2, ++index); @@ -814,9 +949,9 @@ int MonsterTypeFunctions::luaMonsterTypeGetAttackList(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddAttack(lua_State* L) { // monsterType:addAttack(monsterspell) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const auto &spell = getUserdataShared(L, 2); + const auto &spell = Lua::getUserdataShared(L, 2); if (spell) { spellBlock_t sb; if (g_monsters().deserializeSpell(spell, sb, monsterType->name)) { @@ -835,7 +970,7 @@ int MonsterTypeFunctions::luaMonsterTypeAddAttack(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetDefenseList(lua_State* L) { // monsterType:getDefenseList() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -847,15 +982,15 @@ int MonsterTypeFunctions::luaMonsterTypeGetDefenseList(lua_State* L) { for (const auto &spellBlock : monsterType->info.defenseSpells) { lua_createtable(L, 0, 8); - setField(L, "chance", spellBlock.chance); - setField(L, "isCombatSpell", spellBlock.combatSpell ? 1 : 0); - setField(L, "isMelee", spellBlock.isMelee ? 1 : 0); - setField(L, "minCombatValue", spellBlock.minCombatValue); - setField(L, "maxCombatValue", spellBlock.maxCombatValue); - setField(L, "range", spellBlock.range); - setField(L, "speed", spellBlock.speed); + Lua::setField(L, "chance", spellBlock.chance); + Lua::setField(L, "isCombatSpell", spellBlock.combatSpell ? 1 : 0); + Lua::setField(L, "isMelee", spellBlock.isMelee ? 1 : 0); + Lua::setField(L, "minCombatValue", spellBlock.minCombatValue); + Lua::setField(L, "maxCombatValue", spellBlock.maxCombatValue); + Lua::setField(L, "range", spellBlock.range); + Lua::setField(L, "speed", spellBlock.speed); const auto combatSpell = std::static_pointer_cast(spellBlock.spell); - pushUserdata(L, combatSpell); + Lua::pushUserdata(L, combatSpell); lua_setfield(L, -2, "spell"); lua_rawseti(L, -2, ++index); @@ -865,20 +1000,20 @@ int MonsterTypeFunctions::luaMonsterTypeGetDefenseList(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetTypeName(lua_State* L) { // monsterType:getTypeName() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { return 1; } - pushString(L, monsterType->typeName); + Lua::pushString(L, monsterType->typeName); return 1; } int MonsterTypeFunctions::luaMonsterTypeAddDefense(lua_State* L) { // monsterType:addDefense(monsterspell) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const auto &spell = getUserdataShared(L, 2); + const auto &spell = Lua::getUserdataShared(L, 2); if (spell) { spellBlock_t sb; if (g_monsters().deserializeSpell(spell, sb, monsterType->name)) { @@ -897,11 +1032,11 @@ int MonsterTypeFunctions::luaMonsterTypeAddDefense(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddElement(lua_State* L) { // monsterType:addElement(type, percent) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const CombatType_t element = getNumber(L, 2); - monsterType->info.elementMap[element] = getNumber(L, 3); - pushBoolean(L, true); + const CombatType_t element = Lua::getNumber(L, 2); + monsterType->info.elementMap[element] = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -910,11 +1045,11 @@ int MonsterTypeFunctions::luaMonsterTypeAddElement(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddReflect(lua_State* L) { // monsterType:addReflect(type, percent) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const CombatType_t element = getNumber(L, 2); - monsterType->info.reflectMap[element] = getNumber(L, 3); - pushBoolean(L, true); + const CombatType_t element = Lua::getNumber(L, 2); + monsterType->info.reflectMap[element] = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -923,11 +1058,11 @@ int MonsterTypeFunctions::luaMonsterTypeAddReflect(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddHealing(lua_State* L) { // monsterType:addHealing(type, percent) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const CombatType_t element = getNumber(L, 2); - monsterType->info.healingMap[element] = getNumber(L, 3); - pushBoolean(L, true); + const CombatType_t element = Lua::getNumber(L, 2); + monsterType->info.healingMap[element] = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -936,7 +1071,7 @@ int MonsterTypeFunctions::luaMonsterTypeAddHealing(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetElementList(lua_State* L) { // monsterType:getElementList() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -952,15 +1087,15 @@ int MonsterTypeFunctions::luaMonsterTypeGetElementList(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddVoice(lua_State* L) { // monsterType:addVoice(sentence, interval, chance, yell) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { voiceBlock_t voice; - voice.text = getString(L, 2); - monsterType->info.yellSpeedTicks = getNumber(L, 3); - monsterType->info.yellChance = getNumber(L, 4); - voice.yellText = getBoolean(L, 5); + voice.text = Lua::getString(L, 2); + monsterType->info.yellSpeedTicks = Lua::getNumber(L, 3); + monsterType->info.yellChance = Lua::getNumber(L, 4); + voice.yellText = Lua::getBoolean(L, 5); monsterType->info.voiceVector.push_back(voice); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -969,7 +1104,7 @@ int MonsterTypeFunctions::luaMonsterTypeAddVoice(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetVoices(lua_State* L) { // monsterType:getVoices() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -979,8 +1114,8 @@ int MonsterTypeFunctions::luaMonsterTypeGetVoices(lua_State* L) { lua_createtable(L, monsterType->info.voiceVector.size(), 0); for (const auto &voiceBlock : monsterType->info.voiceVector) { lua_createtable(L, 0, 2); - setField(L, "text", voiceBlock.text); - setField(L, "yellText", voiceBlock.yellText); + Lua::setField(L, "text", voiceBlock.text); + Lua::setField(L, "yellText", voiceBlock.yellText); lua_rawseti(L, -2, ++index); } return 1; @@ -988,7 +1123,7 @@ int MonsterTypeFunctions::luaMonsterTypeGetVoices(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetLoot(lua_State* L) { // monsterType:getLoot() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -1000,12 +1135,12 @@ int MonsterTypeFunctions::luaMonsterTypeGetLoot(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddLoot(lua_State* L) { // monsterType:addLoot(loot) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const auto &loot = getUserdataShared(L, 2); + const auto &loot = Lua::getUserdataShared(L, 2); if (loot) { monsterType->loadLoot(monsterType, loot->lootBlock); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1017,7 +1152,7 @@ int MonsterTypeFunctions::luaMonsterTypeAddLoot(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetCreatureEvents(lua_State* L) { // monsterType:getCreatureEvents() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -1026,7 +1161,7 @@ int MonsterTypeFunctions::luaMonsterTypeGetCreatureEvents(lua_State* L) { int index = 0; lua_createtable(L, monsterType->info.scripts.size(), 0); for (const std::string &creatureEvent : monsterType->info.scripts) { - pushString(L, creatureEvent); + Lua::pushString(L, creatureEvent); lua_rawseti(L, -2, ++index); } return 1; @@ -1034,16 +1169,16 @@ int MonsterTypeFunctions::luaMonsterTypeGetCreatureEvents(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRegisterEvent(lua_State* L) { // monsterType:registerEvent(name) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { - const auto eventName = getString(L, 2); + const auto eventName = Lua::getString(L, 2); monsterType->info.scripts.insert(eventName); for (const auto &[_, monster] : g_game().getMonsters()) { if (monster->getMonsterType() == monsterType) { monster->registerCreatureEvent(eventName); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1058,13 +1193,13 @@ int MonsterTypeFunctions::luaMonsterTypeEventOnCallback(lua_State* L) { // monsterType:onSay(callback) // monsterType:onPlayerAttack(callback) // monsterType:onSpawn(callback) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (monsterType->loadCallback(&g_scripts().getScriptInterface())) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else { lua_pushnil(L); } @@ -1073,10 +1208,10 @@ int MonsterTypeFunctions::luaMonsterTypeEventOnCallback(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeEventType(lua_State* L) { // monstertype:eventType(event) - const auto &mType = getUserdataShared(L, 1); + const auto &mType = Lua::getUserdataShared(L, 1); if (mType) { - mType->info.eventType = getNumber(L, 2); - pushBoolean(L, true); + mType->info.eventType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1085,7 +1220,7 @@ int MonsterTypeFunctions::luaMonsterTypeEventType(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeGetSummonList(lua_State* L) { // monsterType:getSummonList() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -1095,9 +1230,9 @@ int MonsterTypeFunctions::luaMonsterTypeGetSummonList(lua_State* L) { lua_createtable(L, monsterType->info.summons.size(), 0); for (const auto &summonBlock : monsterType->info.summons) { lua_createtable(L, 0, 3); - setField(L, "name", summonBlock.name); - setField(L, "speed", summonBlock.speed); - setField(L, "chance", summonBlock.chance); + Lua::setField(L, "name", summonBlock.name); + Lua::setField(L, "speed", summonBlock.speed); + Lua::setField(L, "chance", summonBlock.chance); lua_rawseti(L, -2, ++index); } return 1; @@ -1105,15 +1240,15 @@ int MonsterTypeFunctions::luaMonsterTypeGetSummonList(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeAddSummon(lua_State* L) { // monsterType:addSummon(name, interval, chance[, count = 1]) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { summonBlock_t summon; - summon.name = getString(L, 2); - summon.speed = getNumber(L, 3); - summon.count = getNumber(L, 5, 1); - summon.chance = getNumber(L, 4); + summon.name = Lua::getString(L, 2); + summon.speed = Lua::getNumber(L, 3); + summon.count = Lua::getNumber(L, 5, 1); + summon.chance = Lua::getNumber(L, 4); monsterType->info.summons.push_back(summon); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1122,13 +1257,13 @@ int MonsterTypeFunctions::luaMonsterTypeAddSummon(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeMaxSummons(lua_State* L) { // get: monsterType:maxSummons() set: monsterType:maxSummons(ammount) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.maxSummons); } else { - monsterType->info.maxSummons = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.maxSummons = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1138,13 +1273,13 @@ int MonsterTypeFunctions::luaMonsterTypeMaxSummons(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeArmor(lua_State* L) { // get: monsterType:armor() set: monsterType:armor(armor) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.armor); } else { - monsterType->info.armor = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.armor = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1154,31 +1289,31 @@ int MonsterTypeFunctions::luaMonsterTypeArmor(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeMitigation(lua_State* L) { // get: monsterType:mitigation() set: monsterType:mitigation(mitigation) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.mitigation); } else { - monsterType->info.mitigation = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.mitigation = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int MonsterTypeFunctions::luaMonsterTypeDefense(lua_State* L) { // get: monsterType:defense() set: monsterType:defense(defense) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.defense); } else { - monsterType->info.defense = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.defense = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1188,18 +1323,18 @@ int MonsterTypeFunctions::luaMonsterTypeDefense(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeOutfit(lua_State* L) { // get: monsterType:outfit() set: monsterType:outfit(outfit) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushOutfit(L, monsterType->info.outfit); + Lua::pushOutfit(L, monsterType->info.outfit); } else { - Outfit_t outfit = getOutfit(L, 2); + Outfit_t outfit = Lua::getOutfit(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[MonsterTypeFunctions::luaMonsterTypeOutfit] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); lua_pushnil(L); } else { monsterType->info.outfit = outfit; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } } else { @@ -1210,8 +1345,8 @@ int MonsterTypeFunctions::luaMonsterTypeOutfit(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRace(lua_State* L) { // get: monsterType:race() set: monsterType:race(race) - const auto &monsterType = getUserdataShared(L, 1); - std::string race = getString(L, 2); + const auto &monsterType = Lua::getUserdataShared(L, 1); + std::string race = Lua::getString(L, 2); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.race); @@ -1235,7 +1370,7 @@ int MonsterTypeFunctions::luaMonsterTypeRace(lua_State* L) { lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1245,12 +1380,12 @@ int MonsterTypeFunctions::luaMonsterTypeRace(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCorpseId(lua_State* L) { // get: monsterType:corpseId() set: monsterType:corpseId(id) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.lookcorpse); } else { - monsterType->info.lookcorpse = getNumber(L, 2); + monsterType->info.lookcorpse = Lua::getNumber(L, 2); lua_pushboolean(L, true); } } else { @@ -1261,13 +1396,13 @@ int MonsterTypeFunctions::luaMonsterTypeCorpseId(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeManaCost(lua_State* L) { // get: monsterType:manaCost() set: monsterType:manaCost(mana) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.manaCost); } else { - monsterType->info.manaCost = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.manaCost = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1277,13 +1412,13 @@ int MonsterTypeFunctions::luaMonsterTypeManaCost(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBaseSpeed(lua_State* L) { // monsterType:baseSpeed() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->getBaseSpeed()); } else { - monsterType->setBaseSpeed(getNumber(L, 2)); - pushBoolean(L, true); + monsterType->setBaseSpeed(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1292,7 +1427,7 @@ int MonsterTypeFunctions::luaMonsterTypeBaseSpeed(lua_State* L) { } int MonsterTypeFunctions::luaMonsterTypeLight(lua_State* L) { // get: monsterType:light() set: monsterType:light(color, level) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -1303,22 +1438,22 @@ int MonsterTypeFunctions::luaMonsterTypeLight(lua_State* L) { lua_pushnumber(L, monsterType->info.light.color); return 2; } else { - monsterType->info.light.color = getNumber(L, 2); - monsterType->info.light.level = getNumber(L, 3); - pushBoolean(L, true); + monsterType->info.light.color = Lua::getNumber(L, 2); + monsterType->info.light.level = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } return 1; } int MonsterTypeFunctions::luaMonsterTypeStaticAttackChance(lua_State* L) { // get: monsterType:staticAttackChance() set: monsterType:staticAttackChance(chance) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.staticAttackChance); } else { - monsterType->info.staticAttackChance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.staticAttackChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1328,13 +1463,13 @@ int MonsterTypeFunctions::luaMonsterTypeStaticAttackChance(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeTargetDistance(lua_State* L) { // get: monsterType:targetDistance() set: monsterType:targetDistance(distance) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.targetDistance); } else { - monsterType->info.targetDistance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.targetDistance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1344,18 +1479,18 @@ int MonsterTypeFunctions::luaMonsterTypeTargetDistance(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeYellChance(lua_State* L) { // get: monsterType:yellChance() set: monsterType:yellChance(chance) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.yellChance); } else { - monsterType->info.yellChance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.yellChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { - monsterType->info.yellChance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.yellChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1365,13 +1500,13 @@ int MonsterTypeFunctions::luaMonsterTypeYellChance(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeYellSpeedTicks(lua_State* L) { // get: monsterType:yellSpeedTicks() set: monsterType:yellSpeedTicks(rate) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.yellSpeedTicks); } else { - monsterType->info.yellSpeedTicks = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.yellSpeedTicks = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1381,13 +1516,13 @@ int MonsterTypeFunctions::luaMonsterTypeYellSpeedTicks(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeChangeTargetChance(lua_State* L) { // monsterType:getChangeTargetChance() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.changeTargetChance); } else { - monsterType->info.changeTargetChance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.changeTargetChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1397,13 +1532,13 @@ int MonsterTypeFunctions::luaMonsterTypeChangeTargetChance(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeChangeTargetSpeed(lua_State* L) { // get: monsterType:changeTargetSpeed() set: monsterType:changeTargetSpeed(speed) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.changeTargetSpeed); } else { - monsterType->info.changeTargetSpeed = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.changeTargetSpeed = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1413,13 +1548,13 @@ int MonsterTypeFunctions::luaMonsterTypeChangeTargetSpeed(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCanWalkOnEnergy(lua_State* L) { // get: monsterType:canWalkOnEnergy() set: monsterType:canWalkOnEnergy(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.canWalkOnEnergy); + Lua::pushBoolean(L, monsterType->info.canWalkOnEnergy); } else { - monsterType->info.canWalkOnEnergy = getBoolean(L, 2, true); - pushBoolean(L, true); + monsterType->info.canWalkOnEnergy = Lua::getBoolean(L, 2, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1429,13 +1564,13 @@ int MonsterTypeFunctions::luaMonsterTypeCanWalkOnEnergy(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCanWalkOnFire(lua_State* L) { // get: monsterType:canWalkOnFire() set: monsterType:canWalkOnFire(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.canWalkOnFire); + Lua::pushBoolean(L, monsterType->info.canWalkOnFire); } else { - monsterType->info.canWalkOnFire = getBoolean(L, 2, true); - pushBoolean(L, true); + monsterType->info.canWalkOnFire = Lua::getBoolean(L, 2, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1445,13 +1580,13 @@ int MonsterTypeFunctions::luaMonsterTypeCanWalkOnFire(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeCanWalkOnPoison(lua_State* L) { // get: monsterType:canWalkOnPoison() set: monsterType:canWalkOnPoison(bool) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { - pushBoolean(L, monsterType->info.canWalkOnPoison); + Lua::pushBoolean(L, monsterType->info.canWalkOnPoison); } else { - monsterType->info.canWalkOnPoison = getBoolean(L, 2, true); - pushBoolean(L, true); + monsterType->info.canWalkOnPoison = Lua::getBoolean(L, 2, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1461,13 +1596,13 @@ int MonsterTypeFunctions::luaMonsterTypeCanWalkOnPoison(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetNearest(lua_State* L) { // monsterType:strategiesTargetNearest() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.strategiesTargetNearest); } else { - monsterType->info.strategiesTargetNearest = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.strategiesTargetNearest = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1477,13 +1612,13 @@ int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetNearest(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetHealth(lua_State* L) { // monsterType:strategiesTargetHealth() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.strategiesTargetHealth); } else { - monsterType->info.strategiesTargetHealth = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.strategiesTargetHealth = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1493,13 +1628,13 @@ int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetHealth(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetDamage(lua_State* L) { // monsterType:strategiesTargetDamage() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.strategiesTargetDamage); } else { - monsterType->info.strategiesTargetDamage = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.strategiesTargetDamage = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1509,13 +1644,13 @@ int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetDamage(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetRandom(lua_State* L) { // monsterType:strategiesTargetRandom() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.strategiesTargetRandom); } else { - monsterType->info.strategiesTargetRandom = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.strategiesTargetRandom = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1529,13 +1664,13 @@ int MonsterTypeFunctions::luaMonsterTypeStrategiesTargetRandom(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRespawnTypePeriod(lua_State* L) { // monsterType:respawnTypePeriod() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.respawnType.period); } else { - monsterType->info.respawnType.period = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.respawnType.period = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1545,13 +1680,13 @@ int MonsterTypeFunctions::luaMonsterTypeRespawnTypePeriod(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeRespawnTypeIsUnderground(lua_State* L) { // monsterType:respawnTypeIsUnderground() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (monsterType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.respawnType.underground); } else { - monsterType->info.respawnType.underground = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.respawnType.underground = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -1562,10 +1697,10 @@ int MonsterTypeFunctions::luaMonsterTypeRespawnTypeIsUnderground(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBossRace(lua_State* L) { // set: monsterType:bosstiaryRace(raceId, class) // get: monsterType:bosstiaryRace() = this return only class name - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 0; } @@ -1574,13 +1709,13 @@ int MonsterTypeFunctions::luaMonsterTypeBossRace(lua_State* L) { lua_pushnil(L); return 1; } - pushString(L, monsterType->info.bosstiaryClass); + Lua::pushString(L, monsterType->info.bosstiaryClass); } else { - const auto bossRace = getNumber(L, 2, 0); - const auto bossClass = getString(L, 3); + const auto bossRace = Lua::getNumber(L, 2, 0); + const auto bossClass = Lua::getString(L, 3); monsterType->info.bosstiaryRace = magic_enum::enum_value(bossRace); monsterType->info.bosstiaryClass = bossClass; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } return 1; @@ -1589,10 +1724,10 @@ int MonsterTypeFunctions::luaMonsterTypeBossRace(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeBossRaceId(lua_State* L) { // set: monsterType:bossRaceId(raceId) // get: monsterType:bossRaceId() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_MONSTER_TYPE_NOT_FOUND)); return 0; } @@ -1603,10 +1738,10 @@ int MonsterTypeFunctions::luaMonsterTypeBossRaceId(lua_State* L) { lua_pushnumber(L, static_cast(monsterType->info.bosstiaryRace)); } } else { - const auto raceId = getNumber(L, 2, 0); + const auto raceId = Lua::getNumber(L, 2, 0); monsterType->info.raceid = raceId; g_ioBosstiary().addBosstiaryMonster(raceId, monsterType->typeName); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } return 1; @@ -1614,57 +1749,57 @@ int MonsterTypeFunctions::luaMonsterTypeBossRaceId(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeSoundChance(lua_State* L) { // get: monsterType:soundChance() set: monsterType:soundChance(chance) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.soundChance); } else { - monsterType->info.soundChance = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.soundChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int MonsterTypeFunctions::luaMonsterTypeSoundSpeedTicks(lua_State* L) { // get: monsterType:soundSpeedTicks() set: monsterType:soundSpeedTicks(ticks) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, monsterType->info.soundSpeedTicks); } else { - monsterType->info.soundSpeedTicks = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.soundSpeedTicks = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int MonsterTypeFunctions::luaMonsterTypeAddSound(lua_State* L) { // monsterType:addSound(soundId) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - monsterType->info.soundVector.push_back(getNumber(L, 2)); - pushBoolean(L, true); + monsterType->info.soundVector.push_back(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int MonsterTypeFunctions::luaMonsterTypeGetSounds(lua_State* L) { // monsterType:getSounds() - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { lua_pushnil(L); return 1; @@ -1683,18 +1818,18 @@ int MonsterTypeFunctions::luaMonsterTypeGetSounds(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypedeathSound(lua_State* L) { // get: monsterType:deathSound() set: monsterType:deathSound(sound) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(monsterType->info.deathSound)); } else { - monsterType->info.deathSound = getNumber(L, 2); - pushBoolean(L, true); + monsterType->info.deathSound = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; @@ -1702,18 +1837,18 @@ int MonsterTypeFunctions::luaMonsterTypedeathSound(lua_State* L) { int MonsterTypeFunctions::luaMonsterTypeVariant(lua_State* L) { // get: monsterType:variant() set: monsterType:variant(variantName) - const auto &monsterType = getUserdataShared(L, 1); + const auto &monsterType = Lua::getUserdataShared(L, 1); if (!monsterType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { - pushString(L, monsterType->variantName); + Lua::pushString(L, monsterType->variantName); } else { - monsterType->variantName = getString(L, 2); - pushBoolean(L, true); + monsterType->variantName = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } return 1; diff --git a/src/lua/functions/creatures/monster/monster_type_functions.hpp b/src/lua/functions/creatures/monster/monster_type_functions.hpp index a10f1619d61..e272ea45cd7 100644 --- a/src/lua/functions/creatures/monster/monster_type_functions.hpp +++ b/src/lua/functions/creatures/monster/monster_type_functions.hpp @@ -9,149 +9,11 @@ #pragma once -#include "lua/scripts/luascript.hpp" +struct LootBlock; -class MonsterTypeFunctions final : LuaScriptInterface { +class MonsterTypeFunctions { public: - explicit MonsterTypeFunctions(lua_State* L) : - LuaScriptInterface("MonsterTypeFunctions") { - init(L); - } - ~MonsterTypeFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "MonsterType", "", MonsterTypeFunctions::luaMonsterTypeCreate); - registerMetaMethod(L, "MonsterType", "__eq", MonsterTypeFunctions::luaUserdataCompare); - - registerMethod(L, "MonsterType", "isAttackable", MonsterTypeFunctions::luaMonsterTypeIsAttackable); - registerMethod(L, "MonsterType", "isConvinceable", MonsterTypeFunctions::luaMonsterTypeIsConvinceable); - registerMethod(L, "MonsterType", "isSummonable", MonsterTypeFunctions::luaMonsterTypeIsSummonable); - registerMethod(L, "MonsterType", "isPreyable", MonsterTypeFunctions::luaMonsterTypeIsPreyable); - registerMethod(L, "MonsterType", "isPreyExclusive", MonsterTypeFunctions::luaMonsterTypeIsPreyExclusive); - registerMethod(L, "MonsterType", "isIllusionable", MonsterTypeFunctions::luaMonsterTypeIsIllusionable); - registerMethod(L, "MonsterType", "isHostile", MonsterTypeFunctions::luaMonsterTypeIsHostile); - registerMethod(L, "MonsterType", "isPushable", MonsterTypeFunctions::luaMonsterTypeIsPushable); - registerMethod(L, "MonsterType", "isHealthHidden", MonsterTypeFunctions::luaMonsterTypeIsHealthHidden); - registerMethod(L, "MonsterType", "isBlockable", MonsterTypeFunctions::luaMonsterTypeIsBlockable); - registerMethod(L, "MonsterType", "isForgeCreature", MonsterTypeFunctions::luaMonsterTypeIsForgeCreature); - - registerMethod(L, "MonsterType", "familiar", MonsterTypeFunctions::luaMonsterTypeFamiliar); - registerMethod(L, "MonsterType", "isRewardBoss", MonsterTypeFunctions::luaMonsterTypeIsRewardBoss); - - registerMethod(L, "MonsterType", "canSpawn", MonsterTypeFunctions::luaMonsterTypeCanSpawn); - - registerMethod(L, "MonsterType", "canPushItems", MonsterTypeFunctions::luaMonsterTypeCanPushItems); - registerMethod(L, "MonsterType", "canPushCreatures", MonsterTypeFunctions::luaMonsterTypeCanPushCreatures); - - registerMethod(L, "MonsterType", "critChance", MonsterTypeFunctions::luaMonsterTypeCritChance); - - registerMethod(L, "MonsterType", "name", MonsterTypeFunctions::luaMonsterTypeName); - - registerMethod(L, "MonsterType", "nameDescription", MonsterTypeFunctions::luaMonsterTypeNameDescription); - - registerMethod(L, "MonsterType", "getCorpseId", MonsterTypeFunctions::luaMonsterTypegetCorpseId); - - registerMethod(L, "MonsterType", "health", MonsterTypeFunctions::luaMonsterTypeHealth); - registerMethod(L, "MonsterType", "maxHealth", MonsterTypeFunctions::luaMonsterTypeMaxHealth); - registerMethod(L, "MonsterType", "runHealth", MonsterTypeFunctions::luaMonsterTypeRunHealth); - registerMethod(L, "MonsterType", "experience", MonsterTypeFunctions::luaMonsterTypeExperience); - - registerMethod(L, "MonsterType", "faction", MonsterTypeFunctions::luaMonsterTypeFaction); - registerMethod(L, "MonsterType", "enemyFactions", MonsterTypeFunctions::luaMonsterTypeEnemyFactions); - registerMethod(L, "MonsterType", "targetPreferPlayer", MonsterTypeFunctions::luaMonsterTypeTargetPreferPlayer); - registerMethod(L, "MonsterType", "targetPreferMaster", MonsterTypeFunctions::luaMonsterTypeTargetPreferMaster); - - registerMethod(L, "MonsterType", "raceId", MonsterTypeFunctions::luaMonsterTypeRaceid); - registerMethod(L, "MonsterType", "Bestiaryclass", MonsterTypeFunctions::luaMonsterTypeBestiaryclass); - registerMethod(L, "MonsterType", "BestiaryOccurrence", MonsterTypeFunctions::luaMonsterTypeBestiaryOccurrence); - registerMethod(L, "MonsterType", "BestiaryLocations", MonsterTypeFunctions::luaMonsterTypeBestiaryLocations); - registerMethod(L, "MonsterType", "BestiaryStars", MonsterTypeFunctions::luaMonsterTypeBestiaryStars); - registerMethod(L, "MonsterType", "BestiaryCharmsPoints", MonsterTypeFunctions::luaMonsterTypeBestiaryCharmsPoints); - registerMethod(L, "MonsterType", "BestiarySecondUnlock", MonsterTypeFunctions::luaMonsterTypeBestiarySecondUnlock); - registerMethod(L, "MonsterType", "BestiaryFirstUnlock", MonsterTypeFunctions::luaMonsterTypeBestiaryFirstUnlock); - registerMethod(L, "MonsterType", "BestiarytoKill", MonsterTypeFunctions::luaMonsterTypeBestiarytoKill); - registerMethod(L, "MonsterType", "Bestiaryrace", MonsterTypeFunctions::luaMonsterTypeBestiaryrace); - - registerMethod(L, "MonsterType", "combatImmunities", MonsterTypeFunctions::luaMonsterTypeCombatImmunities); - registerMethod(L, "MonsterType", "conditionImmunities", MonsterTypeFunctions::luaMonsterTypeConditionImmunities); - - registerMethod(L, "MonsterType", "getAttackList", MonsterTypeFunctions::luaMonsterTypeGetAttackList); - registerMethod(L, "MonsterType", "addAttack", MonsterTypeFunctions::luaMonsterTypeAddAttack); - - registerMethod(L, "MonsterType", "getDefenseList", MonsterTypeFunctions::luaMonsterTypeGetDefenseList); - registerMethod(L, "MonsterType", "addDefense", MonsterTypeFunctions::luaMonsterTypeAddDefense); - - registerMethod(L, "MonsterType", "getTypeName", MonsterTypeFunctions::luaMonsterTypeGetTypeName); - - registerMethod(L, "MonsterType", "getElementList", MonsterTypeFunctions::luaMonsterTypeGetElementList); - registerMethod(L, "MonsterType", "addElement", MonsterTypeFunctions::luaMonsterTypeAddElement); - - registerMethod(L, "MonsterType", "addReflect", MonsterTypeFunctions::luaMonsterTypeAddReflect); - registerMethod(L, "MonsterType", "addHealing", MonsterTypeFunctions::luaMonsterTypeAddHealing); - - registerMethod(L, "MonsterType", "getVoices", MonsterTypeFunctions::luaMonsterTypeGetVoices); - registerMethod(L, "MonsterType", "addVoice", MonsterTypeFunctions::luaMonsterTypeAddVoice); - - registerMethod(L, "MonsterType", "getLoot", MonsterTypeFunctions::luaMonsterTypeGetLoot); - registerMethod(L, "MonsterType", "addLoot", MonsterTypeFunctions::luaMonsterTypeAddLoot); - - registerMethod(L, "MonsterType", "getCreatureEvents", MonsterTypeFunctions::luaMonsterTypeGetCreatureEvents); - registerMethod(L, "MonsterType", "registerEvent", MonsterTypeFunctions::luaMonsterTypeRegisterEvent); - - registerMethod(L, "MonsterType", "eventType", MonsterTypeFunctions::luaMonsterTypeEventType); - registerMethod(L, "MonsterType", "onThink", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onAppear", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onDisappear", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onMove", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onSay", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onPlayerAttack", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - registerMethod(L, "MonsterType", "onSpawn", MonsterTypeFunctions::luaMonsterTypeEventOnCallback); - - registerMethod(L, "MonsterType", "getSummonList", MonsterTypeFunctions::luaMonsterTypeGetSummonList); - registerMethod(L, "MonsterType", "addSummon", MonsterTypeFunctions::luaMonsterTypeAddSummon); - - registerMethod(L, "MonsterType", "maxSummons", MonsterTypeFunctions::luaMonsterTypeMaxSummons); - - registerMethod(L, "MonsterType", "armor", MonsterTypeFunctions::luaMonsterTypeArmor); - registerMethod(L, "MonsterType", "mitigation", MonsterTypeFunctions::luaMonsterTypeMitigation); - registerMethod(L, "MonsterType", "defense", MonsterTypeFunctions::luaMonsterTypeDefense); - registerMethod(L, "MonsterType", "outfit", MonsterTypeFunctions::luaMonsterTypeOutfit); - registerMethod(L, "MonsterType", "race", MonsterTypeFunctions::luaMonsterTypeRace); - registerMethod(L, "MonsterType", "corpseId", MonsterTypeFunctions::luaMonsterTypeCorpseId); - registerMethod(L, "MonsterType", "manaCost", MonsterTypeFunctions::luaMonsterTypeManaCost); - registerMethod(L, "MonsterType", "baseSpeed", MonsterTypeFunctions::luaMonsterTypeBaseSpeed); - registerMethod(L, "MonsterType", "light", MonsterTypeFunctions::luaMonsterTypeLight); - - registerMethod(L, "MonsterType", "staticAttackChance", MonsterTypeFunctions::luaMonsterTypeStaticAttackChance); - registerMethod(L, "MonsterType", "targetDistance", MonsterTypeFunctions::luaMonsterTypeTargetDistance); - registerMethod(L, "MonsterType", "yellChance", MonsterTypeFunctions::luaMonsterTypeYellChance); - registerMethod(L, "MonsterType", "yellSpeedTicks", MonsterTypeFunctions::luaMonsterTypeYellSpeedTicks); - registerMethod(L, "MonsterType", "changeTargetChance", MonsterTypeFunctions::luaMonsterTypeChangeTargetChance); - registerMethod(L, "MonsterType", "changeTargetSpeed", MonsterTypeFunctions::luaMonsterTypeChangeTargetSpeed); - - registerMethod(L, "MonsterType", "canWalkOnEnergy", MonsterTypeFunctions::luaMonsterTypeCanWalkOnEnergy); - registerMethod(L, "MonsterType", "canWalkOnFire", MonsterTypeFunctions::luaMonsterTypeCanWalkOnFire); - registerMethod(L, "MonsterType", "canWalkOnPoison", MonsterTypeFunctions::luaMonsterTypeCanWalkOnPoison); - - registerMethod(L, "MonsterType", "strategiesTargetNearest", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetNearest); - registerMethod(L, "MonsterType", "strategiesTargetHealth", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetHealth); - registerMethod(L, "MonsterType", "strategiesTargetDamage", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetDamage); - registerMethod(L, "MonsterType", "strategiesTargetRandom", MonsterTypeFunctions::luaMonsterTypeStrategiesTargetRandom); - - registerMethod(L, "MonsterType", "respawnTypePeriod", MonsterTypeFunctions::luaMonsterTypeRespawnTypePeriod); - registerMethod(L, "MonsterType", "respawnTypeIsUnderground", MonsterTypeFunctions::luaMonsterTypeRespawnTypeIsUnderground); - - registerMethod(L, "MonsterType", "bossRace", MonsterTypeFunctions::luaMonsterTypeBossRace); - registerMethod(L, "MonsterType", "bossRaceId", MonsterTypeFunctions::luaMonsterTypeBossRaceId); - - registerMethod(L, "MonsterType", "soundChance", MonsterTypeFunctions::luaMonsterTypeSoundChance); - registerMethod(L, "MonsterType", "soundSpeedTicks", MonsterTypeFunctions::luaMonsterTypeSoundSpeedTicks); - registerMethod(L, "MonsterType", "addSound", MonsterTypeFunctions::luaMonsterTypeAddSound); - registerMethod(L, "MonsterType", "getSounds", MonsterTypeFunctions::luaMonsterTypeGetSounds); - registerMethod(L, "MonsterType", "deathSound", MonsterTypeFunctions::luaMonsterTypedeathSound); - - registerMethod(L, "MonsterType", "variant", MonsterTypeFunctions::luaMonsterTypeVariant); - } + static void init(lua_State* L); private: static void createMonsterTypeLootLuaTable(lua_State* L, const std::vector &lootList); diff --git a/src/lua/functions/creatures/npc/npc_functions.cpp b/src/lua/functions/creatures/npc/npc_functions.cpp index f3f5a204ba5..533182ea128 100644 --- a/src/lua/functions/creatures/npc/npc_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_functions.cpp @@ -14,31 +14,69 @@ #include "creatures/players/player.hpp" #include "game/game.hpp" #include "map/spectators.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void NpcFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Npc", "Creature", NpcFunctions::luaNpcCreate); + Lua::registerMetaMethod(L, "Npc", "__eq", Lua::luaUserdataCompare); + Lua::registerMethod(L, "Npc", "isNpc", NpcFunctions::luaNpcIsNpc); + Lua::registerMethod(L, "Npc", "setMasterPos", NpcFunctions::luaNpcSetMasterPos); + Lua::registerMethod(L, "Npc", "getCurrency", NpcFunctions::luaNpcGetCurrency); + Lua::registerMethod(L, "Npc", "setCurrency", NpcFunctions::luaNpcSetCurrency); + Lua::registerMethod(L, "Npc", "getSpeechBubble", NpcFunctions::luaNpcGetSpeechBubble); + Lua::registerMethod(L, "Npc", "setSpeechBubble", NpcFunctions::luaNpcSetSpeechBubble); + Lua::registerMethod(L, "Npc", "getId", NpcFunctions::luaNpcGetId); + Lua::registerMethod(L, "Npc", "getName", NpcFunctions::luaNpcGetName); + Lua::registerMethod(L, "Npc", "setName", NpcFunctions::luaNpcSetName); + Lua::registerMethod(L, "Npc", "place", NpcFunctions::luaNpcPlace); + Lua::registerMethod(L, "Npc", "say", NpcFunctions::luaNpcSay); + Lua::registerMethod(L, "Npc", "turnToCreature", NpcFunctions::luaNpcTurnToCreature); + Lua::registerMethod(L, "Npc", "setPlayerInteraction", NpcFunctions::luaNpcSetPlayerInteraction); + Lua::registerMethod(L, "Npc", "removePlayerInteraction", NpcFunctions::luaNpcRemovePlayerInteraction); + Lua::registerMethod(L, "Npc", "isInteractingWithPlayer", NpcFunctions::luaNpcIsInteractingWithPlayer); + Lua::registerMethod(L, "Npc", "isInTalkRange", NpcFunctions::luaNpcIsInTalkRange); + Lua::registerMethod(L, "Npc", "isPlayerInteractingOnTopic", NpcFunctions::luaNpcIsPlayerInteractingOnTopic); + Lua::registerMethod(L, "Npc", "openShopWindow", NpcFunctions::luaNpcOpenShopWindow); + Lua::registerMethod(L, "Npc", "openShopWindowTable", NpcFunctions::luaNpcOpenShopWindowTable); + Lua::registerMethod(L, "Npc", "closeShopWindow", NpcFunctions::luaNpcCloseShopWindow); + Lua::registerMethod(L, "Npc", "getShopItem", NpcFunctions::luaNpcGetShopItem); + Lua::registerMethod(L, "Npc", "isMerchant", NpcFunctions::luaNpcIsMerchant); + + Lua::registerMethod(L, "Npc", "move", NpcFunctions::luaNpcMove); + Lua::registerMethod(L, "Npc", "turn", NpcFunctions::luaNpcTurn); + Lua::registerMethod(L, "Npc", "follow", NpcFunctions::luaNpcFollow); + Lua::registerMethod(L, "Npc", "sellItem", NpcFunctions::luaNpcSellItem); + + Lua::registerMethod(L, "Npc", "getDistanceTo", NpcFunctions::luaNpcGetDistanceTo); + + ShopFunctions::init(L); + NpcTypeFunctions::init(L); +} int NpcFunctions::luaNpcCreate(lua_State* L) { // Npc([id or name or userdata]) std::shared_ptr npc; if (lua_gettop(L) >= 2) { - if (isNumber(L, 2)) { - npc = g_game().getNpcByID(getNumber(L, 2)); - } else if (isString(L, 2)) { - npc = g_game().getNpcByName(getString(L, 2)); - } else if (isUserdata(L, 2)) { - if (getUserdataType(L, 2) != LuaData_t::Npc) { + if (Lua::isNumber(L, 2)) { + npc = g_game().getNpcByID(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + npc = g_game().getNpcByName(Lua::getString(L, 2)); + } else if (Lua::isUserdata(L, 2)) { + if (Lua::getUserdataType(L, 2) != LuaData_t::Npc) { lua_pushnil(L); return 1; } - npc = getUserdataShared(L, 2); + npc = Lua::getUserdataShared(L, 2); } else { npc = nullptr; } } else { - npc = getUserdataShared(L, 1); + npc = Lua::getUserdataShared(L, 1); } if (npc) { - pushUserdata(L, npc); - setMetatable(L, -1, "Npc"); + Lua::pushUserdata(L, npc); + Lua::setMetatable(L, -1, "Npc"); } else { lua_pushnil(L); } @@ -47,30 +85,30 @@ int NpcFunctions::luaNpcCreate(lua_State* L) { int NpcFunctions::luaNpcIsNpc(lua_State* L) { // npc:isNpc() - pushBoolean(L, getUserdataShared(L, 1) != nullptr); + Lua::pushBoolean(L, Lua::getUserdataShared(L, 1) != nullptr); return 1; } int NpcFunctions::luaNpcSetMasterPos(lua_State* L) { // npc:setMasterPos(pos) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const Position &pos = getPosition(L, 2); + const Position &pos = Lua::getPosition(L, 2); npc->setMasterPos(pos); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcGetCurrency(lua_State* L) { // npc:getCurrency() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); } @@ -80,22 +118,22 @@ int NpcFunctions::luaNpcGetCurrency(lua_State* L) { int NpcFunctions::luaNpcSetCurrency(lua_State* L) { // npc:getCurrency() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - npc->setCurrency(getNumber(L, 2)); + npc->setCurrency(Lua::getNumber(L, 2)); return 1; } int NpcFunctions::luaNpcGetSpeechBubble(lua_State* L) { // npc:getSpeechBubble() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); } @@ -105,35 +143,35 @@ int NpcFunctions::luaNpcGetSpeechBubble(lua_State* L) { int NpcFunctions::luaNpcSetSpeechBubble(lua_State* L) { // npc:setSpeechBubble(speechBubble) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); } - npc->setSpeechBubble(getNumber(L, 2)); + npc->setSpeechBubble(Lua::getNumber(L, 2)); return 1; } int NpcFunctions::luaNpcGetName(lua_State* L) { // npc:getName() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } - pushString(L, npc->getName()); + Lua::pushString(L, npc->getName()); return 1; } int NpcFunctions::luaNpcSetName(lua_State* L) { // npc:setName(name) - const auto &npc = getUserdataShared(L, 1); - const std::string &name = getString(L, 2); + const auto &npc = Lua::getUserdataShared(L, 1); + const std::string &name = Lua::getString(L, 2); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); } @@ -143,19 +181,19 @@ int NpcFunctions::luaNpcSetName(lua_State* L) { int NpcFunctions::luaNpcPlace(lua_State* L) { // npc:place(position[, extended = false[, force = true]]) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } - const Position &position = getPosition(L, 2); - const bool extended = getBoolean(L, 3, false); - const bool force = getBoolean(L, 4, true); + const Position &position = Lua::getPosition(L, 2); + const bool extended = Lua::getBoolean(L, 3, false); + const bool force = Lua::getBoolean(L, 4, true); if (g_game().placeCreature(npc, position, extended, force)) { - pushUserdata(L, npc); - setMetatable(L, -1, "Npc"); + Lua::pushUserdata(L, npc); + Lua::setMetatable(L, -1, "Npc"); } else { lua_pushnil(L); } @@ -168,24 +206,24 @@ int NpcFunctions::luaNpcSay(lua_State* L) { Position position; if (parameters >= 6) { - position = getPosition(L, 6); + position = Lua::getPosition(L, 6); if (!position.x || !position.y) { - reportErrorFunc("Invalid position specified."); - pushBoolean(L, false); + Lua::reportErrorFunc("Invalid position specified."); + Lua::pushBoolean(L, false); return 1; } } std::shared_ptr target = nullptr; if (parameters >= 5) { - target = getCreature(L, 5); + target = Lua::getCreature(L, 5); } - const bool ghost = getBoolean(L, 4, false); + const bool ghost = Lua::getBoolean(L, 4, false); - const auto &type = getNumber(L, 3, TALKTYPE_PRIVATE_NP); - const std::string &text = getString(L, 2); - const auto &npc = getUserdataShared(L, 1); + const auto &type = Lua::getNumber(L, 3, TALKTYPE_PRIVATE_NP); + const std::string &text = Lua::getString(L, 2); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { lua_pushnil(L); return 1; @@ -197,9 +235,9 @@ int NpcFunctions::luaNpcSay(lua_State* L) { } if (position.x != 0) { - pushBoolean(L, g_game().internalCreatureSay(npc, type, text, ghost, &spectators, &position)); + Lua::pushBoolean(L, g_game().internalCreatureSay(npc, type, text, ghost, &spectators, &position)); } else { - pushBoolean(L, g_game().internalCreatureSay(npc, type, text, ghost, &spectators)); + Lua::pushBoolean(L, g_game().internalCreatureSay(npc, type, text, ghost, &spectators)); } return 1; } @@ -210,173 +248,173 @@ int NpcFunctions::luaNpcSay(lua_State* L) { */ int NpcFunctions::luaNpcTurnToCreature(lua_State* L) { // npc:turnToCreature(creature, true) - const auto &npc = getUserdataShared(L, 1); - const auto &creature = getCreature(L, 2); + const auto &npc = Lua::getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushnil(L); return 1; } - const bool stopEventWalk = getBoolean(L, 3, true); + const bool stopEventWalk = Lua::getBoolean(L, 3, true); if (stopEventWalk) { npc->stopEventWalk(); } npc->turnToCreature(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcSetPlayerInteraction(lua_State* L) { // npc:setPlayerInteraction(creature, topic = 0) - const auto &npc = getUserdataShared(L, 1); - const auto &creature = getCreature(L, 2); - const auto topicId = getNumber(L, 3, 0); + const auto &npc = Lua::getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); + const auto topicId = Lua::getNumber(L, 3, 0); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushnil(L); return 1; } npc->setPlayerInteraction(creature->getID(), topicId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcRemovePlayerInteraction(lua_State* L) { // npc:removePlayerInteraction() - const auto &npc = getUserdataShared(L, 1); - const auto &creature = getCreature(L, 2); + const auto &npc = Lua::getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushnil(L); return 1; } npc->removePlayerInteraction(creature->getPlayer()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcIsInteractingWithPlayer(lua_State* L) { // npc:isInteractingWithPlayer(creature) - const auto &npc = getUserdataShared(L, 1); - const auto &creature = getCreature(L, 2); + const auto &npc = Lua::getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushnil(L); return 1; } - pushBoolean(L, npc->isInteractingWithPlayer(creature->getID())); + Lua::pushBoolean(L, npc->isInteractingWithPlayer(creature->getID())); return 1; } int NpcFunctions::luaNpcIsPlayerInteractingOnTopic(lua_State* L) { // npc:isPlayerInteractingOnTopic(creature, topicId = 0) - const auto &npc = getUserdataShared(L, 1); - const auto &creature = getCreature(L, 2); - const auto topicId = getNumber(L, 3, 0); + const auto &npc = Lua::getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); + const auto topicId = Lua::getNumber(L, 3, 0); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); lua_pushnil(L); return 1; } - pushBoolean(L, npc->isPlayerInteractingOnTopic(creature->getID(), topicId)); + Lua::pushBoolean(L, npc->isPlayerInteractingOnTopic(creature->getID(), topicId)); return 1; } int NpcFunctions::luaNpcIsInTalkRange(lua_State* L) { // npc:isInTalkRange(position[, range = 4]) - const auto &npc = getUserdataShared(L, 1); - const Position &position = getPosition(L, 2); - const auto range = getNumber(L, 3, 4); + const auto &npc = Lua::getUserdataShared(L, 1); + const Position &position = Lua::getPosition(L, 2); + const auto range = Lua::getNumber(L, 3, 4); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } - pushBoolean(L, npc && npc->canInteract(position, range)); + Lua::pushBoolean(L, npc && npc->canInteract(position, range)); return 1; } int NpcFunctions::luaNpcOpenShopWindow(lua_State* L) { // npc:openShopWindow(player) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } player->closeShopWindow(); - pushBoolean(L, player->openShopWindow(npc)); + Lua::pushBoolean(L, player->openShopWindow(npc)); return 1; } int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { // npc:openShopWindowTable(player, items) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getUserdataShared(L, 2); + const auto &player = Lua::getUserdataShared(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } if (lua_istable(L, 3) == 0) { - reportError(__FUNCTION__, "item list is not a table."); - pushBoolean(L, false); + Lua::reportError(__FUNCTION__, "item list is not a table."); + Lua::pushBoolean(L, false); return 1; } @@ -385,18 +423,18 @@ int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { while (lua_next(L, 3) != 0) { const auto tableIndex = lua_gettop(L); - auto itemId = getField(L, tableIndex, "clientId"); - auto subType = getField(L, tableIndex, "subType"); + auto itemId = Lua::getField(L, tableIndex, "clientId"); + auto subType = Lua::getField(L, tableIndex, "subType"); if (subType == 0) { - subType = getField(L, tableIndex, "subtype"); + subType = Lua::getField(L, tableIndex, "subtype"); lua_pop(L, 1); } - auto buyPrice = getField(L, tableIndex, "buy"); - auto sellPrice = getField(L, tableIndex, "sell"); - auto storageKey = getField(L, tableIndex, "storageKey"); - auto storageValue = getField(L, tableIndex, "storageValue"); - auto itemName = getFieldString(L, tableIndex, "itemName"); + auto buyPrice = Lua::getField(L, tableIndex, "buy"); + auto sellPrice = Lua::getField(L, tableIndex, "sell"); + auto storageKey = Lua::getField(L, tableIndex, "storageKey"); + auto storageValue = Lua::getField(L, tableIndex, "storageValue"); + auto itemName = Lua::getFieldString(L, tableIndex, "itemName"); if (itemName.empty()) { itemName = Item::items[itemId].name; } @@ -406,23 +444,23 @@ int NpcFunctions::luaNpcOpenShopWindowTable(lua_State* L) { lua_pop(L, 3); player->closeShopWindow(); - pushBoolean(L, player->openShopWindow(npc, items)); + Lua::pushBoolean(L, player->openShopWindow(npc, items)); return 1; } int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { // npc:closeShopWindow(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -430,96 +468,96 @@ int NpcFunctions::luaNpcCloseShopWindow(lua_State* L) { player->closeShopWindow(); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcIsMerchant(lua_State* L) { // npc:isMerchant() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto playerGUID = getNumber(L, 2, 0); + const auto playerGUID = Lua::getNumber(L, 2, 0); const auto &shopItems = npc->getShopItemVector(playerGUID); if (shopItems.empty()) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcGetShopItem(lua_State* L) { // npc:getShopItem(itemId) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_CREATURE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto playerGUID = getNumber(L, 2, 0); + const auto playerGUID = Lua::getNumber(L, 2, 0); const auto &shopItems = npc->getShopItemVector(playerGUID); for (const ShopBlock &shopBlock : shopItems) { - setField(L, "id", shopBlock.itemId); - setField(L, "name", shopBlock.itemName); - setField(L, "subType", shopBlock.itemSubType); - setField(L, "buyPrice", shopBlock.itemBuyPrice); - setField(L, "sellPrice", shopBlock.itemSellPrice); - setField(L, "storageKey", shopBlock.itemStorageKey); - setField(L, "storageValue", shopBlock.itemStorageValue); + Lua::setField(L, "id", shopBlock.itemId); + Lua::setField(L, "name", shopBlock.itemName); + Lua::setField(L, "subType", shopBlock.itemSubType); + Lua::setField(L, "buyPrice", shopBlock.itemBuyPrice); + Lua::setField(L, "sellPrice", shopBlock.itemSellPrice); + Lua::setField(L, "storageKey", shopBlock.itemStorageKey); + Lua::setField(L, "storageValue", shopBlock.itemStorageValue); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcMove(lua_State* L) { // npc:move(direction) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (npc) { - g_game().internalMoveCreature(npc, getNumber(L, 2)); + g_game().internalMoveCreature(npc, Lua::getNumber(L, 2)); } return 0; } int NpcFunctions::luaNpcTurn(lua_State* L) { // npc:turn(direction) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (npc) { - g_game().internalCreatureTurn(npc, getNumber(L, 2)); + g_game().internalCreatureTurn(npc, Lua::getNumber(L, 2)); } return 0; } int NpcFunctions::luaNpcFollow(lua_State* L) { // npc:follow(player) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - pushBoolean(L, npc->setFollowCreature(player)); + Lua::pushBoolean(L, npc->setFollowCreature(player)); return 1; } int NpcFunctions::luaNpcGetId(lua_State* L) { // npc:getId() - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); lua_pushnil(L); return 1; } @@ -530,30 +568,30 @@ int NpcFunctions::luaNpcGetId(lua_State* L) { int NpcFunctions::luaNpcSellItem(lua_State* L) { // npc:sellItem(player, itemid, amount, subtype, actionid, ignoreCap, inBackpacks) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - auto itemId = getNumber(L, 3); - const double amount = getNumber(L, 4); - const auto subType = getNumber(L, 5, 1); - const auto actionId = getNumber(L, 6, 0); - const bool ignoreCap = getBoolean(L, 7, false); - const bool inBackpacks = getBoolean(L, 8, false); + auto itemId = Lua::getNumber(L, 3); + const double amount = Lua::getNumber(L, 4); + const auto subType = Lua::getNumber(L, 5, 1); + const auto actionId = Lua::getNumber(L, 6, 0); + const bool ignoreCap = Lua::getBoolean(L, 7, false); + const bool inBackpacks = Lua::getBoolean(L, 8, false); const ItemType &it = Item::items[itemId]; if (it.id == 0) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -568,7 +606,7 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { } if ((static_cast(tile->getItemList()->size()) + (slotsNedeed - player->getFreeBackpackSlots())) > 30) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); return 1; } @@ -642,23 +680,23 @@ int NpcFunctions::luaNpcSellItem(lua_State* L) { } player->sendTextMessage(MESSAGE_TRADE, ss.str()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int NpcFunctions::luaNpcGetDistanceTo(lua_State* L) { // npc:getDistanceTo(uid) - const auto &npc = getUserdataShared(L, 1); + const auto &npc = Lua::getUserdataShared(L, 1); if (!npc) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &thing = getScriptEnv()->getThingByUID(getNumber(L, -1)); - pushBoolean(L, thing && thing->isPushable()); + const auto &thing = Lua::getScriptEnv()->getThingByUID(Lua::getNumber(L, -1)); + Lua::pushBoolean(L, thing && thing->isPushable()); if (!thing) { - reportErrorFunc(getErrorDesc(LUA_ERROR_THING_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_THING_NOT_FOUND)); lua_pushnil(L); return 1; } diff --git a/src/lua/functions/creatures/npc/npc_functions.hpp b/src/lua/functions/creatures/npc/npc_functions.hpp index e03e3f72b25..4d0adc7335a 100644 --- a/src/lua/functions/creatures/npc/npc_functions.hpp +++ b/src/lua/functions/creatures/npc/npc_functions.hpp @@ -11,52 +11,9 @@ #include "lua/functions/creatures/npc/npc_type_functions.hpp" #include "lua/functions/creatures/npc/shop_functions.hpp" -#include "lua/scripts/luascript.hpp" - -class NpcFunctions final : LuaScriptInterface { +class NpcFunctions { private: - explicit NpcFunctions(lua_State* L) : - LuaScriptInterface("NpcFunctions") { - init(L); - } - ~NpcFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Npc", "Creature", NpcFunctions::luaNpcCreate); - registerMetaMethod(L, "Npc", "__eq", NpcFunctions::luaUserdataCompare); - registerMethod(L, "Npc", "isNpc", NpcFunctions::luaNpcIsNpc); - registerMethod(L, "Npc", "setMasterPos", NpcFunctions::luaNpcSetMasterPos); - registerMethod(L, "Npc", "getCurrency", NpcFunctions::luaNpcGetCurrency); - registerMethod(L, "Npc", "setCurrency", NpcFunctions::luaNpcSetCurrency); - registerMethod(L, "Npc", "getSpeechBubble", NpcFunctions::luaNpcGetSpeechBubble); - registerMethod(L, "Npc", "setSpeechBubble", NpcFunctions::luaNpcSetSpeechBubble); - registerMethod(L, "Npc", "getId", NpcFunctions::luaNpcGetId); - registerMethod(L, "Npc", "getName", NpcFunctions::luaNpcGetName); - registerMethod(L, "Npc", "setName", NpcFunctions::luaNpcSetName); - registerMethod(L, "Npc", "place", NpcFunctions::luaNpcPlace); - registerMethod(L, "Npc", "say", NpcFunctions::luaNpcSay); - registerMethod(L, "Npc", "turnToCreature", NpcFunctions::luaNpcTurnToCreature); - registerMethod(L, "Npc", "setPlayerInteraction", NpcFunctions::luaNpcSetPlayerInteraction); - registerMethod(L, "Npc", "removePlayerInteraction", NpcFunctions::luaNpcRemovePlayerInteraction); - registerMethod(L, "Npc", "isInteractingWithPlayer", NpcFunctions::luaNpcIsInteractingWithPlayer); - registerMethod(L, "Npc", "isInTalkRange", NpcFunctions::luaNpcIsInTalkRange); - registerMethod(L, "Npc", "isPlayerInteractingOnTopic", NpcFunctions::luaNpcIsPlayerInteractingOnTopic); - registerMethod(L, "Npc", "openShopWindow", NpcFunctions::luaNpcOpenShopWindow); - registerMethod(L, "Npc", "openShopWindowTable", NpcFunctions::luaNpcOpenShopWindowTable); - registerMethod(L, "Npc", "closeShopWindow", NpcFunctions::luaNpcCloseShopWindow); - registerMethod(L, "Npc", "getShopItem", NpcFunctions::luaNpcGetShopItem); - registerMethod(L, "Npc", "isMerchant", NpcFunctions::luaNpcIsMerchant); - - registerMethod(L, "Npc", "move", NpcFunctions::luaNpcMove); - registerMethod(L, "Npc", "turn", NpcFunctions::luaNpcTurn); - registerMethod(L, "Npc", "follow", NpcFunctions::luaNpcFollow); - registerMethod(L, "Npc", "sellItem", NpcFunctions::luaNpcSellItem); - - registerMethod(L, "Npc", "getDistanceTo", NpcFunctions::luaNpcGetDistanceTo); - - ShopFunctions::init(L); - NpcTypeFunctions::init(L); - } + static void init(lua_State* L); static int luaNpcCreate(lua_State* L); diff --git a/src/lua/functions/creatures/npc/npc_type_functions.cpp b/src/lua/functions/creatures/npc/npc_type_functions.cpp index 9360591318c..84609be95b1 100644 --- a/src/lua/functions/creatures/npc/npc_type_functions.cpp +++ b/src/lua/functions/creatures/npc/npc_type_functions.cpp @@ -13,6 +13,65 @@ #include "creatures/npcs/npcs.hpp" #include "game/game.hpp" #include "lua/scripts/scripts.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void NpcTypeFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "NpcType", "", NpcTypeFunctions::luaNpcTypeCreate); + Lua::registerMetaMethod(L, "NpcType", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "NpcType", "isPushable", NpcTypeFunctions::luaNpcTypeIsPushable); + Lua::registerMethod(L, "NpcType", "floorChange", NpcTypeFunctions::luaNpcTypeFloorChange); + + Lua::registerMethod(L, "NpcType", "canSpawn", NpcTypeFunctions::luaNpcTypeCanSpawn); + + Lua::registerMethod(L, "NpcType", "canPushItems", NpcTypeFunctions::luaNpcTypeCanPushItems); + Lua::registerMethod(L, "NpcType", "canPushCreatures", NpcTypeFunctions::luaNpcTypeCanPushCreatures); + + Lua::registerMethod(L, "NpcType", "name", NpcTypeFunctions::luaNpcTypeName); + + Lua::registerMethod(L, "NpcType", "nameDescription", NpcTypeFunctions::luaNpcTypeNameDescription); + + Lua::registerMethod(L, "NpcType", "health", NpcTypeFunctions::luaNpcTypeHealth); + Lua::registerMethod(L, "NpcType", "maxHealth", NpcTypeFunctions::luaNpcTypeMaxHealth); + + Lua::registerMethod(L, "NpcType", "getVoices", NpcTypeFunctions::luaNpcTypeGetVoices); + Lua::registerMethod(L, "NpcType", "addVoice", NpcTypeFunctions::luaNpcTypeAddVoice); + + Lua::registerMethod(L, "NpcType", "getCreatureEvents", NpcTypeFunctions::luaNpcTypeGetCreatureEvents); + Lua::registerMethod(L, "NpcType", "registerEvent", NpcTypeFunctions::luaNpcTypeRegisterEvent); + + Lua::registerMethod(L, "NpcType", "eventType", NpcTypeFunctions::luaNpcTypeEventType); + Lua::registerMethod(L, "NpcType", "onThink", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onAppear", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onDisappear", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onMove", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onSay", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onCloseChannel", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onBuyItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onSellItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); + Lua::registerMethod(L, "NpcType", "onCheckItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); + + Lua::registerMethod(L, "NpcType", "outfit", NpcTypeFunctions::luaNpcTypeOutfit); + Lua::registerMethod(L, "NpcType", "baseSpeed", NpcTypeFunctions::luaNpcTypeBaseSpeed); + Lua::registerMethod(L, "NpcType", "walkInterval", NpcTypeFunctions::luaNpcTypeWalkInterval); + Lua::registerMethod(L, "NpcType", "walkRadius", NpcTypeFunctions::luaNpcTypeWalkRadius); + Lua::registerMethod(L, "NpcType", "light", NpcTypeFunctions::luaNpcTypeLight); + + Lua::registerMethod(L, "NpcType", "yellChance", NpcTypeFunctions::luaNpcTypeYellChance); + Lua::registerMethod(L, "NpcType", "yellSpeedTicks", NpcTypeFunctions::luaNpcTypeYellSpeedTicks); + + Lua::registerMethod(L, "NpcType", "respawnTypePeriod", NpcTypeFunctions::luaNpcTypeRespawnTypePeriod); + Lua::registerMethod(L, "NpcType", "respawnTypeIsUnderground", NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground); + Lua::registerMethod(L, "NpcType", "speechBubble", NpcTypeFunctions::luaNpcTypeSpeechBubble); + Lua::registerMethod(L, "NpcType", "currency", NpcTypeFunctions::luaNpcTypeCurrency); + + Lua::registerMethod(L, "NpcType", "addShopItem", NpcTypeFunctions::luaNpcTypeAddShopItem); + + Lua::registerMethod(L, "NpcType", "soundChance", NpcTypeFunctions::luaNpcTypeSoundChance); + Lua::registerMethod(L, "NpcType", "soundSpeedTicks", NpcTypeFunctions::luaNpcTypeSoundSpeedTicks); + Lua::registerMethod(L, "NpcType", "addSound", NpcTypeFunctions::luaNpcTypeAddSound); + Lua::registerMethod(L, "NpcType", "getSounds", NpcTypeFunctions::luaNpcTypeGetSounds); +} void NpcTypeFunctions::createNpcTypeShopLuaTable(lua_State* L, const std::vector &shopVector) { lua_createtable(L, shopVector.size(), 0); @@ -21,12 +80,12 @@ void NpcTypeFunctions::createNpcTypeShopLuaTable(lua_State* L, const std::vector for (const auto &shopBlock : shopVector) { lua_createtable(L, 0, 5); - setField(L, "itemId", shopBlock.itemId); - setField(L, "itemName", shopBlock.itemName); - setField(L, "itemBuyPrice", shopBlock.itemBuyPrice); - setField(L, "itemSellPrice", shopBlock.itemSellPrice); - setField(L, "itemStorageKey", shopBlock.itemStorageKey); - setField(L, "itemStorageValue", shopBlock.itemStorageValue); + Lua::setField(L, "itemId", shopBlock.itemId); + Lua::setField(L, "itemName", shopBlock.itemName); + Lua::setField(L, "itemBuyPrice", shopBlock.itemBuyPrice); + Lua::setField(L, "itemSellPrice", shopBlock.itemSellPrice); + Lua::setField(L, "itemStorageKey", shopBlock.itemStorageKey); + Lua::setField(L, "itemStorageValue", shopBlock.itemStorageValue); createNpcTypeShopLuaTable(L, shopBlock.childShop); lua_setfield(L, -2, "childShop"); @@ -37,21 +96,21 @@ void NpcTypeFunctions::createNpcTypeShopLuaTable(lua_State* L, const std::vector int NpcTypeFunctions::luaNpcTypeCreate(lua_State* L) { // NpcType(name) - const auto &npcType = g_npcs().getNpcType(getString(L, 1), true); - pushUserdata(L, npcType); - setMetatable(L, -1, "NpcType"); + const auto &npcType = g_npcs().getNpcType(Lua::getString(L, 1), true); + Lua::pushUserdata(L, npcType); + Lua::setMetatable(L, -1, "NpcType"); return 1; } int NpcTypeFunctions::luaNpcTypeIsPushable(lua_State* L) { // get: npcType:isPushable() set: npcType:isPushable(bool) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushBoolean(L, npcType->info.pushable); + Lua::pushBoolean(L, npcType->info.pushable); } else { - npcType->info.pushable = getBoolean(L, 2); - pushBoolean(L, true); + npcType->info.pushable = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -61,13 +120,13 @@ int NpcTypeFunctions::luaNpcTypeIsPushable(lua_State* L) { int NpcTypeFunctions::luaNpcTypeFloorChange(lua_State* L) { // get: npcType:floorChange() set: npcType:floorChange(bool) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushBoolean(L, npcType->info.floorChange); + Lua::pushBoolean(L, npcType->info.floorChange); } else { - npcType->info.floorChange = getBoolean(L, 2); - pushBoolean(L, true); + npcType->info.floorChange = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -77,10 +136,10 @@ int NpcTypeFunctions::luaNpcTypeFloorChange(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanSpawn(lua_State* L) { // monsterType:canSpawn(pos) - const auto &npcType = getUserdataShared(L, 1); - const Position &position = getPosition(L, 2); + const auto &npcType = Lua::getUserdataShared(L, 1); + const Position &position = Lua::getPosition(L, 2); if (npcType) { - pushBoolean(L, npcType->canSpawn(position)); + Lua::pushBoolean(L, npcType->canSpawn(position)); } else { lua_pushnil(L); } @@ -89,13 +148,13 @@ int NpcTypeFunctions::luaNpcTypeCanSpawn(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanPushItems(lua_State* L) { // get: npcType:canPushItems() set: npcType:canPushItems(bool) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushBoolean(L, npcType->info.canPushItems); + Lua::pushBoolean(L, npcType->info.canPushItems); } else { - npcType->info.canPushItems = getBoolean(L, 2); - pushBoolean(L, true); + npcType->info.canPushItems = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -105,13 +164,13 @@ int NpcTypeFunctions::luaNpcTypeCanPushItems(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCanPushCreatures(lua_State* L) { // get: npcType:canPushCreatures() set: npcType:canPushCreatures(bool) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushBoolean(L, npcType->info.canPushCreatures); + Lua::pushBoolean(L, npcType->info.canPushCreatures); } else { - npcType->info.canPushCreatures = getBoolean(L, 2); - pushBoolean(L, true); + npcType->info.canPushCreatures = Lua::getBoolean(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -121,13 +180,13 @@ int NpcTypeFunctions::luaNpcTypeCanPushCreatures(lua_State* L) { int32_t NpcTypeFunctions::luaNpcTypeName(lua_State* L) { // get: npcType:name() set: npcType:name(name) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushString(L, npcType->name); + Lua::pushString(L, npcType->name); } else { - npcType->name = getString(L, 2); - pushBoolean(L, true); + npcType->name = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -137,13 +196,13 @@ int32_t NpcTypeFunctions::luaNpcTypeName(lua_State* L) { int NpcTypeFunctions::luaNpcTypeNameDescription(lua_State* L) { // get: npcType:nameDescription() set: npcType:nameDescription(desc) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushString(L, npcType->nameDescription); + Lua::pushString(L, npcType->nameDescription); } else { - npcType->nameDescription = getString(L, 2); - pushBoolean(L, true); + npcType->nameDescription = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -153,13 +212,13 @@ int NpcTypeFunctions::luaNpcTypeNameDescription(lua_State* L) { int NpcTypeFunctions::luaNpcTypeHealth(lua_State* L) { // get: npcType:health() set: npcType:health(health) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.health); } else { - npcType->info.health = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.health = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -169,13 +228,13 @@ int NpcTypeFunctions::luaNpcTypeHealth(lua_State* L) { int NpcTypeFunctions::luaNpcTypeMaxHealth(lua_State* L) { // get: npcType:maxHealth() set: npcType:maxHealth(health) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.healthMax); } else { - npcType->info.healthMax = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.healthMax = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -185,16 +244,16 @@ int NpcTypeFunctions::luaNpcTypeMaxHealth(lua_State* L) { int NpcTypeFunctions::luaNpcTypeAddShopItem(lua_State* L) { // npcType:addShopItem(shop) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; } - const auto &shop = getUserdataShared(L, 2); + const auto &shop = Lua::getUserdataShared(L, 2); if (shop) { npcType->loadShop(npcType, shop->shopBlock); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -203,15 +262,15 @@ int NpcTypeFunctions::luaNpcTypeAddShopItem(lua_State* L) { int NpcTypeFunctions::luaNpcTypeAddVoice(lua_State* L) { // npcType:addVoice(sentence, interval, chance, yell) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { voiceBlock_t voice; - voice.text = getString(L, 2); - npcType->info.yellSpeedTicks = getNumber(L, 3); - npcType->info.yellChance = getNumber(L, 4); - voice.yellText = getBoolean(L, 5); + voice.text = Lua::getString(L, 2); + npcType->info.yellSpeedTicks = Lua::getNumber(L, 3); + npcType->info.yellChance = Lua::getNumber(L, 4); + voice.yellText = Lua::getBoolean(L, 5); npcType->info.voiceVector.push_back(voice); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -220,7 +279,7 @@ int NpcTypeFunctions::luaNpcTypeAddVoice(lua_State* L) { int NpcTypeFunctions::luaNpcTypeGetVoices(lua_State* L) { // npcType:getVoices() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -230,8 +289,8 @@ int NpcTypeFunctions::luaNpcTypeGetVoices(lua_State* L) { lua_createtable(L, npcType->info.voiceVector.size(), 0); for (const auto &voiceBlock : npcType->info.voiceVector) { lua_createtable(L, 0, 2); - setField(L, "text", voiceBlock.text); - setField(L, "yellText", voiceBlock.yellText); + Lua::setField(L, "text", voiceBlock.text); + Lua::setField(L, "yellText", voiceBlock.yellText); lua_rawseti(L, -2, ++index); } return 1; @@ -239,7 +298,7 @@ int NpcTypeFunctions::luaNpcTypeGetVoices(lua_State* L) { int NpcTypeFunctions::luaNpcTypeGetCreatureEvents(lua_State* L) { // npcType:getCreatureEvents() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -248,7 +307,7 @@ int NpcTypeFunctions::luaNpcTypeGetCreatureEvents(lua_State* L) { int index = 0; lua_createtable(L, npcType->info.scripts.size(), 0); for (const std::string &creatureEvent : npcType->info.scripts) { - pushString(L, creatureEvent); + Lua::pushString(L, creatureEvent); lua_rawseti(L, -2, ++index); } return 1; @@ -256,10 +315,10 @@ int NpcTypeFunctions::luaNpcTypeGetCreatureEvents(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRegisterEvent(lua_State* L) { // npcType:registerEvent(name) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { - npcType->info.scripts.insert(getString(L, 2)); - pushBoolean(L, true); + npcType->info.scripts.insert(Lua::getString(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -275,13 +334,13 @@ int NpcTypeFunctions::luaNpcTypeEventOnCallback(lua_State* L) { // npcType:onBuyItem(callback) // npcType:onSellItem(callback) // npcType:onCheckItem(callback) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (npcType->loadCallback(&g_scripts().getScriptInterface())) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else { lua_pushnil(L); } @@ -290,10 +349,10 @@ int NpcTypeFunctions::luaNpcTypeEventOnCallback(lua_State* L) { int NpcTypeFunctions::luaNpcTypeEventType(lua_State* L) { // npcType:eventType(event) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { - npcType->info.eventType = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.eventType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -302,18 +361,18 @@ int NpcTypeFunctions::luaNpcTypeEventType(lua_State* L) { int NpcTypeFunctions::luaNpcTypeOutfit(lua_State* L) { // get: npcType:outfit() set: npcType:outfit(outfit) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { - pushOutfit(L, npcType->info.outfit); + Lua::pushOutfit(L, npcType->info.outfit); } else { - Outfit_t outfit = getOutfit(L, 2); + Outfit_t outfit = Lua::getOutfit(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && outfit.lookType != 0 && !g_game().isLookTypeRegistered(outfit.lookType)) { g_logger().warn("[NpcTypeFunctions::luaNpcTypeOutfit] An unregistered creature looktype type with id '{}' was blocked to prevent client crash.", outfit.lookType); lua_pushnil(L); } else { - npcType->info.outfit = getOutfit(L, 2); - pushBoolean(L, true); + npcType->info.outfit = Lua::getOutfit(L, 2); + Lua::pushBoolean(L, true); } } } else { @@ -324,13 +383,13 @@ int NpcTypeFunctions::luaNpcTypeOutfit(lua_State* L) { int NpcTypeFunctions::luaNpcTypeBaseSpeed(lua_State* L) { // npcType:getBaseSpeed() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.baseSpeed); } else { - npcType->info.baseSpeed = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.baseSpeed = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -340,12 +399,12 @@ int NpcTypeFunctions::luaNpcTypeBaseSpeed(lua_State* L) { int NpcTypeFunctions::luaNpcTypeWalkInterval(lua_State* L) { // get: npcType:walkInterval() set: npcType:walkInterval(interval) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.walkInterval); } else { - npcType->info.walkInterval = getNumber(L, 2); + npcType->info.walkInterval = Lua::getNumber(L, 2); lua_pushboolean(L, true); } } else { @@ -356,12 +415,12 @@ int NpcTypeFunctions::luaNpcTypeWalkInterval(lua_State* L) { int NpcTypeFunctions::luaNpcTypeWalkRadius(lua_State* L) { // get: npcType:walkRadius() set: npcType:walkRadius(id) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.walkRadius); } else { - npcType->info.walkRadius = getNumber(L, 2); + npcType->info.walkRadius = Lua::getNumber(L, 2); lua_pushboolean(L, true); } } else { @@ -372,7 +431,7 @@ int NpcTypeFunctions::luaNpcTypeWalkRadius(lua_State* L) { int NpcTypeFunctions::luaNpcTypeLight(lua_State* L) { // get: npcType:light() set: npcType:light(color, level) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; @@ -383,27 +442,27 @@ int NpcTypeFunctions::luaNpcTypeLight(lua_State* L) { lua_pushnumber(L, npcType->info.light.color); return 2; } else { - npcType->info.light.color = getNumber(L, 2); - npcType->info.light.level = getNumber(L, 3); - pushBoolean(L, true); + npcType->info.light.color = Lua::getNumber(L, 2); + npcType->info.light.level = Lua::getNumber(L, 3); + Lua::pushBoolean(L, true); } return 1; } int NpcTypeFunctions::luaNpcTypeYellChance(lua_State* L) { // get: npcType:yellChance() set: npcType:yellChance(chance) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.yellChance); } else { - npcType->info.yellChance = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.yellChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { - npcType->info.yellChance = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.yellChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -413,13 +472,13 @@ int NpcTypeFunctions::luaNpcTypeYellChance(lua_State* L) { int NpcTypeFunctions::luaNpcTypeYellSpeedTicks(lua_State* L) { // get: npcType:yellSpeedTicks() set: npcType:yellSpeedTicks(rate) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.yellSpeedTicks); } else { - npcType->info.yellSpeedTicks = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.yellSpeedTicks = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -433,13 +492,13 @@ int NpcTypeFunctions::luaNpcTypeYellSpeedTicks(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRespawnTypePeriod(lua_State* L) { // npcType:respawnTypePeriod() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.respawnType.period); } else { - npcType->info.respawnType.period = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.respawnType.period = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -449,13 +508,13 @@ int NpcTypeFunctions::luaNpcTypeRespawnTypePeriod(lua_State* L) { int NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground(lua_State* L) { // npcType:respawnTypeIsUnderground() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (npcType) { if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.respawnType.underground); } else { - npcType->info.respawnType.underground = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.respawnType.underground = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -466,18 +525,18 @@ int NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground(lua_State* L) { int NpcTypeFunctions::luaNpcTypeSpeechBubble(lua_State* L) { // get = npcType:speechBubble() // set = npcType:speechBubble(newSpeechBubble) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.speechBubble); } else { - npcType->info.speechBubble = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.speechBubble = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } @@ -485,75 +544,75 @@ int NpcTypeFunctions::luaNpcTypeSpeechBubble(lua_State* L) { int NpcTypeFunctions::luaNpcTypeCurrency(lua_State* L) { // get = npcType:currency() // set = npcType:currency(newCurrency) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.currencyId); } else { - npcType->info.currencyId = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.currencyId = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int NpcTypeFunctions::luaNpcTypeSoundChance(lua_State* L) { // get: npcType:soundChance() set: npcType:soundChance(chance) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.soundChance); } else { - npcType->info.soundChance = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.soundChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int NpcTypeFunctions::luaNpcTypeSoundSpeedTicks(lua_State* L) { // get: npcType:soundSpeedTicks() set: npcType:soundSpeedTicks(ticks) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } if (lua_gettop(L) == 1) { lua_pushnumber(L, npcType->info.soundSpeedTicks); } else { - npcType->info.soundSpeedTicks = getNumber(L, 2); - pushBoolean(L, true); + npcType->info.soundSpeedTicks = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } return 1; } int NpcTypeFunctions::luaNpcTypeAddSound(lua_State* L) { // npcType:addSound(soundId) - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { - reportErrorFunc(getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_NPC_TYPE_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - npcType->info.soundVector.push_back(getNumber(L, 2)); - pushBoolean(L, true); + npcType->info.soundVector.push_back(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int NpcTypeFunctions::luaNpcTypeGetSounds(lua_State* L) { // npcType:getSounds() - const auto &npcType = getUserdataShared(L, 1); + const auto &npcType = Lua::getUserdataShared(L, 1); if (!npcType) { lua_pushnil(L); return 1; diff --git a/src/lua/functions/creatures/npc/npc_type_functions.hpp b/src/lua/functions/creatures/npc/npc_type_functions.hpp index ee54f124992..1c40cb8ccfc 100644 --- a/src/lua/functions/creatures/npc/npc_type_functions.hpp +++ b/src/lua/functions/creatures/npc/npc_type_functions.hpp @@ -9,73 +9,11 @@ #pragma once -#include "lua/scripts/luascript.hpp" +struct ShopBlock; -class NpcTypeFunctions final : LuaScriptInterface { +class NpcTypeFunctions { public: - explicit NpcTypeFunctions(lua_State* L) : - LuaScriptInterface("NpcTypeFunctions") { - init(L); - } - ~NpcTypeFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "NpcType", "", NpcTypeFunctions::luaNpcTypeCreate); - registerMetaMethod(L, "NpcType", "__eq", NpcTypeFunctions::luaUserdataCompare); - - registerMethod(L, "NpcType", "isPushable", NpcTypeFunctions::luaNpcTypeIsPushable); - registerMethod(L, "NpcType", "floorChange", NpcTypeFunctions::luaNpcTypeFloorChange); - - registerMethod(L, "NpcType", "canSpawn", NpcTypeFunctions::luaNpcTypeCanSpawn); - - registerMethod(L, "NpcType", "canPushItems", NpcTypeFunctions::luaNpcTypeCanPushItems); - registerMethod(L, "NpcType", "canPushCreatures", NpcTypeFunctions::luaNpcTypeCanPushCreatures); - - registerMethod(L, "NpcType", "name", NpcTypeFunctions::luaNpcTypeName); - - registerMethod(L, "NpcType", "nameDescription", NpcTypeFunctions::luaNpcTypeNameDescription); - - registerMethod(L, "NpcType", "health", NpcTypeFunctions::luaNpcTypeHealth); - registerMethod(L, "NpcType", "maxHealth", NpcTypeFunctions::luaNpcTypeMaxHealth); - - registerMethod(L, "NpcType", "getVoices", NpcTypeFunctions::luaNpcTypeGetVoices); - registerMethod(L, "NpcType", "addVoice", NpcTypeFunctions::luaNpcTypeAddVoice); - - registerMethod(L, "NpcType", "getCreatureEvents", NpcTypeFunctions::luaNpcTypeGetCreatureEvents); - registerMethod(L, "NpcType", "registerEvent", NpcTypeFunctions::luaNpcTypeRegisterEvent); - - registerMethod(L, "NpcType", "eventType", NpcTypeFunctions::luaNpcTypeEventType); - registerMethod(L, "NpcType", "onThink", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onAppear", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onDisappear", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onMove", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onSay", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onCloseChannel", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onBuyItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onSellItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); - registerMethod(L, "NpcType", "onCheckItem", NpcTypeFunctions::luaNpcTypeEventOnCallback); - - registerMethod(L, "NpcType", "outfit", NpcTypeFunctions::luaNpcTypeOutfit); - registerMethod(L, "NpcType", "baseSpeed", NpcTypeFunctions::luaNpcTypeBaseSpeed); - registerMethod(L, "NpcType", "walkInterval", NpcTypeFunctions::luaNpcTypeWalkInterval); - registerMethod(L, "NpcType", "walkRadius", NpcTypeFunctions::luaNpcTypeWalkRadius); - registerMethod(L, "NpcType", "light", NpcTypeFunctions::luaNpcTypeLight); - - registerMethod(L, "NpcType", "yellChance", NpcTypeFunctions::luaNpcTypeYellChance); - registerMethod(L, "NpcType", "yellSpeedTicks", NpcTypeFunctions::luaNpcTypeYellSpeedTicks); - - registerMethod(L, "NpcType", "respawnTypePeriod", NpcTypeFunctions::luaNpcTypeRespawnTypePeriod); - registerMethod(L, "NpcType", "respawnTypeIsUnderground", NpcTypeFunctions::luaNpcTypeRespawnTypeIsUnderground); - registerMethod(L, "NpcType", "speechBubble", NpcTypeFunctions::luaNpcTypeSpeechBubble); - registerMethod(L, "NpcType", "currency", NpcTypeFunctions::luaNpcTypeCurrency); - - registerMethod(L, "NpcType", "addShopItem", NpcTypeFunctions::luaNpcTypeAddShopItem); - - registerMethod(L, "NpcType", "soundChance", NpcTypeFunctions::luaNpcTypeSoundChance); - registerMethod(L, "NpcType", "soundSpeedTicks", NpcTypeFunctions::luaNpcTypeSoundSpeedTicks); - registerMethod(L, "NpcType", "addSound", NpcTypeFunctions::luaNpcTypeAddSound); - registerMethod(L, "NpcType", "getSounds", NpcTypeFunctions::luaNpcTypeGetSounds); - } + static void init(lua_State* L); private: static void createNpcTypeShopLuaTable(lua_State* L, const std::vector &shopVector); @@ -83,7 +21,6 @@ class NpcTypeFunctions final : LuaScriptInterface { static int luaNpcTypeIsPushable(lua_State* L); static int luaNpcTypeFloorChange(lua_State* L); - static int luaNpcTypeRespawnType(lua_State* L); static int luaNpcTypeCanSpawn(lua_State* L); static int luaNpcTypeCanPushItems(lua_State* L); diff --git a/src/lua/functions/creatures/npc/shop_functions.cpp b/src/lua/functions/creatures/npc/shop_functions.cpp index 7ba7f89d43f..04d62ae585b 100644 --- a/src/lua/functions/creatures/npc/shop_functions.cpp +++ b/src/lua/functions/creatures/npc/shop_functions.cpp @@ -13,21 +13,35 @@ #include "items/item.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ShopFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Shop", "", ShopFunctions::luaCreateShop); + Lua::registerMethod(L, "Shop", "setId", ShopFunctions::luaShopSetId); + Lua::registerMethod(L, "Shop", "setIdFromName", ShopFunctions::luaShopSetIdFromName); + Lua::registerMethod(L, "Shop", "setNameItem", ShopFunctions::luaShopSetNameItem); + Lua::registerMethod(L, "Shop", "setCount", ShopFunctions::luaShopSetCount); + Lua::registerMethod(L, "Shop", "setBuyPrice", ShopFunctions::luaShopSetBuyPrice); + Lua::registerMethod(L, "Shop", "setSellPrice", ShopFunctions::luaShopSetSellPrice); + Lua::registerMethod(L, "Shop", "setStorageKey", ShopFunctions::luaShopSetStorageKey); + Lua::registerMethod(L, "Shop", "setStorageValue", ShopFunctions::luaShopSetStorageValue); + Lua::registerMethod(L, "Shop", "addChildShop", ShopFunctions::luaShopAddChildShop); +} int ShopFunctions::luaCreateShop(lua_State* L) { // Shop() will create a new shop item - pushUserdata(L, std::make_shared()); - setMetatable(L, -1, "Shop"); + Lua::pushUserdata(L, std::make_shared()); + Lua::setMetatable(L, -1, "Shop"); return 1; } int ShopFunctions::luaShopSetId(lua_State* L) { // shop:setId(id) - if (const auto &shop = getUserdataShared(L, 1)) { - if (isNumber(L, 2)) { - shop->shopBlock.itemId = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + if (Lua::isNumber(L, 2)) { + shop->shopBlock.itemId = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { g_logger().warn("[ShopFunctions::luaShopSetId] - " "Unknown shop item shop, int value expected"); @@ -41,9 +55,9 @@ int ShopFunctions::luaShopSetId(lua_State* L) { int ShopFunctions::luaShopSetIdFromName(lua_State* L) { // shop:setIdFromName(name) - const auto &shop = getUserdataShared(L, 1); - if (shop && isString(L, 2)) { - auto name = getString(L, 2); + const auto &shop = Lua::getUserdataShared(L, 1); + if (shop && Lua::isString(L, 2)) { + auto name = Lua::getString(L, 2); const auto ids = Item::items.nameToItems.equal_range(asLowerCaseString(name)); if (ids.first == Item::items.nameToItems.cend()) { @@ -63,7 +77,7 @@ int ShopFunctions::luaShopSetIdFromName(lua_State* L) { } shop->shopBlock.itemId = ids.first->second; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { g_logger().warn("[ShopFunctions::luaShopSetIdFromName] - " "Unknown shop item shop, string value expected"); @@ -74,9 +88,9 @@ int ShopFunctions::luaShopSetIdFromName(lua_State* L) { int ShopFunctions::luaShopSetNameItem(lua_State* L) { // shop:setNameItem(name) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemName = getString(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemName = Lua::getString(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -85,9 +99,9 @@ int ShopFunctions::luaShopSetNameItem(lua_State* L) { int ShopFunctions::luaShopSetCount(lua_State* L) { // shop:setCount(count) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemSubType = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemSubType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -96,9 +110,9 @@ int ShopFunctions::luaShopSetCount(lua_State* L) { int ShopFunctions::luaShopSetBuyPrice(lua_State* L) { // shop:setBuyPrice(price) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemBuyPrice = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemBuyPrice = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -107,9 +121,9 @@ int ShopFunctions::luaShopSetBuyPrice(lua_State* L) { int ShopFunctions::luaShopSetSellPrice(lua_State* L) { // shop:setSellPrice(chance) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemSellPrice = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemSellPrice = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -118,9 +132,9 @@ int ShopFunctions::luaShopSetSellPrice(lua_State* L) { int ShopFunctions::luaShopSetStorageKey(lua_State* L) { // shop:setStorageKey(storage) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemStorageKey = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemStorageKey = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -129,9 +143,9 @@ int ShopFunctions::luaShopSetStorageKey(lua_State* L) { int ShopFunctions::luaShopSetStorageValue(lua_State* L) { // shop:setStorageValue(value) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.itemStorageValue = getNumber(L, 2); - pushBoolean(L, true); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.itemStorageValue = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -140,8 +154,8 @@ int ShopFunctions::luaShopSetStorageValue(lua_State* L) { int ShopFunctions::luaShopAddChildShop(lua_State* L) { // shop:addChildShop(shop) - if (const auto &shop = getUserdataShared(L, 1)) { - shop->shopBlock.childShop.push_back(getUserdataShared(L, 2)->shopBlock); + if (const auto &shop = Lua::getUserdataShared(L, 1)) { + shop->shopBlock.childShop.push_back(Lua::getUserdataShared(L, 2)->shopBlock); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/npc/shop_functions.hpp b/src/lua/functions/creatures/npc/shop_functions.hpp index 2d326ff73e2..7bd91568601 100644 --- a/src/lua/functions/creatures/npc/shop_functions.hpp +++ b/src/lua/functions/creatures/npc/shop_functions.hpp @@ -9,28 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ShopFunctions final : LuaScriptInterface { +class ShopFunctions { public: - explicit ShopFunctions(lua_State* L) : - LuaScriptInterface("ShopFunctions") { - init(L); - } - ~ShopFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Shop", "", ShopFunctions::luaCreateShop); - registerMethod(L, "Shop", "setId", ShopFunctions::luaShopSetId); - registerMethod(L, "Shop", "setIdFromName", ShopFunctions::luaShopSetIdFromName); - registerMethod(L, "Shop", "setNameItem", ShopFunctions::luaShopSetNameItem); - registerMethod(L, "Shop", "setCount", ShopFunctions::luaShopSetCount); - registerMethod(L, "Shop", "setBuyPrice", ShopFunctions::luaShopSetBuyPrice); - registerMethod(L, "Shop", "setSellPrice", ShopFunctions::luaShopSetSellPrice); - registerMethod(L, "Shop", "setStorageKey", ShopFunctions::luaShopSetStorageKey); - registerMethod(L, "Shop", "setStorageValue", ShopFunctions::luaShopSetStorageValue); - registerMethod(L, "Shop", "addChildShop", ShopFunctions::luaShopAddChildShop); - } + static void init(lua_State* L); private: static int luaCreateShop(lua_State* L); diff --git a/src/lua/functions/creatures/player/group_functions.cpp b/src/lua/functions/creatures/player/group_functions.cpp index 66003a64926..0c538a10eef 100644 --- a/src/lua/functions/creatures/player/group_functions.cpp +++ b/src/lua/functions/creatures/player/group_functions.cpp @@ -11,15 +11,29 @@ #include "creatures/players/grouping/groups.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void GroupFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Group", "", GroupFunctions::luaGroupCreate); + Lua::registerMetaMethod(L, "Group", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Group", "getId", GroupFunctions::luaGroupGetId); + Lua::registerMethod(L, "Group", "getName", GroupFunctions::luaGroupGetName); + Lua::registerMethod(L, "Group", "getFlags", GroupFunctions::luaGroupGetFlags); + Lua::registerMethod(L, "Group", "getAccess", GroupFunctions::luaGroupGetAccess); + Lua::registerMethod(L, "Group", "getMaxDepotItems", GroupFunctions::luaGroupGetMaxDepotItems); + Lua::registerMethod(L, "Group", "getMaxVipEntries", GroupFunctions::luaGroupGetMaxVipEntries); + Lua::registerMethod(L, "Group", "hasFlag", GroupFunctions::luaGroupHasFlag); +} int GroupFunctions::luaGroupCreate(lua_State* L) { // Group(id) - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); const auto &group = g_game().groups.getGroup(id); if (group) { - pushUserdata(L, group); - setMetatable(L, -1, "Group"); + Lua::pushUserdata(L, group); + Lua::setMetatable(L, -1, "Group"); } else { lua_pushnil(L); } @@ -28,7 +42,7 @@ int GroupFunctions::luaGroupCreate(lua_State* L) { int GroupFunctions::luaGroupGetId(lua_State* L) { // group:getId() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { lua_pushnumber(L, group->id); } else { @@ -39,9 +53,9 @@ int GroupFunctions::luaGroupGetId(lua_State* L) { int GroupFunctions::luaGroupGetName(lua_State* L) { // group:getName() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { - pushString(L, group->name); + Lua::pushString(L, group->name); } else { lua_pushnil(L); } @@ -50,7 +64,7 @@ int GroupFunctions::luaGroupGetName(lua_State* L) { int GroupFunctions::luaGroupGetFlags(lua_State* L) { // group:getFlags() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { std::bitset flags; for (uint8_t i = 0; i < magic_enum::enum_integer(PlayerFlags_t::FlagLast); ++i) { @@ -67,9 +81,9 @@ int GroupFunctions::luaGroupGetFlags(lua_State* L) { int GroupFunctions::luaGroupGetAccess(lua_State* L) { // group:getAccess() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { - pushBoolean(L, group->access); + Lua::pushBoolean(L, group->access); } else { lua_pushnil(L); } @@ -78,7 +92,7 @@ int GroupFunctions::luaGroupGetAccess(lua_State* L) { int GroupFunctions::luaGroupGetMaxDepotItems(lua_State* L) { // group:getMaxDepotItems() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { lua_pushnumber(L, group->maxDepotItems); } else { @@ -89,7 +103,7 @@ int GroupFunctions::luaGroupGetMaxDepotItems(lua_State* L) { int GroupFunctions::luaGroupGetMaxVipEntries(lua_State* L) { // group:getMaxVipEntries() - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { lua_pushnumber(L, group->maxVipEntries); } else { @@ -100,10 +114,10 @@ int GroupFunctions::luaGroupGetMaxVipEntries(lua_State* L) { int GroupFunctions::luaGroupHasFlag(lua_State* L) { // group:hasFlag(flag) - const auto &group = getUserdataShared(L, 1); + const auto &group = Lua::getUserdataShared(L, 1); if (group) { - const auto flag = static_cast(getNumber(L, 2)); - pushBoolean(L, group->flags[Groups::getFlagNumber(flag)]); + const auto flag = static_cast(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, group->flags[Groups::getFlagNumber(flag)]); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/player/group_functions.hpp b/src/lua/functions/creatures/player/group_functions.hpp index 7729690b771..76774df5bb2 100644 --- a/src/lua/functions/creatures/player/group_functions.hpp +++ b/src/lua/functions/creatures/player/group_functions.hpp @@ -9,28 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class GroupFunctions final : LuaScriptInterface { +class GroupFunctions { public: - explicit GroupFunctions(lua_State* L) : - LuaScriptInterface("GroupFunctions") { - init(L); - } - ~GroupFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Group", "", GroupFunctions::luaGroupCreate); - registerMetaMethod(L, "Group", "__eq", GroupFunctions::luaUserdataCompare); - - registerMethod(L, "Group", "getId", GroupFunctions::luaGroupGetId); - registerMethod(L, "Group", "getName", GroupFunctions::luaGroupGetName); - registerMethod(L, "Group", "getFlags", GroupFunctions::luaGroupGetFlags); - registerMethod(L, "Group", "getAccess", GroupFunctions::luaGroupGetAccess); - registerMethod(L, "Group", "getMaxDepotItems", GroupFunctions::luaGroupGetMaxDepotItems); - registerMethod(L, "Group", "getMaxVipEntries", GroupFunctions::luaGroupGetMaxVipEntries); - registerMethod(L, "Group", "hasFlag", GroupFunctions::luaGroupHasFlag); - } + static void init(lua_State* L); private: static int luaGroupCreate(lua_State* L); diff --git a/src/lua/functions/creatures/player/guild_functions.cpp b/src/lua/functions/creatures/player/guild_functions.cpp index 808a5725ea5..62082d4f43a 100644 --- a/src/lua/functions/creatures/player/guild_functions.cpp +++ b/src/lua/functions/creatures/player/guild_functions.cpp @@ -11,13 +11,33 @@ #include "game/game.hpp" #include "creatures/players/grouping/guild.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void GuildFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Guild", "", GuildFunctions::luaGuildCreate); + Lua::registerMetaMethod(L, "Guild", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Guild", "getId", GuildFunctions::luaGuildGetId); + Lua::registerMethod(L, "Guild", "getName", GuildFunctions::luaGuildGetName); + Lua::registerMethod(L, "Guild", "getMembersOnline", GuildFunctions::luaGuildGetMembersOnline); + + Lua::registerMethod(L, "Guild", "getBankBalance", GuildFunctions::luaGuildGetBankBalance); + Lua::registerMethod(L, "Guild", "setBankBalance", GuildFunctions::luaGuildSetBankBalance); + + Lua::registerMethod(L, "Guild", "addRank", GuildFunctions::luaGuildAddRank); + Lua::registerMethod(L, "Guild", "getRankById", GuildFunctions::luaGuildGetRankById); + Lua::registerMethod(L, "Guild", "getRankByLevel", GuildFunctions::luaGuildGetRankByLevel); + + Lua::registerMethod(L, "Guild", "getMotd", GuildFunctions::luaGuildGetMotd); + Lua::registerMethod(L, "Guild", "setMotd", GuildFunctions::luaGuildSetMotd); +} int GuildFunctions::luaGuildCreate(lua_State* L) { - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); const auto &guild = g_game().getGuild(id); if (guild) { - pushUserdata(L, guild); - setMetatable(L, -1, "Guild"); + Lua::pushUserdata(L, guild); + Lua::setMetatable(L, -1, "Guild"); } else { lua_pushnil(L); } @@ -25,7 +45,7 @@ int GuildFunctions::luaGuildCreate(lua_State* L) { } int GuildFunctions::luaGuildGetId(lua_State* L) { - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (guild) { lua_pushnumber(L, guild->getId()); } else { @@ -36,18 +56,18 @@ int GuildFunctions::luaGuildGetId(lua_State* L) { int GuildFunctions::luaGuildGetName(lua_State* L) { // guild:getName() - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - pushString(L, guild->getName()); + Lua::pushString(L, guild->getName()); return 1; } int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { // guild:getMembersOnline() - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; @@ -58,8 +78,8 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { int index = 0; for (const auto &player : members) { - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); } return 1; @@ -67,7 +87,7 @@ int GuildFunctions::luaGuildGetMembersOnline(lua_State* L) { int GuildFunctions::luaGuildGetBankBalance(lua_State* L) { // guild:getBankBalance() - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; @@ -78,47 +98,47 @@ int GuildFunctions::luaGuildGetBankBalance(lua_State* L) { int GuildFunctions::luaGuildSetBankBalance(lua_State* L) { // guild:setBankBalance(bankBalance) - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - guild->setBankBalance(getNumber(L, 2)); - pushBoolean(L, true); + guild->setBankBalance(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int GuildFunctions::luaGuildAddRank(lua_State* L) { // guild:addRank(id, name, level) - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - const uint32_t id = getNumber(L, 2); - const std::string &name = getString(L, 3); - const uint8_t level = getNumber(L, 4); + const uint32_t id = Lua::getNumber(L, 2); + const std::string &name = Lua::getString(L, 3); + const uint8_t level = Lua::getNumber(L, 4); guild->addRank(id, name, level); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int GuildFunctions::luaGuildGetRankById(lua_State* L) { // guild:getRankById(id) - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); const GuildRank_ptr rank = guild->getRankById(id); if (rank) { lua_createtable(L, 0, 3); - setField(L, "id", rank->id); - setField(L, "name", rank->name); - setField(L, "level", rank->level); + Lua::setField(L, "id", rank->id); + Lua::setField(L, "name", rank->name); + Lua::setField(L, "level", rank->level); } else { lua_pushnil(L); } @@ -127,19 +147,19 @@ int GuildFunctions::luaGuildGetRankById(lua_State* L) { int GuildFunctions::luaGuildGetRankByLevel(lua_State* L) { // guild:getRankByLevel(level) - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - const uint8_t level = getNumber(L, 2); + const uint8_t level = Lua::getNumber(L, 2); const GuildRank_ptr rank = guild->getRankByLevel(level); if (rank) { lua_createtable(L, 0, 3); - setField(L, "id", rank->id); - setField(L, "name", rank->name); - setField(L, "level", rank->level); + Lua::setField(L, "id", rank->id); + Lua::setField(L, "name", rank->name); + Lua::setField(L, "level", rank->level); } else { lua_pushnil(L); } @@ -148,24 +168,24 @@ int GuildFunctions::luaGuildGetRankByLevel(lua_State* L) { int GuildFunctions::luaGuildGetMotd(lua_State* L) { // guild:getMotd() - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - pushString(L, guild->getMotd()); + Lua::pushString(L, guild->getMotd()); return 1; } int GuildFunctions::luaGuildSetMotd(lua_State* L) { // guild:setMotd(motd) - const auto &guild = getUserdataShared(L, 1); + const auto &guild = Lua::getUserdataShared(L, 1); if (!guild) { lua_pushnil(L); return 1; } - const std::string &motd = getString(L, 2); + const std::string &motd = Lua::getString(L, 2); guild->setMotd(motd); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/creatures/player/guild_functions.hpp b/src/lua/functions/creatures/player/guild_functions.hpp index d8f844de751..9c5ded2b63b 100644 --- a/src/lua/functions/creatures/player/guild_functions.hpp +++ b/src/lua/functions/creatures/player/guild_functions.hpp @@ -9,34 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class GuildFunctions final : LuaScriptInterface { +class GuildFunctions { public: - explicit GuildFunctions(lua_State* L) : - LuaScriptInterface("GuildFunctions") { - init(L); - } - ~GuildFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Guild", "", GuildFunctions::luaGuildCreate); - registerMetaMethod(L, "Guild", "__eq", GuildFunctions::luaUserdataCompare); - - registerMethod(L, "Guild", "getId", GuildFunctions::luaGuildGetId); - registerMethod(L, "Guild", "getName", GuildFunctions::luaGuildGetName); - registerMethod(L, "Guild", "getMembersOnline", GuildFunctions::luaGuildGetMembersOnline); - - registerMethod(L, "Guild", "getBankBalance", GuildFunctions::luaGuildGetBankBalance); - registerMethod(L, "Guild", "setBankBalance", GuildFunctions::luaGuildSetBankBalance); - - registerMethod(L, "Guild", "addRank", GuildFunctions::luaGuildAddRank); - registerMethod(L, "Guild", "getRankById", GuildFunctions::luaGuildGetRankById); - registerMethod(L, "Guild", "getRankByLevel", GuildFunctions::luaGuildGetRankByLevel); - - registerMethod(L, "Guild", "getMotd", GuildFunctions::luaGuildGetMotd); - registerMethod(L, "Guild", "setMotd", GuildFunctions::luaGuildSetMotd); - } + static void init(lua_State* L); private: static int luaGuildCreate(lua_State* L); diff --git a/src/lua/functions/creatures/player/mount_functions.cpp b/src/lua/functions/creatures/player/mount_functions.cpp index 7822e4f8ea5..6c6d929ed5c 100644 --- a/src/lua/functions/creatures/player/mount_functions.cpp +++ b/src/lua/functions/creatures/player/mount_functions.cpp @@ -11,22 +11,33 @@ #include "creatures/appearance/mounts/mounts.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void MountFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Mount", "", MountFunctions::luaCreateMount); + Lua::registerMetaMethod(L, "Mount", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Mount", "getName", MountFunctions::luaMountGetName); + Lua::registerMethod(L, "Mount", "getId", MountFunctions::luaMountGetId); + Lua::registerMethod(L, "Mount", "getClientId", MountFunctions::luaMountGetClientId); + Lua::registerMethod(L, "Mount", "getSpeed", MountFunctions::luaMountGetSpeed); +} int MountFunctions::luaCreateMount(lua_State* L) { // Mount(id or name) std::shared_ptr mount; - if (isNumber(L, 2)) { - mount = g_game().mounts->getMountByID(getNumber(L, 2)); - } else if (isString(L, 2)) { - std::string mountName = getString(L, 2); + if (Lua::isNumber(L, 2)) { + mount = g_game().mounts->getMountByID(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + std::string mountName = Lua::getString(L, 2); mount = g_game().mounts->getMountByName(mountName); } else { mount = nullptr; } if (mount) { - pushUserdata(L, mount); - setMetatable(L, -1, "Mount"); + Lua::pushUserdata(L, mount); + Lua::setMetatable(L, -1, "Mount"); } else { lua_pushnil(L); } @@ -36,9 +47,9 @@ int MountFunctions::luaCreateMount(lua_State* L) { int MountFunctions::luaMountGetName(lua_State* L) { // mount:getName() - const auto &mount = getUserdataShared(L, 1); + const auto &mount = Lua::getUserdataShared(L, 1); if (mount) { - pushString(L, mount->name); + Lua::pushString(L, mount->name); } else { lua_pushnil(L); } @@ -48,7 +59,7 @@ int MountFunctions::luaMountGetName(lua_State* L) { int MountFunctions::luaMountGetId(lua_State* L) { // mount:getId() - const auto &mount = getUserdataShared(L, 1); + const auto &mount = Lua::getUserdataShared(L, 1); if (mount) { lua_pushnumber(L, mount->id); } else { @@ -60,7 +71,7 @@ int MountFunctions::luaMountGetId(lua_State* L) { int MountFunctions::luaMountGetClientId(lua_State* L) { // mount:getClientId() - const auto &mount = getUserdataShared(L, 1); + const auto &mount = Lua::getUserdataShared(L, 1); if (mount) { lua_pushnumber(L, mount->clientId); } else { @@ -72,7 +83,7 @@ int MountFunctions::luaMountGetClientId(lua_State* L) { int MountFunctions::luaMountGetSpeed(lua_State* L) { // mount:getSpeed() - const auto &mount = getUserdataShared(L, 1); + const auto &mount = Lua::getUserdataShared(L, 1); if (mount) { lua_pushnumber(L, mount->speed); } else { diff --git a/src/lua/functions/creatures/player/mount_functions.hpp b/src/lua/functions/creatures/player/mount_functions.hpp index a6ce7003ecc..e49e67173e3 100644 --- a/src/lua/functions/creatures/player/mount_functions.hpp +++ b/src/lua/functions/creatures/player/mount_functions.hpp @@ -9,25 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class MountFunctions final : LuaScriptInterface { +class MountFunctions { public: - explicit MountFunctions(lua_State* L) : - LuaScriptInterface("MountFunctions") { - init(L); - } - ~MountFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Mount", "", MountFunctions::luaCreateMount); - registerMetaMethod(L, "Mount", "__eq", MountFunctions::luaUserdataCompare); - - registerMethod(L, "Mount", "getName", MountFunctions::luaMountGetName); - registerMethod(L, "Mount", "getId", MountFunctions::luaMountGetId); - registerMethod(L, "Mount", "getClientId", MountFunctions::luaMountGetClientId); - registerMethod(L, "Mount", "getSpeed", MountFunctions::luaMountGetSpeed); - } + static void init(lua_State* L); private: static int luaCreateMount(lua_State* L); diff --git a/src/lua/functions/creatures/player/party_functions.cpp b/src/lua/functions/creatures/player/party_functions.cpp index 2c420c3ec3f..5c43593282a 100644 --- a/src/lua/functions/creatures/player/party_functions.cpp +++ b/src/lua/functions/creatures/player/party_functions.cpp @@ -12,10 +12,31 @@ #include "creatures/players/grouping/party.hpp" #include "creatures/players/player.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void PartyFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Party", "", PartyFunctions::luaPartyCreate); + Lua::registerMetaMethod(L, "Party", "__eq", Lua::luaUserdataCompare); + Lua::registerMethod(L, "Party", "disband", PartyFunctions::luaPartyDisband); + Lua::registerMethod(L, "Party", "getLeader", PartyFunctions::luaPartyGetLeader); + Lua::registerMethod(L, "Party", "setLeader", PartyFunctions::luaPartySetLeader); + Lua::registerMethod(L, "Party", "getMembers", PartyFunctions::luaPartyGetMembers); + Lua::registerMethod(L, "Party", "getMemberCount", PartyFunctions::luaPartyGetMemberCount); + Lua::registerMethod(L, "Party", "getInvitees", PartyFunctions::luaPartyGetInvitees); + Lua::registerMethod(L, "Party", "getInviteeCount", PartyFunctions::luaPartyGetInviteeCount); + Lua::registerMethod(L, "Party", "addInvite", PartyFunctions::luaPartyAddInvite); + Lua::registerMethod(L, "Party", "removeInvite", PartyFunctions::luaPartyRemoveInvite); + Lua::registerMethod(L, "Party", "addMember", PartyFunctions::luaPartyAddMember); + Lua::registerMethod(L, "Party", "removeMember", PartyFunctions::luaPartyRemoveMember); + Lua::registerMethod(L, "Party", "isSharedExperienceActive", PartyFunctions::luaPartyIsSharedExperienceActive); + Lua::registerMethod(L, "Party", "isSharedExperienceEnabled", PartyFunctions::luaPartyIsSharedExperienceEnabled); + Lua::registerMethod(L, "Party", "shareExperience", PartyFunctions::luaPartyShareExperience); + Lua::registerMethod(L, "Party", "setSharedExperience", PartyFunctions::luaPartySetSharedExperience); +} int32_t PartyFunctions::luaPartyCreate(lua_State* L) { // Party(userdata) - const auto &player = getUserdataShared(L, 2); + const auto &player = Lua::getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; @@ -26,8 +47,8 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { party = Party::create(player); g_game().updatePlayerShield(player); player->sendCreatureSkull(player); - pushUserdata(L, party); - setMetatable(L, -1, "Party"); + Lua::pushUserdata(L, party); + Lua::setMetatable(L, -1, "Party"); } else { lua_pushnil(L); } @@ -36,12 +57,12 @@ int32_t PartyFunctions::luaPartyCreate(lua_State* L) { int PartyFunctions::luaPartyDisband(lua_State* L) { // party:disband() - auto* partyPtr = getRawUserDataShared(L, 1); + auto* partyPtr = Lua::getRawUserDataShared(L, 1); if (partyPtr && *partyPtr) { std::shared_ptr &party = *partyPtr; party->disband(); party = nullptr; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -50,7 +71,7 @@ int PartyFunctions::luaPartyDisband(lua_State* L) { int PartyFunctions::luaPartyGetLeader(lua_State* L) { // party:getLeader() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (!party) { lua_pushnil(L); return 1; @@ -58,8 +79,8 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { const auto &leader = party->getLeader(); if (leader) { - pushUserdata(L, leader); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, leader); + Lua::setMetatable(L, -1, "Player"); } else { lua_pushnil(L); } @@ -68,15 +89,15 @@ int PartyFunctions::luaPartyGetLeader(lua_State* L) { int PartyFunctions::luaPartySetLeader(lua_State* L) { // party:setLeader(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { - pushBoolean(L, party->passPartyLeadership(player)); + Lua::pushBoolean(L, party->passPartyLeadership(player)); } else { lua_pushnil(L); } @@ -85,7 +106,7 @@ int PartyFunctions::luaPartySetLeader(lua_State* L) { int PartyFunctions::luaPartyGetMembers(lua_State* L) { // party:getMembers() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (!party) { lua_pushnil(L); return 1; @@ -94,8 +115,8 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int index = 0; lua_createtable(L, party->getMemberCount(), 0); for (const auto &player : party->getMembers()) { - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); } return 1; @@ -103,7 +124,7 @@ int PartyFunctions::luaPartyGetMembers(lua_State* L) { int PartyFunctions::luaPartyGetMemberCount(lua_State* L) { // party:getMemberCount() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { lua_pushnumber(L, party->getMemberCount()); } else { @@ -114,14 +135,14 @@ int PartyFunctions::luaPartyGetMemberCount(lua_State* L) { int PartyFunctions::luaPartyGetInvitees(lua_State* L) { // party:getInvitees() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { lua_createtable(L, party->getInvitationCount(), 0); int index = 0; for (const auto &player : party->getInvitees()) { - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); lua_rawseti(L, -2, ++index); } } else { @@ -132,7 +153,7 @@ int PartyFunctions::luaPartyGetInvitees(lua_State* L) { int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { // party:getInviteeCount() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { lua_pushnumber(L, party->getInvitationCount()); } else { @@ -143,15 +164,15 @@ int PartyFunctions::luaPartyGetInviteeCount(lua_State* L) { int PartyFunctions::luaPartyAddInvite(lua_State* L) { // party:addInvite(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party && player) { - pushBoolean(L, party->invitePlayer(player)); + Lua::pushBoolean(L, party->invitePlayer(player)); } else { lua_pushnil(L); } @@ -160,15 +181,15 @@ int PartyFunctions::luaPartyAddInvite(lua_State* L) { int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { // party:removeInvite(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party && player) { - pushBoolean(L, party->removeInvite(player)); + Lua::pushBoolean(L, party->removeInvite(player)); } else { lua_pushnil(L); } @@ -177,15 +198,15 @@ int PartyFunctions::luaPartyRemoveInvite(lua_State* L) { int PartyFunctions::luaPartyAddMember(lua_State* L) { // party:addMember(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party && player) { - pushBoolean(L, party->joinParty(player)); + Lua::pushBoolean(L, party->joinParty(player)); } else { lua_pushnil(L); } @@ -194,15 +215,15 @@ int PartyFunctions::luaPartyAddMember(lua_State* L) { int PartyFunctions::luaPartyRemoveMember(lua_State* L) { // party:removeMember(player) - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party && player) { - pushBoolean(L, party->leaveParty(player)); + Lua::pushBoolean(L, party->leaveParty(player)); } else { lua_pushnil(L); } @@ -211,9 +232,9 @@ int PartyFunctions::luaPartyRemoveMember(lua_State* L) { int PartyFunctions::luaPartyIsSharedExperienceActive(lua_State* L) { // party:isSharedExperienceActive() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { - pushBoolean(L, party->isSharedExperienceActive()); + Lua::pushBoolean(L, party->isSharedExperienceActive()); } else { lua_pushnil(L); } @@ -222,9 +243,9 @@ int PartyFunctions::luaPartyIsSharedExperienceActive(lua_State* L) { int PartyFunctions::luaPartyIsSharedExperienceEnabled(lua_State* L) { // party:isSharedExperienceEnabled() - const auto &party = getUserdataShared(L, 1); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { - pushBoolean(L, party->isSharedExperienceEnabled()); + Lua::pushBoolean(L, party->isSharedExperienceEnabled()); } else { lua_pushnil(L); } @@ -233,11 +254,11 @@ int PartyFunctions::luaPartyIsSharedExperienceEnabled(lua_State* L) { int PartyFunctions::luaPartyShareExperience(lua_State* L) { // party:shareExperience(experience) - const uint64_t experience = getNumber(L, 2); - const auto &party = getUserdataShared(L, 1); + const uint64_t experience = Lua::getNumber(L, 2); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { party->shareExperience(experience); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -246,10 +267,10 @@ int PartyFunctions::luaPartyShareExperience(lua_State* L) { int PartyFunctions::luaPartySetSharedExperience(lua_State* L) { // party:setSharedExperience(active) - const bool active = getBoolean(L, 2); - const auto &party = getUserdataShared(L, 1); + const bool active = Lua::getBoolean(L, 2); + const auto &party = Lua::getUserdataShared(L, 1); if (party) { - pushBoolean(L, party->setSharedExperience(party->getLeader(), active)); + Lua::pushBoolean(L, party->setSharedExperience(party->getLeader(), active)); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/player/party_functions.hpp b/src/lua/functions/creatures/player/party_functions.hpp index 79e6a07de71..52801e349d6 100644 --- a/src/lua/functions/creatures/player/party_functions.hpp +++ b/src/lua/functions/creatures/player/party_functions.hpp @@ -9,35 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class PartyFunctions final : LuaScriptInterface { +class PartyFunctions { public: - explicit PartyFunctions(lua_State* L) : - LuaScriptInterface("PartyFunctions") { - init(L); - } - ~PartyFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Party", "", PartyFunctions::luaPartyCreate); - registerMetaMethod(L, "Party", "__eq", PartyFunctions::luaUserdataCompare); - registerMethod(L, "Party", "disband", PartyFunctions::luaPartyDisband); - registerMethod(L, "Party", "getLeader", PartyFunctions::luaPartyGetLeader); - registerMethod(L, "Party", "setLeader", PartyFunctions::luaPartySetLeader); - registerMethod(L, "Party", "getMembers", PartyFunctions::luaPartyGetMembers); - registerMethod(L, "Party", "getMemberCount", PartyFunctions::luaPartyGetMemberCount); - registerMethod(L, "Party", "getInvitees", PartyFunctions::luaPartyGetInvitees); - registerMethod(L, "Party", "getInviteeCount", PartyFunctions::luaPartyGetInviteeCount); - registerMethod(L, "Party", "addInvite", PartyFunctions::luaPartyAddInvite); - registerMethod(L, "Party", "removeInvite", PartyFunctions::luaPartyRemoveInvite); - registerMethod(L, "Party", "addMember", PartyFunctions::luaPartyAddMember); - registerMethod(L, "Party", "removeMember", PartyFunctions::luaPartyRemoveMember); - registerMethod(L, "Party", "isSharedExperienceActive", PartyFunctions::luaPartyIsSharedExperienceActive); - registerMethod(L, "Party", "isSharedExperienceEnabled", PartyFunctions::luaPartyIsSharedExperienceEnabled); - registerMethod(L, "Party", "shareExperience", PartyFunctions::luaPartyShareExperience); - registerMethod(L, "Party", "setSharedExperience", PartyFunctions::luaPartySetSharedExperience); - } + static void init(lua_State* L); private: static int luaPartyCreate(lua_State* L); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index c4c2faa8cee..08045f1de00 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -9,6 +9,7 @@ #include "lua/functions/creatures/player/player_functions.hpp" +#include "account/account.hpp" #include "creatures/appearance/mounts/mounts.hpp" #include "creatures/combat/spells.hpp" #include "creatures/creature.hpp" @@ -32,93 +33,465 @@ #include "items/containers/rewards/reward.hpp" #include "items/item.hpp" #include "map/spectators.hpp" +#include "kv/kv.hpp" #include "enums/account_coins.hpp" #include "enums/account_errors.hpp" #include "enums/player_icons.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void PlayerFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Player", "Creature", PlayerFunctions::luaPlayerCreate); + Lua::registerMetaMethod(L, "Player", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Player", "resetCharmsBestiary", PlayerFunctions::luaPlayerResetCharmsMonsters); + Lua::registerMethod(L, "Player", "unlockAllCharmRunes", PlayerFunctions::luaPlayerUnlockAllCharmRunes); + Lua::registerMethod(L, "Player", "addCharmPoints", PlayerFunctions::luaPlayeraddCharmPoints); + Lua::registerMethod(L, "Player", "isPlayer", PlayerFunctions::luaPlayerIsPlayer); + + Lua::registerMethod(L, "Player", "getGuid", PlayerFunctions::luaPlayerGetGuid); + Lua::registerMethod(L, "Player", "getIp", PlayerFunctions::luaPlayerGetIp); + Lua::registerMethod(L, "Player", "getAccountId", PlayerFunctions::luaPlayerGetAccountId); + Lua::registerMethod(L, "Player", "getLastLoginSaved", PlayerFunctions::luaPlayerGetLastLoginSaved); + Lua::registerMethod(L, "Player", "getLastLogout", PlayerFunctions::luaPlayerGetLastLogout); + + Lua::registerMethod(L, "Player", "getAccountType", PlayerFunctions::luaPlayerGetAccountType); + Lua::registerMethod(L, "Player", "setAccountType", PlayerFunctions::luaPlayerSetAccountType); + + Lua::registerMethod(L, "Player", "isMonsterBestiaryUnlocked", PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked); + Lua::registerMethod(L, "Player", "addBestiaryKill", PlayerFunctions::luaPlayerAddBestiaryKill); + Lua::registerMethod(L, "Player", "charmExpansion", PlayerFunctions::luaPlayercharmExpansion); + Lua::registerMethod(L, "Player", "getCharmMonsterType", PlayerFunctions::luaPlayergetCharmMonsterType); + + Lua::registerMethod(L, "Player", "isMonsterPrey", PlayerFunctions::luaPlayerisMonsterPrey); + Lua::registerMethod(L, "Player", "getPreyCards", PlayerFunctions::luaPlayerGetPreyCards); + Lua::registerMethod(L, "Player", "getPreyLootPercentage", PlayerFunctions::luaPlayerGetPreyLootPercentage); + Lua::registerMethod(L, "Player", "getPreyExperiencePercentage", PlayerFunctions::luaPlayerGetPreyExperiencePercentage); + Lua::registerMethod(L, "Player", "preyThirdSlot", PlayerFunctions::luaPlayerPreyThirdSlot); + Lua::registerMethod(L, "Player", "taskHuntingThirdSlot", PlayerFunctions::luaPlayerTaskThirdSlot); + Lua::registerMethod(L, "Player", "removePreyStamina", PlayerFunctions::luaPlayerRemovePreyStamina); + Lua::registerMethod(L, "Player", "addPreyCards", PlayerFunctions::luaPlayerAddPreyCards); + Lua::registerMethod(L, "Player", "removeTaskHuntingPoints", PlayerFunctions::luaPlayerRemoveTaskHuntingPoints); + Lua::registerMethod(L, "Player", "getTaskHuntingPoints", PlayerFunctions::luaPlayerGetTaskHuntingPoints); + Lua::registerMethod(L, "Player", "addTaskHuntingPoints", PlayerFunctions::luaPlayerAddTaskHuntingPoints); + + Lua::registerMethod(L, "Player", "getCapacity", PlayerFunctions::luaPlayerGetCapacity); + Lua::registerMethod(L, "Player", "setCapacity", PlayerFunctions::luaPlayerSetCapacity); + + Lua::registerMethod(L, "Player", "isTraining", PlayerFunctions::luaPlayerGetIsTraining); + Lua::registerMethod(L, "Player", "setTraining", PlayerFunctions::luaPlayerSetTraining); + + Lua::registerMethod(L, "Player", "getFreeCapacity", PlayerFunctions::luaPlayerGetFreeCapacity); + + Lua::registerMethod(L, "Player", "getKills", PlayerFunctions::luaPlayerGetKills); + Lua::registerMethod(L, "Player", "setKills", PlayerFunctions::luaPlayerSetKills); + + Lua::registerMethod(L, "Player", "getReward", PlayerFunctions::luaPlayerGetReward); + Lua::registerMethod(L, "Player", "removeReward", PlayerFunctions::luaPlayerRemoveReward); + Lua::registerMethod(L, "Player", "getRewardList", PlayerFunctions::luaPlayerGetRewardList); + + Lua::registerMethod(L, "Player", "setDailyReward", PlayerFunctions::luaPlayerSetDailyReward); + + Lua::registerMethod(L, "Player", "sendInventory", PlayerFunctions::luaPlayerSendInventory); + Lua::registerMethod(L, "Player", "sendLootStats", PlayerFunctions::luaPlayerSendLootStats); + Lua::registerMethod(L, "Player", "updateSupplyTracker", PlayerFunctions::luaPlayerUpdateSupplyTracker); + Lua::registerMethod(L, "Player", "updateKillTracker", PlayerFunctions::luaPlayerUpdateKillTracker); + + Lua::registerMethod(L, "Player", "getDepotLocker", PlayerFunctions::luaPlayerGetDepotLocker); + Lua::registerMethod(L, "Player", "getDepotChest", PlayerFunctions::luaPlayerGetDepotChest); + Lua::registerMethod(L, "Player", "getInbox", PlayerFunctions::luaPlayerGetInbox); + + Lua::registerMethod(L, "Player", "getSkullTime", PlayerFunctions::luaPlayerGetSkullTime); + Lua::registerMethod(L, "Player", "setSkullTime", PlayerFunctions::luaPlayerSetSkullTime); + Lua::registerMethod(L, "Player", "getDeathPenalty", PlayerFunctions::luaPlayerGetDeathPenalty); + + Lua::registerMethod(L, "Player", "getExperience", PlayerFunctions::luaPlayerGetExperience); + Lua::registerMethod(L, "Player", "addExperience", PlayerFunctions::luaPlayerAddExperience); + Lua::registerMethod(L, "Player", "removeExperience", PlayerFunctions::luaPlayerRemoveExperience); + Lua::registerMethod(L, "Player", "getLevel", PlayerFunctions::luaPlayerGetLevel); + + Lua::registerMethod(L, "Player", "getMagicShieldCapacityFlat", PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat); + Lua::registerMethod(L, "Player", "getMagicShieldCapacityPercent", PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent); + + Lua::registerMethod(L, "Player", "sendSpellCooldown", PlayerFunctions::luaPlayerSendSpellCooldown); + Lua::registerMethod(L, "Player", "sendSpellGroupCooldown", PlayerFunctions::luaPlayerSendSpellGroupCooldown); + + Lua::registerMethod(L, "Player", "getMagicLevel", PlayerFunctions::luaPlayerGetMagicLevel); + Lua::registerMethod(L, "Player", "getBaseMagicLevel", PlayerFunctions::luaPlayerGetBaseMagicLevel); + Lua::registerMethod(L, "Player", "getMana", PlayerFunctions::luaPlayerGetMana); + Lua::registerMethod(L, "Player", "addMana", PlayerFunctions::luaPlayerAddMana); + Lua::registerMethod(L, "Player", "getMaxMana", PlayerFunctions::luaPlayerGetMaxMana); + Lua::registerMethod(L, "Player", "setMaxMana", PlayerFunctions::luaPlayerSetMaxMana); + Lua::registerMethod(L, "Player", "getManaSpent", PlayerFunctions::luaPlayerGetManaSpent); + Lua::registerMethod(L, "Player", "addManaSpent", PlayerFunctions::luaPlayerAddManaSpent); + + Lua::registerMethod(L, "Player", "getBaseMaxHealth", PlayerFunctions::luaPlayerGetBaseMaxHealth); + Lua::registerMethod(L, "Player", "getBaseMaxMana", PlayerFunctions::luaPlayerGetBaseMaxMana); + + Lua::registerMethod(L, "Player", "getSkillLevel", PlayerFunctions::luaPlayerGetSkillLevel); + Lua::registerMethod(L, "Player", "getEffectiveSkillLevel", PlayerFunctions::luaPlayerGetEffectiveSkillLevel); + Lua::registerMethod(L, "Player", "getSkillPercent", PlayerFunctions::luaPlayerGetSkillPercent); + Lua::registerMethod(L, "Player", "getSkillTries", PlayerFunctions::luaPlayerGetSkillTries); + Lua::registerMethod(L, "Player", "addSkillTries", PlayerFunctions::luaPlayerAddSkillTries); + + Lua::registerMethod(L, "Player", "setLevel", PlayerFunctions::luaPlayerSetLevel); + Lua::registerMethod(L, "Player", "setMagicLevel", PlayerFunctions::luaPlayerSetMagicLevel); + Lua::registerMethod(L, "Player", "setSkillLevel", PlayerFunctions::luaPlayerSetSkillLevel); + + Lua::registerMethod(L, "Player", "addOfflineTrainingTime", PlayerFunctions::luaPlayerAddOfflineTrainingTime); + Lua::registerMethod(L, "Player", "getOfflineTrainingTime", PlayerFunctions::luaPlayerGetOfflineTrainingTime); + Lua::registerMethod(L, "Player", "removeOfflineTrainingTime", PlayerFunctions::luaPlayerRemoveOfflineTrainingTime); + + Lua::registerMethod(L, "Player", "addOfflineTrainingTries", PlayerFunctions::luaPlayerAddOfflineTrainingTries); + + Lua::registerMethod(L, "Player", "getOfflineTrainingSkill", PlayerFunctions::luaPlayerGetOfflineTrainingSkill); + Lua::registerMethod(L, "Player", "setOfflineTrainingSkill", PlayerFunctions::luaPlayerSetOfflineTrainingSkill); + + Lua::registerMethod(L, "Player", "getItemCount", PlayerFunctions::luaPlayerGetItemCount); + Lua::registerMethod(L, "Player", "getStashItemCount", PlayerFunctions::luaPlayerGetStashItemCount); + Lua::registerMethod(L, "Player", "getItemById", PlayerFunctions::luaPlayerGetItemById); + + Lua::registerMethod(L, "Player", "getVocation", PlayerFunctions::luaPlayerGetVocation); + Lua::registerMethod(L, "Player", "setVocation", PlayerFunctions::luaPlayerSetVocation); + Lua::registerMethod(L, "Player", "isPromoted", PlayerFunctions::luaPlayerIsPromoted); + + Lua::registerMethod(L, "Player", "getSex", PlayerFunctions::luaPlayerGetSex); + Lua::registerMethod(L, "Player", "setSex", PlayerFunctions::luaPlayerSetSex); + + Lua::registerMethod(L, "Player", "getPronoun", PlayerFunctions::luaPlayerGetPronoun); + Lua::registerMethod(L, "Player", "setPronoun", PlayerFunctions::luaPlayerSetPronoun); + + Lua::registerMethod(L, "Player", "getTown", PlayerFunctions::luaPlayerGetTown); + Lua::registerMethod(L, "Player", "setTown", PlayerFunctions::luaPlayerSetTown); + + Lua::registerMethod(L, "Player", "getGuild", PlayerFunctions::luaPlayerGetGuild); + Lua::registerMethod(L, "Player", "setGuild", PlayerFunctions::luaPlayerSetGuild); + + Lua::registerMethod(L, "Player", "getGuildLevel", PlayerFunctions::luaPlayerGetGuildLevel); + Lua::registerMethod(L, "Player", "setGuildLevel", PlayerFunctions::luaPlayerSetGuildLevel); + + Lua::registerMethod(L, "Player", "getGuildNick", PlayerFunctions::luaPlayerGetGuildNick); + Lua::registerMethod(L, "Player", "setGuildNick", PlayerFunctions::luaPlayerSetGuildNick); + + Lua::registerMethod(L, "Player", "getGroup", PlayerFunctions::luaPlayerGetGroup); + Lua::registerMethod(L, "Player", "setGroup", PlayerFunctions::luaPlayerSetGroup); + + Lua::registerMethod(L, "Player", "setSpecialContainersAvailable", PlayerFunctions::luaPlayerSetSpecialContainersAvailable); + Lua::registerMethod(L, "Player", "getStashCount", PlayerFunctions::luaPlayerGetStashCounter); + Lua::registerMethod(L, "Player", "openStash", PlayerFunctions::luaPlayerOpenStash); + + Lua::registerMethod(L, "Player", "getStamina", PlayerFunctions::luaPlayerGetStamina); + Lua::registerMethod(L, "Player", "setStamina", PlayerFunctions::luaPlayerSetStamina); + + Lua::registerMethod(L, "Player", "getSoul", PlayerFunctions::luaPlayerGetSoul); + Lua::registerMethod(L, "Player", "addSoul", PlayerFunctions::luaPlayerAddSoul); + Lua::registerMethod(L, "Player", "getMaxSoul", PlayerFunctions::luaPlayerGetMaxSoul); + + Lua::registerMethod(L, "Player", "getBankBalance", PlayerFunctions::luaPlayerGetBankBalance); + Lua::registerMethod(L, "Player", "setBankBalance", PlayerFunctions::luaPlayerSetBankBalance); + + Lua::registerMethod(L, "Player", "getStorageValue", PlayerFunctions::luaPlayerGetStorageValue); + Lua::registerMethod(L, "Player", "setStorageValue", PlayerFunctions::luaPlayerSetStorageValue); + + Lua::registerMethod(L, "Player", "getStorageValueByName", PlayerFunctions::luaPlayerGetStorageValueByName); + Lua::registerMethod(L, "Player", "setStorageValueByName", PlayerFunctions::luaPlayerSetStorageValueByName); + + Lua::registerMethod(L, "Player", "addItem", PlayerFunctions::luaPlayerAddItem); + Lua::registerMethod(L, "Player", "addItemEx", PlayerFunctions::luaPlayerAddItemEx); + Lua::registerMethod(L, "Player", "addItemStash", PlayerFunctions::luaPlayerAddItemStash); + Lua::registerMethod(L, "Player", "removeStashItem", PlayerFunctions::luaPlayerRemoveStashItem); + Lua::registerMethod(L, "Player", "removeItem", PlayerFunctions::luaPlayerRemoveItem); + Lua::registerMethod(L, "Player", "sendContainer", PlayerFunctions::luaPlayerSendContainer); + Lua::registerMethod(L, "Player", "sendUpdateContainer", PlayerFunctions::luaPlayerSendUpdateContainer); + + Lua::registerMethod(L, "Player", "getMoney", PlayerFunctions::luaPlayerGetMoney); + Lua::registerMethod(L, "Player", "addMoney", PlayerFunctions::luaPlayerAddMoney); + Lua::registerMethod(L, "Player", "removeMoney", PlayerFunctions::luaPlayerRemoveMoney); + + Lua::registerMethod(L, "Player", "showTextDialog", PlayerFunctions::luaPlayerShowTextDialog); + + Lua::registerMethod(L, "Player", "sendTextMessage", PlayerFunctions::luaPlayerSendTextMessage); + Lua::registerMethod(L, "Player", "sendChannelMessage", PlayerFunctions::luaPlayerSendChannelMessage); + Lua::registerMethod(L, "Player", "sendPrivateMessage", PlayerFunctions::luaPlayerSendPrivateMessage); + Lua::registerMethod(L, "Player", "channelSay", PlayerFunctions::luaPlayerChannelSay); + Lua::registerMethod(L, "Player", "openChannel", PlayerFunctions::luaPlayerOpenChannel); + + Lua::registerMethod(L, "Player", "getSlotItem", PlayerFunctions::luaPlayerGetSlotItem); + + Lua::registerMethod(L, "Player", "getParty", PlayerFunctions::luaPlayerGetParty); + + Lua::registerMethod(L, "Player", "addOutfit", PlayerFunctions::luaPlayerAddOutfit); + Lua::registerMethod(L, "Player", "addOutfitAddon", PlayerFunctions::luaPlayerAddOutfitAddon); + Lua::registerMethod(L, "Player", "removeOutfit", PlayerFunctions::luaPlayerRemoveOutfit); + Lua::registerMethod(L, "Player", "removeOutfitAddon", PlayerFunctions::luaPlayerRemoveOutfitAddon); + Lua::registerMethod(L, "Player", "hasOutfit", PlayerFunctions::luaPlayerHasOutfit); + Lua::registerMethod(L, "Player", "sendOutfitWindow", PlayerFunctions::luaPlayerSendOutfitWindow); + + Lua::registerMethod(L, "Player", "addMount", PlayerFunctions::luaPlayerAddMount); + Lua::registerMethod(L, "Player", "removeMount", PlayerFunctions::luaPlayerRemoveMount); + Lua::registerMethod(L, "Player", "hasMount", PlayerFunctions::luaPlayerHasMount); + + Lua::registerMethod(L, "Player", "addFamiliar", PlayerFunctions::luaPlayerAddFamiliar); + Lua::registerMethod(L, "Player", "removeFamiliar", PlayerFunctions::luaPlayerRemoveFamiliar); + Lua::registerMethod(L, "Player", "hasFamiliar", PlayerFunctions::luaPlayerHasFamiliar); + Lua::registerMethod(L, "Player", "setFamiliarLooktype", PlayerFunctions::luaPlayerSetFamiliarLooktype); + Lua::registerMethod(L, "Player", "getFamiliarLooktype", PlayerFunctions::luaPlayerGetFamiliarLooktype); + + Lua::registerMethod(L, "Player", "getPremiumDays", PlayerFunctions::luaPlayerGetPremiumDays); + Lua::registerMethod(L, "Player", "addPremiumDays", PlayerFunctions::luaPlayerAddPremiumDays); + Lua::registerMethod(L, "Player", "removePremiumDays", PlayerFunctions::luaPlayerRemovePremiumDays); + + Lua::registerMethod(L, "Player", "getTibiaCoins", PlayerFunctions::luaPlayerGetTibiaCoins); + Lua::registerMethod(L, "Player", "addTibiaCoins", PlayerFunctions::luaPlayerAddTibiaCoins); + Lua::registerMethod(L, "Player", "removeTibiaCoins", PlayerFunctions::luaPlayerRemoveTibiaCoins); + + Lua::registerMethod(L, "Player", "getTransferableCoins", PlayerFunctions::luaPlayerGetTransferableCoins); + Lua::registerMethod(L, "Player", "addTransferableCoins", PlayerFunctions::luaPlayerAddTransferableCoins); + Lua::registerMethod(L, "Player", "removeTransferableCoins", PlayerFunctions::luaPlayerRemoveTransferableCoins); + + Lua::registerMethod(L, "Player", "sendBlessStatus", PlayerFunctions::luaPlayerSendBlessStatus); + Lua::registerMethod(L, "Player", "hasBlessing", PlayerFunctions::luaPlayerHasBlessing); + Lua::registerMethod(L, "Player", "addBlessing", PlayerFunctions::luaPlayerAddBlessing); + Lua::registerMethod(L, "Player", "removeBlessing", PlayerFunctions::luaPlayerRemoveBlessing); + Lua::registerMethod(L, "Player", "getBlessingCount", PlayerFunctions::luaPlayerGetBlessingCount); + + Lua::registerMethod(L, "Player", "canLearnSpell", PlayerFunctions::luaPlayerCanLearnSpell); + Lua::registerMethod(L, "Player", "learnSpell", PlayerFunctions::luaPlayerLearnSpell); + Lua::registerMethod(L, "Player", "forgetSpell", PlayerFunctions::luaPlayerForgetSpell); + Lua::registerMethod(L, "Player", "hasLearnedSpell", PlayerFunctions::luaPlayerHasLearnedSpell); + + Lua::registerMethod(L, "Player", "openImbuementWindow", PlayerFunctions::luaPlayerOpenImbuementWindow); + Lua::registerMethod(L, "Player", "closeImbuementWindow", PlayerFunctions::luaPlayerCloseImbuementWindow); + + Lua::registerMethod(L, "Player", "sendTutorial", PlayerFunctions::luaPlayerSendTutorial); + Lua::registerMethod(L, "Player", "addMapMark", PlayerFunctions::luaPlayerAddMapMark); + + Lua::registerMethod(L, "Player", "save", PlayerFunctions::luaPlayerSave); + Lua::registerMethod(L, "Player", "popupFYI", PlayerFunctions::luaPlayerPopupFYI); + + Lua::registerMethod(L, "Player", "isPzLocked", PlayerFunctions::luaPlayerIsPzLocked); + + Lua::registerMethod(L, "Player", "getClient", PlayerFunctions::luaPlayerGetClient); + + Lua::registerMethod(L, "Player", "getHouse", PlayerFunctions::luaPlayerGetHouse); + Lua::registerMethod(L, "Player", "sendHouseWindow", PlayerFunctions::luaPlayerSendHouseWindow); + Lua::registerMethod(L, "Player", "setEditHouse", PlayerFunctions::luaPlayerSetEditHouse); + + Lua::registerMethod(L, "Player", "setGhostMode", PlayerFunctions::luaPlayerSetGhostMode); + + Lua::registerMethod(L, "Player", "getContainerId", PlayerFunctions::luaPlayerGetContainerId); + Lua::registerMethod(L, "Player", "getContainerById", PlayerFunctions::luaPlayerGetContainerById); + Lua::registerMethod(L, "Player", "getContainerIndex", PlayerFunctions::luaPlayerGetContainerIndex); + + Lua::registerMethod(L, "Player", "getInstantSpells", PlayerFunctions::luaPlayerGetInstantSpells); + Lua::registerMethod(L, "Player", "canCast", PlayerFunctions::luaPlayerCanCast); + + Lua::registerMethod(L, "Player", "hasChaseMode", PlayerFunctions::luaPlayerHasChaseMode); + Lua::registerMethod(L, "Player", "hasSecureMode", PlayerFunctions::luaPlayerHasSecureMode); + Lua::registerMethod(L, "Player", "getFightMode", PlayerFunctions::luaPlayerGetFightMode); + + Lua::registerMethod(L, "Player", "getBaseXpGain", PlayerFunctions::luaPlayerGetBaseXpGain); + Lua::registerMethod(L, "Player", "setBaseXpGain", PlayerFunctions::luaPlayerSetBaseXpGain); + Lua::registerMethod(L, "Player", "getVoucherXpBoost", PlayerFunctions::luaPlayerGetVoucherXpBoost); + Lua::registerMethod(L, "Player", "setVoucherXpBoost", PlayerFunctions::luaPlayerSetVoucherXpBoost); + Lua::registerMethod(L, "Player", "getGrindingXpBoost", PlayerFunctions::luaPlayerGetGrindingXpBoost); + Lua::registerMethod(L, "Player", "setGrindingXpBoost", PlayerFunctions::luaPlayerSetGrindingXpBoost); + Lua::registerMethod(L, "Player", "getXpBoostPercent", PlayerFunctions::luaPlayerGetXpBoostPercent); + Lua::registerMethod(L, "Player", "setXpBoostPercent", PlayerFunctions::luaPlayerSetXpBoostPercent); + Lua::registerMethod(L, "Player", "getStaminaXpBoost", PlayerFunctions::luaPlayerGetStaminaXpBoost); + Lua::registerMethod(L, "Player", "setStaminaXpBoost", PlayerFunctions::luaPlayerSetStaminaXpBoost); + Lua::registerMethod(L, "Player", "getXpBoostTime", PlayerFunctions::luaPlayerGetXpBoostTime); + Lua::registerMethod(L, "Player", "setXpBoostTime", PlayerFunctions::luaPlayerSetXpBoostTime); + + Lua::registerMethod(L, "Player", "getIdleTime", PlayerFunctions::luaPlayerGetIdleTime); + Lua::registerMethod(L, "Player", "getFreeBackpackSlots", PlayerFunctions::luaPlayerGetFreeBackpackSlots); + + Lua::registerMethod(L, "Player", "isOffline", PlayerFunctions::luaPlayerIsOffline); + + Lua::registerMethod(L, "Player", "openMarket", PlayerFunctions::luaPlayerOpenMarket); + + Lua::registerMethod(L, "Player", "instantSkillWOD", PlayerFunctions::luaPlayerInstantSkillWOD); + Lua::registerMethod(L, "Player", "upgradeSpellsWOD", PlayerFunctions::luaPlayerUpgradeSpellWOD); + Lua::registerMethod(L, "Player", "revelationStageWOD", PlayerFunctions::luaPlayerRevelationStageWOD); + Lua::registerMethod(L, "Player", "reloadData", PlayerFunctions::luaPlayerReloadData); + Lua::registerMethod(L, "Player", "onThinkWheelOfDestiny", PlayerFunctions::luaPlayerOnThinkWheelOfDestiny); + Lua::registerMethod(L, "Player", "avatarTimer", PlayerFunctions::luaPlayerAvatarTimer); + Lua::registerMethod(L, "Player", "getWheelSpellAdditionalArea", PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea); + Lua::registerMethod(L, "Player", "getWheelSpellAdditionalTarget", PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget); + Lua::registerMethod(L, "Player", "getWheelSpellAdditionalDuration", PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration); + + // Forge Functions + Lua::registerMethod(L, "Player", "openForge", PlayerFunctions::luaPlayerOpenForge); + Lua::registerMethod(L, "Player", "closeForge", PlayerFunctions::luaPlayerCloseForge); + + Lua::registerMethod(L, "Player", "addForgeDusts", PlayerFunctions::luaPlayerAddForgeDusts); + Lua::registerMethod(L, "Player", "removeForgeDusts", PlayerFunctions::luaPlayerRemoveForgeDusts); + Lua::registerMethod(L, "Player", "getForgeDusts", PlayerFunctions::luaPlayerGetForgeDusts); + Lua::registerMethod(L, "Player", "setForgeDusts", PlayerFunctions::luaPlayerSetForgeDusts); + + Lua::registerMethod(L, "Player", "addForgeDustLevel", PlayerFunctions::luaPlayerAddForgeDustLevel); + Lua::registerMethod(L, "Player", "removeForgeDustLevel", PlayerFunctions::luaPlayerRemoveForgeDustLevel); + Lua::registerMethod(L, "Player", "getForgeDustLevel", PlayerFunctions::luaPlayerGetForgeDustLevel); + + Lua::registerMethod(L, "Player", "getForgeSlivers", PlayerFunctions::luaPlayerGetForgeSlivers); + Lua::registerMethod(L, "Player", "getForgeCores", PlayerFunctions::luaPlayerGetForgeCores); + Lua::registerMethod(L, "Player", "isUIExhausted", PlayerFunctions::luaPlayerIsUIExhausted); + Lua::registerMethod(L, "Player", "updateUIExhausted", PlayerFunctions::luaPlayerUpdateUIExhausted); + + Lua::registerMethod(L, "Player", "setFaction", PlayerFunctions::luaPlayerSetFaction); + Lua::registerMethod(L, "Player", "getFaction", PlayerFunctions::luaPlayerGetFaction); + + // Bosstiary Functions + Lua::registerMethod(L, "Player", "getBosstiaryLevel", PlayerFunctions::luaPlayerGetBosstiaryLevel); + Lua::registerMethod(L, "Player", "getBosstiaryKills", PlayerFunctions::luaPlayerGetBosstiaryKills); + Lua::registerMethod(L, "Player", "addBosstiaryKill", PlayerFunctions::luaPlayerAddBosstiaryKill); + Lua::registerMethod(L, "Player", "setBossPoints", PlayerFunctions::luaPlayerSetBossPoints); + Lua::registerMethod(L, "Player", "setRemoveBossTime", PlayerFunctions::luaPlayerSetRemoveBossTime); + Lua::registerMethod(L, "Player", "getSlotBossId", PlayerFunctions::luaPlayerGetSlotBossId); + Lua::registerMethod(L, "Player", "getBossBonus", PlayerFunctions::luaPlayerGetBossBonus); + Lua::registerMethod(L, "Player", "sendBosstiaryCooldownTimer", PlayerFunctions::luaPlayerBosstiaryCooldownTimer); + + Lua::registerMethod(L, "Player", "sendSingleSoundEffect", PlayerFunctions::luaPlayerSendSingleSoundEffect); + Lua::registerMethod(L, "Player", "sendDoubleSoundEffect", PlayerFunctions::luaPlayerSendDoubleSoundEffect); + + Lua::registerMethod(L, "Player", "getName", PlayerFunctions::luaPlayerGetName); + Lua::registerMethod(L, "Player", "changeName", PlayerFunctions::luaPlayerChangeName); + + Lua::registerMethod(L, "Player", "hasGroupFlag", PlayerFunctions::luaPlayerHasGroupFlag); + Lua::registerMethod(L, "Player", "setGroupFlag", PlayerFunctions::luaPlayerSetGroupFlag); + Lua::registerMethod(L, "Player", "removeGroupFlag", PlayerFunctions::luaPlayerRemoveGroupFlag); + + Lua::registerMethod(L, "Player", "setHazardSystemPoints", PlayerFunctions::luaPlayerAddHazardSystemPoints); + Lua::registerMethod(L, "Player", "getHazardSystemPoints", PlayerFunctions::luaPlayerGetHazardSystemPoints); + + Lua::registerMethod(L, "Player", "setLoyaltyBonus", PlayerFunctions::luaPlayerSetLoyaltyBonus); + Lua::registerMethod(L, "Player", "getLoyaltyBonus", PlayerFunctions::luaPlayerGetLoyaltyBonus); + Lua::registerMethod(L, "Player", "getLoyaltyPoints", PlayerFunctions::luaPlayerGetLoyaltyPoints); + Lua::registerMethod(L, "Player", "getLoyaltyTitle", PlayerFunctions::luaPlayerGetLoyaltyTitle); + Lua::registerMethod(L, "Player", "setLoyaltyTitle", PlayerFunctions::luaPlayerSetLoyaltyTitle); + + Lua::registerMethod(L, "Player", "updateConcoction", PlayerFunctions::luaPlayerUpdateConcoction); + Lua::registerMethod(L, "Player", "clearSpellCooldowns", PlayerFunctions::luaPlayerClearSpellCooldowns); + + Lua::registerMethod(L, "Player", "isVip", PlayerFunctions::luaPlayerIsVip); + Lua::registerMethod(L, "Player", "getVipDays", PlayerFunctions::luaPlayerGetVipDays); + Lua::registerMethod(L, "Player", "getVipTime", PlayerFunctions::luaPlayerGetVipTime); + + Lua::registerMethod(L, "Player", "kv", PlayerFunctions::luaPlayerKV); + Lua::registerMethod(L, "Player", "getStoreInbox", PlayerFunctions::luaPlayerGetStoreInbox); + + Lua::registerMethod(L, "Player", "hasAchievement", PlayerFunctions::luaPlayerHasAchievement); + Lua::registerMethod(L, "Player", "addAchievement", PlayerFunctions::luaPlayerAddAchievement); + Lua::registerMethod(L, "Player", "removeAchievement", PlayerFunctions::luaPlayerRemoveAchievement); + Lua::registerMethod(L, "Player", "getAchievementPoints", PlayerFunctions::luaPlayerGetAchievementPoints); + Lua::registerMethod(L, "Player", "addAchievementPoints", PlayerFunctions::luaPlayerAddAchievementPoints); + Lua::registerMethod(L, "Player", "removeAchievementPoints", PlayerFunctions::luaPlayerRemoveAchievementPoints); + + // Badge Functions + Lua::registerMethod(L, "Player", "addBadge", PlayerFunctions::luaPlayerAddBadge); + + // Title Functions + Lua::registerMethod(L, "Player", "addTitle", PlayerFunctions::luaPlayerAddTitle); + Lua::registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles); + Lua::registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle); + + // Store Summary + Lua::registerMethod(L, "Player", "createTransactionSummary", PlayerFunctions::luaPlayerCreateTransactionSummary); + + Lua::registerMethod(L, "Player", "takeScreenshot", PlayerFunctions::luaPlayerTakeScreenshot); + Lua::registerMethod(L, "Player", "sendIconBakragore", PlayerFunctions::luaPlayerSendIconBakragore); + Lua::registerMethod(L, "Player", "removeIconBakragore", PlayerFunctions::luaPlayerRemoveIconBakragore); + Lua::registerMethod(L, "Player", "sendCreatureAppear", PlayerFunctions::luaPlayerSendCreatureAppear); + + GroupFunctions::init(L); + GuildFunctions::init(L); + MountFunctions::init(L); + PartyFunctions::init(L); + VocationFunctions::init(L); +} int PlayerFunctions::luaPlayerSendInventory(lua_State* L) { // player:sendInventory() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } player->sendInventoryIds(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendLootStats(lua_State* L) { // player:sendLootStats(item, count) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } - const auto count = getNumber(L, 3, 0); + const auto count = Lua::getNumber(L, 3, 0); if (count == 0) { lua_pushnil(L); return 1; } player->sendLootStats(item, count); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerUpdateSupplyTracker(lua_State* L) { // player:updateSupplyTracker(item) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } player->updateSupplyTracker(item); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { // player:updateKillTracker(creature, corpse) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &monster = getUserdataShared(L, 2); + const auto &monster = Lua::getUserdataShared(L, 2); if (!monster) { lua_pushnil(L); return 1; } - const auto &corpse = getUserdataShared(L, 3); + const auto &corpse = Lua::getUserdataShared(L, 3); if (!corpse) { lua_pushnil(L); return 1; } player->updateKillTracker(corpse, monster->getName(), monster->getCurrentOutfit()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -127,33 +500,33 @@ int PlayerFunctions::luaPlayerUpdateKillTracker(lua_State* L) { int PlayerFunctions::luaPlayerCreate(lua_State* L) { // Player(id or guid or name or userdata) std::shared_ptr player; - if (isNumber(L, 2)) { - const uint32_t id = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + const uint32_t id = Lua::getNumber(L, 2); if (id >= Player::getFirstID() && id <= Player::getLastID()) { player = g_game().getPlayerByID(id); } else { player = g_game().getPlayerByGUID(id); } - } else if (isString(L, 2)) { - ReturnValue ret = g_game().getPlayerByNameWildcard(getString(L, 2), player); + } else if (Lua::isString(L, 2)) { + ReturnValue ret = g_game().getPlayerByNameWildcard(Lua::getString(L, 2), player); if (ret != RETURNVALUE_NOERROR) { lua_pushnil(L); lua_pushnumber(L, ret); return 2; } - } else if (isUserdata(L, 2)) { - if (getUserdataType(L, 2) != LuaData_t::Player) { + } else if (Lua::isUserdata(L, 2)) { + if (Lua::getUserdataType(L, 2) != LuaData_t::Player) { lua_pushnil(L); return 1; } - player = getUserdataShared(L, 2); + player = Lua::getUserdataShared(L, 2); } else { player = nullptr; } if (player) { - pushUserdata(L, player); - setMetatable(L, -1, "Player"); + Lua::pushUserdata(L, player); + Lua::setMetatable(L, -1, "Player"); } else { lua_pushnil(L); } @@ -162,7 +535,7 @@ int PlayerFunctions::luaPlayerCreate(lua_State* L) { int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { // player:resetCharmsBestiary() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->setCharmPoints(0); player->setCharmExpansion(false); @@ -171,7 +544,7 @@ int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { for (int8_t i = CHARM_WOUND; i <= CHARM_LAST; i++) { player->parseRacebyCharm(static_cast(i), true, 0); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -180,7 +553,7 @@ int PlayerFunctions::luaPlayerResetCharmsMonsters(lua_State* L) { int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { // player:unlockAllCharmRunes() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { for (int8_t i = CHARM_WOUND; i <= CHARM_LAST; i++) { const auto charm = g_iobestiary().getBestiaryCharm(static_cast(i)); @@ -189,7 +562,7 @@ int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { player->setUnlockedRunesBit(value); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -198,16 +571,16 @@ int PlayerFunctions::luaPlayerUnlockAllCharmRunes(lua_State* L) { int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { // player:addCharmPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - int16_t charms = getNumber(L, 2); + int16_t charms = Lua::getNumber(L, 2); if (charms >= 0) { g_iobestiary().addCharmPoints(player, static_cast(charms)); } else { charms = -charms; g_iobestiary().addCharmPoints(player, static_cast(charms), true); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -216,13 +589,13 @@ int PlayerFunctions::luaPlayeraddCharmPoints(lua_State* L) { int PlayerFunctions::luaPlayerIsPlayer(lua_State* L) { // player:isPlayer() - pushBoolean(L, getUserdataShared(L, 1) != nullptr); + Lua::pushBoolean(L, Lua::getUserdataShared(L, 1) != nullptr); return 1; } int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { // player:getGuid() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGUID()); } else { @@ -233,7 +606,7 @@ int PlayerFunctions::luaPlayerGetGuid(lua_State* L) { int PlayerFunctions::luaPlayerGetIp(lua_State* L) { // player:getIp() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIP()); } else { @@ -244,7 +617,7 @@ int PlayerFunctions::luaPlayerGetIp(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { // player:getAccountId() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || player->getAccountId() == 0) { lua_pushnil(L); return 1; @@ -257,7 +630,7 @@ int PlayerFunctions::luaPlayerGetAccountId(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { // player:getLastLoginSaved() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLoginSaved()); } else { @@ -268,7 +641,7 @@ int PlayerFunctions::luaPlayerGetLastLoginSaved(lua_State* L) { int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { // player:getLastLogout() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLastLogout()); } else { @@ -279,7 +652,7 @@ int PlayerFunctions::luaPlayerGetLastLogout(lua_State* L) { int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { // player:getAccountType() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getAccountType()); } else { @@ -290,13 +663,13 @@ int PlayerFunctions::luaPlayerGetAccountType(lua_State* L) { int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { // player:setAccountType(accountType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; } - if (player->getAccount()->setAccountType(getNumber(L, 2)) != AccountErrors_t::Ok) { + if (player->getAccount()->setAccountType(Lua::getNumber(L, 2)) != AccountErrors_t::Ok) { lua_pushnil(L); return 1; } @@ -306,18 +679,18 @@ int PlayerFunctions::luaPlayerSetAccountType(lua_State* L) { return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { // player:addBestiaryKill(name[, amount = 1]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const auto &mtype = g_monsters().getMonsterType(getString(L, 2)); + const auto &mtype = g_monsters().getMonsterType(Lua::getString(L, 2)); if (mtype) { - g_iobestiary().addBestiaryKill(player, mtype, getNumber(L, 3, 1)); - pushBoolean(L, true); + g_iobestiary().addBestiaryKill(player, mtype, Lua::getNumber(L, 3, 1)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -329,42 +702,42 @@ int PlayerFunctions::luaPlayerAddBestiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked(lua_State* L) { // player:isMonsterBestiaryUnlocked(raceId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player == nullptr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const auto raceId = getNumber(L, 2, 0); + const auto raceId = Lua::getNumber(L, 2, 0); if (!g_monsters().getMonsterTypeByRaceId(raceId)) { - reportErrorFunc("Monster race id not exists"); - pushBoolean(L, false); + Lua::reportErrorFunc("Monster race id not exists"); + Lua::pushBoolean(L, false); return 0; } for (const uint16_t finishedRaceId : g_iobestiary().getBestiaryFinished(player)) { if (raceId == finishedRaceId) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } } - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 0; } int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { // player:getCharmMonsterType(charmRune_t) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const charmRune_t charmid = getNumber(L, 2); + const charmRune_t charmid = Lua::getNumber(L, 2); const uint16_t raceid = player->parseRacebyCharm(charmid, false, 0); if (raceid > 0) { const auto &mtype = g_monsters().getMonsterTypeByRaceId(raceid); if (mtype) { - pushUserdata(L, mtype); - setMetatable(L, -1, "MonsterType"); + Lua::pushUserdata(L, mtype); + Lua::setMetatable(L, -1, "MonsterType"); } else { lua_pushnil(L); } @@ -379,10 +752,10 @@ int PlayerFunctions::luaPlayergetCharmMonsterType(lua_State* L) { int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { // player:removePreyStamina(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - g_ioprey().checkPlayerPreys(player, getNumber(L, 2, 1)); - pushBoolean(L, true); + g_ioprey().checkPlayerPreys(player, Lua::getNumber(L, 2, 1)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -391,9 +764,9 @@ int PlayerFunctions::luaPlayerRemovePreyStamina(lua_State* L) { int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { // player:addPreyCards(amount) - if (const auto &player = getUserdataShared(L, 1)) { - player->addPreyCards(getNumber(L, 2, 0)); - pushBoolean(L, true); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + player->addPreyCards(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -402,7 +775,7 @@ int PlayerFunctions::luaPlayerAddPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { // player:getPreyCards() - if (const auto &player = getUserdataShared(L, 1)) { + if (const auto &player = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, static_cast(player->getPreyCards())); } else { lua_pushnil(L); @@ -412,8 +785,8 @@ int PlayerFunctions::luaPlayerGetPreyCards(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { // player:getPreyExperiencePercentage(raceId) - if (const auto &player = getUserdataShared(L, 1)) { - if (const std::unique_ptr &slot = player->getPreyWithMonster(getNumber(L, 2, 0)); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + if (const std::unique_ptr &slot = player->getPreyWithMonster(Lua::getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Experience && slot->bonusTimeLeft > 0) { lua_pushnumber(L, static_cast(100 + slot->bonusPercentage)); } else { @@ -427,8 +800,8 @@ int PlayerFunctions::luaPlayerGetPreyExperiencePercentage(lua_State* L) { int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { // player:removeTaskHuntingPoints(amount) - if (const auto &player = getUserdataShared(L, 1)) { - pushBoolean(L, player->useTaskHuntingPoints(getNumber(L, 2, 0))); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + Lua::pushBoolean(L, player->useTaskHuntingPoints(Lua::getNumber(L, 2, 0))); } else { lua_pushnil(L); } @@ -437,10 +810,10 @@ int PlayerFunctions::luaPlayerRemoveTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { // player:getTaskHuntingPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player == nullptr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -450,9 +823,9 @@ int PlayerFunctions::luaPlayerGetTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { // player:addTaskHuntingPoints(amount) - if (const auto &player = getUserdataShared(L, 1)) { - const auto points = getNumber(L, 2); - player->addTaskHuntingPoints(getNumber(L, 2)); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + const auto points = Lua::getNumber(L, 2); + player->addTaskHuntingPoints(Lua::getNumber(L, 2)); lua_pushnumber(L, static_cast(points)); } else { lua_pushnil(L); @@ -462,8 +835,8 @@ int PlayerFunctions::luaPlayerAddTaskHuntingPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { // player:getPreyLootPercentage(raceid) - if (const auto &player = getUserdataShared(L, 1)) { - if (const std::unique_ptr &slot = player->getPreyWithMonster(getNumber(L, 2, 0)); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + if (const std::unique_ptr &slot = player->getPreyWithMonster(Lua::getNumber(L, 2, 0)); slot && slot->isOccupied() && slot->bonus == PreyBonus_Loot) { lua_pushnumber(L, slot->bonusPercentage); } else { @@ -477,12 +850,12 @@ int PlayerFunctions::luaPlayerGetPreyLootPercentage(lua_State* L) { int PlayerFunctions::luaPlayerisMonsterPrey(lua_State* L) { // player:isMonsterPrey(raceid) - if (const auto &player = getUserdataShared(L, 1)) { - if (const std::unique_ptr &slot = player->getPreyWithMonster(getNumber(L, 2, 0)); + if (const auto &player = Lua::getUserdataShared(L, 1)) { + if (const std::unique_ptr &slot = player->getPreyWithMonster(Lua::getNumber(L, 2, 0)); slot && slot->isOccupied()) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } } else { lua_pushnil(L); @@ -492,14 +865,14 @@ int PlayerFunctions::luaPlayerisMonsterPrey(lua_State* L) { int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { // get: player:preyThirdSlot() set: player:preyThirdSlot(bool) - if (const auto &player = getUserdataShared(L, 1); + if (const auto &player = Lua::getUserdataShared(L, 1); const auto &slot = player->getPreySlotById(PreySlot_Three)) { if (!slot) { lua_pushnil(L); } else if (lua_gettop(L) == 1) { - pushBoolean(L, slot->state != PreyDataState_Locked); + Lua::pushBoolean(L, slot->state != PreyDataState_Locked); } else { - if (getBoolean(L, 2, false)) { + if (Lua::getBoolean(L, 2, false)) { slot->eraseBonus(); slot->state = PreyDataState_Selection; slot->reloadMonsterGrid(player->getPreyBlackList(), player->getLevel()); @@ -508,7 +881,7 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { slot->state = PreyDataState_Locked; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -519,12 +892,12 @@ int PlayerFunctions::luaPlayerPreyThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { // get: player:taskHuntingThirdSlot() set: player:taskHuntingThirdSlot(bool) - if (const auto &player = getUserdataShared(L, 1); + if (const auto &player = Lua::getUserdataShared(L, 1); const auto &slot = player->getTaskHuntingSlotById(PreySlot_Three)) { if (lua_gettop(L) == 1) { - pushBoolean(L, slot->state != PreyTaskDataState_Locked); + Lua::pushBoolean(L, slot->state != PreyTaskDataState_Locked); } else { - if (getBoolean(L, 2, false)) { + if (Lua::getBoolean(L, 2, false)) { slot->eraseTask(); slot->reloadReward(); slot->state = PreyTaskDataState_Selection; @@ -534,7 +907,7 @@ int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { slot->state = PreyTaskDataState_Locked; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -544,13 +917,13 @@ int PlayerFunctions::luaPlayerTaskThirdSlot(lua_State* L) { int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { // get: player:charmExpansion() set: player:charmExpansion(bool) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { if (lua_gettop(L) == 1) { - pushBoolean(L, player->hasCharmExpansion()); + Lua::pushBoolean(L, player->hasCharmExpansion()); } else { - player->setCharmExpansion(getBoolean(L, 2, false)); - pushBoolean(L, true); + player->setCharmExpansion(Lua::getBoolean(L, 2, false)); + Lua::pushBoolean(L, true); } } else { lua_pushnil(L); @@ -560,7 +933,7 @@ int PlayerFunctions::luaPlayercharmExpansion(lua_State* L) { int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { // player:getCapacity() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getCapacity()); } else { @@ -571,11 +944,11 @@ int PlayerFunctions::luaPlayerGetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { // player:setCapacity(capacity) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->capacity = getNumber(L, 2); + player->capacity = Lua::getNumber(L, 2); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -584,11 +957,11 @@ int PlayerFunctions::luaPlayerSetCapacity(lua_State* L) { int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { // player:setTraining(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const bool value = getBoolean(L, 2, false); + const bool value = Lua::getBoolean(L, 2, false); player->setTraining(value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -597,10 +970,10 @@ int PlayerFunctions::luaPlayerSetTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { // player:isTraining() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } @@ -610,7 +983,7 @@ int PlayerFunctions::luaPlayerGetIsTraining(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { // player:getFreeCapacity() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getFreeCapacity()); } else { @@ -621,7 +994,7 @@ int PlayerFunctions::luaPlayerGetFreeCapacity(lua_State* L) { int PlayerFunctions::luaPlayerGetKills(lua_State* L) { // player:getKills() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -635,7 +1008,7 @@ int PlayerFunctions::luaPlayerGetKills(lua_State* L) { lua_rawseti(L, -2, 1); lua_pushnumber(L, kill.time); lua_rawseti(L, -2, 2); - pushBoolean(L, kill.unavenged); + Lua::pushBoolean(L, kill.unavenged); lua_rawseti(L, -2, 3); lua_rawseti(L, -2, ++idx); } @@ -645,7 +1018,7 @@ int PlayerFunctions::luaPlayerGetKills(lua_State* L) { int PlayerFunctions::luaPlayerSetKills(lua_State* L) { // player:setKills(kills) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -661,52 +1034,52 @@ int PlayerFunctions::luaPlayerSetKills(lua_State* L) { lua_rawgeti(L, -1, 1); // push target lua_rawgeti(L, -2, 2); // push time lua_rawgeti(L, -3, 3); // push unavenged - newKills.emplace_back(luaL_checknumber(L, -3), luaL_checknumber(L, -2), getBoolean(L, -1)); + newKills.emplace_back(luaL_checknumber(L, -3), luaL_checknumber(L, -2), Lua::getBoolean(L, -1)); lua_pop(L, 4); } player->unjustifiedKills = std::move(newKills); player->sendUnjustifiedPoints(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetReward(lua_State* L) { // player:getReward(rewardId[, autoCreate = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint64_t rewardId = getNumber(L, 2); - const bool autoCreate = getBoolean(L, 3, false); + const uint64_t rewardId = Lua::getNumber(L, 2); + const bool autoCreate = Lua::getBoolean(L, 3, false); if (const auto &reward = player->getReward(rewardId, autoCreate)) { - pushUserdata(L, reward); - setItemMetatable(L, -1, reward); + Lua::pushUserdata(L, reward); + Lua::setItemMetatable(L, -1, reward); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PlayerFunctions::luaPlayerRemoveReward(lua_State* L) { // player:removeReward(rewardId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint32_t rewardId = getNumber(L, 2); + const uint32_t rewardId = Lua::getNumber(L, 2); player->removeReward(rewardId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { // player:getRewardList() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -726,10 +1099,10 @@ int PlayerFunctions::luaPlayerGetRewardList(lua_State* L) { int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { // player:setDailyReward(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setDailyReward(getNumber(L, 2)); - pushBoolean(L, true); + player->setDailyReward(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -738,27 +1111,27 @@ int PlayerFunctions::luaPlayerSetDailyReward(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotLocker(lua_State* L) { // player:getDepotLocker(depotId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint32_t depotId = getNumber(L, 2); + const uint32_t depotId = Lua::getNumber(L, 2); const auto &depotLocker = player->getDepotLocker(depotId); if (depotLocker) { depotLocker->setParent(player); - pushUserdata(L, depotLocker); - setItemMetatable(L, -1, depotLocker); + Lua::pushUserdata(L, depotLocker); + Lua::setItemMetatable(L, -1, depotLocker); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { // player:getStashCount() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { const uint16_t sizeStash = getStashSize(player->getStashItems()); lua_pushnumber(L, sizeStash); @@ -770,28 +1143,28 @@ int PlayerFunctions::luaPlayerGetStashCounter(lua_State* L) { int PlayerFunctions::luaPlayerGetDepotChest(lua_State* L) { // player:getDepotChest(depotId[, autoCreate = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint32_t depotId = getNumber(L, 2); - const bool autoCreate = getBoolean(L, 3, false); + const uint32_t depotId = Lua::getNumber(L, 2); + const bool autoCreate = Lua::getBoolean(L, 3, false); const auto &depotChest = player->getDepotChest(depotId, autoCreate); if (depotChest) { player->setLastDepotId(depotId); - pushUserdata(L, depotChest); - setItemMetatable(L, -1, depotChest); + Lua::pushUserdata(L, depotChest); + Lua::setItemMetatable(L, -1, depotChest); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { // player:getInbox() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -799,17 +1172,17 @@ int PlayerFunctions::luaPlayerGetInbox(lua_State* L) { const auto &inbox = player->getInbox(); if (inbox) { - pushUserdata(L, inbox); - setItemMetatable(L, -1, inbox); + Lua::pushUserdata(L, inbox); + Lua::setItemMetatable(L, -1, inbox); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { // player:getSkullTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSkullTicks()); } else { @@ -820,10 +1193,10 @@ int PlayerFunctions::luaPlayerGetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { // player:setSkullTime(skullTime) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setSkullTicks(getNumber(L, 2)); - pushBoolean(L, true); + player->setSkullTicks(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -832,7 +1205,7 @@ int PlayerFunctions::luaPlayerSetSkullTime(lua_State* L) { int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { // player:getDeathPenalty() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, static_cast(player->getLostPercent() * 100)); } else { @@ -843,7 +1216,7 @@ int PlayerFunctions::luaPlayerGetDeathPenalty(lua_State* L) { int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { // player:getExperience() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getExperience()); } else { @@ -854,12 +1227,12 @@ int PlayerFunctions::luaPlayerGetExperience(lua_State* L) { int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { // player:addExperience(experience[, sendText = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const int64_t experience = getNumber(L, 2); - const bool sendText = getBoolean(L, 3, false); + const int64_t experience = Lua::getNumber(L, 2); + const bool sendText = Lua::getBoolean(L, 3, false); player->addExperience(nullptr, experience, sendText); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -868,12 +1241,12 @@ int PlayerFunctions::luaPlayerAddExperience(lua_State* L) { int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { // player:removeExperience(experience[, sendText = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const int64_t experience = getNumber(L, 2); - const bool sendText = getBoolean(L, 3, false); + const int64_t experience = Lua::getNumber(L, 2); + const bool sendText = Lua::getBoolean(L, 3, false); player->removeExperience(experience, sendText); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -882,7 +1255,7 @@ int PlayerFunctions::luaPlayerRemoveExperience(lua_State* L) { int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { // player:getLevel() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getLevel()); } else { @@ -893,9 +1266,9 @@ int PlayerFunctions::luaPlayerGetLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { // player:getMagicShieldCapacityFlat(useCharges) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - lua_pushnumber(L, player->getMagicShieldCapacityFlat(getBoolean(L, 2, false))); + lua_pushnumber(L, player->getMagicShieldCapacityFlat(Lua::getBoolean(L, 2, false))); } else { lua_pushnil(L); } @@ -904,9 +1277,9 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat(lua_State* L) { int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { // player:getMagicShieldCapacityPercent(useCharges) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - lua_pushnumber(L, player->getMagicShieldCapacityPercent(getBoolean(L, 2, false))); + lua_pushnumber(L, player->getMagicShieldCapacityPercent(Lua::getBoolean(L, 2, false))); } else { lua_pushnil(L); } @@ -915,39 +1288,39 @@ int PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent(lua_State* L) { int PlayerFunctions::luaPlayerSendSpellCooldown(lua_State* L) { // player:sendSpellCooldown(spellId, time) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint8_t spellId = getNumber(L, 2, 1); - const auto time = getNumber(L, 3, 0); + const uint8_t spellId = Lua::getNumber(L, 2, 1); + const auto time = Lua::getNumber(L, 3, 0); player->sendSpellCooldown(spellId, time); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendSpellGroupCooldown(lua_State* L) { // player:sendSpellGroupCooldown(groupId, time) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto groupId = getNumber(L, 2, SPELLGROUP_ATTACK); - const auto time = getNumber(L, 3, 0); + const auto groupId = Lua::getNumber(L, 2, SPELLGROUP_ATTACK); + const auto time = Lua::getNumber(L, 3, 0); player->sendSpellGroupCooldown(groupId, time); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { // player:getMagicLevel() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMagicLevel()); } else { @@ -958,7 +1331,7 @@ int PlayerFunctions::luaPlayerGetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { // player:getBaseMagicLevel() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseMagicLevel()); } else { @@ -969,7 +1342,7 @@ int PlayerFunctions::luaPlayerGetBaseMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetMana(lua_State* L) { // player:getMana() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMana()); } else { @@ -980,14 +1353,14 @@ int PlayerFunctions::luaPlayerGetMana(lua_State* L) { int PlayerFunctions::luaPlayerAddMana(lua_State* L) { // player:addMana(manaChange[, animationOnLoss = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const int32_t manaChange = getNumber(L, 2); - const bool animationOnLoss = getBoolean(L, 3, false); + const int32_t manaChange = Lua::getNumber(L, 2); + const bool animationOnLoss = Lua::getBoolean(L, 3, false); if (!animationOnLoss && manaChange < 0) { player->changeMana(manaChange); } else { @@ -996,13 +1369,13 @@ int PlayerFunctions::luaPlayerAddMana(lua_State* L) { damage.origin = ORIGIN_NONE; g_game().combatChangeMana(nullptr, player, damage); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { // player:getMaxMana() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMaxMana()); } else { @@ -1013,23 +1386,23 @@ int PlayerFunctions::luaPlayerGetMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerSetMaxMana(lua_State* L) { // player:setMaxMana(maxMana) - const auto &player = getPlayer(L, 1); + const auto &player = Lua::getPlayer(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - player->manaMax = getNumber(L, 2); + player->manaMax = Lua::getNumber(L, 2); player->mana = std::min(player->mana, player->manaMax); g_game().addPlayerMana(player); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { // player:getManaSpent() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSpentMana()); } else { @@ -1040,10 +1413,10 @@ int PlayerFunctions::luaPlayerGetManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { // player:addManaSpent(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->addManaSpent(getNumber(L, 2)); - pushBoolean(L, true); + player->addManaSpent(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1052,7 +1425,7 @@ int PlayerFunctions::luaPlayerAddManaSpent(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { // player:getBaseMaxHealth() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->healthMax); } else { @@ -1063,7 +1436,7 @@ int PlayerFunctions::luaPlayerGetBaseMaxHealth(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { // player:getBaseMaxMana() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->manaMax); } else { @@ -1074,8 +1447,8 @@ int PlayerFunctions::luaPlayerGetBaseMaxMana(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { // player:getSkillLevel(skillType) - const skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const skills_t skillType = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].level); } else { @@ -1086,8 +1459,8 @@ int PlayerFunctions::luaPlayerGetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { // player:getEffectiveSkillLevel(skillType) - const skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const skills_t skillType = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->getSkillLevel(skillType)); } else { @@ -1098,8 +1471,8 @@ int PlayerFunctions::luaPlayerGetEffectiveSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { // player:getSkillPercent(skillType) - const skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const skills_t skillType = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].percent); } else { @@ -1110,8 +1483,8 @@ int PlayerFunctions::luaPlayerGetSkillPercent(lua_State* L) { int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { // player:getSkillTries(skillType) - const skills_t skillType = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const skills_t skillType = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player && skillType <= SKILL_LAST) { lua_pushnumber(L, player->skills[skillType].tries); } else { @@ -1122,12 +1495,12 @@ int PlayerFunctions::luaPlayerGetSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { // player:addSkillTries(skillType, tries) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const skills_t skillType = getNumber(L, 2); - const uint64_t tries = getNumber(L, 3); + const skills_t skillType = Lua::getNumber(L, 2); + const uint64_t tries = Lua::getNumber(L, 3); player->addSkillAdvance(skillType, tries); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1136,14 +1509,14 @@ int PlayerFunctions::luaPlayerAddSkillTries(lua_State* L) { int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { // player:setLevel(level) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t level = getNumber(L, 2); + const uint16_t level = Lua::getNumber(L, 2); player->level = level; player->experience = Player::getExpForLevel(level); player->sendStats(); player->sendSkills(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1152,12 +1525,12 @@ int PlayerFunctions::luaPlayerSetLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { // player:setMagicLevel(level[, manaSpent]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t level = getNumber(L, 2); + const uint16_t level = Lua::getNumber(L, 2); player->magLevel = level; - if (getNumber(L, 3, 0) > 0) { - const uint64_t manaSpent = getNumber(L, 3); + if (Lua::getNumber(L, 3, 0) > 0) { + const uint64_t manaSpent = Lua::getNumber(L, 3); const uint64_t nextReqMana = player->vocation->getReqMana(level + 1); player->manaSpent = manaSpent; player->magLevelPercent = Player::getPercentLevel(manaSpent, nextReqMana); @@ -1167,7 +1540,7 @@ int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { } player->sendStats(); player->sendSkills(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1176,13 +1549,13 @@ int PlayerFunctions::luaPlayerSetMagicLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { // player:setSkillLevel(skillType, level[, tries]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const skills_t skillType = getNumber(L, 2); - const uint16_t level = getNumber(L, 3); + const skills_t skillType = Lua::getNumber(L, 2); + const uint16_t level = Lua::getNumber(L, 3); player->skills[skillType].level = level; - if (getNumber(L, 4, 0) > 0) { - const uint64_t tries = getNumber(L, 4); + if (Lua::getNumber(L, 4, 0) > 0) { + const uint64_t tries = Lua::getNumber(L, 4); const uint64_t nextReqTries = player->vocation->getReqSkillTries(skillType, level + 1); player->skills[skillType].tries = tries; player->skills[skillType].percent = Player::getPercentLevel(tries, nextReqTries); @@ -1192,7 +1565,7 @@ int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { } player->sendStats(); player->sendSkills(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1201,12 +1574,12 @@ int PlayerFunctions::luaPlayerSetSkillLevel(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { // player:addOfflineTrainingTime(time) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const int32_t time = getNumber(L, 2); + const int32_t time = Lua::getNumber(L, 2); player->addOfflineTrainingTime(time); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1215,7 +1588,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { // player:getOfflineTrainingTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingTime()); } else { @@ -1226,12 +1599,12 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { // player:removeOfflineTrainingTime(time) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const int32_t time = getNumber(L, 2); + const int32_t time = Lua::getNumber(L, 2); player->removeOfflineTrainingTime(time); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1240,11 +1613,11 @@ int PlayerFunctions::luaPlayerRemoveOfflineTrainingTime(lua_State* L) { int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { // player:addOfflineTrainingTries(skillType, tries) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const skills_t skillType = getNumber(L, 2); - const uint64_t tries = getNumber(L, 3); - pushBoolean(L, player->addOfflineTrainingTries(skillType, tries)); + const skills_t skillType = Lua::getNumber(L, 2); + const uint64_t tries = Lua::getNumber(L, 3); + Lua::pushBoolean(L, player->addOfflineTrainingTries(skillType, tries)); } else { lua_pushnil(L); } @@ -1253,7 +1626,7 @@ int PlayerFunctions::luaPlayerAddOfflineTrainingTries(lua_State* L) { int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { // player:getOfflineTrainingSkill() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getOfflineTrainingSkill()); } else { @@ -1264,11 +1637,11 @@ int PlayerFunctions::luaPlayerGetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { // player:setOfflineTrainingSkill(skillId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const int8_t skillId = getNumber(L, 2); + const int8_t skillId = Lua::getNumber(L, 2); player->setOfflineTrainingSkill(skillId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1277,11 +1650,11 @@ int PlayerFunctions::luaPlayerSetOfflineTrainingSkill(lua_State* L) { int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { // player:openStash(isNpc) - const auto &player = getUserdataShared(L, 1); - const bool isNpc = getBoolean(L, 2, false); + const auto &player = Lua::getUserdataShared(L, 1); + const bool isNpc = Lua::getBoolean(L, 2, false); if (player) { player->sendOpenStash(isNpc); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1291,41 +1664,41 @@ int PlayerFunctions::luaPlayerOpenStash(lua_State* L) { int PlayerFunctions::luaPlayerGetItemCount(lua_State* L) { // player:getItemCount(itemId[, subType = -1]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto subType = getNumber(L, 3, -1); + const auto subType = Lua::getNumber(L, 3, -1); lua_pushnumber(L, player->getItemTypeCount(itemId, subType)); return 1; } int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { // player:getStashItemCount(itemId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; @@ -1344,29 +1717,29 @@ int PlayerFunctions::luaPlayerGetStashItemCount(lua_State* L) { int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { // player:getItemById(itemId, deepSearch[, subType = -1]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const bool deepSearch = getBoolean(L, 3); - const auto subType = getNumber(L, 4, -1); + const bool deepSearch = Lua::getBoolean(L, 3); + const auto subType = Lua::getNumber(L, 4, -1); const auto &item = g_game().findItemOfType(player, itemId, deepSearch, subType); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -1375,10 +1748,10 @@ int PlayerFunctions::luaPlayerGetItemById(lua_State* L) { int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { // player:getVocation() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushUserdata(L, player->getVocation()); - setMetatable(L, -1, "Vocation"); + Lua::pushUserdata(L, player->getVocation()); + Lua::setMetatable(L, -1, "Vocation"); } else { lua_pushnil(L); } @@ -1387,25 +1760,25 @@ int PlayerFunctions::luaPlayerGetVocation(lua_State* L) { int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { // player:setVocation(id or name or userdata) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } std::shared_ptr vocation; - if (isNumber(L, 2)) { - vocation = g_vocations().getVocation(getNumber(L, 2)); - } else if (isString(L, 2)) { - vocation = g_vocations().getVocation(g_vocations().getVocationId(getString(L, 2))); - } else if (isUserdata(L, 2)) { - vocation = getUserdataShared(L, 2); + if (Lua::isNumber(L, 2)) { + vocation = g_vocations().getVocation(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + vocation = g_vocations().getVocation(g_vocations().getVocationId(Lua::getString(L, 2))); + } else if (Lua::isUserdata(L, 2)) { + vocation = Lua::getUserdataShared(L, 2); } else { vocation = nullptr; } if (!vocation) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -1415,15 +1788,15 @@ int PlayerFunctions::luaPlayerSetVocation(lua_State* L) { player->sendBasicData(); player->wheel()->sendGiftOfLifeCooldown(); g_game().reloadCreature(player); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerIsPromoted(lua_State* L) { // player:isPromoted() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->isPromoted()); + Lua::pushBoolean(L, player->isPromoted()); } else { lua_pushnil(L); } @@ -1432,7 +1805,7 @@ int PlayerFunctions::luaPlayerIsPromoted(lua_State* L) { int PlayerFunctions::luaPlayerGetSex(lua_State* L) { // player:getSex() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSex()); } else { @@ -1443,11 +1816,11 @@ int PlayerFunctions::luaPlayerGetSex(lua_State* L) { int PlayerFunctions::luaPlayerSetSex(lua_State* L) { // player:setSex(newSex) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const PlayerSex_t newSex = getNumber(L, 2); + const PlayerSex_t newSex = Lua::getNumber(L, 2); player->setSex(newSex); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1456,7 +1829,7 @@ int PlayerFunctions::luaPlayerSetSex(lua_State* L) { int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { // player:getPronoun() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getPronoun()); } else { @@ -1467,11 +1840,11 @@ int PlayerFunctions::luaPlayerGetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { // player:setPronoun(newPronoun) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const PlayerPronoun_t newPronoun = getNumber(L, 2); + const PlayerPronoun_t newPronoun = Lua::getNumber(L, 2); player->setPronoun(newPronoun); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1480,10 +1853,10 @@ int PlayerFunctions::luaPlayerSetPronoun(lua_State* L) { int PlayerFunctions::luaPlayerGetTown(lua_State* L) { // player:getTown() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushUserdata(L, player->getTown()); - setMetatable(L, -1, "Town"); + Lua::pushUserdata(L, player->getTown()); + Lua::setMetatable(L, -1, "Town"); } else { lua_pushnil(L); } @@ -1492,16 +1865,16 @@ int PlayerFunctions::luaPlayerGetTown(lua_State* L) { int PlayerFunctions::luaPlayerSetTown(lua_State* L) { // player:setTown(town) - const auto &town = getUserdataShared(L, 2); + const auto &town = Lua::getUserdataShared(L, 2); if (!town) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->setTown(town); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1510,7 +1883,7 @@ int PlayerFunctions::luaPlayerSetTown(lua_State* L) { int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { // player:getGuild() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -1522,29 +1895,29 @@ int PlayerFunctions::luaPlayerGetGuild(lua_State* L) { return 1; } - pushUserdata(L, guild); - setMetatable(L, -1, "Guild"); + Lua::pushUserdata(L, guild); + Lua::setMetatable(L, -1, "Guild"); return 1; } int PlayerFunctions::luaPlayerSetGuild(lua_State* L) { // player:setGuild(guild) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &guild = getUserdataShared(L, 2); + const auto &guild = Lua::getUserdataShared(L, 2); player->setGuild(guild); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { // player:getGuildLevel() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player && player->getGuild()) { lua_pushnumber(L, player->getGuildRank()->level); } else { @@ -1555,8 +1928,8 @@ int PlayerFunctions::luaPlayerGetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { // player:setGuildLevel(level) - const uint8_t level = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const uint8_t level = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getGuild()) { lua_pushnil(L); return 1; @@ -1564,10 +1937,10 @@ int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { const auto &rank = player->getGuild()->getRankByLevel(level); if (!rank) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else { player->setGuildRank(rank); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } return 1; @@ -1575,9 +1948,9 @@ int PlayerFunctions::luaPlayerSetGuildLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { // player:getGuildNick() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushString(L, player->getGuildNick()); + Lua::pushString(L, player->getGuildNick()); } else { lua_pushnil(L); } @@ -1586,11 +1959,11 @@ int PlayerFunctions::luaPlayerGetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { // player:setGuildNick(nick) - const std::string &nick = getString(L, 2); - const auto &player = getUserdataShared(L, 1); + const std::string &nick = Lua::getString(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->setGuildNick(nick); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1599,10 +1972,10 @@ int PlayerFunctions::luaPlayerSetGuildNick(lua_State* L) { int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { // player:getGroup() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushUserdata(L, player->getGroup()); - setMetatable(L, -1, "Group"); + Lua::pushUserdata(L, player->getGroup()); + Lua::setMetatable(L, -1, "Group"); } else { lua_pushnil(L); } @@ -1611,16 +1984,16 @@ int PlayerFunctions::luaPlayerGetGroup(lua_State* L) { int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { // player:setGroup(group) - const auto &group = getUserdataShared(L, 2); + const auto &group = Lua::getUserdataShared(L, 2); if (!group) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->setGroup(group); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1629,13 +2002,13 @@ int PlayerFunctions::luaPlayerSetGroup(lua_State* L) { int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { // player:setSpecialContainersAvailable(stashMenu, marketMenu, depotSearchMenu) - const bool supplyStashMenu = getBoolean(L, 2, false); - const bool marketMenu = getBoolean(L, 3, false); - const bool depotSearchMenu = getBoolean(L, 4, false); - const auto &player = getUserdataShared(L, 1); + const bool supplyStashMenu = Lua::getBoolean(L, 2, false); + const bool marketMenu = Lua::getBoolean(L, 3, false); + const bool depotSearchMenu = Lua::getBoolean(L, 4, false); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->setSpecialMenuAvailable(supplyStashMenu, marketMenu, depotSearchMenu); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1644,7 +2017,7 @@ int PlayerFunctions::luaPlayerSetSpecialContainersAvailable(lua_State* L) { int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { // player:getStamina() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaMinutes()); } else { @@ -1655,8 +2028,8 @@ int PlayerFunctions::luaPlayerGetStamina(lua_State* L) { int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { // player:setStamina(stamina) - const uint16_t stamina = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const uint16_t stamina = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->staminaMinutes = std::min(2520, stamina); player->sendStats(); @@ -1668,7 +2041,7 @@ int PlayerFunctions::luaPlayerSetStamina(lua_State* L) { int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { // player:getSoul() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getSoul()); } else { @@ -1679,11 +2052,11 @@ int PlayerFunctions::luaPlayerGetSoul(lua_State* L) { int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { // player:addSoul(soulChange) - const int32_t soulChange = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const int32_t soulChange = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->changeSoul(soulChange); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1692,7 +2065,7 @@ int PlayerFunctions::luaPlayerAddSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { // player:getMaxSoul() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player && player->vocation) { lua_pushnumber(L, player->vocation->getSoulMax()); } else { @@ -1703,7 +2076,7 @@ int PlayerFunctions::luaPlayerGetMaxSoul(lua_State* L) { int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { // player:getBankBalance() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBankBalance()); } else { @@ -1714,51 +2087,51 @@ int PlayerFunctions::luaPlayerGetBankBalance(lua_State* L) { int PlayerFunctions::luaPlayerSetBankBalance(lua_State* L) { // player:setBankBalance(bankBalance) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - player->setBankBalance(getNumber(L, 2)); - pushBoolean(L, true); + player->setBankBalance(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetStorageValue(lua_State* L) { // player:getStorageValue(key) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint32_t key = getNumber(L, 2); + const uint32_t key = Lua::getNumber(L, 2); lua_pushnumber(L, player->getStorageValue(key)); return 1; } int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { // player:setStorageValue(key, value) - const int32_t value = getNumber(L, 3); - const uint32_t key = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const int32_t value = Lua::getNumber(L, 3); + const uint32_t key = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (IS_IN_KEYRANGE(key, RESERVED_RANGE)) { std::ostringstream ss; ss << "Accessing reserved range: " << key; - reportErrorFunc(ss.str()); - pushBoolean(L, false); + Lua::reportErrorFunc(ss.str()); + Lua::pushBoolean(L, false); return 1; } if (key == 0) { - reportErrorFunc("Storage key is nil"); + Lua::reportErrorFunc("Storage key is nil"); return 1; } if (player) { player->addStorageValue(key, value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -1767,58 +2140,58 @@ int PlayerFunctions::luaPlayerSetStorageValue(lua_State* L) { int PlayerFunctions::luaPlayerGetStorageValueByName(lua_State* L) { // player:getStorageValueByName(name) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } g_logger().warn("The function 'player:getStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); - const auto name = getString(L, 2); + const auto name = Lua::getString(L, 2); lua_pushnumber(L, player->getStorageValueByName(name)); return 1; } int PlayerFunctions::luaPlayerSetStorageValueByName(lua_State* L) { // player:setStorageValueByName(storageName, value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } g_logger().warn("The function 'player:setStorageValueByName' is deprecated and will be removed in future versions, please use KV system"); - const auto storageName = getString(L, 2); - const int32_t value = getNumber(L, 3); + const auto storageName = Lua::getString(L, 2); + const int32_t value = Lua::getNumber(L, 3); player->addStorageValueByName(storageName, value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddItem(lua_State* L) { // player:addItem(itemId, count = 1, canDropOnMap = true, subType = 1, slot = CONST_SLOT_WHEREEVER, tier = 0) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto count = getNumber(L, 3, 1); - auto subType = getNumber(L, 5, 1); + const auto count = Lua::getNumber(L, 3, 1); + auto subType = Lua::getNumber(L, 5, 1); const ItemType &it = Item::items[itemId]; @@ -1844,9 +2217,9 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { return 1; } - const bool canDropOnMap = getBoolean(L, 4, true); - const auto slot = getNumber(L, 6, CONST_SLOT_WHEREEVER); - const auto tier = getNumber(L, 7, 0); + const bool canDropOnMap = Lua::getBoolean(L, 4, true); + const auto slot = Lua::getNumber(L, 6, CONST_SLOT_WHEREEVER); + const auto tier = Lua::getNumber(L, 7, 0); for (int32_t i = 1; i <= itemCount; ++i) { int32_t stackCount = subType; if (it.stackable) { @@ -1878,12 +2251,12 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { if (hasTable) { lua_pushnumber(L, i); - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); lua_settable(L, -3); } else { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } } return 1; @@ -1892,33 +2265,33 @@ int PlayerFunctions::luaPlayerAddItem(lua_State* L) { int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { // player:addItemEx(item[, canDropOnMap = false[, index = INDEX_WHEREEVER[, flags = 0]]]) // player:addItemEx(item[, canDropOnMap = true[, slot = CONST_SLOT_WHEREEVER]]) - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } if (item->getParent() != VirtualCylinder::virtualCylinder) { - reportErrorFunc("Item already has a parent"); - pushBoolean(L, false); + Lua::reportErrorFunc("Item already has a parent"); + Lua::pushBoolean(L, false); return 1; } - const bool canDropOnMap = getBoolean(L, 3, false); + const bool canDropOnMap = Lua::getBoolean(L, 3, false); ReturnValue returnValue; if (canDropOnMap) { - const auto slot = getNumber(L, 4, CONST_SLOT_WHEREEVER); + const auto slot = Lua::getNumber(L, 4, CONST_SLOT_WHEREEVER); returnValue = g_game().internalPlayerAddItem(player, item, true, slot); } else { - const auto index = getNumber(L, 4, INDEX_WHEREEVER); - const auto flags = getNumber(L, 5, 0); + const auto index = Lua::getNumber(L, 4, INDEX_WHEREEVER); + const auto flags = Lua::getNumber(L, 5, 0); returnValue = g_game().internalAddItem(player, item, index, flags); } @@ -1931,33 +2304,33 @@ int PlayerFunctions::luaPlayerAddItemEx(lua_State* L) { int PlayerFunctions::luaPlayerAddItemStash(lua_State* L) { // player:addItemStash(itemId, count = 1) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto itemId = getNumber(L, 2); - const auto count = getNumber(L, 3, 1); + const auto itemId = Lua::getNumber(L, 2); + const auto count = Lua::getNumber(L, 3, 1); player->addItemOnStash(itemId, count); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { // player:removeStashItem(itemId, count) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; @@ -1970,78 +2343,78 @@ int PlayerFunctions::luaPlayerRemoveStashItem(lua_State* L) { return 1; } - const uint32_t count = getNumber(L, 3); - pushBoolean(L, player->withdrawItem(itemType.id, count)); + const uint32_t count = Lua::getNumber(L, 3); + Lua::pushBoolean(L, player->withdrawItem(itemType.id, count)); return 1; } int PlayerFunctions::luaPlayerRemoveItem(lua_State* L) { // player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const uint32_t count = getNumber(L, 3); - const auto subType = getNumber(L, 4, -1); - const bool ignoreEquipped = getBoolean(L, 5, false); - pushBoolean(L, player->removeItemOfType(itemId, count, subType, ignoreEquipped)); + const uint32_t count = Lua::getNumber(L, 3); + const auto subType = Lua::getNumber(L, 4, -1); + const bool ignoreEquipped = Lua::getBoolean(L, 5, false); + Lua::pushBoolean(L, player->removeItemOfType(itemId, count, subType, ignoreEquipped)); return 1; } int PlayerFunctions::luaPlayerSendContainer(lua_State* L) { // player:sendContainer(container) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &container = getUserdataShared(L, 2); + const auto &container = Lua::getUserdataShared(L, 2); if (!container) { lua_pushnil(L); return 1; } player->sendContainer(static_cast(container->getID()), container, container->hasParent(), static_cast(container->getFirstIndex())); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendUpdateContainer(lua_State* L) { // player:sendUpdateContainer(container) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &container = getUserdataShared(L, 2); + const auto &container = Lua::getUserdataShared(L, 2); if (!container) { - reportErrorFunc("Container is nullptr"); + Lua::reportErrorFunc("Container is nullptr"); return 1; } player->onSendContainer(container); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { // player:getMoney() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getMoney()); } else { @@ -2052,11 +2425,11 @@ int PlayerFunctions::luaPlayerGetMoney(lua_State* L) { int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { // player:addMoney(money) - const uint64_t money = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const uint64_t money = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { g_game().addMoney(player, money); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2065,12 +2438,12 @@ int PlayerFunctions::luaPlayerAddMoney(lua_State* L) { int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { // player:removeMoney(money[, flags = 0[, useBank = true]]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint64_t money = getNumber(L, 2); - const auto flags = getNumber(L, 3, 0); - const bool useBank = getBoolean(L, 4, true); - pushBoolean(L, g_game().removeMoney(player, money, flags, useBank)); + const uint64_t money = Lua::getNumber(L, 2); + const auto flags = Lua::getNumber(L, 3, 0); + const bool useBank = Lua::getBoolean(L, 4, true); + Lua::pushBoolean(L, g_game().removeMoney(player, money, flags, useBank)); } else { lua_pushnil(L); } @@ -2079,40 +2452,40 @@ int PlayerFunctions::luaPlayerRemoveMoney(lua_State* L) { int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { // player:showTextDialog(id or name or userdata[, text[, canWrite[, length]]]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - auto length = getNumber(L, 5, -1); - const bool canWrite = getBoolean(L, 4, false); + auto length = Lua::getNumber(L, 5, -1); + const bool canWrite = Lua::getBoolean(L, 4, false); std::string text; const int parameters = lua_gettop(L); if (parameters >= 3) { - text = getString(L, 3); + text = Lua::getString(L, 3); } std::shared_ptr item; - if (isNumber(L, 2)) { - item = Item::CreateItem(getNumber(L, 2)); - } else if (isString(L, 2)) { - item = Item::CreateItem(Item::items.getItemIdByName(getString(L, 2))); - } else if (isUserdata(L, 2)) { - if (getUserdataType(L, 2) != LuaData_t::Item) { - pushBoolean(L, false); + if (Lua::isNumber(L, 2)) { + item = Item::CreateItem(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + item = Item::CreateItem(Item::items.getItemIdByName(Lua::getString(L, 2))); + } else if (Lua::isUserdata(L, 2)) { + if (Lua::getUserdataType(L, 2) != LuaData_t::Item) { + Lua::pushBoolean(L, false); return 1; } - item = getUserdataShared(L, 2); + item = Lua::getUserdataShared(L, 2); } else { item = nullptr; } if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -2128,7 +2501,7 @@ int PlayerFunctions::luaPlayerShowTextDialog(lua_State* L) { item->setParent(player); player->setWriteItem(item, length); player->sendTextWindow(item, length, canWrite); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -2136,7 +2509,7 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { // player:sendTextMessage(type, text[, position, primaryValue = 0, primaryColor = TEXTCOLOR_NONE[, secondaryValue = 0, secondaryColor = TEXTCOLOR_NONE]]) // player:sendTextMessage(type, text, channelId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2144,91 +2517,91 @@ int PlayerFunctions::luaPlayerSendTextMessage(lua_State* L) { const int parameters = lua_gettop(L); - TextMessage message(getNumber(L, 2), getString(L, 3)); + TextMessage message(Lua::getNumber(L, 2), Lua::getString(L, 3)); if (parameters == 4) { - const uint16_t channelId = getNumber(L, 4); + const uint16_t channelId = Lua::getNumber(L, 4); const auto &channel = g_chat().getChannel(player, channelId); if (!channel || !channel->hasUser(player)) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } message.channelId = channelId; } else { if (parameters >= 6) { - message.position = getPosition(L, 4); - message.primary.value = getNumber(L, 5); - message.primary.color = getNumber(L, 6); + message.position = Lua::getPosition(L, 4); + message.primary.value = Lua::getNumber(L, 5); + message.primary.color = Lua::getNumber(L, 6); } if (parameters >= 8) { - message.secondary.value = getNumber(L, 7); - message.secondary.color = getNumber(L, 8); + message.secondary.value = Lua::getNumber(L, 7); + message.secondary.color = Lua::getNumber(L, 8); } } player->sendTextMessage(message); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendChannelMessage(lua_State* L) { // player:sendChannelMessage(author, text, type, channelId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint16_t channelId = getNumber(L, 5); - const SpeakClasses type = getNumber(L, 4); - const std::string &text = getString(L, 3); - const std::string &author = getString(L, 2); + const uint16_t channelId = Lua::getNumber(L, 5); + const SpeakClasses type = Lua::getNumber(L, 4); + const std::string &text = Lua::getString(L, 3); + const std::string &author = Lua::getString(L, 2); player->sendChannelMessage(author, text, type, channelId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendPrivateMessage(lua_State* L) { // player:sendPrivateMessage(speaker, text[, type]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &speaker = getUserdataShared(L, 2); - const std::string &text = getString(L, 3); - const auto type = getNumber(L, 4, TALKTYPE_PRIVATE_FROM); + const auto &speaker = Lua::getUserdataShared(L, 2); + const std::string &text = Lua::getString(L, 3); + const auto type = Lua::getNumber(L, 4, TALKTYPE_PRIVATE_FROM); player->sendPrivateMessage(speaker, type, text); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerChannelSay(lua_State* L) { // player:channelSay(speaker, type, text, channelId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &speaker = getCreature(L, 2); - const SpeakClasses type = getNumber(L, 3); - const std::string &text = getString(L, 4); - const uint16_t channelId = getNumber(L, 5); + const auto &speaker = Lua::getCreature(L, 2); + const SpeakClasses type = Lua::getNumber(L, 3); + const std::string &text = Lua::getString(L, 4); + const uint16_t channelId = Lua::getNumber(L, 5); player->sendToChannel(speaker, type, text, channelId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { // player:openChannel(channelId) - const uint16_t channelId = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const uint16_t channelId = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { g_game().playerOpenChannel(player->getID(), channelId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2237,13 +2610,13 @@ int PlayerFunctions::luaPlayerOpenChannel(lua_State* L) { int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { // player:getSlotItem(slot) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint32_t slot = getNumber(L, 2); + const uint32_t slot = Lua::getNumber(L, 2); const auto &thing = player->getThing(slot); if (!thing) { lua_pushnil(L); @@ -2252,8 +2625,8 @@ int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { const auto &item = thing->getItem(); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -2262,7 +2635,7 @@ int PlayerFunctions::luaPlayerGetSlotItem(lua_State* L) { int PlayerFunctions::luaPlayerGetParty(lua_State* L) { // player:getParty() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2270,8 +2643,8 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { const auto &party = player->getParty(); if (party) { - pushUserdata(L, party); - setMetatable(L, -1, "Party"); + Lua::pushUserdata(L, party); + Lua::setMetatable(L, -1, "Party"); } else { lua_pushnil(L); } @@ -2280,23 +2653,23 @@ int PlayerFunctions::luaPlayerGetParty(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { // player:addOutfit(lookType or name, addon = 0) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - auto addon = getNumber(L, 3, 0); + auto addon = Lua::getNumber(L, 3, 0); if (lua_isnumber(L, 2)) { - player->addOutfit(getNumber(L, 2), addon); + player->addOutfit(Lua::getNumber(L, 2), addon); } else if (lua_isstring(L, 2)) { - const std::string &outfitName = getString(L, 2); + const std::string &outfitName = Lua::getString(L, 2); const auto &outfit = Outfits::getInstance().getOutfitByName(player->getSex(), outfitName); if (!outfit) { - reportErrorFunc("Outfit not found"); + Lua::reportErrorFunc("Outfit not found"); return 1; } player->addOutfit(outfit->lookType, addon); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2305,12 +2678,12 @@ int PlayerFunctions::luaPlayerAddOutfit(lua_State* L) { int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { // player:addOutfitAddon(lookType, addon) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - const uint8_t addon = getNumber(L, 3); + const uint16_t lookType = Lua::getNumber(L, 2); + const uint8_t addon = Lua::getNumber(L, 3); player->addOutfit(lookType, addon); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2319,10 +2692,10 @@ int PlayerFunctions::luaPlayerAddOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { // player:removeOutfit(lookType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - pushBoolean(L, player->removeOutfit(lookType)); + const uint16_t lookType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, player->removeOutfit(lookType)); } else { lua_pushnil(L); } @@ -2331,11 +2704,11 @@ int PlayerFunctions::luaPlayerRemoveOutfit(lua_State* L) { int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { // player:removeOutfitAddon(lookType, addon) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - const uint8_t addon = getNumber(L, 3); - pushBoolean(L, player->removeOutfitAddon(lookType, addon)); + const uint16_t lookType = Lua::getNumber(L, 2); + const uint8_t addon = Lua::getNumber(L, 3); + Lua::pushBoolean(L, player->removeOutfitAddon(lookType, addon)); } else { lua_pushnil(L); } @@ -2344,11 +2717,11 @@ int PlayerFunctions::luaPlayerRemoveOutfitAddon(lua_State* L) { int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { // player:hasOutfit(lookType[, addon = 0]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - const auto addon = getNumber(L, 3, 0); - pushBoolean(L, player->canWear(lookType, addon)); + const uint16_t lookType = Lua::getNumber(L, 2); + const auto addon = Lua::getNumber(L, 3, 0); + Lua::pushBoolean(L, player->canWear(lookType, addon)); } else { lua_pushnil(L); } @@ -2357,10 +2730,10 @@ int PlayerFunctions::luaPlayerHasOutfit(lua_State* L) { int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { // player:sendOutfitWindow() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { player->sendOutfitWindow(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2369,67 +2742,67 @@ int PlayerFunctions::luaPlayerSendOutfitWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMount(lua_State* L) { // player:addMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint8_t mountId; - if (isNumber(L, 2)) { - mountId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + mountId = Lua::getNumber(L, 2); } else { - const auto &mount = g_game().mounts->getMountByName(getString(L, 2)); + const auto &mount = g_game().mounts->getMountByName(Lua::getString(L, 2)); if (!mount) { lua_pushnil(L); return 1; } mountId = mount->id; } - pushBoolean(L, player->tameMount(mountId)); + Lua::pushBoolean(L, player->tameMount(mountId)); return 1; } int PlayerFunctions::luaPlayerRemoveMount(lua_State* L) { // player:removeMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } uint8_t mountId; - if (isNumber(L, 2)) { - mountId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + mountId = Lua::getNumber(L, 2); } else { - const auto &mount = g_game().mounts->getMountByName(getString(L, 2)); + const auto &mount = g_game().mounts->getMountByName(Lua::getString(L, 2)); if (!mount) { lua_pushnil(L); return 1; } mountId = mount->id; } - pushBoolean(L, player->untameMount(mountId)); + Lua::pushBoolean(L, player->untameMount(mountId)); return 1; } int PlayerFunctions::luaPlayerHasMount(lua_State* L) { // player:hasMount(mountId or mountName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } std::shared_ptr mount = nullptr; - if (isNumber(L, 2)) { - mount = g_game().mounts->getMountByID(getNumber(L, 2)); + if (Lua::isNumber(L, 2)) { + mount = g_game().mounts->getMountByID(Lua::getNumber(L, 2)); } else { - mount = g_game().mounts->getMountByName(getString(L, 2)); + mount = g_game().mounts->getMountByName(Lua::getString(L, 2)); } if (mount) { - pushBoolean(L, player->hasMount(mount)); + Lua::pushBoolean(L, player->hasMount(mount)); } else { lua_pushnil(L); } @@ -2438,10 +2811,10 @@ int PlayerFunctions::luaPlayerHasMount(lua_State* L) { int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { // player:addFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->addFamiliar(getNumber(L, 2)); - pushBoolean(L, true); + player->addFamiliar(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2450,10 +2823,10 @@ int PlayerFunctions::luaPlayerAddFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { // player:removeFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - pushBoolean(L, player->removeFamiliar(lookType)); + const uint16_t lookType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, player->removeFamiliar(lookType)); } else { lua_pushnil(L); } @@ -2462,10 +2835,10 @@ int PlayerFunctions::luaPlayerRemoveFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { // player:hasFamiliar(lookType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t lookType = getNumber(L, 2); - pushBoolean(L, player->canFamiliar(lookType)); + const uint16_t lookType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, player->canFamiliar(lookType)); } else { lua_pushnil(L); } @@ -2474,10 +2847,10 @@ int PlayerFunctions::luaPlayerHasFamiliar(lua_State* L) { int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { // player:setFamiliarLooktype(lookType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setFamiliarLooktype(getNumber(L, 2)); - pushBoolean(L, true); + player->setFamiliarLooktype(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2486,7 +2859,7 @@ int PlayerFunctions::luaPlayerSetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { // player:getFamiliarLooktype() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->defaultOutfit.lookFamiliarsType); } else { @@ -2497,7 +2870,7 @@ int PlayerFunctions::luaPlayerGetFamiliarLooktype(lua_State* L) { int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { // player:getPremiumDays() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player && player->getAccount()) { lua_pushnumber(L, player->getAccount()->getPremiumRemainingDays()); } else { @@ -2508,7 +2881,7 @@ int PlayerFunctions::luaPlayerGetPremiumDays(lua_State* L) { int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { // player:addPremiumDays(days) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2520,7 +2893,7 @@ int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { return 1; } - const int32_t addDays = std::min(0xFFFE - premiumDays, getNumber(L, 2)); + const int32_t addDays = std::min(0xFFFE - premiumDays, Lua::getNumber(L, 2)); if (addDays <= 0) { return 1; } @@ -2531,13 +2904,13 @@ int PlayerFunctions::luaPlayerAddPremiumDays(lua_State* L) { return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { // player:removePremiumDays(days) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { lua_pushnil(L); return 1; @@ -2549,7 +2922,7 @@ int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { return 1; } - const int32_t removeDays = std::min(0xFFFE - premiumDays, getNumber(L, 2)); + const int32_t removeDays = std::min(0xFFFE - premiumDays, Lua::getNumber(L, 2)); if (removeDays <= 0) { return 1; } @@ -2560,15 +2933,15 @@ int PlayerFunctions::luaPlayerRemovePremiumDays(lua_State* L) { return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { // player:getTibiaCoins() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } @@ -2584,60 +2957,60 @@ int PlayerFunctions::luaPlayerGetTibiaCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTibiaCoins(lua_State* L) { // player:addTibiaCoins(coins) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } - if (player->account->addCoins(CoinType::Normal, getNumber(L, 2)) != AccountErrors_t::Ok) { - reportErrorFunc("Failed to add coins"); + if (player->account->addCoins(CoinType::Normal, Lua::getNumber(L, 2)) != AccountErrors_t::Ok) { + Lua::reportErrorFunc("Failed to add coins"); lua_pushnil(L); return 1; } if (player->getAccount()->save() != AccountErrors_t::Ok) { - reportErrorFunc("Failed to save account"); + Lua::reportErrorFunc("Failed to save account"); lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveTibiaCoins(lua_State* L) { // player:removeTibiaCoins(coins) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } - if (player->account->removeCoins(CoinType::Normal, getNumber(L, 2)) != AccountErrors_t::Ok) { - reportErrorFunc("Failed to remove coins"); + if (player->account->removeCoins(CoinType::Normal, Lua::getNumber(L, 2)) != AccountErrors_t::Ok) { + Lua::reportErrorFunc("Failed to remove coins"); return 1; } if (player->getAccount()->save() != AccountErrors_t::Ok) { - reportErrorFunc("Failed to save account"); + Lua::reportErrorFunc("Failed to save account"); lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { // player:getTransferableCoins() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } @@ -2653,62 +3026,76 @@ int PlayerFunctions::luaPlayerGetTransferableCoins(lua_State* L) { int PlayerFunctions::luaPlayerAddTransferableCoins(lua_State* L) { // player:addTransferableCoins(coins) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } - if (player->account->addCoins(CoinType::Transferable, getNumber(L, 2)) != AccountErrors_t::Ok) { - reportErrorFunc("failed to add transferable coins"); + if (player->account->addCoins(CoinType::Transferable, Lua::getNumber(L, 2)) != AccountErrors_t::Ok) { + Lua::reportErrorFunc("failed to add transferable coins"); lua_pushnil(L); return 1; } if (player->getAccount()->save() != AccountErrors_t::Ok) { - reportErrorFunc("failed to save account"); + Lua::reportErrorFunc("failed to save account"); lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveTransferableCoins(lua_State* L) { // player:removeTransferableCoins(coins) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player || !player->getAccount()) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); lua_pushnil(L); return 1; } - if (player->account->removeCoins(CoinType::Transferable, getNumber(L, 2)) != AccountErrors_t::Ok) { - reportErrorFunc("failed to remove transferable coins"); + if (player->account->removeCoins(CoinType::Transferable, Lua::getNumber(L, 2)) != AccountErrors_t::Ok) { + Lua::reportErrorFunc("failed to remove transferable coins"); lua_pushnil(L); return 1; } if (player->getAccount()->save() != AccountErrors_t::Ok) { - reportErrorFunc("failed to save account"); + Lua::reportErrorFunc("failed to save account"); lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); + + return 1; +} +int PlayerFunctions::luaPlayerSendBlessStatus(lua_State* L) { + // player:sendBlessStatus() + const auto &player = Lua::getUserdataShared(L, 1); + if (!player) { + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); + return 0; + } + + player->sendBlessStatus(); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { // player:hasBlessing(blessing) - const uint8_t blessing = getNumber(L, 2); - const auto &player = getUserdataShared(L, 1); + const uint8_t blessing = Lua::getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->hasBlessing(blessing)); + Lua::pushBoolean(L, player->hasBlessing(blessing)); } else { lua_pushnil(L); } @@ -2717,52 +3104,52 @@ int PlayerFunctions::luaPlayerHasBlessing(lua_State* L) { int PlayerFunctions::luaPlayerAddBlessing(lua_State* L) { // player:addBlessing(blessing) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint8_t blessing = getNumber(L, 2); - const uint8_t count = getNumber(L, 3); + const uint8_t blessing = Lua::getNumber(L, 2); + const uint8_t count = Lua::getNumber(L, 3); player->addBlessing(blessing, count); player->sendBlessStatus(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveBlessing(lua_State* L) { // player:removeBlessing(blessing) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const uint8_t blessing = getNumber(L, 2); - const uint8_t count = getNumber(L, 3); + const uint8_t blessing = Lua::getNumber(L, 2); + const uint8_t count = Lua::getNumber(L, 3); if (!player->hasBlessing(blessing)) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } player->removeBlessing(blessing, count); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { // player:getBlessingCount(index[, storeCount = false]) - const auto &player = getUserdataShared(L, 1); - uint8_t index = getNumber(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); + uint8_t index = Lua::getNumber(L, 2); if (index == 0) { index = 1; } if (player) { - lua_pushnumber(L, player->getBlessingCount(index, getBoolean(L, 3, false))); + lua_pushnumber(L, player->getBlessingCount(index, Lua::getBoolean(L, 3, false))); } else { lua_pushnil(L); } @@ -2771,45 +3158,45 @@ int PlayerFunctions::luaPlayerGetBlessingCount(lua_State* L) { int PlayerFunctions::luaPlayerCanLearnSpell(lua_State* L) { // player:canLearnSpell(spellName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const std::string &spellName = getString(L, 2); + const std::string &spellName = Lua::getString(L, 2); const auto &spell = g_spells().getInstantSpellByName(spellName); if (!spell) { - reportErrorFunc("Spell \"" + spellName + "\" not found"); - pushBoolean(L, false); + Lua::reportErrorFunc("Spell \"" + spellName + "\" not found"); + Lua::pushBoolean(L, false); return 1; } if (player->hasFlag(PlayerFlags_t::IgnoreSpellCheck)) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } const auto vocMap = spell->getVocMap(); if (!vocMap.contains(player->getVocationId())) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else if (player->getLevel() < spell->getLevel()) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else if (player->getMagicLevel() < spell->getMagicLevel()) { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } else { - pushBoolean(L, true); + Lua::pushBoolean(L, true); } return 1; } int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { // player:learnSpell(spellName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const std::string &spellName = getString(L, 2); + const std::string &spellName = Lua::getString(L, 2); player->learnInstantSpell(spellName); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2818,11 +3205,11 @@ int PlayerFunctions::luaPlayerLearnSpell(lua_State* L) { int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { // player:forgetSpell(spellName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const std::string &spellName = getString(L, 2); + const std::string &spellName = Lua::getString(L, 2); player->forgetInstantSpell(spellName); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2831,10 +3218,10 @@ int PlayerFunctions::luaPlayerForgetSpell(lua_State* L) { int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { // player:hasLearnedSpell(spellName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const std::string &spellName = getString(L, 2); - pushBoolean(L, player->hasLearnedInstantSpell(spellName)); + const std::string &spellName = Lua::getString(L, 2); + Lua::pushBoolean(L, player->hasLearnedInstantSpell(spellName)); } else { lua_pushnil(L); } @@ -2843,11 +3230,11 @@ int PlayerFunctions::luaPlayerHasLearnedSpell(lua_State* L) { int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { // player:sendTutorial(tutorialId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint8_t tutorialId = getNumber(L, 2); + const uint8_t tutorialId = Lua::getNumber(L, 2); player->sendTutorial(tutorialId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2856,17 +3243,17 @@ int PlayerFunctions::luaPlayerSendTutorial(lua_State* L) { int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { // player:openImbuementWindow(item) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -2876,10 +3263,10 @@ int PlayerFunctions::luaPlayerOpenImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { // player:closeImbuementWindow() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -2889,13 +3276,13 @@ int PlayerFunctions::luaPlayerCloseImbuementWindow(lua_State* L) { int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { // player:addMapMark(position, type, description) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const Position &position = getPosition(L, 2); - const uint8_t type = getNumber(L, 3); - const std::string &description = getString(L, 4); + const Position &position = Lua::getPosition(L, 2); + const uint8_t type = Lua::getNumber(L, 3); + const std::string &description = Lua::getString(L, 4); player->sendAddMarker(position, type, description); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2904,12 +3291,12 @@ int PlayerFunctions::luaPlayerAddMapMark(lua_State* L) { int PlayerFunctions::luaPlayerSave(lua_State* L) { // player:save() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { if (!player->isOffline()) { player->loginPosition = player->getPosition(); } - pushBoolean(L, g_saveManager().savePlayer(player)); + Lua::pushBoolean(L, g_saveManager().savePlayer(player)); } else { lua_pushnil(L); } @@ -2918,11 +3305,11 @@ int PlayerFunctions::luaPlayerSave(lua_State* L) { int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { // player:popupFYI(message) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const std::string &message = getString(L, 2); + const std::string &message = Lua::getString(L, 2); player->sendFYIBox(message); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -2931,9 +3318,9 @@ int PlayerFunctions::luaPlayerPopupFYI(lua_State* L) { int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { // player:isPzLocked() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->isPzLocked()); + Lua::pushBoolean(L, player->isPzLocked()); } else { lua_pushnil(L); } @@ -2942,11 +3329,11 @@ int PlayerFunctions::luaPlayerIsPzLocked(lua_State* L) { int PlayerFunctions::luaPlayerGetClient(lua_State* L) { // player:getClient() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_createtable(L, 0, 2); - setField(L, "version", player->getProtocolVersion()); - setField(L, "os", player->getOperatingSystem()); + Lua::setField(L, "version", player->getProtocolVersion()); + Lua::setField(L, "os", player->getOperatingSystem()); } else { lua_pushnil(L); } @@ -2955,7 +3342,7 @@ int PlayerFunctions::luaPlayerGetClient(lua_State* L) { int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { // player:getHouse() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -2963,8 +3350,8 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { const auto &house = g_game().map.houses.getHouseByPlayerId(player->getGUID()); if (house) { - pushUserdata(L, house); - setMetatable(L, -1, "House"); + Lua::pushUserdata(L, house); + Lua::setMetatable(L, -1, "House"); } else { lua_pushnil(L); } @@ -2973,55 +3360,55 @@ int PlayerFunctions::luaPlayerGetHouse(lua_State* L) { int PlayerFunctions::luaPlayerSendHouseWindow(lua_State* L) { // player:sendHouseWindow(house, listId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &house = getUserdataShared(L, 2); + const auto &house = Lua::getUserdataShared(L, 2); if (!house) { lua_pushnil(L); return 1; } - const uint32_t listId = getNumber(L, 3); + const uint32_t listId = Lua::getNumber(L, 3); player->sendHouseWindow(house, listId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSetEditHouse(lua_State* L) { // player:setEditHouse(house, listId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &house = getUserdataShared(L, 2); + const auto &house = Lua::getUserdataShared(L, 2); if (!house) { lua_pushnil(L); return 1; } - const uint32_t listId = getNumber(L, 3); + const uint32_t listId = Lua::getNumber(L, 3); player->setEditHouse(house, listId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { // player:setGhostMode(enabled) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const bool enabled = getBoolean(L, 2); + const bool enabled = Lua::getBoolean(L, 2); if (player->isInGhostMode() == enabled) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -3056,19 +3443,19 @@ int PlayerFunctions::luaPlayerSetGhostMode(lua_State* L) { } } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { // player:getContainerId(container) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &container = getUserdataShared(L, 2); + const auto &container = Lua::getUserdataShared(L, 2); if (container) { lua_pushnumber(L, player->getContainerID(container)); } else { @@ -3079,16 +3466,16 @@ int PlayerFunctions::luaPlayerGetContainerId(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { // player:getContainerById(id) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto &container = player->getContainerByID(getNumber(L, 2)); + const auto &container = player->getContainerByID(Lua::getNumber(L, 2)); if (container) { - pushUserdata(L, container); - setMetatable(L, -1, "Container"); + Lua::pushUserdata(L, container); + Lua::setMetatable(L, -1, "Container"); } else { lua_pushnil(L); } @@ -3097,9 +3484,9 @@ int PlayerFunctions::luaPlayerGetContainerById(lua_State* L) { int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { // player:getContainerIndex(id) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - lua_pushnumber(L, player->getContainerIndex(getNumber(L, 2))); + lua_pushnumber(L, player->getContainerIndex(Lua::getNumber(L, 2))); } else { lua_pushnil(L); } @@ -3108,7 +3495,7 @@ int PlayerFunctions::luaPlayerGetContainerIndex(lua_State* L) { int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { // player:getInstantSpells() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3125,7 +3512,7 @@ int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { int index = 0; for (const auto &spell : spells) { - pushInstantSpell(L, *spell); + Lua::pushInstantSpell(L, *spell); lua_rawseti(L, -2, ++index); } return 1; @@ -3133,10 +3520,10 @@ int PlayerFunctions::luaPlayerGetInstantSpells(lua_State* L) { int PlayerFunctions::luaPlayerCanCast(lua_State* L) { // player:canCast(spell) - const auto &player = getUserdataShared(L, 1); - const auto &spell = getUserdataShared(L, 2); + const auto &player = Lua::getUserdataShared(L, 1); + const auto &spell = Lua::getUserdataShared(L, 2); if (player && spell) { - pushBoolean(L, spell->canCast(player)); + Lua::pushBoolean(L, spell->canCast(player)); } else { lua_pushnil(L); } @@ -3145,9 +3532,9 @@ int PlayerFunctions::luaPlayerCanCast(lua_State* L) { int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { // player:hasChaseMode() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->chaseMode); + Lua::pushBoolean(L, player->chaseMode); } else { lua_pushnil(L); } @@ -3156,9 +3543,9 @@ int PlayerFunctions::luaPlayerHasChaseMode(lua_State* L) { int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { // player:hasSecureMode() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->secureMode); + Lua::pushBoolean(L, player->secureMode); } else { lua_pushnil(L); } @@ -3167,7 +3554,7 @@ int PlayerFunctions::luaPlayerHasSecureMode(lua_State* L) { int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { // player:getFightMode() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->fightMode); } else { @@ -3178,7 +3565,7 @@ int PlayerFunctions::luaPlayerGetFightMode(lua_State* L) { int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { // player:getBaseXpGain() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getBaseXpGain()); } else { @@ -3189,11 +3576,11 @@ int PlayerFunctions::luaPlayerGetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { // player:setBaseXpGain(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setBaseXpGain(getNumber(L, 2)); + player->setBaseXpGain(Lua::getNumber(L, 2)); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3202,7 +3589,7 @@ int PlayerFunctions::luaPlayerSetBaseXpGain(lua_State* L) { int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { // player:getVoucherXpBoost() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getVoucherXpBoost()); } else { @@ -3213,11 +3600,11 @@ int PlayerFunctions::luaPlayerGetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { // player:setVoucherXpBoost(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setVoucherXpBoost(getNumber(L, 2)); + player->setVoucherXpBoost(Lua::getNumber(L, 2)); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3226,7 +3613,7 @@ int PlayerFunctions::luaPlayerSetVoucherXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { // player:getGrindingXpBoost() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getGrindingXpBoost()); } else { @@ -3237,11 +3624,11 @@ int PlayerFunctions::luaPlayerGetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { // player:setGrindingXpBoost(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setGrindingXpBoost(getNumber(L, 2)); + player->setGrindingXpBoost(Lua::getNumber(L, 2)); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3250,7 +3637,7 @@ int PlayerFunctions::luaPlayerSetGrindingXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerGetXpBoostPercent(lua_State* L) { // player:getXpBoostPercent() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getXpBoostPercent()); } else { @@ -3261,11 +3648,11 @@ int PlayerFunctions::luaPlayerGetXpBoostPercent(lua_State* L) { int PlayerFunctions::luaPlayerSetXpBoostPercent(lua_State* L) { // player:setXpBoostPercent(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t percent = getNumber(L, 2); + const uint16_t percent = Lua::getNumber(L, 2); player->setXpBoostPercent(percent); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3274,7 +3661,7 @@ int PlayerFunctions::luaPlayerSetXpBoostPercent(lua_State* L) { int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { // player:getStaminaXpBoost() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getStaminaXpBoost()); } else { @@ -3285,11 +3672,11 @@ int PlayerFunctions::luaPlayerGetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { // player:setStaminaXpBoost(value) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - player->setStaminaXpBoost(getNumber(L, 2)); + player->setStaminaXpBoost(Lua::getNumber(L, 2)); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3298,12 +3685,12 @@ int PlayerFunctions::luaPlayerSetStaminaXpBoost(lua_State* L) { int PlayerFunctions::luaPlayerSetXpBoostTime(lua_State* L) { // player:setXpBoostTime(timeLeft) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - const uint16_t timeLeft = getNumber(L, 2); + const uint16_t timeLeft = Lua::getNumber(L, 2); player->setXpBoostTime(timeLeft); player->sendStats(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3312,7 +3699,7 @@ int PlayerFunctions::luaPlayerSetXpBoostTime(lua_State* L) { int PlayerFunctions::luaPlayerGetXpBoostTime(lua_State* L) { // player:getXpBoostTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getXpBoostTime()); } else { @@ -3323,7 +3710,7 @@ int PlayerFunctions::luaPlayerGetXpBoostTime(lua_State* L) { int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { // player:getIdleTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { lua_pushnumber(L, player->getIdleTime()); } else { @@ -3334,7 +3721,7 @@ int PlayerFunctions::luaPlayerGetIdleTime(lua_State* L) { int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { // player:getFreeBackpackSlots() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); } @@ -3344,11 +3731,11 @@ int PlayerFunctions::luaPlayerGetFreeBackpackSlots(lua_State* L) { } int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player) { - pushBoolean(L, player->isOffline()); + Lua::pushBoolean(L, player->isOffline()); } else { - pushBoolean(L, true); + Lua::pushBoolean(L, true); } return 1; @@ -3356,80 +3743,80 @@ int PlayerFunctions::luaPlayerIsOffline(lua_State* L) { int PlayerFunctions::luaPlayerOpenMarket(lua_State* L) { // player:openMarket() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } player->sendMarketEnter(player->getLastDepotId()); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } // Forge int PlayerFunctions::luaPlayerOpenForge(lua_State* L) { // player:openForge() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } player->sendOpenForge(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerCloseForge(lua_State* L) { // player:closeForge() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } player->closeForgeWindow(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddForgeDusts(lua_State* L) { // player:addForgeDusts(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->addForgeDusts(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->addForgeDusts(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveForgeDusts(lua_State* L) { // player:removeForgeDusts(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->removeForgeDusts(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->removeForgeDusts(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { // player:getForgeDusts() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -3439,52 +3826,52 @@ int PlayerFunctions::luaPlayerGetForgeDusts(lua_State* L) { int PlayerFunctions::luaPlayerSetForgeDusts(lua_State* L) { // player:setForgeDusts() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->setForgeDusts(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->setForgeDusts(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddForgeDustLevel(lua_State* L) { // player:addForgeDustLevel(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->addForgeDustLevel(getNumber(L, 2, 1)); - pushBoolean(L, true); + player->addForgeDustLevel(Lua::getNumber(L, 2, 1)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveForgeDustLevel(lua_State* L) { // player:removeForgeDustLevel(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->removeForgeDustLevel(getNumber(L, 2, 1)); - pushBoolean(L, true); + player->removeForgeDustLevel(Lua::getNumber(L, 2, 1)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { // player:getForgeDustLevel() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -3494,10 +3881,10 @@ int PlayerFunctions::luaPlayerGetForgeDustLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { // player:getForgeSlivers() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -3508,10 +3895,10 @@ int PlayerFunctions::luaPlayerGetForgeSlivers(lua_State* L) { int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { // player:getForgeCores() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -3522,25 +3909,25 @@ int PlayerFunctions::luaPlayerGetForgeCores(lua_State* L) { int PlayerFunctions::luaPlayerSetFaction(lua_State* L) { // player:setFaction(factionId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player == nullptr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const Faction_t factionId = getNumber(L, 2); + const Faction_t factionId = Lua::getNumber(L, 2); player->setFaction(factionId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { // player:getFaction() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (player == nullptr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -3550,52 +3937,52 @@ int PlayerFunctions::luaPlayerGetFaction(lua_State* L) { int PlayerFunctions::luaPlayerIsUIExhausted(lua_State* L) { // player:isUIExhausted() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const uint16_t time = getNumber(L, 2); - pushBoolean(L, player->isUIExhausted(time)); + const uint16_t time = Lua::getNumber(L, 2); + Lua::pushBoolean(L, player->isUIExhausted(time)); return 1; } int PlayerFunctions::luaPlayerUpdateUIExhausted(lua_State* L) { // player:updateUIExhausted(exhaustionTime = 250) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } player->updateUIExhausted(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } // Bosstiary Cooldown Timer int PlayerFunctions::luaPlayerBosstiaryCooldownTimer(lua_State* L) { // player:sendBosstiaryCooldownTimer() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } player->sendBosstiaryCooldownTimer(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { // player:getBosstiaryLevel(name) - if (const auto &player = getUserdataShared(L, 1); + if (const auto &player = Lua::getUserdataShared(L, 1); player) { - const auto &mtype = g_monsters().getMonsterType(getString(L, 2)); + const auto &mtype = g_monsters().getMonsterType(Lua::getString(L, 2)); if (mtype) { const uint32_t bossId = mtype->info.raceid; if (bossId == 0) { @@ -3615,9 +4002,9 @@ int PlayerFunctions::luaPlayerGetBosstiaryLevel(lua_State* L) { int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { // player:getBosstiaryKills(name) - if (const auto &player = getUserdataShared(L, 1); + if (const auto &player = Lua::getUserdataShared(L, 1); player) { - const auto &mtype = g_monsters().getMonsterType(getString(L, 2)); + const auto &mtype = g_monsters().getMonsterType(Lua::getString(L, 2)); if (mtype) { const uint32_t bossId = mtype->info.raceid; if (bossId == 0) { @@ -3637,12 +4024,12 @@ int PlayerFunctions::luaPlayerGetBosstiaryKills(lua_State* L) { int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { // player:addBosstiaryKill(name[, amount = 1]) - if (const auto &player = getUserdataShared(L, 1); + if (const auto &player = Lua::getUserdataShared(L, 1); player) { - const auto &mtype = g_monsters().getMonsterType(getString(L, 2)); + const auto &mtype = g_monsters().getMonsterType(Lua::getString(L, 2)); if (mtype) { - g_ioBosstiary().addBosstiaryKill(player, mtype, getNumber(L, 3, 1)); - pushBoolean(L, true); + g_ioBosstiary().addBosstiaryKill(player, mtype, Lua::getNumber(L, 3, 1)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -3654,42 +4041,42 @@ int PlayerFunctions::luaPlayerAddBosstiaryKill(lua_State* L) { int PlayerFunctions::luaPlayerSetBossPoints(lua_State* L) { // player:setBossPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->setBossPoints(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->setBossPoints(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSetRemoveBossTime(lua_State* L) { // player:setRemoveBossTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->setRemoveBossTime(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->setRemoveBossTime(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { // player:getSlotBossId(slotId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const uint8_t slotId = getNumber(L, 2); + const uint8_t slotId = Lua::getNumber(L, 2); const auto bossId = player->getSlotBossId(slotId); lua_pushnumber(L, static_cast(bossId)); return 1; @@ -3697,14 +4084,14 @@ int PlayerFunctions::luaPlayerGetSlotBossId(lua_State* L) { int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { // player:getBossBonus(slotId) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const uint8_t slotId = getNumber(L, 2); + const uint8_t slotId = Lua::getNumber(L, 2); const auto bossId = player->getSlotBossId(slotId); const uint32_t playerBossPoints = player->getBossPoints(); @@ -3719,65 +4106,65 @@ int PlayerFunctions::luaPlayerGetBossBonus(lua_State* L) { int PlayerFunctions::luaPlayerSendSingleSoundEffect(lua_State* L) { // player:sendSingleSoundEffect(soundId[, actor = true]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const SoundEffect_t soundEffect = getNumber(L, 2); - const bool actor = getBoolean(L, 3, true); + const SoundEffect_t soundEffect = Lua::getNumber(L, 2); + const bool actor = Lua::getBoolean(L, 3, true); player->sendSingleSoundEffect(player->getPosition(), soundEffect, actor ? SourceEffect_t::OWN : SourceEffect_t::GLOBAL); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendDoubleSoundEffect(lua_State* L) { // player:sendDoubleSoundEffect(mainSoundId, secondarySoundId[, actor = true]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const SoundEffect_t mainSoundEffect = getNumber(L, 2); - const SoundEffect_t secondarySoundEffect = getNumber(L, 3); - const bool actor = getBoolean(L, 4, true); + const SoundEffect_t mainSoundEffect = Lua::getNumber(L, 2); + const SoundEffect_t secondarySoundEffect = Lua::getNumber(L, 3); + const bool actor = Lua::getBoolean(L, 4, true); player->sendDoubleSoundEffect(player->getPosition(), mainSoundEffect, actor ? SourceEffect_t::OWN : SourceEffect_t::GLOBAL, secondarySoundEffect, actor ? SourceEffect_t::OWN : SourceEffect_t::GLOBAL); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetName(lua_State* L) { // player:getName() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushString(L, player->getName()); + Lua::pushString(L, player->getName()); return 1; } int PlayerFunctions::luaPlayerChangeName(lua_State* L) { // player:changeName(newName) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } if (player->isOnline()) { player->removePlayer(true, true); } player->kv()->remove("namelock"); - const auto newName = getString(L, 2); + const auto newName = Lua::getString(L, 2); player->setName(newName); g_saveManager().savePlayer(player); return 1; @@ -3785,64 +4172,64 @@ int PlayerFunctions::luaPlayerChangeName(lua_State* L) { int PlayerFunctions::luaPlayerHasGroupFlag(lua_State* L) { // player:hasGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushBoolean(L, player->hasFlag(getNumber(L, 2))); + Lua::pushBoolean(L, player->hasFlag(Lua::getNumber(L, 2))); return 1; } int PlayerFunctions::luaPlayerSetGroupFlag(lua_State* L) { // player:setGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->setFlag(getNumber(L, 2)); + player->setFlag(Lua::getNumber(L, 2)); return 1; } int PlayerFunctions::luaPlayerRemoveGroupFlag(lua_State* L) { // player:removeGroupFlag(flag) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - player->removeFlag(getNumber(L, 2)); + player->removeFlag(Lua::getNumber(L, 2)); return 1; } // Hazard system int PlayerFunctions::luaPlayerAddHazardSystemPoints(lua_State* L) { // player:setHazardSystemPoints(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - player->setHazardSystemPoints(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->setHazardSystemPoints(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { // player:getHazardSystemPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - pushBoolean(L, false); - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } @@ -3852,20 +4239,20 @@ int PlayerFunctions::luaPlayerGetHazardSystemPoints(lua_State* L) { int PlayerFunctions::luaPlayerSetLoyaltyBonus(lua_State* L) { // player:setLoyaltyBonus(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - player->setLoyaltyBonus(getNumber(L, 2)); - pushBoolean(L, true); + player->setLoyaltyBonus(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { // player:getLoyaltyBonus() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3877,7 +4264,7 @@ int PlayerFunctions::luaPlayerGetLoyaltyBonus(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { // player:getLoyaltyPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3889,51 +4276,51 @@ int PlayerFunctions::luaPlayerGetLoyaltyPoints(lua_State* L) { int PlayerFunctions::luaPlayerGetLoyaltyTitle(lua_State* L) { // player:getLoyaltyTitle() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - pushString(L, player->getLoyaltyTitle()); + Lua::pushString(L, player->getLoyaltyTitle()); return 1; } int PlayerFunctions::luaPlayerSetLoyaltyTitle(lua_State* L) { // player:setLoyaltyTitle(name) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - player->setLoyaltyTitle(getString(L, 2)); - pushBoolean(L, true); + player->setLoyaltyTitle(Lua::getString(L, 2)); + Lua::pushBoolean(L, true); return 1; } // Wheel of destiny system int PlayerFunctions::luaPlayerInstantSkillWOD(lua_State* L) { // player:instantSkillWOD(name[, value]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const std::string name = getString(L, 2); + const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { - pushBoolean(L, player->wheel()->getInstant(name)); + Lua::pushBoolean(L, player->wheel()->getInstant(name)); } else { - player->wheel()->setSpellInstant(name, getBoolean(L, 3)); - pushBoolean(L, true); + player->wheel()->setSpellInstant(name, Lua::getBoolean(L, 3)); + Lua::pushBoolean(L, true); } return 1; } int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { // player:upgradeSpellsWOD([name[, add]]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3944,26 +4331,26 @@ int PlayerFunctions::luaPlayerUpgradeSpellWOD(lua_State* L) { return 1; } - const std::string name = getString(L, 2); + const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { lua_pushnumber(L, static_cast(player->wheel()->getSpellUpgrade(name))); return 1; } - const bool add = getBoolean(L, 3); + const bool add = Lua::getBoolean(L, 3); if (add) { player->wheel()->upgradeSpell(name); } else { player->wheel()->downgradeSpell(name); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { // player:revelationStageWOD([name[, set]]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -3974,22 +4361,22 @@ int PlayerFunctions::luaPlayerRevelationStageWOD(lua_State* L) { return 1; } - const std::string name = getString(L, 2); + const std::string name = Lua::getString(L, 2); if (lua_gettop(L) == 2) { lua_pushnumber(L, static_cast(player->wheel()->getStage(name))); return 1; } - const bool value = getNumber(L, 3); + const bool value = Lua::getNumber(L, 3); player->wheel()->setSpellInstant(name, value); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerReloadData(lua_State* L) { // player:reloadData() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4000,26 +4387,26 @@ int PlayerFunctions::luaPlayerReloadData(lua_State* L) { player->sendBasicData(); player->wheel()->sendGiftOfLifeCooldown(); g_game().reloadCreature(player); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerOnThinkWheelOfDestiny(lua_State* L) { // player:onThinkWheelOfDestiny([force = false]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - player->wheel()->onThink(getBoolean(L, 2, false)); - pushBoolean(L, true); + player->wheel()->onThink(Lua::getBoolean(L, 2, false)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { // player:avatarTimer([value]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; @@ -4028,59 +4415,59 @@ int PlayerFunctions::luaPlayerAvatarTimer(lua_State* L) { if (lua_gettop(L) == 1) { lua_pushnumber(L, static_cast(player->wheel()->getOnThinkTimer(WheelOnThink_t::AVATAR_SPELL))); } else { - player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, getNumber(L, 2)); - pushBoolean(L, true); + player->wheel()->setOnThinkTimer(WheelOnThink_t::AVATAR_SPELL, Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } return 1; } int PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea(lua_State* L) { // player:getWheelSpellAdditionalArea(spellname) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const auto spellName = getString(L, 2); + const auto spellName = Lua::getString(L, 2); if (spellName.empty()) { - reportErrorFunc("Spell name is empty"); - pushBoolean(L, false); + Lua::reportErrorFunc("Spell name is empty"); + Lua::pushBoolean(L, false); return 0; } const auto &spell = g_spells().getInstantSpellByName(spellName); if (!spell) { - reportErrorFunc(getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - pushBoolean(L, player->wheel()->getSpellAdditionalArea(spellName)); + Lua::pushBoolean(L, player->wheel()->getSpellAdditionalArea(spellName)); return 1; } int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { // player:getWheelSpellAdditionalTarget(spellname) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const auto spellName = getString(L, 2); + const auto spellName = Lua::getString(L, 2); if (spellName.empty()) { - reportErrorFunc("Spell name is empty"); - pushBoolean(L, false); + Lua::reportErrorFunc("Spell name is empty"); + Lua::pushBoolean(L, false); return 0; } const auto &spell = g_spells().getInstantSpellByName(spellName); if (!spell) { - reportErrorFunc(getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -4090,24 +4477,24 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget(lua_State* L) { int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { // player:getWheelSpellAdditionalDuration(spellname) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } - const auto spellName = getString(L, 2); + const auto spellName = Lua::getString(L, 2); if (spellName.empty()) { - reportErrorFunc("Spell name is empty"); - pushBoolean(L, false); + Lua::reportErrorFunc("Spell name is empty"); + Lua::pushBoolean(L, false); return 0; } const auto &spell = g_spells().getInstantSpellByName(spellName); if (!spell) { - reportErrorFunc(getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_SPELL_NOT_FOUND)); + Lua::pushBoolean(L, false); return 0; } @@ -4117,46 +4504,46 @@ int PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration(lua_State* L) { int PlayerFunctions::luaPlayerUpdateConcoction(lua_State* L) { // player:updateConcoction(itemid, timeLeft) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - player->updateConcoction(getNumber(L, 2), getNumber(L, 3)); - pushBoolean(L, true); + player->updateConcoction(Lua::getNumber(L, 2), Lua::getNumber(L, 3)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerClearSpellCooldowns(lua_State* L) { // player:clearSpellCooldowns() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } player->clearCooldowns(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerIsVip(lua_State* L) { // player:isVip() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, player->isVip()); + Lua::pushBoolean(L, player->isVip()); return 1; } int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { // player:getVipDays() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -4166,10 +4553,10 @@ int PlayerFunctions::luaPlayerGetVipDays(lua_State* L) { int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { // player:getVipTime() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -4179,102 +4566,102 @@ int PlayerFunctions::luaPlayerGetVipTime(lua_State* L) { int PlayerFunctions::luaPlayerKV(lua_State* L) { // player:kv() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushUserdata(L, player->kv()); - setMetatable(L, -1, "KV"); + Lua::pushUserdata(L, player->kv()); + Lua::setMetatable(L, -1, "KV"); return 1; } int PlayerFunctions::luaPlayerGetStoreInbox(lua_State* L) { // player:getStoreInbox() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } if (const auto &item = player->getStoreInbox()) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PlayerFunctions::luaPlayerHasAchievement(lua_State* L) { // player:hasAchievement(id or name) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } uint16_t achievementId = 0; - if (isNumber(L, 2)) { - achievementId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + achievementId = Lua::getNumber(L, 2); } else { - achievementId = g_game().getAchievementByName(getString(L, 2)).id; + achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - pushBoolean(L, player->achiev()->isUnlocked(achievementId)); + Lua::pushBoolean(L, player->achiev()->isUnlocked(achievementId)); return 1; } int PlayerFunctions::luaPlayerAddAchievement(lua_State* L) { // player:addAchievement(id or name[, sendMessage = true]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } uint16_t achievementId = 0; - if (isNumber(L, 2)) { - achievementId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + achievementId = Lua::getNumber(L, 2); } else { - achievementId = g_game().getAchievementByName(getString(L, 2)).id; + achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - const bool success = player->achiev()->add(achievementId, getBoolean(L, 3, true)); + const bool success = player->achiev()->add(achievementId, Lua::getBoolean(L, 3, true)); if (success) { player->sendTakeScreenshot(SCREENSHOT_TYPE_ACHIEVEMENT); } - pushBoolean(L, success); + Lua::pushBoolean(L, success); return 1; } int PlayerFunctions::luaPlayerRemoveAchievement(lua_State* L) { // player:removeAchievement(id or name) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } uint16_t achievementId = 0; - if (isNumber(L, 2)) { - achievementId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + achievementId = Lua::getNumber(L, 2); } else { - achievementId = g_game().getAchievementByName(getString(L, 2)).id; + achievementId = g_game().getAchievementByName(Lua::getString(L, 2)).id; } - pushBoolean(L, player->achiev()->remove(achievementId)); + Lua::pushBoolean(L, player->achiev()->remove(achievementId)); return 1; } int PlayerFunctions::luaPlayerGetAchievementPoints(lua_State* L) { // player:getAchievementPoints() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } @@ -4284,67 +4671,67 @@ int PlayerFunctions::luaPlayerGetAchievementPoints(lua_State* L) { int PlayerFunctions::luaPlayerAddAchievementPoints(lua_State* L) { // player:addAchievementPoints(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto points = getNumber(L, 2); + const auto points = Lua::getNumber(L, 2); if (points > 0) { player->achiev()->addPoints(points); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveAchievementPoints(lua_State* L) { // player:removeAchievementPoints(amount) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto points = getNumber(L, 2); + const auto points = Lua::getNumber(L, 2); if (points > 0) { player->achiev()->removePoints(points); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddBadge(lua_State* L) { // player:addBadge(id) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - player->badge()->add(getNumber(L, 2, 0)); - pushBoolean(L, true); + player->badge()->add(Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerAddTitle(lua_State* L) { // player:addTitle(id) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - player->title()->manage(true, getNumber(L, 2, 0)); - pushBoolean(L, true); + player->title()->manage(true, Lua::getNumber(L, 2, 0)); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { // player:getTitles() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } @@ -4354,9 +4741,9 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { int index = 0; for (const auto &title : playerTitles) { lua_createtable(L, 0, 3); - setField(L, "id", title.first.m_id); - setField(L, "name", player->title()->getNameBySex(player->getSex(), title.first.m_maleName, title.first.m_femaleName)); - setField(L, "description", title.first.m_description); + Lua::setField(L, "id", title.first.m_id); + Lua::setField(L, "name", player->title()->getNameBySex(player->getSex(), title.first.m_maleName, title.first.m_femaleName)); + Lua::setField(L, "description", title.first.m_description); lua_rawseti(L, -2, ++index); } return 1; @@ -4364,101 +4751,101 @@ int PlayerFunctions::luaPlayerGetTitles(lua_State* L) { int PlayerFunctions::luaPlayerSetCurrentTitle(lua_State* L) { // player:setCurrentTitle(id) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto &title = g_game().getTitleById(getNumber(L, 2, 0)); + const auto &title = g_game().getTitleById(Lua::getNumber(L, 2, 0)); if (title.m_id == 0) { - reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); return 1; } player->title()->setCurrentTitle(title.m_id); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerCreateTransactionSummary(lua_State* L) { // player:createTransactionSummary(type, amount[, id = 0]) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - const auto type = getNumber(L, 2, 0); + const auto type = Lua::getNumber(L, 2, 0); if (type == 0) { - reportErrorFunc(getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_VARIANT_NOT_FOUND)); return 1; } - const auto amount = getNumber(L, 3, 1); - const auto id = getString(L, 4, ""); + const auto amount = Lua::getNumber(L, 3, 1); + const auto id = Lua::getString(L, 4, ""); player->cyclopedia()->updateStoreSummary(type, amount, id); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerTakeScreenshot(lua_State* L) { // player:takeScreenshot(screenshotType) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto screenshotType = getNumber(L, 2); + const auto screenshotType = Lua::getNumber(L, 2); player->sendTakeScreenshot(screenshotType); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendIconBakragore(lua_State* L) { // player:sendIconBakragore() - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto iconType = getNumber(L, 2); + const auto iconType = Lua::getNumber(L, 2); player->sendIconBakragore(iconType); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerRemoveIconBakragore(lua_State* L) { // player:removeIconBakragore(iconType or nil for remove all bakragore icons) - const auto &player = getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 1); if (!player) { lua_pushnil(L); return 1; } - const auto iconType = getNumber(L, 2, IconBakragore::None); + const auto iconType = Lua::getNumber(L, 2, IconBakragore::None); if (iconType == IconBakragore::None) { player->removeBakragoreIcons(); } else { player->removeBakragoreIcon(iconType); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PlayerFunctions::luaPlayerSendCreatureAppear(lua_State* L) { - auto player = getUserdataShared(L, 1); + auto player = Lua::getUserdataShared(L, 1); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - bool isLogin = getBoolean(L, 2, false); + bool isLogin = Lua::getBoolean(L, 2, false); player->sendCreatureAppear(player, player->getPosition(), isLogin); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index 090e4371abe..ab617c35132 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -9,7 +9,6 @@ #pragma once -#include "lua/scripts/luascript.hpp" #include "lua/functions/creatures/player/group_functions.hpp" #include "lua/functions/creatures/player/guild_functions.hpp" #include "lua/functions/creatures/player/mount_functions.hpp" @@ -19,381 +18,8 @@ enum class PlayerIcon : uint8_t; enum class IconBakragore : uint8_t; -class PlayerFunctions final : LuaScriptInterface { - explicit PlayerFunctions(lua_State* L) : - LuaScriptInterface("PlayerFunctions") { - init(L); - } - ~PlayerFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Player", "Creature", PlayerFunctions::luaPlayerCreate); - registerMetaMethod(L, "Player", "__eq", PlayerFunctions::luaUserdataCompare); - - registerMethod(L, "Player", "resetCharmsBestiary", PlayerFunctions::luaPlayerResetCharmsMonsters); - registerMethod(L, "Player", "unlockAllCharmRunes", PlayerFunctions::luaPlayerUnlockAllCharmRunes); - registerMethod(L, "Player", "addCharmPoints", PlayerFunctions::luaPlayeraddCharmPoints); - registerMethod(L, "Player", "isPlayer", PlayerFunctions::luaPlayerIsPlayer); - - registerMethod(L, "Player", "getGuid", PlayerFunctions::luaPlayerGetGuid); - registerMethod(L, "Player", "getIp", PlayerFunctions::luaPlayerGetIp); - registerMethod(L, "Player", "getAccountId", PlayerFunctions::luaPlayerGetAccountId); - registerMethod(L, "Player", "getLastLoginSaved", PlayerFunctions::luaPlayerGetLastLoginSaved); - registerMethod(L, "Player", "getLastLogout", PlayerFunctions::luaPlayerGetLastLogout); - - registerMethod(L, "Player", "getAccountType", PlayerFunctions::luaPlayerGetAccountType); - registerMethod(L, "Player", "setAccountType", PlayerFunctions::luaPlayerSetAccountType); - - registerMethod(L, "Player", "isMonsterBestiaryUnlocked", PlayerFunctions::luaPlayerIsMonsterBestiaryUnlocked); - registerMethod(L, "Player", "addBestiaryKill", PlayerFunctions::luaPlayerAddBestiaryKill); - registerMethod(L, "Player", "charmExpansion", PlayerFunctions::luaPlayercharmExpansion); - registerMethod(L, "Player", "getCharmMonsterType", PlayerFunctions::luaPlayergetCharmMonsterType); - - registerMethod(L, "Player", "isMonsterPrey", PlayerFunctions::luaPlayerisMonsterPrey); - registerMethod(L, "Player", "getPreyCards", PlayerFunctions::luaPlayerGetPreyCards); - registerMethod(L, "Player", "getPreyLootPercentage", PlayerFunctions::luaPlayerGetPreyLootPercentage); - registerMethod(L, "Player", "getPreyExperiencePercentage", PlayerFunctions::luaPlayerGetPreyExperiencePercentage); - registerMethod(L, "Player", "preyThirdSlot", PlayerFunctions::luaPlayerPreyThirdSlot); - registerMethod(L, "Player", "taskHuntingThirdSlot", PlayerFunctions::luaPlayerTaskThirdSlot); - registerMethod(L, "Player", "removePreyStamina", PlayerFunctions::luaPlayerRemovePreyStamina); - registerMethod(L, "Player", "addPreyCards", PlayerFunctions::luaPlayerAddPreyCards); - registerMethod(L, "Player", "removeTaskHuntingPoints", PlayerFunctions::luaPlayerRemoveTaskHuntingPoints); - registerMethod(L, "Player", "getTaskHuntingPoints", PlayerFunctions::luaPlayerGetTaskHuntingPoints); - registerMethod(L, "Player", "addTaskHuntingPoints", PlayerFunctions::luaPlayerAddTaskHuntingPoints); - - registerMethod(L, "Player", "getCapacity", PlayerFunctions::luaPlayerGetCapacity); - registerMethod(L, "Player", "setCapacity", PlayerFunctions::luaPlayerSetCapacity); - - registerMethod(L, "Player", "isTraining", PlayerFunctions::luaPlayerGetIsTraining); - registerMethod(L, "Player", "setTraining", PlayerFunctions::luaPlayerSetTraining); - - registerMethod(L, "Player", "getFreeCapacity", PlayerFunctions::luaPlayerGetFreeCapacity); - - registerMethod(L, "Player", "getKills", PlayerFunctions::luaPlayerGetKills); - registerMethod(L, "Player", "setKills", PlayerFunctions::luaPlayerSetKills); - - registerMethod(L, "Player", "getReward", PlayerFunctions::luaPlayerGetReward); - registerMethod(L, "Player", "removeReward", PlayerFunctions::luaPlayerRemoveReward); - registerMethod(L, "Player", "getRewardList", PlayerFunctions::luaPlayerGetRewardList); - - registerMethod(L, "Player", "setDailyReward", PlayerFunctions::luaPlayerSetDailyReward); - - registerMethod(L, "Player", "sendInventory", PlayerFunctions::luaPlayerSendInventory); - registerMethod(L, "Player", "sendLootStats", PlayerFunctions::luaPlayerSendLootStats); - registerMethod(L, "Player", "updateSupplyTracker", PlayerFunctions::luaPlayerUpdateSupplyTracker); - registerMethod(L, "Player", "updateKillTracker", PlayerFunctions::luaPlayerUpdateKillTracker); - - registerMethod(L, "Player", "getDepotLocker", PlayerFunctions::luaPlayerGetDepotLocker); - registerMethod(L, "Player", "getDepotChest", PlayerFunctions::luaPlayerGetDepotChest); - registerMethod(L, "Player", "getInbox", PlayerFunctions::luaPlayerGetInbox); - - registerMethod(L, "Player", "getSkullTime", PlayerFunctions::luaPlayerGetSkullTime); - registerMethod(L, "Player", "setSkullTime", PlayerFunctions::luaPlayerSetSkullTime); - registerMethod(L, "Player", "getDeathPenalty", PlayerFunctions::luaPlayerGetDeathPenalty); - - registerMethod(L, "Player", "getExperience", PlayerFunctions::luaPlayerGetExperience); - registerMethod(L, "Player", "addExperience", PlayerFunctions::luaPlayerAddExperience); - registerMethod(L, "Player", "removeExperience", PlayerFunctions::luaPlayerRemoveExperience); - registerMethod(L, "Player", "getLevel", PlayerFunctions::luaPlayerGetLevel); - - registerMethod(L, "Player", "getMagicShieldCapacityFlat", PlayerFunctions::luaPlayerGetMagicShieldCapacityFlat); - registerMethod(L, "Player", "getMagicShieldCapacityPercent", PlayerFunctions::luaPlayerGetMagicShieldCapacityPercent); - - registerMethod(L, "Player", "sendSpellCooldown", PlayerFunctions::luaPlayerSendSpellCooldown); - registerMethod(L, "Player", "sendSpellGroupCooldown", PlayerFunctions::luaPlayerSendSpellGroupCooldown); - - registerMethod(L, "Player", "getMagicLevel", PlayerFunctions::luaPlayerGetMagicLevel); - registerMethod(L, "Player", "getBaseMagicLevel", PlayerFunctions::luaPlayerGetBaseMagicLevel); - registerMethod(L, "Player", "getMana", PlayerFunctions::luaPlayerGetMana); - registerMethod(L, "Player", "addMana", PlayerFunctions::luaPlayerAddMana); - registerMethod(L, "Player", "getMaxMana", PlayerFunctions::luaPlayerGetMaxMana); - registerMethod(L, "Player", "setMaxMana", PlayerFunctions::luaPlayerSetMaxMana); - registerMethod(L, "Player", "getManaSpent", PlayerFunctions::luaPlayerGetManaSpent); - registerMethod(L, "Player", "addManaSpent", PlayerFunctions::luaPlayerAddManaSpent); - - registerMethod(L, "Player", "getBaseMaxHealth", PlayerFunctions::luaPlayerGetBaseMaxHealth); - registerMethod(L, "Player", "getBaseMaxMana", PlayerFunctions::luaPlayerGetBaseMaxMana); - - registerMethod(L, "Player", "getSkillLevel", PlayerFunctions::luaPlayerGetSkillLevel); - registerMethod(L, "Player", "getEffectiveSkillLevel", PlayerFunctions::luaPlayerGetEffectiveSkillLevel); - registerMethod(L, "Player", "getSkillPercent", PlayerFunctions::luaPlayerGetSkillPercent); - registerMethod(L, "Player", "getSkillTries", PlayerFunctions::luaPlayerGetSkillTries); - registerMethod(L, "Player", "addSkillTries", PlayerFunctions::luaPlayerAddSkillTries); - - registerMethod(L, "Player", "setLevel", PlayerFunctions::luaPlayerSetLevel); - registerMethod(L, "Player", "setMagicLevel", PlayerFunctions::luaPlayerSetMagicLevel); - registerMethod(L, "Player", "setSkillLevel", PlayerFunctions::luaPlayerSetSkillLevel); - - registerMethod(L, "Player", "addOfflineTrainingTime", PlayerFunctions::luaPlayerAddOfflineTrainingTime); - registerMethod(L, "Player", "getOfflineTrainingTime", PlayerFunctions::luaPlayerGetOfflineTrainingTime); - registerMethod(L, "Player", "removeOfflineTrainingTime", PlayerFunctions::luaPlayerRemoveOfflineTrainingTime); - - registerMethod(L, "Player", "addOfflineTrainingTries", PlayerFunctions::luaPlayerAddOfflineTrainingTries); - - registerMethod(L, "Player", "getOfflineTrainingSkill", PlayerFunctions::luaPlayerGetOfflineTrainingSkill); - registerMethod(L, "Player", "setOfflineTrainingSkill", PlayerFunctions::luaPlayerSetOfflineTrainingSkill); - - registerMethod(L, "Player", "getItemCount", PlayerFunctions::luaPlayerGetItemCount); - registerMethod(L, "Player", "getStashItemCount", PlayerFunctions::luaPlayerGetStashItemCount); - registerMethod(L, "Player", "getItemById", PlayerFunctions::luaPlayerGetItemById); - - registerMethod(L, "Player", "getVocation", PlayerFunctions::luaPlayerGetVocation); - registerMethod(L, "Player", "setVocation", PlayerFunctions::luaPlayerSetVocation); - registerMethod(L, "Player", "isPromoted", PlayerFunctions::luaPlayerIsPromoted); - - registerMethod(L, "Player", "getSex", PlayerFunctions::luaPlayerGetSex); - registerMethod(L, "Player", "setSex", PlayerFunctions::luaPlayerSetSex); - - registerMethod(L, "Player", "getPronoun", PlayerFunctions::luaPlayerGetPronoun); - registerMethod(L, "Player", "setPronoun", PlayerFunctions::luaPlayerSetPronoun); - - registerMethod(L, "Player", "getTown", PlayerFunctions::luaPlayerGetTown); - registerMethod(L, "Player", "setTown", PlayerFunctions::luaPlayerSetTown); - - registerMethod(L, "Player", "getGuild", PlayerFunctions::luaPlayerGetGuild); - registerMethod(L, "Player", "setGuild", PlayerFunctions::luaPlayerSetGuild); - - registerMethod(L, "Player", "getGuildLevel", PlayerFunctions::luaPlayerGetGuildLevel); - registerMethod(L, "Player", "setGuildLevel", PlayerFunctions::luaPlayerSetGuildLevel); - - registerMethod(L, "Player", "getGuildNick", PlayerFunctions::luaPlayerGetGuildNick); - registerMethod(L, "Player", "setGuildNick", PlayerFunctions::luaPlayerSetGuildNick); - - registerMethod(L, "Player", "getGroup", PlayerFunctions::luaPlayerGetGroup); - registerMethod(L, "Player", "setGroup", PlayerFunctions::luaPlayerSetGroup); - - registerMethod(L, "Player", "setSpecialContainersAvailable", PlayerFunctions::luaPlayerSetSpecialContainersAvailable); - registerMethod(L, "Player", "getStashCount", PlayerFunctions::luaPlayerGetStashCounter); - registerMethod(L, "Player", "openStash", PlayerFunctions::luaPlayerOpenStash); - - registerMethod(L, "Player", "getStamina", PlayerFunctions::luaPlayerGetStamina); - registerMethod(L, "Player", "setStamina", PlayerFunctions::luaPlayerSetStamina); - - registerMethod(L, "Player", "getSoul", PlayerFunctions::luaPlayerGetSoul); - registerMethod(L, "Player", "addSoul", PlayerFunctions::luaPlayerAddSoul); - registerMethod(L, "Player", "getMaxSoul", PlayerFunctions::luaPlayerGetMaxSoul); - - registerMethod(L, "Player", "getBankBalance", PlayerFunctions::luaPlayerGetBankBalance); - registerMethod(L, "Player", "setBankBalance", PlayerFunctions::luaPlayerSetBankBalance); - - registerMethod(L, "Player", "getStorageValue", PlayerFunctions::luaPlayerGetStorageValue); - registerMethod(L, "Player", "setStorageValue", PlayerFunctions::luaPlayerSetStorageValue); - - registerMethod(L, "Player", "getStorageValueByName", PlayerFunctions::luaPlayerGetStorageValueByName); - registerMethod(L, "Player", "setStorageValueByName", PlayerFunctions::luaPlayerSetStorageValueByName); - - registerMethod(L, "Player", "addItem", PlayerFunctions::luaPlayerAddItem); - registerMethod(L, "Player", "addItemEx", PlayerFunctions::luaPlayerAddItemEx); - registerMethod(L, "Player", "addItemStash", PlayerFunctions::luaPlayerAddItemStash); - registerMethod(L, "Player", "removeStashItem", PlayerFunctions::luaPlayerRemoveStashItem); - registerMethod(L, "Player", "removeItem", PlayerFunctions::luaPlayerRemoveItem); - registerMethod(L, "Player", "sendContainer", PlayerFunctions::luaPlayerSendContainer); - registerMethod(L, "Player", "sendUpdateContainer", PlayerFunctions::luaPlayerSendUpdateContainer); - - registerMethod(L, "Player", "getMoney", PlayerFunctions::luaPlayerGetMoney); - registerMethod(L, "Player", "addMoney", PlayerFunctions::luaPlayerAddMoney); - registerMethod(L, "Player", "removeMoney", PlayerFunctions::luaPlayerRemoveMoney); - - registerMethod(L, "Player", "showTextDialog", PlayerFunctions::luaPlayerShowTextDialog); - - registerMethod(L, "Player", "sendTextMessage", PlayerFunctions::luaPlayerSendTextMessage); - registerMethod(L, "Player", "sendChannelMessage", PlayerFunctions::luaPlayerSendChannelMessage); - registerMethod(L, "Player", "sendPrivateMessage", PlayerFunctions::luaPlayerSendPrivateMessage); - registerMethod(L, "Player", "channelSay", PlayerFunctions::luaPlayerChannelSay); - registerMethod(L, "Player", "openChannel", PlayerFunctions::luaPlayerOpenChannel); - - registerMethod(L, "Player", "getSlotItem", PlayerFunctions::luaPlayerGetSlotItem); - - registerMethod(L, "Player", "getParty", PlayerFunctions::luaPlayerGetParty); - - registerMethod(L, "Player", "addOutfit", PlayerFunctions::luaPlayerAddOutfit); - registerMethod(L, "Player", "addOutfitAddon", PlayerFunctions::luaPlayerAddOutfitAddon); - registerMethod(L, "Player", "removeOutfit", PlayerFunctions::luaPlayerRemoveOutfit); - registerMethod(L, "Player", "removeOutfitAddon", PlayerFunctions::luaPlayerRemoveOutfitAddon); - registerMethod(L, "Player", "hasOutfit", PlayerFunctions::luaPlayerHasOutfit); - registerMethod(L, "Player", "sendOutfitWindow", PlayerFunctions::luaPlayerSendOutfitWindow); - - registerMethod(L, "Player", "addMount", PlayerFunctions::luaPlayerAddMount); - registerMethod(L, "Player", "removeMount", PlayerFunctions::luaPlayerRemoveMount); - registerMethod(L, "Player", "hasMount", PlayerFunctions::luaPlayerHasMount); - - registerMethod(L, "Player", "addFamiliar", PlayerFunctions::luaPlayerAddFamiliar); - registerMethod(L, "Player", "removeFamiliar", PlayerFunctions::luaPlayerRemoveFamiliar); - registerMethod(L, "Player", "hasFamiliar", PlayerFunctions::luaPlayerHasFamiliar); - registerMethod(L, "Player", "setFamiliarLooktype", PlayerFunctions::luaPlayerSetFamiliarLooktype); - registerMethod(L, "Player", "getFamiliarLooktype", PlayerFunctions::luaPlayerGetFamiliarLooktype); - - registerMethod(L, "Player", "getPremiumDays", PlayerFunctions::luaPlayerGetPremiumDays); - registerMethod(L, "Player", "addPremiumDays", PlayerFunctions::luaPlayerAddPremiumDays); - registerMethod(L, "Player", "removePremiumDays", PlayerFunctions::luaPlayerRemovePremiumDays); - - registerMethod(L, "Player", "getTibiaCoins", PlayerFunctions::luaPlayerGetTibiaCoins); - registerMethod(L, "Player", "addTibiaCoins", PlayerFunctions::luaPlayerAddTibiaCoins); - registerMethod(L, "Player", "removeTibiaCoins", PlayerFunctions::luaPlayerRemoveTibiaCoins); - - registerMethod(L, "Player", "getTransferableCoins", PlayerFunctions::luaPlayerGetTransferableCoins); - registerMethod(L, "Player", "addTransferableCoins", PlayerFunctions::luaPlayerAddTransferableCoins); - registerMethod(L, "Player", "removeTransferableCoins", PlayerFunctions::luaPlayerRemoveTransferableCoins); - - registerMethod(L, "Player", "hasBlessing", PlayerFunctions::luaPlayerHasBlessing); - registerMethod(L, "Player", "addBlessing", PlayerFunctions::luaPlayerAddBlessing); - registerMethod(L, "Player", "removeBlessing", PlayerFunctions::luaPlayerRemoveBlessing); - registerMethod(L, "Player", "getBlessingCount", PlayerFunctions::luaPlayerGetBlessingCount); - - registerMethod(L, "Player", "canLearnSpell", PlayerFunctions::luaPlayerCanLearnSpell); - registerMethod(L, "Player", "learnSpell", PlayerFunctions::luaPlayerLearnSpell); - registerMethod(L, "Player", "forgetSpell", PlayerFunctions::luaPlayerForgetSpell); - registerMethod(L, "Player", "hasLearnedSpell", PlayerFunctions::luaPlayerHasLearnedSpell); - - registerMethod(L, "Player", "openImbuementWindow", PlayerFunctions::luaPlayerOpenImbuementWindow); - registerMethod(L, "Player", "closeImbuementWindow", PlayerFunctions::luaPlayerCloseImbuementWindow); - - registerMethod(L, "Player", "sendTutorial", PlayerFunctions::luaPlayerSendTutorial); - registerMethod(L, "Player", "addMapMark", PlayerFunctions::luaPlayerAddMapMark); - - registerMethod(L, "Player", "save", PlayerFunctions::luaPlayerSave); - registerMethod(L, "Player", "popupFYI", PlayerFunctions::luaPlayerPopupFYI); - - registerMethod(L, "Player", "isPzLocked", PlayerFunctions::luaPlayerIsPzLocked); - - registerMethod(L, "Player", "getClient", PlayerFunctions::luaPlayerGetClient); - - registerMethod(L, "Player", "getHouse", PlayerFunctions::luaPlayerGetHouse); - registerMethod(L, "Player", "sendHouseWindow", PlayerFunctions::luaPlayerSendHouseWindow); - registerMethod(L, "Player", "setEditHouse", PlayerFunctions::luaPlayerSetEditHouse); - - registerMethod(L, "Player", "setGhostMode", PlayerFunctions::luaPlayerSetGhostMode); - - registerMethod(L, "Player", "getContainerId", PlayerFunctions::luaPlayerGetContainerId); - registerMethod(L, "Player", "getContainerById", PlayerFunctions::luaPlayerGetContainerById); - registerMethod(L, "Player", "getContainerIndex", PlayerFunctions::luaPlayerGetContainerIndex); - - registerMethod(L, "Player", "getInstantSpells", PlayerFunctions::luaPlayerGetInstantSpells); - registerMethod(L, "Player", "canCast", PlayerFunctions::luaPlayerCanCast); - - registerMethod(L, "Player", "hasChaseMode", PlayerFunctions::luaPlayerHasChaseMode); - registerMethod(L, "Player", "hasSecureMode", PlayerFunctions::luaPlayerHasSecureMode); - registerMethod(L, "Player", "getFightMode", PlayerFunctions::luaPlayerGetFightMode); - - registerMethod(L, "Player", "getBaseXpGain", PlayerFunctions::luaPlayerGetBaseXpGain); - registerMethod(L, "Player", "setBaseXpGain", PlayerFunctions::luaPlayerSetBaseXpGain); - registerMethod(L, "Player", "getVoucherXpBoost", PlayerFunctions::luaPlayerGetVoucherXpBoost); - registerMethod(L, "Player", "setVoucherXpBoost", PlayerFunctions::luaPlayerSetVoucherXpBoost); - registerMethod(L, "Player", "getGrindingXpBoost", PlayerFunctions::luaPlayerGetGrindingXpBoost); - registerMethod(L, "Player", "setGrindingXpBoost", PlayerFunctions::luaPlayerSetGrindingXpBoost); - registerMethod(L, "Player", "getXpBoostPercent", PlayerFunctions::luaPlayerGetXpBoostPercent); - registerMethod(L, "Player", "setXpBoostPercent", PlayerFunctions::luaPlayerSetXpBoostPercent); - registerMethod(L, "Player", "getStaminaXpBoost", PlayerFunctions::luaPlayerGetStaminaXpBoost); - registerMethod(L, "Player", "setStaminaXpBoost", PlayerFunctions::luaPlayerSetStaminaXpBoost); - registerMethod(L, "Player", "getXpBoostTime", PlayerFunctions::luaPlayerGetXpBoostTime); - registerMethod(L, "Player", "setXpBoostTime", PlayerFunctions::luaPlayerSetXpBoostTime); - - registerMethod(L, "Player", "getIdleTime", PlayerFunctions::luaPlayerGetIdleTime); - registerMethod(L, "Player", "getFreeBackpackSlots", PlayerFunctions::luaPlayerGetFreeBackpackSlots); - - registerMethod(L, "Player", "isOffline", PlayerFunctions::luaPlayerIsOffline); - - registerMethod(L, "Player", "openMarket", PlayerFunctions::luaPlayerOpenMarket); - - registerMethod(L, "Player", "instantSkillWOD", PlayerFunctions::luaPlayerInstantSkillWOD); - registerMethod(L, "Player", "upgradeSpellsWOD", PlayerFunctions::luaPlayerUpgradeSpellWOD); - registerMethod(L, "Player", "revelationStageWOD", PlayerFunctions::luaPlayerRevelationStageWOD); - registerMethod(L, "Player", "reloadData", PlayerFunctions::luaPlayerReloadData); - registerMethod(L, "Player", "onThinkWheelOfDestiny", PlayerFunctions::luaPlayerOnThinkWheelOfDestiny); - registerMethod(L, "Player", "avatarTimer", PlayerFunctions::luaPlayerAvatarTimer); - registerMethod(L, "Player", "getWheelSpellAdditionalArea", PlayerFunctions::luaPlayerGetWheelSpellAdditionalArea); - registerMethod(L, "Player", "getWheelSpellAdditionalTarget", PlayerFunctions::luaPlayerGetWheelSpellAdditionalTarget); - registerMethod(L, "Player", "getWheelSpellAdditionalDuration", PlayerFunctions::luaPlayerGetWheelSpellAdditionalDuration); - - // Forge Functions - registerMethod(L, "Player", "openForge", PlayerFunctions::luaPlayerOpenForge); - registerMethod(L, "Player", "closeForge", PlayerFunctions::luaPlayerCloseForge); - - registerMethod(L, "Player", "addForgeDusts", PlayerFunctions::luaPlayerAddForgeDusts); - registerMethod(L, "Player", "removeForgeDusts", PlayerFunctions::luaPlayerRemoveForgeDusts); - registerMethod(L, "Player", "getForgeDusts", PlayerFunctions::luaPlayerGetForgeDusts); - registerMethod(L, "Player", "setForgeDusts", PlayerFunctions::luaPlayerSetForgeDusts); - - registerMethod(L, "Player", "addForgeDustLevel", PlayerFunctions::luaPlayerAddForgeDustLevel); - registerMethod(L, "Player", "removeForgeDustLevel", PlayerFunctions::luaPlayerRemoveForgeDustLevel); - registerMethod(L, "Player", "getForgeDustLevel", PlayerFunctions::luaPlayerGetForgeDustLevel); - - registerMethod(L, "Player", "getForgeSlivers", PlayerFunctions::luaPlayerGetForgeSlivers); - registerMethod(L, "Player", "getForgeCores", PlayerFunctions::luaPlayerGetForgeCores); - registerMethod(L, "Player", "isUIExhausted", PlayerFunctions::luaPlayerIsUIExhausted); - registerMethod(L, "Player", "updateUIExhausted", PlayerFunctions::luaPlayerUpdateUIExhausted); - - registerMethod(L, "Player", "setFaction", PlayerFunctions::luaPlayerSetFaction); - registerMethod(L, "Player", "getFaction", PlayerFunctions::luaPlayerGetFaction); - - // Bosstiary Functions - registerMethod(L, "Player", "getBosstiaryLevel", PlayerFunctions::luaPlayerGetBosstiaryLevel); - registerMethod(L, "Player", "getBosstiaryKills", PlayerFunctions::luaPlayerGetBosstiaryKills); - registerMethod(L, "Player", "addBosstiaryKill", PlayerFunctions::luaPlayerAddBosstiaryKill); - registerMethod(L, "Player", "setBossPoints", PlayerFunctions::luaPlayerSetBossPoints); - registerMethod(L, "Player", "setRemoveBossTime", PlayerFunctions::luaPlayerSetRemoveBossTime); - registerMethod(L, "Player", "getSlotBossId", PlayerFunctions::luaPlayerGetSlotBossId); - registerMethod(L, "Player", "getBossBonus", PlayerFunctions::luaPlayerGetBossBonus); - registerMethod(L, "Player", "sendBosstiaryCooldownTimer", PlayerFunctions::luaPlayerBosstiaryCooldownTimer); - - registerMethod(L, "Player", "sendSingleSoundEffect", PlayerFunctions::luaPlayerSendSingleSoundEffect); - registerMethod(L, "Player", "sendDoubleSoundEffect", PlayerFunctions::luaPlayerSendDoubleSoundEffect); - - registerMethod(L, "Player", "getName", PlayerFunctions::luaPlayerGetName); - registerMethod(L, "Player", "changeName", PlayerFunctions::luaPlayerChangeName); - - registerMethod(L, "Player", "hasGroupFlag", PlayerFunctions::luaPlayerHasGroupFlag); - registerMethod(L, "Player", "setGroupFlag", PlayerFunctions::luaPlayerSetGroupFlag); - registerMethod(L, "Player", "removeGroupFlag", PlayerFunctions::luaPlayerRemoveGroupFlag); - - registerMethod(L, "Player", "setHazardSystemPoints", PlayerFunctions::luaPlayerAddHazardSystemPoints); - registerMethod(L, "Player", "getHazardSystemPoints", PlayerFunctions::luaPlayerGetHazardSystemPoints); - - registerMethod(L, "Player", "setLoyaltyBonus", PlayerFunctions::luaPlayerSetLoyaltyBonus); - registerMethod(L, "Player", "getLoyaltyBonus", PlayerFunctions::luaPlayerGetLoyaltyBonus); - registerMethod(L, "Player", "getLoyaltyPoints", PlayerFunctions::luaPlayerGetLoyaltyPoints); - registerMethod(L, "Player", "getLoyaltyTitle", PlayerFunctions::luaPlayerGetLoyaltyTitle); - registerMethod(L, "Player", "setLoyaltyTitle", PlayerFunctions::luaPlayerSetLoyaltyTitle); - - registerMethod(L, "Player", "updateConcoction", PlayerFunctions::luaPlayerUpdateConcoction); - registerMethod(L, "Player", "clearSpellCooldowns", PlayerFunctions::luaPlayerClearSpellCooldowns); - - registerMethod(L, "Player", "isVip", PlayerFunctions::luaPlayerIsVip); - registerMethod(L, "Player", "getVipDays", PlayerFunctions::luaPlayerGetVipDays); - registerMethod(L, "Player", "getVipTime", PlayerFunctions::luaPlayerGetVipTime); - - registerMethod(L, "Player", "kv", PlayerFunctions::luaPlayerKV); - registerMethod(L, "Player", "getStoreInbox", PlayerFunctions::luaPlayerGetStoreInbox); - - registerMethod(L, "Player", "hasAchievement", PlayerFunctions::luaPlayerHasAchievement); - registerMethod(L, "Player", "addAchievement", PlayerFunctions::luaPlayerAddAchievement); - registerMethod(L, "Player", "removeAchievement", PlayerFunctions::luaPlayerRemoveAchievement); - registerMethod(L, "Player", "getAchievementPoints", PlayerFunctions::luaPlayerGetAchievementPoints); - registerMethod(L, "Player", "addAchievementPoints", PlayerFunctions::luaPlayerAddAchievementPoints); - registerMethod(L, "Player", "removeAchievementPoints", PlayerFunctions::luaPlayerRemoveAchievementPoints); - - // Badge Functions - registerMethod(L, "Player", "addBadge", PlayerFunctions::luaPlayerAddBadge); - - // Title Functions - registerMethod(L, "Player", "addTitle", PlayerFunctions::luaPlayerAddTitle); - registerMethod(L, "Player", "getTitles", PlayerFunctions::luaPlayerGetTitles); - registerMethod(L, "Player", "setCurrentTitle", PlayerFunctions::luaPlayerSetCurrentTitle); - - // Store Summary - registerMethod(L, "Player", "createTransactionSummary", PlayerFunctions::luaPlayerCreateTransactionSummary); - - registerMethod(L, "Player", "takeScreenshot", PlayerFunctions::luaPlayerTakeScreenshot); - registerMethod(L, "Player", "sendIconBakragore", PlayerFunctions::luaPlayerSendIconBakragore); - registerMethod(L, "Player", "removeIconBakragore", PlayerFunctions::luaPlayerRemoveIconBakragore); - registerMethod(L, "Player", "sendCreatureAppear", PlayerFunctions::luaPlayerSendCreatureAppear); - - GroupFunctions::init(L); - GuildFunctions::init(L); - MountFunctions::init(L); - PartyFunctions::init(L); - VocationFunctions::init(L); - } +class PlayerFunctions { + static void init(lua_State* L); static int luaPlayerCreate(lua_State* L); @@ -603,6 +229,7 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerAddTransferableCoins(lua_State* L); static int luaPlayerRemoveTransferableCoins(lua_State* L); + static int luaPlayerSendBlessStatus(lua_State* L); static int luaPlayerHasBlessing(lua_State* L); static int luaPlayerAddBlessing(lua_State* L); static int luaPlayerRemoveBlessing(lua_State* L); diff --git a/src/lua/functions/creatures/player/vocation_functions.cpp b/src/lua/functions/creatures/player/vocation_functions.cpp index 59b2a0d87dc..166e000f433 100644 --- a/src/lua/functions/creatures/player/vocation_functions.cpp +++ b/src/lua/functions/creatures/player/vocation_functions.cpp @@ -10,20 +10,55 @@ #include "lua/functions/creatures/player/vocation_functions.hpp" #include "creatures/players/vocations/vocation.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void VocationFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Vocation", "", VocationFunctions::luaVocationCreate); + Lua::registerMetaMethod(L, "Vocation", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Vocation", "getId", VocationFunctions::luaVocationGetId); + Lua::registerMethod(L, "Vocation", "getClientId", VocationFunctions::luaVocationGetClientId); + Lua::registerMethod(L, "Vocation", "getBaseId", VocationFunctions::luaVocationGetBaseId); + Lua::registerMethod(L, "Vocation", "getName", VocationFunctions::luaVocationGetName); + Lua::registerMethod(L, "Vocation", "getDescription", VocationFunctions::luaVocationGetDescription); + + Lua::registerMethod(L, "Vocation", "getRequiredSkillTries", VocationFunctions::luaVocationGetRequiredSkillTries); + Lua::registerMethod(L, "Vocation", "getRequiredManaSpent", VocationFunctions::luaVocationGetRequiredManaSpent); + + Lua::registerMethod(L, "Vocation", "getCapacityGain", VocationFunctions::luaVocationGetCapacityGain); + + Lua::registerMethod(L, "Vocation", "getHealthGain", VocationFunctions::luaVocationGetHealthGain); + Lua::registerMethod(L, "Vocation", "getHealthGainTicks", VocationFunctions::luaVocationGetHealthGainTicks); + Lua::registerMethod(L, "Vocation", "getHealthGainAmount", VocationFunctions::luaVocationGetHealthGainAmount); + + Lua::registerMethod(L, "Vocation", "getManaGain", VocationFunctions::luaVocationGetManaGain); + Lua::registerMethod(L, "Vocation", "getManaGainTicks", VocationFunctions::luaVocationGetManaGainTicks); + Lua::registerMethod(L, "Vocation", "getManaGainAmount", VocationFunctions::luaVocationGetManaGainAmount); + + Lua::registerMethod(L, "Vocation", "getMaxSoul", VocationFunctions::luaVocationGetMaxSoul); + Lua::registerMethod(L, "Vocation", "getSoulGainTicks", VocationFunctions::luaVocationGetSoulGainTicks); + + Lua::registerMethod(L, "Vocation", "getBaseAttackSpeed", VocationFunctions::luaVocationGetBaseAttackSpeed); + Lua::registerMethod(L, "Vocation", "getAttackSpeed", VocationFunctions::luaVocationGetAttackSpeed); + Lua::registerMethod(L, "Vocation", "getBaseSpeed", VocationFunctions::luaVocationGetBaseSpeed); + + Lua::registerMethod(L, "Vocation", "getDemotion", VocationFunctions::luaVocationGetDemotion); + Lua::registerMethod(L, "Vocation", "getPromotion", VocationFunctions::luaVocationGetPromotion); +} int VocationFunctions::luaVocationCreate(lua_State* L) { // Vocation(id or name) uint16_t vocationId; - if (isNumber(L, 2)) { - vocationId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + vocationId = Lua::getNumber(L, 2); } else { - vocationId = g_vocations().getVocationId(getString(L, 2)); + vocationId = g_vocations().getVocationId(Lua::getString(L, 2)); } const auto &vocation = g_vocations().getVocation(vocationId); if (vocation) { - pushUserdata(L, vocation); - setMetatable(L, -1, "Vocation"); + Lua::pushUserdata(L, vocation); + Lua::setMetatable(L, -1, "Vocation"); } else { lua_pushnil(L); } @@ -32,7 +67,7 @@ int VocationFunctions::luaVocationCreate(lua_State* L) { int VocationFunctions::luaVocationGetId(lua_State* L) { // vocation:getId() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getId()); } else { @@ -43,7 +78,7 @@ int VocationFunctions::luaVocationGetId(lua_State* L) { int VocationFunctions::luaVocationGetClientId(lua_State* L) { // vocation:getClientId() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getClientId()); } else { @@ -54,7 +89,7 @@ int VocationFunctions::luaVocationGetClientId(lua_State* L) { int VocationFunctions::luaVocationGetBaseId(lua_State* L) { // vocation:getBaseId() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseId()); } else { @@ -65,9 +100,9 @@ int VocationFunctions::luaVocationGetBaseId(lua_State* L) { int VocationFunctions::luaVocationGetName(lua_State* L) { // vocation:getName() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { - pushString(L, vocation->getVocName()); + Lua::pushString(L, vocation->getVocName()); } else { lua_pushnil(L); } @@ -76,9 +111,9 @@ int VocationFunctions::luaVocationGetName(lua_State* L) { int VocationFunctions::luaVocationGetDescription(lua_State* L) { // vocation:getDescription() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { - pushString(L, vocation->getVocDescription()); + Lua::pushString(L, vocation->getVocDescription()); } else { lua_pushnil(L); } @@ -87,10 +122,10 @@ int VocationFunctions::luaVocationGetDescription(lua_State* L) { int VocationFunctions::luaVocationGetRequiredSkillTries(lua_State* L) { // vocation:getRequiredSkillTries(skillType, skillLevel) - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { - const skills_t skillType = getNumber(L, 2); - const uint16_t skillLevel = getNumber(L, 3); + const skills_t skillType = Lua::getNumber(L, 2); + const uint16_t skillLevel = Lua::getNumber(L, 3); lua_pushnumber(L, vocation->getReqSkillTries(skillType, skillLevel)); } else { lua_pushnil(L); @@ -100,9 +135,9 @@ int VocationFunctions::luaVocationGetRequiredSkillTries(lua_State* L) { int VocationFunctions::luaVocationGetRequiredManaSpent(lua_State* L) { // vocation:getRequiredManaSpent(magicLevel) - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { - const uint32_t magicLevel = getNumber(L, 2); + const uint32_t magicLevel = Lua::getNumber(L, 2); lua_pushnumber(L, vocation->getReqMana(magicLevel)); } else { lua_pushnil(L); @@ -112,7 +147,7 @@ int VocationFunctions::luaVocationGetRequiredManaSpent(lua_State* L) { int VocationFunctions::luaVocationGetCapacityGain(lua_State* L) { // vocation:getCapacityGain() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getCapGain()); } else { @@ -123,7 +158,7 @@ int VocationFunctions::luaVocationGetCapacityGain(lua_State* L) { int VocationFunctions::luaVocationGetHealthGain(lua_State* L) { // vocation:getHealthGain() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHPGain()); } else { @@ -134,7 +169,7 @@ int VocationFunctions::luaVocationGetHealthGain(lua_State* L) { int VocationFunctions::luaVocationGetHealthGainTicks(lua_State* L) { // vocation:getHealthGainTicks() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHealthGainTicks()); } else { @@ -145,7 +180,7 @@ int VocationFunctions::luaVocationGetHealthGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetHealthGainAmount(lua_State* L) { // vocation:getHealthGainAmount() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getHealthGainAmount()); } else { @@ -156,7 +191,7 @@ int VocationFunctions::luaVocationGetHealthGainAmount(lua_State* L) { int VocationFunctions::luaVocationGetManaGain(lua_State* L) { // vocation:getManaGain() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGain()); } else { @@ -167,7 +202,7 @@ int VocationFunctions::luaVocationGetManaGain(lua_State* L) { int VocationFunctions::luaVocationGetManaGainTicks(lua_State* L) { // vocation:getManaGainTicks() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGainTicks()); } else { @@ -178,7 +213,7 @@ int VocationFunctions::luaVocationGetManaGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetManaGainAmount(lua_State* L) { // vocation:getManaGainAmount() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getManaGainAmount()); } else { @@ -189,7 +224,7 @@ int VocationFunctions::luaVocationGetManaGainAmount(lua_State* L) { int VocationFunctions::luaVocationGetMaxSoul(lua_State* L) { // vocation:getMaxSoul() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getSoulMax()); } else { @@ -200,7 +235,7 @@ int VocationFunctions::luaVocationGetMaxSoul(lua_State* L) { int VocationFunctions::luaVocationGetSoulGainTicks(lua_State* L) { // vocation:getSoulGainTicks() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getSoulGainTicks()); } else { @@ -211,7 +246,7 @@ int VocationFunctions::luaVocationGetSoulGainTicks(lua_State* L) { int VocationFunctions::luaVocationGetBaseAttackSpeed(lua_State* L) { // vocation:getBaseAttackSpeed() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseAttackSpeed()); } else { @@ -222,7 +257,7 @@ int VocationFunctions::luaVocationGetBaseAttackSpeed(lua_State* L) { int VocationFunctions::luaVocationGetAttackSpeed(lua_State* L) { // vocation:getAttackSpeed() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getAttackSpeed()); } else { @@ -233,7 +268,7 @@ int VocationFunctions::luaVocationGetAttackSpeed(lua_State* L) { int VocationFunctions::luaVocationGetBaseSpeed(lua_State* L) { // vocation:getBaseSpeed() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (vocation) { lua_pushnumber(L, vocation->getBaseSpeed()); } else { @@ -244,7 +279,7 @@ int VocationFunctions::luaVocationGetBaseSpeed(lua_State* L) { int VocationFunctions::luaVocationGetDemotion(lua_State* L) { // vocation:getDemotion() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (!vocation) { lua_pushnil(L); return 1; @@ -258,8 +293,8 @@ int VocationFunctions::luaVocationGetDemotion(lua_State* L) { const auto &demotedVocation = g_vocations().getVocation(fromId); if (demotedVocation && demotedVocation != vocation) { - pushUserdata(L, demotedVocation); - setMetatable(L, -1, "Vocation"); + Lua::pushUserdata(L, demotedVocation); + Lua::setMetatable(L, -1, "Vocation"); } else { lua_pushnil(L); } @@ -268,7 +303,7 @@ int VocationFunctions::luaVocationGetDemotion(lua_State* L) { int VocationFunctions::luaVocationGetPromotion(lua_State* L) { // vocation:getPromotion() - const auto &vocation = getUserdataShared(L, 1); + const auto &vocation = Lua::getUserdataShared(L, 1); if (!vocation) { lua_pushnil(L); return 1; @@ -282,8 +317,8 @@ int VocationFunctions::luaVocationGetPromotion(lua_State* L) { const auto &promotedVocation = g_vocations().getVocation(promotedId); if (promotedVocation && promotedVocation != vocation) { - pushUserdata(L, promotedVocation); - setMetatable(L, -1, "Vocation"); + Lua::pushUserdata(L, promotedVocation); + Lua::setMetatable(L, -1, "Vocation"); } else { lua_pushnil(L); } diff --git a/src/lua/functions/creatures/player/vocation_functions.hpp b/src/lua/functions/creatures/player/vocation_functions.hpp index 7d98131ecb3..10c9364680d 100644 --- a/src/lua/functions/creatures/player/vocation_functions.hpp +++ b/src/lua/functions/creatures/player/vocation_functions.hpp @@ -9,49 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class VocationFunctions final : LuaScriptInterface { +class VocationFunctions { public: - explicit VocationFunctions(lua_State* L) : - LuaScriptInterface("VocationFunctions") { - init(L); - } - ~VocationFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Vocation", "", VocationFunctions::luaVocationCreate); - registerMetaMethod(L, "Vocation", "__eq", VocationFunctions::luaUserdataCompare); - - registerMethod(L, "Vocation", "getId", VocationFunctions::luaVocationGetId); - registerMethod(L, "Vocation", "getClientId", VocationFunctions::luaVocationGetClientId); - registerMethod(L, "Vocation", "getBaseId", VocationFunctions::luaVocationGetBaseId); - registerMethod(L, "Vocation", "getName", VocationFunctions::luaVocationGetName); - registerMethod(L, "Vocation", "getDescription", VocationFunctions::luaVocationGetDescription); - - registerMethod(L, "Vocation", "getRequiredSkillTries", VocationFunctions::luaVocationGetRequiredSkillTries); - registerMethod(L, "Vocation", "getRequiredManaSpent", VocationFunctions::luaVocationGetRequiredManaSpent); - - registerMethod(L, "Vocation", "getCapacityGain", VocationFunctions::luaVocationGetCapacityGain); - - registerMethod(L, "Vocation", "getHealthGain", VocationFunctions::luaVocationGetHealthGain); - registerMethod(L, "Vocation", "getHealthGainTicks", VocationFunctions::luaVocationGetHealthGainTicks); - registerMethod(L, "Vocation", "getHealthGainAmount", VocationFunctions::luaVocationGetHealthGainAmount); - - registerMethod(L, "Vocation", "getManaGain", VocationFunctions::luaVocationGetManaGain); - registerMethod(L, "Vocation", "getManaGainTicks", VocationFunctions::luaVocationGetManaGainTicks); - registerMethod(L, "Vocation", "getManaGainAmount", VocationFunctions::luaVocationGetManaGainAmount); - - registerMethod(L, "Vocation", "getMaxSoul", VocationFunctions::luaVocationGetMaxSoul); - registerMethod(L, "Vocation", "getSoulGainTicks", VocationFunctions::luaVocationGetSoulGainTicks); - - registerMethod(L, "Vocation", "getBaseAttackSpeed", VocationFunctions::luaVocationGetBaseAttackSpeed); - registerMethod(L, "Vocation", "getAttackSpeed", VocationFunctions::luaVocationGetAttackSpeed); - registerMethod(L, "Vocation", "getBaseSpeed", VocationFunctions::luaVocationGetBaseSpeed); - - registerMethod(L, "Vocation", "getDemotion", VocationFunctions::luaVocationGetDemotion); - registerMethod(L, "Vocation", "getPromotion", VocationFunctions::luaVocationGetPromotion); - } + static void init(lua_State* L); private: static int luaVocationCreate(lua_State* L); diff --git a/src/lua/functions/events/action_functions.cpp b/src/lua/functions/events/action_functions.cpp index a21ab37ebd9..39ca0939150 100644 --- a/src/lua/functions/events/action_functions.cpp +++ b/src/lua/functions/events/action_functions.cpp @@ -12,105 +12,119 @@ #include "lua/creature/actions.hpp" #include "game/game.hpp" #include "items/item.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ActionFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Action", "", ActionFunctions::luaCreateAction); + Lua::registerMethod(L, "Action", "onUse", ActionFunctions::luaActionOnUse); + Lua::registerMethod(L, "Action", "register", ActionFunctions::luaActionRegister); + Lua::registerMethod(L, "Action", "id", ActionFunctions::luaActionItemId); + Lua::registerMethod(L, "Action", "aid", ActionFunctions::luaActionActionId); + Lua::registerMethod(L, "Action", "uid", ActionFunctions::luaActionUniqueId); + Lua::registerMethod(L, "Action", "position", ActionFunctions::luaActionPosition); + Lua::registerMethod(L, "Action", "allowFarUse", ActionFunctions::luaActionAllowFarUse); + Lua::registerMethod(L, "Action", "blockWalls", ActionFunctions::luaActionBlockWalls); + Lua::registerMethod(L, "Action", "checkFloor", ActionFunctions::luaActionCheckFloor); + Lua::registerMethod(L, "Action", "position", ActionFunctions::luaActionPosition); +} int ActionFunctions::luaCreateAction(lua_State* L) { // Action() - const auto action = std::make_shared(getScriptEnv()->getScriptInterface()); - pushUserdata(L, action); - setMetatable(L, -1, "Action"); + const auto action = std::make_shared(); + Lua::pushUserdata(L, action); + Lua::setMetatable(L, -1, "Action"); return 1; } int ActionFunctions::luaActionOnUse(lua_State* L) { // action:onUse(callback) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { - if (!action->loadCallback()) { - pushBoolean(L, false); + if (!action->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - action->setLoadedCallback(true); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionRegister(lua_State* L) { // action:register() - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { - if (!action->isLoadedCallback()) { - pushBoolean(L, false); + if (!action->isLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_actions().registerLuaEvent(action)); - pushBoolean(L, true); + Lua::pushBoolean(L, g_actions().registerLuaEvent(action)); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionItemId(lua_State* L) { // action:id(ids) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - action->setItemIdsVector(getNumber(L, 2 + i)); + action->setItemIdsVector(Lua::getNumber(L, 2 + i)); } } else { - action->setItemIdsVector(getNumber(L, 2)); + action->setItemIdsVector(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionActionId(lua_State* L) { // action:aid(aids) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - action->setActionIdsVector(getNumber(L, 2 + i)); + action->setActionIdsVector(Lua::getNumber(L, 2 + i)); } } else { - action->setActionIdsVector(getNumber(L, 2)); + action->setActionIdsVector(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionUniqueId(lua_State* L) { // action:uid(uids) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - action->setUniqueIdsVector(getNumber(L, 2 + i)); + action->setUniqueIdsVector(Lua::getNumber(L, 2 + i)); } } else { - action->setUniqueIdsVector(getNumber(L, 2)); + action->setUniqueIdsVector(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } @@ -121,20 +135,20 @@ int ActionFunctions::luaActionPosition(lua_State* L) { * @param itemId or @param itemName = if item id or string name is set, the item is created on position (if not exists), this variable is nil by default * action:position(positions, itemId or name) */ - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (!action) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const Position position = getPosition(L, 2); + const Position position = Lua::getPosition(L, 2); // The parameter "- 1" because self is a parameter aswell, which we want to skip L 1 (UserData) - // isNumber(L, 2) is for skip the itemId + // Lua::isNumber(L, 2) is for skip the itemId if (const int parameters = lua_gettop(L) - 1; - parameters > 1 && isNumber(L, 2)) { + parameters > 1 && Lua::isNumber(L, 2)) { for (int i = 0; i < parameters; ++i) { - action->setPositionsVector(getPosition(L, 2 + i)); + action->setPositionsVector(Lua::getPosition(L, 2 + i)); } } else { action->setPositionsVector(position); @@ -142,14 +156,14 @@ int ActionFunctions::luaActionPosition(lua_State* L) { uint16_t itemId; bool createItem = false; - if (isNumber(L, 3)) { - itemId = getNumber(L, 3); + if (Lua::isNumber(L, 3)) { + itemId = Lua::getNumber(L, 3); createItem = true; - } else if (isString(L, 3)) { - itemId = Item::items.getItemIdByName(getString(L, 3)); + } else if (Lua::isString(L, 3)) { + itemId = Item::items.getItemIdByName(Lua::getString(L, 3)); if (itemId == 0) { - reportErrorFunc("Not found item with name: " + getString(L, 3)); - pushBoolean(L, false); + Lua::reportErrorFunc("Not found item with name: " + Lua::getString(L, 3)); + Lua::pushBoolean(L, false); return 1; } @@ -158,8 +172,8 @@ int ActionFunctions::luaActionPosition(lua_State* L) { if (createItem) { if (!Item::items.hasItemType(itemId)) { - reportErrorFunc("Not found item with id: " + itemId); - pushBoolean(L, false); + Lua::reportErrorFunc("Not found item with id: " + itemId); + Lua::pushBoolean(L, false); return 1; } @@ -172,45 +186,45 @@ int ActionFunctions::luaActionPosition(lua_State* L) { g_game().setCreateLuaItems(position, itemId); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ActionFunctions::luaActionAllowFarUse(lua_State* L) { // action:allowFarUse(bool) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { - action->setAllowFarUse(getBoolean(L, 2)); - pushBoolean(L, true); + action->setAllowFarUse(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionBlockWalls(lua_State* L) { // action:blockWalls(bool) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { - action->setCheckLineOfSight(getBoolean(L, 2)); - pushBoolean(L, true); + action->setCheckLineOfSight(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } int ActionFunctions::luaActionCheckFloor(lua_State* L) { // action:checkFloor(bool) - const auto &action = getUserdataShared(L, 1); + const auto &action = Lua::getUserdataShared(L, 1); if (action) { - action->setCheckFloor(getBoolean(L, 2)); - pushBoolean(L, true); + action->setCheckFloor(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { - reportErrorFunc(getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); } return 1; } diff --git a/src/lua/functions/events/action_functions.hpp b/src/lua/functions/events/action_functions.hpp index 0816ca9d334..e72b65bf726 100644 --- a/src/lua/functions/events/action_functions.hpp +++ b/src/lua/functions/events/action_functions.hpp @@ -9,29 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ActionFunctions final : LuaScriptInterface { +class ActionFunctions { public: - explicit ActionFunctions(lua_State* L) : - LuaScriptInterface("ActionFunctions") { - init(L); - } - ~ActionFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Action", "", ActionFunctions::luaCreateAction); - registerMethod(L, "Action", "onUse", ActionFunctions::luaActionOnUse); - registerMethod(L, "Action", "register", ActionFunctions::luaActionRegister); - registerMethod(L, "Action", "id", ActionFunctions::luaActionItemId); - registerMethod(L, "Action", "aid", ActionFunctions::luaActionActionId); - registerMethod(L, "Action", "uid", ActionFunctions::luaActionUniqueId); - registerMethod(L, "Action", "position", ActionFunctions::luaActionPosition); - registerMethod(L, "Action", "allowFarUse", ActionFunctions::luaActionAllowFarUse); - registerMethod(L, "Action", "blockWalls", ActionFunctions::luaActionBlockWalls); - registerMethod(L, "Action", "checkFloor", ActionFunctions::luaActionCheckFloor); - registerMethod(L, "Action", "position", ActionFunctions::luaActionPosition); - } + static void init(lua_State* L); private: static int luaCreateAction(lua_State* L); diff --git a/src/lua/functions/events/creature_event_functions.cpp b/src/lua/functions/events/creature_event_functions.cpp index ea4c05758d5..6f67375d3eb 100644 --- a/src/lua/functions/events/creature_event_functions.cpp +++ b/src/lua/functions/events/creature_event_functions.cpp @@ -11,21 +11,40 @@ #include "lua/creature/creatureevent.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void CreatureEventFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "CreatureEvent", "", CreatureEventFunctions::luaCreateCreatureEvent); + Lua::registerMethod(L, "CreatureEvent", "type", CreatureEventFunctions::luaCreatureEventType); + Lua::registerMethod(L, "CreatureEvent", "register", CreatureEventFunctions::luaCreatureEventRegister); + Lua::registerMethod(L, "CreatureEvent", "onLogin", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onLogout", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onThink", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onPrepareDeath", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onDeath", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onKill", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onAdvance", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onModalWindow", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onTextEdit", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onHealthChange", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onManaChange", CreatureEventFunctions::luaCreatureEventOnCallback); + Lua::registerMethod(L, "CreatureEvent", "onExtendedOpcode", CreatureEventFunctions::luaCreatureEventOnCallback); +} int CreatureEventFunctions::luaCreateCreatureEvent(lua_State* L) { // CreatureEvent(eventName) - const auto creatureEvent = std::make_shared(getScriptEnv()->getScriptInterface()); - creatureEvent->setName(getString(L, 2)); - pushUserdata(L, creatureEvent); - setMetatable(L, -1, "CreatureEvent"); + const auto creatureEvent = std::make_shared(); + creatureEvent->setName(Lua::getString(L, 2)); + Lua::pushUserdata(L, creatureEvent); + Lua::setMetatable(L, -1, "CreatureEvent"); return 1; } int CreatureEventFunctions::luaCreatureEventType(lua_State* L) { // creatureevent:type(callback) - const auto &creatureEvent = getUserdataShared(L, 1); + const auto &creatureEvent = Lua::getUserdataShared(L, 1); if (creatureEvent) { - std::string typeName = getString(L, 2); + std::string typeName = Lua::getString(L, 2); const std::string tmpStr = asLowerCaseString(typeName); if (tmpStr == "login") { creatureEvent->setEventType(CREATURE_EVENT_LOGIN); @@ -55,10 +74,10 @@ int CreatureEventFunctions::luaCreatureEventType(lua_State* L) { g_logger().error("[CreatureEventFunctions::luaCreatureEventType] - " "Invalid type for creature event: {}", typeName); - pushBoolean(L, false); + Lua::pushBoolean(L, false); } creatureEvent->setLoaded(true); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -67,13 +86,13 @@ int CreatureEventFunctions::luaCreatureEventType(lua_State* L) { int CreatureEventFunctions::luaCreatureEventRegister(lua_State* L) { // creatureevent:register() - const auto &creatureEvent = getUserdataShared(L, 1); + const auto &creatureEvent = Lua::getUserdataShared(L, 1); if (creatureEvent) { - if (!creatureEvent->isLoadedCallback()) { - pushBoolean(L, false); + if (!creatureEvent->isLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_creatureEvents().registerLuaEvent(creatureEvent)); + Lua::pushBoolean(L, g_creatureEvents().registerLuaEvent(creatureEvent)); } else { lua_pushnil(L); } @@ -82,13 +101,13 @@ int CreatureEventFunctions::luaCreatureEventRegister(lua_State* L) { int CreatureEventFunctions::luaCreatureEventOnCallback(lua_State* L) { // creatureevent:onLogin / logout / etc. (callback) - const auto &creatureEvent = getUserdataShared(L, 1); + const auto &creatureEvent = Lua::getUserdataShared(L, 1); if (creatureEvent) { - if (!creatureEvent->loadCallback()) { - pushBoolean(L, false); + if (!creatureEvent->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/events/creature_event_functions.hpp b/src/lua/functions/events/creature_event_functions.hpp index f605d517fbf..be896a495ec 100644 --- a/src/lua/functions/events/creature_event_functions.hpp +++ b/src/lua/functions/events/creature_event_functions.hpp @@ -9,33 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class CreatureEventFunctions final : LuaScriptInterface { +class CreatureEventFunctions { public: - explicit CreatureEventFunctions(lua_State* L) : - LuaScriptInterface("CreatureEventFunctions") { - init(L); - } - ~CreatureEventFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "CreatureEvent", "", CreatureEventFunctions::luaCreateCreatureEvent); - registerMethod(L, "CreatureEvent", "type", CreatureEventFunctions::luaCreatureEventType); - registerMethod(L, "CreatureEvent", "register", CreatureEventFunctions::luaCreatureEventRegister); - registerMethod(L, "CreatureEvent", "onLogin", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onLogout", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onThink", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onPrepareDeath", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onDeath", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onKill", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onAdvance", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onModalWindow", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onTextEdit", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onHealthChange", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onManaChange", CreatureEventFunctions::luaCreatureEventOnCallback); - registerMethod(L, "CreatureEvent", "onExtendedOpcode", CreatureEventFunctions::luaCreatureEventOnCallback); - } + static void init(lua_State* L); private: static int luaCreateCreatureEvent(lua_State* L); diff --git a/src/lua/functions/events/event_callback_functions.cpp b/src/lua/functions/events/event_callback_functions.cpp index db59092f3af..bec82177256 100644 --- a/src/lua/functions/events/event_callback_functions.cpp +++ b/src/lua/functions/events/event_callback_functions.cpp @@ -14,6 +14,7 @@ #include "utils/tools.hpp" #include "items/item.hpp" #include "creatures/players/player.hpp" +#include "lua/functions/lua_functions_loader.hpp" /** * @class EventCallbackFunctions @@ -26,33 +27,33 @@ */ void EventCallbackFunctions::init(lua_State* luaState) { - registerSharedClass(luaState, "EventCallback", "", EventCallbackFunctions::luaEventCallbackCreate); - registerMethod(luaState, "EventCallback", "type", EventCallbackFunctions::luaEventCallbackType); - registerMethod(luaState, "EventCallback", "register", EventCallbackFunctions::luaEventCallbackRegister); + Lua::registerSharedClass(luaState, "EventCallback", "", EventCallbackFunctions::luaEventCallbackCreate); + Lua::registerMethod(luaState, "EventCallback", "type", EventCallbackFunctions::luaEventCallbackType); + Lua::registerMethod(luaState, "EventCallback", "register", EventCallbackFunctions::luaEventCallbackRegister); } int EventCallbackFunctions::luaEventCallbackCreate(lua_State* luaState) { - const auto &callbackName = getString(luaState, 2); + const auto &callbackName = Lua::getString(luaState, 2); if (callbackName.empty()) { - reportErrorFunc("Invalid callback name"); + Lua::reportErrorFunc("Invalid callback name"); return 1; } - bool skipDuplicationCheck = getBoolean(luaState, 3, false); - const auto eventCallback = std::make_shared(getScriptEnv()->getScriptInterface(), callbackName, skipDuplicationCheck); - pushUserdata(luaState, eventCallback); - setMetatable(luaState, -1, "EventCallback"); + bool skipDuplicationCheck = Lua::getBoolean(luaState, 3, false); + const auto eventCallback = std::make_shared(callbackName, skipDuplicationCheck); + Lua::pushUserdata(luaState, eventCallback); + Lua::setMetatable(luaState, -1, "EventCallback"); return 1; } int EventCallbackFunctions::luaEventCallbackType(lua_State* luaState) { - const auto &callback = getUserdataShared(luaState, 1); + const auto &callback = Lua::getUserdataShared(luaState, 1); if (!callback) { - reportErrorFunc("EventCallback is nil"); + Lua::reportErrorFunc("EventCallback is nil"); return 0; } - auto typeName = getString(luaState, 2); + auto typeName = Lua::getString(luaState, 2); auto lowerTypeName = asLowerCaseString(typeName); bool found = false; for (auto enumValue : magic_enum::enum_values()) { @@ -69,46 +70,45 @@ int EventCallbackFunctions::luaEventCallbackType(lua_State* luaState) { if (!found) { g_logger().error("[{}] No valid event name: {}", __func__, typeName); - pushBoolean(luaState, false); + Lua::pushBoolean(luaState, false); } - pushBoolean(luaState, true); + Lua::pushBoolean(luaState, true); return 1; } int EventCallbackFunctions::luaEventCallbackRegister(lua_State* luaState) { - const auto &callback = getUserdataShared(luaState, 1); + const auto &callback = Lua::getUserdataShared(luaState, 1); if (!callback) { return 0; } - if (!callback->isLoadedCallback()) { + if (!callback->isLoadedScriptId()) { return 0; } if (g_callbacks().isCallbackRegistered(callback)) { - reportErrorFunc(fmt::format("EventCallback is duplicated for event with name: {}", callback->getName())); + Lua::reportErrorFunc(fmt::format("EventCallback is duplicated for event with name: {}", callback->getName())); return 0; } g_callbacks().addCallback(callback); - pushBoolean(luaState, true); + Lua::pushBoolean(luaState, true); return 1; } // Callback functions int EventCallbackFunctions::luaEventCallbackLoad(lua_State* luaState) { - const auto &callback = getUserdataShared(luaState, 1); + const auto &callback = Lua::getUserdataShared(luaState, 1); if (!callback) { return 1; } - if (!callback->loadCallback()) { - reportErrorFunc("Cannot load callback"); + if (!callback->loadScriptId()) { + Lua::reportErrorFunc("Cannot load callback"); return 1; } - callback->setLoadedCallback(true); - pushBoolean(luaState, true); + Lua::pushBoolean(luaState, true); return 1; } diff --git a/src/lua/functions/events/event_callback_functions.hpp b/src/lua/functions/events/event_callback_functions.hpp index 9623a52169b..34a08995b2b 100644 --- a/src/lua/functions/events/event_callback_functions.hpp +++ b/src/lua/functions/events/event_callback_functions.hpp @@ -9,8 +9,6 @@ #pragma once -#include "lua/scripts/luascript.hpp" - /** * @class EventCallbackFunctions * @brief Provides a set of static functions for working with Event Callbacks in Lua. @@ -18,14 +16,8 @@ * @details This class encapsulates the Lua binding functions related to event callbacks, * allowing for interaction between the C++ codebase and Lua scripts. */ -class EventCallbackFunctions final : public LuaScriptInterface { +class EventCallbackFunctions { public: - explicit EventCallbackFunctions(lua_State* L) : - LuaScriptInterface("EventCallbackFunctions") { - init(L); - } - ~EventCallbackFunctions() override = default; - /** * @brief Initializes the Lua state with the event callback functions. * diff --git a/src/lua/functions/events/events_scheduler_functions.cpp b/src/lua/functions/events/events_scheduler_functions.cpp index 7b9e7709d9e..0c83a862ff4 100644 --- a/src/lua/functions/events/events_scheduler_functions.cpp +++ b/src/lua/functions/events/events_scheduler_functions.cpp @@ -10,6 +10,17 @@ #include "lua/functions/events/events_scheduler_functions.hpp" #include "game/scheduling/events_scheduler.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void EventsSchedulerFunctions::init(lua_State* L) { + Lua::registerTable(L, "EventsScheduler"); + + Lua::registerMethod(L, "EventsScheduler", "getEventSLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSLoot); + Lua::registerMethod(L, "EventsScheduler", "getEventSBossLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSBossLoot); + Lua::registerMethod(L, "EventsScheduler", "getEventSSkill", EventsSchedulerFunctions::luaEventsSchedulergetEventSSkill); + Lua::registerMethod(L, "EventsScheduler", "getEventSExp", EventsSchedulerFunctions::luaEventsSchedulergetEventSExp); + Lua::registerMethod(L, "EventsScheduler", "getSpawnMonsterSchedule", EventsSchedulerFunctions::luaEventsSchedulergetSpawnMonsterSchedule); +} int EventsSchedulerFunctions::luaEventsSchedulergetEventSLoot(lua_State* L) { // EventsScheduler.getEventSLoot diff --git a/src/lua/functions/events/events_scheduler_functions.hpp b/src/lua/functions/events/events_scheduler_functions.hpp index 9059bf1fdfb..58919ebc9c5 100644 --- a/src/lua/functions/events/events_scheduler_functions.hpp +++ b/src/lua/functions/events/events_scheduler_functions.hpp @@ -9,25 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class EventsSchedulerFunctions final : private LuaScriptInterface { +class EventsSchedulerFunctions { public: - explicit EventsSchedulerFunctions(lua_State* L) : - LuaScriptInterface("EventsSchedulerFunctions") { - init(L); - } - ~EventsSchedulerFunctions() override = default; - - static void init(lua_State* L) { - registerTable(L, "EventsScheduler"); - - registerMethod(L, "EventsScheduler", "getEventSLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSLoot); - registerMethod(L, "EventsScheduler", "getEventSBossLoot", EventsSchedulerFunctions::luaEventsSchedulergetEventSBossLoot); - registerMethod(L, "EventsScheduler", "getEventSSkill", EventsSchedulerFunctions::luaEventsSchedulergetEventSSkill); - registerMethod(L, "EventsScheduler", "getEventSExp", EventsSchedulerFunctions::luaEventsSchedulergetEventSExp); - registerMethod(L, "EventsScheduler", "getSpawnMonsterSchedule", EventsSchedulerFunctions::luaEventsSchedulergetSpawnMonsterSchedule); - } + static void init(lua_State* L); private: static int luaEventsSchedulergetEventSLoot(lua_State* L); diff --git a/src/lua/functions/events/global_event_functions.cpp b/src/lua/functions/events/global_event_functions.cpp index 32c9eccf2e5..b7dddb9bb02 100644 --- a/src/lua/functions/events/global_event_functions.cpp +++ b/src/lua/functions/events/global_event_functions.cpp @@ -12,21 +12,37 @@ #include "game/game.hpp" #include "lua/global/globalevent.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void GlobalEventFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "GlobalEvent", "", GlobalEventFunctions::luaCreateGlobalEvent); + Lua::registerMethod(L, "GlobalEvent", "type", GlobalEventFunctions::luaGlobalEventType); + Lua::registerMethod(L, "GlobalEvent", "register", GlobalEventFunctions::luaGlobalEventRegister); + Lua::registerMethod(L, "GlobalEvent", "time", GlobalEventFunctions::luaGlobalEventTime); + Lua::registerMethod(L, "GlobalEvent", "interval", GlobalEventFunctions::luaGlobalEventInterval); + Lua::registerMethod(L, "GlobalEvent", "onThink", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onTime", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onStartup", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onShutdown", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onRecord", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onPeriodChange", GlobalEventFunctions::luaGlobalEventOnCallback); + Lua::registerMethod(L, "GlobalEvent", "onSave", GlobalEventFunctions::luaGlobalEventOnCallback); +} int GlobalEventFunctions::luaCreateGlobalEvent(lua_State* L) { - const auto global = std::make_shared(getScriptEnv()->getScriptInterface()); - global->setName(getString(L, 2)); + const auto global = std::make_shared(); + global->setName(Lua::getString(L, 2)); global->setEventType(GLOBALEVENT_NONE); - pushUserdata(L, global); - setMetatable(L, -1, "GlobalEvent"); + Lua::pushUserdata(L, global); + Lua::setMetatable(L, -1, "GlobalEvent"); return 1; } int GlobalEventFunctions::luaGlobalEventType(lua_State* L) { // globalevent:type(callback) - const auto &global = getUserdataShared(L, 1); + const auto &global = Lua::getUserdataShared(L, 1); if (global) { - const std::string typeName = getString(L, 2); + const std::string typeName = Lua::getString(L, 2); const std::string tmpStr = asLowerCaseString(typeName); if (tmpStr == "startup") { global->setEventType(GLOBALEVENT_STARTUP); @@ -43,9 +59,9 @@ int GlobalEventFunctions::luaGlobalEventType(lua_State* L) { } else { g_logger().error("[GlobalEventFunctions::luaGlobalEventType] - " "Invalid type for global event: {}"); - pushBoolean(L, false); + Lua::pushBoolean(L, false); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -54,18 +70,18 @@ int GlobalEventFunctions::luaGlobalEventType(lua_State* L) { int GlobalEventFunctions::luaGlobalEventRegister(lua_State* L) { // globalevent:register() - const auto &globalevent = getUserdataShared(L, 1); + const auto &globalevent = Lua::getUserdataShared(L, 1); if (globalevent) { - if (!globalevent->isLoadedCallback()) { - pushBoolean(L, false); + if (!globalevent->isLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } if (globalevent->getEventType() == GLOBALEVENT_NONE && globalevent->getInterval() == 0) { g_logger().error("{} - No interval for globalevent with name {}", __FUNCTION__, globalevent->getName()); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_globalEvents().registerLuaEvent(globalevent)); + Lua::pushBoolean(L, g_globalEvents().registerLuaEvent(globalevent)); } else { lua_pushnil(L); } @@ -74,13 +90,13 @@ int GlobalEventFunctions::luaGlobalEventRegister(lua_State* L) { int GlobalEventFunctions::luaGlobalEventOnCallback(lua_State* L) { // globalevent:onThink / record / etc. (callback) - const auto &globalevent = getUserdataShared(L, 1); + const auto &globalevent = Lua::getUserdataShared(L, 1); if (globalevent) { - if (!globalevent->loadCallback()) { - pushBoolean(L, false); + if (!globalevent->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -89,9 +105,9 @@ int GlobalEventFunctions::luaGlobalEventOnCallback(lua_State* L) { int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { // globalevent:time(time) - const auto &globalevent = getUserdataShared(L, 1); + const auto &globalevent = Lua::getUserdataShared(L, 1); if (globalevent) { - std::string timer = getString(L, 2); + std::string timer = Lua::getString(L, 2); const std::vector params = vectorAtoi(explodeString(timer, ":")); const int32_t hour = params.front(); @@ -99,7 +115,7 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { g_logger().error("[GlobalEventFunctions::luaGlobalEventTime] - " "Invalid hour {} for globalevent with name: {}", timer, globalevent->getName()); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -113,7 +129,7 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { g_logger().error("[GlobalEventFunctions::luaGlobalEventTime] - " "Invalid minute: {} for globalevent with name: {}", timer, globalevent->getName()); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } @@ -123,7 +139,7 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { g_logger().error("[GlobalEventFunctions::luaGlobalEventTime] - " "Invalid minute: {} for globalevent with name: {}", timer, globalevent->getName()); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } } @@ -143,7 +159,7 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { globalevent->setNextExecution(current_time + difference); globalevent->setEventType(GLOBALEVENT_TIMER); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -152,11 +168,11 @@ int GlobalEventFunctions::luaGlobalEventTime(lua_State* L) { int GlobalEventFunctions::luaGlobalEventInterval(lua_State* L) { // globalevent:interval(interval) - const auto &globalevent = getUserdataShared(L, 1); + const auto &globalevent = Lua::getUserdataShared(L, 1); if (globalevent) { - globalevent->setInterval(getNumber(L, 2)); - globalevent->setNextExecution(OTSYS_TIME() + getNumber(L, 2)); - pushBoolean(L, true); + globalevent->setInterval(Lua::getNumber(L, 2)); + globalevent->setNextExecution(OTSYS_TIME() + Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/events/global_event_functions.hpp b/src/lua/functions/events/global_event_functions.hpp index 41fc57fdfea..1860a7a8d39 100644 --- a/src/lua/functions/events/global_event_functions.hpp +++ b/src/lua/functions/events/global_event_functions.hpp @@ -9,30 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class GlobalEventFunctions final : LuaScriptInterface { +class GlobalEventFunctions { public: - explicit GlobalEventFunctions(lua_State* L) : - LuaScriptInterface("GlobalEventFunctions") { - init(L); - } - ~GlobalEventFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "GlobalEvent", "", GlobalEventFunctions::luaCreateGlobalEvent); - registerMethod(L, "GlobalEvent", "type", GlobalEventFunctions::luaGlobalEventType); - registerMethod(L, "GlobalEvent", "register", GlobalEventFunctions::luaGlobalEventRegister); - registerMethod(L, "GlobalEvent", "time", GlobalEventFunctions::luaGlobalEventTime); - registerMethod(L, "GlobalEvent", "interval", GlobalEventFunctions::luaGlobalEventInterval); - registerMethod(L, "GlobalEvent", "onThink", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onTime", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onStartup", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onShutdown", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onRecord", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onPeriodChange", GlobalEventFunctions::luaGlobalEventOnCallback); - registerMethod(L, "GlobalEvent", "onSave", GlobalEventFunctions::luaGlobalEventOnCallback); - } + static void init(lua_State* L); private: static int luaCreateGlobalEvent(lua_State* L); diff --git a/src/lua/functions/events/move_event_functions.cpp b/src/lua/functions/events/move_event_functions.cpp index ac7727fb2a9..c5ea87b5a45 100644 --- a/src/lua/functions/events/move_event_functions.cpp +++ b/src/lua/functions/events/move_event_functions.cpp @@ -12,20 +12,42 @@ #include "creatures/creature.hpp" #include "lua/creature/movement.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void MoveEventFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "MoveEvent", "", MoveEventFunctions::luaCreateMoveEvent); + Lua::registerMethod(L, "MoveEvent", "type", MoveEventFunctions::luaMoveEventType); + Lua::registerMethod(L, "MoveEvent", "register", MoveEventFunctions::luaMoveEventRegister); + Lua::registerMethod(L, "MoveEvent", "level", MoveEventFunctions::luaMoveEventLevel); + Lua::registerMethod(L, "MoveEvent", "magicLevel", MoveEventFunctions::luaMoveEventMagLevel); + Lua::registerMethod(L, "MoveEvent", "slot", MoveEventFunctions::luaMoveEventSlot); + Lua::registerMethod(L, "MoveEvent", "id", MoveEventFunctions::luaMoveEventItemId); + Lua::registerMethod(L, "MoveEvent", "aid", MoveEventFunctions::luaMoveEventActionId); + Lua::registerMethod(L, "MoveEvent", "uid", MoveEventFunctions::luaMoveEventUniqueId); + Lua::registerMethod(L, "MoveEvent", "position", MoveEventFunctions::luaMoveEventPosition); + Lua::registerMethod(L, "MoveEvent", "premium", MoveEventFunctions::luaMoveEventPremium); + Lua::registerMethod(L, "MoveEvent", "vocation", MoveEventFunctions::luaMoveEventVocation); + Lua::registerMethod(L, "MoveEvent", "onEquip", MoveEventFunctions::luaMoveEventOnCallback); + Lua::registerMethod(L, "MoveEvent", "onDeEquip", MoveEventFunctions::luaMoveEventOnCallback); + Lua::registerMethod(L, "MoveEvent", "onStepIn", MoveEventFunctions::luaMoveEventOnCallback); + Lua::registerMethod(L, "MoveEvent", "onStepOut", MoveEventFunctions::luaMoveEventOnCallback); + Lua::registerMethod(L, "MoveEvent", "onAddItem", MoveEventFunctions::luaMoveEventOnCallback); + Lua::registerMethod(L, "MoveEvent", "onRemoveItem", MoveEventFunctions::luaMoveEventOnCallback); +} int MoveEventFunctions::luaCreateMoveEvent(lua_State* L) { // MoveEvent() - const auto moveevent = std::make_shared(getScriptEnv()->getScriptInterface()); - pushUserdata(L, moveevent); - setMetatable(L, -1, "MoveEvent"); + const auto moveevent = std::make_shared(); + Lua::pushUserdata(L, moveevent); + Lua::setMetatable(L, -1, "MoveEvent"); return 1; } int MoveEventFunctions::luaMoveEventType(lua_State* L) { // moveevent:type(callback) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - std::string typeName = getString(L, 2); + std::string typeName = Lua::getString(L, 2); const std::string tmpStr = asLowerCaseString(typeName); if (tmpStr == "stepin") { moveevent->setEventType(MOVE_EVENT_STEP_IN); @@ -49,9 +71,9 @@ int MoveEventFunctions::luaMoveEventType(lua_State* L) { g_logger().error("[MoveEventFunctions::luaMoveEventType] - " "No valid event name: {}", typeName); - pushBoolean(L, false); + Lua::pushBoolean(L, false); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -60,16 +82,16 @@ int MoveEventFunctions::luaMoveEventType(lua_State* L) { int MoveEventFunctions::luaMoveEventRegister(lua_State* L) { // moveevent:register() - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { // If not scripted, register item event // Example: unscripted_equipments.lua - if (!moveevent->isLoadedCallback()) { - pushBoolean(L, g_moveEvents().registerLuaItemEvent(moveevent)); + if (!moveevent->isLoadedScriptId()) { + Lua::pushBoolean(L, g_moveEvents().registerLuaItemEvent(moveevent)); return 1; } - pushBoolean(L, g_moveEvents().registerLuaEvent(moveevent)); + Lua::pushBoolean(L, g_moveEvents().registerLuaEvent(moveevent)); } else { lua_pushnil(L); } @@ -78,14 +100,14 @@ int MoveEventFunctions::luaMoveEventRegister(lua_State* L) { int MoveEventFunctions::luaMoveEventOnCallback(lua_State* L) { // moveevent:onEquip / deEquip / etc. (callback) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - if (!moveevent->loadCallback()) { - pushBoolean(L, false); + if (!moveevent->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -94,14 +116,14 @@ int MoveEventFunctions::luaMoveEventOnCallback(lua_State* L) { int MoveEventFunctions::luaMoveEventSlot(lua_State* L) { // moveevent:slot(slot) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (!moveevent) { lua_pushnil(L); return 1; } if (moveevent->getEventType() == MOVE_EVENT_EQUIP || moveevent->getEventType() == MOVE_EVENT_DEEQUIP) { - std::string slotName = asLowerCaseString(getString(L, 2)); + std::string slotName = asLowerCaseString(Lua::getString(L, 2)); if (slotName == "head") { moveevent->setSlot(SLOTP_HEAD); } else if (slotName == "necklace") { @@ -128,22 +150,22 @@ int MoveEventFunctions::luaMoveEventSlot(lua_State* L) { g_logger().warn("[MoveEventFunctions::luaMoveEventSlot] - " "Unknown slot type: {}", slotName); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int MoveEventFunctions::luaMoveEventLevel(lua_State* L) { // moveevent:level(lvl) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - moveevent->setRequiredLevel(getNumber(L, 2)); + moveevent->setRequiredLevel(Lua::getNumber(L, 2)); moveevent->setWieldInfo(WIELDINFO_LEVEL); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -152,11 +174,11 @@ int MoveEventFunctions::luaMoveEventLevel(lua_State* L) { int MoveEventFunctions::luaMoveEventMagLevel(lua_State* L) { // moveevent:magicLevel(lvl) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - moveevent->setRequiredMagLevel(getNumber(L, 2)); + moveevent->setRequiredMagLevel(Lua::getNumber(L, 2)); moveevent->setWieldInfo(WIELDINFO_MAGLV); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -165,11 +187,11 @@ int MoveEventFunctions::luaMoveEventMagLevel(lua_State* L) { int MoveEventFunctions::luaMoveEventPremium(lua_State* L) { // moveevent:premium(bool) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - moveevent->setNeedPremium(getBoolean(L, 2)); + moveevent->setNeedPremium(Lua::getBoolean(L, 2)); moveevent->setWieldInfo(WIELDINFO_PREMIUM); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -178,22 +200,22 @@ int MoveEventFunctions::luaMoveEventPremium(lua_State* L) { int MoveEventFunctions::luaMoveEventVocation(lua_State* L) { // moveevent:vocation(vocName[, showInDescription = false, lastVoc = false]) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { - moveevent->addVocEquipMap(getString(L, 2)); + moveevent->addVocEquipMap(Lua::getString(L, 2)); moveevent->setWieldInfo(WIELDINFO_VOCREQ); std::string tmp; bool showInDescription = false; bool lastVoc = false; - if (getBoolean(L, 3)) { - showInDescription = getBoolean(L, 3); + if (Lua::getBoolean(L, 3)) { + showInDescription = Lua::getBoolean(L, 3); } - if (getBoolean(L, 4)) { - lastVoc = getBoolean(L, 4); + if (Lua::getBoolean(L, 4)) { + lastVoc = Lua::getBoolean(L, 4); } if (showInDescription) { if (moveevent->getVocationString().empty()) { - tmp = asLowerCaseString(getString(L, 2)); + tmp = asLowerCaseString(Lua::getString(L, 2)); tmp += "s"; moveevent->setVocationString(tmp); } else { @@ -203,12 +225,12 @@ int MoveEventFunctions::luaMoveEventVocation(lua_State* L) { } else { tmp += ", "; } - tmp += asLowerCaseString(getString(L, 2)); + tmp += asLowerCaseString(Lua::getString(L, 2)); tmp += "s"; moveevent->setVocationString(tmp); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -217,17 +239,17 @@ int MoveEventFunctions::luaMoveEventVocation(lua_State* L) { int MoveEventFunctions::luaMoveEventItemId(lua_State* L) { // moveevent:id(ids) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - moveevent->setItemId(getNumber(L, 2 + i)); + moveevent->setItemId(Lua::getNumber(L, 2 + i)); } } else { - moveevent->setItemId(getNumber(L, 2)); + moveevent->setItemId(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -236,17 +258,17 @@ int MoveEventFunctions::luaMoveEventItemId(lua_State* L) { int MoveEventFunctions::luaMoveEventActionId(lua_State* L) { // moveevent:aid(ids) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - moveevent->setActionId(getNumber(L, 2 + i)); + moveevent->setActionId(Lua::getNumber(L, 2 + i)); } } else { - moveevent->setActionId(getNumber(L, 2)); + moveevent->setActionId(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -255,17 +277,17 @@ int MoveEventFunctions::luaMoveEventActionId(lua_State* L) { int MoveEventFunctions::luaMoveEventUniqueId(lua_State* L) { // moveevent:uid(ids) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - moveevent->setUniqueId(getNumber(L, 2 + i)); + moveevent->setUniqueId(Lua::getNumber(L, 2 + i)); } } else { - moveevent->setUniqueId(getNumber(L, 2)); + moveevent->setUniqueId(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -274,17 +296,17 @@ int MoveEventFunctions::luaMoveEventUniqueId(lua_State* L) { int MoveEventFunctions::luaMoveEventPosition(lua_State* L) { // moveevent:position(positions) - const auto &moveevent = getUserdataShared(L, 1); + const auto &moveevent = Lua::getUserdataShared(L, 1); if (moveevent) { const int parameters = lua_gettop(L) - 1; // - 1 because self is a parameter aswell, which we want to skip ofc if (parameters > 1) { for (int i = 0; i < parameters; ++i) { - moveevent->setPosition(getPosition(L, 2 + i)); + moveevent->setPosition(Lua::getPosition(L, 2 + i)); } } else { - moveevent->setPosition(getPosition(L, 2)); + moveevent->setPosition(Lua::getPosition(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/events/move_event_functions.hpp b/src/lua/functions/events/move_event_functions.hpp index 202006257e6..cfc30c3ecda 100644 --- a/src/lua/functions/events/move_event_functions.hpp +++ b/src/lua/functions/events/move_event_functions.hpp @@ -9,36 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class MoveEventFunctions final : LuaScriptInterface { +class MoveEventFunctions { public: - explicit MoveEventFunctions(lua_State* L) : - LuaScriptInterface("MoveEventFunctions") { - init(L); - } - ~MoveEventFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "MoveEvent", "", MoveEventFunctions::luaCreateMoveEvent); - registerMethod(L, "MoveEvent", "type", MoveEventFunctions::luaMoveEventType); - registerMethod(L, "MoveEvent", "register", MoveEventFunctions::luaMoveEventRegister); - registerMethod(L, "MoveEvent", "level", MoveEventFunctions::luaMoveEventLevel); - registerMethod(L, "MoveEvent", "magicLevel", MoveEventFunctions::luaMoveEventMagLevel); - registerMethod(L, "MoveEvent", "slot", MoveEventFunctions::luaMoveEventSlot); - registerMethod(L, "MoveEvent", "id", MoveEventFunctions::luaMoveEventItemId); - registerMethod(L, "MoveEvent", "aid", MoveEventFunctions::luaMoveEventActionId); - registerMethod(L, "MoveEvent", "uid", MoveEventFunctions::luaMoveEventUniqueId); - registerMethod(L, "MoveEvent", "position", MoveEventFunctions::luaMoveEventPosition); - registerMethod(L, "MoveEvent", "premium", MoveEventFunctions::luaMoveEventPremium); - registerMethod(L, "MoveEvent", "vocation", MoveEventFunctions::luaMoveEventVocation); - registerMethod(L, "MoveEvent", "onEquip", MoveEventFunctions::luaMoveEventOnCallback); - registerMethod(L, "MoveEvent", "onDeEquip", MoveEventFunctions::luaMoveEventOnCallback); - registerMethod(L, "MoveEvent", "onStepIn", MoveEventFunctions::luaMoveEventOnCallback); - registerMethod(L, "MoveEvent", "onStepOut", MoveEventFunctions::luaMoveEventOnCallback); - registerMethod(L, "MoveEvent", "onAddItem", MoveEventFunctions::luaMoveEventOnCallback); - registerMethod(L, "MoveEvent", "onRemoveItem", MoveEventFunctions::luaMoveEventOnCallback); - } + static void init(lua_State* L); private: static int luaCreateMoveEvent(lua_State* L); diff --git a/src/lua/functions/events/talk_action_functions.cpp b/src/lua/functions/events/talk_action_functions.cpp index 1b87fec4b7d..39328ea7de4 100644 --- a/src/lua/functions/events/talk_action_functions.cpp +++ b/src/lua/functions/events/talk_action_functions.cpp @@ -14,53 +14,67 @@ #include "utils/tools.hpp" #include "enums/account_group_type.hpp" +#include "lua/functions/lua_functions_loader.hpp" +#include "lua/scripts/luascript.hpp" + +void TalkActionFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "TalkAction", "", TalkActionFunctions::luaCreateTalkAction); + Lua::registerMethod(L, "TalkAction", "onSay", TalkActionFunctions::luaTalkActionOnSay); + Lua::registerMethod(L, "TalkAction", "groupType", TalkActionFunctions::luaTalkActionGroupType); + Lua::registerMethod(L, "TalkAction", "register", TalkActionFunctions::luaTalkActionRegister); + Lua::registerMethod(L, "TalkAction", "separator", TalkActionFunctions::luaTalkActionSeparator); + Lua::registerMethod(L, "TalkAction", "getName", TalkActionFunctions::luaTalkActionGetName); + Lua::registerMethod(L, "TalkAction", "getDescription", TalkActionFunctions::luaTalkActionGetDescription); + Lua::registerMethod(L, "TalkAction", "setDescription", TalkActionFunctions::luaTalkActionSetDescription); + Lua::registerMethod(L, "TalkAction", "getGroupType", TalkActionFunctions::luaTalkActionGetGroupType); +} int TalkActionFunctions::luaCreateTalkAction(lua_State* L) { // TalkAction(words) or TalkAction(word1, word2, word3) std::vector wordsVector; for (int i = 2; i <= lua_gettop(L); i++) { - wordsVector.push_back(getString(L, i)); + wordsVector.push_back(Lua::getString(L, i)); } - const auto talkactionSharedPtr = std::make_shared(getScriptEnv()->getScriptInterface()); + const auto talkactionSharedPtr = std::make_shared(); talkactionSharedPtr->setWords(wordsVector); - pushUserdata(L, talkactionSharedPtr); - setMetatable(L, -1, "TalkAction"); + Lua::pushUserdata(L, talkactionSharedPtr); + Lua::setMetatable(L, -1, "TalkAction"); return 1; } int TalkActionFunctions::luaTalkActionOnSay(lua_State* L) { // talkAction:onSay(callback) - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - if (!talkactionSharedPtr->loadCallback()) { - pushBoolean(L, false); + if (!talkactionSharedPtr->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int TalkActionFunctions::luaTalkActionGroupType(lua_State* L) { // talkAction:groupType(GroupType = GROUP_TYPE_NORMAL) - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } GroupType groupType; const int type = lua_type(L, 2); if (type == LUA_TNUMBER) { - groupType = enumFromValue(getNumber(L, 2)); + groupType = enumFromValue(Lua::getNumber(L, 2)); } else if (type == LUA_TSTRING) { - std::string strValue = getString(L, 2); + std::string strValue = Lua::getString(L, 2); if (strValue == "normal") { groupType = GROUP_TYPE_NORMAL; } else if (strValue == "tutor") { @@ -74,108 +88,108 @@ int TalkActionFunctions::luaTalkActionGroupType(lua_State* L) { } else if (strValue == "god") { groupType = GROUP_TYPE_GOD; } else { - const auto string = fmt::format("Invalid group type string value {} for group type for script: {}", strValue, getScriptEnv()->getScriptInterface()->getLoadingScriptName()); - reportErrorFunc(string); - pushBoolean(L, false); + const auto string = fmt::format("Invalid group type string value {} for group type for script: {}", strValue, Lua::getScriptEnv()->getScriptInterface()->getLoadingScriptName()); + Lua::reportErrorFunc(string); + Lua::pushBoolean(L, false); return 1; } } else { - const auto string = fmt::format("Expected number or string value for group type for script: {}", getScriptEnv()->getScriptInterface()->getLoadingScriptName()); - reportErrorFunc(string); - pushBoolean(L, false); + const auto string = fmt::format("Expected number or string value for group type for script: {}", Lua::getScriptEnv()->getScriptInterface()->getLoadingScriptName()); + Lua::reportErrorFunc(string); + Lua::pushBoolean(L, false); return 1; } talkactionSharedPtr->setGroupType(groupType); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int TalkActionFunctions::luaTalkActionRegister(lua_State* L) { // talkAction:register() - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - if (!talkactionSharedPtr->isLoadedCallback()) { - pushBoolean(L, false); + if (!talkactionSharedPtr->isLoadedScriptId()) { + Lua::pushBoolean(L, false); return 1; } if (talkactionSharedPtr->getGroupType() == GROUP_TYPE_NONE) { const auto string = fmt::format("TalkAction with name {} does't have groupType", talkactionSharedPtr->getWords()); - reportErrorFunc(string); - pushBoolean(L, false); + Lua::reportErrorFunc(string); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, g_talkActions().registerLuaEvent(talkactionSharedPtr)); + Lua::pushBoolean(L, g_talkActions().registerLuaEvent(talkactionSharedPtr)); return 1; } int TalkActionFunctions::luaTalkActionSeparator(lua_State* L) { // talkAction:separator(sep) - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - talkactionSharedPtr->setSeparator(getString(L, 2)); - pushBoolean(L, true); + talkactionSharedPtr->setSeparator(Lua::getString(L, 2)); + Lua::pushBoolean(L, true); return 1; } int TalkActionFunctions::luaTalkActionGetName(lua_State* L) { // local name = talkAction:getName() - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushString(L, talkactionSharedPtr->getWords()); + Lua::pushString(L, talkactionSharedPtr->getWords()); return 1; } int TalkActionFunctions::luaTalkActionGetDescription(lua_State* L) { // local description = talkAction:getDescription() - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushString(L, talkactionSharedPtr->getDescription()); + Lua::pushString(L, talkactionSharedPtr->getDescription()); return 1; } int TalkActionFunctions::luaTalkActionSetDescription(lua_State* L) { // local description = talkAction:setDescription() - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - talkactionSharedPtr->setDescription(getString(L, 2)); - pushBoolean(L, true); + talkactionSharedPtr->setDescription(Lua::getString(L, 2)); + Lua::pushBoolean(L, true); return 1; } int TalkActionFunctions::luaTalkActionGetGroupType(lua_State* L) { // local groupType = talkAction:getGroupType() - const auto &talkactionSharedPtr = getUserdataShared(L, 1); + const auto &talkactionSharedPtr = Lua::getUserdataShared(L, 1); if (!talkactionSharedPtr) { - reportErrorFunc(getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_TALK_ACTION_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } diff --git a/src/lua/functions/events/talk_action_functions.hpp b/src/lua/functions/events/talk_action_functions.hpp index 487f2046d2f..5877293bb9e 100644 --- a/src/lua/functions/events/talk_action_functions.hpp +++ b/src/lua/functions/events/talk_action_functions.hpp @@ -9,27 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class TalkActionFunctions final : LuaScriptInterface { +class TalkActionFunctions { public: - explicit TalkActionFunctions(lua_State* L) : - LuaScriptInterface("TalkActionFunctions") { - init(L); - } - ~TalkActionFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "TalkAction", "", TalkActionFunctions::luaCreateTalkAction); - registerMethod(L, "TalkAction", "onSay", TalkActionFunctions::luaTalkActionOnSay); - registerMethod(L, "TalkAction", "groupType", TalkActionFunctions::luaTalkActionGroupType); - registerMethod(L, "TalkAction", "register", TalkActionFunctions::luaTalkActionRegister); - registerMethod(L, "TalkAction", "separator", TalkActionFunctions::luaTalkActionSeparator); - registerMethod(L, "TalkAction", "getName", TalkActionFunctions::luaTalkActionGetName); - registerMethod(L, "TalkAction", "getDescription", TalkActionFunctions::luaTalkActionGetDescription); - registerMethod(L, "TalkAction", "setDescription", TalkActionFunctions::luaTalkActionSetDescription); - registerMethod(L, "TalkAction", "getGroupType", TalkActionFunctions::luaTalkActionGetGroupType); - } + static void init(lua_State* L); private: static int luaCreateTalkAction(lua_State* L); diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index 8a0a84e3199..934c8ce3ff8 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -12,15 +12,37 @@ #include "game/game.hpp" #include "items/item.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ContainerFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Container", "Item", ContainerFunctions::luaContainerCreate); + Lua::registerMetaMethod(L, "Container", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Container", "getSize", ContainerFunctions::luaContainerGetSize); + Lua::registerMethod(L, "Container", "getMaxCapacity", ContainerFunctions::luaContainerGetMaxCapacity); + Lua::registerMethod(L, "Container", "getCapacity", ContainerFunctions::luaContainerGetCapacity); + Lua::registerMethod(L, "Container", "getEmptySlots", ContainerFunctions::luaContainerGetEmptySlots); + Lua::registerMethod(L, "Container", "getContentDescription", ContainerFunctions::luaContainerGetContentDescription); + Lua::registerMethod(L, "Container", "getItems", ContainerFunctions::luaContainerGetItems); + Lua::registerMethod(L, "Container", "getItemHoldingCount", ContainerFunctions::luaContainerGetItemHoldingCount); + Lua::registerMethod(L, "Container", "getItemCountById", ContainerFunctions::luaContainerGetItemCountById); + + Lua::registerMethod(L, "Container", "getItem", ContainerFunctions::luaContainerGetItem); + Lua::registerMethod(L, "Container", "hasItem", ContainerFunctions::luaContainerHasItem); + Lua::registerMethod(L, "Container", "addItem", ContainerFunctions::luaContainerAddItem); + Lua::registerMethod(L, "Container", "addItemEx", ContainerFunctions::luaContainerAddItemEx); + Lua::registerMethod(L, "Container", "getCorpseOwner", ContainerFunctions::luaContainerGetCorpseOwner); + Lua::registerMethod(L, "Container", "registerReward", ContainerFunctions::luaContainerRegisterReward); +} int ContainerFunctions::luaContainerCreate(lua_State* L) { // Container(uid) - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); - const auto &container = getScriptEnv()->getContainerByUID(id); + const auto &container = Lua::getScriptEnv()->getContainerByUID(id); if (container) { - pushUserdata(L, container); - setMetatable(L, -1, "Container"); + Lua::pushUserdata(L, container); + Lua::setMetatable(L, -1, "Container"); } else { lua_pushnil(L); } @@ -29,7 +51,7 @@ int ContainerFunctions::luaContainerCreate(lua_State* L) { int ContainerFunctions::luaContainerGetSize(lua_State* L) { // container:getSize() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->size()); } else { @@ -40,7 +62,7 @@ int ContainerFunctions::luaContainerGetSize(lua_State* L) { int ContainerFunctions::luaContainerGetMaxCapacity(lua_State* L) { // container:getMaxCapacity() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->getMaxCapacity()); } else { @@ -51,7 +73,7 @@ int ContainerFunctions::luaContainerGetMaxCapacity(lua_State* L) { int ContainerFunctions::luaContainerGetCapacity(lua_State* L) { // container:getCapacity() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->capacity()); } else { @@ -62,14 +84,14 @@ int ContainerFunctions::luaContainerGetCapacity(lua_State* L) { int ContainerFunctions::luaContainerGetEmptySlots(lua_State* L) { // container:getEmptySlots([recursive = false]) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } uint32_t slots = container->capacity() - container->size(); - const bool recursive = getBoolean(L, 2, false); + const bool recursive = Lua::getBoolean(L, 2, false); if (recursive) { for (ContainerIterator it = container->iterator(); it.hasNext(); it.advance()) { if (const auto &tmpContainer = (*it)->getContainer()) { @@ -83,7 +105,7 @@ int ContainerFunctions::luaContainerGetEmptySlots(lua_State* L) { int ContainerFunctions::luaContainerGetItemHoldingCount(lua_State* L) { // container:getItemHoldingCount() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->getItemHoldingCount()); } else { @@ -94,17 +116,17 @@ int ContainerFunctions::luaContainerGetItemHoldingCount(lua_State* L) { int ContainerFunctions::luaContainerGetItem(lua_State* L) { // container:getItem(index) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } - const uint32_t index = getNumber(L, 2); + const uint32_t index = Lua::getNumber(L, 2); const auto &item = container->getItemByIndex(index); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -113,10 +135,10 @@ int ContainerFunctions::luaContainerGetItem(lua_State* L) { int ContainerFunctions::luaContainerHasItem(lua_State* L) { // container:hasItem(item) - const auto &item = getUserdataShared(L, 2); - const auto &container = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 2); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { - pushBoolean(L, container->isHoldingItem(item)); + Lua::pushBoolean(L, container->isHoldingItem(item)); } else { lua_pushnil(L); } @@ -125,26 +147,26 @@ int ContainerFunctions::luaContainerHasItem(lua_State* L) { int ContainerFunctions::luaContainerAddItem(lua_State* L) { // container:addItem(itemId[, count/subType = 1[, index = INDEX_WHEREEVER[, flags = 0]]]) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); - reportErrorFunc("Container is nullptr"); + Lua::reportErrorFunc("Container is nullptr"); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); - reportErrorFunc("Item id is wrong"); + Lua::reportErrorFunc("Item id is wrong"); return 1; } } - auto count = getNumber(L, 3, 1); + auto count = Lua::getNumber(L, 3, 1); const ItemType &it = Item::items[itemId]; if (it.stackable) { count = std::min(count, it.stackSize); @@ -153,46 +175,46 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { const auto &item = Item::CreateItem(itemId, count); if (!item) { lua_pushnil(L); - reportErrorFunc("Item is nullptr"); + Lua::reportErrorFunc("Item is nullptr"); return 1; } - const auto index = getNumber(L, 4, INDEX_WHEREEVER); - const auto flags = getNumber(L, 5, 0); + const auto index = Lua::getNumber(L, 4, INDEX_WHEREEVER); + const auto flags = Lua::getNumber(L, 5, 0); ReturnValue ret = g_game().internalAddItem(container, item, index, flags); if (ret == RETURNVALUE_NOERROR) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { - reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); - pushBoolean(L, false); + Lua::reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); + Lua::pushBoolean(L, false); } return 1; } int ContainerFunctions::luaContainerAddItemEx(lua_State* L) { // container:addItemEx(item[, index = INDEX_WHEREEVER[, flags = 0]]) - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } if (item->getParent() != VirtualCylinder::virtualCylinder) { - reportErrorFunc("Item already has a parent"); + Lua::reportErrorFunc("Item already has a parent"); lua_pushnil(L); return 1; } - const auto index = getNumber(L, 3, INDEX_WHEREEVER); - const auto flags = getNumber(L, 4, 0); + const auto index = Lua::getNumber(L, 3, INDEX_WHEREEVER); + const auto flags = Lua::getNumber(L, 4, 0); ReturnValue ret = g_game().internalAddItem(container, item, index, flags); if (ret == RETURNVALUE_NOERROR) { ScriptEnvironment::removeTempItem(item); @@ -203,7 +225,7 @@ int ContainerFunctions::luaContainerAddItemEx(lua_State* L) { int ContainerFunctions::luaContainerGetCorpseOwner(lua_State* L) { // container:getCorpseOwner() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { lua_pushnumber(L, container->getCorpseOwner()); } else { @@ -214,33 +236,33 @@ int ContainerFunctions::luaContainerGetCorpseOwner(lua_State* L) { int ContainerFunctions::luaContainerGetItemCountById(lua_State* L) { // container:getItemCountById(itemId[, subType = -1]) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto subType = getNumber(L, 3, -1); + const auto subType = Lua::getNumber(L, 3, -1); lua_pushnumber(L, container->getItemTypeCount(itemId, subType)); return 1; } int ContainerFunctions::luaContainerGetContentDescription(lua_State* L) { // container:getContentDescription([oldProtocol]) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (container) { - pushString(L, container->getContentDescription(getBoolean(L, 2, false))); + Lua::pushString(L, container->getContentDescription(Lua::getBoolean(L, 2, false))); } else { lua_pushnil(L); } @@ -249,13 +271,13 @@ int ContainerFunctions::luaContainerGetContentDescription(lua_State* L) { int ContainerFunctions::luaContainerGetItems(lua_State* L) { // container:getItems([recursive = false]) - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; } - const bool recursive = getBoolean(L, 2, false); + const bool recursive = Lua::getBoolean(L, 2, false); const std::vector> items = container->getItems(recursive); lua_createtable(L, static_cast(items.size()), 0); @@ -263,8 +285,8 @@ int ContainerFunctions::luaContainerGetItems(lua_State* L) { int index = 0; for (const auto &item : items) { index++; - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); lua_rawseti(L, -2, index); } return 1; @@ -272,7 +294,7 @@ int ContainerFunctions::luaContainerGetItems(lua_State* L) { int ContainerFunctions::luaContainerRegisterReward(lua_State* L) { // container:registerReward() - const auto &container = getUserdataShared(L, 1); + const auto &container = Lua::getUserdataShared(L, 1); if (!container) { lua_pushnil(L); return 1; @@ -285,6 +307,6 @@ int ContainerFunctions::luaContainerRegisterReward(lua_State* L) { container->internalAddThing(rewardContainer); container->setRewardCorpse(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } diff --git a/src/lua/functions/items/container_functions.hpp b/src/lua/functions/items/container_functions.hpp index 52bb33e6b52..8510a717b48 100644 --- a/src/lua/functions/items/container_functions.hpp +++ b/src/lua/functions/items/container_functions.hpp @@ -9,36 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ContainerFunctions final : LuaScriptInterface { +class ContainerFunctions { private: - explicit ContainerFunctions(lua_State* L) : - LuaScriptInterface("ContainerFunctions") { - init(L); - } - ~ContainerFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Container", "Item", ContainerFunctions::luaContainerCreate); - registerMetaMethod(L, "Container", "__eq", ContainerFunctions::luaUserdataCompare); - - registerMethod(L, "Container", "getSize", ContainerFunctions::luaContainerGetSize); - registerMethod(L, "Container", "getMaxCapacity", ContainerFunctions::luaContainerGetMaxCapacity); - registerMethod(L, "Container", "getCapacity", ContainerFunctions::luaContainerGetCapacity); - registerMethod(L, "Container", "getEmptySlots", ContainerFunctions::luaContainerGetEmptySlots); - registerMethod(L, "Container", "getContentDescription", ContainerFunctions::luaContainerGetContentDescription); - registerMethod(L, "Container", "getItems", ContainerFunctions::luaContainerGetItems); - registerMethod(L, "Container", "getItemHoldingCount", ContainerFunctions::luaContainerGetItemHoldingCount); - registerMethod(L, "Container", "getItemCountById", ContainerFunctions::luaContainerGetItemCountById); - - registerMethod(L, "Container", "getItem", ContainerFunctions::luaContainerGetItem); - registerMethod(L, "Container", "hasItem", ContainerFunctions::luaContainerHasItem); - registerMethod(L, "Container", "addItem", ContainerFunctions::luaContainerAddItem); - registerMethod(L, "Container", "addItemEx", ContainerFunctions::luaContainerAddItemEx); - registerMethod(L, "Container", "getCorpseOwner", ContainerFunctions::luaContainerGetCorpseOwner); - registerMethod(L, "Container", "registerReward", ContainerFunctions::luaContainerRegisterReward); - } + static void init(lua_State* L); static int luaContainerCreate(lua_State* L); diff --git a/src/lua/functions/items/imbuement_functions.cpp b/src/lua/functions/items/imbuement_functions.cpp index cf01295ed96..b28cc771a78 100644 --- a/src/lua/functions/items/imbuement_functions.cpp +++ b/src/lua/functions/items/imbuement_functions.cpp @@ -11,15 +11,30 @@ #include "items/weapons/weapons.hpp" #include "creatures/players/imbuements/imbuements.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ImbuementFunctions::init(lua_State* L) { + Lua::registerClass(L, "Imbuement", "", ImbuementFunctions::luaCreateImbuement); + Lua::registerMetaMethod(L, "Imbuement", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Imbuement", "getName", ImbuementFunctions::luaImbuementGetName); + Lua::registerMethod(L, "Imbuement", "getId", ImbuementFunctions::luaImbuementGetId); + Lua::registerMethod(L, "Imbuement", "getItems", ImbuementFunctions::luaImbuementGetItems); + Lua::registerMethod(L, "Imbuement", "getBase", ImbuementFunctions::luaImbuementGetBase); + Lua::registerMethod(L, "Imbuement", "getCategory", ImbuementFunctions::luaImbuementGetCategory); + Lua::registerMethod(L, "Imbuement", "isPremium", ImbuementFunctions::luaImbuementIsPremium); + Lua::registerMethod(L, "Imbuement", "getElementDamage", ImbuementFunctions::luaImbuementGetElementDamage); + Lua::registerMethod(L, "Imbuement", "getCombatType", ImbuementFunctions::luaImbuementGetCombatType); +} int ImbuementFunctions::luaCreateImbuement(lua_State* L) { // Imbuement(id) - const uint16_t imbuementId = getNumber(L, 2); + const uint16_t imbuementId = Lua::getNumber(L, 2); Imbuement* imbuement = g_imbuements().getImbuement(imbuementId); if (imbuement) { - pushUserdata(L, imbuement); - setMetatable(L, -1, "Imbuement"); + Lua::pushUserdata(L, imbuement); + Lua::setMetatable(L, -1, "Imbuement"); } else { lua_pushnil(L); } @@ -28,9 +43,9 @@ int ImbuementFunctions::luaCreateImbuement(lua_State* L) { int ImbuementFunctions::luaImbuementGetName(lua_State* L) { // imbuement:getName() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (imbuement) { - pushString(L, imbuement->getName()); + Lua::pushString(L, imbuement->getName()); } else { lua_pushnil(L); } @@ -39,7 +54,7 @@ int ImbuementFunctions::luaImbuementGetName(lua_State* L) { int ImbuementFunctions::luaImbuementGetId(lua_State* L) { // imbuement:getId() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (imbuement) { lua_pushnumber(L, imbuement->getID()); } else { @@ -50,7 +65,7 @@ int ImbuementFunctions::luaImbuementGetId(lua_State* L) { int ImbuementFunctions::luaImbuementGetItems(lua_State* L) { // imbuement:getItems() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (!imbuement) { lua_pushnil(L); return 1; @@ -61,8 +76,8 @@ int ImbuementFunctions::luaImbuementGetItems(lua_State* L) { lua_createtable(L, items.size(), 0); for (const auto &itm : items) { lua_createtable(L, 0, 2); - setField(L, "itemid", itm.first); - setField(L, "count", itm.second); + Lua::setField(L, "itemid", itm.first); + Lua::setField(L, "count", itm.second); lua_rawseti(L, -2, itm.first); } @@ -71,7 +86,7 @@ int ImbuementFunctions::luaImbuementGetItems(lua_State* L) { int ImbuementFunctions::luaImbuementGetBase(lua_State* L) { // imbuement:getBase() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (!imbuement) { lua_pushnil(L); return 1; @@ -84,19 +99,19 @@ int ImbuementFunctions::luaImbuementGetBase(lua_State* L) { } lua_createtable(L, 0, 7); - setField(L, "id", baseImbuement->id); - setField(L, "name", baseImbuement->name); - setField(L, "price", baseImbuement->price); - setField(L, "protection", baseImbuement->protectionPrice); - setField(L, "percent", baseImbuement->percent); - setField(L, "removeCost", baseImbuement->removeCost); - setField(L, "duration", baseImbuement->duration); + Lua::setField(L, "id", baseImbuement->id); + Lua::setField(L, "name", baseImbuement->name); + Lua::setField(L, "price", baseImbuement->price); + Lua::setField(L, "protection", baseImbuement->protectionPrice); + Lua::setField(L, "percent", baseImbuement->percent); + Lua::setField(L, "removeCost", baseImbuement->removeCost); + Lua::setField(L, "duration", baseImbuement->duration); return 1; } int ImbuementFunctions::luaImbuementGetCategory(lua_State* L) { // imbuement:getCategory() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (!imbuement) { lua_pushnil(L); return 1; @@ -106,8 +121,8 @@ int ImbuementFunctions::luaImbuementGetCategory(lua_State* L) { if (categoryImbuement) { lua_createtable(L, 0, 2); - setField(L, "id", categoryImbuement->id); - setField(L, "name", categoryImbuement->name); + Lua::setField(L, "id", categoryImbuement->id); + Lua::setField(L, "name", categoryImbuement->name); } else { lua_pushnil(L); } @@ -117,19 +132,19 @@ int ImbuementFunctions::luaImbuementGetCategory(lua_State* L) { int ImbuementFunctions::luaImbuementIsPremium(lua_State* L) { // imbuement:isPremium() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (!imbuement) { lua_pushnil(L); return 1; } - pushBoolean(L, imbuement->isPremium()); + Lua::pushBoolean(L, imbuement->isPremium()); return 1; } int ImbuementFunctions::luaImbuementGetElementDamage(lua_State* L) { // imbuement:getElementDamage() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (imbuement) { lua_pushnumber(L, imbuement->elementDamage); } else { @@ -140,7 +155,7 @@ int ImbuementFunctions::luaImbuementGetElementDamage(lua_State* L) { int ImbuementFunctions::luaImbuementGetCombatType(lua_State* L) { // imbuement:getCombatType() - const auto* imbuement = getUserdata(L, 1); + const auto* imbuement = Lua::getUserdata(L, 1); if (imbuement) { lua_pushnumber(L, imbuement->combatType); } else { diff --git a/src/lua/functions/items/imbuement_functions.hpp b/src/lua/functions/items/imbuement_functions.hpp index f86882b1cd2..7631cbb1b2f 100644 --- a/src/lua/functions/items/imbuement_functions.hpp +++ b/src/lua/functions/items/imbuement_functions.hpp @@ -9,29 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ImbuementFunctions final : LuaScriptInterface { +class ImbuementFunctions { public: - explicit ImbuementFunctions(lua_State* L) : - LuaScriptInterface("ImbuementFunctions") { - init(L); - } - ~ImbuementFunctions() override = default; - - static void init(lua_State* L) { - registerClass(L, "Imbuement", "", ImbuementFunctions::luaCreateImbuement); - registerMetaMethod(L, "Imbuement", "__eq", ImbuementFunctions::luaUserdataCompare); - - registerMethod(L, "Imbuement", "getName", ImbuementFunctions::luaImbuementGetName); - registerMethod(L, "Imbuement", "getId", ImbuementFunctions::luaImbuementGetId); - registerMethod(L, "Imbuement", "getItems", ImbuementFunctions::luaImbuementGetItems); - registerMethod(L, "Imbuement", "getBase", ImbuementFunctions::luaImbuementGetBase); - registerMethod(L, "Imbuement", "getCategory", ImbuementFunctions::luaImbuementGetCategory); - registerMethod(L, "Imbuement", "isPremium", ImbuementFunctions::luaImbuementIsPremium); - registerMethod(L, "Imbuement", "getElementDamage", ImbuementFunctions::luaImbuementGetElementDamage); - registerMethod(L, "Imbuement", "getCombatType", ImbuementFunctions::luaImbuementGetCombatType); - } + static void init(lua_State* L); private: static int luaCreateImbuement(lua_State* L); diff --git a/src/lua/functions/items/item_classification_functions.cpp b/src/lua/functions/items/item_classification_functions.cpp index 0b68458f2a3..5d1ccea8aff 100644 --- a/src/lua/functions/items/item_classification_functions.cpp +++ b/src/lua/functions/items/item_classification_functions.cpp @@ -11,15 +11,23 @@ #include "game/game.hpp" #include "items/items_classification.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ItemClassificationFunctions::init(lua_State* L) { + Lua::registerClass(L, "ItemClassification", "", ItemClassificationFunctions::luaItemClassificationCreate); + Lua::registerMetaMethod(L, "ItemClassification", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "ItemClassification", "addTier", ItemClassificationFunctions::luaItemClassificationAddTier); +} int ItemClassificationFunctions::luaItemClassificationCreate(lua_State* L) { // ItemClassification(id) - if (isNumber(L, 2)) { - const ItemClassification* itemClassification = g_game().getItemsClassification(getNumber(L, 2), false); + if (Lua::isNumber(L, 2)) { + const ItemClassification* itemClassification = g_game().getItemsClassification(Lua::getNumber(L, 2), false); if (itemClassification) { - pushUserdata(L, itemClassification); - setMetatable(L, -1, "ItemClassification"); - pushBoolean(L, true); + Lua::pushUserdata(L, itemClassification); + Lua::setMetatable(L, -1, "ItemClassification"); + Lua::pushBoolean(L, true); } } @@ -29,16 +37,16 @@ int ItemClassificationFunctions::luaItemClassificationCreate(lua_State* L) { int ItemClassificationFunctions::luaItemClassificationAddTier(lua_State* L) { // itemClassification:addTier(id, core, regularPrice, convergenceFusionPrice, convergenceTransferPrice) - auto* itemClassification = getUserdata(L, 1); + auto* itemClassification = Lua::getUserdata(L, 1); if (itemClassification) { itemClassification->addTier( - getNumber(L, 2), - getNumber(L, 3), - getNumber(L, 4), - getNumber(L, 5), - getNumber(L, 6) + Lua::getNumber(L, 2), + Lua::getNumber(L, 3), + Lua::getNumber(L, 4), + Lua::getNumber(L, 5), + Lua::getNumber(L, 6) ); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/items/item_classification_functions.hpp b/src/lua/functions/items/item_classification_functions.hpp index 29b04268282..413e549a601 100644 --- a/src/lua/functions/items/item_classification_functions.hpp +++ b/src/lua/functions/items/item_classification_functions.hpp @@ -9,22 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class ItemClassificationFunctions final : LuaScriptInterface { +class ItemClassificationFunctions { public: - explicit ItemClassificationFunctions(lua_State* L) : - LuaScriptInterface("ItemClassificationFunctions") { - init(L); - } - ~ItemClassificationFunctions() override = default; - - static void init(lua_State* L) { - registerClass(L, "ItemClassification", "", ItemClassificationFunctions::luaItemClassificationCreate); - registerMetaMethod(L, "ItemClassification", "__eq", ItemClassificationFunctions::luaUserdataCompare); - - registerMethod(L, "ItemClassification", "addTier", ItemClassificationFunctions::luaItemClassificationAddTier); - } + static void init(lua_State* L); private: static int luaItemClassificationCreate(lua_State* L); diff --git a/src/lua/functions/items/item_functions.cpp b/src/lua/functions/items/item_functions.cpp index c54d43bc94b..11d719f44f7 100644 --- a/src/lua/functions/items/item_functions.cpp +++ b/src/lua/functions/items/item_functions.cpp @@ -16,16 +16,97 @@ #include "items/decay/decay.hpp" #include "items/item.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ItemFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Item", "", ItemFunctions::luaItemCreate); + Lua::registerMetaMethod(L, "Item", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Item", "isItem", ItemFunctions::luaItemIsItem); + + Lua::registerMethod(L, "Item", "getContainer", ItemFunctions::luaItemGetContainer); + Lua::registerMethod(L, "Item", "getParent", ItemFunctions::luaItemGetParent); + Lua::registerMethod(L, "Item", "getTopParent", ItemFunctions::luaItemGetTopParent); + + Lua::registerMethod(L, "Item", "getId", ItemFunctions::luaItemGetId); + + Lua::registerMethod(L, "Item", "clone", ItemFunctions::luaItemClone); + Lua::registerMethod(L, "Item", "split", ItemFunctions::luaItemSplit); + Lua::registerMethod(L, "Item", "remove", ItemFunctions::luaItemRemove); + + Lua::registerMethod(L, "Item", "getUniqueId", ItemFunctions::luaItemGetUniqueId); + Lua::registerMethod(L, "Item", "getActionId", ItemFunctions::luaItemGetActionId); + Lua::registerMethod(L, "Item", "setActionId", ItemFunctions::luaItemSetActionId); + + Lua::registerMethod(L, "Item", "getCount", ItemFunctions::luaItemGetCount); + Lua::registerMethod(L, "Item", "getCharges", ItemFunctions::luaItemGetCharges); + Lua::registerMethod(L, "Item", "getFluidType", ItemFunctions::luaItemGetFluidType); + Lua::registerMethod(L, "Item", "getWeight", ItemFunctions::luaItemGetWeight); + + Lua::registerMethod(L, "Item", "getSubType", ItemFunctions::luaItemGetSubType); + + Lua::registerMethod(L, "Item", "getName", ItemFunctions::luaItemGetName); + Lua::registerMethod(L, "Item", "getPluralName", ItemFunctions::luaItemGetPluralName); + Lua::registerMethod(L, "Item", "getArticle", ItemFunctions::luaItemGetArticle); + + Lua::registerMethod(L, "Item", "getPosition", ItemFunctions::luaItemGetPosition); + Lua::registerMethod(L, "Item", "getTile", ItemFunctions::luaItemGetTile); + + Lua::registerMethod(L, "Item", "hasAttribute", ItemFunctions::luaItemHasAttribute); + Lua::registerMethod(L, "Item", "getAttribute", ItemFunctions::luaItemGetAttribute); + Lua::registerMethod(L, "Item", "setAttribute", ItemFunctions::luaItemSetAttribute); + Lua::registerMethod(L, "Item", "removeAttribute", ItemFunctions::luaItemRemoveAttribute); + Lua::registerMethod(L, "Item", "getCustomAttribute", ItemFunctions::luaItemGetCustomAttribute); + Lua::registerMethod(L, "Item", "setCustomAttribute", ItemFunctions::luaItemSetCustomAttribute); + Lua::registerMethod(L, "Item", "removeCustomAttribute", ItemFunctions::luaItemRemoveCustomAttribute); + Lua::registerMethod(L, "Item", "canBeMoved", ItemFunctions::luaItemCanBeMoved); + + Lua::registerMethod(L, "Item", "setOwner", ItemFunctions::luaItemSetOwner); + Lua::registerMethod(L, "Item", "getOwnerId", ItemFunctions::luaItemGetOwnerId); + Lua::registerMethod(L, "Item", "isOwner", ItemFunctions::luaItemIsOwner); + Lua::registerMethod(L, "Item", "getOwnerName", ItemFunctions::luaItemGetOwnerName); + Lua::registerMethod(L, "Item", "hasOwner", ItemFunctions::luaItemHasOwner); + + Lua::registerMethod(L, "Item", "moveTo", ItemFunctions::luaItemMoveTo); + Lua::registerMethod(L, "Item", "transform", ItemFunctions::luaItemTransform); + Lua::registerMethod(L, "Item", "decay", ItemFunctions::luaItemDecay); + + Lua::registerMethod(L, "Item", "serializeAttributes", ItemFunctions::luaItemSerializeAttributes); + Lua::registerMethod(L, "Item", "moveToSlot", ItemFunctions::luaItemMoveToSlot); + + Lua::registerMethod(L, "Item", "getDescription", ItemFunctions::luaItemGetDescription); + + Lua::registerMethod(L, "Item", "hasProperty", ItemFunctions::luaItemHasProperty); + + Lua::registerMethod(L, "Item", "getImbuementSlot", ItemFunctions::luaItemGetImbuementSlot); + Lua::registerMethod(L, "Item", "getImbuement", ItemFunctions::luaItemGetImbuement); + + Lua::registerMethod(L, "Item", "setDuration", ItemFunctions::luaItemSetDuration); + + Lua::registerMethod(L, "Item", "isInsideDepot", ItemFunctions::luaItemIsInsideDepot); + Lua::registerMethod(L, "Item", "isContainer", ItemFunctions::luaItemIsContainer); + + Lua::registerMethod(L, "Item", "getTier", ItemFunctions::luaItemGetTier); + Lua::registerMethod(L, "Item", "setTier", ItemFunctions::luaItemSetTier); + Lua::registerMethod(L, "Item", "getClassification", ItemFunctions::luaItemGetClassification); + + Lua::registerMethod(L, "Item", "canReceiveAutoCarpet", ItemFunctions::luaItemCanReceiveAutoCarpet); + + ContainerFunctions::init(L); + ImbuementFunctions::init(L); + ItemTypeFunctions::init(L); + WeaponFunctions::init(L); +} // Item int ItemFunctions::luaItemCreate(lua_State* L) { // Item(uid) - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); - const auto &item = getScriptEnv()->getItemByUID(id); + const auto &item = Lua::getScriptEnv()->getItemByUID(id); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -34,13 +115,13 @@ int ItemFunctions::luaItemCreate(lua_State* L) { int ItemFunctions::luaItemIsItem(lua_State* L) { // item:isItem() - pushBoolean(L, getUserdataShared(L, 1) != nullptr); + Lua::pushBoolean(L, Lua::getUserdataShared(L, 1) != nullptr); return 1; } int ItemFunctions::luaItemGetContainer(lua_State* L) { // item:getContainer() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -49,17 +130,17 @@ int ItemFunctions::luaItemGetContainer(lua_State* L) { const auto &container = item->getContainer(); if (!container) { g_logger().trace("Item {} is not a container", item->getName()); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - pushUserdata(L, container); + Lua::pushUserdata(L, container); return 1; } int ItemFunctions::luaItemGetParent(lua_State* L) { // item:getParent() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -71,13 +152,13 @@ int ItemFunctions::luaItemGetParent(lua_State* L) { return 1; } - pushCylinder(L, parent); + Lua::pushCylinder(L, parent); return 1; } int ItemFunctions::luaItemGetTopParent(lua_State* L) { // item:getTopParent() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -89,13 +170,13 @@ int ItemFunctions::luaItemGetTopParent(lua_State* L) { return 1; } - pushCylinder(L, topParent); + Lua::pushCylinder(L, topParent); return 1; } int ItemFunctions::luaItemGetId(lua_State* L) { // item:getId() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getID()); } else { @@ -106,7 +187,7 @@ int ItemFunctions::luaItemGetId(lua_State* L) { int ItemFunctions::luaItemClone(lua_State* L) { // item:clone() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -118,17 +199,17 @@ int ItemFunctions::luaItemClone(lua_State* L) { return 1; } - getScriptEnv()->addTempItem(clone); + Lua::getScriptEnv()->addTempItem(clone); clone->setParent(VirtualCylinder::virtualCylinder); - pushUserdata(L, clone); - setItemMetatable(L, -1, clone); + Lua::pushUserdata(L, clone); + Lua::setItemMetatable(L, -1, clone); return 1; } int ItemFunctions::luaItemSplit(lua_State* L) { // item:split([count = 1]) - const auto &itemPtr = getRawUserDataShared(L, 1); + const auto &itemPtr = Lua::getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; @@ -140,7 +221,7 @@ int ItemFunctions::luaItemSplit(lua_State* L) { return 1; } - const uint16_t count = std::min(getNumber(L, 2, 1), item->getItemCount()); + const uint16_t count = std::min(Lua::getNumber(L, 2, 1), item->getItemCount()); const uint16_t diff = item->getItemCount() - count; const auto &splitItem = item->clone(); @@ -151,7 +232,7 @@ int ItemFunctions::luaItemSplit(lua_State* L) { splitItem->setItemCount(count); - ScriptEnvironment* env = getScriptEnv(); + ScriptEnvironment* env = Lua::getScriptEnv(); const uint32_t uid = env->addThing(item); const auto &newItem = g_game().transformItem(item, item->getID(), diff); @@ -168,17 +249,17 @@ int ItemFunctions::luaItemSplit(lua_State* L) { splitItem->setParent(VirtualCylinder::virtualCylinder); env->addTempItem(splitItem); - pushUserdata(L, splitItem); - setItemMetatable(L, -1, splitItem); + Lua::pushUserdata(L, splitItem); + Lua::setItemMetatable(L, -1, splitItem); return 1; } int ItemFunctions::luaItemRemove(lua_State* L) { // item:remove([count = -1]) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - const auto count = getNumber(L, 2, -1); - pushBoolean(L, g_game().internalRemoveItem(item, count) == RETURNVALUE_NOERROR); + const auto count = Lua::getNumber(L, 2, -1); + Lua::pushBoolean(L, g_game().internalRemoveItem(item, count) == RETURNVALUE_NOERROR); } else { lua_pushnil(L); } @@ -187,11 +268,11 @@ int ItemFunctions::luaItemRemove(lua_State* L) { int ItemFunctions::luaItemGetUniqueId(lua_State* L) { // item:getUniqueId() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { uint32_t uniqueId = item->getAttribute(ItemAttribute_t::UNIQUEID); if (uniqueId == 0) { - uniqueId = getScriptEnv()->addThing(item); + uniqueId = Lua::getScriptEnv()->addThing(item); } lua_pushnumber(L, static_cast(uniqueId)); } else { @@ -202,7 +283,7 @@ int ItemFunctions::luaItemGetUniqueId(lua_State* L) { int ItemFunctions::luaItemGetActionId(lua_State* L) { // item:getActionId() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { const auto actionId = item->getAttribute(ItemAttribute_t::ACTIONID); lua_pushnumber(L, actionId); @@ -214,11 +295,11 @@ int ItemFunctions::luaItemGetActionId(lua_State* L) { int ItemFunctions::luaItemSetActionId(lua_State* L) { // item:setActionId(actionId) - const uint16_t actionId = getNumber(L, 2); - const auto &item = getUserdataShared(L, 1); + const uint16_t actionId = Lua::getNumber(L, 2); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { item->setAttribute(ItemAttribute_t::ACTIONID, actionId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -227,7 +308,7 @@ int ItemFunctions::luaItemSetActionId(lua_State* L) { int ItemFunctions::luaItemGetCount(lua_State* L) { // item:getCount() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getItemCount()); } else { @@ -238,7 +319,7 @@ int ItemFunctions::luaItemGetCount(lua_State* L) { int ItemFunctions::luaItemGetCharges(lua_State* L) { // item:getCharges() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getCharges()); } else { @@ -249,7 +330,7 @@ int ItemFunctions::luaItemGetCharges(lua_State* L) { int ItemFunctions::luaItemGetFluidType(lua_State* L) { // item:getFluidType() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, static_cast(item->getAttribute(ItemAttribute_t::FLUIDTYPE))); } else { @@ -260,7 +341,7 @@ int ItemFunctions::luaItemGetFluidType(lua_State* L) { int ItemFunctions::luaItemGetWeight(lua_State* L) { // item:getWeight() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getWeight()); } else { @@ -271,7 +352,7 @@ int ItemFunctions::luaItemGetWeight(lua_State* L) { int ItemFunctions::luaItemGetSubType(lua_State* L) { // item:getSubType() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { lua_pushnumber(L, item->getSubType()); } else { @@ -282,9 +363,9 @@ int ItemFunctions::luaItemGetSubType(lua_State* L) { int ItemFunctions::luaItemGetName(lua_State* L) { // item:getName() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - pushString(L, item->getName()); + Lua::pushString(L, item->getName()); } else { lua_pushnil(L); } @@ -293,9 +374,9 @@ int ItemFunctions::luaItemGetName(lua_State* L) { int ItemFunctions::luaItemGetPluralName(lua_State* L) { // item:getPluralName() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - pushString(L, item->getPluralName()); + Lua::pushString(L, item->getPluralName()); } else { lua_pushnil(L); } @@ -304,9 +385,9 @@ int ItemFunctions::luaItemGetPluralName(lua_State* L) { int ItemFunctions::luaItemGetArticle(lua_State* L) { // item:getArticle() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - pushString(L, item->getArticle()); + Lua::pushString(L, item->getArticle()); } else { lua_pushnil(L); } @@ -314,10 +395,10 @@ int ItemFunctions::luaItemGetArticle(lua_State* L) { } int ItemFunctions::luaItemGetPosition(lua_State* L) { - // item:getPosition() - const auto &item = getUserdataShared(L, 1); + // item:Lua::getPosition() + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - pushPosition(L, item->getPosition()); + Lua::pushPosition(L, item->getPosition()); } else { lua_pushnil(L); } @@ -326,7 +407,7 @@ int ItemFunctions::luaItemGetPosition(lua_State* L) { int ItemFunctions::luaItemGetTile(lua_State* L) { // item:getTile() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -334,8 +415,8 @@ int ItemFunctions::luaItemGetTile(lua_State* L) { const auto &tile = item->getTile(); if (tile) { - pushUserdata(L, tile); - setMetatable(L, -1, "Tile"); + Lua::pushUserdata(L, tile); + Lua::setMetatable(L, -1, "Tile"); } else { lua_pushnil(L); } @@ -344,38 +425,38 @@ int ItemFunctions::luaItemGetTile(lua_State* L) { int ItemFunctions::luaItemHasAttribute(lua_State* L) { // item:hasAttribute(key) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } ItemAttribute_t attribute; - if (isNumber(L, 2)) { - attribute = getNumber(L, 2); - } else if (isString(L, 2)) { - attribute = stringToItemAttribute(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + attribute = Lua::getNumber(L, 2); + } else if (Lua::isString(L, 2)) { + attribute = stringToItemAttribute(Lua::getString(L, 2)); } else { attribute = ItemAttribute_t::NONE; } - pushBoolean(L, item->hasAttribute(attribute)); + Lua::pushBoolean(L, item->hasAttribute(attribute)); return 1; } int ItemFunctions::luaItemGetAttribute(lua_State* L) { // item:getAttribute(key) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } ItemAttribute_t attribute; - if (isNumber(L, 2)) { - attribute = getNumber(L, 2); - } else if (isString(L, 2)) { - attribute = stringToItemAttribute(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + attribute = Lua::getNumber(L, 2); + } else if (Lua::isString(L, 2)) { + attribute = stringToItemAttribute(Lua::getString(L, 2)); } else { attribute = ItemAttribute_t::NONE; } @@ -388,7 +469,7 @@ int ItemFunctions::luaItemGetAttribute(lua_State* L) { lua_pushnumber(L, static_cast(item->getAttribute(attribute))); } else if (item->isAttributeString(attribute)) { - pushString(L, item->getAttribute(attribute)); + Lua::pushString(L, item->getAttribute(attribute)); } else { lua_pushnil(L); } @@ -397,17 +478,17 @@ int ItemFunctions::luaItemGetAttribute(lua_State* L) { int ItemFunctions::luaItemSetAttribute(lua_State* L) { // item:setAttribute(key, value) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } ItemAttribute_t attribute; - if (isNumber(L, 2)) { - attribute = getNumber(L, 2); - } else if (isString(L, 2)) { - attribute = stringToItemAttribute(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + attribute = Lua::getNumber(L, 2); + } else if (Lua::isString(L, 2)) { + attribute = stringToItemAttribute(Lua::getString(L, 2)); } else { attribute = ItemAttribute_t::NONE; } @@ -415,39 +496,39 @@ int ItemFunctions::luaItemSetAttribute(lua_State* L) { if (item->isAttributeInteger(attribute)) { switch (attribute) { case ItemAttribute_t::DECAYSTATE: { - if (const auto decayState = getNumber(L, 3); + if (const auto decayState = Lua::getNumber(L, 3); decayState == DECAYING_FALSE || decayState == DECAYING_STOPPING) { g_decay().stopDecay(item); } else { g_decay().startDecay(item); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } case ItemAttribute_t::DURATION: { item->setDecaying(DECAYING_PENDING); - item->setDuration(getNumber(L, 3)); + item->setDuration(Lua::getNumber(L, 3)); g_decay().startDecay(item); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } case ItemAttribute_t::DURATION_TIMESTAMP: { - reportErrorFunc("Attempt to set protected key \"duration timestamp\""); - pushBoolean(L, false); + Lua::reportErrorFunc("Attempt to set protected key \"duration timestamp\""); + Lua::pushBoolean(L, false); return 1; } default: break; } - item->setAttribute(attribute, getNumber(L, 3)); + item->setAttribute(attribute, Lua::getNumber(L, 3)); item->updateTileFlags(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else if (item->isAttributeString(attribute)) { - const auto newAttributeString = getString(L, 3); + const auto newAttributeString = Lua::getString(L, 3); item->setAttribute(attribute, newAttributeString); item->updateTileFlags(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -456,17 +537,17 @@ int ItemFunctions::luaItemSetAttribute(lua_State* L) { int ItemFunctions::luaItemRemoveAttribute(lua_State* L) { // item:removeAttribute(key) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } ItemAttribute_t attribute; - if (isNumber(L, 2)) { - attribute = getNumber(L, 2); - } else if (isString(L, 2)) { - attribute = stringToItemAttribute(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + attribute = Lua::getNumber(L, 2); + } else if (Lua::isString(L, 2)) { + attribute = stringToItemAttribute(Lua::getString(L, 2)); } else { attribute = ItemAttribute_t::NONE; } @@ -477,28 +558,28 @@ int ItemFunctions::luaItemRemoveAttribute(lua_State* L) { if (ret) { item->removeAttribute(attribute); } else { - reportErrorFunc("Attempt to erase protected key \"duration timestamp\""); + Lua::reportErrorFunc("Attempt to erase protected key \"duration timestamp\""); } } else { - reportErrorFunc("Attempt to erase protected key \"uid\""); + Lua::reportErrorFunc("Attempt to erase protected key \"uid\""); } - pushBoolean(L, ret); + Lua::pushBoolean(L, ret); return 1; } int ItemFunctions::luaItemGetCustomAttribute(lua_State* L) { // item:getCustomAttribute(key) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } const CustomAttribute* customAttribute; - if (isNumber(L, 2)) { - customAttribute = item->getCustomAttribute(std::to_string(getNumber(L, 2))); - } else if (isString(L, 2)) { - customAttribute = item->getCustomAttribute(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + customAttribute = item->getCustomAttribute(std::to_string(Lua::getNumber(L, 2))); + } else if (Lua::isString(L, 2)) { + customAttribute = item->getCustomAttribute(Lua::getString(L, 2)); } else { lua_pushnil(L); return 1; @@ -514,57 +595,57 @@ int ItemFunctions::luaItemGetCustomAttribute(lua_State* L) { int ItemFunctions::luaItemSetCustomAttribute(lua_State* L) { // item:setCustomAttribute(key, value) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } std::string key; - if (isNumber(L, 2)) { - key = std::to_string(getNumber(L, 2)); - } else if (isString(L, 2)) { - key = getString(L, 2); + if (Lua::isNumber(L, 2)) { + key = std::to_string(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + key = Lua::getString(L, 2); } else { lua_pushnil(L); return 1; } - if (isNumber(L, 3)) { - const double doubleValue = getNumber(L, 3); + if (Lua::isNumber(L, 3)) { + const double doubleValue = Lua::getNumber(L, 3); if (std::floor(doubleValue) < doubleValue) { item->setCustomAttribute(key, doubleValue); } else { - const int64_t int64 = getNumber(L, 3); + const int64_t int64 = Lua::getNumber(L, 3); item->setCustomAttribute(key, int64); } - } else if (isString(L, 3)) { - const std::string stringValue = getString(L, 3); + } else if (Lua::isString(L, 3)) { + const std::string stringValue = Lua::getString(L, 3); item->setCustomAttribute(key, stringValue); - } else if (isBoolean(L, 3)) { - const bool boolValue = getBoolean(L, 3); + } else if (Lua::isBoolean(L, 3)) { + const bool boolValue = Lua::getBoolean(L, 3); item->setCustomAttribute(key, boolValue); } else { lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ItemFunctions::luaItemRemoveCustomAttribute(lua_State* L) { // item:removeCustomAttribute(key) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; } - if (isNumber(L, 2)) { - pushBoolean(L, item->removeCustomAttribute(std::to_string(getNumber(L, 2)))); - } else if (isString(L, 2)) { - pushBoolean(L, item->removeCustomAttribute(getString(L, 2))); + if (Lua::isNumber(L, 2)) { + Lua::pushBoolean(L, item->removeCustomAttribute(std::to_string(Lua::getNumber(L, 2)))); + } else if (Lua::isString(L, 2)) { + Lua::pushBoolean(L, item->removeCustomAttribute(Lua::getString(L, 2))); } else { lua_pushnil(L); } @@ -573,9 +654,9 @@ int ItemFunctions::luaItemRemoveCustomAttribute(lua_State* L) { int ItemFunctions::luaItemCanBeMoved(lua_State* L) { // item:canBeMoved() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - pushBoolean(L, item->canBeMoved()); + Lua::pushBoolean(L, item->canBeMoved()); } else { lua_pushnil(L); } @@ -584,7 +665,7 @@ int ItemFunctions::luaItemCanBeMoved(lua_State* L) { int ItemFunctions::luaItemSerializeAttributes(lua_State* L) { // item:serializeAttributes() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { lua_pushnil(L); return 1; @@ -601,7 +682,7 @@ int ItemFunctions::luaItemSerializeAttributes(lua_State* L) { int ItemFunctions::luaItemMoveTo(lua_State* L) { // item:moveTo(position or cylinder[, flags]) - const auto &itemPtr = getRawUserDataShared(L, 1); + const auto &itemPtr = Lua::getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; @@ -614,24 +695,24 @@ int ItemFunctions::luaItemMoveTo(lua_State* L) { } std::shared_ptr toCylinder; - if (isUserdata(L, 2)) { - const LuaData_t type = getUserdataType(L, 2); + if (Lua::isUserdata(L, 2)) { + const LuaData_t type = Lua::getUserdataType(L, 2); switch (type) { case LuaData_t::Container: - toCylinder = getUserdataShared(L, 2); + toCylinder = Lua::getUserdataShared(L, 2); break; case LuaData_t::Player: - toCylinder = getUserdataShared(L, 2); + toCylinder = Lua::getUserdataShared(L, 2); break; case LuaData_t::Tile: - toCylinder = getUserdataShared(L, 2); + toCylinder = Lua::getUserdataShared(L, 2); break; default: toCylinder = nullptr; break; } } else { - toCylinder = g_game().map.getTile(getPosition(L, 2)); + toCylinder = g_game().map.getTile(Lua::getPosition(L, 2)); } if (!toCylinder) { @@ -640,28 +721,28 @@ int ItemFunctions::luaItemMoveTo(lua_State* L) { } if (item->getParent() == toCylinder) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } - const auto flags = getNumber(L, 3, FLAG_NOLIMIT | FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE | FLAG_IGNORENOTMOVABLE); + const auto flags = Lua::getNumber(L, 3, FLAG_NOLIMIT | FLAG_IGNOREBLOCKITEM | FLAG_IGNOREBLOCKCREATURE | FLAG_IGNORENOTMOVABLE); if (item->getParent() == VirtualCylinder::virtualCylinder) { - pushBoolean(L, g_game().internalAddItem(toCylinder, item, INDEX_WHEREEVER, flags) == RETURNVALUE_NOERROR); + Lua::pushBoolean(L, g_game().internalAddItem(toCylinder, item, INDEX_WHEREEVER, flags) == RETURNVALUE_NOERROR); } else { std::shared_ptr moveItem = nullptr; ReturnValue ret = g_game().internalMoveItem(item->getParent(), toCylinder, INDEX_WHEREEVER, item, item->getItemCount(), &moveItem, flags); if (moveItem) { *itemPtr = moveItem; } - pushBoolean(L, ret == RETURNVALUE_NOERROR); + Lua::pushBoolean(L, ret == RETURNVALUE_NOERROR); } return 1; } int ItemFunctions::luaItemTransform(lua_State* L) { // item:transform(itemId[, count/subType = -1]) - const auto &itemPtr = getRawUserDataShared(L, 1); + const auto &itemPtr = Lua::getRawUserDataShared(L, 1); if (!itemPtr) { lua_pushnil(L); return 1; @@ -674,19 +755,19 @@ int ItemFunctions::luaItemTransform(lua_State* L) { } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - auto subType = getNumber(L, 3, -1); + auto subType = Lua::getNumber(L, 3, -1); if (item->getID() == itemId && (subType == -1 || subType == item->getSubType())) { - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -695,7 +776,7 @@ int ItemFunctions::luaItemTransform(lua_State* L) { subType = std::min(subType, it.stackSize); } - ScriptEnvironment* env = getScriptEnv(); + ScriptEnvironment* env = Lua::getScriptEnv(); const uint32_t uid = env->addThing(item); const auto &newItem = g_game().transformItem(item, itemId, subType); @@ -708,21 +789,21 @@ int ItemFunctions::luaItemTransform(lua_State* L) { } item = newItem; - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ItemFunctions::luaItemDecay(lua_State* L) { // item:decay(decayId) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - if (isNumber(L, 2)) { + if (Lua::isNumber(L, 2)) { ItemType &it = Item::items.getItemType(item->getID()); - it.decayTo = getNumber(L, 2); + it.decayTo = Lua::getNumber(L, 2); } item->startDecaying(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -731,32 +812,32 @@ int ItemFunctions::luaItemDecay(lua_State* L) { int ItemFunctions::luaItemMoveToSlot(lua_State* L) { // item:moveToSlot(player, slot) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item || item->isRemoved()) { lua_pushnil(L); return 1; } - const auto &player = getUserdataShared(L, 2); + const auto &player = Lua::getUserdataShared(L, 2); if (!player) { lua_pushnil(L); return 1; } - const auto slot = getNumber(L, 3, CONST_SLOT_WHEREEVER); + const auto slot = Lua::getNumber(L, 3, CONST_SLOT_WHEREEVER); ReturnValue ret = g_game().internalMoveItem(item->getParent(), player, slot, item, item->getItemCount(), nullptr); - pushBoolean(L, ret == RETURNVALUE_NOERROR); + Lua::pushBoolean(L, ret == RETURNVALUE_NOERROR); return 1; } int ItemFunctions::luaItemGetDescription(lua_State* L) { // item:getDescription(distance) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - const int32_t distance = getNumber(L, 2); - pushString(L, item->getDescription(distance)); + const int32_t distance = Lua::getNumber(L, 2); + Lua::pushString(L, item->getDescription(distance)); } else { lua_pushnil(L); } @@ -765,10 +846,10 @@ int ItemFunctions::luaItemGetDescription(lua_State* L) { int ItemFunctions::luaItemHasProperty(lua_State* L) { // item:hasProperty(property) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (item) { - const ItemProperty property = getNumber(L, 2); - pushBoolean(L, item->hasProperty(property)); + const ItemProperty property = Lua::getNumber(L, 2); + Lua::pushBoolean(L, item->hasProperty(property)); } else { lua_pushnil(L); } @@ -777,10 +858,10 @@ int ItemFunctions::luaItemHasProperty(lua_State* L) { int ItemFunctions::luaItemGetImbuement(lua_State* L) { // item:getImbuement() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -795,23 +876,23 @@ int ItemFunctions::luaItemGetImbuement(lua_State* L) { continue; } - pushUserdata(L, imbuement); - setMetatable(L, -1, "Imbuement"); + Lua::pushUserdata(L, imbuement); + Lua::setMetatable(L, -1, "Imbuement"); lua_createtable(L, 0, 3); - setField(L, "id", imbuement->getID()); - setField(L, "name", imbuement->getName()); - setField(L, "duration", static_cast(imbuementInfo.duration)); + Lua::setField(L, "id", imbuement->getID()); + Lua::setField(L, "name", imbuement->getName()); + Lua::setField(L, "duration", static_cast(imbuementInfo.duration)); } return 1; } int ItemFunctions::luaItemGetImbuementSlot(lua_State* L) { // item:getImbuementSlot() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -822,26 +903,26 @@ int ItemFunctions::luaItemGetImbuementSlot(lua_State* L) { int ItemFunctions::luaItemSetDuration(lua_State* L) { // item:setDuration(minDuration, maxDuration = 0, decayTo = 0, showDuration = true) // Example: item:setDuration(10000, 20000, 2129, false) = random duration from range 10000/20000 - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - const uint32_t minDuration = getNumber(L, 2); + const uint32_t minDuration = Lua::getNumber(L, 2); uint32_t maxDuration = 0; if (lua_gettop(L) > 2) { - maxDuration = uniform_random(minDuration, getNumber(L, 3)); + maxDuration = uniform_random(minDuration, Lua::getNumber(L, 3)); } uint16_t itemid = 0; if (lua_gettop(L) > 3) { - itemid = getNumber(L, 4); + itemid = Lua::getNumber(L, 4); } bool showDuration = true; if (lua_gettop(L) > 4) { - showDuration = getBoolean(L, 5); + showDuration = Lua::getBoolean(L, 5); } ItemType &it = Item::items.getItemType(item->getID()); @@ -853,43 +934,43 @@ int ItemFunctions::luaItemSetDuration(lua_State* L) { it.showDuration = showDuration; it.decayTo = itemid; item->startDecaying(); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int ItemFunctions::luaItemIsInsideDepot(lua_State* L) { // item:isInsideDepot([includeInbox = false]) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, item->isInsideDepot(getBoolean(L, 2, false))); + Lua::pushBoolean(L, item->isInsideDepot(Lua::getBoolean(L, 2, false))); return 1; } int ItemFunctions::luaItemIsContainer(lua_State* L) { // item:isContainer() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } const auto &it = Item::items[item->getID()]; - pushBoolean(L, it.isContainer()); + Lua::pushBoolean(L, it.isContainer()); return 1; } int ItemFunctions::luaItemGetTier(lua_State* L) { // item:getTier() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -899,24 +980,24 @@ int ItemFunctions::luaItemGetTier(lua_State* L) { int ItemFunctions::luaItemSetTier(lua_State* L) { // item:setTier(tier) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - item->setTier(getNumber(L, 2)); - pushBoolean(L, true); + item->setTier(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); return 1; } int ItemFunctions::luaItemGetClassification(lua_State* L) { // item:getClassification() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } @@ -926,52 +1007,52 @@ int ItemFunctions::luaItemGetClassification(lua_State* L) { int ItemFunctions::luaItemCanReceiveAutoCarpet(lua_State* L) { // item:canReceiveAutoCarpet() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); - pushBoolean(L, false); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, item->canReceiveAutoCarpet()); + Lua::pushBoolean(L, item->canReceiveAutoCarpet()); return 1; } int ItemFunctions::luaItemSetOwner(lua_State* L) { // item:setOwner(creature|creatureId) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); return 0; } - if (isUserdata(L, 2)) { - const auto &creature = getUserdataShared(L, 2); + if (Lua::isUserdata(L, 2)) { + const auto &creature = Lua::getUserdataShared(L, 2); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 0; } item->setOwner(creature); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } - const auto creatureId = getNumber(L, 2); + const auto creatureId = Lua::getNumber(L, 2); if (creatureId != 0) { item->setOwner(creatureId); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } int ItemFunctions::luaItemGetOwnerId(lua_State* L) { // item:getOwner() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); return 0; } @@ -986,42 +1067,42 @@ int ItemFunctions::luaItemGetOwnerId(lua_State* L) { int ItemFunctions::luaItemIsOwner(lua_State* L) { // item:isOwner(creature|creatureId) - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); return 0; } - if (isUserdata(L, 2)) { - const auto &creature = getUserdataShared(L, 2); + if (Lua::isUserdata(L, 2)) { + const auto &creature = Lua::getUserdataShared(L, 2); if (!creature) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 0; } - pushBoolean(L, item->isOwner(creature)); + Lua::pushBoolean(L, item->isOwner(creature)); return 1; } - const auto creatureId = getNumber(L, 2); + const auto creatureId = Lua::getNumber(L, 2); if (creatureId != 0) { - pushBoolean(L, item->isOwner(creatureId)); + Lua::pushBoolean(L, item->isOwner(creatureId)); return 1; } - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } int ItemFunctions::luaItemGetOwnerName(lua_State* L) { // item:getOwnerName() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); return 0; } if (const auto ownerName = item->getOwnerName(); !ownerName.empty()) { - pushString(L, ownerName); + Lua::pushString(L, ownerName); return 1; } @@ -1031,12 +1112,12 @@ int ItemFunctions::luaItemGetOwnerName(lua_State* L) { int ItemFunctions::luaItemHasOwner(lua_State* L) { // item:hasOwner() - const auto &item = getUserdataShared(L, 1); + const auto &item = Lua::getUserdataShared(L, 1); if (!item) { - reportErrorFunc(getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_ITEM_NOT_FOUND)); return 1; } - pushBoolean(L, item->hasOwner()); + Lua::pushBoolean(L, item->hasOwner()); return 1; } diff --git a/src/lua/functions/items/item_functions.hpp b/src/lua/functions/items/item_functions.hpp index 1cf3764eac8..44b97c0e113 100644 --- a/src/lua/functions/items/item_functions.hpp +++ b/src/lua/functions/items/item_functions.hpp @@ -13,95 +13,9 @@ #include "lua/functions/items/imbuement_functions.hpp" #include "lua/functions/items/item_type_functions.hpp" #include "lua/functions/items/weapon_functions.hpp" -#include "lua/scripts/luascript.hpp" - -class ItemFunctions final : LuaScriptInterface { +class ItemFunctions { public: - explicit ItemFunctions(lua_State* L) : - LuaScriptInterface("ItemFunctions") { - init(L); - } - ~ItemFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Item", "", ItemFunctions::luaItemCreate); - registerMetaMethod(L, "Item", "__eq", ItemFunctions::luaUserdataCompare); - - registerMethod(L, "Item", "isItem", ItemFunctions::luaItemIsItem); - - registerMethod(L, "Item", "getContainer", ItemFunctions::luaItemGetContainer); - registerMethod(L, "Item", "getParent", ItemFunctions::luaItemGetParent); - registerMethod(L, "Item", "getTopParent", ItemFunctions::luaItemGetTopParent); - - registerMethod(L, "Item", "getId", ItemFunctions::luaItemGetId); - - registerMethod(L, "Item", "clone", ItemFunctions::luaItemClone); - registerMethod(L, "Item", "split", ItemFunctions::luaItemSplit); - registerMethod(L, "Item", "remove", ItemFunctions::luaItemRemove); - - registerMethod(L, "Item", "getUniqueId", ItemFunctions::luaItemGetUniqueId); - registerMethod(L, "Item", "getActionId", ItemFunctions::luaItemGetActionId); - registerMethod(L, "Item", "setActionId", ItemFunctions::luaItemSetActionId); - - registerMethod(L, "Item", "getCount", ItemFunctions::luaItemGetCount); - registerMethod(L, "Item", "getCharges", ItemFunctions::luaItemGetCharges); - registerMethod(L, "Item", "getFluidType", ItemFunctions::luaItemGetFluidType); - registerMethod(L, "Item", "getWeight", ItemFunctions::luaItemGetWeight); - - registerMethod(L, "Item", "getSubType", ItemFunctions::luaItemGetSubType); - - registerMethod(L, "Item", "getName", ItemFunctions::luaItemGetName); - registerMethod(L, "Item", "getPluralName", ItemFunctions::luaItemGetPluralName); - registerMethod(L, "Item", "getArticle", ItemFunctions::luaItemGetArticle); - - registerMethod(L, "Item", "getPosition", ItemFunctions::luaItemGetPosition); - registerMethod(L, "Item", "getTile", ItemFunctions::luaItemGetTile); - - registerMethod(L, "Item", "hasAttribute", ItemFunctions::luaItemHasAttribute); - registerMethod(L, "Item", "getAttribute", ItemFunctions::luaItemGetAttribute); - registerMethod(L, "Item", "setAttribute", ItemFunctions::luaItemSetAttribute); - registerMethod(L, "Item", "removeAttribute", ItemFunctions::luaItemRemoveAttribute); - registerMethod(L, "Item", "getCustomAttribute", ItemFunctions::luaItemGetCustomAttribute); - registerMethod(L, "Item", "setCustomAttribute", ItemFunctions::luaItemSetCustomAttribute); - registerMethod(L, "Item", "removeCustomAttribute", ItemFunctions::luaItemRemoveCustomAttribute); - registerMethod(L, "Item", "canBeMoved", ItemFunctions::luaItemCanBeMoved); - - registerMethod(L, "Item", "setOwner", ItemFunctions::luaItemSetOwner); - registerMethod(L, "Item", "getOwnerId", ItemFunctions::luaItemGetOwnerId); - registerMethod(L, "Item", "isOwner", ItemFunctions::luaItemIsOwner); - registerMethod(L, "Item", "getOwnerName", ItemFunctions::luaItemGetOwnerName); - registerMethod(L, "Item", "hasOwner", ItemFunctions::luaItemHasOwner); - - registerMethod(L, "Item", "moveTo", ItemFunctions::luaItemMoveTo); - registerMethod(L, "Item", "transform", ItemFunctions::luaItemTransform); - registerMethod(L, "Item", "decay", ItemFunctions::luaItemDecay); - - registerMethod(L, "Item", "serializeAttributes", ItemFunctions::luaItemSerializeAttributes); - registerMethod(L, "Item", "moveToSlot", ItemFunctions::luaItemMoveToSlot); - - registerMethod(L, "Item", "getDescription", ItemFunctions::luaItemGetDescription); - - registerMethod(L, "Item", "hasProperty", ItemFunctions::luaItemHasProperty); - - registerMethod(L, "Item", "getImbuementSlot", ItemFunctions::luaItemGetImbuementSlot); - registerMethod(L, "Item", "getImbuement", ItemFunctions::luaItemGetImbuement); - - registerMethod(L, "Item", "setDuration", ItemFunctions::luaItemSetDuration); - - registerMethod(L, "Item", "isInsideDepot", ItemFunctions::luaItemIsInsideDepot); - registerMethod(L, "Item", "isContainer", ItemFunctions::luaItemIsContainer); - - registerMethod(L, "Item", "getTier", ItemFunctions::luaItemGetTier); - registerMethod(L, "Item", "setTier", ItemFunctions::luaItemSetTier); - registerMethod(L, "Item", "getClassification", ItemFunctions::luaItemGetClassification); - - registerMethod(L, "Item", "canReceiveAutoCarpet", ItemFunctions::luaItemCanReceiveAutoCarpet); - - ContainerFunctions::init(L); - ImbuementFunctions::init(L); - ItemTypeFunctions::init(L); - WeaponFunctions::init(L); - } + static void init(lua_State* L); private: static int luaItemCreate(lua_State* L); diff --git a/src/lua/functions/items/item_type_functions.cpp b/src/lua/functions/items/item_type_functions.cpp index 57c5cc5b999..1669e6b795e 100644 --- a/src/lua/functions/items/item_type_functions.cpp +++ b/src/lua/functions/items/item_type_functions.cpp @@ -11,27 +11,96 @@ #include "items/item.hpp" #include "items/items.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void ItemTypeFunctions::init(lua_State* L) { + Lua::registerClass(L, "ItemType", "", ItemTypeFunctions::luaItemTypeCreate); + Lua::registerMetaMethod(L, "ItemType", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "ItemType", "isCorpse", ItemTypeFunctions::luaItemTypeIsCorpse); + Lua::registerMethod(L, "ItemType", "isDoor", ItemTypeFunctions::luaItemTypeIsDoor); + Lua::registerMethod(L, "ItemType", "isContainer", ItemTypeFunctions::luaItemTypeIsContainer); + Lua::registerMethod(L, "ItemType", "isFluidContainer", ItemTypeFunctions::luaItemTypeIsFluidContainer); + Lua::registerMethod(L, "ItemType", "isMovable", ItemTypeFunctions::luaItemTypeIsMovable); + Lua::registerMethod(L, "ItemType", "isRune", ItemTypeFunctions::luaItemTypeIsRune); + Lua::registerMethod(L, "ItemType", "isStackable", ItemTypeFunctions::luaItemTypeIsStackable); + Lua::registerMethod(L, "ItemType", "isStowable", ItemTypeFunctions::luaItemTypeIsStowable); + Lua::registerMethod(L, "ItemType", "isReadable", ItemTypeFunctions::luaItemTypeIsReadable); + Lua::registerMethod(L, "ItemType", "isWritable", ItemTypeFunctions::luaItemTypeIsWritable); + Lua::registerMethod(L, "ItemType", "isBlocking", ItemTypeFunctions::luaItemTypeIsBlocking); + Lua::registerMethod(L, "ItemType", "isGroundTile", ItemTypeFunctions::luaItemTypeIsGroundTile); + Lua::registerMethod(L, "ItemType", "isMagicField", ItemTypeFunctions::luaItemTypeIsMagicField); + Lua::registerMethod(L, "ItemType", "isMultiUse", ItemTypeFunctions::luaItemTypeIsMultiUse); + Lua::registerMethod(L, "ItemType", "isPickupable", ItemTypeFunctions::luaItemTypeIsPickupable); + Lua::registerMethod(L, "ItemType", "isKey", ItemTypeFunctions::luaItemTypeIsKey); + Lua::registerMethod(L, "ItemType", "isQuiver", ItemTypeFunctions::luaItemTypeIsQuiver); + + Lua::registerMethod(L, "ItemType", "getType", ItemTypeFunctions::luaItemTypeGetType); + Lua::registerMethod(L, "ItemType", "getId", ItemTypeFunctions::luaItemTypeGetId); + Lua::registerMethod(L, "ItemType", "getName", ItemTypeFunctions::luaItemTypeGetName); + Lua::registerMethod(L, "ItemType", "getPluralName", ItemTypeFunctions::luaItemTypeGetPluralName); + Lua::registerMethod(L, "ItemType", "getArticle", ItemTypeFunctions::luaItemTypeGetArticle); + Lua::registerMethod(L, "ItemType", "getDescription", ItemTypeFunctions::luaItemTypeGetDescription); + Lua::registerMethod(L, "ItemType", "getSlotPosition", ItemTypeFunctions::luaItemTypeGetSlotPosition); + + Lua::registerMethod(L, "ItemType", "getCharges", ItemTypeFunctions::luaItemTypeGetCharges); + Lua::registerMethod(L, "ItemType", "getFluidSource", ItemTypeFunctions::luaItemTypeGetFluidSource); + Lua::registerMethod(L, "ItemType", "getCapacity", ItemTypeFunctions::luaItemTypeGetCapacity); + Lua::registerMethod(L, "ItemType", "getWeight", ItemTypeFunctions::luaItemTypeGetWeight); + Lua::registerMethod(L, "ItemType", "getStackSize", ItemTypeFunctions::luaItemTypeGetStackSize); + + Lua::registerMethod(L, "ItemType", "getHitChance", ItemTypeFunctions::luaItemTypeGetHitChance); + Lua::registerMethod(L, "ItemType", "getShootRange", ItemTypeFunctions::luaItemTypeGetShootRange); + + Lua::registerMethod(L, "ItemType", "getAttack", ItemTypeFunctions::luaItemTypeGetAttack); + Lua::registerMethod(L, "ItemType", "getDefense", ItemTypeFunctions::luaItemTypeGetDefense); + Lua::registerMethod(L, "ItemType", "getExtraDefense", ItemTypeFunctions::luaItemTypeGetExtraDefense); + Lua::registerMethod(L, "ItemType", "getImbuementSlot", ItemTypeFunctions::luaItemTypeGetImbuementSlot); + Lua::registerMethod(L, "ItemType", "getArmor", ItemTypeFunctions::luaItemTypeGetArmor); + Lua::registerMethod(L, "ItemType", "getWeaponType", ItemTypeFunctions::luaItemTypeGetWeaponType); + + Lua::registerMethod(L, "ItemType", "getElementType", ItemTypeFunctions::luaItemTypeGetElementType); + Lua::registerMethod(L, "ItemType", "getElementDamage", ItemTypeFunctions::luaItemTypeGetElementDamage); + + Lua::registerMethod(L, "ItemType", "getTransformEquipId", ItemTypeFunctions::luaItemTypeGetTransformEquipId); + Lua::registerMethod(L, "ItemType", "getTransformDeEquipId", ItemTypeFunctions::luaItemTypeGetTransformDeEquipId); + Lua::registerMethod(L, "ItemType", "getDestroyId", ItemTypeFunctions::luaItemTypeGetDestroyId); + Lua::registerMethod(L, "ItemType", "getDecayId", ItemTypeFunctions::luaItemTypeGetDecayId); + Lua::registerMethod(L, "ItemType", "getRequiredLevel", ItemTypeFunctions::luaItemTypeGetRequiredLevel); + Lua::registerMethod(L, "ItemType", "getAmmoType", ItemTypeFunctions::luaItemTypeGetAmmoType); + + Lua::registerMethod(L, "ItemType", "getDecayTime", ItemTypeFunctions::luaItemTypeGetDecayTime); + Lua::registerMethod(L, "ItemType", "getShowDuration", ItemTypeFunctions::luaItemTypeGetShowDuration); + Lua::registerMethod(L, "ItemType", "getWrapableTo", ItemTypeFunctions::luaItemTypeGetWrapableTo); + Lua::registerMethod(L, "ItemType", "getSpeed", ItemTypeFunctions::luaItemTypeGetSpeed); + Lua::registerMethod(L, "ItemType", "getBaseSpeed", ItemTypeFunctions::luaItemTypeGetBaseSpeed); + Lua::registerMethod(L, "ItemType", "getVocationString", ItemTypeFunctions::luaItemTypeGetVocationString); + + Lua::registerMethod(L, "ItemType", "hasSubType", ItemTypeFunctions::luaItemTypeHasSubType); + + ItemClassificationFunctions::init(L); +} int ItemTypeFunctions::luaItemTypeCreate(lua_State* L) { // ItemType(id or name) uint32_t id; - if (isNumber(L, 2)) { - id = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + id = Lua::getNumber(L, 2); } else { - id = Item::items.getItemIdByName(getString(L, 2)); + id = Item::items.getItemIdByName(Lua::getString(L, 2)); } const ItemType &itemType = Item::items[id]; - pushUserdata(L, &itemType); - setMetatable(L, -1, "ItemType"); + Lua::pushUserdata(L, &itemType); + Lua::setMetatable(L, -1, "ItemType"); return 1; } int ItemTypeFunctions::luaItemTypeIsCorpse(lua_State* L) { // itemType:isCorpse() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isCorpse); + Lua::pushBoolean(L, itemType->isCorpse); } else { lua_pushnil(L); } @@ -40,9 +109,9 @@ int ItemTypeFunctions::luaItemTypeIsCorpse(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsDoor(lua_State* L) { // itemType:isDoor() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isDoor()); + Lua::pushBoolean(L, itemType->isDoor()); } else { lua_pushnil(L); } @@ -51,9 +120,9 @@ int ItemTypeFunctions::luaItemTypeIsDoor(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsContainer(lua_State* L) { // itemType:isContainer() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isContainer()); + Lua::pushBoolean(L, itemType->isContainer()); } else { lua_pushnil(L); } @@ -62,9 +131,9 @@ int ItemTypeFunctions::luaItemTypeIsContainer(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsFluidContainer(lua_State* L) { // itemType:isFluidContainer() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isFluidContainer()); + Lua::pushBoolean(L, itemType->isFluidContainer()); } else { lua_pushnil(L); } @@ -73,9 +142,9 @@ int ItemTypeFunctions::luaItemTypeIsFluidContainer(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsMovable(lua_State* L) { // itemType:isMovable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->movable); + Lua::pushBoolean(L, itemType->movable); } else { lua_pushnil(L); } @@ -84,9 +153,9 @@ int ItemTypeFunctions::luaItemTypeIsMovable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsRune(lua_State* L) { // itemType:isRune() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isRune()); + Lua::pushBoolean(L, itemType->isRune()); } else { lua_pushnil(L); } @@ -95,9 +164,9 @@ int ItemTypeFunctions::luaItemTypeIsRune(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsStackable(lua_State* L) { // itemType:isStackable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->stackable); + Lua::pushBoolean(L, itemType->stackable); } else { lua_pushnil(L); } @@ -106,9 +175,9 @@ int ItemTypeFunctions::luaItemTypeIsStackable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsStowable(lua_State* L) { // itemType:isStowable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->stackable && itemType->wareId > 0); + Lua::pushBoolean(L, itemType->stackable && itemType->wareId > 0); } else { lua_pushnil(L); } @@ -117,9 +186,9 @@ int ItemTypeFunctions::luaItemTypeIsStowable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsReadable(lua_State* L) { // itemType:isReadable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->canReadText); + Lua::pushBoolean(L, itemType->canReadText); } else { lua_pushnil(L); } @@ -128,9 +197,9 @@ int ItemTypeFunctions::luaItemTypeIsReadable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsWritable(lua_State* L) { // itemType:isWritable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->canWriteText); + Lua::pushBoolean(L, itemType->canWriteText); } else { lua_pushnil(L); } @@ -139,9 +208,9 @@ int ItemTypeFunctions::luaItemTypeIsWritable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsBlocking(lua_State* L) { // itemType:isBlocking() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->blockProjectile || itemType->blockSolid); + Lua::pushBoolean(L, itemType->blockProjectile || itemType->blockSolid); } else { lua_pushnil(L); } @@ -150,9 +219,9 @@ int ItemTypeFunctions::luaItemTypeIsBlocking(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsGroundTile(lua_State* L) { // itemType:isGroundTile() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isGroundTile()); + Lua::pushBoolean(L, itemType->isGroundTile()); } else { lua_pushnil(L); } @@ -161,9 +230,9 @@ int ItemTypeFunctions::luaItemTypeIsGroundTile(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsMagicField(lua_State* L) { // itemType:isMagicField() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isMagicField()); + Lua::pushBoolean(L, itemType->isMagicField()); } else { lua_pushnil(L); } @@ -172,9 +241,9 @@ int ItemTypeFunctions::luaItemTypeIsMagicField(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsMultiUse(lua_State* L) { // itemType:isMultiUse() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isMultiUse()); + Lua::pushBoolean(L, itemType->isMultiUse()); } else { lua_pushnil(L); } @@ -183,9 +252,9 @@ int ItemTypeFunctions::luaItemTypeIsMultiUse(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsPickupable(lua_State* L) { // itemType:isPickupable() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isPickupable()); + Lua::pushBoolean(L, itemType->isPickupable()); } else { lua_pushnil(L); } @@ -194,9 +263,9 @@ int ItemTypeFunctions::luaItemTypeIsPickupable(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsKey(lua_State* L) { // itemType:isKey() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isKey()); + Lua::pushBoolean(L, itemType->isKey()); } else { lua_pushnil(L); } @@ -205,9 +274,9 @@ int ItemTypeFunctions::luaItemTypeIsKey(lua_State* L) { int ItemTypeFunctions::luaItemTypeIsQuiver(lua_State* L) { // itemType:isQuiver() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->isQuiver()); + Lua::pushBoolean(L, itemType->isQuiver()); } else { lua_pushnil(L); } @@ -216,7 +285,7 @@ int ItemTypeFunctions::luaItemTypeIsQuiver(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetType(lua_State* L) { // itemType:getType() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->type); } else { @@ -227,7 +296,7 @@ int ItemTypeFunctions::luaItemTypeGetType(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetId(lua_State* L) { // itemType:getId() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->id); } else { @@ -238,9 +307,9 @@ int ItemTypeFunctions::luaItemTypeGetId(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetName(lua_State* L) { // itemType:getName() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushString(L, itemType->name); + Lua::pushString(L, itemType->name); } else { lua_pushnil(L); } @@ -249,9 +318,9 @@ int ItemTypeFunctions::luaItemTypeGetName(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetPluralName(lua_State* L) { // itemType:getPluralName() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushString(L, itemType->getPluralName()); + Lua::pushString(L, itemType->getPluralName()); } else { lua_pushnil(L); } @@ -260,9 +329,9 @@ int ItemTypeFunctions::luaItemTypeGetPluralName(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetArticle(lua_State* L) { // itemType:getArticle() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushString(L, itemType->article); + Lua::pushString(L, itemType->article); } else { lua_pushnil(L); } @@ -271,11 +340,11 @@ int ItemTypeFunctions::luaItemTypeGetArticle(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetDescription(lua_State* L) { // itemType:getDescription([count]) - const auto &itemType = getUserdata(L, 1); + const auto &itemType = Lua::getUserdata(L, 1); if (itemType) { - const auto count = getNumber(L, 2, -1); + const auto count = Lua::getNumber(L, 2, -1); const auto description = Item::getDescription(*itemType, 1, nullptr, count); - pushString(L, description); + Lua::pushString(L, description); } else { lua_pushnil(L); } @@ -284,7 +353,7 @@ int ItemTypeFunctions::luaItemTypeGetDescription(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetSlotPosition(lua_State* L) { // itemType:getSlotPosition() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->slotPosition); } else { @@ -295,7 +364,7 @@ int ItemTypeFunctions::luaItemTypeGetSlotPosition(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetCharges(lua_State* L) { // itemType:getCharges() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->charges); } else { @@ -306,7 +375,7 @@ int ItemTypeFunctions::luaItemTypeGetCharges(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetFluidSource(lua_State* L) { // itemType:getFluidSource() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->fluidSource); } else { @@ -317,7 +386,7 @@ int ItemTypeFunctions::luaItemTypeGetFluidSource(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetCapacity(lua_State* L) { // itemType:getCapacity() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->maxItems); } else { @@ -328,9 +397,9 @@ int ItemTypeFunctions::luaItemTypeGetCapacity(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetWeight(lua_State* L) { // itemType:getWeight([count = 1]) - const auto count = getNumber(L, 2, 1); + const auto count = Lua::getNumber(L, 2, 1); - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (!itemType) { lua_pushnil(L); return 1; @@ -343,7 +412,7 @@ int ItemTypeFunctions::luaItemTypeGetWeight(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetStackSize(lua_State* L) { // itemType:getStackSize() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (!itemType) { lua_pushnil(L); return 1; @@ -356,7 +425,7 @@ int ItemTypeFunctions::luaItemTypeGetStackSize(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetHitChance(lua_State* L) { // itemType:getHitChance() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->hitChance); } else { @@ -367,7 +436,7 @@ int ItemTypeFunctions::luaItemTypeGetHitChance(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetShootRange(lua_State* L) { // itemType:getShootRange() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->shootRange); } else { @@ -378,7 +447,7 @@ int ItemTypeFunctions::luaItemTypeGetShootRange(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetAttack(lua_State* L) { // itemType:getAttack() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->attack); } else { @@ -389,7 +458,7 @@ int ItemTypeFunctions::luaItemTypeGetAttack(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetDefense(lua_State* L) { // itemType:getDefense() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->defense); } else { @@ -400,7 +469,7 @@ int ItemTypeFunctions::luaItemTypeGetDefense(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetExtraDefense(lua_State* L) { // itemType:getExtraDefense() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->extraDefense); } else { @@ -411,7 +480,7 @@ int ItemTypeFunctions::luaItemTypeGetExtraDefense(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetImbuementSlot(lua_State* L) { // itemType:getImbuementSlot() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->imbuementSlot); } else { @@ -422,7 +491,7 @@ int ItemTypeFunctions::luaItemTypeGetImbuementSlot(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetArmor(lua_State* L) { // itemType:getArmor() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->armor); } else { @@ -433,7 +502,7 @@ int ItemTypeFunctions::luaItemTypeGetArmor(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetWeaponType(lua_State* L) { // itemType:getWeaponType() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->weaponType); } else { @@ -444,7 +513,7 @@ int ItemTypeFunctions::luaItemTypeGetWeaponType(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetAmmoType(lua_State* L) { // itemType:getAmmoType() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->ammoType); } else { @@ -455,7 +524,7 @@ int ItemTypeFunctions::luaItemTypeGetAmmoType(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetElementType(lua_State* L) { // itemType:getElementType() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (!itemType) { lua_pushnil(L); return 1; @@ -472,7 +541,7 @@ int ItemTypeFunctions::luaItemTypeGetElementType(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetElementDamage(lua_State* L) { // itemType:getElementDamage() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (!itemType) { lua_pushnil(L); return 1; @@ -489,7 +558,7 @@ int ItemTypeFunctions::luaItemTypeGetElementDamage(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetTransformEquipId(lua_State* L) { // itemType:getTransformEquipId() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->transformEquipTo); } else { @@ -500,7 +569,7 @@ int ItemTypeFunctions::luaItemTypeGetTransformEquipId(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetTransformDeEquipId(lua_State* L) { // itemType:getTransformDeEquipId() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->transformDeEquipTo); } else { @@ -511,7 +580,7 @@ int ItemTypeFunctions::luaItemTypeGetTransformDeEquipId(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetDestroyId(lua_State* L) { // itemType:getDestroyId() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->destroyTo); } else { @@ -522,7 +591,7 @@ int ItemTypeFunctions::luaItemTypeGetDestroyId(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetDecayId(lua_State* L) { // itemType:getDecayId() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->decayTo); } else { @@ -533,7 +602,7 @@ int ItemTypeFunctions::luaItemTypeGetDecayId(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetRequiredLevel(lua_State* L) { // itemType:getRequiredLevel() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->minReqLevel); } else { @@ -544,7 +613,7 @@ int ItemTypeFunctions::luaItemTypeGetRequiredLevel(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetSpeed(lua_State* L) { // itemType:getSpeed() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (!itemType) { lua_pushnil(L); return 1; @@ -561,7 +630,7 @@ int ItemTypeFunctions::luaItemTypeGetSpeed(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetBaseSpeed(lua_State* L) { // itemType:getBaseSpeed() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->speed); } else { @@ -572,7 +641,7 @@ int ItemTypeFunctions::luaItemTypeGetBaseSpeed(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetDecayTime(lua_State* L) { // itemType:getDecayTime() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->decayTime); } else { @@ -583,7 +652,7 @@ int ItemTypeFunctions::luaItemTypeGetDecayTime(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetShowDuration(lua_State* L) { // itemType:getShowDuration() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushboolean(L, itemType->showDuration); } else { @@ -593,7 +662,7 @@ int ItemTypeFunctions::luaItemTypeGetShowDuration(lua_State* L) { } int ItemTypeFunctions::luaItemTypeGetWrapableTo(lua_State* L) { // itemType:getWrapableTo() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { lua_pushnumber(L, itemType->wrapableTo); } else { @@ -604,9 +673,9 @@ int ItemTypeFunctions::luaItemTypeGetWrapableTo(lua_State* L) { int ItemTypeFunctions::luaItemTypeHasSubType(lua_State* L) { // itemType:hasSubType() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushBoolean(L, itemType->hasSubType()); + Lua::pushBoolean(L, itemType->hasSubType()); } else { lua_pushnil(L); } @@ -615,9 +684,9 @@ int ItemTypeFunctions::luaItemTypeHasSubType(lua_State* L) { int ItemTypeFunctions::luaItemTypeGetVocationString(lua_State* L) { // itemType:getVocationString() - const auto* itemType = getUserdata(L, 1); + const auto* itemType = Lua::getUserdata(L, 1); if (itemType) { - pushString(L, itemType->vocationString); + Lua::pushString(L, itemType->vocationString); } else { lua_pushnil(L); } diff --git a/src/lua/functions/items/item_type_functions.hpp b/src/lua/functions/items/item_type_functions.hpp index 254831fba56..19a401bc235 100644 --- a/src/lua/functions/items/item_type_functions.hpp +++ b/src/lua/functions/items/item_type_functions.hpp @@ -9,84 +9,11 @@ #pragma once -#include "lua/scripts/luascript.hpp" #include "lua/functions/items/item_classification_functions.hpp" -class ItemTypeFunctions final : LuaScriptInterface { +class ItemTypeFunctions { public: - explicit ItemTypeFunctions(lua_State* L) : - LuaScriptInterface("ItemTypeFunctions") { - init(L); - } - ~ItemTypeFunctions() override = default; - - static void init(lua_State* L) { - registerClass(L, "ItemType", "", ItemTypeFunctions::luaItemTypeCreate); - registerMetaMethod(L, "ItemType", "__eq", ItemTypeFunctions::luaUserdataCompare); - - registerMethod(L, "ItemType", "isCorpse", ItemTypeFunctions::luaItemTypeIsCorpse); - registerMethod(L, "ItemType", "isDoor", ItemTypeFunctions::luaItemTypeIsDoor); - registerMethod(L, "ItemType", "isContainer", ItemTypeFunctions::luaItemTypeIsContainer); - registerMethod(L, "ItemType", "isFluidContainer", ItemTypeFunctions::luaItemTypeIsFluidContainer); - registerMethod(L, "ItemType", "isMovable", ItemTypeFunctions::luaItemTypeIsMovable); - registerMethod(L, "ItemType", "isRune", ItemTypeFunctions::luaItemTypeIsRune); - registerMethod(L, "ItemType", "isStackable", ItemTypeFunctions::luaItemTypeIsStackable); - registerMethod(L, "ItemType", "isStowable", ItemTypeFunctions::luaItemTypeIsStowable); - registerMethod(L, "ItemType", "isReadable", ItemTypeFunctions::luaItemTypeIsReadable); - registerMethod(L, "ItemType", "isWritable", ItemTypeFunctions::luaItemTypeIsWritable); - registerMethod(L, "ItemType", "isBlocking", ItemTypeFunctions::luaItemTypeIsBlocking); - registerMethod(L, "ItemType", "isGroundTile", ItemTypeFunctions::luaItemTypeIsGroundTile); - registerMethod(L, "ItemType", "isMagicField", ItemTypeFunctions::luaItemTypeIsMagicField); - registerMethod(L, "ItemType", "isMultiUse", ItemTypeFunctions::luaItemTypeIsMultiUse); - registerMethod(L, "ItemType", "isPickupable", ItemTypeFunctions::luaItemTypeIsPickupable); - registerMethod(L, "ItemType", "isKey", ItemTypeFunctions::luaItemTypeIsKey); - registerMethod(L, "ItemType", "isQuiver", ItemTypeFunctions::luaItemTypeIsQuiver); - - registerMethod(L, "ItemType", "getType", ItemTypeFunctions::luaItemTypeGetType); - registerMethod(L, "ItemType", "getId", ItemTypeFunctions::luaItemTypeGetId); - registerMethod(L, "ItemType", "getName", ItemTypeFunctions::luaItemTypeGetName); - registerMethod(L, "ItemType", "getPluralName", ItemTypeFunctions::luaItemTypeGetPluralName); - registerMethod(L, "ItemType", "getArticle", ItemTypeFunctions::luaItemTypeGetArticle); - registerMethod(L, "ItemType", "getDescription", ItemTypeFunctions::luaItemTypeGetDescription); - registerMethod(L, "ItemType", "getSlotPosition", ItemTypeFunctions::luaItemTypeGetSlotPosition); - - registerMethod(L, "ItemType", "getCharges", ItemTypeFunctions::luaItemTypeGetCharges); - registerMethod(L, "ItemType", "getFluidSource", ItemTypeFunctions::luaItemTypeGetFluidSource); - registerMethod(L, "ItemType", "getCapacity", ItemTypeFunctions::luaItemTypeGetCapacity); - registerMethod(L, "ItemType", "getWeight", ItemTypeFunctions::luaItemTypeGetWeight); - registerMethod(L, "ItemType", "getStackSize", ItemTypeFunctions::luaItemTypeGetStackSize); - - registerMethod(L, "ItemType", "getHitChance", ItemTypeFunctions::luaItemTypeGetHitChance); - registerMethod(L, "ItemType", "getShootRange", ItemTypeFunctions::luaItemTypeGetShootRange); - - registerMethod(L, "ItemType", "getAttack", ItemTypeFunctions::luaItemTypeGetAttack); - registerMethod(L, "ItemType", "getDefense", ItemTypeFunctions::luaItemTypeGetDefense); - registerMethod(L, "ItemType", "getExtraDefense", ItemTypeFunctions::luaItemTypeGetExtraDefense); - registerMethod(L, "ItemType", "getImbuementSlot", ItemTypeFunctions::luaItemTypeGetImbuementSlot); - registerMethod(L, "ItemType", "getArmor", ItemTypeFunctions::luaItemTypeGetArmor); - registerMethod(L, "ItemType", "getWeaponType", ItemTypeFunctions::luaItemTypeGetWeaponType); - - registerMethod(L, "ItemType", "getElementType", ItemTypeFunctions::luaItemTypeGetElementType); - registerMethod(L, "ItemType", "getElementDamage", ItemTypeFunctions::luaItemTypeGetElementDamage); - - registerMethod(L, "ItemType", "getTransformEquipId", ItemTypeFunctions::luaItemTypeGetTransformEquipId); - registerMethod(L, "ItemType", "getTransformDeEquipId", ItemTypeFunctions::luaItemTypeGetTransformDeEquipId); - registerMethod(L, "ItemType", "getDestroyId", ItemTypeFunctions::luaItemTypeGetDestroyId); - registerMethod(L, "ItemType", "getDecayId", ItemTypeFunctions::luaItemTypeGetDecayId); - registerMethod(L, "ItemType", "getRequiredLevel", ItemTypeFunctions::luaItemTypeGetRequiredLevel); - registerMethod(L, "ItemType", "getAmmoType", ItemTypeFunctions::luaItemTypeGetAmmoType); - - registerMethod(L, "ItemType", "getDecayTime", ItemTypeFunctions::luaItemTypeGetDecayTime); - registerMethod(L, "ItemType", "getShowDuration", ItemTypeFunctions::luaItemTypeGetShowDuration); - registerMethod(L, "ItemType", "getWrapableTo", ItemTypeFunctions::luaItemTypeGetWrapableTo); - registerMethod(L, "ItemType", "getSpeed", ItemTypeFunctions::luaItemTypeGetSpeed); - registerMethod(L, "ItemType", "getBaseSpeed", ItemTypeFunctions::luaItemTypeGetBaseSpeed); - registerMethod(L, "ItemType", "getVocationString", ItemTypeFunctions::luaItemTypeGetVocationString); - - registerMethod(L, "ItemType", "hasSubType", ItemTypeFunctions::luaItemTypeHasSubType); - - ItemClassificationFunctions::init(L); - } + static void init(lua_State* L); private: static int luaItemTypeCreate(lua_State* L); diff --git a/src/lua/functions/items/weapon_functions.cpp b/src/lua/functions/items/weapon_functions.cpp index 4a02b1c4b29..e87d843116a 100644 --- a/src/lua/functions/items/weapon_functions.cpp +++ b/src/lua/functions/items/weapon_functions.cpp @@ -13,43 +13,76 @@ #include "items/item.hpp" #include "lua/scripts/lua_environment.hpp" #include "utils/tools.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void WeaponFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Weapon", "", WeaponFunctions::luaCreateWeapon); + Lua::registerMethod(L, "Weapon", "action", WeaponFunctions::luaWeaponAction); + Lua::registerMethod(L, "Weapon", "register", WeaponFunctions::luaWeaponRegister); + Lua::registerMethod(L, "Weapon", "id", WeaponFunctions::luaWeaponId); + Lua::registerMethod(L, "Weapon", "level", WeaponFunctions::luaWeaponLevel); + Lua::registerMethod(L, "Weapon", "magicLevel", WeaponFunctions::luaWeaponMagicLevel); + Lua::registerMethod(L, "Weapon", "mana", WeaponFunctions::luaWeaponMana); + Lua::registerMethod(L, "Weapon", "manaPercent", WeaponFunctions::luaWeaponManaPercent); + Lua::registerMethod(L, "Weapon", "health", WeaponFunctions::luaWeaponHealth); + Lua::registerMethod(L, "Weapon", "healthPercent", WeaponFunctions::luaWeaponHealthPercent); + Lua::registerMethod(L, "Weapon", "soul", WeaponFunctions::luaWeaponSoul); + Lua::registerMethod(L, "Weapon", "breakChance", WeaponFunctions::luaWeaponBreakChance); + Lua::registerMethod(L, "Weapon", "premium", WeaponFunctions::luaWeaponPremium); + Lua::registerMethod(L, "Weapon", "wieldUnproperly", WeaponFunctions::luaWeaponUnproperly); + Lua::registerMethod(L, "Weapon", "vocation", WeaponFunctions::luaWeaponVocation); + Lua::registerMethod(L, "Weapon", "onUseWeapon", WeaponFunctions::luaWeaponOnUseWeapon); + Lua::registerMethod(L, "Weapon", "element", WeaponFunctions::luaWeaponElement); + Lua::registerMethod(L, "Weapon", "attack", WeaponFunctions::luaWeaponAttack); + Lua::registerMethod(L, "Weapon", "defense", WeaponFunctions::luaWeaponDefense); + Lua::registerMethod(L, "Weapon", "range", WeaponFunctions::luaWeaponRange); + Lua::registerMethod(L, "Weapon", "charges", WeaponFunctions::luaWeaponCharges); + Lua::registerMethod(L, "Weapon", "duration", WeaponFunctions::luaWeaponDuration); + Lua::registerMethod(L, "Weapon", "decayTo", WeaponFunctions::luaWeaponDecayTo); + Lua::registerMethod(L, "Weapon", "transformEquipTo", WeaponFunctions::luaWeaponTransformEquipTo); + Lua::registerMethod(L, "Weapon", "transformDeEquipTo", WeaponFunctions::luaWeaponTransformDeEquipTo); + Lua::registerMethod(L, "Weapon", "slotType", WeaponFunctions::luaWeaponSlotType); + Lua::registerMethod(L, "Weapon", "hitChance", WeaponFunctions::luaWeaponHitChance); + Lua::registerMethod(L, "Weapon", "extraElement", WeaponFunctions::luaWeaponExtraElement); + + // exclusively for distance weapons + Lua::registerMethod(L, "Weapon", "ammoType", WeaponFunctions::luaWeaponAmmoType); + Lua::registerMethod(L, "Weapon", "maxHitChance", WeaponFunctions::luaWeaponMaxHitChance); + + // exclusively for wands + Lua::registerMethod(L, "Weapon", "damage", WeaponFunctions::luaWeaponWandDamage); + + // exclusively for wands & distance weapons + Lua::registerMethod(L, "Weapon", "shootType", WeaponFunctions::luaWeaponShootType); +} int WeaponFunctions::luaCreateWeapon(lua_State* L) { // Weapon(type) - const WeaponType_t type = getNumber(L, 2); + const WeaponType_t type = Lua::getNumber(L, 2); switch (type) { case WEAPON_SWORD: case WEAPON_AXE: case WEAPON_CLUB: { - if (const auto &weaponPtr = g_luaEnvironment().createWeaponObject(getScriptEnv()->getScriptInterface())) { - pushUserdata(L, weaponPtr); - setMetatable(L, -1, "Weapon"); - weaponPtr->weaponType = type; - } else { - lua_pushnil(L); - } + auto weaponPtr = std::make_shared(); + Lua::pushUserdata(L, weaponPtr); + Lua::setMetatable(L, -1, "Weapon"); + weaponPtr->weaponType = type; break; } case WEAPON_MISSILE: case WEAPON_DISTANCE: case WEAPON_AMMO: { - if (const auto &weaponPtr = g_luaEnvironment().createWeaponObject(getScriptEnv()->getScriptInterface())) { - pushUserdata(L, weaponPtr); - setMetatable(L, -1, "Weapon"); - weaponPtr->weaponType = type; - } else { - lua_pushnil(L); - } + auto weaponPtr = std::make_shared(); + Lua::pushUserdata(L, weaponPtr); + Lua::setMetatable(L, -1, "Weapon"); + weaponPtr->weaponType = type; break; } case WEAPON_WAND: { - if (const auto &weaponPtr = g_luaEnvironment().createWeaponObject(getScriptEnv()->getScriptInterface())) { - pushUserdata(L, weaponPtr); - setMetatable(L, -1, "Weapon"); - weaponPtr->weaponType = type; - } else { - lua_pushnil(L); - } + auto weaponPtr = std::make_shared(); + Lua::pushUserdata(L, weaponPtr); + Lua::setMetatable(L, -1, "Weapon"); + weaponPtr->weaponType = type; break; } default: { @@ -62,9 +95,9 @@ int WeaponFunctions::luaCreateWeapon(lua_State* L) { int WeaponFunctions::luaWeaponAction(lua_State* L) { // weapon:action(callback) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - std::string typeName = getString(L, 2); + std::string typeName = Lua::getString(L, 2); const std::string tmpStr = asLowerCaseString(typeName); if (tmpStr == "removecount") { weapon->action = WEAPONACTION_REMOVECOUNT; @@ -76,9 +109,9 @@ int WeaponFunctions::luaWeaponAction(lua_State* L) { g_logger().error("[WeaponFunctions::luaWeaponAction] - " "No valid action {}", typeName); - pushBoolean(L, false); + Lua::pushBoolean(L, false); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -87,15 +120,15 @@ int WeaponFunctions::luaWeaponAction(lua_State* L) { int WeaponFunctions::luaWeaponRegister(lua_State* L) { // weapon:register() - const WeaponShared_ptr* weaponPtr = getRawUserDataShared(L, 1); + const WeaponShared_ptr* weaponPtr = Lua::getRawUserDataShared(L, 1); if (weaponPtr && *weaponPtr) { WeaponShared_ptr weapon = *weaponPtr; if (weapon->weaponType == WEAPON_DISTANCE || weapon->weaponType == WEAPON_AMMO || weapon->weaponType == WEAPON_MISSILE) { - weapon = getUserdataShared(L, 1); + weapon = Lua::getUserdataShared(L, 1); } else if (weapon->weaponType == WEAPON_WAND) { - weapon = getUserdataShared(L, 1); + weapon = Lua::getUserdataShared(L, 1); } else { - weapon = getUserdataShared(L, 1); + weapon = Lua::getUserdataShared(L, 1); } const uint16_t id = weapon->getID(); @@ -110,7 +143,7 @@ int WeaponFunctions::luaWeaponRegister(lua_State* L) { } weapon->configureWeapon(it); - pushBoolean(L, g_weapons().registerLuaEvent(weapon)); + Lua::pushBoolean(L, g_weapons().registerLuaEvent(weapon)); weapon = nullptr; // Releases weapon, removing the luascript reference } else { lua_pushnil(L); @@ -120,14 +153,14 @@ int WeaponFunctions::luaWeaponRegister(lua_State* L) { int WeaponFunctions::luaWeaponOnUseWeapon(lua_State* L) { // weapon:onUseWeapon(callback) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - if (!weapon->loadCallback()) { - pushBoolean(L, false); + if (!weapon->loadScriptId()) { + Lua::pushBoolean(L, false); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -136,10 +169,10 @@ int WeaponFunctions::luaWeaponOnUseWeapon(lua_State* L) { int WeaponFunctions::luaWeaponUnproperly(lua_State* L) { // weapon:wieldedUnproperly(bool) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setWieldUnproperly(getBoolean(L, 2)); - pushBoolean(L, true); + weapon->setWieldUnproperly(Lua::getBoolean(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -148,11 +181,11 @@ int WeaponFunctions::luaWeaponUnproperly(lua_State* L) { int WeaponFunctions::luaWeaponLevel(lua_State* L) { // weapon:level(lvl) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setRequiredLevel(getNumber(L, 2)); + weapon->setRequiredLevel(Lua::getNumber(L, 2)); weapon->setWieldInfo(WIELDINFO_LEVEL); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -161,11 +194,11 @@ int WeaponFunctions::luaWeaponLevel(lua_State* L) { int WeaponFunctions::luaWeaponMagicLevel(lua_State* L) { // weapon:magicLevel(lvl) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setRequiredMagLevel(getNumber(L, 2)); + weapon->setRequiredMagLevel(Lua::getNumber(L, 2)); weapon->setWieldInfo(WIELDINFO_MAGLV); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -174,10 +207,10 @@ int WeaponFunctions::luaWeaponMagicLevel(lua_State* L) { int WeaponFunctions::luaWeaponMana(lua_State* L) { // weapon:mana(mana) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setMana(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setMana(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -186,10 +219,10 @@ int WeaponFunctions::luaWeaponMana(lua_State* L) { int WeaponFunctions::luaWeaponManaPercent(lua_State* L) { // weapon:manaPercent(percent) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setManaPercent(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setManaPercent(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -198,10 +231,10 @@ int WeaponFunctions::luaWeaponManaPercent(lua_State* L) { int WeaponFunctions::luaWeaponHealth(lua_State* L) { // weapon:health(health) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setHealth(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setHealth(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -210,10 +243,10 @@ int WeaponFunctions::luaWeaponHealth(lua_State* L) { int WeaponFunctions::luaWeaponHealthPercent(lua_State* L) { // weapon:healthPercent(percent) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setHealthPercent(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setHealthPercent(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -222,10 +255,10 @@ int WeaponFunctions::luaWeaponHealthPercent(lua_State* L) { int WeaponFunctions::luaWeaponSoul(lua_State* L) { // weapon:soul(soul) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setSoul(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setSoul(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -234,10 +267,10 @@ int WeaponFunctions::luaWeaponSoul(lua_State* L) { int WeaponFunctions::luaWeaponBreakChance(lua_State* L) { // weapon:breakChance(percent) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setBreakChance(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setBreakChance(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -246,15 +279,15 @@ int WeaponFunctions::luaWeaponBreakChance(lua_State* L) { int WeaponFunctions::luaWeaponWandDamage(lua_State* L) { // weapon:damage(damage[min, max]) only use this if the weapon is a wand! - const auto &weapon = getUserdataShared(L, 1); + const auto &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setMinChange(getNumber(L, 2)); + weapon->setMinChange(Lua::getNumber(L, 2)); if (lua_gettop(L) > 2) { - weapon->setMaxChange(getNumber(L, 3)); + weapon->setMaxChange(Lua::getNumber(L, 3)); } else { - weapon->setMaxChange(getNumber(L, 2)); + weapon->setMaxChange(Lua::getNumber(L, 2)); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -263,10 +296,10 @@ int WeaponFunctions::luaWeaponWandDamage(lua_State* L) { int WeaponFunctions::luaWeaponElement(lua_State* L) { // weapon:element(combatType) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - if (!getNumber(L, 2)) { - std::string element = getString(L, 2); + if (!Lua::getNumber(L, 2)) { + std::string element = Lua::getString(L, 2); const std::string tmpStrValue = asLowerCaseString(element); if (tmpStrValue == "earth") { weapon->params.combatType = COMBAT_EARTHDAMAGE; @@ -286,9 +319,9 @@ int WeaponFunctions::luaWeaponElement(lua_State* L) { element); } } else { - weapon->params.combatType = getNumber(L, 2); + weapon->params.combatType = Lua::getNumber(L, 2); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -297,11 +330,11 @@ int WeaponFunctions::luaWeaponElement(lua_State* L) { int WeaponFunctions::luaWeaponPremium(lua_State* L) { // weapon:premium(bool) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setNeedPremium(getBoolean(L, 2)); + weapon->setNeedPremium(Lua::getBoolean(L, 2)); weapon->setWieldInfo(WIELDINFO_PREMIUM); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -310,22 +343,22 @@ int WeaponFunctions::luaWeaponPremium(lua_State* L) { int WeaponFunctions::luaWeaponVocation(lua_State* L) { // weapon:vocation(vocName[, showInDescription = false, lastVoc = false]) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->addVocWeaponMap(getString(L, 2)); + weapon->addVocWeaponMap(Lua::getString(L, 2)); weapon->setWieldInfo(WIELDINFO_VOCREQ); std::string tmp; bool showInDescription = false; bool lastVoc = false; - if (getBoolean(L, 3)) { - showInDescription = getBoolean(L, 3); + if (Lua::getBoolean(L, 3)) { + showInDescription = Lua::getBoolean(L, 3); } - if (getBoolean(L, 4)) { - lastVoc = getBoolean(L, 4); + if (Lua::getBoolean(L, 4)) { + lastVoc = Lua::getBoolean(L, 4); } if (showInDescription) { if (weapon->getVocationString().empty()) { - tmp = asLowerCaseString(getString(L, 2)); + tmp = asLowerCaseString(Lua::getString(L, 2)); tmp += "s"; weapon->setVocationString(tmp); } else { @@ -335,12 +368,12 @@ int WeaponFunctions::luaWeaponVocation(lua_State* L) { } else { tmp += ", "; } - tmp += asLowerCaseString(getString(L, 2)); + tmp += asLowerCaseString(Lua::getString(L, 2)); tmp += "s"; weapon->setVocationString(tmp); } } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -349,10 +382,10 @@ int WeaponFunctions::luaWeaponVocation(lua_State* L) { int WeaponFunctions::luaWeaponId(lua_State* L) { // weapon:id(id) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { - weapon->setID(getNumber(L, 2)); - pushBoolean(L, true); + weapon->setID(Lua::getNumber(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -361,12 +394,12 @@ int WeaponFunctions::luaWeaponId(lua_State* L) { int WeaponFunctions::luaWeaponAttack(lua_State* L) { // weapon:attack(atk) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.attack = getNumber(L, 2); - pushBoolean(L, true); + it.attack = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -375,15 +408,15 @@ int WeaponFunctions::luaWeaponAttack(lua_State* L) { int WeaponFunctions::luaWeaponDefense(lua_State* L) { // weapon:defense(defense[, extraDefense]) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.defense = getNumber(L, 2); + it.defense = Lua::getNumber(L, 2); if (lua_gettop(L) > 2) { - it.extraDefense = getNumber(L, 3); + it.extraDefense = Lua::getNumber(L, 3); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -392,12 +425,12 @@ int WeaponFunctions::luaWeaponDefense(lua_State* L) { int WeaponFunctions::luaWeaponRange(lua_State* L) { // weapon:range(range) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.shootRange = getNumber(L, 2); - pushBoolean(L, true); + it.shootRange = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -406,17 +439,17 @@ int WeaponFunctions::luaWeaponRange(lua_State* L) { int WeaponFunctions::luaWeaponCharges(lua_State* L) { // weapon:charges(charges[, showCharges = true]) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { bool showCharges = true; if (lua_gettop(L) > 2) { - showCharges = getBoolean(L, 3); + showCharges = Lua::getBoolean(L, 3); } const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.charges = getNumber(L, 2); + it.charges = Lua::getNumber(L, 2); it.showCharges = showCharges; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -425,17 +458,17 @@ int WeaponFunctions::luaWeaponCharges(lua_State* L) { int WeaponFunctions::luaWeaponDuration(lua_State* L) { // weapon:duration(duration[, showDuration = true]) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { bool showDuration = true; if (lua_gettop(L) > 2) { - showDuration = getBoolean(L, 3); + showDuration = Lua::getBoolean(L, 3); } const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.decayTime = getNumber(L, 2); + it.decayTime = Lua::getNumber(L, 2); it.showDuration = showDuration; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -444,16 +477,16 @@ int WeaponFunctions::luaWeaponDuration(lua_State* L) { int WeaponFunctions::luaWeaponDecayTo(lua_State* L) { // weapon:decayTo([itemid = 0] - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { uint16_t itemid = 0; if (lua_gettop(L) > 1) { - itemid = getNumber(L, 2); + itemid = Lua::getNumber(L, 2); } const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); it.decayTo = itemid; - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -462,12 +495,12 @@ int WeaponFunctions::luaWeaponDecayTo(lua_State* L) { int WeaponFunctions::luaWeaponTransformEquipTo(lua_State* L) { // weapon:transformEquipTo(itemid) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.transformEquipTo = getNumber(L, 2); - pushBoolean(L, true); + it.transformEquipTo = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -476,12 +509,12 @@ int WeaponFunctions::luaWeaponTransformEquipTo(lua_State* L) { int WeaponFunctions::luaWeaponTransformDeEquipTo(lua_State* L) { // weapon:transformDeEquipTo(itemid) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.transformDeEquipTo = getNumber(L, 2); - pushBoolean(L, true); + it.transformDeEquipTo = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -490,12 +523,12 @@ int WeaponFunctions::luaWeaponTransformDeEquipTo(lua_State* L) { int WeaponFunctions::luaWeaponShootType(lua_State* L) { // weapon:shootType(type) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.shootType = getNumber(L, 2); - pushBoolean(L, true); + it.shootType = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -504,18 +537,18 @@ int WeaponFunctions::luaWeaponShootType(lua_State* L) { int WeaponFunctions::luaWeaponSlotType(lua_State* L) { // weapon:slotType(slot) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - const std::string slot = getString(L, 2); + const std::string slot = Lua::getString(L, 2); if (slot == "two-handed") { it.slotPosition = SLOTP_TWO_HAND; } else { it.slotPosition = SLOTP_HAND; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -524,11 +557,11 @@ int WeaponFunctions::luaWeaponSlotType(lua_State* L) { int WeaponFunctions::luaWeaponAmmoType(lua_State* L) { // weapon:ammoType(type) - const auto &weapon = getUserdataShared(L, 1); + const auto &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - std::string type = getString(L, 2); + std::string type = Lua::getString(L, 2); if (type == "arrow") { it.ammoType = AMMO_ARROW; @@ -541,7 +574,7 @@ int WeaponFunctions::luaWeaponAmmoType(lua_State* L) { lua_pushnil(L); return 1; } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -550,12 +583,12 @@ int WeaponFunctions::luaWeaponAmmoType(lua_State* L) { int WeaponFunctions::luaWeaponHitChance(lua_State* L) { // weapon:hitChance(chance) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.hitChance = getNumber(L, 2); - pushBoolean(L, true); + it.hitChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -564,12 +597,12 @@ int WeaponFunctions::luaWeaponHitChance(lua_State* L) { int WeaponFunctions::luaWeaponMaxHitChance(lua_State* L) { // weapon:maxHitChance(max) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); ItemType &it = Item::items.getItemType(id); - it.maxHitChance = getNumber(L, 2); - pushBoolean(L, true); + it.maxHitChance = Lua::getNumber(L, 2); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -578,14 +611,14 @@ int WeaponFunctions::luaWeaponMaxHitChance(lua_State* L) { int WeaponFunctions::luaWeaponExtraElement(lua_State* L) { // weapon:extraElement(atk, combatType) - const WeaponShared_ptr &weapon = getUserdataShared(L, 1); + const WeaponShared_ptr &weapon = Lua::getUserdataShared(L, 1); if (weapon) { const uint16_t id = weapon->getID(); const ItemType &it = Item::items.getItemType(id); - it.abilities->elementDamage = getNumber(L, 2); + it.abilities->elementDamage = Lua::getNumber(L, 2); - if (!getNumber(L, 3)) { - std::string element = getString(L, 3); + if (!Lua::getNumber(L, 3)) { + std::string element = Lua::getString(L, 3); const std::string tmpStrValue = asLowerCaseString(element); if (tmpStrValue == "earth") { it.abilities->elementType = COMBAT_EARTHDAMAGE; @@ -605,9 +638,9 @@ int WeaponFunctions::luaWeaponExtraElement(lua_State* L) { element); } } else { - it.abilities->elementType = getNumber(L, 3); + it.abilities->elementType = Lua::getNumber(L, 3); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/items/weapon_functions.hpp b/src/lua/functions/items/weapon_functions.hpp index d68146f82bc..971ff286036 100644 --- a/src/lua/functions/items/weapon_functions.hpp +++ b/src/lua/functions/items/weapon_functions.hpp @@ -9,56 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class WeaponFunctions final : LuaScriptInterface { +class WeaponFunctions { public: - explicit WeaponFunctions(lua_State* L) : - LuaScriptInterface("WeaponFunctions") { - init(L); - } - ~WeaponFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Weapon", "", WeaponFunctions::luaCreateWeapon); - registerMethod(L, "Weapon", "action", WeaponFunctions::luaWeaponAction); - registerMethod(L, "Weapon", "register", WeaponFunctions::luaWeaponRegister); - registerMethod(L, "Weapon", "id", WeaponFunctions::luaWeaponId); - registerMethod(L, "Weapon", "level", WeaponFunctions::luaWeaponLevel); - registerMethod(L, "Weapon", "magicLevel", WeaponFunctions::luaWeaponMagicLevel); - registerMethod(L, "Weapon", "mana", WeaponFunctions::luaWeaponMana); - registerMethod(L, "Weapon", "manaPercent", WeaponFunctions::luaWeaponManaPercent); - registerMethod(L, "Weapon", "health", WeaponFunctions::luaWeaponHealth); - registerMethod(L, "Weapon", "healthPercent", WeaponFunctions::luaWeaponHealthPercent); - registerMethod(L, "Weapon", "soul", WeaponFunctions::luaWeaponSoul); - registerMethod(L, "Weapon", "breakChance", WeaponFunctions::luaWeaponBreakChance); - registerMethod(L, "Weapon", "premium", WeaponFunctions::luaWeaponPremium); - registerMethod(L, "Weapon", "wieldUnproperly", WeaponFunctions::luaWeaponUnproperly); - registerMethod(L, "Weapon", "vocation", WeaponFunctions::luaWeaponVocation); - registerMethod(L, "Weapon", "onUseWeapon", WeaponFunctions::luaWeaponOnUseWeapon); - registerMethod(L, "Weapon", "element", WeaponFunctions::luaWeaponElement); - registerMethod(L, "Weapon", "attack", WeaponFunctions::luaWeaponAttack); - registerMethod(L, "Weapon", "defense", WeaponFunctions::luaWeaponDefense); - registerMethod(L, "Weapon", "range", WeaponFunctions::luaWeaponRange); - registerMethod(L, "Weapon", "charges", WeaponFunctions::luaWeaponCharges); - registerMethod(L, "Weapon", "duration", WeaponFunctions::luaWeaponDuration); - registerMethod(L, "Weapon", "decayTo", WeaponFunctions::luaWeaponDecayTo); - registerMethod(L, "Weapon", "transformEquipTo", WeaponFunctions::luaWeaponTransformEquipTo); - registerMethod(L, "Weapon", "transformDeEquipTo", WeaponFunctions::luaWeaponTransformDeEquipTo); - registerMethod(L, "Weapon", "slotType", WeaponFunctions::luaWeaponSlotType); - registerMethod(L, "Weapon", "hitChance", WeaponFunctions::luaWeaponHitChance); - registerMethod(L, "Weapon", "extraElement", WeaponFunctions::luaWeaponExtraElement); - - // exclusively for distance weapons - registerMethod(L, "Weapon", "ammoType", WeaponFunctions::luaWeaponAmmoType); - registerMethod(L, "Weapon", "maxHitChance", WeaponFunctions::luaWeaponMaxHitChance); - - // exclusively for wands - registerMethod(L, "Weapon", "damage", WeaponFunctions::luaWeaponWandDamage); - - // exclusively for wands & distance weapons - registerMethod(L, "Weapon", "shootType", WeaponFunctions::luaWeaponShootType); - } + static void init(lua_State* L); private: static int luaCreateWeapon(lua_State* L); diff --git a/src/lua/functions/lua_functions_loader.cpp b/src/lua/functions/lua_functions_loader.cpp index 894cf252c80..d4aeac2a7f1 100644 --- a/src/lua/functions/lua_functions_loader.cpp +++ b/src/lua/functions/lua_functions_loader.cpp @@ -30,7 +30,7 @@ class LuaScriptInterface; -void LuaFunctionsLoader::load(lua_State* L) { +void Lua::load(lua_State* L) { if (!L) { g_game().dieSafely("Invalid lua state, cannot load lua functions."); } @@ -45,7 +45,7 @@ void LuaFunctionsLoader::load(lua_State* L) { ZoneFunctions::init(L); } -std::string LuaFunctionsLoader::getErrorDesc(ErrorCode_t code) { +std::string Lua::getErrorDesc(ErrorCode_t code) { switch (code) { case LUA_ERROR_PLAYER_NOT_FOUND: return "Player not found"; @@ -92,7 +92,7 @@ std::string LuaFunctionsLoader::getErrorDesc(ErrorCode_t code) { } } -int LuaFunctionsLoader::protectedCall(lua_State* L, int nargs, int nresults) { +int Lua::protectedCall(lua_State* L, int nargs, int nresults) { if (const int ret = validateDispatcherContext(__FUNCTION__); ret != 0) { return ret; } @@ -106,7 +106,7 @@ int LuaFunctionsLoader::protectedCall(lua_State* L, int nargs, int nresults) { return ret; } -void LuaFunctionsLoader::reportError(const char* function, const std::string &error_desc, bool stack_trace /* = false*/) { +void Lua::reportError(const char* function, const std::string &error_desc, bool stack_trace /* = false*/) { int32_t scriptId; int32_t callbackId; bool timerEvent; @@ -144,7 +144,7 @@ void LuaFunctionsLoader::reportError(const char* function, const std::string &er g_logger().error(logMsg.str()); } -int LuaFunctionsLoader::luaErrorHandler(lua_State* L) { +int Lua::luaErrorHandler(lua_State* L) { const std::string &errorMessage = popString(L); const auto interface = getScriptEnv()->getScriptInterface(); if (!interface) { @@ -157,7 +157,7 @@ int LuaFunctionsLoader::luaErrorHandler(lua_State* L) { return 1; } -void LuaFunctionsLoader::pushVariant(lua_State* L, const LuaVariant &var) { +void Lua::pushVariant(lua_State* L, const LuaVariant &var) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -185,7 +185,7 @@ void LuaFunctionsLoader::pushVariant(lua_State* L, const LuaVariant &var) { setMetatable(L, -1, "Variant"); } -void LuaFunctionsLoader::pushThing(lua_State* L, const std::shared_ptr &thing) { +void Lua::pushThing(lua_State* L, const std::shared_ptr &thing) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -210,7 +210,7 @@ void LuaFunctionsLoader::pushThing(lua_State* L, const std::shared_ptr &t } } -void LuaFunctionsLoader::pushCylinder(lua_State* L, const std::shared_ptr &cylinder) { +void Lua::pushCylinder(lua_State* L, const std::shared_ptr &cylinder) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -231,7 +231,7 @@ void LuaFunctionsLoader::pushCylinder(lua_State* L, const std::shared_ptr weakObjectTypes; if (validateDispatcherContext(__FUNCTION__)) { return; @@ -309,7 +317,7 @@ void LuaFunctionsLoader::setWeakMetatable(lua_State* L, int32_t index, const std lua_setmetatable(L, index - 1); } -void LuaFunctionsLoader::setItemMetatable(lua_State* L, int32_t index, const std::shared_ptr &item) { +void Lua::setItemMetatable(lua_State* L, int32_t index, const std::shared_ptr &item) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -324,7 +332,7 @@ void LuaFunctionsLoader::setItemMetatable(lua_State* L, int32_t index, const std lua_setmetatable(L, index - 1); } -void LuaFunctionsLoader::setCreatureMetatable(lua_State* L, int32_t index, const std::shared_ptr &creature) { +void Lua::setCreatureMetatable(lua_State* L, int32_t index, const std::shared_ptr &creature) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -339,7 +347,7 @@ void LuaFunctionsLoader::setCreatureMetatable(lua_State* L, int32_t index, const lua_setmetatable(L, index - 1); } -CombatDamage LuaFunctionsLoader::getCombatDamage(lua_State* L) { +CombatDamage Lua::getCombatDamage(lua_State* L) { CombatDamage damage; damage.primary.value = getNumber(L, -4); damage.primary.type = getNumber(L, -3); @@ -351,7 +359,7 @@ CombatDamage LuaFunctionsLoader::getCombatDamage(lua_State* L) { } // Get -std::string LuaFunctionsLoader::getFormatedLoggerMessage(lua_State* L) { +std::string Lua::getFormatedLoggerMessage(lua_State* L) { const std::string format = getString(L, 1); const int n = lua_gettop(L); fmt::dynamic_format_arg_store args; @@ -387,7 +395,7 @@ std::string LuaFunctionsLoader::getFormatedLoggerMessage(lua_State* L) { return {}; } -std::string LuaFunctionsLoader::getString(lua_State* L, int32_t arg) { +std::string Lua::getString(lua_State* L, int32_t arg) { size_t len; const char* c_str = lua_tolstring(L, arg, &len); if (!c_str || len == 0) { @@ -396,7 +404,7 @@ std::string LuaFunctionsLoader::getString(lua_State* L, int32_t arg) { return std::string(c_str, len); } -Position LuaFunctionsLoader::getPosition(lua_State* L, int32_t arg, int32_t &stackpos) { +Position Lua::getPosition(lua_State* L, int32_t arg, int32_t &stackpos) { Position position; position.x = getField(L, arg, "x"); position.y = getField(L, arg, "y"); @@ -413,7 +421,7 @@ Position LuaFunctionsLoader::getPosition(lua_State* L, int32_t arg, int32_t &sta return position; } -Position LuaFunctionsLoader::getPosition(lua_State* L, int32_t arg) { +Position Lua::getPosition(lua_State* L, int32_t arg) { Position position; position.x = getField(L, arg, "x"); position.y = getField(L, arg, "y"); @@ -423,7 +431,7 @@ Position LuaFunctionsLoader::getPosition(lua_State* L, int32_t arg) { return position; } -Outfit_t LuaFunctionsLoader::getOutfit(lua_State* L, int32_t arg) { +Outfit_t Lua::getOutfit(lua_State* L, int32_t arg) { Outfit_t outfit; outfit.lookMountFeet = getField(L, arg, "lookMountFeet"); outfit.lookMountLegs = getField(L, arg, "lookMountLegs"); @@ -445,7 +453,7 @@ Outfit_t LuaFunctionsLoader::getOutfit(lua_State* L, int32_t arg) { return outfit; } -LuaVariant LuaFunctionsLoader::getVariant(lua_State* L, int32_t arg) { +LuaVariant Lua::getVariant(lua_State* L, int32_t arg) { LuaVariant var; var.instantName = getFieldString(L, arg, "instantName"); var.runeName = getFieldString(L, arg, "runeName"); @@ -479,7 +487,7 @@ LuaVariant LuaFunctionsLoader::getVariant(lua_State* L, int32_t arg) { return var; } -std::shared_ptr LuaFunctionsLoader::getThing(lua_State* L, int32_t arg) { +std::shared_ptr Lua::getThing(lua_State* L, int32_t arg) { std::shared_ptr thing; if (lua_getmetatable(L, arg) != 0) { lua_rawgeti(L, -1, 't'); @@ -513,14 +521,14 @@ std::shared_ptr LuaFunctionsLoader::getThing(lua_State* L, int32_t arg) { return thing; } -std::shared_ptr LuaFunctionsLoader::getCreature(lua_State* L, int32_t arg) { +std::shared_ptr Lua::getCreature(lua_State* L, int32_t arg) { if (isUserdata(L, arg)) { return getUserdataShared(L, arg); } return g_game().getCreatureByID(getNumber(L, arg)); } -std::shared_ptr LuaFunctionsLoader::getPlayer(lua_State* L, int32_t arg, bool allowOffline /* = false */) { +std::shared_ptr Lua::getPlayer(lua_State* L, int32_t arg, bool allowOffline /* = false */) { if (isUserdata(L, arg)) { return getUserdataShared(L, arg); } else if (isNumber(L, arg)) { @@ -528,11 +536,11 @@ std::shared_ptr LuaFunctionsLoader::getPlayer(lua_State* L, int32_t arg, } else if (isString(L, arg)) { return g_game().getPlayerByName(getString(L, arg), allowOffline); } - g_logger().warn("LuaFunctionsLoader::getPlayer: Invalid argument."); + g_logger().warn("Lua::getPlayer: Invalid argument."); return nullptr; } -std::shared_ptr LuaFunctionsLoader::getGuild(lua_State* L, int32_t arg, bool allowOffline /* = false */) { +std::shared_ptr Lua::getGuild(lua_State* L, int32_t arg, bool allowOffline /* = false */) { if (isUserdata(L, arg)) { return getUserdataShared(L, arg); } else if (isNumber(L, arg)) { @@ -540,16 +548,16 @@ std::shared_ptr LuaFunctionsLoader::getGuild(lua_State* L, int32_t arg, b } else if (isString(L, arg)) { return g_game().getGuildByName(getString(L, arg), allowOffline); } - g_logger().warn("LuaFunctionsLoader::getGuild: Invalid argument."); + g_logger().warn("Lua::getGuild: Invalid argument."); return nullptr; } -std::string LuaFunctionsLoader::getFieldString(lua_State* L, int32_t arg, const std::string &key) { +std::string Lua::getFieldString(lua_State* L, int32_t arg, const std::string &key) { lua_getfield(L, arg, key.c_str()); return getString(L, -1); } -LuaData_t LuaFunctionsLoader::getUserdataType(lua_State* L, int32_t arg) { +LuaData_t Lua::getUserdataType(lua_State* L, int32_t arg) { if (lua_getmetatable(L, arg) == 0) { return LuaData_t::Unknown; } @@ -561,12 +569,12 @@ LuaData_t LuaFunctionsLoader::getUserdataType(lua_State* L, int32_t arg) { return type; } -std::string LuaFunctionsLoader::getUserdataTypeName(LuaData_t userType) { +std::string Lua::getUserdataTypeName(LuaData_t userType) { return magic_enum::enum_name(userType).data(); } // Push -void LuaFunctionsLoader::pushBoolean(lua_State* L, bool value) { +void Lua::pushBoolean(lua_State* L, bool value) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -574,7 +582,7 @@ void LuaFunctionsLoader::pushBoolean(lua_State* L, bool value) { lua_pushboolean(L, value ? 1 : 0); } -void LuaFunctionsLoader::pushCombatDamage(lua_State* L, const CombatDamage &damage) { +void Lua::pushCombatDamage(lua_State* L, const CombatDamage &damage) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -586,7 +594,7 @@ void LuaFunctionsLoader::pushCombatDamage(lua_State* L, const CombatDamage &dama lua_pushnumber(L, damage.origin); } -void LuaFunctionsLoader::pushInstantSpell(lua_State* L, const InstantSpell &spell) { +void Lua::pushInstantSpell(lua_State* L, const InstantSpell &spell) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -603,7 +611,7 @@ void LuaFunctionsLoader::pushInstantSpell(lua_State* L, const InstantSpell &spel setMetatable(L, -1, "Spell"); } -void LuaFunctionsLoader::pushPosition(lua_State* L, const Position &position, int32_t stackpos /* = 0*/) { +void Lua::pushPosition(lua_State* L, const Position &position, int32_t stackpos /* = 0*/) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -618,7 +626,7 @@ void LuaFunctionsLoader::pushPosition(lua_State* L, const Position &position, in setMetatable(L, -1, "Position"); } -void LuaFunctionsLoader::pushOutfit(lua_State* L, const Outfit_t &outfit) { +void Lua::pushOutfit(lua_State* L, const Outfit_t &outfit) { if (validateDispatcherContext(__FUNCTION__)) { return; } @@ -639,7 +647,7 @@ void LuaFunctionsLoader::pushOutfit(lua_State* L, const Outfit_t &outfit) { setField(L, "lookFamiliarsType", outfit.lookFamiliarsType); } -void LuaFunctionsLoader::registerClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction /* = nullptr*/) { +void Lua::registerClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction /* = nullptr*/) { // className = {} lua_newtable(L); lua_pushvalue(L, -1); @@ -701,7 +709,7 @@ void LuaFunctionsLoader::registerClass(lua_State* L, const std::string &classNam lua_pop(L, 2); } -void LuaFunctionsLoader::registerMethod(lua_State* L, const std::string &globalName, const std::string &methodName, lua_CFunction func) { +void Lua::registerMethod(lua_State* L, const std::string &globalName, const std::string &methodName, lua_CFunction func) { // globalName.methodName = func lua_getglobal(L, globalName.c_str()); lua_pushcfunction(L, func); @@ -711,13 +719,13 @@ void LuaFunctionsLoader::registerMethod(lua_State* L, const std::string &globalN lua_pop(L, 1); } -void LuaFunctionsLoader::registerTable(lua_State* L, const std::string &tableName) { +void Lua::registerTable(lua_State* L, const std::string &tableName) { // _G[tableName] = {} lua_newtable(L); lua_setglobal(L, tableName.c_str()); } -void LuaFunctionsLoader::registerMetaMethod(lua_State* L, const std::string &className, const std::string &methodName, lua_CFunction func) { +void Lua::registerMetaMethod(lua_State* L, const std::string &className, const std::string &methodName, lua_CFunction func) { // className.metatable.methodName = func luaL_getmetatable(L, className.c_str()); lua_pushcfunction(L, func); @@ -727,7 +735,7 @@ void LuaFunctionsLoader::registerMetaMethod(lua_State* L, const std::string &cla lua_pop(L, 1); } -void LuaFunctionsLoader::registerVariable(lua_State* L, const std::string &tableName, const std::string &name, lua_Number value) { +void Lua::registerVariable(lua_State* L, const std::string &tableName, const std::string &name, lua_Number value) { // tableName.name = value lua_getglobal(L, tableName.c_str()); setField(L, name.c_str(), value); @@ -736,31 +744,31 @@ void LuaFunctionsLoader::registerVariable(lua_State* L, const std::string &table lua_pop(L, 1); } -void LuaFunctionsLoader::registerGlobalBoolean(lua_State* L, const std::string &name, bool value) { +void Lua::registerGlobalBoolean(lua_State* L, const std::string &name, bool value) { // _G[name] = value pushBoolean(L, value); lua_setglobal(L, name.c_str()); } -void LuaFunctionsLoader::registerGlobalMethod(lua_State* L, const std::string &functionName, lua_CFunction func) { +void Lua::registerGlobalMethod(lua_State* L, const std::string &functionName, lua_CFunction func) { // _G[functionName] = func lua_pushcfunction(L, func); lua_setglobal(L, functionName.c_str()); } -void LuaFunctionsLoader::registerGlobalVariable(lua_State* L, const std::string &name, lua_Number value) { +void Lua::registerGlobalVariable(lua_State* L, const std::string &name, lua_Number value) { // _G[name] = value lua_pushnumber(L, value); lua_setglobal(L, name.c_str()); } -void LuaFunctionsLoader::registerGlobalString(lua_State* L, const std::string &variable, const std::string &name) { +void Lua::registerGlobalString(lua_State* L, const std::string &variable, const std::string &name) { // Example: registerGlobalString(L, "VARIABLE_NAME", "variable string"); pushString(L, name); lua_setglobal(L, variable.c_str()); } -std::string LuaFunctionsLoader::escapeString(const std::string &string) { +std::string Lua::escapeString(const std::string &string) { std::string s = string; replaceString(s, "\\", "\\\\"); replaceString(s, "\"", "\\\""); @@ -769,17 +777,17 @@ std::string LuaFunctionsLoader::escapeString(const std::string &string) { return s; } -int LuaFunctionsLoader::luaUserdataCompare(lua_State* L) { +int Lua::luaUserdataCompare(lua_State* L) { pushBoolean(L, getUserdata(L, 1) == getUserdata(L, 2)); return 1; } -void LuaFunctionsLoader::registerSharedClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction) { +void Lua::registerSharedClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction) { registerClass(L, className, baseClass, newFunction); registerMetaMethod(L, className, "__gc", luaGarbageCollection); } -int LuaFunctionsLoader::luaGarbageCollection(lua_State* L) { +int Lua::luaGarbageCollection(lua_State* L) { const auto objPtr = static_cast*>(lua_touserdata(L, 1)); if (objPtr) { objPtr->reset(); @@ -787,7 +795,7 @@ int LuaFunctionsLoader::luaGarbageCollection(lua_State* L) { return 0; } -int LuaFunctionsLoader::validateDispatcherContext(std::string_view fncName) { +int Lua::validateDispatcherContext(std::string_view fncName) { if (DispatcherContext::isOn() && g_dispatcher().context().isAsync()) { g_logger().warn("[{}] The call to lua was ignored because the '{}' task is trying to communicate while in async mode.", fncName, g_dispatcher().context().getName()); return LUA_ERRRUN; diff --git a/src/lua/functions/lua_functions_loader.hpp b/src/lua/functions/lua_functions_loader.hpp index 9c5b65c14bb..68cfeb45c51 100644 --- a/src/lua/functions/lua_functions_loader.hpp +++ b/src/lua/functions/lua_functions_loader.hpp @@ -26,11 +26,13 @@ class Guild; class Zone; class KV; +using lua_Number = double; + struct LuaVariant; #define reportErrorFunc(a) reportError(__FUNCTION__, a, true) -class LuaFunctionsLoader { +class Lua { public: static void load(lua_State* L); @@ -42,6 +44,7 @@ class LuaFunctionsLoader { static void pushThing(lua_State* L, const std::shared_ptr &thing); static void pushVariant(lua_State* L, const LuaVariant &var); static void pushString(lua_State* L, const std::string &value); + static void pushNumber(lua_State* L, lua_Number value); static void pushCallback(lua_State* L, int32_t callback); static void pushCylinder(lua_State* L, const std::shared_ptr &cylinder); @@ -60,23 +63,29 @@ class LuaFunctionsLoader { static void setCreatureMetatable(lua_State* L, int32_t index, const std::shared_ptr &creature); template - static std::enable_if_t, T> - getNumber(lua_State* L, int32_t arg) { - return static_cast(static_cast(lua_tonumber(L, arg))); - } - template - static std::enable_if_t || std::is_floating_point_v, T> getNumber(lua_State* L, int32_t arg) { + static T getNumber(lua_State* L, int32_t arg, std::source_location location = std::source_location::current()) { auto number = lua_tonumber(L, arg); - // If there is overflow, we return the value 0 - if constexpr (std::is_integral_v && std::is_unsigned_v) { - if (number < 0) { - g_logger().debug("[{}] overflow, setting to default signed value (0)", __FUNCTION__); - number = T(0); + + if constexpr (std::is_enum_v) { + return static_cast(static_cast(number)); + } + + if constexpr (std::is_integral_v) { + if constexpr (std::is_unsigned_v) { + if (number < 0) { + g_logger().debug("[{}] overflow, setting to default unsigned value (0), called line: {}:{}, in {}", __FUNCTION__, location.line(), location.column(), location.function_name()); + return T(0); + } } + return static_cast(number); + } + if constexpr (std::is_floating_point_v) { + return static_cast(number); } - return static_cast(number); + return T {}; } + template static T getNumber(lua_State* L, int32_t arg, T defaultValue) { const auto parameters = lua_gettop(L); @@ -228,7 +237,6 @@ class LuaFunctionsLoader { new (userData) std::shared_ptr(value); } -protected: static void registerClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction = nullptr); static void registerSharedClass(lua_State* L, const std::string &className, const std::string &baseClass, lua_CFunction newFunction = nullptr); static void registerMethod(lua_State* L, const std::string &globalName, const std::string &methodName, lua_CFunction func); diff --git a/src/lua/functions/map/house_functions.cpp b/src/lua/functions/map/house_functions.cpp index 708b9233a3a..10ebbc2cf0c 100644 --- a/src/lua/functions/map/house_functions.cpp +++ b/src/lua/functions/map/house_functions.cpp @@ -15,12 +15,51 @@ #include "game/movement/position.hpp" #include "io/iologindata.hpp" #include "map/house/house.hpp" +#include "creatures/players/player.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void HouseFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "House", "", HouseFunctions::luaHouseCreate); + Lua::registerMetaMethod(L, "House", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "House", "getId", HouseFunctions::luaHouseGetId); + Lua::registerMethod(L, "House", "getName", HouseFunctions::luaHouseGetName); + Lua::registerMethod(L, "House", "getTown", HouseFunctions::luaHouseGetTown); + Lua::registerMethod(L, "House", "getExitPosition", HouseFunctions::luaHouseGetExitPosition); + Lua::registerMethod(L, "House", "getRent", HouseFunctions::luaHouseGetRent); + Lua::registerMethod(L, "House", "getPrice", HouseFunctions::luaHouseGetPrice); + + Lua::registerMethod(L, "House", "getOwnerGuid", HouseFunctions::luaHouseGetOwnerGuid); + Lua::registerMethod(L, "House", "setHouseOwner", HouseFunctions::luaHouseSetHouseOwner); + Lua::registerMethod(L, "House", "setNewOwnerGuid", HouseFunctions::luaHouseSetNewOwnerGuid); + Lua::registerMethod(L, "House", "hasItemOnTile", HouseFunctions::luaHouseHasItemOnTile); + Lua::registerMethod(L, "House", "hasNewOwnership", HouseFunctions::luaHouseHasNewOwnership); + Lua::registerMethod(L, "House", "startTrade", HouseFunctions::luaHouseStartTrade); + + Lua::registerMethod(L, "House", "getBeds", HouseFunctions::luaHouseGetBeds); + Lua::registerMethod(L, "House", "getBedCount", HouseFunctions::luaHouseGetBedCount); + + Lua::registerMethod(L, "House", "getDoors", HouseFunctions::luaHouseGetDoors); + Lua::registerMethod(L, "House", "getDoorCount", HouseFunctions::luaHouseGetDoorCount); + Lua::registerMethod(L, "House", "getDoorIdByPosition", HouseFunctions::luaHouseGetDoorIdByPosition); + + Lua::registerMethod(L, "House", "getTiles", HouseFunctions::luaHouseGetTiles); + Lua::registerMethod(L, "House", "getItems", HouseFunctions::luaHouseGetItems); + Lua::registerMethod(L, "House", "getTileCount", HouseFunctions::luaHouseGetTileCount); + + Lua::registerMethod(L, "House", "canEditAccessList", HouseFunctions::luaHouseCanEditAccessList); + Lua::registerMethod(L, "House", "getAccessList", HouseFunctions::luaHouseGetAccessList); + Lua::registerMethod(L, "House", "setAccessList", HouseFunctions::luaHouseSetAccessList); + + Lua::registerMethod(L, "House", "kickPlayer", HouseFunctions::luaHouseKickPlayer); + Lua::registerMethod(L, "House", "isInvited", HouseFunctions::luaHouseIsInvited); +} int HouseFunctions::luaHouseCreate(lua_State* L) { // House(id) - if (const auto &house = g_game().map.houses.getHouse(getNumber(L, 2))) { - pushUserdata(L, house); - setMetatable(L, -1, "House"); + if (const auto &house = g_game().map.houses.getHouse(Lua::getNumber(L, 2))) { + Lua::pushUserdata(L, house); + Lua::setMetatable(L, -1, "House"); } else { lua_pushnil(L); } @@ -29,7 +68,7 @@ int HouseFunctions::luaHouseCreate(lua_State* L) { int HouseFunctions::luaHouseGetId(lua_State* L) { // house:getId() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getId()); } else { lua_pushnil(L); @@ -39,8 +78,8 @@ int HouseFunctions::luaHouseGetId(lua_State* L) { int HouseFunctions::luaHouseGetName(lua_State* L) { // house:getName() - if (const auto &house = getUserdataShared(L, 1)) { - pushString(L, house->getName()); + if (const auto &house = Lua::getUserdataShared(L, 1)) { + Lua::pushString(L, house->getName()); } else { lua_pushnil(L); } @@ -49,15 +88,15 @@ int HouseFunctions::luaHouseGetName(lua_State* L) { int HouseFunctions::luaHouseGetTown(lua_State* L) { // house:getTown() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } if (const auto &town = g_game().map.towns.getTown(house->getTownId())) { - pushUserdata(L, town); - setMetatable(L, -1, "Town"); + Lua::pushUserdata(L, town); + Lua::setMetatable(L, -1, "Town"); } else { lua_pushnil(L); } @@ -66,8 +105,8 @@ int HouseFunctions::luaHouseGetTown(lua_State* L) { int HouseFunctions::luaHouseGetExitPosition(lua_State* L) { // house:getExitPosition() - if (const auto &house = getUserdataShared(L, 1)) { - pushPosition(L, house->getEntryPosition()); + if (const auto &house = Lua::getUserdataShared(L, 1)) { + Lua::pushPosition(L, house->getEntryPosition()); } else { lua_pushnil(L); } @@ -76,7 +115,7 @@ int HouseFunctions::luaHouseGetExitPosition(lua_State* L) { int HouseFunctions::luaHouseGetRent(lua_State* L) { // house:getRent() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getRent()); } else { lua_pushnil(L); @@ -86,9 +125,9 @@ int HouseFunctions::luaHouseGetRent(lua_State* L) { int HouseFunctions::luaHouseGetPrice(lua_State* L) { // house:getPrice() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { - reportErrorFunc("House not found"); + Lua::reportErrorFunc("House not found"); lua_pushnumber(L, 0); return 1; } @@ -99,7 +138,7 @@ int HouseFunctions::luaHouseGetPrice(lua_State* L) { int HouseFunctions::luaHouseGetOwnerGuid(lua_State* L) { // house:getOwnerGuid() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getOwner()); } else { lua_pushnil(L); @@ -109,23 +148,23 @@ int HouseFunctions::luaHouseGetOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseSetHouseOwner(lua_State* L) { // house:setHouseOwner(guid[, updateDatabase = true]) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { - reportErrorFunc("House not found"); + Lua::reportErrorFunc("House not found"); lua_pushnil(L); return 1; } - const uint32_t guid = getNumber(L, 2); - const bool updateDatabase = getBoolean(L, 3, true); + const uint32_t guid = Lua::getNumber(L, 2); + const bool updateDatabase = Lua::getBoolean(L, 3, true); house->setOwner(guid, updateDatabase); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int HouseFunctions::luaHouseSetNewOwnerGuid(lua_State* L) { // house:setNewOwnerGuid(guid[, updateDatabase = true]) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (house) { auto isTransferOnRestart = g_configManager().getBoolean(TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART); if (isTransferOnRestart && house->hasNewOwnership()) { @@ -137,9 +176,9 @@ int HouseFunctions::luaHouseSetNewOwnerGuid(lua_State* L) { return 1; } - const auto guid = getNumber(L, 2, 0); + const auto guid = Lua::getNumber(L, 2, 0); house->setNewOwnerGuid(guid, false); - pushBoolean(L, true); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } @@ -148,36 +187,36 @@ int HouseFunctions::luaHouseSetNewOwnerGuid(lua_State* L) { int HouseFunctions::luaHouseHasItemOnTile(lua_State* L) { // house:hasItemOnTile() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { - reportErrorFunc("House not found"); + Lua::reportErrorFunc("House not found"); lua_pushnil(L); return 1; } - pushBoolean(L, house->hasItemOnTile()); + Lua::pushBoolean(L, house->hasItemOnTile()); return 1; } int HouseFunctions::luaHouseHasNewOwnership(lua_State* L) { // house:hasNewOwnership(guid) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { - reportErrorFunc("House not found"); + Lua::reportErrorFunc("House not found"); lua_pushnil(L); return 1; } auto isTransferOnRestart = g_configManager().getBoolean(TOGGLE_HOUSE_TRANSFER_ON_SERVER_RESTART); - pushBoolean(L, isTransferOnRestart && house->hasNewOwnership()); + Lua::pushBoolean(L, isTransferOnRestart && house->hasNewOwnership()); return 1; } int HouseFunctions::luaHouseStartTrade(lua_State* L) { // house:startTrade(player, tradePartner) - const auto &house = getUserdataShared(L, 1); - const auto &player = getUserdataShared(L, 2); - const auto &tradePartner = getUserdataShared(L, 3); + const auto &house = Lua::getUserdataShared(L, 1); + const auto &player = Lua::getUserdataShared(L, 2); + const auto &tradePartner = Lua::getUserdataShared(L, 3); if (!player || !tradePartner || !house) { lua_pushnil(L); @@ -229,7 +268,7 @@ int HouseFunctions::luaHouseStartTrade(lua_State* L) { int HouseFunctions::luaHouseGetBeds(lua_State* L) { // house:getBeds() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -240,8 +279,8 @@ int HouseFunctions::luaHouseGetBeds(lua_State* L) { int index = 0; for (const auto &bedItem : beds) { - pushUserdata(L, bedItem); - setItemMetatable(L, -1, bedItem); + Lua::pushUserdata(L, bedItem); + Lua::setItemMetatable(L, -1, bedItem); lua_rawseti(L, -2, ++index); } return 1; @@ -249,7 +288,7 @@ int HouseFunctions::luaHouseGetBeds(lua_State* L) { int HouseFunctions::luaHouseGetBedCount(lua_State* L) { // house:getBedCount() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getBedCount()); } else { lua_pushnil(L); @@ -259,7 +298,7 @@ int HouseFunctions::luaHouseGetBedCount(lua_State* L) { int HouseFunctions::luaHouseGetDoors(lua_State* L) { // house:getDoors() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -270,8 +309,8 @@ int HouseFunctions::luaHouseGetDoors(lua_State* L) { int index = 0; for (const auto &door : doors) { - pushUserdata(L, door); - setItemMetatable(L, -1, door); + Lua::pushUserdata(L, door); + Lua::setItemMetatable(L, -1, door); lua_rawseti(L, -2, ++index); } return 1; @@ -279,7 +318,7 @@ int HouseFunctions::luaHouseGetDoors(lua_State* L) { int HouseFunctions::luaHouseGetDoorCount(lua_State* L) { // house:getDoorCount() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getDoors().size()); } else { lua_pushnil(L); @@ -289,13 +328,13 @@ int HouseFunctions::luaHouseGetDoorCount(lua_State* L) { int HouseFunctions::luaHouseGetDoorIdByPosition(lua_State* L) { // house:getDoorIdByPosition(position) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } - const auto &door = house->getDoorByPosition(getPosition(L, 2)); + const auto &door = house->getDoorByPosition(Lua::getPosition(L, 2)); if (door) { lua_pushnumber(L, door->getDoorId()); } else { @@ -306,7 +345,7 @@ int HouseFunctions::luaHouseGetDoorIdByPosition(lua_State* L) { int HouseFunctions::luaHouseGetTiles(lua_State* L) { // house:getTiles() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -317,8 +356,8 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { int index = 0; for (const auto &tile : tiles) { - pushUserdata(L, tile); - setMetatable(L, -1, "Tile"); + Lua::pushUserdata(L, tile); + Lua::setMetatable(L, -1, "Tile"); lua_rawseti(L, -2, ++index); } return 1; @@ -326,7 +365,7 @@ int HouseFunctions::luaHouseGetTiles(lua_State* L) { int HouseFunctions::luaHouseGetItems(lua_State* L) { // house:getItems() - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; @@ -340,8 +379,8 @@ int HouseFunctions::luaHouseGetItems(lua_State* L) { const TileItemVector* itemVector = tile->getItemList(); if (itemVector) { for (const auto &item : *itemVector) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); lua_rawseti(L, -2, ++index); } } @@ -351,7 +390,7 @@ int HouseFunctions::luaHouseGetItems(lua_State* L) { int HouseFunctions::luaHouseGetTileCount(lua_State* L) { // house:getTileCount() - if (const auto &house = getUserdataShared(L, 1)) { + if (const auto &house = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, house->getTiles().size()); } else { lua_pushnil(L); @@ -361,95 +400,95 @@ int HouseFunctions::luaHouseGetTileCount(lua_State* L) { int HouseFunctions::luaHouseCanEditAccessList(lua_State* L) { // house:canEditAccessList(listId, player) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } - const uint32_t listId = getNumber(L, 2); + const uint32_t listId = Lua::getNumber(L, 2); - const auto &player = getPlayer(L, 3); + const auto &player = Lua::getPlayer(L, 3); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - pushBoolean(L, house->canEditAccessList(listId, player)); + Lua::pushBoolean(L, house->canEditAccessList(listId, player)); return 1; } int HouseFunctions::luaHouseGetAccessList(lua_State* L) { // house:getAccessList(listId) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } std::string list; - const uint32_t listId = getNumber(L, 2); + const uint32_t listId = Lua::getNumber(L, 2); if (house->getAccessList(listId, list)) { - pushString(L, list); + Lua::pushString(L, list); } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int HouseFunctions::luaHouseSetAccessList(lua_State* L) { // house:setAccessList(listId, list) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } - const uint32_t listId = getNumber(L, 2); - const std::string &list = getString(L, 3); + const uint32_t listId = Lua::getNumber(L, 2); + const std::string &list = Lua::getString(L, 3); house->setAccessList(listId, list); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int HouseFunctions::luaHouseKickPlayer(lua_State* L) { // house:kickPlayer(player, targetPlayer) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc("Player is nullptr"); + Lua::reportErrorFunc("Player is nullptr"); return 1; } - const auto &targetPlayer = getPlayer(L, 3); + const auto &targetPlayer = Lua::getPlayer(L, 3); if (!targetPlayer) { - reportErrorFunc("Target player is nullptr"); + Lua::reportErrorFunc("Target player is nullptr"); return 1; } - pushBoolean(L, house->kickPlayer(player, targetPlayer)); + Lua::pushBoolean(L, house->kickPlayer(player, targetPlayer)); return 1; } int HouseFunctions::luaHouseIsInvited(lua_State* L) { // house:isInvited(player) - const auto &house = getUserdataShared(L, 1); + const auto &house = Lua::getUserdataShared(L, 1); if (!house) { lua_pushnil(L); return 1; } - const auto &player = getPlayer(L, 2); + const auto &player = Lua::getPlayer(L, 2); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } - pushBoolean(L, house->isInvited(player)); + Lua::pushBoolean(L, house->isInvited(player)); return 1; } diff --git a/src/lua/functions/map/house_functions.hpp b/src/lua/functions/map/house_functions.hpp index 8d527bf6354..bb7200a5b3f 100644 --- a/src/lua/functions/map/house_functions.hpp +++ b/src/lua/functions/map/house_functions.hpp @@ -9,52 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class HouseFunctions final : LuaScriptInterface { +class HouseFunctions { public: - explicit HouseFunctions(lua_State* L) : - LuaScriptInterface("HouseFunctions") { - init(L); - } - ~HouseFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "House", "", HouseFunctions::luaHouseCreate); - registerMetaMethod(L, "House", "__eq", HouseFunctions::luaUserdataCompare); - - registerMethod(L, "House", "getId", HouseFunctions::luaHouseGetId); - registerMethod(L, "House", "getName", HouseFunctions::luaHouseGetName); - registerMethod(L, "House", "getTown", HouseFunctions::luaHouseGetTown); - registerMethod(L, "House", "getExitPosition", HouseFunctions::luaHouseGetExitPosition); - registerMethod(L, "House", "getRent", HouseFunctions::luaHouseGetRent); - registerMethod(L, "House", "getPrice", HouseFunctions::luaHouseGetPrice); - - registerMethod(L, "House", "getOwnerGuid", HouseFunctions::luaHouseGetOwnerGuid); - registerMethod(L, "House", "setHouseOwner", HouseFunctions::luaHouseSetHouseOwner); - registerMethod(L, "House", "setNewOwnerGuid", HouseFunctions::luaHouseSetNewOwnerGuid); - registerMethod(L, "House", "hasItemOnTile", HouseFunctions::luaHouseHasItemOnTile); - registerMethod(L, "House", "hasNewOwnership", HouseFunctions::luaHouseHasNewOwnership); - registerMethod(L, "House", "startTrade", HouseFunctions::luaHouseStartTrade); - - registerMethod(L, "House", "getBeds", HouseFunctions::luaHouseGetBeds); - registerMethod(L, "House", "getBedCount", HouseFunctions::luaHouseGetBedCount); - - registerMethod(L, "House", "getDoors", HouseFunctions::luaHouseGetDoors); - registerMethod(L, "House", "getDoorCount", HouseFunctions::luaHouseGetDoorCount); - registerMethod(L, "House", "getDoorIdByPosition", HouseFunctions::luaHouseGetDoorIdByPosition); - - registerMethod(L, "House", "getTiles", HouseFunctions::luaHouseGetTiles); - registerMethod(L, "House", "getItems", HouseFunctions::luaHouseGetItems); - registerMethod(L, "House", "getTileCount", HouseFunctions::luaHouseGetTileCount); - - registerMethod(L, "House", "canEditAccessList", HouseFunctions::luaHouseCanEditAccessList); - registerMethod(L, "House", "getAccessList", HouseFunctions::luaHouseGetAccessList); - registerMethod(L, "House", "setAccessList", HouseFunctions::luaHouseSetAccessList); - - registerMethod(L, "House", "kickPlayer", HouseFunctions::luaHouseKickPlayer); - registerMethod(L, "House", "isInvited", HouseFunctions::luaHouseIsInvited); - } + static void init(lua_State* L); private: static int luaHouseCreate(lua_State* L); diff --git a/src/lua/functions/map/position_functions.cpp b/src/lua/functions/map/position_functions.cpp index b182ee5e447..a9de71fde2b 100644 --- a/src/lua/functions/map/position_functions.cpp +++ b/src/lua/functions/map/position_functions.cpp @@ -14,26 +14,50 @@ #include "creatures/players/player.hpp" #include "game/game.hpp" #include "game/movement/position.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void PositionFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Position", "", PositionFunctions::luaPositionCreate); + Lua::registerMetaMethod(L, "Position", "__add", PositionFunctions::luaPositionAdd); + Lua::registerMetaMethod(L, "Position", "__sub", PositionFunctions::luaPositionSub); + Lua::registerMetaMethod(L, "Position", "__eq", PositionFunctions::luaPositionCompare); + + Lua::registerMethod(L, "Position", "getDistance", PositionFunctions::luaPositionGetDistance); + Lua::registerMethod(L, "Position", "getPathTo", PositionFunctions::luaPositionGetPathTo); + Lua::registerMethod(L, "Position", "isSightClear", PositionFunctions::luaPositionIsSightClear); + + Lua::registerMethod(L, "Position", "getTile", PositionFunctions::luaPositionGetTile); + Lua::registerMethod(L, "Position", "getZones", PositionFunctions::luaPositionGetZones); + + Lua::registerMethod(L, "Position", "sendMagicEffect", PositionFunctions::luaPositionSendMagicEffect); + Lua::registerMethod(L, "Position", "removeMagicEffect", PositionFunctions::luaPositionRemoveMagicEffect); + Lua::registerMethod(L, "Position", "sendDistanceEffect", PositionFunctions::luaPositionSendDistanceEffect); + + Lua::registerMethod(L, "Position", "sendSingleSoundEffect", PositionFunctions::luaPositionSendSingleSoundEffect); + Lua::registerMethod(L, "Position", "sendDoubleSoundEffect", PositionFunctions::luaPositionSendDoubleSoundEffect); + + Lua::registerMethod(L, "Position", "toString", PositionFunctions::luaPositionToString); +} int PositionFunctions::luaPositionCreate(lua_State* L) { // Position([x = 0[, y = 0[, z = 0[, stackpos = 0]]]]) // Position([position]) if (lua_gettop(L) <= 1) { - pushPosition(L, Position()); + Lua::pushPosition(L, Position()); return 1; } int32_t stackpos; - if (isTable(L, 2)) { - const Position &position = getPosition(L, 2, stackpos); - pushPosition(L, position, stackpos); + if (Lua::isTable(L, 2)) { + const Position &position = Lua::getPosition(L, 2, stackpos); + Lua::pushPosition(L, position, stackpos); } else { - const auto x = getNumber(L, 2, 0); - const auto y = getNumber(L, 3, 0); - const auto z = getNumber(L, 4, 0); - stackpos = getNumber(L, 5, 0); + const auto x = Lua::getNumber(L, 2, 0); + const auto y = Lua::getNumber(L, 3, 0); + const auto z = Lua::getNumber(L, 4, 0); + stackpos = Lua::getNumber(L, 5, 0); - pushPosition(L, Position(x, y, z), stackpos); + Lua::pushPosition(L, Position(x, y, z), stackpos); } return 1; } @@ -41,62 +65,62 @@ int PositionFunctions::luaPositionCreate(lua_State* L) { int PositionFunctions::luaPositionAdd(lua_State* L) { // positionValue = position + positionEx int32_t stackpos; - const Position &position = getPosition(L, 1, stackpos); + const Position &position = Lua::getPosition(L, 1, stackpos); Position positionEx; if (stackpos == 0) { - positionEx = getPosition(L, 2, stackpos); + positionEx = Lua::getPosition(L, 2, stackpos); } else { - positionEx = getPosition(L, 2); + positionEx = Lua::getPosition(L, 2); } - pushPosition(L, position + positionEx, stackpos); + Lua::pushPosition(L, position + positionEx, stackpos); return 1; } int PositionFunctions::luaPositionSub(lua_State* L) { // positionValue = position - positionEx int32_t stackpos; - const Position &position = getPosition(L, 1, stackpos); + const Position &position = Lua::getPosition(L, 1, stackpos); Position positionEx; if (stackpos == 0) { - positionEx = getPosition(L, 2, stackpos); + positionEx = Lua::getPosition(L, 2, stackpos); } else { - positionEx = getPosition(L, 2); + positionEx = Lua::getPosition(L, 2); } - pushPosition(L, position - positionEx, stackpos); + Lua::pushPosition(L, position - positionEx, stackpos); return 1; } int PositionFunctions::luaPositionCompare(lua_State* L) { // position == positionEx - const Position &positionEx = getPosition(L, 2); - const Position &position = getPosition(L, 1); - pushBoolean(L, position == positionEx); + const Position &positionEx = Lua::getPosition(L, 2); + const Position &position = Lua::getPosition(L, 1); + Lua::pushBoolean(L, position == positionEx); return 1; } int PositionFunctions::luaPositionGetDistance(lua_State* L) { // position:getDistance(positionEx) - const Position &positionEx = getPosition(L, 2); - const Position &position = getPosition(L, 1); + const Position &positionEx = Lua::getPosition(L, 2); + const Position &position = Lua::getPosition(L, 1); lua_pushnumber(L, std::max(std::max(std::abs(Position::getDistanceX(position, positionEx)), std::abs(Position::getDistanceY(position, positionEx))), std::abs(Position::getDistanceZ(position, positionEx)))); return 1; } int PositionFunctions::luaPositionGetPathTo(lua_State* L) { // position:getPathTo(pos[, minTargetDist = 0[, maxTargetDist = 1[, fullPathSearch = true[, clearSight = true[, maxSearchDist = 0]]]]]) - const Position &pos = getPosition(L, 1); - const Position &position = getPosition(L, 2); + const Position &pos = Lua::getPosition(L, 1); + const Position &position = Lua::getPosition(L, 2); FindPathParams fpp; - fpp.minTargetDist = getNumber(L, 3, 0); - fpp.maxTargetDist = getNumber(L, 4, 1); - fpp.fullPathSearch = getBoolean(L, 5, fpp.fullPathSearch); - fpp.clearSight = getBoolean(L, 6, fpp.clearSight); - fpp.maxSearchDist = getNumber(L, 7, fpp.maxSearchDist); + fpp.minTargetDist = Lua::getNumber(L, 3, 0); + fpp.maxTargetDist = Lua::getNumber(L, 4, 1); + fpp.fullPathSearch = Lua::getBoolean(L, 5, fpp.fullPathSearch); + fpp.clearSight = Lua::getBoolean(L, 6, fpp.clearSight); + fpp.maxSearchDist = Lua::getNumber(L, 7, fpp.maxSearchDist); std::vector dirList; if (g_game().map.getPathMatching(pos, dirList, FrozenPathingConditionCall(position), fpp)) { @@ -108,30 +132,30 @@ int PositionFunctions::luaPositionGetPathTo(lua_State* L) { lua_rawseti(L, -2, ++index); } } else { - pushBoolean(L, false); + Lua::pushBoolean(L, false); } return 1; } int PositionFunctions::luaPositionIsSightClear(lua_State* L) { // position:isSightClear(positionEx[, sameFloor = true]) - const bool sameFloor = getBoolean(L, 3, true); - const Position &positionEx = getPosition(L, 2); - const Position &position = getPosition(L, 1); - pushBoolean(L, g_game().isSightClear(position, positionEx, sameFloor)); + const bool sameFloor = Lua::getBoolean(L, 3, true); + const Position &positionEx = Lua::getPosition(L, 2); + const Position &position = Lua::getPosition(L, 1); + Lua::pushBoolean(L, g_game().isSightClear(position, positionEx, sameFloor)); return 1; } int PositionFunctions::luaPositionGetTile(lua_State* L) { // position:getTile() - const Position &position = getPosition(L, 1); - pushUserdata(L, g_game().map.getTile(position)); + const Position &position = Lua::getPosition(L, 1); + Lua::pushUserdata(L, g_game().map.getTile(position)); return 1; } int PositionFunctions::luaPositionGetZones(lua_State* L) { // position:getZones() - const Position &position = getPosition(L, 1); + const Position &position = Lua::getPosition(L, 1); const auto &tile = g_game().map.getTile(position); if (tile == nullptr) { lua_pushnil(L); @@ -140,8 +164,8 @@ int PositionFunctions::luaPositionGetZones(lua_State* L) { int index = 0; for (const auto &zone : tile->getZones()) { index++; - pushUserdata(L, zone); - setMetatable(L, -1, "Zone"); + Lua::pushUserdata(L, zone); + Lua::setMetatable(L, -1, "Zone"); lua_rawseti(L, -2, index); } return 1; @@ -151,30 +175,30 @@ int PositionFunctions::luaPositionSendMagicEffect(lua_State* L) { // position:sendMagicEffect(magicEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 3) { - const auto &player = getPlayer(L, 3); + const auto &player = Lua::getPlayer(L, 3); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } spectators.emplace_back(player); } - MagicEffectClasses magicEffect = getNumber(L, 2); + MagicEffectClasses magicEffect = Lua::getNumber(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && !g_game().isMagicEffectRegistered(magicEffect)) { g_logger().warn("[PositionFunctions::luaPositionSendMagicEffect] An unregistered magic effect type with id '{}' was blocked to prevent client crash.", fmt::underlying(magicEffect)); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const Position &position = getPosition(L, 1); + const Position &position = Lua::getPosition(L, 1); if (!spectators.empty()) { Game::addMagicEffect(spectators, position, magicEffect); } else { g_game().addMagicEffect(position, magicEffect); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -182,30 +206,30 @@ int PositionFunctions::luaPositionRemoveMagicEffect(lua_State* L) { // position:removeMagicEffect(magicEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 3) { - const auto &player = getPlayer(L, 3); + const auto &player = Lua::getPlayer(L, 3); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } spectators.emplace_back(player); } - MagicEffectClasses magicEffect = getNumber(L, 2); + MagicEffectClasses magicEffect = Lua::getNumber(L, 2); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && !g_game().isMagicEffectRegistered(magicEffect)) { g_logger().warn("[PositionFunctions::luaPositionRemoveMagicEffect] An unregistered magic effect type with id '{}' was blocked to prevent client crash.", fmt::underlying(magicEffect)); - pushBoolean(L, false); + Lua::pushBoolean(L, false); return 1; } - const Position &position = getPosition(L, 1); + const Position &position = Lua::getPosition(L, 1); if (!spectators.empty()) { Game::removeMagicEffect(spectators, position, magicEffect); } else { g_game().removeMagicEffect(position, magicEffect); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } @@ -213,18 +237,18 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { // position:sendDistanceEffect(positionEx, distanceEffect[, player = nullptr]) CreatureVector spectators; if (lua_gettop(L) >= 4) { - const auto &player = getPlayer(L, 4); + const auto &player = Lua::getPlayer(L, 4); if (!player) { - reportErrorFunc(getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); + Lua::reportErrorFunc(Lua::getErrorDesc(LUA_ERROR_PLAYER_NOT_FOUND)); return 1; } spectators.emplace_back(player); } - const ShootType_t distanceEffect = getNumber(L, 3); - const Position &positionEx = getPosition(L, 2); - const Position &position = getPosition(L, 1); + const ShootType_t distanceEffect = Lua::getNumber(L, 3); + const Position &positionEx = Lua::getPosition(L, 2); + const Position &position = Lua::getPosition(L, 1); if (g_configManager().getBoolean(WARN_UNSAFE_SCRIPTS) && !g_game().isDistanceEffectRegistered(distanceEffect)) { g_logger().warn("[PositionFunctions::luaPositionSendDistanceEffect] An unregistered distance effect type with id '{}' was blocked to prevent client crash.", fmt::underlying(distanceEffect)); return 1; @@ -236,36 +260,36 @@ int PositionFunctions::luaPositionSendDistanceEffect(lua_State* L) { g_game().addDistanceEffect(position, positionEx, distanceEffect); } - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PositionFunctions::luaPositionSendSingleSoundEffect(lua_State* L) { // position:sendSingleSoundEffect(soundId[, actor = nullptr]) - const Position &position = getPosition(L, 1); - const SoundEffect_t soundEffect = getNumber(L, 2); - const auto actor = getCreature(L, 3); + const Position &position = Lua::getPosition(L, 1); + const SoundEffect_t soundEffect = Lua::getNumber(L, 2); + const auto actor = Lua::getCreature(L, 3); g_game().sendSingleSoundEffect(position, soundEffect, actor); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PositionFunctions::luaPositionSendDoubleSoundEffect(lua_State* L) { // position:sendDoubleSoundEffect(mainSoundId, secondarySoundId[, actor = nullptr]) - const Position &position = getPosition(L, 1); - const SoundEffect_t mainSoundEffect = getNumber(L, 2); - const SoundEffect_t secondarySoundEffect = getNumber(L, 3); - const auto &actor = getCreature(L, 4); + const Position &position = Lua::getPosition(L, 1); + const SoundEffect_t mainSoundEffect = Lua::getNumber(L, 2); + const SoundEffect_t secondarySoundEffect = Lua::getNumber(L, 3); + const auto &actor = Lua::getCreature(L, 4); g_game().sendDoubleSoundEffect(position, mainSoundEffect, secondarySoundEffect, actor); - pushBoolean(L, true); + Lua::pushBoolean(L, true); return 1; } int PositionFunctions::luaPositionToString(lua_State* L) { // position:toString() - const Position &position = getPosition(L, 1); - pushString(L, position.toString()); + const Position &position = Lua::getPosition(L, 1); + Lua::pushString(L, position.toString()); return 1; } diff --git a/src/lua/functions/map/position_functions.hpp b/src/lua/functions/map/position_functions.hpp index 4bb6917aecc..eb864a5417f 100644 --- a/src/lua/functions/map/position_functions.hpp +++ b/src/lua/functions/map/position_functions.hpp @@ -9,38 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class PositionFunctions final : LuaScriptInterface { +class PositionFunctions { public: - explicit PositionFunctions(lua_State* L) : - LuaScriptInterface("PositionFunctions") { - init(L); - } - ~PositionFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Position", "", PositionFunctions::luaPositionCreate); - registerMetaMethod(L, "Position", "__add", PositionFunctions::luaPositionAdd); - registerMetaMethod(L, "Position", "__sub", PositionFunctions::luaPositionSub); - registerMetaMethod(L, "Position", "__eq", PositionFunctions::luaPositionCompare); - - registerMethod(L, "Position", "getDistance", PositionFunctions::luaPositionGetDistance); - registerMethod(L, "Position", "getPathTo", PositionFunctions::luaPositionGetPathTo); - registerMethod(L, "Position", "isSightClear", PositionFunctions::luaPositionIsSightClear); - - registerMethod(L, "Position", "getTile", PositionFunctions::luaPositionGetTile); - registerMethod(L, "Position", "getZones", PositionFunctions::luaPositionGetZones); - - registerMethod(L, "Position", "sendMagicEffect", PositionFunctions::luaPositionSendMagicEffect); - registerMethod(L, "Position", "removeMagicEffect", PositionFunctions::luaPositionRemoveMagicEffect); - registerMethod(L, "Position", "sendDistanceEffect", PositionFunctions::luaPositionSendDistanceEffect); - - registerMethod(L, "Position", "sendSingleSoundEffect", PositionFunctions::luaPositionSendSingleSoundEffect); - registerMethod(L, "Position", "sendDoubleSoundEffect", PositionFunctions::luaPositionSendDoubleSoundEffect); - - registerMethod(L, "Position", "toString", PositionFunctions::luaPositionToString); - } + static void init(lua_State* L); private: static int luaPositionCreate(lua_State* L); diff --git a/src/lua/functions/map/teleport_functions.cpp b/src/lua/functions/map/teleport_functions.cpp index 84eafe21ba4..c3e6f60effc 100644 --- a/src/lua/functions/map/teleport_functions.cpp +++ b/src/lua/functions/map/teleport_functions.cpp @@ -11,16 +11,25 @@ #include "game/movement/teleport.hpp" #include "items/item.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void TeleportFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Teleport", "Item", TeleportFunctions::luaTeleportCreate); + Lua::registerMetaMethod(L, "Teleport", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Teleport", "getDestination", TeleportFunctions::luaTeleportGetDestination); + Lua::registerMethod(L, "Teleport", "setDestination", TeleportFunctions::luaTeleportSetDestination); +} // Teleport int TeleportFunctions::luaTeleportCreate(lua_State* L) { // Teleport(uid) - const uint32_t id = getNumber(L, 2); + const uint32_t id = Lua::getNumber(L, 2); - const auto &item = getScriptEnv()->getItemByUID(id); + const auto &item = Lua::getScriptEnv()->getItemByUID(id); if (item && item->getTeleport()) { - pushUserdata(L, item); - setMetatable(L, -1, "Teleport"); + Lua::pushUserdata(L, item); + Lua::setMetatable(L, -1, "Teleport"); } else { lua_pushnil(L); } @@ -29,9 +38,9 @@ int TeleportFunctions::luaTeleportCreate(lua_State* L) { int TeleportFunctions::luaTeleportGetDestination(lua_State* L) { // teleport:getDestination() - const auto &teleport = getUserdataShared(L, 1); + const auto &teleport = Lua::getUserdataShared(L, 1); if (teleport) { - pushPosition(L, teleport->getDestPos()); + Lua::pushPosition(L, teleport->getDestPos()); } else { lua_pushnil(L); } @@ -40,10 +49,10 @@ int TeleportFunctions::luaTeleportGetDestination(lua_State* L) { int TeleportFunctions::luaTeleportSetDestination(lua_State* L) { // teleport:setDestination(position) - const auto &teleport = getUserdataShared(L, 1); + const auto &teleport = Lua::getUserdataShared(L, 1); if (teleport) { - teleport->setDestPos(getPosition(L, 2)); - pushBoolean(L, true); + teleport->setDestPos(Lua::getPosition(L, 2)); + Lua::pushBoolean(L, true); } else { lua_pushnil(L); } diff --git a/src/lua/functions/map/teleport_functions.hpp b/src/lua/functions/map/teleport_functions.hpp index 57f59a70315..636590c1491 100644 --- a/src/lua/functions/map/teleport_functions.hpp +++ b/src/lua/functions/map/teleport_functions.hpp @@ -9,23 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class TeleportFunctions final : LuaScriptInterface { +class TeleportFunctions { public: - explicit TeleportFunctions(lua_State* L) : - LuaScriptInterface("TeleportFunctions") { - init(L); - } - ~TeleportFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Teleport", "Item", TeleportFunctions::luaTeleportCreate); - registerMetaMethod(L, "Teleport", "__eq", TeleportFunctions::luaUserdataCompare); - - registerMethod(L, "Teleport", "getDestination", TeleportFunctions::luaTeleportGetDestination); - registerMethod(L, "Teleport", "setDestination", TeleportFunctions::luaTeleportSetDestination); - } + static void init(lua_State* L); private: static int luaTeleportCreate(lua_State* L); diff --git a/src/lua/functions/map/tile_functions.cpp b/src/lua/functions/map/tile_functions.cpp index d43ce68e6be..c39d96348bd 100644 --- a/src/lua/functions/map/tile_functions.cpp +++ b/src/lua/functions/map/tile_functions.cpp @@ -11,23 +11,69 @@ #include "creatures/combat/combat.hpp" #include "game/game.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void TileFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Tile", "", TileFunctions::luaTileCreate); + Lua::registerMetaMethod(L, "Tile", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Tile", "getPosition", TileFunctions::luaTileGetPosition); + Lua::registerMethod(L, "Tile", "getGround", TileFunctions::luaTileGetGround); + Lua::registerMethod(L, "Tile", "getThing", TileFunctions::luaTileGetThing); + Lua::registerMethod(L, "Tile", "getThingCount", TileFunctions::luaTileGetThingCount); + Lua::registerMethod(L, "Tile", "getTopVisibleThing", TileFunctions::luaTileGetTopVisibleThing); + + Lua::registerMethod(L, "Tile", "getTopTopItem", TileFunctions::luaTileGetTopTopItem); + Lua::registerMethod(L, "Tile", "getTopDownItem", TileFunctions::luaTileGetTopDownItem); + Lua::registerMethod(L, "Tile", "getFieldItem", TileFunctions::luaTileGetFieldItem); + + Lua::registerMethod(L, "Tile", "getItemById", TileFunctions::luaTileGetItemById); + Lua::registerMethod(L, "Tile", "getItemByType", TileFunctions::luaTileGetItemByType); + Lua::registerMethod(L, "Tile", "getItemByTopOrder", TileFunctions::luaTileGetItemByTopOrder); + Lua::registerMethod(L, "Tile", "getItemCountById", TileFunctions::luaTileGetItemCountById); + + Lua::registerMethod(L, "Tile", "getBottomCreature", TileFunctions::luaTileGetBottomCreature); + Lua::registerMethod(L, "Tile", "getTopCreature", TileFunctions::luaTileGetTopCreature); + Lua::registerMethod(L, "Tile", "getBottomVisibleCreature", TileFunctions::luaTileGetBottomVisibleCreature); + Lua::registerMethod(L, "Tile", "getTopVisibleCreature", TileFunctions::luaTileGetTopVisibleCreature); + + Lua::registerMethod(L, "Tile", "getItems", TileFunctions::luaTileGetItems); + Lua::registerMethod(L, "Tile", "getItemCount", TileFunctions::luaTileGetItemCount); + Lua::registerMethod(L, "Tile", "getDownItemCount", TileFunctions::luaTileGetDownItemCount); + Lua::registerMethod(L, "Tile", "getTopItemCount", TileFunctions::luaTileGetTopItemCount); + + Lua::registerMethod(L, "Tile", "getCreatures", TileFunctions::luaTileGetCreatures); + Lua::registerMethod(L, "Tile", "getCreatureCount", TileFunctions::luaTileGetCreatureCount); + + Lua::registerMethod(L, "Tile", "getThingIndex", TileFunctions::luaTileGetThingIndex); + + Lua::registerMethod(L, "Tile", "hasProperty", TileFunctions::luaTileHasProperty); + Lua::registerMethod(L, "Tile", "hasFlag", TileFunctions::luaTileHasFlag); + + Lua::registerMethod(L, "Tile", "queryAdd", TileFunctions::luaTileQueryAdd); + Lua::registerMethod(L, "Tile", "addItem", TileFunctions::luaTileAddItem); + Lua::registerMethod(L, "Tile", "addItemEx", TileFunctions::luaTileAddItemEx); + + Lua::registerMethod(L, "Tile", "getHouse", TileFunctions::luaTileGetHouse); + Lua::registerMethod(L, "Tile", "sweep", TileFunctions::luaTileSweep); +} int TileFunctions::luaTileCreate(lua_State* L) { // Tile(x, y, z) // Tile(position) std::shared_ptr tile; - if (isTable(L, 2)) { - tile = g_game().map.getTile(getPosition(L, 2)); + if (Lua::isTable(L, 2)) { + tile = g_game().map.getTile(Lua::getPosition(L, 2)); } else { - const uint8_t z = getNumber(L, 4); - const uint16_t y = getNumber(L, 3); - const uint16_t x = getNumber(L, 2); + const uint8_t z = Lua::getNumber(L, 4); + const uint16_t y = Lua::getNumber(L, 3); + const uint16_t x = Lua::getNumber(L, 2); tile = g_game().map.getTile(x, y, z); } if (tile) { - pushUserdata(L, tile); - setMetatable(L, -1, "Tile"); + Lua::pushUserdata(L, tile); + Lua::setMetatable(L, -1, "Tile"); } else { lua_pushnil(L); } @@ -35,10 +81,10 @@ int TileFunctions::luaTileCreate(lua_State* L) { } int TileFunctions::luaTileGetPosition(lua_State* L) { - // tile:getPosition() - const auto &tile = getUserdataShared(L, 1); + // tile:Lua::getPosition() + const auto &tile = Lua::getUserdataShared(L, 1); if (tile) { - pushPosition(L, tile->getPosition()); + Lua::pushPosition(L, tile->getPosition()); } else { lua_pushnil(L); } @@ -47,10 +93,10 @@ int TileFunctions::luaTileGetPosition(lua_State* L) { int TileFunctions::luaTileGetGround(lua_State* L) { // tile:getGround() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (tile && tile->getGround()) { - pushUserdata(L, tile->getGround()); - setItemMetatable(L, -1, tile->getGround()); + Lua::pushUserdata(L, tile->getGround()); + Lua::setItemMetatable(L, -1, tile->getGround()); } else { lua_pushnil(L); } @@ -59,8 +105,8 @@ int TileFunctions::luaTileGetGround(lua_State* L) { int TileFunctions::luaTileGetThing(lua_State* L) { // tile:getThing(index) - const int32_t index = getNumber(L, 2); - const auto &tile = getUserdataShared(L, 1); + const int32_t index = Lua::getNumber(L, 2); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -73,11 +119,11 @@ int TileFunctions::luaTileGetThing(lua_State* L) { } if (const auto &creature = thing->getCreature()) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); } else if (const auto &item = thing->getItem()) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -86,7 +132,7 @@ int TileFunctions::luaTileGetThing(lua_State* L) { int TileFunctions::luaTileGetThingCount(lua_State* L) { // tile:getThingCount() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (tile) { lua_pushnumber(L, tile->getThingCount()); } else { @@ -97,8 +143,8 @@ int TileFunctions::luaTileGetThingCount(lua_State* L) { int TileFunctions::luaTileGetTopVisibleThing(lua_State* L) { // tile:getTopVisibleThing(creature) - const auto &creature = getCreature(L, 2); - const auto &tile = getUserdataShared(L, 1); + const auto &creature = Lua::getCreature(L, 2); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -111,11 +157,11 @@ int TileFunctions::luaTileGetTopVisibleThing(lua_State* L) { } if (const auto &visibleCreature = thing->getCreature()) { - pushUserdata(L, visibleCreature); - setCreatureMetatable(L, -1, visibleCreature); + Lua::pushUserdata(L, visibleCreature); + Lua::setCreatureMetatable(L, -1, visibleCreature); } else if (const auto &visibleItem = thing->getItem()) { - pushUserdata(L, visibleItem); - setItemMetatable(L, -1, visibleItem); + Lua::pushUserdata(L, visibleItem); + Lua::setItemMetatable(L, -1, visibleItem); } else { lua_pushnil(L); } @@ -124,7 +170,7 @@ int TileFunctions::luaTileGetTopVisibleThing(lua_State* L) { int TileFunctions::luaTileGetTopTopItem(lua_State* L) { // tile:getTopTopItem() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -132,8 +178,8 @@ int TileFunctions::luaTileGetTopTopItem(lua_State* L) { const auto &item = tile->getTopTopItem(); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -142,7 +188,7 @@ int TileFunctions::luaTileGetTopTopItem(lua_State* L) { int TileFunctions::luaTileGetTopDownItem(lua_State* L) { // tile:getTopDownItem() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -150,8 +196,8 @@ int TileFunctions::luaTileGetTopDownItem(lua_State* L) { const auto &item = tile->getTopDownItem(); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -160,7 +206,7 @@ int TileFunctions::luaTileGetTopDownItem(lua_State* L) { int TileFunctions::luaTileGetFieldItem(lua_State* L) { // tile:getFieldItem() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -168,8 +214,8 @@ int TileFunctions::luaTileGetFieldItem(lua_State* L) { const auto &item = tile->getFieldItem(); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -178,28 +224,28 @@ int TileFunctions::luaTileGetFieldItem(lua_State* L) { int TileFunctions::luaTileGetItemById(lua_State* L) { // tile:getItemById(itemId[, subType = -1]) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto subType = getNumber(L, 3, -1); + const auto subType = Lua::getNumber(L, 3, -1); const auto &item = g_game().findItemOfType(tile, itemId, false, subType); if (item) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); } @@ -208,7 +254,7 @@ int TileFunctions::luaTileGetItemById(lua_State* L) { int TileFunctions::luaTileGetItemByType(lua_State* L) { // tile:getItemByType(itemType) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -216,7 +262,7 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { bool found; - const ItemTypes_t itemType = getNumber(L, 2); + const ItemTypes_t itemType = Lua::getNumber(L, 2); switch (itemType) { case ITEM_TYPE_TELEPORT: found = tile->hasFlag(TILESTATE_TELEPORT); @@ -249,8 +295,8 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { if (const auto &item = tile->getGround()) { const ItemType &it = Item::items[item->getID()]; if (it.type == itemType) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); return 1; } } @@ -259,8 +305,8 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { for (auto &item : *items) { const ItemType &it = Item::items[item->getID()]; if (it.type == itemType) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); return 1; } } @@ -272,13 +318,13 @@ int TileFunctions::luaTileGetItemByType(lua_State* L) { int TileFunctions::luaTileGetItemByTopOrder(lua_State* L) { // tile:getItemByTopOrder(topOrder) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const int32_t topOrder = getNumber(L, 2); + const int32_t topOrder = Lua::getNumber(L, 2); const auto &item = tile->getItemByTopOrder(topOrder); if (!item) { @@ -286,26 +332,26 @@ int TileFunctions::luaTileGetItemByTopOrder(lua_State* L) { return 1; } - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); return 1; } int TileFunctions::luaTileGetItemCountById(lua_State* L) { // tile:getItemCountById(itemId[, subType = -1]) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto subType = getNumber(L, 3, -1); + const auto subType = Lua::getNumber(L, 3, -1); uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; @@ -318,7 +364,7 @@ int TileFunctions::luaTileGetItemCountById(lua_State* L) { int TileFunctions::luaTileGetBottomCreature(lua_State* L) { // tile:getBottomCreature() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -330,14 +376,14 @@ int TileFunctions::luaTileGetBottomCreature(lua_State* L) { return 1; } - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); return 1; } int TileFunctions::luaTileGetTopCreature(lua_State* L) { // tile:getTopCreature() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -349,20 +395,20 @@ int TileFunctions::luaTileGetTopCreature(lua_State* L) { return 1; } - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); return 1; } int TileFunctions::luaTileGetBottomVisibleCreature(lua_State* L) { // tile:getBottomVisibleCreature(creature) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto &creature = getCreature(L, 2); + const auto &creature = Lua::getCreature(L, 2); if (!creature) { lua_pushnil(L); return 1; @@ -370,8 +416,8 @@ int TileFunctions::luaTileGetBottomVisibleCreature(lua_State* L) { const auto &visibleCreature = tile->getBottomVisibleCreature(creature); if (visibleCreature) { - pushUserdata(L, visibleCreature); - setCreatureMetatable(L, -1, visibleCreature); + Lua::pushUserdata(L, visibleCreature); + Lua::setCreatureMetatable(L, -1, visibleCreature); } else { lua_pushnil(L); } @@ -380,13 +426,13 @@ int TileFunctions::luaTileGetBottomVisibleCreature(lua_State* L) { int TileFunctions::luaTileGetTopVisibleCreature(lua_State* L) { // tile:getTopVisibleCreature(creature) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto &creature = getCreature(L, 2); + const auto &creature = Lua::getCreature(L, 2); if (!creature) { lua_pushnil(L); return 1; @@ -394,8 +440,8 @@ int TileFunctions::luaTileGetTopVisibleCreature(lua_State* L) { const auto &visibleCreature = tile->getTopVisibleCreature(creature); if (visibleCreature) { - pushUserdata(L, visibleCreature); - setCreatureMetatable(L, -1, visibleCreature); + Lua::pushUserdata(L, visibleCreature); + Lua::setCreatureMetatable(L, -1, visibleCreature); } else { lua_pushnil(L); } @@ -404,7 +450,7 @@ int TileFunctions::luaTileGetTopVisibleCreature(lua_State* L) { int TileFunctions::luaTileGetItems(lua_State* L) { // tile:getItems() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -420,8 +466,8 @@ int TileFunctions::luaTileGetItems(lua_State* L) { int index = 0; for (auto &item : *itemVector) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); lua_rawseti(L, -2, ++index); } return 1; @@ -429,7 +475,7 @@ int TileFunctions::luaTileGetItems(lua_State* L) { int TileFunctions::luaTileGetItemCount(lua_State* L) { // tile:getItemCount() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -441,7 +487,7 @@ int TileFunctions::luaTileGetItemCount(lua_State* L) { int TileFunctions::luaTileGetDownItemCount(lua_State* L) { // tile:getDownItemCount() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (tile) { lua_pushnumber(L, tile->getDownItemCount()); } else { @@ -452,7 +498,7 @@ int TileFunctions::luaTileGetDownItemCount(lua_State* L) { int TileFunctions::luaTileGetTopItemCount(lua_State* L) { // tile:getTopItemCount() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -464,7 +510,7 @@ int TileFunctions::luaTileGetTopItemCount(lua_State* L) { int TileFunctions::luaTileGetCreatures(lua_State* L) { // tile:getCreatures() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -480,8 +526,8 @@ int TileFunctions::luaTileGetCreatures(lua_State* L) { int index = 0; for (auto &creature : *creatureVector) { - pushUserdata(L, creature); - setCreatureMetatable(L, -1, creature); + Lua::pushUserdata(L, creature); + Lua::setCreatureMetatable(L, -1, creature); lua_rawseti(L, -2, ++index); } return 1; @@ -489,7 +535,7 @@ int TileFunctions::luaTileGetCreatures(lua_State* L) { int TileFunctions::luaTileGetCreatureCount(lua_State* L) { // tile:getCreatureCount() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -501,7 +547,7 @@ int TileFunctions::luaTileGetCreatureCount(lua_State* L) { int TileFunctions::luaTileHasProperty(lua_State* L) { // tile:hasProperty(property[, item]) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; @@ -509,29 +555,29 @@ int TileFunctions::luaTileHasProperty(lua_State* L) { std::shared_ptr item; if (lua_gettop(L) >= 3) { - item = getUserdataShared(L, 3); + item = Lua::getUserdataShared(L, 3); } else { item = nullptr; } - ItemProperty property = getNumber(L, 2); + ItemProperty property = Lua::getNumber(L, 2); if (item) { - pushBoolean(L, tile->hasProperty(item, property)); + Lua::pushBoolean(L, tile->hasProperty(item, property)); } else { - pushBoolean(L, tile->hasProperty(property)); + Lua::pushBoolean(L, tile->hasProperty(property)); } return 1; } int TileFunctions::luaTileGetThingIndex(lua_State* L) { // tile:getThingIndex(thing) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto &thing = getThing(L, 2); + const auto &thing = Lua::getThing(L, 2); if (thing) { lua_pushnumber(L, tile->getThingIndex(thing)); } else { @@ -542,10 +588,10 @@ int TileFunctions::luaTileGetThingIndex(lua_State* L) { int TileFunctions::luaTileHasFlag(lua_State* L) { // tile:hasFlag(flag) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (tile) { - TileFlags_t flag = getNumber(L, 2); - pushBoolean(L, tile->hasFlag(flag)); + TileFlags_t flag = Lua::getNumber(L, 2); + Lua::pushBoolean(L, tile->hasFlag(flag)); } else { lua_pushnil(L); } @@ -554,15 +600,15 @@ int TileFunctions::luaTileHasFlag(lua_State* L) { int TileFunctions::luaTileQueryAdd(lua_State* L) { // tile:queryAdd(thing[, flags]) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto &thing = getThing(L, 2); + const auto &thing = Lua::getThing(L, 2); if (thing) { - const auto flags = getNumber(L, 3, 0); + const auto flags = Lua::getNumber(L, 3, 0); lua_pushnumber(L, tile->queryAdd(0, thing, 1, flags)); } else { lua_pushnil(L); @@ -572,24 +618,24 @@ int TileFunctions::luaTileQueryAdd(lua_State* L) { int TileFunctions::luaTileAddItem(lua_State* L) { // tile:addItem(itemId[, count/subType = 1[, flags = 0]]) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } uint16_t itemId; - if (isNumber(L, 2)) { - itemId = getNumber(L, 2); + if (Lua::isNumber(L, 2)) { + itemId = Lua::getNumber(L, 2); } else { - itemId = Item::items.getItemIdByName(getString(L, 2)); + itemId = Item::items.getItemIdByName(Lua::getString(L, 2)); if (itemId == 0) { lua_pushnil(L); return 1; } } - const auto subType = getNumber(L, 3, 1); + const auto subType = Lua::getNumber(L, 3, 1); const auto &item = Item::CreateItem(itemId, std::min(subType, Item::items[itemId].stackSize)); if (!item) { @@ -597,12 +643,12 @@ int TileFunctions::luaTileAddItem(lua_State* L) { return 1; } - const auto flags = getNumber(L, 4, 0); + const auto flags = Lua::getNumber(L, 4, 0); ReturnValue ret = g_game().internalAddItem(tile, item, INDEX_WHEREEVER, flags); if (ret == RETURNVALUE_NOERROR) { - pushUserdata(L, item); - setItemMetatable(L, -1, item); + Lua::pushUserdata(L, item); + Lua::setItemMetatable(L, -1, item); } else { lua_pushnil(L); @@ -612,25 +658,25 @@ int TileFunctions::luaTileAddItem(lua_State* L) { int TileFunctions::luaTileAddItemEx(lua_State* L) { // tile:addItemEx(item[, flags = 0]) - const auto &item = getUserdataShared(L, 2); + const auto &item = Lua::getUserdataShared(L, 2); if (!item) { lua_pushnil(L); return 1; } - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } if (item->getParent() != VirtualCylinder::virtualCylinder) { - reportErrorFunc("Item already has a parent"); + Lua::reportErrorFunc("Item already has a parent"); lua_pushnil(L); return 1; } - const auto flags = getNumber(L, 3, 0); + const auto flags = Lua::getNumber(L, 3, 0); ReturnValue ret = g_game().internalAddItem(tile, item, INDEX_WHEREEVER, flags); if (ret == RETURNVALUE_NOERROR) { ScriptEnvironment::removeTempItem(item); @@ -641,15 +687,15 @@ int TileFunctions::luaTileAddItemEx(lua_State* L) { int TileFunctions::luaTileGetHouse(lua_State* L) { // tile:getHouse() - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } if (const auto &houseTile = std::dynamic_pointer_cast(tile)) { - pushUserdata(L, houseTile->getHouse()); - setMetatable(L, -1, "House"); + Lua::pushUserdata(L, houseTile->getHouse()); + Lua::setMetatable(L, -1, "House"); } else { lua_pushnil(L); } @@ -658,12 +704,12 @@ int TileFunctions::luaTileGetHouse(lua_State* L) { int TileFunctions::luaTileSweep(lua_State* L) { // tile:sweep(actor) - const auto &tile = getUserdataShared(L, 1); + const auto &tile = Lua::getUserdataShared(L, 1); if (!tile) { lua_pushnil(L); return 1; } - const auto &actor = getPlayer(L, 2); + const auto &actor = Lua::getPlayer(L, 2); if (!actor) { lua_pushnil(L); return 1; @@ -689,6 +735,6 @@ int TileFunctions::luaTileSweep(lua_State* L) { return 1; } - pushBoolean(L, house->transferToDepot(actor, houseTile)); + Lua::pushBoolean(L, house->transferToDepot(actor, houseTile)); return 1; } diff --git a/src/lua/functions/map/tile_functions.hpp b/src/lua/functions/map/tile_functions.hpp index a1183508b45..e88b39acef8 100644 --- a/src/lua/functions/map/tile_functions.hpp +++ b/src/lua/functions/map/tile_functions.hpp @@ -9,60 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class TileFunctions final : LuaScriptInterface { +class TileFunctions { public: - explicit TileFunctions(lua_State* L) : - LuaScriptInterface("TileFunctions") { - init(L); - } - ~TileFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Tile", "", TileFunctions::luaTileCreate); - registerMetaMethod(L, "Tile", "__eq", TileFunctions::luaUserdataCompare); - - registerMethod(L, "Tile", "getPosition", TileFunctions::luaTileGetPosition); - registerMethod(L, "Tile", "getGround", TileFunctions::luaTileGetGround); - registerMethod(L, "Tile", "getThing", TileFunctions::luaTileGetThing); - registerMethod(L, "Tile", "getThingCount", TileFunctions::luaTileGetThingCount); - registerMethod(L, "Tile", "getTopVisibleThing", TileFunctions::luaTileGetTopVisibleThing); - - registerMethod(L, "Tile", "getTopTopItem", TileFunctions::luaTileGetTopTopItem); - registerMethod(L, "Tile", "getTopDownItem", TileFunctions::luaTileGetTopDownItem); - registerMethod(L, "Tile", "getFieldItem", TileFunctions::luaTileGetFieldItem); - - registerMethod(L, "Tile", "getItemById", TileFunctions::luaTileGetItemById); - registerMethod(L, "Tile", "getItemByType", TileFunctions::luaTileGetItemByType); - registerMethod(L, "Tile", "getItemByTopOrder", TileFunctions::luaTileGetItemByTopOrder); - registerMethod(L, "Tile", "getItemCountById", TileFunctions::luaTileGetItemCountById); - - registerMethod(L, "Tile", "getBottomCreature", TileFunctions::luaTileGetBottomCreature); - registerMethod(L, "Tile", "getTopCreature", TileFunctions::luaTileGetTopCreature); - registerMethod(L, "Tile", "getBottomVisibleCreature", TileFunctions::luaTileGetBottomVisibleCreature); - registerMethod(L, "Tile", "getTopVisibleCreature", TileFunctions::luaTileGetTopVisibleCreature); - - registerMethod(L, "Tile", "getItems", TileFunctions::luaTileGetItems); - registerMethod(L, "Tile", "getItemCount", TileFunctions::luaTileGetItemCount); - registerMethod(L, "Tile", "getDownItemCount", TileFunctions::luaTileGetDownItemCount); - registerMethod(L, "Tile", "getTopItemCount", TileFunctions::luaTileGetTopItemCount); - - registerMethod(L, "Tile", "getCreatures", TileFunctions::luaTileGetCreatures); - registerMethod(L, "Tile", "getCreatureCount", TileFunctions::luaTileGetCreatureCount); - - registerMethod(L, "Tile", "getThingIndex", TileFunctions::luaTileGetThingIndex); - - registerMethod(L, "Tile", "hasProperty", TileFunctions::luaTileHasProperty); - registerMethod(L, "Tile", "hasFlag", TileFunctions::luaTileHasFlag); - - registerMethod(L, "Tile", "queryAdd", TileFunctions::luaTileQueryAdd); - registerMethod(L, "Tile", "addItem", TileFunctions::luaTileAddItem); - registerMethod(L, "Tile", "addItemEx", TileFunctions::luaTileAddItemEx); - - registerMethod(L, "Tile", "getHouse", TileFunctions::luaTileGetHouse); - registerMethod(L, "Tile", "sweep", TileFunctions::luaTileSweep); - } + static void init(lua_State* L); private: static int luaTileCreate(lua_State* L); diff --git a/src/lua/functions/map/town_functions.cpp b/src/lua/functions/map/town_functions.cpp index eba9213d0de..fa77003fe77 100644 --- a/src/lua/functions/map/town_functions.cpp +++ b/src/lua/functions/map/town_functions.cpp @@ -11,21 +11,31 @@ #include "game/game.hpp" #include "map/town.hpp" +#include "lua/functions/lua_functions_loader.hpp" + +void TownFunctions::init(lua_State* L) { + Lua::registerSharedClass(L, "Town", "", TownFunctions::luaTownCreate); + Lua::registerMetaMethod(L, "Town", "__eq", Lua::luaUserdataCompare); + + Lua::registerMethod(L, "Town", "getId", TownFunctions::luaTownGetId); + Lua::registerMethod(L, "Town", "getName", TownFunctions::luaTownGetName); + Lua::registerMethod(L, "Town", "getTemplePosition", TownFunctions::luaTownGetTemplePosition); +} int TownFunctions::luaTownCreate(lua_State* L) { // Town(id or name) std::shared_ptr town; - if (isNumber(L, 2)) { - town = g_game().map.towns.getTown(getNumber(L, 2)); - } else if (isString(L, 2)) { - town = g_game().map.towns.getTown(getString(L, 2)); + if (Lua::isNumber(L, 2)) { + town = g_game().map.towns.getTown(Lua::getNumber(L, 2)); + } else if (Lua::isString(L, 2)) { + town = g_game().map.towns.getTown(Lua::getString(L, 2)); } else { town = nullptr; } if (town) { - pushUserdata(L, town); - setMetatable(L, -1, "Town"); + Lua::pushUserdata(L, town); + Lua::setMetatable(L, -1, "Town"); } else { lua_pushnil(L); } @@ -34,7 +44,7 @@ int TownFunctions::luaTownCreate(lua_State* L) { int TownFunctions::luaTownGetId(lua_State* L) { // town:getId() - if (const auto &town = getUserdataShared(L, 1)) { + if (const auto &town = Lua::getUserdataShared(L, 1)) { lua_pushnumber(L, town->getID()); } else { lua_pushnil(L); @@ -44,8 +54,8 @@ int TownFunctions::luaTownGetId(lua_State* L) { int TownFunctions::luaTownGetName(lua_State* L) { // town:getName() - if (const auto &town = getUserdataShared(L, 1)) { - pushString(L, town->getName()); + if (const auto &town = Lua::getUserdataShared(L, 1)) { + Lua::pushString(L, town->getName()); } else { lua_pushnil(L); } @@ -54,8 +64,8 @@ int TownFunctions::luaTownGetName(lua_State* L) { int TownFunctions::luaTownGetTemplePosition(lua_State* L) { // town:getTemplePosition() - if (const auto &town = getUserdataShared(L, 1)) { - pushPosition(L, town->getTemplePosition()); + if (const auto &town = Lua::getUserdataShared(L, 1)) { + Lua::pushPosition(L, town->getTemplePosition()); } else { lua_pushnil(L); } diff --git a/src/lua/functions/map/town_functions.hpp b/src/lua/functions/map/town_functions.hpp index a3e41ec67ae..81430daf2c4 100644 --- a/src/lua/functions/map/town_functions.hpp +++ b/src/lua/functions/map/town_functions.hpp @@ -9,24 +9,9 @@ #pragma once -#include "lua/scripts/luascript.hpp" - -class TownFunctions final : LuaScriptInterface { +class TownFunctions { public: - explicit TownFunctions(lua_State* L) : - LuaScriptInterface("TownFunctions") { - init(L); - } - ~TownFunctions() override = default; - - static void init(lua_State* L) { - registerSharedClass(L, "Town", "", TownFunctions::luaTownCreate); - registerMetaMethod(L, "Town", "__eq", TownFunctions::luaUserdataCompare); - - registerMethod(L, "Town", "getId", TownFunctions::luaTownGetId); - registerMethod(L, "Town", "getName", TownFunctions::luaTownGetName); - registerMethod(L, "Town", "getTemplePosition", TownFunctions::luaTownGetTemplePosition); - } + static void init(lua_State* L); private: static int luaTownCreate(lua_State* L); diff --git a/src/lua/global/globalevent.cpp b/src/lua/global/globalevent.cpp index f7de024bda1..ae988a814de 100644 --- a/src/lua/global/globalevent.cpp +++ b/src/lua/global/globalevent.cpp @@ -12,10 +12,16 @@ #include "utils/tools.hpp" #include "game/game.hpp" #include "game/scheduling/dispatcher.hpp" +#include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" GlobalEvents::GlobalEvents() = default; GlobalEvents::~GlobalEvents() = default; +GlobalEvents &GlobalEvents::getInstance() { + return inject(); +} + void GlobalEvents::clear() { // Stop events g_dispatcher().stopEvent(thinkEventId); @@ -184,8 +190,34 @@ GlobalEventMap GlobalEvents::getEventMap(GlobalEvent_t type) { } } -GlobalEvent::GlobalEvent(LuaScriptInterface* interface) : - Script(interface) { } +GlobalEvent::GlobalEvent() = default; + +LuaScriptInterface* GlobalEvent::getScriptInterface() const { + return &g_scripts().getScriptInterface(); +} + +bool GlobalEvent::loadScriptId() { + LuaScriptInterface &luaInterface = g_scripts().getScriptInterface(); + m_scriptId = luaInterface.getEvent(); + if (m_scriptId == -1) { + g_logger().error("[MoveEvent::loadScriptId] Failed to load event. Script name: '{}', Module: '{}'", luaInterface.getLoadingScriptName(), luaInterface.getInterfaceName()); + return false; + } + + return true; +} + +int32_t GlobalEvent::getScriptId() const { + return m_scriptId; +} + +void GlobalEvent::setScriptId(int32_t newScriptId) { + m_scriptId = newScriptId; +} + +bool GlobalEvent::isLoadedScriptId() const { + return m_scriptId != 0; +} std::string GlobalEvent::getScriptTypeName() const { switch (eventType) { diff --git a/src/lua/global/globalevent.hpp b/src/lua/global/globalevent.hpp index cc08bb9c771..f8337cd773f 100644 --- a/src/lua/global/globalevent.hpp +++ b/src/lua/global/globalevent.hpp @@ -10,12 +10,17 @@ #pragma once #include "utils/utils_definitions.hpp" -#include "lua/scripts/scripts.hpp" +#include "lua/lua_definitions.hpp" +class LuaScriptInterface; class GlobalEvent; using GlobalEventMap = std::map>; -class GlobalEvents final : public Scripts { +enum LightState_t : uint8_t; + +struct LightInfo; + +class GlobalEvents { public: GlobalEvents(); ~GlobalEvents(); @@ -24,9 +29,7 @@ class GlobalEvents final : public Scripts { GlobalEvents(const GlobalEvents &) = delete; GlobalEvents &operator=(const GlobalEvents &) = delete; - static GlobalEvents &getInstance() { - return inject(); - } + static GlobalEvents &getInstance(); void startup() const; void shutdown() const; @@ -43,14 +46,15 @@ class GlobalEvents final : public Scripts { private: GlobalEventMap thinkMap, serverMap, timerMap; - uint64_t thinkEventId = 0, timerEventId = 0; + uint64_t thinkEventId = 0; + uint64_t timerEventId = 0; }; constexpr auto g_globalEvents = GlobalEvents::getInstance; -class GlobalEvent final : public Script { +class GlobalEvent { public: - explicit GlobalEvent(LuaScriptInterface* interface); + explicit GlobalEvent(); bool executePeriodChange(LightState_t lightState, LightInfo lightInfo) const; bool executeRecord(uint32_t current, uint32_t old) const; @@ -83,10 +87,17 @@ class GlobalEvent final : public Script { nextExecution = time; } + std::string getScriptTypeName() const; + LuaScriptInterface* getScriptInterface() const; + bool loadScriptId(); + int32_t getScriptId() const; + void setScriptId(int32_t newScriptId); + bool isLoadedScriptId() const; + private: - GlobalEvent_t eventType = GLOBALEVENT_NONE; + int32_t m_scriptId {}; - std::string getScriptTypeName() const override; + GlobalEvent_t eventType = GLOBALEVENT_NONE; std::string name; int64_t nextExecution = 0; diff --git a/src/lua/lua_definitions.hpp b/src/lua/lua_definitions.hpp index ace5ee32164..fa1bdcec01a 100644 --- a/src/lua/lua_definitions.hpp +++ b/src/lua/lua_definitions.hpp @@ -99,7 +99,7 @@ enum TalkActionResult_t { TALKACTION_FAILED, }; -enum GlobalEvent_t { +enum GlobalEvent_t : uint8_t { GLOBALEVENT_NONE, GLOBALEVENT_TIMER, diff --git a/src/lua/scripts/lua_environment.cpp b/src/lua/scripts/lua_environment.cpp index b4cc620b1ce..9e95beaf8da 100644 --- a/src/lua/scripts/lua_environment.cpp +++ b/src/lua/scripts/lua_environment.cpp @@ -13,9 +13,14 @@ #include "lua/functions/lua_functions_loader.hpp" #include "lua/scripts/script_environment.hpp" #include "lua/global/lua_timer_event_descr.hpp" +#include "lib/di/container.hpp" bool LuaEnvironment::shuttingDown = false; +LuaEnvironment &LuaEnvironment::getInstance() { + return inject(); +} + static const std::unique_ptr &AreaCombatNull {}; LuaEnvironment::LuaEnvironment() : @@ -43,7 +48,7 @@ lua_State* LuaEnvironment::getLuaState() { bool LuaEnvironment::initState() { luaState = luaL_newstate(); - LuaFunctionsLoader::load(luaState); + Lua::load(luaState); runningEventId = EVENT_ID_USER; return true; @@ -60,10 +65,6 @@ bool LuaEnvironment::closeState() { return false; } - for (const auto &combatEntry : combatIdMap) { - clearCombatObjects(combatEntry.first); - } - for (const auto &areaEntry : areaIdMap) { clearAreaObjects(areaEntry.first); } @@ -76,7 +77,6 @@ bool LuaEnvironment::closeState() { luaL_unref(luaState, LUA_REGISTRYINDEX, timerEventDesc.function); } - combatIdMap.clear(); areaIdMap.clear(); timerEvents.clear(); cacheFiles.clear(); @@ -94,31 +94,6 @@ LuaScriptInterface* LuaEnvironment::getTestInterface() { return testInterface; } -std::shared_ptr LuaEnvironment::getCombatObject(uint32_t id) const { - const auto it = combatMap.find(id); - if (it == combatMap.end()) { - return nullptr; - } - return it->second; -} - -std::shared_ptr LuaEnvironment::createCombatObject(LuaScriptInterface* interface) { - auto combat = std::make_shared(); - combatMap[++lastCombatId] = combat; - combatIdMap[interface].push_back(lastCombatId); - return combat; -} - -void LuaEnvironment::clearCombatObjects(LuaScriptInterface* interface) { - const auto it = combatIdMap.find(interface); - if (it == combatIdMap.end()) { - return; - } - - it->second.clear(); - combatMap.clear(); -} - const std::unique_ptr &LuaEnvironment::getAreaObject(uint32_t id) const { const auto it = areaMap.find(id); if (it == areaMap.end()) { diff --git a/src/lua/scripts/lua_environment.hpp b/src/lua/scripts/lua_environment.hpp index e7751bb4969..63efd2d7033 100644 --- a/src/lua/scripts/lua_environment.hpp +++ b/src/lua/scripts/lua_environment.hpp @@ -35,9 +35,7 @@ class LuaEnvironment final : public LuaScriptInterface { LuaEnvironment(const LuaEnvironment &) = delete; LuaEnvironment &operator=(const LuaEnvironment &) = delete; - static LuaEnvironment &getInstance() { - return inject(); - } + static LuaEnvironment &getInstance(); bool initState() override; bool reInitState() override; @@ -45,38 +43,6 @@ class LuaEnvironment final : public LuaScriptInterface { LuaScriptInterface* getTestInterface(); - std::shared_ptr getCombatObject(uint32_t id) const; - std::shared_ptr createCombatObject(LuaScriptInterface* interface); - void clearCombatObjects(LuaScriptInterface* interface); - - template - std::shared_ptr createWeaponObject(LuaScriptInterface* interface) { - auto weapon = std::make_shared(interface); - const auto weaponId = ++lastWeaponId; - weaponMap[weaponId] = weapon; - weaponIdMap[interface].push_back(weaponId); - return weapon; - } - - template - std::shared_ptr getWeaponObject(uint32_t id) const { - const auto it = weaponMap.find(id); - if (it == weaponMap.end()) { - return nullptr; - } - return it->second; - } - - void clearWeaponObjects(LuaScriptInterface* interface) { - const auto it = weaponIdMap.find(interface); - if (it == weaponIdMap.end()) { - return; - } - - it->second.clear(); - weaponMap.clear(); - } - const std::unique_ptr &getAreaObject(uint32_t id) const; uint32_t createAreaObject(LuaScriptInterface* interface); void clearAreaObjects(LuaScriptInterface* interface); @@ -96,14 +62,6 @@ class LuaEnvironment final : public LuaScriptInterface { phmap::flat_hash_map> areaIdMap; uint32_t lastAreaId = 0; - phmap::flat_hash_map> combatMap; - phmap::flat_hash_map> combatIdMap; - uint32_t lastCombatId = 0; - - std::unordered_map> weaponMap; - std::unordered_map> weaponIdMap; - uint32_t lastWeaponId = 0; - LuaScriptInterface* testInterface = nullptr; friend class LuaScriptInterface; diff --git a/src/lua/scripts/luascript.cpp b/src/lua/scripts/luascript.cpp index aa1b6011886..9bb926b5676 100644 --- a/src/lua/scripts/luascript.cpp +++ b/src/lua/scripts/luascript.cpp @@ -16,8 +16,8 @@ ScriptEnvironment::DBResultMap ScriptEnvironment::tempResults; uint32_t ScriptEnvironment::lastResultId = 0; std::multimap> ScriptEnvironment::tempItems; -ScriptEnvironment LuaFunctionsLoader::scriptEnv[16]; -int32_t LuaFunctionsLoader::scriptEnvIndex = -1; +ScriptEnvironment Lua::scriptEnv[16]; +int32_t Lua::scriptEnvIndex = -1; LuaScriptInterface::LuaScriptInterface(std::string initInterfaceName) : interfaceName(std::move(initInterfaceName)) { @@ -28,7 +28,6 @@ LuaScriptInterface::~LuaScriptInterface() { } bool LuaScriptInterface::reInitState() { - g_luaEnvironment().clearCombatObjects(this); g_luaEnvironment().clearAreaObjects(this); closeState(); @@ -237,7 +236,8 @@ bool LuaScriptInterface::closeState() { } std::string LuaScriptInterface::getMetricsScope() const { - metrics::method_latency measure(__METHOD_NAME__); +#ifdef FEATURE_METRICS + metrics::method_latency measure(__METRICS_METHOD_NAME__); int32_t scriptId; int32_t callbackId; bool timerEvent; @@ -261,6 +261,9 @@ std::string LuaScriptInterface::getMetricsScope() const { } return fmt::format("{}:{}", name, timerEvent ? "timer" : ""); +#else + return {}; +#endif } bool LuaScriptInterface::callFunction(int params) const { diff --git a/src/lua/scripts/luascript.hpp b/src/lua/scripts/luascript.hpp index 82ed9fa69af..c4d916a593c 100644 --- a/src/lua/scripts/luascript.hpp +++ b/src/lua/scripts/luascript.hpp @@ -12,7 +12,7 @@ #include "lua/functions/lua_functions_loader.hpp" #include "lua/scripts/script_environment.hpp" -class LuaScriptInterface : public LuaFunctionsLoader { +class LuaScriptInterface : public Lua { public: explicit LuaScriptInterface(std::string interfaceName); virtual ~LuaScriptInterface(); diff --git a/src/lua/scripts/scripts.cpp b/src/lua/scripts/scripts.cpp index 556ed1be50b..f4a141253c4 100644 --- a/src/lua/scripts/scripts.cpp +++ b/src/lua/scripts/scripts.cpp @@ -9,6 +9,7 @@ #include "lua/scripts/scripts.hpp" +#include "lib/di/container.hpp" #include "config/configmanager.hpp" #include "creatures/combat/spells.hpp" #include "creatures/monsters/monsters.hpp" @@ -24,6 +25,11 @@ Scripts::Scripts() : scriptInterface.initState(); } +Scripts &Scripts::getInstance() { + static Scripts instance; + return instance; +} + void Scripts::clearAllScripts() const { g_actions().clear(); g_creatureEvents().clear(); @@ -61,16 +67,18 @@ bool Scripts::loadEventSchedulerScripts(const std::string &fileName) { return false; } -bool Scripts::loadScripts(std::string loadPath, bool isLib, bool reload) { - const auto dir = std::filesystem::current_path() / loadPath; +bool Scripts::loadScripts(std::string_view folderName, bool isLib, bool reload) { + const auto dir = std::filesystem::current_path() / folderName; + // Checks if the folder exists and is really a folder if (!std::filesystem::exists(dir) || !std::filesystem::is_directory(dir)) { - g_logger().error("Can not load folder {}", loadPath); + g_logger().error("Can not load folder {}", folderName); return false; } // Declare a string variable to store the last directory std::string lastDirectory; + // Recursive iterate through all entries in the directory for (const auto &entry : std::filesystem::recursive_directory_iterator(dir)) { // Get the filename of the entry as a string @@ -78,11 +86,14 @@ bool Scripts::loadScripts(std::string loadPath, bool isLib, bool reload) { std::string fileFolder = realPath.parent_path().filename().string(); // Script folder, example: "actions" std::string scriptFolder = realPath.parent_path().string(); + // Create a string_view for the fileFolder and scriptFolder strings const std::string_view fileFolderView(fileFolder); const std::string_view scriptFolderView(scriptFolder); + // Filename, example: "demon.lua" std::string file(realPath.filename().string()); + if (!std::filesystem::is_regular_file(entry) || realPath.extension() != ".lua") { // Skip this entry if it is not a regular file or does not have a .lua extension continue; diff --git a/src/lua/scripts/scripts.hpp b/src/lua/scripts/scripts.hpp index 10ed18ed4f4..2efedb04232 100644 --- a/src/lua/scripts/scripts.hpp +++ b/src/lua/scripts/scripts.hpp @@ -9,118 +9,27 @@ #pragma once -#include "lib/di/container.hpp" #include "lua/scripts/luascript.hpp" class Scripts { public: - Scripts(); - // non-copyable Scripts(const Scripts &) = delete; Scripts &operator=(const Scripts &) = delete; - static Scripts &getInstance() { - return inject(); - } + static Scripts &getInstance(); void clearAllScripts() const; bool loadEventSchedulerScripts(const std::string &fileName); - bool loadScripts(std::string folderName, bool isLib, bool reload); + bool loadScripts(std::string_view folderName, bool isLib, bool reload); LuaScriptInterface &getScriptInterface() { return scriptInterface; } - /** - * @brief Get the Script Id object - * - * @return int32_t - */ - int32_t getScriptId() const { - return scriptId; - } private: - int32_t scriptId = 0; LuaScriptInterface scriptInterface; + Scripts(); }; constexpr auto g_scripts = Scripts::getInstance; - -class Script { -public: - /** - * @brief Explicit construtor - * explicit, that is, it cannot be used for implicit conversions and - * copy-initialization. - * - * @param interface Lua Script Interface - */ - explicit Script(LuaScriptInterface* interface) : - scriptInterface(interface) { } - virtual ~Script() = default; - - /** - * @brief Check if script is loaded - * - * @return true - * @return false - */ - bool isLoadedCallback() const { - return loadedCallback; - } - void setLoadedCallback(bool loaded) { - loadedCallback = loaded; - } - - // Load revscriptsys callback - bool loadCallback() { - if (!scriptInterface) { - g_logger().error("[Script::loadCallback] scriptInterface is nullptr, scriptid = {}", scriptId); - return false; - } - - if (scriptId != 0) { - g_logger().error("[Script::loadCallback] scriptid is not zero, scriptid = {}, scriptName {}", scriptId, scriptInterface->getLoadingScriptName()); - return false; - } - - const int32_t id = scriptInterface->getEvent(); - if (id == -1) { - g_logger().error("[Script::loadCallback] Event {} not found for script with name {}", getScriptTypeName(), scriptInterface->getLoadingScriptName()); - return false; - } - - setLoadedCallback(true); - scriptId = id; - return true; - } - - // NOTE: Pure virtual method ( = 0) that must be implemented in derived classes - // Script type (Action, CreatureEvent, GlobalEvent, MoveEvent, Spell, Weapon) - virtual std::string getScriptTypeName() const = 0; - - // Method to access the scriptInterface in derived classes - virtual LuaScriptInterface* getScriptInterface() const { - return scriptInterface; - } - - virtual void setScriptInterface(LuaScriptInterface* newInterface) { - scriptInterface = newInterface; - } - - // Method to access the scriptId in derived classes - virtual int32_t getScriptId() const { - return scriptId; - } - virtual void setScriptId(int32_t newScriptId) { - scriptId = newScriptId; - } - -private: - // If script is loaded callback - bool loadedCallback = false; - - int32_t scriptId = 0; - LuaScriptInterface* scriptInterface = nullptr; -}; diff --git a/src/map/house/house.cpp b/src/map/house/house.cpp index 334144cfbd1..6d93561172b 100644 --- a/src/map/house/house.cpp +++ b/src/map/house/house.cpp @@ -18,6 +18,7 @@ #include "items/containers/inbox/inbox.hpp" #include "lib/metrics/metrics.hpp" #include "utils/pugicast.hpp" +#include "creatures/players/player.hpp" House::House(uint32_t houseId) : id(houseId) { } @@ -471,7 +472,7 @@ std::shared_ptr House::getTransferItem() { void House::resetTransferItem() { if (transferItem) { - const auto &tmpItem = transferItem; + auto tmpItem = transferItem; transferItem = nullptr; transfer_container->resetParent(); transfer_container->removeThing(tmpItem, tmpItem->getItemCount()); @@ -848,7 +849,7 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { if (house->getPayRentWarnings() < 7) { const int32_t daysLeft = 7 - house->getPayRentWarnings(); - std::shared_ptr letter = Item::CreateItem(ITEM_LETTER_STAMPED); + const std::shared_ptr &letter = Item::CreateItem(ITEM_LETTER_STAMPED); std::string period; switch (rentPeriod) { @@ -875,7 +876,8 @@ void Houses::payHouses(RentPeriod_t rentPeriod) const { std::ostringstream ss; ss << "Warning! \nThe " << period << " rent of " << house->getRent() << " gold for your house \"" << house->getName() << "\" is payable. Have it within " << daysLeft << " days or you will lose this house."; letter->setAttribute(ItemAttribute_t::TEXT, ss.str()); - g_game().internalAddItem(player->getInbox(), letter, INDEX_WHEREEVER, FLAG_NOLIMIT); + const auto &playerInbox = player->getInbox(); + g_game().internalAddItem(playerInbox, letter, INDEX_WHEREEVER, FLAG_NOLIMIT); house->setPayRentWarnings(house->getPayRentWarnings() + 1); } else { house->setOwner(0, true, player); diff --git a/src/map/house/housetile.cpp b/src/map/house/housetile.cpp index ce9229ce42c..71d6ee241ed 100644 --- a/src/map/house/housetile.cpp +++ b/src/map/house/housetile.cpp @@ -17,6 +17,9 @@ #include "map/house/house.hpp" #include "utils/tools.hpp" +HouseTile::HouseTile(const Position &position, std::shared_ptr newHouse) : + DynamicTile(position.x, position.y, position.z), house(std::move(newHouse)) { } + HouseTile::HouseTile(int32_t initX, int32_t initY, int32_t initZ, std::shared_ptr initHouse) : DynamicTile(initX, initY, initZ), house(std::move(initHouse)) { } diff --git a/src/map/house/housetile.hpp b/src/map/house/housetile.hpp index 6a191d0f84d..293fc0074ee 100644 --- a/src/map/house/housetile.hpp +++ b/src/map/house/housetile.hpp @@ -17,6 +17,7 @@ class HouseTile final : public DynamicTile { public: using Tile::addThing; + HouseTile(const Position &position, std::shared_ptr house); HouseTile(int32_t x, int32_t y, int32_t z, std::shared_ptr house); // cylinder implementations diff --git a/src/map/map.cpp b/src/map/map.cpp index 768ba959dce..8cb17c01752 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -442,6 +442,13 @@ void Map::moveCreature(const std::shared_ptr &creature, const std::sha } else { events(); } + + if (forceTeleport) { + if (const auto &player = creature->getPlayer()) { + player->sendMagicEffect(oldPos, CONST_ME_TELEPORT); + player->sendMagicEffect(newPos, CONST_ME_TELEPORT); + } + } } bool Map::canThrowObjectTo(const Position &fromPos, const Position &toPos, const SightLines_t lineOfSight /*= SightLine_CheckSightLine*/, const int32_t rangex /*= Map::maxClientViewportX*/, const int32_t rangey /*= Map::maxClientViewportY*/) { @@ -633,17 +640,6 @@ std::shared_ptr Map::canWalkTo(const std::shared_ptr &creature, return nullptr; } - const int32_t walkCache = creature->getWalkCache(pos); - - if (walkCache == 0) { - return nullptr; - } - - if (walkCache == 1) { - return getTile(pos.x, pos.y, pos.z); - } - - // used for non-cached tiles const auto &tile = getTile(pos.x, pos.y, pos.z); if (creature->getTile() != tile) { if (!tile || tile->queryAdd(0, creature, 1, FLAG_PATHFINDING | FLAG_IGNOREFIELDDAMAGE) != RETURNVALUE_NOERROR) { diff --git a/src/map/mapcache.cpp b/src/map/mapcache.cpp index 01fd9da63d8..f505c544fe2 100644 --- a/src/map/mapcache.cpp +++ b/src/map/mapcache.cpp @@ -120,20 +120,21 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::shared_ptr tile = nullptr; + auto pos = Position(x, y, z); + if (cachedTile->isHouse()) { - const auto &house = map->houses.getHouse(cachedTile->houseId); - tile = std::make_shared(x, y, z, house); - house->addTile(std::static_pointer_cast(tile)); + if (const auto &house = map->houses.getHouse(cachedTile->houseId)) { + tile = std::make_shared(pos, house); + tile->safeCall([tile] { + tile->getHouse()->addTile(tile->static_self_cast()); + }); + } else { + g_logger().error("[{}] house not found for houseId {}", std::source_location::current().function_name(), cachedTile->houseId); + } } else if (cachedTile->isStatic) { - tile = std::make_shared(x, y, z); + tile = std::make_shared(pos); } else { - tile = std::make_shared(x, y, z); - } - - auto pos = Position(x, y, z); - - for (const auto &creature : oldCreatureList) { - tile->internalAddThing(creature); + tile = std::make_shared(pos); } if (cachedTile->ground != nullptr) { @@ -146,15 +147,15 @@ std::shared_ptr MapCache::getOrCreateTileFromCache(const std::shared_ptrsetFlag(static_cast(cachedTile->flags)); - // add zone synchronously - g_dispatcher().context().tryAddEvent( - [tile, pos] { - for (const auto &zone : Zone::getZones(pos)) { - tile->addZone(zone); - } - }, - "Zone::getZones" - ); + tile->safeCall([tile, pos, movedOldCreatureList = std::move(oldCreatureList)]() { + for (const auto &creature : movedOldCreatureList) { + tile->internalAddThing(creature); + } + + for (const auto &zone : Zone::getZones(pos)) { + tile->addZone(zone); + } + }); floor->setTile(x, y, tile); diff --git a/src/map/spectators.cpp b/src/map/spectators.cpp index 74c6aa19af0..6a3ca09c513 100644 --- a/src/map/spectators.cpp +++ b/src/map/spectators.cpp @@ -41,7 +41,7 @@ Spectators Spectators::insertAll(const CreatureVector &list) { return *this; } -bool Spectators::checkCache(const SpectatorsCache::FloorData &specData, bool onlyPlayers, const Position ¢erPos, bool checkDistance, bool multifloor, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY) { +bool Spectators::checkCache(const SpectatorsCache::FloorData &specData, bool onlyPlayers, bool onlyMonsters, bool onlyNpcs, const Position ¢erPos, bool checkDistance, bool multifloor, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY) { const auto &list = multifloor || !specData.floor ? specData.multiFloor : specData.floor; if (!list) { @@ -58,12 +58,15 @@ bool Spectators::checkCache(const SpectatorsCache::FloorData &specData, bool onl spectators.reserve(creatures.size()); for (const auto &creature : *list) { const auto &specPos = creature->getPosition(); - if (centerPos.x - specPos.x >= minRangeX - && centerPos.y - specPos.y >= minRangeY - && centerPos.x - specPos.x <= maxRangeX - && centerPos.y - specPos.y <= maxRangeY - && (multifloor || specPos.z == centerPos.z) - && (!onlyPlayers || creature->getPlayer())) { + if ((centerPos.x - specPos.x >= minRangeX + && centerPos.y - specPos.y >= minRangeY + && centerPos.x - specPos.x <= maxRangeX + && centerPos.y - specPos.y <= maxRangeY + && (multifloor || specPos.z == centerPos.z) + && ((onlyPlayers && creature->getPlayer()) + || (onlyMonsters && creature->getMonster()) + || (onlyNpcs && creature->getNpc())) + || (!onlyPlayers && !onlyMonsters && !onlyNpcs))) { spectators.emplace_back(creature); } } @@ -75,7 +78,7 @@ bool Spectators::checkCache(const SpectatorsCache::FloorData &specData, bool onl return true; } -CreatureVector Spectators::getSpectators(const Position ¢erPos, bool multifloor, bool onlyPlayers, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY) { +CreatureVector Spectators::getSpectators(const Position ¢erPos, bool multifloor, bool onlyPlayers, bool onlyMonsters, bool onlyNpcs, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY) { uint8_t minRangeZ = centerPos.z; uint8_t maxRangeZ = centerPos.z; @@ -126,8 +129,12 @@ CreatureVector Spectators::getSpectators(const Position ¢erPos, bool multifl const MapSector* sectorE = sectorS; for (int32_t nx = startx1; nx <= endx2; nx += SECTOR_SIZE) { if (sectorE) { - const auto &node_list = onlyPlayers ? sectorE->player_list : sectorE->creature_list; - for (const auto &creature : node_list) { + const auto &nodeList = onlyPlayers ? sectorE->player_list + : onlyMonsters ? sectorE->monster_list + : onlyNpcs ? sectorE->npc_list + : sectorE->creature_list; + + for (const auto &creature : nodeList) { const auto &cpos = creature->getPosition(); if (static_cast(static_cast(cpos.z) - minRangeZ) <= depth) { const int_fast16_t offsetZ = Position::getOffsetZ(centerPos, cpos); @@ -152,14 +159,14 @@ CreatureVector Spectators::getSpectators(const Position ¢erPos, bool multifl return spectators; } -Spectators Spectators::find(const Position ¢erPos, bool multifloor, bool onlyPlayers, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY, bool useCache) { +Spectators Spectators::find(const Position ¢erPos, bool multifloor, bool onlyPlayers, bool onlyMonsters, bool onlyNpcs, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY, bool useCache) { minRangeX = (minRangeX == 0 ? -MAP_MAX_VIEW_PORT_X : -minRangeX); maxRangeX = (maxRangeX == 0 ? MAP_MAX_VIEW_PORT_X : maxRangeX); minRangeY = (minRangeY == 0 ? -MAP_MAX_VIEW_PORT_Y : -minRangeY); maxRangeY = (maxRangeY == 0 ? MAP_MAX_VIEW_PORT_Y : maxRangeY); if (!useCache) { - insertAll(getSpectators(centerPos, multifloor, onlyPlayers, minRangeX, maxRangeX, minRangeY, maxRangeY)); + insertAll(getSpectators(centerPos, multifloor, onlyPlayers, onlyMonsters, onlyNpcs, minRangeX, maxRangeX, minRangeY, maxRangeY)); return *this; } @@ -176,29 +183,38 @@ Spectators Spectators::find(const Position ¢erPos, bool multifloor, bool onl } else { const bool checkDistance = minRangeX != cache.minRangeX || maxRangeX != cache.maxRangeX || minRangeY != cache.minRangeY || maxRangeY != cache.maxRangeY; - if (onlyPlayers) { - // check players cache - if (checkCache(cache.players, true, centerPos, checkDistance, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { + if (onlyPlayers || onlyMonsters || onlyNpcs) { + static const SpectatorsCache::FloorData EMPTY_FLOOR_DATA; + + const auto &creaturesCache = onlyPlayers ? cache.players + : onlyMonsters ? cache.monsters + : onlyNpcs ? cache.npcs + : EMPTY_FLOOR_DATA; + + // check players/monsters/npcs cache + if (checkCache(creaturesCache, onlyPlayers, onlyMonsters, onlyNpcs, centerPos, checkDistance, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { return *this; } - // if there is no player cache, look for players in the creatures cache. - if (checkCache(cache.creatures, true, centerPos, true, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { + // if there is no players/monsters/npcs cache, look for players/monsters/npcs in the creatures cache. + if (checkCache(cache.creatures, onlyPlayers, onlyMonsters, onlyNpcs, centerPos, true, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { return *this; } - // All Creatures - } else if (checkCache(cache.creatures, false, centerPos, checkDistance, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { + } else if (checkCache(cache.creatures, false, false, false, centerPos, checkDistance, multifloor, minRangeX, maxRangeX, minRangeY, maxRangeY)) { return *this; } } } - const auto &spectators = getSpectators(centerPos, multifloor, onlyPlayers, minRangeX, maxRangeX, minRangeY, maxRangeY); + const auto &spectators = getSpectators(centerPos, multifloor, onlyPlayers, onlyMonsters, onlyNpcs, minRangeX, maxRangeX, minRangeY, maxRangeY); // It is necessary to create the cache even if no spectators is found, so that there is no future query. - auto &cache = cacheFound ? it->second : spectatorsCache.emplace(centerPos, SpectatorsCache { .minRangeX = minRangeX, .maxRangeX = maxRangeX, .minRangeY = minRangeY, .maxRangeY = maxRangeY, .creatures = {}, .players = {} }).first->second; - auto &creaturesCache = onlyPlayers ? cache.players : cache.creatures; + auto &cache = cacheFound ? it->second : spectatorsCache.emplace(centerPos, SpectatorsCache { .minRangeX = minRangeX, .maxRangeX = maxRangeX, .minRangeY = minRangeY, .maxRangeY = maxRangeY, .creatures = {}, .monsters = {}, .npcs = {}, .players = {} }).first->second; + auto &creaturesCache = onlyPlayers ? cache.players + : onlyMonsters ? cache.monsters + : onlyNpcs ? cache.npcs + : cache.creatures; auto &creatureList = (multifloor ? creaturesCache.multiFloor : creaturesCache.floor); if (creatureList) { creatureList->clear(); @@ -215,6 +231,40 @@ Spectators Spectators::find(const Position ¢erPos, bool multifloor, bool onl return *this; } +Spectators Spectators::excludeMaster() const { + auto specs = Spectators(); + if (creatures.empty()) { + return specs; + } + + specs.creatures.reserve(creatures.size()); + + for (const auto &c : creatures) { + if (c->getMonster() != nullptr && !c->getMaster()) { + specs.insert(c); + } + } + + return specs; +} + +Spectators Spectators::excludePlayerMaster() const { + auto specs = Spectators(); + if (creatures.empty()) { + return specs; + } + + specs.creatures.reserve(creatures.size()); + + for (const auto &c : creatures) { + if ((c->getMonster() != nullptr && !c->getMaster() || !c->getMaster()->getPlayer())) { + specs.insert(c); + } + } + + return specs; +} + Spectators Spectators::filter(bool onlyPlayers, bool onlyMonsters, bool onlyNpcs) const { auto specs = Spectators(); specs.creatures.reserve(creatures.size()); diff --git a/src/map/spectators.hpp b/src/map/spectators.hpp index 68ad751b056..f858603a791 100644 --- a/src/map/spectators.hpp +++ b/src/map/spectators.hpp @@ -30,6 +30,8 @@ struct SpectatorsCache { int32_t maxRangeY { 0 }; FloorData creatures; + FloorData monsters; + FloorData npcs; FloorData players; }; @@ -38,21 +40,26 @@ class Spectators { static void clearCache(); template - requires std::is_same_v || std::is_same_v + requires std::is_base_of_v Spectators find(const Position ¢erPos, bool multifloor = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0, bool useCache = true) { constexpr bool onlyPlayers = std::is_same_v; - return find(centerPos, multifloor, onlyPlayers, minRangeX, maxRangeX, minRangeY, maxRangeY, useCache); + constexpr bool onlyMonsters = std::is_same_v; + constexpr bool onlyNpcs = std::is_same_v; + return find(centerPos, multifloor, onlyPlayers, onlyMonsters, onlyNpcs, minRangeX, maxRangeX, minRangeY, maxRangeY, useCache); } template requires std::is_base_of_v Spectators filter() const { - bool onlyPlayers = std::is_same_v; - bool onlyMonsters = std::is_same_v; - bool onlyNpcs = std::is_same_v; + constexpr bool onlyPlayers = std::is_same_v; + constexpr bool onlyMonsters = std::is_same_v; + constexpr bool onlyNpcs = std::is_same_v; return filter(onlyPlayers, onlyMonsters, onlyNpcs); } + Spectators excludeMaster() const; + Spectators excludePlayerMaster() const; + Spectators insert(const std::shared_ptr &creature); Spectators insertAll(const CreatureVector &list); Spectators join(const Spectators &anotherSpectators) { @@ -90,12 +97,12 @@ class Spectators { private: static phmap::flat_hash_map spectatorsCache; - Spectators find(const Position ¢erPos, bool multifloor = false, bool onlyPlayers = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0, bool useCache = true); - CreatureVector getSpectators(const Position ¢erPos, bool multifloor = false, bool onlyPlayers = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0); + Spectators find(const Position ¢erPos, bool multifloor = false, bool onlyPlayers = false, bool onlyMonsters = false, bool onlyNpcs = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0, bool useCache = true); + CreatureVector getSpectators(const Position ¢erPos, bool multifloor = false, bool onlyPlayers = false, bool onlyMonsters = false, bool onlyNpcs = false, int32_t minRangeX = 0, int32_t maxRangeX = 0, int32_t minRangeY = 0, int32_t maxRangeY = 0); Spectators filter(bool onlyPlayers, bool onlyMonsters, bool onlyNpcs) const; - bool checkCache(const SpectatorsCache::FloorData &specData, bool onlyPlayers, const Position ¢erPos, bool checkDistance, bool multifloor, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY); + bool checkCache(const SpectatorsCache::FloorData &specData, bool onlyPlayers, bool onlyMonsters, bool onlyNpcs, const Position ¢erPos, bool checkDistance, bool multifloor, int32_t minRangeX, int32_t maxRangeX, int32_t minRangeY, int32_t maxRangeY); CreatureVector creatures; }; diff --git a/src/map/utils/mapsector.cpp b/src/map/utils/mapsector.cpp index f07c2a3e1b1..c6546ebd02c 100644 --- a/src/map/utils/mapsector.cpp +++ b/src/map/utils/mapsector.cpp @@ -17,6 +17,10 @@ void MapSector::addCreature(const std::shared_ptr &c) { creature_list.emplace_back(c); if (c->getPlayer()) { player_list.emplace_back(c); + } else if (c->getMonster()) { + monster_list.emplace_back(c); + } else if (c->getNpc()) { + npc_list.emplace_back(c); } } @@ -41,5 +45,25 @@ void MapSector::removeCreature(const std::shared_ptr &c) { assert(iter != player_list.end()); *iter = player_list.back(); player_list.pop_back(); + } else if (c->getMonster()) { + iter = std::ranges::find(monster_list, c); + if (iter == monster_list.end()) { + g_logger().error("[{}]: Monster not found in player_list!", __FUNCTION__); + return; + } + + assert(iter != monster_list.end()); + *iter = monster_list.back(); + monster_list.pop_back(); + } else if (c->getNpc()) { + iter = std::ranges::find(npc_list, c); + if (iter == npc_list.end()) { + g_logger().error("[{}]: NPC not found in player_list!", __FUNCTION__); + return; + } + + assert(iter != npc_list.end()); + *iter = npc_list.back(); + npc_list.pop_back(); } } diff --git a/src/map/utils/mapsector.hpp b/src/map/utils/mapsector.hpp index 58130007e5e..0b8be45e973 100644 --- a/src/map/utils/mapsector.hpp +++ b/src/map/utils/mapsector.hpp @@ -98,6 +98,8 @@ class MapSector { std::vector> creature_list; std::vector> player_list; + std::vector> monster_list; + std::vector> npc_list; mutable std::mutex floors_mutex; diff --git a/src/pch.hpp b/src/pch.hpp index 79f14433fcc..d66b5fc10ce 100644 --- a/src/pch.hpp +++ b/src/pch.hpp @@ -170,20 +170,5 @@ format_as(E e) { #include "lua/global/shared_object.hpp" -constexpr std::string_view methodName(const char* s) { - const std::string_view prettyFunction(s); - const size_t bracket = prettyFunction.rfind('('); - const size_t space = prettyFunction.rfind(' ', bracket) + 1; - return prettyFunction.substr(space, bracket - space); -} - -#if defined(__GNUC__) || defined(__clang__) - #define __METHOD_NAME__ methodName(__PRETTY_FUNCTION__) -#elif defined(_MSC_VER) - #define __METHOD_NAME__ methodName(__FUNCSIG__) -#else - #error "Compiler not supported" -#endif - #include "account/account_info.hpp" #include "config/config_enums.hpp" diff --git a/src/protobuf/appearances.proto b/src/protobuf/appearances.proto index ed924febfc4..1ca8defac0c 100644 --- a/src/protobuf/appearances.proto +++ b/src/protobuf/appearances.proto @@ -42,6 +42,7 @@ enum ITEM_CATEGORY { ITEM_CATEGORY_TIBIA_COINS = 23; ITEM_CATEGORY_CREATURE_PRODUCTS = 24; ITEM_CATEGORY_QUIVER = 25; + ITEM_CATEGORY_SOULCORES = 26; } enum PLAYER_PROFESSION { diff --git a/src/server/network/protocol/protocolgame.cpp b/src/server/network/protocol/protocolgame.cpp index 29270e08eb5..5ae18f2a5cb 100644 --- a/src/server/network/protocol/protocolgame.cpp +++ b/src/server/network/protocol/protocolgame.cpp @@ -9,6 +9,7 @@ #include "server/network/protocol/protocolgame.hpp" +#include "account/account.hpp" #include "config/configmanager.hpp" #include "core.hpp" #include "creatures/appearance/mounts/mounts.hpp" @@ -47,6 +48,7 @@ #include "lua/modules/modules.hpp" #include "server/network/message/outputmessage.hpp" #include "utils/tools.hpp" +#include "creatures/players/vocations/vocation.hpp" #include "enums/account_coins.hpp" #include "enums/account_group_type.hpp" @@ -62,16 +64,6 @@ // This "getIteration" function will allow us to get the total number of iterations that run within a specific map // Very useful to send the total amount in certain bytes in the ProtocolGame class namespace { - template - uint16_t getIterationIncreaseCount(T &map) { - uint16_t totalIterationCount = 0; - for ([[maybe_unused]] const auto &[first, second] : map) { - totalIterationCount++; - } - - return totalIterationCount; - } - template uint16_t getVectorIterationIncreaseCount(T &vector) { uint16_t totalIterationCount = 0; @@ -1014,24 +1006,24 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage &msg, uint8_t recvby case 0x1E: g_game().playerReceivePing(player->getID()); break; - case 0x2a: + case 0x28: + parseStashWithdraw(msg); + break; + case 0x29: + parseRetrieveDepotSearch(msg); + break; + case 0x2A: parseCyclopediaMonsterTracker(msg); break; case 0x2B: parsePartyAnalyzerAction(msg); break; - case 0x2c: + case 0x2C: parseLeaderFinderWindow(msg); break; - case 0x2d: + case 0x2D: parseMemberFinderWindow(msg); break; - case 0x28: - parseStashWithdraw(msg); - break; - case 0x29: - parseRetrieveDepotSearch(msg); - break; case 0x32: parseExtendedOpcode(msg); break; // otclient extended opcode @@ -1276,6 +1268,9 @@ void ProtocolGame::parsePacketFromDispatcher(NetworkMessage &msg, uint8_t recvby case 0xCD: parseInspectionObject(msg); break; + case 0xCF: + sendBlessingWindow(); + break; case 0xD2: g_game().playerRequestOutfit(player->getID()); break; @@ -1523,9 +1518,9 @@ void ProtocolGame::checkCreatureAsKnown(uint32_t id, bool &known, uint32_t &remo continue; } // We need to protect party players from removing - std::shared_ptr creature = g_game().getCreatureByID(*it); - if (std::shared_ptr checkPlayer; - creature && (checkPlayer = creature->getPlayer()) != nullptr) { + const auto &creature = g_game().getCreatureByID(*it); + const auto &checkPlayer = creature ? creature->getPlayer() : nullptr; + if (checkPlayer) { if (player->getParty() != checkPlayer->getParty() && !canSee(creature)) { removedKnown = *it; knownCreatureSet.erase(it); @@ -2315,7 +2310,7 @@ void ProtocolGame::parseBestiarysendRaces() { } NetworkMessage msg; - msg.addByte(0xd5); + msg.addByte(0xD5); msg.add(BESTY_RACE_LAST); std::map mtype_list = g_game().getBestiaryList(); for (uint8_t i = BESTY_RACE_FIRST; i <= BESTY_RACE_LAST; i++) { @@ -2347,7 +2342,7 @@ void ProtocolGame::sendBestiaryEntryChanged(uint16_t raceid) { } NetworkMessage msg; - msg.addByte(0xd9); + msg.addByte(0xD9); msg.add(raceid); writeToOutputBuffer(msg); } @@ -2381,7 +2376,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { uint8_t currentLevel = g_iobestiary().getKillStatus(mtype, killCounter); NetworkMessage newmsg; - newmsg.addByte(0xd7); + newmsg.addByte(0xD7); newmsg.add(raceId); newmsg.addString(Class); @@ -2443,7 +2438,7 @@ void ProtocolGame::parseBestiarysendMonsterData(NetworkMessage &msg) { } newmsg.addByte(attackmode); - newmsg.addByte(0x2); + newmsg.addByte(0x02); newmsg.add(mtype->info.healthMax); newmsg.add(mtype->info.experience); newmsg.add(mtype->getBaseSpeed()); @@ -2915,7 +2910,7 @@ void ProtocolGame::BestiarysendCharms() { removeRuneCost = (removeRuneCost * 75) / 100; } NetworkMessage msg; - msg.addByte(0xd8); + msg.addByte(0xD8); msg.add(player->getCharmPoints()); const auto charmList = g_game().getCharmList(); @@ -2994,7 +2989,7 @@ void ProtocolGame::parseBestiarysendCreatures(NetworkMessage &msg) { text = raceName; } NetworkMessage newmsg; - newmsg.addByte(0xd6); + newmsg.addByte(0xD6); newmsg.addString(text); newmsg.add(race.size()); std::map creaturesKilled = g_iobestiary().getBestiaryKillCountByMonsterIDs(player, race); @@ -3488,8 +3483,8 @@ void ProtocolGame::sendCyclopediaCharacterGeneralStats() { msg.add(player->getLevel()); msg.addByte(player->getLevelPercent()); msg.add(player->getBaseXpGain()); // BaseXPGainRate - msg.add(player->getGrindingXpBoost()); // LowLevelBonus - msg.add(player->getXpBoostPercent()); // XPBoost + msg.add(player->getDisplayGrindingXpBoost()); // LowLevelBonus + msg.add(player->getDisplayXpBoostPercent()); // XPBoost msg.add(player->getStaminaXpBoost()); // StaminaMultiplier(100=x1.0) msg.add(player->getXpBoostTime()); // xpBoostRemainingTime msg.addByte(player->getXpBoostTime() > 0 ? 0x00 : 0x01); // canBuyXpBoost @@ -4346,28 +4341,96 @@ void ProtocolGame::sendBasicData() { writeToOutputBuffer(msg); } -void ProtocolGame::sendBlessStatus() { +void ProtocolGame::sendBlessingWindow() { if (!player) { return; } NetworkMessage msg; - // uint8_t maxClientBlessings = (player->operatingSystem == CLIENTOS_NEW_WINDOWS) ? 8 : 6; (compartability for the client 10) - // Ignore ToF (bless 1) + msg.addByte(0x9B); + + bool isRetro = g_configManager().getBoolean(TOGGLE_SERVER_IS_RETRO); + + msg.addByte(isRetro ? 0x07 : 0x08); + for (auto blessing : magic_enum::enum_values()) { + if (isRetro && blessing == Blessings::TwistOfFate) { + continue; + } + + const auto blessingValue = enumToValue(blessing); + const auto blessingId = 1 << blessingValue; + msg.add(blessingId); + msg.addByte(player->getBlessingCount(blessingValue)); + msg.addByte(player->getBlessingCount(blessingValue, true)); + } + + // Start at "The Wisdom Of Solitude" uint8_t blessCount = 0; - uint16_t flag = 0; - uint16_t pow2 = 2; - for (int i = 1; i <= 8; i++) { - if (player->hasBlessing(i)) { - if (i > 1) { - blessCount++; - } + for (auto bless : magic_enum::enum_values()) { + if (bless == Blessings::TwistOfFate) { + continue; + } - flag |= pow2; + if (player->hasBlessing(enumToValue(bless))) { + blessCount++; + } + } + + const auto isPromoted = player->isPromoted(); + const auto factor = (isRetro ? 6.31 : 8); + const auto skillReduction = factor * blessCount; + const auto promotionReduction = (isPromoted ? 30 : 0); + const auto minReduction = skillReduction + promotionReduction; + const auto maxLossPvpDeath = calculateMaxPvpReduction(blessCount, isPromoted); + + msg.addByte(isPromoted); + msg.addByte(30); // Reduction bonus with promotion + msg.addByte(minReduction); + msg.addByte(isRetro ? minReduction : maxLossPvpDeath); + msg.addByte(minReduction); + + const auto playerSkull = player->getSkull(); + const auto &playerAmulet = player->getThing(CONST_SLOT_NECKLACE); + bool hasSkull = (playerSkull == Skulls_t::SKULL_RED || playerSkull == Skulls_t::SKULL_BLACK); + bool usingAol = (playerAmulet && playerAmulet->getItem()->getID() == ITEM_AMULETOFLOSS); + if (hasSkull) { + msg.addByte(100); + msg.addByte(100); + } else if (usingAol) { + msg.addByte(0); + msg.addByte(0); + } else { + msg.addByte(calculateEquipmentLoss(blessCount, true)); + msg.addByte(calculateEquipmentLoss(blessCount, true)); + } + + msg.addByte(hasSkull); + msg.addByte(usingAol); + + msg.addByte(0x00); + + writeToOutputBuffer(msg); +} + +void ProtocolGame::sendBlessStatus() { + if (!player) { + return; + } + + // Ignore Twist of Fate (Id 1) + uint8_t blessCount = 0; + for (auto bless : magic_enum::enum_values()) { + if (bless == Blessings::TwistOfFate) { + continue; + } + if (player->hasBlessing(enumToValue(bless))) { + blessCount++; } } + NetworkMessage msg; msg.addByte(0x9C); + if (oldProtocol) { msg.add(blessCount >= 5 ? 0x01 : 0x00); } else { @@ -4380,16 +4443,20 @@ void ProtocolGame::sendBlessStatus() { } void ProtocolGame::sendPremiumTrigger() { - if (!g_configManager().getBoolean(FREE_PREMIUM) && !g_configManager().getBoolean(VIP_SYSTEM_ENABLED)) { - NetworkMessage msg; - msg.addByte(0x9E); - msg.addByte(16); - for (uint16_t i = 0; i <= 15; i++) { - // PREMIUM_TRIGGER_TRAIN_OFFLINE = false, PREMIUM_TRIGGER_XP_BOOST = false, PREMIUM_TRIGGER_MARKET = false, PREMIUM_TRIGGER_VIP_LIST = false, PREMIUM_TRIGGER_DEPOT_SPACE = false, PREMIUM_TRIGGER_INVITE_PRIVCHAT = false - msg.addByte(0x01); - } - writeToOutputBuffer(msg); + if (g_configManager().getBoolean(FREE_PREMIUM) || g_configManager().getBoolean(VIP_SYSTEM_ENABLED)) { + return; + } + + NetworkMessage msg; + msg.addByte(0x9E); + + msg.addByte(16); + for (uint16_t i = 0; i <= 15; i++) { + // PREMIUM_TRIGGER_TRAIN_OFFLINE = false, PREMIUM_TRIGGER_XP_BOOST = false, PREMIUM_TRIGGER_MARKET = false, PREMIUM_TRIGGER_VIP_LIST = false, PREMIUM_TRIGGER_DEPOT_SPACE = false, PREMIUM_TRIGGER_INVITE_PRIVCHAT = false + msg.addByte(0x01); } + + writeToOutputBuffer(msg); } void ProtocolGame::sendTextMessage(const TextMessage &message) { @@ -5482,8 +5549,8 @@ void ProtocolGame::sendOpenForge() { msg.add(convergenceFusionCount); msg.setBufferPosition(transferTotalCountPosition); - auto transferTotalCount = getIterationIncreaseCount(donorTierItemMap); - msg.addByte(static_cast(transferTotalCount)); + auto transferTotalCount = donorTierItemMap.size(); + msg.addByte(transferTotalCount); if (transferTotalCount > 0) { for (const auto &[itemId, tierAndCountMap] : donorTierItemMap) { // Let's access the itemType to check the item's (donator of tier) classification level @@ -5495,7 +5562,7 @@ void ProtocolGame::sendOpenForge() { } // Total count of item (donator of tier) - auto donorTierTotalItemsCount = getIterationIncreaseCount(tierAndCountMap); + auto donorTierTotalItemsCount = tierAndCountMap.size(); msg.add(donorTierTotalItemsCount); for (const auto &[donorItemTier, donorItemCount] : tierAndCountMap) { msg.add(itemId); @@ -5680,20 +5747,27 @@ void ProtocolGame::sendForgeResult(ForgeAction_t actionType, uint16_t leftItemId void ProtocolGame::sendForgeHistory(uint8_t page) { page = page + 1; auto historyVector = player->getForgeHistory(); - auto historyVectorLen = getVectorIterationIncreaseCount(historyVector); + auto historyVectorLen = historyVector.size(); - uint16_t lastPage = (1 < std::floor((historyVectorLen - 1) / 9) + 1) ? static_cast(std::floor((historyVectorLen - 1) / 9) + 1) : 1; - uint16_t currentPage = (lastPage < page) ? lastPage : page; + uint16_t currentPage = 1; + uint16_t lastPage = 1; + uint16_t pageFirstEntry = 0; + uint16_t pageLastEntry = 0; std::vector historyPerPage; - uint16_t pageFirstEntry = (0 < historyVectorLen - (currentPage - 1) * 9) ? historyVectorLen - (currentPage - 1) * 9 : 0; - uint16_t pageLastEntry = (0 < historyVectorLen - currentPage * 9) ? historyVectorLen - currentPage * 9 : 0; - for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) { - historyPerPage.emplace_back(historyVector[entry - 1]); - } + if (historyVectorLen > 0) { + lastPage = std::clamp(std::floor((historyVectorLen - 1) / 9) + 1, 0, std::numeric_limits::max()); + currentPage = (lastPage < page) ? lastPage : page; - auto historyPageToSend = getVectorIterationIncreaseCount(historyPerPage); + pageFirstEntry = std::clamp(historyVectorLen - (currentPage - 1) * 9, 0, std::numeric_limits::max()); + pageLastEntry = historyVectorLen > currentPage * 9 ? std::clamp(historyVectorLen - currentPage * 9, 0, std::numeric_limits::max()) : 0; + for (uint16_t entry = pageFirstEntry; entry > pageLastEntry; --entry) { + historyPerPage.emplace_back(historyVector[entry - 1]); + } + } + + auto historyPageToSend = historyPerPage.size(); NetworkMessage msg; msg.addByte(0x88); msg.add(currentPage - 1); // Current page @@ -7778,8 +7852,8 @@ void ProtocolGame::AddPlayerStats(NetworkMessage &msg) { msg.add(player->getVoucherXpBoost()); // xp voucher } - msg.add(player->getGrindingXpBoost()); // low level bonus - msg.add(player->getXpBoostPercent()); // xp boost + msg.add(player->getDisplayGrindingXpBoost()); // low level bonus + msg.add(player->getDisplayXpBoostPercent()); // xp boost msg.add(player->getStaminaXpBoost()); // stamina multiplier (100 = 1.0x) if (!oldProtocol) { @@ -8860,7 +8934,11 @@ void ProtocolGame::parseSendBosstiarySlots() { uint32_t boostedBossId = g_ioBosstiary().getBoostedBossId(); // Sanity checks - std::string boostedBossName = g_ioBosstiary().getBoostedBossName(); + const std::string &boostedBossName = g_ioBosstiary().getBoostedBossName(); + if (boostedBossName.empty()) { + g_logger().error("[{}] The boosted boss name is empty", __FUNCTION__); + return; + } const auto mTypeBoosted = g_monsters().getMonsterType(boostedBossName); auto boostedBossRace = mTypeBoosted ? mTypeBoosted->info.bosstiaryRace : BosstiaryRarity_t::BOSS_INVALID; auto isValidBoostedBoss = boostedBossId == 0 || (boostedBossRace >= BosstiaryRarity_t::RARITY_BANE && boostedBossRace <= BosstiaryRarity_t::RARITY_NEMESIS); diff --git a/src/server/network/protocol/protocolgame.hpp b/src/server/network/protocol/protocolgame.hpp index 27fa6c8716c..2048bea7c16 100644 --- a/src/server/network/protocol/protocolgame.hpp +++ b/src/server/network/protocol/protocolgame.hpp @@ -466,7 +466,10 @@ class ProtocolGame final : public Protocol { void AddPlayerStats(NetworkMessage &msg); void AddOutfit(NetworkMessage &msg, const Outfit_t &outfit, bool addMount = true); void AddPlayerSkills(NetworkMessage &msg); + // Blessing + void sendBlessingWindow(); void sendBlessStatus(); + // End Blessing void sendPremiumTrigger(); void sendMessageDialog(const std::string &message); void AddWorldLight(NetworkMessage &msg, LightInfo lightInfo); diff --git a/src/server/signals.cpp b/src/server/signals.cpp index 29382c55809..1e6e0e4ece7 100644 --- a/src/server/signals.cpp +++ b/src/server/signals.cpp @@ -19,6 +19,7 @@ #include "lua/creature/events.hpp" #include "lua/global/globalevent.hpp" #include "lua/scripts/lua_environment.hpp" +#include "lib/di/container.hpp" Signals::Signals(asio::io_service &service) : set(service) { diff --git a/src/utils/definitions.hpp b/src/utils/definitions.hpp index d557896f361..24a6b7d134b 100644 --- a/src/utils/definitions.hpp +++ b/src/utils/definitions.hpp @@ -13,6 +13,8 @@ #define __FUNCTION__ __func__ #endif +#define __METRICS_METHOD_NAME__ std::source_location::current().function_name() + #ifndef _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS #endif diff --git a/src/utils/pugicast.hpp b/src/utils/pugicast.hpp index b59e95d37ab..91043596605 100644 --- a/src/utils/pugicast.hpp +++ b/src/utils/pugicast.hpp @@ -38,14 +38,12 @@ namespace pugi { // If the string could not be parsed as the specified type if (errorCode == std::errc::invalid_argument) { // Throw an exception indicating that the argument is invalid - logError(fmt::format("Invalid argument {}", str)); - throw std::invalid_argument("Invalid argument: " + std::string(str)); + logError(fmt::format("[{}] Invalid argument {}", __FUNCTION__, str)); } // If the parsed value is out of range for the specified type else if (errorCode == std::errc::result_out_of_range) { // Throw an exception indicating that the result is out of range - logError(fmt::format("Result out of range: {}", str)); - throw std::out_of_range("Result out of range: " + std::string(str)); + logError(fmt::format("[{}] Result out of range: {}", __FUNCTION__, str)); } // Return a default value if no exception is thrown diff --git a/src/utils/tools.cpp b/src/utils/tools.cpp index f393f5332ae..57c9c873282 100644 --- a/src/utils/tools.cpp +++ b/src/utils/tools.cpp @@ -1145,12 +1145,12 @@ CombatType_t getCombatTypeByName(const std::string &combatname) { return it != combatTypeNames.end() ? it->first : COMBAT_NONE; } -size_t combatTypeToIndex(CombatType_t combatType) { +size_t combatTypeToIndex(CombatType_t combatType, std::source_location location) { const auto enum_index_opt = magic_enum::enum_index(combatType); if (enum_index_opt.has_value() && enum_index_opt.value() < COMBAT_COUNT) { return enum_index_opt.value(); } else { - g_logger().error("[{}] Combat type {} is out of range", __FUNCTION__, fmt::underlying(combatType)); + g_logger().error("[{}] Combat type {} is out of range, called line '{}:{}' in '{}'", __FUNCTION__, fmt::underlying(combatType), location.line(), location.column(), location.function_name()); // Uncomment for catch the function call with debug // throw std::out_of_range("Combat is out of range"); } @@ -1583,6 +1583,12 @@ SpellGroup_t stringToSpellGroup(const std::string &value) { if (tmpStr == "ultimatestrikes" || tmpStr == "8") { return SPELLGROUP_ULTIMATESTRIKES; } + if (tmpStr == "burstsofnature" || tmpStr == "9") { + return SPELLGROUP_BURSTS_OF_NATURE; + } + if (tmpStr == "greatbeams" || tmpStr == "10") { + return SPELLGROUP_GREAT_BEAMS; + } return SPELLGROUP_NONE; } @@ -2079,3 +2085,44 @@ const std::map &getMaxValuePerSkill() { return maxValuePerSkill; } + +float calculateEquipmentLoss(uint8_t blessingAmount, bool isContainer /* = false*/) { + float lossPercent = 0; + switch (blessingAmount) { + case 0: + lossPercent = 10; + break; + case 1: + lossPercent = 7; + break; + case 2: + lossPercent = 4.5; + break; + case 3: + lossPercent = 2.5; + break; + case 4: + lossPercent = 1; + break; + default: + // Blessing Amount >= 5 + lossPercent = 0; + break; + } + + return isContainer ? lossPercent * 10 : lossPercent; +} + +uint8_t calculateMaxPvpReduction(uint8_t blessCount, bool isPromoted /* = false*/) { + uint8_t result = 80 + (2 * blessCount) - (blessCount / 3); + + if (blessCount == 5) { + result -= 1; + } + + if (isPromoted) { + result += 6; + } + + return result; +} diff --git a/src/utils/tools.hpp b/src/utils/tools.hpp index 7a7d4a22bdd..64fd2e8c1e6 100644 --- a/src/utils/tools.hpp +++ b/src/utils/tools.hpp @@ -137,7 +137,7 @@ CombatType_t getCombatTypeByName(const std::string &combatname); * @return The corresponding index of the CombatType_t enumeration. * If the CombatType_t is out of range, this function will log an error and return an empty size_t. */ -size_t combatTypeToIndex(CombatType_t combatType); +size_t combatTypeToIndex(CombatType_t combatType, std::source_location location = std::source_location::current()); /** * @brief Convert the CombatType_t enumeration to its corresponding string representation. @@ -212,3 +212,6 @@ bool caseInsensitiveCompare(std::string_view str1, std::string_view str2, size_t void printStackTrace(); const std::map &getMaxValuePerSkill(); + +float calculateEquipmentLoss(uint8_t blessingAmount, bool isContainer = false); +uint8_t calculateMaxPvpReduction(uint8_t blessCount, bool isPromoted = false); diff --git a/vcproj/canary.vcxproj b/vcproj/canary.vcxproj index 7cbdd118ccc..6436dd704a9 100644 --- a/vcproj/canary.vcxproj +++ b/vcproj/canary.vcxproj @@ -137,7 +137,6 @@ - @@ -336,7 +335,6 @@ -