No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

playerdeath.lua 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. deathWindow = nil
  2. local deathTexts = {
  3. regular = {text = 'Alas! Brave adventurer, you have met a sad fate.\nBut do not despair, for the gods will bring you back\ninto this world in exchange for a small sacrifice\n\nSimply click on Ok to resume your journeys!', height = 140, width = 0},
  4. unfair = {text = 'Alas! Brave adventurer, you have met a sad fate.\nBut do not despair, for the gods will bring you back\ninto this world in exchange for a small sacrifice\n\nThis death penalty has been reduced by %i%%\nbecause it was an unfair fight.\n\nSimply click on Ok to resume your journeys!', height = 185, width = 0},
  5. blessed = {text = 'Alas! Brave adventurer, you have met a sad fate.\nBut do not despair, for the gods will bring you back into this world\n\nThis death penalty has been reduced by 100%\nbecause you are blessed with the Adventurer\'s Blessing\n\nSimply click on Ok to resume your journeys!', height = 170, width = 90}
  6. }
  7. function init()
  8. g_ui.importStyle('deathwindow')
  9. connect(g_game, { onDeath = display,
  10. onGameEnd = reset })
  11. end
  12. function terminate()
  13. disconnect(g_game, { onDeath = display,
  14. onGameEnd = reset })
  15. reset()
  16. end
  17. function reset()
  18. if deathWindow then
  19. deathWindow:destroy()
  20. deathWindow = nil
  21. end
  22. end
  23. function display(deathType, penalty)
  24. displayDeadMessage()
  25. openWindow(deathType, penalty)
  26. end
  27. function displayDeadMessage()
  28. local advanceLabel = modules.game_interface.getRootPanel():recursiveGetChildById('middleCenterLabel')
  29. if advanceLabel:isVisible() then return end
  30. modules.game_textmessage.displayGameMessage(tr('You are dead.'))
  31. end
  32. function openWindow(deathType, penalty)
  33. if deathWindow then
  34. deathWindow:destroy()
  35. return
  36. end
  37. deathWindow = g_ui.createWidget('DeathWindow', rootWidget)
  38. local textLabel = deathWindow:getChildById('labelText')
  39. if deathType == DeathType.Regular then
  40. if penalty == 100 then
  41. textLabel:setText(deathTexts.regular.text)
  42. deathWindow:setHeight(deathWindow.baseHeight + deathTexts.regular.height)
  43. deathWindow:setWidth(deathWindow.baseWidth + deathTexts.regular.width)
  44. else
  45. textLabel:setText(string.format(deathTexts.unfair.text, 100 - penalty))
  46. deathWindow:setHeight(deathWindow.baseHeight + deathTexts.unfair.height)
  47. deathWindow:setWidth(deathWindow.baseWidth + deathTexts.unfair.width)
  48. end
  49. elseif deathType == DeathType.Blessed then
  50. textLabel:setText(deathTexts.blessed.text)
  51. deathWindow:setHeight(deathWindow.baseHeight + deathTexts.blessed.height)
  52. deathWindow:setWidth(deathWindow.baseWidth + deathTexts.blessed.width)
  53. end
  54. local okButton = deathWindow:getChildById('buttonOk')
  55. local cancelButton = deathWindow:getChildById('buttonCancel')
  56. local okFunc = function()
  57. CharacterList.doLogin()
  58. okButton:getParent():destroy()
  59. deathWindow = nil
  60. end
  61. local cancelFunc = function()
  62. g_game.safeLogout()
  63. cancelButton:getParent():destroy()
  64. deathWindow = nil
  65. end
  66. deathWindow.onEnter = okFunc
  67. deathWindow.onEscape = cancelFunc
  68. okButton.onClick = okFunc
  69. cancelButton.onClick = cancelFunc
  70. end