From 83dc129f036b72973e489cfc0743444b0e4eec29 Mon Sep 17 00:00:00 2001 From: TheSumm Date: Sat, 7 Mar 2015 06:09:00 +0100 Subject: [PATCH] Protocol 10.76, fixed death window & death packet --- modules/game_playerdeath/deathwindow.otui | 5 ++-- modules/game_playerdeath/playerdeath.lua | 31 ++++++++++++++++++++--- modules/gamelib/const.lua | 6 +++++ modules/gamelib/game.lua | 2 +- src/client/const.h | 6 +++++ src/client/game.cpp | 12 ++++++--- src/client/game.h | 2 +- src/client/protocolgameparse.cpp | 10 ++++++-- 8 files changed, 61 insertions(+), 13 deletions(-) diff --git a/modules/game_playerdeath/deathwindow.otui b/modules/game_playerdeath/deathwindow.otui index 4e395bc0..4f185bf1 100644 --- a/modules/game_playerdeath/deathwindow.otui +++ b/modules/game_playerdeath/deathwindow.otui @@ -1,10 +1,11 @@ DeathWindow < MainWindow id: deathWindow !text: tr('You are dead') - size: 350 155 + &baseWidth: 350 + &baseHeight: 15 Label - !text: tr('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!') + id: labelText width: 550 height: 140 anchors.left: parent.left diff --git a/modules/game_playerdeath/playerdeath.lua b/modules/game_playerdeath/playerdeath.lua index 5592797b..736f86e6 100644 --- a/modules/game_playerdeath/playerdeath.lua +++ b/modules/game_playerdeath/playerdeath.lua @@ -1,5 +1,11 @@ deathWindow = nil +local deathTexts = { + 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}, + 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}, + 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} +} + function init() g_ui.importStyle('deathwindow') @@ -21,9 +27,9 @@ function reset() end end -function display() +function display(deathType, penalty) displayDeadMessage() - openWindow() + openWindow(deathType, penalty) end function displayDeadMessage() @@ -33,12 +39,31 @@ function displayDeadMessage() modules.game_textmessage.displayGameMessage(tr('You are dead.')) end -function openWindow() +function openWindow(deathType, penalty) if deathWindow then deathWindow:destroy() return end + deathWindow = g_ui.createWidget('DeathWindow', rootWidget) + + local textLabel = deathWindow:getChildById('labelText') + if deathType == DeathType.Regular then + if penalty == 100 then + textLabel:setText(deathTexts.regular.text) + deathWindow:setHeight(deathWindow.baseHeight + deathTexts.regular.height) + deathWindow:setWidth(deathWindow.baseWidth + deathTexts.regular.width) + else + textLabel:setText(string.format(deathTexts.unfair.text, 100 - penalty)) + deathWindow:setHeight(deathWindow.baseHeight + deathTexts.unfair.height) + deathWindow:setWidth(deathWindow.baseWidth + deathTexts.unfair.width) + end + elseif deathType == DeathType.Blessed then + textLabel:setText(deathTexts.blessed.text) + deathWindow:setHeight(deathWindow.baseHeight + deathTexts.blessed.height) + deathWindow:setWidth(deathWindow.baseWidth + deathTexts.blessed.width) + end + local okButton = deathWindow:getChildById('buttonOk') local cancelButton = deathWindow:getChildById('buttonCancel') diff --git a/modules/gamelib/const.lua b/modules/gamelib/const.lua index 4d64f686..71594a6c 100644 --- a/modules/gamelib/const.lua +++ b/modules/gamelib/const.lua @@ -130,6 +130,7 @@ GameExperienceBonus = 66 GameAuthenticator = 67 GameUnjustifiedPoints = 68 GameSessionKey = 69 +GameDeathType = 70 TextColors = { red = '#f55e5e', --'#c83200' @@ -270,4 +271,9 @@ Blessings = { SparkOfPhoenix = 32 } +DeathType = { + Regular = 0, + Blessed = 1 +} + -- @} diff --git a/modules/gamelib/game.lua b/modules/gamelib/game.lua index 3189538c..aff644c7 100644 --- a/modules/gamelib/game.lua +++ b/modules/gamelib/game.lua @@ -73,7 +73,7 @@ function g_game.getSupportedClients() 1053, 1054, 1055, 1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1070, 1071, 1072, - 1073, 1074, 1075 + 1073, 1074, 1075, 1076 } end diff --git a/src/client/const.h b/src/client/const.h index 3e2db411..54bd164f 100644 --- a/src/client/const.h +++ b/src/client/const.h @@ -402,6 +402,7 @@ namespace Otc GameAuthenticator = 67, GameUnjustifiedPoints = 68, GameSessionKey = 69, + GameDeathType = 70, LastGameFeature = 101 }; @@ -466,6 +467,11 @@ namespace Otc BlessingWisdomOfSolitude = 1 << 4, BlessingSparkOfPhoenix = 1 << 5 }; + + enum DeathType { + DeathRegular = 0, + DeathBlessed = 1 + }; } #endif diff --git a/src/client/game.cpp b/src/client/game.cpp index 448e0544..106742c6 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -228,12 +228,12 @@ void Game::processGameEnd() g_map.cleanDynamicThings(); } -void Game::processDeath(int penality) +void Game::processDeath(int deathType, int penality) { m_dead = true; m_localPlayer->stopWalk(); - g_lua.callGlobalField("g_game", "onDeath", penality); + g_lua.callGlobalField("g_game", "onDeath", deathType, penality); } void Game::processGMActions(const std::vector& actions) @@ -1450,7 +1450,7 @@ void Game::setProtocolVersion(int version) if(isOnline()) stdext::throw_exception("Unable to change protocol version while online"); - if(version != 0 && (version < 740 || version > 1075)) + if(version != 0 && (version < 740 || version > 1076)) stdext::throw_exception(stdext::format("Protocol version %d not supported", version)); m_protocolVersion = version; @@ -1468,7 +1468,7 @@ void Game::setClientVersion(int version) if(isOnline()) stdext::throw_exception("Unable to change client version while online"); - if(version != 0 && (version < 740 || version > 1075)) + if(version != 0 && (version < 740 || version > 1076)) stdext::throw_exception(stdext::format("Client version %d not supported", version)); m_features.reset(); @@ -1596,6 +1596,10 @@ void Game::setClientVersion(int version) enableFeature(Otc::GameExperienceBonus); } + if(version >= 1055) { + enableFeature(Otc::GameDeathType); + } + if(version >= 1061) { enableFeature(Otc::GameOGLInformation); } diff --git a/src/client/game.h b/src/client/game.h index afe80b42..cf51fe6c 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -86,7 +86,7 @@ protected: void processGameStart(); void processGameEnd(); - void processDeath(int penality); + void processDeath(int deathType, int penality); void processGMActions(const std::vector& actions); void processInventoryChange(int slot, const ItemPtr& item); diff --git a/src/client/protocolgameparse.cpp b/src/client/protocolgameparse.cpp index a687a03a..d155b8d1 100644 --- a/src/client/protocolgameparse.cpp +++ b/src/client/protocolgameparse.cpp @@ -537,9 +537,15 @@ void ProtocolGame::parseChallenge(const InputMessagePtr& msg) void ProtocolGame::parseDeath(const InputMessagePtr& msg) { int penality = 100; - if(g_game.getFeature(Otc::GamePenalityOnDeath)) + int deathType = Otc::DeathRegular; + + if(g_game.getFeature(Otc::GameDeathType)) + deathType = msg->getU8(); + + if(g_game.getFeature(Otc::GamePenalityOnDeath) && deathType == Otc::DeathRegular) penality = msg->getU8(); - g_game.processDeath(penality); + + g_game.processDeath(deathType, penality); } void ProtocolGame::parseMapDescription(const InputMessagePtr& msg)