diff --git a/modules/corelib/ui/uiminiwindowcontainer.lua b/modules/corelib/ui/uiminiwindowcontainer.lua index 959ef5be..30b1a005 100644 --- a/modules/corelib/ui/uiminiwindowcontainer.lua +++ b/modules/corelib/ui/uiminiwindowcontainer.lua @@ -11,21 +11,21 @@ end function UIMiniWindowContainer:onDrop(widget, mousePos) if widget:getClassName() == 'UIMiniWindow' then - local oldParent = widget:getParent() - if oldParent == self then - return true - end + local oldParent = widget:getParent() + if oldParent == self then + return true + end if oldParent then - oldParent:removeChild(widget) + oldParent:removeChild(widget) end - if widget.movedWidget then - local index = self:getChildIndex(widget.movedWidget) - self:insertChild(index + widget.movedIndex, widget) - else - self:addChild(widget) - end + if widget.movedWidget then + local index = self:getChildIndex(widget.movedWidget) + self:insertChild(index + widget.movedIndex, widget) + else + self:addChild(widget) + end return true end @@ -47,7 +47,7 @@ end function UIMiniWindowContainer:scheduleInsert(widget, index) if index - 1 > self:getChildCount() then if self.scheduledWidgets[index] then - warning('replacing scheduled widget id ' .. widget:getId()) + pwarning('replacing scheduled widget id ' .. widget:getId()) end self.scheduledWidgets[index] = widget else diff --git a/modules/game_interface/widgets/uiitem.lua b/modules/game_interface/widgets/uiitem.lua index 410ad832..2db36691 100644 --- a/modules/game_interface/widgets/uiitem.lua +++ b/modules/game_interface/widgets/uiitem.lua @@ -32,7 +32,6 @@ function UIItem:onDrop(widget, mousePos) if itemPos.x == toPos.x and itemPos.y == toPos.y and itemPos.z == toPos.z then return false end if item:getCount() > 1 then - g_game.look(item) modules.game_interface.moveStackableItem(item, toPos) else g_game.move(item, toPos, 1) diff --git a/modules/game_npctrade/npctrade.lua b/modules/game_npctrade/npctrade.lua index 69e3e6b3..5435cc55 100644 --- a/modules/game_npctrade/npctrade.lua +++ b/modules/game_npctrade/npctrade.lua @@ -380,6 +380,11 @@ function onOpenNpcTrade(items) addEvent(show) -- player goods has not been parsed yet end +function closeNpcTrade() + g_game.closeNpcTrade() + hide() +end + function onCloseNpcTrade() hide() end diff --git a/modules/game_npctrade/npctrade.otui b/modules/game_npctrade/npctrade.otui index d7e1f5c0..1286cfcd 100644 --- a/modules/game_npctrade/npctrade.otui +++ b/modules/game_npctrade/npctrade.otui @@ -33,7 +33,7 @@ MainWindow id: npcWindow !text: tr('NPC Trade') size: 550 515 - @onEscape: g_game.closeNpcTrade() + @onEscape: modules.game_npctrade.closeNpcTrade() TabButton id: buyTab @@ -264,4 +264,4 @@ MainWindow width: 64 anchors.right: parent.right anchors.bottom: parent.bottom - @onClick: g_game.closeNpcTrade() + @onClick: modules.game_npctrade.closeNpcTrade() diff --git a/modules/game_outfit/outfit.lua b/modules/game_outfit/outfit.lua index 463d0a2d..a17848c2 100644 --- a/modules/game_outfit/outfit.lua +++ b/modules/game_outfit/outfit.lua @@ -150,6 +150,7 @@ function destroy() currentColorBox = nil currentClotheButtonBox = nil colorBoxes = {} + addons = nil end end diff --git a/modules/game_viplist/viplist.otui b/modules/game_viplist/viplist.otui index 22ef225c..69443470 100644 --- a/modules/game_viplist/viplist.otui +++ b/modules/game_viplist/viplist.otui @@ -12,4 +12,4 @@ MiniWindow MiniWindowContents layout: verticalBox anchors.fill: parent - @onMousePress: onVipListMousePress() + &onMousePress: modules.game_viplist.onVipListMousePress diff --git a/src/otclient/game.cpp b/src/otclient/game.cpp index bc9123d3..ad5068eb 100644 --- a/src/otclient/game.cpp +++ b/src/otclient/game.cpp @@ -158,6 +158,11 @@ void Game::processPing() g_lua.callGlobalField("g_game", "onPing"); } +void Game::processPingBack(int elapsed) +{ + g_lua.callGlobalField("g_game", "onPingBack", elapsed); +} + void Game::processTextMessage(Otc::MessageMode mode, const std::string& text) { g_lua.callGlobalField("g_game", "onTextMessage", mode, text); @@ -1073,6 +1078,16 @@ void Game::mount(bool mount) m_mounted = mount; } +void Game::ping() +{ + if(!m_protocolGame || !m_protocolGame->isConnected()) + return; + + m_denyBotCall = false; + m_protocolGame->sendPing(); + m_denyBotCall = true; +} + bool Game::checkBotProtection() { #ifdef BOT_PROTECTION diff --git a/src/otclient/game.h b/src/otclient/game.h index 71490093..1ab75fa6 100644 --- a/src/otclient/game.h +++ b/src/otclient/game.h @@ -51,6 +51,7 @@ protected: void processConnectionError(const boost::system::error_code& error); void processDisconnect(); void processPing(); + void processPingBack(int elapsed); void processLoginError(const std::string& error); void processLoginAdvice(const std::string& message); @@ -232,7 +233,7 @@ public: // 910 only //void requestItemInfo(); //void reportRuleViolation2(); - // TODO: market related + void ping(); // dynamic support for game features void enableFeature(Otc::GameFeature feature) { m_features.set(feature, true); } diff --git a/src/otclient/localplayer.cpp b/src/otclient/localplayer.cpp index 755d24e4..d70ac00c 100644 --- a/src/otclient/localplayer.cpp +++ b/src/otclient/localplayer.cpp @@ -37,6 +37,7 @@ LocalPlayer::LocalPlayer() m_states = 0; m_vocation = 0; + m_walkLockInterval = 0; m_skillsLevel.fill(-1); m_skillsLevelPercent.fill(-1); @@ -55,7 +56,7 @@ LocalPlayer::LocalPlayer() m_stamina = -1; } -void LocalPlayer::lockWalk() +void LocalPlayer::lockWalk(int millis) { // prevents double locks if(m_walkLocked) @@ -63,6 +64,7 @@ void LocalPlayer::lockWalk() m_walkLocked = true; m_walkLockTimer.restart(); + m_walkLockInterval = millis; } bool LocalPlayer::canWalk(Otc::Direction direction) @@ -79,7 +81,7 @@ bool LocalPlayer::canWalk(Otc::Direction direction) return false; // cannot walk while locked - if(m_walkLocked && m_walkLockTimer.ticksElapsed() <= WALK_LOCK_INTERVAL) + if(m_walkLocked && m_walkLockTimer.ticksElapsed() <= m_walkLockInterval) return false; else m_walkLocked = false; diff --git a/src/otclient/localplayer.h b/src/otclient/localplayer.h index 7d38ab80..97668a90 100644 --- a/src/otclient/localplayer.h +++ b/src/otclient/localplayer.h @@ -29,7 +29,6 @@ class LocalPlayer : public Player { enum { - WALK_LOCK_INTERVAL = 250, PREWALK_TIMEOUT = 1000 }; @@ -37,7 +36,7 @@ public: LocalPlayer(); void unlockWalk() { m_walkLocked = false; } - void lockWalk(); + void lockWalk(int millis = 250); bool canWalk(Otc::Direction direction); void setStates(int states); @@ -112,6 +111,7 @@ private: bool m_known; int m_states; int m_vocation; + int m_walkLockInterval; double m_health; double m_maxHealth; diff --git a/src/otclient/luafunctions.cpp b/src/otclient/luafunctions.cpp index 725cab91..91c03331 100644 --- a/src/otclient/luafunctions.cpp +++ b/src/otclient/luafunctions.cpp @@ -164,6 +164,7 @@ void OTClient::registerLuaFunctions() g_lua.bindSingletonFunction("g_game", "inspectNpcTrade", &Game::inspectNpcTrade, &g_game); g_lua.bindSingletonFunction("g_game", "buyItem", &Game::buyItem, &g_game); g_lua.bindSingletonFunction("g_game", "sellItem", &Game::sellItem, &g_game); + g_lua.bindSingletonFunction("g_game", "ping", &Game::ping, &g_game); g_lua.bindSingletonFunction("g_game", "closeNpcTrade", &Game::closeNpcTrade, &g_game); g_lua.bindSingletonFunction("g_game", "requestTrade", &Game::requestTrade, &g_game); g_lua.bindSingletonFunction("g_game", "inspectTrade", &Game::inspectTrade, &g_game); @@ -249,6 +250,8 @@ void OTClient::registerLuaFunctions() g_lua.bindClassMemberFunction("getStackPriority", &Thing::getStackPriority); g_lua.bindClassMemberFunction("getAnimationPhases", &Thing::getAnimationPhases); g_lua.bindClassMemberFunction("isItem", &Thing::isItem); + g_lua.bindClassMemberFunction("isMonster", &Thing::isMonster); + g_lua.bindClassMemberFunction("isNpc", &Thing::isNpc); g_lua.bindClassMemberFunction("isCreature", &Thing::isCreature); g_lua.bindClassMemberFunction("isEffect", &Thing::isEffect); g_lua.bindClassMemberFunction("isMissile", &Thing::isMissile); diff --git a/src/otclient/protocolgame.h b/src/otclient/protocolgame.h index 61b4e9ae..948f6941 100644 --- a/src/otclient/protocolgame.h +++ b/src/otclient/protocolgame.h @@ -219,6 +219,7 @@ private: std::string m_accountName; std::string m_accountPassword; std::string m_characterName; + Timer m_pingTimer; LocalPlayerPtr m_localPlayer; }; diff --git a/src/otclient/protocolgameparse.cpp b/src/otclient/protocolgameparse.cpp index b61fb921..0b87c757 100644 --- a/src/otclient/protocolgameparse.cpp +++ b/src/otclient/protocolgameparse.cpp @@ -378,7 +378,7 @@ void ProtocolGame::parsePing(const InputMessagePtr& msg) void ProtocolGame::parsePingBack(const InputMessagePtr& msg) { - // nothing to do + g_game.processPingBack(m_pingTimer.ticksElapsed()); } void ProtocolGame::parseChallange(const InputMessagePtr& msg) @@ -928,7 +928,7 @@ void ProtocolGame::parsePlayerCancelAttack(const InputMessagePtr& msg) void ProtocolGame::parseSpellCooldown(const InputMessagePtr& msg) { - msg->getU16(); // spell id + msg->getU8(); // spell id msg->getU32(); // cooldown } @@ -1083,16 +1083,26 @@ void ProtocolGame::parseTextMessage(const InputMessagePtr& msg) case Otc::MessageDamageReceived: case Otc::MessageDamageOthers: { Position pos = getPosition(msg); - uint value = msg->getU32(); - int color = msg->getU8(); - msg->getU32(); // ?? - msg->getU8(); // ?? + uint value[2]; + int color[2]; + + // physical damage + value[0] = msg->getU32(); + color[0] = msg->getU8(); + + // magic damage + value[1] = msg->getU32(); + color[1] = msg->getU8(); text = msg->getString(); - AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); - animatedText->setColor(color); - animatedText->setText(stdext::to_string(value)); - g_map.addThing(animatedText, pos); + for(int i=0;i<2;++i) { + if(value[i] == 0) + continue; + AnimatedTextPtr animatedText = AnimatedTextPtr(new AnimatedText); + animatedText->setColor(color[i]); + animatedText->setText(stdext::to_string(value[i])); + g_map.addThing(animatedText, pos); + } break; } case Otc::MessageHeal: @@ -1130,8 +1140,8 @@ void ProtocolGame::parseCancelWalk(const InputMessagePtr& msg) void ProtocolGame::parseWalkWait(const InputMessagePtr& msg) { - //TODO: implement walk wait time - msg->getU16(); // time + int millis = msg->getU16(); + m_localPlayer->lockWalk(millis); } void ProtocolGame::parseFloorChangeUp(const InputMessagePtr& msg) diff --git a/src/otclient/protocolgamesend.cpp b/src/otclient/protocolgamesend.cpp index 1459a09d..3e022ba4 100644 --- a/src/otclient/protocolgamesend.cpp +++ b/src/otclient/protocolgamesend.cpp @@ -109,6 +109,7 @@ void ProtocolGame::sendPing() { OutputMessagePtr msg(new OutputMessage); msg->addU8(Proto::ClientPing); + m_pingTimer.restart(); Protocol::send(msg); }