Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
caioavidal committed Dec 28, 2024
1 parent d61f282 commit cb4c720
Show file tree
Hide file tree
Showing 118 changed files with 1,779 additions and 2,163 deletions.
4 changes: 2 additions & 2 deletions data/LuaJit/core.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
logger.debug('Starting lua.')
logger.debug(tostring(os.getenv('LOCAL_LUA_DEBUGGER_VSCODE')))
if os.getenv('LOCAL_LUA_DEBUGGER_VSCODE') == '1' then
require('lldebugger').start()
logger.debug('Started LUA debugger.')
require('lldebugger').start()
logger.debug('Started LUA debugger.')
end

CORE_DIRECTORY = configKeys.BASE_DIRECTORY
Expand Down
40 changes: 20 additions & 20 deletions data/LuaJit/global.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,38 @@ SAVE_INTERVAL_TYPE = configManager.getString(configKeys.SAVE_INTERVAL_TYPE)
SAVE_INTERVAL_CONFIG_TIME = configManager.getNumber(configKeys.SAVE_INTERVAL_TIME)
SAVE_INTERVAL_TIME = 0
if SAVE_INTERVAL_TYPE == "second" then
SAVE_INTERVAL_TIME = 1000
SAVE_INTERVAL_TIME = 1000
elseif SAVE_INTERVAL_TYPE == "minute" then
SAVE_INTERVAL_TIME = 60 * 1000
SAVE_INTERVAL_TIME = 60 * 1000
elseif SAVE_INTERVAL_TYPE == "hour" then
SAVE_INTERVAL_TIME = 60 * 60 * 1000
SAVE_INTERVAL_TIME = 60 * 60 * 1000
end

table.contains = function(array, value)
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
for _, targetColumn in pairs(array) do
if targetColumn == value then
return true
end
end
return false
end

string.split = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
res[#res + 1] = v
end
return res
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
res[#res + 1] = v
end
return res
end

string.splitTrimmed = function(str, sep)
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
res[#res + 1] = v:trim()
end
return res
local res = {}
for v in str:gmatch("([^" .. sep .. "]+)") do
res[#res + 1] = v:trim()
end
return res
end

string.trim = function(str)
return str:match'^()%s*$' and '' or str:match'^%s*(.*%S)'
return str:match '^()%s*$' and '' or str:match '^%s*(.*%S)'
end
18 changes: 9 additions & 9 deletions data/LuaJit/libs/functions/creature.lua
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
function Creature.getMonster(self)
return self:isMonster() and self or nil
return self:isMonster() and self or nil
end

function Creature.getPlayer(self)
return self:isPlayer() and self or nil
return self:isPlayer() and self or nil
end

function Creature.isContainer(self)
return false
return false
end

function Creature.isItem(self)
return false
return false
end

function Creature.isMonster(self)
return false
return false
end

function Creature.isNpc(self)
return false
return false
end

function Creature.isPlayer(self)
return false
return false
end

function Creature.isTeleport(self)
return false
return false
end

function Creature.isTile(self)
return false
return false
end
16 changes: 8 additions & 8 deletions data/LuaJit/libs/functions/item.lua
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
function Item.getType(self)
return ItemType(self:getId())
return ItemType(self:getId())
end

function Item.isContainer(self)
return false
return false
end

function Item.isCreature(self)
return false
return false
end

function Item.isMonster(self)
return false
return false
end

function Item.isNpc(self)
return false
return false
end

function Item.isPlayer(self)
return false
return false
end

function Item.isTeleport(self)
return false
return false
end

function Item.isTile(self)
return false
return false
end
8 changes: 4 additions & 4 deletions data/LuaJit/libs/functions/player.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Player.sendCancelMessage(self, message)
if type(message) == "number" then
message = Game.getReturnMessage(message)
end
return self:sendTextMessage(MESSAGE_STATUS_SMALL, message)
if type(message) == "number" then
message = Game.getReturnMessage(message)
end
return self:sendTextMessage(MESSAGE_STATUS_SMALL, message)
end
114 changes: 57 additions & 57 deletions data/LuaJit/libs/functions/position.lua
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
Position.directionOffset = {
[DIRECTION_NORTH] = {x = 0, y = -1},
[DIRECTION_EAST] = {x = 1, y = 0},
[DIRECTION_SOUTH] = {x = 0, y = 1},
[DIRECTION_WEST] = {x = -1, y = 0},
[DIRECTION_SOUTHWEST] = {x = -1, y = 1},
[DIRECTION_SOUTHEAST] = {x = 1, y = 1},
[DIRECTION_NORTHWEST] = {x = -1, y = -1},
[DIRECTION_NORTHEAST] = {x = 1, y = -1}
[DIRECTION_NORTH] = { x = 0, y = -1 },
[DIRECTION_EAST] = { x = 1, y = 0 },
[DIRECTION_SOUTH] = { x = 0, y = 1 },
[DIRECTION_WEST] = { x = -1, y = 0 },
[DIRECTION_SOUTHWEST] = { x = -1, y = 1 },
[DIRECTION_SOUTHEAST] = { x = 1, y = 1 },
[DIRECTION_NORTHWEST] = { x = -1, y = -1 },
[DIRECTION_NORTHEAST] = { x = 1, y = -1 }
}

function Position:getNextPosition(direction, steps)
local offset = Position.directionOffset[direction]
if offset then
steps = steps or 1
self.x = self.x + offset.x * steps
self.y = self.y + offset.y * steps
end
local offset = Position.directionOffset[direction]
if offset then
steps = steps or 1
self.x = self.x + offset.x * steps
self.y = self.y + offset.y * steps
end
end

function Position:moveUpstairs()
local swap = function (lhs, rhs)
lhs.x, rhs.x = rhs.x, lhs.x
lhs.y, rhs.y = rhs.y, lhs.y
lhs.z, rhs.z = rhs.z, lhs.z
end
local swap = function(lhs, rhs)
lhs.x, rhs.x = rhs.x, lhs.x
lhs.y, rhs.y = rhs.y, lhs.y
lhs.z, rhs.z = rhs.z, lhs.z
end

self.z = self.z - 1
self.z = self.z - 1

local defaultPosition = self + Position.directionOffset[DIRECTION_SOUTH]
local toTile = Tile(defaultPosition)
if not toTile or not toTile:isWalkable() then
for direction = DIRECTION_NORTH, DIRECTION_NORTHEAST do
if direction == DIRECTION_SOUTH then
direction = DIRECTION_WEST
end
local defaultPosition = self + Position.directionOffset[DIRECTION_SOUTH]
local toTile = Tile(defaultPosition)
if not toTile or not toTile:isWalkable() then
for direction = DIRECTION_NORTH, DIRECTION_NORTHEAST do
if direction == DIRECTION_SOUTH then
direction = DIRECTION_WEST
end

local position = self + Position.directionOffset[direction]
toTile = Tile(position)
if toTile and toTile:isWalkable() then
swap(self, position)
return self
end
end
end
swap(self, defaultPosition)
return self
local position = self + Position.directionOffset[direction]
toTile = Tile(position)
if toTile and toTile:isWalkable() then
swap(self, position)
return self
end
end
end
swap(self, defaultPosition)
return self
end

function Position:isInRange(from, to)
-- No matter what corner from and to is, we want to make
-- life easier by calculating north-west and south-east
local zone = {
nW = {
x = (from.x < to.x and from.x or to.x),
y = (from.y < to.y and from.y or to.y),
z = (from.z < to.z and from.z or to.z)
},
sE = {
x = (to.x > from.x and to.x or from.x),
y = (to.y > from.y and to.y or from.y),
z = (to.z > from.z and to.z or from.z)
}
}
-- No matter what corner from and to is, we want to make
-- life easier by calculating north-west and south-east
local zone = {
nW = {
x = (from.x < to.x and from.x or to.x),
y = (from.y < to.y and from.y or to.y),
z = (from.z < to.z and from.z or to.z)
},
sE = {
x = (to.x > from.x and to.x or from.x),
y = (to.y > from.y and to.y or from.y),
z = (to.z > from.z and to.z or from.z)
}
}

if self.x >= zone.nW.x and self.x <= zone.sE.x
and self.y >= zone.nW.y and self.y <= zone.sE.y
and self.z >= zone.nW.z and self.z <= zone.sE.z then
return true
end
return false
if self.x >= zone.nW.x and self.x <= zone.sE.x
and self.y >= zone.nW.y and self.y <= zone.sE.y
and self.z >= zone.nW.z and self.z <= zone.sE.z then
return true
end
return false
end
Loading

0 comments on commit cb4c720

Please sign in to comment.