From 5a418e2c949f223a308c92b8d973e0fa722fe727 Mon Sep 17 00:00:00 2001 From: Matt Wagner Date: Tue, 24 Aug 2021 19:10:16 -0700 Subject: [PATCH] Add support for preset map coordinates --- src/scripts/info-panel/info-panel.lua | 2 + src/scripts/mapper/mapper.lua | 81 +++++++++++++++++++++--- src/triggers/galaxy-map/planets-line.lua | 8 +-- src/triggers/galaxy-map/triggers.json | 2 +- src/triggers/mapper/triggers.json | 30 +++++++++ 5 files changed, 110 insertions(+), 13 deletions(-) diff --git a/src/scripts/info-panel/info-panel.lua b/src/scripts/info-panel/info-panel.lua index 4d54955..e22e95a 100644 --- a/src/scripts/info-panel/info-panel.lua +++ b/src/scripts/info-panel/info-panel.lua @@ -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 diff --git a/src/scripts/mapper/mapper.lua b/src/scripts/mapper/mapper.lua index d8894ef..b4f5eb0 100644 --- a/src/scripts/mapper/mapper.lua +++ b/src/scripts/mapper/mapper.lua @@ -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 map help.") 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([[ + +map setroomcoords + +(Staff Command) 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 @@ -371,14 +417,30 @@ function lotj.mapper.processCurrentRoom() end 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 diff --git a/src/triggers/galaxy-map/planets-line.lua b/src/triggers/galaxy-map/planets-line.lua index 5817378..f4fb644 100644 --- a/src/triggers/galaxy-map/planets-line.lua +++ b/src/triggers/galaxy-map/planets-line.lua @@ -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") diff --git a/src/triggers/galaxy-map/triggers.json b/src/triggers/galaxy-map/triggers.json index 815d112..8d803b9 100644 --- a/src/triggers/galaxy-map/triggers.json +++ b/src/triggers/galaxy-map/triggers.json @@ -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" } ], diff --git a/src/triggers/mapper/triggers.json b/src/triggers/mapper/triggers.json index ce867d0..bf0b111 100644 --- a/src/triggers/mapper/triggers.json +++ b/src/triggers/mapper/triggers.json @@ -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()" } ]