Add support for preset map coordinates

This commit is contained in:
Matt Wagner 2021-08-24 19:10:16 -07:00
parent ba79ab2e5e
commit 5a418e2c94
5 changed files with 110 additions and 13 deletions

View File

@ -136,6 +136,7 @@ function lotj.infoPanel.createBasicStats(container)
wireGaugeUpdate(manaGauge, "Char.Vitals.mana", "Char.Vitals.maxMana", "mn", "gmcp.Char.Vitals")
lotj.setup.registerEventHandler("gmcp.Char.Vitals", function()
if not gmcp.Char or not gmcp.Char.Vitals then return end
local totalSpace = lotj.layout.lowerInfoPanelHeight
local manaMax = gmcp.Char.Vitals.maxMana or 0
if manaMax > 0 then
@ -357,6 +358,7 @@ end
-- Sets up timers to refresh the space tick counter
function lotj.infoPanel.markSpaceTick()
local spaceStatFontSize = getFontSize()-1
for _, timerId in ipairs(lotj.infoPanel.spaceTickTimers or {}) do
killTimer(timerId)
end

View File

@ -116,6 +116,8 @@ function lotj.mapper.mapCommand(input)
lotj.mapper.shiftCurrentRoom(args)
elseif cmd == "save" then
lotj.mapper.saveMap()
elseif cmd == "setroomcoords" then
lotj.mapper.setRoomCoords(args)
else
lotj.mapper.logError("Unknown map command. Try <yellow>map help<reset>.")
end
@ -185,6 +187,18 @@ Deletes all data for an area. There's no confirmation and no undo!
Moves the current room in whichever direction you enter. Useful for adjusting placement of
rooms when you need to space them out.
]])
if gmcp.Char.Info.immLevel and gmcp.Char.Info.immLevel >= 102 then
cecho([[
<yellow>map setroomcoords <area name><reset>
<orange>(Staff Command)<reset> Assuming you are happy with your local copy of a map, sends commands to the
game to set the x/y/z coordinates of all rooms. (Requires the 'at' command.)
]])
end
end
@ -280,6 +294,25 @@ function lotj.mapper.saveMap()
end
function lotj.mapper.setRoomCoords(areaName)
if not gmcp.Char.Info.immLevel or gmcp.Char.Info.immLevel < 102 then
lotj.mapper.logError("This command only works for imm characters.")
return
end
local areaId = getAreaTable()[areaName]
if not areaId then
lotj.mapper.logError("Area not found by name "..areaName)
return
end
for _, roomId in ipairs(getAreaRooms(areaId)) do
local x, y, z = getRoomCoordinates(roomId)
send("at "..roomId.." redit xyz "..x.." "..y.." "..z)
end
end
------------------------------------------------------------------------------
-- Event Handlers
------------------------------------------------------------------------------
@ -329,17 +362,30 @@ function lotj.mapper.handleSentCommand(event, cmd)
local dir = dirObj(trim(cmd))
if dir ~= nil then
lotj.mapper.lastMoveDir = dir
lotj.mapper.lastMoveDirs = lotj.mapper.lastMoveDirs or {}
table.insert(lotj.mapper.lastMoveDirs, dir)
lotj.mapper.logDebug("Pushed movement dir: "..dir.long)
end
end
function lotj.mapper.popMoveDir()
if not lotj.mapper.lastMoveDirs or #lotj.mapper.lastMoveDirs == 0 then
lotj.mapper.logDebug("Popped movement dir: nil")
return nil
end
local result = table.remove(lotj.mapper.lastMoveDirs, 1)
lotj.mapper.logDebug("Popped movement dir: "..result.long)
return result
end
-- Function used to handle a room that we've moved into. This will use the data on
-- lotj.mapper.current, compared with lotj.mapper.last, to potentially create a new room and
-- link it with an exit on the previous room.
function lotj.mapper.processCurrentRoom()
local vnum = lotj.mapper.current.vnum
local moveDir = lotj.mapper.lastMoveDir
local moveDir = lotj.mapper.popMoveDir()
local room = lotj.mapper.getRoomByVnum(vnum)
if lotj.mapper.mappingArea == nil and room == nil then
@ -372,13 +418,29 @@ function lotj.mapper.processCurrentRoom()
end
end
-- Position the room relative to the room we came from
local lastRoomAtPresetCoords = false
if lastRoom ~= nil then
-- Figure out if our last room was positioned by ingame room settings.
local lastX, lastY, lastZ = getRoomCoordinates(lotj.mapper.last.vnum)
if lotj.mapper.last.x == lastX and
lotj.mapper.last.y == lastY and
lotj.mapper.last.z == lastZ then
lastRoomAtPresetCoords = true
end
end
if lotj.mapper.current.x ~= nil and (not lastRoom or lastRoomAtPresetCoords) then
-- This room has x/y/z set ingame and we're not coming from a lastRoom with
-- a custom direction, so we should honor what the game said to use.
setRoomCoordinates(vnum, lotj.mapper.current.x, lotj.mapper.current.y, lotj.mapper.current.z)
elseif lastRoom ~= nil then
-- Position the room relative to the room we came from
local lastX, lastY, lastZ = getRoomCoordinates(lotj.mapper.last.vnum)
-- If we recorded a valid movement command, use that direction to position this room
if moveDir ~= nil then
local dx, dy, dz = unpack(moveDir.xyzDiff)
lotj.mapper.log("Positioning new room "..moveDir.long.." of the previous room based on movement command.")
setRoomCoordinates(vnum, lastX+dx, lastY+dy, lastZ+dz)
else
-- We didn't have a valid movement command but we still changed rooms, so try to guess
@ -494,6 +556,13 @@ function lotj.mapper.onEnterRoom()
planet = gmcp.Room.Info.planet,
}
-- This room has coordinates set in the game which we should use.
if gmcp.Room.Info.x ~= nil then
lotj.mapper.current.x = gmcp.Room.Info.x
lotj.mapper.current.y = gmcp.Room.Info.y
lotj.mapper.current.z = gmcp.Room.Info.z
end
-- If the new room has has a planet different than the last one and we don't have
-- an area for that planet yet, give a prompt about how to start mapping it.
if lotj.mapper.current.planet then
@ -507,10 +576,6 @@ function lotj.mapper.onEnterRoom()
end
lotj.mapper.processCurrentRoom()
-- Since we've handled the move, we don't want the last move command to get
-- used by anything else.
lotj.mapper.lastMoveDir = nil
end

View File

@ -6,17 +6,17 @@ local function starts_with(str, start)
return str:sub(1, #start) == start
end
if starts_with(line, "Use SHOWPLANET for more information.") then
-- After all the planets there's a blank line
if line == "" then
lotj.galaxyMap.enqueuePendingRefreshCommands()
return
end
line = line:gsub("%(UFG%)", "")
line = line:gsub(" +", ";")
local startIdx, _, planet, system, gov, support, military = line:find("([^;]+);([^;]+);([^;]+);([^;]+);([^;]+)")
local startIdx, _, planet, system, gov, notices = line:find("([^;]+);([^;]+);([^;]+);([^;]+)")
if not startIdx then
gov = "None"
startIdx, _, planet, system, support, military = line:find("([^;]+);([^;]+);([^;]+);([^;]+)")
startIdx, _, planet, system, notices = line:find("([^;]+);([^;]+);([^;]+)")
end
if not startIdx then
echo("\n")

View File

@ -9,7 +9,7 @@
"fireLength": 1,
"patterns": [
{
"pattern": "Planet\\s+Starsystem\\s+Governed By\\s+Opinion\\s+Military",
"pattern": "Planet\\s+Starsystem\\s+Governed By\\s+Notices",
"type": "regex"
}
],

View File

@ -8,5 +8,35 @@
}
],
"script": "lotj.mapper.checkAmenityLine(matches[2], matches[3])"
},
{
"name": "invalid-dir",
"patterns": [
{
"pattern": "^Alas, you cannot go that way.$",
"type": "regex"
},
{
"pattern": "^The .* is closed.$",
"type": "regex"
},
{
"pattern": "^You can't go that way,",
"type": "regex"
},
{
"pattern": "^You can't do that sitting down.$",
"type": "regex"
},
{
"pattern": "^Nah... You feel too relaxed...$",
"type": "regex"
},
{
"pattern": "^In your dreams, or what\\?$",
"type": "regex"
}
],
"script": "lotj.mapper.popMoveDir()"
}
]