From 1c8a885b516492dd24574906e98669334867b8ff Mon Sep 17 00:00:00 2001 From: Marco Date: Mon, 30 Sep 2024 20:32:48 -0300 Subject: [PATCH 1/2] refactor: improve readability and optimize toPosition function --- data-otservbr-global/lib/quests/soul_war.lua | 18 ------------------ data/libs/functions/functions.lua | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/data-otservbr-global/lib/quests/soul_war.lua b/data-otservbr-global/lib/quests/soul_war.lua index 668c67f92b9..f5b2d75f5ba 100644 --- a/data-otservbr-global/lib/quests/soul_war.lua +++ b/data-otservbr-global/lib/quests/soul_war.lua @@ -1569,21 +1569,3 @@ function Creature:applyZoneEffect(var, combat, zoneName) return true end - -function string.toPosition(str) - local patterns = { - -- table format - "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", - -- Position format - "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", - -- x, y, z format - "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", - } - - for _, pattern in ipairs(patterns) do - local x, y, z = string.match(str, pattern) - if x and y and z then - return Position(tonumber(x), tonumber(y), tonumber(z)) - end - end -end diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index c2349ce7fd6..7afb6b94375 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -1154,3 +1154,19 @@ function onDeathForDamagingPlayers(creature, func) end end end + +function string.toPosition(inputString) + local positionPatterns = { + "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", + "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", + "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", + } + + for _, pattern in ipairs(positionPatterns) do + local posX, posY, posZ = string.match(inputString, pattern) + if posX and posY and posZ then + return Position(tonumber(posX), tonumber(posY), tonumber(posZ)) + end + end + return nil +end From b571c5fbd60ee6a7dfc7190eff61927a41f6dece Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 17 Oct 2024 16:44:51 -0300 Subject: [PATCH 2/2] resolve conversation --- data/libs/functions/functions.lua | 16 ---------------- data/libs/functions/string.lua | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/data/libs/functions/functions.lua b/data/libs/functions/functions.lua index 7afb6b94375..c2349ce7fd6 100644 --- a/data/libs/functions/functions.lua +++ b/data/libs/functions/functions.lua @@ -1154,19 +1154,3 @@ function onDeathForDamagingPlayers(creature, func) end end end - -function string.toPosition(inputString) - local positionPatterns = { - "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", - "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", - "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", - } - - for _, pattern in ipairs(positionPatterns) do - local posX, posY, posZ = string.match(inputString, pattern) - if posX and posY and posZ then - return Position(tonumber(posX), tonumber(posY), tonumber(posZ)) - end - end - return nil -end diff --git a/data/libs/functions/string.lua b/data/libs/functions/string.lua index 9d746b82e3a..42b7a8bab4b 100644 --- a/data/libs/functions/string.lua +++ b/data/libs/functions/string.lua @@ -129,3 +129,19 @@ end string.capitalize = function(str) return str:gsub("%f[%a].", string.upper) end + +function string.toPosition(inputString) + local positionPatterns = { + "{%s*x%s*=%s*(%d+)%s*,%s*y%s*=%s*(%d+)%s*,%s*z%s*=%s*(%d+)%s*}", + "Position%s*%((%d+)%s*,%s*(%d+)%s*,%s*(%d+)%s*%)", + "(%d+)%s*,%s*(%d+)%s*,%s*(%d+)", + } + + for _, pattern in ipairs(positionPatterns) do + local posX, posY, posZ = string.match(inputString, pattern) + if posX and posY and posZ then + return Position(tonumber(posX), tonumber(posY), tonumber(posZ)) + end + end + return nil +end