shipvitalsbox.lua
ShipVitalsBox = {}
function ShipVitalsBox:new(_name, _elementX, _elementY)
local _adjustmentFactor = -33
cloudDir = cloudDir or [[D:\Achaea\]]
self.__index = ShipVitalsBox
local self = setmetatable({}, ShipVitalsBox)
self._instanceName = _name
if self._updateHandler then killAnonymousEventHandler(self._updateHandler) self._updateHandler = false end
self._updateHandler = self._updateHandler or registerAnonymousEventHandler("svo done with prompt", self._instanceName..":update")
self._container = Geyser.Label:new({ name = self._instanceName.."._container", x = _elementX, y = _elementY, width = 942, height = 32 })
self._labelBalance = Geyser.Label:new({ name = self._instanceName.."._balance", x = 445 + _adjustmentFactor, y = 0, width = 26, height = 32, color = "#007700" }, self._container )
self._labelCrewBalance = Geyser.Label:new({ name = self._instanceName.."._labelCrewBalance", x = 511 + _adjustmentFactor, y = 0, width = 52, height = 32, color = "#007700" }, self._container )
self._labelEquilibrium = Geyser.Label:new({ name = self._instanceName.."._equilibrium", x = 471 + _adjustmentFactor, y = 0, width = 26, height = 32, color = "#007700" }, self._container )
self._container:setStyleSheet( [[background-color: #00000000;]] )
self._labelBalance:setStyleSheet( gui.css.ship.balanceGreen )
self._labelCrewBalance:setStyleSheet( gui.css.ship.balanceBlue )
self._labelEquilibrium:setStyleSheet( gui.css.ship.balanceRed )
self._labelBalance:echo( "B", "white", "14" )
self._labelCrewBalance:echo( "C", "white", "14" )
self._labelEquilibrium:echo( "E", "white", "14" )
self._gaugeEndurance = Geyser.Gauge:new({ name = self._instanceName.."._gaugeEndurance", x = 239 + _adjustmentFactor, y = 0, height = 32, width = 89 }, self._container )
self._gaugeFigurehead = Geyser.Gauge:new({ name = self._instanceName.."._gaugeFigurehead", x = 577 + _adjustmentFactor, y = 0, height = 32, width = 192 }, self._container )
self._gaugeHealth = Geyser.Gauge:new({ name = self._instanceName.."._gaugeHealth", x = 33 + _adjustmentFactor, y = 0, height = 32, width = 89 }, self._container )
self._gaugeMana = Geyser.Gauge:new({ name = self._instanceName.."._gaugeMana", x = 136 + _adjustmentFactor, y = 0, height = 32, width = 89 }, self._container )
self._gaugeSeamonster = Geyser.Gauge:new({ name = self._instanceName.."._gaugeSeamonster", x = 783 + _adjustmentFactor, y = 0, height = 32, width = 192 }, self._container )
self._gaugeWillpower = Geyser.Gauge:new({ name = self._instanceName.."._gaugeWillpower", x = 342 + _adjustmentFactor, y = 0, height = 32, width = 89 }, self._container )
self._gaugeEndurance.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeEndurance.front:setStyleSheet( gui.css.ship.defaultGaugeYellow )
self._gaugeFigurehead.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeFigurehead.front:setStyleSheet( gui.css.ship.defaultGaugeSeafoam )
self._gaugeHealth.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeHealth.front:setStyleSheet( gui.css.ship.defaultGaugeYellow )
self._gaugeMana.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeMana.front:setStyleSheet( gui.css.ship.defaultGaugeYellow )
self._gaugeSeamonster.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeSeamonster.front:setStyleSheet( gui.css.ship.defaultGaugeOrange )
self._gaugeWillpower.back:setStyleSheet( gui.css.ship.defaultGaugeBack )
self._gaugeWillpower.front:setStyleSheet( gui.css.ship.defaultGaugeYellow )
self._gaugeEndurance:setValue( 50,100 )
self._gaugeFigurehead:setValue( 50,100 )
self._gaugeSeamonster:setValue( 50,100 )
self._gaugeHealth:setValue( 50,100 )
self._gaugeMana:setValue( 50,100 )
self._gaugeWillpower:setValue( 50,100 )
self._gaugeHealth.front:echo( " HP: ---%","grey","b10" )
self._gaugeMana.front:echo( " MP: ---%","grey","b10" )
self._gaugeEndurance.front:echo( " EN: ---%","grey","b10" )
self._gaugeWillpower.front:echo( " WP: ---%","grey","b10" )
self._gaugeHealth.back:echo( " HP: ---%","grey","b10" )
self._gaugeMana.back:echo( " MP: ---%","grey","b10" )
self._gaugeEndurance.back:echo( " EN: ---%","grey","b10" )
self._gaugeWillpower.back:echo( " WP: ---%","grey","b10" )
self._container:raiseAll()
return self
end
function ShipVitalsBox:setEndurance(_currentEnd, _maxEnd)
self._gaugeEndurance:setValue(_currentEnd, _maxEnd)
self._gaugeEndurance.front:echo(" EN: " .. round((_currentEnd/_maxEnd)*100).."%", "white", "b10" )
self._gaugeEndurance.back:echo(" EN: " .. round((_currentEnd/_maxEnd)*100).."%", "white", "b10" )
end
function ShipVitalsBox:setFigurehead(_currentCharge)
if not thisFigurehead then
self._gaugeFigurehead:setValue(0,10000)
self._gaugeFigurehead.front:echo("(no tracker)", "red", "cb14" )
self._gaugeFigurehead.back:echo("(no tracker)", "red", "cb14" )
return
end
if not thisShip then
self._gaugeFigurehead:setValue(_currentCharge,10000)
self._gaugeFigurehead.front:echo(" FH: " .. _currentCharge, "white", "b10" )
self._gaugeFigurehead.back:echo(" FH: " .. _currentCharge, "white", "b10" )
return
end
if not thisFigurehead:isMelded() and thisShip:isDocked() then
self._gaugeFigurehead:setValue(0,10000)
self._gaugeFigurehead.front:echo("DOCKED", "SeaGreen", "c14" )
self._gaugeFigurehead.back:echo("DOCKED", "SeaGreen", "c14" )
elseif not thisFigurehead:isMelded() then
self._gaugeFigurehead:setValue(0,10000)
self._gaugeFigurehead.front:echo("UNMELDED", "gold", "cb14" )
self._gaugeFigurehead.back:echo("UNMELDED", "gold", "cb14" )
else
_currentCharge = math.min( 10000, _currentCharge )
self._gaugeFigurehead:setValue(_currentCharge,10000)
self._gaugeFigurehead.front:echo(" FH: " .. _currentCharge, "white", "b10" )
self._gaugeFigurehead.back:echo(" FH: " .. _currentCharge, "white", "b10" )
end
end
function ShipVitalsBox:setHealth(_currentHP, _maxHP)
self._gaugeHealth:setValue(_currentHP, _maxHP)
self._gaugeHealth.front:echo(" HP: " .. _currentHP .. " / " .. _maxHP, "white", "b10" )
self._gaugeHealth.back:echo(" HP: " .. _currentHP .. " / " .. _maxHP, "white", "b10" )
end
function ShipVitalsBox:setMana(_currentMP, _maxMP)
self._gaugeMana:setValue(_currentMP, _maxMP)
self._gaugeMana.front:echo(" MP: " .. _currentMP .. " / " .. _maxMP, "white", "b10" )
self._gaugeMana.back:echo(" MP: " .. _currentMP .. " / " .. _maxMP, "white", "b10" )
end
function ShipVitalsBox:setSeamonsterGauge(currentHealth, maxHealth)
self._gaugeSeamonster:setValue(currentHealth,maxHealth)
self._gaugeSeamonster.front:echo(" Seamonster: " .. currentHealth .."/".. maxHealth, "white", "b10" )
self._gaugeSeamonster.back:echo(" Seamonster: " .. currentHealth .."/".. maxHealth, "white", "b10" )
end
function ShipVitalsBox:setTargetHealth(_value)
self._gaugeTargetHP:setValue(_value,100)
self._gaugeTargetHP.front:echo(" " .. _value .. "%","white","b12")
self._gaugeTargetHP.back:echo(" " .. _value .. "%","white","b12")
end
function ShipVitalsBox:setWillpower(_currentWP, _maxWP)
self._gaugeWillpower:setValue(_currentWP, _maxWP)
self._gaugeWillpower.front:echo(" WP: " .. round((_currentWP/_maxWP)*100).."%", "white", "b10" )
self._gaugeWillpower.back:echo(" WP: " .. round((_currentWP/_maxWP)*100).."%", "white", "b10" )
end
function ShipVitalsBox:setBalance(_haveBalance)
if _haveBalance then
self._labelBalance:setStyleSheet(gui.css.balanceGreen:getCSS())
else
self._labelBalance:setStyleSheet(gui.css.balanceRed:getCSS())
end
end
function ShipVitalsBox:setCrewBalanceLabel(_haveBalance)
if _haveBalance then
self._labelCrewBalance:setStyleSheet(gui.css.ship.balanceBlue)
else
self._labelCrewBalance:setStyleSheet(gui.css.ship.balanceRed)
end
end
function ShipVitalsBox:setEquilibrium(_haveEquilibrium)
if _haveEquilibrium then
self._labelEquilibrium:setStyleSheet(gui.css.ship.balanceGreen)
else
self._labelEquilibrium:setStyleSheet(gui.css.ship.balanceRed)
end
end
function ShipVitalsBox:setTargetName(_name)
self._labelTargetName:echo(" " .. _name)
end
function ShipVitalsBox:promptUpdate()
if not svo.stats then return end
if not loginComplete then return end
self:setHealth ( svo.stats.currenthealth, svo.stats.maxhealth )
self:setMana ( svo.stats.currentmana, svo.stats.maxmana )
self:setEndurance( svo.stats.currentendurance, svo.stats.maxendurance )
self:setWillpower( svo.stats.currentwillpower, svo.stats.maxwillpower )
self:setBalance ( svo.bals.balance )
self:setEquilibrium( svo.bals.equilibrium )
local _isLowHP = not (svo.stats.hp >= 40) or (svo.stats.hp == 0)
self:setLowHP(_isLowHP)
end
function ShipVitalsBox:setVisible(_visible)
if _visible then
self._container:show()
else
self._container:hide()
end
end
function ShipVitalsBox:setLowHP(_value)
if _value and svo.stats.hp >= 0 and not soundCooldown then
playSoundFile(cloudDir..[[Sounds\warning.wav]])
soundCooldown = true
tempTimer( 1.0, function() soundCooldown = false end )
end
end
function ShipVitalsBox:update(...)
if not svo.stats then return end
if not loginComplete then return end
if not jcs then return end
self:setHealth( svo.stats.currenthealth, svo.stats.maxhealth )
self:setMana( svo.stats.currentmana, svo.stats.maxmana )
self:setEndurance( svo.stats.currentendurance, svo.stats.maxendurance )
self:setWillpower( svo.stats.currentwillpower, svo.stats.maxwillpower )
self:setBalance( svo.bals.balance )
self:setEquilibrium( svo.bals.equilibrium )
self:setLowHP(not (svo.stats.hp >= 40) or (svo.stats.hp == 0))
self:setCrewBalanceLabel(self.crewBalance)
self:setFigurehead(self.figurehead)
end