From ad0ed2b1a9b8f2d5859305ff8374e02d51a322f0 Mon Sep 17 00:00:00 2001 From: Eduardo Bart Date: Sun, 19 Aug 2012 06:46:24 -0300 Subject: [PATCH] Bind spell functions --- modules/gamelib/const.lua | 1 + src/otclient/const.h | 1 + src/otclient/game.cpp | 1 + src/otclient/localplayer.cpp | 10 ++++++++++ src/otclient/localplayer.h | 3 +++ src/otclient/protocolgameparse.cpp | 24 ++++++++++++++++-------- 6 files changed, 32 insertions(+), 8 deletions(-) diff --git a/modules/gamelib/const.lua b/modules/gamelib/const.lua index 9ccedead..ee1ead0a 100644 --- a/modules/gamelib/const.lua +++ b/modules/gamelib/const.lua @@ -63,6 +63,7 @@ GameChargeableItems = 19 GameOfflineTrainingTime = 20 GamePurseSlot = 21 GameFormatCreatureName = 22 +GameSpellList = 23 TextColors = { red = '#f55e5e', --'#c83200' diff --git a/src/otclient/const.h b/src/otclient/const.h index a2e4bc7f..2e89e7a8 100644 --- a/src/otclient/const.h +++ b/src/otclient/const.h @@ -334,6 +334,7 @@ namespace Otc GameOfflineTrainingTime = 20, GamePurseSlot = 21, GameFormatCreatureName = 22, + GameSpellList = 23, // 23-50 unused yet // 51-100 reserved to be defined in lua LastGameFeature = 101 diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index b1a22465..fdf6da20 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -1157,6 +1157,7 @@ void Game::setClientVersion(int version) if(version >= 870) { enableFeature(Otc::GameDoubleExperience); enableFeature(Otc::GamePlayerMounts); + enableFeature(Otc::GameSpellList); } if(version >= 910) { diff --git a/src/otclient/localplayer.cpp b/src/otclient/localplayer.cpp index 51bd6bed..c7bbbc36 100644 --- a/src/otclient/localplayer.cpp +++ b/src/otclient/localplayer.cpp @@ -448,6 +448,16 @@ void LocalPlayer::setOfflineTrainingTime(double offlineTrainingTime) } } +void LocalPlayer::setSpells(const std::vector& spells) +{ + if(m_spells != spells) { + std::vector oldSpells = m_spells; + m_spells = spells; + + callLuaField("onSpellsChange", spells, oldSpells); + } +} + double LocalPlayer::getWalkPing() { if(m_lastWalkPings.empty()) diff --git a/src/otclient/localplayer.h b/src/otclient/localplayer.h index d1face12..b7d6e5c4 100644 --- a/src/otclient/localplayer.h +++ b/src/otclient/localplayer.h @@ -59,6 +59,7 @@ public: void setBaseSpeed(double baseSpeed); void setRegenerationTime(double regenerationTime); void setOfflineTrainingTime(double offlineTrainingTime); + void setSpells(const std::vector& spells); int getStates() { return m_states; } int getSkillLevel(Otc::Skill skill) { return m_skillsLevel[skill]; } @@ -83,6 +84,7 @@ public: double getBaseSpeed() { return m_baseSpeed; } double getRegenerationTime() { return m_regenerationTime; } double getOfflineTrainingTime() { return m_offlineTrainingTime; } + std::vector getSpells() { return m_spells; } ItemPtr getInventoryItem(Otc::InventorySlot inventory) { return m_inventoryItems[inventory]; } bool hasSight(const Position& pos); @@ -125,6 +127,7 @@ private: std::array m_skillsLevel; std::array m_skillsBaseLevel; std::array m_skillsLevelPercent; + std::vector m_spells; bool m_known; int m_states; diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index 8b1ca1b4..090acb54 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -856,13 +856,15 @@ void ProtocolGame::parsePlayerInfo(const InputMessagePtr& msg) { bool premium = msg->getU8(); // premium int vocation = msg->getU8(); // vocation + int spellCount = msg->getU16(); - for(int i=0;igetU8(); // spell id - TODO: add to local player - } + std::vector spells; + for(int i=0;igetU8()); // spell id m_localPlayer->setPremium(premium); m_localPlayer->setVocation(vocation); + m_localPlayer->setSpells(spells); } void ProtocolGame::parsePlayerStats(const InputMessagePtr& msg) @@ -963,19 +965,25 @@ void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg) void ProtocolGame::parseSpellCooldown(const InputMessagePtr& msg) { - msg->getU8(); // spell id - msg->getU32(); // cooldown + int spellId = msg->getU8(); + int delay = msg->getU32(); + + g_lua.callGlobalField("g_game", "onSpellCooldown", delay); } void ProtocolGame::parseSpellGroupCooldown(const InputMessagePtr& msg) { - msg->getU8(); // group id - msg->getU32(); // cooldown + int groupId = msg->getU8(); + int delay = msg->getU32(); + + g_lua.callGlobalField("g_game", "onSpellGroupCooldown", groupId, delay); } void ProtocolGame::parseMultiUseCooldown(const InputMessagePtr& msg) { - msg->getU32(); // cooldown + int delay = msg->getU32(); + + g_lua.callGlobalField("g_game", "onMultiUseCooldown", delay); } void ProtocolGame::parseTalk(const InputMessagePtr& msg)