-- OT-MMO: aviso de ABATIDO (vault OT-MMO/raids/plan-raids.md 13.10). A 0 de vida el servidor (server/scripts/abatido.lua) -- te deja en el suelo en vez de matarte; aqui solo se dibuja un aviso pequeno, sin ventana modal. -- Opcode 131: servidor -> cliente "A|restanteMs|botonMs|res|ayudante" (res = -1 si no hay combate de jefe) -- "F" fin (levantado o muerto) -- cliente -> servidor "T" ir al templo, "P" pedir estado (al cargar el modulo a mitad de partida) -- Archivo en ASCII: los acentos van como escapes de Lua (cp1252), como en game_objetivo. local OPCODE = 131 local C = OtmmoTheme.color local TEXTO = 'Abatido: un compa\241ero puede levantarte' local TEXTO_SIN_RES = 'Abatido: ya no pueden levantarte' abatidoController = Controller:new() local panel = nil local estado = nil -- { fin, boton, total, res, ayudante } (fin y boton en g_clock.millis()) local reloj = nil local function enviar(texto) local protocol = g_game.getProtocolGame() if protocol then protocol:sendExtendedOpcode(OPCODE, texto) end end local function campos(t, sep) local r = {} for x in (t .. sep):gmatch('(.-)%' .. sep) do table.insert(r, x) end return r end local function pintar() if not panel or not estado then return end local ahora = g_clock.millis() local resta = math.max(0, estado.fin - ahora) local s = math.ceil(resta / 1000) panel.tiempo:setText(s .. 's') panel.tiempo:setColor(s <= 10 and C.hp or C.text) local ancho = panel.barra:getWidth() panel.barra.fill:setWidth(math.max(0, math.floor(ancho * resta / math.max(1, estado.total)))) local sinRes = estado.res == 0 panel.texto:setText(sinRes and TEXTO_SIN_RES or TEXTO) panel.texto:setColor(sinRes and C.errorText or C.accent) panel:setBorderColor(sinRes and C.hp or C.accent) panel.barra.fill:setBackgroundColor(sinRes and C.hp or C.accent) if estado.ayudante ~= '' then panel.estado:setText(estado.ayudante .. ' te est\225 levantando...') panel.estado:setColor(C.ok) elseif sinRes then panel.estado:setText('No quedan resurrecciones en este combate.') panel.estado:setColor(C.errorText) elseif estado.res > 0 then panel.estado:setText('Resurrecciones en este combate: ' .. estado.res .. ' de 3') panel.estado:setColor(C.text2) else panel.estado:setText('Si nadie te levanta, vuelves al templo.') panel.estado:setColor(C.text2) end local espera = math.max(0, estado.boton - ahora) if espera > 0 then panel.templo:setEnabled(false) panel.templo:setText('Ir al templo (' .. math.ceil(espera / 1000) .. ')') else panel.templo:setEnabled(true) panel.templo:setText('Ir al templo') end end local function ocultar() estado = nil if reloj then removeEvent(reloj) reloj = nil end if panel then panel:hide() end end local function mostrar(resta, boton, res, ayudante) if not panel then return end local ahora = g_clock.millis() local total = estado and estado.total or math.max(resta, 1) estado = { fin = ahora + resta, boton = ahora + boton, total = math.max(total, resta), res = res, ayudante = ayudante or '' } panel:show() panel:raise() if not reloj then reloj = cycleEvent(pintar, 200) end pintar() end local function onOpcode(protocol, opcode, buffer) if buffer == 'F' then return ocultar() end if buffer:sub(1, 2) ~= 'A|' then return end local f = campos(buffer:sub(3), '|') mostrar(tonumber(f[1]) or 0, tonumber(f[2]) or 0, tonumber(f[3]) or -1, f[4]) end function irAlTemplo() if estado and g_clock.millis() >= estado.boton then enviar('T') end end function abatido() return estado ~= nil end function abatidoController:onInit() ProtocolGame.registerExtendedOpcode(OPCODE, onOpcode) if g_game.isOnline() then -- recargado a mitad de partida: Controller:init llama a onGameStart; luego se pide el estado scheduleEvent(function() enviar('P') end, 500) end end function abatidoController:onGameStart() if panel then panel:destroy() end panel = g_ui.loadUI('abatido', modules.game_interface.getRootPanel()) -- abajo y al centro del mapa, por encima del borde: no tapa al personaje ni la barra de habilidades panel:addAnchor(AnchorHorizontalCenter, 'gameMapPanel', AnchorHorizontalCenter) panel:addAnchor(AnchorBottom, 'gameMapPanel', AnchorBottom) panel:setMarginBottom(24) ocultar() end function abatidoController:onGameEnd() ocultar() if panel then panel:destroy() panel = nil end end function abatidoController:onTerminate() ProtocolGame.unregisterExtendedOpcode(OPCODE) self:onGameEnd() end