Convert to GMCP

This commit is contained in:
Matt Wagner 2021-06-03 23:40:52 -07:00
parent 5bdd41586c
commit 874bdb0496
6 changed files with 69 additions and 120 deletions

View File

@ -41,7 +41,7 @@ registerAnonymousEventHandler("lotjUICreated", function()
lotj.galaxyMap.drawSystems() lotj.galaxyMap.drawSystems()
end end
registerAnonymousEventHandler("msdp.SHIPGALY", lotj.galaxyMap.setShipGalCoords) registerAnonymousEventHandler("gmcp.Ship.System.y", lotj.galaxyMap.setShipGalCoords)
end) end)
@ -50,11 +50,9 @@ function lotj.galaxyMap.log(text)
end end
function lotj.galaxyMap.setShipGalCoords() function lotj.galaxyMap.setShipGalCoords()
-- Assume "0" in both values means we don't have valid coordinates and leave them what they were. if gmcp.Ship.System.x ~= nil and gmcp.Ship.System.y ~= nil then
-- TODO: Find a way to support a system actually located at 0, 0 lotj.galaxyMap.currentX = gmcp.Ship.System.x
if msdp.SHIPGALX ~= "0" or msdp.SHIPGALY ~= "0" then lotj.galaxyMap.currentY = gmcp.Ship.System.y
lotj.galaxyMap.currentX = tonumber(msdp.SHIPGALX)
lotj.galaxyMap.currentY = tonumber(msdp.SHIPGALY)
lotj.galaxyMap.drawSystems() lotj.galaxyMap.drawSystems()
end end
end end

View File

@ -52,20 +52,32 @@ local function styleGaugeText(gauge, fontSize)
gauge:setFontSize(fontSize) gauge:setFontSize(fontSize)
end end
-- Wires up MSDP subscriptions for a gauge. local function gmcpVarByPath(varPath)
local temp = gmcp
for varStep in varPath:gmatch("([^\\.]+)") do
if temp and temp[varStep] then
temp = temp[varStep]
else
return nil
end
end
return temp
end
-- Wires up GMCP subscriptions for a gauge.
-- statName is the short version of the stat name to show after the value (mv, hp, etc) -- statName is the short version of the stat name to show after the value (mv, hp, etc)
local function wireGaugeUpdate(gauge, valueVarName, maxVarName, statName) local function wireGaugeUpdate(gauge, valueVarName, maxVarName, statName)
local function doUpdate() local function doUpdate()
local current = tonumber(msdp[valueVarName] or "0") local current = gmcpVarByPath(valueVarName) or 0
local max = tonumber(msdp[maxVarName] or "0") local max = gmcpVarByPath(maxVarName) or 0
if max > 0 then if max > 0 then
gauge:setValue(current, max, current.."/"..max.." "..statName) gauge:setValue(current, max, current.."/"..max.." "..statName)
else else
gauge:setValue(0, 1, "") gauge:setValue(0, 1, "")
end end
end end
registerAnonymousEventHandler("msdp."..valueVarName, doUpdate) registerAnonymousEventHandler("gmcp."..valueVarName, doUpdate)
registerAnonymousEventHandler("msdp."..maxVarName, doUpdate) registerAnonymousEventHandler("gmcp."..maxVarName, doUpdate)
end end
@ -78,7 +90,7 @@ function lotj.infoPanel.createBasicStats(container)
healthGauge.front:setStyleSheet(gaugeFrontStyle("#f04141", "#ef2929", "#cc0000", "#a40000", "#cc0000")) healthGauge.front:setStyleSheet(gaugeFrontStyle("#f04141", "#ef2929", "#cc0000", "#a40000", "#cc0000"))
healthGauge.back:setStyleSheet(gaugeBackStyle("#3f1111", "#3f0707", "#330000", "#220000", "#330000")) healthGauge.back:setStyleSheet(gaugeBackStyle("#3f1111", "#3f0707", "#330000", "#220000", "#330000"))
styleGaugeText(healthGauge, 12) styleGaugeText(healthGauge, 12)
wireGaugeUpdate(healthGauge, "HEALTH", "HEALTHMAX", "hp") wireGaugeUpdate(healthGauge, "Char.Stats.hp", "Char.Stats.maxHp", "hp")
local wimpyBar = Geyser.Label:new({ local wimpyBar = Geyser.Label:new({
x=0, y=0, x=0, y=0,
@ -88,10 +100,10 @@ function lotj.infoPanel.createBasicStats(container)
background-color: yellow; background-color: yellow;
]]) ]])
registerAnonymousEventHandler("msdp.WIMPY", function() registerAnonymousEventHandler("gmcp.Char.Stats.wimpy", function()
local health = tonumber(msdp.HEALTH or 0) local health = gmcp.Char.Stats.hp
local healthMax = tonumber(msdp.HEALTHMAX or 0) local healthMax = gmcp.Char.Stats.maxHp
local wimpy = tonumber(msdp.WIMPY or 0) local wimpy = gmcp.Char.Stats.wimpy
if healthMax > 0 then if healthMax > 0 then
if wimpy > 0 and health > 0 and wimpy < health then if wimpy > 0 and health > 0 and wimpy < health then
wimpyBar:show() wimpyBar:show()
@ -110,7 +122,7 @@ function lotj.infoPanel.createBasicStats(container)
movementGauge.front:setStyleSheet(gaugeFrontStyle("#41f041", "#29ef29", "#00cc00", "#00a400", "#00cc00")) movementGauge.front:setStyleSheet(gaugeFrontStyle("#41f041", "#29ef29", "#00cc00", "#00a400", "#00cc00"))
movementGauge.back:setStyleSheet(gaugeBackStyle("#113f11", "#073f07", "#003300", "#002200", "#003300")) movementGauge.back:setStyleSheet(gaugeBackStyle("#113f11", "#073f07", "#003300", "#002200", "#003300"))
styleGaugeText(movementGauge, 12) styleGaugeText(movementGauge, 12)
wireGaugeUpdate(movementGauge, "MOVEMENT", "MOVEMENTMAX", "mv") wireGaugeUpdate(movementGauge, "Char.Stats.move", "Char.Stats.maxMove", "mv")
-- Mana gauge (will be hidden later if we do not have mana) -- Mana gauge (will be hidden later if we do not have mana)
local manaGauge = Geyser.Gauge:new({ local manaGauge = Geyser.Gauge:new({
@ -120,10 +132,10 @@ function lotj.infoPanel.createBasicStats(container)
manaGauge.front:setStyleSheet(gaugeFrontStyle("#4141f0", "#2929ef", "#0000cc", "#0000a4", "#0000cc")) manaGauge.front:setStyleSheet(gaugeFrontStyle("#4141f0", "#2929ef", "#0000cc", "#0000a4", "#0000cc"))
manaGauge.back:setStyleSheet(gaugeBackStyle("#11113f", "#07073f", "#000033", "#000022", "#000011")) manaGauge.back:setStyleSheet(gaugeBackStyle("#11113f", "#07073f", "#000033", "#000022", "#000011"))
styleGaugeText(manaGauge, 12) styleGaugeText(manaGauge, 12)
wireGaugeUpdate(manaGauge, "MANA", "MANAMAX", "mn") wireGaugeUpdate(manaGauge, "Char.Stats.mana", "Char.stats.maxMana", "mn")
registerAnonymousEventHandler("msdp.MANAMAX", function() registerAnonymousEventHandler("gmcp.Char.Stats.maxMana", function()
local manaMax = tonumber(msdp.MANAMAX or 0) local manaMax = gmcp.Char.Stats.maxMana or 0
if manaMax > 0 then if manaMax > 0 then
healthGauge:move(nil, 4) healthGauge:move(nil, 4)
healthGauge:resize(nil, 16) healthGauge:resize(nil, 16)
@ -165,22 +177,20 @@ function lotj.infoPanel.createOpponentStats(container)
opponentGauge:setFontSize("12") opponentGauge:setFontSize("12")
local function update() local function update()
local opponentName = string.gsub(msdp.OPPONENTNAME or "", "&.", "") local opponentName = string.gsub(gmcp.Char.Enemy.name or "", "&.", "")
-- Opponent name seems to always be empty string even when fighting, so fall back to something reasonable -- Opponent name seems to always be empty string even when fighting, so fall back to something reasonable
if opponentName == "" then if opponentName == "" then
opponentName = "Current target" opponentName = "Current target"
end end
local opponentHealth = tonumber(msdp.OPPONENTHEALTH or "0") local opponentHealth = gmcp.Char.Enemy.Percent
local opponentHealthMax = tonumber(msdp.OPPONENTHEALTHMAX or "0") local opponentHealthMax = 100
if opponentHealth > 0 then if opponentHealth ~= nil then
opponentGauge:setValue(opponentHealth, opponentHealthMax, opponentName.."<br>"..opponentHealth.."%") opponentGauge:setValue(opponentHealth, opponentHealthMax, opponentName.."<br>"..opponentHealth.."%")
else else
opponentGauge:setValue(0, 1, "Not fighting") opponentGauge:setValue(0, 1, "Not fighting")
end end
end end
registerAnonymousEventHandler("msdp.OPPONENTNAME", update) registerAnonymousEventHandler("gmcp.Char.Enemy", update)
registerAnonymousEventHandler("msdp.OPPONENTHEALTH", update)
registerAnonymousEventHandler("msdp.OPPONENTHEALTHMAX", update)
end end
@ -197,16 +207,17 @@ function lotj.infoPanel.createChatInfo(container)
}, container) }, container)
local function updateCommnet() local function updateCommnet()
local commChannel = msdp.COMMCHANNEL or "0" local commChannel = gmcp.Char.Chat.commChannel
local commEncrypt = msdp.COMMENCRYPT or "0" local commEncrypt = gmcp.Char.Chat.commEncrypt
if commEncrypt == "0" then if not commChannel then
commnetInfo:echo(commChannel, nil, "l13") commnetInfo:echo("None", nil, "l13")
else elseif commEncrypt then
commnetInfo:echo(commChannel.." (E "..commEncrypt..")", nil, "l13") commnetInfo:echo(commChannel.." (E "..commEncrypt..")", nil, "l13")
else
commnetInfo:echo(commChannel, nil, "l13")
end end
end end
registerAnonymousEventHandler("msdp.COMMCHANNEL", updateCommnet) registerAnonymousEventHandler("gmcp.Char.Chat", updateCommnet)
registerAnonymousEventHandler("msdp.COMMENCRYPT", updateCommnet)
-- OOC meter -- OOC meter
local oocLabel = Geyser.Label:new({ local oocLabel = Geyser.Label:new({
@ -221,8 +232,8 @@ function lotj.infoPanel.createChatInfo(container)
oocGauge.front:setStyleSheet(gaugeFrontStyle("#31d0d0", "#22cfcf", "#00b2b2", "#009494", "#00b2b2")) oocGauge.front:setStyleSheet(gaugeFrontStyle("#31d0d0", "#22cfcf", "#00b2b2", "#009494", "#00b2b2"))
oocGauge.back:setStyleSheet(gaugeBackStyle("#113f3f", "#073f3f", "#003333", "#002222", "#001111")) oocGauge.back:setStyleSheet(gaugeBackStyle("#113f3f", "#073f3f", "#003333", "#002222", "#001111"))
registerAnonymousEventHandler("msdp.OOCLIMIT", function() registerAnonymousEventHandler("gmcp.Char.Chat.oocLimit", function()
local oocLeft = tonumber(msdp.OOCLIMIT or 0) local oocLeft = gmcp.Char.Chat.oocLimit or 0
local oocMax = 6 local oocMax = 6
oocGauge:setValue(oocLeft, oocMax) oocGauge:setValue(oocLeft, oocMax)
end) end)
@ -237,7 +248,7 @@ function lotj.infoPanel.createSpaceStats(container)
energyGauge.front:setStyleSheet(gaugeFrontStyle("#7a7a7a", "#777777", "#656565", "#505050", "#656565")) energyGauge.front:setStyleSheet(gaugeFrontStyle("#7a7a7a", "#777777", "#656565", "#505050", "#656565"))
energyGauge.back:setStyleSheet(gaugeBackStyle("#383838", "#303030", "#222222", "#151515", "#222222")) energyGauge.back:setStyleSheet(gaugeBackStyle("#383838", "#303030", "#222222", "#151515", "#222222"))
styleGaugeText(energyGauge, 12) styleGaugeText(energyGauge, 12)
wireGaugeUpdate(energyGauge, "SHIPENERGY", "SHIPMAXENERGY", "en") wireGaugeUpdate(energyGauge, "Ship.Info.energy", "Ship.Info.maxEnergy", "en")
local hullGauge = Geyser.Gauge:new({ local hullGauge = Geyser.Gauge:new({
x="3%", y=23, x="3%", y=23,
@ -246,7 +257,7 @@ function lotj.infoPanel.createSpaceStats(container)
hullGauge.front:setStyleSheet(gaugeFrontStyle("#bd7833", "#bd6e20", "#994c00", "#703800", "#994c00")) hullGauge.front:setStyleSheet(gaugeFrontStyle("#bd7833", "#bd6e20", "#994c00", "#703800", "#994c00"))
hullGauge.back:setStyleSheet(gaugeBackStyle("#442511", "#441d08", "#331100", "#200900", "#331100")) hullGauge.back:setStyleSheet(gaugeBackStyle("#442511", "#441d08", "#331100", "#200900", "#331100"))
styleGaugeText(hullGauge, 12) styleGaugeText(hullGauge, 12)
wireGaugeUpdate(hullGauge, "SHIPHULL", "SHIPMAXHULL", "hl") wireGaugeUpdate(hullGauge, "Ship.Info.hull", "Ship.Info.maxHull", "hl")
local shieldGauge = Geyser.Gauge:new({ local shieldGauge = Geyser.Gauge:new({
x="3%", y=42, x="3%", y=42,
@ -255,7 +266,7 @@ function lotj.infoPanel.createSpaceStats(container)
shieldGauge.front:setStyleSheet(gaugeFrontStyle("#31d0d0", "#22cfcf", "#00b2b2", "#009494", "#00b2b2")) shieldGauge.front:setStyleSheet(gaugeFrontStyle("#31d0d0", "#22cfcf", "#00b2b2", "#009494", "#00b2b2"))
shieldGauge.back:setStyleSheet(gaugeBackStyle("#113f3f", "#073f3f", "#003333", "#002222", "#001111")) shieldGauge.back:setStyleSheet(gaugeBackStyle("#113f3f", "#073f3f", "#003333", "#002222", "#001111"))
styleGaugeText(shieldGauge, 12) styleGaugeText(shieldGauge, 12)
wireGaugeUpdate(shieldGauge, "SHIPSHIELD", "SHIPMAXSHIELD", "sh") wireGaugeUpdate(shieldGauge, "Ship.Info.shield", "Ship.Info.maxShield", "sh")
-- Piloting indicator -- Piloting indicator
@ -274,9 +285,8 @@ function lotj.infoPanel.createSpaceStats(container)
width=16, height=16 width=16, height=16
}, pilotBoxCont) }, pilotBoxCont)
registerAnonymousEventHandler("msdp.PILOTING", function() registerAnonymousEventHandler("gmcp.Ship.Base.piloting", function()
local piloting = tonumber(msdp.PILOTING or "0") if gmcp.Ship.Base.piloting then
if piloting == 1 then
pilotBox:setStyleSheet("background-color: #29efef; border: 2px solid #eeeeee;") pilotBox:setStyleSheet("background-color: #29efef; border: 2px solid #eeeeee;")
else else
pilotBox:setStyleSheet("background-color: #073f3f; border: 2px solid #eeeeee;") pilotBox:setStyleSheet("background-color: #073f3f; border: 2px solid #eeeeee;")
@ -290,28 +300,25 @@ function lotj.infoPanel.createSpaceStats(container)
}, container) }, container)
local function updateSpeed() local function updateSpeed()
local speed = tonumber(msdp.SHIPSPEED or "0") local speed = gmcp.Ship.Base.speed or 0
local maxSpeed = tonumber(msdp.SHIPMAXSPEED or "0") local maxSpeed = gmcp.Ship.Base.maxSpeed or 0
speedGauge:echo("<b>Sp:</b> "..speed.."<b>/</b>"..maxSpeed, nil, "l12") speedGauge:echo("<b>Sp:</b> "..speed.."<b>/</b>"..maxSpeed, nil, "l12")
end end
registerAnonymousEventHandler("msdp.SHIPSPEED", updateSpeed) registerAnonymousEventHandler("gmcp.Ship.Base", updateSpeed)
registerAnonymousEventHandler("msdp.SHIPMAXSPEED", updateSpeed)
local coordsInfo = Geyser.Label:new({ local coordsInfo = Geyser.Label:new({
x="35%", y=32, x="35%", y=32,
width="40%", height=24, width="40%", height=24,
}, container) }, container)
local function updateCoords() local function updateCoords()
local shipX = tonumber(msdp.SHIPSYSX or "0") local shipX = gmcp.Ship.Base.posX or 0
local shipY = tonumber(msdp.SHIPSYSY or "0") local shipY = gmcp.Ship.Base.posY or 0
local shipZ = tonumber(msdp.SHIPSYSZ or "0") local shipZ = gmcp.Ship.Base.posZ or 0
coordsInfo:echo("<b>Coords:</b> "..shipX.." "..shipY.." "..shipZ, nil, "l12") coordsInfo:echo("<b>Coords:</b> "..shipX.." "..shipY.." "..shipZ, nil, "l12")
end end
registerAnonymousEventHandler("msdp.SHIPSYSX", updateCoords) registerAnonymousEventHandler("gmcp.Ship.Base", updateCoords)
registerAnonymousEventHandler("msdp.SHIPSYSY", updateCoords)
registerAnonymousEventHandler("msdp.SHIPSYSZ", updateCoords)
lotj.infoPanel.spaceTickCounter = Geyser.Label:new({ lotj.infoPanel.spaceTickCounter = Geyser.Label:new({
x="77%", y=6, x="77%", y=6,

View File

@ -94,7 +94,7 @@ function lotj.mapper.printMainMenu()
lotj.mapper.log("Mapper Introduction and Status") lotj.mapper.log("Mapper Introduction and Status")
cecho([[ cecho([[
The LOTJ Mapper plugin tracks movement using MSDP variables. To begin, try <yellow>map start <current area><reset>. The LOTJ Mapper plugin tracks movement using GMCP variables. To begin, try <yellow>map start <current area><reset>.
Once mapping is started, move <red>slowly<reset> between rooms to map them. Moving too quickly will cause the Once mapping is started, move <red>slowly<reset> between rooms to map them. Moving too quickly will cause the
mapper to skip rooms. You should wait for the map to reflect your movements before moving again mapper to skip rooms. You should wait for the map to reflect your movements before moving again
whenever you are in mapping mode. whenever you are in mapping mode.
@ -282,7 +282,7 @@ registerAnonymousEventHandler("lotjUICreated", function()
end end
registerAnonymousEventHandler("sysDataSendRequest", "lotj.mapper.handleSentCommand") registerAnonymousEventHandler("sysDataSendRequest", "lotj.mapper.handleSentCommand")
registerAnonymousEventHandler("msdp.ROOMVNUM", "lotj.mapper.onEnterRoom") registerAnonymousEventHandler("gmcp.Room.Info.vnum", "lotj.mapper.onEnterRoom")
end) end)
@ -444,7 +444,7 @@ function lotj.mapper.checkAmenityLine(roomName, amenityName, wasPending)
if addAmenityRoom == nil then if addAmenityRoom == nil then
-- The room name we're triggering on might be the room we just entered but we haven't -- The room name we're triggering on might be the room we just entered but we haven't
-- received the MSDP event yet, so we'll store this for the next time we do. -- received the GMCP event yet, so we'll store this for the next time we do.
lotj.mapper.pendingAmenity = { lotj.mapper.pendingAmenity = {
roomName = roomName, roomName = roomName,
amenityName = amenityName, amenityName = amenityName,
@ -463,14 +463,10 @@ function lotj.mapper.onEnterRoom()
if lotj.mapper.current ~= nil then if lotj.mapper.current ~= nil then
lotj.mapper.last = lotj.mapper.current lotj.mapper.last = lotj.mapper.current
end end
local exits = {}
if msdp.ROOMEXITS ~= "" then
exits = msdp.ROOMEXITS
end
lotj.mapper.current = { lotj.mapper.current = {
vnum = tonumber(msdp.ROOMVNUM), vnum = gmcp.Room.Info.vnum,
name = string.gsub(msdp.ROOMNAME, "&.", ""), name = gmcp.Room.Info.name:gsub("&.", ""),
exits = exits, exits = gmcp.Room.Info.exits or {},
} }
lotj.mapper.processCurrentRoom() lotj.mapper.processCurrentRoom()

View File

@ -1,45 +0,0 @@
registerAnonymousEventHandler("sysLoadEvent", function()
registerAnonymousEventHandler("msdp.COMMANDS", function()
local msdpVars = {}
table.insert(msdpVars, "HEALTH")
table.insert(msdpVars, "HEALTHMAX")
table.insert(msdpVars, "WIMPY")
table.insert(msdpVars, "MOVEMENT")
table.insert(msdpVars, "MOVEMENTMAX")
table.insert(msdpVars, "MANA")
table.insert(msdpVars, "MANAMAX")
table.insert(msdpVars, "OPPONENTNAME")
table.insert(msdpVars, "OPPONENTHEALTH")
table.insert(msdpVars, "OPPONENTHEALTHMAX")
table.insert(msdpVars, "COMMCHANNEL")
table.insert(msdpVars, "COMMENCRYPT")
table.insert(msdpVars, "OOCLIMIT")
table.insert(msdpVars, "ROOMNAME")
table.insert(msdpVars, "ROOMEXITS")
table.insert(msdpVars, "ROOMVNUM")
table.insert(msdpVars, "PILOTING")
table.insert(msdpVars, "SHIPSPEED")
table.insert(msdpVars, "SHIPMAXSPEED")
table.insert(msdpVars, "SHIPHULL")
table.insert(msdpVars, "SHIPMAXHULL")
table.insert(msdpVars, "SHIPSHIELD")
table.insert(msdpVars, "SHIPMAXSHIELD")
table.insert(msdpVars, "SHIPENERGY")
table.insert(msdpVars, "SHIPMAXENERGY")
table.insert(msdpVars, "SHIPSYSX")
table.insert(msdpVars, "SHIPSYSY")
table.insert(msdpVars, "SHIPSYSZ")
table.insert(msdpVars, "SHIPGALX")
table.insert(msdpVars, "SHIPGALY")
table.insert(msdpVars, "SHIPSYSNAME")
for _, varName in ipairs(msdpVars) do
sendMSDP("REPORT", varName)
end
end)
end)

View File

@ -1,5 +0,0 @@
[
{
"name": "msdp"
}
]

View File

@ -90,9 +90,7 @@ registerAnonymousEventHandler("lotjUICreated", function()
positionRangeCircle() positionRangeCircle()
registerAnonymousEventHandler("sysWindowResizeEvent", positionRangeCircle) registerAnonymousEventHandler("sysWindowResizeEvent", positionRangeCircle)
registerAnonymousEventHandler("msdp.SHIPSYSX", "lotj.systemMap.drawMap") registerAnonymousEventHandler("gmcp.Ship.Base", "lotj.systemMap.drawMap")
registerAnonymousEventHandler("msdp.SHIPSYSY", "lotj.systemMap.drawMap")
registerAnonymousEventHandler("msdp.SHIPSYSZ", "lotj.systemMap.drawMap")
end) end)
function lotj.systemMap.resetItems() function lotj.systemMap.resetItems()
@ -115,13 +113,13 @@ function lotj.systemMap.drawMap()
end end
-- We use ship max speed as a proxy for "do we have ship data at all" -- We use ship max speed as a proxy for "do we have ship data at all"
if tonumber(msdp.SHIPMAXSPEED or "0") == 0 then if gmcp.Ship.Base.maxSpeed == nil then
return return
end end
local shipX = tonumber(msdp.SHIPSYSX or "0") local shipX = gmcp.Ship.Base.posX
local shipY = tonumber(msdp.SHIPSYSY or "0") local shipY = gmcp.Ship.Base.posY
local shipZ = tonumber(msdp.SHIPSYSZ or "0") local shipZ = gmcp.Ship.Base.posZ
local selfData = {name="You", x=shipX, y=shipY, z=shipZ} local selfData = {name="You", x=shipX, y=shipY, z=shipZ}
local itemsToDraw = {} local itemsToDraw = {}